Skip to contentSkip to conversation

Hi3660: enable sp804 timer

PATCH Superseded Leo Yan 3 participants 7 messages May 18, 2017 – May 19, 2017

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Leo Yan

author
#0 lore raw

v2 cover Hi3660: enable sp804 timer

This patch set is to enable sp804 timer on Hi3660 for Hikey960 platform.

On Hi3660, the sp804 timer co-exists with CPUs' architecture timer; but sp804 timer is located in SoC level but CPU's architecture timer is in CPU power domain. sp804 timer is used as broadcast timer when CPU enters idle states and the CPU (includes architecture timer) power domain is powered off. So sp804 timer enabling is prerequisite before we enable CPUIdle on Hi3660.

This patch set is to enable sp804 timer, the first patch is to adjust crgctrl clock regiseration so ensure clock is avaiable for timer. The second patch is to add description for timer in dts. Have rebased this patch set on Guodong's dts patch set [1] and verified this patch set on Hikey960.

[1] http://archive.armlinux.org.uk/lurker/message/20170517.083733.8207a50e.en.html

Changes from v1:
* Follow Steven's suggestion on IRC, Change to only use CLK_OF_DECLARE_DRIVER for crgctrl clock.

Leo Yan (2):
clk: Hi3660: change to register crgctrl clock with
CLK_OF_DECLARE_DRIVER
arm64: dts: add sp804 timer node for Hi3660

 arch/arm64/boot/dts/hisilicon/hi3660.dtsi | 11 +++++++++++
 drivers/clk/hisilicon/clk-hi3660.c        |  4 ++--
 2 files changed, 13 insertions(+), 2 deletions(-)
Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v2 1/2 clk: Hi3660: change to register crgctrl clock with CLK_OF_DECLARE_DRIVER

The timer will register into system at very early phase at kernel boot; if timer needs to use clock, the clock should be get ready in function of_clk_init() so later the timer driver probe can retrieve clock successfully. This is finished in below flow on arm64:

start_kernel()

    `-> time_init()
          `-> of_clk_init(NULL)    => register timer's clock
          `-> clocksource_probe()  => register timer

On Hi3660 the sp804 timer uses clock "osc32k", this clock is registered as platform driver rather than CLK_OF_DECLARE_DRIVER method. As result, sp804 timer probe returns failure due if cannot bind clock properly. To fix the failure, this patch is to change crgctrl clock registration from platform driver to CLK_OF_DECLARE_DRIVER method so the clocks can be registered ahead with function of_clk_init() and then timer driver can use it.

---
 drivers/clk/hisilicon/clk-hi3660.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/hisilicon/clk-hi3660.c +2 -2
index fd5ce7f..4e5713b 100644
@@ -547,10 +547,10 @@ static void hi3660_clk_crgctrl_init(struct device_node *np)
 				  ARRAY_SIZE(hi3660_crgctrl_divider_clks),
 				  clk_data);
 }
+CLK_OF_DECLARE_DRIVER(hi3660_clk_crgctrl, "hisilicon,hi3660-crgctrl",
+		      hi3660_clk_crgctrl_init);
 
 static const struct of_device_id hi3660_clk_match_table[] = {
-	{ .compatible = "hisilicon,hi3660-crgctrl",
-	  .data = hi3660_clk_crgctrl_init },
 	{ .compatible = "hisilicon,hi3660-pctrl",
 	  .data = hi3660_clk_pctrl_init },
 	{ .compatible = "hisilicon,hi3660-pmuctrl",
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v2 1/2] clk: Hi3660: change to register crgctrl clock with CLK_OF_DECLARE_DRIVER

Quoted 30 lines · Leo Yan

The timer will register into system at very early phase at kernel boot; if timer needs to use clock, the clock should be get ready in function of_clk_init() so later the timer driver probe can retrieve clock successfully. This is finished in below flow on arm64:

start_kernel()

    `-> time_init()
          `-> of_clk_init(NULL)    => register timer's clock
          `-> clocksource_probe()  => register timer

On Hi3660 the sp804 timer uses clock "osc32k", this clock is registered as platform driver rather than CLK_OF_DECLARE_DRIVER method. As result, sp804 timer probe returns failure due if cannot bind clock properly. To fix the failure, this patch is to change crgctrl clock registration from platform driver to CLK_OF_DECLARE_DRIVER method so the clocks can be registered ahead with function of_clk_init() and then timer driver can use it.

---
 drivers/clk/hisilicon/clk-hi3660.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/hisilicon/clk-hi3660.c +0 -0
index fd5ce7f..4e5713b 100644
@@ -547,10 +547,10 @@ static void hi3660_clk_crgctrl_init(struct device_node *np)
 				  ARRAY_SIZE(hi3660_crgctrl_divider_clks),
 				  clk_data);

drivers/clk/hisilicon/clk-hi3660.c static void hi3660_clk_crgctrl_init(struct device_node *np) · line 556

Quoted 10 lines
drivers/clk/hisilicon/clk-hi3660.c +2 -2
 }
+CLK_OF_DECLARE_DRIVER(hi3660_clk_crgctrl, "hisilicon,hi3660-crgctrl",
+		      hi3660_clk_crgctrl_init);
 
 static const struct of_device_id hi3660_clk_match_table[] = {
-	{ .compatible = "hisilicon,hi3660-crgctrl",
-	  .data = hi3660_clk_crgctrl_init },
 	{ .compatible = "hisilicon,hi3660-pctrl",
 	  .data = hi3660_clk_pctrl_init },
 	{ .compatible = "hisilicon,hi3660-pmuctrl",

Why not do the change for all the clocks and remove the hi3660_clk_match_table[]? and all the related platform driver code?

That will be consistent with the other clk-hi* drivers.

Signature · 5 lines
 <http://www.linaro.org/> Linaro.org ? Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
author
#3 lore raw

Re: [PATCH v2 1/2] clk: Hi3660: change to register crgctrl clock with CLK_OF_DECLARE_DRIVER

Hi Daniel,

Quoted 45 lines · Daniel Lezcano
Quoted 30 lines · Leo Yan

The timer will register into system at very early phase at kernel boot; if timer needs to use clock, the clock should be get ready in function of_clk_init() so later the timer driver probe can retrieve clock successfully. This is finished in below flow on arm64:

start_kernel()

    `-> time_init()
          `-> of_clk_init(NULL)    => register timer's clock
          `-> clocksource_probe()  => register timer

On Hi3660 the sp804 timer uses clock "osc32k", this clock is registered as platform driver rather than CLK_OF_DECLARE_DRIVER method. As result, sp804 timer probe returns failure due if cannot bind clock properly. To fix the failure, this patch is to change crgctrl clock registration from platform driver to CLK_OF_DECLARE_DRIVER method so the clocks can be registered ahead with function of_clk_init() and then timer driver can use it.

---
 drivers/clk/hisilicon/clk-hi3660.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/hisilicon/clk-hi3660.c +0 -0
index fd5ce7f..4e5713b 100644
@@ -547,10 +547,10 @@ static void hi3660_clk_crgctrl_init(struct device_node *np)
 				  ARRAY_SIZE(hi3660_crgctrl_divider_clks),
 				  clk_data);

drivers/clk/hisilicon/clk-hi3660.c static void hi3660_clk_crgctrl_init(struct device_node *np) · line 556

Quoted 10 lines
drivers/clk/hisilicon/clk-hi3660.c +2 -2
 }
+CLK_OF_DECLARE_DRIVER(hi3660_clk_crgctrl, "hisilicon,hi3660-crgctrl",
+		      hi3660_clk_crgctrl_init);
 
 static const struct of_device_id hi3660_clk_match_table[] = {
-	{ .compatible = "hisilicon,hi3660-crgctrl",
-	  .data = hi3660_clk_crgctrl_init },
 	{ .compatible = "hisilicon,hi3660-pctrl",
 	  .data = hi3660_clk_pctrl_init },
 	{ .compatible = "hisilicon,hi3660-pmuctrl",

Why not do the change for all the clocks and remove the hi3660_clk_match_table[]? and all the related platform driver code?

Quoted 1 line

That will be consistent with the other clk-hi* drivers.

I checked a bit with Stephen on IRC, follow the suggestion to 'split the clks are registsered between CLK_OF_DECLARE_DRIVER() and driver probe so that the ones you need really early are done through the CLK_OF path and the other ones are done through regular driver probe'.

Also checked for mainline kernel, now there have some examples,
like: drivers/clk/mediatek/clk-mt2701.c.

Thanks,
Leo Yan

#4 lore raw

Re: [PATCH v2 1/2] clk: Hi3660: change to register crgctrl clock with CLK_OF_DECLARE_DRIVER

In reply to Leo Yan
Quoted 5 lines · Leo Yan
drivers/clk/hisilicon/clk-hi3660.c +0 -0
index fd5ce7f..4e5713b 100644

drivers/clk/hisilicon/clk-hi3660.c static void hi3660_clk_crgctrl_init(struct device_node *np) · line 553

Quoted 9 lines
drivers/clk/hisilicon/clk-hi3660.c +2 -2
@@ -547,10 +547,10 @@ static void hi3660_clk_crgctrl_init(struct device_node *np)
 				  ARRAY_SIZE(hi3660_crgctrl_divider_clks),
 				  clk_data);
 }
+CLK_OF_DECLARE_DRIVER(hi3660_clk_crgctrl, "hisilicon,hi3660-crgctrl",
+		      hi3660_clk_crgctrl_init);
 
 static const struct of_device_id hi3660_clk_match_table[] = {
-	{ .compatible = "hisilicon,hi3660-crgctrl",
-	  .data = hi3660_clk_crgctrl_init },

I'm slightly confused. CLK_OF_DECLARE_DRIVER is for when a platform driver _and_ CLK_OF_DELARE need to "probe" the same device node. But in this patch, the compatible string is being deleted from the driver's match table. Also, are all the registered in hi3660_clk_crgctrl_init() actually needed for the timer? If only a subset, then I would expect to split the code and have the CLK_OF_DECLARE_DRIVER() path register just the clks that matter for the timer, and then leave the rest of the clks to be registered by the probe of the platform driver.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#5 lore raw

Re: [PATCH v2 1/2] clk: Hi3660: change to register crgctrl clock with CLK_OF_DECLARE_DRIVER

Quoted 12 lines · Stephen Boyd
Quoted 11 lines · Leo Yan
drivers/clk/hisilicon/clk-hi3660.c +2 -0
index fd5ce7f..4e5713b 100644
@@ -547,10 +547,10 @@ static void hi3660_clk_crgctrl_init(struct device_node *np)
 				  ARRAY_SIZE(hi3660_crgctrl_divider_clks),
 				  clk_data);
 }
+CLK_OF_DECLARE_DRIVER(hi3660_clk_crgctrl, "hisilicon,hi3660-crgctrl",
+		      hi3660_clk_crgctrl_init);
 
Quoted 10 lines

drivers/clk/hisilicon/clk-hi3660.c static void hi3660_clk_crgctrl_init(struct device_node *np) · line 553

Quoted 3 lines
drivers/clk/hisilicon/clk-hi3660.c +0 -2
 static const struct of_device_id hi3660_clk_match_table[] = {
-	{ .compatible = "hisilicon,hi3660-crgctrl",
-	  .data = hi3660_clk_crgctrl_init },

I'm slightly confused. CLK_OF_DECLARE_DRIVER is for when a platform driver _and_ CLK_OF_DELARE need to "probe" the same device node. But in this patch, the compatible string is being deleted from the driver's match table. Also, are all the registered in hi3660_clk_crgctrl_init() actually needed for the timer?

No.

Quoted 4 lines

If only a subset, then I would expect to split the code and have the CLK_OF_DECLARE_DRIVER() path register just the clks that matter for the timer, and then leave the rest of the clks to be registered by the probe of the platform driver.

I'm also puzzled if need divide crgctrl clock into two parts. Thanks for suggestion, will do this.

Thanks,
Leo Yan

author
#6 lore raw

PATCH v2 2/2 arm64: dts: add sp804 timer node for Hi3660

In reply to Leo Yan

The Hi3660 SoC comes with the sp804 timer in addition to the architecture timers. These ones are shutdown when reaching a deep idle states and a backup timer is needed. The sp804 belongs to another power domain and can fulfill the purpose of replacing temporarily an architecture timer when the CPU is idle.

Describe it in the device tree, so it can be enabled at boot time.

---
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/hisilicon/hi3660.dtsi +11 -0
index 138fcba..f75c792 100644
@@ -173,6 +173,17 @@
 			#clock-cells = <1>;
 		};
 
+		dual_timer0: timer at fff14000 {
+			compatible = "arm,sp804", "arm,primecell";
+			reg = <0x0 0xfff14000 0x0 0x1000>;
+			interrupts = <GIC_SPI 48 IRQ_TYPE_LEVEL_HIGH>,
+				     <GIC_SPI 49 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&crg_ctrl HI3660_OSC32K>,
+				 <&crg_ctrl HI3660_OSC32K>,
+				 <&crg_ctrl HI3660_OSC32K>;
+			clock-names = "timer1", "timer2", "apb_pclk";
+		};
+
 		ufs: ufs at ff3b0000 {
 			compatible = "jedec,ufs-1.1", "hisilicon,hi3660-ufs";
 			reg = <0x0 0xff3b0000 0x0 0x1000>, /* 0: HCI standard */
Signature · 1 line
1.9.1