drivers/spi/spi-bcm2835.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-bcm2835.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-bcm2835.c- Extension
.c- Size
- 43250 bytes
- Lines
- 1459
- 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/cleanup.hlinux/clk.hlinux/completion.hlinux/debugfs.hlinux/delay.hlinux/dma-mapping.hlinux/dmaengine.hlinux/err.hlinux/interrupt.hlinux/io.hlinux/kernel.hlinux/module.hlinux/of.hlinux/of_address.hlinux/platform_device.hlinux/gpio/consumer.hlinux/gpio/machine.hlinux/of_irq.hlinux/overflow.hlinux/slab.hlinux/spi/spi.h
Detected Declarations
struct bcm2835_spistruct bcm2835_spidevfunction bcm2835_debugfs_createfunction bcm2835_debugfs_removefunction bcm2835_debugfs_createfunction bcm2835_wrfunction bcm2835_rd_fifofunction bcm2835_wr_fifofunction bcm2835_rd_fifo_countfunction bcm2835_wr_fifo_countfunction bcm2835_wait_tx_fifo_emptyfunction bcm2835_rd_fifo_blindfunction bcm2835_wr_fifo_blindfunction bcm2835_spi_reset_hwfunction bcm2835_spi_interruptfunction bcm2835_spi_transfer_one_irqfunction bcm2835_spi_transfer_prologuefunction bcm2835_spi_undo_prologuefunction bcm2835_spi_dma_rx_donefunction bcm2835_spi_dma_tx_donefunction bcm2835_spi_prepare_sgfunction bcm2835_spi_transfer_one_dmafunction cmpxchgfunction bcm2835_spi_can_dmafunction bcm2835_dma_releasefunction bcm2835_dma_initfunction bcm2835_spi_transfer_one_pollfunction bcm2835_spi_transfer_onefunction bcm2835_spi_prepare_messagefunction bcm2835_spi_handle_errfunction bcm2835_spi_cleanupfunction bcm2835_spi_setup_dmafunction bcm2835_spi_max_transfer_sizefunction bcm2835_spi_setupfunction bcm2835_spi_probefunction bcm2835_spi_remove
Annotated Snippet
struct bcm2835_spi {
void __iomem *regs;
struct clk *clk;
struct gpio_desc *cs_gpio;
unsigned long clk_hz;
int irq;
struct spi_transfer *tfr;
struct spi_controller *ctlr;
const u8 *tx_buf;
u8 *rx_buf;
int tx_len;
int rx_len;
int tx_prologue;
int rx_prologue;
unsigned int tx_spillover;
struct dentry *debugfs_dir;
u64 count_transfer_polling;
u64 count_transfer_irq;
u64 count_transfer_irq_after_polling;
u64 count_transfer_dma;
struct bcm2835_spidev *target;
unsigned int tx_dma_active;
unsigned int rx_dma_active;
struct dma_async_tx_descriptor *fill_tx_desc;
dma_addr_t fill_tx_addr;
};
/**
* struct bcm2835_spidev - BCM2835 SPI target
* @prepare_cs: precalculated CS register value for ->prepare_message()
* (uses target-specific clock polarity and phase settings)
* @clear_rx_desc: preallocated RX DMA descriptor used for TX-only transfers
* (cyclically clears RX FIFO by writing @clear_rx_cs to CS register)
* @clear_rx_addr: bus address of @clear_rx_cs
* @clear_rx_cs: precalculated CS register value to clear RX FIFO
* (uses target-specific clock polarity and phase settings)
*/
struct bcm2835_spidev {
u32 prepare_cs;
struct dma_async_tx_descriptor *clear_rx_desc;
dma_addr_t clear_rx_addr;
u32 clear_rx_cs ____cacheline_aligned;
};
#if defined(CONFIG_DEBUG_FS)
static void bcm2835_debugfs_create(struct bcm2835_spi *bs,
const char *dname)
{
char name[64];
struct dentry *dir;
/* get full name */
snprintf(name, sizeof(name), "spi-bcm2835-%s", dname);
/* the base directory */
dir = debugfs_create_dir(name, NULL);
bs->debugfs_dir = dir;
/* the counters */
debugfs_create_u64("count_transfer_polling", 0444, dir,
&bs->count_transfer_polling);
debugfs_create_u64("count_transfer_irq", 0444, dir,
&bs->count_transfer_irq);
debugfs_create_u64("count_transfer_irq_after_polling", 0444, dir,
&bs->count_transfer_irq_after_polling);
debugfs_create_u64("count_transfer_dma", 0444, dir,
&bs->count_transfer_dma);
}
static void bcm2835_debugfs_remove(struct bcm2835_spi *bs)
{
debugfs_remove_recursive(bs->debugfs_dir);
bs->debugfs_dir = NULL;
}
#else
static void bcm2835_debugfs_create(struct bcm2835_spi *bs,
const char *dname)
{
}
static void bcm2835_debugfs_remove(struct bcm2835_spi *bs)
{
}
#endif /* CONFIG_DEBUG_FS */
static inline u32 bcm2835_rd(struct bcm2835_spi *bs, unsigned int reg)
{
return readl(bs->regs + reg);
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/clk.h`, `linux/completion.h`, `linux/debugfs.h`, `linux/delay.h`, `linux/dma-mapping.h`, `linux/dmaengine.h`, `linux/err.h`.
- Detected declarations: `struct bcm2835_spi`, `struct bcm2835_spidev`, `function bcm2835_debugfs_create`, `function bcm2835_debugfs_remove`, `function bcm2835_debugfs_create`, `function bcm2835_wr`, `function bcm2835_rd_fifo`, `function bcm2835_wr_fifo`, `function bcm2835_rd_fifo_count`, `function bcm2835_wr_fifo_count`.
- 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.