Serial slave device bus
Subsystems (5)
Rob Herring
maintainerv4 cover Serial slave device bus
Here's V4 of the serdev bus support. Just 2 small fixes from V3 and Sebastian's Tested-by(Thanks!). I fixed a module build breakage in serdev.h and dropped setting of receive_room. It was only needed for the ldisc->receive_buf() function.
There's a few additions Sebastion needed for more serial port control of RTS/CTS. I think these can be added on top of this series as drivers need them.
Changelog is in individual patches. Previous versions are here[1][2][3]. This series and the mentioned drivers can be found here[4].
Rob
[1] http://www.mail-archive.com/[email protected]/msg1304151.html
[2] http://www.mail-archive.com/[email protected]/msg1311650.html
[3] https://www.mail-archive.com/[email protected]/msg1318626.html
[4] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git serial-bus-v5
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 | 224 +++++++++++ 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, 1037 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
Signature · 1 line
2.10.1
Rob Herring
maintainerPATCH v4 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.
---
v4:
- no change
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
@@ -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
@@ -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 */
Signature · 1 line
2.10.1
Rob Herring
maintainerPATCH v4 2/5 dt/bindings: Add a serial/UART attached device binding
In reply to Rob HerringAdd 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.
---
v4:
- no change
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
@@ -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
Rob Herring
maintainerPATCH v4 3/5 serdev: Introduce new bus for serial attached devices
In reply to Rob HerringThe 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.
---
v4:
- Use IS_ENABLED() in serdev.h to fix module builds 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Rob Herring
maintainerPATCH v4 4/5 serdev: add a tty port controller driver
In reply to Rob HerringAdd 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.
---
v4:
- Remove setting of tty->receive_room. Was only necessary for old ldisc->receive_buf() function.
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 | 224 ++++++++++++++++++++++++++++++++++++ include/linux/serdev.h | 21 ++++ 4 files changed, 255 insertions(+) create mode 100644 drivers/tty/serdev/serdev-ttyport.c
drivers/tty/serdev/Kconfig +8 -0
@@ -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
@@ -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 +224 -0
224 lines not on this page · raw message
include/linux/serdev.h +21 -0
@@ -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
Rob Herring
maintainerPATCH v4 5/5 tty_port: register tty ports with serdev bus
In reply to Rob HerringRegister 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).
---
v4:
- no change
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
@@ -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