2 * USB driver for Gigaset 307x directly or using M105 Data.
4 * Copyright (c) 2001 by Stefan Eilers
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 * =====================================================================
19 #include <linux/usb.h>
20 #include <linux/module.h>
21 #include <linux/moduleparam.h>
23 /* Version Information */
24 #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
25 #define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
27 /* Module parameters */
29 static int startmode
= SM_ISDN
;
30 static int cidmode
= 1;
32 module_param(startmode
, int, S_IRUGO
);
33 module_param(cidmode
, int, S_IRUGO
);
34 MODULE_PARM_DESC(startmode
, "start in isdn4linux mode");
35 MODULE_PARM_DESC(cidmode
, "Call-ID mode");
37 #define GIGASET_MINORS 1
38 #define GIGASET_MINOR 8
39 #define GIGASET_MODULENAME "usb_gigaset"
40 #define GIGASET_DEVNAME "ttyGU"
42 #define IF_WRITEBUF 2000 /* arbitrary limit */
44 /* Values for the Gigaset M105 Data */
45 #define USB_M105_VENDOR_ID 0x0681
46 #define USB_M105_PRODUCT_ID 0x0009
48 /* table of devices that work with this driver */
49 static const struct usb_device_id gigaset_table
[] = {
50 { USB_DEVICE(USB_M105_VENDOR_ID
, USB_M105_PRODUCT_ID
) },
51 { } /* Terminating entry */
54 MODULE_DEVICE_TABLE(usb
, gigaset_table
);
57 * Control requests (empty fields: 00)
59 * RT|RQ|VALUE|INDEX|LEN |DATA
62 * Get flags (1 byte). Bits: 0=dtr,1=rts,3-7:?
64 * Get device information/status (llll: 0x200 and 0x40 seen).
65 * Real size: I only saw MIN(llll,0x64).
66 * Contents: seems to be always the same...
67 * offset 0x00: Length of this structure (0x64) (len: 1,2,3 bytes)
68 * offset 0x3c: String (16 bit chars): "MCCI USB Serial V2.0"
72 * Initialize/reset device ?
74 * ? (xx=00 or 01; 01 on start, 00 on close)
76 * Set/clear flags vv=value, mm=mask (see RQ 08)
78 * Used before the following configuration requests are issued
79 * (with xx=0x0f). I've seen other values<0xf, though.
81 * Set baud rate. xxxx=ceil(0x384000/rate)=trunc(0x383fff/rate)+1.
83 * Set byte size and parity. p: 0x20=even,0x10=odd,0x00=no parity
84 * [ 0x30: m, 0x40: s ]
85 * [s: 0: 1 stop bit; 1: 1.5; 2: 2]
86 * bb: bits/byte (seen 7 and 8)
87 * 41 13 -- -- -- -- 10 00 ww 00 00 00 xx 00 00 00 yy 00 00 00 zz 00 00 00
89 * Initialization: 01, 40, 00, 00
90 * Open device: 00 40, 00, 00
91 * yy and zz seem to be equal, either 0x00 or 0x0a
92 * (ww,xx) pairs seen: (00,00), (00,40), (01,40), (09,80), (19,80)
93 * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13
94 * Used after every "configuration sequence" (RQ 12, RQs 01/03/13).
95 * xx is usually 0x00 but was 0x7e before starting data transfer
96 * in unimodem mode. So, this might be an array of characters that
97 * need special treatment ("commit all bufferd data"?), 11=^Q, 13=^S.
99 * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two
103 /* functions called if a device of this driver is connected/disconnected */
104 static int gigaset_probe(struct usb_interface
*interface
,
105 const struct usb_device_id
*id
);
106 static void gigaset_disconnect(struct usb_interface
*interface
);
108 /* functions called before/after suspend */
109 static int gigaset_suspend(struct usb_interface
*intf
, pm_message_t message
);
110 static int gigaset_resume(struct usb_interface
*intf
);
111 static int gigaset_pre_reset(struct usb_interface
*intf
);
113 static struct gigaset_driver
*driver
;
115 /* usb specific object needed to register this driver with the usb subsystem */
116 static struct usb_driver gigaset_usb_driver
= {
117 .name
= GIGASET_MODULENAME
,
118 .probe
= gigaset_probe
,
119 .disconnect
= gigaset_disconnect
,
120 .id_table
= gigaset_table
,
121 .suspend
= gigaset_suspend
,
122 .resume
= gigaset_resume
,
123 .reset_resume
= gigaset_resume
,
124 .pre_reset
= gigaset_pre_reset
,
125 .post_reset
= gigaset_resume
,
128 struct usb_cardstate
{
129 struct usb_device
*udev
; /* usb device pointer */
130 struct usb_interface
*interface
; /* interface for this device */
131 int busy
; /* bulk output in progress */
134 unsigned char *bulk_out_buffer
;
136 __u8 bulk_out_endpointAddr
;
137 struct urb
*bulk_out_urb
;
140 unsigned char *rcvbuf
;
142 struct urb
*read_urb
;
143 __u8 int_in_endpointAddr
;
145 char bchars
[6]; /* for request 0x19 */
148 static inline unsigned tiocm_to_gigaset(unsigned state
)
150 return ((state
& TIOCM_DTR
) ? 1 : 0) | ((state
& TIOCM_RTS
) ? 2 : 0);
153 static int gigaset_set_modem_ctrl(struct cardstate
*cs
, unsigned old_state
,
156 struct usb_device
*udev
= cs
->hw
.usb
->udev
;
160 mask
= tiocm_to_gigaset(old_state
^ new_state
);
161 val
= tiocm_to_gigaset(new_state
);
163 gig_dbg(DEBUG_USBREQ
, "set flags 0x%02x with mask 0x%02x", val
, mask
);
164 r
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 7, 0x41,
165 (val
& 0xff) | ((mask
& 0xff) << 8), 0,
166 NULL
, 0, 2000 /* timeout? */);
173 * Set M105 configuration value
174 * using undocumented device commands reverse engineered from USB traces
175 * of the Siemens Windows driver
177 static int set_value(struct cardstate
*cs
, u8 req
, u16 val
)
179 struct usb_device
*udev
= cs
->hw
.usb
->udev
;
182 gig_dbg(DEBUG_USBREQ
, "request %02x (%04x)",
183 (unsigned)req
, (unsigned)val
);
184 r
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 0x12, 0x41,
185 0xf /*?*/, 0, NULL
, 0, 2000 /*?*/);
186 /* no idea what this does */
188 dev_err(&udev
->dev
, "error %d on request 0x12\n", -r
);
192 r
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), req
, 0x41,
193 val
, 0, NULL
, 0, 2000 /*?*/);
195 dev_err(&udev
->dev
, "error %d on request 0x%02x\n",
198 r2
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 0x19, 0x41,
199 0, 0, cs
->hw
.usb
->bchars
, 6, 2000 /*?*/);
201 dev_err(&udev
->dev
, "error %d on request 0x19\n", -r2
);
203 return r
< 0 ? r
: (r2
< 0 ? r2
: 0);
207 * set the baud rate on the internal serial adapter
208 * using the undocumented parameter setting command
210 static int gigaset_baud_rate(struct cardstate
*cs
, unsigned cflag
)
218 case B300
: rate
= 300; break;
219 case B600
: rate
= 600; break;
220 case B1200
: rate
= 1200; break;
221 case B2400
: rate
= 2400; break;
222 case B4800
: rate
= 4800; break;
223 case B9600
: rate
= 9600; break;
224 case B19200
: rate
= 19200; break;
225 case B38400
: rate
= 38400; break;
226 case B57600
: rate
= 57600; break;
227 case B115200
: rate
= 115200; break;
230 dev_err(cs
->dev
, "unsupported baudrate request 0x%x,"
231 " using default of B9600\n", cflag
);
234 val
= 0x383fff / rate
+ 1;
236 return set_value(cs
, 1, val
);
240 * set the line format on the internal serial adapter
241 * using the undocumented parameter setting command
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 dev_err(cs
->dev
, "CSIZE was not CS5-CS8, using default of 8\n");
267 /* set the number of stop bits */
268 if (cflag
& CSTOPB
) {
269 if ((cflag
& CSIZE
) == CS5
)
270 val
|= 1; /* 1.5 stop bits */
272 val
|= 2; /* 2 stop bits */
275 return set_value(cs
, 3, val
);
279 /*============================================================================*/
280 static int gigaset_init_bchannel(struct bc_state
*bcs
)
282 /* nothing to do for M10x */
283 gigaset_bchannel_up(bcs
);
287 static int gigaset_close_bchannel(struct bc_state
*bcs
)
289 /* nothing to do for M10x */
290 gigaset_bchannel_down(bcs
);
294 static int write_modem(struct cardstate
*cs
);
295 static int send_cb(struct cardstate
*cs
, struct cmdbuf_t
*cb
);
298 /* Write tasklet handler: Continue sending current skb, or send command, or
299 * start sending an skb from the send queue.
301 static void gigaset_modem_fill(unsigned long data
)
303 struct cardstate
*cs
= (struct cardstate
*) data
;
304 struct bc_state
*bcs
= &cs
->bcs
[0]; /* only one channel */
308 gig_dbg(DEBUG_OUTPUT
, "modem_fill");
310 if (cs
->hw
.usb
->busy
) {
311 gig_dbg(DEBUG_OUTPUT
, "modem_fill: busy");
317 if (!bcs
->tx_skb
) { /* no skb is being sent */
319 if (cb
) { /* commands to send? */
320 gig_dbg(DEBUG_OUTPUT
, "modem_fill: cb");
321 if (send_cb(cs
, cb
) < 0) {
322 gig_dbg(DEBUG_OUTPUT
,
323 "modem_fill: send_cb failed");
324 again
= 1; /* no callback will be
327 } else { /* skbs to send? */
328 bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
);
331 "Dequeued skb (Adr: %lx)!",
332 (unsigned long) bcs
->tx_skb
);
337 gig_dbg(DEBUG_OUTPUT
, "modem_fill: tx_skb");
338 if (write_modem(cs
) < 0) {
339 gig_dbg(DEBUG_OUTPUT
,
340 "modem_fill: write_modem failed");
341 again
= 1; /* no callback will be called! */
348 * Interrupt Input URB completion routine
350 static void gigaset_read_int_callback(struct urb
*urb
)
352 struct cardstate
*cs
= urb
->context
;
353 struct inbuf_t
*inbuf
= cs
->inbuf
;
354 int status
= urb
->status
;
361 numbytes
= urb
->actual_length
;
364 src
= cs
->hw
.usb
->rcvbuf
;
367 "%s: There was no leading 0, but 0x%02x!\n",
368 __func__
, (unsigned) *src
);
369 ++src
; /* skip leading 0x00 */
371 if (gigaset_fill_inbuf(inbuf
, src
, numbytes
)) {
372 gig_dbg(DEBUG_INTR
, "%s-->BH", __func__
);
373 gigaset_schedule_event(inbuf
->cs
);
376 gig_dbg(DEBUG_INTR
, "Received zero block length");
378 /* The urb might have been killed. */
379 gig_dbg(DEBUG_ANY
, "%s - nonzero status received: %d",
381 if (status
== -ENOENT
|| status
== -ESHUTDOWN
)
382 /* killed or endpoint shutdown: don't resubmit */
387 spin_lock_irqsave(&cs
->lock
, flags
);
388 if (!cs
->connected
) {
389 spin_unlock_irqrestore(&cs
->lock
, flags
);
390 pr_err("%s: disconnected\n", __func__
);
393 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
394 spin_unlock_irqrestore(&cs
->lock
, flags
);
396 dev_err(cs
->dev
, "error %d resubmitting URB\n", -r
);
400 /* This callback routine is called when data was transmitted to the device. */
401 static void gigaset_write_bulk_callback(struct urb
*urb
)
403 struct cardstate
*cs
= urb
->context
;
404 int status
= urb
->status
;
408 case 0: /* normal completion */
410 case -ENOENT
: /* killed */
411 gig_dbg(DEBUG_ANY
, "%s: killed", __func__
);
412 cs
->hw
.usb
->busy
= 0;
415 dev_err(cs
->dev
, "bulk transfer failed (status %d)\n",
417 /* That's all we can do. Communication problems
418 are handled by timeouts or network protocols. */
421 spin_lock_irqsave(&cs
->lock
, flags
);
422 if (!cs
->connected
) {
423 pr_err("%s: disconnected\n", __func__
);
425 cs
->hw
.usb
->busy
= 0;
426 tasklet_schedule(&cs
->write_tasklet
);
428 spin_unlock_irqrestore(&cs
->lock
, flags
);
431 static int send_cb(struct cardstate
*cs
, struct cmdbuf_t
*cb
)
433 struct cmdbuf_t
*tcb
;
436 int status
= -ENOENT
;
437 struct usb_cardstate
*ucs
= cs
->hw
.usb
;
443 spin_lock_irqsave(&cs
->cmdlock
, flags
);
444 cs
->cmdbytes
-= cs
->curlen
;
445 gig_dbg(DEBUG_OUTPUT
, "send_cb: sent %u bytes, %u left",
446 cs
->curlen
, cs
->cmdbytes
);
447 cs
->cmdbuf
= cb
= cb
->next
;
450 cs
->curlen
= cb
->len
;
452 cs
->lastcmdbuf
= NULL
;
455 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
457 if (tcb
->wake_tasklet
)
458 tasklet_schedule(tcb
->wake_tasklet
);
462 count
= min(cb
->len
, ucs
->bulk_out_size
);
463 gig_dbg(DEBUG_OUTPUT
, "send_cb: send %d bytes", count
);
465 usb_fill_bulk_urb(ucs
->bulk_out_urb
, ucs
->udev
,
466 usb_sndbulkpipe(ucs
->udev
,
467 ucs
->bulk_out_endpointAddr
& 0x0f),
468 cb
->buf
+ cb
->offset
, count
,
469 gigaset_write_bulk_callback
, cs
);
475 spin_lock_irqsave(&cs
->lock
, flags
);
476 status
= cs
->connected
?
477 usb_submit_urb(ucs
->bulk_out_urb
, GFP_ATOMIC
) :
479 spin_unlock_irqrestore(&cs
->lock
, flags
);
484 "could not submit urb (error %d)\n",
486 cb
->len
= 0; /* skip urb => remove cb+wakeup
487 in next loop cycle */
490 } while (cb
&& status
); /* next command on error */
495 /* Send command to device. */
496 static int gigaset_write_cmd(struct cardstate
*cs
, const unsigned char *buf
,
497 int len
, struct tasklet_struct
*wake_tasklet
)
502 gigaset_dbg_buffer(cs
->mstate
!= MS_LOCKED
?
503 DEBUG_TRANSCMD
: DEBUG_LOCKCMD
,
504 "CMD Transmit", len
, buf
);
508 cb
= kmalloc(sizeof(struct cmdbuf_t
) + len
, GFP_ATOMIC
);
510 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
514 memcpy(cb
->buf
, buf
, len
);
518 cb
->wake_tasklet
= wake_tasklet
;
520 spin_lock_irqsave(&cs
->cmdlock
, flags
);
521 cb
->prev
= cs
->lastcmdbuf
;
523 cs
->lastcmdbuf
->next
= cb
;
530 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
532 spin_lock_irqsave(&cs
->lock
, flags
);
534 tasklet_schedule(&cs
->write_tasklet
);
535 spin_unlock_irqrestore(&cs
->lock
, flags
);
539 static int gigaset_write_room(struct cardstate
*cs
)
543 bytes
= cs
->cmdbytes
;
544 return bytes
< IF_WRITEBUF
? IF_WRITEBUF
- bytes
: 0;
547 static int gigaset_chars_in_buffer(struct cardstate
*cs
)
553 * set the break characters on the internal serial adapter
554 * using undocumented device commands reverse engineered from USB traces
555 * of the Siemens Windows driver
557 static int gigaset_brkchars(struct cardstate
*cs
, const unsigned char buf
[6])
559 struct usb_device
*udev
= cs
->hw
.usb
->udev
;
561 gigaset_dbg_buffer(DEBUG_USBREQ
, "brkchars", 6, buf
);
562 memcpy(cs
->hw
.usb
->bchars
, buf
, 6);
563 return usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 0x19, 0x41,
564 0, 0, &buf
, 6, 2000);
567 static int gigaset_freebcshw(struct bc_state
*bcs
)
573 /* Initialize the b-channel structure */
574 static int gigaset_initbcshw(struct bc_state
*bcs
)
581 static void gigaset_reinitbcshw(struct bc_state
*bcs
)
583 /* nothing to do for M10x */
586 static void gigaset_freecshw(struct cardstate
*cs
)
588 tasklet_kill(&cs
->write_tasklet
);
592 static int gigaset_initcshw(struct cardstate
*cs
)
594 struct usb_cardstate
*ucs
;
597 kmalloc(sizeof(struct usb_cardstate
), GFP_KERNEL
);
599 pr_err("out of memory\n");
607 ucs
->bchars
[4] = 0x11;
608 ucs
->bchars
[5] = 0x13;
609 ucs
->bulk_out_buffer
= NULL
;
610 ucs
->bulk_out_urb
= NULL
;
611 ucs
->read_urb
= NULL
;
612 tasklet_init(&cs
->write_tasklet
,
613 gigaset_modem_fill
, (unsigned long) cs
);
618 /* Send data from current skb to the device. */
619 static int write_modem(struct cardstate
*cs
)
623 struct bc_state
*bcs
= &cs
->bcs
[0]; /* only one channel */
624 struct usb_cardstate
*ucs
= cs
->hw
.usb
;
627 gig_dbg(DEBUG_OUTPUT
, "len: %d...", bcs
->tx_skb
->len
);
629 if (!bcs
->tx_skb
->len
) {
630 dev_kfree_skb_any(bcs
->tx_skb
);
635 /* Copy data to bulk out buffer and transmit data */
636 count
= min(bcs
->tx_skb
->len
, (unsigned) ucs
->bulk_out_size
);
637 skb_copy_from_linear_data(bcs
->tx_skb
, ucs
->bulk_out_buffer
, count
);
638 skb_pull(bcs
->tx_skb
, count
);
640 gig_dbg(DEBUG_OUTPUT
, "write_modem: send %d bytes", count
);
642 spin_lock_irqsave(&cs
->lock
, flags
);
644 usb_fill_bulk_urb(ucs
->bulk_out_urb
, ucs
->udev
,
645 usb_sndbulkpipe(ucs
->udev
,
646 ucs
->bulk_out_endpointAddr
&
648 ucs
->bulk_out_buffer
, count
,
649 gigaset_write_bulk_callback
, cs
);
650 ret
= usb_submit_urb(ucs
->bulk_out_urb
, GFP_ATOMIC
);
654 spin_unlock_irqrestore(&cs
->lock
, flags
);
657 dev_err(cs
->dev
, "could not submit urb (error %d)\n", -ret
);
661 if (!bcs
->tx_skb
->len
) {
662 /* skb sent completely */
663 gigaset_skb_sent(bcs
, bcs
->tx_skb
);
665 gig_dbg(DEBUG_INTR
, "kfree skb (Adr: %lx)!",
666 (unsigned long) bcs
->tx_skb
);
667 dev_kfree_skb_any(bcs
->tx_skb
);
674 static int gigaset_probe(struct usb_interface
*interface
,
675 const struct usb_device_id
*id
)
678 struct usb_device
*udev
= interface_to_usbdev(interface
);
679 struct usb_host_interface
*hostif
= interface
->cur_altsetting
;
680 struct cardstate
*cs
= NULL
;
681 struct usb_cardstate
*ucs
= NULL
;
682 struct usb_endpoint_descriptor
*endpoint
;
685 gig_dbg(DEBUG_ANY
, "%s: Check if device matches ...", __func__
);
687 /* See if the device offered us matches what we can accept */
688 if ((le16_to_cpu(udev
->descriptor
.idVendor
) != USB_M105_VENDOR_ID
) ||
689 (le16_to_cpu(udev
->descriptor
.idProduct
) != USB_M105_PRODUCT_ID
)) {
690 gig_dbg(DEBUG_ANY
, "device ID (0x%x, 0x%x) not for me - skip",
691 le16_to_cpu(udev
->descriptor
.idVendor
),
692 le16_to_cpu(udev
->descriptor
.idProduct
));
695 if (hostif
->desc
.bInterfaceNumber
!= 0) {
696 gig_dbg(DEBUG_ANY
, "interface %d not for me - skip",
697 hostif
->desc
.bInterfaceNumber
);
700 if (hostif
->desc
.bAlternateSetting
!= 0) {
701 dev_notice(&udev
->dev
, "unsupported altsetting %d - skip",
702 hostif
->desc
.bAlternateSetting
);
705 if (hostif
->desc
.bInterfaceClass
!= 255) {
706 dev_notice(&udev
->dev
, "unsupported interface class %d - skip",
707 hostif
->desc
.bInterfaceClass
);
711 dev_info(&udev
->dev
, "%s: Device matched ... !\n", __func__
);
713 /* allocate memory for our device state and intialize it */
714 cs
= gigaset_initcs(driver
, 1, 1, 0, cidmode
, GIGASET_MODULENAME
);
719 /* save off device structure ptrs for later use */
722 ucs
->interface
= interface
;
723 cs
->dev
= &interface
->dev
;
725 /* save address of controller structure */
726 usb_set_intfdata(interface
, cs
);
728 endpoint
= &hostif
->endpoint
[0].desc
;
730 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
731 ucs
->bulk_out_size
= buffer_size
;
732 ucs
->bulk_out_endpointAddr
= endpoint
->bEndpointAddress
;
733 ucs
->bulk_out_buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
734 if (!ucs
->bulk_out_buffer
) {
735 dev_err(cs
->dev
, "Couldn't allocate bulk_out_buffer\n");
740 ucs
->bulk_out_urb
= usb_alloc_urb(0, GFP_KERNEL
);
741 if (!ucs
->bulk_out_urb
) {
742 dev_err(cs
->dev
, "Couldn't allocate bulk_out_urb\n");
747 endpoint
= &hostif
->endpoint
[1].desc
;
751 ucs
->read_urb
= usb_alloc_urb(0, GFP_KERNEL
);
752 if (!ucs
->read_urb
) {
753 dev_err(cs
->dev
, "No free urbs available\n");
757 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
758 ucs
->rcvbuf_size
= buffer_size
;
759 ucs
->int_in_endpointAddr
= endpoint
->bEndpointAddress
;
760 ucs
->rcvbuf
= kmalloc(buffer_size
, GFP_KERNEL
);
762 dev_err(cs
->dev
, "Couldn't allocate rcvbuf\n");
766 /* Fill the interrupt urb and send it to the core */
767 usb_fill_int_urb(ucs
->read_urb
, udev
,
769 endpoint
->bEndpointAddress
& 0x0f),
770 ucs
->rcvbuf
, buffer_size
,
771 gigaset_read_int_callback
,
772 cs
, endpoint
->bInterval
);
774 retval
= usb_submit_urb(ucs
->read_urb
, GFP_KERNEL
);
776 dev_err(cs
->dev
, "Could not submit URB (error %d)\n", -retval
);
780 /* tell common part that the device is ready */
781 if (startmode
== SM_LOCKED
)
782 cs
->mstate
= MS_LOCKED
;
784 if (!gigaset_start(cs
)) {
785 tasklet_kill(&cs
->write_tasklet
);
792 usb_kill_urb(ucs
->read_urb
);
793 kfree(ucs
->bulk_out_buffer
);
794 usb_free_urb(ucs
->bulk_out_urb
);
796 usb_free_urb(ucs
->read_urb
);
797 usb_set_intfdata(interface
, NULL
);
798 ucs
->read_urb
= ucs
->bulk_out_urb
= NULL
;
799 ucs
->rcvbuf
= ucs
->bulk_out_buffer
= NULL
;
800 usb_put_dev(ucs
->udev
);
802 ucs
->interface
= NULL
;
807 static void gigaset_disconnect(struct usb_interface
*interface
)
809 struct cardstate
*cs
;
810 struct usb_cardstate
*ucs
;
812 cs
= usb_get_intfdata(interface
);
815 dev_info(cs
->dev
, "disconnecting Gigaset USB adapter\n");
817 usb_kill_urb(ucs
->read_urb
);
821 usb_set_intfdata(interface
, NULL
);
822 tasklet_kill(&cs
->write_tasklet
);
824 usb_kill_urb(ucs
->bulk_out_urb
);
826 kfree(ucs
->bulk_out_buffer
);
827 usb_free_urb(ucs
->bulk_out_urb
);
829 usb_free_urb(ucs
->read_urb
);
830 ucs
->read_urb
= ucs
->bulk_out_urb
= NULL
;
831 ucs
->rcvbuf
= ucs
->bulk_out_buffer
= NULL
;
833 usb_put_dev(ucs
->udev
);
834 ucs
->interface
= NULL
;
841 * This function is called before the USB connection is suspended or reset.
843 static int gigaset_suspend(struct usb_interface
*intf
, pm_message_t message
)
845 struct cardstate
*cs
= usb_get_intfdata(intf
);
848 cs
->connected
= 0; /* prevent rescheduling */
849 usb_kill_urb(cs
->hw
.usb
->read_urb
);
850 tasklet_kill(&cs
->write_tasklet
);
851 usb_kill_urb(cs
->hw
.usb
->bulk_out_urb
);
853 gig_dbg(DEBUG_SUSPEND
, "suspend complete");
858 * This function is called after the USB connection has been resumed or reset.
860 static int gigaset_resume(struct usb_interface
*intf
)
862 struct cardstate
*cs
= usb_get_intfdata(intf
);
865 /* resubmit interrupt URB */
867 rc
= usb_submit_urb(cs
->hw
.usb
->read_urb
, GFP_KERNEL
);
869 dev_err(cs
->dev
, "Could not submit read URB (error %d)\n", -rc
);
873 gig_dbg(DEBUG_SUSPEND
, "resume complete");
878 * This function is called before the USB connection is reset.
880 static int gigaset_pre_reset(struct usb_interface
*intf
)
882 /* same as suspend */
883 return gigaset_suspend(intf
, PMSG_ON
);
886 static const struct gigaset_ops ops
= {
889 gigaset_chars_in_buffer
,
891 gigaset_init_bchannel
,
892 gigaset_close_bchannel
,
898 gigaset_set_modem_ctrl
,
900 gigaset_set_line_ctrl
,
901 gigaset_m10x_send_skb
,
906 * This function is called while kernel-module is loaded
908 static int __init
usb_gigaset_init(void)
912 /* allocate memory for our driver state and intialize it */
913 driver
= gigaset_initdriver(GIGASET_MINOR
, GIGASET_MINORS
,
914 GIGASET_MODULENAME
, GIGASET_DEVNAME
,
919 /* register this driver with the USB subsystem */
920 result
= usb_register(&gigaset_usb_driver
);
922 pr_err("error %d registering USB driver\n", -result
);
926 pr_info(DRIVER_DESC
"\n");
931 gigaset_freedriver(driver
);
937 * This function is called while unloading the kernel-module
939 static void __exit
usb_gigaset_exit(void)
943 gigaset_blockdriver(driver
); /* => probe will fail
944 * => no gigaset_start any more
947 /* stop all connected devices */
948 for (i
= 0; i
< driver
->minors
; i
++)
949 gigaset_shutdown(driver
->cs
+ i
);
951 /* from now on, no isdn callback should be possible */
953 /* deregister this driver with the USB subsystem */
954 usb_deregister(&gigaset_usb_driver
);
955 /* this will call the disconnect-callback */
956 /* from now on, no disconnect/probe callback should be running */
958 gigaset_freedriver(driver
);
963 module_init(usb_gigaset_init
);
964 module_exit(usb_gigaset_exit
);
966 MODULE_AUTHOR(DRIVER_AUTHOR
);
967 MODULE_DESCRIPTION(DRIVER_DESC
);
969 MODULE_LICENSE("GPL");