linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: "Marek Behún" <kabel@kernel.org>
Cc: linux-serial@vger.kernel.org, "Pali Rohár" <pali@kernel.org>
Subject: Re: [PATCH 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baudrate
Date: Thu, 7 Jul 2022 17:11:56 +0200	[thread overview]
Message-ID: <Ysb3vBoSp2hIY2f8@kroah.com> (raw)
In-Reply-To: <20220707145354.29705-8-kabel@kernel.org>

On Thu, Jul 07, 2022 at 04:53:54PM +0200, Marek Behún wrote:
> From: Pali Rohár <pali@kernel.org>
> 
> Calculate baudrate value in c_*speed fields to the real value which was set
> to hardware. For this operation add a new set of functions divisor_to_baud
> for each chip and use it for calculating the real baudrate value.
> 
> Each divisor_to_baud function is constructed as an inverse function of
> corresponding baud_to_divisor function.
> 
> Signed-off-by: Pali Rohár <pali@kernel.org>
> Tested-by: Marek Behún <kabel@kernel.org>
> ---
>  drivers/usb/serial/ftdi_sio.c | 79 +++++++++++++++++++++++++++++++++++
>  1 file changed, 79 insertions(+)
> 
> diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
> index 3bf5750e76de..1f78ae695a1b 100644
> --- a/drivers/usb/serial/ftdi_sio.c
> +++ b/drivers/usb/serial/ftdi_sio.c
> @@ -1167,6 +1167,23 @@ static u32 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;
> +	}
> +}
> +
>  static unsigned short int ftdi_232am_baud_base_to_divisor(int baud, int base)
>  {
>  	unsigned short int divisor;
> @@ -1189,11 +1206,27 @@ 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)
> +{
> +	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);
> +}
> +
>  static unsigned short int ftdi_232am_baud_to_divisor(int baud)
>  {
>  	 return ftdi_232am_baud_base_to_divisor(baud, 48000000);
>  }
>  
> +static int ftdi_232am_divisor_to_baud(unsigned short int divisor)
> +{
> +	return ftdi_232am_divisor_base_to_baud(divisor, 48000000);
> +}
> +
>  static u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
>  {
>  	static const unsigned char divfrac[8] = { 0, 3, 2, 4, 1, 5, 6, 7 };
> @@ -1212,11 +1245,30 @@ static u32 ftdi_232bm_baud_base_to_divisor(int baud, int base)
>  	return divisor;
>  }
>  
> +static int ftdi_232bm_divisor_base_to_baud(u32 divisor, int base)
> +{
> +	static const unsigned char divfrac_inv[8] = { 0, 4, 2, 1, 3, 5, 6, 7 };
> +	u32 divisor3;
> +	/* Deal with special cases for highest baud rates. */
> +	if (divisor == 0)
> +		divisor = 1;		/* 1.0 */
> +	else if (divisor == 1)
> +		divisor = 0x4001;	/* 1.5 */
> +	divisor3 = (GENMASK(13, 0) & divisor) << 3;
> +	divisor3 |= divfrac_inv[(divisor >> 14) & 0x7];
> +	return DIV_ROUND_CLOSEST(base, 2 * divisor3);
> +}

Always run your patches through checkpatch so you do not get grumpy
maintainers telling you to run your patches through checkpatch...

thanks,

greg k-h

  reply	other threads:[~2022-07-07 15:12 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07 14:53 [PATCH 0/7] ftdi_sio driver improvements Marek Behún
2022-07-07 14:53 ` [PATCH 1/7] USB: serial: ftdi_sio: Fix divisor overflow Marek Behún
2022-07-07 15:07   ` Greg Kroah-Hartman
2022-07-07 15:37     ` Marek Behún
2022-07-07 15:50       ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 2/7] USB: serial: ftdi_sio: Add missing baudrate validation Marek Behún
2022-07-07 15:08   ` Greg Kroah-Hartman
2022-07-07 16:22     ` Marek Behún
2022-07-07 16:50       ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 3/7] USB: serial: ftdi_sio: Extract SIO divisor code to function Marek Behún
2022-07-07 15:06   ` Greg Kroah-Hartman
2022-07-07 15:41     ` Marek Behún
2022-07-07 15:09   ` Greg Kroah-Hartman
2022-07-07 15:50     ` Marek Behún
2022-07-07 14:53 ` [PATCH 4/7] USB: serial: ftdi_sio: Do not reset baudrate to 9600 on error Marek Behún
2022-07-07 15:10   ` Greg Kroah-Hartman
2022-07-07 15:52     ` Marek Behún
2022-07-07 16:06       ` Greg Kroah-Hartman
2022-07-08 15:51   ` Andy Shevchenko
2022-07-12 11:28     ` m.brock
2022-07-12 12:09       ` Marek Behún
2022-07-12 12:11     ` Marek Behún
2022-07-07 14:53 ` [PATCH 5/7] USB: serial: ftdi_sio: Fix baudrate rounding for ASYNC_SPD_CUST Marek Behún
2022-07-07 15:11   ` Greg Kroah-Hartman
2022-07-07 16:08     ` Marek Behún
2022-07-07 16:12       ` Greg Kroah-Hartman
2022-07-07 14:53 ` [PATCH 6/7] USB: serial: ftdi_sio: Fix custom_divisor and c_*speed " Marek Behún
2022-07-07 14:53 ` [PATCH 7/7] USB: serial: ftdi_sio: Fill c_*speed fields with real baudrate Marek Behún
2022-07-07 15:11   ` Greg Kroah-Hartman [this message]
2022-07-07 15:07 ` [PATCH 0/7] ftdi_sio driver improvements Greg Kroah-Hartman

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=Ysb3vBoSp2hIY2f8@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=kabel@kernel.org \
    --cc=linux-serial@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).