drivers/spi/spi-mpc52xx.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-mpc52xx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-mpc52xx.c- Extension
.c- Size
- 14514 bytes
- Lines
- 559
- 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.
- 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
linux/module.hlinux/err.hlinux/errno.hlinux/of_platform.hlinux/interrupt.hlinux/delay.hlinux/gpio/consumer.hlinux/spi/spi.hlinux/io.hlinux/slab.hlinux/of_address.hlinux/of_irq.hlinux/platform_device.hasm/time.hasm/mpc52xx.h
Detected Declarations
struct mpc52xx_spifunction mpc52xx_spi_chipselfunction mpc52xx_spi_start_transferfunction mpc52xx_spi_fsmstate_idlefunction mpc52xx_spi_fsmstate_transferfunction mpc52xx_spi_fsmstate_waitfunction mpc52xx_spi_fsm_processfunction mpc52xx_spi_irqfunction mpc52xx_spi_wqfunction mpc52xx_spi_transferfunction mpc52xx_spi_probefunction mpc52xx_spi_remove
Annotated Snippet
struct mpc52xx_spi {
struct spi_controller *host;
void __iomem *regs;
int irq0; /* MODF irq */
int irq1; /* SPIF irq */
unsigned int ipb_freq;
/* Statistics; not used now, but will be reintroduced for debugfs */
int msg_count;
int wcol_count;
int wcol_ticks;
u32 wcol_tx_timestamp;
int modf_count;
int byte_count;
struct list_head queue; /* queue of pending messages */
spinlock_t lock;
struct work_struct work;
/* Details of current transfer (length, and buffer pointers) */
struct spi_message *message; /* current message */
struct spi_transfer *transfer; /* current transfer */
int (*state)(int irq, struct mpc52xx_spi *ms, u8 status, u8 data);
int len;
int timestamp;
u8 *rx_buf;
const u8 *tx_buf;
int cs_change;
int gpio_cs_count;
struct gpio_desc **gpio_cs;
};
/*
* CS control function
*/
static void mpc52xx_spi_chipsel(struct mpc52xx_spi *ms, int value)
{
int cs;
if (ms->gpio_cs_count > 0) {
cs = spi_get_chipselect(ms->message->spi, 0);
gpiod_set_value(ms->gpio_cs[cs], value);
} else {
out_8(ms->regs + SPI_PORTDATA, value ? 0 : 0x08);
}
}
/*
* Start a new transfer. This is called both by the idle state
* for the first transfer in a message, and by the wait state when the
* previous transfer in a message is complete.
*/
static void mpc52xx_spi_start_transfer(struct mpc52xx_spi *ms)
{
ms->rx_buf = ms->transfer->rx_buf;
ms->tx_buf = ms->transfer->tx_buf;
ms->len = ms->transfer->len;
/* Activate the chip select */
if (ms->cs_change)
mpc52xx_spi_chipsel(ms, 1);
ms->cs_change = ms->transfer->cs_change;
/* Write out the first byte */
ms->wcol_tx_timestamp = mftb();
if (ms->tx_buf)
out_8(ms->regs + SPI_DATA, *ms->tx_buf++);
else
out_8(ms->regs + SPI_DATA, 0);
}
/* Forward declaration of state handlers */
static int mpc52xx_spi_fsmstate_transfer(int irq, struct mpc52xx_spi *ms,
u8 status, u8 data);
static int mpc52xx_spi_fsmstate_wait(int irq, struct mpc52xx_spi *ms,
u8 status, u8 data);
/*
* IDLE state
*
* No transfers are in progress; if another transfer is pending then retrieve
* it and kick it off. Otherwise, stop processing the state machine
*/
static int
mpc52xx_spi_fsmstate_idle(int irq, struct mpc52xx_spi *ms, u8 status, u8 data)
{
struct spi_device *spi;
int spr, sppr;
u8 ctrl1;
Annotation
- Immediate include surface: `linux/module.h`, `linux/err.h`, `linux/errno.h`, `linux/of_platform.h`, `linux/interrupt.h`, `linux/delay.h`, `linux/gpio/consumer.h`, `linux/spi/spi.h`.
- Detected declarations: `struct mpc52xx_spi`, `function mpc52xx_spi_chipsel`, `function mpc52xx_spi_start_transfer`, `function mpc52xx_spi_fsmstate_idle`, `function mpc52xx_spi_fsmstate_transfer`, `function mpc52xx_spi_fsmstate_wait`, `function mpc52xx_spi_fsm_process`, `function mpc52xx_spi_irq`, `function mpc52xx_spi_wq`, `function mpc52xx_spi_transfer`.
- Atlas domain: Driver Families / drivers/spi.
- Implementation status: source 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.