* [PATCH V2] serial: sprd: Use devm_clk_get_optional() to get the input clock
@ 2025-12-10 6:35 Wenhua Lin
2025-12-10 7:12 ` Chunyan Zhang
0 siblings, 1 reply; 3+ messages in thread
From: Wenhua Lin @ 2025-12-10 6:35 UTC (permalink / raw)
To: Greg Kroah-Hartman, Jiri Slaby
Cc: Orson Zhai, Baolin Wang, Chunyan Zhang, Cixi Geng, linux-kernel,
linux-serial, wenhua lin, Wenhua Lin, Xiongpeng Wu, Zhaochen Su,
Zhirong Qiu
Simplify the code which fetches the input clock by using
devm_clk_get_optional(). If no input clock is present
devm_clk_get_optional() will return NULL instead of an error
which matches the behavior of the old code.
Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
---
Change in V2:
-Change title.
-Change commit message.
-Replace devm_clk_get() by devm_clk_get_optional() and drop NULL assignment.
-Delete the sprd_uart_is_console function, after using the devm_clk_get_optional()
interface, this conditional check is redundant.
---
drivers/tty/serial/sprd_serial.c | 40 +++++++-------------------------
1 file changed, 9 insertions(+), 31 deletions(-)
diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
index 8c9366321f8e..83ce77b435ee 100644
--- a/drivers/tty/serial/sprd_serial.c
+++ b/drivers/tty/serial/sprd_serial.c
@@ -1115,34 +1115,21 @@ static void sprd_remove(struct platform_device *dev)
uart_unregister_driver(&sprd_uart_driver);
}
-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) ||
- of_console_check(uport->dev->of_node, SPRD_TTY_NAME, uport->line))
- return true;
-
- return false;
-}
-
static int sprd_clk_init(struct uart_port *uport)
{
struct clk *clk_uart, *clk_parent;
struct sprd_uart_port *u = container_of(uport, struct sprd_uart_port, port);
- clk_uart = devm_clk_get(uport->dev, "uart");
+ clk_uart = devm_clk_get_optional(uport->dev, "uart");
if (IS_ERR(clk_uart)) {
- dev_warn(uport->dev, "uart%d can't get uart clock\n",
- uport->line);
- clk_uart = NULL;
+ return dev_err_probe(uport->dev, PTR_ERR(clk_uart),
+ "uart%d can't get uart clock\n", uport->line);
}
- clk_parent = devm_clk_get(uport->dev, "source");
+ clk_parent = devm_clk_get_optional(uport->dev, "source");
if (IS_ERR(clk_parent)) {
- dev_warn(uport->dev, "uart%d can't get source clock\n",
- uport->line);
- clk_parent = NULL;
+ return dev_err_probe(uport->dev, PTR_ERR(clk_parent),
+ "uart%d can't get source clock\n", uport->line);
}
if (!clk_uart || clk_set_parent(clk_uart, clk_parent))
@@ -1150,19 +1137,10 @@ static int sprd_clk_init(struct uart_port *uport)
else
uport->uartclk = clk_get_rate(clk_uart);
- u->clk = devm_clk_get(uport->dev, "enable");
+ u->clk = devm_clk_get_optional(uport->dev, "enable");
if (IS_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 dev_err_probe(uport->dev, PTR_ERR(u->clk),
+ "uart%d can't get enable clock\n", uport->line);
}
return 0;
--
2.34.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] serial: sprd: Use devm_clk_get_optional() to get the input clock
2025-12-10 6:35 [PATCH V2] serial: sprd: Use devm_clk_get_optional() to get the input clock Wenhua Lin
@ 2025-12-10 7:12 ` Chunyan Zhang
2025-12-10 7:36 ` wenhua lin
0 siblings, 1 reply; 3+ messages in thread
From: Chunyan Zhang @ 2025-12-10 7:12 UTC (permalink / raw)
To: Wenhua Lin
Cc: Greg Kroah-Hartman, Jiri Slaby, Orson Zhai, Baolin Wang,
Cixi Geng, linux-kernel, linux-serial, wenhua lin, Xiongpeng Wu,
Zhaochen Su, Zhirong Qiu
On Wed, 10 Dec 2025 at 14:36, Wenhua Lin <Wenhua.Lin@unisoc.com> wrote:
>
> Simplify the code which fetches the input clock by using
> devm_clk_get_optional(). If no input clock is present
> devm_clk_get_optional() will return NULL instead of an error
> which matches the behavior of the old code.
This commit message is not describing the key point of its changes.
>
> Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
> ---
> Change in V2:
> -Change title.
> -Change commit message.
> -Replace devm_clk_get() by devm_clk_get_optional() and drop NULL assignment.
> -Delete the sprd_uart_is_console function, after using the devm_clk_get_optional()
> interface, this conditional check is redundant.
> ---
> drivers/tty/serial/sprd_serial.c | 40 +++++++-------------------------
> 1 file changed, 9 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> index 8c9366321f8e..83ce77b435ee 100644
> --- a/drivers/tty/serial/sprd_serial.c
> +++ b/drivers/tty/serial/sprd_serial.c
> @@ -1115,34 +1115,21 @@ static void sprd_remove(struct platform_device *dev)
> uart_unregister_driver(&sprd_uart_driver);
> }
>
> -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) ||
> - of_console_check(uport->dev->of_node, SPRD_TTY_NAME, uport->line))
> - return true;
> -
> - return false;
> -}
> -
> static int sprd_clk_init(struct uart_port *uport)
> {
> struct clk *clk_uart, *clk_parent;
> struct sprd_uart_port *u = container_of(uport, struct sprd_uart_port, port);
>
> - clk_uart = devm_clk_get(uport->dev, "uart");
> + clk_uart = devm_clk_get_optional(uport->dev, "uart");
> if (IS_ERR(clk_uart)) {
> - dev_warn(uport->dev, "uart%d can't get uart clock\n",
> - uport->line);
> - clk_uart = NULL;
> + return dev_err_probe(uport->dev, PTR_ERR(clk_uart),
> + "uart%d can't get uart clock\n", uport->line);
No, as I said before, you cannot do like this, this patch is making
the clocks mandatory, sprd_serial driver could work as serial ports
for logs output without this "uart" clock.
It is very useful for early debugging when the clock driver is not even ready.
If other SPRD serials' default clock is 24M rather than 26M, like I
said in the last version patch, you can set default clock according to
the compatible string, that's saying make SPRD_DEFAULT_SOURCE_CLK to
be an element of "of_device_id.data".
So NAK for this change, sorry!
Thanks,
Chunyan
> }
>
> - clk_parent = devm_clk_get(uport->dev, "source");
> + clk_parent = devm_clk_get_optional(uport->dev, "source");
> if (IS_ERR(clk_parent)) {
> - dev_warn(uport->dev, "uart%d can't get source clock\n",
> - uport->line);
> - clk_parent = NULL;
> + return dev_err_probe(uport->dev, PTR_ERR(clk_parent),
> + "uart%d can't get source clock\n", uport->line);
> }
>
> if (!clk_uart || clk_set_parent(clk_uart, clk_parent))
> @@ -1150,19 +1137,10 @@ static int sprd_clk_init(struct uart_port *uport)
> else
> uport->uartclk = clk_get_rate(clk_uart);
>
> - u->clk = devm_clk_get(uport->dev, "enable");
> + u->clk = devm_clk_get_optional(uport->dev, "enable");
> if (IS_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 dev_err_probe(uport->dev, PTR_ERR(u->clk),
> + "uart%d can't get enable clock\n", uport->line);
> }
>
> return 0;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH V2] serial: sprd: Use devm_clk_get_optional() to get the input clock
2025-12-10 7:12 ` Chunyan Zhang
@ 2025-12-10 7:36 ` wenhua lin
0 siblings, 0 replies; 3+ messages in thread
From: wenhua lin @ 2025-12-10 7:36 UTC (permalink / raw)
To: Chunyan Zhang
Cc: Wenhua Lin, Greg Kroah-Hartman, Jiri Slaby, Orson Zhai,
Baolin Wang, Cixi Geng, linux-kernel, linux-serial, Xiongpeng Wu,
Zhaochen Su, Zhirong Qiu
On Wed, Dec 10, 2025 at 3:12 PM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
>
> On Wed, 10 Dec 2025 at 14:36, Wenhua Lin <Wenhua.Lin@unisoc.com> wrote:
> >
> > Simplify the code which fetches the input clock by using
> > devm_clk_get_optional(). If no input clock is present
> > devm_clk_get_optional() will return NULL instead of an error
> > which matches the behavior of the old code.
>
> This commit message is not describing the key point of its changes.
>
> >
> > Signed-off-by: Wenhua Lin <Wenhua.Lin@unisoc.com>
> > ---
> > Change in V2:
> > -Change title.
> > -Change commit message.
> > -Replace devm_clk_get() by devm_clk_get_optional() and drop NULL assignment.
> > -Delete the sprd_uart_is_console function, after using the devm_clk_get_optional()
> > interface, this conditional check is redundant.
> > ---
> > drivers/tty/serial/sprd_serial.c | 40 +++++++-------------------------
> > 1 file changed, 9 insertions(+), 31 deletions(-)
> >
> > diff --git a/drivers/tty/serial/sprd_serial.c b/drivers/tty/serial/sprd_serial.c
> > index 8c9366321f8e..83ce77b435ee 100644
> > --- a/drivers/tty/serial/sprd_serial.c
> > +++ b/drivers/tty/serial/sprd_serial.c
> > @@ -1115,34 +1115,21 @@ static void sprd_remove(struct platform_device *dev)
> > uart_unregister_driver(&sprd_uart_driver);
> > }
> >
> > -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) ||
> > - of_console_check(uport->dev->of_node, SPRD_TTY_NAME, uport->line))
> > - return true;
> > -
> > - return false;
> > -}
> > -
> > static int sprd_clk_init(struct uart_port *uport)
> > {
> > struct clk *clk_uart, *clk_parent;
> > struct sprd_uart_port *u = container_of(uport, struct sprd_uart_port, port);
> >
> > - clk_uart = devm_clk_get(uport->dev, "uart");
> > + clk_uart = devm_clk_get_optional(uport->dev, "uart");
> > if (IS_ERR(clk_uart)) {
> > - dev_warn(uport->dev, "uart%d can't get uart clock\n",
> > - uport->line);
> > - clk_uart = NULL;
> > + return dev_err_probe(uport->dev, PTR_ERR(clk_uart),
> > + "uart%d can't get uart clock\n", uport->line);
>
> No, as I said before, you cannot do like this, this patch is making
> the clocks mandatory, sprd_serial driver could work as serial ports
> for logs output without this "uart" clock.
>
> It is very useful for early debugging when the clock driver is not even ready.
>
> If other SPRD serials' default clock is 24M rather than 26M, like I
> said in the last version patch, you can set default clock according to
> the compatible string, that's saying make SPRD_DEFAULT_SOURCE_CLK to
> be an element of "of_device_id.data".
>
> So NAK for this change, sorry!
>
> Thanks,
> Chunyan
Hi chunyan:
When the clock driver is not yet ready, the earlyconsole remains functional.
At this stage, even if the UART driver probe fails, it will not
affect the debugging process.
Thanks
>
> > }
> >
> > - clk_parent = devm_clk_get(uport->dev, "source");
> > + clk_parent = devm_clk_get_optional(uport->dev, "source");
> > if (IS_ERR(clk_parent)) {
> > - dev_warn(uport->dev, "uart%d can't get source clock\n",
> > - uport->line);
> > - clk_parent = NULL;
> > + return dev_err_probe(uport->dev, PTR_ERR(clk_parent),
> > + "uart%d can't get source clock\n", uport->line);
> > }
> >
> > if (!clk_uart || clk_set_parent(clk_uart, clk_parent))
> > @@ -1150,19 +1137,10 @@ static int sprd_clk_init(struct uart_port *uport)
> > else
> > uport->uartclk = clk_get_rate(clk_uart);
> >
> > - u->clk = devm_clk_get(uport->dev, "enable");
> > + u->clk = devm_clk_get_optional(uport->dev, "enable");
> > if (IS_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 dev_err_probe(uport->dev, PTR_ERR(u->clk),
> > + "uart%d can't get enable clock\n", uport->line);
> > }
> >
> > return 0;
> > --
> > 2.34.1
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-12-10 7:36 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-10 6:35 [PATCH V2] serial: sprd: Use devm_clk_get_optional() to get the input clock Wenhua Lin
2025-12-10 7:12 ` Chunyan Zhang
2025-12-10 7:36 ` wenhua lin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®