linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jiri Slaby" <jirislaby@kernel.org>,
	"Johan Hovold" <johan@kernel.org>,
	"Marek Behún" <kabel@kernel.org>
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/3] serial: core: Fix function uart_update_timeout() to handle UPF_SPD_CUST flag
Date: Mon, 21 Mar 2022 17:30:54 +0100	[thread overview]
Message-ID: <20220321163055.4058-3-pali@kernel.org> (raw)
In-Reply-To: <20220321163055.4058-1-pali@kernel.org>

Function uart_update_timeout() currently handles UPF_SPD_HI, UPF_SPD_VHI,
UPF_SPD_SHI and UPF_SPD_WARP flags thanks to how uart_get_baud_rate()
works and how should be used. uart_get_baud_rate() already translates these
4 special flags to real baud rate value and therefore uart_update_timeout()
is called with the correct baud rate argument.

What is not handled in this function is the last remaining flag
UPF_SPD_CUST. It is because uart_get_baud_rate() returns hardcoded value
38400 when UPF_SPD_CUST is set and in use.

Implement support for UPF_SPD_CUST in uart_update_timeout(), so
port->timeout is calculated also when UPF_SPD_CUST flag is set.

For calculation use base uart clock and custom divisor. This calculation
does not have to be precise for all UART hardware but this the best
approximation which can be done. It is for sure better than hardcoded baud
rate value 38400.

Signed-off-by: Pali Rohár <pali@kernel.org>
---
 drivers/tty/serial/serial_core.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index d8fc2616d62b..34e085a038fe 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -343,6 +343,16 @@ uart_update_timeout(struct uart_port *port, unsigned int cflag,
 {
 	unsigned int size;
 
+	/*
+	 * Old custom speed handling. See function uart_get_divisor()
+	 * and description in uart_get_baud_rate() function.
+	 * This calculation does not have to be precise for all UART
+	 * hardware but it is the best approximation which we can do here
+	 * as we do not know the exact baud rate.
+	 */
+	if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
+		baud = DIV_ROUND_CLOSEST(port->uartclk, 16 * port->custom_divisor);
+
 	size = tty_get_frame_size(cflag) * port->fifosize;
 
 	/*
-- 
2.20.1


  parent reply	other threads:[~2022-03-21 16:31 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 16:30 [PATCH 0/3] serial: Fix support for UPF_SPD_* flags Pali Rohár
2022-03-21 16:30 ` [PATCH 1/3] serial: core: Document why UPF_SPD_CUST is not handled in uart_get_baud_rate() Pali Rohár
2022-03-21 16:30 ` Pali Rohár [this message]
2022-03-21 16:30 ` [PATCH 3/3] serial: Fix support for UPF_SPD_* flags in serial drivers Pali Rohár
2022-03-22 14:29 ` [PATCH 0/3] serial: Fix support for UPF_SPD_* flags Andy Shevchenko
2022-03-22 18:53   ` Pali Rohár
2022-04-22 14:28   ` Greg Kroah-Hartman
2022-07-07  8:48     ` Pali Rohár
2022-07-08 13:07       ` Greg Kroah-Hartman
2022-07-08 13:26         ` Pali Rohár
2022-07-08 13:51           ` Greg Kroah-Hartman
2022-07-08 14:20             ` Pali Rohár
2022-07-08 15:42               ` Andy Shevchenko
2022-07-08 15:54                 ` Pali Rohár
2022-07-08 16:09                   ` Andy Shevchenko
2022-07-08 16:25                     ` Pali Rohár
2022-07-08 17:41                       ` Andy Shevchenko

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=20220321163055.4058-3-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=johan@kernel.org \
    --cc=kabel@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).