From: "Peter E. Berger" <pberger@xxxxxxxxxxx> When using newer Edgeport devices such as the EP/416, 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 Edgeports now ship from the factory with firmware that expects periodic "heartbeat" queries from the driver to keep ports alive. This patch implements heartbeat support using the mechanism Digi suggested (requesting an I2C descriptor address every 15 seconds) that appears effective on Edgeports running the newer firmware (that require it) and benign on Edgeport devices running older firmware. Signed-off-by: Peter E. Berger <pberger@xxxxxxxxxxx> --- drivers/usb/serial/io_ti.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c index ddbb8fe..c882716 100644 --- a/drivers/usb/serial/io_ti.c +++ b/drivers/usb/serial/io_ti.c @@ -101,6 +101,7 @@ struct edgeport_serial { struct mutex es_lock; int num_ports_open; struct usb_serial *serial; + struct delayed_work heartbeat_task; }; @@ -209,6 +210,8 @@ 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); +/* Newer Edgeport firmware disconnects ports after periods of inactivity */ +#define EP_HEARTBEAT_SECS 15 static int ti_vread_sync(struct usb_device *dev, __u8 request, __u16 value, __u16 index, u8 *data, int size) @@ -2373,11 +2376,33 @@ static void edge_break(struct tty_struct *tty, int break_state) __func__, status); } +static void heartbeat(struct work_struct *taskp) +{ + struct edgeport_serial *serial; + struct ti_i2c_desc rom_desc; + + serial = container_of(taskp, struct edgeport_serial, + heartbeat_task.work); + + dev_dbg(&serial->serial->dev->dev, "%s - serial:%s", + __func__, serial->serial->dev->serial); + + /* Descriptor address request is enough to reset the firmware timer */ + if (!get_descriptor_addr(serial, I2C_DESC_TYPE_ION, &rom_desc)) + dev_warn(&serial->serial->dev->dev, + "%s - Incomplete heartbeat.", __func__); + + schedule_delayed_work(&serial->heartbeat_task, HZ * EP_HEARTBEAT_SECS); + +} + static int edge_startup(struct usb_serial *serial) { struct edgeport_serial *edge_serial; int status; + dev_dbg(&serial->dev->dev, "%s: serial:%s\n", __func__, + serial->dev->serial); /* create our private serial structure */ edge_serial = kzalloc(sizeof(struct edgeport_serial), GFP_KERNEL); if (!edge_serial) @@ -2393,6 +2418,10 @@ static int edge_startup(struct usb_serial *serial) return status; } + INIT_DELAYED_WORK(&edge_serial->heartbeat_task, heartbeat); + schedule_delayed_work(&edge_serial->heartbeat_task, + HZ * EP_HEARTBEAT_SECS); + return 0; } @@ -2458,8 +2487,11 @@ err: static int edge_port_remove(struct usb_serial_port *port) { struct edgeport_port *edge_port; + struct edgeport_serial *edge_serial; edge_port = usb_get_serial_port_data(port); + edge_serial = edge_port->edge_serial; + cancel_delayed_work_sync(&edge_serial->heartbeat_task); edge_remove_sysfs_attrs(port); kfree(edge_port); @@ -2506,6 +2538,28 @@ 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); + + dev_dbg(&serial->dev->dev, "%s: serial:%s\n", __func__, + serial->dev->serial); + cancel_delayed_work_sync(&edge_serial->heartbeat_task); + return 0; +} + +/* Since usb-serial unbinds and reprobes on resume, the re-initialization + * (including re-scheduling heartbeat_task) is handled by edge_startup(). + */ +static int edge_resume(struct usb_serial *serial) +{ + dev_dbg(&serial->dev->dev, "%s: serial:%s\n", __func__, + serial->dev->serial); + return 0; +} +#endif + static struct usb_serial_driver edgeport_1port_device = { .driver = { @@ -2538,6 +2592,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 = { @@ -2571,6 +2629,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 majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html