drivers/spi/spi-microchip-core-spi.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-microchip-core-spi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-microchip-core-spi.c- Extension
.c- Size
- 12301 bytes
- Lines
- 432
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/delay.hlinux/err.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/spi/spi.h
Detected Declarations
struct mchp_corespifunction mchp_corespi_disablefunction mchp_corespi_read_fifofunction mchp_corespi_enable_intsfunction mchp_corespi_disable_intsfunction mchp_corespi_write_fifofunction mchp_corespi_set_csfunction mchp_corespi_setupfunction mchp_corespi_initfunction mchp_corespi_interruptfunction mchp_corespi_set_clk_divfunction mchp_corespi_transfer_onefunction mchp_corespi_probefunction mchp_corespi_remove
Annotated Snippet
struct mchp_corespi {
void __iomem *regs;
struct clk *clk;
const u8 *tx_buf;
u8 *rx_buf;
u32 clk_gen;
int irq;
unsigned int tx_len;
unsigned int rx_len;
u32 fifo_depth;
};
static inline void mchp_corespi_disable(struct mchp_corespi *spi)
{
u8 control = readb(spi->regs + MCHP_CORESPI_REG_CONTROL);
control &= ~MCHP_CORESPI_CONTROL_ENABLE;
writeb(control, spi->regs + MCHP_CORESPI_REG_CONTROL);
}
static inline void mchp_corespi_read_fifo(struct mchp_corespi *spi, u32 fifo_max)
{
for (int i = 0; i < fifo_max; i++) {
u32 data;
while (readb(spi->regs + MCHP_CORESPI_REG_STAT) &
MCHP_CORESPI_STATUS_RXFIFO_EMPTY)
;
/* On TX-only transfers always perform a dummy read */
data = readb(spi->regs + MCHP_CORESPI_REG_RXDATA);
if (spi->rx_buf)
*spi->rx_buf++ = data;
spi->rx_len--;
}
}
static void mchp_corespi_enable_ints(struct mchp_corespi *spi)
{
u8 control = readb(spi->regs + MCHP_CORESPI_REG_CONTROL);
control |= INT_ENABLE_MASK;
writeb(control, spi->regs + MCHP_CORESPI_REG_CONTROL);
}
static void mchp_corespi_disable_ints(struct mchp_corespi *spi)
{
u8 control = readb(spi->regs + MCHP_CORESPI_REG_CONTROL);
control &= ~INT_ENABLE_MASK;
writeb(control, spi->regs + MCHP_CORESPI_REG_CONTROL);
}
static inline void mchp_corespi_write_fifo(struct mchp_corespi *spi, u32 fifo_max)
{
for (int i = 0; i < fifo_max; i++) {
if (readb(spi->regs + MCHP_CORESPI_REG_STAT) &
MCHP_CORESPI_STATUS_TXFIFO_FULL)
break;
/* On RX-only transfers always perform a dummy write */
if (spi->tx_buf)
writeb(*spi->tx_buf++, spi->regs + MCHP_CORESPI_REG_TXDATA);
else
writeb(0xaa, spi->regs + MCHP_CORESPI_REG_TXDATA);
spi->tx_len--;
}
}
static void mchp_corespi_set_cs(struct spi_device *spi, bool disable)
{
struct mchp_corespi *corespi = spi_controller_get_devdata(spi->controller);
u32 reg;
reg = readb(corespi->regs + MCHP_CORESPI_REG_SSEL);
reg &= ~BIT(spi_get_chipselect(spi, 0));
reg |= !disable << spi_get_chipselect(spi, 0);
writeb(reg, corespi->regs + MCHP_CORESPI_REG_SSEL);
}
static int mchp_corespi_setup(struct spi_device *spi)
{
if (spi_get_csgpiod(spi, 0))
return 0;
if (spi->mode & (SPI_CS_HIGH)) {
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/err.h`, `linux/init.h`, `linux/interrupt.h`, `linux/io.h`, `linux/module.h`, `linux/of.h`.
- Detected declarations: `struct mchp_corespi`, `function mchp_corespi_disable`, `function mchp_corespi_read_fifo`, `function mchp_corespi_enable_ints`, `function mchp_corespi_disable_ints`, `function mchp_corespi_write_fifo`, `function mchp_corespi_set_cs`, `function mchp_corespi_setup`, `function mchp_corespi_init`, `function mchp_corespi_interrupt`.
- 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.