Lines Matching +full:qe +full:- +full:muram
1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * CPM SPI and QE buffer descriptors mode support:
15 #include <soc/fsl/qe/qe.h>
16 #include <linux/dma-mapping.h>
26 #include "spi-fsl-cpm.h"
27 #include "spi-fsl-lib.h"
28 #include "spi-fsl-spi.h"
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()
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()
86 iowrite16be(0, &rx_bd->cbd_datlen); in fsl_spi_cpm_bufs_start()
87 iowrite16be(BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP, &rx_bd->cbd_sc); 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()
93 iowrite16be(xfer_len, &tx_bd->cbd_datlen); in fsl_spi_cpm_bufs_start()
95 &tx_bd->cbd_sc); in fsl_spi_cpm_bufs_start()
98 mpc8xxx_spi_write_reg(®_base->command, SPCOM_STR); in fsl_spi_cpm_bufs_start()
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()
109 if (!t->tx_buf) { 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()
114 if (!t->rx_buf) { 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()
118 if (t->bits_per_word == 16 && t->tx_buf) { in fsl_spi_cpm_bufs()
119 const u16 *src = t->tx_buf; in fsl_spi_cpm_bufs()
123 dst = kmalloc(t->len, GFP_KERNEL); in fsl_spi_cpm_bufs()
125 return -ENOMEM; in fsl_spi_cpm_bufs()
127 for (i = 0; i < t->len >> 1; i++) 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()
141 return -ENOMEM; in fsl_spi_cpm_bufs()
143 } else if (t->tx_buf) { 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()
154 } else if (t->rx_buf) { in fsl_spi_cpm_bufs()
155 mspi->rx_dma = t->rx_dma; in fsl_spi_cpm_bufs()
159 mpc8xxx_spi_write_reg(®_base->mask, SPIE_RXB); 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()
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()
172 return -ENOMEM; in fsl_spi_cpm_bufs()
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()
187 if (t->bits_per_word == 16 && t->rx_buf) { in fsl_spi_cpm_bufs_complete()
190 for (i = 0; i < t->len; i += 2) in fsl_spi_cpm_bufs_complete()
191 le16_to_cpus(t->rx_buf + i); in fsl_spi_cpm_bufs_complete()
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()
211 mpc8xxx_spi_write_reg(®_base->event, events); in fsl_spi_cpm_irq()
213 mspi->count -= len; in fsl_spi_cpm_irq()
214 if (mspi->count) in fsl_spi_cpm_irq()
217 complete(&mspi->done); in fsl_spi_cpm_irq()
248 fsl_dummy_rx_refcnt--; in fsl_spi_free_dummy_rx()
257 struct device *dev = mspi->dev; in fsl_spi_cpm_get_pram()
258 struct device_node *np = dev->of_node; in fsl_spi_cpm_get_pram()
262 unsigned long pram_ofs = -ENOMEM; in fsl_spi_cpm_get_pram()
264 /* Can't use of_address_to_resource(), QE muram isn't at 0. */ in fsl_spi_cpm_get_pram()
267 /* QE with a fixed pram location? */ in fsl_spi_cpm_get_pram()
268 if (mspi->flags & SPI_QE && iprop && size == sizeof(*iprop) * 4) in fsl_spi_cpm_get_pram()
271 /* QE but with a dynamic pram location? */ 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()
281 return -EINVAL; in fsl_spi_cpm_get_pram()
283 if (mspi->flags & SPI_CPM2) { in fsl_spi_cpm_get_pram()
294 struct device *dev = mspi->dev; in fsl_spi_cpm_init()
295 struct device_node *np = dev->of_node; in fsl_spi_cpm_init()
300 if (!(mspi->flags & SPI_CPM_MODE)) in fsl_spi_cpm_init()
304 return -ENOMEM; in fsl_spi_cpm_init()
306 if (mspi->flags & SPI_QE) { in fsl_spi_cpm_init()
307 iprop = of_get_property(np, "cell-index", &size); in fsl_spi_cpm_init()
309 mspi->subblock = *iprop; in fsl_spi_cpm_init()
311 switch (mspi->subblock) { in fsl_spi_cpm_init()
313 dev_warn(dev, "cell-index unspecified, assuming SPI1\n"); 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()
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()
398 return -ENOMEM; in fsl_spi_cpm_init()
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()