Skip to content

Commit b67686e

Browse files
MrVandlezcano
authored andcommitted
clocksource/drivers/imx-sysctr: Add i.MX95 support
To i.MX95 System counter module, we use Read register space to get the counter, not the Control register space to get the counter, because System Manager firmware not allow Linux to read Control register space, so add a new TIMER_OF_DECLARE entry for i.MX95. Signed-off-by: Peng Fan <[email protected]> Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 418062b commit b67686e

File tree

1 file changed

+49
-4
lines changed

1 file changed

+49
-4
lines changed

drivers/clocksource/timer-imx-sysctr.c

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
#include "timer-of.h"
1010

1111
#define CMP_OFFSET 0x10000
12+
#define RD_OFFSET 0x20000
1213

1314
#define CNTCV_LO 0x8
1415
#define CNTCV_HI 0xc
1516
#define CMPCV_LO (CMP_OFFSET + 0x20)
1617
#define CMPCV_HI (CMP_OFFSET + 0x24)
1718
#define CMPCR (CMP_OFFSET + 0x2c)
19+
#define CNTCV_LO_IMX95 (RD_OFFSET + 0x8)
20+
#define CNTCV_HI_IMX95 (RD_OFFSET + 0xc)
1821

1922
#define SYS_CTR_EN 0x1
2023
#define SYS_CTR_IRQ_MASK 0x2
@@ -23,6 +26,8 @@
2326

2427
struct sysctr_private {
2528
u32 cmpcr;
29+
u32 lo_off;
30+
u32 hi_off;
2631
};
2732

2833
static void sysctr_timer_enable(struct clock_event_device *evt, bool enable)
@@ -47,13 +52,14 @@ static void sysctr_irq_acknowledge(struct clock_event_device *evt)
4752
static inline u64 sysctr_read_counter(struct clock_event_device *evt)
4853
{
4954
struct timer_of *to = to_timer_of(evt);
55+
struct sysctr_private *priv = to->private_data;
5056
void __iomem *base = timer_of_base(to);
5157
u32 cnt_hi, tmp_hi, cnt_lo;
5258

5359
do {
54-
cnt_hi = readl_relaxed(base + CNTCV_HI);
55-
cnt_lo = readl_relaxed(base + CNTCV_LO);
56-
tmp_hi = readl_relaxed(base + CNTCV_HI);
60+
cnt_hi = readl_relaxed(base + priv->hi_off);
61+
cnt_lo = readl_relaxed(base + priv->lo_off);
62+
tmp_hi = readl_relaxed(base + priv->hi_off);
5763
} while (tmp_hi != cnt_hi);
5864

5965
return ((u64) cnt_hi << 32) | cnt_lo;
@@ -127,7 +133,7 @@ static struct timer_of to_sysctr = {
127133
},
128134
};
129135

130-
static int __init sysctr_timer_init(struct device_node *np)
136+
static int __init __sysctr_timer_init(struct device_node *np)
131137
{
132138
struct sysctr_private *priv;
133139
void __iomem *base;
@@ -154,9 +160,48 @@ static int __init sysctr_timer_init(struct device_node *np)
154160
base = timer_of_base(&to_sysctr);
155161
priv->cmpcr = readl(base + CMPCR) & ~SYS_CTR_EN;
156162

163+
return 0;
164+
}
165+
166+
static int __init sysctr_timer_init(struct device_node *np)
167+
{
168+
struct sysctr_private *priv;
169+
int ret;
170+
171+
ret = __sysctr_timer_init(np);
172+
if (ret)
173+
return ret;
174+
175+
priv = to_sysctr.private_data;
176+
priv->lo_off = CNTCV_LO;
177+
priv->hi_off = CNTCV_HI;
178+
157179
clockevents_config_and_register(&to_sysctr.clkevt,
158180
timer_of_rate(&to_sysctr),
159181
0xff, 0x7fffffff);
182+
160183
return 0;
161184
}
185+
186+
static int __init sysctr_timer_imx95_init(struct device_node *np)
187+
{
188+
struct sysctr_private *priv;
189+
int ret;
190+
191+
ret = __sysctr_timer_init(np);
192+
if (ret)
193+
return ret;
194+
195+
priv = to_sysctr.private_data;
196+
priv->lo_off = CNTCV_LO_IMX95;
197+
priv->hi_off = CNTCV_HI_IMX95;
198+
199+
clockevents_config_and_register(&to_sysctr.clkevt,
200+
timer_of_rate(&to_sysctr),
201+
0xff, 0x7fffffff);
202+
203+
return 0;
204+
}
205+
162206
TIMER_OF_DECLARE(sysctr_timer, "nxp,sysctr-timer", sysctr_timer_init);
207+
TIMER_OF_DECLARE(sysctr_timer_imx95, "nxp,imx95-sysctr-timer", sysctr_timer_imx95_init);

0 commit comments

Comments
 (0)