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