Lines Matching +full:32 +full:- +full:bits

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Inspired by time-efm32.c from Uwe Kleine-Koenig
23 #include "timer-of.h"
50 int bits; member
54 * stm32_timer_of_bits_set - set accessor helper
56 * @bits: the number of bits (16 or 32)
58 * Accessor helper to set the number of bits in the timer-of private
62 static void stm32_timer_of_bits_set(struct timer_of *to, int bits) in stm32_timer_of_bits_set() argument
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
76 * Returns: an integer corresponding to the number of bits.
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
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
184 * is 32 bits wide, the result will be UINT_MAX, otherwise it will
185 * be truncated by the 16-bit register to USHRT_MAX.
196 stm32_timer_of_bits_set(to, width == UINT_MAX ? 32 : 16); in stm32_timer_set_width()
200 * stm32_timer_set_prescaler - Compute and set the prescaler register
201 * @to: a pointer to a timer-of structure
204 * target a 10MHz timer rate for 16 bits. 32-bit timers are
211 if (stm32_timer_of_bits_get(to) != 32) { in stm32_timer_set_prescaler()
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()
233 u32 bits = stm32_timer_of_bits_get(to); in stm32_clocksource_init() local
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()
245 if (bits == 32 && !stm32_timer_cnt) { in stm32_clocksource_init()
254 sched_clock_register(stm32_read_sched_clock, bits, timer_of_rate(to)); in stm32_clocksource_init()
264 timer_of_rate(to), bits == 32 ? 250 : 100, in stm32_clocksource_init()
265 bits, clocksource_mmio_readl_up); in stm32_clocksource_init()
270 u32 bits = stm32_timer_of_bits_get(to); in stm32_clockevent_init() local
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);