static int ccm_attach(device_t dev) { struct ccm_softc *sc; int reg; int i; sc = device_get_softc(dev); sc->dev = dev; if (bus_alloc_resources(dev, ccm_spec, sc->res)) { device_printf(dev, "could not allocate resources\n"); return (ENXIO); } /* Memory interface */ sc->bst = rman_get_bustag(sc->res[0]); sc->bsh = rman_get_bushandle(sc->res[0]); /* Enable oscillator */ reg = READ4(sc, CCM_CCR); reg |= (FIRC_EN | FXOSC_EN); WRITE4(sc, CCM_CCR, reg); /* Wait 10 times */ for (i = 0; i < 10; i++) { if (READ4(sc, CCM_CSR) & FXOSC_RDY) { device_printf(sc->dev, "On board oscillator is ready.\n"); break; } cpufunc_nullop(); } /* Clock is on during all modes, except stop mode. */ for (i = 0; i < CCM_CCGRN; i++) { WRITE4(sc, CCM_CCGR(i), 0xffffffff); } /* Enable ENET clocks */ reg = READ4(sc, CCM_CSCDR1); reg |= (ENET_TS_EN | RMII_CLK_EN); WRITE4(sc, CCM_CSCDR1, reg); return (0); }
void ccm_clock_gate_disable(enum ccm_clock_gate gr) { uint32_t offset = (uint32_t)gr / 16; uint32_t gr_mask = 0x3 << ((gr % 16) * 2); CCM_CCGR(offset * 4) &= ~gr_mask; }