drivers/spi/spi-fsl-cpm.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-fsl-cpm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-fsl-cpm.c- Extension
.c- Size
- 10615 bytes
- Lines
- 420
- Domain
- Driver Families
- Bucket
- drivers/spi
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/cpm.hsoc/fsl/qe/qe.hlinux/dma-mapping.hlinux/fsl_devices.hlinux/kernel.hlinux/module.hlinux/of_address.hlinux/spi/spi.hlinux/types.hlinux/platform_device.hlinux/byteorder/generic.hspi-fsl-cpm.hspi-fsl-lib.hspi-fsl-spi.hasm/cpm1.hasm/cpm2.h
Detected Declarations
function fsl_spi_cpm_reinit_txrxfunction fsl_spi_cpm_bufs_startfunction fsl_spi_cpm_bufsfunction fsl_spi_cpm_bufs_completefunction fsl_spi_cpm_irqfunction fsl_spi_free_dummy_rxfunction fsl_spi_cpm_get_pramfunction fsl_spi_cpm_initfunction fsl_spi_cpm_freeexport fsl_spi_cpm_reinit_txrxexport fsl_spi_cpm_bufsexport fsl_spi_cpm_bufs_completeexport fsl_spi_cpm_irqexport fsl_spi_cpm_initexport fsl_spi_cpm_free
Annotated Snippet
if (mspi->flags & SPI_CPM1) {
iowrite32be(0, &mspi->pram->rstate);
iowrite16be(ioread16be(&mspi->pram->rbase),
&mspi->pram->rbptr);
iowrite32be(0, &mspi->pram->tstate);
iowrite16be(ioread16be(&mspi->pram->tbase),
&mspi->pram->tbptr);
} else {
cpm_command(CPM_SPI_CMD, CPM_CR_INIT_TRX);
}
}
}
EXPORT_SYMBOL_GPL(fsl_spi_cpm_reinit_txrx);
static void fsl_spi_cpm_bufs_start(struct mpc8xxx_spi *mspi)
{
struct cpm_buf_desc __iomem *tx_bd = mspi->tx_bd;
struct cpm_buf_desc __iomem *rx_bd = mspi->rx_bd;
unsigned int xfer_len = min(mspi->count, SPI_MRBLR);
unsigned int xfer_ofs;
struct fsl_spi_reg __iomem *reg_base = mspi->reg_base;
xfer_ofs = mspi->xfer_in_progress->len - mspi->count;
if (mspi->rx_dma == mspi->dma_dummy_rx)
iowrite32be(mspi->rx_dma, &rx_bd->cbd_bufaddr);
else
iowrite32be(mspi->rx_dma + xfer_ofs, &rx_bd->cbd_bufaddr);
iowrite16be(0, &rx_bd->cbd_datlen);
iowrite16be(BD_SC_EMPTY | BD_SC_INTRPT | BD_SC_WRAP, &rx_bd->cbd_sc);
if (mspi->tx_dma == mspi->dma_dummy_tx)
iowrite32be(mspi->tx_dma, &tx_bd->cbd_bufaddr);
else
iowrite32be(mspi->tx_dma + xfer_ofs, &tx_bd->cbd_bufaddr);
iowrite16be(xfer_len, &tx_bd->cbd_datlen);
iowrite16be(BD_SC_READY | BD_SC_INTRPT | BD_SC_WRAP | BD_SC_LAST,
&tx_bd->cbd_sc);
/* start transfer */
mpc8xxx_spi_write_reg(®_base->command, SPCOM_STR);
}
int fsl_spi_cpm_bufs(struct mpc8xxx_spi *mspi, struct spi_transfer *t)
{
struct device *dev = mspi->dev;
struct fsl_spi_reg __iomem *reg_base = mspi->reg_base;
mspi->map_tx_dma = 1;
mspi->map_rx_dma = 1;
if (!t->tx_buf) {
mspi->tx_dma = mspi->dma_dummy_tx;
mspi->map_tx_dma = 0;
}
if (!t->rx_buf) {
mspi->rx_dma = mspi->dma_dummy_rx;
mspi->map_rx_dma = 0;
}
if (t->bits_per_word == 16 && t->tx_buf) {
const u16 *src = t->tx_buf;
__le16 *dst;
int i;
dst = kmalloc(t->len, GFP_KERNEL);
if (!dst)
return -ENOMEM;
for (i = 0; i < t->len >> 1; i++)
dst[i] = cpu_to_le16p(src + i);
mspi->tx = dst;
mspi->map_tx_dma = 1;
}
if (mspi->map_tx_dma) {
void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */
mspi->tx_dma = dma_map_single(dev, nonconst_tx, t->len,
DMA_TO_DEVICE);
if (dma_mapping_error(dev, mspi->tx_dma)) {
dev_err(dev, "unable to map tx dma\n");
return -ENOMEM;
}
} else if (t->tx_buf) {
mspi->tx_dma = 0;
}
if (mspi->map_rx_dma) {
Annotation
- Immediate include surface: `asm/cpm.h`, `soc/fsl/qe/qe.h`, `linux/dma-mapping.h`, `linux/fsl_devices.h`, `linux/kernel.h`, `linux/module.h`, `linux/of_address.h`, `linux/spi/spi.h`.
- Detected declarations: `function fsl_spi_cpm_reinit_txrx`, `function fsl_spi_cpm_bufs_start`, `function fsl_spi_cpm_bufs`, `function fsl_spi_cpm_bufs_complete`, `function fsl_spi_cpm_irq`, `function fsl_spi_free_dummy_rx`, `function fsl_spi_cpm_get_pram`, `function fsl_spi_cpm_init`, `function fsl_spi_cpm_free`, `export fsl_spi_cpm_reinit_txrx`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.