2 * Prolific PL2303 USB to serial adaptor driver
4 * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2003 IBM Corp.
7 * Original driver for 2.2.x by anonymous
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * See Documentation/usb/usb-serial.txt for more information on using this driver
17 * allowed driver to work properly if there is no tty assigned to a port
18 * (this happens for serial console devices.)
21 * Added RTS and DTR line control. Thanks to joe@bndlg.de for parts of it.
24 * Added break support.
27 * fixed oops in write_bulk_callback.
30 * reworked buffer logic to be like other usb-serial drivers. Hopefully
31 * removing some reported problems.
34 * finished porting to 2.4 format.
38 #include <linux/config.h>
39 #include <linux/kernel.h>
40 #include <linux/errno.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/tty.h>
44 #include <linux/tty_driver.h>
45 #include <linux/tty_flip.h>
46 #include <linux/serial.h>
47 #include <linux/module.h>
48 #include <linux/moduleparam.h>
49 #include <linux/spinlock.h>
50 #include <asm/uaccess.h>
51 #include <linux/usb.h>
53 #ifdef CONFIG_USB_SERIAL_DEBUG
59 #include "usb-serial.h"
65 #define DRIVER_VERSION "v0.10"
66 #define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver"
70 static struct usb_device_id id_table [] = {
71 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
72 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
73 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
74 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
75 { USB_DEVICE(ATEN_VENDOR_ID2, ATEN_PRODUCT_ID) },
76 { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) },
77 { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID) },
78 { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) },
79 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) },
80 { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) },
81 { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) },
82 { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) },
83 { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) },
84 { USB_DEVICE(ALCATEL_VENDOR_ID, ALCATEL_PRODUCT_ID) },
85 { } /* Terminating entry */
88 MODULE_DEVICE_TABLE (usb, id_table);
90 static struct usb_driver pl2303_driver = {
93 .probe = usb_serial_probe,
94 .disconnect = usb_serial_disconnect,
98 #define SET_LINE_REQUEST_TYPE 0x21
99 #define SET_LINE_REQUEST 0x20
101 #define SET_CONTROL_REQUEST_TYPE 0x21
102 #define SET_CONTROL_REQUEST 0x22
103 #define CONTROL_DTR 0x01
104 #define CONTROL_RTS 0x02
106 #define BREAK_REQUEST_TYPE 0x21
107 #define BREAK_REQUEST 0x23
108 #define BREAK_ON 0xffff
109 #define BREAK_OFF 0x0000
111 #define GET_LINE_REQUEST_TYPE 0xa1
112 #define GET_LINE_REQUEST 0x21
114 #define VENDOR_WRITE_REQUEST_TYPE 0x40
115 #define VENDOR_WRITE_REQUEST 0x01
117 #define VENDOR_READ_REQUEST_TYPE 0xc0
118 #define VENDOR_READ_REQUEST 0x01
120 #define UART_STATE 0x08
121 #define UART_STATE_TRANSIENT_MASK 0x74
122 #define UART_DCD 0x01
123 #define UART_DSR 0x02
124 #define UART_BREAK_ERROR 0x04
125 #define UART_RING 0x08
126 #define UART_FRAME_ERROR 0x10
127 #define UART_PARITY_ERROR 0x20
128 #define UART_OVERRUN_ERROR 0x40
129 #define UART_CTS 0x80
131 /* function prototypes for a PL2303 serial converter */
132 static int pl2303_open (struct usb_serial_port *port, struct file *filp);
133 static void pl2303_close (struct usb_serial_port *port, struct file *filp);
134 static void pl2303_set_termios (struct usb_serial_port *port,
135 struct termios *old);
136 static int pl2303_ioctl (struct usb_serial_port *port, struct file *file,
137 unsigned int cmd, unsigned long arg);
138 static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs);
139 static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
140 static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
141 static int pl2303_write (struct usb_serial_port *port, int from_user,
142 const unsigned char *buf, int count);
143 static void pl2303_break_ctl(struct usb_serial_port *port,int break_state);
144 static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file);
145 static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
146 unsigned int set, unsigned int clear);
147 static int pl2303_startup (struct usb_serial *serial);
148 static void pl2303_shutdown (struct usb_serial *serial);
151 /* All of the device info needed for the PL2303 SIO serial converter */
152 static struct usb_serial_device_type pl2303_device = {
153 .owner = THIS_MODULE,
155 .id_table = id_table,
156 .num_interrupt_in = NUM_DONT_CARE,
161 .close = pl2303_close,
162 .write = pl2303_write,
163 .ioctl = pl2303_ioctl,
164 .break_ctl = pl2303_break_ctl,
165 .set_termios = pl2303_set_termios,
166 .tiocmget = pl2303_tiocmget,
167 .tiocmset = pl2303_tiocmset,
168 .read_bulk_callback = pl2303_read_bulk_callback,
169 .read_int_callback = pl2303_read_int_callback,
170 .write_bulk_callback = pl2303_write_bulk_callback,
171 .attach = pl2303_startup,
172 .shutdown = pl2303_shutdown,
175 struct pl2303_private {
177 wait_queue_head_t delta_msr_wait;
180 u8 termios_initialized;
184 static int pl2303_startup (struct usb_serial *serial)
186 struct pl2303_private *priv;
189 for (i = 0; i < serial->num_ports; ++i) {
190 priv = kmalloc (sizeof (struct pl2303_private), GFP_KERNEL);
193 memset (priv, 0x00, sizeof (struct pl2303_private));
194 spin_lock_init(&priv->lock);
195 init_waitqueue_head(&priv->delta_msr_wait);
196 usb_set_serial_port_data(serial->port[i], priv);
201 static int set_control_lines (struct usb_device *dev, u8 value)
205 retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0),
206 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
207 value, 0, NULL, 0, 100);
208 dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval);
212 static int pl2303_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
216 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
221 if (port->write_urb->status == -EINPROGRESS) {
222 dbg("%s - already writing", __FUNCTION__);
226 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
228 if (copy_from_user (port->write_urb->transfer_buffer, buf, count))
231 memcpy (port->write_urb->transfer_buffer, buf, count);
234 usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
236 port->write_urb->transfer_buffer_length = count;
237 port->write_urb->dev = port->serial->dev;
238 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
240 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
249 static void pl2303_set_termios (struct usb_serial_port *port, struct termios *old_termios)
251 struct usb_serial *serial = port->serial;
252 struct pl2303_private *priv = usb_get_serial_port_data(port);
260 dbg("%s - port %d", __FUNCTION__, port->number);
262 if ((!port->tty) || (!port->tty->termios)) {
263 dbg("%s - no tty structures", __FUNCTION__);
267 spin_lock_irqsave(&priv->lock, flags);
268 if (!priv->termios_initialized) {
269 *(port->tty->termios) = tty_std_termios;
270 port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
271 priv->termios_initialized = 1;
273 spin_unlock_irqrestore(&priv->lock, flags);
275 cflag = port->tty->termios->c_cflag;
276 /* check that they really want us to change something */
278 if ((cflag == old_termios->c_cflag) &&
279 (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
280 dbg("%s - nothing to change...", __FUNCTION__);
285 buf = kmalloc (7, GFP_KERNEL);
287 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
290 memset (buf, 0x00, 0x07);
292 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
293 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
295 dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
296 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
300 switch (cflag & CSIZE) {
301 case CS5: buf[6] = 5; break;
302 case CS6: buf[6] = 6; break;
303 case CS7: buf[6] = 7; break;
305 case CS8: buf[6] = 8; break;
307 dbg("%s - data bits = %d", __FUNCTION__, buf[6]);
311 switch (cflag & CBAUD) {
312 case B0: baud = 0; break;
313 case B75: baud = 75; break;
314 case B150: baud = 150; break;
315 case B300: baud = 300; break;
316 case B600: baud = 600; break;
317 case B1200: baud = 1200; break;
318 case B1800: baud = 1800; break;
319 case B2400: baud = 2400; break;
320 case B4800: baud = 4800; break;
321 case B9600: baud = 9600; break;
322 case B19200: baud = 19200; break;
323 case B38400: baud = 38400; break;
324 case B57600: baud = 57600; break;
325 case B115200: baud = 115200; break;
326 case B230400: baud = 230400; break;
327 case B460800: baud = 460800; break;
329 dev_err(&port->dev, "pl2303 driver does not support the baudrate requested (fix it)\n");
332 dbg("%s - baud = %d", __FUNCTION__, baud);
334 buf[0] = baud & 0xff;
335 buf[1] = (baud >> 8) & 0xff;
336 buf[2] = (baud >> 16) & 0xff;
337 buf[3] = (baud >> 24) & 0xff;
340 /* For reference buf[4]=0 is 1 stop bits */
341 /* For reference buf[4]=1 is 1.5 stop bits */
342 /* For reference buf[4]=2 is 2 stop bits */
343 if (cflag & CSTOPB) {
345 dbg("%s - stop bits = 2", __FUNCTION__);
348 dbg("%s - stop bits = 1", __FUNCTION__);
351 if (cflag & PARENB) {
352 /* For reference buf[5]=0 is none parity */
353 /* For reference buf[5]=1 is odd parity */
354 /* For reference buf[5]=2 is even parity */
355 /* For reference buf[5]=3 is mark parity */
356 /* For reference buf[5]=4 is space parity */
357 if (cflag & PARODD) {
359 dbg("%s - parity = odd", __FUNCTION__);
362 dbg("%s - parity = even", __FUNCTION__);
366 dbg("%s - parity = none", __FUNCTION__);
369 i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
370 SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
372 dbg ("0x21:0x20:0:0 %d", i);
374 /* change control lines if we are switching to or from B0 */
375 spin_lock_irqsave(&priv->lock, flags);
376 control = priv->line_control;
377 if ((cflag & CBAUD) == B0)
378 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
380 priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
381 if (control != priv->line_control) {
382 control = priv->line_control;
383 spin_unlock_irqrestore(&priv->lock, flags);
384 set_control_lines(serial->dev, control);
386 spin_unlock_irqrestore(&priv->lock, flags);
389 buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0;
391 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
392 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
394 dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
395 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
397 if (cflag & CRTSCTS) {
398 i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
399 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
400 0x0, 0x41, NULL, 0, 100);
401 dbg ("0x40:0x1:0x0:0x41 %d", i);
408 static int pl2303_open (struct usb_serial_port *port, struct file *filp)
410 struct termios tmp_termios;
411 struct usb_serial *serial = port->serial;
415 dbg("%s - port %d", __FUNCTION__, port->number);
417 usb_clear_halt(serial->dev, port->write_urb->pipe);
418 usb_clear_halt(serial->dev, port->read_urb->pipe);
420 buf = kmalloc(10, GFP_KERNEL);
424 #define FISH(a,b,c,d) \
425 result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \
426 b, a, c, d, buf, 1, 100); \
427 dbg("0x%x:0x%x:0x%x:0x%x %d - %x",a,b,c,d,result,buf[0]);
429 #define SOUP(a,b,c,d) \
430 result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \
431 b, a, c, d, NULL, 0, 100); \
432 dbg("0x%x:0x%x:0x%x:0x%x %d",a,b,c,d,result);
434 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
435 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0);
436 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
437 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
438 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
439 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1);
440 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
441 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
447 pl2303_set_termios (port, &tmp_termios);
450 //FIXME: need to assert RTS and DTR if CRTSCTS off
452 dbg("%s - submitting read urb", __FUNCTION__);
453 port->read_urb->dev = serial->dev;
454 result = usb_submit_urb (port->read_urb, GFP_KERNEL);
456 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
457 pl2303_close (port, NULL);
461 dbg("%s - submitting interrupt urb", __FUNCTION__);
462 port->interrupt_in_urb->dev = serial->dev;
463 result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL);
465 dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", __FUNCTION__, result);
466 pl2303_close (port, NULL);
473 static void pl2303_close (struct usb_serial_port *port, struct file *filp)
475 struct pl2303_private *priv;
477 unsigned int c_cflag;
480 dbg("%s - port %d", __FUNCTION__, port->number);
482 /* shutdown our urbs */
483 dbg("%s - shutting down urbs", __FUNCTION__);
484 result = usb_unlink_urb (port->write_urb);
486 dbg("%s - usb_unlink_urb (write_urb)"
487 " failed with reason: %d", __FUNCTION__,
490 result = usb_unlink_urb (port->read_urb);
492 dbg("%s - usb_unlink_urb (read_urb) "
493 "failed with reason: %d", __FUNCTION__,
496 result = usb_unlink_urb (port->interrupt_in_urb);
498 dbg("%s - usb_unlink_urb (interrupt_in_urb)"
499 " failed with reason: %d", __FUNCTION__,
503 c_cflag = port->tty->termios->c_cflag;
504 if (c_cflag & HUPCL) {
505 /* drop DTR and RTS */
506 priv = usb_get_serial_port_data(port);
507 spin_lock_irqsave(&priv->lock, flags);
508 priv->line_control = 0;
509 spin_unlock_irqrestore (&priv->lock, flags);
510 set_control_lines (port->serial->dev, 0);
516 static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
517 unsigned int set, unsigned int clear)
519 struct pl2303_private *priv = usb_get_serial_port_data(port);
523 spin_lock_irqsave (&priv->lock, flags);
525 priv->line_control |= CONTROL_RTS;
527 priv->line_control |= CONTROL_DTR;
528 if (clear & TIOCM_RTS)
529 priv->line_control &= ~CONTROL_RTS;
530 if (clear & TIOCM_DTR)
531 priv->line_control &= ~CONTROL_DTR;
532 control = priv->line_control;
533 spin_unlock_irqrestore (&priv->lock, flags);
535 return set_control_lines (port->serial->dev, control);
538 static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file)
540 struct pl2303_private *priv = usb_get_serial_port_data(port);
546 dbg("%s (%d)", __FUNCTION__, port->number);
548 spin_lock_irqsave (&priv->lock, flags);
549 mcr = priv->line_control;
550 status = priv->line_status;
551 spin_unlock_irqrestore (&priv->lock, flags);
553 result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0)
554 | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0)
555 | ((status & UART_CTS) ? TIOCM_CTS : 0)
556 | ((status & UART_DSR) ? TIOCM_DSR : 0)
557 | ((status & UART_RING) ? TIOCM_RI : 0)
558 | ((status & UART_DCD) ? TIOCM_CD : 0);
560 dbg("%s - result = %x", __FUNCTION__, result);
565 static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
567 struct pl2303_private *priv = usb_get_serial_port_data(port);
569 unsigned int prevstatus;
571 unsigned int changed;
573 spin_lock_irqsave (&priv->lock, flags);
574 prevstatus = priv->line_status;
575 spin_unlock_irqrestore (&priv->lock, flags);
578 interruptible_sleep_on(&priv->delta_msr_wait);
579 /* see if a signal did it */
580 if (signal_pending(current))
583 spin_lock_irqsave (&priv->lock, flags);
584 status = priv->line_status;
585 spin_unlock_irqrestore (&priv->lock, flags);
587 changed=prevstatus^status;
589 if (((arg & TIOCM_RNG) && (changed & UART_RING)) ||
590 ((arg & TIOCM_DSR) && (changed & UART_DSR)) ||
591 ((arg & TIOCM_CD) && (changed & UART_DCD)) ||
592 ((arg & TIOCM_CTS) && (changed & UART_CTS)) ) {
601 static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
603 dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
607 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
608 return wait_modem_info(port, arg);
611 dbg("%s not supported = 0x%04x", __FUNCTION__, cmd);
618 static void pl2303_break_ctl (struct usb_serial_port *port, int break_state)
620 struct usb_serial *serial = port->serial;
624 dbg("%s - port %d", __FUNCTION__, port->number);
626 if (break_state == 0)
630 dbg("%s - turning break %s", state==BREAK_OFF ? "off" : "on", __FUNCTION__);
632 result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
633 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
636 dbg("%s - error sending break = %d", __FUNCTION__, result);
640 static void pl2303_shutdown (struct usb_serial *serial)
644 dbg("%s", __FUNCTION__);
646 for (i = 0; i < serial->num_ports; ++i) {
647 kfree (usb_get_serial_port_data(serial->port[i]));
648 usb_set_serial_port_data(serial->port[i], NULL);
653 static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs)
655 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
656 struct pl2303_private *priv = usb_get_serial_port_data(port);
657 unsigned char *data = urb->transfer_buffer;
662 dbg("%s (%d)", __FUNCTION__, port->number);
664 switch (urb->status) {
671 /* this urb is terminated, clean up */
672 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
675 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
680 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
682 if (urb->actual_length < UART_STATE)
685 /* Save off the uart status for others to look at */
686 uart_state = data[UART_STATE];
687 spin_lock_irqsave(&priv->lock, flags);
688 uart_state |= (priv->line_status & UART_STATE_TRANSIENT_MASK);
689 priv->line_status = uart_state;
690 spin_unlock_irqrestore(&priv->lock, flags);
693 status = usb_submit_urb (urb, GFP_ATOMIC);
695 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
696 __FUNCTION__, status);
700 static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
702 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
703 struct pl2303_private *priv = usb_get_serial_port_data(port);
704 struct tty_struct *tty;
705 unsigned char *data = urb->transfer_buffer;
712 dbg("%s - port %d", __FUNCTION__, port->number);
715 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
716 if (!port->open_count) {
717 dbg("%s - port is closed, exiting.", __FUNCTION__);
720 if (urb->status == -EPROTO) {
721 /* PL2303 mysteriously fails with -EPROTO reschedule the read */
722 dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__);
724 urb->dev = port->serial->dev;
725 result = usb_submit_urb(urb, GFP_ATOMIC);
727 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
730 dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
734 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
736 /* get tty_flag from status */
737 tty_flag = TTY_NORMAL;
739 spin_lock_irqsave(&priv->lock, flags);
740 status = priv->line_status;
741 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
742 spin_unlock_irqrestore(&priv->lock, flags);
743 wake_up_interruptible (&priv->delta_msr_wait);
745 /* break takes precedence over parity, */
746 /* which takes precedence over framing errors */
747 if (status & UART_BREAK_ERROR )
748 tty_flag = TTY_BREAK;
749 else if (status & UART_PARITY_ERROR)
750 tty_flag = TTY_PARITY;
751 else if (status & UART_FRAME_ERROR)
752 tty_flag = TTY_FRAME;
753 dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag);
756 if (tty && urb->actual_length) {
757 /* overrun is special, not associated with a char */
758 if (status & UART_OVERRUN_ERROR)
759 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
761 for (i = 0; i < urb->actual_length; ++i) {
762 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
763 tty_flip_buffer_push(tty);
765 tty_insert_flip_char (tty, data[i], tty_flag);
767 tty_flip_buffer_push (tty);
770 /* Schedule the next read _if_ we are still open */
771 if (port->open_count) {
772 urb->dev = port->serial->dev;
773 result = usb_submit_urb(urb, GFP_ATOMIC);
775 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
783 static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
785 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
788 dbg("%s - port %d", __FUNCTION__, port->number);
791 /* error in the urb, so we have to resubmit it */
792 dbg("%s - Overflow in write", __FUNCTION__);
793 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
794 port->write_urb->transfer_buffer_length = 1;
795 port->write_urb->dev = port->serial->dev;
796 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
798 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", __FUNCTION__, result);
803 schedule_work(&port->work);
807 static int __init pl2303_init (void)
810 retval = usb_serial_register(&pl2303_device);
812 goto failed_usb_serial_register;
813 retval = usb_register(&pl2303_driver);
815 goto failed_usb_register;
816 info(DRIVER_DESC " " DRIVER_VERSION);
819 usb_serial_deregister(&pl2303_device);
820 failed_usb_serial_register:
825 static void __exit pl2303_exit (void)
827 usb_deregister (&pl2303_driver);
828 usb_serial_deregister (&pl2303_device);
832 module_init(pl2303_init);
833 module_exit(pl2303_exit);
835 MODULE_DESCRIPTION(DRIVER_DESC);
836 MODULE_LICENSE("GPL");
838 module_param(debug, bool, S_IRUGO | S_IWUSR);
839 MODULE_PARM_DESC(debug, "Debug enabled or not");