Skip to contentSkip to conversation

Implement clocksource for rockchip SoC using rockchip timer

PATCH Superseded Alexander Kochetkov 3 participants 12 messages Jan 31, 2017 – Mar 21, 2017

Subsystems (3)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover Implement clocksource for rockchip SoC using rockchip timer

From: Alexander Kochetkov <[email protected]>

Hello, Daniel, Heiko.

Here is try 6 :) Thanks a lot for helping me to bring the code into kernel!

This patch series contain:
- devicetree bindings clarification for rockchip timers
- dts files fixes for rk3228-evb, rk3229-evb and rk3188
- implementation of clocksource and sched clock for rockchip SoC

The clock supplying the arm-global-timer on the rk3188 is coming from the the cpu clock itself and thus changes its rate everytime cpufreq adjusts the cpu frequency making this timer unsuitable as a stable clocksource.

The rk3188, rk3288 and following socs share a separate timer block already handled by the rockchip-timer driver. Therefore adapt this driver to also be able to act as clocksource on rk3188.

In order to test clocksource you can run following commands and check how much time it take in real. On rk3188 it take about ~45 seconds.

cpufreq-set -f 1.6GHZ
date; sleep 60; date

rk3288 (and probably anything newer) is irrelevant to this patch, as it has the arch timer interface. This patch may be usefull for Cortex-A9/A5 based parts.

Regards,
Alexander.

Changes in v6:
- Removed Reviewed-by: Heiko St?bner <[email protected]> tag
- Merge 5/8, 6/8, 7/8, 8/9 into single file
- split init paths into rk_clkevt_init() and rk_clksrc_init() so the driver code could be adopted to CLOCKEVENT_OF_DECLARE()
- clockevents implemented using clocksource_mmio_init()
- fixed commit message for 4/8 (thanks a lot Daniel)

Changes in v5:
- Add Acked-by: Rob Herring <[email protected]> to 1/8
http://lists.infradead.org/pipermail/linux-rockchip/2016-December/013308.html
- Add Reviwed-by: Heiko St?bner <[email protected]> to series
- change timer compatible property in the rk322x.dtsi 2/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013784.html
- updated comment message for 4/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013786.html
- updated comment message for 5/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013787.html
- fixed build error for 8/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013789.html

Alexander Kochetkov (5):
dt-bindings: clarify compatible property for rockchip timers
ARM: dts: rockchip: update compatible property for rk322x timer clocksource/drivers/rockchip_timer: implement clocksource timer
ARM: dts: rockchip: add timer entries to rk3188 SoC
ARM: dts: rockchip: disable arm-global-timer for rk3188

 .../bindings/timer/rockchip,rk-timer.txt           |   12 +-
 arch/arm/boot/dts/rk3188.dtsi                      |   17 ++
 arch/arm/boot/dts/rk322x.dtsi                      |    2 +-
 drivers/clocksource/Kconfig                        |    1 +
 drivers/clocksource/rockchip_timer.c               |  218 ++++++++++++++------
 5 files changed, 185 insertions(+), 65 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v6 1/5 dt-bindings: clarify compatible property for rockchip timers

Make all properties description in form '"rockchip,<chip>-timer", "rockchip,rk3288-timer"' for all chips found in linux kernel.

---
 .../bindings/timer/rockchip,rk-timer.txt           |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
Documentation/devicetree/bindings/timer/rockchip,rk-timer.txt +9 -3
index a41b184..16a5f45 100644
@@ -1,9 +1,15 @@
 Rockchip rk timer
 
 Required properties:
-- compatible: shall be one of:
-  "rockchip,rk3288-timer" - for rk3066, rk3036, rk3188, rk322x, rk3288, rk3368
-  "rockchip,rk3399-timer" - for rk3399
+- compatible: should be:
+  "rockchip,rk3036-timer", "rockchip,rk3288-timer": for Rockchip RK3036
+  "rockchip,rk3066-timer", "rockchip,rk3288-timer": for Rockchip RK3066
+  "rockchip,rk3188-timer", "rockchip,rk3288-timer": for Rockchip RK3188
+  "rockchip,rk3228-timer", "rockchip,rk3288-timer": for Rockchip RK3228
+  "rockchip,rk3229-timer", "rockchip,rk3288-timer": for Rockchip RK3229
+  "rockchip,rk3288-timer": for Rockchip RK3288
+  "rockchip,rk3368-timer", "rockchip,rk3288-timer": for Rockchip RK3368
+  "rockchip,rk3399-timer": for Rockchip RK3399
 - reg: base address of the timer register starting with TIMERS CONTROL register
 - interrupts: should contain the interrupts for Timer0
 - clocks : must contain an entry for each entry in clock-names
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v6 2/5 ARM: dts: rockchip: update compatible property for rk322x timer

In reply to Alexander Kochetkov

Property set to '"rockchip,rk3228-timer", "rockchip,rk3288-timer"' to match devicetree bindings.

---
 arch/arm/boot/dts/rk322x.dtsi |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/boot/dts/rk322x.dtsi +1 -1
index 9e6bf0e..2a4eee2 100644
@@ -323,7 +323,7 @@
 	};
 
 	timer: timer at 110c0000 {
-		compatible = "rockchip,rk3288-timer";
+		compatible = "rockchip,rk3228-timer", "rockchip,rk3288-timer";
 		reg = <0x110c0000 0x20>;
 		interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH>;
 		clocks = <&xin24m>, <&cru PCLK_TIMER>;
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v6 3/5 clocksource/drivers/rockchip_timer: implement clocksource timer

In reply to Alexander Kochetkov

The clock supplying the arm-global-timer on the rk3188 is coming from the the cpu clock itself and thus changes its rate everytime cpufreq adjusts the cpu frequency making this timer unsuitable as a stable clocksource and sched clock.

The rk3188, rk3288 and following socs share a separate timer block already handled by the rockchip-timer driver. Therefore adapt this driver to also be able to act as clocksource and sched clock on rk3188.

In order to test clocksource you can run following commands and check how much time it take in real. On rk3188 it take about ~45 seconds.

cpufreq-set -f 1.6GHZ
date; sleep 60; date

In order to use the patch you need to declare two timers in the dts file. The first timer will be initialized as clockevent provider and the second one as clocksource. The clockevent must be from alive subsystem as it used as backup for the local timers at sleep time.

The patch does not break compatibility with older device tree files. The older device tree files contain only one timer. The timer will be initialized as clockevent, as expected.

rk3288 (and probably anything newer) is irrelevant to this patch, as it has the arch timer interface. This patch may be useful for Cortex-A9/A5 based parts.

---
 drivers/clocksource/Kconfig          |    1 +
 drivers/clocksource/rockchip_timer.c |  218 ++++++++++++++++++++++++----------
 2 files changed, 158 insertions(+), 61 deletions(-)
drivers/clocksource/Kconfig +1 -0
index 5677886..e34d4ac 100644
@@ -64,6 +64,7 @@ config ROCKCHIP_TIMER
 	bool "Rockchip timer driver" if COMPILE_TEST
 	depends on ARM || ARM64
 	select CLKSRC_OF
+	select CLKSRC_MMIO
 	help
 	  Enables the support for the rockchip timer driver.
 
drivers/clocksource/rockchip_timer.c +157 -61

337 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v6 4/5 ARM: dts: rockchip: add timer entries to rk3188 SoC

In reply to Alexander Kochetkov

The patch add two timers to all rk3188 based boards.

The first timer is from alive subsystem and it act as a backup for the local timers at sleep time. It act the same as other SoC rockchip timers already present in kernel.

The second timer is from CPU subsystem and act as replacement for the arm-global-timer clocksource and sched clock. It run at stable frequency 24MHz.

---
 arch/arm/boot/dts/rk3188.dtsi |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/boot/dts/rk3188.dtsi +16 -0
index 31f81b2..0dc52fe 100644
@@ -106,6 +106,22 @@
 		};
 	};
 
+	timer3: timer at 2000e000 {
+		compatible = "rockchip,rk3188-timer", "rockchip,rk3288-timer";
+		reg = <0x2000e000 0x20>;
+		interrupts = <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TIMER3>, <&cru PCLK_TIMER3>;
+		clock-names = "timer", "pclk";
+	};
+
+	timer6: timer at 200380a0 {
+		compatible = "rockchip,rk3188-timer", "rockchip,rk3288-timer";
+		reg = <0x200380a0 0x20>;
+		interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TIMER6>, <&cru PCLK_TIMER0>;
+		clock-names = "timer", "pclk";
+	};
+
 	i2s0: i2s at 1011a000 {
 		compatible = "rockchip,rk3188-i2s", "rockchip,rk3066-i2s";
 		reg = <0x1011a000 0x2000>;
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v6 5/5 ARM: dts: rockchip: disable arm-global-timer for rk3188

In reply to Alexander Kochetkov

The clocksource and the sched_clock provided by the arm_global_timer are quite unstable because their rates depend on the cpu frequency.

On the other side, the arm_global_timer has a higher rating than the rockchip_timer, it will be selected by default by the time framework while we want to use the stable rockchip clocksource.

Let's disable the arm_global_timer in order to have the rockchip clocksource selected by default.

---
 arch/arm/boot/dts/rk3188.dtsi |    1 +
 1 file changed, 1 insertion(+)
arch/arm/boot/dts/rk3188.dtsi +1 -0
index 0dc52fe..44da3d42 100644
@@ -546,6 +546,7 @@
 
 &global_timer {
 	interrupts = <GIC_PPI 11 0xf04>;
+	status = "disabled";
 };
 
 &local_timer {
Signature · 1 line
1.7.9.5
maintainer Reviewed-by on v6 1/5
#2 lore raw

Re: [PATCH v6 1/5] dt-bindings: clarify compatible property for rockchip timers

In reply to Alexander Kochetkov

Am Dienstag, 31. Januar 2017, 15:43:12 CET schrieb Alexander Kochetkov:

Quoted 6 lines

Make all properties description in form '"rockchip,<chip>-timer", "rockchip,rk3288-timer"' for all chips found in linux kernel.

looks good

maintainer Reviewed-by on v6 2/5
#4 lore raw

Re: [PATCH v6 2/5] ARM: dts: rockchip: update compatible property for rk322x timer

In reply to Alexander Kochetkov

Am Dienstag, 31. Januar 2017, 15:43:13 CET schrieb Alexander Kochetkov:

Quoted 5 lines

Property set to '"rockchip,rk3228-timer", "rockchip,rk3288-timer"' to match devicetree bindings.

depending on who is picking that up, they can add my

if needed

maintainer Reviewed-by on v6 4/5
#7 lore raw

Re: [PATCH v6 4/5] ARM: dts: rockchip: add timer entries to rk3188 SoC

In reply to Alexander Kochetkov

Am Dienstag, 31. Januar 2017, 15:43:15 CET schrieb Alexander Kochetkov:

Quoted 29 lines

The patch add two timers to all rk3188 based boards.

The first timer is from alive subsystem and it act as a backup for the local timers at sleep time. It act the same as other SoC rockchip timers already present in kernel.

The second timer is from CPU subsystem and act as replacement for the arm-global-timer clocksource and sched clock. It run at stable frequency 24MHz.

---
 arch/arm/boot/dts/rk3188.dtsi |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/boot/dts/rk3188.dtsi +6 -0
index 31f81b2..0dc52fe 100644
@@ -106,6 +106,22 @@
 		};
 	};
 
+	timer3: timer at 2000e000 {
+		compatible = "rockchip,rk3188-timer", "rockchip,rk3288-timer";
+		reg = <0x2000e000 0x20>;
+		interrupts = <GIC_SPI 46 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TIMER3>, <&cru PCLK_TIMER3>;
+		clock-names = "timer", "pclk";

arch/arm/boot/dts/rk3188.dtsi line 124

Quoted 10 lines
arch/arm/boot/dts/rk3188.dtsi +10 -0
+	};
+
+	timer6: timer at 200380a0 {
+		compatible = "rockchip,rk3188-timer", "rockchip,rk3288-timer";
+		reg = <0x200380a0 0x20>;
+		interrupts = <GIC_SPI 64 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&cru SCLK_TIMER6>, <&cru PCLK_TIMER0>;
+		clock-names = "timer", "pclk";
+	};
+

depending on who is picking that up, they can add my

if needed.

I've also double checked the timer clocks - especially the pclks. Timer3 has its own separate pclk, while all other timers are supplied by pclk_timer0.

Heiko

maintainer Reviewed-by on v6 5/5
#9 lore raw

Re: [PATCH v6 5/5] ARM: dts: rockchip: disable arm-global-timer for rk3188

In reply to Alexander Kochetkov

Am Dienstag, 31. Januar 2017, 15:43:16 CET schrieb Alexander Kochetkov:

Quoted 11 lines

The clocksource and the sched_clock provided by the arm_global_timer are quite unstable because their rates depend on the cpu frequency.

On the other side, the arm_global_timer has a higher rating than the rockchip_timer, it will be selected by default by the time framework while we want to use the stable rockchip clocksource.

Let's disable the arm_global_timer in order to have the rockchip clocksource selected by default.

depending on who is picking that up, they can add my

if needed.

Later on we might need to look at the rk3066 as well, as it might have the same issue.

#10 lore raw
In reply to Alexander Kochetkov

Hello, Daniel.

Sorry for bothering you, but could you please take a look at v6[1] series and tell what do you think about it? I see your commit[2] in the git, but I don?t understand well how to use it in rockchip driver.

[1] https://lkml.org/lkml/2017/1/31/401
[2] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/clocksource?id=376bc27150f180d9f5eddec6a14117780177589d

Regards,
Alexander.

Quoted 73 lines

31 ???. 2017 ?., ? 15:43, Alexander Kochetkov <[email protected]> ???????(?):

From: Alexander Kochetkov <[email protected]>

Hello, Daniel, Heiko.

Here is try 6 :) Thanks a lot for helping me to bring the code into kernel!

This patch series contain:
- devicetree bindings clarification for rockchip timers
- dts files fixes for rk3228-evb, rk3229-evb and rk3188
- implementation of clocksource and sched clock for rockchip SoC

The clock supplying the arm-global-timer on the rk3188 is coming from the the cpu clock itself and thus changes its rate everytime cpufreq adjusts the cpu frequency making this timer unsuitable as a stable clocksource.

The rk3188, rk3288 and following socs share a separate timer block already handled by the rockchip-timer driver. Therefore adapt this driver to also be able to act as clocksource on rk3188.

In order to test clocksource you can run following commands and check how much time it take in real. On rk3188 it take about ~45 seconds.

cpufreq-set -f 1.6GHZ
date; sleep 60; date

rk3288 (and probably anything newer) is irrelevant to this patch, as it has the arch timer interface. This patch may be usefull for Cortex-A9/A5 based parts.

Regards,
Alexander.

Changes in v6:
- Removed Reviewed-by: Heiko St?bner <[email protected]> tag
- Merge 5/8, 6/8, 7/8, 8/9 into single file
- split init paths into rk_clkevt_init() and rk_clksrc_init() so the driver code could be adopted to CLOCKEVENT_OF_DECLARE()
- clockevents implemented using clocksource_mmio_init()
- fixed commit message for 4/8 (thanks a lot Daniel)

Changes in v5:
- Add Acked-by: Rob Herring <[email protected]> to 1/8
http://lists.infradead.org/pipermail/linux-rockchip/2016-December/013308.html
- Add Reviwed-by: Heiko St?bner <[email protected]> to series
- change timer compatible property in the rk322x.dtsi 2/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013784.html
- updated comment message for 4/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013786.html
- updated comment message for 5/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013787.html
- fixed build error for 8/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013789.html

Alexander Kochetkov (5):
dt-bindings: clarify compatible property for rockchip timers
ARM: dts: rockchip: update compatible property for rk322x timer clocksource/drivers/rockchip_timer: implement clocksource timer
ARM: dts: rockchip: add timer entries to rk3188 SoC
ARM: dts: rockchip: disable arm-global-timer for rk3188

.../bindings/timer/rockchip,rk-timer.txt           |   12 +-
arch/arm/boot/dts/rk3188.dtsi                      |   17 ++
arch/arm/boot/dts/rk322x.dtsi                      |    2 +-
drivers/clocksource/Kconfig                        |    1 +
drivers/clocksource/rockchip_timer.c               |  218 ++++++++++++++------
5 files changed, 185 insertions(+), 65 deletions(-)
Signature · 1 line
1.7.9.5
#11 lore raw
Quoted 7 lines · Alexander Kochetkov

Hello, Daniel.

Sorry for bothering you, but could you please take a look at v6[1] series and tell what do you think about it? I see your commit[2] in the git, but I don?t understand well how to use it in rockchip driver.

[1] https://lkml.org/lkml/2017/1/31/401
[2] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/drivers/clocksource?id=376bc27150f180d9f5eddec6a14117780177589d

Hi Alexander,

I have been through the patchset and it is ok except for the patch 3/5. I wanted to investigate a bit on this one because of the patch [2] you are mentioning.

I think there is small missing piece of devicetree binding to specify 'clocksource' or 'clockevent'. Rob Herring is ok with an attribute of this kind.

That would help to clearly separate these drivers without ambiguity.

However, it results on some duplicated code I'm not very happy with, so that is my major issue with this approach I would like to solve. That is the status today.

I wanted to take the opportunity of your changes to investigate this area.

Quoted 74 lines
Quoted 73 lines

31 ???. 2017 ?., ? 15:43, Alexander Kochetkov <[email protected]> ???????(?):

From: Alexander Kochetkov <[email protected]>

Hello, Daniel, Heiko.

Here is try 6 :) Thanks a lot for helping me to bring the code into kernel!

This patch series contain:
- devicetree bindings clarification for rockchip timers
- dts files fixes for rk3228-evb, rk3229-evb and rk3188
- implementation of clocksource and sched clock for rockchip SoC

The clock supplying the arm-global-timer on the rk3188 is coming from the the cpu clock itself and thus changes its rate everytime cpufreq adjusts the cpu frequency making this timer unsuitable as a stable clocksource.

The rk3188, rk3288 and following socs share a separate timer block already handled by the rockchip-timer driver. Therefore adapt this driver to also be able to act as clocksource on rk3188.

In order to test clocksource you can run following commands and check how much time it take in real. On rk3188 it take about ~45 seconds.

cpufreq-set -f 1.6GHZ
date; sleep 60; date

rk3288 (and probably anything newer) is irrelevant to this patch, as it has the arch timer interface. This patch may be usefull for Cortex-A9/A5 based parts.

Regards,
Alexander.

Changes in v6:
- Removed Reviewed-by: Heiko St?bner <[email protected]> tag
- Merge 5/8, 6/8, 7/8, 8/9 into single file
- split init paths into rk_clkevt_init() and rk_clksrc_init() so the driver code could be adopted to CLOCKEVENT_OF_DECLARE()
- clockevents implemented using clocksource_mmio_init()
- fixed commit message for 4/8 (thanks a lot Daniel)

Changes in v5:
- Add Acked-by: Rob Herring <[email protected]> to 1/8
http://lists.infradead.org/pipermail/linux-rockchip/2016-December/013308.html
- Add Reviwed-by: Heiko St?bner <[email protected]> to series
- change timer compatible property in the rk322x.dtsi 2/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013784.html
- updated comment message for 4/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013786.html
- updated comment message for 5/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013787.html
- fixed build error for 8/8
http://lists.infradead.org/pipermail/linux-rockchip/2017-January/013789.html

Alexander Kochetkov (5):
dt-bindings: clarify compatible property for rockchip timers
ARM: dts: rockchip: update compatible property for rk322x timer clocksource/drivers/rockchip_timer: implement clocksource timer
ARM: dts: rockchip: add timer entries to rk3188 SoC
ARM: dts: rockchip: disable arm-global-timer for rk3188

.../bindings/timer/rockchip,rk-timer.txt           |   12 +-
arch/arm/boot/dts/rk3188.dtsi                      |   17 ++
arch/arm/boot/dts/rk322x.dtsi                      |    2 +-
drivers/clocksource/Kconfig                        |    1 +
drivers/clocksource/rockchip_timer.c               |  218 ++++++++++++++------
5 files changed, 185 insertions(+), 65 deletions(-)
Signature · 1 line
1.7.9.5
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