Skip to contentSkip to conversation

clocksource: imx-sysctr: Add internal clock divider handle

PATCH Superseded [email protected] 3 participants 13 messages Jul 10, 2019 – Aug 19, 2019

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/5 clocksource: imx-sysctr: Add internal clock divider handle

From: Anson Huang <[email protected]>

The system counter block guide states that the base clock is internally divided by 3 before use, that means the clock input of system counter defined in DT should be base clock which is normally from OSC, and then internally divided by 3 before use.

---
Changes since V4:
- to solve the clock driver probed after system counter driver issue, now we can easily switch to use fixed clock defined in DT and get its rate, then divided by 3 to get real clock rate for system counter driver, no need to add "clock-frequency" property in DT.

---
 drivers/clocksource/timer-imx-sysctr.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/clocksource/timer-imx-sysctr.c +5 -0
index fd7d680..b7c80a3 100644
@@ -20,6 +20,8 @@
 #define SYS_CTR_EN		0x1
 #define SYS_CTR_IRQ_MASK	0x2
 
+#define SYS_CTR_CLK_DIV		0x3
+
 static void __iomem *sys_ctr_base;
 static u32 cmpcr;
 
@@ -134,6 +136,9 @@ static int __init sysctr_timer_init(struct device_node *np)
 	if (ret)
 		return ret;
 
+	/* system counter clock is divided by 3 internally */
+	to_sysctr.of_clk.rate /= SYS_CTR_CLK_DIV;
+
 	sys_ctr_base = timer_of_base(&to_sysctr);
 	cmpcr = readl(sys_ctr_base + CMPCR);
 	cmpcr &= ~SYS_CTR_EN;
Signature · 1 line
2.7.4
#1 lore raw

PATCH v5 2/5 arm64: Enable TIMER_IMX_SYS_CTR for ARCH_MXC platforms

From: Anson Huang <[email protected]>

ARCH_MXC platforms needs system counter as broadcast timer to support cpuidle, enable it by default.

---
New patch, now that system counter driver lands in main line, we can enable it by default.

---
 arch/arm64/Kconfig.platforms | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/Kconfig.platforms +1 -0
index 4778c77..f5e623f 100644
@@ -173,6 +173,7 @@ config ARCH_MXC
 	select PM
 	select PM_GENERIC_DOMAINS
 	select SOC_BUS
+	select TIMER_IMX_SYS_CTR
 	help
 	  This enables support for the ARMv8 based SoCs in the
 	  NXP i.MX family.
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH V5 2/5] arm64: Enable TIMER_IMX_SYS_CTR for ARCH_MXC platforms

Quoted 6 lines · On Wed, Jul 10, 2019 at 02:30:53PM +0800, [email protected] wrote:

From: Anson Huang <[email protected]>

ARCH_MXC platforms needs system counter as broadcast timer to support cpuidle, enable it by default.

This one is identical to what I just picked up from v4 series, right?

Shawn

#3 lore raw

PATCH v5 3/5 arm64: dts: imx8mm: Add system counter node

In reply to [email protected]

From: Anson Huang <[email protected]>

Add i.MX8MM system counter node to enable timer-imx-sysctr broadcast timer driver.

---
Changes since V4:
- update the clock info using fixed clock node;
- correct the reg range;
- update the interrupt number as the system counter driver ONLY uses 1 irq now.

---
 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/freescale/imx8mm.dtsi +8 -0
index b5637f8..8cf7f34 100644
@@ -560,6 +560,14 @@
 				#pwm-cells = <2>;
 				status = "disabled";
 			};
+
+			system_counter: timer@306a0000 {
+				compatible = "nxp,sysctr-timer";
+				reg = <0x306a0000 0x20000>;
+				interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>;
+				clocks = <&osc_24m>;
+				clock-names = "per";
+			};
 		};
 
 		aips3: bus@30800000 {
Signature · 1 line
2.7.4
#4 lore raw

Re: [PATCH V5 3/5] arm64: dts: imx8mm: Add system counter node

Quoted 6 lines · On Wed, Jul 10, 2019 at 02:30:54PM +0800, [email protected] wrote:

From: Anson Huang <[email protected]>

Add i.MX8MM system counter node to enable timer-imx-sysctr broadcast timer driver.

Do I need to wait for patch #1 landing before I apply #3 ~ #5, or can they be applied independently (no breaking on anything)?

Shawn

Quoted 31 lines

---
Changes since V4:
- update the clock info using fixed clock node;
- correct the reg range;
- update the interrupt number as the system counter driver ONLY uses 1 irq now.

---
 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/freescale/imx8mm.dtsi +8 -0
index b5637f8..8cf7f34 100644
@@ -560,6 +560,14 @@
 				#pwm-cells = <2>;
 				status = "disabled";
 			};
+
+			system_counter: timer@306a0000 {
+				compatible = "nxp,sysctr-timer";
+				reg = <0x306a0000 0x20000>;
+				interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>;
+				clocks = <&osc_24m>;
+				clock-names = "per";
+			};
 		};
 
 		aips3: bus@30800000 {
Signature · 1 line
2.7.4
#5 lore raw

RE: [PATCH V5 3/5] arm64: dts: imx8mm: Add system counter node

Hi, Shawn

Quoted 10 lines · On Wed, Jul 10, 2019 at 02:30:54PM +0800, [email protected] wrote:
Quoted 6 lines

From: Anson Huang <[email protected]>

Add i.MX8MM system counter node to enable timer-imx-sysctr broadcast timer driver.

Do I need to wait for patch #1 landing before I apply #3 ~ #5, or can they be applied independently (no breaking on anything)?

Without #1, system can bootup, but the system counter's freq will be incorrect, although it does NOT impact normal function. So I think it is better to wait for #1 landing. @[email protected], can you help review the #1 patch, since I use a different way to fix the clock issue which is more simple.

Anson

#6 lore raw

PATCH v5 4/5 arm64: dts: imx8mq: Add system counter node

In reply to [email protected]

From: Anson Huang <[email protected]>

Add i.MX8MQ system counter node to enable timer-imx-sysctr broadcast timer driver.

---
Changes since V4:
- update the clock info using fixed clock node;
- correct the reg range;
- update the interrupt number as the system counter driver ONLY uses 1 irq now.

---
 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 8 ++++++++
 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/freescale/imx8mq.dtsi +8 -0
index a1bbd80..2991172 100644
@@ -644,6 +644,14 @@
 				#pwm-cells = <2>;
 				status = "disabled";
 			};
+
+			system_counter: timer@306a0000 {
+				compatible = "nxp,sysctr-timer";
+				reg = <0x306a0000 0x20000>;
+				interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>;
+				clocks = <&osc_25m>;
+				clock-names = "per";
+			};
 		};
 
 		bus@30800000 { /* AIPS3 */
Signature · 1 line
2.7.4
#7 lore raw

PATCH v5 5/5 arm64: dts: imx8mm: Enable cpu-idle driver

In reply to [email protected]

From: Anson Huang <[email protected]>

Enable i.MX8MM cpu-idle using generic ARM cpu-idle driver, 2 states are supported, details as below:

root@imx8mmevk:~# cat /sys/devices/system/cpu/cpu0/cpuidle/state0/name
WFI
root@imx8mmevk:~# cat /sys/devices/system/cpu/cpu0/cpuidle/state0/usage
3973
root@imx8mmevk:~# cat /sys/devices/system/cpu/cpu0/cpuidle/state1/name
cpu-sleep-wait
root@imx8mmevk:~# cat /sys/devices/system/cpu/cpu0/cpuidle/state1/usage
6647

---
New patch, as this patch is based on other patches in this series, so I include it.

---
 arch/arm64/boot/dts/freescale/imx8mm.dtsi | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/arm64/boot/dts/freescale/imx8mm.dtsi +18 -0
index 8cf7f34..8f3ed39 100644
@@ -44,6 +44,20 @@
 		#address-cells = <1>;
 		#size-cells = <0>;
 
+		idle-states {
+			entry-method = "psci";
+
+			cpu_sleep_wait: cpu-sleep-wait {
+				compatible = "arm,idle-state";
+				arm,psci-suspend-param = <0x0010033>;
+				local-timer-stop;
+				entry-latency-us = <1000>;
+				exit-latency-us = <700>;
+				min-residency-us = <2700>;
+				wakeup-latency-us = <1500>;
+			};
+		};
+
 		A53_0: cpu@0 {
 			device_type = "cpu";
 			compatible = "arm,cortex-a53";
@@ -56,6 +70,7 @@
 			nvmem-cells = <&cpu_speed_grade>;
 			nvmem-cell-names = "speed_grade";
 			#cooling-cells = <2>;
+			cpu-idle-states = <&cpu_sleep_wait>;
 		};
 
 		A53_1: cpu@1 {
@@ -68,6 +83,7 @@
 			next-level-cache = <&A53_L2>;
 			operating-points-v2 = <&a53_opp_table>;
 			#cooling-cells = <2>;
+			cpu-idle-states = <&cpu_sleep_wait>;
 		};
 
 		A53_2: cpu@2 {
@@ -80,6 +96,7 @@
 			next-level-cache = <&A53_L2>;
 			operating-points-v2 = <&a53_opp_table>;
 			#cooling-cells = <2>;
+			cpu-idle-states = <&cpu_sleep_wait>;
 		};
 
 		A53_3: cpu@3 {
@@ -92,6 +109,7 @@
 			next-level-cache = <&A53_L2>;
 			operating-points-v2 = <&a53_opp_table>;
 			#cooling-cells = <2>;
+			cpu-idle-states = <&cpu_sleep_wait>;
 		};
 
 		A53_L2: l2-cache0 {
Signature · 1 line
2.7.4
#8 lore raw

Re: [PATCH V5 5/5] arm64: dts: imx8mm: Enable cpu-idle driver

Hi Anson,

sorry for the late review, I've been pretty busy.

If Shawn is ok, I can pick the patches 1-4 in my tree and then this one after you fix the comments below.

On 10/07/2019 08:30, [email protected] wrote:

[ ... ]

arch/arm64/boot/dts/freescale/imx8mm.dtsi line 50

Quoted 4 lines
arch/arm64/boot/dts/freescale/imx8mm.dtsi +4 -0
+		idle-states {
+			entry-method = "psci";
+
+			cpu_sleep_wait: cpu-sleep-wait {

Is that a retention state or a powerdown? It is preferable to change the name to the idle state naming convention given in the PSCI documentation
[1] page 16-17

arch/arm64/boot/dts/freescale/imx8mm.dtsi line 57

Quoted 7 lines
arch/arm64/boot/dts/freescale/imx8mm.dtsi +7 -0
+				compatible = "arm,idle-state";
+				arm,psci-suspend-param = <0x0010033>;
+				local-timer-stop;
+				entry-latency-us = <1000>;
+				exit-latency-us = <700>;
+				min-residency-us = <2700>;
+				wakeup-latency-us = <1500>;

It is pointless to specify the entry + exit *and* the wakeup-latency [2].

Thanks

-- Daniel

[1]
http://infocenter.arm.com/help/topic/com.arm.doc.den0022d/Power_State_Coordination_Interface_PDD_v1_1_DEN0022D.pdf

[2]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/cpuidle/dt_idle_states.c#n41

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
#9 lore raw

RE: [PATCH V5 5/5] arm64: dts: imx8mm: Enable cpu-idle driver

Hi, Daniel

Quoted 3 lines

Hi Anson,

sorry for the late review, I've been pretty busy.

That is OK for sure.

Quoted 3 lines

If Shawn is ok, I can pick the patches 1-4 in my tree and then this one after you fix the comments below.

Shawn should be OK for it, and he already took patch [PATCH V5 2/5] arm64: Enable TIMER_IMX_SYS_CTR for ARCH_MXC platforms since I ever sent it before in other series when system counter driver is NOT landing on main line, now it landed, Shawn just apply that old patch, so in V6 patch I just sent, I did NOT include this patch, you can just apply the 4 patches in V6.

Hi, Shawn
Daniel will pick this whole patch series, please raise if you have any concern, thanks.

Quoted 13 lines · On 10/07/2019 08:30, [email protected] wrote:

[ ... ]

arch/arm64/boot/dts/freescale/imx8mm.dtsi line 50

Quoted 4 lines
arch/arm64/boot/dts/freescale/imx8mm.dtsi +4 -0
+		idle-states {
+			entry-method = "psci";
+
+			cpu_sleep_wait: cpu-sleep-wait {

Is that a retention state or a powerdown? It is preferable to change the name to the idle state naming convention given in the PSCI documentation [1] page 16-17

Thanks for your detail reference, it is a power down state with SoC entering WAIT mode, so in V6, I change the name to "cpu_pd_wait:cpu-pd-wait".

Quoted 11 lines

arch/arm64/boot/dts/freescale/imx8mm.dtsi line 57

Quoted 9 lines
arch/arm64/boot/dts/freescale/imx8mm.dtsi +7 -0
+				compatible = "arm,idle-state";
+				arm,psci-suspend-param = <0x0010033>;
+				local-timer-stop;
+				entry-latency-us = <1000>;
+				exit-latency-us = <700>;
+				min-residency-us = <2700>;
+				wakeup-latency-us = <1500>;

It is pointless to specify the entry + exit *and* the wakeup-latency [2].

Ah, yes, this is new to me, I will just remove the “wakeup-latency-us” property.

Thanks,
Anson.

Acked-by
#10 lore raw

Re: [PATCH V5 5/5] arm64: dts: imx8mm: Enable cpu-idle driver

In reply to Daniel Lezcano
Quoted 7 lines · Daniel Lezcano

Hi Anson,

sorry for the late review, I've been pretty busy.

If Shawn is ok, I can pick the patches 1-4 in my tree and then this one after you fix the comments below.

I'm okay, so:

#11 lore raw
In reply to [email protected]

Gentle ping...

Quoted 47 lines

From: Anson Huang <[email protected]>

The system counter block guide states that the base clock is internally divided by 3 before use, that means the clock input of system counter defined in DT should be base clock which is normally from OSC, and then internally divided by 3 before use.

---
Changes since V4:
- to solve the clock driver probed after system counter driver issue,
now we can easily switch to
use fixed clock defined in DT and get its rate, then divided by 3 to
get real clock rate for
system counter driver, no need to add "clock-frequency" property in
DT.

---
 drivers/clocksource/timer-imx-sysctr.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/clocksource/timer-imx-sysctr.c +5 -0
index fd7d680..b7c80a3 100644
@@ -20,6 +20,8 @@
 #define SYS_CTR_EN		0x1
 #define SYS_CTR_IRQ_MASK	0x2
 
+#define SYS_CTR_CLK_DIV		0x3
+
 static void __iomem *sys_ctr_base;
 static u32 cmpcr;
 
@@ -134,6 +136,9 @@ static int __init sysctr_timer_init(struct device_node
 *np)
 	if (ret)
 		return ret;
 
+	/* system counter clock is divided by 3 internally */
+	to_sysctr.of_clk.rate /= SYS_CTR_CLK_DIV;
+
 	sys_ctr_base = timer_of_base(&to_sysctr);
 	cmpcr = readl(sys_ctr_base + CMPCR);

cmpcr &= ~SYS_CTR_EN;
--
2.7.4

#12 lore raw
Quoted 1 line · Anson Huang

Gentle ping...

Coming back from vacation. It is in the pipe ... :)

Quoted 48 lines
Quoted 47 lines

From: Anson Huang <[email protected]>

The system counter block guide states that the base clock is internally divided by 3 before use, that means the clock input of system counter defined in DT should be base clock which is normally from OSC, and then internally divided by 3 before use.

---
Changes since V4:
- to solve the clock driver probed after system counter driver issue,
now we can easily switch to
use fixed clock defined in DT and get its rate, then divided by 3 to
get real clock rate for
system counter driver, no need to add "clock-frequency" property in
DT.

---
 drivers/clocksource/timer-imx-sysctr.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/clocksource/timer-imx-sysctr.c +5 -0
index fd7d680..b7c80a3 100644
@@ -20,6 +20,8 @@
 #define SYS_CTR_EN		0x1
 #define SYS_CTR_IRQ_MASK	0x2
 
+#define SYS_CTR_CLK_DIV		0x3
+
 static void __iomem *sys_ctr_base;
 static u32 cmpcr;
 
@@ -134,6 +136,9 @@ static int __init sysctr_timer_init(struct device_node
 *np)
 	if (ret)
 		return ret;
 
+	/* system counter clock is divided by 3 internally */
+	to_sysctr.of_clk.rate /= SYS_CTR_CLK_DIV;
+
 	sys_ctr_base = timer_of_base(&to_sysctr);
 	cmpcr = readl(sys_ctr_base + CMPCR);

cmpcr &= ~SYS_CTR_EN;
--
2.7.4

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