Align serial stm32x7 driver with kernel's one
Subsystems (2)
cover Align serial stm32x7 driver with kernel's one
From: Patrice Chotard <[email protected]>
This patch update the STM32F7 serial driver compatible string with the one used in kernel.
It reworks the baud rate register calculation, this code is inspired by the kernel driver implementation.
Patrice Chotard (2):
serial: stm32x7: align compatible with kernel one
serial: stm32x7: simplify baud rate register calculation
arch/arm/dts/stm32f746.dtsi | 2 +- drivers/serial/serial_stm32x7.c | 25 +++++++++++++++++-------- drivers/serial/serial_stm32x7.h | 3 ++- 3 files changed, 20 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/2 serial: stm32x7: align compatible with kernel one
From: Patrice Chotard <[email protected]>
stm32x7.c driver is dedicated for STM32F7.
In kernel, "st,stm32-usart" and "st,stm32-uart" compatible strings are dedicated for STM32F4.
To keep U-boot and kernel aligned, replace the serial compatible string from "st,stm32-usart", "st,stm32-uart" to "st,stm32f7-usart", "st,stm32f7-uart" specific for STM32F7.
--- arch/arm/dts/stm32f746.dtsi | 2 +- drivers/serial/serial_stm32x7.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
arch/arm/dts/stm32f746.dtsi +1 -1
@@ -90,7 +90,7 @@ status = "disabled"; }; usart1: serial at 40011000 { - compatible = "st,stm32-usart", "st,stm32-uart"; + compatible = "st,stm32f7-usart", "st,stm32f7-uart"; reg = <0x40011000 0x400>; interrupts = <37>; clocks = <&rcc 0 164>;
drivers/serial/serial_stm32x7.c +2 -2
@@ -100,8 +100,8 @@ static int stm32_serial_probe(struct udevice *dev)#if CONFIG_IS_ENABLED (OF_CONTROL )static const struct udevice_id stm32_serial_id[] = { - {.compatible ="st,stm32-usart" }, - {.compatible ="st,stm32-uart" }, + {.compatible ="st,stm32f7-usart" }, + {.compatible ="st,stm32f7-uart" }, {} };
Signature · 1 line
1.9.1
PATCH 1/2 serial: stm32x7: align compatible with kernel one
Quoted 6 lines · Patrice Chotard
From: Patrice Chotard <[email protected]>
stm32x7.cdriver is dedicated for STM32F7.
In kernel, "st,stm32-usart" and "st,stm32-uart" compatible strings are dedicated for STM32F4.
Quoted 8 lines
To keep U-boot and kernel aligned, replace the serial compatible string from "st,stm32-usart", "st,stm32-uart" to "st,stm32f7-usart", "st,stm32f7-uart" specific for STM32F7.
Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Christophe KERELLO <[email protected]>Reviewed-by Patrick DELAUNAY <[email protected]>Acked-by Vikas MANOCHA <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/7728e3d5/attachment.sig>
PATCH 2/2 serial: stm32x7: simplify baud rate register calculation
In reply to patrice.chotard at st.comFrom: Patrice Chotard <[email protected]>
Simplify baud rate register formula and use the oversampling uart feature.
This code is aligned with what is implemented in kernel driver drivers/tty/serial/stm32-usart.c since kernel v4.9.
--- drivers/serial/serial_stm32x7.c | 21 +++++++++++++++------ drivers/serial/serial_stm32x7.h | 3 ++- 2 files changed, 17 insertions(+), 7 deletions(-)
drivers/serial/serial_stm32x7.c +15 -6
@@ -20,7 +20,7 @@ static int stm32_serial_setbrg(struct udevice *dev, int baudrate) {struct stm32x7_serial_platdata *plat = dev->platdata;struct stm32_usart *const usart = plat->base; -u32 clock, int_div, frac_div, tmp; +u32 clock, int_div, mantissa, fraction, oversampling;if (((u32 )usart &STM32_BUS_MASK ) ==APB1_PERIPH_BASE ) clock =clock_get (CLOCK_APB1 );
@@ -29,11 +29,20 @@ static int stm32_serial_setbrg(struct udevice *dev, int baudrate)else return -EINVAL ; - int_div = (25 * clock) / (4 * baudrate); - tmp = ((int_div /100 ) <<USART_BRR_M_SHIFT ) &USART_BRR_M_MASK ; - frac_div = int_div - (100 * (tmp >>USART_BRR_M_SHIFT )); - tmp |= (((frac_div *16 ) +50 ) /100 ) &USART_BRR_F_MASK ; -writel (tmp, &usart->brr); + int_div =DIV_ROUND_CLOSEST (clock, baudrate); + +if (int_div <16 ) { + oversampling =8 ; +setbits_le32 (&usart->cr1,USART_CR1_OVER8 ); + }else { + oversampling =16 ; +clrbits_le32 (&usart->cr1,USART_CR1_OVER8 ); + } + + mantissa = (int_div / oversampling) <<USART_BRR_M_SHIFT ; + fraction = int_div % oversampling; + +writel (mantissa | fraction, &usart->brr);return 0 ; }
drivers/serial/serial_stm32x7.h +2 -1
@@ -23,8 +23,9 @@ struct stm32_usart { }; -#define USART_CR1_RE (1 << 2) +#define USART_CR1_OVER8 (1 << 15)#define USART_CR1_TE (1 << 3) +#define USART_CR1_RE (1 << 2)#define USART_CR1_UE (1 << 0)#define USART_SR_FLAG_RXNE (1 << 5)
Signature · 1 line
1.9.1
PATCH 2/2 serial: stm32x7: simplify baud rate register calculation
Quoted 11 lines · Patrice Chotard
From: Patrice Chotard <[email protected]>
Simplify baud rate register formula and use the oversampling uart feature.
This code is aligned with what is implemented in kernel driverdrivers/tty/serial/stm32-usart.csince kernel v4.9.Signed-off-by Patrice Chotard <[email protected]>Reviewed-by Christophe KERELLO <[email protected]>Reviewed-by Patrick DELAUNAY <[email protected]>Acked-by Vikas MANOCHA <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170612/453d900c/attachment.sig>