serial: 8250/ingenic: Add support for the JZ4750
v3 cover serial: 8250/ingenic: Add support for the JZ4750
JZ4750 and JZ4755 have an extra clock divisor in CGU called CPCCR.ECS. It needs to be handled properly in the early console driver.
v3:
- fix build errors
v2:
- serial moved into separate patchset
- code refactored to avoid peek in CGU register
- Krzysztof's ack picked
v1:
- big patchset for the whole JZ4755 support
Siarhei Volkau (2):
dt-bindings: serial: ingenic: Add support for the JZ4750/55 SoCs
serial: 8250/ingenic: Add support for the JZ4750/JZ4755
.../bindings/serial/ingenic,uart.yaml | 4 ++ drivers/tty/serial/8250/8250_ingenic.c | 48 ++++++++++++++++--- 2 files changed, 46 insertions(+), 6 deletions(-)
Signature · 1 line
2.36.1
PATCH v3 1/2 dt-bindings: serial: ingenic: Add support for the JZ4750/55 SoCs
These SoCs UART block are the same as JZ4725b' one, the difference is outside of the block - it is in the clock generation unit (CGU). The difference requires to make a quirk for early console init.
--- Documentation/devicetree/bindings/serial/ingenic,uart.yaml | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/serial/ingenic,uart.yaml +4 -0
@@ -20,6 +20,7 @@ properties: oneOf: - enum: - ingenic,jz4740-uart + - ingenic,jz4750-uart - ingenic,jz4760-uart - ingenic,jz4780-uart - ingenic,x1000-uart
@@ -31,6 +32,9 @@ properties: - items: - const: ingenic,jz4725b-uart - const: ingenic,jz4740-uart + - items: + - const: ingenic,jz4755-uart + - const: ingenic,jz4750-uart reg: maxItems: 1
Signature · 1 line
2.36.1
PATCH v3 2/2 serial: 8250/ingenic: Add support for the JZ4750/JZ4755
In reply to Siarhei VolkauJZ4750/55/60 (but not JZ4760b) have an extra divisor in between extclk and peripheral clock, called CPCCR.ECS, the driver can't figure out the real state of the divisor without dirty hack - peek CGU CPCCR register. However, we can rely on a vendor's bootloader (u-boot 1.1.6) behavior:
if (extclk > 16MHz)
the divisor is enabled, so the UART driving clock is extclk/2.
This behavior relies on hardware differences: most boards (if not all) with those SoCs have 12 or 24 MHz oscillators but many peripherals want 12Mhz to operate properly (AIC and USB-PHY at least).
The patch doesn't affect JZ4760's behavior as it is subject for another patchset with re-classification of all supported ingenic UARTs.
--- drivers/tty/serial/8250/8250_ingenic.c | 48 ++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-)
drivers/tty/serial/8250/8250_ingenic.c +42 -6
@@ -87,24 +87,19 @@ static void __init ingenic_early_console_setup_clock(struct earlycon_device *dev dev->port.uartclk =be32_to_cpup (prop); } -static int __init ingenic_early_console_setup (struct earlycon_device *dev, +static int __init ingenic_earlycon_setup_tail (struct earlycon_device *dev,const char *opt) {struct uart_port *port = &dev->port;unsigned int divisor;int baud =115200 ; -if (!dev->port.membase) -return -ENODEV ; -if (opt) {unsigned int parity, bits, flow;/* unused for now */ uart_parse_options (opt, &baud, &parity, &bits, &flow); } -ingenic_early_console_setup_clock (dev); -if (dev->baud) baud = dev->baud; divisor =DIV_ROUND_CLOSEST (port->uartclk,16 * baud);
@@ -129,9 +124,49 @@ static int __init ingenic_early_console_setup(struct earlycon_device *dev,return 0 ; } +static int __init ingenic_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +ingenic_early_console_setup_clock (dev); + +return ingenic_earlycon_setup_tail (dev, opt); +} + +static int __init jz4750_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +/* +* JZ4750/55/60 (not JZ4760b) have an extra divisor +* between extclk and peripheral clock, the +* driver can't figure out the real state of the +* divisor without dirty hacks (peek CGU register). +* However, we can rely on a vendor's behavior: +* if (extclk > 16MHz) +* the divisor is enabled. +* This behavior relies on hardware differences: +* most boards with those SoCs have 12 or 24 MHz +* oscillators but many peripherals want 12Mhz +* to operate properly (AIC and USB-phy at least). +*/ +ingenic_early_console_setup_clock (dev); +if (dev->port.uartclk >16000000 ) + dev->port.uartclk /=2 ; + +return ingenic_earlycon_setup_tail (dev, opt); +} +OF_EARLYCON_DECLARE (jz4740_uart,"ingenic,jz4740-uart" , ingenic_early_console_setup); +OF_EARLYCON_DECLARE (jz4750_uart,"ingenic,jz4750-uart" , + jz4750_early_console_setup); +OF_EARLYCON_DECLARE (jz4770_uart,"ingenic,jz4770-uart" , ingenic_early_console_setup);
@@ -328,6 +363,7 @@ static const struct ingenic_uart_config x1000_uart_config = {static const struct of_device_id of_match[] = { { .compatible ="ingenic,jz4740-uart" , .data = &jz4740_uart_config }, + { .compatible ="ingenic,jz4750-uart" , .data = &jz4760_uart_config }, { .compatible ="ingenic,jz4760-uart" , .data = &jz4760_uart_config }, { .compatible ="ingenic,jz4770-uart" , .data = &jz4760_uart_config }, { .compatible ="ingenic,jz4775-uart" , .data = &jz4760_uart_config },
Signature · 1 line
2.36.1
Paul Cercueil
maintainerRe: [PATCH v3 2/2] serial: 8250/ingenic: Add support for the JZ4750/JZ4755
Hi Siarhei,
Quoted 84 lines · Siarhei Volkau
JZ4750/55/60 (but not JZ4760b) have an extra divisor in between extclk and peripheral clock, called CPCCR.ECS, the driver can't figure out the real state of the divisor without dirty hack - peek CGU CPCCR register. However, we can rely on a vendor's bootloader (u-boot 1.1.6) behavior:
if (extclk > 16MHz)
the divisor is enabled, so the UART driving clock is extclk/2.This behavior relies on hardware differences: most boards (if not all) with those SoCs have 12 or 24 MHz oscillators but many peripherals want 12Mhz to operate properly (AIC and USB-PHY at least).
The patch doesn't affect JZ4760's behavior as it is subject for another patchset with re-classification of all supported ingenic UARTs.
Signed-off-by Siarhei Volkau <[email protected]>--- drivers/tty/serial/8250/8250_ingenic.c | 48 ++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-)drivers/tty/serial/8250/8250_ingenic.c +0
-0@@ -87,24 +87,19 @@ static void __initingenic_early_console_setup_clock(struct
earlycon_device*devdrivers/tty/serial/8250/8250_ingenic.c +0
-1dev->port.uartclk =be32_to_cpup (prop); } -static int __init ingenic_early_console_setup(struct earlycon_device*dev,
+static int__initingenic_earlycon_setup_tail(structearlycon_device*dev,drivers/tty/serial/8250/8250_ingenic.c +23
-5const char *opt) {struct uart_port *port = &dev->port;unsigned int divisor;int baud =115200 ; -if (!dev->port.membase) -return -ENODEV ; -if (opt) {unsigned int parity, bits, flow;/* unused for now */ uart_parse_options (opt, &baud, &parity, &bits, &flow); } -ingenic_early_console_setup_clock (dev); -if (dev->baud) baud = dev->baud; divisor =DIV_ROUND_CLOSEST (port->uartclk,16 * baud);@@ -129,9 +124,49 @@ static int __init ingenic_early_console_setup(struct earlycon_device *dev, return 0; } +static int __init ingenic_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +ingenic_early_console_setup_clock (dev); + +return ingenic_earlycon_setup_tail (dev, opt); +} + +static int __init jz4750_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +/* +* JZ4750/55/60 (not JZ4760b) have an extra divisor +* between extclk and peripheral clock, the +* driver can't figure out the real state of the +* divisor without dirty hacks (peek CGU register). +* However, we can rely on a vendor's behavior:
drivers/tty/serial/8250/8250_ingenic.c static int __init · line 162
Quoted 10 lines
drivers/tty/serial/8250/8250_ingenic.c +10
-0+* if (extclk > 16MHz) +* the divisor is enabled. +* This behavior relies on hardware differences: +* most boards with those SoCs have 12 or 24 MHz +* oscillators but many peripherals want 12Mhz +* to operate properly (AIC and USB-phy at least). +*/ +ingenic_early_console_setup_clock (dev); +if (dev->port.uartclk >16000000 ) + dev->port.uartclk /=2 ;
I don't understand, didn't we came up to the conclusion in your V1 that it was better to force-enable the EXT/2 divider in the ingenic init code?
-Paul
Quoted 30 lines
drivers/tty/serial/8250/8250_ingenic.c +7
-0+ +return ingenic_earlycon_setup_tail (dev, opt); +} +OF_EARLYCON_DECLARE (jz4740_uart,"ingenic,jz4740-uart" , ingenic_early_console_setup); +OF_EARLYCON_DECLARE (jz4750_uart,"ingenic,jz4750-uart" , + jz4750_early_console_setup); +OF_EARLYCON_DECLARE(jz4770_uart, "ingenic,jz4770-uart",
drivers/tty/serial/8250/8250_ingenic.c +1
-0ingenic_early_console_setup);@@ -328,6 +363,7 @@ static const struct ingenic_uart_config x1000_uart_config = {static const struct of_device_id of_match[] = { { .compatible ="ingenic,jz4740-uart" , .data = &jz4740_uart_config }, + { .compatible ="ingenic,jz4750-uart" , .data = &jz4760_uart_config },{ .compatible = "ingenic,jz4760-uart", .data =
&jz4760_uart_config
},
{ .compatible = "ingenic,jz4770-uart", .data =&jz4760_uart_config
},
{ .compatible = "ingenic,jz4775-uart", .data =&jz4760_uart_config
},
--
2.36.1
Re: [PATCH v3 2/2] serial: 8250/ingenic: Add support for the JZ4750/JZ4755
сб, 22 окт. 2022 г. в 23:07, Paul Cercueil <[email protected]>:
Quoted 110 lines
Hi Siarhei,
Quoted 90 lines · Siarhei Volkau
JZ4750/55/60 (but not JZ4760b) have an extra divisor in between extclk and peripheral clock, called CPCCR.ECS, the driver can't figure out the
real state of the divisor without dirty hack - peek CGU CPCCR register.
However, we can rely on a vendor's bootloader (u-boot 1.1.6) behavior:
if (extclk > 16MHz)
the divisor is enabled, so the UART driving clock is extclk/2.This behavior relies on hardware differences: most boards (if not all) with those SoCs have 12 or 24 MHz oscillators but many peripherals want
12Mhz to operate properly (AIC and USB-PHY at least).The patch doesn't affect JZ4760's behavior as it is subject for another
patchset with re-classification of all supported ingenic UARTs.Link:
https://github.com/carlos-wong/uboot_jz4755/blob/master/cpu/mips/jz_serial.c#L158Signed-off-by Siarhei Volkau <[email protected]>--- drivers/tty/serial/8250/8250_ingenic.c | 48 ++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-)drivers/tty/serial/8250/8250_ingenic.c +0
-0@@ -87,24 +87,19 @@ static void __initingenic_early_console_setup_clock(struct
earlycon_device*devdev->port.uartclk = be32_to_cpup(prop);}
-static int
__initingenic_early_console_setup(structearlycon_device*dev,
+static int__initingenic_earlycon_setup_tail(structearlycon_device*dev,
const char *opt){ struct uart_port *port = &dev->port; unsigned int divisor; int baud = 115200;drivers/tty/serial/8250/8250_ingenic.c +23
-5-if (!dev->port.membase) -return -ENODEV ; -if (opt) {unsigned int parity, bits, flow;/* unused for now */ uart_parse_options (opt, &baud, &parity, &bits, &flow); } -ingenic_early_console_setup_clock (dev); -if (dev->baud) baud = dev->baud; divisor =DIV_ROUND_CLOSEST (port->uartclk,16 * baud);@@ -129,9 +124,49 @@ static int __init ingenic_early_console_setup(struct earlycon_device *dev, return 0; } +static int __init ingenic_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +ingenic_early_console_setup_clock (dev); + +return ingenic_earlycon_setup_tail (dev, opt); +} + +static int __init jz4750_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +/* +* JZ4750/55/60 (not JZ4760b) have an extra divisor +* between extclk and peripheral clock, the +* driver can't figure out the real state of the +* divisor without dirty hacks (peek CGU register). +* However, we can rely on a vendor's behavior: drivers/tty/serial/8250/8250_ingenic.c static int __init · line 162
Quoted 10 lines
drivers/tty/serial/8250/8250_ingenic.c +10
-0+* if (extclk > 16MHz) +* the divisor is enabled. +* This behavior relies on hardware differences: +* most boards with those SoCs have 12 or 24 MHz +* oscillators but many peripherals want 12Mhz +* to operate properly (AIC and USB-phy at least). +*/ +ingenic_early_console_setup_clock (dev); +if (dev->port.uartclk >16000000 ) + dev->port.uartclk /=2 ;I don't understand, didn't we came up to the conclusion in your V1 that it was better to force-enable the EXT/2 divider in the ingenic init code?
Quoted 2 lines
-Paul
That was better at that moment. I dived deeper in the situation and found a more simple and universal solution, as I think.
Your proposal doesn't cover following situations:
- JZ475x with 12MHz crystal
- JZ4760 with 24MHz crystal
which are legal and might appear in some hardware.
Quoted 32 lines
Quoted 30 lines
drivers/tty/serial/8250/8250_ingenic.c +7
-0+ +return ingenic_earlycon_setup_tail (dev, opt); +} +OF_EARLYCON_DECLARE (jz4740_uart,"ingenic,jz4740-uart" , ingenic_early_console_setup); +OF_EARLYCON_DECLARE (jz4750_uart,"ingenic,jz4750-uart" , + jz4750_early_console_setup); +OF_EARLYCON_DECLARE(jz4770_uart, "ingenic,jz4770-uart",
ingenic_early_console_setup);drivers/tty/serial/8250/8250_ingenic.c +1
-0@@ -328,6 +363,7 @@ static const struct ingenic_uart_config x1000_uart_config = {static const struct of_device_id of_match[] = { { .compatible ="ingenic,jz4740-uart" , .data = &jz4740_uart_config }, + { .compatible ="ingenic,jz4750-uart" , .data = &jz4760_uart_config },{ .compatible = "ingenic,jz4760-uart", .data = &jz4760_uart_config }, { .compatible = "ingenic,jz4770-uart", .data = &jz4760_uart_config }, { .compatible = "ingenic,jz4775-uart", .data = &jz4760_uart_config },--
2.36.1
Paul Cercueil
maintainerRe: [PATCH v3 2/2] serial: 8250/ingenic: Add support for the JZ4750/JZ4755
Hi,
Quoted 126 lines · Siarhei Volkau
сб, 22 окт. 2022 г. в 23:07, Paul Cercueil <[email protected]>:
Quoted 122 lines
Hi Siarhei,
Quoted 1 line · Siarhei Volkau
JZ4750/55/60 (but not JZ4760b) have an extra divisor in between
extclk
Quoted 1 line
and peripheral clock, called CPCCR.ECS, the driver can't figure
out
Quoted 4 lines
the
real state of the divisor without dirty hack - peek CGU CPCCR register.
However, we can rely on a vendor's bootloader (u-boot 1.1.6)behavior:
Quoted 4 lines
if (extclk > 16MHz)
the divisor is enabled, so the UART driving clock is extclk/2.This behavior relies on hardware differences: most boards (if not
all)
Quoted 10 lines
with those SoCs have 12 or 24 MHz oscillators but many peripherals want
12Mhz to operate properly (AIC and USB-PHY at least).The patch doesn't affect JZ4760's behavior as it is subject for another
patchset with re-classification of all supported ingenic UARTs.Link:
https://github.com/carlos-wong/uboot_jz4755/blob/master/cpu/mips/jz_serial.c#L158
Quoted 13 lines
Signed-off-by Siarhei Volkau <[email protected]>--- drivers/tty/serial/8250/8250_ingenic.c | 48 ++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-)drivers/tty/serial/8250/8250_ingenic.c +0
-0@@ -87,24 +87,19 @@ static void __initingenic_early_console_setup_clock(struct
earlycon_device*devQuoted 4 lines
dev->port.uartclk = be32_to_cpup(prop);}
-static int
__initingenic_early_console_setup(struct
earlycon_deviceQuoted 2 lines
*dev,
+static int__initingenic_earlycon_setup_tail(struct
earlycon_devicedrivers/tty/serial/8250/8250_ingenic.c static void __init ingenic_early_console_setup_clock(struct earlycon_device *dev
Quoted 12 lines
*dev,
const char *opt){ struct uart_port *port = &dev->port; unsigned int divisor; int baud = 115200;drivers/tty/serial/8250/8250_ingenic.c +0
-3-if (!dev->port.membase) -return -ENODEV ; -if (opt) {unsigned int parity, bits, flow;/* unused for now */
Quoted 2 lines
uart_parse_options(opt, &baud, &parity, &bits,
&flow);
drivers/tty/serial/8250/8250_ingenic.c static int __init · line 128
Quoted 13 lines
}drivers/tty/serial/8250/8250_ingenic.c +1
-2-ingenic_early_console_setup_clock (dev); -if (dev->baud) baud = dev->baud; divisor =DIV_ROUND_CLOSEST (port->uartclk,16 * baud);@@ -129,9 +124,49 @@ static int __init ingenic_early_console_setup(struct earlycon_device *dev, return 0; } +static int __init ingenic_early_console_setup(struct
earlycon_devicedrivers/tty/serial/8250/8250_ingenic.c static int __init ingenic_early_console_setup(struct earlycon_device *dev,
Quoted 12 lines
drivers/tty/serial/8250/8250_ingenic.c +11
-0*dev, + const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +ingenic_early_console_setup_clock (dev); + +return ingenic_earlycon_setup_tail (dev, opt); +} + +static int __init jz4750_early_console_setup(struct
earlycon_deviceQuoted 12 lines
drivers/tty/serial/8250/8250_ingenic.c +11
-0*dev, + const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +/* +* JZ4750/55/60 (not JZ4760b) have an extra divisor +* between extclk and peripheral clock, the +* driver can't figure out the real state of the +* divisor without dirty hacks (peek CGU register). +* However, we can rely on a vendor's behavior: drivers/tty/serial/8250/8250_ingenic.c static int __init ingenic_early_console_setup(struct earlycon_device *dev, · line 159
Quoted 10 lines
drivers/tty/serial/8250/8250_ingenic.c +10
-0+* if (extclk > 16MHz) +* the divisor is enabled. +* This behavior relies on hardware differences: +* most boards with those SoCs have 12 or 24 MHz +* oscillators but many peripherals want 12Mhz +* to operate properly (AIC and USB-phy at least). +*/ +ingenic_early_console_setup_clock (dev); +if (dev->port.uartclk >16000000 ) + dev->port.uartclk /=2 ;I don't understand, didn't we came up to the conclusion in your V1
that
it was better to force-enable the EXT/2 divider in the ingenic init code?Quoted 2 lines
-Paul
Quoted 6 lines
That was better at that moment. I dived deeper in the situation and found a more simple and universal solution, as I think.
Your proposal doesn't cover following situations:
- JZ475x with 12MHz crystal
- JZ4760 with 24MHz crystal
which are legal and might appear in some hardware.
Do you have such hardware?
Don't add support for cases you can't test.
For what we know - all JZ475x use a 24 MHz crystal and all JZ4760(B) use a 12 MHz crystal, until proven otherwise.
-Paul
Quoted 37 lines
Quoted 37 lines
Quoted 14 lines
drivers/tty/serial/8250/8250_ingenic.c +7
-0+ +return ingenic_earlycon_setup_tail (dev, opt); +} +OF_EARLYCON_DECLARE (jz4740_uart,"ingenic,jz4740-uart" , ingenic_early_console_setup); +OF_EARLYCON_DECLARE (jz4750_uart,"ingenic,jz4750-uart" , + jz4750_early_console_setup); +OF_EARLYCON_DECLARE(jz4770_uart, "ingenic,jz4770-uart",
ingenic_early_console_setup);drivers/tty/serial/8250/8250_ingenic.c static const struct ingenic_uart_config · line 366
Quoted 4 lines
drivers/tty/serial/8250/8250_ingenic.c +0
-0@@ -328,6 +363,7 @@ static const struct ingenic_uart_config x1000_uart_config = { static const struct of_device_id of_match[] = { { .compatible = "ingenic,jz4740-uart", .data =
&jz4740_uart_configdrivers/tty/serial/8250/8250_ingenic.c static const struct ingenic_uart_config · line 368
Quoted 2 lines
drivers/tty/serial/8250/8250_ingenic.c +1
-0}, + { .compatible = "ingenic,jz4750-uart", .data =
&jz4760_uart_configQuoted 2 lines
drivers/tty/serial/8250/8250_ingenic.c +0
-0},{ .compatible = "ingenic,jz4760-uart", .data =
&jz4760_uart_configQuoted 2 lines
},
{ .compatible = "ingenic,jz4770-uart", .data =
&jz4760_uart_configQuoted 2 lines
},
{ .compatible = "ingenic,jz4775-uart", .data =
&jz4760_uart_configQuoted 4 lines
},
--
2.36.1
Re: [PATCH v3 2/2] serial: 8250/ingenic: Add support for the JZ4750/JZ4755
вс, 23 окт. 2022 г. в 12:16, Paul Cercueil <[email protected]>:
Quoted 1 line
Do you have such hardware?
No
Quoted 1 line
Don't add support for cases you can't test.
It's just a side effect of that approach.
Quoted 2 lines
For what we know - all JZ475x use a 24 MHz crystal and all JZ4760(B) use a 12 MHz crystal, until proven otherwise.
Ouf course it just confirms the rule but I found one exception: JZ4750 & 12MHz
Regarding your proposal:
In my opinion enabling the divisor unconditionally is a bad practice, as it's already enabled (or not) by the bootloader, with respect to the hardware capabilities.I think it's better to keep the driver as it is than adding such things.
BR,
Siarhei
Paul Cercueil
maintainerRe: [PATCH v3 2/2] serial: 8250/ingenic: Add support for the JZ4750/JZ4755
Quoted 7 lines · Siarhei Volkau
вс, 23 окт. 2022 г. в 12:16, Paul Cercueil <[email protected]>:
Quoted 1 line
Do you have such hardware?
No
Quoted 1 line
Don't add support for cases you can't test.
Quoted 7 lines
It's just a side effect of that approach.
Quoted 2 lines
For what we know - all JZ475x use a 24 MHz crystal and all JZ4760(B) use a 12 MHz crystal, until proven otherwise.
Ouf course it just confirms the rule but I found one exception: JZ4750 & 12MHz
Then when this board is upstreamed it will declare a 12 MHz oscillator in its DT, and the ingenic init code won't have to enable the /2 divider for that particular board.
Quoted 5 lines
Regarding your proposal:
In my opinion enabling the divisor unconditionally is a bad practice, as it's already enabled (or not) by the bootloader, with respect to the hardware capabilities.I think it's better to keep the driver as it is than adding such things.
Well, I disagree. Linux should not depend on whatever the bootloader configures.
-Paul
Paul Cercueil
maintainerRe: [PATCH v3 2/2] serial: 8250/ingenic: Add support for the JZ4750/JZ4755
In reply to Siarhei VolkauHi Siarhei,
Quoted 34 lines · Siarhei Volkau
JZ4750/55/60 (but not JZ4760b) have an extra divisor in between extclk and peripheral clock, called CPCCR.ECS, the driver can't figure out the real state of the divisor without dirty hack - peek CGU CPCCR register. However, we can rely on a vendor's bootloader (u-boot 1.1.6) behavior:
if (extclk > 16MHz)
the divisor is enabled, so the UART driving clock is extclk/2.This behavior relies on hardware differences: most boards (if not all) with those SoCs have 12 or 24 MHz oscillators but many peripherals want 12Mhz to operate properly (AIC and USB-PHY at least).
The patch doesn't affect JZ4760's behavior as it is subject for another patchset with re-classification of all supported ingenic UARTs.
Signed-off-by Siarhei Volkau <[email protected]>--- drivers/tty/serial/8250/8250_ingenic.c | 48 ++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 6 deletions(-)drivers/tty/serial/8250/8250_ingenic.c +0
-0@@ -87,24 +87,19 @@ static void __initingenic_early_console_setup_clock(struct
earlycon_device*devdrivers/tty/serial/8250/8250_ingenic.c +0
-1dev->port.uartclk =be32_to_cpup (prop); } -static int __init ingenic_early_console_setup(struct earlycon_device*dev,
+static int__initingenic_earlycon_setup_tail(structearlycon_device*dev,
drivers/tty/serial/8250/8250_ingenic.c static void __init ingenic_early_console_setup_clock(struct earlycon_device *dev · line 98
Quoted 8 lines
drivers/tty/serial/8250/8250_ingenic.c +0
-2const char *opt) {struct uart_port *port = &dev->port;unsigned int divisor;int baud =115200 ; -if (!dev->port.membase) -return -ENODEV ;
Again, as I said on your v2, you can keep this here. Then you won't have to duplicate code.
Quoted 42 lines
drivers/tty/serial/8250/8250_ingenic.c +23
-3-if (opt) {unsigned int parity, bits, flow;/* unused for now */ uart_parse_options (opt, &baud, &parity, &bits, &flow); } -ingenic_early_console_setup_clock (dev); -if (dev->baud) baud = dev->baud; divisor =DIV_ROUND_CLOSEST (port->uartclk,16 * baud);@@ -129,9 +124,49 @@ static int __init ingenic_early_console_setup(struct earlycon_device *dev, return 0; } +static int __init ingenic_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +ingenic_early_console_setup_clock (dev); + +return ingenic_earlycon_setup_tail (dev, opt); +} + +static int __init jz4750_early_console_setup (struct earlycon_device *dev, +const char *opt) +{ +if (!dev->port.membase) +return -ENODEV ; + +/* +* JZ4750/55/60 (not JZ4760b) have an extra divisor +* between extclk and peripheral clock, the +* driver can't figure out the real state of the +* divisor without dirty hacks (peek CGU register). +* However, we can rely on a vendor's behavior:
drivers/tty/serial/8250/8250_ingenic.c static int __init · line 162
Quoted 10 lines
drivers/tty/serial/8250/8250_ingenic.c +10
-0+* if (extclk > 16MHz) +* the divisor is enabled. +* This behavior relies on hardware differences: +* most boards with those SoCs have 12 or 24 MHz +* oscillators but many peripherals want 12Mhz +* to operate properly (AIC and USB-phy at least). +*/ +ingenic_early_console_setup_clock (dev); +if (dev->port.uartclk >16000000 ) + dev->port.uartclk /=2 ;
I'm OK with this code, but the comment is not very clear.
What about:
"JZ4750/55/60 have an optional /2 divider between the EXT oscillator and some peripherals including UART, which will be enabled if using a 24 MHz oscillator, and disabled when using a 12 MHz oscillator."
Cheers,
-Paul
Quoted 30 lines
drivers/tty/serial/8250/8250_ingenic.c +7
-0+ +return ingenic_earlycon_setup_tail (dev, opt); +} +OF_EARLYCON_DECLARE (jz4740_uart,"ingenic,jz4740-uart" , ingenic_early_console_setup); +OF_EARLYCON_DECLARE (jz4750_uart,"ingenic,jz4750-uart" , + jz4750_early_console_setup); +OF_EARLYCON_DECLARE(jz4770_uart, "ingenic,jz4770-uart",
drivers/tty/serial/8250/8250_ingenic.c +1
-0ingenic_early_console_setup);@@ -328,6 +363,7 @@ static const struct ingenic_uart_config x1000_uart_config = {static const struct of_device_id of_match[] = { { .compatible ="ingenic,jz4740-uart" , .data = &jz4740_uart_config }, + { .compatible ="ingenic,jz4750-uart" , .data = &jz4760_uart_config },{ .compatible = "ingenic,jz4760-uart", .data =
&jz4760_uart_config
},
{ .compatible = "ingenic,jz4770-uart", .data =&jz4760_uart_config
},
{ .compatible = "ingenic,jz4775-uart", .data =&jz4760_uart_config
},
--
2.36.1