| 132 | } |
| 133 | |
| 134 | static int |
| 135 | ti_mbox_attach(device_t dev) |
| 136 | { |
| 137 | struct ti_mbox_softc *sc; |
| 138 | int rid, delay, chan; |
| 139 | uint32_t rev, sysconfig; |
| 140 | |
| 141 | if (ti_sysc_clock_enable(device_get_parent(dev)) != 0) { |
| 142 | device_printf(dev, "could not enable MBOX clock\n"); |
| 143 | return (ENXIO); |
| 144 | } |
| 145 | |
| 146 | sc = device_get_softc(dev); |
| 147 | rid = 0; |
| 148 | mtx_init(&sc->sc_mtx, "TI mbox", NULL, MTX_DEF); |
| 149 | sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, |
| 150 | RF_ACTIVE); |
| 151 | if (sc->sc_mem_res == NULL) { |
| 152 | device_printf(dev, "could not allocate memory resource\n"); |
| 153 | return (ENXIO); |
| 154 | } |
| 155 | sc->sc_bt = rman_get_bustag(sc->sc_mem_res); |
| 156 | sc->sc_bh = rman_get_bushandle(sc->sc_mem_res); |
| 157 | rid = 0; |
| 158 | sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, |
| 159 | RF_ACTIVE); |
| 160 | if (sc->sc_irq_res == NULL) { |
| 161 | device_printf(dev, "could not allocate interrupt resource\n"); |
| 162 | ti_mbox_detach(dev); |
| 163 | return (ENXIO); |
| 164 | } |
| 165 | if (bus_setup_intr(dev, sc->sc_irq_res, INTR_MPSAFE | INTR_TYPE_MISC, |
| 166 | NULL, ti_mbox_intr, sc, &sc->sc_intr) != 0) { |
| 167 | device_printf(dev, "unable to setup the interrupt handler\n"); |
| 168 | ti_mbox_detach(dev); |
| 169 | return (ENXIO); |
| 170 | } |
| 171 | /* |
| 172 | * Reset the controller. |
| 173 | */ |
| 174 | sysconfig = ti_mbox_reg_read(sc, TI_MBOX_SYSCONFIG); |
| 175 | DPRINTF("initial sysconfig %d\n", sysconfig); |
| 176 | sysconfig |= TI_MBOX_SYSCONFIG_SOFTRST; |
| 177 | delay = 100; |
| 178 | while (ti_mbox_reg_read(sc, TI_MBOX_SYSCONFIG) & |
| 179 | TI_MBOX_SYSCONFIG_SOFTRST) { |
| 180 | delay--; |
| 181 | DELAY(10); |
| 182 | } |
| 183 | if (delay == 0) { |
| 184 | device_printf(dev, "controller reset failed\n"); |
| 185 | ti_mbox_detach(dev); |
| 186 | return (ENXIO); |
| 187 | } |
| 188 | /* |
| 189 | * Enable smart idle mode. |
| 190 | */ |
| 191 | ti_mbox_reg_write(sc, TI_MBOX_SYSCONFIG, |
nothing calls this directly
no test coverage detected