From: Peter Hurley <peter-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
To: Maxime Coquelin
<mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: "Andy Shevchenko"
<andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
"Uwe Kleine-König"
<u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
"Andreas Färber" <afaerber-l3A5Bk7waGM@public.gmane.org>,
"Geert Uytterhoeven"
<geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org>,
"Rob Herring" <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
"Philipp Zabel" <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
"Linus Walleij"
<linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
"Arnd Bergmann" <arnd-r2nGTMty4D4@public.gmane.org>,
"Stefan Agner" <stefan-XLVq0VzYD2Y@public.gmane.org>,
"Peter Meerwald" <pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
"Paul Bolle" <pebolle-IWqWACnzNjzz+pZb47iToQ@public.gmane.org>,
"Jonathan Corbet" <corbet-T1hC0tSOHrs@public.gmane.org>,
"Pawel Moll" <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
"Mark Rutland" <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
"Ian Campbell"
<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
"Kumar Gala" <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
"Russell King" <linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org>,
"Daniel Lezcano"
<daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>,
"Thomas Gleixner" <tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org>,
"Greg Kroah-Hartman"
<gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org>,
"Jiri Slaby" <jslaby-AlSwsSmVLrQ@public.gmane.org>
Subject: Re: [PATCH v3 10/15] serial: stm32-usart: Add STM32 USART Driver
Date: Tue, 24 Mar 2015 13:44:53 -0400 [thread overview]
Message-ID: <5511A295.1060103@hurleysoftware.com> (raw)
In-Reply-To: <CALszF6Dg7t9+F9NG+xREPQeaAj7T6D1GuGabkr8EvOAAdtg7yA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Hi Maxime,
On 03/24/2015 01:21 PM, Maxime Coquelin wrote:
> Hi Peter,
>
> 2015-03-19 18:35 GMT+01:00 Maxime Coquelin <mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
>> 2015-03-19 15:58 GMT+01:00 Peter Hurley <peter-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>:
>>> On 03/19/2015 09:55 AM, Maxime Coquelin wrote:
>>>>>>>> +static void stm32_set_termios(struct uart_port *port, struct ktermios *termios,
>>>>>>>> + struct ktermios *old)
>>> [...]
>>>>>>>> + usardiv = (port->uartclk * 25) / (baud * 4);
>>>>>>>> + mantissa = (usardiv / 100) << USART_BRR_DIV_M_SHIFT;
>>>>>>>> + fraction = DIV_ROUND_CLOSEST((usardiv % 100) * 16, 100);
>>>>>>>> + if (fraction & ~USART_BRR_DIV_F_MASK) {
>>>>>>>> + fraction = 0;
>>>>>>>> + mantissa += (1 << USART_BRR_DIV_M_SHIFT);
>>>>>>>> + }
>>> [...]
>>>> Really, I would prefer keeping this fractional divider as it is
>>>> implemented today.
>>>
>>> You have to admit that's basically an unintelligible mess;
>>> how would anyone ever be able to refactor and replace that with a
>>> common divider implementation?
>>>
>>> At the very least, please comment on the formula and format.
>>
>> Ok, I will refactor the implementation, and comment it.
>
> The implementation was indeed a mess.
> I found some time to refactor the code, and also added support for 8
> times oversampling (16 by default).
> It will allow to achieve higher speeds, with the side effect of being
> less tolerant to clock deviations.
>
> What do you think about the code below?
>
>
> usartdiv = DIV_ROUND_CLOSEST(port->uartclk, baud);
>
> /*
> * The USART supports 16 or 8 times oversampling.
> * By default we prefer 16 times oversampling, so that the receiver
> * has a better tolerance to clock deviations.
> * 8 times oversampling is only used to achieve higher speeds.
> */
> if (usartdiv < 16) {
> oversampling = 8;
> stm32_set_bits(port, USART_CR1, USART_CR1_OVER8);
> } else {
> oversampling = 16;
> stm32_clr_bits(port, USART_CR1, USART_CR1_OVER8);
> }
>
> mantissa = (usartdiv / oversampling) << USART_BRR_DIV_M_SHIFT;
> fraction = usartdiv % oversampling;
> writel_relaxed(mantissa | fraction, port->membase + USART_BRR)
Thanks! Way better :)
Much more obvious this is a fixed-point divisor.
Regards,
Peter Hurley
next prev parent reply other threads:[~2015-03-24 17:44 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-12 21:55 [PATCH v3 00/15] Add support to STMicroelectronics STM32 family Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 02/15] ARM: ARMv7-M: Enlarge vector table up to 256 entries Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 03/15] dt-bindings: Document the ARM System timer bindings Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 04/15] clocksource: Add ARM System timer driver Maxime Coquelin
2015-03-26 9:50 ` Daniel Lezcano
2015-03-26 20:19 ` Maxime Coquelin
2015-03-27 8:36 ` Daniel Lezcano
2015-03-27 12:33 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 05/15] dt-bindings: Document the STM32 reset bindings Maxime Coquelin
2015-03-13 0:09 ` Chanwoo Choi
2015-03-17 16:57 ` Maxime Coquelin
2015-03-13 8:50 ` Philipp Zabel
[not found] ` <1426236654.3083.19.camel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2015-03-17 17:13 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 06/15] drivers: reset: Add STM32 reset driver Maxime Coquelin
2015-03-13 0:11 ` Chanwoo Choi
2015-03-13 8:54 ` Philipp Zabel
2015-03-17 17:23 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 07/15] dt-bindings: Document the STM32 timer bindings Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 08/15] clockevent: Add STM32 Timer driver Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 09/15] dt-bindings: Document the STM32 USART bindings Maxime Coquelin
[not found] ` <1426197361-19290-1-git-send-email-maxime.coquelin-qxv4g6HH51o@public.gmane.org>
2015-03-12 21:55 ` [PATCH v3 01/15] scripts: link-vmlinux: Don't pass page offset to kallsyms if XIP Kernel Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 10/15] serial: stm32-usart: Add STM32 USART Driver Maxime Coquelin
2015-03-13 9:41 ` Paul Bolle
2015-03-17 17:39 ` Maxime Coquelin
2015-03-13 14:19 ` Andy Shevchenko
2015-03-17 17:32 ` Maxime Coquelin
[not found] ` <CALszF6BWuUYRh+3rWnSQLApkAHA5dQXw=6x6D_evRtb+5B_ukA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-17 17:56 ` Andy Shevchenko
2015-03-19 13:55 ` Maxime Coquelin
[not found] ` <CALszF6A5Zu7i0hxSLTS-nfOAXmd0__jLjB=fHxK93Ex5Vbi9LA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-19 14:58 ` Peter Hurley
[not found] ` <550AE41C.8070803-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-03-19 17:35 ` Maxime Coquelin
2015-03-24 17:21 ` Maxime Coquelin
[not found] ` <CALszF6Dg7t9+F9NG+xREPQeaAj7T6D1GuGabkr8EvOAAdtg7yA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-03-24 17:44 ` Peter Hurley [this message]
[not found] ` <1426197361-19290-11-git-send-email-maxime.coquelin-qxv4g6HH51o@public.gmane.org>
2015-03-24 18:23 ` Peter Hurley
[not found] ` <5511ABAA.2010303-WaGBZJeGNqdsbIuE7sb01tBPR1lH4CV8@public.gmane.org>
2015-03-26 15:46 ` Russell King - ARM Linux
2015-03-26 22:05 ` Maxime Coquelin
2015-03-26 22:03 ` Maxime Coquelin
2015-03-27 11:32 ` Peter Hurley
2015-03-27 12:30 ` Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 11/15] ARM: Add STM32 family machine Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 12/15] ARM: dts: Add ARM System timer as clockevent in armv7m Maxime Coquelin
2015-03-12 21:55 ` [PATCH v3 13/15] ARM: dts: Introduce STM32F429 MCU Maxime Coquelin
2015-03-12 21:56 ` [PATCH v3 14/15] ARM: configs: Add STM32 defconfig Maxime Coquelin
2015-03-12 21:56 ` [PATCH v3 15/15] MAINTAINERS: Add entry for STM32 MCUs Maxime Coquelin
2015-03-12 23:45 ` [PATCH v3 00/15] Add support to STMicroelectronics STM32 family Chanwoo Choi
2015-03-18 23:35 ` Chanwoo Choi
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=5511A295.1060103@hurleysoftware.com \
--to=peter-wagbzjegnqdsbiue7sb01tbpr1lh4cv8@public.gmane.org \
--cc=afaerber-l3A5Bk7waGM@public.gmane.org \
--cc=andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=arnd-r2nGTMty4D4@public.gmane.org \
--cc=corbet-T1hC0tSOHrs@public.gmane.org \
--cc=daniel.lezcano-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
--cc=gregkh-hQyY1W1yCW8ekmWlsbkhG0B+6BGkLq7r@public.gmane.org \
--cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
--cc=jslaby-AlSwsSmVLrQ@public.gmane.org \
--cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
--cc=linux-lFZ/pmaqli7XmaaqVzeoHQ@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
--cc=pebolle-IWqWACnzNjzz+pZb47iToQ@public.gmane.org \
--cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=stefan-XLVq0VzYD2Y@public.gmane.org \
--cc=tglx-hfZtesqFncYOwBW4kG4KsQ@public.gmane.org \
--cc=u.kleine-koenig-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.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).