Lines Matching +full:espi +full:- +full:num +full:- +full:chipselects
1 /*-
51 * Optimize FIFO reads and writes to do word-at-a-time instead of byte-at-a-time
105 #define FSL_ESPI_WRITE(sc,off,val) bus_write_4(sc->sc_mem_res, off, val)
106 #define FSL_ESPI_READ(sc,off) bus_read_4(sc->sc_mem_res, off)
107 #define FSL_ESPI_WRITE_FIFO(sc,off,val) bus_write_1(sc->sc_mem_res, off, val)
108 #define FSL_ESPI_READ_FIFO(sc,off) bus_read_1(sc->sc_mem_res, off)
111 mtx_lock(&(_sc)->sc_mtx)
113 mtx_unlock(&(_sc)->sc_mtx)
140 if (!ofw_bus_is_compatible(dev, "fsl,mpc8536-espi")) in fsl_espi_probe()
143 device_set_desc(dev, "Freescale eSPI controller"); in fsl_espi_probe()
156 sc->sc_dev = dev; in fsl_espi_attach()
160 sc->sc_mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, in fsl_espi_attach()
162 if (!sc->sc_mem_res) { in fsl_espi_attach()
168 sc->sc_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, in fsl_espi_attach()
170 if (!sc->sc_irq_res) { in fsl_espi_attach()
171 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); in fsl_espi_attach()
177 if (bus_setup_intr(dev, sc->sc_irq_res, INTR_TYPE_MISC | INTR_MPSAFE, in fsl_espi_attach()
178 NULL, fsl_espi_intr, sc, &sc->sc_intrhand)) { in fsl_espi_attach()
179 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); in fsl_espi_attach()
180 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); in fsl_espi_attach()
184 if (OF_getencprop(node, "fsl,espi-num-chipselects", in fsl_espi_attach()
185 &sc->sc_num_cs, sizeof(sc->sc_num_cs)) < 0 ) in fsl_espi_attach()
186 sc->sc_num_cs = 4; in fsl_espi_attach()
188 mtx_init(&sc->sc_mtx, "fsl_espi", NULL, MTX_DEF); in fsl_espi_attach()
213 mtx_destroy(&sc->sc_mtx); in fsl_espi_detach()
214 if (sc->sc_intrhand) in fsl_espi_detach()
215 bus_teardown_intr(dev, sc->sc_irq_res, sc->sc_intrhand); in fsl_espi_detach()
216 if (sc->sc_irq_res) in fsl_espi_detach()
217 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq_res); in fsl_espi_detach()
218 if (sc->sc_mem_res) in fsl_espi_detach()
219 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mem_res); in fsl_espi_detach()
231 cmd = sc->sc_cmd; in fsl_espi_fill_fifo()
233 while (sc->sc_written < sc->sc_len && in fsl_espi_fill_fifo()
235 data = (uint8_t *)cmd->tx_cmd; in fsl_espi_fill_fifo()
236 written = sc->sc_written++; in fsl_espi_fill_fifo()
237 if (written >= cmd->tx_cmd_sz) { in fsl_espi_fill_fifo()
238 data = (uint8_t *)cmd->tx_data; in fsl_espi_fill_fifo()
239 written -= cmd->tx_cmd_sz; in fsl_espi_fill_fifo()
254 cmd = sc->sc_cmd; in fsl_espi_drain_fifo()
256 while (sc->sc_read < sc->sc_len && (spier & ESPI_SPIE_RNE)) { in fsl_espi_drain_fifo()
257 data = (uint8_t *)cmd->rx_cmd; in fsl_espi_drain_fifo()
258 read = sc->sc_read++; in fsl_espi_drain_fifo()
259 if (read >= cmd->rx_cmd_sz) { in fsl_espi_drain_fifo()
260 data = (uint8_t *)cmd->rx_data; in fsl_espi_drain_fifo()
261 read -= cmd->rx_cmd_sz; in fsl_espi_drain_fifo()
279 if ((sc->sc_flags & FSL_ESPI_BUSY) == 0) { in fsl_espi_intr()
286 /* TX - Fill up the FIFO. */ in fsl_espi_intr()
289 /* RX - Drain the FIFO. */ in fsl_espi_intr()
294 wakeup(sc->sc_dev); in fsl_espi_intr()
309 KASSERT(cmd->tx_cmd_sz == cmd->rx_cmd_sz, in fsl_espi_transfer()
311 KASSERT(cmd->tx_data_sz == cmd->rx_data_sz, in fsl_espi_transfer()
315 if (cmd->tx_cmd_sz + cmd->tx_data_sz > ESPI_SPCOM_TRANLEN_M + 1) { in fsl_espi_transfer()
321 if (cs < 0 || cs > sc->sc_num_cs) { in fsl_espi_transfer()
333 while (sc->sc_flags & FSL_ESPI_BUSY) in fsl_espi_transfer()
334 mtx_sleep(dev, &sc->sc_mtx, 0, "fsl_espi", 0); in fsl_espi_transfer()
337 sc->sc_flags = FSL_ESPI_BUSY; in fsl_espi_transfer()
340 sc->sc_cmd = cmd; in fsl_espi_transfer()
341 sc->sc_read = 0; in fsl_espi_transfer()
342 sc->sc_written = 0; in fsl_espi_transfer()
343 sc->sc_len = cmd->tx_cmd_sz + cmd->tx_data_sz; in fsl_espi_transfer()
357 pm = howmany(plat_clk, spi_clk * 2) - 1; in fsl_espi_transfer()
371 csmode |= ESPI_CSMODE_LEN(7);/* Only deal with 8-bit characters. */ in fsl_espi_transfer()
374 FSL_ESPI_WRITE(sc, ESPI_SPCOM, (cs << ESPI_SPCOM_CS_S) | (sc->sc_len - 1)); in fsl_espi_transfer()
381 err = mtx_sleep(dev, &sc->sc_mtx, 0, "fsl_espi", hz * 2); in fsl_espi_transfer()
385 sc->sc_flags = 0; in fsl_espi_transfer()
394 device_printf(sc->sc_dev, "SPI error\n"); in fsl_espi_transfer()