All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: linux-mips@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 2/5] serial: 8250: Actually allow UPF_MAGIC_MULTIPLIER baud rates
Date: Thu, 10 Jun 2021 20:38:34 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.21.2105190412280.29169@angie.orcam.me.uk> (raw)
In-Reply-To: <alpine.DEB.2.21.2105181800170.3032@angie.orcam.me.uk>

Support for magic baud rate divisors of 32770 and 32769 used with SMSC 
Super I/O chips for extra baud rates of 230400 and 460800 respectively 
where base rate is 115200[1] has been added around Linux 2.5.64, which 
predates our repo history, but the origin could be identified as commit 
2a717aad772f ("Merge with Linux 2.5.64.") with the old MIPS/Linux repo 
also at: <git://git.kernel.org/pub/scm/linux/kernel/git/ralf/linux.git>.

Code that is now in `serial8250_do_get_divisor' was added back then to 
`serial8250_get_divisor', but that code would only ever trigger if one 
of the higher baud rates was actually requested, and that cannot ever 
happen, because the earlier call to `serial8250_get_baud_rate' never 
returns them.  This is because it calls `uart_get_baud_rate' with the 
maximum requested being the base rate, that is clk/16 or 115200 for SMSC 
chips at their nominal clock rate.

Fix it then and allow UPF_MAGIC_MULTIPLIER baud rates to be selected, by 
requesting the maximum baud rate of clk/4 rather than clk/16 if the flag 
has been set.  Also correct the minimum baud rate, observing that these 
ports only support actual (non-magic) divisors of up to 32767 only.

References:

[1] "FDC37M81x, PC98/99 Compliant Enhanced Super I/O Controller with 
    Keyboard/Mouse Wake-Up", Standard Microsystems Corporation, Rev. 
    03/27/2000, Table 31 - "Baud Rates", p. 77

Signed-off-by: Maciej W. Rozycki <macro@orcam.me.uk>
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/tty/serial/8250/8250_port.c |   19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

linux-serial-8250-magic-multiplier-baud-rate.diff
Index: linux-malta-cbus-uart/drivers/tty/serial/8250/8250_port.c
===================================================================
--- linux-malta-cbus-uart.orig/drivers/tty/serial/8250/8250_port.c
+++ linux-malta-cbus-uart/drivers/tty/serial/8250/8250_port.c
@@ -2659,6 +2659,21 @@ static unsigned int serial8250_get_baud_
 					     struct ktermios *old)
 {
 	unsigned int tolerance = port->uartclk / 100;
+	unsigned int min;
+	unsigned int max;
+
+	/*
+	 * Handle magic divisors for baud rates above baud_base on SMSC
+	 * Super I/O chips.  Enable custom rates of clk/4 and clk/8, but
+	 * disable divisor values beyond 32767, which are unavailable.
+	 */
+	if (port->flags & UPF_MAGIC_MULTIPLIER) {
+		min = port->uartclk / 16 / UART_DIV_MAX >> 1;
+		max = (port->uartclk + tolerance) / 4;
+	} else {
+		min = port->uartclk / 16 / UART_DIV_MAX;
+		max = (port->uartclk + tolerance) / 16;
+	}
 
 	/*
 	 * Ask the core to calculate the divisor for us.
@@ -2666,9 +2681,7 @@ static unsigned int serial8250_get_baud_
 	 * slower than nominal still match standard baud rates without
 	 * causing transmission errors.
 	 */
-	return uart_get_baud_rate(port, termios, old,
-				  port->uartclk / 16 / UART_DIV_MAX,
-				  (port->uartclk + tolerance) / 16);
+	return uart_get_baud_rate(port, termios, old, min, max);
 }
 
 /*

  parent reply	other threads:[~2021-06-10 18:38 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10 18:38 [PATCH 0/5] serial, Malta: Fixes to magic multipliers for SMSC Super I/O UARTs Maciej W. Rozycki
2021-06-10 18:38 ` [PATCH 1/5] serial: 8250: Document SMSC Super I/O UART peculiarities Maciej W. Rozycki
2021-06-10 18:38 ` Maciej W. Rozycki [this message]
2021-06-10 18:38 ` [PATCH 3/5] serial: 8250: Handle custom baud rates in UPF_MAGIC_MULTIPLIER range Maciej W. Rozycki
2021-06-10 18:38 ` [PATCH 4/5] serial: core, 8250: Add a hook for extra port property reporting Maciej W. Rozycki
2021-06-15 13:19   ` Greg Kroah-Hartman
2021-06-26  4:12     ` Maciej W. Rozycki
2021-06-10 18:38 ` [PATCH 5/5] MIPS: Malta: Enable magic multipliers for Super I/O UARTs Maciej W. Rozycki

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=alpine.DEB.2.21.2105190412280.29169@angie.orcam.me.uk \
    --to=macro@orcam.me.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /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.