Lines Matching +full:stm32 +full:- +full:timer +full:- +full:counter

1 // SPDX-License-Identifier: GPL-2.0-only
4 * Author: Maxime Coquelin <mcoquelin.stm32@gmail.com>
6 * Inspired by time-efm32.c from Uwe Kleine-Koenig
23 #include "timer-of.h"
54 * stm32_timer_of_bits_set - set accessor helper
58 * Accessor helper to set the number of bits in the timer-of private
64 struct stm32_timer_private *pd = to->private_data; in stm32_timer_of_bits_set()
66 pd->bits = bits; in stm32_timer_of_bits_set()
70 * stm32_timer_of_bits_get - get accessor helper
73 * Accessor helper to get the number of bits in the timer-of private
80 struct stm32_timer_private *pd = to->private_data; in stm32_timer_of_bits_get()
82 return pd->bits; in stm32_timer_of_bits_get()
105 * stm32_timer_start - Start the counter without event
108 * Start the timer in order to have the counter reset and start
109 * incrementing but disable interrupt event when there is a counter
110 * overflow. By default, the counter direction is used as upcounter.
136 if ((next - now) > evt) in stm32_clock_event_set_next_event()
137 return -ETIME; in stm32_clock_event_set_next_event()
174 clkevt->event_handler(clkevt); in stm32_clock_event_handler()
180 * stm32_timer_set_width - Sort out the timer width (32/16)
181 * @to: a pointer to a timer-of structure
183 * Write the 32-bit max value and read/return the result. If the timer
185 * be truncated by the 16-bit register to USHRT_MAX.
200 * stm32_timer_set_prescaler - Compute and set the prescaler register
201 * @to: a pointer to a timer-of structure
203 * Depending on the timer width, compute the prescaler to always
204 * target a 10MHz timer rate for 16 bits. 32-bit timers are
222 writel_relaxed(prescaler - 1, timer_of_base(to) + TIM_PSC); in stm32_timer_set_prescaler()
227 to->of_clk.rate = DIV_ROUND_CLOSEST(to->of_clk.rate, prescaler); in stm32_timer_set_prescaler()
228 to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ); in stm32_timer_set_prescaler()
234 const char *name = to->np->full_name; in stm32_clocksource_init()
241 * 16-bit timers but only for the 32-bit one, so if no 32-bit in stm32_clocksource_init()
242 * timer is registered yet, we select this 32-bit timer as a in stm32_clocksource_init()
248 * Start immediately the counter as we will be using in stm32_clocksource_init()
255 pr_info("%s: STM32 sched_clock registered\n", name); in stm32_clocksource_init()
260 pr_info("%s: STM32 delay timer registered\n", name); in stm32_clocksource_init()
272 to->clkevt.name = to->np->full_name; in stm32_clockevent_init()
273 to->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT; in stm32_clockevent_init()
274 to->clkevt.set_state_shutdown = stm32_clock_event_shutdown; in stm32_clockevent_init()
275 to->clkevt.set_state_periodic = stm32_clock_event_set_periodic; in stm32_clockevent_init()
276 to->clkevt.set_state_oneshot = stm32_clock_event_set_oneshot; in stm32_clockevent_init()
277 to->clkevt.tick_resume = stm32_clock_event_shutdown; in stm32_clockevent_init()
278 to->clkevt.set_next_event = stm32_clock_event_set_next_event; in stm32_clockevent_init()
279 to->clkevt.rating = bits == 32 ? 250 : 100; in stm32_clockevent_init()
281 clockevents_config_and_register(&to->clkevt, timer_of_rate(to), 0x1, in stm32_clockevent_init()
282 (1 << bits) - 1); in stm32_clockevent_init()
284 pr_info("%pOF: STM32 clockevent driver initialized (%d bits)\n", in stm32_clockevent_init()
285 to->np, bits); in stm32_clockevent_init()
296 return -ENOMEM; in stm32_timer_init()
298 to->flags = TIMER_OF_IRQ | TIMER_OF_CLOCK | TIMER_OF_BASE; in stm32_timer_init()
299 to->of_irq.handler = stm32_clock_event_handler; in stm32_timer_init()
305 to->private_data = kzalloc(sizeof(struct stm32_timer_private), in stm32_timer_init()
307 if (!to->private_data) { in stm32_timer_init()
308 ret = -ENOMEM; in stm32_timer_init()
336 TIMER_OF_DECLARE(stm32, "st,stm32-timer", stm32_timer_init);