bf1f8ea989b032ab7760c2ad14e772866b0582ad
[pandora-kernel.git] / drivers / usb / serial / ssu100.c
1 /*
2  * usb-serial driver for Quatech SSU-100
3  *
4  * based on ftdi_sio.c and the original serqt_usb.c from Quatech
5  *
6  */
7
8 #include <linux/errno.h>
9 #include <linux/init.h>
10 #include <linux/slab.h>
11 #include <linux/tty.h>
12 #include <linux/tty_driver.h>
13 #include <linux/tty_flip.h>
14 #include <linux/module.h>
15 #include <linux/serial.h>
16 #include <linux/usb.h>
17 #include <linux/usb/serial.h>
18 #include <linux/serial_reg.h>
19 #include <linux/uaccess.h>
20
21 #define QT_OPEN_CLOSE_CHANNEL       0xca
22 #define QT_SET_GET_DEVICE           0xc2
23 #define QT_SET_GET_REGISTER         0xc0
24 #define QT_GET_SET_PREBUF_TRIG_LVL  0xcc
25 #define QT_SET_ATF                  0xcd
26 #define QT_GET_SET_UART             0xc1
27 #define QT_TRANSFER_IN              0xc0
28 #define QT_HW_FLOW_CONTROL_MASK     0xc5
29 #define QT_SW_FLOW_CONTROL_MASK     0xc6
30
31 #define  SERIAL_MSR_MASK            0xf0
32
33 #define  SERIAL_CRTSCTS ((UART_MCR_RTS << 8) | UART_MSR_CTS)
34
35 #define  SERIAL_EVEN_PARITY         (UART_LCR_PARITY | UART_LCR_EPAR)
36
37 #define  MAX_BAUD_RATE              460800
38
39 #define ATC_DISABLED                0x00
40 #define DUPMODE_BITS        0xc0
41 #define RR_BITS             0x03
42 #define LOOPMODE_BITS       0x41
43 #define RS232_MODE          0x00
44 #define RTSCTS_TO_CONNECTOR 0x40
45 #define CLKS_X4             0x02
46 #define FULLPWRBIT          0x00000080
47 #define NEXT_BOARD_POWER_BIT        0x00000004
48
49 static int debug;
50
51 /* Version Information */
52 #define DRIVER_VERSION "v0.1"
53 #define DRIVER_DESC "Quatech SSU-100 USB to Serial Driver"
54
55 #define USB_VENDOR_ID_QUATECH   0x061d  /* Quatech VID */
56 #define QUATECH_SSU100  0xC020  /* SSU100 */
57
58 static const struct usb_device_id id_table[] = {
59         {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU100)},
60         {}                      /* Terminating entry */
61 };
62
63 MODULE_DEVICE_TABLE(usb, id_table);
64
65
66 static struct usb_driver ssu100_driver = {
67         .name                          = "ssu100",
68         .probe                         = usb_serial_probe,
69         .disconnect                    = usb_serial_disconnect,
70         .id_table                      = id_table,
71         .suspend                       = usb_serial_suspend,
72         .resume                        = usb_serial_resume,
73         .no_dynamic_id                 = 1,
74         .supports_autosuspend          = 1,
75 };
76
77 struct ssu100_port_private {
78         spinlock_t status_lock;
79         u8 shadowLSR;
80         u8 shadowMSR;
81         struct async_icount icount;
82 };
83
84 static void ssu100_release(struct usb_serial *serial)
85 {
86         struct ssu100_port_private *priv = usb_get_serial_port_data(*serial->port);
87
88         dbg("%s", __func__);
89         kfree(priv);
90 }
91
92 static inline int ssu100_control_msg(struct usb_device *dev,
93                                      u8 request, u16 data, u16 index)
94 {
95         return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
96                                request, 0x40, data, index,
97                                NULL, 0, 300);
98 }
99
100 static inline int ssu100_setdevice(struct usb_device *dev, u8 *data)
101 {
102         u16 x = ((u16)(data[1] << 8) | (u16)(data[0]));
103
104         return ssu100_control_msg(dev, QT_SET_GET_DEVICE, x, 0);
105 }
106
107
108 static inline int ssu100_getdevice(struct usb_device *dev, u8 *data)
109 {
110         return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
111                                QT_SET_GET_DEVICE, 0xc0, 0, 0,
112                                data, 3, 300);
113 }
114
115 static inline int ssu100_getregister(struct usb_device *dev,
116                                      unsigned short uart,
117                                      unsigned short reg,
118                                      u8 *data)
119 {
120         return usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
121                                QT_SET_GET_REGISTER, 0xc0, reg,
122                                uart, data, sizeof(*data), 300);
123
124 }
125
126
127 static inline int ssu100_setregister(struct usb_device *dev,
128                                      unsigned short uart,
129                                      unsigned short reg,
130                                      u16 data)
131 {
132         u16 value = (data << 8) | reg;
133
134         return usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
135                                QT_SET_GET_REGISTER, 0x40, value, uart,
136                                NULL, 0, 300);
137
138 }
139
140 #define set_mctrl(dev, set)             update_mctrl((dev), (set), 0)
141 #define clear_mctrl(dev, clear) update_mctrl((dev), 0, (clear))
142
143 /* these do not deal with device that have more than 1 port */
144 static inline int update_mctrl(struct usb_device *dev, unsigned int set,
145                                unsigned int clear)
146 {
147         unsigned urb_value;
148         int result;
149
150         if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0) {
151                 dbg("%s - DTR|RTS not being set|cleared", __func__);
152                 return 0;       /* no change */
153         }
154
155         clear &= ~set;  /* 'set' takes precedence over 'clear' */
156         urb_value = 0;
157         if (set & TIOCM_DTR)
158                 urb_value |= UART_MCR_DTR;
159         if (set & TIOCM_RTS)
160                 urb_value |= UART_MCR_RTS;
161
162         result = ssu100_setregister(dev, 0, UART_MCR, urb_value);
163         if (result < 0)
164                 dbg("%s Error from MODEM_CTRL urb", __func__);
165
166         return result;
167 }
168
169 static int ssu100_initdevice(struct usb_device *dev)
170 {
171         u8 *data;
172         int result = 0;
173
174         dbg("%s", __func__);
175
176         data = kzalloc(3, GFP_KERNEL);
177         if (!data)
178                 return -ENOMEM;
179
180         result = ssu100_getdevice(dev, data);
181         if (result < 0) {
182                 dbg("%s - get_device failed %i", __func__, result);
183                 goto out;
184         }
185
186         data[1] &= ~FULLPWRBIT;
187
188         result = ssu100_setdevice(dev, data);
189         if (result < 0) {
190                 dbg("%s - setdevice failed %i", __func__, result);
191                 goto out;
192         }
193
194         result = ssu100_control_msg(dev, QT_GET_SET_PREBUF_TRIG_LVL, 128, 0);
195         if (result < 0) {
196                 dbg("%s - set prebuffer level failed %i", __func__, result);
197                 goto out;
198         }
199
200         result = ssu100_control_msg(dev, QT_SET_ATF, ATC_DISABLED, 0);
201         if (result < 0) {
202                 dbg("%s - set ATFprebuffer level failed %i", __func__, result);
203                 goto out;
204         }
205
206         result = ssu100_getdevice(dev, data);
207         if (result < 0) {
208                 dbg("%s - get_device failed %i", __func__, result);
209                 goto out;
210         }
211
212         data[0] &= ~(RR_BITS | DUPMODE_BITS);
213         data[0] |= CLKS_X4;
214         data[1] &= ~(LOOPMODE_BITS);
215         data[1] |= RS232_MODE;
216
217         result = ssu100_setdevice(dev, data);
218         if (result < 0) {
219                 dbg("%s - setdevice failed %i", __func__, result);
220                 goto out;
221         }
222
223 out:    kfree(data);
224         return result;
225
226 }
227
228
229 static void ssu100_set_termios(struct tty_struct *tty,
230                                struct usb_serial_port *port,
231                                struct ktermios *old_termios)
232 {
233         struct usb_device *dev = port->serial->dev;
234         struct ktermios *termios = tty->termios;
235         u16 baud, divisor, remainder;
236         unsigned int cflag = termios->c_cflag;
237         u16 urb_value = 0; /* will hold the new flags */
238         int result;
239
240         dbg("%s", __func__);
241
242         if (cflag & PARENB) {
243                 if (cflag & PARODD)
244                         urb_value |= UART_LCR_PARITY;
245                 else
246                         urb_value |= SERIAL_EVEN_PARITY;
247         }
248
249         switch (cflag & CSIZE) {
250         case CS5:
251                 urb_value |= UART_LCR_WLEN5;
252                 break;
253         case CS6:
254                 urb_value |= UART_LCR_WLEN6;
255                 break;
256         case CS7:
257                 urb_value |= UART_LCR_WLEN7;
258                 break;
259         default:
260         case CS8:
261                 urb_value |= UART_LCR_WLEN8;
262                 break;
263         }
264
265         baud = tty_get_baud_rate(tty);
266         if (!baud)
267                 baud = 9600;
268
269         dbg("%s - got baud = %d\n", __func__, baud);
270
271
272         divisor = MAX_BAUD_RATE / baud;
273         remainder = MAX_BAUD_RATE % baud;
274         if (((remainder * 2) >= baud) && (baud != 110))
275                 divisor++;
276
277         urb_value = urb_value << 8;
278
279         result = ssu100_control_msg(dev, QT_GET_SET_UART, divisor, urb_value);
280         if (result < 0)
281                 dbg("%s - set uart failed", __func__);
282
283         if (cflag & CRTSCTS)
284                 result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK,
285                                             SERIAL_CRTSCTS, 0);
286         else
287                 result = ssu100_control_msg(dev, QT_HW_FLOW_CONTROL_MASK,
288                                             0, 0);
289         if (result < 0)
290                 dbg("%s - set HW flow control failed", __func__);
291
292         if (I_IXOFF(tty) || I_IXON(tty)) {
293                 u16 x = ((u16)(START_CHAR(tty) << 8) | (u16)(STOP_CHAR(tty)));
294
295                 result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK,
296                                             x, 0);
297         } else
298                 result = ssu100_control_msg(dev, QT_SW_FLOW_CONTROL_MASK,
299                                             0, 0);
300
301         if (result < 0)
302                 dbg("%s - set SW flow control failed", __func__);
303
304 }
305
306
307 static int ssu100_open(struct tty_struct *tty, struct usb_serial_port *port)
308 {
309         struct usb_device *dev = port->serial->dev;
310         struct ssu100_port_private *priv = usb_get_serial_port_data(port);
311         u8 *data;
312         int result;
313         unsigned long flags;
314
315         dbg("%s - port %d", __func__, port->number);
316
317         data = kzalloc(2, GFP_KERNEL);
318         if (!data)
319                 return -ENOMEM;
320
321         result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
322                                  QT_OPEN_CLOSE_CHANNEL,
323                                  QT_TRANSFER_IN, 0x01,
324                                  0, data, 2, 300);
325         if (result < 0) {
326                 dbg("%s - open failed %i", __func__, result);
327                 kfree(data);
328                 return result;
329         }
330
331         spin_lock_irqsave(&priv->status_lock, flags);
332         priv->shadowLSR = data[0];
333         priv->shadowMSR = data[1];
334         spin_unlock_irqrestore(&priv->status_lock, flags);
335
336         kfree(data);
337
338 /* set to 9600 */
339         result = ssu100_control_msg(dev, QT_GET_SET_UART, 0x30, 0x0300);
340         if (result < 0)
341                 dbg("%s - set uart failed", __func__);
342
343         if (tty)
344                 ssu100_set_termios(tty, port, tty->termios);
345
346         return usb_serial_generic_open(tty, port);
347 }
348
349 static void ssu100_close(struct usb_serial_port *port)
350 {
351         dbg("%s", __func__);
352         usb_serial_generic_close(port);
353 }
354
355 static int get_serial_info(struct usb_serial_port *port,
356                            struct serial_struct __user *retinfo)
357 {
358         struct serial_struct tmp;
359
360         if (!retinfo)
361                 return -EFAULT;
362
363         memset(&tmp, 0, sizeof(tmp));
364         tmp.line                = port->serial->minor;
365         tmp.port                = 0;
366         tmp.irq                 = 0;
367         tmp.flags               = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
368         tmp.xmit_fifo_size      = port->bulk_out_size;
369         tmp.baud_base           = 9600;
370         tmp.close_delay         = 5*HZ;
371         tmp.closing_wait        = 30*HZ;
372
373         if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
374                 return -EFAULT;
375         return 0;
376 }
377
378 static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
379 {
380         struct ssu100_port_private *priv = usb_get_serial_port_data(port);
381         struct async_icount prev, cur;
382         unsigned long flags;
383
384         spin_lock_irqsave(&priv->status_lock, flags);
385         prev = priv->icount;
386         spin_unlock_irqrestore(&priv->status_lock, flags);
387
388         while (1) {
389                 wait_event_interruptible(port->delta_msr_wait,
390                                          (port->serial->disconnected ||
391                                           (priv->icount.rng != prev.rng) ||
392                                           (priv->icount.dsr != prev.dsr) ||
393                                           (priv->icount.dcd != prev.dcd) ||
394                                           (priv->icount.cts != prev.cts)));
395
396                 if (signal_pending(current))
397                         return -ERESTARTSYS;
398
399                 if (port->serial->disconnected)
400                         return -EIO;
401
402                 spin_lock_irqsave(&priv->status_lock, flags);
403                 cur = priv->icount;
404                 spin_unlock_irqrestore(&priv->status_lock, flags);
405
406                 if ((prev.rng == cur.rng) &&
407                     (prev.dsr == cur.dsr) &&
408                     (prev.dcd == cur.dcd) &&
409                     (prev.cts == cur.cts))
410                         return -EIO;
411
412                 if ((arg & TIOCM_RNG && (prev.rng != cur.rng)) ||
413                     (arg & TIOCM_DSR && (prev.dsr != cur.dsr)) ||
414                     (arg & TIOCM_CD  && (prev.dcd != cur.dcd)) ||
415                     (arg & TIOCM_CTS && (prev.cts != cur.cts)))
416                         return 0;
417         }
418         return 0;
419 }
420
421 static int ssu100_get_icount(struct tty_struct *tty,
422                         struct serial_icounter_struct *icount)
423 {
424         struct usb_serial_port *port = tty->driver_data;
425         struct ssu100_port_private *priv = usb_get_serial_port_data(port);
426         struct async_icount cnow = priv->icount;
427
428         icount->cts = cnow.cts;
429         icount->dsr = cnow.dsr;
430         icount->rng = cnow.rng;
431         icount->dcd = cnow.dcd;
432         icount->rx = cnow.rx;
433         icount->tx = cnow.tx;
434         icount->frame = cnow.frame;
435         icount->overrun = cnow.overrun;
436         icount->parity = cnow.parity;
437         icount->brk = cnow.brk;
438         icount->buf_overrun = cnow.buf_overrun;
439
440         return 0;
441 }
442
443
444
445 static int ssu100_ioctl(struct tty_struct *tty,
446                     unsigned int cmd, unsigned long arg)
447 {
448         struct usb_serial_port *port = tty->driver_data;
449
450         dbg("%s cmd 0x%04x", __func__, cmd);
451
452         switch (cmd) {
453         case TIOCGSERIAL:
454                 return get_serial_info(port,
455                                        (struct serial_struct __user *) arg);
456
457         case TIOCMIWAIT:
458                 return wait_modem_info(port, arg);
459
460         default:
461                 break;
462         }
463
464         dbg("%s arg not supported", __func__);
465
466         return -ENOIOCTLCMD;
467 }
468
469 static int ssu100_attach(struct usb_serial *serial)
470 {
471         struct ssu100_port_private *priv;
472         struct usb_serial_port *port = *serial->port;
473
474         dbg("%s", __func__);
475
476         priv = kzalloc(sizeof(*priv), GFP_KERNEL);
477         if (!priv) {
478                 dev_err(&port->dev, "%s- kmalloc(%Zd) failed.\n", __func__,
479                         sizeof(*priv));
480                 return -ENOMEM;
481         }
482
483         spin_lock_init(&priv->status_lock);
484         usb_set_serial_port_data(port, priv);
485
486         return ssu100_initdevice(serial->dev);
487 }
488
489 static int ssu100_tiocmget(struct tty_struct *tty)
490 {
491         struct usb_serial_port *port = tty->driver_data;
492         struct usb_device *dev = port->serial->dev;
493         u8 *d;
494         int r;
495
496         dbg("%s\n", __func__);
497
498         d = kzalloc(2, GFP_KERNEL);
499         if (!d)
500                 return -ENOMEM;
501
502         r = ssu100_getregister(dev, 0, UART_MCR, d);
503         if (r < 0)
504                 goto mget_out;
505
506         r = ssu100_getregister(dev, 0, UART_MSR, d+1);
507         if (r < 0)
508                 goto mget_out;
509
510         r = (d[0] & UART_MCR_DTR ? TIOCM_DTR : 0) |
511                 (d[0] & UART_MCR_RTS ? TIOCM_RTS : 0) |
512                 (d[1] & UART_MSR_CTS ? TIOCM_CTS : 0) |
513                 (d[1] & UART_MSR_DCD ? TIOCM_CAR : 0) |
514                 (d[1] & UART_MSR_RI ? TIOCM_RI : 0) |
515                 (d[1] & UART_MSR_DSR ? TIOCM_DSR : 0);
516
517 mget_out:
518         kfree(d);
519         return r;
520 }
521
522 static int ssu100_tiocmset(struct tty_struct *tty,
523                            unsigned int set, unsigned int clear)
524 {
525         struct usb_serial_port *port = tty->driver_data;
526         struct usb_device *dev = port->serial->dev;
527
528         dbg("%s\n", __func__);
529         return update_mctrl(dev, set, clear);
530 }
531
532 static void ssu100_dtr_rts(struct usb_serial_port *port, int on)
533 {
534         struct usb_device *dev = port->serial->dev;
535
536         dbg("%s\n", __func__);
537
538         /* Disable flow control */
539         if (!on) {
540                 if (ssu100_setregister(dev, 0, UART_MCR, 0) < 0)
541                         dev_err(&port->dev, "error from flowcontrol urb\n");
542         }
543         /* drop RTS and DTR */
544         if (on)
545                 set_mctrl(dev, TIOCM_DTR | TIOCM_RTS);
546         else
547                 clear_mctrl(dev, TIOCM_DTR | TIOCM_RTS);
548 }
549
550 static void ssu100_update_msr(struct usb_serial_port *port, u8 msr)
551 {
552         struct ssu100_port_private *priv = usb_get_serial_port_data(port);
553         unsigned long flags;
554
555         spin_lock_irqsave(&priv->status_lock, flags);
556         priv->shadowMSR = msr;
557         spin_unlock_irqrestore(&priv->status_lock, flags);
558
559         if (msr & UART_MSR_ANY_DELTA) {
560                 /* update input line counters */
561                 if (msr & UART_MSR_DCTS)
562                         priv->icount.cts++;
563                 if (msr & UART_MSR_DDSR)
564                         priv->icount.dsr++;
565                 if (msr & UART_MSR_DDCD)
566                         priv->icount.dcd++;
567                 if (msr & UART_MSR_TERI)
568                         priv->icount.rng++;
569                 wake_up_interruptible(&port->delta_msr_wait);
570         }
571 }
572
573 static void ssu100_update_lsr(struct usb_serial_port *port, u8 lsr,
574                               char *tty_flag)
575 {
576         struct ssu100_port_private *priv = usb_get_serial_port_data(port);
577         unsigned long flags;
578
579         spin_lock_irqsave(&priv->status_lock, flags);
580         priv->shadowLSR = lsr;
581         spin_unlock_irqrestore(&priv->status_lock, flags);
582
583         *tty_flag = TTY_NORMAL;
584         if (lsr & UART_LSR_BRK_ERROR_BITS) {
585                 /* we always want to update icount, but we only want to
586                  * update tty_flag for one case */
587                 if (lsr & UART_LSR_BI) {
588                         priv->icount.brk++;
589                         *tty_flag = TTY_BREAK;
590                         usb_serial_handle_break(port);
591                 }
592                 if (lsr & UART_LSR_PE) {
593                         priv->icount.parity++;
594                         if (*tty_flag == TTY_NORMAL)
595                                 *tty_flag = TTY_PARITY;
596                 }
597                 if (lsr & UART_LSR_FE) {
598                         priv->icount.frame++;
599                         if (*tty_flag == TTY_NORMAL)
600                                 *tty_flag = TTY_FRAME;
601                 }
602                 if (lsr & UART_LSR_OE){
603                         priv->icount.overrun++;
604                         if (*tty_flag == TTY_NORMAL)
605                                 *tty_flag = TTY_OVERRUN;
606                 }
607         }
608
609 }
610
611 static int ssu100_process_packet(struct urb *urb,
612                                  struct tty_struct *tty)
613 {
614         struct usb_serial_port *port = urb->context;
615         char *packet = (char *)urb->transfer_buffer;
616         char flag = TTY_NORMAL;
617         u32 len = urb->actual_length;
618         int i;
619         char *ch;
620
621         dbg("%s - port %d", __func__, port->number);
622
623         if ((len >= 4) &&
624             (packet[0] == 0x1b) && (packet[1] == 0x1b) &&
625             ((packet[2] == 0x00) || (packet[2] == 0x01))) {
626                 if (packet[2] == 0x00) {
627                         ssu100_update_lsr(port, packet[3], &flag);
628                         if (flag == TTY_OVERRUN)
629                                 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
630                 }
631                 if (packet[2] == 0x01)
632                         ssu100_update_msr(port, packet[3]);
633
634                 len -= 4;
635                 ch = packet + 4;
636         } else
637                 ch = packet;
638
639         if (!len)
640                 return 0;       /* status only */
641
642         if (port->port.console && port->sysrq) {
643                 for (i = 0; i < len; i++, ch++) {
644                         if (!usb_serial_handle_sysrq_char(port, *ch))
645                                 tty_insert_flip_char(tty, *ch, flag);
646                 }
647         } else
648                 tty_insert_flip_string_fixed_flag(tty, ch, flag, len);
649
650         return len;
651 }
652
653 static void ssu100_process_read_urb(struct urb *urb)
654 {
655         struct usb_serial_port *port = urb->context;
656         struct tty_struct *tty;
657         int count;
658
659         dbg("%s", __func__);
660
661         tty = tty_port_tty_get(&port->port);
662         if (!tty)
663                 return;
664
665         count = ssu100_process_packet(urb, tty);
666
667         if (count)
668                 tty_flip_buffer_push(tty);
669         tty_kref_put(tty);
670 }
671
672 static struct usb_serial_driver ssu100_device = {
673         .driver = {
674                 .owner = THIS_MODULE,
675                 .name = "ssu100",
676         },
677         .description         = DRIVER_DESC,
678         .id_table            = id_table,
679         .usb_driver          = &ssu100_driver,
680         .num_ports           = 1,
681         .open                = ssu100_open,
682         .close               = ssu100_close,
683         .attach              = ssu100_attach,
684         .release             = ssu100_release,
685         .dtr_rts             = ssu100_dtr_rts,
686         .process_read_urb    = ssu100_process_read_urb,
687         .tiocmget            = ssu100_tiocmget,
688         .tiocmset            = ssu100_tiocmset,
689         .get_icount          = ssu100_get_icount,
690         .ioctl               = ssu100_ioctl,
691         .set_termios         = ssu100_set_termios,
692         .disconnect          = usb_serial_generic_disconnect,
693 };
694
695 static int __init ssu100_init(void)
696 {
697         int retval;
698
699         dbg("%s", __func__);
700
701         /* register with usb-serial */
702         retval = usb_serial_register(&ssu100_device);
703
704         if (retval)
705                 goto failed_usb_sio_register;
706
707         retval = usb_register(&ssu100_driver);
708         if (retval)
709                 goto failed_usb_register;
710
711         printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
712                DRIVER_DESC "\n");
713
714         return 0;
715
716 failed_usb_register:
717         usb_serial_deregister(&ssu100_device);
718 failed_usb_sio_register:
719         return retval;
720 }
721
722 static void __exit ssu100_exit(void)
723 {
724         usb_deregister(&ssu100_driver);
725         usb_serial_deregister(&ssu100_device);
726 }
727
728 module_init(ssu100_init);
729 module_exit(ssu100_exit);
730
731 MODULE_DESCRIPTION(DRIVER_DESC);
732 MODULE_LICENSE("GPL");
733
734 module_param(debug, bool, S_IRUGO | S_IWUSR);
735 MODULE_PARM_DESC(debug, "Debug enabled or not");