All of lore.kernel.org
 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 1/3] serial: core: Document why UPF_SPD_CUST is not handled in uart_get_baud_rate()
Date: Mon, 21 Mar 2022 17:30:53 +0100	[thread overview]
Message-ID: <20220321163055.4058-2-pali@kernel.org> (raw)
In-Reply-To: <20220321163055.4058-1-pali@kernel.org>

Switch in uart_get_baud_rate() function is missing case for UPF_SPD_CUST
flag. It is not obvious why it is missing here, so add comments explaining
how deprecated UPF_SPD_CUST flag is handled and how drivers should call
uart_get_baud_rate() and uart_get_divisor() functions.

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

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 1e738f265eea..d8fc2616d62b 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -364,7 +364,17 @@ EXPORT_SYMBOL(uart_update_timeout);
  *
  *	Decode the termios structure into a numeric baud rate,
  *	taking account of the magic 38400 baud rate (with spd_*
- *	flags), and mapping the %B0 rate to 9600 baud.
+ *	flags, except cust), and mapping the %B0 rate to 9600 baud.
+ *
+ *	UPF_SPD_CUST flag is not handled in this function as it applies
+ *	to the custom divisor. When UPF_SPD_CUST flag is active and in
+ *	use then this function returns value 38400 and not the correct
+ *	baud rate.
+ *
+ *	Drivers should call uart_get_divisor() function with baud rate
+ *	returned from this function to calculate clock divisor. Function
+ *	uart_get_divisor() then handles UPF_SPD_CUST flag with magic
+ *	baud rate value 38400 and returns the correct custom divisor.
  *
  *	If the new baud rate is invalid, try the old termios setting.
  *	If it's still invalid, we try 9600 baud.
@@ -396,6 +406,7 @@ uart_get_baud_rate(struct uart_port *port, struct ktermios *termios,
 	case UPF_SPD_WARP:
 		altbaud = 460800;
 		break;
+	/* Flag UPF_SPD_CUST is not handed here, see description why. */
 	default:
 		altbaud = 38400;
 		break;
@@ -462,6 +473,8 @@ EXPORT_SYMBOL(uart_get_baud_rate);
  *	@baud: desired baud rate
  *
  *	Calculate the uart clock divisor for the port.
+ *
+ *	Handles also special case when UPF_SPD_CUST flag is in use.
  */
 unsigned int
 uart_get_divisor(struct uart_port *port, unsigned int baud)
-- 
2.20.1


  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 ` Pali Rohár [this message]
2022-03-21 16:30 ` [PATCH 2/3] serial: core: Fix function uart_update_timeout() to handle UPF_SPD_CUST flag Pali Rohár
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-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.