devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/3] mips: dts: ingenic: x1000: Add TCU clock to tcu device node
@ 2022-02-24 15:03 Aidan MacDonald
  2022-02-24 15:03 ` [PATCH v3 2/3] mips: dts: ingenic: x1830: " Aidan MacDonald
  2022-02-24 15:03 ` [PATCH v3 3/3] clk: ingenic-tcu: Fix missing TCU clock for X1000 SoC Aidan MacDonald
  0 siblings, 2 replies; 3+ messages in thread
From: Aidan MacDonald @ 2022-02-24 15:03 UTC (permalink / raw)
  To: paul, robh+dt, mturquette, sboyd
  Cc: linux-mips, devicetree, linux-clk, linux-kernel

This should've been present all along, but was omitted due to a
mistake in the driver.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
v1 -> v2: https://lore.kernel.org/linux-mips/20220209230145.18943-1-aidanmacdonald.0x0@gmail.com/
 * Split DTS changes to separate patch.
v2 -> v3: https://lore.kernel.org/linux-mips/20220212150927.39513-1-aidanmacdonald.0x0@gmail.com/
 * Add fallback code if TCU clock is missing
 * Update X1830 devicetree

 arch/mips/boot/dts/ingenic/x1000.dtsi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/mips/boot/dts/ingenic/x1000.dtsi b/arch/mips/boot/dts/ingenic/x1000.dtsi
index 8bd27edef216..c69df8eb158e 100644
--- a/arch/mips/boot/dts/ingenic/x1000.dtsi
+++ b/arch/mips/boot/dts/ingenic/x1000.dtsi
@@ -111,8 +111,9 @@ tcu: timer@10002000 {
 
 		clocks = <&cgu X1000_CLK_RTCLK>,
 			 <&cgu X1000_CLK_EXCLK>,
-			 <&cgu X1000_CLK_PCLK>;
-		clock-names = "rtc", "ext", "pclk";
+			 <&cgu X1000_CLK_PCLK>,
+			 <&cgu X1000_CLK_TCU>;
+		clock-names = "rtc", "ext", "pclk", "tcu";
 
 		interrupt-controller;
 		#interrupt-cells = <1>;
-- 
2.34.1


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

* [PATCH v3 2/3] mips: dts: ingenic: x1830: Add TCU clock to tcu device node
  2022-02-24 15:03 [PATCH v3 1/3] mips: dts: ingenic: x1000: Add TCU clock to tcu device node Aidan MacDonald
@ 2022-02-24 15:03 ` Aidan MacDonald
  2022-02-24 15:03 ` [PATCH v3 3/3] clk: ingenic-tcu: Fix missing TCU clock for X1000 SoC Aidan MacDonald
  1 sibling, 0 replies; 3+ messages in thread
From: Aidan MacDonald @ 2022-02-24 15:03 UTC (permalink / raw)
  To: paul, robh+dt, mturquette, sboyd
  Cc: linux-mips, devicetree, linux-clk, linux-kernel

Like the X1000, the X1830 was missing a TCU clock that belongs here.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
 arch/mips/boot/dts/ingenic/x1830.dtsi | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arch/mips/boot/dts/ingenic/x1830.dtsi b/arch/mips/boot/dts/ingenic/x1830.dtsi
index 2595df8671c7..4408df24ca98 100644
--- a/arch/mips/boot/dts/ingenic/x1830.dtsi
+++ b/arch/mips/boot/dts/ingenic/x1830.dtsi
@@ -104,8 +104,9 @@ tcu: timer@10002000 {
 
 		clocks = <&cgu X1830_CLK_RTCLK>,
 			 <&cgu X1830_CLK_EXCLK>,
-			 <&cgu X1830_CLK_PCLK>;
-		clock-names = "rtc", "ext", "pclk";
+			 <&cgu X1830_CLK_PCLK>,
+			 <&cgu X1830_CLK_TCU>;
+		clock-names = "rtc", "ext", "pclk", "tcu";
 
 		interrupt-controller;
 		#interrupt-cells = <1>;
-- 
2.34.1


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

* [PATCH v3 3/3] clk: ingenic-tcu: Fix missing TCU clock for X1000 SoC
  2022-02-24 15:03 [PATCH v3 1/3] mips: dts: ingenic: x1000: Add TCU clock to tcu device node Aidan MacDonald
  2022-02-24 15:03 ` [PATCH v3 2/3] mips: dts: ingenic: x1830: " Aidan MacDonald
@ 2022-02-24 15:03 ` Aidan MacDonald
  1 sibling, 0 replies; 3+ messages in thread
From: Aidan MacDonald @ 2022-02-24 15:03 UTC (permalink / raw)
  To: paul, robh+dt, mturquette, sboyd
  Cc: linux-mips, devicetree, linux-clk, linux-kernel

The X1000 and X1830 have a TCU clock gate, so pass it to the driver.
Without this the TCU can be gated automatically, which prevents timers
from running.

Add a workaround to allow the driver to probe even if the TCU clock
is missing on the affected SoCs; in this case the TCU clock is ignored,
as it was before. With workarounds like "clk_ignore_unused" on the
kernel command line, this allows users who upgrade the kernel but use
the old device tree to boot successfully. They will now get a warning
encouraging them to update the device tree.

Signed-off-by: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>
---
 drivers/clk/ingenic/tcu.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/drivers/clk/ingenic/tcu.c b/drivers/clk/ingenic/tcu.c
index 77acfbeb4830..03e9553bcac4 100644
--- a/drivers/clk/ingenic/tcu.c
+++ b/drivers/clk/ingenic/tcu.c
@@ -31,6 +31,7 @@ struct ingenic_soc_info {
 	unsigned int num_channels;
 	bool has_ost;
 	bool has_tcu_clk;
+	bool allow_missing_tcu_clk;
 };
 
 struct ingenic_tcu_clk_info {
@@ -320,7 +321,8 @@ static const struct ingenic_soc_info jz4770_soc_info = {
 static const struct ingenic_soc_info x1000_soc_info = {
 	.num_channels = 8,
 	.has_ost = false, /* X1000 has OST, but it not belong TCU */
-	.has_tcu_clk = false,
+	.has_tcu_clk = true,
+	.allow_missing_tcu_clk = true,
 };
 
 static const struct of_device_id __maybe_unused ingenic_tcu_of_match[] __initconst = {
@@ -355,14 +357,29 @@ static int __init ingenic_tcu_probe(struct device_node *np)
 		tcu->clk = of_clk_get_by_name(np, "tcu");
 		if (IS_ERR(tcu->clk)) {
 			ret = PTR_ERR(tcu->clk);
-			pr_crit("Cannot get TCU clock\n");
-			goto err_free_tcu;
-		}
 
-		ret = clk_prepare_enable(tcu->clk);
-		if (ret) {
-			pr_crit("Unable to enable TCU clock\n");
-			goto err_put_clk;
+			/*
+			 * Old versions of this driver incorrectly specified
+			 * some SoCs as not having a TCU clock, so old device
+			 * trees didn't define one. We try to allow the kernel
+			 * to boot with an old device tree by just continuing
+			 * on without the clock and hoping it won't get turned
+			 * off (eg. with "clk_ignore_unused" kernel argument).
+			 */
+			if (ret == -EINVAL &&
+			    tcu->soc_info->allow_missing_tcu_clk) {
+				pr_warn("TCU clock missing from device tree, please update your device tree\n");
+				tcu->clk = NULL;
+			} else {
+				pr_crit("Cannot get TCU clock\n");
+				goto err_free_tcu;
+			}
+		} else {
+			ret = clk_prepare_enable(tcu->clk);
+			if (ret) {
+				pr_crit("Unable to enable TCU clock\n");
+				goto err_put_clk;
+			}
 		}
 	}
 
@@ -432,10 +449,10 @@ static int __init ingenic_tcu_probe(struct device_node *np)
 			clk_hw_unregister(tcu->clocks->hws[i]);
 	kfree(tcu->clocks);
 err_clk_disable:
-	if (tcu->soc_info->has_tcu_clk)
+	if (tcu->clk)
 		clk_disable_unprepare(tcu->clk);
 err_put_clk:
-	if (tcu->soc_info->has_tcu_clk)
+	if (tcu->clk)
 		clk_put(tcu->clk);
 err_free_tcu:
 	kfree(tcu);
-- 
2.34.1


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

end of thread, other threads:[~2022-02-24 15:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-24 15:03 [PATCH v3 1/3] mips: dts: ingenic: x1000: Add TCU clock to tcu device node Aidan MacDonald
2022-02-24 15:03 ` [PATCH v3 2/3] mips: dts: ingenic: x1830: " Aidan MacDonald
2022-02-24 15:03 ` [PATCH v3 3/3] clk: ingenic-tcu: Fix missing TCU clock for X1000 SoC Aidan MacDonald

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