drivers/spi/spi-airoha-snfi.c
Source file repositories/reference/linux-study-clean/drivers/spi/spi-airoha-snfi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/spi/spi-airoha-snfi.c- Extension
.c- Size
- 30214 bytes
- Lines
- 1148
- 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/clk.hlinux/delay.hlinux/device.hlinux/dma-mapping.hlinux/errno.hlinux/limits.hlinux/math.hlinux/minmax.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/property.hlinux/regmap.hlinux/sizes.hlinux/spi/spi.hlinux/spi/spi-mem.hlinux/types.hlinux/unaligned.h
Detected Declarations
struct airoha_snand_ctrlenum airoha_snand_modeenum airoha_snand_csfunction airoha_snand_set_fifo_opfunction airoha_snand_set_csfunction airoha_snand_write_data_to_fifofunction airoha_snand_read_data_from_fifofunction airoha_snand_set_modefunction airoha_snand_write_datafunction airoha_snand_read_datafunction airoha_snand_nfi_initfunction airoha_snand_is_page_opsfunction airoha_snand_supports_opfunction airoha_snand_dirmap_createfunction airoha_snand_dirmap_readfunction airoha_snand_dirmap_writefunction airoha_snand_exec_opfunction airoha_snand_setupfunction airoha_snand_probe
Annotated Snippet
struct airoha_snand_ctrl {
struct device *dev;
struct regmap *regmap_ctrl;
struct regmap *regmap_nfi;
struct clk *spi_clk;
};
static int airoha_snand_set_fifo_op(struct airoha_snand_ctrl *as_ctrl,
u8 op_cmd, int op_len)
{
int err;
u32 val;
err = regmap_write(as_ctrl->regmap_ctrl, REG_SPI_CTRL_OPFIFO_WDATA,
FIELD_PREP(SPI_CTRL_OPFIFO_LEN, op_len) |
FIELD_PREP(SPI_CTRL_OPFIFO_OP, op_cmd));
if (err)
return err;
err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl,
REG_SPI_CTRL_OPFIFO_FULL,
val, !(val & SPI_CTRL_OPFIFO_FULL),
0, 250 * USEC_PER_MSEC);
if (err)
return err;
err = regmap_write(as_ctrl->regmap_ctrl, REG_SPI_CTRL_OPFIFO_WR,
SPI_CTRL_OPFIFO_WR);
if (err)
return err;
return regmap_read_poll_timeout(as_ctrl->regmap_ctrl,
REG_SPI_CTRL_OPFIFO_EMPTY,
val, (val & SPI_CTRL_OPFIFO_EMPTY),
0, 250 * USEC_PER_MSEC);
}
static int airoha_snand_set_cs(struct airoha_snand_ctrl *as_ctrl, u8 cs)
{
return airoha_snand_set_fifo_op(as_ctrl, cs, sizeof(cs));
}
static int airoha_snand_write_data_to_fifo(struct airoha_snand_ctrl *as_ctrl,
const u8 *data, int len)
{
int i;
for (i = 0; i < len; i++) {
int err;
u32 val;
/* 1. Wait until dfifo is not full */
err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl,
REG_SPI_CTRL_DFIFO_FULL, val,
!(val & SPI_CTRL_DFIFO_FULL),
0, 250 * USEC_PER_MSEC);
if (err)
return err;
/* 2. Write data to register DFIFO_WDATA */
err = regmap_write(as_ctrl->regmap_ctrl,
REG_SPI_CTRL_DFIFO_WDATA,
FIELD_PREP(SPI_CTRL_DFIFO_WDATA, data[i]));
if (err)
return err;
/* 3. Wait until dfifo is not full */
err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl,
REG_SPI_CTRL_DFIFO_FULL, val,
!(val & SPI_CTRL_DFIFO_FULL),
0, 250 * USEC_PER_MSEC);
if (err)
return err;
}
return 0;
}
static int airoha_snand_read_data_from_fifo(struct airoha_snand_ctrl *as_ctrl,
u8 *ptr, int len)
{
int i;
for (i = 0; i < len; i++) {
int err;
u32 val;
/* 1. wait until dfifo is not empty */
err = regmap_read_poll_timeout(as_ctrl->regmap_ctrl,
REG_SPI_CTRL_DFIFO_EMPTY, val,
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/dma-mapping.h`, `linux/errno.h`, `linux/limits.h`, `linux/math.h`.
- Detected declarations: `struct airoha_snand_ctrl`, `enum airoha_snand_mode`, `enum airoha_snand_cs`, `function airoha_snand_set_fifo_op`, `function airoha_snand_set_cs`, `function airoha_snand_write_data_to_fifo`, `function airoha_snand_read_data_from_fifo`, `function airoha_snand_set_mode`, `function airoha_snand_write_data`, `function airoha_snand_read_data`.
- 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.