All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stuart Longland <stuartl-EoQOJlg3kTYQrrorzV6ljw@public.gmane.org>
To: linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	alborchers-2TsfIrYsZRL7O9PZeWXHPg@public.gmane.org,
	linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: Stuart Longland <stuartl-EoQOJlg3kTYQrrorzV6ljw@public.gmane.org>
Subject: [PATCH] USB: serial: ti_usb_3410_5052: Port uart_mode from io_ti.
Date: Fri, 18 Aug 2017 12:56:59 +1000	[thread overview]
Message-ID: <20170818025659.4402-1-stuartl@vrt.com.au> (raw)
In-Reply-To: <4a469222-d48d-f498-f2db-ca582295adc3-3e+Fe6x+DsgJbe36r25VNhCuuivNXqWP@public.gmane.org>

This introduces the `uart_mode` sysfs attribute as seen in the `io_ti`
USB serial driver, allowing this USB serial interface to be switched
between RS-232, 2-wire RS-485 and 4-wire RS-485.

/sys/class/tty/ttyUSB${num}/device/uart takes a single integer:

	0:	RS-232 mode (default for RS-232-compatible dongles)
	1:	RS-485 2w mode (default for RS-485-only dongles)
	2:	RS-485 4w mode / RS-422 mode

Write this *before* opening your serial device.

This has been successfully tested on a Moxa UPort 1150 in 4-wire RS-485
mode.

Signed-off-by: Stuart Longland <stuartl-EoQOJlg3kTYQrrorzV6ljw@public.gmane.org>
---
 drivers/usb/serial/ti_usb_3410_5052.c | 48 +++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 8fc3854e5e69..fb30d7ff32d7 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -514,6 +514,46 @@ MODULE_DEVICE_TABLE(usb, ti_id_table_combined);
 
 module_usb_serial_driver(serial_drivers, ti_id_table_combined);
 
+/* Sysfs Attributes */
+
+static ssize_t uart_mode_show(struct device *dev,
+	struct device_attribute *attr, char *buf)
+{
+	struct usb_serial_port *port = to_usb_serial_port(dev);
+	struct ti_port *tport = usb_get_serial_port_data(port);
+
+	return sprintf(buf, "%d\n", tport->tp_uart_mode);
+}
+
+static ssize_t uart_mode_store(struct device *dev,
+	struct device_attribute *attr, const char *valbuf, size_t count)
+{
+	struct usb_serial_port *port = to_usb_serial_port(dev);
+	struct ti_port *tport = usb_get_serial_port_data(port);
+	unsigned int v = simple_strtoul(valbuf, NULL, 0);
+
+	dev_dbg(dev, "%s: setting uart_mode = %d\n", __func__, v);
+
+	if (v < 256)
+		tport->tp_uart_mode = v;
+	else
+		dev_err(dev, "%s - uart_mode %d is invalid\n", __func__, v);
+
+	return count;
+}
+static DEVICE_ATTR_RW(uart_mode);
+
+static int ti_create_sysfs_attrs(struct usb_serial_port *port)
+{
+	return device_create_file(&port->dev, &dev_attr_uart_mode);
+}
+
+static int ti_remove_sysfs_attrs(struct usb_serial_port *port)
+{
+	device_remove_file(&port->dev, &dev_attr_uart_mode);
+	return 0;
+}
+
 static int ti_startup(struct usb_serial *serial)
 {
 	struct ti_device *tdev;
@@ -607,6 +647,7 @@ static void ti_release(struct usb_serial *serial)
 static int ti_port_probe(struct usb_serial_port *port)
 {
 	struct ti_port *tport;
+	int status;
 
 	tport = kzalloc(sizeof(*tport), GFP_KERNEL);
 	if (!tport)
@@ -628,6 +669,12 @@ static int ti_port_probe(struct usb_serial_port *port)
 
 	usb_set_serial_port_data(port, tport);
 
+	status = ti_create_sysfs_attrs(port);
+	if (status) {
+		kfree(tport);
+		return status;
+	}
+
 	port->port.drain_delay = 3;
 
 	return 0;
@@ -638,6 +685,7 @@ static int ti_port_remove(struct usb_serial_port *port)
 	struct ti_port *tport;
 
 	tport = usb_get_serial_port_data(port);
+	ti_remove_sysfs_attrs(port);
 	kfree(tport);
 
 	return 0;
-- 
2.13.0

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

  parent reply	other threads:[~2017-08-18  2:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4a469222-d48d-f498-f2db-ca582295adc3@longlandclan.id.au>
     [not found] ` <4a469222-d48d-f498-f2db-ca582295adc3-3e+Fe6x+DsgJbe36r25VNhCuuivNXqWP@public.gmane.org>
2017-06-27  9:04   ` Moxa UPort 1150 and RS-422/485… what's the "proper" way to switch modes Johan Hovold
2017-06-27  9:43     ` Stuart Longland
     [not found]       ` <42601356-656d-57d0-d366-a0933780b8f9-3e+Fe6x+DsgJbe36r25VNhCuuivNXqWP@public.gmane.org>
2017-06-27 12:08         ` Oliver Neukum
     [not found]           ` <1498565331.30390.5.camel-IBi9RG/b67k@public.gmane.org>
2017-06-27 22:07             ` Stuart Longland
     [not found]               ` <ae2907c2-cb0f-61e4-c6f2-af3dcec93ace-3e+Fe6x+DsgJbe36r25VNhCuuivNXqWP@public.gmane.org>
2017-06-28  9:19                 ` Oliver Neukum
     [not found]                   ` <1498641549.10278.5.camel-IBi9RG/b67k@public.gmane.org>
2017-06-28 12:01                     ` Greg KH
     [not found]                       ` <20170628120120.GA10502-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2017-06-28 12:41                         ` Oliver Neukum
     [not found]                           ` <1498653709.10278.17.camel-IBi9RG/b67k@public.gmane.org>
2017-06-28 14:59                             ` Bjørn Mork
2017-06-28 15:35                 ` Johan Hovold
2017-06-28 15:34             ` Johan Hovold
2017-06-29 19:50               ` Alan Cox
2017-07-03  8:51                 ` Johan Hovold
2017-06-28 15:16         ` Johan Hovold
2017-08-18  2:56   ` Stuart Longland [this message]
     [not found]     ` <20170818025659.4402-1-stuartl-EoQOJlg3kTYQrrorzV6ljw@public.gmane.org>
2017-08-18  3:16       ` [PATCH] USB: serial: ti_usb_3410_5052: Port uart_mode from io_ti Stuart Longland
2017-08-19 20:40       ` Maksim Salau
     [not found]         ` <20170819234056.37c7d339-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-08-19 20:47           ` Stuart Longland
2017-08-28  8:56       ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170818025659.4402-1-stuartl@vrt.com.au \
    --to=stuartl-eoqojlg3ktyqrrorzv6ljw@public.gmane.org \
    --cc=alborchers-2TsfIrYsZRL7O9PZeWXHPg@public.gmane.org \
    --cc=linux-serial-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-usb-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.