Lines Matching refs:to

55  * @to: a timer_of structure pointer
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)
64 struct stm32_timer_private *pd = to->private_data;
71 * @to: a timer_of structure pointer
73 * Accessor helper to get the number of bits in the timer-of private
76 * Returns: an integer corresponding to the number of bits.
78 static int stm32_timer_of_bits_get(struct timer_of *to)
80 struct stm32_timer_private *pd = to->private_data;
99 static void stm32_clock_event_disable(struct timer_of *to)
101 writel_relaxed(0, timer_of_base(to) + TIM_DIER);
106 * @to: a timer_of structure pointer
108 * Start the timer in order to have the counter reset and start
112 static void stm32_timer_start(struct timer_of *to)
114 writel_relaxed(TIM_CR1_UDIS | TIM_CR1_CEN, timer_of_base(to) + TIM_CR1);
119 struct timer_of *to = to_timer_of(clkevt);
121 stm32_clock_event_disable(to);
129 struct timer_of *to = to_timer_of(clkevt);
132 next = readl_relaxed(timer_of_base(to) + TIM_CNT) + evt;
133 writel_relaxed(next, timer_of_base(to) + TIM_CCR1);
134 now = readl_relaxed(timer_of_base(to) + TIM_CNT);
139 writel_relaxed(TIM_DIER_CC1IE, timer_of_base(to) + TIM_DIER);
146 struct timer_of *to = to_timer_of(clkevt);
148 stm32_timer_start(to);
150 return stm32_clock_event_set_next_event(timer_of_period(to), clkevt);
155 struct timer_of *to = to_timer_of(clkevt);
157 stm32_timer_start(to);
165 struct timer_of *to = to_timer_of(clkevt);
167 writel_relaxed(0, timer_of_base(to) + TIM_SR);
181 * @to: a pointer to a timer-of structure
185 * be truncated by the 16-bit register to USHRT_MAX.
188 static void __init stm32_timer_set_width(struct timer_of *to)
192 writel_relaxed(UINT_MAX, timer_of_base(to) + TIM_ARR);
194 width = readl_relaxed(timer_of_base(to) + TIM_ARR);
196 stm32_timer_of_bits_set(to, width == UINT_MAX ? 32 : 16);
201 * @to: a pointer to a timer-of structure
203 * Depending on the timer width, compute the prescaler to always
205 * considered precise and long enough to not use the prescaler.
207 static void __init stm32_timer_set_prescaler(struct timer_of *to)
211 if (stm32_timer_of_bits_get(to) != 32) {
212 prescaler = DIV_ROUND_CLOSEST(timer_of_rate(to),
222 writel_relaxed(prescaler - 1, timer_of_base(to) + TIM_PSC);
223 writel_relaxed(TIM_EGR_UG, timer_of_base(to) + TIM_EGR);
224 writel_relaxed(0, timer_of_base(to) + TIM_SR);
227 to->of_clk.rate = DIV_ROUND_CLOSEST(to->of_clk.rate, prescaler);
228 to->of_clk.period = DIV_ROUND_UP(to->of_clk.rate, HZ);
231 static int __init stm32_clocksource_init(struct timer_of *to)
233 u32 bits = stm32_timer_of_bits_get(to);
234 const char *name = to->np->full_name;
237 * This driver allows to register several timers and relies on
238 * the generic time framework to select the right one.
239 * However, nothing allows to do the same for the
251 stm32_timer_start(to);
253 stm32_timer_cnt = timer_of_base(to) + TIM_CNT;
254 sched_clock_register(stm32_read_sched_clock, bits, timer_of_rate(to));
258 stm32_timer_delay.freq = timer_of_rate(to);
263 return clocksource_mmio_init(timer_of_base(to) + TIM_CNT, name,
264 timer_of_rate(to), bits == 32 ? 250 : 100,
268 static void __init stm32_clockevent_init(struct timer_of *to)
270 u32 bits = stm32_timer_of_bits_get(to);
272 to->clkevt.name = to->np->full_name;
273 to->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
274 to->clkevt.set_state_shutdown = stm32_clock_event_shutdown;
275 to->clkevt.set_state_periodic = stm32_clock_event_set_periodic;
276 to->clkevt.set_state_oneshot = stm32_clock_event_set_oneshot;
277 to->clkevt.tick_resume = stm32_clock_event_shutdown;
278 to->clkevt.set_next_event = stm32_clock_event_set_next_event;
279 to->clkevt.rating = bits == 32 ? 250 : 100;
281 clockevents_config_and_register(&to->clkevt, timer_of_rate(to), 0x1,
285 to->np, bits);
291 struct timer_of *to;
294 to = kzalloc(sizeof(*to), GFP_KERNEL);
295 if (!to)
298 to->flags = TIMER_OF_IRQ | TIMER_OF_CLOCK | TIMER_OF_BASE;
299 to->of_irq.handler = stm32_clock_event_handler;
301 ret = timer_of_init(node, to);
305 to->private_data = kzalloc(sizeof(struct stm32_timer_private),
307 if (!to->private_data) {
318 stm32_timer_set_width(to);
320 stm32_timer_set_prescaler(to);
322 ret = stm32_clocksource_init(to);
326 stm32_clockevent_init(to);
330 timer_of_cleanup(to);
332 kfree(to);