From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: khaliforce <kforce@gmail.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
linux-serial <linux-serial@vger.kernel.org>
Subject: Re: [PATCH] serial: 8250_dw: retain programmed timing for BUSY waits
Date: Mon, 12 Oct 2026 15:08:00 +0300 (EEST) [thread overview]
Message-ID: <3f9f7b12-0edd-1683-6f8b-f14802db832f@linux.intel.com> (raw)
In-Reply-To: <1791785420.8010663.945898876521967.uart-busy-frame-time@gmail.com>
On Mon, 12 Oct 2026, khaliforce wrote:
> Baud changes update frame_time before the programmed divisor changes.
Why not fix this problem instead? It would seem wrong to have wrong value
in ->frame_time.
--
i.
> A switch to a faster baud rate therefore shortens the DesignWare BUSY
> wait.
> The wait can expire while a frame at the old baud rate remains active.
>
> Use the programmed frame duration for FIFO and BUSY waits.
> Account for UART clock changes.
>
> Fixes: a7b9ce39fbe4 ("serial: 8250_dw: Ensure BUSY is deasserted")
> Signed-off-by: khaliforce <kforce@gmail.com>
> ---
> Compared the complete patch off/on on MangoPi MQ Pro UART0.
> Kept other port patches, kernel options and DTB identical.
> Tested BUSY changes from 9600, 1200 and 300 to 115200.
> All 11 paired changes fail without the patch and pass with it.
> Each trial returns 64 matching loopback bytes.
>
> drivers/tty/serial/8250/8250_dw.c | 20 ++++++++++++++++++--
> drivers/tty/serial/8250/8250_dwlib.c | 4 ++++
> drivers/tty/serial/8250/8250_dwlib.h | 4 ++++
> 3 files changed, 26 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
> index 51d026f20825..03be503bcef0 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -17,6 +17,8 @@
> #include <linux/device.h>
> #include <linux/io.h>
> #include <linux/lockdep.h>
> +#include <linux/math64.h>
> +#include <linux/minmax.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> #include <linux/pm_runtime.h>
> @@ -131,6 +133,9 @@ static int dw8250_idle_enter(struct uart_port *p)
> struct dw8250_data *d = to_dw8250_data(p->private_data);
> unsigned int usr_reg = d->pdata ? d->pdata->usr_reg : DW_UART_USR;
> struct uart_8250_port *up = up_to_u8250p(p);
> + unsigned int frame_time = d->data.frame_time ?: p->frame_time;
> + unsigned int saved_frame_time = p->frame_time;
> + u64 scaled_frame_time;
> int retries;
> u32 lsr;
>
> @@ -139,6 +144,12 @@ static int dw8250_idle_enter(struct uart_port *p)
> if (d->uart_16550_compatible)
> return 0;
>
> + if (d->data.frame_time && d->data.frame_time_uartclk && p->uartclk) {
> + scaled_frame_time = (u64)frame_time * d->data.frame_time_uartclk;
> + scaled_frame_time = DIV_ROUND_UP_ULL(scaled_frame_time, p->uartclk);
> + frame_time = min_t(u64, scaled_frame_time, U32_MAX);
> + }
> +
> d->in_idle = 1;
>
> /* Prevent triggering interrupt from RBR filling */
> @@ -156,8 +167,10 @@ static int dw8250_idle_enter(struct uart_port *p)
> *
> * FIXME: frame_time delay is too long with very low baudrates.
> */
> + p->frame_time = frame_time;
> serial8250_fifo_wait_for_lsr_thre(up, NULL, p->fifosize);
> - ndelay(p->frame_time);
> + p->frame_time = saved_frame_time;
> + ndelay(frame_time);
>
> serial_port_out(p, UART_MCR, up->mcr | UART_MCR_LOOP);
>
> @@ -167,7 +180,7 @@ static int dw8250_idle_enter(struct uart_port *p)
> if (!(serial_port_in(p, usr_reg) & DW_UART_USR_BUSY))
> break;
> /* FIXME: frame_time delay is too long with very low baudrates. */
> - ndelay(p->frame_time);
> + ndelay(frame_time);
> } while (--retries);
>
> lsr = serial_lsr_in(up);
> @@ -188,6 +201,7 @@ static int dw8250_idle_enter(struct uart_port *p)
> static void dw8250_set_divisor(struct uart_port *p, unsigned int baud,
> unsigned int quot, unsigned int quot_frac)
> {
> + struct dw8250_port_data *d = p->private_data;
> struct uart_8250_port *up = up_to_u8250p(p);
> int ret;
>
> @@ -200,6 +214,8 @@ static void dw8250_set_divisor(struct uart_port *p, unsigned int baud,
> goto idle_failed;
>
> serial_dl_write(up, quot);
> + d->frame_time = p->frame_time;
> + d->frame_time_uartclk = p->uartclk;
> serial_port_out(p, UART_LCR, up->lcr);
>
> idle_failed:
> diff --git a/drivers/tty/serial/8250/8250_dwlib.c b/drivers/tty/serial/8250/8250_dwlib.c
> index 8859e66d2d71..d74ff203f904 100644
> --- a/drivers/tty/serial/8250/8250_dwlib.c
> +++ b/drivers/tty/serial/8250/8250_dwlib.c
> @@ -39,8 +39,12 @@ static unsigned int dw8250_get_divisor(struct uart_port *p, unsigned int baud,
> static void dw8250_set_divisor(struct uart_port *p, unsigned int baud,
> unsigned int quot, unsigned int quot_frac)
> {
> + struct dw8250_port_data *d = p->private_data;
> +
> dw8250_writel_ext(p, DW_UART_DLF, quot_frac);
> serial8250_do_set_divisor(p, baud, quot);
> + d->frame_time = p->frame_time;
> + d->frame_time_uartclk = p->uartclk;
> }
>
> void dw8250_do_set_termios(struct uart_port *p, struct ktermios *termios,
> diff --git a/drivers/tty/serial/8250/8250_dwlib.h b/drivers/tty/serial/8250/8250_dwlib.h
> index 1fe52332e774..5472c13ca92e 100644
> --- a/drivers/tty/serial/8250/8250_dwlib.h
> +++ b/drivers/tty/serial/8250/8250_dwlib.h
> @@ -88,6 +88,10 @@ struct dw8250_port_data {
> u32 cpr_value;
> u8 dlf_size;
>
> + /* Timing for the programmed divisor. */
> + u32 frame_time;
> + u32 frame_time_uartclk;
> +
> /* RS485 variables */
> bool hw_rs485_support;
> };
>
prev parent reply other threads:[~2026-10-12 12:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-12 6:10 khaliforce
2026-10-12 6:31 ` Greg Kroah-Hartman
2026-10-12 6:33 ` Greg Kroah-Hartman
2026-10-12 12:08 ` Ilpo Järvinen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3f9f7b12-0edd-1683-6f8b-f14802db832f@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kforce@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®