Skip to contentSkip to conversation

Serial slave device bus

PATCH Superseded Rob Herring 2 participants 10 messages Jan 25, 2017 – Jan 31, 2017

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Rob Herring

author maintainer
#0 lore raw

v3 cover Serial slave device bus

Here's V3 of the serdev bus support with all the review feedback so far incorporated. Greg applied the first 4 patches already. I also found a problem in the tty_port_wakeup changes and have fixed that.

I've added serdev support to the BT hci_ll.c driver as it turns out it works on newer TI chips too, but just needed firmware loading. That avoids the impossible mess of cleaning up the TI-ST driver, and it's in a much closer state to being ready for upstream. I've sent that out separately.

Changelog is in individual patches. Previous versions are here[1][2]. This series and the mentioned drivers can be found here[3].

Rob

[1] http://www.mail-archive.com/[email protected]/msg1304151.html
[2] http://www.mail-archive.com/[email protected]/msg1311650.html
[3] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git serial-bus-v4

Rob Herring (5):
tty_port: Add port client functions dt/bindings: Add a serial/UART attached device binding
serdev: Introduce new bus for serial attached devices
serdev: add a tty port controller driver
tty_port: register tty ports with serdev bus

 .../devicetree/bindings/serial/slave-device.txt    |  36 ++
 MAINTAINERS                                        |   8 +
 drivers/char/Kconfig                               |   1 +
 drivers/tty/Makefile                               |   1 +
 drivers/tty/serdev/Kconfig                         |  16 +
 drivers/tty/serdev/Makefile                        |   5 +
 drivers/tty/serdev/core.c                          | 421 +++++++++++++++++++++
 drivers/tty/serdev/serdev-ttyport.c                | 226 +++++++++++
 drivers/tty/tty_buffer.c                           |  17 +-
 drivers/tty/tty_port.c                             |  58 ++-
 include/linux/serdev.h                             | 262 +++++++++++++
 include/linux/tty.h                                |   9 +-
 12 files changed, 1039 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/serial/slave-device.txt
 create mode 100644 drivers/tty/serdev/Kconfig
 create mode 100644 drivers/tty/serdev/Makefile
 create mode 100644 drivers/tty/serdev/core.c
 create mode 100644 drivers/tty/serdev/serdev-ttyport.c
 create mode 100644 include/linux/serdev.h

--
2.10.1

author maintainer
#1 lore raw

PATCH v3 1/5 tty_port: Add port client functions

Introduce a client (upward direction) operations struct for tty_port clients. Initially supported operations are for receiving data and write wake-up. This will allow for having clients other than an ldisc.

Convert the calls to the ldisc to use the client ops as the default operations.

---
v3:
- Restructured wakeup handling. We need to maintain the behavior of getting the tty ptr only once, otherwise the serial port can get in a bad state and stops responding.

v2:
- no change

 drivers/tty/tty_buffer.c | 17 +++--------------
 drivers/tty/tty_port.c   | 46 ++++++++++++++++++++++++++++++++++++++++------
 include/linux/tty.h      |  9 ++++++++-
 3 files changed, 51 insertions(+), 21 deletions(-)
drivers/tty/tty_buffer.c +3 -14
index f4dc3e296dd5..4e7a4e9dcf4d 100644
@@ -437,7 +437,7 @@ int tty_ldisc_receive_buf(struct tty_ldisc *ld, const unsigned char *p,
 EXPORT_SYMBOL_GPL(tty_ldisc_receive_buf);
 
 static int
-receive_buf(struct tty_ldisc *ld, struct tty_buffer *head, int count)
+receive_buf(struct tty_port *port, struct tty_buffer *head, int count)
 {
 	unsigned char *p = char_buf_ptr(head, head->read);
 	char	      *f = NULL;
@@ -445,7 +445,7 @@ receive_buf(struct tty_ldisc *ld, struct tty_buffer *head, int count)
 	if (~head->flags & TTYB_NORMAL)
 		f = flag_buf_ptr(head, head->read);
 
-	return tty_ldisc_receive_buf(ld, p, f, count);
+	return port->client_ops->receive_buf(port, p, f, count);
 }
 
 /**
@@ -465,16 +465,6 @@ static void flush_to_ldisc(struct work_struct *work)
 {
 	struct tty_port *port = container_of(work, struct tty_port, buf.work);
 	struct tty_bufhead *buf = &port->buf;
-	struct tty_struct *tty;
-	struct tty_ldisc *disc;
-
-	tty = READ_ONCE(port->itty);
-	if (tty == NULL)
-		return;
-
-	disc = tty_ldisc_ref(tty);
-	if (disc == NULL)
-		return;
 
 	mutex_lock(&buf->lock);
 
@@ -504,7 +494,7 @@ static void flush_to_ldisc(struct work_struct *work)
 			continue;
 		}
 
-		count = receive_buf(disc, head, count);
+		count = receive_buf(port, head, count);
 		if (!count)
 			break;
 		head->read += count;
@@ -512,7 +502,6 @@ static void flush_to_ldisc(struct work_struct *work)
 
 	mutex_unlock(&buf->lock);
 
-	tty_ldisc_deref(disc);
 }
 
 /**
drivers/tty/tty_port.c +40 -6

64 lines not on this page · raw message

include/linux/tty.h +8 -1
index 21c0fabfed60..1017e904c0a3 100644
@@ -217,12 +217,18 @@ struct tty_port_operations {
 	/* Called on the final put of a port */
 	void (*destruct)(struct tty_port *port);
 };
-
+
+struct tty_port_client_operations {
+	int (*receive_buf)(struct tty_port *port, const unsigned char *, const unsigned char *, size_t);
+	void (*write_wakeup)(struct tty_port *port);
+};
+
 struct tty_port {
 	struct tty_bufhead	buf;		/* Locked internally */
 	struct tty_struct	*tty;		/* Back pointer */
 	struct tty_struct	*itty;		/* internal back ptr */
 	const struct tty_port_operations *ops;	/* Port operations */
+	const struct tty_port_client_operations *client_ops; /* Port client operations */
 	spinlock_t		lock;		/* Lock protecting tty field */
 	int			blocked_open;	/* Waiting to open */
 	int			count;		/* Usage count */
@@ -241,6 +247,7 @@ struct tty_port {
 						   based drain is needed else
 						   set to size of fifo */
 	struct kref		kref;		/* Ref counter */
+	void 			*client_data;
 };
 
 /* tty_port::iflags bits -- use atomic bit ops */

--
2.10.1

author maintainer
#2 lore raw

PATCH v3 2/5 dt/bindings: Add a serial/UART attached device binding

In reply to Rob Herring

Add a common binding for describing serial/UART attached devices. Common examples are Bluetooth, WiFi, NFC and GPS devices.

Serial attached devices are represented as child nodes of a UART node. This may need to be extended for more complex devices with multiple interfaces, but for the simple cases a child node is sufficient.

---
v3:
- no change

v2:
- Drop reg property
- Add max-speed property

 .../devicetree/bindings/serial/slave-device.txt    | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/slave-device.txt
Documentation/devicetree/bindings/serial/slave-device.txt new file +36 -0
new file mode 100644
index 000000000000..f66037928f5f
@@ -0,0 +1,36 @@
+Serial Slave Device DT binding
+
+This documents the binding structure and common properties for serial
+attached devices. Common examples include Bluetooth, WiFi, NFC and GPS
+devices.
+
+Serial attached devices shall be a child node of the host UART device the
+slave device is attached to. It is expected that the attached device is
+the only child node of the UART device. The slave device node name shall
+reflect the generic type of device for the node.
+
+Required Properties:
+
+- compatible 	: A string reflecting the vendor and specific device the node
+		  represents.
+
+Optional Properties:
+
+- max-speed	: The maximum baud rate the device operates at. This should
+		  only be present if the maximum is less than the slave device
+		  can support. For example, a particular board has some signal
+		  quality issue or the host processor can't support higher
+		  baud rates.
+
+Example:
+
+serial@1234 {
+	compatible = "ns16550a";
+	interrupts = <1>;
+
+	bluetooth {
+		compatible = "brcm,bcm43341-bt";
+		interrupt-parent = <&gpio>;
+		interrupts = <10>;
+	};
+};
Signature · 1 line
2.10.1
author maintainer
#3 lore raw

PATCH v3 3/5 serdev: Introduce new bus for serial attached devices

In reply to Rob Herring

The serdev bus is designed for devices such as Bluetooth, WiFi, GPS and NFC connected to UARTs on host processors. Tradionally these have been handled with tty line disciplines, rfkill, and userspace glue such as hciattach. This approach has many drawbacks since it doesn't fit into the Linux driver model. Handling of sideband signals, power control and firmware loading are the main issues.

This creates a serdev bus with controllers (i.e. host serial ports) and attached devices. Typically, these are point to point connections, but some devices have muxing protocols or a h/w mux is conceivable. Any muxing is not yet supported with the serdev bus.

---
v3:
- Added empty device functions for !CONFIG_SERIAL_DEV_BUS

v2:
- Change the sysfs visible names to "serial". Kept serdev as kernel internal name.
- Make function ptr checks and calls follow a consistent structure
- Return error if controller .open() is missing
- Sort includes
- Add an ACPI TODO note
- Fix serdev_controller_add error path handling
- Fix DT child device adding error handling
- Add modalias sysfs attr and uevent hook
- Fix module email address

 MAINTAINERS                 |   8 +
 drivers/char/Kconfig        |   1 +
 drivers/tty/Makefile        |   1 +
 drivers/tty/serdev/Kconfig  |   8 +
 drivers/tty/serdev/Makefile |   3 +
 drivers/tty/serdev/core.c   | 421 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/serdev.h      | 241 +++++++++++++++++++++++++
 7 files changed, 683 insertions(+)
 create mode 100644 drivers/tty/serdev/Kconfig
 create mode 100644 drivers/tty/serdev/Makefile
 create mode 100644 drivers/tty/serdev/core.c
 create mode 100644 include/linux/serdev.h
MAINTAINERS +8 -0
index c36976d3bd1a..90db2b5d418c 100644
@@ -10831,6 +10831,14 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/serial/
 F:	drivers/tty/serial/
 
+SERIAL DEVICE BUS
+M:	Rob Herring <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/serial/slave-device.txt
+F:	drivers/tty/serdev/
+F:	include/linux/serdev.h
+
 SERIAL IR RECEIVER
 M:	Sean Young <[email protected]>
 L:	[email protected]
drivers/char/Kconfig +1 -0
index fde005ef9d36..db8f74bbaf3e 100644
@@ -46,6 +46,7 @@ config SGI_MBCS
          say Y or M here, otherwise say N.
 
 source "drivers/tty/serial/Kconfig"
+source "drivers/tty/serdev/Kconfig"
 
 config TTY_PRINTK
 	tristate "TTY driver to output user messages via printk"
drivers/tty/Makefile +1 -0
index 5817e2397463..b95bed92da9f 100644
@@ -13,6 +13,7 @@ obj-$(CONFIG_R3964)		+= n_r3964.o
 obj-y				+= vt/
 obj-$(CONFIG_HVC_DRIVER)	+= hvc/
 obj-y				+= serial/
+obj-$(CONFIG_SERIAL_DEV_BUS)	+= serdev/
 
 # tty drivers
 obj-$(CONFIG_AMIGA_BUILTIN_SERIAL) += amiserial.o
drivers/tty/serdev/Kconfig new file +8 -0
new file mode 100644
index 000000000000..3b6ecd187bef
@@ -0,0 +1,8 @@
+#
+# Serial bus device driver configuration
+#
+menuconfig SERIAL_DEV_BUS
+	tristate "Serial device bus"
+	help
+	  Core support for devices connected via a serial port.
+
drivers/tty/serdev/Makefile new file +3 -0
new file mode 100644
index 000000000000..01a9b62183f4
@@ -0,0 +1,3 @@
+serdev-objs := core.o
+
+obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o
drivers/tty/serdev/core.c new file +421 -0

421 lines not on this page · raw message

include/linux/serdev.h new file +241 -0

241 lines not on this page · raw message

Signature · 1 line
2.10.1
#4 lore raw

Re: [PATCH v3 3/5] serdev: Introduce new bus for serial attached devices

Hi Rob,

Quoted 12 lines · Rob Herring
include/linux/serdev.h new file +1 -0
new file mode 100644
index 000000000000..4f8f76d02ca8
 
[...]
 
+#ifdef CONFIG_SERIAL_DEV_BUS

[method definitions]

Quoted 7 lines

#else

[method stubs]

#endif

[...]

This should also test for SERIAL_DEV_BUS=m, so use

#if IS_ENABLED(CONFIG_SERIAL_DEV_BUS)

(This was found by the kbuild test robot)

-- Sebastian

author maintainer
#5 lore raw

PATCH v3 4/5 serdev: add a tty port controller driver

In reply to Rob Herring

Add a serdev controller driver for tty ports.

The controller is registered with serdev when tty ports are registered with the TTY core. As the TTY core is built-in only, this has the side effect of making serdev built-in as well.

---
v3:
- Handle testing TTY_DO_WRITE_WAKEUP in write_wakeup callback due to tty core change in patch #1.
- Remove the mutex. The atomic bit is enough.
- Removed unused atomic bit defines.
- Made ctrl_ops static and const.

v2:
- Sort includes
- Made goto labels more descriptive
- Use tty-> instead of serdev->tty-> where possible
- Drop DT specific check in serdev_tty_port_register. DT specifics are only in core bus code now.
- Comments on #endif's
- Use "depends on SERIAL_DEV_BUS != m" instead of "= y"
- Dropped module properties (not a module)

 drivers/tty/serdev/Kconfig          |   8 ++
 drivers/tty/serdev/Makefile         |   2 +
 drivers/tty/serdev/serdev-ttyport.c | 226 ++++++++++++++++++++++++++++++++++++
 include/linux/serdev.h              |  21 ++++
 4 files changed, 257 insertions(+)
 create mode 100644 drivers/tty/serdev/serdev-ttyport.c
drivers/tty/serdev/Kconfig +8 -0
index 3b6ecd187bef..cdc6b820cf93 100644
@@ -6,3 +6,11 @@ menuconfig SERIAL_DEV_BUS
 	help
 	  Core support for devices connected via a serial port.
 
+if SERIAL_DEV_BUS
+
+config SERIAL_DEV_CTRL_TTYPORT
+	bool "Serial device TTY port controller"
+	depends on TTY
+	depends on SERIAL_DEV_BUS != m
+
+endif
drivers/tty/serdev/Makefile +2 -0
index 01a9b62183f4..0cbdb9444d9d 100644
@@ -1,3 +1,5 @@
 serdev-objs := core.o
 
 obj-$(CONFIG_SERIAL_DEV_BUS) += serdev.o
+
+obj-$(CONFIG_SERIAL_DEV_CTRL_TTYPORT) += serdev-ttyport.o
drivers/tty/serdev/serdev-ttyport.c new file +226 -0

226 lines not on this page · raw message

include/linux/serdev.h +21 -0
index 4f8f76d02ca8..c1b498c1eeb3 100644
@@ -238,4 +238,25 @@ static inline int serdev_device_write_room(struct serdev_device *sdev)
 
 #endif /* CONFIG_SERIAL_DEV_BUS */
 
+/*
+ * serdev hooks into TTY core
+ */
+struct tty_port;
+struct tty_driver;
+
+#ifdef CONFIG_SERIAL_DEV_CTRL_TTYPORT
+struct device *serdev_tty_port_register(struct tty_port *port,
+					struct device *parent,
+					struct tty_driver *drv, int idx);
+void serdev_tty_port_unregister(struct tty_port *port);
+#else
+static inline struct device *serdev_tty_port_register(struct tty_port *port,
+					   struct device *parent,
+					   struct tty_driver *drv, int idx)
+{
+	return ERR_PTR(-ENODEV);
+}
+static inline void serdev_tty_port_unregister(struct tty_port *port) {}
+#endif /* CONFIG_SERIAL_DEV_CTRL_TTYPORT */
+
 #endif /*_LINUX_SERDEV_H */
Signature · 1 line
2.10.1
author maintainer
#6 lore raw

PATCH v3 5/5 tty_port: register tty ports with serdev bus

In reply to Rob Herring

Register a serdev controller with the serdev bus when a tty_port is registered. This creates the serdev controller and create's serdev devices for any DT child nodes of the tty_port's parent (i.e. the UART device).

---
v3:
- no change

v2:
- Skip creating the tty device file node when serdev_tty_port_register finds slave devices.

 drivers/tty/tty_port.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/tty/tty_port.c +12 -0
index 8d9886b06037..5cd3cd932293 100644
@@ -16,6 +16,7 @@
 #include <linux/bitops.h>
 #include <linux/delay.h>
 #include <linux/module.h>
+#include <linux/serdev.h>
 
 static int tty_port_default_receive_buf(struct tty_port *port,
 					const unsigned char *p,
@@ -128,7 +129,15 @@ struct device *tty_port_register_device_attr(struct tty_port *port,
 		struct device *device, void *drvdata,
 		const struct attribute_group **attr_grp)
 {
+	struct device *dev;
+
 	tty_port_link_device(port, driver, index);
+
+	dev = serdev_tty_port_register(port, device, driver, index);
+	if (PTR_ERR(dev) != -ENODEV)
+		/* Skip creating cdev if we registered a serdev device */
+		return dev;
+
 	return tty_register_device_attr(driver, index, device, drvdata,
 			attr_grp);
 }
@@ -180,6 +189,9 @@ static void tty_port_destructor(struct kref *kref)
 	/* check if last port ref was dropped before tty release */
 	if (WARN_ON(port->itty))
 		return;
+
+	serdev_tty_port_unregister(port);
+
 	if (port->xmit_buf)
 		free_page((unsigned long)port->xmit_buf);
 	tty_port_destroy(port);
Signature · 1 line
2.10.1
Tested-by on the v3 series
#7 lore raw
In reply to Rob Herring

Hi,

Quoted 9 lines · Rob Herring

Here's V3 of the serdev bus support with all the review feedback so far incorporated. Greg applied the first 4 patches already. I also found a problem in the tty_port_wakeup changes and have fixed that.

I've added serdev support to the BT hci_ll.c driver as it turns out it works on newer TI chips too, but just needed firmware loading. That avoids the impossible mess of cleaning up the TI-ST driver, and it's in a much closer state to being ready for upstream. I've sent that out separately.

Quoted 8 lines

Changelog is in individual patches. Previous versions are here[1][2]. This series and the mentioned drivers can be found here[3].

Rob

[1] http://www.mail-archive.com/[email protected]/msg1304151.html
[2] http://www.mail-archive.com/[email protected]/msg1311650.html
[3] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git serial-bus-v4

I rebased my nokia bluetooth driver on top of [3]. It's not yet working, but everything added by this patchset (and "bluetooth: hci_uart: add serdev driver support library") seems to work as expected, so for the whole series:

-- Sebastian

#8 lore raw

Hi,

Quoted 19 lines · Sebastian Reichel
Quoted 9 lines · Rob Herring

Here's V3 of the serdev bus support with all the review feedback so far incorporated. Greg applied the first 4 patches already. I also found a problem in the tty_port_wakeup changes and have fixed that.

I've added serdev support to the BT hci_ll.c driver as it turns out it works on newer TI chips too, but just needed firmware loading. That avoids the impossible mess of cleaning up the TI-ST driver, and it's in a much closer state to being ready for upstream. I've sent that out separately.

Quoted 8 lines

Changelog is in individual patches. Previous versions are here[1][2]. This series and the mentioned drivers can be found here[3].

Rob

[1] http://www.mail-archive.com/[email protected]/msg1304151.html
[2] http://www.mail-archive.com/[email protected]/msg1311650.html
[3] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git serial-bus-v4

Quoted 6 lines

I rebased my nokia bluetooth driver on top of [3]. It's not yet working, but everything added by this patchset (and "bluetooth: hci_uart: add serdev driver support library") seems to work as expected, so for the whole series:

FWIW, I got bluetooth on top of your patchset working on N950. N900 is not yet tested and probably does not yet work (it's more picky about flow control and usage of the wakeup gpios). You can find a branch with the additional patches @ [4]. I had to add serdev functions to wait for TX buffer depletion and checking CTS. Apart from that flow control only worked correctly when also taking care of RTS (like hci_uart_set_flow_control does).

I noticed, that you did not yet write any DT bindings for your bluetooth slaves. Did you already decide for a location?

[4] git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-n900.git serial-bus-v4-nokia-bt

-- Sebastian

author maintainer
#9 lore raw
Quoted 28 lines · Sebastian Reichel

Hi,

Quoted 25 lines · Sebastian Reichel
Quoted 9 lines · Rob Herring

Here's V3 of the serdev bus support with all the review feedback so far incorporated. Greg applied the first 4 patches already. I also found a problem in the tty_port_wakeup changes and have fixed that.

I've added serdev support to the BT hci_ll.c driver as it turns out it works on newer TI chips too, but just needed firmware loading. That avoids the impossible mess of cleaning up the TI-ST driver, and it's in a much closer state to being ready for upstream. I've sent that out separately.

Quoted 8 lines

Changelog is in individual patches. Previous versions are here[1][2]. This series and the mentioned drivers can be found here[3].

Rob

[1] http://www.mail-archive.com/[email protected]/msg1304151.html
[2] http://www.mail-archive.com/[email protected]/msg1311650.html
[3] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git serial-bus-v4

I rebased my nokia bluetooth driver on top of [3]. It's not yet working, but everything added by this patchset (and "bluetooth: hci_uart: add serdev driver support library") seems to work as expected, so for the whole series:

Thanks.

Quoted 7 lines

FWIW, I got bluetooth on top of your patchset working on N950. N900 is not yet tested and probably does not yet work (it's more picky about flow control and usage of the wakeup gpios). You can find a branch with the additional patches @ [4]. I had to add serdev functions to wait for TX buffer depletion and checking CTS. Apart from that flow control only worked correctly when also taking care of RTS (like hci_uart_set_flow_control does).

I'd originally copied hci_uart_set_flow_control, but then realized that it didn't really do what I wanted. What I have now is turn on or off h/w control (i.e. off is no RTS/CTS signals connected). What hci_uart_set_flow_control does is enable h/w flow control (enable=false) or force assert RTS (enable=true). I guess it didn't help that I used the same _set_flow_control naming with different behavior. I did expect we'd also need something for RTS control, but figured we'd add it as needed and wanted to come up with something a bit clearer as to the function (i.e. serdev_device_pause_rx or serdev_device_assert_rts).

Quoted 2 lines

I noticed, that you did not yet write any DT bindings for your bluetooth slaves. Did you already decide for a location?

Marvell BT is already in bindings/net/.

Rob

Quoted 4 lines

[4] git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-n900.git serial-bus-v4-nokia-bt

-- Sebastian