patch-2.4.20 linux-2.4.20/drivers/usb/serial/pl2303.c
Next file: linux-2.4.20/drivers/usb/serial/pl2303.h
Previous file: linux-2.4.20/drivers/usb/serial/omninet.c
Back to the patch index
Back to the overall index
- Lines: 560
- Date:
Thu Nov 28 15:53:15 2002
- Orig file:
linux-2.4.19/drivers/usb/serial/pl2303.c
- Orig date:
Fri Aug 2 17:39:45 2002
diff -urN linux-2.4.19/drivers/usb/serial/pl2303.c linux-2.4.20/drivers/usb/serial/pl2303.c
@@ -1,7 +1,7 @@
/*
* Prolific PL2303 USB to serial adaptor driver
*
- * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
+ * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com)
*
* Original driver for 2.2.x by anonymous
*
@@ -32,19 +32,16 @@
#include <linux/config.h>
#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/signal.h>
#include <linux/errno.h>
-#include <linux/poll.h>
#include <linux/init.h>
#include <linux/slab.h>
-#include <linux/fcntl.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/serial.h>
#include <linux/module.h>
#include <linux/spinlock.h>
+#include <asm/uaccess.h>
#include <linux/usb.h>
#ifdef CONFIG_USB_SERIAL_DEBUG
@@ -64,11 +61,14 @@
-static __devinitdata struct usb_device_id id_table [] = {
+static struct usb_device_id id_table [] = {
{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID) },
{ USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_RSAQ2) },
{ USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
{ USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID) },
+ { USB_DEVICE(ELCOM_VENDOR_ID, ELCOM_PRODUCT_ID) },
+ { USB_DEVICE(ITEGNO_VENDOR_ID, ITEGNO_PRODUCT_ID) },
+ { USB_DEVICE(MA620_VENDOR_ID, MA620_PRODUCT_ID) },
{ } /* Terminating entry */
};
@@ -116,26 +116,24 @@
/* All of the device info needed for the PL2303 SIO serial converter */
static struct usb_serial_device_type pl2303_device = {
- name: "PL-2303",
- id_table: id_table,
- needs_interrupt_in: DONT_CARE, /* this device must have an interrupt in endpoint */
- needs_bulk_in: MUST_HAVE, /* this device must have a bulk in endpoint */
- needs_bulk_out: MUST_HAVE, /* this device must have a bulk out endpoint */
- num_interrupt_in: NUM_DONT_CARE,
- num_bulk_in: 1,
- num_bulk_out: 1,
- num_ports: 1,
- open: pl2303_open,
- close: pl2303_close,
- write: pl2303_write,
- ioctl: pl2303_ioctl,
- break_ctl: pl2303_break_ctl,
- set_termios: pl2303_set_termios,
- read_bulk_callback: pl2303_read_bulk_callback,
- read_int_callback: pl2303_read_int_callback,
- write_bulk_callback: pl2303_write_bulk_callback,
- startup: pl2303_startup,
- shutdown: pl2303_shutdown,
+ .owner = THIS_MODULE,
+ .name = "PL-2303",
+ .id_table = id_table,
+ .num_interrupt_in = NUM_DONT_CARE,
+ .num_bulk_in = 1,
+ .num_bulk_out = 1,
+ .num_ports = 1,
+ .open = pl2303_open,
+ .close = pl2303_close,
+ .write = pl2303_write,
+ .ioctl = pl2303_ioctl,
+ .break_ctl = pl2303_break_ctl,
+ .set_termios = pl2303_set_termios,
+ .read_bulk_callback = pl2303_read_bulk_callback,
+ .read_int_callback = pl2303_read_int_callback,
+ .write_bulk_callback = pl2303_write_bulk_callback,
+ .startup = pl2303_startup,
+ .shutdown = pl2303_shutdown,
};
struct pl2303_private {
@@ -166,7 +164,7 @@
retval = usb_control_msg (dev, usb_sndctrlpipe (dev, 0),
SET_CONTROL_REQUEST, SET_CONTROL_REQUEST_TYPE,
value, 0, NULL, 0, 100);
- dbg (__FUNCTION__" - value = %d, retval = %d", value, retval);
+ dbg("%s - value = %d, retval = %d", __FUNCTION__, value, retval);
return retval;
}
@@ -174,15 +172,10 @@
{
int result;
- dbg (__FUNCTION__ " - port %d, %d bytes", port->number, count);
-
- if (!port->tty) {
- err (__FUNCTION__ " - no tty???");
- return 0;
- }
+ dbg("%s - port %d, %d bytes", __FUNCTION__, port->number, count);
if (port->write_urb->status == -EINPROGRESS) {
- dbg (__FUNCTION__ " - already writing");
+ dbg("%s - already writing", __FUNCTION__);
return 0;
}
@@ -200,7 +193,7 @@
port->write_urb->dev = port->serial->dev;
result = usb_submit_urb (port->write_urb);
if (result)
- err(__FUNCTION__ " - failed submitting write urb, error %d", result);
+ err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
else
result = count;
@@ -218,15 +211,15 @@
int baud;
int i;
- dbg (__FUNCTION__ " - port %d, initialized = %d", port->number,
+ dbg("%s - port %d, initialized = %d", __FUNCTION__, port->number,
((struct pl2303_private *) port->private)->termios_initialized);
if ((!port->tty) || (!port->tty->termios)) {
- dbg(__FUNCTION__" - no tty structures");
+ dbg("%s - no tty structures", __FUNCTION__);
return;
}
- if (!(((struct pl2303_private *)port->private)->termios_initialized)) {
+ if (!(((struct pl2303_private *) port->private)->termios_initialized)) {
*(port->tty->termios) = tty_std_termios;
port->tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
((struct pl2303_private *) port->private)->termios_initialized = 1;
@@ -236,14 +229,14 @@
if (old_termios) {
if ((cflag == old_termios->c_cflag) &&
(RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
- dbg(__FUNCTION__ " - nothing to change...");
+ dbg("%s - nothing to change...", __FUNCTION__);
return;
}
}
buf = kmalloc (7, GFP_KERNEL);
if (!buf) {
- err(__FUNCTION__ " - out of memory.");
+ err("%s - out of memory.", __FUNCTION__);
return;
}
memset (buf, 0x00, 0x07);
@@ -269,7 +262,7 @@
default:
case CS8: buf[6] = 8; break;
}
- dbg (__FUNCTION__ " - data bits = %d", buf[6]);
+ dbg("%s - data bits = %d", __FUNCTION__, buf[6]);
}
baud = 0;
@@ -294,7 +287,7 @@
err ("pl2303 driver does not support the baudrate requested (fix it)");
break;
}
- dbg (__FUNCTION__ " - baud = %d", baud);
+ dbg("%s - baud = %d", __FUNCTION__, baud);
if (baud) {
buf[0] = baud & 0xff;
buf[1] = (baud >> 8) & 0xff;
@@ -307,10 +300,10 @@
/* For reference buf[4]=2 is 2 stop bits */
if (cflag & CSTOPB) {
buf[4] = 2;
- dbg(__FUNCTION__ " - stop bits = 2");
+ dbg("%s - stop bits = 2", __FUNCTION__);
} else {
buf[4] = 0;
- dbg(__FUNCTION__ " - stop bits = 1");
+ dbg("%s - stop bits = 1", __FUNCTION__);
}
if (cflag & PARENB) {
@@ -321,14 +314,14 @@
/* For reference buf[5]=4 is space parity */
if (cflag & PARODD) {
buf[5] = 1;
- dbg(__FUNCTION__ " - parity = odd");
+ dbg("%s - parity = odd", __FUNCTION__);
} else {
buf[5] = 2;
- dbg(__FUNCTION__ " - parity = even");
+ dbg("%s - parity = even", __FUNCTION__);
}
} else {
buf[5] = 0;
- dbg(__FUNCTION__ " - parity = none");
+ dbg("%s - parity = none", __FUNCTION__);
}
i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
@@ -355,7 +348,7 @@
if (cflag & CRTSCTS) {
i = usb_control_msg (serial->dev, usb_sndctrlpipe (serial->dev, 0),
- VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST_TYPE,
+ VENDOR_WRITE_REQUEST, VENDOR_WRITE_REQUEST_TYPE,
0x0, 0x41, NULL, 0, 100);
dbg ("0x40:0x1:0x0:0x41 %d", i);
}
@@ -374,64 +367,54 @@
if (port_paranoia_check (port, __FUNCTION__))
return -ENODEV;
- dbg (__FUNCTION__ " - port %d", port->number);
+ dbg("%s - port %d", __FUNCTION__, port->number);
- down (&port->sem);
+#define FISH(a,b,c,d) \
+ result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \
+ b, a, c, d, buf, 1, 100); \
+ dbg("0x%x:0x%x:0x%x:0x%x %d - %x",a,b,c,d,result,buf[0]);
+
+#define SOUP(a,b,c,d) \
+ result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \
+ b, a, c, d, NULL, 0, 100); \
+ dbg("0x%x:0x%x:0x%x:0x%x %d",a,b,c,d,result);
+
+ FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
+ SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0);
+ FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
+ FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
+ FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
+ SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1);
+ FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
+ FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
+ SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1);
+ SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0xc0);
+ SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 4);
- ++port->open_count;
- MOD_INC_USE_COUNT;
-
- if (!port->active) {
- port->active = 1;
-
-#define FISH(a,b,c,d) \
- result=usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev,0), \
- b, a, c, d, buf, 1, 100); \
- dbg("0x%x:0x%x:0x%x:0x%x %d - %x",a,b,c,d,result,buf[0]);
-
-#define SOUP(a,b,c,d) \
- result=usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev,0), \
- b, a, c, d, NULL, 0, 100); \
- dbg("0x%x:0x%x:0x%x:0x%x %d",a,b,c,d,result);
-
- FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
- SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 0);
- FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
- FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
- FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
- SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0x0404, 1);
- FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8484, 0);
- FISH (VENDOR_READ_REQUEST_TYPE, VENDOR_READ_REQUEST, 0x8383, 0);
- SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 0, 1);
- SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 1, 0xc0);
- SOUP (VENDOR_WRITE_REQUEST_TYPE, VENDOR_WRITE_REQUEST, 2, 4);
-
- /* Setup termios */
+ /* Setup termios */
+ if (port->tty) {
pl2303_set_termios (port, &tmp_termios);
+ }
- //FIXME: need to assert RTS and DTR if CRTSCTS off
-
- dbg (__FUNCTION__ " - submitting read urb");
- port->read_urb->dev = serial->dev;
- result = usb_submit_urb (port->read_urb);
- if (result) {
- err(__FUNCTION__ " - failed submitting read urb, error %d", result);
- up (&port->sem);
- pl2303_close (port, NULL);
- return -EPROTO;
- }
+ //FIXME: need to assert RTS and DTR if CRTSCTS off
- dbg (__FUNCTION__ " - submitting interrupt urb");
- port->interrupt_in_urb->dev = serial->dev;
- result = usb_submit_urb (port->interrupt_in_urb);
- if (result) {
- err(__FUNCTION__ " - failed submitting interrupt urb, error %d", result);
- up (&port->sem);
- pl2303_close (port, NULL);
- return -EPROTO;
- }
+ dbg("%s - submitting read urb", __FUNCTION__);
+ port->read_urb->dev = serial->dev;
+ result = usb_submit_urb (port->read_urb);
+ if (result) {
+ err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
+ pl2303_close (port, NULL);
+ return -EPROTO;
+ }
+
+ dbg("%s - submitting interrupt urb", __FUNCTION__);
+ port->interrupt_in_urb->dev = serial->dev;
+ result = usb_submit_urb (port->interrupt_in_urb);
+ if (result) {
+ err("%s - failed submitting interrupt urb, error %d", __FUNCTION__, result);
+ pl2303_close (port, NULL);
+ return -EPROTO;
}
- up (&port->sem);
return 0;
}
@@ -449,13 +432,10 @@
if (!serial)
return;
- dbg (__FUNCTION__ " - port %d", port->number);
+ dbg("%s - port %d", __FUNCTION__, port->number);
- down (&port->sem);
-
- --port->open_count;
- if (port->open_count <= 0) {
- if (serial->dev) {
+ if (serial->dev) {
+ if (port->tty) {
c_cflag = port->tty->termios->c_cflag;
if (c_cflag & HUPCL) {
/* drop DTR and RTS */
@@ -464,34 +444,28 @@
set_control_lines (port->serial->dev,
priv->line_control);
}
+ }
- /* shutdown our urbs */
- dbg (__FUNCTION__ " - shutting down urbs");
- result = usb_unlink_urb (port->write_urb);
- if (result)
- dbg (__FUNCTION__ " - usb_unlink_urb "
- "(write_urb) failed with reason: %d",
- result);
-
- result = usb_unlink_urb (port->read_urb);
- if (result)
- dbg (__FUNCTION__ " - usb_unlink_urb "
- "(read_urb) failed with reason: %d",
- result);
+ /* shutdown our urbs */
+ dbg("%s - shutting down urbs", __FUNCTION__);
+ result = usb_unlink_urb (port->write_urb);
+ if (result)
+ dbg("%s - usb_unlink_urb (write_urb)"
+ " failed with reason: %d", __FUNCTION__,
+ result);
- result = usb_unlink_urb (port->interrupt_in_urb);
- if (result)
- dbg (__FUNCTION__ " - usb_unlink_urb "
- "(interrupt_in_urb) failed with reason: %d",
- result);
- }
+ result = usb_unlink_urb (port->read_urb);
+ if (result)
+ dbg("%s - usb_unlink_urb (read_urb) "
+ "failed with reason: %d", __FUNCTION__,
+ result);
- port->active = 0;
- port->open_count = 0;
+ result = usb_unlink_urb (port->interrupt_in_urb);
+ if (result)
+ dbg("%s - usb_unlink_urb (interrupt_in_urb)"
+ " failed with reason: %d", __FUNCTION__,
+ result);
}
-
- up (&port->sem);
- MOD_DEC_USE_COUNT;
}
static int set_modem_info (struct usb_serial_port *port, unsigned int cmd, unsigned int *value)
@@ -538,7 +512,7 @@
result = ((mcr & CONTROL_DTR) ? TIOCM_DTR : 0)
| ((mcr & CONTROL_RTS) ? TIOCM_RTS : 0);
- dbg (__FUNCTION__ " - result = %x", result);
+ dbg("%s - result = %x", __FUNCTION__, result);
if (copy_to_user(value, &result, sizeof(int)))
return -EFAULT;
@@ -547,22 +521,22 @@
static int pl2303_ioctl (struct usb_serial_port *port, struct file *file, unsigned int cmd, unsigned long arg)
{
- dbg (__FUNCTION__" (%d) cmd = 0x%04x", port->number, cmd);
+ dbg("%s (%d) cmd = 0x%04x", __FUNCTION__, port->number, cmd);
switch (cmd) {
case TIOCMGET:
- dbg (__FUNCTION__" (%d) TIOCMGET", port->number);
+ dbg("%s (%d) TIOCMGET", __FUNCTION__, port->number);
return get_modem_info (port, (unsigned int *)arg);
case TIOCMBIS:
case TIOCMBIC:
case TIOCMSET:
- dbg(__FUNCTION__" (%d) TIOCMSET/TIOCMBIC/TIOCMSET", port->number);
+ dbg("%s (%d) TIOCMSET/TIOCMBIC/TIOCMSET", __FUNCTION__, port->number);
return set_modem_info(port, cmd, (unsigned int *) arg);
default:
- dbg (__FUNCTION__" not supported = 0x%04x", cmd);
+ dbg("%s not supported = 0x%04x", __FUNCTION__, cmd);
break;
}
@@ -576,19 +550,19 @@
u16 state;
int result;
- dbg (__FUNCTION__ " - port %d", port->number);
+ dbg("%s - port %d", __FUNCTION__, port->number);
if (break_state == 0)
state = BREAK_OFF;
else
state = BREAK_ON;
- dbg (__FUNCTION__" - turning break %s", state==BREAK_OFF ? "off" : "on");
+ dbg("%s - turning break %s", state==BREAK_OFF ? "off" : "on", __FUNCTION__);
result = usb_control_msg (serial->dev, usb_rcvctrlpipe (serial->dev, 0),
BREAK_REQUEST, BREAK_REQUEST_TYPE, state,
0, NULL, 0, 100);
if (result)
- dbg (__FUNCTION__" - error sending break = %d", result);
+ dbg("%s - error sending break = %d", __FUNCTION__, result);
}
@@ -596,14 +570,10 @@
{
int i;
- dbg (__FUNCTION__);
+ dbg("%s", __FUNCTION__);
- /* stop everything on all ports */
for (i = 0; i < serial->num_ports; ++i)
- while (serial->port[i].open_count > 0) {
- pl2303_close (&serial->port[i], NULL);
- kfree (serial->port[i].private);
- }
+ kfree (serial->port[i].private);
}
@@ -646,37 +616,37 @@
if (port_paranoia_check (port, __FUNCTION__))
return;
- dbg(__FUNCTION__ " - port %d", port->number);
+ dbg("%s - port %d", __FUNCTION__, port->number);
if (!serial) {
- dbg(__FUNCTION__ " - bad serial pointer, exiting");
+ dbg("%s - bad serial pointer, exiting", __FUNCTION__);
return;
}
if (urb->status) {
- dbg (__FUNCTION__ " - urb->status = %d", urb->status);
- if (!port->active) {
- dbg (__FUNCTION__ " - port is closed, exiting.");
+ dbg("%s - urb->status = %d", __FUNCTION__, urb->status);
+ if (!port->open_count) {
+ dbg("%s - port is closed, exiting.", __FUNCTION__);
return;
}
if (urb->status == -EPROTO) {
/* PL2303 mysteriously fails with -EPROTO reschedule the read */
- dbg (__FUNCTION__ " - caught -EPROTO, resubmitting the urb");
+ dbg("%s - caught -EPROTO, resubmitting the urb", __FUNCTION__);
urb->status = 0;
urb->dev = serial->dev;
result = usb_submit_urb(urb);
if (result)
- err(__FUNCTION__ " - failed resubmitting read urb, error %d", result);
+ err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
return;
}
- dbg (__FUNCTION__ " - unable to handle the error, exiting.");
+ dbg("%s - unable to handle the error, exiting.", __FUNCTION__);
return;
}
usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
tty = port->tty;
- if (urb->actual_length) {
+ if (tty && urb->actual_length) {
for (i = 0; i < urb->actual_length; ++i) {
if (tty->flip.count >= TTY_FLIPBUF_SIZE) {
tty_flip_buffer_push(tty);
@@ -687,11 +657,11 @@
}
/* Schedule the next read _if_ we are still open */
- if (port->active) {
+ if (port->open_count) {
urb->dev = serial->dev;
result = usb_submit_urb(urb);
if (result)
- err(__FUNCTION__ " - failed resubmitting read urb, error %d", result);
+ err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
}
return;
@@ -707,20 +677,20 @@
if (port_paranoia_check (port, __FUNCTION__))
return;
- dbg(__FUNCTION__ " - port %d", port->number);
+ dbg("%s - port %d", __FUNCTION__, port->number);
if (urb->status) {
/* error in the urb, so we have to resubmit it */
if (serial_paranoia_check (port->serial, __FUNCTION__)) {
return;
}
- dbg (__FUNCTION__ " - Overflow in write");
- dbg (__FUNCTION__ " - nonzero write bulk status received: %d", urb->status);
+ dbg("%s - Overflow in write", __FUNCTION__);
+ dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
port->write_urb->transfer_buffer_length = 1;
port->write_urb->dev = port->serial->dev;
result = usb_submit_urb (port->write_urb);
if (result)
- err(__FUNCTION__ " - failed resubmitting write urb, error %d", result);
+ err("%s - failed resubmitting write urb, error %d", __FUNCTION__, result);
return;
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)