Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 146290
b: refs/heads/master
c: 557aaa7
h: refs/heads/master
v: v3
  • Loading branch information
Alan Cox authored and Linus Torvalds committed Jun 11, 2009
1 parent 1ed2869 commit a81c6c1
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 35 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4cc27bd6d7d6750dba33b4ccb4585c00b8fca7d2
refs/heads/master: 557aaa7ffab639d0190b935a041b16ae44606342
94 changes: 60 additions & 34 deletions trunk/drivers/usb/serial/ftdi_sio.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ struct ftdi_private {
int force_rtscts; /* if non-zero, force RTS-CTS to always
be enabled */

unsigned int latency; /* latency setting in use */
spinlock_t tx_lock; /* spinlock for transmit state */
unsigned long tx_bytes;
unsigned long tx_outstanding_bytes;
Expand Down Expand Up @@ -1038,7 +1039,54 @@ static int change_speed(struct tty_struct *tty, struct usb_serial_port *port)
return rv;
}

static int write_latency_timer(struct usb_serial_port *port)
{
struct ftdi_private *priv = usb_get_serial_port_data(port);
struct usb_device *udev = port->serial->dev;
char buf[1];
int rv = 0;
int l = priv->latency;

if (priv->flags & ASYNC_LOW_LATENCY)
l = 1;

dbg("%s: setting latency timer = %i", __func__, l);

rv = usb_control_msg(udev,
usb_sndctrlpipe(udev, 0),
FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
l, priv->interface,
buf, 0, WDR_TIMEOUT);

if (rv < 0)
dev_err(&port->dev, "Unable to write latency timer: %i\n", rv);
return rv;
}

static int read_latency_timer(struct usb_serial_port *port)
{
struct ftdi_private *priv = usb_get_serial_port_data(port);
struct usb_device *udev = port->serial->dev;
unsigned short latency = 0;
int rv = 0;


dbg("%s", __func__);

rv = usb_control_msg(udev,
usb_rcvctrlpipe(udev, 0),
FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
0, priv->interface,
(char *) &latency, 1, WDR_TIMEOUT);

if (rv < 0) {
dev_err(&port->dev, "Unable to read latency timer: %i\n", rv);
return -EIO;
}
return latency;
}

static int get_serial_info(struct usb_serial_port *port,
struct serial_struct __user *retinfo)
Expand Down Expand Up @@ -1098,6 +1146,7 @@ static int set_serial_info(struct tty_struct *tty,
priv->custom_divisor = new_serial.custom_divisor;

tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
write_latency_timer(port);

check_and_exit:
if ((old_priv.flags & ASYNC_SPD_MASK) !=
Expand Down Expand Up @@ -1193,53 +1242,27 @@ static ssize_t show_latency_timer(struct device *dev,
{
struct usb_serial_port *port = to_usb_serial_port(dev);
struct ftdi_private *priv = usb_get_serial_port_data(port);
struct usb_device *udev = port->serial->dev;
unsigned short latency = 0;
int rv = 0;


dbg("%s", __func__);

rv = usb_control_msg(udev,
usb_rcvctrlpipe(udev, 0),
FTDI_SIO_GET_LATENCY_TIMER_REQUEST,
FTDI_SIO_GET_LATENCY_TIMER_REQUEST_TYPE,
0, priv->interface,
(char *) &latency, 1, WDR_TIMEOUT);

if (rv < 0) {
dev_err(dev, "Unable to read latency timer: %i\n", rv);
return -EIO;
}
return sprintf(buf, "%i\n", latency);
if (priv->flags & ASYNC_LOW_LATENCY)
return sprintf(buf, "1\n");
else
return sprintf(buf, "%i\n", priv->latency);
}


/* Write a new value of the latency timer, in units of milliseconds. */
static ssize_t store_latency_timer(struct device *dev,
struct device_attribute *attr, const char *valbuf,
size_t count)
{
struct usb_serial_port *port = to_usb_serial_port(dev);
struct ftdi_private *priv = usb_get_serial_port_data(port);
struct usb_device *udev = port->serial->dev;
char buf[1];
int v = simple_strtoul(valbuf, NULL, 10);
int rv = 0;

dbg("%s: setting latency timer = %i", __func__, v);

rv = usb_control_msg(udev,
usb_sndctrlpipe(udev, 0),
FTDI_SIO_SET_LATENCY_TIMER_REQUEST,
FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
v, priv->interface,
buf, 0, WDR_TIMEOUT);

if (rv < 0) {
dev_err(dev, "Unable to write latency timer: %i\n", rv);
priv->latency = v;
rv = write_latency_timer(port);
if (rv < 0)
return -EIO;
}

return count;
}

Expand Down Expand Up @@ -1393,6 +1416,7 @@ static int ftdi_sio_port_probe(struct usb_serial_port *port)
usb_set_serial_port_data(port, priv);

ftdi_determine_type(port);
read_latency_timer(port);
create_sysfs_attrs(port);
return 0;
}
Expand Down Expand Up @@ -1515,6 +1539,8 @@ static int ftdi_open(struct tty_struct *tty,
if (tty)
tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;

write_latency_timer(port);

/* No error checking for this (will get errors later anyway) */
/* See ftdi_sio.h for description of what is reset */
usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
Expand Down

0 comments on commit a81c6c1

Please sign in to comment.