Skip to contentSkip to conversation

dt-bindings: timer: mtk-timer: add optional 13m and bus clock

PATCH In review Fabien Parent 2 participants 5 messages Oct 17, 2020 – Oct 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 dt-bindings: timer: mtk-timer: add optional 13m and bus clock

The timer IP on MT8516 requires two clocks to be enabled. Add both clocks.

---
 .../devicetree/bindings/timer/mediatek,mtk-timer.txt         | 5 +++++
 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/timer/mediatek,mtk-timer.txt +5 -0
index 690a9c0966ac..3f9bfd246f19 100644
@@ -29,6 +29,11 @@ Required properties:
 - reg: Should contain location and length for timer register.
 - clocks: Should contain system clock.
 
+Optional properties:
+- clock-names: May contain:
+	* "clk13m": 13MHz clock system clock
+	* "bus": Bus clock
+
 Examples:
 
 	timer@10008000 {
Signature · 1 line
2.28.0
#1 lore raw

PATCH 2/2 clocksource: mediatek: add clk13m and bus clock support

Some MediaTek SoC like MT8516 need to enable additional clocks for the GPT timer. Enable them if present.

---
 drivers/clocksource/timer-mediatek.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/clocksource/timer-mediatek.c +12 -0
index 9318edcd8963..42e2d2090484 100644
@@ -9,6 +9,7 @@
 
 #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
 
+#include <linux/clk.h>
 #include <linux/clockchips.h>
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
@@ -278,8 +279,19 @@ static int __init mtk_syst_init(struct device_node *node)
 
 static int __init mtk_gpt_init(struct device_node *node)
 {
+	struct clk *clk_13m, *clk_bus;
 	int ret;
 
+	/* Optional clock*/
+	clk_13m = of_clk_get_by_name(node, "clk13m");
+	if (!IS_ERR(clk_13m))
+		clk_prepare_enable(clk_13m);
+
+	/* Optional clock*/
+	clk_bus = of_clk_get_by_name(node, "bus");
+	if (!IS_ERR(clk_bus))
+		clk_prepare_enable(clk_bus);
+
 	to.clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
 	to.clkevt.set_state_shutdown = mtk_gpt_clkevt_shutdown;
 	to.clkevt.set_state_periodic = mtk_gpt_clkevt_set_periodic;
Signature · 1 line
2.28.0
maintainer
#2 lore raw

Re: [PATCH 2/2] clocksource: mediatek: add clk13m and bus clock support

Quoted 21 lines · Fabien Parent

Some MediaTek SoC like MT8516 need to enable additional clocks for the GPT timer. Enable them if present.

---
 drivers/clocksource/timer-mediatek.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/clocksource/timer-mediatek.c +1 -0
index 9318edcd8963..42e2d2090484 100644
@@ -9,6 +9,7 @@
 
 #define pr_fmt(fmt)	KBUILD_MODNAME ": " fmt
 
+#include <linux/clk.h>
 #include <linux/clockchips.h>
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>

drivers/clocksource/timer-mediatek.c static int __init mtk_syst_init(struct device_node *node) · line 285

Quoted 7 lines
drivers/clocksource/timer-mediatek.c +2 -0
@@ -278,8 +279,19 @@ static int __init mtk_syst_init(struct device_node *node)
 
 static int __init mtk_gpt_init(struct device_node *node)
 {
+	struct clk *clk_13m, *clk_bus;
 	int ret;
 
+	/* Optional clock*/

Then use the optional api variant.

drivers/clocksource/timer-mediatek.c static int __init mtk_syst_init(struct device_node *node) · line 287

Quoted 2 lines
drivers/clocksource/timer-mediatek.c +2 -0
+	clk_13m = of_clk_get_by_name(node, "clk13m");
+	if (!IS_ERR(clk_13m))

And then you can drop this check (or handle it for any error other than clock is not present).

Quoted 13 lines
drivers/clocksource/timer-mediatek.c +7 -0
+		clk_prepare_enable(clk_13m);
+
+	/* Optional clock*/
+	clk_bus = of_clk_get_by_name(node, "bus");
+	if (!IS_ERR(clk_bus))
+		clk_prepare_enable(clk_bus);
+
 	to.clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
 	to.clkevt.set_state_shutdown = mtk_gpt_clkevt_shutdown;
 	to.clkevt.set_state_periodic = mtk_gpt_clkevt_set_periodic;
Signature · 1 line
2.28.0

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#3 lore raw

Re: [PATCH 2/2] clocksource: mediatek: add clk13m and bus clock support

Hi Rob,

Quoted 24 lines · Rob Herring
Quoted 22 lines · Fabien Parent

Some MediaTek SoC like MT8516 need to enable additional clocks for the GPT timer. Enable them if present.

---
 drivers/clocksource/timer-mediatek.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/clocksource/timer-mediatek.c +1 -0
index 9318edcd8963..42e2d2090484 100644
@@ -9,6 +9,7 @@
 
 #define pr_fmt(fmt)  KBUILD_MODNAME ": " fmt
 
+#include <linux/clk.h>
 #include <linux/clockchips.h>
 #include <linux/clocksource.h>
 #include <linux/interrupt.h>
@@ -278,8 +279,19 @@ static int __init mtk_syst_init(struct device_node *node)
 
Quoted 8 lines

drivers/clocksource/timer-mediatek.c static int __init mtk_syst_init(struct device_node *node) · line 285

Quoted 6 lines
drivers/clocksource/timer-mediatek.c +2 -0
 static int __init mtk_gpt_init(struct device_node *node)
 {
+     struct clk *clk_13m, *clk_bus;
      int ret;
 
+     /* Optional clock*/

Then use the optional api variant.

I looked for optional API variant but could only find these:
* struct clk *devm_clk_get_optional(struct device *dev, const char *id);
* struct clk *devm_clk_get_optional(struct device *dev, const char *id);

These two require a "struct device" parameter but in the function mtk_gpt_init, we only have a "struct device_node" I didn't see any way to get a "struct device" from a "struct device_node".

Quoted 20 lines

drivers/clocksource/timer-mediatek.c static int __init mtk_syst_init(struct device_node *node) · line 287

Quoted 3 lines
drivers/clocksource/timer-mediatek.c +2 -0
+     clk_13m = of_clk_get_by_name(node, "clk13m");
+     if (!IS_ERR(clk_13m))

And then you can drop this check (or handle it for any error other than clock is not present).

Quoted 13 lines
drivers/clocksource/timer-mediatek.c +7 -1
+             clk_prepare_enable(clk_13m);
+
+     /* Optional clock*/
+     clk_bus = of_clk_get_by_name(node, "bus");
+     if (!IS_ERR(clk_bus))
+             clk_prepare_enable(clk_bus);
+
      to.clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
      to.clkevt.set_state_shutdown = mtk_gpt_clkevt_shutdown;
      to.clkevt.set_state_periodic = mtk_gpt_clkevt_set_periodic;
--

2.28.0

maintainer Acked-by on v1 1/2
#4 lore raw
In reply to Fabien Parent
Quoted 8 lines · Fabien Parent

The timer IP on MT8516 requires two clocks to be enabled. Add both clocks.

---
 .../devicetree/bindings/timer/mediatek,mtk-timer.txt         | 5 +++++
 1 file changed, 5 insertions(+)

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek