Lines Matching +full:timer +full:-
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Rockchip timer support
44 struct rk_timer timer; member
52 return &container_of(ce, struct rk_clkevt, ce)->timer; in rk_timer()
55 static inline void rk_timer_disable(struct rk_timer *timer) in rk_timer_disable() argument
57 writel_relaxed(TIMER_DISABLE, timer->ctrl); in rk_timer_disable()
60 static inline void rk_timer_enable(struct rk_timer *timer, u32 flags) in rk_timer_enable() argument
62 writel_relaxed(TIMER_ENABLE | flags, timer->ctrl); in rk_timer_enable()
66 struct rk_timer *timer) in rk_timer_update_counter() argument
68 writel_relaxed(cycles, timer->base + TIMER_LOAD_COUNT0); in rk_timer_update_counter()
69 writel_relaxed(0, timer->base + TIMER_LOAD_COUNT1); in rk_timer_update_counter()
72 static void rk_timer_interrupt_clear(struct rk_timer *timer) in rk_timer_interrupt_clear() argument
74 writel_relaxed(1, timer->base + TIMER_INT_STATUS); in rk_timer_interrupt_clear()
80 struct rk_timer *timer = rk_timer(ce); in rk_timer_set_next_event() local
82 rk_timer_disable(timer); in rk_timer_set_next_event()
83 rk_timer_update_counter(cycles, timer); in rk_timer_set_next_event()
84 rk_timer_enable(timer, TIMER_MODE_USER_DEFINED_COUNT | in rk_timer_set_next_event()
91 struct rk_timer *timer = rk_timer(ce); in rk_timer_shutdown() local
93 rk_timer_disable(timer); in rk_timer_shutdown()
99 struct rk_timer *timer = rk_timer(ce); in rk_timer_set_periodic() local
101 rk_timer_disable(timer); in rk_timer_set_periodic()
102 rk_timer_update_counter(timer->freq / HZ - 1, timer); in rk_timer_set_periodic()
103 rk_timer_enable(timer, TIMER_MODE_FREE_RUNNING | TIMER_INT_UNMASK); in rk_timer_set_periodic()
110 struct rk_timer *timer = rk_timer(ce); in rk_timer_interrupt() local
112 rk_timer_interrupt_clear(timer); in rk_timer_interrupt()
115 rk_timer_disable(timer); in rk_timer_interrupt()
117 ce->event_handler(ce); in rk_timer_interrupt()
124 return ~readl_relaxed(rk_clksrc->base + TIMER_CURRENT_VALUE0); in rk_timer_sched_read()
128 rk_timer_probe(struct rk_timer *timer, struct device_node *np) in rk_timer_probe() argument
132 int ret = -EINVAL, irq; in rk_timer_probe()
135 timer->base = of_iomap(np, 0); in rk_timer_probe()
136 if (!timer->base) { in rk_timer_probe()
138 return -ENXIO; in rk_timer_probe()
141 if (of_device_is_compatible(np, "rockchip,rk3399-timer")) in rk_timer_probe()
144 timer->ctrl = timer->base + ctrl_reg; in rk_timer_probe()
158 timer->pclk = pclk; in rk_timer_probe()
160 timer_clk = of_clk_get_by_name(np, "timer"); in rk_timer_probe()
163 pr_err("Failed to get timer clock for '%s'\n", TIMER_NAME); in rk_timer_probe()
169 pr_err("Failed to enable timer clock\n"); in rk_timer_probe()
172 timer->clk = timer_clk; in rk_timer_probe()
174 timer->freq = clk_get_rate(timer_clk); in rk_timer_probe()
178 ret = -EINVAL; in rk_timer_probe()
182 timer->irq = irq; in rk_timer_probe()
184 rk_timer_interrupt_clear(timer); in rk_timer_probe()
185 rk_timer_disable(timer); in rk_timer_probe()
193 iounmap(timer->base); in rk_timer_probe()
198 static void __init rk_timer_cleanup(struct rk_timer *timer) in rk_timer_cleanup() argument
200 clk_disable_unprepare(timer->clk); in rk_timer_cleanup()
201 clk_disable_unprepare(timer->pclk); in rk_timer_cleanup()
202 iounmap(timer->base); in rk_timer_cleanup()
208 int ret = -EINVAL; in rk_clkevt_init()
212 ret = -ENOMEM; in rk_clkevt_init()
216 ret = rk_timer_probe(&rk_clkevt->timer, np); in rk_clkevt_init()
220 ce = &rk_clkevt->ce; in rk_clkevt_init()
221 ce->name = TIMER_NAME; in rk_clkevt_init()
222 ce->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT | in rk_clkevt_init()
224 ce->set_next_event = rk_timer_set_next_event; in rk_clkevt_init()
225 ce->set_state_shutdown = rk_timer_shutdown; in rk_clkevt_init()
226 ce->set_state_periodic = rk_timer_set_periodic; in rk_clkevt_init()
227 ce->irq = rk_clkevt->timer.irq; in rk_clkevt_init()
228 ce->cpumask = cpu_possible_mask; in rk_clkevt_init()
229 ce->rating = 250; in rk_clkevt_init()
231 ret = request_irq(rk_clkevt->timer.irq, rk_timer_interrupt, IRQF_TIMER, in rk_clkevt_init()
239 clockevents_config_and_register(&rk_clkevt->ce, in rk_clkevt_init()
240 rk_clkevt->timer.freq, 1, UINT_MAX); in rk_clkevt_init()
244 rk_timer_cleanup(&rk_clkevt->timer); in rk_clkevt_init()
255 int ret = -EINVAL; in rk_clksrc_init()
259 ret = -ENOMEM; in rk_clksrc_init()
270 ret = clocksource_mmio_init(rk_clksrc->base + TIMER_CURRENT_VALUE0, in rk_clksrc_init()
271 TIMER_NAME, rk_clksrc->freq, 250, 32, in rk_clksrc_init()
278 sched_clock_register(rk_timer_sched_read, 32, rk_clksrc->freq); in rk_clksrc_init()
299 pr_err("Too many timer definitions for '%s'\n", TIMER_NAME); in rk_timer_init()
300 return -EINVAL; in rk_timer_init()
303 TIMER_OF_DECLARE(rk3288_timer, "rockchip,rk3288-timer", rk_timer_init);
304 TIMER_OF_DECLARE(rk3399_timer, "rockchip,rk3399-timer", rk_timer_init);