Lines Matching +full:am335x +full:- +full:timer +full:- +full:1 +full:ms
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
10 * 1. Redistributions of source code must retain the above copyright
83 {"ti,am335x-timer", 1},
84 {"ti,am335x-timer-1ms", 1},
88 #define DMTIMER_READ4(sc, reg) bus_read_4((sc)->tmr_mem_res, (reg))
89 #define DMTIMER_WRITE4(sc, reg, val) bus_write_4((sc)->tmr_mem_res, (reg), (val))
97 sc = et->et_priv; in am335x_dmtimer_et_start()
100 * Stop the timer before changing it. This routine will often be called in am335x_dmtimer_et_start()
101 * while the timer is still running, to either lengthen or shorten the in am335x_dmtimer_et_start()
102 * current event time. We need to ensure the timer doesn't expire while in am335x_dmtimer_et_start()
107 * context now, and a timer interrupt could be pending even before we in am335x_dmtimer_et_start()
108 * stopped the timer. The more likely case is that we're being called in am335x_dmtimer_et_start()
112 sc->tclr &= ~(DMT_TCLR_START | DMT_TCLR_AUTOLOAD); in am335x_dmtimer_et_start()
113 DMTIMER_WRITE4(sc, DMT_TCLR, sc->tclr); in am335x_dmtimer_et_start()
117 reload_count = ((uint32_t)et->et_frequency * period) >> 32; in am335x_dmtimer_et_start()
118 sc->tclr |= DMT_TCLR_AUTOLOAD; in am335x_dmtimer_et_start()
124 initial_count = ((uint32_t)et->et_frequency * first) >> 32; in am335x_dmtimer_et_start()
129 * Set auto-reload and current-count values. This timer hardware counts in am335x_dmtimer_et_start()
132 DMTIMER_WRITE4(sc, DMT_TLDR, 0xFFFFFFFF - reload_count); in am335x_dmtimer_et_start()
133 DMTIMER_WRITE4(sc, DMT_TCRR, 0xFFFFFFFF - initial_count); in am335x_dmtimer_et_start()
135 /* Enable overflow interrupt, and start the timer. */ in am335x_dmtimer_et_start()
137 sc->tclr |= DMT_TCLR_START; in am335x_dmtimer_et_start()
138 DMTIMER_WRITE4(sc, DMT_TCLR, sc->tclr); in am335x_dmtimer_et_start()
148 sc = et->et_priv; in am335x_dmtimer_et_stop()
150 /* Stop timer, disable and clear interrupt. */ in am335x_dmtimer_et_stop()
151 sc->tclr &= ~(DMT_TCLR_START | DMT_TCLR_AUTOLOAD); in am335x_dmtimer_et_stop()
152 DMTIMER_WRITE4(sc, DMT_TCLR, sc->tclr); in am335x_dmtimer_et_stop()
167 if (sc->func.et.et_active) in am335x_dmtimer_et_intr()
168 sc->func.et.et_event_cb(&sc->func.et, sc->func.et.et_arg); in am335x_dmtimer_et_intr()
182 sc->tmr_irq_res = bus_alloc_resource_any(sc->dev, SYS_RES_IRQ, in am335x_dmtimer_et_init()
183 &sc->tmr_irq_rid, RF_ACTIVE); in am335x_dmtimer_et_init()
184 if (sc->tmr_irq_res == NULL) in am335x_dmtimer_et_init()
186 if (bus_setup_intr(sc->dev, sc->tmr_irq_res, INTR_TYPE_CLK, in am335x_dmtimer_et_init()
187 am335x_dmtimer_et_intr, NULL, sc, &sc->tmr_irq_handler) != 0) in am335x_dmtimer_et_init()
190 sc->func.et.et_name = sc->tmr_name; in am335x_dmtimer_et_init()
191 sc->func.et.et_flags = ET_FLAGS_PERIODIC | ET_FLAGS_ONESHOT; in am335x_dmtimer_et_init()
192 sc->func.et.et_quality = 500; in am335x_dmtimer_et_init()
193 sc->func.et.et_frequency = sc->sysclk_freq; in am335x_dmtimer_et_init()
194 sc->func.et.et_min_period = in am335x_dmtimer_et_init()
195 ((0x00000005LLU << 32) / sc->func.et.et_frequency); in am335x_dmtimer_et_init()
196 sc->func.et.et_max_period = in am335x_dmtimer_et_init()
197 (0xfffffffeLLU << 32) / sc->func.et.et_frequency; in am335x_dmtimer_et_init()
198 sc->func.et.et_start = am335x_dmtimer_et_start; in am335x_dmtimer_et_init()
199 sc->func.et.et_stop = am335x_dmtimer_et_stop; in am335x_dmtimer_et_init()
200 sc->func.et.et_priv = sc; in am335x_dmtimer_et_init()
203 et_register(&sc->func.et); in am335x_dmtimer_et_init()
213 sc = tc->tc_priv; in am335x_dmtimer_tc_get_timecount()
228 sc->tclr |= DMT_TCLR_START | DMT_TCLR_AUTOLOAD; in am335x_dmtimer_tc_init()
231 DMTIMER_WRITE4(sc, DMT_TCLR, sc->tclr); in am335x_dmtimer_tc_init()
233 sc->func.tc.tc_name = sc->tmr_name; in am335x_dmtimer_tc_init()
234 sc->func.tc.tc_get_timecount = am335x_dmtimer_tc_get_timecount; in am335x_dmtimer_tc_init()
235 sc->func.tc.tc_counter_mask = ~0u; in am335x_dmtimer_tc_init()
236 sc->func.tc.tc_frequency = sc->sysclk_freq; in am335x_dmtimer_tc_init()
237 sc->func.tc.tc_quality = 500; in am335x_dmtimer_tc_init()
238 sc->func.tc.tc_priv = sc; in am335x_dmtimer_tc_init()
241 tc_init(&sc->func.tc); in am335x_dmtimer_tc_init()
257 if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0) in am335x_dmtimer_probe()
278 device_set_descf(dev, "AM335x DMTimer%d", tmr_num); in am335x_dmtimer_probe()
292 sc->dev = dev; in am335x_dmtimer_attach()
295 err = clk_get_by_ofw_index(dev, 0, 0, &sc->clk_fck); in am335x_dmtimer_attach()
308 err = clk_set_parent_by_clk(sc->clk_fck, sys_clkin); in am335x_dmtimer_attach()
322 err = clk_get_freq(sc->clk_fck, &sc->sysclk_freq); in am335x_dmtimer_attach()
329 sc->tmr_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, in am335x_dmtimer_attach()
330 &sc->tmr_mem_rid, RF_ACTIVE); in am335x_dmtimer_attach()
331 if (sc->tmr_mem_res == NULL) { in am335x_dmtimer_attach()
338 sc->tmr_num = 2; in am335x_dmtimer_attach()
341 sc->tmr_num = 3; in am335x_dmtimer_attach()
344 device_printf(dev, "Not timer 2 or 3! %#jx\n", in am335x_dmtimer_attach()
349 snprintf(sc->tmr_name, sizeof(sc->tmr_name), "DMTimer%d", sc->tmr_num); in am335x_dmtimer_attach()
355 if (sc->tmr_num == ET_TMR_NUM) in am335x_dmtimer_attach()
357 else if (sc->tmr_num == TC_TMR_NUM) in am335x_dmtimer_attach()
360 panic("am335x_dmtimer: bad timer number %d", sc->tmr_num); in am335x_dmtimer_attach()
378 MODULE_DEPEND(am335x_dmtimer, ti_sysc, 1, 1, 1);
388 counts = (usec + 1) * (sc->sysclk_freq / 1000000); in am335x_dmtimer_delay()
395 counts -= (int32_t)(last - first); in am335x_dmtimer_delay()
397 counts -= (int32_t)((0xFFFFFFFF - first) + last); in am335x_dmtimer_delay()