From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Jiri Slaby (SUSE)" <jirislaby@kernel.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org
Cc: Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Kevin Hilman <khilman@baylibre.com>,
Tony Lindgren <tony@atomide.com>
Subject: [PATCH v1 2/2] serial: 8250_pci: Remove custom deprecated baud setting routine
Date: Thu, 22 Jan 2026 11:19:48 +0100 [thread overview]
Message-ID: <20260122102349.2395423-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20260122102349.2395423-1-andriy.shevchenko@linux.intel.com>
As comments mentioned this is old (and actually deprecated) interface
to set custom baud rates. This interface has limitations as it only
allows to set a single opaque value called "custom_divisor". If the HW
needs more complex settings (like fractional divisor) it must somehow
encode this. This is horrid interface that is very driver specific
and not flexible. Meanwhile Linux has established way to set free
baud rate settings via BOTHER [1]. With all this being said, remove
deprecated interface for good.
Link: https://stackoverflow.com/questions/12646324/how-can-i-set-a-custom-baud-rate-on-linux [1]
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
Documentation/misc-devices/oxsemi-tornado.rst | 26 +-----
drivers/tty/serial/8250/8250_pci.c | 85 ++++++++-----------
2 files changed, 38 insertions(+), 73 deletions(-)
diff --git a/Documentation/misc-devices/oxsemi-tornado.rst b/Documentation/misc-devices/oxsemi-tornado.rst
index b33351bef6cf..fe2e5f726c2b 100644
--- a/Documentation/misc-devices/oxsemi-tornado.rst
+++ b/Documentation/misc-devices/oxsemi-tornado.rst
@@ -89,31 +89,7 @@ With the baud base set to 15625000 and the unsigned 16-bit UART_DIV_MAX
limitation imposed by ``serial8250_get_baud_rate`` standard baud rates
below 300bps become unavailable in the regular way, e.g. the rate of
200bps requires the baud base to be divided by 78125 and that is beyond
-the unsigned 16-bit range. The historic spd_cust feature can still be
-used by encoding the values for, the prescaler, the oversampling rate
-and the clock divisor (DLM/DLL) as follows to obtain such rates if so
-required:
-
-::
-
- 31 29 28 20 19 16 15 0
- +-----+-----------------+-------+-------------------------------+
- |0 0 0| CPR2:CPR | TCR | DLM:DLL |
- +-----+-----------------+-------+-------------------------------+
-
-Use a value such encoded for the ``custom_divisor`` field along with the
-ASYNC_SPD_CUST flag set in the ``flags`` field in ``struct serial_struct``
-passed with the TIOCSSERIAL ioctl(2), such as with the setserial(8)
-utility and its ``divisor`` and ``spd_cust`` parameters, and then select
-the baud rate of 38400bps. Note that the value of 0 in TCR sets the
-oversampling rate to 16 and prescaler values below 1 in CPR2/CPR are
-clamped by the driver to 1.
-
-For example the value of 0x1f4004e2 will set CPR2/CPR, TCR and DLM/DLL
-respectively to 0x1f4, 0x0 and 0x04e2, choosing the prescaler value,
-the oversampling rate and the clock divisor of 62.500, 16 and 1250
-respectively. These parameters will set the baud rate for the serial
-port to 62500000 / 62.500 / 1250 / 16 = 50bps.
+the unsigned 16-bit range.
Maciej W. Rozycki <macro@orcam.me.uk>
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 3efe075ef7b2..6589bb531cc6 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1205,60 +1205,49 @@ static unsigned int pci_oxsemi_tornado_get_divisor(struct uart_port *port,
u8 tcr;
int i;
- /* Old custom speed handling. */
- if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST) {
- unsigned int cust_div = port->custom_divisor;
+ best_squot = quot_scale;
+ for (i = 0; i < ARRAY_SIZE(p); i++) {
+ unsigned int spre;
+ unsigned int srem;
+ u8 cp;
+ u8 tc;
- quot = cust_div & UART_DIV_MAX;
- tcr = (cust_div >> 16) & OXSEMI_TORNADO_TCR_MASK;
- cpr = (cust_div >> 20) & OXSEMI_TORNADO_CPR_MASK;
- if (cpr < OXSEMI_TORNADO_CPR_MIN)
- cpr = OXSEMI_TORNADO_CPR_DEF;
- } else {
- best_squot = quot_scale;
- for (i = 0; i < ARRAY_SIZE(p); i++) {
- unsigned int spre;
- unsigned int srem;
- u8 cp;
- u8 tc;
+ tc = p[i][0];
+ cp = p[i][1];
+ spre = tc * cp;
- tc = p[i][0];
- cp = p[i][1];
- spre = tc * cp;
+ srem = sdiv % spre;
+ if (srem > spre / 2)
+ srem = spre - srem;
+ squot = DIV_ROUND_CLOSEST(srem * quot_scale, spre);
- srem = sdiv % spre;
- if (srem > spre / 2)
- srem = spre - srem;
- squot = DIV_ROUND_CLOSEST(srem * quot_scale, spre);
-
- if (srem == 0) {
- tcr = tc;
- cpr = cp;
- quot = sdiv / spre;
- break;
- } else if (squot < best_squot) {
- best_squot = squot;
- tcr = tc;
- cpr = cp;
- quot = DIV_ROUND_CLOSEST(sdiv, spre);
- }
+ if (srem == 0) {
+ tcr = tc;
+ cpr = cp;
+ quot = sdiv / spre;
+ break;
+ } else if (squot < best_squot) {
+ best_squot = squot;
+ tcr = tc;
+ cpr = cp;
+ quot = DIV_ROUND_CLOSEST(sdiv, spre);
}
- while (tcr <= (OXSEMI_TORNADO_TCR_MASK + 1) >> 1 &&
- quot % 2 == 0) {
+ }
+ while (tcr <= (OXSEMI_TORNADO_TCR_MASK + 1) >> 1 &&
+ quot % 2 == 0) {
+ quot >>= 1;
+ tcr <<= 1;
+ }
+ while (quot > UART_DIV_MAX) {
+ if (tcr <= (OXSEMI_TORNADO_TCR_MASK + 1) >> 1) {
quot >>= 1;
tcr <<= 1;
- }
- while (quot > UART_DIV_MAX) {
- if (tcr <= (OXSEMI_TORNADO_TCR_MASK + 1) >> 1) {
- quot >>= 1;
- tcr <<= 1;
- } else if (cpr <= OXSEMI_TORNADO_CPR_MASK >> 1) {
- quot >>= 1;
- cpr <<= 1;
- } else {
- quot = quot * cpr / OXSEMI_TORNADO_CPR_MASK;
- cpr = OXSEMI_TORNADO_CPR_MASK;
- }
+ } else if (cpr <= OXSEMI_TORNADO_CPR_MASK >> 1) {
+ quot >>= 1;
+ cpr <<= 1;
+ } else {
+ quot = quot * cpr / OXSEMI_TORNADO_CPR_MASK;
+ cpr = OXSEMI_TORNADO_CPR_MASK;
}
}
--
2.50.1
prev parent reply other threads:[~2026-01-22 10:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 10:19 [PATCH v1 0/2] serial: 8250: Remove highly customised deprecated interface Andy Shevchenko
2026-01-22 10:19 ` [PATCH v1 1/2] serial: 8250_omap: Remove custom deprecated baud setting routine Andy Shevchenko
2026-01-22 10:19 ` Andy Shevchenko [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=20260122102349.2395423-3-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=khilman@baylibre.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=tony@atomide.com \
/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