Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <peng.fan@nxp.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20240205-imx-sysctr-v4-3-ca5a6e1552e7@nxp.com

authored by

Peng Fan and committed by
Daniel Lezcano
b67686e9 418062b5

+49 -4
+49 -4
drivers/clocksource/timer-imx-sysctr.c
··· 9 9 #include "timer-of.h" 10 10 11 11 #define CMP_OFFSET 0x10000 12 + #define RD_OFFSET 0x20000 12 13 13 14 #define CNTCV_LO 0x8 14 15 #define CNTCV_HI 0xc 15 16 #define CMPCV_LO (CMP_OFFSET + 0x20) 16 17 #define CMPCV_HI (CMP_OFFSET + 0x24) 17 18 #define CMPCR (CMP_OFFSET + 0x2c) 19 + #define CNTCV_LO_IMX95 (RD_OFFSET + 0x8) 20 + #define CNTCV_HI_IMX95 (RD_OFFSET + 0xc) 18 21 19 22 #define SYS_CTR_EN 0x1 20 23 #define SYS_CTR_IRQ_MASK 0x2 ··· 26 23 27 24 struct sysctr_private { 28 25 u32 cmpcr; 26 + u32 lo_off; 27 + u32 hi_off; 29 28 }; 30 29 31 30 static void sysctr_timer_enable(struct clock_event_device *evt, bool enable) ··· 52 47 static inline u64 sysctr_read_counter(struct clock_event_device *evt) 53 48 { 54 49 struct timer_of *to = to_timer_of(evt); 50 + struct sysctr_private *priv = to->private_data; 55 51 void __iomem *base = timer_of_base(to); 56 52 u32 cnt_hi, tmp_hi, cnt_lo; 57 53 58 54 do { 59 - cnt_hi = readl_relaxed(base + CNTCV_HI); 60 - cnt_lo = readl_relaxed(base + CNTCV_LO); 61 - tmp_hi = readl_relaxed(base + CNTCV_HI); 55 + cnt_hi = readl_relaxed(base + priv->hi_off); 56 + cnt_lo = readl_relaxed(base + priv->lo_off); 57 + tmp_hi = readl_relaxed(base + priv->hi_off); 62 58 } while (tmp_hi != cnt_hi); 63 59 64 60 return ((u64) cnt_hi << 32) | cnt_lo; ··· 133 127 }, 134 128 }; 135 129 136 - static int __init sysctr_timer_init(struct device_node *np) 130 + static int __init __sysctr_timer_init(struct device_node *np) 137 131 { 138 132 struct sysctr_private *priv; 139 133 void __iomem *base; ··· 160 154 base = timer_of_base(&to_sysctr); 161 155 priv->cmpcr = readl(base + CMPCR) & ~SYS_CTR_EN; 162 156 157 + return 0; 158 + } 159 + 160 + static int __init sysctr_timer_init(struct device_node *np) 161 + { 162 + struct sysctr_private *priv; 163 + int ret; 164 + 165 + ret = __sysctr_timer_init(np); 166 + if (ret) 167 + return ret; 168 + 169 + priv = to_sysctr.private_data; 170 + priv->lo_off = CNTCV_LO; 171 + priv->hi_off = CNTCV_HI; 172 + 163 173 clockevents_config_and_register(&to_sysctr.clkevt, 164 174 timer_of_rate(&to_sysctr), 165 175 0xff, 0x7fffffff); 176 + 166 177 return 0; 167 178 } 179 + 180 + static int __init sysctr_timer_imx95_init(struct device_node *np) 181 + { 182 + struct sysctr_private *priv; 183 + int ret; 184 + 185 + ret = __sysctr_timer_init(np); 186 + if (ret) 187 + return ret; 188 + 189 + priv = to_sysctr.private_data; 190 + priv->lo_off = CNTCV_LO_IMX95; 191 + priv->hi_off = CNTCV_HI_IMX95; 192 + 193 + clockevents_config_and_register(&to_sysctr.clkevt, 194 + timer_of_rate(&to_sysctr), 195 + 0xff, 0x7fffffff); 196 + 197 + return 0; 198 + } 199 + 168 200 TIMER_OF_DECLARE(sysctr_timer, "nxp,sysctr-timer", sysctr_timer_init); 201 + TIMER_OF_DECLARE(sysctr_timer_imx95, "nxp,imx95-sysctr-timer", sysctr_timer_imx95_init);