MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sp804_timer_attach

Function sp804_timer_attach

freebsd/arm/versatile/sp804.c:201–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

199}
200
201static int
202sp804_timer_attach(device_t dev)
203{
204 struct sp804_timer_softc *sc = device_get_softc(dev);
205 int rid = 0;
206 int i;
207 uint32_t id, reg;
208 phandle_t node;
209 pcell_t clock;
210
211 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, RF_ACTIVE);
212 if (sc->mem_res == NULL) {
213 device_printf(dev, "could not allocate memory resource\n");
214 return (ENXIO);
215 }
216
217 sc->bst = rman_get_bustag(sc->mem_res);
218 sc->bsh = rman_get_bushandle(sc->mem_res);
219
220 /* Request the IRQ resources */
221 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
222 if (sc->irq_res == NULL) {
223 device_printf(dev, "Error: could not allocate irq resources\n");
224 return (ENXIO);
225 }
226
227 sc->sysclk_freq = DEFAULT_FREQUENCY;
228 /* Get the base clock frequency */
229 node = ofw_bus_get_node(dev);
230 if ((OF_getencprop(node, "clock-frequency", &clock, sizeof(clock))) > 0) {
231 sc->sysclk_freq = clock;
232 }
233
234 /* Setup and enable the timer */
235 if (bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CLK,
236 sp804_timer_intr, NULL, sc,
237 &sc->intr_hl) != 0) {
238 bus_release_resource(dev, SYS_RES_IRQ, rid,
239 sc->irq_res);
240 device_printf(dev, "Unable to setup the clock irq handler.\n");
241 return (ENXIO);
242 }
243
244 sp804_timer_tc_write_4(SP804_TIMER1_CONTROL, 0);
245 sp804_timer_tc_write_4(SP804_TIMER2_CONTROL, 0);
246
247 /*
248 * Timer 1, timecounter
249 */
250 sc->tc.tc_frequency = sc->sysclk_freq;
251 sc->tc.tc_name = "SP804-1";
252 sc->tc.tc_get_timecount = sp804_timer_tc_get_timecount;
253 sc->tc.tc_poll_pps = NULL;
254 sc->tc.tc_counter_mask = ~0u;
255 sc->tc.tc_quality = 1000;
256 sc->tc.tc_priv = sc;
257
258 sp804_timer_tc_write_4(SP804_TIMER1_VALUE, 0xffffffff);

Callers

nothing calls this directly

Calls 10

device_get_softcFunction · 0.85
bus_alloc_resource_anyFunction · 0.85
device_printfFunction · 0.85
rman_get_bustagFunction · 0.85
rman_get_bushandleFunction · 0.85
bus_setup_intrFunction · 0.85
bus_release_resourceFunction · 0.85
tc_initFunction · 0.85
et_registerFunction · 0.85
arm_set_delayFunction · 0.85

Tested by

no test coverage detected