| 163 | } |
| 164 | |
| 165 | static int |
| 166 | ti_spi_attach(device_t dev) |
| 167 | { |
| 168 | int err, i, rid, timeout; |
| 169 | struct ti_spi_softc *sc; |
| 170 | uint32_t rev; |
| 171 | |
| 172 | sc = device_get_softc(dev); |
| 173 | sc->sc_dev = dev; |
| 174 | |
| 175 | /* Activate the McSPI module. */ |
| 176 | err = ti_sysc_clock_enable(device_get_parent(dev)); |
| 177 | if (err) { |
| 178 | device_printf(dev, "Error: failed to activate source clock\n"); |
| 179 | return (err); |
| 180 | } |
| 181 | |
| 182 | /* Get the number of available channels. */ |
| 183 | if ((OF_getencprop(ofw_bus_get_node(dev), "ti,spi-num-cs", |
| 184 | &sc->sc_numcs, sizeof(sc->sc_numcs))) <= 0) { |
| 185 | sc->sc_numcs = 2; |
| 186 | } |
| 187 | |
| 188 | rid = 0; |
| 189 | sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, |
| 190 | RF_ACTIVE); |
| 191 | if (!sc->sc_mem_res) { |
| 192 | device_printf(dev, "cannot allocate memory window\n"); |
| 193 | return (ENXIO); |
| 194 | } |
| 195 | |
| 196 | sc->sc_bst = rman_get_bustag(sc->sc_mem_res); |
| 197 | sc->sc_bsh = rman_get_bushandle(sc->sc_mem_res); |
| 198 | |
| 199 | rid = 0; |
| 200 | sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, |
| 201 | RF_ACTIVE); |
| 202 | if (!sc->sc_irq_res) { |
| 203 | bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); |
| 204 | device_printf(dev, "cannot allocate interrupt\n"); |
| 205 | return (ENXIO); |
| 206 | } |
| 207 | |
| 208 | /* Hook up our interrupt handler. */ |
| 209 | if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_MISC | INTR_MPSAFE, |
| 210 | NULL, ti_spi_intr, sc, &sc->sc_intrhand)) { |
| 211 | bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); |
| 212 | bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); |
| 213 | device_printf(dev, "cannot setup the interrupt handler\n"); |
| 214 | return (ENXIO); |
| 215 | } |
| 216 | |
| 217 | mtx_init(&sc->sc_mtx, "ti_spi", NULL, MTX_DEF); |
| 218 | |
| 219 | /* Issue a softreset to the controller */ |
| 220 | TI_SPI_WRITE(sc, MCSPI_SYSCONFIG, MCSPI_SYSCONFIG_SOFTRESET); |
| 221 | timeout = 1000; |
| 222 | while (!(TI_SPI_READ(sc, MCSPI_SYSSTATUS) & |
nothing calls this directly
no test coverage detected