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

clocksource/drivers/arm_arch_timer_mmio: Add MMIO clocksource

The MMIO driver can also double as a clocksource, something that was
missing in its previous incarnation. Add it for completeness.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Link: https://lore.kernel.org/r/20250814154622.10193-5-maz@kernel.org

authored by

Marc Zyngier and committed by
Daniel Lezcano
4e9bfe69 0f67b56d

+19
+19
drivers/clocksource/arm_arch_timer_mmio.c
··· 45 45 46 46 struct arch_timer { 47 47 struct clock_event_device evt; 48 + struct clocksource cs; 48 49 struct arch_timer_mem *gt_block; 49 50 void __iomem *base; 50 51 enum arch_timer_access access; ··· 53 52 }; 54 53 55 54 #define evt_to_arch_timer(e) container_of(e, struct arch_timer, evt) 55 + #define cs_to_arch_timer(c) container_of(c, struct arch_timer, cs) 56 56 57 57 static void arch_timer_mmio_write(struct arch_timer *timer, 58 58 enum arch_timer_reg reg, u64 val) ··· 128 126 } while (cnt_hi != tmp_hi); 129 127 130 128 return ((u64) cnt_hi << 32) | cnt_lo; 129 + } 130 + 131 + static u64 arch_mmio_counter_read(struct clocksource *cs) 132 + { 133 + struct arch_timer *at = cs_to_arch_timer(cs); 134 + 135 + return arch_counter_mmio_get_cnt(at); 131 136 } 132 137 133 138 static int arch_timer_mmio_shutdown(struct clock_event_device *clk) ··· 265 256 (unsigned long)CLOCKSOURCE_MASK(56)); 266 257 267 258 enable_irq(at->evt.irq); 259 + 260 + at->cs = (struct clocksource) { 261 + .name = "arch_mmio_counter", 262 + .rating = 300, 263 + .read = arch_mmio_counter_read, 264 + .mask = CLOCKSOURCE_MASK(56), 265 + .flags = CLOCK_SOURCE_IS_CONTINUOUS, 266 + }; 267 + 268 + clocksource_register_hz(&at->cs, at->rate); 268 269 } 269 270 270 271 static int arch_timer_mmio_frame_register(struct platform_device *pdev,