From: Benjamin Larsson <benjamin.larsson@genexis.eu>
To: "Jiri Slaby" <jirislaby@kernel.org>,
"Christian Marangi" <ansuelsmth@gmail.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"John Ogness" <john.ogness@linutronix.de>,
"Marco Felsch" <m.felsch@pengutronix.de>,
"Gerhard Engleder" <eg@keba.com>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Randy Dunlap" <rdunlap@infradead.org>,
"Binbin Zhou" <zhoubinbin@loongson.cn>,
"Rong Zhang" <rongrong@oss.cipunited.com>,
"Lukas Wunner" <lukas@wunner.de>,
"Lubomir Rintel" <lkundrak@v3.sk>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-serial@vger.kernel.org
Subject: Re: [PATCH 4/4] serial: 8250: Add Airoha SoC UART and HSUART support
Date: Tue, 14 Jul 2026 16:55:08 +0200 [thread overview]
Message-ID: <e2d8d438-0710-4796-a5e9-e4c4bc13a9c4@genexis.eu> (raw)
In-Reply-To: <9062ca8c-e29d-4958-a3d3-c86e2a6a9e86@kernel.org>
On 10/07/2026 09:13, Jiri Slaby wrote:
>> +static void airoha_set_termios(struct uart_port *port, struct
>> ktermios *termios,
>> + const struct ktermios *old)
>> +{
>> + const struct airoha_8250_clk_div_info *clk_div_info;
>> + struct uart_8250_port *up = up_to_u8250p(port);
>> + unsigned int xyd_x, nom, denom;
>> + unsigned int baud;
>> + int i;
>> +
>> + serial8250_do_set_termios(port, termios, old);
>> +
>> + baud = serial8250_get_baud_rate(port, termios, old);
>> +
>> + /* Set DLAB to access the baud rate divider registers (BRDH,
>> BRDL) */
>> + serial_port_out(port, UART_LCR, up->lcr | UART_LCR_DLAB);
>> +
>> + /* Set baud rate calculation defaults (BRDIV ([BRDH,BRDL]) to 1) */
>> + serial_port_out(port, UART_AIROHA_BRDL, UART_BRDL_20M);
>> + serial_port_out(port, UART_AIROHA_BRDH, UART_BRDH_20M);
>> +
>> + /*
>> + * Calculate XYD_x and XINCLKDR register by searching
>> + * through a table of crystal_clock divisors.
>> + */
>> + for (i = 0 ; i < ARRAY_SIZE(airoha_clk_div_info) ; i++) {
>> + clk_div_info = &airoha_clk_div_info[i];
>> +
>> + denom = (XINDIV_CLOCK / 40) / clk_div_info->div;
>> + nom = baud * (XYD_Y / 40);
>
> Are these "/ 40" to avoid overflow? Add a comment.
Yes, this is to keep it in 32bits.
>
>> + xyd_x = ((nom / denom) << 4);
>
> * don't you want to round to closest instead of down?
> * I don't understand the purpose of the shift though.
IIRC this is the vendor calculation logic scaled to fit 32bits. With
this rounding/calculation we hit the baud rate exactly for the baud
rates that people actually use.
>
>> + /* For the HSUART xyd_x needs to be scaled by a factor
>> of 2 */
>> + if (port->type == UART_PORT_AIROHA_HS)
>> + xyd_x = xyd_x >> 1;
>
> Do not use shifts for div/mul.
>
>> + if (xyd_x < XYD_Y)
>> + break;
>> + }
>> +
>> + serial_port_out(port, UART_AIROHA_XINCLKDR, clk_div_info->mask);
>> + serial_port_out(port, UART_AIROHA_XYD, (xyd_x << 16) | XYD_Y);
>> +
>> + /* unset DLAB */
>> + serial_port_out(port, UART_LCR, up->lcr);
>> +}
>
> thanks,
> --
> js
> suse labs
MvH
Benjamin Larsson
prev parent reply other threads:[~2026-07-14 14:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 20:56 [PATCH 0/4] serial: 8250: Add AN7581 UART support Christian Marangi
2026-07-09 20:56 ` [PATCH 1/4] dt-bindings: serial: 8250: Add Airoha compatibles Christian Marangi
2026-07-10 16:43 ` Conor Dooley
2026-07-09 20:56 ` [PATCH 2/4] serial: 8250: export serial8250_get_baud_rate() Christian Marangi
2026-07-09 21:35 ` Andy Shevchenko
2026-07-09 21:39 ` Christian Marangi
2026-07-10 8:20 ` Andy Shevchenko
2026-07-10 8:49 ` Christian Marangi
2026-07-10 9:14 ` Andy Shevchenko
2026-07-10 8:19 ` Ilpo Järvinen
2026-07-09 20:56 ` [PATCH 3/4] serial: 8250: map UAPI port type to internal enum Christian Marangi
2026-07-09 21:37 ` Andy Shevchenko
2026-07-09 21:46 ` Christian Marangi
2026-07-10 10:09 ` Andy Shevchenko
2026-07-09 20:56 ` [PATCH 4/4] serial: 8250: Add Airoha SoC UART and HSUART support Christian Marangi
2026-07-10 7:13 ` Jiri Slaby
2026-07-14 14:55 ` Benjamin Larsson [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=e2d8d438-0710-4796-a5e9-e4c4bc13a9c4@genexis.eu \
--to=benjamin.larsson@genexis.eu \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ansuelsmth@gmail.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=eg@keba.com \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jiaxun.yang@flygoat.com \
--cc=jirislaby@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=lkundrak@v3.sk \
--cc=lukas@wunner.de \
--cc=m.felsch@pengutronix.de \
--cc=rdunlap@infradead.org \
--cc=robh@kernel.org \
--cc=rongrong@oss.cipunited.com \
--cc=zhoubinbin@loongson.cn \
/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