| 194 | } |
| 195 | |
| 196 | static int |
| 197 | a10_timer_attach(device_t dev) |
| 198 | { |
| 199 | struct a10_timer_softc *sc; |
| 200 | clk_t clk; |
| 201 | int err; |
| 202 | |
| 203 | sc = device_get_softc(dev); |
| 204 | sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; |
| 205 | |
| 206 | if (bus_alloc_resources(dev, a10_timer_spec, sc->res)) { |
| 207 | device_printf(dev, "could not allocate resources\n"); |
| 208 | return (ENXIO); |
| 209 | } |
| 210 | |
| 211 | sc->sc_dev = dev; |
| 212 | |
| 213 | /* Setup and enable the timer interrupt */ |
| 214 | err = bus_setup_intr(dev, sc->res[A10_TIMER_IRQRES], INTR_TYPE_CLK, |
| 215 | a10_timer_irq, NULL, sc, &sc->sc_ih); |
| 216 | if (err != 0) { |
| 217 | bus_release_resources(dev, a10_timer_spec, sc->res); |
| 218 | device_printf(dev, "Unable to setup the clock irq handler, " |
| 219 | "err = %d\n", err); |
| 220 | return (ENXIO); |
| 221 | } |
| 222 | |
| 223 | if (clk_get_by_ofw_index(dev, 0, 0, &clk) != 0) |
| 224 | sc->timer0_freq = SYS_TIMER_CLKSRC; |
| 225 | else { |
| 226 | if (clk_get_freq(clk, &sc->timer0_freq) != 0) { |
| 227 | device_printf(dev, "Cannot get clock source frequency\n"); |
| 228 | return (ENXIO); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | #if defined(__arm__) |
| 233 | a10_timer_eventtimer_setup(sc); |
| 234 | arm_set_delay(a10_timer_delay, sc); |
| 235 | a10_timer_timecounter.tc_priv = sc; |
| 236 | a10_timer_timecounter.tc_frequency = sc->timer0_freq; |
| 237 | tc_init(&a10_timer_timecounter); |
| 238 | #elif defined(__aarch64__) |
| 239 | a23_timer_timecounter_setup(sc); |
| 240 | #endif |
| 241 | |
| 242 | if (bootverbose) { |
| 243 | device_printf(sc->sc_dev, "clock: hz=%d stathz = %d\n", hz, stathz); |
| 244 | |
| 245 | device_printf(sc->sc_dev, "event timer clock frequency %ju\n", |
| 246 | sc->timer0_freq); |
| 247 | device_printf(sc->sc_dev, "timecounter clock frequency %jd\n", |
| 248 | a10_timer_timecounter.tc_frequency); |
| 249 | } |
| 250 | |
| 251 | return (0); |
| 252 | } |
| 253 |
nothing calls this directly
no test coverage detected