From: "Peter E. Berger" <pber...@brimson.com>

When using Edgeport/416 models with newer firmware (sometime after
firmware version 4.80.0), idle ports are automatically bounced
(disconnected and then reconnected) approximately every 60 seconds.
This breaks programs (e.g: minicom) where idle periods are common,
normal and expected.

I confirmed with the manufacturer (Digi International) that Edgeport/416
models now ship from the factory with firmware that expects periodic
"heartbeat" queries from the driver to keep idle ports alive.  This
patch implements heartbeat support using the mechanism Digi suggested
(periodically requesting an I2C descriptor address) that appears effective
on Edgeports running the newer firmware (that require it) and benign on
Edgeport devices running older firmware.  Since we know that Edgeport
firmware version 4.80 (the version distributed in /lib/firmware/down3.bin
and used for Edgeports that are either running still older versions or
have no onboard non-volatile firmware image) does not require heartbeat
support, this patch schedules heartbeats only on Edgeport/416 devices,
and only if they are running firmware versions newer than 4.80.

Signed-off-by: Peter E. Berger <pber...@brimson.com>
---
 drivers/usb/serial/io_ti.c | 90 +++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 89 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index a73d242..093ff71 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -120,6 +120,7 @@ struct edgeport_serial {
        struct mutex es_lock;
        int num_ports_open;
        struct usb_serial *serial;
+       struct delayed_work heartbeat_work;
        int fw_version;
 };
 
@@ -225,6 +226,22 @@ static void edge_send(struct usb_serial_port *port, struct 
tty_struct *tty);
 static int edge_create_sysfs_attrs(struct usb_serial_port *port);
 static int edge_remove_sysfs_attrs(struct usb_serial_port *port);
 
+/*
+ * Some release of Edgeport firmware "down3.bin" after version 4.80
+ * introduced code to automatically disconnect idle devices on some
+ * Edgeport models after periods of inactivity, typically ~60 seconds.
+ * This occurs without regard to whether ports on the device are open
+ * or not.  Digi International Tech Support suggested:
+ *
+ * 1.  Adding driver "heartbeat" code to reset the firmware timer by
+ *     requesting a descriptor record every 15 seconds, which should be
+ *     effective with newer firmware versions that require it, and benign
+ *     with older versions that do not. In practice 40 seconds seems often
+ *     enough.
+ * 2.  The heartbeat code is currently required only on Edgeport/416 models.
+ */
+#define FW_HEARTBEAT_VERSION_CUTOFF ((4 << 8) + 80)
+#define FW_HEARTBEAT_SECS 40
 
 /* Timeouts in msecs: firmware downloads take longer */
 #define TI_VSEND_TIMEOUT_DEFAULT 1000
@@ -2415,6 +2432,44 @@ static void edge_break(struct tty_struct *tty, int 
break_state)
                        __func__, status);
 }
 
+static inline void edge_heartbeat_schedule(struct edgeport_serial *edge_serial)
+{
+       u16 product_id = le16_to_cpu(
+                       edge_serial->serial->dev->descriptor.idProduct);
+
+       /* Currently only the EP/416 models require heartbeat support */
+       if (product_id != ION_DEVICE_ID_TI_EDGEPORT_416 &&
+                       product_id != ION_DEVICE_ID_TI_EDGEPORT_416B)
+               return;
+
+       if (edge_serial->fw_version <= FW_HEARTBEAT_VERSION_CUTOFF)
+               return;
+
+       schedule_delayed_work(&edge_serial->heartbeat_work,
+                       FW_HEARTBEAT_SECS * HZ);
+}
+
+static void edge_heartbeat_work(struct work_struct *work)
+{
+       struct edgeport_serial *serial;
+       struct ti_i2c_desc *rom_desc;
+
+       serial = container_of(work, struct edgeport_serial,
+                       heartbeat_work.work);
+
+       rom_desc = kmalloc(sizeof(*rom_desc), GFP_KERNEL);
+
+       /* Descriptor address request is enough to reset the firmware timer */
+       if (!rom_desc || !get_descriptor_addr(serial, I2C_DESC_TYPE_ION,
+                       rom_desc)) {
+               dev_err(&serial->serial->interface->dev,
+                               "%s - Incomplete heartbeat\n", __func__);
+       }
+       kfree(rom_desc);
+
+       edge_heartbeat_schedule(serial);
+}
+
 static int edge_startup(struct usb_serial *serial)
 {
        struct edgeport_serial *edge_serial;
@@ -2448,6 +2503,9 @@ static int edge_startup(struct usb_serial *serial)
                return status;
        }
 
+       INIT_DELAYED_WORK(&edge_serial->heartbeat_work, edge_heartbeat_work);
+       edge_heartbeat_schedule(edge_serial);
+
        return 0;
 }
 
@@ -2457,7 +2515,10 @@ static void edge_disconnect(struct usb_serial *serial)
 
 static void edge_release(struct usb_serial *serial)
 {
-       kfree(usb_get_serial_data(serial));
+       struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
+
+       cancel_delayed_work_sync(&edge_serial->heartbeat_work);
+       kfree(edge_serial);
 }
 
 static int edge_port_probe(struct usb_serial_port *port)
@@ -2561,6 +2622,25 @@ static int edge_remove_sysfs_attrs(struct 
usb_serial_port *port)
        return 0;
 }
 
+#ifdef CONFIG_PM
+static int edge_suspend(struct usb_serial *serial, pm_message_t message)
+{
+       struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
+
+       cancel_delayed_work_sync(&edge_serial->heartbeat_work);
+
+       return 0;
+}
+
+static int edge_resume(struct usb_serial *serial)
+{
+       struct edgeport_serial *edge_serial = usb_get_serial_data(serial);
+
+       edge_heartbeat_schedule(edge_serial);
+
+       return 0;
+}
+#endif
 
 static struct usb_serial_driver edgeport_1port_device = {
        .driver = {
@@ -2593,6 +2673,10 @@ static struct usb_serial_driver edgeport_1port_device = {
        .read_int_callback      = edge_interrupt_callback,
        .read_bulk_callback     = edge_bulk_in_callback,
        .write_bulk_callback    = edge_bulk_out_callback,
+#ifdef CONFIG_PM
+       .suspend                = edge_suspend,
+       .resume                 = edge_resume,
+#endif
 };
 
 static struct usb_serial_driver edgeport_2port_device = {
@@ -2626,6 +2710,10 @@ static struct usb_serial_driver edgeport_2port_device = {
        .read_int_callback      = edge_interrupt_callback,
        .read_bulk_callback     = edge_bulk_in_callback,
        .write_bulk_callback    = edge_bulk_out_callback,
+#ifdef CONFIG_PM
+       .suspend                = edge_suspend,
+       .resume                 = edge_resume,
+#endif
 };
 
 static struct usb_serial_driver * const serial_drivers[] = {
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to