All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jay Dolan <jay.dolan@accesio.com>
To: linux-serial@vger.kernel.org
Cc: Jay Dolan <jay.dolan@accesio.com>
Subject: [PATCH 1/3] serial: 8250_pci: rewrite pericom_do_set_divisor
Date: Sun, 14 Nov 2021 10:39:06 -0800	[thread overview]
Message-ID: <20211114183908.444923-2-jay.dolan@accesio.com> (raw)
In-Reply-To: <20211114183908.444923-1-jay.dolan@accesio.com>

Fixes: 6bf4e42f1d19de10800f4483b4bb7945aab283cb

Have pericom_do_set_divisor() use the uartclk instead of a hardcoded
value to work with different speed crystals. Tested with 14.7456 and 24
MHz crystals
Have pericom_do_set_divisor always calculate the divisor rather than
call serial8250_do_set_divisor() for rates below baud_base.
Do not write registers or call serial8250_do_set_divisor() if valid
divisors could not be found.

Signed-off-by: Jay Dolan <jay.dolan@accesio.com>
---
 drivers/tty/serial/8250/8250_pci.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 5d43de143f33..aea43683b76d 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1325,28 +1325,32 @@ pericom_do_set_divisor(struct uart_port *port, unsigned int baud,
 	int scr;
 	int lcr;
 	int actual_baud;
-	int tolerance;
+	int divisor;
 
-	for (scr = 5 ; scr <= 15 ; scr++) {
-		actual_baud = 921600 * 16 / scr;
-		tolerance = actual_baud / 50;
+	for (scr = 16 ; scr > 4 ; scr--) {
+		if (baud > (port->uartclk / scr) + (baud/50))
+			continue;
 
-		if ((baud < actual_baud + tolerance) &&
-			(baud > actual_baud - tolerance)) {
+		divisor = port->uartclk / scr / baud;
+		if (divisor == 0 ||
+			port->uartclk / scr / divisor - baud > baud/50) {
+			divisor++;
+		}
+
+		if (divisor > 0xffff)
+			continue;
 
+		actual_baud = port->uartclk / scr / divisor;
+		if (abs(actual_baud - baud) < baud/50) {
 			lcr = serial_port_in(port, UART_LCR);
 			serial_port_out(port, UART_LCR, lcr | 0x80);
-
-			serial_port_out(port, UART_DLL, 1);
-			serial_port_out(port, UART_DLM, 0);
+			serial_port_out(port, UART_DLL, divisor & 0xff);
+			serial_port_out(port, UART_DLM, divisor >> 8 & 0xff);
 			serial_port_out(port, 2, 16 - scr);
 			serial_port_out(port, UART_LCR, lcr);
 			return;
-		} else if (baud > actual_baud) {
-			break;
 		}
 	}
-	serial8250_do_set_divisor(port, baud, quot, quot_frac);
 }
 static int pci_pericom_setup(struct serial_private *priv,
 		  const struct pciserial_board *board,
-- 
2.25.1


  reply	other threads:[~2021-11-14 18:39 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-14 18:39 [PATCH 0/3] serial: 8250_pci patches to address issues with pericom_do_set_divisor() Jay Dolan
2021-11-14 18:39 ` Jay Dolan [this message]
2021-11-25 17:30   ` [PATCH 1/3] serial: 8250_pci: rewrite pericom_do_set_divisor Greg KH
2021-11-14 18:39 ` [PATCH 2/3] serial: 8250_pci: Re-enable higher baud rates on Pericom chips Jay Dolan
2021-11-16 15:31   ` Andy Shevchenko
2021-11-14 18:39 ` [PATCH 3/3] serial: 8250_pci: Fix ACCES entries in pci_serial_quirks array Jay Dolan
2021-11-16 15:31   ` Andy Shevchenko
2021-11-16 15:34 ` [PATCH 0/3] serial: 8250_pci patches to address issues with pericom_do_set_divisor() Andy Shevchenko
2021-11-17  3:52   ` Jay Dolan
2021-11-17 13:24     ` 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=20211114183908.444923-2-jay.dolan@accesio.com \
    --to=jay.dolan@accesio.com \
    --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.