* [PATCH v4 0/2] gs101 oriole: UART clock fixes
@ 2024-07-12 17:09 André Draszik
2024-07-12 17:09 ` [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally André Draszik
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: André Draszik @ 2024-07-12 17:09 UTC (permalink / raw)
To: Peter Griffin, Krzysztof Kozlowski, Sylwester Nawrocki,
Chanwoo Choi, Alim Akhtar, Michael Turquette, Stephen Boyd,
Tudor Ambarus, Sam Protsenko
Cc: Tudor Ambarus, Will McVicker, kernel-team, linux-arm-kernel,
linux-samsung-soc, linux-clk, linux-kernel, André Draszik
Hi,
This series fixes a long-standing issue in the gs101 clocking / uart
handling.
We can now disable clocks that had previously been marked critical, and
still get a working earlycon.
There is a preparatory patch, and then a patch to drop an incorrect clock
counting work-around. That 2nd patch is essentially the last remaining patch
[1] with all review comments addressed, from the series [2] that was sent
earlier this year, see lore links below.
Patch 2 can not come before or without patch 1.
Signed-off-by: André Draszik <andre.draszik@linaro.org>
[1] https://lore.kernel.org/all/20240130093812.1746512-6-andre.draszik@linaro.org/
[2] https://lore.kernel.org/all/20240130093812.1746512-1-andre.draszik@linaro.org/
[3] https://lore.kernel.org/all/d45de3b2bb6b48653842cf1f74e58889ed6783ae.camel@linaro.org/
Changes in v4:
- new patch "clk: samsung: gs101: allow earlycon to work unconditionally"
- update commit message for patch 2
- Link to v3: https://lore.kernel.org/r/20240710-gs101-non-essential-clocks-2-v3-0-5dcb8d040d1c@linaro.org
---
André Draszik (2):
clk: samsung: gs101: allow earlycon to work unconditionally
clk: samsung: gs101: don't mark non-essential (UART) clocks critical
drivers/clk/samsung/clk-gs101.c | 106 ++++++++++++++++++++++++++++++++++++++--
1 file changed, 102 insertions(+), 4 deletions(-)
---
base-commit: 523b23f0bee3014a7a752c9bb9f5c54f0eddae88
change-id: 20240430-gs101-non-essential-clocks-2-6a3280fa1be8
Best regards,
--
André Draszik <andre.draszik@linaro.org>
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally
2024-07-12 17:09 [PATCH v4 0/2] gs101 oriole: UART clock fixes André Draszik
@ 2024-07-12 17:09 ` André Draszik
2024-07-18 20:46 ` Stephen Boyd
2024-07-12 17:09 ` [PATCH v4 2/2] clk: samsung: gs101: don't mark non-essential (UART) clocks critical André Draszik
2024-07-18 20:55 ` [PATCH v4 0/2] gs101 oriole: UART clock fixes Stephen Boyd
2 siblings, 1 reply; 8+ messages in thread
From: André Draszik @ 2024-07-12 17:09 UTC (permalink / raw)
To: Peter Griffin, Krzysztof Kozlowski, Sylwester Nawrocki,
Chanwoo Choi, Alim Akhtar, Michael Turquette, Stephen Boyd,
Tudor Ambarus, Sam Protsenko
Cc: Tudor Ambarus, Will McVicker, kernel-team, linux-arm-kernel,
linux-samsung-soc, linux-clk, linux-kernel, André Draszik
earlycon depends on the bootloader setup UART clocks being retained.
This patch adds some logic to detect these clocks if earlycon is
enabled, to bump their usage count during init and release them again
at the end of init.
This helps with cases where the UART clocks (or their parents) get
disabled during loading of other drivers (e.g. i2c) causing earlycon to
stop to work sometime into the boot, halting the whole system.
The general idea is based on similar code in the i.MX clock driver, but
since our clocks are coming from various different clock units, we have
to run this code multiple times until all required UART clocks have
probed.
Signed-off-by: André Draszik <andre.draszik@linaro.org>
---
drivers/clk/samsung/clk-gs101.c | 100 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
diff --git a/drivers/clk/samsung/clk-gs101.c b/drivers/clk/samsung/clk-gs101.c
index 85098c61c15e..429690757923 100644
--- a/drivers/clk/samsung/clk-gs101.c
+++ b/drivers/clk/samsung/clk-gs101.c
@@ -8,8 +8,13 @@
#include <linux/clk.h>
#include <linux/clk-provider.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/mutex.h>
#include <linux/of.h>
+#include <linux/of_clk.h>
#include <linux/platform_device.h>
+#include <linux/slab.h>
#include <dt-bindings/clock/google,gs101.h>
@@ -4381,6 +4386,99 @@ static const struct samsung_cmu_info peric1_cmu_info __initconst = {
/* ---- platform_driver ----------------------------------------------------- */
+static struct {
+ struct mutex lock;
+
+ bool bump_refs;
+
+ struct clk **clks;
+ size_t n_clks;
+} gs101_stdout_clks __initdata = {
+ .lock = __MUTEX_INITIALIZER(gs101_stdout_clks.lock),
+};
+
+static int __init gs101_keep_uart_clocks_param(char *str)
+{
+ gs101_stdout_clks.bump_refs = true;
+ return 0;
+}
+early_param("earlycon", gs101_keep_uart_clocks_param);
+
+static void __init gs101_bump_uart_clock_references(void)
+{
+ size_t n_clks;
+
+ /* We only support device trees - do nothing if not available. */
+ if (!IS_ENABLED(CONFIG_OF))
+ return;
+
+ n_clks = of_clk_get_parent_count(of_stdout);
+ if (!n_clks || !of_stdout)
+ return;
+
+ mutex_lock(&gs101_stdout_clks.lock);
+
+ /*
+ * We only need to run this code if required to do so, and if we have
+ * not succeeded previously, which will be the case if not all required
+ * clocks were ready yet during previous attempts.
+ */
+ if (!gs101_stdout_clks.bump_refs)
+ goto out_unlock;
+
+ if (!gs101_stdout_clks.clks) {
+ gs101_stdout_clks.n_clks = n_clks;
+
+ gs101_stdout_clks.clks = kcalloc(gs101_stdout_clks.n_clks,
+ sizeof(*gs101_stdout_clks.clks),
+ GFP_KERNEL);
+ if (!gs101_stdout_clks.clks)
+ goto out_unlock;
+ }
+
+ /* assume that this time we'll be able to grab all required clocks */
+ gs101_stdout_clks.bump_refs = false;
+ for (size_t i = 0; i < n_clks; ++i) {
+ struct clk *clk;
+
+ /* we might have grabbed this clock in a previous attempt */
+ if (gs101_stdout_clks.clks[i])
+ continue;
+
+ clk = of_clk_get(of_stdout, i);
+ if (IS_ERR(clk)) {
+ /*
+ * clock might not have probed yet so we'll have to try
+ * again next time
+ */
+ gs101_stdout_clks.bump_refs = true;
+ continue;
+ }
+
+ if (clk_prepare_enable(clk)) {
+ clk_put(clk);
+ continue;
+ }
+ gs101_stdout_clks.clks[i] = clk;
+ }
+
+out_unlock:
+ mutex_unlock(&gs101_stdout_clks.lock);
+}
+
+static int __init gs101_drop_extra_uart_clock_references(void)
+{
+ for (size_t i = 0; i < gs101_stdout_clks.n_clks; ++i) {
+ clk_disable_unprepare(gs101_stdout_clks.clks[i]);
+ clk_put(gs101_stdout_clks.clks[i]);
+ }
+
+ kfree(gs101_stdout_clks.clks);
+
+ return 0;
+}
+late_initcall_sync(gs101_drop_extra_uart_clock_references);
+
static int __init gs101_cmu_probe(struct platform_device *pdev)
{
const struct samsung_cmu_info *info;
@@ -4389,6 +4487,8 @@ static int __init gs101_cmu_probe(struct platform_device *pdev)
info = of_device_get_match_data(dev);
exynos_arm64_register_cmu(dev, dev->of_node, info);
+ gs101_bump_uart_clock_references();
+
return 0;
}
--
2.45.2.993.g49e7a77208-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH v4 2/2] clk: samsung: gs101: don't mark non-essential (UART) clocks critical
2024-07-12 17:09 [PATCH v4 0/2] gs101 oriole: UART clock fixes André Draszik
2024-07-12 17:09 ` [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally André Draszik
@ 2024-07-12 17:09 ` André Draszik
2024-07-18 20:55 ` [PATCH v4 0/2] gs101 oriole: UART clock fixes Stephen Boyd
2 siblings, 0 replies; 8+ messages in thread
From: André Draszik @ 2024-07-12 17:09 UTC (permalink / raw)
To: Peter Griffin, Krzysztof Kozlowski, Sylwester Nawrocki,
Chanwoo Choi, Alim Akhtar, Michael Turquette, Stephen Boyd,
Tudor Ambarus, Sam Protsenko
Cc: Tudor Ambarus, Will McVicker, kernel-team, linux-arm-kernel,
linux-samsung-soc, linux-clk, linux-kernel, André Draszik
The peric0_top1_ipclk_0 and peric0_top1_pclk_0 are the clocks going to
peric0/uart_usi, with pclk being the bus clock. Without pclk running,
any bus access will hang.
Unfortunately, in commit d97b6c902a40 ("arm64: dts: exynos: gs101:
update USI UART to use peric0 clocks") the gs101 DT ended up specifying
an incorrect pclk in the respective node and instead the two clocks
here were marked as critical.
Since then, the DT has been updated to use the correct clock in
commit 21e4e8807bfc ("arm64: dts: exynos: gs101: use correct clocks for
usi_uart") and the driver here should be corrected and the work-around
removed.
Link: https://lore.kernel.org/all/d45de3b2bb6b48653842cf1f74e58889ed6783ae.camel@linaro.org/ [1]
Fixes: 893f133a040b ("clk: samsung: gs101: add support for cmu_peric0")
Signed-off-by: André Draszik <andre.draszik@linaro.org>
Reviewed-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Reviewed-by: Sam Protsenko <semen.protsenko@linaro.org>
---
v4:
- the earlycon issue described in the commit message in previous
versions of this patch is gone with "clk: samsung: gs101: allow
earlycon to work unconditionally", so no need to mention anything
v3:
- add git commit SHA1s (Krzysztof)
- add link to wordier description of earlycon issue
v2:
- commit message typo fixed
- collect Reviewed-by: tags
---
drivers/clk/samsung/clk-gs101.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/samsung/clk-gs101.c b/drivers/clk/samsung/clk-gs101.c
index 429690757923..a6fc4d7e47fd 100644
--- a/drivers/clk/samsung/clk-gs101.c
+++ b/drivers/clk/samsung/clk-gs101.c
@@ -3951,20 +3951,18 @@ static const struct samsung_gate_clock peric0_gate_clks[] __initconst = {
"gout_peric0_peric0_top0_pclk_9", "mout_peric0_bus_user",
CLK_CON_GAT_GOUT_BLK_PERIC0_UID_PERIC0_TOP0_IPCLKPORT_PCLK_9,
21, 0, 0),
- /* Disabling this clock makes the system hang. Mark the clock as critical. */
GATE(CLK_GOUT_PERIC0_PERIC0_TOP1_IPCLK_0,
"gout_peric0_peric0_top1_ipclk_0", "dout_peric0_usi0_uart",
CLK_CON_GAT_GOUT_BLK_PERIC0_UID_PERIC0_TOP1_IPCLKPORT_IPCLK_0,
- 21, CLK_IS_CRITICAL, 0),
+ 21, 0, 0),
GATE(CLK_GOUT_PERIC0_PERIC0_TOP1_IPCLK_2,
"gout_peric0_peric0_top1_ipclk_2", "dout_peric0_usi14_usi",
CLK_CON_GAT_GOUT_BLK_PERIC0_UID_PERIC0_TOP1_IPCLKPORT_IPCLK_2,
21, CLK_SET_RATE_PARENT, 0),
- /* Disabling this clock makes the system hang. Mark the clock as critical. */
GATE(CLK_GOUT_PERIC0_PERIC0_TOP1_PCLK_0,
"gout_peric0_peric0_top1_pclk_0", "mout_peric0_bus_user",
CLK_CON_GAT_GOUT_BLK_PERIC0_UID_PERIC0_TOP1_IPCLKPORT_PCLK_0,
- 21, CLK_IS_CRITICAL, 0),
+ 21, 0, 0),
GATE(CLK_GOUT_PERIC0_PERIC0_TOP1_PCLK_2,
"gout_peric0_peric0_top1_pclk_2", "mout_peric0_bus_user",
CLK_CON_GAT_GOUT_BLK_PERIC0_UID_PERIC0_TOP1_IPCLKPORT_PCLK_2,
--
2.45.2.993.g49e7a77208-goog
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally
2024-07-12 17:09 ` [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally André Draszik
@ 2024-07-18 20:46 ` Stephen Boyd
2024-07-25 7:14 ` André Draszik
0 siblings, 1 reply; 8+ messages in thread
From: Stephen Boyd @ 2024-07-18 20:46 UTC (permalink / raw)
To: Alim Akhtar, André Draszik, Chanwoo Choi,
Krzysztof Kozlowski, Michael Turquette, Peter Griffin,
Sam Protsenko, Sylwester Nawrocki, Tudor Ambarus
Cc: Tudor Ambarus, Will McVicker, kernel-team, linux-arm-kernel,
linux-samsung-soc, linux-clk, linux-kernel, André Draszik
Quoting André Draszik (2024-07-12 10:09:43)
> diff --git a/drivers/clk/samsung/clk-gs101.c b/drivers/clk/samsung/clk-gs101.c
> index 85098c61c15e..429690757923 100644
> --- a/drivers/clk/samsung/clk-gs101.c
> +++ b/drivers/clk/samsung/clk-gs101.c
> @@ -4381,6 +4386,99 @@ static const struct samsung_cmu_info peric1_cmu_info __initconst = {
>
> /* ---- platform_driver ----------------------------------------------------- */
>
> +static struct {
> + struct mutex lock;
> +
> + bool bump_refs;
> +
> + struct clk **clks;
> + size_t n_clks;
> +} gs101_stdout_clks __initdata = {
> + .lock = __MUTEX_INITIALIZER(gs101_stdout_clks.lock),
> +};
> +
> +static int __init gs101_keep_uart_clocks_param(char *str)
> +{
> + gs101_stdout_clks.bump_refs = true;
> + return 0;
> +}
> +early_param("earlycon", gs101_keep_uart_clocks_param);
> +
> +static void __init gs101_bump_uart_clock_references(void)
> +{
> + size_t n_clks;
> +
> + /* We only support device trees - do nothing if not available. */
> + if (!IS_ENABLED(CONFIG_OF))
> + return;
> +
> + n_clks = of_clk_get_parent_count(of_stdout);
> + if (!n_clks || !of_stdout)
> + return;
I don't see anything in here that's driver specific. Please move this to
the clk framework, hook something like of_clk_add_provider() similar to
how of_clk_set_defaults(), and have it look at the of_stdout node for
'clocks' to munge the clks in the core framework for the serial console.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/2] gs101 oriole: UART clock fixes
2024-07-12 17:09 [PATCH v4 0/2] gs101 oriole: UART clock fixes André Draszik
2024-07-12 17:09 ` [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally André Draszik
2024-07-12 17:09 ` [PATCH v4 2/2] clk: samsung: gs101: don't mark non-essential (UART) clocks critical André Draszik
@ 2024-07-18 20:55 ` Stephen Boyd
2024-07-25 7:12 ` André Draszik
2 siblings, 1 reply; 8+ messages in thread
From: Stephen Boyd @ 2024-07-18 20:55 UTC (permalink / raw)
To: Alim Akhtar, André Draszik, Chanwoo Choi,
Krzysztof Kozlowski, Michael Turquette, Peter Griffin,
Sam Protsenko, Sylwester Nawrocki, Tudor Ambarus
Cc: Tudor Ambarus, Will McVicker, kernel-team, linux-arm-kernel,
linux-samsung-soc, linux-clk, linux-kernel, André Draszik
Quoting André Draszik (2024-07-12 10:09:42)
> Hi,
>
> This series fixes a long-standing issue in the gs101 clocking / uart
> handling.
>
> We can now disable clocks that had previously been marked critical, and
> still get a working earlycon.
>
> There is a preparatory patch, and then a patch to drop an incorrect clock
> counting work-around. That 2nd patch is essentially the last remaining patch
> [1] with all review comments addressed, from the series [2] that was sent
> earlier this year, see lore links below.
Is there a binding update for the chosen node to have a clocks property?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/2] gs101 oriole: UART clock fixes
2024-07-18 20:55 ` [PATCH v4 0/2] gs101 oriole: UART clock fixes Stephen Boyd
@ 2024-07-25 7:12 ` André Draszik
2024-07-26 16:44 ` Stephen Boyd
0 siblings, 1 reply; 8+ messages in thread
From: André Draszik @ 2024-07-25 7:12 UTC (permalink / raw)
To: Stephen Boyd, Alim Akhtar, Chanwoo Choi, Krzysztof Kozlowski,
Michael Turquette, Peter Griffin, Sam Protsenko,
Sylwester Nawrocki, Tudor Ambarus
Cc: Will McVicker, kernel-team, linux-arm-kernel, linux-samsung-soc,
linux-clk, linux-kernel
Hi Stephen,
On Thu, 2024-07-18 at 13:55 -0700, Stephen Boyd wrote:
> Quoting André Draszik (2024-07-12 10:09:42)
> > Hi,
> >
> > This series fixes a long-standing issue in the gs101 clocking / uart
> > handling.
> >
> > We can now disable clocks that had previously been marked critical, and
> > still get a working earlycon.
> >
> > There is a preparatory patch, and then a patch to drop an incorrect clock
> > counting work-around. That 2nd patch is essentially the last remaining patch
> > [1] with all review comments addressed, from the series [2] that was sent
> > earlier this year, see lore links below.
>
> Is there a binding update for the chosen node to have a clocks property?
I didn't think that was necessary (and no, I don't have a binding update at
the moment). It gets the clock associated with the serial port (of_stdout),
if any, and works off that.
Did I miss something?
Cheers,
Andre
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally
2024-07-18 20:46 ` Stephen Boyd
@ 2024-07-25 7:14 ` André Draszik
0 siblings, 0 replies; 8+ messages in thread
From: André Draszik @ 2024-07-25 7:14 UTC (permalink / raw)
To: Stephen Boyd, Alim Akhtar, Chanwoo Choi, Krzysztof Kozlowski,
Michael Turquette, Peter Griffin, Sam Protsenko,
Sylwester Nawrocki, Tudor Ambarus
Cc: Will McVicker, kernel-team, linux-arm-kernel, linux-samsung-soc,
linux-clk, linux-kernel
Hi Stephen,
On Thu, 2024-07-18 at 13:46 -0700, Stephen Boyd wrote:
> I don't see anything in here that's driver specific. Please move this to
> the clk framework, hook something like of_clk_add_provider() similar to
> how of_clk_set_defaults(), and have it look at the of_stdout node for
> 'clocks' to munge the clks in the core framework for the serial console.
That makes sense, I'll have a stab at that instead.
Cheers,
Andre'
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v4 0/2] gs101 oriole: UART clock fixes
2024-07-25 7:12 ` André Draszik
@ 2024-07-26 16:44 ` Stephen Boyd
0 siblings, 0 replies; 8+ messages in thread
From: Stephen Boyd @ 2024-07-26 16:44 UTC (permalink / raw)
To: Alim Akhtar, André Draszik, Chanwoo Choi,
Krzysztof Kozlowski, Michael Turquette, Peter Griffin,
Sam Protsenko, Sylwester Nawrocki, Tudor Ambarus
Cc: Will McVicker, kernel-team, linux-arm-kernel, linux-samsung-soc,
linux-clk, linux-kernel
Quoting André Draszik (2024-07-25 00:12:48)
>
> I didn't think that was necessary (and no, I don't have a binding update at
> the moment). It gets the clock associated with the serial port (of_stdout),
> if any, and works off that.
>
> Did I miss something?
No, I missed it. I was thinking it was the chosen node but it's actually
the serial node.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-07-26 16:44 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-12 17:09 [PATCH v4 0/2] gs101 oriole: UART clock fixes André Draszik
2024-07-12 17:09 ` [PATCH v4 1/2] clk: samsung: gs101: allow earlycon to work unconditionally André Draszik
2024-07-18 20:46 ` Stephen Boyd
2024-07-25 7:14 ` André Draszik
2024-07-12 17:09 ` [PATCH v4 2/2] clk: samsung: gs101: don't mark non-essential (UART) clocks critical André Draszik
2024-07-18 20:55 ` [PATCH v4 0/2] gs101 oriole: UART clock fixes Stephen Boyd
2024-07-25 7:12 ` André Draszik
2024-07-26 16:44 ` Stephen Boyd
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).