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 * =====================================================================
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 <Eilers.Stefan@epost.de>"
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_DEVFSNAME "gig/usb/"
45 #define GIGASET_DEVNAME "ttyGU"
47 #define IF_WRITEBUF 2000 //FIXME // WAKEUP_CHARS: 256
49 /* Values for the Gigaset M105 Data */
50 #define USB_M105_VENDOR_ID 0x0681
51 #define USB_M105_PRODUCT_ID 0x0009
53 /* table of devices that work with this driver */
54 static struct usb_device_id gigaset_table [] = {
55 { USB_DEVICE(USB_M105_VENDOR_ID, USB_M105_PRODUCT_ID) },
56 { } /* Terminating entry */
59 MODULE_DEVICE_TABLE(usb, gigaset_table);
62 * Control requests (empty fields: 00)
64 * RT|RQ|VALUE|INDEX|LEN |DATA
67 * Get flags (1 byte). Bits: 0=dtr,1=rts,3-7:?
69 * Get device information/status (llll: 0x200 and 0x40 seen).
70 * Real size: I only saw MIN(llll,0x64).
71 * Contents: seems to be always the same...
72 * offset 0x00: Length of this structure (0x64) (len: 1,2,3 bytes)
73 * offset 0x3c: String (16 bit chars): "MCCI USB Serial V2.0"
77 * Initialize/reset device ?
79 * ? (xx=00 or 01; 01 on start, 00 on close)
81 * Set/clear flags vv=value, mm=mask (see RQ 08)
83 * Used before the following configuration requests are issued
84 * (with xx=0x0f). I've seen other values<0xf, though.
86 * Set baud rate. xxxx=ceil(0x384000/rate)=trunc(0x383fff/rate)+1.
88 * Set byte size and parity. p: 0x20=even,0x10=odd,0x00=no parity
89 * [ 0x30: m, 0x40: s ]
90 * [s: 0: 1 stop bit; 1: 1.5; 2: 2]
91 * bb: bits/byte (seen 7 and 8)
92 * 41 13 -- -- -- -- 10 00 ww 00 00 00 xx 00 00 00 yy 00 00 00 zz 00 00 00
94 * Initialization: 01, 40, 00, 00
95 * Open device: 00 40, 00, 00
96 * yy and zz seem to be equal, either 0x00 or 0x0a
97 * (ww,xx) pairs seen: (00,00), (00,40), (01,40), (09,80), (19,80)
98 * 41 19 -- -- -- -- 06 00 00 00 00 xx 11 13
99 * Used after every "configuration sequence" (RQ 12, RQs 01/03/13).
100 * xx is usually 0x00 but was 0x7e before starting data transfer
101 * in unimodem mode. So, this might be an array of characters that need
102 * special treatment ("commit all bufferd data"?), 11=^Q, 13=^S.
104 * Unimodem mode: use "modprobe ppp_async flag_time=0" as the device _needs_ two
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 static struct gigaset_driver *driver = NULL;
113 static struct cardstate *cardstate = NULL;
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,
123 struct usb_cardstate {
124 struct usb_device *udev; /* usb device pointer */
125 struct usb_interface *interface; /* interface for this device */
126 atomic_t busy; /* bulk output in progress */
129 unsigned char *bulk_out_buffer; /* send buffer */
130 int bulk_out_size; /* send buffer size */
131 __u8 bulk_out_endpointAddr; /* bulk out endpoint */
132 struct urb *bulk_out_urb; /* bulk out urb */
135 int rcvbuf_size; /* rcv buffer */
136 struct urb *read_urb; /* rcv buffer size */
137 __u8 int_in_endpointAddr; /* int in endpoint */
139 char bchars[6]; /* request 0x19 */
142 struct usb_bc_state {};
144 static inline unsigned tiocm_to_gigaset(unsigned state)
146 return ((state & TIOCM_DTR) ? 1 : 0) | ((state & TIOCM_RTS) ? 2 : 0);
149 #ifdef CONFIG_GIGASET_UNDOCREQ
150 /* WARNING: EXPERIMENTAL! */
151 static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
157 mask = tiocm_to_gigaset(old_state ^ new_state);
158 val = tiocm_to_gigaset(new_state);
160 dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask);
161 // don't use this in an interrupt/BH
162 r = usb_control_msg(cs->hw.usb->udev,
163 usb_sndctrlpipe(cs->hw.usb->udev, 0), 7, 0x41,
164 (val & 0xff) | ((mask & 0xff) << 8), 0,
165 NULL, 0, 2000 /* timeout? */);
172 static int set_value(struct cardstate *cs, u8 req, u16 val)
176 dbg(DEBUG_USBREQ, "request %02x (%04x)", (unsigned)req, (unsigned)val);
177 r = usb_control_msg(cs->hw.usb->udev,
178 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x12, 0x41,
180 NULL, 0, 2000 /*?*/); /* no idea, what this does */
182 err("error %d on request 0x12", -r);
186 r = usb_control_msg(cs->hw.usb->udev,
187 usb_sndctrlpipe(cs->hw.usb->udev, 0), req, 0x41,
189 NULL, 0, 2000 /*?*/);
191 err("error %d on request 0x%02x", -r, (unsigned)req);
193 r2 = usb_control_msg(cs->hw.usb->udev,
194 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41,
195 0, 0, cs->hw.usb->bchars, 6, 2000 /*?*/);
197 err("error %d on request 0x19", -r2);
199 return r < 0 ? r : (r2 < 0 ? r2 : 0);
202 /* WARNING: HIGHLY EXPERIMENTAL! */
203 // don't use this in an interrupt/BH
204 static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
213 case B300: rate = 300; break;
214 case B600: rate = 600; break;
215 case B1200: rate = 1200; break;
216 case B2400: rate = 2400; break;
217 case B4800: rate = 4800; break;
218 case B9600: rate = 9600; break;
219 case B19200: rate = 19200; break;
220 case B38400: rate = 38400; break;
221 case B57600: rate = 57600; break;
222 case B115200: rate = 115200; break;
225 err("unsupported baudrate request 0x%x,"
226 " using default of B9600", cflag);
229 val = 0x383fff / rate + 1;
231 return set_value(cs, 1, val);
234 /* WARNING: HIGHLY EXPERIMENTAL! */
235 // don't use this in an interrupt/BH
236 static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
242 val |= (cflag & PARODD) ? 0x10 : 0x20;
244 /* set the number of data bits */
245 switch (cflag & CSIZE) {
247 val |= 5 << 8; break;
249 val |= 6 << 8; break;
251 val |= 7 << 8; break;
253 val |= 8 << 8; break;
255 err("CSIZE was not CS5-CS8, using default of 8");
260 /* set the number of stop bits */
261 if (cflag & CSTOPB) {
262 if ((cflag & CSIZE) == CS5)
263 val |= 1; /* 1.5 stop bits */ //FIXME is this okay?
265 val |= 2; /* 2 stop bits */
268 return set_value(cs, 3, val);
272 static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
278 static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
283 static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
290 /*================================================================================================================*/
291 static int gigaset_init_bchannel(struct bc_state *bcs)
293 /* nothing to do for M10x */
294 gigaset_bchannel_up(bcs);
298 static int gigaset_close_bchannel(struct bc_state *bcs)
300 /* nothing to do for M10x */
301 gigaset_bchannel_down(bcs);
305 static int write_modem(struct cardstate *cs);
306 static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb);
309 /* Write tasklet handler: Continue sending current skb, or send command, or
310 * start sending an skb from the send queue.
312 static void gigaset_modem_fill(unsigned long data)
314 struct cardstate *cs = (struct cardstate *) data;
315 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
320 dbg(DEBUG_OUTPUT, "modem_fill");
322 if (atomic_read(&cs->hw.usb->busy)) {
323 dbg(DEBUG_OUTPUT, "modem_fill: busy");
329 if (!bcs->tx_skb) { /* no skb is being sent */
330 spin_lock_irqsave(&cs->cmdlock, flags);
332 spin_unlock_irqrestore(&cs->cmdlock, flags);
333 if (cb) { /* commands to send? */
334 dbg(DEBUG_OUTPUT, "modem_fill: cb");
335 if (send_cb(cs, cb) < 0) {
337 "modem_fill: send_cb failed");
338 again = 1; /* no callback will be
341 } else { /* skbs to send? */
342 bcs->tx_skb = skb_dequeue(&bcs->squeue);
345 "Dequeued skb (Adr: %lx)!",
346 (unsigned long) bcs->tx_skb);
351 dbg(DEBUG_OUTPUT, "modem_fill: tx_skb");
352 if (write_modem(cs) < 0) {
354 "modem_fill: write_modem failed");
355 // FIXME should we tell the LL?
356 again = 1; /* no callback will be called! */
363 * gigaset_read_int_callback
365 * It is called if the data was received from the device.
367 static void gigaset_read_int_callback(struct urb *urb, struct pt_regs *regs)
371 struct cardstate *cs;
374 struct inbuf_t *inbuf;
377 inbuf = (struct inbuf_t *) urb->context;
380 IFNULLGOTO(cs, exit);
381 IFNULLGOTO(cardstate, exit);
383 if (!atomic_read(&cs->connected)) {
384 err("%s: disconnected", __func__);
389 numbytes = urb->actual_length;
394 warn("%s: There was no leading 0, but 0x%02x!",
395 __func__, (unsigned) *src);
396 ++src; /* skip leading 0x00 */
398 if (gigaset_fill_inbuf(inbuf, src, numbytes)) {
399 dbg(DEBUG_INTR, "%s-->BH", __func__);
400 gigaset_schedule_event(inbuf->cs);
403 dbg(DEBUG_INTR, "Received zero block length");
406 /* The urb might have been killed. */
407 dbg(DEBUG_ANY, "%s - nonzero read bulk status received: %d",
408 __func__, urb->status);
409 if (urb->status != -ENOENT) /* not killed */
414 r = usb_submit_urb(urb, SLAB_ATOMIC);
416 err("error %d when resubmitting urb.", -r);
421 /* This callback routine is called when data was transmitted to the device. */
422 static void gigaset_write_bulk_callback(struct urb *urb, struct pt_regs *regs)
424 struct cardstate *cs = (struct cardstate *) urb->context;
427 #ifdef CONFIG_GIGASET_DEBUG
428 if (!atomic_read(&cs->connected)) {
429 err("%s:not connected", __func__);
434 err("bulk transfer failed (status %d)", -urb->status);
435 /* That's all we can do. Communication problems
436 are handeled by timeouts or network protocols */
438 atomic_set(&cs->hw.usb->busy, 0);
439 tasklet_schedule(&cs->write_tasklet);
442 static int send_cb(struct cardstate *cs, struct cmdbuf_t *cb)
444 struct cmdbuf_t *tcb;
447 int status = -ENOENT; // FIXME
448 struct usb_cardstate *ucs = cs->hw.usb;
454 spin_lock_irqsave(&cs->cmdlock, flags);
455 cs->cmdbytes -= cs->curlen;
456 dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left",
457 cs->curlen, cs->cmdbytes);
458 cs->cmdbuf = cb = cb->next;
461 cs->curlen = cb->len;
463 cs->lastcmdbuf = NULL;
466 spin_unlock_irqrestore(&cs->cmdlock, flags);
468 if (tcb->wake_tasklet)
469 tasklet_schedule(tcb->wake_tasklet);
473 count = min(cb->len, ucs->bulk_out_size);
474 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
475 usb_sndbulkpipe(ucs->udev,
476 ucs->bulk_out_endpointAddr & 0x0f),
477 cb->buf + cb->offset, count,
478 gigaset_write_bulk_callback, cs);
482 atomic_set(&ucs->busy, 1);
483 dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
485 status = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
487 atomic_set(&ucs->busy, 0);
488 err("could not submit urb (error %d).",
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(atomic_read(&cs->mstate) != MS_LOCKED ?
507 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
508 "CMD Transmit", len, buf, 0);
510 if (!atomic_read(&cs->connected)) {
511 err("%s: not connected", __func__);
518 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
519 err("%s: out of memory", __func__);
523 memcpy(cb->buf, buf, len);
527 cb->wake_tasklet = wake_tasklet;
529 spin_lock_irqsave(&cs->cmdlock, flags);
530 cb->prev = cs->lastcmdbuf;
532 cs->lastcmdbuf->next = cb;
539 spin_unlock_irqrestore(&cs->cmdlock, flags);
541 tasklet_schedule(&cs->write_tasklet);
545 static int gigaset_write_room(struct cardstate *cs)
550 spin_lock_irqsave(&cs->cmdlock, flags);
551 bytes = cs->cmdbytes;
552 spin_unlock_irqrestore(&cs->cmdlock, flags);
554 return bytes < IF_WRITEBUF ? IF_WRITEBUF - bytes : 0;
557 static int gigaset_chars_in_buffer(struct cardstate *cs)
562 static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
564 #ifdef CONFIG_GIGASET_UNDOCREQ
565 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf, 0);
566 memcpy(cs->hw.usb->bchars, buf, 6);
567 return usb_control_msg(cs->hw.usb->udev,
568 usb_sndctrlpipe(cs->hw.usb->udev, 0), 0x19, 0x41,
569 0, 0, &buf, 6, 2000);
575 static int gigaset_freebcshw(struct bc_state *bcs)
584 /* Initialize the b-channel structure */
585 static int gigaset_initbcshw(struct bc_state *bcs)
587 bcs->hw.usb = kmalloc(sizeof(struct usb_bc_state), GFP_KERNEL);
594 static void gigaset_reinitbcshw(struct bc_state *bcs)
598 static void gigaset_freecshw(struct cardstate *cs)
600 tasklet_kill(&cs->write_tasklet);
604 static int gigaset_initcshw(struct cardstate *cs)
606 struct usb_cardstate *ucs;
609 kmalloc(sizeof(struct usb_cardstate), GFP_KERNEL);
617 ucs->bchars[4] = 0x11;
618 ucs->bchars[5] = 0x13;
619 ucs->bulk_out_buffer = NULL;
620 ucs->bulk_out_urb = NULL;
621 //ucs->urb_cmd_out = NULL;
622 ucs->read_urb = NULL;
623 tasklet_init(&cs->write_tasklet,
624 &gigaset_modem_fill, (unsigned long) cs);
629 /* Send data from current skb to the device. */
630 static int write_modem(struct cardstate *cs)
634 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
635 struct usb_cardstate *ucs = cs->hw.usb;
637 IFNULLRETVAL(bcs->tx_skb, -EINVAL);
639 dbg(DEBUG_WRITE, "len: %d...", bcs->tx_skb->len);
642 IFNULLGOTO(ucs->bulk_out_buffer, error);
643 IFNULLGOTO(ucs->bulk_out_urb, error);
646 if (!bcs->tx_skb->len) {
647 dev_kfree_skb_any(bcs->tx_skb);
652 /* Copy data to bulk out buffer and // FIXME copying not necessary
655 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
656 memcpy(ucs->bulk_out_buffer, bcs->tx_skb->data, count);
657 skb_pull(bcs->tx_skb, count);
659 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
660 usb_sndbulkpipe(ucs->udev,
661 ucs->bulk_out_endpointAddr & 0x0f),
662 ucs->bulk_out_buffer, count,
663 gigaset_write_bulk_callback, cs);
664 atomic_set(&ucs->busy, 1);
665 dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count);
667 ret = usb_submit_urb(ucs->bulk_out_urb, SLAB_ATOMIC);
669 err("could not submit urb (error %d).", -ret);
670 atomic_set(&ucs->busy, 0);
672 if (!bcs->tx_skb->len) {
673 /* skb sent completely */
674 gigaset_skb_sent(bcs, bcs->tx_skb); //FIXME also, when ret<0?
677 "kfree skb (Adr: %lx)!", (unsigned long) bcs->tx_skb);
678 dev_kfree_skb_any(bcs->tx_skb);
684 dev_kfree_skb_any(bcs->tx_skb);
690 static int gigaset_probe(struct usb_interface *interface,
691 const struct usb_device_id *id)
694 struct usb_device *udev = interface_to_usbdev(interface);
696 struct usb_host_interface *hostif;
697 struct cardstate *cs = NULL;
698 struct usb_cardstate *ucs = NULL;
699 struct usb_endpoint_descriptor *endpoint;
703 info("%s: Check if device matches .. (Vendor: 0x%x, Product: 0x%x)",
704 __func__, le16_to_cpu(udev->descriptor.idVendor),
705 le16_to_cpu(udev->descriptor.idProduct));
707 retval = -ENODEV; //FIXME
709 /* See if the device offered us matches what we can accept */
710 if ((le16_to_cpu(udev->descriptor.idVendor != USB_M105_VENDOR_ID)) ||
711 (le16_to_cpu(udev->descriptor.idProduct != USB_M105_PRODUCT_ID)))
714 /* this starts to become ascii art... */
715 hostif = interface->cur_altsetting;
716 alt = hostif->desc.bAlternateSetting;
717 ifnum = hostif->desc.bInterfaceNumber; // FIXME ?
719 if (alt != 0 || ifnum != 0) {
720 warn("ifnum %d, alt %d", ifnum, alt);
724 /* Reject application specific intefaces
727 if (hostif->desc.bInterfaceClass != 255) {
728 info("%s: Device matched, but iface_desc[%d]->bInterfaceClass==%d !",
729 __func__, ifnum, hostif->desc.bInterfaceClass);
733 info("%s: Device matched ... !", __func__);
735 cs = gigaset_getunassignedcs(driver);
737 warn("No free cardstate!");
742 endpoint = &hostif->endpoint[0].desc;
744 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
745 ucs->bulk_out_size = buffer_size;
746 ucs->bulk_out_endpointAddr = endpoint->bEndpointAddress;
747 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
748 if (!ucs->bulk_out_buffer) {
749 err("Couldn't allocate bulk_out_buffer");
754 ucs->bulk_out_urb = usb_alloc_urb(0, SLAB_KERNEL);
755 if (!ucs->bulk_out_urb) {
756 err("Couldn't allocate bulk_out_buffer");
761 endpoint = &hostif->endpoint[1].desc;
763 atomic_set(&ucs->busy, 0);
765 ucs->interface = interface;
767 ucs->read_urb = usb_alloc_urb(0, SLAB_KERNEL);
768 if (!ucs->read_urb) {
769 err("No free urbs available");
773 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
774 ucs->rcvbuf_size = buffer_size;
775 ucs->int_in_endpointAddr = endpoint->bEndpointAddress;
776 cs->inbuf[0].rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
777 if (!cs->inbuf[0].rcvbuf) {
778 err("Couldn't allocate rcvbuf");
782 /* Fill the interrupt urb and send it to the core */
783 usb_fill_int_urb(ucs->read_urb, udev,
785 endpoint->bEndpointAddress & 0x0f),
786 cs->inbuf[0].rcvbuf, buffer_size,
787 gigaset_read_int_callback,
788 cs->inbuf + 0, endpoint->bInterval);
790 retval = usb_submit_urb(ucs->read_urb, SLAB_KERNEL);
792 err("Could not submit URB!");
796 /* tell common part that the device is ready */
797 if (startmode == SM_LOCKED)
798 atomic_set(&cs->mstate, MS_LOCKED);
799 if (!gigaset_start(cs)) {
800 tasklet_kill(&cs->write_tasklet);
801 retval = -ENODEV; //FIXME
805 /* save address of controller structure */
806 usb_set_intfdata(interface, cs);
808 /* set up device sysfs */
809 gigaset_init_dev_sysfs(interface);
814 usb_kill_urb(ucs->read_urb);
815 kfree(ucs->bulk_out_buffer);
816 if (ucs->bulk_out_urb != NULL)
817 usb_free_urb(ucs->bulk_out_urb);
818 kfree(cs->inbuf[0].rcvbuf);
819 if (ucs->read_urb != NULL)
820 usb_free_urb(ucs->read_urb);
821 ucs->read_urb = ucs->bulk_out_urb = NULL;
822 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
823 gigaset_unassign(cs);
830 static void gigaset_disconnect(struct usb_interface *interface)
832 struct cardstate *cs;
833 struct usb_cardstate *ucs;
835 cs = usb_get_intfdata(interface);
837 /* clear device sysfs */
838 gigaset_free_dev_sysfs(interface);
840 usb_set_intfdata(interface, NULL);
842 usb_kill_urb(ucs->read_urb);
843 //info("GigaSet USB device #%d will be disconnected", minor);
847 tasklet_kill(&cs->write_tasklet);
849 usb_kill_urb(ucs->bulk_out_urb); /* FIXME: only if active? */
851 kfree(ucs->bulk_out_buffer);
852 if (ucs->bulk_out_urb != NULL)
853 usb_free_urb(ucs->bulk_out_urb);
854 kfree(cs->inbuf[0].rcvbuf);
855 if (ucs->read_urb != NULL)
856 usb_free_urb(ucs->read_urb);
857 ucs->read_urb = ucs->bulk_out_urb = NULL;
858 cs->inbuf[0].rcvbuf = ucs->bulk_out_buffer = NULL;
860 gigaset_unassign(cs);
863 static struct gigaset_ops ops = {
866 gigaset_chars_in_buffer,
868 gigaset_init_bchannel,
869 gigaset_close_bchannel,
875 gigaset_set_modem_ctrl,
877 gigaset_set_line_ctrl,
878 gigaset_m10x_send_skb,
884 * This function is called while kernel-module is loaded
886 static int __init usb_gigaset_init(void)
890 /* allocate memory for our driver state and intialize it */
891 if ((driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
892 GIGASET_MODULENAME, GIGASET_DEVNAME,
893 GIGASET_DEVFSNAME, &ops,
894 THIS_MODULE)) == NULL)
897 /* allocate memory for our device state and intialize it */
898 cardstate = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
902 /* register this driver with the USB subsystem */
903 result = usb_register(&gigaset_usb_driver);
905 err("usb_gigaset: usb_register failed (error %d)",
914 error: if (cardstate)
915 gigaset_freecs(cardstate);
918 gigaset_freedriver(driver);
926 * This function is called while unloading the kernel-module
928 static void __exit usb_gigaset_exit(void)
930 gigaset_blockdriver(driver); /* => probe will fail
931 * => no gigaset_start any more
934 gigaset_shutdown(cardstate);
935 /* from now on, no isdn callback should be possible */
937 /* deregister this driver with the USB subsystem */
938 usb_deregister(&gigaset_usb_driver);
939 /* this will call the disconnect-callback */
940 /* from now on, no disconnect/probe callback should be running */
942 gigaset_freecs(cardstate);
944 gigaset_freedriver(driver);
949 module_init(usb_gigaset_init);
950 module_exit(usb_gigaset_exit);
952 MODULE_AUTHOR(DRIVER_AUTHOR);
953 MODULE_DESCRIPTION(DRIVER_DESC);
955 MODULE_LICENSE("GPL");