Skip to contentSkip to conversation

clk: imx: Fix reparenting of UARTs not associated with sdout

PATCH Superseded Adam Ford 2 participants 4 messages Dec 4, 2020 – Dec 7, 2020

Subsystems (3)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Adam Ford

author
#0 lore raw

PATCH 1/1 clk: imx: Fix reparenting of UARTs not associated with sdout

The default clock source on i.MX8M Mini and Nano boards use a 24MHz clock, but users who need to re-parent the clock source run into issues because all the UART clocks are enabled whether or not they're needed by sdout.

Any attempt to change the parent results in an busy error because the clocks have been enabled already.

clk: failed to reparent uart1 to sys_pll1_80m: -16

Instead of pre-initializing all UARTS, scan the device tree to see if UART clock is used as stdout before initializing it. Only enable the UART clock if it's needed in order to delay the clock initialization until after the re-parenting of the clocks.

Fixes 9461f7b33d11c ("clk: fix CLK_SET_RATE_GATE with clock rate protection")
drivers/clk/imx/clk.c +8 -2
index 47882c51cb85..6dcc5fbd8f3f 100644
@@ -163,12 +163,18 @@ __setup_param("earlyprintk", imx_keep_uart_earlyprintk,
 
 void imx_register_uart_clocks(struct clk ** const clks[])
 {
+	struct clk *uart_clk;
 	if (imx_keep_uart_clocks) {
 		int i;
 
 		imx_uart_clocks = clks;
-		for (i = 0; imx_uart_clocks[i]; i++)
-			clk_prepare_enable(*imx_uart_clocks[i]);
+		for (i = 0; imx_uart_clocks[i]; i++) {
+			uart_clk = of_clk_get(of_stdout, i);
+			if (IS_ERR(uart_clk))
+				continue;
+			clk_prepare_enable(uart_clk);
+			clk_put(uart_clk);
+		}
 	}
 }
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi Adam,

Quoted 25 lines · Adam Ford

The default clock source on i.MX8M Mini and Nano boards use a 24MHz clock, but users who need to re-parent the clock source run into issues because all the UART clocks are enabled whether or not they're needed by sdout.

Any attempt to change the parent results in an busy error because the clocks have been enabled already.

clk: failed to reparent uart1 to sys_pll1_80m: -16

Instead of pre-initializing all UARTS, scan the device tree to see if UART clock is used as stdout before initializing it. Only enable the UART clock if it's needed in order to delay the clock initialization until after the re-parenting of the clocks.

Fixes 9461f7b33d11c ("clk: fix CLK_SET_RATE_GATE with clock rate protection")
drivers/clk/imx/clk.c +0 -0
index 47882c51cb85..6dcc5fbd8f3f 100644
@@ -163,12 +163,18 @@ __setup_param("earlyprintk", imx_keep_uart_earlyprintk,
 
 void imx_register_uart_clocks(struct clk ** const clks[])

drivers/clk/imx/clk.c __setup_param("earlyprintk", imx_keep_uart_earlyprintk, · line 172

Quoted 10 lines
drivers/clk/imx/clk.c +3 -2
 {
+	struct clk *uart_clk;
 	if (imx_keep_uart_clocks) {
 		int i;
 
 		imx_uart_clocks = clks;
-		for (i = 0; imx_uart_clocks[i]; i++)
-			clk_prepare_enable(*imx_uart_clocks[i]);
+		for (i = 0; imx_uart_clocks[i]; i++) {
+			uart_clk = of_clk_get(of_stdout, i);

This looks wrong. imx_uart_clocks is an array containing all clocks that could possibly be used for an UART. With of_clk_get(of_stdout, i) you get the nth clock for one specific UART.
What you have to do here is: For each of imx_uart_clocks[] you have to iterate over all clocks of the of_stdout node.

Sascha

Quoted 12 lines
drivers/clk/imx/clk.c +5 -0
+			if (IS_ERR(uart_clk))
+				continue;
+			clk_prepare_enable(uart_clk);
+			clk_put(uart_clk);
+		}
 	}
 }
 
Signature · 1 line
2.25.1
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author
#2 lore raw
Quoted 34 lines · Sascha Hauer

Hi Adam,

Quoted 30 lines · Adam Ford

The default clock source on i.MX8M Mini and Nano boards use a 24MHz clock, but users who need to re-parent the clock source run into issues because all the UART clocks are enabled whether or not they're needed by sdout.

Any attempt to change the parent results in an busy error because the clocks have been enabled already.

clk: failed to reparent uart1 to sys_pll1_80m: -16

Instead of pre-initializing all UARTS, scan the device tree to see if UART clock is used as stdout before initializing it. Only enable the UART clock if it's needed in order to delay the clock initialization until after the re-parenting of the clocks.

Fixes 9461f7b33d11c ("clk: fix CLK_SET_RATE_GATE with clock rate protection")
drivers/clk/imx/clk.c +1 -0
index 47882c51cb85..6dcc5fbd8f3f 100644
@@ -163,12 +163,18 @@ __setup_param("earlyprintk", imx_keep_uart_earlyprintk,
 
 void imx_register_uart_clocks(struct clk ** const clks[])
 {
+     struct clk *uart_clk;
      if (imx_keep_uart_clocks) {
              int i;
 
Quoted 11 lines

drivers/clk/imx/clk.c __setup_param("earlyprintk", imx_keep_uart_earlyprintk, · line 172

Quoted 5 lines
drivers/clk/imx/clk.c +2 -2
              imx_uart_clocks = clks;
-             for (i = 0; imx_uart_clocks[i]; i++)
-                     clk_prepare_enable(*imx_uart_clocks[i]);
+             for (i = 0; imx_uart_clocks[i]; i++) {
+                     uart_clk = of_clk_get(of_stdout, i);

This looks wrong. imx_uart_clocks is an array containing all clocks that could possibly be used for an UART. With of_clk_get(of_stdout, i) you get the nth clock for one specific UART.
What you have to do here is: For each of imx_uart_clocks[] you have to iterate over all clocks of the of_stdout node.

Sascha,

Thanks for the review.

I agree that I'm using the wrong index when checking of_stdout, but I am not sure we need to loop through imx_uart_clocks at all. I looked at the NXP repo, and they just focus on looping through of_stdout and don't reference the imx_uart_clocks. Can't we just loop through the of_stdout and enable any clocks found in that?

adam

Quoted 21 lines

Sascha

Quoted 9 lines
drivers/clk/imx/clk.c +5 -1
+                     if (IS_ERR(uart_clk))
+                             continue;
+                     clk_prepare_enable(uart_clk);
+                     clk_put(uart_clk);
+             }
      }
 }
 
--
Quoted 3 lines

2.25.1

--

Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#3 lore raw

Hi Adam,

Quoted 49 lines · Adam Ford
Quoted 34 lines · Sascha Hauer

Hi Adam,

Quoted 30 lines · Adam Ford

The default clock source on i.MX8M Mini and Nano boards use a 24MHz clock, but users who need to re-parent the clock source run into issues because all the UART clocks are enabled whether or not they're needed by sdout.

Any attempt to change the parent results in an busy error because the clocks have been enabled already.

clk: failed to reparent uart1 to sys_pll1_80m: -16

Instead of pre-initializing all UARTS, scan the device tree to see if UART clock is used as stdout before initializing it. Only enable the UART clock if it's needed in order to delay the clock initialization until after the re-parenting of the clocks.

Fixes 9461f7b33d11c ("clk: fix CLK_SET_RATE_GATE with clock rate protection")
drivers/clk/imx/clk.c +1 -0
index 47882c51cb85..6dcc5fbd8f3f 100644
@@ -163,12 +163,18 @@ __setup_param("earlyprintk", imx_keep_uart_earlyprintk,
 
 void imx_register_uart_clocks(struct clk ** const clks[])
 {
+     struct clk *uart_clk;
      if (imx_keep_uart_clocks) {
              int i;
 
Quoted 11 lines

drivers/clk/imx/clk.c __setup_param("earlyprintk", imx_keep_uart_earlyprintk, · line 172

Quoted 5 lines
drivers/clk/imx/clk.c +2 -2
              imx_uart_clocks = clks;
-             for (i = 0; imx_uart_clocks[i]; i++)
-                     clk_prepare_enable(*imx_uart_clocks[i]);
+             for (i = 0; imx_uart_clocks[i]; i++) {
+                     uart_clk = of_clk_get(of_stdout, i);

This looks wrong. imx_uart_clocks is an array containing all clocks that could possibly be used for an UART. With of_clk_get(of_stdout, i) you get the nth clock for one specific UART.
What you have to do here is: For each of imx_uart_clocks[] you have to iterate over all clocks of the of_stdout node.

Sascha,

Quoted 7 lines

Thanks for the review.

I agree that I'm using the wrong index when checking of_stdout, but I am not sure we need to loop through imx_uart_clocks at all. I looked at the NXP repo, and they just focus on looping through of_stdout and don't reference the imx_uart_clocks. Can't we just loop through the of_stdout and enable any clocks found in that?

This sounds good. That way we could get rid of the imx_uart_clocks array entirely.

Note that right below imx_register_uart_clocks() there is imx_clk_disable_uart() which disables the previously enabled clocks again later when the real driver has taken over. You'll have to change that as well accordingly.

Sascha

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |