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

Function ti_spi_attach

freebsd/arm/ti/ti_spi.c:165–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165static int
166ti_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) &

Callers

nothing calls this directly

Calls 15

device_get_softcFunction · 0.85
ti_sysc_clock_enableFunction · 0.85
device_get_parentFunction · 0.85
device_printfFunction · 0.85
bus_alloc_resource_anyFunction · 0.85
rman_get_bustagFunction · 0.85
rman_get_bushandleFunction · 0.85
bus_release_resourceFunction · 0.85
bus_setup_intrFunction · 0.85
mtx_initFunction · 0.85
ti_spi_detachFunction · 0.85

Tested by

no test coverage detected