GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / isdn / gigaset / usb-gigaset.c
blob2bd45bb6be5a491af04f551f23a2aef27ca5b855
1 /*
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 * =====================================================================
18 #include "gigaset.h"
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 /* length limit according to Siemens 3070usb-protokoll.doc ch. 2.1 */
43 #define IF_WRITEBUF 264
45 /* Values for the Gigaset M105 Data */
46 #define USB_M105_VENDOR_ID 0x0681
47 #define USB_M105_PRODUCT_ID 0x0009
49 /* table of devices that work with this driver */
50 static const struct usb_device_id gigaset_table[] = {
51 { USB_DEVICE(USB_M105_VENDOR_ID, USB_M105_PRODUCT_ID) },
52 { } /* Terminating entry */
55 MODULE_DEVICE_TABLE(usb, gigaset_table);
58 /* functions called if a device of this driver is connected/disconnected */
59 static int gigaset_probe(struct usb_interface *interface,
60 const struct usb_device_id *id);
61 static void gigaset_disconnect(struct usb_interface *interface);
63 /* functions called before/after suspend */
64 static int gigaset_suspend(struct usb_interface *intf, pm_message_t message);
65 static int gigaset_resume(struct usb_interface *intf);
66 static int gigaset_pre_reset(struct usb_interface *intf);
68 static struct gigaset_driver *driver;
70 /* usb specific object needed to register this driver with the usb subsystem */
71 static struct usb_driver gigaset_usb_driver = {
72 .name = GIGASET_MODULENAME,
73 .probe = gigaset_probe,
74 .disconnect = gigaset_disconnect,
75 .id_table = gigaset_table,
76 .suspend = gigaset_suspend,
77 .resume = gigaset_resume,
78 .reset_resume = gigaset_resume,
79 .pre_reset = gigaset_pre_reset,
80 .post_reset = gigaset_resume,
83 struct usb_cardstate {
84 struct usb_device *udev; /* usb device pointer */
85 struct usb_interface *interface; /* interface for this device */
86 int busy; /* bulk output in progress */
88 /* Output buffer */
89 unsigned char *bulk_out_buffer;
90 int bulk_out_size;
91 __u8 bulk_out_endpointAddr;
92 struct urb *bulk_out_urb;
94 /* Input buffer */
95 unsigned char *rcvbuf;
96 int rcvbuf_size;
97 struct urb *read_urb;
98 __u8 int_in_endpointAddr;
100 char bchars[6]; /* for request 0x19 */
103 static inline unsigned tiocm_to_gigaset(unsigned state)
105 return ((state & TIOCM_DTR) ? 1 : 0) | ((state & TIOCM_RTS) ? 2 : 0);
108 static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
109 unsigned new_state)
111 struct usb_device *udev = cs->hw.usb->udev;
112 unsigned mask, val;
113 int r;
115 mask = tiocm_to_gigaset(old_state ^ new_state);
116 val = tiocm_to_gigaset(new_state);
118 gig_dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask);
119 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 7, 0x41,
120 (val & 0xff) | ((mask & 0xff) << 8), 0,
121 NULL, 0, 2000 /* timeout? */);
122 if (r < 0)
123 return r;
124 return 0;
128 * Set M105 configuration value
129 * using undocumented device commands reverse engineered from USB traces
130 * of the Siemens Windows driver
132 static int set_value(struct cardstate *cs, u8 req, u16 val)
134 struct usb_device *udev = cs->hw.usb->udev;
135 int r, r2;
137 gig_dbg(DEBUG_USBREQ, "request %02x (%04x)",
138 (unsigned)req, (unsigned)val);
139 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x12, 0x41,
140 0xf /*?*/, 0, NULL, 0, 2000 /*?*/);
141 /* no idea what this does */
142 if (r < 0) {
143 dev_err(&udev->dev, "error %d on request 0x12\n", -r);
144 return r;
147 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), req, 0x41,
148 val, 0, NULL, 0, 2000 /*?*/);
149 if (r < 0)
150 dev_err(&udev->dev, "error %d on request 0x%02x\n",
151 -r, (unsigned)req);
153 r2 = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
154 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/);
155 if (r2 < 0)
156 dev_err(&udev->dev, "error %d on request 0x19\n", -r2);
158 return r < 0 ? r : (r2 < 0 ? r2 : 0);
162 * set the baud rate on the internal serial adapter
163 * using the undocumented parameter setting command
165 static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
167 u16 val;
168 u32 rate;
170 cflag &= CBAUD;
172 switch (cflag) {
173 case B300: rate = 300; break;
174 case B600: rate = 600; break;
175 case B1200: rate = 1200; break;
176 case B2400: rate = 2400; break;
177 case B4800: rate = 4800; break;
178 case B9600: rate = 9600; break;
179 case B19200: rate = 19200; break;
180 case B38400: rate = 38400; break;
181 case B57600: rate = 57600; break;
182 case B115200: rate = 115200; break;
183 default:
184 rate = 9600;
185 dev_err(cs->dev, "unsupported baudrate request 0x%x,"
186 " using default of B9600\n", cflag);
189 val = 0x383fff / rate + 1;
191 return set_value(cs, 1, val);
195 * set the line format on the internal serial adapter
196 * using the undocumented parameter setting command
198 static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
200 u16 val = 0;
202 /* set the parity */
203 if (cflag & PARENB)
204 val |= (cflag & PARODD) ? 0x10 : 0x20;
206 /* set the number of data bits */
207 switch (cflag & CSIZE) {
208 case CS5:
209 val |= 5 << 8; break;
210 case CS6:
211 val |= 6 << 8; break;
212 case CS7:
213 val |= 7 << 8; break;
214 case CS8:
215 val |= 8 << 8; break;
216 default:
217 dev_err(cs->dev, "CSIZE was not CS5-CS8, using default of 8\n");
218 val |= 8 << 8;
219 break;
222 /* set the number of stop bits */
223 if (cflag & CSTOPB) {
224 if ((cflag & CSIZE) == CS5)
225 val |= 1; /* 1.5 stop bits */
226 else
227 val |= 2; /* 2 stop bits */
230 return set_value(cs, 3, val);
234 /*============================================================================*/
235 static int gigaset_init_bchannel(struct bc_state *bcs)
237 /* nothing to do for M10x */
238 gigaset_bchannel_up(bcs);
239 return 0;
242 static int gigaset_close_bchannel(struct bc_state *bcs)
244 /* nothing to do for M10x */
245 gigaset_bchannel_down(bcs);
246 return 0;
249 static int write_modem(struct cardstate *cs);
250 static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb);
253 /* Write tasklet handler: Continue sending current skb, or send command, or
254 * start sending an skb from the send queue.
256 static void gigaset_modem_fill(unsigned long data)
258 struct cardstate *cs = (struct cardstate *) data;
259 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
260 struct cmdbuf_t *cb;
261 int again;
263 gig_dbg(DEBUG_OUTPUT, "modem_fill");
265 if (cs->hw.usb->busy) {
266 gig_dbg(DEBUG_OUTPUT, "modem_fill: busy");
267 return;
270 do {
271 again = 0;
272 if (!bcs->tx_skb) { /* no skb is being sent */
273 cb = cs->cmdbuf;
274 if (cb) { /* commands to send? */
275 gig_dbg(DEBUG_OUTPUT, "modem_fill: cb");
276 if (send_cb(cs, cb) < 0) {
277 gig_dbg(DEBUG_OUTPUT,
278 "modem_fill: send_cb failed");
279 again = 1; /* no callback will be
280 called! */
282 } else { /* skbs to send? */
283 bcs->tx_skb = skb_dequeue(&bcs->squeue);
284 if (bcs->tx_skb)
285 gig_dbg(DEBUG_INTR,
286 "Dequeued skb (Adr: %lx)!",
287 (unsigned long) bcs->tx_skb);
291 if (bcs->tx_skb) {
292 gig_dbg(DEBUG_OUTPUT, "modem_fill: tx_skb");
293 if (write_modem(cs) < 0) {
294 gig_dbg(DEBUG_OUTPUT,
295 "modem_fill: write_modem failed");
296 again = 1; /* no callback will be called! */
299 } while (again);
303 * Interrupt Input URB completion routine
305 static void gigaset_read_int_callback(struct urb *urb)
307 struct cardstate *cs = urb->context;
308 struct inbuf_t *inbuf = cs->inbuf;
309 int status = urb->status;
310 int r;
311 unsigned numbytes;
312 unsigned char *src;
313 unsigned long flags;
315 if (!status) {
316 numbytes = urb->actual_length;
318 if (numbytes) {
319 src = cs->hw.usb->rcvbuf;
320 if (unlikely(*src))
321 dev_warn(cs->dev,
322 "%s: There was no leading 0, but 0x%02x!\n",
323 __func__, (unsigned) *src);
324 ++src; /* skip leading 0x00 */
325 --numbytes;
326 if (gigaset_fill_inbuf(inbuf, src, numbytes)) {
327 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
328 gigaset_schedule_event(inbuf->cs);
330 } else
331 gig_dbg(DEBUG_INTR, "Received zero block length");
332 } else {
333 /* The urb might have been killed. */
334 gig_dbg(DEBUG_ANY, "%s - nonzero status received: %d",
335 __func__, status);
336 if (status == -ENOENT || status == -ESHUTDOWN)
337 /* killed or endpoint shutdown: don't resubmit */
338 return;
341 /* resubmit URB */
342 spin_lock_irqsave(&cs->lock, flags);
343 if (!cs->connected) {
344 spin_unlock_irqrestore(&cs->lock, flags);
345 pr_err("%s: disconnected\n", __func__);
346 return;
348 r = usb_submit_urb(urb, GFP_ATOMIC);
349 spin_unlock_irqrestore(&cs->lock, flags);
350 if (r)
351 dev_err(cs->dev, "error %d resubmitting URB\n", -r);
355 /* This callback routine is called when data was transmitted to the device. */
356 static void gigaset_write_bulk_callback(struct urb *urb)
358 struct cardstate *cs = urb->context;
359 int status = urb->status;
360 unsigned long flags;
362 switch (status) {
363 case 0: /* normal completion */
364 break;
365 case -ENOENT: /* killed */
366 gig_dbg(DEBUG_ANY, "%s: killed", __func__);
367 cs->hw.usb->busy = 0;
368 return;
369 default:
370 dev_err(cs->dev, "bulk transfer failed (status %d)\n",
371 -status);
372 /* That's all we can do. Communication problems
373 are handled by timeouts or network protocols. */
376 spin_lock_irqsave(&cs->lock, flags);
377 if (!cs->connected) {
378 pr_err("%s: disconnected\n", __func__);
379 } else {
380 cs->hw.usb->busy = 0;
381 tasklet_schedule(&cs->write_tasklet);
383 spin_unlock_irqrestore(&cs->lock, flags);
386 static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
388 struct cmdbuf_t *tcb;
389 unsigned long flags;
390 int count;
391 int status = -ENOENT;
392 struct usb_cardstate *ucs = cs->hw.usb;
394 do {
395 if (!cb->len) {
396 tcb = cb;
398 spin_lock_irqsave(&cs->cmdlock, flags);
399 cs->cmdbytes -= cs->curlen;
400 gig_dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left",
401 cs->curlen, cs->cmdbytes);
402 cs->cmdbuf = cb = cb->next;
403 if (cb) {
404 cb->prev = NULL;
405 cs->curlen = cb->len;
406 } else {
407 cs->lastcmdbuf = NULL;
408 cs->curlen = 0;
410 spin_unlock_irqrestore(&cs->cmdlock, flags);
412 if (tcb->wake_tasklet)
413 tasklet_schedule(tcb->wake_tasklet);
414 kfree(tcb);
416 if (cb) {
417 count = min(cb->len, ucs->bulk_out_size);
418 gig_dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
420 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
421 usb_sndbulkpipe(ucs->udev,
422 ucs->bulk_out_endpointAddr & 0x0f),
423 cb->buf + cb->offset, count,
424 gigaset_write_bulk_callback, cs);
426 cb->offset += count;
427 cb->len -= count;
428 ucs->busy = 1;
430 spin_lock_irqsave(&cs->lock, flags);
431 status = cs->connected ?
432 usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC) :
433 -ENODEV;
434 spin_unlock_irqrestore(&cs->lock, flags);
436 if (status) {
437 ucs->busy = 0;
438 dev_err(cs->dev,
439 "could not submit urb (error %d)\n",
440 -status);
441 cb->len = 0; /* skip urb => remove cb+wakeup
442 in next loop cycle */
445 } while (cb && status); /* next command on error */
447 return status;
450 /* Send command to device. */
451 static int gigaset_write_cmd(struct cardstate *cs, struct cmdbuf_t *cb)
453 unsigned long flags;
455 gigaset_dbg_buffer(cs->mstate != MS_LOCKED ?
456 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
457 "CMD Transmit", cb->len, cb->buf);
459 spin_lock_irqsave(&cs->cmdlock, flags);
460 cb->prev = cs->lastcmdbuf;
461 if (cs->lastcmdbuf)
462 cs->lastcmdbuf->next = cb;
463 else {
464 cs->cmdbuf = cb;
465 cs->curlen = cb->len;
467 cs->cmdbytes += cb->len;
468 cs->lastcmdbuf = cb;
469 spin_unlock_irqrestore(&cs->cmdlock, flags);
471 spin_lock_irqsave(&cs->lock, flags);
472 if (cs->connected)
473 tasklet_schedule(&cs->write_tasklet);
474 spin_unlock_irqrestore(&cs->lock, flags);
475 return cb->len;
478 static int gigaset_write_room(struct cardstate *cs)
480 unsigned bytes;
482 bytes = cs->cmdbytes;
483 return bytes < IF_WRITEBUF ? IF_WRITEBUF - bytes : 0;
486 static int gigaset_chars_in_buffer(struct cardstate *cs)
488 return cs->cmdbytes;
492 * set the break characters on the internal serial adapter
493 * using undocumented device commands reverse engineered from USB traces
494 * of the Siemens Windows driver
496 static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
498 struct usb_device *udev = cs->hw.usb->udev;
500 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
501 memcpy(cs->hw.usb->bchars, buf, 6);
502 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
503 0, 0, &buf, 6, 2000);
506 static int gigaset_freebcshw(struct bc_state *bcs)
508 /* unused */
509 return 1;
512 /* Initialize the b-channel structure */
513 static int gigaset_initbcshw(struct bc_state *bcs)
515 /* unused */
516 bcs->hw.usb = NULL;
517 return 1;
520 static void gigaset_reinitbcshw(struct bc_state *bcs)
522 /* nothing to do for M10x */
525 static void gigaset_freecshw(struct cardstate *cs)
527 tasklet_kill(&cs->write_tasklet);
528 kfree(cs->hw.usb);
531 static int gigaset_initcshw(struct cardstate *cs)
533 struct usb_cardstate *ucs;
535 cs->hw.usb = ucs =
536 kmalloc(sizeof(struct usb_cardstate), GFP_KERNEL);
537 if (!ucs) {
538 pr_err("out of memory\n");
539 return 0;
542 ucs->bchars[0] = 0;
543 ucs->bchars[1] = 0;
544 ucs->bchars[2] = 0;
545 ucs->bchars[3] = 0;
546 ucs->bchars[4] = 0x11;
547 ucs->bchars[5] = 0x13;
548 ucs->bulk_out_buffer = NULL;
549 ucs->bulk_out_urb = NULL;
550 ucs->read_urb = NULL;
551 tasklet_init(&cs->write_tasklet,
552 gigaset_modem_fill, (unsigned long) cs);
554 return 1;
557 /* Send data from current skb to the device. */
558 static int write_modem(struct cardstate *cs)
560 int ret = 0;
561 int count;
562 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
563 struct usb_cardstate *ucs = cs->hw.usb;
564 unsigned long flags;
566 gig_dbg(DEBUG_OUTPUT, "len: %d...", bcs->tx_skb->len);
568 if (!bcs->tx_skb->len) {
569 dev_kfree_skb_any(bcs->tx_skb);
570 bcs->tx_skb = NULL;
571 return -EINVAL;
574 /* Copy data to bulk out buffer and transmit data */
575 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
576 skb_copy_from_linear_data(bcs->tx_skb, ucs->bulk_out_buffer, count);
577 skb_pull(bcs->tx_skb, count);
578 ucs->busy = 1;
579 gig_dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count);
581 spin_lock_irqsave(&cs->lock, flags);
582 if (cs->connected) {
583 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
584 usb_sndbulkpipe(ucs->udev,
585 ucs->bulk_out_endpointAddr &
586 0x0f),
587 ucs->bulk_out_buffer, count,
588 gigaset_write_bulk_callback, cs);
589 ret = usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC);
590 } else {
591 ret = -ENODEV;
593 spin_unlock_irqrestore(&cs->lock, flags);
595 if (ret) {
596 dev_err(cs->dev, "could not submit urb (error %d)\n", -ret);
597 ucs->busy = 0;
600 if (!bcs->tx_skb->len) {
601 /* skb sent completely */
602 gigaset_skb_sent(bcs, bcs->tx_skb);
604 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
605 (unsigned long) bcs->tx_skb);
606 dev_kfree_skb_any(bcs->tx_skb);
607 bcs->tx_skb = NULL;
610 return ret;
613 static int gigaset_probe(struct usb_interface *interface,
614 const struct usb_device_id *id)
616 int retval;
617 struct usb_device *udev = interface_to_usbdev(interface);
618 struct usb_host_interface *hostif = interface->cur_altsetting;
619 struct cardstate *cs = NULL;
620 struct usb_cardstate *ucs = NULL;
621 struct usb_endpoint_descriptor *endpoint;
622 int buffer_size;
624 gig_dbg(DEBUG_ANY, "%s: Check if device matches ...", __func__);
626 /* See if the device offered us matches what we can accept */
627 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_M105_VENDOR_ID) ||
628 (le16_to_cpu(udev->descriptor.idProduct) != USB_M105_PRODUCT_ID)) {
629 gig_dbg(DEBUG_ANY, "device ID (0x%x, 0x%x) not for me - skip",
630 le16_to_cpu(udev->descriptor.idVendor),
631 le16_to_cpu(udev->descriptor.idProduct));
632 return -ENODEV;
634 if (hostif->desc.bInterfaceNumber != 0) {
635 gig_dbg(DEBUG_ANY, "interface %d not for me - skip",
636 hostif->desc.bInterfaceNumber);
637 return -ENODEV;
639 if (hostif->desc.bAlternateSetting != 0) {
640 dev_notice(&udev->dev, "unsupported altsetting %d - skip",
641 hostif->desc.bAlternateSetting);
642 return -ENODEV;
644 if (hostif->desc.bInterfaceClass != 255) {
645 dev_notice(&udev->dev, "unsupported interface class %d - skip",
646 hostif->desc.bInterfaceClass);
647 return -ENODEV;
650 dev_info(&udev->dev, "%s: Device matched ... !\n", __func__);
652 /* allocate memory for our device state and intialize it */
653 cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
654 if (!cs)
655 return -ENODEV;
656 ucs = cs->hw.usb;
658 /* save off device structure ptrs for later use */
659 usb_get_dev(udev);
660 ucs->udev = udev;
661 ucs->interface = interface;
662 cs->dev = &interface->dev;
664 /* save address of controller structure */
665 usb_set_intfdata(interface, cs);
667 endpoint = &hostif->endpoint[0].desc;
669 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
670 ucs->bulk_out_size = buffer_size;
671 ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress;
672 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
673 if (!ucs->bulk_out_buffer) {
674 dev_err(cs->dev, "Couldn't allocate bulk_out_buffer\n");
675 retval = -ENOMEM;
676 goto error;
679 ucs->bulk_out_urb = usb_alloc_urb(0, GFP_KERNEL);
680 if (!ucs->bulk_out_urb) {
681 dev_err(cs->dev, "Couldn't allocate bulk_out_urb\n");
682 retval = -ENOMEM;
683 goto error;
686 endpoint = &hostif->endpoint[1].desc;
688 ucs->busy = 0;
690 ucs->read_urb = usb_alloc_urb(0, GFP_KERNEL);
691 if (!ucs->read_urb) {
692 dev_err(cs->dev, "No free urbs available\n");
693 retval = -ENOMEM;
694 goto error;
696 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
697 ucs->rcvbuf_size = buffer_size;
698 ucs->int_in_endpointAddr = endpoint->bEndpointAddress;
699 ucs->rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
700 if (!ucs->rcvbuf) {
701 dev_err(cs->dev, "Couldn't allocate rcvbuf\n");
702 retval = -ENOMEM;
703 goto error;
705 /* Fill the interrupt urb and send it to the core */
706 usb_fill_int_urb(ucs->read_urb, udev,
707 usb_rcvintpipe(udev,
708 endpoint->bEndpointAddress & 0x0f),
709 ucs->rcvbuf, buffer_size,
710 gigaset_read_int_callback,
711 cs, endpoint->bInterval);
713 retval = usb_submit_urb(ucs->read_urb, GFP_KERNEL);
714 if (retval) {
715 dev_err(cs->dev, "Could not submit URB (error %d)\n", -retval);
716 goto error;
719 /* tell common part that the device is ready */
720 if (startmode == SM_LOCKED)
721 cs->mstate = MS_LOCKED;
723 if (!gigaset_start(cs)) {
724 tasklet_kill(&cs->write_tasklet);
725 retval = -ENODEV;
726 goto error;
728 return 0;
730 error:
731 usb_kill_urb(ucs->read_urb);
732 kfree(ucs->bulk_out_buffer);
733 usb_free_urb(ucs->bulk_out_urb);
734 kfree(ucs->rcvbuf);
735 usb_free_urb(ucs->read_urb);
736 usb_set_intfdata(interface, NULL);
737 ucs->read_urb = ucs->bulk_out_urb = NULL;
738 ucs->rcvbuf = ucs->bulk_out_buffer = NULL;
739 usb_put_dev(ucs->udev);
740 ucs->udev = NULL;
741 ucs->interface = NULL;
742 gigaset_freecs(cs);
743 return retval;
746 static void gigaset_disconnect(struct usb_interface *interface)
748 struct cardstate *cs;
749 struct usb_cardstate *ucs;
751 cs = usb_get_intfdata(interface);
752 ucs = cs->hw.usb;
754 dev_info(cs->dev, "disconnecting Gigaset USB adapter\n");
756 usb_kill_urb(ucs->read_urb);
758 gigaset_stop(cs);
760 usb_set_intfdata(interface, NULL);
761 tasklet_kill(&cs->write_tasklet);
763 usb_kill_urb(ucs->bulk_out_urb);
765 kfree(ucs->bulk_out_buffer);
766 usb_free_urb(ucs->bulk_out_urb);
767 kfree(ucs->rcvbuf);
768 usb_free_urb(ucs->read_urb);
769 ucs->read_urb = ucs->bulk_out_urb = NULL;
770 ucs->rcvbuf = ucs->bulk_out_buffer = NULL;
772 usb_put_dev(ucs->udev);
773 ucs->interface = NULL;
774 ucs->udev = NULL;
775 cs->dev = NULL;
776 gigaset_freecs(cs);
779 /* gigaset_suspend
780 * This function is called before the USB connection is suspended or reset.
782 static int gigaset_suspend(struct usb_interface *intf, pm_message_t message)
784 struct cardstate *cs = usb_get_intfdata(intf);
786 /* stop activity */
787 cs->connected = 0; /* prevent rescheduling */
788 usb_kill_urb(cs->hw.usb->read_urb);
789 tasklet_kill(&cs->write_tasklet);
790 usb_kill_urb(cs->hw.usb->bulk_out_urb);
792 gig_dbg(DEBUG_SUSPEND, "suspend complete");
793 return 0;
796 /* gigaset_resume
797 * This function is called after the USB connection has been resumed or reset.
799 static int gigaset_resume(struct usb_interface *intf)
801 struct cardstate *cs = usb_get_intfdata(intf);
802 int rc;
804 /* resubmit interrupt URB */
805 cs->connected = 1;
806 rc = usb_submit_urb(cs->hw.usb->read_urb, GFP_KERNEL);
807 if (rc) {
808 dev_err(cs->dev, "Could not submit read URB (error %d)\n", -rc);
809 return rc;
812 gig_dbg(DEBUG_SUSPEND, "resume complete");
813 return 0;
816 /* gigaset_pre_reset
817 * This function is called before the USB connection is reset.
819 static int gigaset_pre_reset(struct usb_interface *intf)
821 /* same as suspend */
822 return gigaset_suspend(intf, PMSG_ON);
825 static const struct gigaset_ops ops = {
826 gigaset_write_cmd,
827 gigaset_write_room,
828 gigaset_chars_in_buffer,
829 gigaset_brkchars,
830 gigaset_init_bchannel,
831 gigaset_close_bchannel,
832 gigaset_initbcshw,
833 gigaset_freebcshw,
834 gigaset_reinitbcshw,
835 gigaset_initcshw,
836 gigaset_freecshw,
837 gigaset_set_modem_ctrl,
838 gigaset_baud_rate,
839 gigaset_set_line_ctrl,
840 gigaset_m10x_send_skb,
841 gigaset_m10x_input,
845 * This function is called while kernel-module is loaded
847 static int __init usb_gigaset_init(void)
849 int result;
851 /* allocate memory for our driver state and intialize it */
852 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
853 GIGASET_MODULENAME, GIGASET_DEVNAME,
854 &ops, THIS_MODULE);
855 if (driver == NULL)
856 goto error;
858 /* register this driver with the USB subsystem */
859 result = usb_register(&gigaset_usb_driver);
860 if (result < 0) {
861 pr_err("error %d registering USB driver\n", -result);
862 goto error;
865 pr_info(DRIVER_DESC "\n");
866 return 0;
868 error:
869 if (driver)
870 gigaset_freedriver(driver);
871 driver = NULL;
872 return -1;
876 * This function is called while unloading the kernel-module
878 static void __exit usb_gigaset_exit(void)
880 int i;
882 gigaset_blockdriver(driver); /* => probe will fail
883 * => no gigaset_start any more
886 /* stop all connected devices */
887 for (i = 0; i < driver->minors; i++)
888 gigaset_shutdown(driver->cs + i);
890 /* from now on, no isdn callback should be possible */
892 /* deregister this driver with the USB subsystem */
893 usb_deregister(&gigaset_usb_driver);
894 /* this will call the disconnect-callback */
895 /* from now on, no disconnect/probe callback should be running */
897 gigaset_freedriver(driver);
898 driver = NULL;
902 module_init(usb_gigaset_init);
903 module_exit(usb_gigaset_exit);
905 MODULE_AUTHOR(DRIVER_AUTHOR);
906 MODULE_DESCRIPTION(DRIVER_DESC);
908 MODULE_LICENSE("GPL");