From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Jisheng Zhang <Jisheng.Zhang@synaptics.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jslaby@suse.com>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH v4 3/3] serial: 8250_dw: add fractional divisor support
Date: Tue, 10 Jul 2018 19:19:21 +0300 [thread overview]
Message-ID: <8c5b6bbbde12b0836e1f833c86b805a817596654.camel@linux.intel.com> (raw)
In-Reply-To: <20180710111516.13b8c570@xhacker.debian>
On Tue, 2018-07-10 at 11:15 +0800, Jisheng Zhang wrote:
> For Synopsys DesignWare 8250 uart which version >= 4.00a, there's a
> valid divisor latch fraction register. The fractional divisor width is
> 4bits ~ 6bits.
>
> Now the preparation is done, it's easy to add the feature support.
> This patch firstly tries to get the fractional divisor width during
> probe, then setups dw specific get_divisor() and set_divisor() hook.
Thanks for an update, my comments below.
> +/*
> + * divisor = div(I) + div(F)
> + * "I" means integer, "F" means fractional
> + * quot = div(I) = clk / (16 * baud)
> + * frac = div(F) * 2^dlf_size
> + *
> + * let rem = clk % (16 * baud)
> + * we have: div(F) * (16 * baud) = rem
> + * so frac = 2^dlf_size * rem / (16 * baud) = (rem << dlf_size) / (16
> * baud)
> + */
> +static unsigned int dw8250_get_divisor(struct uart_port *p,
> + unsigned int baud,
> + unsigned int *frac)
> +{
unsigned int base_baud = baud * 16;
> + unsigned int quot, rem;
> + struct dw8250_data *d = p->private_data;
> +
> + quot = p->uartclk / (16 * baud);
> + rem = p->uartclk % (16 * baud);
> + *frac = DIV_ROUND_CLOSEST(rem << d->dlf_size, 16 * baud);
> +
While it looks indeed better, I would rather like to have a confirmation
it's working as designed.
For example, when I did some calculus, I cooked a preliminary check in
Python (easy and fast to prototype), for example:
https://gist.github.com/andy-shev/06b084488b3629898121 in Python, or
commit 9df461eca18f ("spi: pxa2xx: replace ugly table by approximation")
in the kernel.
Or another one here https://gist.github.com/andy-shev/8b2a73aeca2874f4cc
89 and commits c1a67b48f6a5 ("serial: 8250_pci: replace switch-case by
formula for Intel MID"), 21947ba654a6 ("serial: 8250_pci: replace
switch-case by formula")
P.S. The code itself looks good to me, thanks!
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2018-07-10 16:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-10 3:09 [PATCH v4 0/3] serial: 8250_dw: add fractional divisor support Jisheng Zhang
2018-07-10 3:12 ` [PATCH v4 1/3] serial: 8250: introduce get_divisor() and set_divisor() hook Jisheng Zhang
2018-07-10 3:13 ` [PATCH v4 2/3] serial: 8250: export serial8250_do_set_divisor() Jisheng Zhang
2018-07-10 13:56 ` Andy Shevchenko
2018-07-10 3:15 ` [PATCH v4 3/3] serial: 8250_dw: add fractional divisor support Jisheng Zhang
2018-07-10 16:19 ` Andy Shevchenko [this message]
2018-07-11 6:41 ` Jisheng Zhang
2018-07-11 14:23 ` Andy Shevchenko
2018-07-11 7:11 ` [PATCH v5 " Jisheng Zhang
2018-07-11 11:31 ` 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=8c5b6bbbde12b0836e1f833c86b805a817596654.camel@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=Jisheng.Zhang@synaptics.com \
--cc=gregkh@linuxfoundation.org \
--cc=jslaby@suse.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--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 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).