serial: 8250_dw: Allwinner A733 UART support
Subsystems (6)
v2 cover serial: 8250_dw: Allwinner A733 UART support
While testing the A733 UART, the console stopped taking interrupts at the first termios change from userspace. Termios changes during console output could also corrupt characters even when the baud rate did not change.
Patch 1 is an independent fix for the DesignWare 8250 divisor path. When DLF is detected, dw8250_setup_port() can replace the BUSY-safe divisor hook with one that does not provide that protection. If the LCR write is then dropped while the UART is busy, the retry path can try to restore IER while DLAB is still selected, causing the value to be written to DLH instead of IER.
Patch 2 takes Andre's suggestion to only accept a DLF readback when it is a contiguous 2^n - 1 mask. On the A733, offset 0xc0 is the RS485 control register and reads back 0x19f; Andre observed 0x9f on the A523.
Patches 3 and 4 add the A733 compatible and select SKIP_SET_RATE for it. Stopping the UART clock from set_termios while TX is active corrupts output on this board. Skipping redundant reclocking in general was tried in e5d6bd25f93d and reverted by 7dfae6cbadc1 after regressions on Bay Trail and Cherry Trail, so the change stays specific to the A733.
Tested on a Radxa Cubie A7Z (PCB V1.11, 1 GiB) on top of tty-next 1184f87e2790e8af9be3116f608d2e86b4792d7d, using local A733 DT and clock changes that are not part of this series.
With patch 1 alone and the generic fallback, repeated termios changes no longer stalled the console and hardware IER remained equal to up->ier, while the false DLF was still detected (dlf_size=9).
With the complete series and the A733 compatible, three clean runs of both the CLOCAL and CSTOPB stress tests completed without corrupted output. dlf_size remained 0 and offset 0xc0 remained 0 after the tests. dlf_size and up->ier were read through a temporary debugfs test patch which is not part of this series.
I do not have hardware with a real DLF, or Bay Trail/Cherry Trail, to test those paths.
Changes in v2:
- rework patch 1 around a dwlib divisor helper and preserve an existing set_divisor hook, following Ilpo's review
- add a separate check for contiguous DLF readback, following Andre's suggestion
- drop the A733-specific NO_DLF quirk
- keep the generic DT fallback
- keep only SKIP_SET_RATE in the A733 platform data
- retain Conor's Acked-by on the binding
- rebase and retest on tty-next 1184f87e2790
Link to v1:
https://lore.kernel.org/all/[email protected]/
Vinicius Pedrosa (4):
serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
serial: 8250_dw: Only accept a contiguous DLF readback
dt-bindings: serial: snps-dw-apb-uart: Add Allwinner A733
serial: 8250_dw: Add Allwinner A733 UART
.../bindings/serial/snps-dw-apb-uart.yaml | 1 + drivers/tty/serial/8250/8250_dw.c | 3 +++ drivers/tty/serial/8250/8250_dwlib.c | 22 ++++++++++++++++--- drivers/tty/serial/8250/8250_dwlib.h | 1 + 4 files changed, 24 insertions(+), 3 deletions(-)
base-commit: 1184f87e2790e8af9be3116f608d2e86b4792d7d
PATCH v2 1/4 serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
dw8250_probe() installs dw8250_set_divisor(), which brackets the DLAB/DLL/DLH sequence with dw8250_idle_enter() and dw8250_idle_exit() so a BUSY UART cannot drop the divisor LCR write.
dw8250_setup_port() runs afterwards and replaces that hook with the dwlib divisor hook whenever it detects DLF. The dwlib hook programs the divisor through serial8250_do_set_divisor() without entering idle, leaving the LCR|DLAB write exposed to BUSY.
When termios changes while the UART is transmitting, that LCR|DLAB write can be ignored and dw8250_check_lcr() retries it between dw8250_idle_enter() and dw8250_idle_exit(). dw8250_idle_exit() then restores IER while DLAB is still set, so the value lands in DLH. The real IER stays at the zero written by dw8250_idle_enter(), and the port gets no further TX or RX interrupts while up->ier says they're enabled.
Do not replace a divisor hook the driver has already installed. Program DLF from the BUSY-safe hook, inside the idle section, through a dwlib helper that checks dlf_size.
Observed on an Allwinner A733 (Radxa Cubie A7Z), where dw8250_setup_port() mistakes the RS485 control register for DLF (see the next patch): the first interactive tcsetattr() during console output left hardware IER at 0 and up->ier at 0x07. The shell never printed its prompt or read input. With this change alone the same boot reached the prompt and echoed input, and hardware IER matched up->ier afterwards.
--- drivers/tty/serial/8250/8250_dw.c | 2 ++ drivers/tty/serial/8250/8250_dwlib.c | 16 ++++++++++++++-- drivers/tty/serial/8250/8250_dwlib.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_dw.c +2 -0
@@ -197,6 +197,8 @@ static void dw8250_set_divisor(struct uart_port *p, unsigned int baud,if (ret <0 )return ; +__dw8250_set_divisor (p, quot_frac); +serial_port_out (p,UART_LCR , up->lcr |UART_LCR_DLAB );if (!(serial_port_in (p,UART_LCR ) &UART_LCR_DLAB )) goto idle_failed;
drivers/tty/serial/8250/8250_dwlib.c +14 -2
@@ -36,10 +36,20 @@ static unsigned int dw8250_get_divisor(struct uart_port *p, unsigned int baud,return quot; } +/* Program the fractional part of the divisor, if the UART has one */ +void __dw8250_set_divisor (struct uart_port *p,unsigned int quot_frac) +{ +struct dw8250_port_data *d = p->private_data; + +if (d->dlf_size) +dw8250_writel_ext (p,DW_UART_DLF , quot_frac); +} +EXPORT_SYMBOL_GPL (__dw8250_set_divisor); +static void dw8250_set_divisor (struct uart_port *p,unsigned int baud,unsigned int quot,unsigned int quot_frac) { -dw8250_writel_ext (p,DW_UART_DLF , quot_frac); +__dw8250_set_divisor (p, quot_frac);serial8250_do_set_divisor (p, baud, quot); }
@@ -218,7 +228,9 @@ void dw8250_setup_port(struct uart_port *p)if (reg) { pd->dlf_size =fls (reg); p->get_divisor = dw8250_get_divisor; - p->set_divisor = dw8250_set_divisor; +/* Keep a hook the driver has already installed */ +if (!p->set_divisor) + p->set_divisor = dw8250_set_divisor; } reg =dw8250_readl_ext (p,DW_UART_UCV );
drivers/tty/serial/8250/8250_dwlib.h +1 -0
@@ -99,6 +99,7 @@ struct dw8250_port_data {void dw8250_do_set_termios (struct uart_port *p,struct ktermios *termios,const struct ktermios *old);void dw8250_setup_port (struct uart_port *p); +void __dw8250_set_divisor (struct uart_port *p,unsigned int quot_frac);static inline u32 dw8250_readl_ext (struct uart_port *p,int offset) {
PATCH v2 2/4 serial: 8250_dw: Only accept a contiguous DLF readback
In reply to Vinicius Pedrosadw8250_setup_port() writes all ones to offset 0xc0 and treats any nonzero readback as the DLF register. DLF is a bit field starting at bit 0, so a real one reads back as a contiguous 2^n - 1 mask. On some Allwinner SoCs offset 0xc0 is the RS485 control register instead (UART_485_CTL in the A733 User Manual), whose implemented bits are not contiguous. The probe still takes its readback for a DLF of fls(readback) bits, and every later divisor change writes the fractional divisor into the RS485 control register.
Only accept a readback of the form 2^n - 1.
The probe itself is unchanged: it still writes all ones to offset 0xc0 and then restores the old value, so this only changes how the readback is interpreted.
The A733 reads back 0x19f, and Andre Przywara observed 0x9f on the A523. Without this check the A733 RS485 control register reads 0xb after boot; with it, the register stays 0 across 300 termios toggle and restore cycles.
--- drivers/tty/serial/8250/8250_dwlib.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_dwlib.c +5 -1
@@ -225,7 +225,11 @@ void dw8250_setup_port(struct uart_port *p) reg =dw8250_readl_ext (p,DW_UART_DLF );dw8250_writel_ext (p,DW_UART_DLF , old_dlf); -if (reg) { +/* +* DLF is a bit field starting at bit 0, so a real one reads back as +* 2^n - 1. Any other value means this offset is something else. +*/ +if (reg && !(reg & (reg +1 ))) { pd->dlf_size =fls (reg); p->get_divisor = dw8250_get_divisor;/* Keep a hook the driver has already installed */
PATCH v2 3/4 dt-bindings: serial: snps-dw-apb-uart: Add Allwinner A733
In reply to Vinicius PedrosaThe Allwinner A733 UART is a DesignWare APB UART, but it needs SoC-specific handling so the driver can avoid stopping its clock during termios changes.
Add an A733-specific compatible, with "snps,dw-apb-uart" as the fallback.
--- Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml | 1 + 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml +1 -0
@@ -60,6 +60,7 @@ properties: - const: renesas,rzn1-uart - items: - enum: + - allwinner,sun60i-a733-uart - anlogic,dr1v90-uart - brcm,bcm11351-dw-apb-uart - brcm,bcm21664-dw-apb-uart
PATCH v2 4/4 serial: 8250_dw: Add Allwinner A733 UART
In reply to Vinicius PedrosaOn the A733, dw8250_set_termios() stops the UART clock around clk_set_rate() on every termios change that reaches the driver. If TX is active at that moment, the character being shifted out is corrupted.
No baud rate change is required to trigger the problem. Toggling only CLOCAL or CSTOPB 300 times during continuous console output corrupted bytes in every run without the quirk and in none with it.
Use the existing SKIP_SET_RATE quirk, as the JH7100 and SG2044 UARTs do.
--- drivers/tty/serial/8250/8250_dw.c | 1 + 1 file changed, 1 insertion(+)
drivers/tty/serial/8250/8250_dw.c +1 -0
@@ -906,6 +906,7 @@ static const struct dw8250_platform_data dw8250_tda54 = {static const struct of_device_id dw8250_of_match[] = { { .compatible ="snps,dw-apb-uart" , .data = &dw8250_dw_apb }, + { .compatible ="allwinner,sun60i-a733-uart" , .data = &dw8250_skip_set_rate_data }, { .compatible ="cavium,octeon-3860-uart" , .data = &dw8250_octeon_3860_data }, { .compatible ="marvell,armada-38x-uart" , .data = &dw8250_armada_38x_data }, { .compatible ="renesas,rzn1-uart" , .data = &dw8250_renesas_rzn1_data },
[email protected]
AI reviewRe: [PATCH v2 3/4] dt-bindings: serial: snps-dw-apb-uart: Add Allwinner A733
In reply to Vinicius PedrosaSashiko has reviewed this patch and found no issues.
Quoted 8 lines
The Allwinner A733 UART is a DesignWare APB UART, but it needs SoC-specific handling so the driver can avoid stopping its clock during termios changes.
Add an A733-specific compatible, with "snps,dw-apb-uart" as the fallback.
Signed-off-by Vinicius Pedrosa <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
In reply to Vinicius PedrosaSashiko has reviewed this patch and found no issues.
Quoted 15 lines
dw8250_setup_port()writes all ones to offset0xc0and treats any nonzero readback as the DLF register. DLF is a bit field starting at bit 0, so a real one reads back as a contiguous 2^n - 1 mask. On some Allwinner SoCs offset0xc0is the RS485 control register instead (UART_485_CTLin the A733 User Manual), whose implemented bits are not contiguous. The probe still takes its readback for a DLF of fls(readback) bits, and every later divisor change writes the fractional divisor into the RS485 control register.Only accept a readback of the form 2^n - 1.
The probe itself is unchanged: it still writes all ones to offset
0xc0and then restores the old value, so this only changes how the readback is interpreted.
Quoted 7 lines
The A733 reads back
0x19f, and Andre Przywara observed0x9fon the A523. Without this check the A733 RS485 control register reads0xbafter boot; with it, the register stays 0 across 300 termios toggle and restore cycles.Suggested-by Andre Przywara <[email protected]>Signed-off-by Vinicius Pedrosa <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
[email protected]
AI reviewRe: [PATCH v2 4/4] serial: 8250_dw: Add Allwinner A733 UART
In reply to Vinicius PedrosaSashiko has reviewed this patch and found no issues.
Quoted 11 lines
On the A733,
dw8250_set_termios()stops the UART clock aroundclk_set_rate()on every termios change that reaches the driver. If TX is active at that moment, the character being shifted out is corrupted.No baud rate change is required to trigger the problem. Toggling only CLOCAL or CSTOPB 300 times during continuous console output corrupted bytes in every run without the quirk and in none with it.
Use the existing
SKIP_SET_RATEquirk, as the JH7100 and SG2044 UARTs do.Signed-off-by Vinicius Pedrosa <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Vinicius PedrosaSashiko has reviewed this patch and found no issues.
Quoted 27 lines
dw8250_probe()installsdw8250_set_divisor(), which brackets the DLAB/DLL/DLH sequence withdw8250_idle_enter()anddw8250_idle_exit()so a BUSY UART cannot drop the divisor LCR write.
dw8250_setup_port()runs afterwards and replaces that hook with the dwlib divisor hook whenever it detects DLF. The dwlib hook programs the divisor throughserial8250_do_set_divisor()without entering idle, leaving the LCR|DLAB write exposed to BUSY.When termios changes while the UART is transmitting, that LCR|DLAB write can be ignored and
dw8250_check_lcr()retries it betweendw8250_idle_enter()anddw8250_idle_exit().dw8250_idle_exit()then restores IER while DLAB is still set, so the value lands in DLH. The real IER stays at the zero written bydw8250_idle_enter(), and the port gets no further TX or RX interrupts whileup->iersays they're enabled.Do not replace a divisor hook the driver has already installed. Program DLF from the BUSY-safe hook, inside the idle section, through a dwlib helper that checks
dlf_size.Observed on an Allwinner A733 (Radxa Cubie A7Z), where
dw8250_setup_port()mistakes the RS485 control register for DLF (see the next patch): the first interactivetcsetattr()during console output left hardware IER at 0 andup->ierat0x07. The shell never printed its prompt or read input. With this change alone the same boot reached the prompt and echoed input, and hardware IER matchedup->ierafterwards.
Quoted 3 lines
Fixes a7b9ce39fbe4 ("serial: 8250_dw: Ensure BUSY is deasserted")Signed-off-by Vinicius Pedrosa <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Jiri Slaby
maintainerRe: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
In reply to Vinicius Pedrosadrivers/tty/serial/8250/8250_dwlib.c void dw8250_setup_port(struct uart_port *p) · line 232
Quoted 12 lines · Vinicius Pedrosa
drivers/tty/serial/8250/8250_dwlib.c +5
-1@@ -225,7 +225,11 @@ void dw8250_setup_port(struct uart_port *p) reg =dw8250_readl_ext (p,DW_UART_DLF );dw8250_writel_ext (p,DW_UART_DLF , old_dlf); -if (reg) { +/* +* DLF is a bit field starting at bit 0, so a real one reads back as +* 2^n - 1. Any other value means this offset is something else. +*/ +if (reg && !(reg & (reg +1 ))) {
Do I understand correctly, that this equivalent to:
if (is_power_of_2(reg + 1))
?
thanks,
Signature · 2 lines
js suse labs
Andy Shevchenko
reviewerRe: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Vinicius PedrosaQuoted 26 lines · Vinicius Pedrosa
dw8250_probe()installsdw8250_set_divisor(), which brackets the DLAB/DLL/DLH sequence withdw8250_idle_enter()anddw8250_idle_exit()so a BUSY UART cannot drop the divisor LCR write.
dw8250_setup_port()runs afterwards and replaces that hook with the dwlib divisor hook whenever it detects DLF. The dwlib hook programs the divisor throughserial8250_do_set_divisor()without entering idle, leaving the LCR|DLAB write exposed to BUSY.When termios changes while the UART is transmitting, that LCR|DLAB write can be ignored and
dw8250_check_lcr()retries it betweendw8250_idle_enter()anddw8250_idle_exit().dw8250_idle_exit()then restores IER while DLAB is still set, so the value lands in DLH. The real IER stays at the zero written bydw8250_idle_enter(), and the port gets no further TX or RX interrupts whileup->iersays they're enabled.Do not replace a divisor hook the driver has already installed. Program DLF from the BUSY-safe hook, inside the idle section, through a dwlib helper that checks
dlf_size.Observed on an Allwinner A733 (Radxa Cubie A7Z), where
dw8250_setup_port()mistakes the RS485 control register for DLF (see the next patch): the first interactivetcsetattr()during console output left hardware IER at 0 andup->ierat0x07. The shell never printed its prompt or read input. With this change alone the same boot reached the prompt and echoed input, and hardware IER matchedup->ierafterwards.
...
drivers/tty/serial/8250/8250_dwlib.c static unsigned int dw8250_get_divisor(struct uart_port *p, unsigned int baud, · line 40
Quoted 2 lines
drivers/tty/serial/8250/8250_dwlib.c +2
-0+/* Program the fractional part of the divisor, if the UART has one */ +void __dw8250_set_divisor (struct uart_port *p,unsigned int quot_frac)
Let's reduce amount of double underscore functions. Let's call it dw8250_update_dfl(). Also call the parameter just 'frac'.
void dw8250_update_dfl(struct uart_port *p, unsigned int frac)
...
Quoted 5 lines
+++
b/drivers/tty/serial/8250/8250_dwlib.hvoid
dw8250_do_set_termios(struct uart_port *p, struct ktermios *termios, const struct ktermios *old); voiddw8250_setup_port(struct uart_port *p);
+void__dw8250_set_divisor(struct uart_port *p, unsigned int quot_frac);
Put it rather after _writel_ext() implementation, because it's just a small wrapper on top of it. Or even make it 'static inline' there.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerRe: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
In reply to Jiri SlabyQuoted 1 line · Jiri Slaby
On 19. 10. 26, 22:06, Vinicius Pedrosa wrote:
...
Quoted 10 lines
drivers/tty/serial/8250/8250_dwlib.c void dw8250_setup_port(struct uart_port *p) · line 232
Quoted 6 lines
drivers/tty/serial/8250/8250_dwlib.c +5
-1-if (reg) { +/* +* DLF is a bit field starting at bit 0, so a real one reads back as +* 2^n - 1. Any other value means this offset is something else. +*/ +if (reg && !(reg & (reg +1 ))) {Do I understand correctly, that this equivalent to:
if (is_power_of_2(reg + 1))
?
Yes, and since we check for reg to be "not zero", this will work the rest.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerRe: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Vinicius PedrosaOn Mon, Oct 19, 2026 at 05:06:10PM -0300, Vinicius Pedrosa wrote:
...
drivers/tty/serial/8250/8250_dwlib.c void dw8250_setup_port(struct uart_port *p) · line 230
Quoted 4 lines
drivers/tty/serial/8250/8250_dwlib.c +0
-0@@ -218,7 +228,9 @@ void dw8250_setup_port(struct uart_port *p)if (reg) { pd->dlf_size =fls (reg); p->get_divisor = dw8250_get_divisor;
In the case of existing _set_divisor, do we want to keep the possible set _get_divisor as well? Shouldn't we introduce a respective _get_divisor in 8250_dw.c?
drivers/tty/serial/8250/8250_dwlib.c void dw8250_setup_port(struct uart_port *p) · line 234
Quoted 5 lines
drivers/tty/serial/8250/8250_dwlib.c +3
-1- p->set_divisor = dw8250_set_divisor; +/* Keep a hook the driver has already installed */ +if (!p->set_divisor) + p->set_divisor = dw8250_set_divisor; }
On top of my previous reply, why is this hunk needed?
...
But now I see that we have same function name in two files. Can we rename those in dwlib to, for example,dw8250_get_divisor --> dw8250_get_dfl_divisordw8250_set_divisor --> dw8250_set_dfl_divisor
?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
In reply to Jiri SlabyHi Jiri,
Quoted 3 lines · Jiri Slaby
Do I understand correctly, that this equivalent to:
if (is_power_of_2(reg + 1))
?
Yes, given the existing reg != 0 check. I kept the explicit form in v2 to keep the change minimal, but I'll use
reg && is_power_of_2(reg + 1)
in v3, it reads better.
The two forms only differ for U32_MAX, where reg + 1 wraps to 0. But that isn't a valid DLF readback here.
Thanks,
Vinicius
Re: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Andy ShevchenkoHi Andy,
Quoted 5 lines · Andy Shevchenko
drivers/tty/serial/8250/8250_dwlib.c void dw8250_setup_port(struct uart_port *p) · line 233
Quoted 3 lines
drivers/tty/serial/8250/8250_dwlib.c +3
-0+/* Keep a hook the driver has already installed */ +if (!p->set_divisor) + p->set_divisor = dw8250_set_divisor;On top of my previous reply, why is this hunk needed?
dw8250_probe() installs the BUSY-safe dw8250_set_divisor() before dw8250_setup_port() runs. Without the !p->set_divisor check, detecting DLF replaces it with the dwlib setter, which is the BUSY problem described in the commit message.
Quoted 3 lines
In the case of existing
_set_divisor, do we want to keep the possible set_get_divisoras well? Shouldn't we introduce a respective_get_divisorin8250_dw.c?
8250_dw.c doesn't install a get_divisor, so there's no existing getter to preserve. The dwlib getter is still needed when DLF is present, because it computes the fractional part used by the preserved BUSY-safe setter.
Quoted 4 lines
But now I see that we have same function name in two files. Can we rename those in dwlib to, for example,
dw8250_get_divisor-->dw8250_get_dfl_divisordw8250_set_divisor-->dw8250_set_dfl_divisor
I'll also clean up the naming in v3: dw8250_update_dlf() with a frac parameter, static inline after dw8250_writel_ext(), and the dwlib-local helpers renamed to dw8250_get_dlf_divisor() and dw8250_set_dlf_divisor().
Thanks,
Vinicius
Ilpo Järvinen
maintainerRe: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
In reply to Andy ShevchenkoQuoted 16 lines · Andy Shevchenko
Quoted 1 line · Jiri Slaby
On 19. 10. 26, 22:06, Vinicius Pedrosa wrote:
...
Quoted 10 lines
drivers/tty/serial/8250/8250_dwlib.c void dw8250_setup_port(struct uart_port *p) · line 232
Quoted 6 lines
drivers/tty/serial/8250/8250_dwlib.c +5
-1-if (reg) { +/* +* DLF is a bit field starting at bit 0, so a real one reads back as +* 2^n - 1. Any other value means this offset is something else. +*/ +if (reg && !(reg & (reg +1 ))) {Do I understand correctly, that this equivalent to:
if (is_power_of_2(reg + 1))
?
Quoted 1 line
Yes, and since we check for reg to be "not zero", this will work the rest.
For is_power_of_2(), 0 is not a power of two. And it also wouldn't make sense to have zero bits in the bit field as it's same as no bit field so using just is_power_of_2() should be enough.
It could be that's what Andy meant, but the wording left too much room for interpretation.
Signature · 1 line
i.
Re: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
Hi Ilpo,
Quoted 3 lines · Ilpo Järvinen
For
is_power_of_2(), 0 is not a power of two. And it also wouldn't make sense to have zero bits in the bit field as it's same as no bit field so using justis_power_of_2()should be enough.
I think the reg != 0 check still needs to stay here, since the test is is_power_of_2(reg + 1), rather than is_power_of_2(reg).
For reg == 0, reg + 1 is 1, and is_power_of_2(1) is true. So without the explicit reg check, a zero readback, meaning no DLF, would be accepted as a valid DLF.
I'll keep it as:
reg && is_power_of_2(reg + 1)
in v3.
Thanks,
Vinicius
Ilpo Järvinen
maintainerRe: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
Quoted 15 lines · Vinicius Pedrosa
Hi Ilpo,
Quoted 3 lines · Ilpo Järvinen
For
is_power_of_2(), 0 is not a power of two. And it also wouldn't make sense to have zero bits in the bit field as it's same as no bit field so using justis_power_of_2()should be enough.I think the reg != 0 check still needs to stay here, since the test is
is_power_of_2(reg + 1), rather thanis_power_of_2(reg).For reg == 0, reg + 1 is 1, and
is_power_of_2(1)is true. So without the explicit reg check, a zero readback, meaning no DLF, would be accepted as a valid DLF.
Quoted 5 lines
I'll keep it as:
reg && is_power_of_2(reg + 1)in v3.
Ah, you're right.
Signature · 1 line
i.
Andy Shevchenko
reviewerRe: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Vinicius PedrosaQuoted 1 line · Vinicius Pedrosa
On Tue, 20 Oct 2026, Andy Shevchenko wrote:
...
Quoted 11 lines
Quoted 5 lines
drivers/tty/serial/8250/8250_dwlib.c void dw8250_setup_port(struct uart_port *p) · line 233
Quoted 3 lines
drivers/tty/serial/8250/8250_dwlib.c +3
-0+/* Keep a hook the driver has already installed */ +if (!p->set_divisor) + p->set_divisor = dw8250_set_divisor;On top of my previous reply, why is this hunk needed?
dw8250_probe()installs the BUSY-safedw8250_set_divisor()beforedw8250_setup_port()runs. Without the !p->set_divisor check, detecting DLF replaces it with the dwlib setter, which is the BUSY problem described in the commit message.
Quoted 6 lines
Quoted 3 lines
In the case of existing
_set_divisor, do we want to keep the possible set_get_divisoras well? Shouldn't we introduce a respective_get_divisorin8250_dw.c?
8250_dw.cdoesn't install aget_divisor, so there's no existing getter to preserve.
Right.
Quoted 3 lines
The dwlib getter is still needed when DLF is present, because it computes the fractional part used by the preserved BUSY-safe setter.
Right, but have you read my second question in the above paragraph?
Quoted 9 lines
Quoted 4 lines
But now I see that we have same function name in two files. Can we rename those in dwlib to, for example,
dw8250_get_divisor-->dw8250_get_dfl_divisordw8250_set_divisor-->dw8250_set_dfl_divisorI'll also clean up the naming in v3:
dw8250_update_dlf()with a frac parameter, static inline afterdw8250_writel_ext(), and the dwlib-local helpers renamed todw8250_get_dlf_divisor()anddw8250_set_dlf_divisor().
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andy Shevchenko
reviewerRe: [PATCH v2 2/4] serial: 8250_dw: Only accept a contiguous DLF readback
In reply to Ilpo JärvinenQuoted 14 lines · Ilpo Järvinen
Quoted 13 lines · Vinicius Pedrosa
Quoted 3 lines · Ilpo Järvinen
For
is_power_of_2(), 0 is not a power of two. And it also wouldn't make sense to have zero bits in the bit field as it's same as no bit field so using justis_power_of_2()should be enough.I think the reg != 0 check still needs to stay here, since the test is
is_power_of_2(reg + 1), rather thanis_power_of_2(reg).For reg == 0, reg + 1 is 1, and
is_power_of_2(1)is true. So without the explicit reg check, a zero readback, meaning no DLF, would be accepted as a valid DLF.
Quoted 7 lines
Quoted 5 lines
I'll keep it as:
reg && is_power_of_2(reg + 1)in v3.
Ah, you're right.
Sorry for being unclear, yes, that's what I meant, reg != 0 should stay.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Andy ShevchenkoHi Andy,
Quoted 1 line · Andy Shevchenko
Right, but have you read my second question in the above paragraph?
Sorry, I missed the second part of your question.
If I understand you correctly, since 8250_dw.c already has the BUSY-safe set_divisor, you're suggesting that it should have the matching get_divisor as well, instead of pairing it with the dwlib getter.
The dwlib getter would stay for the other users of dw8250_setup_port(), like 8250_lpss. Is that the structure you had in mind?
Thanks,
Vinicius
Andy Shevchenko
reviewerRe: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
Quoted 9 lines · Vinicius Pedrosa
Quoted 1 line · Andy Shevchenko
Right, but have you read my second question in the above paragraph?
Sorry, I missed the second part of your question.
If I understand you correctly, since
8250_dw.calready has the BUSY-safeset_divisor, you're suggesting that it should have the matchingget_divisoras well, instead of pairing it with the dwlib getter.
Exactly!
Quoted 2 lines
The dwlib getter would stay for the other users of
dw8250_setup_port(), like 8250_lpss. Is that the structure you had in mind?
8250_lpss doesn't redefine either of the _get/_set_divisor, so it won't be affected. But I think that 8250_lpss actually lacks of busy support that's why it uses simpler version of all this. Maybe we can refactor that (in the future?) so that we will have dwlib to provide the IDLE version of them for all and depending on the existence of busy functionality degrade to the same as just current DFL helpers.
Can you check that approach?
Ah, dw8250_idle_*() are already BUSY-functionality aware. So, what we need is to provide dw8250_idlej_*() callbacks via struct dw8250_port_data and make current 8250_dw::dw8250_set_divisor() to be part of dwlib.
Patch 1 (dwlib): Add callback definitions for dw8250_idle_*() to struct dw8250_port_data Patch 2 (dw): Assign new callbacks and use them in dw8250_set_divisor() Patch 3 (lpss): Introduce stubs and assign new callbacks to them
Patch 4 (dwlib): Use dw8250_idle_*() in dw8250_set_divisor()
Patch 5 (dw): Kill now duplicate code pieces
(Some of the patches might be combined, but I think the above split is not bad.)
Would it work?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 3/4] dt-bindings: serial: snps-dw-apb-uart: Add Allwinner A733
In reply to Vinicius PedrosaHi Vinicius,
Quoted 18 lines · Vinicius Pedrosa
The Allwinner A733 UART is a DesignWare APB UART, but it needs SoC-specific handling so the driver can avoid stopping its clock during termios changes.
Add an A733-specific compatible, with "snps,dw-apb-uart" as the fallback.
Signed-off-by Vinicius Pedrosa <[email protected]>Acked-by Conor Dooley <[email protected]>--- Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml | 1 + 1 file changed, 1 insertion(+)Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml +0
-0
Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml properties: · line 63
Quoted 4 lines
Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml +1
-0@@ -60,6 +60,7 @@ properties: - const: renesas,rzn1-uart - items: - enum: + - allwinner,sun60i-a733-uart
So if I understand correctly, this compatible is really there for the clock gating issue, right? As the DLF part is now somewhat correctly auto-detected? Can you share what your termios test looks like? Because I assume this affects more Allwinner SoCs (the DLF change definitely does). Then we should add more compatible strings here. If there is a simple test, I am happy to run this on a bunch of boards, to give you a list.
Cheers,
Andre
Quoted 3 lines
Documentation/devicetree/bindings/serial/snps-dw-apb-uart.yaml +0
-0- anlogic,dr1v90-uart - brcm,bcm11351-dw-apb-uart - brcm,bcm21664-dw-apb-uart
Re: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Andy ShevchenkoHi Andy,
Quoted 11 lines · Andy Shevchenko
Ah, dw8250_idle_*() are already BUSY-functionality aware. So, what we need is to provide dw8250_idlej_*() callbacks via struct
dw8250_port_dataand make current 8250_dw::dw8250_set_divisor() to be part of dwlib.Patch 1 (dwlib): Add callback definitions for dw8250_idle_*() to struct
dw8250_port_dataPatch 2 (dw): Assign new callbacks and use them indw8250_set_divisor()Patch 3 (lpss): Introduce stubs and assign new callbacks to them
Patch 4 (dwlib): Use dw8250_idle_*() indw8250_set_divisor()
Patch 5 (dw): Kill now duplicate code piecesWould it work?
Yes, I think the approach works. Two details from checking the call paths.
dw8250_setup_port() is skipped for Octeon (skip_autocfg), so 8250_dw would still have to install the setter from probe.
For LPSS, I wonder if the idle callbacks could simply be optional. 8250_dw would provide them and LPSS could leave them NULL, avoiding stubs and a separate LPSS patch. The common setter in dwlib would use them when present.
I'd still prefer to keep patch 1 as the small fix with the stable tag and do the refactoring as a separate follow-up series. Would that work for you?
I don't have LPSS hardware, but I can build-test the LPSS side.
Thanks,
Vinicius
Andy Shevchenko
reviewerRe: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
Quoted 12 lines · Vinicius Pedrosa
Quoted 10 lines · Andy Shevchenko
Ah, dw8250_idle_*() are already BUSY-functionality aware. So, what we need is to provide dw8250_idle_*() callbacks via struct
dw8250_port_dataand make current 8250_dw::dw8250_set_divisor() to be part of dwlib.Patch 1 (dwlib): Add callback definitions for dw8250_idle_*() to struct
dw8250_port_dataPatch 2 (dw): Assign new callbacks and use them indw8250_set_divisor()Patch 3 (lpss): Introduce stubs and assign new callbacks to them
Patch 4 (dwlib): Use dw8250_idle_*() indw8250_set_divisor()
Patch 5 (dw): Kill now duplicate code pieces
Quoted 7 lines
Quoted 1 line
Would it work?
Yes, I think the approach works. Two details from checking the call paths.
dw8250_setup_port()is skipped for Octeon (skip_autocfg), so 8250_dw would still have to install the setter from probe.
No, just pass that as a 'bool autoconf' to it, and assign those callbacks there, while calling dw8250_setup_port() unconditionally from _probe().
It might require another patch, though (to make it a parameter first).
Quoted 4 lines
For LPSS, I wonder if the idle callbacks could simply be optional. 8250_dw would provide them and LPSS could leave them NULL, avoiding stubs and a separate LPSS patch. The common setter in dwlib would use them when present.
I think it would be less flexible, also it will add an additional branch (actually two) each time the set_divisor is called (not that it's critical but just wanted to mentioned that).
Quoted 3 lines
I'd still prefer to keep patch 1 as the small fix with the stable tag and do the refactoring as a separate follow-up series. Would that work for you?
I dunno, I prefer just a longer solution, but I don't know how big this issue is that we need to backport in that way (and not taking the whole series as a fix).
Quoted 1 line
I don't have LPSS hardware, but I can build-test the LPSS side.
I have Intel Galileo board that uses 8250_lpss.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
Hi Andy,
Quoted 2 lines · Andy Shevchenko
No, just pass that as a 'bool autoconf' to it, and assign those callbacks there, while calling
dw8250_setup_port()unconditionally from_probe().
I think the autoconf approach works for Octeon as long as everything dw8250_setup_port() probes today stays under it, including the RS485 detection and UART_CAP_NOTEMT, not just DLF/CPR. With autoconf=false it would only install the common divisor setter.
Quoted 3 lines
I think it would be less flexible, also it will add an additional branch (actually two) each time the
set_divisoris called (not that it's critical but just wanted to mentioned that).
The idle callbacks have to come from the drivers, since the dw8250_idle_*() functions are static in 8250_dw.c. Stubs for LPSS are fine with me.
Quoted 3 lines
I dunno, I prefer just a longer solution, but I don't know how big this issue is that we need to backport in that way (and not taking the whole series as a fix).
On the severity: the IER restore comes from a7b9ce39fbe4. On the A733 I saw hardware IER left at 0 and the console stop taking TX/RX interrupts. I haven't tested this on hardware with a real DLF.
Given that, how about keeping the small fix as patch 1 with the stable tag, and putting the refactoring after it in the same series? That would keep the fix independently backportable if needed, while mainline would still end up with the structure you proposed.
Quoted 1 line
I have Intel Galileo board that uses 8250_lpss.
The Galileo should be useful for checking the LPSS path.
Thanks,
Vinicius
Andy Shevchenko
reviewerRe: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
Quoted 1 line · Vinicius Pedrosa
On Wed, 21 Oct 2026, Andy Shevchenko wrote:
...
Quoted 7 lines
Quoted 3 lines
I dunno, I prefer just a longer solution, but I don't know how big this issue is that we need to backport in that way (and not taking the whole series as a fix).
On the severity: the IER restore comes from
a7b9ce39fbe4. On the A733 I saw hardware IER left at 0 and the console stop taking TX/RX interrupts. I haven't tested this on hardware with a real DLF.
Yes. but is it only a single device/platform affected or a big class of the devices? I assume only narrow part of them which unfortunately use DFL register offset for something else in their RTL.
Quoted 4 lines
Given that, how about keeping the small fix as patch 1 with the stable tag, and putting the refactoring after it in the same series? That would keep the fix independently backportable if needed, while mainline would still end up with the structure you proposed.
It all depends on the outcome of the above discussion. Maybe others can share their opinions, but I lean towards a series-as-a-fix rather than a bit ugly fix
+ proper refactoring on top.
The whole approach doesn't seem to me like a pile of changes. The deduplication patch can be deferred for later actually.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 3/4] dt-bindings: serial: snps-dw-apb-uart: Add Allwinner A733
In reply to Andre PrzywaraHi Andre,
Quoted 3 lines · Andre Przywara
So if I understand correctly, this compatible is really there for the clock gating issue, right? As the DLF part is now somewhat correctly auto-detected?
Yes, the compatible is only for the clock issue (SKIP_SET_RATE). The false DLF detection is handled generically by patch 2.
Quoted 4 lines
Can you share what your termios test looks like? Because I assume this affects more Allwinner SoCs (the DLF change definitely does). Then we should add more compatible strings here. If there is a simple test, I am happy to run this on a bunch of boards, to give you a list.
I reduced the termios test to a small standalone reproducer and retested it on the A733. While the serial console is continuously transmitting, this program toggles CLOCAL and restores it:
#include <fcntl.h>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int main(int argc, char **argv)
{
const char *dev = argc > 1 ? argv[1] : "/dev/console";
struct termios orig, changed;
int fd = open(dev, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (fd < 0 || tcgetattr(fd, &orig)) {
perror(dev);
return 1;
}
changed = orig;
changed.c_cflag ^= CLOCAL;
if (tcsetattr(fd, TCSANOW, &changed) ||
tcsetattr(fd, TCSANOW, &orig)) {
perror("tcsetattr");
return 1;
}
return 0;
}I compile it with:
cc -O2 -o clocal-toggle clocal-toggle.c
and run 300 iterations from a shell on the serial console, keeping the console busy:
dmesg -n 1
(while :; do seq 1 1000; done) &
gen=$!
i=0
while [ "$i" -lt 300 ]; do
./clocal-toggle || break
i=$((i + 1))
done
kill $genCLOCAL doesn't change the framing, so the output should stay a clean 1..1000 sequence. A bad run shows garbage characters and missing lines.
On the A733 I ran this test five times without SKIP_SET_RATE and all five runs were corrupted. With the A733 compatible selecting SKIP_SET_RATE, all five were clean.
Running the same test on your other Allwinner boards would be very useful. I also have a small script that checks the capture, if that helps.
Thanks,
Vinicius
Re: [PATCH v2 1/4] serial: 8250_dw: Keep the BUSY-safe divisor hook when DLF is present
In reply to Andy ShevchenkoHi Andy,
Quoted 3 lines · Andy Shevchenko
Yes. but is it only a single device/platform affected or a big class of the devices? I assume only narrow part of them which unfortunately use DFL register offset for something else in their RTL.
The A733 is the only case I've seen, and the false DLF is what exposed it. But I don't think the BUSY problem depends on the DLF offset being
reused: with a real DLF on a UART that isn't 16550-compatible, dw8250_setup_port() also replaces the BUSY-safe setter with the dwlib one, so the same path exists. I haven't confirmed that on hardware.
With patch 2 the A733 no longer takes that path.
Quoted 3 lines
It all depends on the outcome of the above discussion. Maybe others can share their opinions, but I lean towards a series-as-a-fix rather than a bit ugly fix
+ proper refactoring on top.
I'm fine with a series-as-a-fix, and with deferring the deduplication patch.
Thanks,
Vinicius