drivers/nvmem/rockchip-otp.c
Source file repositories/reference/linux-study-clean/drivers/nvmem/rockchip-otp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvmem/rockchip-otp.c- Extension
.c- Size
- 11359 bytes
- Lines
- 478
- Domain
- Driver Families
- Bucket
- drivers/nvmem
- 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/delay.hlinux/device.hlinux/io.hlinux/iopoll.hlinux/module.hlinux/nvmem-provider.hlinux/reset.hlinux/slab.hlinux/of.hlinux/of_platform.hlinux/platform_device.h
Detected Declarations
struct rockchip_datastruct rockchip_otpfunction rockchip_otp_resetfunction rockchip_otp_wait_statusfunction rockchip_otp_ecc_enablefunction px30_otp_readfunction rk3568_otp_readfunction rk3588_otp_readfunction rockchip_otp_readfunction rockchip_otp_probe
Annotated Snippet
struct rockchip_data {
int size;
int read_offset;
int word_size;
const char * const *clks;
int num_clks;
nvmem_reg_read_t reg_read;
};
struct rockchip_otp {
struct device *dev;
void __iomem *base;
struct clk_bulk_data *clks;
struct reset_control *rst;
const struct rockchip_data *data;
};
static int rockchip_otp_reset(struct rockchip_otp *otp)
{
int ret;
ret = reset_control_assert(otp->rst);
if (ret) {
dev_err(otp->dev, "failed to assert otp phy %d\n", ret);
return ret;
}
udelay(2);
ret = reset_control_deassert(otp->rst);
if (ret) {
dev_err(otp->dev, "failed to deassert otp phy %d\n", ret);
return ret;
}
return 0;
}
static int rockchip_otp_wait_status(struct rockchip_otp *otp,
unsigned int reg, u32 flag)
{
u32 status = 0;
int ret;
ret = readl_poll_timeout_atomic(otp->base + reg, status,
(status & flag), 1, OTPC_TIMEOUT);
if (ret)
return ret;
/* clean int status */
writel(flag, otp->base + reg);
return 0;
}
static int rockchip_otp_ecc_enable(struct rockchip_otp *otp, bool enable)
{
int ret = 0;
writel(SBPI_DAP_ADDR_MASK | (SBPI_DAP_ADDR << SBPI_DAP_ADDR_SHIFT),
otp->base + OTPC_SBPI_CTRL);
writel(SBPI_CMD_VALID_MASK | 0x1, otp->base + OTPC_SBPI_CMD_VALID_PRE);
writel(SBPI_DAP_CMD_WRF | SBPI_DAP_REG_ECC,
otp->base + OTPC_SBPI_CMD0_OFFSET);
if (enable)
writel(SBPI_ECC_ENABLE, otp->base + OTPC_SBPI_CMD1_OFFSET);
else
writel(SBPI_ECC_DISABLE, otp->base + OTPC_SBPI_CMD1_OFFSET);
writel(SBPI_ENABLE_MASK | SBPI_ENABLE, otp->base + OTPC_SBPI_CTRL);
ret = rockchip_otp_wait_status(otp, OTPC_INT_STATUS, OTPC_SBPI_DONE);
if (ret < 0)
dev_err(otp->dev, "timeout during ecc_enable\n");
return ret;
}
static int px30_otp_read(void *context, unsigned int offset,
void *val, size_t bytes)
{
struct rockchip_otp *otp = context;
u8 *buf = val;
int ret;
ret = rockchip_otp_reset(otp);
if (ret) {
dev_err(otp->dev, "failed to reset otp phy\n");
return ret;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/delay.h`, `linux/device.h`, `linux/io.h`, `linux/iopoll.h`, `linux/module.h`, `linux/nvmem-provider.h`, `linux/reset.h`.
- Detected declarations: `struct rockchip_data`, `struct rockchip_otp`, `function rockchip_otp_reset`, `function rockchip_otp_wait_status`, `function rockchip_otp_ecc_enable`, `function px30_otp_read`, `function rk3568_otp_read`, `function rk3588_otp_read`, `function rockchip_otp_read`, `function rockchip_otp_probe`.
- Atlas domain: Driver Families / drivers/nvmem.
- 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.