Serial slave device bus
Subsystems (6)
Rob Herring
maintainerv2 cover Serial slave device bus
Here's a new version of the serdev bus support with all the review feedback so far incorporated. I've left it named serdev for now pending any further votes one way or the other, but I did rename the sysfs visible portions to "serial".
There's still some discussion about what to do with devices that pass thru data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
I need a SoB from Alan on his patch 2 and would like review from Alan and/or Peter on the locking in patch 5.
I have hacked up versions of the BT ldisc and TI ST drivers moved over to use the serdev bus. I have BT working on the HiKey board which has TI BT. With the serdev bus support, it eliminates the need for the TI userspace UIM daemon. I've made some progress cleaning up the TI-ST into proper patches and also got it working at 3Mbps.
Changelog is in individual patches. Previous version is here[1]. This series and the mentioned drivers can be found here[2].
Rob
[1] https://lkml.org/lkml/2017/1/6/411
[2] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git serial-bus-v3
Alan Cox (1):
tty_port: allow a port to be opened with a tty that has no file handle
Rob Herring (8):
tty: move the non-file related parts of tty_release to new
tty_release_struct
tty_port: make tty_port_register_device wrap
tty_port_register_device_attr
tty: constify tty_ldisc_receive_buf buffer pointer
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 | 240 ++++++++++++ drivers/tty/tty_buffer.c | 19 +- drivers/tty/tty_io.c | 52 ++- drivers/tty/tty_port.c | 58 ++- include/linux/serdev.h | 234 ++++++++++++ include/linux/tty.h | 12 +- 13 files changed, 1062 insertions(+), 41 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
Rob Herring
maintainerPATCH v2 1/9 tty: move the non-file related parts of tty_release to new tty_release_struct
For in-kernel tty users, we need to be able to create and destroy 'struct tty' that are not associated with a file. The creation side is fine, but tty_release() needs to be split into the file handle portion and the struct tty portion. Introduce a new function, tty_release_struct, to handle just the destroying of a struct tty.
---
v2:
- Add kerneldoc for tty_release_struct
drivers/tty/tty_io.c | 50 ++++++++++++++++++++++++++++++++------------------ include/linux/tty.h | 1 + 2 files changed, 33 insertions(+), 18 deletions(-)
drivers/tty/tty_io.c +32 -18
@@ -1745,6 +1745,37 @@ static int tty_release_checks(struct tty_struct *tty, int idx) }/** +* tty_release_struct - release a tty struct +* @tty: tty device +* @idx: index of the tty +* +* Performs the final steps to release and free a tty device. It is +* roughly the reverse of tty_init_dev. +*/ +void tty_release_struct (struct tty_struct *tty,int idx) +{ +/* +* Ask the line discipline code to release its structures +*/ +tty_ldisc_release (tty); + +/* Wait for pending work before tty destruction commmences */ +tty_flush_works (tty); + +tty_debug_hangup (tty,"freeing structure\n" ); +/* +* The release_tty function takes care of the details of clearing +* the slots and preserving the termios structure. The tty_unlock_pair +* should be safe as we keep a kref while the tty is locked (so the +* unlock never unlocks a freed tty). +*/ +mutex_lock (&tty_mutex); +release_tty (tty, idx); +mutex_unlock (&tty_mutex); +} +EXPORT_SYMBOL_GPL (tty_release_struct); + +/** * tty_release - vfs callback for close * @inode: inode of tty * @filp: file pointer for handle to tty
@@ -1898,25 +1929,8 @@ int tty_release(struct inode *inode, struct file *filp)return 0 ;tty_debug_hangup (tty,"final close\n" ); -/* -* Ask the line discipline code to release its structures -*/ -tty_ldisc_release (tty); - -/* Wait for pending work before tty destruction commmences */ -tty_flush_works (tty); - -tty_debug_hangup (tty,"freeing structure\n" ); -/* -* The release_tty function takes care of the details of clearing -* the slots and preserving the termios structure. The tty_unlock_pair -* should be safe as we keep a kref while the tty is locked (so the -* unlock never unlocks a freed tty). -*/ -mutex_lock (&tty_mutex); -release_tty (tty, idx); -mutex_unlock (&tty_mutex); +tty_release_struct (tty, idx);return 0 ; }
include/linux/tty.h +1 -0
@@ -528,6 +528,7 @@ extern int tty_alloc_file(struct file *file);extern void tty_add_file (struct tty_struct *tty,struct file *file);extern void tty_free_file (struct file *file);extern struct tty_struct *tty_init_dev (struct tty_driver *driver,int idx); +extern void tty_release_struct (struct tty_struct *tty,int idx);extern int tty_release (struct inode *inode,struct file *filp);extern void tty_init_termios (struct tty_struct *tty); extern int tty_standard_install(struct tty_driver *driver,
--
2.10.1
Rob Herring
maintainerPATCH v2 2/9 tty_port: allow a port to be opened with a tty that has no file handle
In reply to Rob HerringFrom: Alan Cox <[email protected]>
Let us create tty objects entirely in kernel space. Untested proposal to show why all the ideas around rewriting half the uart stack are not needed.
With this a kernel created non file backed tty object could be used to handle data, and set terminal modes. Not all ldiscs can cope with this as N_TTY in particular has to work back to the fs/tty layer.
The tty_port code is however otherwise clean of file handles as far as I can tell as is the low level tty port write path used by the ldisc, the configuration low level interfaces and most of the ldiscs.
Currently you don't have any exposure to see tty hangups because those are built around the file layer. However a) it's a fixed port so you probably don't care about that b) if you do we can add a callback and c) you almost certainly don't want the userspace tear down/rebuild behaviour anyway.
This should however be sufficient if we wanted for example to enumerate all the bluetooth bound fixed ports via ACPI and make them directly available. It doesn't deal with the case of a user opening a port that's also kernel opened and that would need some locking out (so it returned EBUSY if bound to a kernel device of some kind). That needs resolving along with how you "up" or "down" your new bluetooth device, or enumerate it while providing the existing tty API to avoid regressions (and to debug).
Alan
---
Alan, Need your SoB here.
v2:
- no change
drivers/tty/tty_io.c | 2 +- drivers/tty/tty_port.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/tty/tty_io.c +1 -1
@@ -855,7 +855,7 @@ static void tty_vhangup_session(struct tty_struct *tty)int tty_hung_up_p (struct file *filp) { -return (filp->f_op == &hung_up_tty_fops); +return (filp && filp->f_op == &hung_up_tty_fops); }EXPORT_SYMBOL (tty_hung_up_p);
drivers/tty/tty_port.c +2 -2
@@ -335,7 +335,7 @@ EXPORT_SYMBOL(tty_port_lower_dtr_rts);* tty_port_block_til_ready - Waiting logic for tty open * @port: the tty port being opened * @tty: the tty device being bound -* @filp: the file pointer of the opener +* @filp: the file pointer of the opener or NULL * * Implement the core POSIX/SuS tty behaviour when opening a tty device. * Handles:
@@ -369,7 +369,7 @@ int tty_port_block_til_ready(struct tty_port *port,tty_port_set_active (port,1 );return 0 ; } -if (filp->f_flags &O_NONBLOCK ) { +if (filp ==NULL || (filp->f_flags &O_NONBLOCK )) {/* Indicate we are open */ if (C_BAUD (tty))tty_port_raise_dtr_rts (port);
--
2.10.1
Rob Herring
maintainerPATCH v2 3/9 tty_port: make tty_port_register_device wrap tty_port_register_device_attr
In reply to Rob Herringtty_register_device is just a wrapper for tty_register_device_attr with NULL passed for drvdata and attr_grp. So similarly make tty_port_register_device a wrapper of tty_port_register_device_attr so that additions don't have to be made in both functions.
---
v2:
- no change
drivers/tty/tty_port.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/tty_port.c +1 -2
@@ -67,8 +67,7 @@ struct device *tty_port_register_device(struct tty_port *port, struct tty_driver *driver, unsigned index, struct device *device) { -tty_port_link_device (port ,driver ,index ); -return tty_register_device (driver, index, device); + return tty_port_register_device_attr(port, driver, index, device, NULL, NULL); }EXPORT_SYMBOL_GPL (tty_port_register_device);
--
2.10.1
Rob Herring
maintainerPATCH v2 4/9 tty: constify tty_ldisc_receive_buf buffer pointer
In reply to Rob HerringThis is needed to work with the client operations which uses const ptrs.
Really, the flags pointer could be const, too, but this would be a tree wide fix.
---
v2:
- no change
drivers/tty/tty_buffer.c | 2 +- include/linux/tty.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/tty/tty_buffer.c +1 -1
@@ -422,7 +422,7 @@ EXPORT_SYMBOL_GPL(tty_prepare_flip_string);* * Returns the number of bytes not processed */ -int tty_ldisc_receive_buf (struct tty_ldisc *ld,unsigned char *p, +int tty_ldisc_receive_buf (struct tty_ldisc *ld,const unsigned char *p,char *f,int count) {if (ld->ops->receive_buf2)
include/linux/tty.h +1 -1
@@ -657,7 +657,7 @@ extern int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);extern void tty_ldisc_release (struct tty_struct *tty);extern void tty_ldisc_init (struct tty_struct *tty);extern void tty_ldisc_deinit (struct tty_struct *tty); -extern int tty_ldisc_receive_buf (struct tty_ldisc *ld,unsigned char *p, +extern int tty_ldisc_receive_buf (struct tty_ldisc *ld,const unsigned char *p,char *f,int count);/* n_tty.c */
--
2.10.1
Rob Herring
maintainerPATCH v2 5/9 tty_port: Add port client functions
In reply to Rob HerringIntroduce 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.
---
v2:
- no change
drivers/tty/tty_buffer.c | 17 +++-------------- drivers/tty/tty_port.c | 39 ++++++++++++++++++++++++++++++++++++++- include/linux/tty.h | 9 ++++++++- 3 files changed, 49 insertions(+), 16 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 +38 -1
@@ -17,6 +17,41 @@#include <linux/delay.h> #include <linux/module.h> +static int tty_port_default_receive_buf (struct tty_port *port, +const unsigned char *p, +const unsigned char *f,size_t count) +{ +int ret; +struct tty_struct *tty; +struct tty_ldisc *disc; + + tty =READ_ONCE (port->itty); +if (!tty) +return 0 ; + + disc =tty_ldisc_ref (tty); +if (!disc) +return 0 ; + + ret =tty_ldisc_receive_buf (disc, p, (char *)f, count); + +tty_ldisc_deref (disc); + +return ret; +} + +static void tty_port_default_wakeup (struct tty_port *port) +{ +/* tty_port_tty_wakeup already took a reference to the tty */ +tty_wakeup (port->tty); +} + +static const struct tty_port_client_operations default_client_ops = { + .receive_buf = tty_port_default_receive_buf, + .write_wakeup = tty_port_default_wakeup, +}; + +void tty_port_init (struct tty_port *port) {memset (port,0 ,sizeof (*port));
@@ -28,6 +63,7 @@ void tty_port_init(struct tty_port *port)spin_lock_init (&port->lock); port->close_delay = (50 *HZ ) /100 ; port->closing_wait = (3000 *HZ ) /100 ; + port->client_ops = &default_client_ops;kref_init (&port->kref); }EXPORT_SYMBOL (tty_port_init);
@@ -275,7 +311,8 @@ void tty_port_tty_wakeup(struct tty_port *port)struct tty_struct *tty =tty_port_tty_get (port);if (tty) { -tty_wakeup (tty); +if (test_bit (TTY_DO_WRITE_WAKEUP , &tty->flags)) + port->client_ops->write_wakeup (port);tty_kref_put (tty); } }
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 */
--
2.10.1
Rob Herring
maintainerPATCH v2 6/9 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.
---
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>; + }; +};
--
2.10.1
Rob Herring
maintainerPATCH v2 7/9 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.
---
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 | 213 ++++++++++++++++++++++ 7 files changed, 655 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 +213 -0
213 lines not on this page · raw message
--
2.10.1
Rob Herring
maintainerPATCH v2 8/9 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.
---
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 | 240 ++++++++++++++++++++++++++++++++++++ include/linux/serdev.h | 21 ++++ 4 files changed, 271 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 +240 -0
240 lines not on this page · raw message
include/linux/serdev.h +21 -0
@@ -210,4 +210,25 @@ static inline int serdev_controller_receive_buf(struct serdev_controller *ctrl, return serdev->ops->receive_buf(ctrl->serdev, data, count); } +/* +* 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 */
--
2.10.1
Rob Herring
maintainerPATCH v2 9/9 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).
---
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,
@@ -125,7 +126,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); }
@@ -177,6 +186,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);
--
2.10.1
Hi!
Quoted 14 lines
Here's a new version of the serdev bus support with all the review feedback so far incorporated. I've left it named serdev for now pending any further votes one way or the other, but I did rename the sysfs visible portions to "serial".
There's still some discussion about what to do with devices that pass thru data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
I need a SoB from Alan on his patch 2 and would like review from Alan and/or Peter on the locking in patch 5.
Quoted 8 lines
I have hacked up versions of the BT ldisc and TI ST drivers moved over to use the serdev bus. I have BT working on the HiKey board which has TI BT. With the serdev bus support, it eliminates the need for the TI userspace UIM daemon. I've made some progress cleaning up the TI-ST into proper patches and also got it working at 3Mbps.
Changelog is in individual patches. Previous version is here[1]. This series and the mentioned drivers can be found here[2].
Series looks good to me. Thanks for doing the work.
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: [PATCH v2 2/9] tty_port: allow a port to be opened with a tty that has no file handle
In reply to Rob HerringQuoted 26 lines · On Mon, 16 Jan 2017 16:54:29 -0600 Rob Herring <[email protected]> wrote:
From: Alan Cox <[email protected]>
Let us create tty objects entirely in kernel space. Untested proposal to show why all the ideas around rewriting half the uart stack are not needed.
With this a kernel created non file backed tty object could be used to handle data, and set terminal modes. Not all ldiscs can cope with this as
N_TTYin particular has to work back to the fs/tty layer.The
tty_portcode is however otherwise clean of file handles as far as I can tell as is the low level tty port write path used by the ldisc, the configuration low level interfaces and most of the ldiscs.Currently you don't have any exposure to see tty hangups because those are built around the file layer. However a) it's a fixed port so you probably don't care about that b) if you do we can add a callback and c) you almost certainly don't want the userspace tear down/rebuild behaviour anyway.
This should however be sufficient if we wanted for example to enumerate all the bluetooth bound fixed ports via ACPI and make them directly available. It doesn't deal with the case of a user opening a port that's also kernel opened and that would need some locking out (so it returned EBUSY if bound to a kernel device of some kind). That needs resolving along with how you "up" or "down" your new bluetooth device, or enumerate it while providing the existing tty API to avoid regressions (and to debug).
Quoted 5 lines
Alan
Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>---
Alan, Need your SoB here.
Alan
Re: [PATCH v2 7/9] serdev: Introduce new bus for serial attached devices
In reply to Rob HerringHello,
Quoted 3 lines · Rob Herring
---
v2:
- Add modalias sysfs attr and uevent hook
...
Quoted 5 lines
drivers/tty/serdev/core.c new file +5
-0+static int serdev_uevent (struct device *dev,struct kobj_uevent_env *env) +{ +/* TODO: ACPI and platform modalias */ +return of_device_uevent_modalias (dev, env); +}
...
drivers/tty/serdev/core.c line 198
Quoted 8 lines
drivers/tty/serdev/core.c new file +8
-0+static ssize_t modalias_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t len =of_device_get_modalias (dev, buf,PAGE_SIZE -2 ); + buf[len] ='\n' ; + buf[len+1 ] =0 ; +return len+1 ; +}
This prevents from building serdev as a module with following errors:
ERROR: "of_device_uevent_modalias" [drivers/tty/serdev/serdev.ko]
undefined!
ERROR: "of_device_get_modalias" [drivers/tty/serdev/serdev.ko] undefined!
Currently, those symbols are not exported in drivers/of/device.c
Frédéric Danis
Re: [PATCH v2 8/9] serdev: add a tty port controller driver
In reply to Rob HerringQuoted 8 lines · 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.
drivers/tty/serdev/Kconfig menuconfig SERIAL_DEV_BUS · line 14
Quoted 8 lines
drivers/tty/serdev/Kconfig +6
-0+if SERIAL_DEV_BUS + +config SERIAL_DEV_CTRL_TTYPORT + bool "Serial device TTY port controller" + depends on TTY + depends on SERIAL_DEV_BUS != m
Since you have this line the
if SERIAL_DEV_BUS
is redundant for it.
So, leave either one or another (as an example you can look at DMADEVICES).
drivers/tty/serdev/serdev-ttyport.c line 26
Quoted 11 lines
drivers/tty/serdev/serdev-ttyport.c new file +10
-0+ +#define SERPORT_BUSY 1 +#define SERPORT_ACTIVE 2 +#define SERPORT_DEAD 3 + +struct serport { +struct tty_port *port; +struct tty_struct *tty; +struct tty_driver *tty_drv; +int tty_idx;
Do you need tty_ prefix for them?
Quoted 16 lines
drivers/tty/serdev/serdev-ttyport.c new file +9
-0+struct mutex lock; +unsigned long flags; +}; + +/* +* Callback functions from the tty port. +*/ + +static int ttyport_receive_buf(struct tty_port *port, const unsignedchar *cp,
(quoted diff) +1
-0+ const unsigned char *fp, size_tcount)
drivers/tty/serdev/serdev-ttyport.c new file +3
-0+{ +struct serdev_controller *ctrl = port->client_data; + struct serport *serport =
serdev_controller_get_drvdata(ctrl);
drivers/tty/serdev/serdev-ttyport.c line 43
Quoted 4 lines
drivers/tty/serdev/serdev-ttyport.c new file +4
-0+ +mutex_lock (&serport->lock); + +if (!test_bit (SERPORT_ACTIVE , &serport->flags))
So, if you are going to use serport->flags always under lock, you don't need to use atomic bit operations.
Either
__test_bit() and Co
Or
flags & BIT(x)
Quoted 14 lines
drivers/tty/serdev/serdev-ttyport.c new file +13
-0+ goto out_unlock; + +serdev_controller_receive_buf (ctrl, cp, count); + +out_unlock: +mutex_unlock (&serport->lock); +return count; +} + +static void ttyport_write_wakeup (struct tty_port *port) +{ +struct serdev_controller *ctrl = port->client_data; + struct serport *serport =
serdev_controller_get_drvdata(ctrl);
drivers/tty/serdev/serdev-ttyport.c line 60
Quoted 4 lines
drivers/tty/serdev/serdev-ttyport.c new file +4
-0+ +clear_bit (TTY_DO_WRITE_WAKEUP , &port->tty->flags); + +if (test_bit (SERPORT_ACTIVE , &serport->flags))
Hmm...
drivers/tty/serdev/serdev-ttyport.c line 98
Quoted 9 lines
drivers/tty/serdev/serdev-ttyport.c new file +6
-0+serdev_controller_write_wakeup (ctrl); +} +return tty_write_room (tty); +} + +
One extra line.
Quoted 6 lines
drivers/tty/serdev/serdev-ttyport.c new file +3
-0+static int ttyport_open (struct serdev_controller *ctrl) +{ + struct serport *serport =
serdev_controller_get_drvdata(ctrl);drivers/tty/serdev/serdev-ttyport.c new file +2
-0+struct tty_struct *tty; +struct ktermios ktermios;
drivers/tty/serdev/serdev-ttyport.c line 111
Quoted 10 lines
drivers/tty/serdev/serdev-ttyport.c new file +8
-0+ + tty =tty_init_dev (serport->tty_drv, serport->tty_idx); + serport->tty = tty; + + serport->port->client_ops = &client_ops; + serport->port->client_data = ctrl; + + tty->receive_room =65536 ;
Magic?
Quoted 16 lines
drivers/tty/serdev/serdev-ttyport.c new file +7
-0+ +if (tty->ops->open) + tty->ops->open (serport->tty,NULL ); +else +tty_port_open (serport->port, tty,NULL ); + +/* Bring the UART into a known 8 bits no parity hw fc state */
drivers/tty/serdev/serdev-ttyport.c new file +5
-0+ ktermios = tty->termios; + ktermios.c_iflag &= ~(IGNBRK |BRKINT |PARMRK |ISTRIP | + INLCR | IGNCR | ICRNL | IXON); + ktermios.c_oflag &= ~OPOST ; + ktermios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG |IEXTEN);
drivers/tty/serdev/serdev-ttyport.c new file +2
-0+ ktermios.c_cflag &= ~(CSIZE |PARENB ); + ktermios.c_cflag |=CS8 ;
drivers/tty/serdev/serdev-ttyport.c line 133
Quoted 10 lines
drivers/tty/serdev/serdev-ttyport.c new file +8
-0+ ktermios.c_cflag |=CRTSCTS ; +tty_set_termios (tty, &ktermios); + +set_bit (TTY_DO_WRITE_WAKEUP , &tty->flags); + +mutex_lock (&serport->lock); +set_bit (SERPORT_ACTIVE , &serport->flags); +mutex_unlock (&serport->lock);
So, some clarification would be good to have to understand why you need mutex _and_ atomic operation together.
What does mutex protect?
Quoted 10 lines
drivers/tty/serdev/serdev-ttyport.c new file +8
-0+ +tty_unlock (serport->tty); +return 0 ; +} +void serdev_tty_port_unregister (struct tty_port *port) +{ +struct serdev_controller *ctrl = port->client_data; + struct serport *serport =
serdev_controller_get_drvdata(ctrl);
drivers/tty/serdev/serdev-ttyport.c line 234
Quoted 4 lines
drivers/tty/serdev/serdev-ttyport.c new file +3
-0+ +if (!serport) +return ;
What this check prevents from?
Quoted 6 lines
drivers/tty/serdev/serdev-ttyport.c new file +6
-0+ +serdev_controller_remove (ctrl); + port->client_ops =NULL ; + port->client_data =NULL ; +serdev_controller_put (ctrl); +}
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Rob Herring
maintainerRe: [PATCH v2 8/9] serdev: add a tty port controller driver
Quoted 16 lines · Andy Shevchenko
Quoted 13 lines · 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.
drivers/tty/serdev/Kconfig +5
-0+if SERIAL_DEV_BUS + +config SERIAL_DEV_CTRL_TTYPORT + bool "Serial device TTY port controller" + depends on TTY
Quoted 5 lines
Quoted 1 line
+ depends on
SERIAL_DEV_BUS!= mSince you have this line the
ifSERIAL_DEV_BUS
is redundant for it.
It is not. It is the standard pattern of
menuconfig BLAH
if BLAH
...
endif
<EOF>
If I remove the "if", then SERIAL_DEV_CTRL_TTYPORT can be enabled when SERIAL_DEV_BUS=n which breaks the build
Quoted 12 lines
So, leave either one or another (as an example you can look at DMADEVICES).
Quoted 8 lines
drivers/tty/serdev/serdev-ttyport.c new file +8
-0+ +#define SERPORT_BUSY 1 +#define SERPORT_ACTIVE 2 +#define SERPORT_DEAD 3 + +struct serport { +struct tty_port *port; +struct tty_struct *tty;
Quoted 4 lines
drivers/tty/serdev/serdev-ttyport.c line 26
Quoted 2 lines
drivers/tty/serdev/serdev-ttyport.c new file +2
-0+struct tty_driver *tty_drv; +int tty_idx;Do you need
tty_prefix for them?
It's just to be clear it's the tty driver and index rather than this driver's driver or index.
Quoted 15 lines
Quoted 14 lines
drivers/tty/serdev/serdev-ttyport.c new file +3
-0+static int ttyport_open (struct serdev_controller *ctrl) +{ + struct serport *serport =
serdev_controller_get_drvdata(ctrl);drivers/tty/serdev/serdev-ttyport.c new file +9
-0+struct tty_struct *tty; +struct ktermios ktermios; + + tty =tty_init_dev (serport->tty_drv, serport->tty_idx); + serport->tty = tty; + + serport->port->client_ops = &client_ops; + serport->port->client_data = ctrl; +
Quoted 3 lines
Quoted 1 line
+
tty->receive_room= 65536;Magic?
Probably. It's just what every ldisc uses. I suppose we could need clients to set this, but we can add that as needed.
Quoted 22 lines
Quoted 21 lines
drivers/tty/serdev/serdev-ttyport.c new file +6
-0+if (tty->ops->open) + tty->ops->open (serport->tty,NULL ); +else +tty_port_open (serport->port, tty,NULL ); + +/* Bring the UART into a known 8 bits no parity hw fc state */
drivers/tty/serdev/serdev-ttyport.c new file +5
-0+ ktermios = tty->termios; + ktermios.c_iflag &= ~(IGNBRK |BRKINT |PARMRK |ISTRIP | +INLCR |IGNCR |ICRNL |IXON ); + ktermios.c_oflag &= ~OPOST ; + ktermios.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG |IEXTEN);
drivers/tty/serdev/serdev-ttyport.c new file +7
-0+ ktermios.c_cflag &= ~(CSIZE |PARENB ); + ktermios.c_cflag |=CS8 ; + ktermios.c_cflag |=CRTSCTS ; +tty_set_termios (tty, &ktermios); + +set_bit (TTY_DO_WRITE_WAKEUP , &tty->flags); +
Quoted 8 lines
drivers/tty/serdev/serdev-ttyport.c line 133
Quoted 3 lines
drivers/tty/serdev/serdev-ttyport.c new file +3
-0+mutex_lock (&serport->lock); +set_bit (SERPORT_ACTIVE , &serport->flags); +mutex_unlock (&serport->lock);So, some clarification would be good to have to understand why you need mutex _and_ atomic operation together.
What does mutex protect?
Paranoia. Actually, looking at this closer, we can get rid of the mutex altogether.
Quoted 11 lines
drivers/tty/serdev/serdev-ttyport.c line 234
Quoted 9 lines
drivers/tty/serdev/serdev-ttyport.c new file +4
-0+void serdev_tty_port_unregister (struct tty_port *port) +{ +struct serdev_controller *ctrl = port->client_data; + struct serport *serport =
serdev_controller_get_drvdata(ctrl);drivers/tty/serdev/serdev-ttyport.c new file +3
-0+ +if (!serport) +return ;What this check prevents from?
Didn't you ask this last time? See patch #9. tty_port_destructor() calls this unconditionally as it doesn't know whether there's a serdev or not. ctrl may be NULL, and then serport may be NULL.
Rob
Rob Herring
maintainerRe: [PATCH v2 7/9] serdev: Introduce new bus for serial attached devices
In reply to Frédéric DanisQuoted 11 lines · On Wed, Jan 18, 2017 at 5:53 AM, Fr=C3=A9d=C3=A9ric Danis…
Hello,
Le 16/01/2017 =C3=A0 23:54, Rob Herring a =C3=A9crit :
Quoted 4 lines
---
v2:
- Add modalias sysfs attr and uevent hook...
Quoted 2 lines
+static int serdev_uevent(struct device *dev, struct
kobj_uevent_env*en=
v)
Quoted 7 lines
Quoted 4 lines
drivers/tty/serdev/core.c new file +4
-0+{ +/* TODO: ACPI and platform modalias */ +return of_device_uevent_modalias (dev, env); +}...
Quoted 1 line
Quoted 14 lines
drivers/tty/serdev/core.c line 198
Quoted 8 lines
drivers/tty/serdev/core.c new file +8
-0+static ssize_t modalias_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ + ssize_t len =3D of_device_get_modalias(dev, buf, PAGE_SIZE - 2); + buf[len] =3D '\n'; + buf[len+1] =3D 0; +return len+1 ; +}This prevents from building serdev as a module with following errors:
ERROR: "of_device_uevent_modalias" [drivers/tty/serdev/serdev.ko]
undefined!
ERROR: "of_device_get_modalias" [drivers/tty/serdev/serdev.ko] undefine=
d!
Turns out, there's a fix already[1] that should be going in via Greg's tree= .
Rob
[1] https://www.mail-archive.com/[email protected]/msg1299121.ht=
ml
Greg Kroah-Hartman
maintainerRe: [PATCH v2 2/9] tty_port: allow a port to be opened with a tty that has no file handle
In reply to Rob HerringQuoted 26 lines · Rob Herring
From: Alan Cox <[email protected]>
Let us create tty objects entirely in kernel space. Untested proposal to show why all the ideas around rewriting half the uart stack are not needed.
With this a kernel created non file backed tty object could be used to handle data, and set terminal modes. Not all ldiscs can cope with this as
N_TTYin particular has to work back to the fs/tty layer.The
tty_portcode is however otherwise clean of file handles as far as I can tell as is the low level tty port write path used by the ldisc, the configuration low level interfaces and most of the ldiscs.Currently you don't have any exposure to see tty hangups because those are built around the file layer. However a) it's a fixed port so you probably don't care about that b) if you do we can add a callback and c) you almost certainly don't want the userspace tear down/rebuild behaviour anyway.
This should however be sufficient if we wanted for example to enumerate all the bluetooth bound fixed ports via ACPI and make them directly available. It doesn't deal with the case of a user opening a port that's also kernel opened and that would need some locking out (so it returned EBUSY if bound to a kernel device of some kind). That needs resolving along with how you "up" or "down" your new bluetooth device, or enumerate it while providing the existing tty API to avoid regressions (and to debug).
Quoted 5 lines
Alan
Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>---
Alan, Need your SoB here.
Rob, as this patch is flowing through you, I need your signed-off-by as well if I am to take it.
thanks,
greg k-h
Rob Herring
maintainerRe: [PATCH v2 2/9] tty_port: allow a port to be opened with a tty that has no file handle
Quoted 27 lines · Greg Kroah-Hartman
Quoted 26 lines · Rob Herring
From: Alan Cox <[email protected]>
Let us create tty objects entirely in kernel space. Untested proposal to show why all the ideas around rewriting half the uart stack are not needed.
With this a kernel created non file backed tty object could be used to handle data, and set terminal modes. Not all ldiscs can cope with this as
N_TTYin particular has to work back to the fs/tty layer.The
tty_portcode is however otherwise clean of file handles as far as I can tell as is the low level tty port write path used by the ldisc, the configuration low level interfaces and most of the ldiscs.Currently you don't have any exposure to see tty hangups because those are built around the file layer. However a) it's a fixed port so you probably don't care about that b) if you do we can add a callback and c) you almost certainly don't want the userspace tear down/rebuild behaviour anyway.
This should however be sufficient if we wanted for example to enumerate all the bluetooth bound fixed ports via ACPI and make them directly available. It doesn't deal with the case of a user opening a port that's also kernel opened and that would need some locking out (so it returned EBUSY if bound to a kernel device of some kind). That needs resolving along with how you "up" or "down" your new bluetooth device, or enumerate it while providing the existing tty API to avoid regressions (and to debug).
Quoted 8 lines
Quoted 5 lines
Alan
Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>---
Alan, Need your SoB here.Rob, as this patch is flowing through you, I need your signed-off-by as well if I am to take it.
Right. I've added both for the next version.
Rob
Rob Herring
maintainerRe: [PATCH v2 2/9] tty_port: allow a port to be opened with a tty that has no file handle
Quoted 35 lines · Rob Herring
Quoted 33 lines · Greg Kroah-Hartman
Quoted 31 lines · Rob Herring
From: Alan Cox <[email protected]>
Let us create tty objects entirely in kernel space. Untested proposal to show why all the ideas around rewriting half the uart stack are not needed.
With this a kernel created non file backed tty object could be used to handle data, and set terminal modes. Not all ldiscs can cope with this as
N_TTYin particular has to work back to the fs/tty layer.The
tty_portcode is however otherwise clean of file handles as far as I can tell as is the low level tty port write path used by the ldisc, the configuration low level interfaces and most of the ldiscs.Currently you don't have any exposure to see tty hangups because those are built around the file layer. However a) it's a fixed port so you probably don't care about that b) if you do we can add a callback and c) you almost certainly don't want the userspace tear down/rebuild behaviour anyway.
This should however be sufficient if we wanted for example to enumerate all the bluetooth bound fixed ports via ACPI and make them directly available. It doesn't deal with the case of a user opening a port that's also kernel opened and that would need some locking out (so it returned EBUSY if bound to a kernel device of some kind). That needs resolving along with how you "up" or "down" your new bluetooth device, or enumerate it while providing the existing tty API to avoid regressions (and to debug).
Alan
Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>---
Alan, Need your SoB here.
Quoted 4 lines
Quoted 2 lines
Rob, as this patch is flowing through you, I need your signed-off-by as well if I am to take it.
Right. I've added both for the next version.
Oh, I see you applied the 1st patch. Thanks. If you want to apply this one now here's my S-o-B:
Patches 3 and 4 can be applied too.
For patch 5, I'd really like someone with more tty knowledge to comment on.
Rob
Re: [PATCH v2 4/9] tty: constify tty_ldisc_receive_buf buffer pointer
In reply to Rob HerringQuoted 8 lines · Rob Herring
This is needed to work with the client operations which uses const ptrs.
Really, the flags pointer could be const, too, but this would be a tree wide fix.
Signed-off-by Rob Herring <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Reviewed-by Sebastian Reichel <[email protected]>
I've applied the first 4 patches in this series to my tree now, thanks.
greg k-h
Quoted 10 lines · Rob Herring
Here's a new version of the serdev bus support with all the review feedback so far incorporated. I've left it named serdev for now pending any further votes one way or the other, but I did rename the sysfs visible portions to "serial".
There's still some discussion about what to do with devices that pass thru data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
The whole point of the serial bus is to simplify and clean up support for serial devices.
If tty users cannot use the kernel support for automagic kill switches/resets/whatever with kernel GPIO or whatever framework and must continue supporting userspace GPIO and hacks for writing IO space from userland for their devices there is just no point.
I mean it's fine to add support for your single pet device but if you are to support non-trivial number of devices they don't get all perfect kernel driver overnight. And if you need userspace GPIO for half of your devices you can just continue using it for all to *simplify* your userspace code.
It has already happened for SPI devices and the implementation of the userspace access to SPI is dragging for years.
Thanks
Michal
Hi,
Quoted 21 lines · msuchanek
Quoted 6 lines · Rob Herring
Here's a new version of the serdev bus support with all the review feedback so far incorporated. I've left it named serdev for now pending any further votes one way or the other, but I did rename the sysfs visible
portions to "serial".Quoted 6 lines
There's still some discussion about what to do with devices that pass thru
data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.The whole point of the serial bus is to simplify and clean up support for serial devices.
If tty users cannot use the kernel support for automagic kill switches/resets/whatever with kernel GPIO or whatever framework and must continue supporting userspace GPIO and hacks for writing IO space from userland for their devices there is just no point.
Quoted 4 lines
I mean it's fine to add support for your single pet device but if you are to support non-trivial number of devices they don't get all perfect kernel driver overnight. And if you need userspace GPIO for half of your devices you can just continue using it for all to *simplify* your userspace code.
This is definitely not about a single pet device. It helps for most of the serial attached bluetooth chips. For example my work on the Nokia N-series bluetooth driver is waiting for this series and supporting the nokia bluetooth chips with userspace GPIOs is more or less impossible with the data being handled in the kernel, since GPIOs have to be toggled based on that data.
Also there is the kurobox, which uses a serial attached board reset controller. It may not need extra GPIOs/regulators/whatever, but it must have a full-in-kernel driver, so that 'reboot' works as expected ;)
Quoted 2 lines
It has already happened for SPI devices and the implementation of the userspace access to SPI is dragging for years.
Talking about dragging for years: This series has been initially discussed in 2014. Implementing this step-by-step looks sensible to me.
-- Sebastian
Greg Kroah-Hartman
maintainerQuoted 5 lines · Rob Herring
Here's a new version of the serdev bus support with all the review feedback so far incorporated. I've left it named serdev for now pending any further votes one way or the other, but I did rename the sysfs visible portions to "serial".
Quoted 8 lines
There's still some discussion about what to do with devices that pass thru data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
I need a SoB from Alan on his patch 2 and would like review from Alan and/or Peter on the locking in patch 5.
I've applied the first 4 patches now, can you respin this and hopefully Peter will review that patch, as I'd like him to before taking it.
thanks,
greg k-h
Quoted 1 line · Rob Herring
There's still some discussion about what to do with devices that pass thr=
u
Quoted 4 lines
data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
In my simple opinion GPSes shound live in drivers/iio/gps simply by usecase association: streaming out a series of accelerometer readings periodically through IIOs chardevs and other data about the physical world is not any different from the GPS usecase that give you a stream of coordinates on where on this planet you are.
The fact that vendors like to defer GPS processing to userspace because it is considered "secret sauce" is not the concern of the kernel community, though problems like that in general is the great tragedy of our time.
It would be fun to see a pure, reverse-engineered GPS driver in IIO.
Just my =E2=82=AC0.01
(And by the way: awesome work on this series.)
Yours,
Linus Walleij
Marcel Holtmann
maintainerHi Linus,
Quoted 12 lines
Quoted 5 lines
There's still some discussion about what to do with devices that pass thru data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
In my simple opinion GPSes shound live in
drivers/iio/gpssimply by usecase association: streaming out a series of accelerometer readings periodically through IIOs chardevs and other data about the physical world is not any different from the GPS usecase that give you a stream of coordinates on where on this planet you are.
Quoted 5 lines
The fact that vendors like to defer GPS processing to userspace because it is considered "secret sauce" is not the concern of the kernel community, though problems like that in general is the great tragedy of our time.
It would be fun to see a pure, reverse-engineered GPS driver in IIO.
except for the pure NMEA devices. Which are pretty much defined as terminal devices using RS422 and 4800 baud. For anything non-NMEA, I would agree that using IIO might be a good option. So instead of a GPS subsystem, might just have a GPS class / type in the IIO subsystem.
Regards
Marcel
GPS drivers (was Re: [PATCH v2 0/9] Serial slave device bus)
In reply to Linus WalleijHi!
Switched subject: Rob's work is great for GPS and bluetooth, but this goes beyond it.
Quoted 8 lines · Rob Herring
Quoted 6 lines
There's still some discussion about what to do with devices that pass thru data to userspace unmodified like GPS and could still use tty device for the data path. IMO, we should treat this as a separate problem following this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
Quoted 5 lines
In my simple opinion GPSes shound live in
drivers/iio/gpssimply by usecase association: streaming out a series of accelerometer readings periodically through IIOs chardevs and other data about the physical world is not any different from the GPS usecase that give you a stream of coordinates on where on this planet you are.
That is... not quite how GPSes work. What interface would you propose? It would be good to support error estimates in position/velocities and AGPS data upload.
Now, NMEA knows about some of the complexity (not AGPS), but gets the details wrong. In particular, it would be good to have error estimates and velocities from the same moment you get position estimates.
Quoted 5 lines
The fact that vendors like to defer GPS processing to userspace because it is considered "secret sauce" is not the concern of the kernel community, though problems like that in general is the great tragedy of our time.
It would be fun to see a pure, reverse-engineered GPS driver in IIO.
Well, many GPSes simply produce NMEA, and we have drivers for some other.
Here's example driver:
https://gitlab.com/tui/tui/blob/master/ofone/gps3.c
Best regards,
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 6 lines
Am 20.01.2017 um 15:14 schrieb Marcel Holtmann <[email protected]>:
=20
Hi Linus,
=20Quoted 1 line
Quoted 1 line
There's still some discussion about what to do with devices that =
pass thru
Quoted 1 line
Quoted 1 line
Quoted 1 line
data to userspace unmodified like GPS and could still use tty device =
for
Quoted 1 line
Quoted 1 line
Quoted 1 line
the data path. IMO, we should treat this as a separate problem =
following
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
this series. Drivers we want to convert to serdev and already in the kernel don't need this functionality.
=20
In my simple opinion GPSes shound live indrivers/iio/gpssimply by usecase association: streaming out a series of accelerometer readings periodically through IIOs chardevs and other data about the physical world is not any different from the GPS usecase that give you a =
stream
Quoted 3 lines
Quoted 3 lines
of coordinates on where on this planet you are.
=20
The fact that vendors like to defer GPS processing to userspace =
because
Quoted 1 line
Quoted 1 line
it is considered "secret sauce" is not the concern of the kernel =
community,
Quoted 1 line
Quoted 1 line
though problems like that in general is the great tragedy of our =
time.
Quoted 4 lines
Quoted 2 lines
=20
It would be fun to see a pure, reverse-engineered GPS driver in IIO.=20
except for the pure NMEA devices. Which are pretty much defined as =
terminal devices using RS422 and 4800 baud. For anything non-NMEA, I = would agree that using IIO might be a good option. So instead of a GPS = subsystem, might just have a GPS class / type in the IIO subsystem.
Well, we could implement a default NMEA parser in the iio subsystem to translate satellite time, geolocation, orientation, speed, and satellite signal strengths to iio channels.
On the other hand we have to wait until all user-space GPS applications use it and appear in wider use in distribution. Let's say in 3-4 years?
Therefore, I'd like to see NMEA records passed to user space and not shielded completely.
And some GPS devices send extensions to the core set of NEMA records, which might give other useful information. Having this needs some extensibility to the iio translation or side-channels.
BR,
Nikolaus
Re: GPS drivers (was Re: [PATCH v2 0/9] Serial slave device bus)
In reply to Pavel MachekQuoted 2 lines · Pavel Machek
Switched subject: Rob's work is great for GPS and bluetooth, but this goes beyond it.
Sure why not talk around a bit.
Quoted 9 lines
Quoted 5 lines
In my simple opinion GPSes shound live in
drivers/iio/gpssimply by usecase association: streaming out a series of accelerometer readings periodically through IIOs chardevs and other data about the physical world is not any different from the GPS usecase that give you a stream of coordinates on where on this planet you are.That is... not quite how GPSes work. What interface would you propose? It would be good to support error estimates in position/velocities and AGPS data upload.
Sorry for my ignorance. I have not had the opportunity to work directly with a GPS hardware.
Quoted 3 lines
Now, NMEA knows about some of the complexity (not AGPS), but gets the details wrong. In particular, it would be good to have error estimates and velocities from the same moment you get position estimates.
NMEA if it is this:
https://en.wikipedia.org/wiki/NMEA_0183
Seems to be a high-level format such as XML or CSV or any other $FAVOURITE_ASCII_TRANSPORT format.
What we want to push into the ring buffer is of course the raw data that is produced by the GPS hardware, whatever that may be. If what we have is this text format we should not reverse-translate it back any more than modem AT commands, it doesn't make sense I guess.
So NMEA processing would be in userspace. And if the GPS is just streaming this text data over to the client, like Marcel says, it is more reasonable to just feed that up to userspace (no policy in the kernel).
I am however aware of certain hardware such as the ST Microelectronis STA2062 produced for Garmin, which is *not* connected to any external chip, and is not talking over serial to any RSx port, and does not have an embedded firmware running on another SoC in any special GPS chip. And it is unassisted.
Maybe that is an oddity. In the mobile phone business I guess it could be more common to have a separate SoC that by way of standards just stream NMEA data.
Fusing that with other sensor data (accelerometer, compass, etc) is again indeed a userspace task. I hope NMEA includes very good timestamps.
Thanks,
Linus Walleij
Re: GPS drivers (was Re: [PATCH v2 0/9] Serial slave device bus)
Quoted 11 lines · Linus Walleij
Quoted 5 lines
Now, NMEA knows about some of the complexity (not AGPS), but gets the
details wrong. In particular, it would be good to have error estimates
and velocities from the same moment you get position estimates.NMEA if it is this:
https://en.wikipedia.org/wiki/NMEA_0183Seems to be a high-level format such as XML or CSV or any other $FAVOURITE_ASCII_TRANSPORT format.
Not exactly. It depends on device settings.
Old GPS I used to play with have AT command to switch between ASCII and binary format. Some of the devices might use non-standard binary protocols (however, representable as NMEA), etc.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: GPS drivers (was Re: [PATCH v2 0/9] Serial slave device bus)
In reply to Linus WalleijHi!
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
In my simple opinion GPSes shound live in
drivers/iio/gpssimply by usecase association: streaming out a series of accelerometer readings periodically through IIOs chardevs and other data about the physical world is not any different from the GPS usecase that give you a stream of coordinates on where on this planet you are.
Quoted 6 lines
Quoted 3 lines
That is... not quite how GPSes work. What interface would you propose? It would be good to support error estimates in position/velocities and AGPS data upload.
Sorry for my ignorance. I have not had the opportunity to work directly with a GPS hardware.
Few people have. It is CDMA corelators at the low level.
Quoted 6 lines
Quoted 3 lines
Now, NMEA knows about some of the complexity (not AGPS), but gets the details wrong. In particular, it would be good to have error estimates and velocities from the same moment you get position estimates.
NMEA if it is this:
https://en.wikipedia.org/wiki/NMEA_0183
Yes.
Quoted 8 lines
Seems to be a high-level format such as XML or CSV or any other $FAVOURITE_ASCII_TRANSPORT format.
What we want to push into the ring buffer is of course the raw data that is produced by the GPS hardware, whatever that may be. If what we have is this text format we should not reverse-translate it back any more than modem AT commands, it doesn't make sense I guess.
Umm. Its hairy. Each GPS talks slightly different version of NMEA :-(. But yes, we have userland driver called 'gpsd' that understands most of them. Many GPSes have additional, non-NMEA protocol you can switch them to.
Quoted 4 lines
So NMEA processing would be in userspace. And if the GPS is just streaming this text data over to the client, like Marcel says, it is more reasonable to just feed that up to userspace (no policy in the kernel).
Well -- we normally do hardware abstraction in the kernel :-).
Quoted 5 lines
I am however aware of certain hardware such as the ST Microelectronis STA2062 produced for Garmin, which is *not* connected to any external chip, and is not talking over serial to any RSx port, and does not have an embedded firmware running on another SoC in any special GPS chip. And it is unassisted.
I googled STA2062 but it does not make much sense to me.
Yes, not everything talks NMEA. Nokia N900 is an example, and it has in-tree driver.
Quoted 3 lines
Maybe that is an oddity. In the mobile phone business I guess it could be more common to have a separate SoC that by way of standards just stream NMEA data.
Sorry, I don't understand. Yes, in mobile phones GPSes that produce something else than NMEA are pretty common.
Quoted 3 lines
Fusing that with other sensor data (accelerometer, compass, etc) is again indeed a userspace task. I hope NMEA includes very good timestamps.
Umm. Timestamps are quite hard to do over serial :-(.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Re: GPS drivers (was Re: [PATCH v2 0/9] Serial slave device bus)
In reply to Andy ShevchenkoQuoted 11 lines · Andy Shevchenko
Quoted 9 lines · Linus Walleij
Quoted 5 lines
Now, NMEA knows about some of the complexity (not AGPS), but gets the
details wrong. In particular, it would be good to have error estimates
and velocities from the same moment you get position estimates.NMEA if it is this:
https://en.wikipedia.org/wiki/NMEA_0183
Quoted 7 lines
Quoted 2 lines
Seems to be a high-level format such as XML or CSV or any other $FAVOURITE_ASCII_TRANSPORT format.
Not exactly. It depends on device settings.
Old GPS I used to play with have AT command to switch between ASCII and binary format. Some of the devices might use non-standard binary protocols (however, representable as NMEA), etc.
Apparently NMEA has some serious limitations. gpsd authors have some good docs about that.
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html