Hi,

I have an application the relies on setting the serial port into low latency mode, but this doesn't work well with ftdi_sio.c, because:

1. setting low latency (priv->flags & ASYNC_LOW_LATENCY) requires CAP_SYS_ADMIN 2. setting low latency doesn't affect the latency timer (FTDI_SIO_SET_LATENCY_TIMER_REQUEST)

The submitted patch makes:

  1. The driver start in normal latency mode (previously low latency)
  2. Let any user change latency (i.e. no CAP_SYS_ADMIN required)
3. Setting low latency sets the latency timer to 1 ms, normal latency sets the
     latency timer to 16 ms (chip default).

With the patch applied, low latency mode gives a delay of about 3-4 ms in contrast
to the 16 ms normally encountered.



Best regards

Anders Blomdell

------------------------------------------------------------------------ ------
 Anders Blomdell
Department of Automatic Control Email: [EMAIL PROTECTED]
 Lund Institute of Technology        Phone: +46 46 222 4625
 Box 118, S-221 00 Lund, Sweden      Fax:   +46 46 138118


--- old/ftdi_sio.c      2005-09-08 21:28:50.000000000 +0200
+++ new/ftdi_sio.c      2005-09-19 12:21:20.073885017 +0200
@@ -1184,7 +1184,6 @@ static int set_serial_info(struct usb_se
                       (new_serial.flags & ASYNC_FLAGS));
        priv->custom_divisor = new_serial.custom_divisor;

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

 check_and_exit:
        if ((old_priv.flags & ASYNC_SPD_MASK) !=
@@ -1206,7 +1205,29 @@ check_and_exit:
             (old_priv.custom_divisor != priv->custom_divisor))) {
                change_speed(port);
        }
+       if (((old_priv.flags & ASYNC_LOW_LATENCY) !=
+            (priv->flags & ASYNC_LOW_LATENCY))) {
+               int latency;
+               char buf[1];
+
+               if (priv->flags & ASYNC_LOW_LATENCY) {
+                       port->tty->low_latency = 1;
+                       latency = 1;
+               } else {
+                       port->tty->low_latency = 0;
+                       latency = 16;
+               }
+ if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { + dbg("%s: setting latency timer = %i", __FUNCTION__, latency);

+                       usb_control_msg(port->serial->dev,
+ usb_sndctrlpipe(port->serial->dev, 0), + FTDI_SIO_SET_LATENCY_TIMER_REQUEST, + FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
+                                       latency, priv->interface,
+                                       buf, 0, WDR_TIMEOUT);
+               }
+       }
        return (0);

 } /* set_serial_info */
@@ -1373,9 +1394,6 @@ static int ftdi_common_startup (struct u

        spin_lock_init(&priv->rx_lock);
         init_waitqueue_head(&priv->delta_msr_wait);
-       /* This will push the characters through immediately rather
-          than queue a task to deliver them */
-       priv->flags = ASYNC_LOW_LATENCY;

        /* Increase the size of read buffers */
        kfree(port->bulk_in_buffer);
@@ -1589,7 +1607,28 @@ static int  ftdi_open (struct usb_serial
        dbg("%s", __FUNCTION__);


- port->tty->low_latency = (priv->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
+       {
+               int latency;
+               char buf[1];
+
+               if (priv->flags & ASYNC_LOW_LATENCY) {
+                       port->tty->low_latency = 1;
+                       latency = 1;
+               } else {
+                       port->tty->low_latency = 0;
+                       latency = 16;
+               }
+ if (priv->chip_type == FT232BM || priv->chip_type == FT2232C) { + dbg("%s: setting latency timer = %i", __FUNCTION__, latency);
+
+                       usb_control_msg(port->serial->dev,
+ usb_sndctrlpipe(port->serial->dev, 0), + FTDI_SIO_SET_LATENCY_TIMER_REQUEST, + FTDI_SIO_SET_LATENCY_TIMER_REQUEST_TYPE,
+                                       latency, priv->interface,
+                                       buf, 0, WDR_TIMEOUT);
+               }
+       }

        /* No error checking for this (will get errors later anyway) */
        /* See ftdi_sio.h for description of what is reset */



-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
[email protected]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to