2 * USB driver for Gigaset 307x directly or using M105 Data.
4 * Copyright (c) 2001 by Stefan Eilers <Eilers.Stefan@epost.de>
5 * and Hansjoerg Lipp <hjlipp@web.de>.
7 * This driver was derived from the USB skeleton driver by
8 * Greg Kroah-Hartman <greg@kroah.com>
10 * =====================================================================
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 * =====================================================================
17 * =====================================================================
18 * Version: $Id: usb-gigaset.c,v 1.85.4.18 2006/02/04 18:28:16 hjlipp Exp $
19 * =====================================================================
24 #include <linux/errno.h>
25 #include <linux/init.h>
26 #include <linux/slab.h>
27 #include <linux/usb.h>
28 #include <linux/module.h>
29 #include <linux/moduleparam.h>
31 /* Version Information */
32 #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers <Eilers.Stefan@epost.de>"
33 #define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
35 /* Module parameters */
37 static int startmode
= SM_ISDN
;
38 static int cidmode
= 1;
40 module_param(startmode
, int, S_IRUGO
);
41 module_param(cidmode
, int, S_IRUGO
);
42 MODULE_PARM_DESC(startmode
, "start in isdn4linux mode");
43 MODULE_PARM_DESC(cidmode
, "Call-ID mode");
45 #define GIGASET_MINORS 1
46 #define GIGASET_MINOR 8
47 #define GIGASET_MODULENAME "usb_gigaset"
48 #define GIGASET_DEVFSNAME "gig/usb/"
49 #define GIGASET_DEVNAME "ttyGU"
51 #define IF_WRITEBUF 2000 //FIXME // WAKEUP_CHARS: 256
53 /* Values for the Gigaset M105 Data */
54 #define USB_M105_VENDOR_ID 0x0681
55 #define USB_M105_PRODUCT_ID 0x0009
57 /* table of devices that work with this driver */
58 static struct usb_device_id gigaset_table
[] = {
59 { USB_DEVICE(USB_M105_VENDOR_ID
, USB_M105_PRODUCT_ID
) },
60 { } /* Terminating entry */
63 MODULE_DEVICE_TABLE(usb
, gigaset_table
);
65 /* Get a minor range for your devices from the usb maintainer */
66 #define USB_SKEL_MINOR_BASE 200
70 * Control requests (empty fields: 00)
72 * RT|RQ|VALUE|INDEX|LEN |DATA
75 * Get flags (1 byte). Bits: 0=dtr,1=rts,3-7:?
77 * Get device information/status (llll: 0x200 and 0x40 seen).
78 * Real size: I only saw MIN(llll,0x64).
79 * Contents: seems to be always the same...
80 * offset 0x00: Length of this structure (0x64) (len: 1,2,3 bytes)
81 * offset 0x3c: String (16 bit chars): "MCCI USB Serial V2.0"
85 * Initialize/reset device ?
87 * ? (xx=00 or 01; 01 on start, 00 on close)
89 * Set/clear flags vv=value, mm=mask (see RQ 08)
91 * Used before the following configuration requests are issued
92 * (with xx=0x0f). I've seen other values<0xf, though.
94 * Set baud rate. xxxx=ceil(0x384000/rate)=trunc(0x383fff/rate)+1.
96 * Set byte size and parity. p: 0x20=even,0x10=odd,0x00=no parity
97 * [ 0x30: m, 0x40: s ]
98 * [s: 0: 1 stop bit; 1: 1.5; 2: 2]
99 * bb: bits/byte (seen 7 and 8)
100 * 41 13 -- -- -- -- 10 00 ww 00 00 00 xx 00 00 00 yy 00 00 00 zz 00 00 00
102 * Initialization: 01, 40, 00, 00
103 * Open device: 00 40, 00, 00
104 * yy and zz seem to be equal, either 0x00 or 0x0a
105 * (ww,xx) pairs seen: (00,00), (00,40), (01,40), (09,80), (19,80)
106 * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13
107 * Used after every "configuration sequence" (RQ 12, RQs 01/03/13).
108 * xx is usually 0x00 but was 0x7e before starting data transfer
109 * in unimodem mode. So, this might be an array of characters that need
110 * special treatment ("commit all bufferd data"?), 11=^Q, 13=^S.
112 * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two
116 static int gigaset_probe(struct usb_interface
*interface
,
117 const struct usb_device_id
*id
);
118 static void gigaset_disconnect(struct usb_interface
*interface
);
120 static struct gigaset_driver
*driver
= NULL
;
121 static struct cardstate
*cardstate
= NULL
;
123 /* usb specific object needed to register this driver with the usb subsystem */
124 static struct usb_driver gigaset_usb_driver
= {
125 .name
= GIGASET_MODULENAME
,
126 .probe
= gigaset_probe
,
127 .disconnect
= gigaset_disconnect
,
128 .id_table
= gigaset_table
,
131 struct usb_cardstate
{
132 struct usb_device
*udev
; /* save off the usb device pointer */
133 struct usb_interface
*interface
; /* the interface for this device */
134 atomic_t busy
; /* bulk output in progress */
136 /* Output buffer for commands (M105: and data)*/
137 unsigned char *bulk_out_buffer
; /* the buffer to send data */
138 int bulk_out_size
; /* the size of the send buffer */
139 __u8 bulk_out_endpointAddr
; /* the address of the bulk out endpoint */
140 struct urb
*bulk_out_urb
; /* the urb used to transmit data */
142 /* Input buffer for command responses (M105: and data)*/
143 int rcvbuf_size
; /* the size of the receive buffer */
144 struct urb
*read_urb
; /* the urb used to receive data */
145 __u8 int_in_endpointAddr
; /* the address of the bulk in endpoint */
147 char bchars
[6]; /* req. 0x19 */
150 struct usb_bc_state
{};
152 static inline unsigned tiocm_to_gigaset(unsigned state
)
154 return ((state
& TIOCM_DTR
) ? 1 : 0) | ((state
& TIOCM_RTS
) ? 2 : 0);
157 #ifdef CONFIG_GIGASET_UNDOCREQ
158 /* WARNING: EXPERIMENTAL! */
159 static int gigaset_set_modem_ctrl(struct cardstate
*cs
, unsigned old_state
,
165 mask
= tiocm_to_gigaset(old_state
^ new_state
);
166 val
= tiocm_to_gigaset(new_state
);
168 dbg(DEBUG_USBREQ
, "set flags 0x%02x with mask 0x%02x", val
, mask
);
169 r
= usb_control_msg(cs
->hw
.usb
->udev
,
170 usb_sndctrlpipe(cs
->hw
.usb
->udev
, 0), 7, 0x41,
171 (val
& 0xff) | ((mask
& 0xff) << 8), 0,
172 NULL
, 0, 2000 /*timeout??*/); // don't use this in an interrupt/BH
179 static int set_value(struct cardstate
*cs
, u8 req
, u16 val
)
183 dbg(DEBUG_USBREQ
, "request %02x (%04x)", (unsigned)req
, (unsigned)val
);
184 r
= usb_control_msg(cs
->hw
.usb
->udev
,
185 usb_sndctrlpipe(cs
->hw
.usb
->udev
, 0), 0x12, 0x41,
187 NULL
, 0, 2000 /*?*/); /* no idea, what this does */
189 err("error %d on request 0x12", -r
);
193 r
= usb_control_msg(cs
->hw
.usb
->udev
,
194 usb_sndctrlpipe(cs
->hw
.usb
->udev
, 0), req
, 0x41,
196 NULL
, 0, 2000 /*?*/);
198 err("error %d on request 0x%02x", -r
, (unsigned)req
);
200 r2
= usb_control_msg(cs
->hw
.usb
->udev
,
201 usb_sndctrlpipe(cs
->hw
.usb
->udev
, 0), 0x19, 0x41,
202 0, 0, cs
->hw
.usb
->bchars
, 6, 2000 /*?*/);
204 err("error %d on request 0x19", -r2
);
206 return r
< 0 ? r
: (r2
< 0 ? r2
: 0);
209 /* WARNING: HIGHLY EXPERIMENTAL! */
210 // don't use this in an interrupt/BH
211 static int gigaset_baud_rate(struct cardstate
*cs
, unsigned cflag
)
220 case B300
: rate
= 300; break;
221 case B600
: rate
= 600; break;
222 case B1200
: rate
= 1200; break;
223 case B2400
: rate
= 2400; break;
224 case B4800
: rate
= 4800; break;
225 case B9600
: rate
= 9600; break;
226 case B19200
: rate
= 19200; break;
227 case B38400
: rate
= 38400; break;
228 case B57600
: rate
= 57600; break;
229 case B115200
: rate
= 115200; break;
232 err("unsupported baudrate request 0x%x,"
233 " using default of B9600", cflag
);
236 val
= 0x383fff / rate
+ 1;
238 return set_value(cs
, 1, val
);
241 /* WARNING: HIGHLY EXPERIMENTAL! */
242 // don't use this in an interrupt/BH
243 static int gigaset_set_line_ctrl(struct cardstate
*cs
, unsigned cflag
)
249 val
|= (cflag
& PARODD
) ? 0x10 : 0x20;
251 /* set the number of data bits */
252 switch (cflag
& CSIZE
) {
254 val
|= 5 << 8; break;
256 val
|= 6 << 8; break;
258 val
|= 7 << 8; break;
260 val
|= 8 << 8; break;
262 err("CSIZE was not CS5-CS8, using default of 8");
267 /* set the number of stop bits */
268 if (cflag
& CSTOPB
) {
269 if ((cflag
& CSIZE
) == CS5
)
270 val
|= 1; /* 1.5 stop bits */ //FIXME is this okay?
272 val
|= 2; /* 2 stop bits */
275 return set_value(cs
, 3, val
);
279 static int gigaset_set_modem_ctrl(struct cardstate
*cs
, unsigned old_state
,
285 static int gigaset_set_line_ctrl(struct cardstate
*cs
, unsigned cflag
)
290 static int gigaset_baud_rate(struct cardstate
*cs
, unsigned cflag
)
297 /*================================================================================================================*/
298 static int gigaset_init_bchannel(struct bc_state
*bcs
)
300 /* nothing to do for M10x */
301 gigaset_bchannel_up(bcs
);
305 static int gigaset_close_bchannel(struct bc_state
*bcs
)
307 /* nothing to do for M10x */
308 gigaset_bchannel_down(bcs
);
312 //void send_ack_to_LL(void *data);
313 static int write_modem(struct cardstate
*cs
);
314 static int send_cb(struct cardstate
*cs
, struct cmdbuf_t
*cb
);
317 /* Handling of send queue. If there is already a skb opened, put data to
318 * the transfer buffer by calling "write_modem". Otherwise take a new skb out of the queue.
319 * This function will be called by the ISR via "transmit_chars" (USB: B-Channel Bulk callback handler
320 * via immediate task queue) or by writebuf_from_LL if the LL wants to transmit data.
322 static void gigaset_modem_fill(unsigned long data
)
324 struct cardstate
*cs
= (struct cardstate
*) data
;
325 struct bc_state
*bcs
= &cs
->bcs
[0]; /* only one channel */
330 dbg(DEBUG_OUTPUT
, "modem_fill");
332 if (atomic_read(&cs
->hw
.usb
->busy
)) {
333 dbg(DEBUG_OUTPUT
, "modem_fill: busy");
339 if (!bcs
->tx_skb
) { /* no skb is being sent */
340 spin_lock_irqsave(&cs
->cmdlock
, flags
);
342 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
343 if (cb
) { /* commands to send? */
344 dbg(DEBUG_OUTPUT
, "modem_fill: cb");
345 if (send_cb(cs
, cb
) < 0) {
347 "modem_fill: send_cb failed");
348 again
= 1; /* no callback will be called! */
350 } else { /* skbs to send? */
351 bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
);
354 "Dequeued skb (Adr: %lx)!",
355 (unsigned long) bcs
->tx_skb
);
360 dbg(DEBUG_OUTPUT
, "modem_fill: tx_skb");
361 if (write_modem(cs
) < 0) {
363 "modem_fill: write_modem failed");
364 // FIXME should we tell the LL?
365 again
= 1; /* no callback will be called! */
372 * gigaset_read_int_callback
374 * It is called if the data was received from the device. This is almost similiar to
375 * the interrupt service routine in the serial device.
377 static void gigaset_read_int_callback(struct urb
*urb
, struct pt_regs
*regs
)
381 struct cardstate
*cs
;
384 //unsigned long flags;
385 struct inbuf_t
*inbuf
;
388 inbuf
= (struct inbuf_t
*) urb
->context
;
390 //spin_lock_irqsave(&inbuf->lock, flags);
392 IFNULLGOTO(cs
, exit
);
393 IFNULLGOTO(cardstate
, exit
);
395 if (!atomic_read(&cs
->connected
)) {
396 err("%s: disconnected", __func__
);
401 numbytes
= urb
->actual_length
;
406 warn("%s: There was no leading 0, but 0x%02x!",
407 __func__
, (unsigned) *src
);
408 ++src
; /* skip leading 0x00 */
410 if (gigaset_fill_inbuf(inbuf
, src
, numbytes
)) {
411 dbg(DEBUG_INTR
, "%s-->BH", __func__
);
412 gigaset_schedule_event(inbuf
->cs
);
415 dbg(DEBUG_INTR
, "Received zero block length");
418 /* The urb might have been killed. */
419 dbg(DEBUG_ANY
, "%s - nonzero read bulk status received: %d",
420 __func__
, urb
->status
);
421 if (urb
->status
!= -ENOENT
) /* not killed */
425 //spin_unlock_irqrestore(&inbuf->lock, flags);
427 r
= usb_submit_urb(urb
, SLAB_ATOMIC
);
429 err("error %d when resubmitting urb.", -r
);
434 /* This callback routine is called when data was transmitted to a B-Channel.
435 * Therefore it has to check if there is still data to transmit. This
436 * happens by calling modem_fill via task queue.
439 static void gigaset_write_bulk_callback(struct urb
*urb
, struct pt_regs
*regs
)
441 struct cardstate
*cs
= (struct cardstate
*) urb
->context
;
444 #ifdef CONFIG_GIGASET_DEBUG
445 if (!atomic_read(&cs
->connected
)) {
446 err("%s:not connected", __func__
);
451 err("bulk transfer failed (status %d)", -urb
->status
); /* That's all we can do. Communication problems
452 are handeled by timeouts or network protocols */
454 atomic_set(&cs
->hw
.usb
->busy
, 0);
455 tasklet_schedule(&cs
->write_tasklet
);
458 static int send_cb(struct cardstate
*cs
, struct cmdbuf_t
*cb
)
460 struct cmdbuf_t
*tcb
;
463 int status
= -ENOENT
; // FIXME
464 struct usb_cardstate
*ucs
= cs
->hw
.usb
;
470 spin_lock_irqsave(&cs
->cmdlock
, flags
);
471 cs
->cmdbytes
-= cs
->curlen
;
472 dbg(DEBUG_OUTPUT
, "send_cb: sent %u bytes, %u left",
473 cs
->curlen
, cs
->cmdbytes
);
474 cs
->cmdbuf
= cb
= cb
->next
;
477 cs
->curlen
= cb
->len
;
479 cs
->lastcmdbuf
= NULL
;
482 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
484 if (tcb
->wake_tasklet
)
485 tasklet_schedule(tcb
->wake_tasklet
);
489 count
= min(cb
->len
, ucs
->bulk_out_size
);
490 usb_fill_bulk_urb(ucs
->bulk_out_urb
, ucs
->udev
,
491 usb_sndbulkpipe(ucs
->udev
,
492 ucs
->bulk_out_endpointAddr
& 0x0f),
493 cb
->buf
+ cb
->offset
, count
,
494 gigaset_write_bulk_callback
, cs
);
498 atomic_set(&ucs
->busy
, 1);
499 dbg(DEBUG_OUTPUT
, "send_cb: send %d bytes", count
);
501 status
= usb_submit_urb(ucs
->bulk_out_urb
, SLAB_ATOMIC
);
503 atomic_set(&ucs
->busy
, 0);
504 err("could not submit urb (error %d).",
506 cb
->len
= 0; /* skip urb => remove cb+wakeup in next loop cycle */
509 } while (cb
&& status
); /* bei Fehler naechster Befehl //FIXME: ist das OK? */
514 /* Write string into transbuf and send it to modem.
516 static int gigaset_write_cmd(struct cardstate
*cs
, const unsigned char *buf
,
517 int len
, struct tasklet_struct
*wake_tasklet
)
522 gigaset_dbg_buffer(atomic_read(&cs
->mstate
) != MS_LOCKED
?
523 DEBUG_TRANSCMD
: DEBUG_LOCKCMD
,
524 "CMD Transmit", len
, buf
, 0);
526 if (!atomic_read(&cs
->connected
)) {
527 err("%s: not connected", __func__
);
534 if (!(cb
= kmalloc(sizeof(struct cmdbuf_t
) + len
, GFP_ATOMIC
))) {
535 err("%s: out of memory", __func__
);
539 memcpy(cb
->buf
, buf
, len
);
543 cb
->wake_tasklet
= wake_tasklet
;
545 spin_lock_irqsave(&cs
->cmdlock
, flags
);
546 cb
->prev
= cs
->lastcmdbuf
;
548 cs
->lastcmdbuf
->next
= cb
;
555 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
557 tasklet_schedule(&cs
->write_tasklet
);
561 static int gigaset_write_room(struct cardstate
*cs
)
566 spin_lock_irqsave(&cs
->cmdlock
, flags
);
567 bytes
= cs
->cmdbytes
;
568 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
570 return bytes
< IF_WRITEBUF
? IF_WRITEBUF
- bytes
: 0;
573 static int gigaset_chars_in_buffer(struct cardstate
*cs
)
578 static int gigaset_brkchars(struct cardstate
*cs
, const unsigned char buf
[6])
580 #ifdef CONFIG_GIGASET_UNDOCREQ
581 gigaset_dbg_buffer(DEBUG_USBREQ
, "brkchars", 6, buf
, 0);
582 memcpy(cs
->hw
.usb
->bchars
, buf
, 6);
583 return usb_control_msg(cs
->hw
.usb
->udev
,
584 usb_sndctrlpipe(cs
->hw
.usb
->udev
, 0), 0x19, 0x41,
585 0, 0, &buf
, 6, 2000);
591 static int gigaset_freebcshw(struct bc_state
*bcs
)
600 /* Initialize the b-channel structure */
601 static int gigaset_initbcshw(struct bc_state
*bcs
)
603 bcs
->hw
.usb
= kmalloc(sizeof(struct usb_bc_state
), GFP_KERNEL
);
607 //bcs->hw.usb->trans_flg = READY_TO_TRNSMIT; /* B-Channel ready to transmit */
611 static void gigaset_reinitbcshw(struct bc_state
*bcs
)
615 static void gigaset_freecshw(struct cardstate
*cs
)
618 tasklet_kill(&cs
->write_tasklet
);
622 static int gigaset_initcshw(struct cardstate
*cs
)
624 struct usb_cardstate
*ucs
;
627 kmalloc(sizeof(struct usb_cardstate
), GFP_KERNEL
);
635 ucs
->bchars
[4] = 0x11;
636 ucs
->bchars
[5] = 0x13;
637 ucs
->bulk_out_buffer
= NULL
;
638 ucs
->bulk_out_urb
= NULL
;
639 //ucs->urb_cmd_out = NULL;
640 ucs
->read_urb
= NULL
;
641 tasklet_init(&cs
->write_tasklet
,
642 &gigaset_modem_fill
, (unsigned long) cs
);
647 /* Writes the data of the current open skb into the modem.
648 * We have to protect against multiple calls until the
649 * callback handler () is called , due to the fact that we
650 * are just allowed to send data once to an endpoint. Therefore
651 * we using "trans_flg" to synchonize ...
653 static int write_modem(struct cardstate
*cs
)
657 struct bc_state
*bcs
= &cs
->bcs
[0]; /* only one channel */
658 struct usb_cardstate
*ucs
= cs
->hw
.usb
;
659 //unsigned long flags;
661 IFNULLRETVAL(bcs
->tx_skb
, -EINVAL
);
663 dbg(DEBUG_WRITE
, "len: %d...", bcs
->tx_skb
->len
);
666 IFNULLGOTO(ucs
->bulk_out_buffer
, error
);
667 IFNULLGOTO(ucs
->bulk_out_urb
, error
);
670 if (!bcs
->tx_skb
->len
) {
671 dev_kfree_skb_any(bcs
->tx_skb
);
676 /* Copy data to bulk out buffer and // FIXME copying not necessary
679 count
= min(bcs
->tx_skb
->len
, (unsigned) ucs
->bulk_out_size
);
680 memcpy(ucs
->bulk_out_buffer
, bcs
->tx_skb
->data
, count
);
681 skb_pull(bcs
->tx_skb
, count
);
683 usb_fill_bulk_urb(ucs
->bulk_out_urb
, ucs
->udev
,
684 usb_sndbulkpipe(ucs
->udev
,
685 ucs
->bulk_out_endpointAddr
& 0x0f),
686 ucs
->bulk_out_buffer
, count
,
687 gigaset_write_bulk_callback
, cs
);
688 atomic_set(&ucs
->busy
, 1);
689 dbg(DEBUG_OUTPUT
, "write_modem: send %d bytes", count
);
691 ret
= usb_submit_urb(ucs
->bulk_out_urb
, SLAB_ATOMIC
);
693 err("could not submit urb (error %d).", -ret
);
694 atomic_set(&ucs
->busy
, 0);
696 if (!bcs
->tx_skb
->len
) {
697 /* skb sent completely */
698 gigaset_skb_sent(bcs
, bcs
->tx_skb
); //FIXME also, when ret<0?
701 "kfree skb (Adr: %lx)!", (unsigned long) bcs
->tx_skb
);
702 dev_kfree_skb_any(bcs
->tx_skb
);
708 dev_kfree_skb_any(bcs
->tx_skb
);
714 static int gigaset_probe(struct usb_interface
*interface
,
715 const struct usb_device_id
*id
)
718 struct usb_device
*udev
= interface_to_usbdev(interface
);
720 struct usb_host_interface
*hostif
;
721 struct cardstate
*cs
= NULL
;
722 struct usb_cardstate
*ucs
= NULL
;
723 //struct usb_interface_descriptor *iface_desc;
724 struct usb_endpoint_descriptor
*endpoint
;
728 //unsigned long flags;
730 info("%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
731 __func__
, le16_to_cpu(udev
->descriptor
.idVendor
),
732 le16_to_cpu(udev
->descriptor
.idProduct
));
734 retval
= -ENODEV
; //FIXME
736 /* See if the device offered us matches what we can accept */
737 if ((le16_to_cpu(udev
->descriptor
.idVendor
!= USB_M105_VENDOR_ID
)) ||
738 (le16_to_cpu(udev
->descriptor
.idProduct
!= USB_M105_PRODUCT_ID
)))
741 /* this starts to become ascii art... */
742 hostif
= interface
->cur_altsetting
;
743 alt
= hostif
->desc
.bAlternateSetting
;
744 ifnum
= hostif
->desc
.bInterfaceNumber
; // FIXME ?
746 if (alt
!= 0 || ifnum
!= 0) {
747 warn("ifnum %d, alt %d", ifnum
, alt
);
751 /* Reject application specific intefaces
754 if (hostif
->desc
.bInterfaceClass
!= 255) {
755 info("%s: Device matched, but iface_desc[%d]->bInterfaceClass==%d !",
756 __func__
, ifnum
, hostif
->desc
.bInterfaceClass
);
760 info("%s: Device matched ... !", __func__
);
762 cs
= gigaset_getunassignedcs(driver
);
764 warn("No free cardstate!");
770 if (usb_set_configuration(udev
, udev
->config
[0].desc
.bConfigurationValue
) < 0) {
771 warn("set_configuration failed");
776 if (usb_set_interface(udev
, ifnum
/*==0*/, alt
/*==0*/) < 0) {
777 warn("usb_set_interface failed, device %d interface %d altsetting %d",
778 udev
->devnum
, ifnum
, alt
);
783 /* set up the endpoint information */
784 /* check out the endpoints */
785 /* We will get 2 endpoints: One for sending commands to the device (bulk out) and one to
786 * poll messages from the device(int in).
787 * Therefore we will have an almost similiar situation as with our serial port handler.
788 * If an connection will be established, we will have to create data in/out pipes
792 endpoint
= &hostif
->endpoint
[0].desc
;
794 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
795 ucs
->bulk_out_size
= buffer_size
;
796 ucs
->bulk_out_endpointAddr
= endpoint
->bEndpointAddress
;
797 ucs
->bulk_out_buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
798 if (!ucs
->bulk_out_buffer
) {
799 err("Couldn't allocate bulk_out_buffer");
804 ucs
->bulk_out_urb
= usb_alloc_urb(0, SLAB_KERNEL
);
805 if (!ucs
->bulk_out_urb
) {
806 err("Couldn't allocate bulk_out_buffer");
811 endpoint
= &hostif
->endpoint
[1].desc
;
813 atomic_set(&ucs
->busy
, 0);
815 ucs
->interface
= interface
;
817 ucs
->read_urb
= usb_alloc_urb(0, SLAB_KERNEL
);
818 if (!ucs
->read_urb
) {
819 err("No free urbs available");
823 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
824 ucs
->rcvbuf_size
= buffer_size
;
825 ucs
->int_in_endpointAddr
= endpoint
->bEndpointAddress
;
826 cs
->inbuf
[0].rcvbuf
= kmalloc(buffer_size
, GFP_KERNEL
);
827 if (!cs
->inbuf
[0].rcvbuf
) {
828 err("Couldn't allocate rcvbuf");
832 /* Fill the interrupt urb and send it to the core */
833 usb_fill_int_urb(ucs
->read_urb
, udev
,
835 endpoint
->bEndpointAddress
& 0x0f),
836 cs
->inbuf
[0].rcvbuf
, buffer_size
,
837 gigaset_read_int_callback
,
838 cs
->inbuf
+ 0, endpoint
->bInterval
);
840 retval
= usb_submit_urb(ucs
->read_urb
, SLAB_KERNEL
);
842 err("Could not submit URB!");
846 /* tell common part that the device is ready */
847 if (startmode
== SM_LOCKED
)
848 atomic_set(&cs
->mstate
, MS_LOCKED
);
849 if (!gigaset_start(cs
)) {
850 tasklet_kill(&cs
->write_tasklet
);
851 retval
= -ENODEV
; //FIXME
855 /* save address of controller structure */
856 usb_set_intfdata(interface
, cs
);
858 /* set up device sysfs */
859 gigaset_init_dev_sysfs(interface
);
864 usb_kill_urb(ucs
->read_urb
);
865 kfree(ucs
->bulk_out_buffer
);
866 if (ucs
->bulk_out_urb
!= NULL
)
867 usb_free_urb(ucs
->bulk_out_urb
);
868 kfree(cs
->inbuf
[0].rcvbuf
);
869 if (ucs
->read_urb
!= NULL
)
870 usb_free_urb(ucs
->read_urb
);
871 ucs
->read_urb
= ucs
->bulk_out_urb
= NULL
;
872 cs
->inbuf
[0].rcvbuf
= ucs
->bulk_out_buffer
= NULL
;
873 gigaset_unassign(cs
);
880 static void gigaset_disconnect(struct usb_interface
*interface
)
882 struct cardstate
*cs
;
883 struct usb_cardstate
*ucs
;
885 cs
= usb_get_intfdata(interface
);
887 /* clear device sysfs */
888 gigaset_free_dev_sysfs(interface
);
890 usb_set_intfdata(interface
, NULL
);
892 usb_kill_urb(ucs
->read_urb
);
893 //info("GigaSet USB device #%d will be disconnected", minor);
897 tasklet_kill(&cs
->write_tasklet
);
899 usb_kill_urb(ucs
->bulk_out_urb
); /* FIXME: nur, wenn noetig */
900 //usb_kill_urb(ucs->urb_cmd_out); /* FIXME: nur, wenn noetig */
902 kfree(ucs
->bulk_out_buffer
);
903 if (ucs
->bulk_out_urb
!= NULL
)
904 usb_free_urb(ucs
->bulk_out_urb
);
905 //if(ucs->urb_cmd_out != NULL)
906 // usb_free_urb(ucs->urb_cmd_out);
907 kfree(cs
->inbuf
[0].rcvbuf
);
908 if (ucs
->read_urb
!= NULL
)
909 usb_free_urb(ucs
->read_urb
);
910 ucs
->read_urb
= ucs
->bulk_out_urb
/*=ucs->urb_cmd_out*/=NULL
;
911 cs
->inbuf
[0].rcvbuf
= ucs
->bulk_out_buffer
= NULL
;
913 gigaset_unassign(cs
);
916 static struct gigaset_ops ops
= {
919 gigaset_chars_in_buffer
,
921 gigaset_init_bchannel
,
922 gigaset_close_bchannel
,
928 gigaset_set_modem_ctrl
,
930 gigaset_set_line_ctrl
,
931 gigaset_m10x_send_skb
,
937 * This function is called while kernel-module is loaded
939 static int __init
usb_gigaset_init(void)
943 /* allocate memory for our driver state and intialize it */
944 if ((driver
= gigaset_initdriver(GIGASET_MINOR
, GIGASET_MINORS
,
945 GIGASET_MODULENAME
, GIGASET_DEVNAME
,
946 GIGASET_DEVFSNAME
, &ops
,
947 THIS_MODULE
)) == NULL
)
950 /* allocate memory for our device state and intialize it */
951 cardstate
= gigaset_initcs(driver
, 1, 1, 0, cidmode
, GIGASET_MODULENAME
);
955 /* register this driver with the USB subsystem */
956 result
= usb_register(&gigaset_usb_driver
);
958 err("usb_gigaset: usb_register failed (error %d)",
967 error
: if (cardstate
)
968 gigaset_freecs(cardstate
);
971 gigaset_freedriver(driver
);
979 * This function is called while unloading the kernel-module
981 static void __exit
usb_gigaset_exit(void)
983 gigaset_blockdriver(driver
); /* => probe will fail
984 * => no gigaset_start any more
987 gigaset_shutdown(cardstate
);
988 /* from now on, no isdn callback should be possible */
990 /* deregister this driver with the USB subsystem */
991 usb_deregister(&gigaset_usb_driver
);
992 /* this will call the disconnect-callback */
993 /* from now on, no disconnect/probe callback should be running */
995 gigaset_freecs(cardstate
);
997 gigaset_freedriver(driver
);
1002 module_init(usb_gigaset_init
);
1003 module_exit(usb_gigaset_exit
);
1005 MODULE_AUTHOR(DRIVER_AUTHOR
);
1006 MODULE_DESCRIPTION(DRIVER_DESC
);
1008 MODULE_LICENSE("GPL");