Lines Matching +full:ftm +full:- +full:src +full:- +full:counter +full:- +full:en
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Freescale FlexTimer Module (FTM) timer driver.
18 #include <linux/fsl/ftm.h>
34 if (priv->big_endian) in ftm_readl()
42 if (priv->big_endian) in ftm_writel()
52 /* select and enable counter clock source */ in ftm_counter_enable()
55 val |= priv->ps | FTM_SC_CLK(1); in ftm_counter_enable()
63 /* disable counter clock source */ in ftm_counter_disable()
99 * The CNT register contains the FTM counter value. in ftm_reset_counter()
101 * updates the counter with its initial value, CNTIN. in ftm_reset_counter()
108 return ftm_readl(priv->clksrc_base + FTM_CNT); in ftm_read_sched_clock()
119 * a, the counter source clock is disabled. in ftm_set_next_event()
121 ftm_counter_disable(priv->clkevt_base); in ftm_set_next_event()
123 /* Force the value of CNTIN to be loaded into the FTM counter */ in ftm_set_next_event()
124 ftm_reset_counter(priv->clkevt_base); in ftm_set_next_event()
127 * The counter increments until the value of MOD is reached, in ftm_set_next_event()
128 * at which point the counter is reloaded with the value of CNTIN. in ftm_set_next_event()
129 * The TOF (the overflow flag) bit is set when the FTM counter in ftm_set_next_event()
130 * changes from MOD to CNTIN. So we should using the delta - 1. in ftm_set_next_event()
132 ftm_writel(delta - 1, priv->clkevt_base + FTM_MOD); in ftm_set_next_event()
134 ftm_counter_enable(priv->clkevt_base); in ftm_set_next_event()
136 ftm_irq_enable(priv->clkevt_base); in ftm_set_next_event()
143 ftm_counter_disable(priv->clkevt_base); in ftm_set_oneshot()
149 ftm_set_next_event(priv->periodic_cyc, evt); in ftm_set_periodic()
157 ftm_irq_acknowledge(priv->clkevt_base); in ftm_evt_interrupt()
160 ftm_irq_disable(priv->clkevt_base); in ftm_evt_interrupt()
161 ftm_counter_disable(priv->clkevt_base); in ftm_evt_interrupt()
164 evt->event_handler(evt); in ftm_evt_interrupt()
170 .name = "Freescale ftm timer",
183 ftm_writel(0x00, priv->clkevt_base + FTM_CNTIN); in ftm_clockevent_init()
184 ftm_writel(~0u, priv->clkevt_base + FTM_MOD); in ftm_clockevent_init()
186 ftm_reset_counter(priv->clkevt_base); in ftm_clockevent_init()
189 "Freescale ftm timer", &ftm_clockevent); in ftm_clockevent_init()
191 pr_err("ftm: setup irq failed: %d\n", err); in ftm_clockevent_init()
199 freq / (1 << priv->ps), in ftm_clockevent_init()
202 ftm_counter_enable(priv->clkevt_base); in ftm_clockevent_init()
211 ftm_writel(0x00, priv->clksrc_base + FTM_CNTIN); in ftm_clocksource_init()
212 ftm_writel(~0u, priv->clksrc_base + FTM_MOD); in ftm_clocksource_init()
214 ftm_reset_counter(priv->clksrc_base); in ftm_clocksource_init()
216 sched_clock_register(ftm_read_sched_clock, 16, freq / (1 << priv->ps)); in ftm_clocksource_init()
217 err = clocksource_mmio_init(priv->clksrc_base + FTM_CNT, "fsl-ftm", in ftm_clocksource_init()
218 freq / (1 << priv->ps), 300, 16, in ftm_clocksource_init()
221 pr_err("ftm: init clock source mmio failed: %d\n", err); in ftm_clocksource_init()
225 ftm_counter_enable(priv->clksrc_base); in ftm_clocksource_init()
238 pr_err("ftm: Cannot get \"%s\": %ld\n", cnt_name, PTR_ERR(clk)); in __ftm_clk_init()
243 pr_err("ftm: clock failed to prepare+enable \"%s\": %d\n", in __ftm_clk_init()
250 pr_err("ftm: Cannot get \"%s\": %ld\n", ftm_name, PTR_ERR(clk)); in __ftm_clk_init()
255 pr_err("ftm: clock failed to prepare+enable \"%s\": %d\n", in __ftm_clk_init()
265 freq = __ftm_clk_init(np, "ftm-evt-counter-en", "ftm-evt"); in ftm_clk_init()
269 freq = __ftm_clk_init(np, "ftm-src-counter-en", "ftm-src"); in ftm_clk_init()
278 priv->ps = 0; in ftm_calc_closest_round_cyc()
280 /* The counter register is only using the lower 16 bits, and in ftm_calc_closest_round_cyc()
285 priv->periodic_cyc = DIV_ROUND_CLOSEST(freq, in ftm_calc_closest_round_cyc()
286 HZ * (1 << priv->ps++)); in ftm_calc_closest_round_cyc()
287 } while (priv->periodic_cyc > 0xFFFF); in ftm_calc_closest_round_cyc()
289 if (priv->ps > FTM_PS_MAX) { in ftm_calc_closest_round_cyc()
290 pr_err("ftm: the prescaler is %lu > %d\n", in ftm_calc_closest_round_cyc()
291 priv->ps, FTM_PS_MAX); in ftm_calc_closest_round_cyc()
292 return -EINVAL; in ftm_calc_closest_round_cyc()
305 return -ENOMEM; in ftm_timer_init()
307 ret = -ENXIO; in ftm_timer_init()
308 priv->clkevt_base = of_iomap(np, 0); in ftm_timer_init()
309 if (!priv->clkevt_base) { in ftm_timer_init()
310 pr_err("ftm: unable to map event timer registers\n"); in ftm_timer_init()
314 priv->clksrc_base = of_iomap(np, 1); in ftm_timer_init()
315 if (!priv->clksrc_base) { in ftm_timer_init()
316 pr_err("ftm: unable to map source timer registers\n"); in ftm_timer_init()
320 ret = -EINVAL; in ftm_timer_init()
323 pr_err("ftm: unable to get IRQ from DT, %d\n", irq); in ftm_timer_init()
327 priv->big_endian = of_property_read_bool(np, "big-endian"); in ftm_timer_init()
348 iounmap(priv->clksrc_base); in ftm_timer_init()
350 iounmap(priv->clkevt_base); in ftm_timer_init()
355 TIMER_OF_DECLARE(flextimer, "fsl,ftm-timer", ftm_timer_init);