drivers/nvmem/lan9662-otpc.c
Source file repositories/reference/linux-study-clean/drivers/nvmem/lan9662-otpc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvmem/lan9662-otpc.c- Extension
.c- Size
- 5527 bytes
- Lines
- 223
- 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/iopoll.hlinux/module.hlinux/nvmem-provider.hlinux/of.hlinux/platform_device.h
Detected Declarations
struct lan9662_otpfunction lan9662_otp_wait_flag_clearfunction lan9662_otp_powerfunction lan9662_otp_executefunction lan9662_otp_set_addressfunction lan9662_otp_read_bytefunction lan9662_otp_write_bytefunction lan9662_otp_readfunction lan9662_otp_writefunction lan9662_otp_probe
Annotated Snippet
struct lan9662_otp {
struct device *dev;
void __iomem *base;
};
static int lan9662_otp_wait_flag_clear(void __iomem *reg, u32 flag)
{
u32 val;
return readl_poll_timeout(reg, val, !(val & flag),
OTP_SLEEP_US, OTP_TIMEOUT_US);
}
static int lan9662_otp_power(struct lan9662_otp *otp, bool up)
{
void __iomem *pwrdn = OTP_OTP_PWR_DN(otp->base);
if (up) {
writel(readl(pwrdn) & ~OTP_OTP_PWR_DN_OTP_PWRDN_N, pwrdn);
if (lan9662_otp_wait_flag_clear(OTP_OTP_STATUS(otp->base),
OTP_OTP_STATUS_OTP_CPUMPEN))
return -ETIMEDOUT;
} else {
writel(readl(pwrdn) | OTP_OTP_PWR_DN_OTP_PWRDN_N, pwrdn);
}
return 0;
}
static int lan9662_otp_execute(struct lan9662_otp *otp)
{
if (lan9662_otp_wait_flag_clear(OTP_OTP_CMD_GO(otp->base),
OTP_OTP_CMD_GO_OTP_GO))
return -ETIMEDOUT;
if (lan9662_otp_wait_flag_clear(OTP_OTP_STATUS(otp->base),
OTP_OTP_STATUS_OTP_BUSY))
return -ETIMEDOUT;
return 0;
}
static void lan9662_otp_set_address(struct lan9662_otp *otp, u32 offset)
{
writel(0xff & (offset >> 8), OTP_OTP_ADDR_HI(otp->base));
writel(0xff & offset, OTP_OTP_ADDR_LO(otp->base));
}
static int lan9662_otp_read_byte(struct lan9662_otp *otp, u32 offset, u8 *dst)
{
u32 pass;
int rc;
lan9662_otp_set_address(otp, offset);
writel(OTP_OTP_FUNC_CMD_OTP_READ, OTP_OTP_FUNC_CMD(otp->base));
writel(OTP_OTP_CMD_GO_OTP_GO, OTP_OTP_CMD_GO(otp->base));
rc = lan9662_otp_execute(otp);
if (!rc) {
pass = readl(OTP_OTP_PASS_FAIL(otp->base));
if (pass & OTP_OTP_PASS_FAIL_OTP_READ_PROHIBITED)
return -EACCES;
*dst = (u8) readl(OTP_OTP_RD_DATA(otp->base));
}
return rc;
}
static int lan9662_otp_write_byte(struct lan9662_otp *otp, u32 offset, u8 data)
{
u32 pass;
int rc;
lan9662_otp_set_address(otp, offset);
writel(OTP_OTP_PRGM_MODE_OTP_PGM_MODE_BYTE, OTP_OTP_PRGM_MODE(otp->base));
writel(data, OTP_OTP_PRGM_DATA(otp->base));
writel(OTP_OTP_FUNC_CMD_OTP_PROGRAM, OTP_OTP_FUNC_CMD(otp->base));
writel(OTP_OTP_CMD_GO_OTP_GO, OTP_OTP_CMD_GO(otp->base));
rc = lan9662_otp_execute(otp);
if (!rc) {
pass = readl(OTP_OTP_PASS_FAIL(otp->base));
if (pass & OTP_OTP_PASS_FAIL_OTP_WRITE_PROHIBITED)
return -EACCES;
if (pass & OTP_OTP_PASS_FAIL_OTP_FAIL)
return -EIO;
}
return rc;
}
static int lan9662_otp_read(void *context, unsigned int offset,
void *_val, size_t bytes)
Annotation
- Immediate include surface: `linux/iopoll.h`, `linux/module.h`, `linux/nvmem-provider.h`, `linux/of.h`, `linux/platform_device.h`.
- Detected declarations: `struct lan9662_otp`, `function lan9662_otp_wait_flag_clear`, `function lan9662_otp_power`, `function lan9662_otp_execute`, `function lan9662_otp_set_address`, `function lan9662_otp_read_byte`, `function lan9662_otp_write_byte`, `function lan9662_otp_read`, `function lan9662_otp_write`, `function lan9662_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.