2 * Prolific PL2303 USB to serial adaptor driver
4 * Copyright (C) 2001-2003 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/spinlock.h>
49 #include <asm/uaccess.h>
50 #include <linux/usb.h>
52 #ifdef CONFIG_USB_SERIAL_DEBUG
58 #include "usb-serial.h"
64 #define DRIVER_VERSION "v0.10"
65 #define DRIVER_DESC "Prolific PL2303 USB to serial adaptor driver"
69 static struct usb_device_id id_table [] = {
70 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
71 { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
72 { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
73 { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
74 { USB_DEVICE(ATEN_VENDOR_ID2, ATEN_PRODUCT_ID) },
75 { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) },
76 { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID) },
77 { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) },
78 { USB_DEVICE(RATOC_VENDOR_ID, RATOC_PRODUCT_ID) },
79 { USB_DEVICE(TRIPP_VENDOR_ID, TRIPP_PRODUCT_ID) },
80 { USB_DEVICE(RADIOSHACK_VENDOR_ID, RADIOSHACK_PRODUCT_ID) },
81 { USB_DEVICE(DCU10_VENDOR_ID, DCU10_PRODUCT_ID) },
82 { USB_DEVICE(SITECOM_VENDOR_ID, SITECOM_PRODUCT_ID) },
83 { } /* Terminating entry */
86 MODULE_DEVICE_TABLE (usb, id_table);
88 static struct usb_driver pl2303_driver = {
91 .probe = usb_serial_probe,
92 .disconnect = usb_serial_disconnect,
96 #define SET_LINE_REQUEST_TYPE 0x21
97 #define SET_LINE_REQUEST 0x20
99 #define SET_CONTROL_REQUEST_TYPE 0x21
100 #define SET_CONTROL_REQUEST 0x22
101 #define CONTROL_DTR 0x01
102 #define CONTROL_RTS 0x02
104 #define BREAK_REQUEST_TYPE 0x21
105 #define BREAK_REQUEST 0x23
106 #define BREAK_ON 0xffff
107 #define BREAK_OFF 0x0000
109 #define GET_LINE_REQUEST_TYPE 0xa1
110 #define GET_LINE_REQUEST 0x21
112 #define VENDOR_WRITE_REQUEST_TYPE 0x40
113 #define VENDOR_WRITE_REQUEST 0x01
115 #define VENDOR_READ_REQUEST_TYPE 0xc0
116 #define VENDOR_READ_REQUEST 0x01
118 #define UART_STATE 0x08
119 #define UART_STATE_TRANSIENT_MASK 0x74
120 #define UART_DCD 0x01
121 #define UART_DSR 0x02
122 #define UART_BREAK_ERROR 0x04
123 #define UART_RING 0x08
124 #define UART_FRAME_ERROR 0x10
125 #define UART_PARITY_ERROR 0x20
126 #define UART_OVERRUN_ERROR 0x40
127 #define UART_CTS 0x80
129 /* function prototypes for a PL2303 serial converter */
130 static int pl2303_open (struct usb_serial_port *port, struct file *filp);
131 static void pl2303_close (struct usb_serial_port *port, struct file *filp);
132 static void pl2303_set_termios (struct usb_serial_port *port,
133 struct termios *old);
134 static int pl2303_ioctl (struct usb_serial_port *port, struct file *file,
135 unsigned int cmd, unsigned long arg);
136 static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs);
137 static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
138 static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
139 static int pl2303_write (struct usb_serial_port *port, int from_user,
140 const unsigned char *buf, int count);
141 static void pl2303_break_ctl(struct usb_serial_port *port,int break_state);
142 static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file);
143 static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
144 unsigned int set, unsigned int clear);
145 static int pl2303_startup (struct usb_serial *serial);
146 static void pl2303_shutdown (struct usb_serial *serial);
149 /* All of the device info needed for the PL2303 SIO serial converter */
150 static struct usb_serial_device_type pl2303_device = {
151 .owner = THIS_MODULE,
153 .id_table = id_table,
154 .num_interrupt_in = NUM_DONT_CARE,
159 .close = pl2303_close,
160 .write = pl2303_write,
161 .ioctl = pl2303_ioctl,
162 .break_ctl = pl2303_break_ctl,
163 .set_termios = pl2303_set_termios,
164 .tiocmget = pl2303_tiocmget,
165 .tiocmset = pl2303_tiocmset,
166 .read_bulk_callback = pl2303_read_bulk_callback,
167 .read_int_callback = pl2303_read_int_callback,
168 .write_bulk_callback = pl2303_write_bulk_callback,
169 .attach = pl2303_startup,
170 .shutdown = pl2303_shutdown,
173 struct pl2303_private {
175 wait_queue_head_t delta_msr_wait;
178 u8 termios_initialized;
182 static int pl2303_startup (struct usb_serial *serial)
184 struct pl2303_private *priv;
187 for (i = 0; i < serial->num_ports; ++i) {
188 priv = kmalloc (sizeof (struct pl2303_private), GFP_KERNEL);
191 memset (priv, 0x00, sizeof (struct pl2303_private));
192 spin_lock_init(&priv->lock);
193 init_waitqueue_head(&priv->delta_msr_wait);
194 usb_set_serial_port_data(serial->port[i], priv);
199 static int set_control_lines (struct usb_device *dev, u8 value)
203 retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0),
204 SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
205 value, 0, NULL, 0, 100);
206 dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval);
210 static int pl2303_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
214 dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
219 if (port->write_urb->status == -EINPROGRESS) {
220 dbg("%s - already writing", __FUNCTION__);
224 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
226 if (copy_from_user (port->write_urb->transfer_buffer, buf, count))
229 memcpy (port->write_urb->transfer_buffer, buf, count);
232 usb_serial_debug_data (__FILE__, __FUNCTION__, count, port->write_urb->transfer_buffer);
234 port->write_urb->transfer_buffer_length = count;
235 port->write_urb->dev = port->serial->dev;
236 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
238 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __FUNCTION__, result);
247 static void pl2303_set_termios (struct usb_serial_port *port, struct termios *old_termios)
249 struct usb_serial *serial = port->serial;
250 struct pl2303_private *priv = usb_get_serial_port_data(port);
258 dbg("%s - port %d", __FUNCTION__, port->number);
260 if ((!port->tty) || (!port->tty->termios)) {
261 dbg("%s - no tty structures", __FUNCTION__);
265 spin_lock_irqsave(&priv->lock, flags);
266 if (!priv->termios_initialized) {
267 *(port->tty->termios) = tty_std_termios;
268 port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
269 priv->termios_initialized = 1;
271 spin_unlock_irqrestore(&priv->lock, flags);
273 cflag = port->tty->termios->c_cflag;
274 /* check that they really want us to change something */
276 if ((cflag == old_termios->c_cflag) &&
277 (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
278 dbg("%s - nothing to change...", __FUNCTION__);
283 buf = kmalloc (7, GFP_KERNEL);
285 dev_err(&port->dev, "%s - out of memory.\n", __FUNCTION__);
288 memset (buf, 0x00, 0x07);
290 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
291 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
293 dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
294 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
298 switch (cflag & CSIZE) {
299 case CS5: buf[6] = 5; break;
300 case CS6: buf[6] = 6; break;
301 case CS7: buf[6] = 7; break;
303 case CS8: buf[6] = 8; break;
305 dbg("%s - data bits = %d", __FUNCTION__, buf[6]);
309 switch (cflag & CBAUD) {
310 case B0: baud = 0; break;
311 case B75: baud = 75; break;
312 case B150: baud = 150; break;
313 case B300: baud = 300; break;
314 case B600: baud = 600; break;
315 case B1200: baud = 1200; break;
316 case B1800: baud = 1800; break;
317 case B2400: baud = 2400; break;
318 case B4800: baud = 4800; break;
319 case B9600: baud = 9600; break;
320 case B19200: baud = 19200; break;
321 case B38400: baud = 38400; break;
322 case B57600: baud = 57600; break;
323 case B115200: baud = 115200; break;
324 case B230400: baud = 230400; break;
325 case B460800: baud = 460800; break;
327 dev_err(&port->dev, "pl2303 driver does not support the baudrate requested (fix it)\n");
330 dbg("%s - baud = %d", __FUNCTION__, baud);
332 buf[0] = baud & 0xff;
333 buf[1] = (baud >> 8) & 0xff;
334 buf[2] = (baud >> 16) & 0xff;
335 buf[3] = (baud >> 24) & 0xff;
338 /* For reference buf[4]=0 is 1 stop bits */
339 /* For reference buf[4]=1 is 1.5 stop bits */
340 /* For reference buf[4]=2 is 2 stop bits */
341 if (cflag & CSTOPB) {
343 dbg("%s - stop bits = 2", __FUNCTION__);
346 dbg("%s - stop bits = 1", __FUNCTION__);
349 if (cflag & PARENB) {
350 /* For reference buf[5]=0 is none parity */
351 /* For reference buf[5]=1 is odd parity */
352 /* For reference buf[5]=2 is even parity */
353 /* For reference buf[5]=3 is mark parity */
354 /* For reference buf[5]=4 is space parity */
355 if (cflag & PARODD) {
357 dbg("%s - parity = odd", __FUNCTION__);
360 dbg("%s - parity = even", __FUNCTION__);
364 dbg("%s - parity = none", __FUNCTION__);
367 i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
368 SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE,
370 dbg ("0x21:0x20:0:0 %d", i);
372 /* change control lines if we are switching to or from B0 */
373 spin_lock_irqsave(&priv->lock, flags);
374 control = priv->line_control;
375 if ((cflag & CBAUD) == B0)
376 priv->line_control &= ~(CONTROL_DTR | CONTROL_RTS);
378 priv->line_control |= (CONTROL_DTR | CONTROL_RTS);
379 if (control != priv->line_control) {
380 control = priv->line_control;
381 spin_unlock_irqrestore(&priv->lock, flags);
382 set_control_lines(serial->dev, control);
384 spin_unlock_irqrestore(&priv->lock, flags);
387 buf[0] = buf[1] = buf[2] = buf[3] = buf[4] = buf[5] = buf[6] = 0;
389 i = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
390 GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE,
392 dbg ("0xa1:0x21:0:0 %d - %x %x %x %x %x %x %x", i,
393 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6]);
395 if (cflag & CRTSCTS) {
396 i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
397 VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
398 0x0, 0x41, NULL, 0, 100);
399 dbg ("0x40:0x1:0x0:0x41 %d", i);
406 static int pl2303_open (struct usb_serial_port *port, struct file *filp)
408 struct termios tmp_termios;
409 struct usb_serial *serial = port->serial;
413 if (port_paranoia_check (port, __FUNCTION__))
416 dbg("%s - port %d", __FUNCTION__, port->number);
418 usb_clear_halt(serial->dev, port->write_urb->pipe);
419 usb_clear_halt(serial->dev, port->read_urb->pipe);
421 buf = kmalloc(10, GFP_KERNEL);
425 #define FISH(a,b,c,d) \
426 result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \
427 b, a, c, d, buf, 1, 100); \
428 dbg("0x%x:0x%x:0x%x:0x%x %d - %x",a,b,c,d,result,buf[0]);
430 #define SOUP(a,b,c,d) \
431 result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \
432 b, a, c, d, NULL, 0, 100); \
433 dbg("0x%x:0x%x:0x%x:0x%x %d",a,b,c,d,result);
435 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
436 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0);
437 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
438 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
439 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
440 SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1);
441 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
442 FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
448 pl2303_set_termios (port, &tmp_termios);
451 //FIXME: need to assert RTS and DTR if CRTSCTS off
453 dbg("%s - submitting read urb", __FUNCTION__);
454 port->read_urb->dev = serial->dev;
455 result = usb_submit_urb (port->read_urb, GFP_KERNEL);
457 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __FUNCTION__, result);
458 pl2303_close (port, NULL);
462 dbg("%s - submitting interrupt urb", __FUNCTION__);
463 port->interrupt_in_urb->dev = serial->dev;
464 result = usb_submit_urb (port->interrupt_in_urb, GFP_KERNEL);
466 dev_err(&port->dev, "%s - failed submitting interrupt urb, error %d\n", __FUNCTION__, result);
467 pl2303_close (port, NULL);
474 static void pl2303_close (struct usb_serial_port *port, struct file *filp)
476 struct usb_serial *serial;
477 struct pl2303_private *priv;
479 unsigned int c_cflag;
482 if (port_paranoia_check (port, __FUNCTION__))
484 serial = get_usb_serial (port, __FUNCTION__);
488 dbg("%s - port %d", __FUNCTION__, port->number);
490 /* shutdown our urbs */
491 dbg("%s - shutting down urbs", __FUNCTION__);
492 result = usb_unlink_urb (port->write_urb);
494 dbg("%s - usb_unlink_urb (write_urb)"
495 " failed with reason: %d", __FUNCTION__,
498 result = usb_unlink_urb (port->read_urb);
500 dbg("%s - usb_unlink_urb (read_urb) "
501 "failed with reason: %d", __FUNCTION__,
504 result = usb_unlink_urb (port->interrupt_in_urb);
506 dbg("%s - usb_unlink_urb (interrupt_in_urb)"
507 " failed with reason: %d", __FUNCTION__,
511 c_cflag = port->tty->termios->c_cflag;
512 if (c_cflag & HUPCL) {
513 /* drop DTR and RTS */
514 priv = usb_get_serial_port_data(port);
515 spin_lock_irqsave(&priv->lock, flags);
516 priv->line_control = 0;
517 spin_unlock_irqrestore (&priv->lock, flags);
518 set_control_lines (port->serial->dev, 0);
524 static int pl2303_tiocmset (struct usb_serial_port *port, struct file *file,
525 unsigned int set, unsigned int clear)
527 struct pl2303_private *priv = usb_get_serial_port_data(port);
531 spin_lock_irqsave (&priv->lock, flags);
533 priv->line_control |= CONTROL_RTS;
535 priv->line_control |= CONTROL_DTR;
536 if (clear & TIOCM_RTS)
537 priv->line_control &= ~CONTROL_RTS;
538 if (clear & TIOCM_DTR)
539 priv->line_control &= ~CONTROL_DTR;
540 control = priv->line_control;
541 spin_unlock_irqrestore (&priv->lock, flags);
543 return set_control_lines (port->serial->dev, control);
546 static int pl2303_tiocmget (struct usb_serial_port *port, struct file *file)
548 struct pl2303_private *priv = usb_get_serial_port_data(port);
554 dbg("%s (%d)", __FUNCTION__, port->number);
556 spin_lock_irqsave (&priv->lock, flags);
557 mcr = priv->line_control;
558 status = priv->line_status;
559 spin_unlock_irqrestore (&priv->lock, flags);
561 result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0)
562 | ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0)
563 | ((status & UART_CTS) ? TIOCM_CTS : 0)
564 | ((status & UART_DSR) ? TIOCM_DSR : 0)
565 | ((status & UART_RING) ? TIOCM_RI : 0)
566 | ((status & UART_DCD) ? TIOCM_CD : 0);
568 dbg("%s - result = %x", __FUNCTION__, result);
573 static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
575 struct pl2303_private *priv = usb_get_serial_port_data(port);
577 unsigned int prevstatus;
579 unsigned int changed;
581 spin_lock_irqsave (&priv->lock, flags);
582 prevstatus = priv->line_status;
583 spin_unlock_irqrestore (&priv->lock, flags);
586 interruptible_sleep_on(&priv->delta_msr_wait);
587 /* see if a signal did it */
588 if (signal_pending(current))
591 spin_lock_irqsave (&priv->lock, flags);
592 status = priv->line_status;
593 spin_unlock_irqrestore (&priv->lock, flags);
595 changed=prevstatus^status;
597 if (((arg & TIOCM_RNG) && (changed & UART_RING)) ||
598 ((arg & TIOCM_DSR) && (changed & UART_DSR)) ||
599 ((arg & TIOCM_CD) && (changed & UART_DCD)) ||
600 ((arg & TIOCM_CTS) && (changed & UART_CTS)) ) {
609 static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
611 dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
615 dbg("%s (%d) TIOCMIWAIT", __FUNCTION__, port->number);
616 return wait_modem_info(port, arg);
619 dbg("%s not supported = 0x%04x", __FUNCTION__, cmd);
626 static void pl2303_break_ctl (struct usb_serial_port *port, int break_state)
628 struct usb_serial *serial = port->serial;
632 dbg("%s - port %d", __FUNCTION__, port->number);
634 if (break_state == 0)
638 dbg("%s - turning break %s", state==BREAK_OFF ? "off" : "on", __FUNCTION__);
640 result = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
641 BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
644 dbg("%s - error sending break = %d", __FUNCTION__, result);
648 static void pl2303_shutdown (struct usb_serial *serial)
652 dbg("%s", __FUNCTION__);
654 for (i = 0; i < serial->num_ports; ++i) {
655 kfree (usb_get_serial_port_data(serial->port[i]));
656 usb_set_serial_port_data(serial->port[i], NULL);
661 static void pl2303_read_int_callback (struct urb *urb, struct pt_regs *regs)
663 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
664 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
665 struct pl2303_private *priv = usb_get_serial_port_data(port);
666 unsigned char *data = urb->transfer_buffer;
671 dbg("%s (%d)", __FUNCTION__, port->number);
673 switch (urb->status) {
680 /* this urb is terminated, clean up */
681 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status);
684 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status);
692 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, urb->transfer_buffer);
694 if (urb->actual_length < UART_STATE)
697 /* Save off the uart status for others to look at */
698 uart_state = data[UART_STATE];
699 spin_lock_irqsave(&priv->lock, flags);
700 uart_state |= (priv->line_status & UART_STATE_TRANSIENT_MASK);
701 priv->line_status = uart_state;
702 spin_unlock_irqrestore(&priv->lock, flags);
705 status = usb_submit_urb (urb, GFP_ATOMIC);
707 dev_err(&urb->dev->dev, "%s - usb_submit_urb failed with result %d\n",
708 __FUNCTION__, status);
712 static void pl2303_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
714 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
715 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
716 struct pl2303_private *priv = usb_get_serial_port_data(port);
717 struct tty_struct *tty;
718 unsigned char *data = urb->transfer_buffer;
725 if (port_paranoia_check (port, __FUNCTION__))
728 dbg("%s - port %d", __FUNCTION__, port->number);
731 dbg("%s - bad serial pointer, exiting", __FUNCTION__);
736 dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
737 if (!port->open_count) {
738 dbg("%s - port is closed, exiting.", __FUNCTION__);
741 if (urb->status == -EPROTO) {
742 /* PL2303 mysteriously fails with -EPROTO reschedule the read */
743 dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__);
745 urb->dev = serial->dev;
746 result = usb_submit_urb(urb, GFP_ATOMIC);
748 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
751 dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
755 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
757 /* get tty_flag from status */
758 tty_flag = TTY_NORMAL;
760 spin_lock_irqsave(&priv->lock, flags);
761 status = priv->line_status;
762 priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
763 spin_unlock_irqrestore(&priv->lock, flags);
764 wake_up_interruptible (&priv->delta_msr_wait);
766 /* break takes precedence over parity, */
767 /* which takes precedence over framing errors */
768 if (status & UART_BREAK_ERROR )
769 tty_flag = TTY_BREAK;
770 else if (status & UART_PARITY_ERROR)
771 tty_flag = TTY_PARITY;
772 else if (status & UART_FRAME_ERROR)
773 tty_flag = TTY_FRAME;
774 dbg("%s - tty_flag = %d", __FUNCTION__, tty_flag);
777 if (tty && urb->actual_length) {
778 /* overrun is special, not associated with a char */
779 if (status & UART_OVERRUN_ERROR)
780 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
782 for (i = 0; i < urb->actual_length; ++i) {
783 if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
784 tty_flip_buffer_push(tty);
786 tty_insert_flip_char (tty, data[i], tty_flag);
788 tty_flip_buffer_push (tty);
791 /* Schedule the next read _if_ we are still open */
792 if (port->open_count) {
793 urb->dev = serial->dev;
794 result = usb_submit_urb(urb, GFP_ATOMIC);
796 dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __FUNCTION__, result);
804 static void pl2303_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
806 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
809 if (port_paranoia_check (port, __FUNCTION__))
812 dbg("%s - port %d", __FUNCTION__, port->number);
815 /* error in the urb, so we have to resubmit it */
816 if (serial_paranoia_check (port->serial, __FUNCTION__)) {
819 dbg("%s - Overflow in write", __FUNCTION__);
820 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
821 port->write_urb->transfer_buffer_length = 1;
822 port->write_urb->dev = port->serial->dev;
823 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
825 dev_err(&urb->dev->dev, "%s - failed resubmitting write urb, error %d\n", __FUNCTION__, result);
830 schedule_work(&port->work);
834 static int __init pl2303_init (void)
837 retval = usb_serial_register(&pl2303_device);
839 goto failed_usb_serial_register;
840 retval = usb_register(&pl2303_driver);
842 goto failed_usb_register;
843 info(DRIVER_DESC " " DRIVER_VERSION);
846 usb_serial_deregister(&pl2303_device);
847 failed_usb_serial_register:
852 static void __exit pl2303_exit (void)
854 usb_deregister (&pl2303_driver);
855 usb_serial_deregister (&pl2303_device);
859 module_init(pl2303_init);
860 module_exit(pl2303_exit);
862 MODULE_DESCRIPTION(DRIVER_DESC);
863 MODULE_LICENSE("GPL");
865 MODULE_PARM(debug, "i");
866 MODULE_PARM_DESC(debug, "Debug enabled or not");