a few fixes for sprd serial driver
Subsystems (2)
Chunyan Zhang
reviewercover a few fixes for sprd serial driver
From: Chunyan Zhang <[email protected]>
Recently I found that sprd serial driver has a few problems if the clock drivers were built as modules which were needed by serial driver, and the serial driver would be postponed until those clock modules were installed.
Chunyan Zhang (3):
serial: sprd: check console via stdout-path in addition
serial: sprd: remove __init from sprd_console_setup
serial: sprd: cleanup the sprd_port when return -EPROBE_DEFER
drivers/tty/serial/sprd_serial.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.20.1
Chunyan Zhang
reviewerPATCH 1/3 serial: sprd: check console via stdout-path in addition
From: Chunyan Zhang <[email protected]>
The SPRD serial driver need to know which serial port would be used as console in an early period during initialization, the purpose is to keep the console port alive as possible even if there's some error caused by no clock configured under serial devicetree nodes. But with the patch [1], the console port couldn't be identified if missing console command line.
So this patch adds using another interface to do check by reading stdout-path.
[1] https://lore.kernel.org/lkml/[email protected]/
--- drivers/tty/serial/sprd_serial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +2 -1
@@ -1147,7 +1147,8 @@ 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) +if ((cons && cons->index >=0 && cons->index == uport->line) || +of_console_check (uport->dev->of_node,SPRD_TTY_NAME , uport->line))return true;return false;
Signature · 1 line
2.20.1
Chunyan Zhang
reviewerPATCH 2/3 serial: sprd: remove __init from sprd_console_setup
In reply to Chunyan ZhangFrom: Chunyan Zhang <[email protected]>
The function sprd_console_setup() would be called from .probe() which can be called after freeing __init functions, for example the .probe() would return -EPROBE_DEFER since it depends on clock modules.
--- drivers/tty/serial/sprd_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +1 -1
@@ -1013,7 +1013,7 @@ static void sprd_console_write(struct console *co, const char *s,spin_unlock_irqrestore (&port->lock, flags); } -static int __init sprd_console_setup (struct console *co,char *options) +static int sprd_console_setup (struct console *co,char *options) {struct sprd_uart_port *sprd_uart_port;int baud =115200 ;
Signature · 1 line
2.20.1
Chunyan Zhang
reviewerPATCH 3/3 serial: sprd: cleanup the sprd_port when return -EPROBE_DEFER
In reply to Chunyan ZhangFrom: Chunyan Zhang <[email protected]>
cleanup the sprd_port for the device when its .probe() would be called later, and then alloc memory for its sprd_port again.
--- drivers/tty/serial/sprd_serial.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/tty/serial/sprd_serial.c +6 -1
@@ -1230,8 +1230,13 @@ static int sprd_probe(struct platform_device *pdev) up->has_sysrq =IS_ENABLED (CONFIG_SERIAL_SPRD_CONSOLE ); ret =sprd_clk_init (up); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) { +devm_kfree (&pdev->dev, sprd_port[index]); + sprd_port[index] =NULL ; + }return ret; + } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); up->membase =devm_ioremap_resource (&pdev->dev, res);
Signature · 1 line
2.20.1
Re: [PATCH 1/3] serial: sprd: check console via stdout-path in addition
In reply to Chunyan ZhangQuoted 10 lines · Chunyan Zhang
From: Chunyan Zhang <[email protected]>
The SPRD serial driver need to know which serial port would be used as console in an early period during initialization, the purpose is to keep the console port alive as possible even if there's some error caused by no clock configured under serial devicetree nodes. But with the patch [1], the console port couldn't be identified if missing console command line.
Quoted 6 lines
So this patch adds using another interface to do check by reading stdout-path.
[1] https://lore.kernel.org/lkml/[email protected]/
Signed-off-by Chunyan Zhang <[email protected]>
Quoted 21 lines
--- drivers/tty/serial/sprd_serial.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/tty/serial/sprd_serial.c +2
-2@@ -1147,7 +1147,8 @@ 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) +if ((cons && cons->index >=0 && cons->index == uport->line) || +of_console_check (uport->dev->of_node,SPRD_TTY_NAME , uport->line))return true;return false; --2.20.1
Signature · 1 line
Baolin Wang
Re: [PATCH 2/3] serial: sprd: remove __init from sprd_console_setup
In reply to Chunyan ZhangQuoted 8 lines · Chunyan Zhang
From: Chunyan Zhang <[email protected]>
The function
sprd_console_setup()would be called from .probe() which can be called after freeing__initfunctions, for example the .probe() would return -EPROBE_DEFER since it depends on clock modules.Signed-off-by Chunyan Zhang <[email protected]>
Quoted 20 lines
--- drivers/tty/serial/sprd_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/tty/serial/sprd_serial.c +1
-2@@ -1013,7 +1013,7 @@ static void sprd_console_write(struct console *co, const char *s,spin_unlock_irqrestore (&port->lock, flags); } -static int __init sprd_console_setup (struct console *co,char *options) +static int sprd_console_setup (struct console *co,char *options) {struct sprd_uart_port *sprd_uart_port;int baud =115200 ; --2.20.1
Signature · 1 line
Baolin Wang
Baolin Wang
maintainerRe: [PATCH 3/3] serial: sprd: cleanup the sprd_port when return -EPROBE_DEFER
In reply to Chunyan ZhangQuoted 16 lines · Chunyan Zhang
From: Chunyan Zhang <[email protected]>
cleanup the
sprd_portfor the device when its .probe() would be called later, and then alloc memory for itssprd_portagain.Signed-off-by Chunyan Zhang <[email protected]>--- drivers/tty/serial/sprd_serial.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/tty/serial/sprd_serial.c +0
-0
drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1234
Quoted 6 lines
drivers/tty/serial/sprd_serial.c +2
-1@@ -1230,8 +1230,13 @@ static int sprd_probe(struct platform_device *pdev) up->has_sysrq =IS_ENABLED (CONFIG_SERIAL_SPRD_CONSOLE ); ret =sprd_clk_init (up); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) {
I think we can remove the condition and devm_kfree() here, just simplify the code as below?
if (ret) {
sprd_port[index] = NULL;
return ret;
}Quoted 11 lines
drivers/tty/serial/sprd_serial.c +4
-1+devm_kfree (&pdev->dev, sprd_port[index]); + sprd_port[index] =NULL ; + }return ret; + } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); up->membase =devm_ioremap_resource (&pdev->dev, res); --2.20.1
Signature · 1 line
Baolin Wang
Chunyan Zhang
reviewerRe: [PATCH 3/3] serial: sprd: cleanup the sprd_port when return -EPROBE_DEFER
Quoted 27 lines · Baolin Wang
Quoted 16 lines · Chunyan Zhang
From: Chunyan Zhang <[email protected]>
cleanup the
sprd_portfor the device when its .probe() would be called later, and then alloc memory for itssprd_portagain.Signed-off-by Chunyan Zhang <[email protected]>--- drivers/tty/serial/sprd_serial.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/tty/serial/sprd_serial.c +0
-0drivers/tty/serial/sprd_serial.c static int sprd_probe(struct platform_device *pdev) · line 1234
Quoted 6 lines
drivers/tty/serial/sprd_serial.c +2
-1@@ -1230,8 +1230,13 @@ static int sprd_probe(struct platform_device *pdev) up->has_sysrq =IS_ENABLED (CONFIG_SERIAL_SPRD_CONSOLE ); ret =sprd_clk_init (up); -if (ret) +if (ret) { +if (ret == -EPROBE_DEFER ) {I think we can remove the condition and
devm_kfree()here, just simplify the code as below?
Quoted 4 lines
if (ret) {
sprd_port[index] = NULL;
return ret;
}Humm.. I admit that here's a little confused.
Let assume we don't have aliases for serial nodes, and we set both earlycon and console via bootargs, what will happen?
We can simplify the code like above and we have to ensure all platforms have serial aliases in their devicetree, then we also can simplify the process of getting port index with of_alias_get_id() only.
We can discuss further offline, and also save community resource :)
Thanks,
Chunyan
Quoted 16 lines
Quoted 10 lines
drivers/tty/serial/sprd_serial.c +4
-1+devm_kfree (&pdev->dev, sprd_port[index]); + sprd_port[index] =NULL ; + }return ret; + } res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); up->membase =devm_ioremap_resource (&pdev->dev, res); --Quoted 2 lines
2.20.1
--
Baolin Wang