From: Johan Hovold <johan@kernel.org>
To: "Marek Behún" <kabel@kernel.org>
Cc: linux-usb@vger.kernel.org, "Pali Rohár" <pali@kernel.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v2 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baud rate
Date: Sun, 24 Jul 2022 14:41:19 +0200 [thread overview]
Message-ID: <Yt097+xTMPrMpfvX@hovoldconsulting.com> (raw)
In-Reply-To: <20220712115306.26471-8-kabel@kernel.org>
On Tue, Jul 12, 2022 at 01:53:06PM +0200, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
>
> Calculate baud rate value in c_*speed fields to the real values which were
> set on hardware. For this operation, add a new set of methods
> *_divisor_to_baud() for each chip and use them for calculating the real
> baud rate values.
>
> Each *_divisor_to_baud() method is constructed as an inverse function of
> its corresponding *_baud_to_divisor() method.
>
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Tested-by: Marek Behún <kabel@kernel.org>
> Signed-off-by: Marek Behún <kabel@kernel.org>
> ---
> drivers/usb/serial/ftdi_sio.c | 83 +++++++++++++++++++++++++++++++++++
> 1 file changed, 83 insertions(+)
>
> diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
> index 39e8c5d06157..838acce53e69 100644
> --- a/drivers/usb/serial/ftdi_sio.c
> +++ b/drivers/usb/serial/ftdi_sio.c
> @@ -1167,6 +1167,23 @@ static int ftdi_sio_baud_to_divisor(int baud)
> }
> }
>
> +static int ftdi_sdio_divisor_to_baud(u32 divisor)
> +{
> + switch (divisor) {
> + case ftdi_sio_b300: return 300;
> + case ftdi_sio_b600: return 600;
> + case ftdi_sio_b1200: return 1200;
> + case ftdi_sio_b2400: return 2400;
> + case ftdi_sio_b4800: return 4800;
> + case ftdi_sio_b9600: return 9600;
> + case ftdi_sio_b19200: return 19200;
> + case ftdi_sio_b38400: return 38400;
> + case ftdi_sio_b57600: return 57600;
> + case ftdi_sio_b115200: return 115200;
> + default: return 9600;
> + }
> +}
This one should not be needed as sio only supports this discrete set of
values in the first place.
> static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
> {
> unsigned short int divisor;
> @@ -1189,15 +1206,33 @@ static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
> return divisor;
> }
>
> +static int ftdi_232am_divisor_base_to_baud(unsigned short int divisor, int base)
I believe "base" was used as a function name suffix in the inverse
function (due to the additional base argument).
> +{
> + static const unsigned char divfrac_inv[4] = { 0, 4, 2, 1 };
> + unsigned int divisor3;
> +
> + if (divisor == 0)
> + divisor = 1;
> + divisor3 = (GENMASK(13, 0) & divisor) << 3;
> + divisor3 |= divfrac_inv[(divisor >> 14) & 0x3];
> + return DIV_ROUND_CLOSEST(base, 2 * divisor3);
> +}
I don't have the motivation to try to review these inverses right now.
Let's get the rest of the series in order first.
Johan
next prev parent reply other threads:[~2022-07-24 12:41 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 11:52 [PATCH v2 0/7] ftdi_sio driver improvements Marek Behún
2022-07-12 11:53 ` [PATCH v2 1/7] USB: serial: ftdi_sio: Fix divisor overflow Marek Behún
2022-07-24 12:02 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 2/7] USB: serial: ftdi_sio: Add missing baud rate validation Marek Behún
2022-07-12 17:27 ` Rob Pearce
2022-07-12 22:24 ` Marek Behún
2022-07-12 11:53 ` [PATCH v2 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function Marek Behún
2022-07-24 12:06 ` Johan Hovold
2022-08-18 14:11 ` Pali Rohár
2022-09-13 14:49 ` Johan Hovold
2022-09-13 15:30 ` Pali Rohár
2022-09-13 15:44 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 4/7] USB: serial: ftdi_sio: Do not reset baud rate to 9600 Baud on error Marek Behún
2022-07-24 12:20 ` Johan Hovold
2022-08-18 14:12 ` Pali Rohár
2022-09-13 14:54 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 5/7] USB: serial: ftdi_sio: Fix baud rate rounding for ASYNC_SPD_CUST Marek Behún
2022-07-24 12:26 ` Johan Hovold
2022-07-12 11:53 ` [PATCH v2 6/7] USB: serial: ftdi_sio: Fix custom_divisor and c_*speed " Marek Behún
2022-07-24 12:28 ` Johan Hovold
2022-07-24 12:33 ` Pali Rohár
2022-07-24 12:54 ` Johan Hovold
2022-07-24 12:59 ` Pali Rohár
2022-07-24 13:08 ` Johan Hovold
2022-08-18 14:09 ` Pali Rohár
2022-09-13 14:59 ` Johan Hovold
2022-09-14 8:48 ` Pali Rohár
2022-09-14 8:58 ` Johan Hovold
2022-09-14 9:10 ` Pali Rohár
2022-09-14 9:18 ` Johan Hovold
2022-09-14 9:20 ` Pali Rohár
2022-07-12 11:53 ` [PATCH v2 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baud rate Marek Behún
2022-07-24 12:41 ` Johan Hovold [this message]
2022-08-18 14:17 ` Pali Rohár
2022-09-13 15:02 ` Johan Hovold
2022-09-13 15:24 ` Pali Rohár
2022-09-13 15:34 ` Johan Hovold
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=Yt097+xTMPrMpfvX@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=kabel@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=pali@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).