Re: support for TIOCSERGETLSR in ftdi_sio

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Dec 10, 2010 at 01:46:32PM -0800, Greg KH wrote:
> On Fri, Dec 10, 2010 at 01:44:20PM -0800, Greg KH wrote:
> > On Fri, Dec 10, 2010 at 10:23:31PM +0100, W. de Hoog wrote:
> > > >It uses LSR to see if the data is sent?  That's a bit strange, but ok.
> > > Not that strange. The comments in mos7840.c suggest that this is the
> > > reason why they support it as well.
> > 
> > Sorry, you are right, I was thinking of line settings like CTS/DTR, I
> > forgot that this was the actual number of characters left in the device
> > buffer.
> > 
> > > >No, that wouldn't really work.  What you need is the real TIOCSERGETLSR
> > > >support added to the driver, as it currently doesn't support it.
> > > >
> > > >Or you can go get a different device, as a few other usb to serial
> > > >devices do support TIOCSERGETLSR already.  Those would be ones
> > > >controlled by the io_edgeport, mos7840, and mos7720 drivers.
> > > I only checked mos7840 and they use the result of the
> > > chars_in_buffer function. The ftdi_sio has one as well.
> > > 
> > > Does this function return the number of characters in the PC buffer
> > > or in the ftdi usb chips buffer? So if it is 0 does it mean the data
> > > has been sent?
> > 
> > That function shows the number of characters left in the PC buffer, not
> > the device's buffer.  0 means the data has been sent to the device, but
> > the UART in the device might still not have sent the data out.
> > 
> > I don't know if the FTDI_SIO devices can report if their uarts are empty
> > or not (the io_edgeport devices can), perhaps someone else on this list
> > who is more familiar with that chiptype can let us know.
> 
> Ah, it looks like it can report this information, see the TEMT
> (Transmitter Empty) flag in the ftdi_sio.h file.  Can you test patches
> to the driver if I provide one to see if it works or not?

And if you can test, can you try the patch below and let me know if that
works or not for you?

thanks,

greg k-h

------------

Subject: usb: serial: ftdi_sio: add TIOCSERGETLSR support

Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxx>

--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -75,6 +75,7 @@ struct ftdi_private {
 	unsigned long last_dtr_rts;	/* saved modem control outputs */
 	wait_queue_head_t delta_msr_wait; /* Used for TIOCMIWAIT */
 	char prev_status, diff_status;        /* Used for TIOCMIWAIT */
+	char transmit_empty;	/* If transmitter is empty or not */
 	struct usb_serial_port *port;
 	__u16 interface;	/* FT2232C, FT2232H or FT4232H port interface
 				   (0 for FT232/245) */
@@ -1322,6 +1323,23 @@ check_and_exit:
 	return 0;
 }
 
+static int get_lsr_info(struct usb_serial_port *port,
+			struct serial_struct __user *retinfo)
+{
+	struct ftdi_private *priv = usb_get_serial_port_data(port);
+	unsigned int result = 0;
+
+	if (!retinfo)
+		return -EFAULT;
+
+	if (priv->transmit_empty)
+		result = TIOCSER_TEMT;
+
+	if (copy_to_user(retinfo, &result, sizeof(unsigned int)))
+		return -EFAULT;
+	return 0;
+}
+
 
 /* Determine type of FTDI chip based on USB config and descriptor. */
 static void ftdi_determine_type(struct usb_serial_port *port)
@@ -1871,6 +1889,12 @@ static int ftdi_process_packet(struct tty_struct *tty,
 			tty_insert_flip_char(tty, 0, TTY_OVERRUN);
 	}
 
+	/* save if the transmitter is empty or not */
+	if (packet[1] & FTDI_RS_TEMT)
+		priv->transmit_empty = 1;
+	else
+		priv->transmit_empty = 0;
+
 	len -= 2;
 	if (!len)
 		return 0;	/* status only */
@@ -2234,6 +2258,9 @@ static int ftdi_ioctl(struct tty_struct *tty, struct file *file,
 			}
 		}
 		return 0;
+	case TIOCSERGETLSR:
+		return get_lsr_info(port, (struct serial_struct __user *)arg);
+		break;
 	default:
 		break;
 	}
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux