serial: fsl_lpuart: add support for GPIO-controlled modem lines
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
Greg Kroah-Hartman
maintainerQuoted 40 lines · João Loureiro
LPUART has no register bit to drive RTS to a chosen level: UARTMODIR only offers receiver-driven auto-RTS (RXRTSE) and RTS-during-transmit (TXRTSE). Consequently
lpuart_set_mctrl()andlpuart32_set_mctrl()ignoreTIOCM_RTS, and theirget_mctrl()counterparts report a hardcodedTIOCM_CAR|TIOCM_DSR|TIOCM_CTS.That makes it impossible to talk to a peripheral which is driven by a software controlled RTS strobe and answers on CTS. TIOCMBIS/TIOCMBIC silently do nothing, and because CTS always reads back as asserted, a userspace handshake that waits for CTS to follow RTS can never complete:
de-asserting RTS and waiting for CTS to drop times out every time. Boards that route the two pins to plain GPIOs cannot work around it either, since the driver never looks at rts-gpios/cts-gpios.Wire the driver up to the
serial_mctrl_gpiohelpers, asimx.candatmel_serial.calready do.set_mctrl()forwards the state tomctrl_gpio_set(), andget_mctrl()runs the flags throughmctrl_gpio_get()so that a described cts-gpios overrides the assumed-asserted default. Boards without such a description keep the previous behaviour. Modem status interrupts are enabled fromstartup()and disabled fromshutdown(), with a .enable_ms callback for the serial core.The same limitation was reported for an i.MX 8XLite board that needs RS-485 with a GPIO RTS [1]. This change was developed and tested on an i.MX95 board whose barcode scanner is driven over LPUART with a manual RTS strobe; with it, RTS toggles as requested and CTS is reported from the real pin.
[1] https://lore.kernel.org/all/[email protected]/
Signed-off-by João Loureiro <[email protected]>--- drivers/tty/serial/Kconfig | 1 + drivers/tty/serial/fsl_lpuart.c | 35 +++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-)drivers/tty/serial/Kconfig +0
-0
drivers/tty/serial/Kconfig config SERIAL_FSL_LPUART · line 1304
Quoted 4 lines
drivers/tty/serial/Kconfig +1
-0@@ -1301,6 +1301,7 @@ config SERIAL_FSL_LPUART tristate "Freescale lpuart serial port support" depends on HAS_DMA select SERIAL_CORE + select SERIAL_MCTRL_GPIO if GPIOLIB
Why not depends?
thanks,
greg k-h
Quoted 10 lines · Greg Kroah-Hartman
drivers/tty/serial/Kconfig config SERIAL_FSL_LPUART · line 1304
Quoted 7 lines · João Loureiro
drivers/tty/serial/Kconfig +1
-0@@ -1301,6 +1301,7 @@ config SERIAL_FSL_LPUART tristate "Freescale lpuart serial port support" depends on HAS_DMA select SERIAL_CORE + select SERIAL_MCTRL_GPIO if GPIOLIBWhy not depends?
Because SERIAL_MCTRL_GPIO is a hidden symbol. It is declared as a bare "tristate" with no prompt at the end of the same Kconfig file, so it can only ever be enabled by a select. With "depends on SERIAL_MCTRL_GPIO" nothing could ever satisfy the dependency and SERIAL_FSL_LPUART would become unselectable.
The dependency is also not a hard one. serial_mctrl_gpio.h provides no-op static inlines for the !CONFIG_GPIOLIB case, so fsl_lpuart still builds and behaves exactly as before when GPIOLIB is off; the GPIO modem lines are an optional extra rather than a requirement. A depends would silently drop LPUART from those configurations.
Finally, this is what every other user of the helpers does:SERIAL_ATMEL, SERIAL_IMX, SERIAL_SH_SCI, SERIAL_STM32, SERIAL_MXS_AUART, SERIAL_SA1100, SERIAL_CLPS711X and SERIAL_AR933X all spell it as "select SERIAL_MCTRL_GPIO if GPIOLIB" in the same file, so this keeps fsl_lpuart consistent with them.
Thanks,
João
Greg Kroah-Hartman
maintainerQuoted 24 lines · João Loureiro
Quoted 10 lines · Greg Kroah-Hartman
drivers/tty/serial/Kconfig config SERIAL_FSL_LPUART · line 1304
Quoted 7 lines · João Loureiro
drivers/tty/serial/Kconfig +1
-0@@ -1301,6 +1301,7 @@ config SERIAL_FSL_LPUART tristate "Freescale lpuart serial port support" depends on HAS_DMA select SERIAL_CORE + select SERIAL_MCTRL_GPIO if GPIOLIBWhy not depends?
Because
SERIAL_MCTRL_GPIOis a hidden symbol. It is declared as a bare "tristate" with no prompt at the end of the sameKconfigfile, so it can only ever be enabled by a select. With "depends onSERIAL_MCTRL_GPIO" nothing could ever satisfy the dependency andSERIAL_FSL_LPUARTwould become unselectable.The dependency is also not a hard one.
serial_mctrl_gpio.hprovides no-op static inlines for the !CONFIG_GPIOLIB case, sofsl_lpuartstill builds and behaves exactly as before when GPIOLIB is off; the GPIO modem lines are an optional extra rather than a requirement. A depends would silently drop LPUART from those configurations.
Quoted 5 lines
Finally, this is what every other user of the helpers does:
SERIAL_ATMEL,SERIAL_IMX,SERIAL_SH_SCI,SERIAL_STM32,SERIAL_MXS_AUART,SERIAL_SA1100,SERIAL_CLPS711XandSERIAL_AR933Xall spell it as "selectSERIAL_MCTRL_GPIOif GPIOLIB" in the same file, so this keepsfsl_lpuartconsistent with them.
for some reason your first email in this thread is not on lore.kernel.org so I can't run the CI tools on it.
Can you resend a new version so that we can test it?
thanks,
greg k-h