From: mcoquelin.stm32@gmail.com (Maxime Coquelin)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 10/15] serial: stm32-usart: Add STM32 USART Driver
Date: Tue, 17 Mar 2015 18:32:24 +0100 [thread overview]
Message-ID: <CALszF6BWuUYRh+3rWnSQLApkAHA5dQXw=6x6D_evRtb+5B_ukA@mail.gmail.com> (raw)
In-Reply-To: <CAHp75Vd7+oLiLLuyocYh95TebtocWrRho6xNjuSUt8fYGp8npg@mail.gmail.com>
2015-03-13 15:19 GMT+01:00 Andy Shevchenko <andy.shevchenko@gmail.com>:
> On Thu, Mar 12, 2015 at 11:55 PM, Maxime Coquelin
> <mcoquelin.stm32@gmail.com> wrote:
>> From: Maxime Coquelin <mcoquelin.stm32@gmail.com>
>>
>> This drivers adds support to the STM32 USART controller, which is a
>> standard serial driver.
>
> My comment below.
>
>>
>> Signed-off-by: Maxime Coquelin <mcoquelin.stm32@gmail.com>
>> ---
>> drivers/tty/serial/Kconfig | 17 +
>> drivers/tty/serial/Makefile | 1 +
>> drivers/tty/serial/stm32-usart.c | 695 +++++++++++++++++++++++++++++++++++++++
>> include/uapi/linux/serial_core.h | 3 +
>> 4 files changed, 716 insertions(+)
>> create mode 100644 drivers/tty/serial/stm32-usart.c
>>
>> diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
>> index d2501f0..880cb4f 100644
>> --- a/drivers/tty/serial/Kconfig
>> +++ b/drivers/tty/serial/Kconfig
>> @@ -1611,6 +1611,23 @@ config SERIAL_SPRD_CONSOLE
>> with "earlycon" on the kernel command line. The console is
>> enabled when early_param is processed.
>>
>> +config SERIAL_STM32
>> + tristate "STMicroelectronics STM32 serial port support"
>> + select SERIAL_CORE
>> + depends on ARM || COMPILE_TEST
>> + help
>> + This driver is for the on-chip Serial Controller on
>> + STMicroelectronics STM32 MCUs.
>> + USART supports Rx & Tx functionality.
>> + It support all industry standard baud rates.
>> +
>> + If unsure, say N.
>> +
>> +config SERIAL_STM32_CONSOLE
>> + bool "Support for console on STM32"
>> + depends on SERIAL_STM32=y
>> + select SERIAL_CORE_CONSOLE
>> +
>> endmenu
>>
>> config SERIAL_MCTRL_GPIO
>> diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
>> index 599be4b..67c5023 100644
>> --- a/drivers/tty/serial/Makefile
>> +++ b/drivers/tty/serial/Makefile
>> @@ -95,6 +95,7 @@ obj-$(CONFIG_SERIAL_FSL_LPUART) += fsl_lpuart.o
>> obj-$(CONFIG_SERIAL_CONEXANT_DIGICOLOR) += digicolor-usart.o
>> obj-$(CONFIG_SERIAL_MEN_Z135) += men_z135_uart.o
>> obj-$(CONFIG_SERIAL_SPRD) += sprd_serial.o
>> +obj-$(CONFIG_SERIAL_STM32) += stm32-usart.o
>>
>> # GPIOLIB helpers for modem control lines
>> obj-$(CONFIG_SERIAL_MCTRL_GPIO) += serial_mctrl_gpio.o
>> diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c
>> new file mode 100644
>> index 0000000..61bb065
>> --- /dev/null
>> +++ b/drivers/tty/serial/stm32-usart.c
>> @@ -0,0 +1,695 @@
<snip>
>> +
>> +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.
What would be the gain?
Kind regards,
Maxime
next prev parent reply other threads:[~2015-03-17 17:32 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 01/15] scripts: link-vmlinux: Don't pass page offset to kallsyms if XIP Kernel 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
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
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 [this message]
2015-03-17 17:56 ` Andy Shevchenko
2015-03-19 13:55 ` Maxime Coquelin
2015-03-19 14:58 ` Peter Hurley
2015-03-19 17:35 ` Maxime Coquelin
2015-03-24 17:21 ` Maxime Coquelin
2015-03-24 17:44 ` Peter Hurley
2015-03-24 18:23 ` Peter Hurley
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='CALszF6BWuUYRh+3rWnSQLApkAHA5dQXw=6x6D_evRtb+5B_ukA@mail.gmail.com' \
--to=mcoquelin.stm32@gmail.com \
--cc=linux-arm-kernel@lists.infradead.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).