diff mbox series

[RFC] tty: serial: meson: add new compatible for gxl uart

Message ID fd06c40a-4f63-3b93-8471-477506f4ef38@gmail.com (mailing list archive)
State New, archived
Headers show
Series [RFC] tty: serial: meson: add new compatible for gxl uart | expand

Commit Message

Heiner Kallweit April 25, 2022, 8:39 p.m. UTC
My SC2 test system (ah212-based HK1 RBOX X4) uses an uboot console
speed of 921600 bps. Being able to use the same speed in Linux
requires using a 12MHz clock source. Ideally we'd set the new
compatible to the first chip version supporting the
AML_UART_BAUD_XTAL_DIV2 bit. Not having access to chip documentation
I'd appreciate a hint on when this bit was introduced.
If fine with you in general the final series would include a
separate patch for the new compatible.

Note: This patch doesn't consider "tty: serial: meson:
Use DIV_ROUND_CLOSEST to calculate baud rates" yet and therefore
won't apply cleanly on linux-next.
I locally used the same DIV_ROUND_CLOSEST() changes before.
----------------------------------------------------------------
Newer SoC versions support using XTAL / 2 (12MHz) as clock source
for the UART. This clock source allows to support 921600 bps as used
by vendor uboot on certain systems like ah212 ref board.

12MHz / 13 = 923076 bps
With the currently used 8MHz clock source only 888888bps or
1000000 bps are possible.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/tty/serial/meson_uart.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Neil Armstrong April 26, 2022, 7:21 a.m. UTC | #1
Hi,

On 25/04/2022 22:39, Heiner Kallweit wrote:
> My SC2 test system (ah212-based HK1 RBOX X4) uses an uboot console
> speed of 921600 bps. Being able to use the same speed in Linux
> requires using a 12MHz clock source. Ideally we'd set the new
> compatible to the first chip version supporting the
> AML_UART_BAUD_XTAL_DIV2 bit.

Actually G12A is the first chip having AML_UART_BAUD_XTAL_DIV2, but SC2 is
the first one requiring it to achieve 921600 bps correctly.

> Not having access to chip documentation
> I'd appreciate a hint on when this bit was introduced.
> If fine with you in general the final series would include a
> separate patch for the new compatible.

This has been already handled in:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=368ab68b18de104719f386a5cfe3595673cc96de
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=00a7fa836dbc454faf5b7027ad67519af7c6c15b
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=9b92cc5ee2d10e6c4d327d1e4ceb77aa8b1081ee

> 
> Note: This patch doesn't consider "tty: serial: meson:
> Use DIV_ROUND_CLOSEST to calculate baud rates" yet and therefore
> won't apply cleanly on linux-next.
> I locally used the same DIV_ROUND_CLOSEST() changes before.
> ----------------------------------------------------------------
> Newer SoC versions support using XTAL / 2 (12MHz) as clock source
> for the UART. This clock source allows to support 921600 bps as used
> by vendor uboot on certain systems like ah212 ref board.
> 
> 12MHz / 13 = 923076 bps
> With the currently used 8MHz clock source only 888888bps or
> 1000000 bps are possible.
> 
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>   drivers/tty/serial/meson_uart.c | 13 ++++++++++---
>   1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
> index 2bf1c57e0..0a0a0636f 100644
> --- a/drivers/tty/serial/meson_uart.c
> +++ b/drivers/tty/serial/meson_uart.c
> @@ -68,6 +68,7 @@
>   #define AML_UART_BAUD_MASK		0x7fffff
>   #define AML_UART_BAUD_USE		BIT(23)
>   #define AML_UART_BAUD_XTAL		BIT(24)
> +#define AML_UART_BAUD_XTAL_DIV2		BIT(27)
>   
>   #define AML_UART_PORT_NUM		12
>   #define AML_UART_PORT_OFFSET		6
> @@ -299,10 +300,15 @@ static void meson_uart_change_speed(struct uart_port *port, unsigned long baud)
>   		cpu_relax();
>   
>   	if (port->uartclk == 24000000) {
> -		val = ((port->uartclk / 3) / baud) - 1;
> -		val |= AML_UART_BAUD_XTAL;
> +		if (of_device_is_compatible(port->dev->of_node, "amlogic,meson-gxl-uart")) {
> +			val = DIV_ROUND_CLOSEST(port->uartclk, 2 * baud) - 1;
> +			val |= AML_UART_BAUD_XTAL | AML_UART_BAUD_XTAL_DIV2;
> +		} else {
> +			val = DIV_ROUND_CLOSEST(port->uartclk, 3 * baud) - 1;
> +			val |= AML_UART_BAUD_XTAL;
> +		}
>   	} else {
> -		val = ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1;
> +		val = DIV_ROUND_CLOSEST(port->uartclk, 4 * baud) - 1;
>   	}
>   	val |= AML_UART_BAUD_USE;
>   	writel(val, port->membase + AML_UART_REG5);
> @@ -782,6 +788,7 @@ static const struct of_device_id meson_uart_dt_match[] = {
>   	{ .compatible = "amlogic,meson8-uart" },
>   	{ .compatible = "amlogic,meson8b-uart" },
>   	{ .compatible = "amlogic,meson-gx-uart" },
> +	{ .compatible = "amlogic,meson-gxl-uart" },
>   	{ /* sentinel */ },
>   };
>   MODULE_DEVICE_TABLE(of, meson_uart_dt_match);
Heiner Kallweit April 26, 2022, 8:49 a.m. UTC | #2
On 26.04.2022 09:21, Neil Armstrong wrote:
> Hi,
> 
> On 25/04/2022 22:39, Heiner Kallweit wrote:
>> My SC2 test system (ah212-based HK1 RBOX X4) uses an uboot console
>> speed of 921600 bps. Being able to use the same speed in Linux
>> requires using a 12MHz clock source. Ideally we'd set the new
>> compatible to the first chip version supporting the
>> AML_UART_BAUD_XTAL_DIV2 bit.
> 
> Actually G12A is the first chip having AML_UART_BAUD_XTAL_DIV2, but SC2 is
> the first one requiring it to achieve 921600 bps correctly.
> 
>> Not having access to chip documentation
>> I'd appreciate a hint on when this bit was introduced.
>> If fine with you in general the final series would include a
>> separate patch for the new compatible.
> 
> This has been already handled in:
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=368ab68b18de104719f386a5cfe3595673cc96de
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=00a7fa836dbc454faf5b7027ad67519af7c6c15b
> https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-next&id=9b92cc5ee2d10e6c4d327d1e4ceb77aa8b1081ee
> 

Good to know, thanks for the hint!

>>
>> Note: This patch doesn't consider "tty: serial: meson:
>> Use DIV_ROUND_CLOSEST to calculate baud rates" yet and therefore
>> won't apply cleanly on linux-next.
>> I locally used the same DIV_ROUND_CLOSEST() changes before.
>> ----------------------------------------------------------------
>> Newer SoC versions support using XTAL / 2 (12MHz) as clock source
>> for the UART. This clock source allows to support 921600 bps as used
>> by vendor uboot on certain systems like ah212 ref board.
>>
>> 12MHz / 13 = 923076 bps
>> With the currently used 8MHz clock source only 888888bps or
>> 1000000 bps are possible.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>   drivers/tty/serial/meson_uart.c | 13 ++++++++++---
>>   1 file changed, 10 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
>> index 2bf1c57e0..0a0a0636f 100644
>> --- a/drivers/tty/serial/meson_uart.c
>> +++ b/drivers/tty/serial/meson_uart.c
>> @@ -68,6 +68,7 @@
>>   #define AML_UART_BAUD_MASK        0x7fffff
>>   #define AML_UART_BAUD_USE        BIT(23)
>>   #define AML_UART_BAUD_XTAL        BIT(24)
>> +#define AML_UART_BAUD_XTAL_DIV2        BIT(27)
>>     #define AML_UART_PORT_NUM        12
>>   #define AML_UART_PORT_OFFSET        6
>> @@ -299,10 +300,15 @@ static void meson_uart_change_speed(struct uart_port *port, unsigned long baud)
>>           cpu_relax();
>>         if (port->uartclk == 24000000) {
>> -        val = ((port->uartclk / 3) / baud) - 1;
>> -        val |= AML_UART_BAUD_XTAL;
>> +        if (of_device_is_compatible(port->dev->of_node, "amlogic,meson-gxl-uart")) {
>> +            val = DIV_ROUND_CLOSEST(port->uartclk, 2 * baud) - 1;
>> +            val |= AML_UART_BAUD_XTAL | AML_UART_BAUD_XTAL_DIV2;
>> +        } else {
>> +            val = DIV_ROUND_CLOSEST(port->uartclk, 3 * baud) - 1;
>> +            val |= AML_UART_BAUD_XTAL;
>> +        }
>>       } else {
>> -        val = ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1;
>> +        val = DIV_ROUND_CLOSEST(port->uartclk, 4 * baud) - 1;
>>       }
>>       val |= AML_UART_BAUD_USE;
>>       writel(val, port->membase + AML_UART_REG5);
>> @@ -782,6 +788,7 @@ static const struct of_device_id meson_uart_dt_match[] = {
>>       { .compatible = "amlogic,meson8-uart" },
>>       { .compatible = "amlogic,meson8b-uart" },
>>       { .compatible = "amlogic,meson-gx-uart" },
>> +    { .compatible = "amlogic,meson-gxl-uart" },
>>       { /* sentinel */ },
>>   };
>>   MODULE_DEVICE_TABLE(of, meson_uart_dt_match);
>
diff mbox series

Patch

diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
index 2bf1c57e0..0a0a0636f 100644
--- a/drivers/tty/serial/meson_uart.c
+++ b/drivers/tty/serial/meson_uart.c
@@ -68,6 +68,7 @@ 
 #define AML_UART_BAUD_MASK		0x7fffff
 #define AML_UART_BAUD_USE		BIT(23)
 #define AML_UART_BAUD_XTAL		BIT(24)
+#define AML_UART_BAUD_XTAL_DIV2		BIT(27)
 
 #define AML_UART_PORT_NUM		12
 #define AML_UART_PORT_OFFSET		6
@@ -299,10 +300,15 @@  static void meson_uart_change_speed(struct uart_port *port, unsigned long baud)
 		cpu_relax();
 
 	if (port->uartclk == 24000000) {
-		val = ((port->uartclk / 3) / baud) - 1;
-		val |= AML_UART_BAUD_XTAL;
+		if (of_device_is_compatible(port->dev->of_node, "amlogic,meson-gxl-uart")) {
+			val = DIV_ROUND_CLOSEST(port->uartclk, 2 * baud) - 1;
+			val |= AML_UART_BAUD_XTAL | AML_UART_BAUD_XTAL_DIV2;
+		} else {
+			val = DIV_ROUND_CLOSEST(port->uartclk, 3 * baud) - 1;
+			val |= AML_UART_BAUD_XTAL;
+		}
 	} else {
-		val = ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1;
+		val = DIV_ROUND_CLOSEST(port->uartclk, 4 * baud) - 1;
 	}
 	val |= AML_UART_BAUD_USE;
 	writel(val, port->membase + AML_UART_REG5);
@@ -782,6 +788,7 @@  static const struct of_device_id meson_uart_dt_match[] = {
 	{ .compatible = "amlogic,meson8-uart" },
 	{ .compatible = "amlogic,meson8b-uart" },
 	{ .compatible = "amlogic,meson-gx-uart" },
+	{ .compatible = "amlogic,meson-gxl-uart" },
 	{ /* sentinel */ },
 };
 MODULE_DEVICE_TABLE(of, meson_uart_dt_match);