20 #include <linux/module.h>
25 #define DRIVER_DESC "USB Driver for Gigaset 307x using M105"
30 static int cidmode = 1;
37 #define GIGASET_MINORS 1
38 #define GIGASET_MINOR 8
39 #define GIGASET_MODULENAME "usb_gigaset"
40 #define GIGASET_DEVNAME "ttyGU"
43 #define IF_WRITEBUF 264
46 #define USB_M105_VENDOR_ID 0x0681
47 #define USB_M105_PRODUCT_ID 0x0009
117 static struct usb_driver gigaset_usb_driver = {
119 .probe = gigaset_probe,
120 .disconnect = gigaset_disconnect,
121 .id_table = gigaset_table,
122 .suspend = gigaset_suspend,
123 .resume = gigaset_resume,
124 .reset_resume = gigaset_resume,
125 .pre_reset = gigaset_pre_reset,
126 .post_reset = gigaset_resume,
127 .disable_hub_initiated_lpm = 1,
150 static inline unsigned tiocm_to_gigaset(
unsigned state)
155 static int gigaset_set_modem_ctrl(
struct cardstate *
cs,
unsigned old_state,
158 struct usb_device *
udev = cs->
hw.
usb->udev;
162 mask = tiocm_to_gigaset(old_state ^ new_state);
163 val = tiocm_to_gigaset(new_state);
167 (val & 0xff) | ((mask & 0xff) << 8), 0,
181 struct usb_device *udev = cs->
hw.
usb->udev;
185 (
unsigned)req, (
unsigned)val);
187 0xf , 0,
NULL, 0, 2000 );
190 dev_err(&udev->dev,
"error %d on request 0x12\n", -r);
195 val, 0,
NULL, 0, 2000 );
197 dev_err(&udev->dev,
"error %d on request 0x%02x\n",
201 0, 0, cs->
hw.
usb->bchars, 6, 2000 );
203 dev_err(&udev->dev,
"error %d on request 0x19\n", -r2);
205 return r < 0 ? r : (r2 < 0 ? r2 : 0);
212 static int gigaset_baud_rate(
struct cardstate *cs,
unsigned cflag)
220 case B300: rate = 300;
break;
221 case B600: rate = 600;
break;
222 case B1200: rate = 1200;
break;
223 case B2400: rate = 2400;
break;
224 case B4800: rate = 4800;
break;
225 case B9600: rate = 9600;
break;
226 case B19200: rate = 19200;
break;
227 case B38400: rate = 38400;
break;
228 case B57600: rate = 57600;
break;
229 case B115200: rate = 115200;
break;
232 dev_err(cs->
dev,
"unsupported baudrate request 0x%x,"
233 " using default of B9600\n", cflag);
236 val = 0x383fff / rate + 1;
238 return set_value(cs, 1, val);
245 static int gigaset_set_line_ctrl(
struct cardstate *cs,
unsigned cflag)
251 val |= (cflag &
PARODD) ? 0x10 : 0x20;
254 switch (cflag &
CSIZE) {
256 val |= 5 << 8;
break;
258 val |= 6 << 8;
break;
260 val |= 7 << 8;
break;
262 val |= 8 << 8;
break;
264 dev_err(cs->
dev,
"CSIZE was not CS5-CS8, using default of 8\n");
271 if ((cflag & CSIZE) ==
CS5)
277 return set_value(cs, 3, val);
282 static int gigaset_init_bchannel(
struct bc_state *bcs)
285 gigaset_bchannel_up(bcs);
289 static int gigaset_close_bchannel(
struct bc_state *bcs)
292 gigaset_bchannel_down(bcs);
296 static int write_modem(
struct cardstate *cs);
303 static void gigaset_modem_fill(
unsigned long data)
312 if (cs->
hw.
usb->busy) {
323 if (send_cb(cs, cb) < 0) {
325 "modem_fill: send_cb failed");
333 "Dequeued skb (Adr: %lx)!",
334 (
unsigned long) bcs->
tx_skb);
340 if (write_modem(cs) < 0) {
342 "modem_fill: write_modem failed");
352 static void gigaset_read_int_callback(
struct urb *
urb)
363 numbytes = urb->actual_length;
366 src = cs->
hw.
usb->rcvbuf;
369 "%s: There was no leading 0, but 0x%02x!\n",
370 __func__, (
unsigned) *src);
375 gigaset_schedule_event(inbuf->
cs);
391 spin_unlock_irqrestore(&cs->
lock, flags);
392 pr_err(
"%s: disconnected\n", __func__);
396 spin_unlock_irqrestore(&cs->
lock, flags);
398 dev_err(cs->
dev,
"error %d resubmitting URB\n", -r);
403 static void gigaset_write_bulk_callback(
struct urb *urb)
406 int status = urb->status;
414 cs->
hw.
usb->busy = 0;
417 dev_err(cs->
dev,
"bulk transfer failed (status %d)\n",
425 pr_err(
"%s: disconnected\n", __func__);
427 cs->
hw.
usb->busy = 0;
430 spin_unlock_irqrestore(&cs->
lock, flags);
457 spin_unlock_irqrestore(&cs->
cmdlock, flags);
468 usb_sndbulkpipe(ucs->
udev,
471 gigaset_write_bulk_callback, cs);
481 spin_unlock_irqrestore(&cs->
lock, flags);
486 "could not submit urb (error %d)\n",
492 }
while (cb && status);
504 "CMD Transmit", cb->
len, cb->
buf);
516 spin_unlock_irqrestore(&cs->
cmdlock, flags);
521 spin_unlock_irqrestore(&cs->
lock, flags);
525 static int gigaset_write_room(
struct cardstate *cs)
533 static int gigaset_chars_in_buffer(
struct cardstate *cs)
543 static int gigaset_brkchars(
struct cardstate *cs,
const unsigned char buf[6])
545 struct usb_device *udev = cs->
hw.
usb->udev;
550 0, 0, &buf, 6, 2000);
553 static void gigaset_freebcshw(
struct bc_state *bcs)
559 static int gigaset_initbcshw(
struct bc_state *bcs)
566 static void gigaset_reinitbcshw(
struct bc_state *bcs)
571 static void gigaset_freecshw(
struct cardstate *cs)
577 static int gigaset_initcshw(
struct cardstate *cs)
584 pr_err(
"out of memory\n");
598 gigaset_modem_fill, (
unsigned long) cs);
604 static int write_modem(
struct cardstate *cs)
630 usb_sndbulkpipe(ucs->
udev,
634 gigaset_write_bulk_callback, cs);
639 spin_unlock_irqrestore(&cs->
lock, flags);
642 dev_err(cs->
dev,
"could not submit urb (error %d)\n", -ret);
651 (
unsigned long) bcs->
tx_skb);
663 struct usb_device *udev = interface_to_usbdev(interface);
664 struct usb_host_interface *hostif = interface->cur_altsetting;
680 if (hostif->desc.bInterfaceNumber != 0) {
682 hostif->desc.bInterfaceNumber);
685 if (hostif->desc.bAlternateSetting != 0) {
686 dev_notice(&udev->dev,
"unsupported altsetting %d - skip",
687 hostif->desc.bAlternateSetting);
690 if (hostif->desc.bInterfaceClass != 255) {
691 dev_notice(&udev->dev,
"unsupported interface class %d - skip",
692 hostif->desc.bInterfaceClass);
696 dev_info(&udev->dev,
"%s: Device matched ... !\n", __func__);
708 cs->
dev = &interface->dev;
711 usb_set_intfdata(interface, cs);
713 endpoint = &hostif->endpoint[0].desc;
720 dev_err(cs->
dev,
"Couldn't allocate bulk_out_buffer\n");
727 dev_err(cs->
dev,
"Couldn't allocate bulk_out_urb\n");
732 endpoint = &hostif->endpoint[1].desc;
747 dev_err(cs->
dev,
"Couldn't allocate rcvbuf\n");
752 usb_fill_int_urb(ucs->
read_urb, udev,
756 gigaset_read_int_callback,
761 dev_err(cs->
dev,
"Could not submit URB (error %d)\n", -retval);
782 usb_set_intfdata(interface,
NULL);
792 static void gigaset_disconnect(
struct usb_interface *interface)
797 cs = usb_get_intfdata(interface);
800 dev_info(cs->
dev,
"disconnecting Gigaset USB adapter\n");
806 usb_set_intfdata(interface,
NULL);
830 struct cardstate *cs = usb_get_intfdata(intf);
847 struct cardstate *cs = usb_get_intfdata(intf);
854 dev_err(cs->
dev,
"Could not submit read URB (error %d)\n", -rc);
868 return gigaset_suspend(intf,
PMSG_ON);
874 gigaset_chars_in_buffer,
876 gigaset_init_bchannel,
877 gigaset_close_bchannel,
883 gigaset_set_modem_ctrl,
885 gigaset_set_line_ctrl,
893 static int __init usb_gigaset_init(
void)
901 if (driver ==
NULL) {
907 result = usb_register(&gigaset_usb_driver);
909 pr_err(
"error %d registering USB driver\n", -result);
926 static void __exit usb_gigaset_exit(
void)
935 for (i = 0; i < driver->
minors; i++)