keep console alive even if missing the 'enable' clock
Subsystems (2)
Chunyan Zhang
reviewercover keep console alive even if missing the 'enable' clock
From: Chunyan Zhang <[email protected]>
After the commit 4007098f4ce4 (serial: sprd: Add power management for the Spreadtrum serial controller), the 'enable' clock was forced to be configured in device tree, otherwise the uart devices couldn't be probed successfully.
With this patch-set, the uart device which is used as console would be allowed to register even without any clock configured in device tree, this will make debug easier.
Chunyan Zhang (3):
serial: sprd: check the right port and membase
serial: sprd: add console_initcall in sprd's uart driver
serial: sprd: keep console alive even if missing the 'enable' clock
drivers/tty/serial/sprd_serial.c | 42 ++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-)
Signature · 1 line
2.20.1
Chunyan Zhang
reviewerPATCH 1/3 serial: sprd: check the right port and membase
From: Chunyan Zhang <[email protected]>
When calling sprd_console_setup(), sprd_uart_port probably is NULL, we should check that first instead of checking its items directly.
Also we should check membase to avoid accessing uart device before its initialization finished.
--- drivers/tty/serial/sprd_serial.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/tty/serial/sprd_serial.c +6 -4
@@ -975,7 +975,7 @@ static void sprd_console_write(struct console *co, const char *s,static int __init sprd_console_setup (struct console *co,char *options) { -struct uart_port *port; +struct sprd_uart_port *sprd_uart_port;int baud =115200 ;int bits =8 ;int parity ='n' ;
@@ -984,15 +984,17 @@ static int __init sprd_console_setup(struct console *co, char *options)if (co->index >=UART_NR_MAX || co->index <0 ) co->index =0 ; - port = &sprd_port[co->index]->port; -if (port ==NULL ) { + sprd_uart_port = sprd_port[co->index]; +if (!sprd_uart_port || !sprd_uart_port->port.membase) {pr_info ("serial port %d not yet initialized\n" , co->index);return -ENODEV ; } +if (options)uart_parse_options (options, &baud, &parity, &bits, &flow); -return uart_set_options (port, co, baud, parity, bits, flow); +return uart_set_options (&sprd_uart_port->port, co, baud, + parity, bits, flow); }static struct uart_driver sprd_uart_driver;
Signature · 1 line
2.20.1
Chunyan Zhang
reviewerPATCH 2/3 serial: sprd: add console_initcall in sprd's uart driver
In reply to Chunyan ZhangFrom: Chunyan Zhang <[email protected]>
Use console_initcall to save the console index we selected on the command line to sprd_console before probe finished. Thus we can make different processes to the uart devices during initialization according to whether it is used for console.
--- drivers/tty/serial/sprd_serial.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/tty/serial/sprd_serial.c +7 -0
@@ -1008,6 +1008,13 @@ static struct console sprd_console = { .data = &sprd_uart_driver, }; +static int __init sprd_serial_console_init (void ) +{ +register_console (&sprd_console); +return 0 ; +} +console_initcall (sprd_serial_console_init); +#define SPRD_CONSOLE (&sprd_console)/* Support for earlycon */
Signature · 1 line
2.20.1
Chunyan Zhang
reviewerPATCH 3/3 serial: sprd: keep console alive even if missing the 'enable' clock
In reply to Chunyan ZhangFrom: Chunyan Zhang <[email protected]>
The sprd serial console can work with only 26M fixed clock, but the probe() is returning fail if the clock "enable" is not configured in device tree.
This patch will fix the problem to let the uart device which is used for console can be initialized even missing "enable" clock configured in devicetree. We should make sure the debug function as available as we can.
--- drivers/tty/serial/sprd_serial.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
drivers/tty/serial/sprd_serial.c +21 -4
@@ -1103,6 +1103,16 @@ static int sprd_remove(struct platform_device *dev)return 0 ; } +static bool sprd_uart_is_console (struct uart_port *uport) +{ +struct console *cons = sprd_uart_driver.cons; + +if (cons && cons->index >=0 && cons->index == uport->line) +return true; + +return false; +} +static int sprd_clk_init (struct uart_port *uport) {struct clk *clk_uart, *clk_parent;
@@ -1129,10 +1139,17 @@ static int sprd_clk_init(struct uart_port *uport) u->clk =devm_clk_get (uport->dev,"enable" );if (IS_ERR (u->clk)) { -if (PTR_ERR (u->clk) != -EPROBE_DEFER ) -dev_err (uport->dev,"uart%d can't get enable clock\n" , - uport->line); -return PTR_ERR (u->clk); +if (PTR_ERR (u->clk) == -EPROBE_DEFER ) +return -EPROBE_DEFER ; + +dev_warn (uport->dev,"uart%d can't get enable clock\n" , + uport->line); + +/* To keep console alive even if the error occurred */ +if (!sprd_uart_is_console (uport)) +return PTR_ERR (u->clk); + + u->clk =NULL ; }return 0 ;
Signature · 1 line
2.20.1
Quoted 9 lines · Chunyan Zhang
From: Chunyan Zhang <[email protected]>
After the commit
4007098f4ce4(serial: sprd: Add power management for the Spreadtrum serial controller), the 'enable' clock was forced to be configured in device tree, otherwise the uart devices couldn't be probed successfully.With this patch-set, the uart device which is used as console would be allowed to register even without any clock configured in device tree, this will make debug easier.
Tested on my board, works well and looks good to me. So for the whole series:
Quoted 12 lines
Chunyan Zhang (3):
serial: sprd: check the right port and membase
serial: sprd: addconsole_initcallin sprd's uart driver
serial: sprd: keep console alive even if missing the 'enable' clockdrivers/tty/serial/sprd_serial.c | 42 ++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 8 deletions(-)--
2.20.1
Signature · 2 lines
Baolin Wang Best Regards