• Al Borchers's avatar
    [PATCH] USB: close waits for drain in pl2303 · 66d2dc06
    Al Borchers authored
    Here is an additional patch for pl2303 in 2.6.9-rc1,
    to be applied after my previous circular buffer patch.
    This patch waits for the buffer to drain on close and
    then clears the buffer.  In addition to the obvious
    features, this also fixes a bug where closing a port
    with a full buffer would accidentally disable writes
    when the port was re-opened.
    
    The original pl2303 could lose data that was still going
    out the port on close, and even this patch only solves
    the problem completely for data rates of 1200 bps and
    above.
    
    Waiting for data to drain from the circular buffer is
    easy, but the problem is waiting for data to drain from
    the 256 byte hardware buffer on the device.  I don't know
    how much data is in the hardware buffer, so I just wait
    long enough for a potentially full hardware buffer to
    drain, but I don't want to wait that long for low data
    rates if the buffer isn't full.  There is probably some
    way to query the pl2303 to find out how much data is in
    its hardware buffer, maybe snooping would reveal that.
    
    - Added a wait for data to drain from the driver
      write buffer when closing.
    
    - Added a wait for the data to drain from the
      device hardware buffer when closing.
    
    - Cleared the driver write buffer when closing.
    Signed-off-by: default avatarAl Borchers <alborchers@steinerpoint.com>
    Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
    66d2dc06
pl2303.c 32.3 KB