drivers/spi/spi-atmel.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-atmel.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-atmel.c- Extension
.c- Size
- 47397 bytes
- Lines
- 1828
- 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/kernel.hlinux/clk.hlinux/module.hlinux/platform_device.hlinux/delay.hlinux/dma-mapping.hlinux/dmaengine.hlinux/err.hlinux/interrupt.hlinux/spi/spi.hlinux/slab.hlinux/of.hlinux/io.hlinux/gpio/consumer.hlinux/pinctrl/consumer.hlinux/pm_runtime.hlinux/iopoll.htrace/events/spi.h
Detected Declarations
struct atmel_spi_capsstruct atmel_spistruct atmel_spi_devicefunction registersfunction atmel_spi_send_dummyfunction andfunction cs_deactivatefunction atmel_spi_lockfunction atmel_spi_unlockfunction atmel_spi_is_vmalloc_xferfunction atmel_spi_use_dmafunction atmel_spi_can_dmafunction atmel_spi_dma_slave_configfunction modefunction modefunction atmel_spi_release_dmafunction atmel_spi_configure_dmafunction atmel_spi_stop_dmafunction dma_callbackfunction atmel_spi_next_xfer_singlefunction atmel_spi_next_xfer_fifofunction atmel_spi_next_xfer_piofunction atmel_spi_next_xfer_dma_submitfunction IS_ENABLEDfunction atmel_spi_next_xfer_datafunction atmel_spi_set_xfer_speedfunction atmel_spi_pdc_next_xferfunction atmel_spi_dma_map_xferfunction atmel_spi_dma_unmap_xferfunction atmel_spi_disable_pdc_transferfunction atmel_spi_pump_single_datafunction atmel_spi_pump_fifo_datafunction atmel_spi_pump_pio_datafunction atmel_spi_pio_interruptfunction atmel_spi_pdc_interruptfunction atmel_word_delay_csrfunction initialize_native_cs_for_gpiofunction atmel_spi_setupfunction atmel_spi_set_csfunction atmel_spi_one_transferfunction atmel_spi_cleanupfunction atmel_get_versionfunction atmel_get_capsfunction atmel_spi_initfunction atmel_spi_probefunction thresholdfunction atmel_spi_removefunction atmel_spi_runtime_suspend
Annotated Snippet
struct atmel_spi_caps {
bool is_spi2;
bool has_wdrbt;
bool has_dma_support;
bool has_pdc_support;
};
/*
* The core SPI transfer engine just talks to a register bank to set up
* DMA transfers; transfer queue progress is driven by IRQs. The clock
* framework provides the base clock, subdivided for each spi_device.
*/
struct atmel_spi {
spinlock_t lock;
unsigned long flags;
phys_addr_t phybase;
void __iomem *regs;
int irq;
struct clk *clk;
struct clk *gclk;
struct platform_device *pdev;
unsigned long spi_clk;
struct spi_transfer *current_transfer;
int current_remaining_bytes;
int done_status;
dma_addr_t dma_addr_rx_bbuf;
dma_addr_t dma_addr_tx_bbuf;
void *addr_rx_bbuf;
void *addr_tx_bbuf;
struct completion xfer_completion;
struct atmel_spi_caps caps;
bool use_dma;
bool use_pdc;
bool keep_cs;
u32 fifo_size;
bool last_polarity;
u8 native_cs_free;
u8 native_cs_for_gpio;
};
/* Controller-specific per-slave state */
struct atmel_spi_device {
u32 csr;
};
#define SPI_MAX_DMA_XFER 65535 /* true for both PDC and DMA */
#define INVALID_DMA_ADDRESS 0xffffffff
/*
* This frequency can be anything supported by the controller, but to avoid
* unnecessary delay, the highest possible frequency is chosen.
*
* This frequency is the highest possible which is not interfering with other
* chip select registers (see Note for Serial Clock Bit Rate configuration in
* Atmel-11121F-ATARM-SAMA5D3-Series-Datasheet_02-Feb-16, page 1283)
*/
#define DUMMY_MSG_FREQUENCY 0x02
/*
* 8 bits is the minimum data the controller is capable of sending.
*
* This message can be anything as it should not be treated by any SPI device.
*/
#define DUMMY_MSG 0xAA
/*
* Version 2 of the SPI controller has
* - CR.LASTXFER
* - SPI_MR.DIV32 may become FDIV or must-be-zero (here: always zero)
* - SPI_SR.TXEMPTY, SPI_SR.NSSR (and corresponding irqs)
* - SPI_CSRx.CSAAT
* - SPI_CSRx.SBCR allows faster clocking
*/
static bool atmel_spi_is_v2(struct atmel_spi *as)
{
return as->caps.is_spi2;
}
/*
* Send a dummy message.
*
* This is sometimes needed when using a CS GPIO to force clock transition when
* switching between devices with different polarities.
*/
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/clk.h`, `linux/module.h`, `linux/platform_device.h`, `linux/delay.h`, `linux/dma-mapping.h`, `linux/dmaengine.h`, `linux/err.h`.
- Detected declarations: `struct atmel_spi_caps`, `struct atmel_spi`, `struct atmel_spi_device`, `function registers`, `function atmel_spi_send_dummy`, `function and`, `function cs_deactivate`, `function atmel_spi_lock`, `function atmel_spi_unlock`, `function atmel_spi_is_vmalloc_xfer`.
- 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.