Hi.
This series enable the PPS reporting for USB serial devices. This
third submission improve commit messages, and fix some coding
guidelines. The last patch of the v2 will be integrated in an more
global reworking of the pl2303 driver.
Paul Chavent (2):
USB : serial : call handle_dcd_change in ftdi driver.
USB : serial : invoke dcd_change ldisc's handler.
Documentation/pps/pps.txt | 15 +++++++++++++++
drivers/usb/serial/ftdi_sio.c | 10 +++++++++-
drivers/usb/serial/generic.c | 10 ++++++++++
3 files changed, 34 insertions(+), 1 deletion(-)
--
1.7.12.1
When the device receive a DCD status change, forward the signal to the
USB serial system. This way, we can detect, for instance, PPS pulses.
Signed-off-by: Paul Chavent <[email protected]>
---
drivers/usb/serial/ftdi_sio.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index c45f9c0..f53298d 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1966,8 +1966,16 @@ static int ftdi_process_packet(struct usb_serial_port *port,
port->icount.dsr++;
if (diff_status & FTDI_RS0_RI)
port->icount.rng++;
- if (diff_status & FTDI_RS0_RLSD)
+ if (diff_status & FTDI_RS0_RLSD) {
+ struct tty_struct *tty;
+
port->icount.dcd++;
+ tty = tty_port_tty_get(&port->port);
+ if (tty)
+ usb_serial_handle_dcd_change(port, tty,
+ status & FTDI_RS0_RLSD);
+ tty_kref_put(tty);
+ }
wake_up_interruptible(&port->port.delta_msr_wait);
priv->prev_status = status;
--
1.7.12.1
The DCD pin of the serial port can receive a PPS signal. By calling
the port line discipline dcd handle, this patch allow to monitor PPS
through USB serial devices.
However the performance aren't as good as the uart drivers, so
document this point too.
Signed-off-by: Paul Chavent <[email protected]>
---
Documentation/pps/pps.txt | 15 +++++++++++++++
drivers/usb/serial/generic.c | 10 ++++++++++
2 files changed, 25 insertions(+)
diff --git a/Documentation/pps/pps.txt b/Documentation/pps/pps.txt
index d35dcdd..c03b1be 100644
--- a/Documentation/pps/pps.txt
+++ b/Documentation/pps/pps.txt
@@ -66,6 +66,21 @@ In LinuxPPS the PPS sources are simply char devices usually mapped
into files /dev/pps0, /dev/pps1, etc..
+PPS with USB to serial devices
+------------------------------
+
+It is possible to grab the PPS from an USB to serial device. However,
+you should take into account the latencies and jitter introduced by
+the USB stack. Users has reported clock instability around +-1ms when
+synchronized with PPS through USB. This isn't suited for time server
+synchronization.
+
+If your device doesn't report PPS, you can check that the feature is
+supported by its driver. Most of the time, you only need to add a call
+to usb_serial_handle_dcd_change after checking the DCD status (see
+ch341 and pl2303 examples).
+
+
Coding example
--------------
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 1f31e6b..3a5dac8 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -570,6 +570,16 @@ void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port,
dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status);
+ if (tty) {
+ struct tty_ldisc *ld = tty_ldisc_ref(tty);
+
+ if (ld) {
+ if (ld->ops->dcd_change)
+ ld->ops->dcd_change(tty, status);
+ tty_ldisc_deref(ld);
+ }
+ }
+
if (status)
wake_up_interruptible(&port->open_wait);
else if (tty && !C_CLOCAL(tty))
--
1.7.12.1
On Mon, Sep 16, 2013 at 08:41:00AM +0200, Paul Chavent wrote:
> The DCD pin of the serial port can receive a PPS signal. By calling
> the port line discipline dcd handle, this patch allow to monitor PPS
> through USB serial devices.
>
> However the performance aren't as good as the uart drivers, so
> document this point too.
>
> Signed-off-by: Paul Chavent <[email protected]>
Acked-by: Rodolfo Giometti <[email protected]>
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
Freelance ICT Italia - Consulente ICT Italia - http://www.consulenti-ict.it