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 * =====================================================================
20 #include <linux/errno.h>
21 #include <linux/init.h>
22 #include <linux/slab.h>
23 #include <linux/usb.h>
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
27 /* Version Information */
28 #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
29 #define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
31 /* Module parameters */
33 static int startmode
= SM_ISDN
;
34 static int cidmode
= 1;
36 module_param(startmode
, int, S_IRUGO
);
37 module_param(cidmode
, int, S_IRUGO
);
38 MODULE_PARM_DESC(startmode
, "start in isdn4linux mode");
39 MODULE_PARM_DESC(cidmode
, "Call-ID mode");
41 #define GIGASET_MINORS 1
42 #define GIGASET_MINOR 8
43 #define GIGASET_MODULENAME "usb_gigaset"
44 #define GIGASET_DEVNAME "ttyGU"
46 #define IF_WRITEBUF 2000 /* arbitrary limit */
48 /* Values for the Gigaset M105 Data */
49 #define USB_M105_VENDOR_ID 0x0681
50 #define USB_M105_PRODUCT_ID 0x0009
52 /* table of devices that work with this driver */
53 static const struct usb_device_id gigaset_table
[] = {
54 { USB_DEVICE(USB_M105_VENDOR_ID
, USB_M105_PRODUCT_ID
) },
55 { } /* Terminating entry */
58 MODULE_DEVICE_TABLE(usb
, gigaset_table
);
61 * Control requests (empty fields: 00)
63 * RT|RQ|VALUE|INDEX|LEN |DATA
66 * Get flags (1 byte). Bits: 0=dtr,1=rts,3-7:?
68 * Get device information/status (llll: 0x200 and 0x40 seen).
69 * Real size: I only saw MIN(llll,0x64).
70 * Contents: seems to be always the same...
71 * offset 0x00: Length of this structure (0x64) (len: 1,2,3 bytes)
72 * offset 0x3c: String (16 bit chars): "MCCI USB Serial V2.0"
76 * Initialize/reset device ?
78 * ? (xx=00 or 01; 01 on start, 00 on close)
80 * Set/clear flags vv=value, mm=mask (see RQ 08)
82 * Used before the following configuration requests are issued
83 * (with xx=0x0f). I've seen other values<0xf, though.
85 * Set baud rate. xxxx=ceil(0x384000/rate)=trunc(0x383fff/rate)+1.
87 * Set byte size and parity. p: 0x20=even,0x10=odd,0x00=no parity
88 * [ 0x30: m, 0x40: s ]
89 * [s: 0: 1 stop bit; 1: 1.5; 2: 2]
90 * bb: bits/byte (seen 7 and 8)
91 * 41 13 -- -- -- -- 10 00 ww 00 00 00 xx 00 00 00 yy 00 00 00 zz 00 00 00
93 * Initialization: 01, 40, 00, 00
94 * Open device: 00 40, 00, 00
95 * yy and zz seem to be equal, either 0x00 or 0x0a
96 * (ww,xx) pairs seen: (00,00), (00,40), (01,40), (09,80), (19,80)
97 * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13
98 * Used after every "configuration sequence" (RQ 12, RQs 01/03/13).
99 * xx is usually 0x00 but was 0x7e before starting data transfer
100 * in unimodem mode. So, this might be an array of characters that
101 * need special treatment ("commit all bufferd data"?), 11=^Q, 13=^S.
103 * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two
107 /* functions called if a device of this driver is connected/disconnected */
108 static int gigaset_probe(struct usb_interface
*interface
,
109 const struct usb_device_id
*id
);
110 static void gigaset_disconnect(struct usb_interface
*interface
);
112 /* functions called before/after suspend */
113 static int gigaset_suspend(struct usb_interface
*intf
, pm_message_t message
);
114 static int gigaset_resume(struct usb_interface
*intf
);
115 static int gigaset_pre_reset(struct usb_interface
*intf
);
117 static struct gigaset_driver
*driver
;
119 /* usb specific object needed to register this driver with the usb subsystem */
120 static struct usb_driver gigaset_usb_driver
= {
121 .name
= GIGASET_MODULENAME
,
122 .probe
= gigaset_probe
,
123 .disconnect
= gigaset_disconnect
,
124 .id_table
= gigaset_table
,
125 .suspend
= gigaset_suspend
,
126 .resume
= gigaset_resume
,
127 .reset_resume
= gigaset_resume
,
128 .pre_reset
= gigaset_pre_reset
,
129 .post_reset
= gigaset_resume
,
132 struct usb_cardstate
{
133 struct usb_device
*udev
; /* usb device pointer */
134 struct usb_interface
*interface
; /* interface for this device */
135 int busy
; /* bulk output in progress */
138 unsigned char *bulk_out_buffer
;
140 __u8 bulk_out_endpointAddr
;
141 struct urb
*bulk_out_urb
;
144 unsigned char *rcvbuf
;
146 struct urb
*read_urb
;
147 __u8 int_in_endpointAddr
;
149 char bchars
[6]; /* for request 0x19 */
152 static inline unsigned tiocm_to_gigaset(unsigned state
)
154 return ((state
& TIOCM_DTR
) ? 1 : 0) | ((state
& TIOCM_RTS
) ? 2 : 0);
157 static int gigaset_set_modem_ctrl(struct cardstate
*cs
, unsigned old_state
,
160 struct usb_device
*udev
= cs
->hw
.usb
->udev
;
164 mask
= tiocm_to_gigaset(old_state
^ new_state
);
165 val
= tiocm_to_gigaset(new_state
);
167 gig_dbg(DEBUG_USBREQ
, "set flags 0x%02x with mask 0x%02x", val
, mask
);
168 r
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 7, 0x41,
169 (val
& 0xff) | ((mask
& 0xff) << 8), 0,
170 NULL
, 0, 2000 /* timeout? */);
177 * Set M105 configuration value
178 * using undocumented device commands reverse engineered from USB traces
179 * of the Siemens Windows driver
181 static int set_value(struct cardstate
*cs
, u8 req
, u16 val
)
183 struct usb_device
*udev
= cs
->hw
.usb
->udev
;
186 gig_dbg(DEBUG_USBREQ
, "request %02x (%04x)",
187 (unsigned)req
, (unsigned)val
);
188 r
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 0x12, 0x41,
189 0xf /*?*/, 0, NULL
, 0, 2000 /*?*/);
190 /* no idea what this does */
192 dev_err(&udev
->dev
, "error %d on request 0x12\n", -r
);
196 r
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), req
, 0x41,
197 val
, 0, NULL
, 0, 2000 /*?*/);
199 dev_err(&udev
->dev
, "error %d on request 0x%02x\n",
202 r2
= usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 0x19, 0x41,
203 0, 0, cs
->hw
.usb
->bchars
, 6, 2000 /*?*/);
205 dev_err(&udev
->dev
, "error %d on request 0x19\n", -r2
);
207 return r
< 0 ? r
: (r2
< 0 ? r2
: 0);
211 * set the baud rate on the internal serial adapter
212 * using the undocumented parameter setting command
214 static int gigaset_baud_rate(struct cardstate
*cs
, unsigned cflag
)
222 case B300
: rate
= 300; break;
223 case B600
: rate
= 600; break;
224 case B1200
: rate
= 1200; break;
225 case B2400
: rate
= 2400; break;
226 case B4800
: rate
= 4800; break;
227 case B9600
: rate
= 9600; break;
228 case B19200
: rate
= 19200; break;
229 case B38400
: rate
= 38400; break;
230 case B57600
: rate
= 57600; break;
231 case B115200
: rate
= 115200; break;
234 dev_err(cs
->dev
, "unsupported baudrate request 0x%x,"
235 " using default of B9600\n", cflag
);
238 val
= 0x383fff / rate
+ 1;
240 return set_value(cs
, 1, val
);
244 * set the line format on the internal serial adapter
245 * using the undocumented parameter setting command
247 static int gigaset_set_line_ctrl(struct cardstate
*cs
, unsigned cflag
)
253 val
|= (cflag
& PARODD
) ? 0x10 : 0x20;
255 /* set the number of data bits */
256 switch (cflag
& CSIZE
) {
258 val
|= 5 << 8; break;
260 val
|= 6 << 8; break;
262 val
|= 7 << 8; break;
264 val
|= 8 << 8; break;
266 dev_err(cs
->dev
, "CSIZE was not CS5-CS8, using default of 8\n");
271 /* set the number of stop bits */
272 if (cflag
& CSTOPB
) {
273 if ((cflag
& CSIZE
) == CS5
)
274 val
|= 1; /* 1.5 stop bits */
276 val
|= 2; /* 2 stop bits */
279 return set_value(cs
, 3, val
);
283 /*============================================================================*/
284 static int gigaset_init_bchannel(struct bc_state
*bcs
)
286 /* nothing to do for M10x */
287 gigaset_bchannel_up(bcs
);
291 static int gigaset_close_bchannel(struct bc_state
*bcs
)
293 /* nothing to do for M10x */
294 gigaset_bchannel_down(bcs
);
298 static int write_modem(struct cardstate
*cs
);
299 static int send_cb(struct cardstate
*cs
, struct cmdbuf_t
*cb
);
302 /* Write tasklet handler: Continue sending current skb, or send command, or
303 * start sending an skb from the send queue.
305 static void gigaset_modem_fill(unsigned long data
)
307 struct cardstate
*cs
= (struct cardstate
*) data
;
308 struct bc_state
*bcs
= &cs
->bcs
[0]; /* only one channel */
312 gig_dbg(DEBUG_OUTPUT
, "modem_fill");
314 if (cs
->hw
.usb
->busy
) {
315 gig_dbg(DEBUG_OUTPUT
, "modem_fill: busy");
321 if (!bcs
->tx_skb
) { /* no skb is being sent */
323 if (cb
) { /* commands to send? */
324 gig_dbg(DEBUG_OUTPUT
, "modem_fill: cb");
325 if (send_cb(cs
, cb
) < 0) {
326 gig_dbg(DEBUG_OUTPUT
,
327 "modem_fill: send_cb failed");
328 again
= 1; /* no callback will be
331 } else { /* skbs to send? */
332 bcs
->tx_skb
= skb_dequeue(&bcs
->squeue
);
335 "Dequeued skb (Adr: %lx)!",
336 (unsigned long) bcs
->tx_skb
);
341 gig_dbg(DEBUG_OUTPUT
, "modem_fill: tx_skb");
342 if (write_modem(cs
) < 0) {
343 gig_dbg(DEBUG_OUTPUT
,
344 "modem_fill: write_modem failed");
345 again
= 1; /* no callback will be called! */
352 * Interrupt Input URB completion routine
354 static void gigaset_read_int_callback(struct urb
*urb
)
356 struct cardstate
*cs
= urb
->context
;
357 struct inbuf_t
*inbuf
= cs
->inbuf
;
358 int status
= urb
->status
;
365 numbytes
= urb
->actual_length
;
368 src
= cs
->hw
.usb
->rcvbuf
;
371 "%s: There was no leading 0, but 0x%02x!\n",
372 __func__
, (unsigned) *src
);
373 ++src
; /* skip leading 0x00 */
375 if (gigaset_fill_inbuf(inbuf
, src
, numbytes
)) {
376 gig_dbg(DEBUG_INTR
, "%s-->BH", __func__
);
377 gigaset_schedule_event(inbuf
->cs
);
380 gig_dbg(DEBUG_INTR
, "Received zero block length");
382 /* The urb might have been killed. */
383 gig_dbg(DEBUG_ANY
, "%s - nonzero status received: %d",
385 if (status
== -ENOENT
|| status
== -ESHUTDOWN
)
386 /* killed or endpoint shutdown: don't resubmit */
391 spin_lock_irqsave(&cs
->lock
, flags
);
392 if (!cs
->connected
) {
393 spin_unlock_irqrestore(&cs
->lock
, flags
);
394 pr_err("%s: disconnected\n", __func__
);
397 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
398 spin_unlock_irqrestore(&cs
->lock
, flags
);
400 dev_err(cs
->dev
, "error %d resubmitting URB\n", -r
);
404 /* This callback routine is called when data was transmitted to the device. */
405 static void gigaset_write_bulk_callback(struct urb
*urb
)
407 struct cardstate
*cs
= urb
->context
;
408 int status
= urb
->status
;
412 case 0: /* normal completion */
414 case -ENOENT
: /* killed */
415 gig_dbg(DEBUG_ANY
, "%s: killed", __func__
);
416 cs
->hw
.usb
->busy
= 0;
419 dev_err(cs
->dev
, "bulk transfer failed (status %d)\n",
421 /* That's all we can do. Communication problems
422 are handled by timeouts or network protocols. */
425 spin_lock_irqsave(&cs
->lock
, flags
);
426 if (!cs
->connected
) {
427 pr_err("%s: disconnected\n", __func__
);
429 cs
->hw
.usb
->busy
= 0;
430 tasklet_schedule(&cs
->write_tasklet
);
432 spin_unlock_irqrestore(&cs
->lock
, flags
);
435 static int send_cb(struct cardstate
*cs
, struct cmdbuf_t
*cb
)
437 struct cmdbuf_t
*tcb
;
440 int status
= -ENOENT
;
441 struct usb_cardstate
*ucs
= cs
->hw
.usb
;
447 spin_lock_irqsave(&cs
->cmdlock
, flags
);
448 cs
->cmdbytes
-= cs
->curlen
;
449 gig_dbg(DEBUG_OUTPUT
, "send_cb: sent %u bytes, %u left",
450 cs
->curlen
, cs
->cmdbytes
);
451 cs
->cmdbuf
= cb
= cb
->next
;
454 cs
->curlen
= cb
->len
;
456 cs
->lastcmdbuf
= NULL
;
459 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
461 if (tcb
->wake_tasklet
)
462 tasklet_schedule(tcb
->wake_tasklet
);
466 count
= min(cb
->len
, ucs
->bulk_out_size
);
467 gig_dbg(DEBUG_OUTPUT
, "send_cb: send %d bytes", count
);
469 usb_fill_bulk_urb(ucs
->bulk_out_urb
, ucs
->udev
,
470 usb_sndbulkpipe(ucs
->udev
,
471 ucs
->bulk_out_endpointAddr
& 0x0f),
472 cb
->buf
+ cb
->offset
, count
,
473 gigaset_write_bulk_callback
, cs
);
479 spin_lock_irqsave(&cs
->lock
, flags
);
480 status
= cs
->connected
?
481 usb_submit_urb(ucs
->bulk_out_urb
, GFP_ATOMIC
) :
483 spin_unlock_irqrestore(&cs
->lock
, flags
);
488 "could not submit urb (error %d)\n",
490 cb
->len
= 0; /* skip urb => remove cb+wakeup
491 in next loop cycle */
494 } while (cb
&& status
); /* next command on error */
499 /* Send command to device. */
500 static int gigaset_write_cmd(struct cardstate
*cs
, const unsigned char *buf
,
501 int len
, struct tasklet_struct
*wake_tasklet
)
506 gigaset_dbg_buffer(cs
->mstate
!= MS_LOCKED
?
507 DEBUG_TRANSCMD
: DEBUG_LOCKCMD
,
508 "CMD Transmit", len
, buf
);
512 cb
= kmalloc(sizeof(struct cmdbuf_t
) + len
, GFP_ATOMIC
);
514 dev_err(cs
->dev
, "%s: out of memory\n", __func__
);
518 memcpy(cb
->buf
, buf
, len
);
522 cb
->wake_tasklet
= wake_tasklet
;
524 spin_lock_irqsave(&cs
->cmdlock
, flags
);
525 cb
->prev
= cs
->lastcmdbuf
;
527 cs
->lastcmdbuf
->next
= cb
;
534 spin_unlock_irqrestore(&cs
->cmdlock
, flags
);
536 spin_lock_irqsave(&cs
->lock
, flags
);
538 tasklet_schedule(&cs
->write_tasklet
);
539 spin_unlock_irqrestore(&cs
->lock
, flags
);
543 static int gigaset_write_room(struct cardstate
*cs
)
547 bytes
= cs
->cmdbytes
;
548 return bytes
< IF_WRITEBUF
? IF_WRITEBUF
- bytes
: 0;
551 static int gigaset_chars_in_buffer(struct cardstate
*cs
)
557 * set the break characters on the internal serial adapter
558 * using undocumented device commands reverse engineered from USB traces
559 * of the Siemens Windows driver
561 static int gigaset_brkchars(struct cardstate
*cs
, const unsigned char buf
[6])
563 struct usb_device
*udev
= cs
->hw
.usb
->udev
;
565 gigaset_dbg_buffer(DEBUG_USBREQ
, "brkchars", 6, buf
);
566 memcpy(cs
->hw
.usb
->bchars
, buf
, 6);
567 return usb_control_msg(udev
, usb_sndctrlpipe(udev
, 0), 0x19, 0x41,
568 0, 0, &buf
, 6, 2000);
571 static int gigaset_freebcshw(struct bc_state
*bcs
)
577 /* Initialize the b-channel structure */
578 static int gigaset_initbcshw(struct bc_state
*bcs
)
585 static void gigaset_reinitbcshw(struct bc_state
*bcs
)
587 /* nothing to do for M10x */
590 static void gigaset_freecshw(struct cardstate
*cs
)
592 tasklet_kill(&cs
->write_tasklet
);
596 static int gigaset_initcshw(struct cardstate
*cs
)
598 struct usb_cardstate
*ucs
;
601 kmalloc(sizeof(struct usb_cardstate
), GFP_KERNEL
);
603 pr_err("out of memory\n");
611 ucs
->bchars
[4] = 0x11;
612 ucs
->bchars
[5] = 0x13;
613 ucs
->bulk_out_buffer
= NULL
;
614 ucs
->bulk_out_urb
= NULL
;
615 ucs
->read_urb
= NULL
;
616 tasklet_init(&cs
->write_tasklet
,
617 gigaset_modem_fill
, (unsigned long) cs
);
622 /* Send data from current skb to the device. */
623 static int write_modem(struct cardstate
*cs
)
627 struct bc_state
*bcs
= &cs
->bcs
[0]; /* only one channel */
628 struct usb_cardstate
*ucs
= cs
->hw
.usb
;
631 gig_dbg(DEBUG_WRITE
, "len: %d...", bcs
->tx_skb
->len
);
633 if (!bcs
->tx_skb
->len
) {
634 dev_kfree_skb_any(bcs
->tx_skb
);
639 /* Copy data to bulk out buffer and transmit data */
640 count
= min(bcs
->tx_skb
->len
, (unsigned) ucs
->bulk_out_size
);
641 skb_copy_from_linear_data(bcs
->tx_skb
, ucs
->bulk_out_buffer
, count
);
642 skb_pull(bcs
->tx_skb
, count
);
644 gig_dbg(DEBUG_OUTPUT
, "write_modem: send %d bytes", count
);
646 spin_lock_irqsave(&cs
->lock
, flags
);
648 usb_fill_bulk_urb(ucs
->bulk_out_urb
, ucs
->udev
,
649 usb_sndbulkpipe(ucs
->udev
,
650 ucs
->bulk_out_endpointAddr
&
652 ucs
->bulk_out_buffer
, count
,
653 gigaset_write_bulk_callback
, cs
);
654 ret
= usb_submit_urb(ucs
->bulk_out_urb
, GFP_ATOMIC
);
658 spin_unlock_irqrestore(&cs
->lock
, flags
);
661 dev_err(cs
->dev
, "could not submit urb (error %d)\n", -ret
);
665 if (!bcs
->tx_skb
->len
) {
666 /* skb sent completely */
667 gigaset_skb_sent(bcs
, bcs
->tx_skb
);
669 gig_dbg(DEBUG_INTR
, "kfree skb (Adr: %lx)!",
670 (unsigned long) bcs
->tx_skb
);
671 dev_kfree_skb_any(bcs
->tx_skb
);
678 static int gigaset_probe(struct usb_interface
*interface
,
679 const struct usb_device_id
*id
)
682 struct usb_device
*udev
= interface_to_usbdev(interface
);
683 struct usb_host_interface
*hostif
= interface
->cur_altsetting
;
684 struct cardstate
*cs
= NULL
;
685 struct usb_cardstate
*ucs
= NULL
;
686 struct usb_endpoint_descriptor
*endpoint
;
689 gig_dbg(DEBUG_ANY
, "%s: Check if device matches ...", __func__
);
691 /* See if the device offered us matches what we can accept */
692 if ((le16_to_cpu(udev
->descriptor
.idVendor
) != USB_M105_VENDOR_ID
) ||
693 (le16_to_cpu(udev
->descriptor
.idProduct
) != USB_M105_PRODUCT_ID
)) {
694 gig_dbg(DEBUG_ANY
, "device ID (0x%x, 0x%x) not for me - skip",
695 le16_to_cpu(udev
->descriptor
.idVendor
),
696 le16_to_cpu(udev
->descriptor
.idProduct
));
699 if (hostif
->desc
.bInterfaceNumber
!= 0) {
700 gig_dbg(DEBUG_ANY
, "interface %d not for me - skip",
701 hostif
->desc
.bInterfaceNumber
);
704 if (hostif
->desc
.bAlternateSetting
!= 0) {
705 dev_notice(&udev
->dev
, "unsupported altsetting %d - skip",
706 hostif
->desc
.bAlternateSetting
);
709 if (hostif
->desc
.bInterfaceClass
!= 255) {
710 dev_notice(&udev
->dev
, "unsupported interface class %d - skip",
711 hostif
->desc
.bInterfaceClass
);
715 dev_info(&udev
->dev
, "%s: Device matched ... !\n", __func__
);
717 /* allocate memory for our device state and intialize it */
718 cs
= gigaset_initcs(driver
, 1, 1, 0, cidmode
, GIGASET_MODULENAME
);
723 /* save off device structure ptrs for later use */
726 ucs
->interface
= interface
;
727 cs
->dev
= &interface
->dev
;
729 /* save address of controller structure */
730 usb_set_intfdata(interface
, cs
);
732 endpoint
= &hostif
->endpoint
[0].desc
;
734 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
735 ucs
->bulk_out_size
= buffer_size
;
736 ucs
->bulk_out_endpointAddr
= endpoint
->bEndpointAddress
;
737 ucs
->bulk_out_buffer
= kmalloc(buffer_size
, GFP_KERNEL
);
738 if (!ucs
->bulk_out_buffer
) {
739 dev_err(cs
->dev
, "Couldn't allocate bulk_out_buffer\n");
744 ucs
->bulk_out_urb
= usb_alloc_urb(0, GFP_KERNEL
);
745 if (!ucs
->bulk_out_urb
) {
746 dev_err(cs
->dev
, "Couldn't allocate bulk_out_urb\n");
751 endpoint
= &hostif
->endpoint
[1].desc
;
755 ucs
->read_urb
= usb_alloc_urb(0, GFP_KERNEL
);
756 if (!ucs
->read_urb
) {
757 dev_err(cs
->dev
, "No free urbs available\n");
761 buffer_size
= le16_to_cpu(endpoint
->wMaxPacketSize
);
762 ucs
->rcvbuf_size
= buffer_size
;
763 ucs
->int_in_endpointAddr
= endpoint
->bEndpointAddress
;
764 ucs
->rcvbuf
= kmalloc(buffer_size
, GFP_KERNEL
);
766 dev_err(cs
->dev
, "Couldn't allocate rcvbuf\n");
770 /* Fill the interrupt urb and send it to the core */
771 usb_fill_int_urb(ucs
->read_urb
, udev
,
773 endpoint
->bEndpointAddress
& 0x0f),
774 ucs
->rcvbuf
, buffer_size
,
775 gigaset_read_int_callback
,
776 cs
, endpoint
->bInterval
);
778 retval
= usb_submit_urb(ucs
->read_urb
, GFP_KERNEL
);
780 dev_err(cs
->dev
, "Could not submit URB (error %d)\n", -retval
);
784 /* tell common part that the device is ready */
785 if (startmode
== SM_LOCKED
)
786 cs
->mstate
= MS_LOCKED
;
788 if (!gigaset_start(cs
)) {
789 tasklet_kill(&cs
->write_tasklet
);
796 usb_kill_urb(ucs
->read_urb
);
797 kfree(ucs
->bulk_out_buffer
);
798 usb_free_urb(ucs
->bulk_out_urb
);
800 usb_free_urb(ucs
->read_urb
);
801 usb_set_intfdata(interface
, NULL
);
802 ucs
->read_urb
= ucs
->bulk_out_urb
= NULL
;
803 ucs
->rcvbuf
= ucs
->bulk_out_buffer
= NULL
;
804 usb_put_dev(ucs
->udev
);
806 ucs
->interface
= NULL
;
811 static void gigaset_disconnect(struct usb_interface
*interface
)
813 struct cardstate
*cs
;
814 struct usb_cardstate
*ucs
;
816 cs
= usb_get_intfdata(interface
);
819 dev_info(cs
->dev
, "disconnecting Gigaset USB adapter\n");
821 usb_kill_urb(ucs
->read_urb
);
825 usb_set_intfdata(interface
, NULL
);
826 tasklet_kill(&cs
->write_tasklet
);
828 usb_kill_urb(ucs
->bulk_out_urb
);
830 kfree(ucs
->bulk_out_buffer
);
831 usb_free_urb(ucs
->bulk_out_urb
);
833 usb_free_urb(ucs
->read_urb
);
834 ucs
->read_urb
= ucs
->bulk_out_urb
= NULL
;
835 ucs
->rcvbuf
= ucs
->bulk_out_buffer
= NULL
;
837 usb_put_dev(ucs
->udev
);
838 ucs
->interface
= NULL
;
845 * This function is called before the USB connection is suspended or reset.
847 static int gigaset_suspend(struct usb_interface
*intf
, pm_message_t message
)
849 struct cardstate
*cs
= usb_get_intfdata(intf
);
852 cs
->connected
= 0; /* prevent rescheduling */
853 usb_kill_urb(cs
->hw
.usb
->read_urb
);
854 tasklet_kill(&cs
->write_tasklet
);
855 usb_kill_urb(cs
->hw
.usb
->bulk_out_urb
);
857 gig_dbg(DEBUG_SUSPEND
, "suspend complete");
862 * This function is called after the USB connection has been resumed or reset.
864 static int gigaset_resume(struct usb_interface
*intf
)
866 struct cardstate
*cs
= usb_get_intfdata(intf
);
869 /* resubmit interrupt URB */
871 rc
= usb_submit_urb(cs
->hw
.usb
->read_urb
, GFP_KERNEL
);
873 dev_err(cs
->dev
, "Could not submit read URB (error %d)\n", -rc
);
877 gig_dbg(DEBUG_SUSPEND
, "resume complete");
882 * This function is called before the USB connection is reset.
884 static int gigaset_pre_reset(struct usb_interface
*intf
)
886 /* same as suspend */
887 return gigaset_suspend(intf
, PMSG_ON
);
890 static const struct gigaset_ops ops
= {
893 gigaset_chars_in_buffer
,
895 gigaset_init_bchannel
,
896 gigaset_close_bchannel
,
902 gigaset_set_modem_ctrl
,
904 gigaset_set_line_ctrl
,
905 gigaset_m10x_send_skb
,
910 * This function is called while kernel-module is loaded
912 static int __init
usb_gigaset_init(void)
916 /* allocate memory for our driver state and intialize it */
917 driver
= gigaset_initdriver(GIGASET_MINOR
, GIGASET_MINORS
,
918 GIGASET_MODULENAME
, GIGASET_DEVNAME
,
923 /* register this driver with the USB subsystem */
924 result
= usb_register(&gigaset_usb_driver
);
926 pr_err("error %d registering USB driver\n", -result
);
930 pr_info(DRIVER_DESC
"\n");
935 gigaset_freedriver(driver
);
941 * This function is called while unloading the kernel-module
943 static void __exit
usb_gigaset_exit(void)
947 gigaset_blockdriver(driver
); /* => probe will fail
948 * => no gigaset_start any more
951 /* stop all connected devices */
952 for (i
= 0; i
< driver
->minors
; i
++)
953 gigaset_shutdown(driver
->cs
+ i
);
955 /* from now on, no isdn callback should be possible */
957 /* deregister this driver with the USB subsystem */
958 usb_deregister(&gigaset_usb_driver
);
959 /* this will call the disconnect-callback */
960 /* from now on, no disconnect/probe callback should be running */
962 gigaset_freedriver(driver
);
967 module_init(usb_gigaset_init
);
968 module_exit(usb_gigaset_exit
);
970 MODULE_AUTHOR(DRIVER_AUTHOR
);
971 MODULE_DESCRIPTION(DRIVER_DESC
);
973 MODULE_LICENSE("GPL");