drivers/spi/spi-amlogic-spisg.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-amlogic-spisg.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-amlogic-spisg.c- Extension
.c- Size
- 23836 bytes
- Lines
- 881
- 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/bitfield.hlinux/device.hlinux/module.hlinux/of.hlinux/clk.hlinux/clk-provider.hlinux/dma-mapping.hlinux/platform_device.hlinux/pinctrl/consumer.hlinux/pm_runtime.hlinux/spi/spi.hlinux/types.hlinux/interrupt.hlinux/reset.hlinux/regmap.h
Detected Declarations
struct spisg_sg_linkstruct spisg_descriptorstruct spisg_descriptor_extrastruct spisg_devicefunction spi_delay_to_sclkfunction aml_spisg_sem_down_readfunction aml_spisg_sem_up_writefunction aml_spisg_set_speedfunction aml_spisg_can_dmafunction aml_spisg_sg_xlatefunction for_each_sgfunction aml_spisg_setup_transferfunction aml_spisg_cleanup_transferfunction aml_spisg_setup_null_descfunction aml_spisg_pendingfunction aml_spisg_irqfunction aml_spisg_transfer_one_messagefunction aml_spisg_prepare_messagefunction aml_spisg_setupfunction aml_spisg_cleanupfunction aml_spisg_target_abortfunction aml_spisg_clk_initfunction aml_spisg_probefunction aml_spisg_removefunction spisg_suspend_runtimefunction spisg_resume_runtime
Annotated Snippet
struct spisg_sg_link {
#define LINK_ADDR_VALID BIT(0)
#define LINK_ADDR_EOC BIT(1)
#define LINK_ADDR_IRQ BIT(2)
#define LINK_ADDR_ACT GENMASK(5, 3)
#define LINK_ADDR_RING BIT(6)
#define LINK_ADDR_LEN GENMASK(31, 8)
u32 addr;
u32 addr1;
};
struct spisg_descriptor {
u32 cfg_start;
u32 cfg_bus;
u64 tx_paddr;
u64 rx_paddr;
};
struct spisg_descriptor_extra {
struct spisg_sg_link *tx_ccsg;
struct spisg_sg_link *rx_ccsg;
int tx_ccsg_len;
int rx_ccsg_len;
};
struct spisg_device {
struct spi_controller *controller;
struct platform_device *pdev;
struct regmap *map;
struct clk *core;
struct clk *pclk;
struct clk *sclk;
struct clk_div_table *tbl;
struct completion completion;
u32 status;
u32 speed_hz;
u32 effective_speed_hz;
u32 bytes_per_word;
u32 cfg_spi;
u32 cfg_start;
u32 cfg_bus;
};
static int spi_delay_to_sclk(u32 slck_speed_hz, struct spi_delay *delay)
{
s32 ns;
if (!delay)
return 0;
if (delay->unit == SPI_DELAY_UNIT_SCK)
return delay->value;
ns = spi_delay_to_ns(delay, NULL);
if (ns < 0)
return 0;
return DIV_ROUND_UP_ULL(slck_speed_hz * ns, NSEC_PER_SEC);
}
static inline u32 aml_spisg_sem_down_read(struct spisg_device *spisg)
{
u32 ret;
regmap_read(spisg->map, SPISG_REG_CFG_READY, &ret);
if (ret)
regmap_write(spisg->map, SPISG_REG_CFG_READY, 0);
return ret;
}
static inline void aml_spisg_sem_up_write(struct spisg_device *spisg)
{
regmap_write(spisg->map, SPISG_REG_CFG_READY, 1);
}
static int aml_spisg_set_speed(struct spisg_device *spisg, uint speed_hz)
{
u32 cfg_bus;
if (!speed_hz || speed_hz == spisg->speed_hz)
return 0;
spisg->speed_hz = speed_hz;
clk_set_rate(spisg->sclk, speed_hz);
/* Store the div for the descriptor mode */
regmap_read(spisg->map, SPISG_REG_CFG_BUS, &cfg_bus);
spisg->cfg_bus &= ~CFG_CLK_DIV;
spisg->cfg_bus |= cfg_bus & CFG_CLK_DIV;
spisg->effective_speed_hz = clk_get_rate(spisg->sclk);
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/device.h`, `linux/module.h`, `linux/of.h`, `linux/clk.h`, `linux/clk-provider.h`, `linux/dma-mapping.h`, `linux/platform_device.h`.
- Detected declarations: `struct spisg_sg_link`, `struct spisg_descriptor`, `struct spisg_descriptor_extra`, `struct spisg_device`, `function spi_delay_to_sclk`, `function aml_spisg_sem_down_read`, `function aml_spisg_sem_up_write`, `function aml_spisg_set_speed`, `function aml_spisg_can_dma`, `function aml_spisg_sg_xlate`.
- 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.