Lines Matching refs:stm_timer
55 struct stm_timer { struct
65 static DEFINE_PER_CPU(struct stm_timer *, stm_timers); argument
67 static struct stm_timer *stm_sched_clock;
82 static struct stm_timer *cs_to_stm(struct clocksource *cs) in DEFINE_GUARD()
84 return container_of(cs, struct stm_timer, cs); in DEFINE_GUARD()
87 static struct stm_timer *ced_to_stm(struct clock_event_device *ced) in ced_to_stm()
89 return container_of(ced, struct stm_timer, ced); in ced_to_stm()
97 static u32 nxp_stm_clocksource_getcnt(struct stm_timer *stm_timer) in nxp_stm_clocksource_getcnt() argument
99 return readl(STM_CNT(stm_timer->base)); in nxp_stm_clocksource_getcnt()
102 static void nxp_stm_clocksource_setcnt(struct stm_timer *stm_timer, u32 cnt) in nxp_stm_clocksource_setcnt() argument
104 writel(cnt, STM_CNT(stm_timer->base)); in nxp_stm_clocksource_setcnt()
109 struct stm_timer *stm_timer = cs_to_stm(cs); in nxp_stm_clocksource_read() local
111 return (u64)nxp_stm_clocksource_getcnt(stm_timer); in nxp_stm_clocksource_read()
114 static void nxp_stm_module_enable(struct stm_timer *stm_timer) in nxp_stm_module_enable() argument
118 reg = readl(STM_CR(stm_timer->base)); in nxp_stm_module_enable()
122 writel(reg, STM_CR(stm_timer->base)); in nxp_stm_module_enable()
125 static void nxp_stm_module_disable(struct stm_timer *stm_timer) in nxp_stm_module_disable() argument
129 reg = readl(STM_CR(stm_timer->base)); in nxp_stm_module_disable()
133 writel(reg, STM_CR(stm_timer->base)); in nxp_stm_module_disable()
136 static void nxp_stm_module_put(struct stm_timer *stm_timer) in nxp_stm_module_put() argument
138 if (atomic_dec_and_test(&stm_timer->refcnt)) in nxp_stm_module_put()
139 nxp_stm_module_disable(stm_timer); in nxp_stm_module_put()
142 static void nxp_stm_module_get(struct stm_timer *stm_timer) in nxp_stm_module_get() argument
144 if (atomic_inc_return(&stm_timer->refcnt) == 1) in nxp_stm_module_get()
145 nxp_stm_module_enable(stm_timer); in nxp_stm_module_get()
150 struct stm_timer *stm_timer = cs_to_stm(cs); in nxp_stm_clocksource_enable() local
152 nxp_stm_module_get(stm_timer); in nxp_stm_clocksource_enable()
159 struct stm_timer *stm_timer = cs_to_stm(cs); in nxp_stm_clocksource_disable() local
161 nxp_stm_module_put(stm_timer); in nxp_stm_clocksource_disable()
166 struct stm_timer *stm_timer = cs_to_stm(cs); in nxp_stm_clocksource_suspend() local
169 stm_timer->counter = nxp_stm_clocksource_getcnt(stm_timer); in nxp_stm_clocksource_suspend()
174 struct stm_timer *stm_timer = cs_to_stm(cs); in nxp_stm_clocksource_resume() local
176 nxp_stm_clocksource_setcnt(stm_timer, stm_timer->counter); in nxp_stm_clocksource_resume()
182 struct stm_timer *stm_timer = data; in devm_clocksource_unregister() local
184 clocksource_unregister(&stm_timer->cs); in devm_clocksource_unregister()
187 static int __init nxp_stm_clocksource_init(struct device *dev, struct stm_timer *stm_timer, in nxp_stm_clocksource_init() argument
192 stm_timer->base = base; in nxp_stm_clocksource_init()
193 stm_timer->rate = clk_get_rate(clk); in nxp_stm_clocksource_init()
195 stm_timer->cs.name = name; in nxp_stm_clocksource_init()
196 stm_timer->cs.rating = 460; in nxp_stm_clocksource_init()
197 stm_timer->cs.read = nxp_stm_clocksource_read; in nxp_stm_clocksource_init()
198 stm_timer->cs.enable = nxp_stm_clocksource_enable; in nxp_stm_clocksource_init()
199 stm_timer->cs.disable = nxp_stm_clocksource_disable; in nxp_stm_clocksource_init()
200 stm_timer->cs.suspend = nxp_stm_clocksource_suspend; in nxp_stm_clocksource_init()
201 stm_timer->cs.resume = nxp_stm_clocksource_resume; in nxp_stm_clocksource_init()
202 stm_timer->cs.mask = CLOCKSOURCE_MASK(32); in nxp_stm_clocksource_init()
203 stm_timer->cs.flags = CLOCK_SOURCE_IS_CONTINUOUS; in nxp_stm_clocksource_init()
205 ret = clocksource_register_hz(&stm_timer->cs, stm_timer->rate); in nxp_stm_clocksource_init()
209 ret = devm_add_action_or_reset(dev, devm_clocksource_unregister, stm_timer); in nxp_stm_clocksource_init()
211 clocksource_unregister(&stm_timer->cs); in nxp_stm_clocksource_init()
215 stm_sched_clock = stm_timer; in nxp_stm_clocksource_init()
217 sched_clock_register(nxp_stm_read_sched_clock, 32, stm_timer->rate); in nxp_stm_clocksource_init()
224 static int nxp_stm_clockevent_read_counter(struct stm_timer *stm_timer) in nxp_stm_clockevent_read_counter() argument
226 return readl(STM_CNT(stm_timer->base)); in nxp_stm_clockevent_read_counter()
229 static void nxp_stm_clockevent_disable(struct stm_timer *stm_timer) in nxp_stm_clockevent_disable() argument
231 writel(0, STM_CCR0(stm_timer->base)); in nxp_stm_clockevent_disable()
234 static void nxp_stm_clockevent_enable(struct stm_timer *stm_timer) in nxp_stm_clockevent_enable() argument
236 writel(STM_CCR_CEN, STM_CCR0(stm_timer->base)); in nxp_stm_clockevent_enable()
241 struct stm_timer *stm_timer = ced_to_stm(ced); in nxp_stm_clockevent_shutdown() local
243 nxp_stm_clockevent_disable(stm_timer); in nxp_stm_clockevent_shutdown()
250 struct stm_timer *stm_timer = ced_to_stm(ced); in nxp_stm_clockevent_set_next_event() local
253 nxp_stm_clockevent_disable(stm_timer); in nxp_stm_clockevent_set_next_event()
255 stm_timer->delta = delta; in nxp_stm_clockevent_set_next_event()
257 val = nxp_stm_clockevent_read_counter(stm_timer) + delta; in nxp_stm_clockevent_set_next_event()
259 writel(val, STM_CMP0(stm_timer->base)); in nxp_stm_clockevent_set_next_event()
271 if (val > nxp_stm_clockevent_read_counter(stm_timer) + delta) in nxp_stm_clockevent_set_next_event()
274 nxp_stm_clockevent_enable(stm_timer); in nxp_stm_clockevent_set_next_event()
281 struct stm_timer *stm_timer = ced_to_stm(ced); in nxp_stm_clockevent_set_periodic() local
283 return nxp_stm_clockevent_set_next_event(stm_timer->rate, ced); in nxp_stm_clockevent_set_periodic()
288 struct stm_timer *stm_timer = ced_to_stm(ced); in nxp_stm_clockevent_suspend() local
290 nxp_stm_module_put(stm_timer); in nxp_stm_clockevent_suspend()
295 struct stm_timer *stm_timer = ced_to_stm(ced); in nxp_stm_clockevent_resume() local
297 nxp_stm_module_get(stm_timer); in nxp_stm_clockevent_resume()
300 static int __init nxp_stm_clockevent_per_cpu_init(struct device *dev, struct stm_timer *stm_timer, in nxp_stm_clockevent_per_cpu_init() argument
304 stm_timer->base = base; in nxp_stm_clockevent_per_cpu_init()
305 stm_timer->rate = clk_get_rate(clk); in nxp_stm_clockevent_per_cpu_init()
307 stm_timer->ced.name = name; in nxp_stm_clockevent_per_cpu_init()
308 stm_timer->ced.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; in nxp_stm_clockevent_per_cpu_init()
309 stm_timer->ced.set_state_shutdown = nxp_stm_clockevent_shutdown; in nxp_stm_clockevent_per_cpu_init()
310 stm_timer->ced.set_state_periodic = nxp_stm_clockevent_set_periodic; in nxp_stm_clockevent_per_cpu_init()
311 stm_timer->ced.set_next_event = nxp_stm_clockevent_set_next_event; in nxp_stm_clockevent_per_cpu_init()
312 stm_timer->ced.suspend = nxp_stm_clockevent_suspend; in nxp_stm_clockevent_per_cpu_init()
313 stm_timer->ced.resume = nxp_stm_clockevent_resume; in nxp_stm_clockevent_per_cpu_init()
314 stm_timer->ced.cpumask = cpumask_of(cpu); in nxp_stm_clockevent_per_cpu_init()
315 stm_timer->ced.rating = 460; in nxp_stm_clockevent_per_cpu_init()
316 stm_timer->ced.irq = irq; in nxp_stm_clockevent_per_cpu_init()
318 per_cpu(stm_timers, cpu) = stm_timer; in nxp_stm_clockevent_per_cpu_init()
320 nxp_stm_module_get(stm_timer); in nxp_stm_clockevent_per_cpu_init()
329 struct stm_timer *stm_timer = per_cpu(stm_timers, cpu); in nxp_stm_clockevent_starting_cpu() local
332 if (WARN_ON(!stm_timer)) in nxp_stm_clockevent_starting_cpu()
335 ret = irq_force_affinity(stm_timer->ced.irq, cpumask_of(cpu)); in nxp_stm_clockevent_starting_cpu()
348 clockevents_config_and_register(&stm_timer->ced, stm_timer->rate, in nxp_stm_clockevent_starting_cpu()
349 (stm_timer->rate / MICRO) * 2, ULONG_MAX); in nxp_stm_clockevent_starting_cpu()
356 struct stm_timer *stm_timer = dev_id; in nxp_stm_module_interrupt() local
357 struct clock_event_device *ced = &stm_timer->ced; in nxp_stm_module_interrupt()
367 writel(STM_CIR_CIF, STM_CIR0(stm_timer->base)); in nxp_stm_module_interrupt()
372 val = nxp_stm_clockevent_read_counter(stm_timer) + stm_timer->delta; in nxp_stm_module_interrupt()
374 writel(val, STM_CMP0(stm_timer->base)); in nxp_stm_module_interrupt()
382 nxp_stm_clockevent_disable(stm_timer); in nxp_stm_module_interrupt()
391 struct stm_timer *stm_timer; in nxp_stm_timer_probe() local
437 stm_timer = devm_kzalloc(dev, sizeof(*stm_timer), GFP_KERNEL); in nxp_stm_timer_probe()
438 if (!stm_timer) in nxp_stm_timer_probe()
442 IRQF_TIMER | IRQF_NOBALANCING, name, stm_timer); in nxp_stm_timer_probe()
446 ret = nxp_stm_clocksource_init(dev, stm_timer, name, base, clk); in nxp_stm_timer_probe()
455 ret = nxp_stm_clockevent_per_cpu_init(dev, stm_timer, name, in nxp_stm_timer_probe()