This source file includes following definitions.
- tiocm_to_gigaset
- gigaset_set_modem_ctrl
- set_value
- gigaset_baud_rate
- gigaset_set_line_ctrl
- gigaset_init_bchannel
- gigaset_close_bchannel
- gigaset_modem_fill
- gigaset_read_int_callback
- gigaset_write_bulk_callback
- send_cb
- gigaset_write_cmd
- gigaset_write_room
- gigaset_chars_in_buffer
- gigaset_brkchars
- gigaset_freebcshw
- gigaset_initbcshw
- gigaset_reinitbcshw
- gigaset_freecshw
- gigaset_initcshw
- write_modem
- gigaset_probe
- gigaset_disconnect
- gigaset_suspend
- gigaset_resume
- gigaset_pre_reset
- usb_gigaset_init
- usb_gigaset_exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 #include "gigaset.h"
16 #include <linux/usb.h>
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19
20
21 #define DRIVER_AUTHOR "Hansjoerg Lipp <hjlipp@web.de>, Stefan Eilers"
22 #define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
23
24
25
26 static int startmode = SM_ISDN;
27 static int cidmode = 1;
28
29 module_param(startmode, int, S_IRUGO);
30 module_param(cidmode, int, S_IRUGO);
31 MODULE_PARM_DESC(startmode, "start in isdn4linux mode");
32 MODULE_PARM_DESC(cidmode, "Call-ID mode");
33
34 #define GIGASET_MINORS 1
35 #define GIGASET_MINOR 8
36 #define GIGASET_MODULENAME "usb_gigaset"
37 #define GIGASET_DEVNAME "ttyGU"
38
39
40 #define IF_WRITEBUF 264
41
42
43 #define USB_M105_VENDOR_ID 0x0681
44 #define USB_M105_PRODUCT_ID 0x0009
45
46
47 static const struct usb_device_id gigaset_table[] = {
48 { USB_DEVICE(USB_M105_VENDOR_ID, USB_M105_PRODUCT_ID) },
49 { }
50 };
51
52 MODULE_DEVICE_TABLE(usb, gigaset_table);
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 static int gigaset_probe(struct usb_interface *interface,
103 const struct usb_device_id *id);
104 static void gigaset_disconnect(struct usb_interface *interface);
105
106
107 static int gigaset_suspend(struct usb_interface *intf, pm_message_t message);
108 static int gigaset_resume(struct usb_interface *intf);
109 static int gigaset_pre_reset(struct usb_interface *intf);
110
111 static struct gigaset_driver *driver;
112
113
114 static struct usb_driver gigaset_usb_driver = {
115 .name = GIGASET_MODULENAME,
116 .probe = gigaset_probe,
117 .disconnect = gigaset_disconnect,
118 .id_table = gigaset_table,
119 .suspend = gigaset_suspend,
120 .resume = gigaset_resume,
121 .reset_resume = gigaset_resume,
122 .pre_reset = gigaset_pre_reset,
123 .post_reset = gigaset_resume,
124 .disable_hub_initiated_lpm = 1,
125 };
126
127 struct usb_cardstate {
128 struct usb_device *udev;
129 struct usb_interface *interface;
130 int busy;
131
132
133 unsigned char *bulk_out_buffer;
134 int bulk_out_size;
135 int bulk_out_epnum;
136 struct urb *bulk_out_urb;
137
138
139 unsigned char *rcvbuf;
140 int rcvbuf_size;
141 struct urb *read_urb;
142
143 char bchars[6];
144 };
145
146 static inline unsigned tiocm_to_gigaset(unsigned state)
147 {
148 return ((state & TIOCM_DTR) ? 1 : 0) | ((state & TIOCM_RTS) ? 2 : 0);
149 }
150
151 static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state,
152 unsigned new_state)
153 {
154 struct usb_device *udev = cs->hw.usb->udev;
155 unsigned mask, val;
156 int r;
157
158 mask = tiocm_to_gigaset(old_state ^ new_state);
159 val = tiocm_to_gigaset(new_state);
160
161 gig_dbg(DEBUG_USBREQ, "set flags 0x%02x with mask 0x%02x", val, mask);
162 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 7, 0x41,
163 (val & 0xff) | ((mask & 0xff) << 8), 0,
164 NULL, 0, 2000 );
165 if (r < 0)
166 return r;
167 return 0;
168 }
169
170
171
172
173
174
175 static int set_value(struct cardstate *cs, u8 req, u16 val)
176 {
177 struct usb_device *udev = cs->hw.usb->udev;
178 int r, r2;
179
180 gig_dbg(DEBUG_USBREQ, "request %02x (%04x)",
181 (unsigned)req, (unsigned)val);
182 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x12, 0x41,
183 0xf , 0, NULL, 0, 2000 );
184
185 if (r < 0) {
186 dev_err(&udev->dev, "error %d on request 0x12\n", -r);
187 return r;
188 }
189
190 r = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), req, 0x41,
191 val, 0, NULL, 0, 2000 );
192 if (r < 0)
193 dev_err(&udev->dev, "error %d on request 0x%02x\n",
194 -r, (unsigned)req);
195
196 r2 = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
197 0, 0, cs->hw.usb->bchars, 6, 2000 );
198 if (r2 < 0)
199 dev_err(&udev->dev, "error %d on request 0x19\n", -r2);
200
201 return r < 0 ? r : (r2 < 0 ? r2 : 0);
202 }
203
204
205
206
207
208 static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
209 {
210 u16 val;
211 u32 rate;
212
213 cflag &= CBAUD;
214
215 switch (cflag) {
216 case B300: rate = 300; break;
217 case B600: rate = 600; break;
218 case B1200: rate = 1200; break;
219 case B2400: rate = 2400; break;
220 case B4800: rate = 4800; break;
221 case B9600: rate = 9600; break;
222 case B19200: rate = 19200; break;
223 case B38400: rate = 38400; break;
224 case B57600: rate = 57600; break;
225 case B115200: rate = 115200; break;
226 default:
227 rate = 9600;
228 dev_err(cs->dev, "unsupported baudrate request 0x%x,"
229 " using default of B9600\n", cflag);
230 }
231
232 val = 0x383fff / rate + 1;
233
234 return set_value(cs, 1, val);
235 }
236
237
238
239
240
241 static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
242 {
243 u16 val = 0;
244
245
246 if (cflag & PARENB)
247 val |= (cflag & PARODD) ? 0x10 : 0x20;
248
249
250 switch (cflag & CSIZE) {
251 case CS5:
252 val |= 5 << 8; break;
253 case CS6:
254 val |= 6 << 8; break;
255 case CS7:
256 val |= 7 << 8; break;
257 case CS8:
258 val |= 8 << 8; break;
259 default:
260 dev_err(cs->dev, "CSIZE was not CS5-CS8, using default of 8\n");
261 val |= 8 << 8;
262 break;
263 }
264
265
266 if (cflag & CSTOPB) {
267 if ((cflag & CSIZE) == CS5)
268 val |= 1;
269 else
270 val |= 2;
271 }
272
273 return set_value(cs, 3, val);
274 }
275
276
277
278 static int gigaset_init_bchannel(struct bc_state *bcs)
279 {
280
281 gigaset_bchannel_up(bcs);
282 return 0;
283 }
284
285 static int gigaset_close_bchannel(struct bc_state *bcs)
286 {
287
288 gigaset_bchannel_down(bcs);
289 return 0;
290 }
291
292 static int write_modem(struct cardstate *cs);
293 static int send_cb(struct cardstate *cs);
294
295
296
297
298
299 static void gigaset_modem_fill(unsigned long data)
300 {
301 struct cardstate *cs = (struct cardstate *) data;
302 struct bc_state *bcs = &cs->bcs[0];
303
304 gig_dbg(DEBUG_OUTPUT, "modem_fill");
305
306 if (cs->hw.usb->busy) {
307 gig_dbg(DEBUG_OUTPUT, "modem_fill: busy");
308 return;
309 }
310
311 again:
312 if (!bcs->tx_skb) {
313 if (cs->cmdbuf) {
314 gig_dbg(DEBUG_OUTPUT, "modem_fill: cb");
315 if (send_cb(cs) < 0) {
316 gig_dbg(DEBUG_OUTPUT,
317 "modem_fill: send_cb failed");
318 goto again;
319 }
320 return;
321 }
322
323
324 bcs->tx_skb = skb_dequeue(&bcs->squeue);
325 if (!bcs->tx_skb)
326 return;
327
328 gig_dbg(DEBUG_INTR, "Dequeued skb (Adr: %lx)!",
329 (unsigned long) bcs->tx_skb);
330 }
331
332 gig_dbg(DEBUG_OUTPUT, "modem_fill: tx_skb");
333 if (write_modem(cs) < 0) {
334 gig_dbg(DEBUG_OUTPUT, "modem_fill: write_modem failed");
335 goto again;
336 }
337 }
338
339
340
341
342 static void gigaset_read_int_callback(struct urb *urb)
343 {
344 struct cardstate *cs = urb->context;
345 struct inbuf_t *inbuf = cs->inbuf;
346 int status = urb->status;
347 int r;
348 unsigned numbytes;
349 unsigned char *src;
350 unsigned long flags;
351
352 if (!status) {
353 numbytes = urb->actual_length;
354
355 if (numbytes) {
356 src = cs->hw.usb->rcvbuf;
357 if (unlikely(*src))
358 dev_warn(cs->dev,
359 "%s: There was no leading 0, but 0x%02x!\n",
360 __func__, (unsigned) *src);
361 ++src;
362 --numbytes;
363 if (gigaset_fill_inbuf(inbuf, src, numbytes)) {
364 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
365 gigaset_schedule_event(inbuf->cs);
366 }
367 } else
368 gig_dbg(DEBUG_INTR, "Received zero block length");
369 } else {
370
371 gig_dbg(DEBUG_ANY, "%s - nonzero status received: %d",
372 __func__, status);
373 if (status == -ENOENT || status == -ESHUTDOWN)
374
375 return;
376 }
377
378
379 spin_lock_irqsave(&cs->lock, flags);
380 if (!cs->connected) {
381 spin_unlock_irqrestore(&cs->lock, flags);
382 pr_err("%s: disconnected\n", __func__);
383 return;
384 }
385 r = usb_submit_urb(urb, GFP_ATOMIC);
386 spin_unlock_irqrestore(&cs->lock, flags);
387 if (r)
388 dev_err(cs->dev, "error %d resubmitting URB\n", -r);
389 }
390
391
392
393 static void gigaset_write_bulk_callback(struct urb *urb)
394 {
395 struct cardstate *cs = urb->context;
396 int status = urb->status;
397 unsigned long flags;
398
399 switch (status) {
400 case 0:
401 break;
402 case -ENOENT:
403 gig_dbg(DEBUG_ANY, "%s: killed", __func__);
404 cs->hw.usb->busy = 0;
405 return;
406 default:
407 dev_err(cs->dev, "bulk transfer failed (status %d)\n",
408 -status);
409
410
411 }
412
413 spin_lock_irqsave(&cs->lock, flags);
414 if (!cs->connected) {
415 pr_err("%s: disconnected\n", __func__);
416 } else {
417 cs->hw.usb->busy = 0;
418 tasklet_schedule(&cs->write_tasklet);
419 }
420 spin_unlock_irqrestore(&cs->lock, flags);
421 }
422
423 static int send_cb(struct cardstate *cs)
424 {
425 struct cmdbuf_t *cb = cs->cmdbuf;
426 unsigned long flags;
427 int count;
428 int status = -ENOENT;
429 struct usb_cardstate *ucs = cs->hw.usb;
430
431 do {
432 if (!cb->len) {
433 spin_lock_irqsave(&cs->cmdlock, flags);
434 cs->cmdbytes -= cs->curlen;
435 gig_dbg(DEBUG_OUTPUT, "send_cb: sent %u bytes, %u left",
436 cs->curlen, cs->cmdbytes);
437 cs->cmdbuf = cb->next;
438 if (cs->cmdbuf) {
439 cs->cmdbuf->prev = NULL;
440 cs->curlen = cs->cmdbuf->len;
441 } else {
442 cs->lastcmdbuf = NULL;
443 cs->curlen = 0;
444 }
445 spin_unlock_irqrestore(&cs->cmdlock, flags);
446
447 if (cb->wake_tasklet)
448 tasklet_schedule(cb->wake_tasklet);
449 kfree(cb);
450
451 cb = cs->cmdbuf;
452 }
453
454 if (cb) {
455 count = min(cb->len, ucs->bulk_out_size);
456 gig_dbg(DEBUG_OUTPUT, "send_cb: send %d bytes", count);
457
458 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
459 usb_sndbulkpipe(ucs->udev,
460 ucs->bulk_out_epnum),
461 cb->buf + cb->offset, count,
462 gigaset_write_bulk_callback, cs);
463
464 cb->offset += count;
465 cb->len -= count;
466 ucs->busy = 1;
467
468 spin_lock_irqsave(&cs->lock, flags);
469 status = cs->connected ?
470 usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC) :
471 -ENODEV;
472 spin_unlock_irqrestore(&cs->lock, flags);
473
474 if (status) {
475 ucs->busy = 0;
476 dev_err(cs->dev,
477 "could not submit urb (error %d)\n",
478 -status);
479 cb->len = 0;
480
481 }
482 }
483 } while (cb && status);
484
485 return status;
486 }
487
488
489 static int gigaset_write_cmd(struct cardstate *cs, struct cmdbuf_t *cb)
490 {
491 unsigned long flags;
492 int len;
493
494 gigaset_dbg_buffer(cs->mstate != MS_LOCKED ?
495 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
496 "CMD Transmit", cb->len, cb->buf);
497
498 spin_lock_irqsave(&cs->cmdlock, flags);
499 cb->prev = cs->lastcmdbuf;
500 if (cs->lastcmdbuf)
501 cs->lastcmdbuf->next = cb;
502 else {
503 cs->cmdbuf = cb;
504 cs->curlen = cb->len;
505 }
506 cs->cmdbytes += cb->len;
507 cs->lastcmdbuf = cb;
508 spin_unlock_irqrestore(&cs->cmdlock, flags);
509
510 spin_lock_irqsave(&cs->lock, flags);
511 len = cb->len;
512 if (cs->connected)
513 tasklet_schedule(&cs->write_tasklet);
514 spin_unlock_irqrestore(&cs->lock, flags);
515 return len;
516 }
517
518 static int gigaset_write_room(struct cardstate *cs)
519 {
520 unsigned bytes;
521
522 bytes = cs->cmdbytes;
523 return bytes < IF_WRITEBUF ? IF_WRITEBUF - bytes : 0;
524 }
525
526 static int gigaset_chars_in_buffer(struct cardstate *cs)
527 {
528 return cs->cmdbytes;
529 }
530
531
532
533
534
535
536 static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
537 {
538 struct usb_device *udev = cs->hw.usb->udev;
539
540 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
541 memcpy(cs->hw.usb->bchars, buf, 6);
542 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
543 0, 0, &buf, 6, 2000);
544 }
545
546 static void gigaset_freebcshw(struct bc_state *bcs)
547 {
548
549 }
550
551
552 static int gigaset_initbcshw(struct bc_state *bcs)
553 {
554
555 bcs->hw.usb = NULL;
556 return 0;
557 }
558
559 static void gigaset_reinitbcshw(struct bc_state *bcs)
560 {
561
562 }
563
564 static void gigaset_freecshw(struct cardstate *cs)
565 {
566 tasklet_kill(&cs->write_tasklet);
567 kfree(cs->hw.usb);
568 }
569
570 static int gigaset_initcshw(struct cardstate *cs)
571 {
572 struct usb_cardstate *ucs;
573
574 cs->hw.usb = ucs = kzalloc(sizeof(struct usb_cardstate), GFP_KERNEL);
575 if (!ucs) {
576 pr_err("out of memory\n");
577 return -ENOMEM;
578 }
579
580 ucs->bchars[0] = 0;
581 ucs->bchars[1] = 0;
582 ucs->bchars[2] = 0;
583 ucs->bchars[3] = 0;
584 ucs->bchars[4] = 0x11;
585 ucs->bchars[5] = 0x13;
586 tasklet_init(&cs->write_tasklet,
587 gigaset_modem_fill, (unsigned long) cs);
588
589 return 0;
590 }
591
592
593 static int write_modem(struct cardstate *cs)
594 {
595 int ret = 0;
596 int count;
597 struct bc_state *bcs = &cs->bcs[0];
598 struct usb_cardstate *ucs = cs->hw.usb;
599 unsigned long flags;
600
601 gig_dbg(DEBUG_OUTPUT, "len: %d...", bcs->tx_skb->len);
602
603 if (!bcs->tx_skb->len) {
604 dev_kfree_skb_any(bcs->tx_skb);
605 bcs->tx_skb = NULL;
606 return -EINVAL;
607 }
608
609
610 count = min(bcs->tx_skb->len, (unsigned) ucs->bulk_out_size);
611 skb_copy_from_linear_data(bcs->tx_skb, ucs->bulk_out_buffer, count);
612 skb_pull(bcs->tx_skb, count);
613 ucs->busy = 1;
614 gig_dbg(DEBUG_OUTPUT, "write_modem: send %d bytes", count);
615
616 spin_lock_irqsave(&cs->lock, flags);
617 if (cs->connected) {
618 usb_fill_bulk_urb(ucs->bulk_out_urb, ucs->udev,
619 usb_sndbulkpipe(ucs->udev,
620 ucs->bulk_out_epnum),
621 ucs->bulk_out_buffer, count,
622 gigaset_write_bulk_callback, cs);
623 ret = usb_submit_urb(ucs->bulk_out_urb, GFP_ATOMIC);
624 } else {
625 ret = -ENODEV;
626 }
627 spin_unlock_irqrestore(&cs->lock, flags);
628
629 if (ret) {
630 dev_err(cs->dev, "could not submit urb (error %d)\n", -ret);
631 ucs->busy = 0;
632 }
633
634 if (!bcs->tx_skb->len) {
635
636 gigaset_skb_sent(bcs, bcs->tx_skb);
637
638 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
639 (unsigned long) bcs->tx_skb);
640 dev_kfree_skb_any(bcs->tx_skb);
641 bcs->tx_skb = NULL;
642 }
643
644 return ret;
645 }
646
647 static int gigaset_probe(struct usb_interface *interface,
648 const struct usb_device_id *id)
649 {
650 int retval;
651 struct usb_device *udev = interface_to_usbdev(interface);
652 struct usb_host_interface *hostif = interface->cur_altsetting;
653 struct cardstate *cs = NULL;
654 struct usb_cardstate *ucs = NULL;
655 struct usb_endpoint_descriptor *endpoint;
656 int buffer_size;
657
658 gig_dbg(DEBUG_ANY, "%s: Check if device matches ...", __func__);
659
660
661 if ((le16_to_cpu(udev->descriptor.idVendor) != USB_M105_VENDOR_ID) ||
662 (le16_to_cpu(udev->descriptor.idProduct) != USB_M105_PRODUCT_ID)) {
663 gig_dbg(DEBUG_ANY, "device ID (0x%x, 0x%x) not for me - skip",
664 le16_to_cpu(udev->descriptor.idVendor),
665 le16_to_cpu(udev->descriptor.idProduct));
666 return -ENODEV;
667 }
668 if (hostif->desc.bInterfaceNumber != 0) {
669 gig_dbg(DEBUG_ANY, "interface %d not for me - skip",
670 hostif->desc.bInterfaceNumber);
671 return -ENODEV;
672 }
673 if (hostif->desc.bAlternateSetting != 0) {
674 dev_notice(&udev->dev, "unsupported altsetting %d - skip",
675 hostif->desc.bAlternateSetting);
676 return -ENODEV;
677 }
678 if (hostif->desc.bInterfaceClass != 255) {
679 dev_notice(&udev->dev, "unsupported interface class %d - skip",
680 hostif->desc.bInterfaceClass);
681 return -ENODEV;
682 }
683
684 if (hostif->desc.bNumEndpoints < 2) {
685 dev_err(&interface->dev, "missing endpoints\n");
686 return -ENODEV;
687 }
688
689 dev_info(&udev->dev, "%s: Device matched ... !\n", __func__);
690
691
692 cs = gigaset_initcs(driver, 1, 1, 0, cidmode, GIGASET_MODULENAME);
693 if (!cs)
694 return -ENODEV;
695 ucs = cs->hw.usb;
696
697
698 usb_get_dev(udev);
699 ucs->udev = udev;
700 ucs->interface = interface;
701 cs->dev = &interface->dev;
702
703
704 usb_set_intfdata(interface, cs);
705
706 endpoint = &hostif->endpoint[0].desc;
707
708 if (!usb_endpoint_is_bulk_out(endpoint)) {
709 dev_err(&interface->dev, "missing bulk-out endpoint\n");
710 retval = -ENODEV;
711 goto error;
712 }
713
714 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
715 ucs->bulk_out_size = buffer_size;
716 ucs->bulk_out_epnum = usb_endpoint_num(endpoint);
717 ucs->bulk_out_buffer = kmalloc(buffer_size, GFP_KERNEL);
718 if (!ucs->bulk_out_buffer) {
719 dev_err(cs->dev, "Couldn't allocate bulk_out_buffer\n");
720 retval = -ENOMEM;
721 goto error;
722 }
723
724 ucs->bulk_out_urb = usb_alloc_urb(0, GFP_KERNEL);
725 if (!ucs->bulk_out_urb) {
726 dev_err(cs->dev, "Couldn't allocate bulk_out_urb\n");
727 retval = -ENOMEM;
728 goto error;
729 }
730
731 endpoint = &hostif->endpoint[1].desc;
732
733 if (!usb_endpoint_is_int_in(endpoint)) {
734 dev_err(&interface->dev, "missing int-in endpoint\n");
735 retval = -ENODEV;
736 goto error;
737 }
738
739 ucs->busy = 0;
740
741 ucs->read_urb = usb_alloc_urb(0, GFP_KERNEL);
742 if (!ucs->read_urb) {
743 dev_err(cs->dev, "No free urbs available\n");
744 retval = -ENOMEM;
745 goto error;
746 }
747 buffer_size = le16_to_cpu(endpoint->wMaxPacketSize);
748 ucs->rcvbuf_size = buffer_size;
749 ucs->rcvbuf = kmalloc(buffer_size, GFP_KERNEL);
750 if (!ucs->rcvbuf) {
751 dev_err(cs->dev, "Couldn't allocate rcvbuf\n");
752 retval = -ENOMEM;
753 goto error;
754 }
755
756 usb_fill_int_urb(ucs->read_urb, udev,
757 usb_rcvintpipe(udev, usb_endpoint_num(endpoint)),
758 ucs->rcvbuf, buffer_size,
759 gigaset_read_int_callback,
760 cs, endpoint->bInterval);
761
762 retval = usb_submit_urb(ucs->read_urb, GFP_KERNEL);
763 if (retval) {
764 dev_err(cs->dev, "Could not submit URB (error %d)\n", -retval);
765 goto error;
766 }
767
768
769 if (startmode == SM_LOCKED)
770 cs->mstate = MS_LOCKED;
771
772 retval = gigaset_start(cs);
773 if (retval < 0) {
774 tasklet_kill(&cs->write_tasklet);
775 goto error;
776 }
777 return 0;
778
779 error:
780 usb_kill_urb(ucs->read_urb);
781 kfree(ucs->bulk_out_buffer);
782 usb_free_urb(ucs->bulk_out_urb);
783 kfree(ucs->rcvbuf);
784 usb_free_urb(ucs->read_urb);
785 usb_set_intfdata(interface, NULL);
786 ucs->read_urb = ucs->bulk_out_urb = NULL;
787 ucs->rcvbuf = ucs->bulk_out_buffer = NULL;
788 usb_put_dev(ucs->udev);
789 ucs->udev = NULL;
790 ucs->interface = NULL;
791 gigaset_freecs(cs);
792 return retval;
793 }
794
795 static void gigaset_disconnect(struct usb_interface *interface)
796 {
797 struct cardstate *cs;
798 struct usb_cardstate *ucs;
799
800 cs = usb_get_intfdata(interface);
801 ucs = cs->hw.usb;
802
803 dev_info(cs->dev, "disconnecting Gigaset USB adapter\n");
804
805 usb_kill_urb(ucs->read_urb);
806
807 gigaset_stop(cs);
808
809 usb_set_intfdata(interface, NULL);
810 tasklet_kill(&cs->write_tasklet);
811
812 usb_kill_urb(ucs->bulk_out_urb);
813
814 kfree(ucs->bulk_out_buffer);
815 usb_free_urb(ucs->bulk_out_urb);
816 kfree(ucs->rcvbuf);
817 usb_free_urb(ucs->read_urb);
818 ucs->read_urb = ucs->bulk_out_urb = NULL;
819 ucs->rcvbuf = ucs->bulk_out_buffer = NULL;
820
821 usb_put_dev(ucs->udev);
822 ucs->interface = NULL;
823 ucs->udev = NULL;
824 cs->dev = NULL;
825 gigaset_freecs(cs);
826 }
827
828
829
830
831 static int gigaset_suspend(struct usb_interface *intf, pm_message_t message)
832 {
833 struct cardstate *cs = usb_get_intfdata(intf);
834
835
836 cs->connected = 0;
837 usb_kill_urb(cs->hw.usb->read_urb);
838 tasklet_kill(&cs->write_tasklet);
839 usb_kill_urb(cs->hw.usb->bulk_out_urb);
840
841 gig_dbg(DEBUG_SUSPEND, "suspend complete");
842 return 0;
843 }
844
845
846
847
848 static int gigaset_resume(struct usb_interface *intf)
849 {
850 struct cardstate *cs = usb_get_intfdata(intf);
851 int rc;
852
853
854 cs->connected = 1;
855 rc = usb_submit_urb(cs->hw.usb->read_urb, GFP_KERNEL);
856 if (rc) {
857 dev_err(cs->dev, "Could not submit read URB (error %d)\n", -rc);
858 return rc;
859 }
860
861 gig_dbg(DEBUG_SUSPEND, "resume complete");
862 return 0;
863 }
864
865
866
867
868 static int gigaset_pre_reset(struct usb_interface *intf)
869 {
870
871 return gigaset_suspend(intf, PMSG_ON);
872 }
873
874 static const struct gigaset_ops ops = {
875 .write_cmd = gigaset_write_cmd,
876 .write_room = gigaset_write_room,
877 .chars_in_buffer = gigaset_chars_in_buffer,
878 .brkchars = gigaset_brkchars,
879 .init_bchannel = gigaset_init_bchannel,
880 .close_bchannel = gigaset_close_bchannel,
881 .initbcshw = gigaset_initbcshw,
882 .freebcshw = gigaset_freebcshw,
883 .reinitbcshw = gigaset_reinitbcshw,
884 .initcshw = gigaset_initcshw,
885 .freecshw = gigaset_freecshw,
886 .set_modem_ctrl = gigaset_set_modem_ctrl,
887 .baud_rate = gigaset_baud_rate,
888 .set_line_ctrl = gigaset_set_line_ctrl,
889 .send_skb = gigaset_m10x_send_skb,
890 .handle_input = gigaset_m10x_input,
891 };
892
893
894
895
896 static int __init usb_gigaset_init(void)
897 {
898 int result;
899
900
901 driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
902 GIGASET_MODULENAME, GIGASET_DEVNAME,
903 &ops, THIS_MODULE);
904 if (driver == NULL) {
905 result = -ENOMEM;
906 goto error;
907 }
908
909
910 result = usb_register(&gigaset_usb_driver);
911 if (result < 0) {
912 pr_err("error %d registering USB driver\n", -result);
913 goto error;
914 }
915
916 pr_info(DRIVER_DESC "\n");
917 return 0;
918
919 error:
920 if (driver)
921 gigaset_freedriver(driver);
922 driver = NULL;
923 return result;
924 }
925
926
927
928
929 static void __exit usb_gigaset_exit(void)
930 {
931 int i;
932
933 gigaset_blockdriver(driver);
934
935
936
937
938 for (i = 0; i < driver->minors; i++)
939 gigaset_shutdown(driver->cs + i);
940
941
942
943
944 usb_deregister(&gigaset_usb_driver);
945
946
947
948 gigaset_freedriver(driver);
949 driver = NULL;
950 }
951
952
953 module_init(usb_gigaset_init);
954 module_exit(usb_gigaset_exit);
955
956 MODULE_AUTHOR(DRIVER_AUTHOR);
957 MODULE_DESCRIPTION(DRIVER_DESC);
958
959 MODULE_LICENSE("GPL");