drivers/spi/spi-mpc512x-psc.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-mpc512x-psc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-mpc512x-psc.c- Extension
.c- Size
- 14077 bytes
- Lines
- 537
- Domain
- Driver Families
- Bucket
- drivers/spi
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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
linux/module.hlinux/kernel.hlinux/errno.hlinux/interrupt.hlinux/completion.hlinux/io.hlinux/platform_device.hlinux/property.hlinux/delay.hlinux/clk.hlinux/spi/spi.hasm/mpc52xx_psc.h
Detected Declarations
struct mpc512x_psc_spistruct mpc512x_psc_spi_csfunction mpc512x_psc_spi_transfer_setupfunction mpc512x_psc_spi_activate_csfunction mpc512x_psc_spi_deactivate_csfunction mpc512x_psc_spi_transfer_rxtxfunction NOPfunction mpc512x_psc_spi_msg_xferfunction mpc512x_psc_spi_prep_xfer_hwfunction mpc512x_psc_spi_unprep_xfer_hwfunction mpc512x_psc_spi_setupfunction mpc512x_psc_spi_cleanupfunction mpc512x_psc_spi_port_configfunction mpc512x_psc_spi_isrfunction in_be32function mpc512x_psc_spi_of_probe
Annotated Snippet
struct mpc512x_psc_spi {
/* driver internal data */
int type;
void __iomem *psc;
struct mpc512x_psc_fifo __iomem *fifo;
int irq;
u8 bits_per_word;
u32 mclk_rate;
struct completion txisrdone;
};
/* controller state */
struct mpc512x_psc_spi_cs {
int bits_per_word;
int speed_hz;
};
/* set clock freq, clock ramp, bits per work
* if t is NULL then reset the values to the default values
*/
static int mpc512x_psc_spi_transfer_setup(struct spi_device *spi,
struct spi_transfer *t)
{
struct mpc512x_psc_spi_cs *cs = spi->controller_state;
cs->speed_hz = (t && t->speed_hz)
? t->speed_hz : spi->max_speed_hz;
cs->bits_per_word = (t && t->bits_per_word)
? t->bits_per_word : spi->bits_per_word;
cs->bits_per_word = ((cs->bits_per_word + 7) / 8) * 8;
return 0;
}
static void mpc512x_psc_spi_activate_cs(struct spi_device *spi)
{
struct mpc512x_psc_spi_cs *cs = spi->controller_state;
struct mpc512x_psc_spi *mps = spi_controller_get_devdata(spi->controller);
u32 sicr;
u32 ccr;
int speed;
u16 bclkdiv;
sicr = in_be32(psc_addr(mps, sicr));
/* Set clock phase and polarity */
if (spi->mode & SPI_CPHA)
sicr |= 0x00001000;
else
sicr &= ~0x00001000;
if (spi->mode & SPI_CPOL)
sicr |= 0x00002000;
else
sicr &= ~0x00002000;
if (spi->mode & SPI_LSB_FIRST)
sicr |= 0x10000000;
else
sicr &= ~0x10000000;
out_be32(psc_addr(mps, sicr), sicr);
ccr = in_be32(psc_addr(mps, ccr));
ccr &= 0xFF000000;
speed = cs->speed_hz;
if (!speed)
speed = 1000000; /* default 1MHz */
bclkdiv = (mps->mclk_rate / speed) - 1;
ccr |= (((bclkdiv & 0xff) << 16) | (((bclkdiv >> 8) & 0xff) << 8));
out_be32(psc_addr(mps, ccr), ccr);
mps->bits_per_word = cs->bits_per_word;
if (spi_get_csgpiod(spi, 0)) {
/* gpiolib will deal with the inversion */
gpiod_set_value(spi_get_csgpiod(spi, 0), 1);
}
}
static void mpc512x_psc_spi_deactivate_cs(struct spi_device *spi)
{
if (spi_get_csgpiod(spi, 0)) {
/* gpiolib will deal with the inversion */
gpiod_set_value(spi_get_csgpiod(spi, 0), 0);
}
}
/* extract and scale size field in txsz or rxsz */
#define MPC512x_PSC_FIFO_SZ(sz) ((sz & 0x7ff) << 2);
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/errno.h`, `linux/interrupt.h`, `linux/completion.h`, `linux/io.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct mpc512x_psc_spi`, `struct mpc512x_psc_spi_cs`, `function mpc512x_psc_spi_transfer_setup`, `function mpc512x_psc_spi_activate_cs`, `function mpc512x_psc_spi_deactivate_cs`, `function mpc512x_psc_spi_transfer_rxtx`, `function NOP`, `function mpc512x_psc_spi_msg_xfer`, `function mpc512x_psc_spi_prep_xfer_hw`, `function mpc512x_psc_spi_unprep_xfer_hw`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: source implementation candidate.
- 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.