Hi3660: enable sp804 timer
Subsystems (3)
v3 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 subset of crgctrl clock regiseration to CLK_OF_DECLARE_DRIVER method so ensure timer clock is avaiable when timer probing. 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 v2:
* According to Stephen's suggestion, only changed necessary clocks of fixed_rate_clks to CLK_OF_DECLARE_DRIVER method.
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: register fixed_rate_clks 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 | 48 ++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 10 deletions(-)
Signature · 1 line
1.9.1
PATCH v3 1/2 clk: Hi3660: register fixed_rate_clks 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 timerOn 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 split crgctrl clocks into two subsets. One part is for fixed_rate_clks which includes pre-defined fixed rate clocks, and "osc32k" clock is in this category; So we change their registration to CLK_OF_DECLARE_DRIVER method, as result the clocks can be registered ahead with function of_clk_init() and timer driver can bind timer clock successfully; the rest of the crgctrl clocks are still registered by the probe of the platform driver.
This patch also adds checking for all crgctrl clocks registration and print out log if any clock has failure.
--- drivers/clk/hisilicon/clk-hi3660.c | 48 ++++++++++++++++++++++++++++++-------- 1 file changed, 38 insertions(+), 10 deletions(-)
drivers/clk/hisilicon/clk-hi3660.c +38 -10
@@ -452,6 +452,8 @@ CLK_SET_RATE_PARENT, 0x90, 0, 0, }, }; +static struct hisi_clock_data *clk_crgctrl_data; +static void hi3660_clk_iomcu_init (struct device_node *np) {struct hisi_clock_data *clk_data;
@@ -514,38 +516,64 @@ static void hi3660_clk_sctrl_init(struct device_node *np) clk_data); } -static void hi3660_clk_crgctrl_init (struct device_node *np) +static void hi3660_clk_crgctrl_early_init (struct device_node *np) { -struct hisi_clock_data *clk_data;int nr =ARRAY_SIZE (hi3660_fixed_rate_clks) +ARRAY_SIZE (hi3660_crgctrl_gate_sep_clks) +ARRAY_SIZE (hi3660_crgctrl_gate_clks) +ARRAY_SIZE (hi3660_crgctrl_mux_clks) +ARRAY_SIZE (hi3660_crg_fixed_factor_clks) +ARRAY_SIZE (hi3660_crgctrl_divider_clks); +int i; - clk_data =hisi_clk_init (np, nr); -if (!clk_data) + clk_crgctrl_data =hisi_clk_init (np, nr); +if (!clk_crgctrl_data)return ; +for (i =0 ; i < nr; i++) + clk_crgctrl_data->clk_data.clks[i] =ERR_PTR (-EPROBE_DEFER ); +hisi_clk_register_fixed_rate (hi3660_fixed_rate_clks,ARRAY_SIZE (hi3660_fixed_rate_clks), - clk_data); + clk_crgctrl_data); +} +CLK_OF_DECLARE_DRIVER (hi3660_clk_crgctrl,"hisilicon,hi3660-crgctrl" , + hi3660_clk_crgctrl_early_init); + +static void hi3660_clk_crgctrl_init (struct device_node *np) +{ +struct clk **clks; +int i; + +if (!clk_crgctrl_data) +hi3660_clk_crgctrl_early_init (np); + +/* clk_crgctrl_data initialization failed */ +if (!clk_crgctrl_data) +return ; +hisi_clk_register_gate_sep (hi3660_crgctrl_gate_sep_clks,ARRAY_SIZE (hi3660_crgctrl_gate_sep_clks), - clk_data); + clk_crgctrl_data);hisi_clk_register_gate (hi3660_crgctrl_gate_clks,ARRAY_SIZE (hi3660_crgctrl_gate_clks), - clk_data); + clk_crgctrl_data);hisi_clk_register_mux (hi3660_crgctrl_mux_clks,ARRAY_SIZE (hi3660_crgctrl_mux_clks), - clk_data); + clk_crgctrl_data);hisi_clk_register_fixed_factor (hi3660_crg_fixed_factor_clks,ARRAY_SIZE (hi3660_crg_fixed_factor_clks), - clk_data); + clk_crgctrl_data);hisi_clk_register_divider (hi3660_crgctrl_divider_clks,ARRAY_SIZE (hi3660_crgctrl_divider_clks), - clk_data); + clk_crgctrl_data); + + clks = clk_crgctrl_data->clk_data.clks; +for (i =0 ; i < clk_crgctrl_data->clk_data.clk_num; i++) { +if (IS_ERR (clks[i]) &&PTR_ERR (clks[i]) != -EPROBE_DEFER ) +pr_err ("Failed to register crgctrl clock[%d] err=%ld\n" , + i,PTR_ERR (clks[i])); + } }static const struct of_device_id hi3660_clk_match_table[] = {
Signature · 1 line
1.9.1
Stephen Boyd
AppliedRe: [PATCH v3 1/2] clk: Hi3660: register fixed_rate_clks with CLK_OF_DECLARE_DRIVER
Quoted 22 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 timerOn Hi3660 the sp804 timer uses clock "osc32k", this clock is registered as platform driver rather than
CLK_OF_DECLARE_DRIVERmethod. As result, sp804 timer probe returns failure due if cannot bind clock properly.To fix the failure, this patch is to split crgctrl clocks into two subsets. One part is for
fixed_rate_clkswhich includes pre-defined fixed rate clocks, and "osc32k" clock is in this category; So we change their registration toCLK_OF_DECLARE_DRIVERmethod, as result the clocks can be registered ahead with functionof_clk_init()and timer driver can bind timer clock successfully; the rest of the crgctrl clocks are still registered by the probe of the platform driver.
Quoted 5 lines
This patch also adds checking for all crgctrl clocks registration and print out log if any clock has failure.
Signed-off-by Leo Yan <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 1/2] clk: Hi3660: register fixed_rate_clks with CLK_OF_DECLARE_DRIVER
Quoted 23 lines · Stephen Boyd
Quoted 22 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 timerOn Hi3660 the sp804 timer uses clock "osc32k", this clock is registered as platform driver rather than
CLK_OF_DECLARE_DRIVERmethod. As result, sp804 timer probe returns failure due if cannot bind clock properly.To fix the failure, this patch is to split crgctrl clocks into two subsets. One part is for
fixed_rate_clkswhich includes pre-defined fixed rate clocks, and "osc32k" clock is in this category; So we change their registration toCLK_OF_DECLARE_DRIVERmethod, as result the clocks can be registered ahead with functionof_clk_init()and timer driver can bind timer clock successfully; the rest of the crgctrl clocks are still registered by the probe of the platform driver.
Quoted 7 lines
Quoted 5 lines
This patch also adds checking for all crgctrl clocks registration and print out log if any clock has failure.
Signed-off-by Leo Yan <[email protected]>---
Applied to clk-next
Thanks!
Quoted 3 lines
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v3 2/2 arm64: dts: add sp804 timer node for Hi3660
In reply to Leo YanThe 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
@@ -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
Wei Xu
maintainerRe: [PATCH v3 2/2] arm64: dts: add sp804 timer node for Hi3660
Hi Leo,
Quoted 28 lines · 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.
Suggested-by Daniel Lezcano <[email protected]>Acked-by Daniel Lezcano <[email protected]>Signed-off-by Leo Yan <[email protected]>--- arch/arm64/boot/dts/hisilicon/hi3660.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/arm64/boot/dts/hisilicon/hi3660.dtsi +4
-0@@ -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>,
arch/arm64/boot/dts/hisilicon/hi3660.dtsi line 189
Quoted 10 lines
arch/arm64/boot/dts/hisilicon/hi3660.dtsi +7
-0+ <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 */
Since the dts part is not depended on the driver and Guodong has put this into another patch set[1], I will pick up that one.
Thanks!
[1]: https://lkml.org/lkml/2017/6/14/1049
BR,
Wei
Re: [PATCH v3 2/2] arm64: dts: add sp804 timer node for Hi3660
On Thu, Jun 15, 2017 at 09:00:58PM +0100, Wei Xu wrote:
[...]
Quoted 5 lines
Since the dts part is not depended on the driver and Guodong has put this into another patch set[1], I will pick up that one.
Thanks!
Yeah, thanks for picking up from Guodong's patch set.
Thanks,
Leo Yan