serial: 8250: Add AN7581 UART support
Subsystems (2)
v4 cover serial: 8250: Add AN7581 UART support
This is a new version of [1] to support UART driver for Airoha SoC.
One additional function was needed serial8250_get_baud_rate() for the driver to work correctly for baud rate calculation.
While at it also try to clarify a long standing issue with new UART driver when adding new ids for uart_config[].
[1] https://lore.kernel.org/all/[email protected]/
Changes v4:
- Add Review tag
- Add errno and types header
- Drop redundant () from comment
- Use define for get_divisor
Changes v3:
- Address review from ai bot
- Add all missing kernel headers
- Improve divisor calculation
- Fix wrong uart config table
- Simplify divisor table handling
Changes v2:
- Drop intermediate patch
- Use .set_divisor OPs
- Use div_u64 instead of / 40 for 32 bit overflow
- Drop dedicated match table and use compatible for type
Changes compared to [1]:
- Fix all formal error
- Use better compatible names
- Drop unneeded header
- Drop usage of irq (it's filled by the generic function)
- General code cleanup and reorg
- Split to patch and add the UAPI map patch
Benjamin Larsson (1):
dt-bindings: serial: 8250: Add Airoha compatibles
Christian Marangi (1):
serial: 8250: Add Airoha SoC UART and HSUART support
.../devicetree/bindings/serial/8250.yaml | 5 + drivers/tty/serial/8250/8250.h | 6 + drivers/tty/serial/8250/8250_airoha.c | 187 ++++++++++++++++++ drivers/tty/serial/8250/8250_port.c | 16 ++ drivers/tty/serial/8250/Kconfig | 11 ++ drivers/tty/serial/8250/Makefile | 1 + 6 files changed, 226 insertions(+) create mode 100644 drivers/tty/serial/8250/8250_airoha.c
Signature · 1 line
2.53.0
PATCH v4 1/2 dt-bindings: serial: 8250: Add Airoha compatibles
From: Benjamin Larsson <[email protected]>
The Airoha SoC family have a mostly 16550-compatible UART and High-Speed UART hardware with the exception of custom baud rate settings register.
--- Documentation/devicetree/bindings/serial/8250.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/serial/8250.yaml +5 -0
@@ -110,6 +110,11 @@ properties: - const: mrvl,pxa-uart - const: nuvoton,wpcm450-uart - const: nuvoton,npcm750-uart + - const: airoha,en7523-uart + - items: + - const: airoha,an7581-uart + - const: airoha,en7523-uart + - const: airoha,an7581-hsuart - const: nvidia,tegra20-uart - const: nxp,lpc3220-uart - items:
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v4 1/2] dt-bindings: serial: 8250: Add Airoha compatibles
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] Alphabetical sorting and schema structure violation in the compatible list. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] Alphabetical sorting and schema structure violation in the compatible list. --
--- Patch [1]: [PATCH v4 1/2] dt-bindings: serial: 8250: Add Airoha compatibles --- commit 27d01f216d527b904216459304a02e2d8c5f87e2
Author: Benjamin Larsson <[email protected]>
dt-bindings: serial: 8250: Add Airoha compatibles
This commit adds compatibles for the Airoha SoC family's 16550-compatible UART and High-Speed UART hardware. The hardware features a custom baud rate settings register.
Documentation/devicetree/bindings/serial/8250.yaml properties: · line 117
Quoted 13 lines
Documentation/devicetree/bindings/serial/8250.yaml +5
-0@@ -110,6 +110,11 @@ properties: - const: mrvl,pxa-uart - const: nuvoton,wpcm450-uart - const: nuvoton,npcm750-uart + - const: airoha,en7523-uart + - items: + - const: airoha,an7581-uart + - const: airoha,en7523-uart + - const: airoha,an7581-hsuart
[Severity: Low]
This isn't a bug, but are the airoha entries inserted out of alphabetical order here? The existing const compatibles appear to be grouped together and sorted alphabetically by vendor prefix, meaning airoha should likely appear earlier in the list.
Additionally, should the items block for the multi-string compatible be moved? It seems to break the structural convention of the file by inserting an items block into the middle of the standalone const block, whereas other items blocks are typically grouped together after the const entries.
Quoted 3 lines
Documentation/devicetree/bindings/serial/8250.yaml +0
-0- const: nvidia,tegra20-uart - const: nxp,lpc3220-uart - items:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Rob Herring
maintainerRe: [PATCH v4 1/2] dt-bindings: serial: 8250: Add Airoha compatibles
In reply to Christian MarangiQuoted 18 lines · Christian Marangi
From: Benjamin Larsson <[email protected]>
The Airoha SoC family have a mostly 16550-compatible UART and High-Speed UART hardware with the exception of custom baud rate settings register.
Signed-off-by Benjamin Larsson <[email protected]>Signed-off-by Christian Marangi <[email protected]>Acked-by Conor Dooley <[email protected]>--- Documentation/devicetree/bindings/serial/8250.yaml | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/serial/8250.yaml +0
-0
Documentation/devicetree/bindings/serial/8250.yaml properties: · line 116
Quoted 7 lines
Documentation/devicetree/bindings/serial/8250.yaml +4
-0@@ -110,6 +110,11 @@ properties: - const: mrvl,pxa-uart - const: nuvoton,wpcm450-uart - const: nuvoton,npcm750-uart + - const: airoha,en7523-uart + - items: + - const: airoha,an7581-uart + - const: airoha,en7523-uart
Don't stick this in the middle of a bunch single entry items (which should really be an 'enum' if you would like to clean that up).
Quoted 8 lines
Documentation/devicetree/bindings/serial/8250.yaml +1
-0+ - const: airoha,an7581-hsuart - const: nvidia,tegra20-uart - const: nxp,lpc3220-uart- items:
Signature · 1 line
2.53.0
Re: [PATCH v4 1/2] dt-bindings: serial: 8250: Add Airoha compatibles
Quoted 14 lines · Rob Herring
Quoted 13 lines · Christian Marangi
From: Benjamin Larsson <[email protected]>
The Airoha SoC family have a mostly 16550-compatible UART and High-Speed UART hardware with the exception of custom baud rate settings register.
Signed-off-by Benjamin Larsson <[email protected]>Signed-off-by Christian Marangi <[email protected]>Acked-by Conor Dooley <[email protected]>--- Documentation/devicetree/bindings/serial/8250.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Quoted 16 lines
Documentation/devicetree/bindings/serial/8250.yaml properties: · line 116
Quoted 12 lines
Documentation/devicetree/bindings/serial/8250.yaml +4
-0@@ -110,6 +110,11 @@ properties: - const: mrvl,pxa-uart - const: nuvoton,wpcm450-uart - const: nuvoton,npcm750-uart + - const: airoha,en7523-uart + - items: + - const: airoha,an7581-uart + - const: airoha,en7523-uartDon't stick this in the middle of a bunch single entry items (which should really be an 'enum' if you would like to clean that up).
Let me see what I can do... Seems this schema really needs some love.
Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/serial/8250.yaml +1
-0+ - const: airoha,an7581-hsuart - const: nvidia,tegra20-uart - const: nxp,lpc3220-uart- items:
Signature · 1 line
2.53.0
Signature · 1 line
Ansuel
PATCH v4 2/2 serial: 8250: Add Airoha SoC UART and HSUART support
In reply to Christian MarangiAdd support for Airoha AN7523 UART and AN7581 HSUART.
These implement a standard 16550 UART with only some custom logic for baud rate handling.
--- drivers/tty/serial/8250/8250.h | 6 + drivers/tty/serial/8250/8250_airoha.c | 187 ++++++++++++++++++++++++++ drivers/tty/serial/8250/8250_port.c | 16 +++ drivers/tty/serial/8250/Kconfig | 11 ++ drivers/tty/serial/8250/Makefile | 1 + 5 files changed, 221 insertions(+) create mode 100644 drivers/tty/serial/8250/8250_airoha.c
drivers/tty/serial/8250/8250.h +6 -0
@@ -73,6 +73,12 @@ struct serial8250_config {unsigned int flags; }; +enum uart_port_type { +/* Internal 8250 only */ +UART_PORT_AIROHA =124 , +UART_PORT_AIROHA_HS =125 , +}; +#define UART_CAP_FIFO BIT(8)/* UART has FIFO */ #define UART_CAP_EFR BIT(9)/* UART has EFR */ #define UART_CAP_SLEEP BIT(10)/* UART has IER sleep */
drivers/tty/serial/8250/8250_airoha.c new file +187 -0
187 lines not on this page · raw message
drivers/tty/serial/8250/8250_port.c +16 -0
@@ -311,6 +311,22 @@ static const struct serial8250_config uart_config[] = { .rxtrig_bytes = {1, 8, 16, 30}, .flags = UART_CAP_FIFO | UART_CAP_AFE, }, + [UART_PORT_AIROHA] = { + .name ="Airoha UART" , + .fifo_size = 8, + .tx_loadsz = 1, + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | UART_FCR_CLEAR_RCVR, + .rxtrig_bytes = {1, 4, 4, 4}, + .flags = UART_CAP_FIFO, + }, + [UART_PORT_AIROHA_HS] = { + .name ="Airoha HSUART" , + .fifo_size = 128, + .tx_loadsz = 128, + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | UART_FCR_CLEAR_RCVR, + .rxtrig_bytes = {1, 4}, + .flags = UART_CAP_FIFO, + }, };/* Uart divisor latch read */
drivers/tty/serial/8250/Kconfig +11 -0
@@ -337,6 +337,17 @@ config SERIAL_8250_ACORN system, say Y to this option. The driver can handle 1, 2, or 3 port cards. If unsure, say N. +config SERIAL_8250_AIROHA + tristate "Airoha UART support" + depends on ARCH_AIROHA || COMPILE_TEST + depends on SERIAL_8250 + help + Selecting this option enables an Airoha SoC specific baud rate + calculation routine on an otherwise 16550 compatible UART hardware. + + If you have an Airoha based board and want to use the serial port, + say Y to this option. If unsure, say N. + config SERIAL_8250_BCM2835AUX tristate "BCM2835 auxiliar mini UART support" depends on ARCH_BCM2835 || COMPILE_TEST
drivers/tty/serial/8250/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_SERIAL_8250_CONSOLE) += 8250_early.o obj-$(CONFIG_SERIAL_8250_ACCENT) += 8250_accent.o obj-$(CONFIG_SERIAL_8250_ACORN) += 8250_acorn.o +obj-$(CONFIG_SERIAL_8250_AIROHA) += 8250_airoha.o obj-$(CONFIG_SERIAL_8250_ASPEED_VUART) += 8250_aspeed_vuart.o obj-$(CONFIG_SERIAL_8250_BCM2835AUX) += 8250_bcm2835aux.o obj-$(CONFIG_SERIAL_8250_BCM7271) += 8250_bcm7271.o
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v4 2/2] serial: 8250: Add Airoha SoC UART and HSUART support
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [Critical] Calling dev_err() in airoha_set_divisor() causes a spinlock deadlock if the port is the kernel…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [Critical] Calling dev_err() in airoha_set_divisor() causes a spinlock deadlock if the port is the kernel console.
- [High] Writing to the 32-bit UART_AIROHA_XYD register using serial_port_out() will silently truncate data to 8 bits if the device tree does not explicitly specify a 32-bit I/O width.
- [High] The custom rxtrig_bytes configurations for Airoha UARTs are incompletely populated, breaking the generic 8250 trigger level logic and causing incorrect FIFO trigger values to be programmed.
- [Medium] Defining UART_PORT_AIROHA and UART_PORT_AIROHA_HS in a private header improperly extends the global userspace-visible PORT_* numbering sequence.
--
--- Patch [2]: [PATCH v4 2/2] serial: 8250: Add Airoha SoC UART and HSUART support --- commit 6a010d96ca9cacd9ae30a034a1c0bf970a220d58
Author: Christian Marangi <[email protected]>
serial: 8250: Add Airoha SoC UART and HSUART support
This patch adds support for Airoha AN7523 UART and AN7581 HSUART. It implements a standard 16550 UART with custom logic for baud rate handling.
drivers/tty/serial/8250/8250.h struct serial8250_config { · line 80
Quoted 13 lines
drivers/tty/serial/8250/8250.h +5
-0@@ -73,6 +73,12 @@ struct serial8250_config {unsigned int flags; }; +enum uart_port_type { +/* Internal 8250 only */ +UART_PORT_AIROHA =124 , +UART_PORT_AIROHA_HS =125 , +};
[Severity: Medium]
Is it safe to define these port type numbers in a private header instead of include/uapi/linux/serial_core.h?
Since userspace can read this value via the TIOCGSERIAL ioctl, could this lead to a collision if another port type is assigned the same ID in the global UAPI header?
Quoted 5 lines
drivers/tty/serial/8250/8250_airoha.c new file +0
-0
[ ... ]
Quoted 3 lines
drivers/tty/serial/8250/8250_airoha.c new file +3
-0+static void airoha_set_divisor (struct uart_port *port,unsigned int baud, +unsigned int quot,unsigned int quot_frac) +{
[ ... ]
drivers/tty/serial/8250/8250_airoha.c line 107
Quoted 6 lines
drivers/tty/serial/8250/8250_airoha.c new file +6
-0+/* Couldn't find a valid xyd_x */ +if (div_bit <0 ) { +dev_err (port->dev,"failed to find suitable clock divisor for baud %u\n" , + baud); +return ; + }
[Severity: Critical]
Can this cause a spinlock deadlock if the port is the kernel console?
The caller serial8250_do_set_termios() holds the port->lock spinlock when invoking the set_divisor callback. If dev_err() is called and this UART is the active console, printk will synchronously try to acquire the same port->lock in serial8250_console_write(), leading to a deadlock.
drivers/tty/serial/8250/8250_airoha.c line 112
Quoted 5 lines
drivers/tty/serial/8250/8250_airoha.c new file +5
-0+ +serial_port_out (port,UART_AIROHA_XINCLKDR ,BIT (div_bit)); +serial_port_out (port,UART_AIROHA_XYD , +FIELD_PREP (UART_AIROHA_XYD_X , xyd_x) | +FIELD_PREP (UART_AIROHA_XYD_Y ,XYD_Y ));
[Severity: High]
Is there a risk that writing to the 32-bit UART_AIROHA_XYD register using serial_port_out() will silently truncate the data to 8 bits?
If the device tree is missing the reg-io-width property, the 8250 core will default to 8-bit I/O. Since the hardware requires 32-bit writes here, should the driver explicitly set uart.port.iotype to UPIO_MEM32 in the probe function to ensure the generic accessor doesn't invoke writeb() and discard the upper 24 bits?
Quoted 4 lines
drivers/tty/serial/8250/8250_port.c +0
-0
[ ... ]
drivers/tty/serial/8250/8250_port.c static const struct serial8250_config uart_config[] = { · line 329
Quoted 8 lines
drivers/tty/serial/8250/8250_port.c +8
-0+ [UART_PORT_AIROHA_HS] = { + .name = "Airoha HSUART", + .fifo_size = 128, + .tx_loadsz = 128, + .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_01 | UART_FCR_CLEAR_RCVR, + .rxtrig_bytes = {1, 4}, + .flags = UART_CAP_FIFO, + },
[Severity: High]
Does the incomplete initialization of rxtrig_bytes for UART_PORT_AIROHA_HS break the generic trigger level logic?
The array defines only the first two elements, leaving indices 2 and 3 as 0. When bytes_to_fcr_rxtrig() iterates over all states:
for (i = 1; i < UART_FCR_R_TRIG_MAX_STATE; i++) {
if (bytes < conf_type->rxtrig_bytes[i])Since bytes is unsigned, bytes < 0 is false, so it will fall through and return UART_FCR_R_TRIG_11 for any requested trigger size of 4 or more, which would program 0 bytes into the hardware's FCR. Should the rest of the elements be populated?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2