Lines Matching full:mspi

52 void fsl_spi_cpm_reinit_txrx(struct mpc8xxx_spi *mspi)  in fsl_spi_cpm_reinit_txrx()  argument
54 if (mspi->flags & SPI_QE) { in fsl_spi_cpm_reinit_txrx()
55 qe_issue_cmd(QE_INIT_TX_RX, mspi->subblock, in fsl_spi_cpm_reinit_txrx()
58 if (mspi->flags & SPI_CPM1) { in fsl_spi_cpm_reinit_txrx()
59 iowrite32be(0, &mspi->pram->rstate); in fsl_spi_cpm_reinit_txrx()
60 iowrite16be(ioread16be(&mspi->pram->rbase), in fsl_spi_cpm_reinit_txrx()
61 &mspi->pram->rbptr); in fsl_spi_cpm_reinit_txrx()
62 iowrite32be(0, &mspi->pram->tstate); in fsl_spi_cpm_reinit_txrx()
63 iowrite16be(ioread16be(&mspi->pram->tbase), in fsl_spi_cpm_reinit_txrx()
64 &mspi->pram->tbptr); in fsl_spi_cpm_reinit_txrx()
72 static void fsl_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi) in fsl_spi_cpm_bufs_start() argument
74 struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd; in fsl_spi_cpm_bufs_start()
75 struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd; in fsl_spi_cpm_bufs_start()
76 unsigned int xfer_len = min(mspi->count, SPI_MRBLR); in fsl_spi_cpm_bufs_start()
78 struct fsl_spi_reg __iomem *reg_base = mspi->reg_base; in fsl_spi_cpm_bufs_start()
80 xfer_ofs = mspi->xfer_in_progress->len - mspi->count; in fsl_spi_cpm_bufs_start()
82 if (mspi->rx_dma == mspi->dma_dummy_rx) in fsl_spi_cpm_bufs_start()
83 iowrite32be(mspi->rx_dma, &rx_bd->cbd_bufaddr); in fsl_spi_cpm_bufs_start()
85 iowrite32be(mspi->rx_dma + xfer_ofs, &rx_bd->cbd_bufaddr); in fsl_spi_cpm_bufs_start()
89 if (mspi->tx_dma == mspi->dma_dummy_tx) in fsl_spi_cpm_bufs_start()
90 iowrite32be(mspi->tx_dma, &tx_bd->cbd_bufaddr); in fsl_spi_cpm_bufs_start()
92 iowrite32be(mspi->tx_dma + xfer_ofs, &tx_bd->cbd_bufaddr); in fsl_spi_cpm_bufs_start()
101 int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, struct spi_transfer *t) in fsl_spi_cpm_bufs() argument
103 struct device *dev = mspi->dev; in fsl_spi_cpm_bufs()
104 struct fsl_spi_reg __iomem *reg_base = mspi->reg_base; in fsl_spi_cpm_bufs()
106 mspi->map_tx_dma = 1; in fsl_spi_cpm_bufs()
107 mspi->map_rx_dma = 1; in fsl_spi_cpm_bufs()
110 mspi->tx_dma = mspi->dma_dummy_tx; in fsl_spi_cpm_bufs()
111 mspi->map_tx_dma = 0; in fsl_spi_cpm_bufs()
115 mspi->rx_dma = mspi->dma_dummy_rx; in fsl_spi_cpm_bufs()
116 mspi->map_rx_dma = 0; in fsl_spi_cpm_bufs()
130 mspi->tx = dst; in fsl_spi_cpm_bufs()
131 mspi->map_tx_dma = 1; in fsl_spi_cpm_bufs()
134 if (mspi->map_tx_dma) { in fsl_spi_cpm_bufs()
135 void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */ in fsl_spi_cpm_bufs()
137 mspi->tx_dma = dma_map_single(dev, nonconst_tx, t->len, in fsl_spi_cpm_bufs()
139 if (dma_mapping_error(dev, mspi->tx_dma)) { in fsl_spi_cpm_bufs()
144 mspi->tx_dma = 0; in fsl_spi_cpm_bufs()
147 if (mspi->map_rx_dma) { in fsl_spi_cpm_bufs()
148 mspi->rx_dma = dma_map_single(dev, mspi->rx, t->len, in fsl_spi_cpm_bufs()
150 if (dma_mapping_error(dev, mspi->rx_dma)) { in fsl_spi_cpm_bufs()
155 mspi->rx_dma = t->rx_dma; in fsl_spi_cpm_bufs()
161 mspi->xfer_in_progress = t; in fsl_spi_cpm_bufs()
162 mspi->count = t->len; in fsl_spi_cpm_bufs()
165 fsl_spi_cpm_bufs_start(mspi); in fsl_spi_cpm_bufs()
170 if (mspi->map_tx_dma) in fsl_spi_cpm_bufs()
171 dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE); in fsl_spi_cpm_bufs()
176 void fsl_spi_cpm_bufs_complete(struct mpc8xxx_spi *mspi) in fsl_spi_cpm_bufs_complete() argument
178 struct device *dev = mspi->dev; in fsl_spi_cpm_bufs_complete()
179 struct spi_transfer *t = mspi->xfer_in_progress; in fsl_spi_cpm_bufs_complete()
181 if (mspi->map_tx_dma) in fsl_spi_cpm_bufs_complete()
182 dma_unmap_single(dev, mspi->tx_dma, t->len, DMA_TO_DEVICE); in fsl_spi_cpm_bufs_complete()
183 if (mspi->map_rx_dma) in fsl_spi_cpm_bufs_complete()
184 dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE); in fsl_spi_cpm_bufs_complete()
185 mspi->xfer_in_progress = NULL; in fsl_spi_cpm_bufs_complete()
196 void fsl_spi_cpm_irq(struct mpc8xxx_spi *mspi, u32 events) in fsl_spi_cpm_irq() argument
199 struct fsl_spi_reg __iomem *reg_base = mspi->reg_base; in fsl_spi_cpm_irq()
201 dev_dbg(mspi->dev, "%s: bd datlen %d, count %d\n", __func__, in fsl_spi_cpm_irq()
202 ioread16be(&mspi->rx_bd->cbd_datlen), mspi->count); in fsl_spi_cpm_irq()
204 len = ioread16be(&mspi->rx_bd->cbd_datlen); in fsl_spi_cpm_irq()
205 if (len > mspi->count) { in fsl_spi_cpm_irq()
207 len = mspi->count; in fsl_spi_cpm_irq()
213 mspi->count -= len; in fsl_spi_cpm_irq()
214 if (mspi->count) in fsl_spi_cpm_irq()
215 fsl_spi_cpm_bufs_start(mspi); in fsl_spi_cpm_irq()
217 complete(&mspi->done); in fsl_spi_cpm_irq()
255 static unsigned long fsl_spi_cpm_get_pram(struct mpc8xxx_spi *mspi) in fsl_spi_cpm_get_pram() argument
257 struct device *dev = mspi->dev; in fsl_spi_cpm_get_pram()
268 if (mspi->flags & SPI_QE && iprop && size == sizeof(*iprop) * 4) in fsl_spi_cpm_get_pram()
272 if (mspi->flags & SPI_QE) { in fsl_spi_cpm_get_pram()
274 qe_issue_cmd(QE_ASSIGN_PAGE_TO_DEVICE, mspi->subblock, in fsl_spi_cpm_get_pram()
283 if (mspi->flags & SPI_CPM2) { in fsl_spi_cpm_get_pram()
292 int fsl_spi_cpm_init(struct mpc8xxx_spi *mspi) in fsl_spi_cpm_init() argument
294 struct device *dev = mspi->dev; in fsl_spi_cpm_init()
300 if (!(mspi->flags & SPI_CPM_MODE)) in fsl_spi_cpm_init()
306 if (mspi->flags & SPI_QE) { in fsl_spi_cpm_init()
309 mspi->subblock = *iprop; in fsl_spi_cpm_init()
311 switch (mspi->subblock) { in fsl_spi_cpm_init()
316 mspi->subblock = QE_CR_SUBBLOCK_SPI1; in fsl_spi_cpm_init()
319 mspi->subblock = QE_CR_SUBBLOCK_SPI2; in fsl_spi_cpm_init()
324 if (mspi->flags & SPI_CPM1) { in fsl_spi_cpm_init()
330 mspi->pram = NULL; in fsl_spi_cpm_init()
332 mspi->pram = pram; in fsl_spi_cpm_init()
334 unsigned long pram_ofs = fsl_spi_cpm_get_pram(mspi); in fsl_spi_cpm_init()
337 mspi->pram = NULL; in fsl_spi_cpm_init()
339 mspi->pram = cpm_muram_addr(pram_ofs); in fsl_spi_cpm_init()
341 if (mspi->pram == NULL) { in fsl_spi_cpm_init()
346 bds_ofs = cpm_muram_alloc(sizeof(*mspi->tx_bd) + in fsl_spi_cpm_init()
347 sizeof(*mspi->rx_bd), 8); in fsl_spi_cpm_init()
353 mspi->dma_dummy_tx = dma_map_single(dev, ZERO_PAGE(0), PAGE_SIZE, in fsl_spi_cpm_init()
355 if (dma_mapping_error(dev, mspi->dma_dummy_tx)) { in fsl_spi_cpm_init()
360 mspi->dma_dummy_rx = dma_map_single(dev, fsl_dummy_rx, SPI_MRBLR, in fsl_spi_cpm_init()
362 if (dma_mapping_error(dev, mspi->dma_dummy_rx)) { in fsl_spi_cpm_init()
367 mspi->tx_bd = cpm_muram_addr(bds_ofs); in fsl_spi_cpm_init()
368 mspi->rx_bd = cpm_muram_addr(bds_ofs + sizeof(*mspi->tx_bd)); in fsl_spi_cpm_init()
371 iowrite16be(cpm_muram_offset(mspi->tx_bd), &mspi->pram->tbase); in fsl_spi_cpm_init()
372 iowrite16be(cpm_muram_offset(mspi->rx_bd), &mspi->pram->rbase); in fsl_spi_cpm_init()
373 iowrite8(CPMFCR_EB | CPMFCR_GBL, &mspi->pram->tfcr); in fsl_spi_cpm_init()
374 iowrite8(CPMFCR_EB | CPMFCR_GBL, &mspi->pram->rfcr); in fsl_spi_cpm_init()
375 iowrite16be(SPI_MRBLR, &mspi->pram->mrblr); in fsl_spi_cpm_init()
376 iowrite32be(0, &mspi->pram->rstate); in fsl_spi_cpm_init()
377 iowrite32be(0, &mspi->pram->rdp); in fsl_spi_cpm_init()
378 iowrite16be(0, &mspi->pram->rbptr); in fsl_spi_cpm_init()
379 iowrite16be(0, &mspi->pram->rbc); in fsl_spi_cpm_init()
380 iowrite32be(0, &mspi->pram->rxtmp); in fsl_spi_cpm_init()
381 iowrite32be(0, &mspi->pram->tstate); in fsl_spi_cpm_init()
382 iowrite32be(0, &mspi->pram->tdp); in fsl_spi_cpm_init()
383 iowrite16be(0, &mspi->pram->tbptr); in fsl_spi_cpm_init()
384 iowrite16be(0, &mspi->pram->tbc); in fsl_spi_cpm_init()
385 iowrite32be(0, &mspi->pram->txtmp); in fsl_spi_cpm_init()
390 dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); in fsl_spi_cpm_init()
394 if (!(mspi->flags & SPI_CPM1)) in fsl_spi_cpm_init()
395 cpm_muram_free(cpm_muram_offset(mspi->pram)); in fsl_spi_cpm_init()
402 void fsl_spi_cpm_free(struct mpc8xxx_spi *mspi) in fsl_spi_cpm_free() argument
404 struct device *dev = mspi->dev; in fsl_spi_cpm_free()
406 if (!(mspi->flags & SPI_CPM_MODE)) in fsl_spi_cpm_free()
409 dma_unmap_single(dev, mspi->dma_dummy_rx, SPI_MRBLR, DMA_FROM_DEVICE); in fsl_spi_cpm_free()
410 dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); in fsl_spi_cpm_free()
411 cpm_muram_free(cpm_muram_offset(mspi->tx_bd)); in fsl_spi_cpm_free()
412 if (!(mspi->flags & SPI_CPM1)) in fsl_spi_cpm_free()
413 cpm_muram_free(cpm_muram_offset(mspi->pram)); in fsl_spi_cpm_free()