linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] keep console alive even if missing the 'enable' clock
@ 2019-08-26  7:29 Chunyan Zhang
  2019-08-26  7:29 ` [PATCH 1/3] serial: sprd: check the right port and membase Chunyan Zhang
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Chunyan Zhang @ 2019-08-26  7:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Orson Zhai, Baolin Wang
  Cc: linux-serial, linux-kernel, Chunyan Zhang

From: Chunyan Zhang <chunyan.zhang@unisoc.com>

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(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] serial: sprd: check the right port and membase
  2019-08-26  7:29 [PATCH 0/3] keep console alive even if missing the 'enable' clock Chunyan Zhang
@ 2019-08-26  7:29 ` Chunyan Zhang
  2019-08-26  7:29 ` [PATCH 2/3] serial: sprd: add console_initcall in sprd's uart driver Chunyan Zhang
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Chunyan Zhang @ 2019-08-26  7:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Orson Zhai, Baolin Wang
  Cc: linux-serial, linux-kernel, Chunyan Zhang

From: Chunyan Zhang <chunyan.zhang@unisoc.com>

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.

Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Signed-off-by: Chunyan Zhang <zhang.lyra@gmail.com>
---
 drivers/tty/serial/sprd_serial.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
index 73d71a4e6c0c..a3be4e2dd019 100644
--- a/drivers/tty/serial/sprd_serial.c
+++ b/drivers/tty/serial/sprd_serial.c
@@ -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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] serial: sprd: add console_initcall in sprd's uart driver
  2019-08-26  7:29 [PATCH 0/3] keep console alive even if missing the 'enable' clock Chunyan Zhang
  2019-08-26  7:29 ` [PATCH 1/3] serial: sprd: check the right port and membase Chunyan Zhang
@ 2019-08-26  7:29 ` Chunyan Zhang
  2019-08-26  7:29 ` [PATCH 3/3] serial: sprd: keep console alive even if missing the 'enable' clock Chunyan Zhang
  2019-09-03  9:20 ` [PATCH 0/3] " Baolin Wang
  3 siblings, 0 replies; 5+ messages in thread
From: Chunyan Zhang @ 2019-08-26  7:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Orson Zhai, Baolin Wang
  Cc: linux-serial, linux-kernel, Chunyan Zhang

From: Chunyan Zhang <chunyan.zhang@unisoc.com>

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.

Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Signed-off-by: Chunyan Zhang <zhang.lyra@gmail.com>
---
 drivers/tty/serial/sprd_serial.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
index a3be4e2dd019..aead823c650b 100644
--- a/drivers/tty/serial/sprd_serial.c
+++ b/drivers/tty/serial/sprd_serial.c
@@ -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 */
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] serial: sprd: keep console alive even if missing the 'enable' clock
  2019-08-26  7:29 [PATCH 0/3] keep console alive even if missing the 'enable' clock Chunyan Zhang
  2019-08-26  7:29 ` [PATCH 1/3] serial: sprd: check the right port and membase Chunyan Zhang
  2019-08-26  7:29 ` [PATCH 2/3] serial: sprd: add console_initcall in sprd's uart driver Chunyan Zhang
@ 2019-08-26  7:29 ` Chunyan Zhang
  2019-09-03  9:20 ` [PATCH 0/3] " Baolin Wang
  3 siblings, 0 replies; 5+ messages in thread
From: Chunyan Zhang @ 2019-08-26  7:29 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Orson Zhai, Baolin Wang
  Cc: linux-serial, linux-kernel, Chunyan Zhang

From: Chunyan Zhang <chunyan.zhang@unisoc.com>

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. 

Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
Signed-off-by: Chunyan Zhang <zhang.lyra@gmail.com>
---
 drivers/tty/serial/sprd_serial.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
index aead823c650b..c4d8c77c1261 100644
--- a/drivers/tty/serial/sprd_serial.c
+++ b/drivers/tty/serial/sprd_serial.c
@@ -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;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] keep console alive even if missing the 'enable' clock
  2019-08-26  7:29 [PATCH 0/3] keep console alive even if missing the 'enable' clock Chunyan Zhang
                   ` (2 preceding siblings ...)
  2019-08-26  7:29 ` [PATCH 3/3] serial: sprd: keep console alive even if missing the 'enable' clock Chunyan Zhang
@ 2019-09-03  9:20 ` Baolin Wang
  3 siblings, 0 replies; 5+ messages in thread
From: Baolin Wang @ 2019-09-03  9:20 UTC (permalink / raw)
  To: Chunyan Zhang
  Cc: Greg Kroah-Hartman, Jiri Slaby, Orson Zhai, linux-serial, LKML

On Mon, 26 Aug 2019 at 15:29, Chunyan Zhang <zhang.lyra@gmail.com> wrote:
>
> From: Chunyan Zhang <chunyan.zhang@unisoc.com>
>
> 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:
Reviewed-by: Baolin Wang <baolin.wang@linaro.org>
Tested-by: Baolin Wang <baolin.wang@linaro.org>

>
> 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(-)
>
> --
> 2.20.1
>


-- 
Baolin Wang
Best Regards

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-09-03  9:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26  7:29 [PATCH 0/3] keep console alive even if missing the 'enable' clock Chunyan Zhang
2019-08-26  7:29 ` [PATCH 1/3] serial: sprd: check the right port and membase Chunyan Zhang
2019-08-26  7:29 ` [PATCH 2/3] serial: sprd: add console_initcall in sprd's uart driver Chunyan Zhang
2019-08-26  7:29 ` [PATCH 3/3] serial: sprd: keep console alive even if missing the 'enable' clock Chunyan Zhang
2019-09-03  9:20 ` [PATCH 0/3] " Baolin Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).