[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHp75Vdf6=z1d5+eYJ+QGTko9kkZf-oPfoWaf8FRoTdqcdWxjw@mail.gmail.com>
Date: Tue, 17 Mar 2015 19:56:47 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Maxime Coquelin <mcoquelin.stm32@...il.com>
Cc: Uwe Kleine-König
<u.kleine-koenig@...gutronix.de>,
Andreas Färber <afaerber@...e.de>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Rob Herring <robh+dt@...nel.org>,
Philipp Zabel <p.zabel@...gutronix.de>,
Linus Walleij <linus.walleij@...aro.org>,
Arnd Bergmann <arnd@...db.de>, Stefan Agner <stefan@...er.ch>,
Peter Meerwald <pmeerw@...erw.net>,
Paul Bolle <pebolle@...cali.nl>,
Jonathan Corbet <corbet@....net>,
Pawel Moll <pawel.moll@....com>,
Mark Rutland <mark.rutland@....com>,
Ian Campbell <ijc+devicetree@...lion.org.uk>,
Kumar Gala <galak@...eaurora.org>,
Russell King <linux@....linux.org.uk>,
Daniel Lezcano <daniel.lezcano@...aro.org>,
Thomas Gleixner <tglx@...utronix.de>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jslaby@...e.cz>,
Andrew Morton <akpm@...ux-foundation.org>,
"David S. Miller" <davem@...emloft.net>,
Mauro Carvalho Chehab <mchehab@....samsung.com>,
Joe Perches <joe@...ches.com>, Antti Palosaari <crope@....fi>,
Tejun Heo <tj@...nel.org>, Will Deacon <will.deacon@....com>,
Nikolay Borisov <Nikolay.Borisov@....com>,
Rusty Russell <rusty@...tcorp.com.au>,
Kees Cook <keescook@...omium.org>,
Michal Marek <mmarek@...e.cz>,
Linux Documentation List <linux-doc@...r.kernel.org>,
linux-arm Mailing List <linux-arm-kernel@...ts.infradead.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
devicetree <devicetree@...r.kernel.org>,
"linux-gpio@...r.kernel.org" <linux-gpio@...r.kernel.org>,
"linux-serial@...r.kernel.org" <linux-serial@...r.kernel.org>,
Linux-Arch <linux-arch@...r.kernel.org>,
"linux-api@...r.kernel.org" <linux-api@...r.kernel.org>
Subject: Re: [PATCH v3 10/15] serial: stm32-usart: Add STM32 USART Driver
On Tue, Mar 17, 2015 at 7:32 PM, Maxime Coquelin
<mcoquelin.stm32@...il.com> wrote:
> 2015-03-13 15:19 GMT+01:00 Andy Shevchenko <andy.shevchenko@...il.com>:
>>> +static void stm32_set_termios(struct uart_port *port, struct ktermios *termios,
>>> + struct ktermios *old)
>>> +{
>>> + unsigned int baud;
>>> + u32 usardiv, mantissa, fraction;
>>> + tcflag_t cflag;
>>> + u32 cr1, cr2, cr3;
>>> + unsigned long flags;
>>> +
>>> + baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
>>> + cflag = termios->c_cflag;
>>> +
>>> + spin_lock_irqsave(&port->lock, flags);
>>> +
>>> + /* Stop serial port and reset value */
>>> + writel_relaxed(0, port->membase + USART_CR1);
>>> +
>>> + cr1 = USART_CR1_TE | USART_CR1_RE | USART_CR1_UE | USART_CR1_RXNEIE;
>>> +
>>> + if (cflag & CSTOPB)
>>> + cr2 = USART_CR2_STOP_2B;
>>> +
>>> + if (cflag & PARENB) {
>>> + cr1 |= USART_CR1_PCE;
>>> + if ((cflag & CSIZE) == CS8)
>>> + cr1 |= USART_CR1_M;
>>> + }
>>> +
>>> + if (cflag & PARODD)
>>> + cr1 |= USART_CR1_PS;
>>> +
>>> + if (cflag & CRTSCTS)
>>> + cr3 = USART_CR3_RTSE | USART_CR3_CTSE;
>>> +
>>> + 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);
>>> + }
>>
>> So, it's a fractional divider. right? Could it be then fractional
>> divider clock in this first place (see
>> drivers/clk/clk-fractional-divider.c)?
>>
>
> I'm not sure it makes sense to represent this baudrate divider within
> the UART IP as a clock.
You have it already. I mean it should be fractional divider clock.
stm32port->clk = devm_clk_get(&pdev->dev, NULL);
+
+ if (WARN_ON(IS_ERR(stm32port->clk)))
+ return -EINVAL;
+
+ /* ensure that clk rate is correct by enabling the clk */
+ clk_prepare_enable(stm32port->clk);
+ stm32port->port.uartclk = clk_get_rate(stm32port->clk);
> What would be the gain?
Remove custom implementation of the calculations. It will be just one
line to refresh the baud rate. I think we have a lot of duplicates
here and there in the kernel. It would be nice not to bring another
one.
--
With Best Regards,
Andy Shevchenko
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists