drivers/mtd/spi-nor/controllers/nxp-spifi.c
Source file repositories/reference/linux-study-clean/drivers/mtd/spi-nor/controllers/nxp-spifi.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mtd/spi-nor/controllers/nxp-spifi.c- Extension
.c- Size
- 11077 bytes
- Lines
- 460
- Domain
- Driver Families
- Bucket
- drivers/mtd
- 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.
- 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/clk.hlinux/err.hlinux/io.hlinux/iopoll.hlinux/module.hlinux/mtd/mtd.hlinux/mtd/partitions.hlinux/mtd/spi-nor.hlinux/of.hlinux/platform_device.hlinux/spi/spi.h
Detected Declarations
struct nxp_spififunction nxp_spifi_wait_for_cmdfunction nxp_spifi_resetfunction nxp_spifi_set_memory_mode_offfunction nxp_spifi_set_memory_mode_onfunction nxp_spifi_read_regfunction nxp_spifi_write_regfunction nxp_spifi_readfunction nxp_spifi_writefunction nxp_spifi_erasefunction nxp_spifi_setup_memory_cmdfunction nxp_spifi_dummy_id_readfunction nxp_spifi_setup_flashfunction nxp_spifi_probefunction nxp_spifi_remove
Annotated Snippet
struct nxp_spifi {
struct device *dev;
struct clk *clk_spifi;
struct clk *clk_reg;
void __iomem *io_base;
void __iomem *flash_base;
struct spi_nor nor;
bool memory_mode;
u32 mcmd;
};
static int nxp_spifi_wait_for_cmd(struct nxp_spifi *spifi)
{
u8 stat;
int ret;
ret = readb_poll_timeout(spifi->io_base + SPIFI_STAT, stat,
!(stat & SPIFI_STAT_CMD), 10, 30);
if (ret)
dev_warn(spifi->dev, "command timed out\n");
return ret;
}
static int nxp_spifi_reset(struct nxp_spifi *spifi)
{
u8 stat;
int ret;
writel(SPIFI_STAT_RESET, spifi->io_base + SPIFI_STAT);
ret = readb_poll_timeout(spifi->io_base + SPIFI_STAT, stat,
!(stat & SPIFI_STAT_RESET), 10, 30);
if (ret)
dev_warn(spifi->dev, "state reset timed out\n");
return ret;
}
static int nxp_spifi_set_memory_mode_off(struct nxp_spifi *spifi)
{
int ret;
if (!spifi->memory_mode)
return 0;
ret = nxp_spifi_reset(spifi);
if (ret)
dev_err(spifi->dev, "unable to enter command mode\n");
else
spifi->memory_mode = false;
return ret;
}
static int nxp_spifi_set_memory_mode_on(struct nxp_spifi *spifi)
{
u8 stat;
int ret;
if (spifi->memory_mode)
return 0;
writel(spifi->mcmd, spifi->io_base + SPIFI_MCMD);
ret = readb_poll_timeout(spifi->io_base + SPIFI_STAT, stat,
stat & SPIFI_STAT_MCINIT, 10, 30);
if (ret)
dev_err(spifi->dev, "unable to enter memory mode\n");
else
spifi->memory_mode = true;
return ret;
}
static int nxp_spifi_read_reg(struct spi_nor *nor, u8 opcode, u8 *buf,
size_t len)
{
struct nxp_spifi *spifi = nor->priv;
u32 cmd;
int ret;
ret = nxp_spifi_set_memory_mode_off(spifi);
if (ret)
return ret;
cmd = SPIFI_CMD_DATALEN(len) |
SPIFI_CMD_OPCODE(opcode) |
SPIFI_CMD_FIELDFORM_ALL_SERIAL |
SPIFI_CMD_FRAMEFORM_OPCODE_ONLY;
writel(cmd, spifi->io_base + SPIFI_CMD);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/err.h`, `linux/io.h`, `linux/iopoll.h`, `linux/module.h`, `linux/mtd/mtd.h`, `linux/mtd/partitions.h`, `linux/mtd/spi-nor.h`.
- Detected declarations: `struct nxp_spifi`, `function nxp_spifi_wait_for_cmd`, `function nxp_spifi_reset`, `function nxp_spifi_set_memory_mode_off`, `function nxp_spifi_set_memory_mode_on`, `function nxp_spifi_read_reg`, `function nxp_spifi_write_reg`, `function nxp_spifi_read`, `function nxp_spifi_write`, `function nxp_spifi_erase`.
- Atlas domain: Driver Families / drivers/mtd.
- Implementation status: source implementation candidate.
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.