drivers/nvmem/lpc18xx_eeprom.c
Source file repositories/reference/linux-study-clean/drivers/nvmem/lpc18xx_eeprom.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvmem/lpc18xx_eeprom.c- Extension
.c- Size
- 7126 bytes
- Lines
- 279
- 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/device.hlinux/delay.hlinux/err.hlinux/io.hlinux/module.hlinux/mod_devicetable.hlinux/nvmem-provider.hlinux/platform_device.hlinux/reset.h
Detected Declarations
struct lpc18xx_eeprom_devfunction lpc18xx_eeprom_writelfunction lpc18xx_eeprom_readlfunction lpc18xx_eeprom_busywait_until_progfunction lpc18xx_eeprom_gather_writefunction lpc18xx_eeprom_readfunction lpc18xx_eeprom_probefunction lpc18xx_eeprom_remove
Annotated Snippet
struct lpc18xx_eeprom_dev {
struct clk *clk;
void __iomem *reg_base;
void __iomem *mem_base;
struct nvmem_device *nvmem;
unsigned reg_bytes;
unsigned val_bytes;
int size;
};
static inline void lpc18xx_eeprom_writel(struct lpc18xx_eeprom_dev *eeprom,
u32 reg, u32 val)
{
writel(val, eeprom->reg_base + reg);
}
static inline u32 lpc18xx_eeprom_readl(struct lpc18xx_eeprom_dev *eeprom,
u32 reg)
{
return readl(eeprom->reg_base + reg);
}
static int lpc18xx_eeprom_busywait_until_prog(struct lpc18xx_eeprom_dev *eeprom)
{
unsigned long end;
u32 val;
/* Wait until EEPROM program operation has finished */
end = jiffies + msecs_to_jiffies(LPC18XX_EEPROM_PROGRAM_TIME * 10);
while (time_is_after_jiffies(end)) {
val = lpc18xx_eeprom_readl(eeprom, LPC18XX_EEPROM_INTSTAT);
if (val & LPC18XX_EEPROM_INTSTAT_END_OF_PROG) {
lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_INTSTATCLR,
LPC18XX_EEPROM_INTSTATCLR_PROG_CLR_ST);
return 0;
}
usleep_range(LPC18XX_EEPROM_PROGRAM_TIME * USEC_PER_MSEC,
(LPC18XX_EEPROM_PROGRAM_TIME + 1) * USEC_PER_MSEC);
}
return -ETIMEDOUT;
}
static int lpc18xx_eeprom_gather_write(void *context, unsigned int reg,
void *val, size_t bytes)
{
struct lpc18xx_eeprom_dev *eeprom = context;
unsigned int offset = reg;
int ret;
/*
* The last page contains the EEPROM initialization data and is not
* writable.
*/
if ((reg > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE) ||
(reg + bytes > eeprom->size - LPC18XX_EEPROM_PAGE_SIZE))
return -EINVAL;
lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN,
LPC18XX_EEPROM_PWRDWN_NO);
/* Wait 100 us while the EEPROM wakes up */
usleep_range(100, 200);
while (bytes) {
writel(*(u32 *)val, eeprom->mem_base + offset);
ret = lpc18xx_eeprom_busywait_until_prog(eeprom);
if (ret < 0)
return ret;
bytes -= eeprom->val_bytes;
val += eeprom->val_bytes;
offset += eeprom->val_bytes;
}
lpc18xx_eeprom_writel(eeprom, LPC18XX_EEPROM_PWRDWN,
LPC18XX_EEPROM_PWRDWN_YES);
return 0;
}
static int lpc18xx_eeprom_read(void *context, unsigned int offset,
void *val, size_t bytes)
{
struct lpc18xx_eeprom_dev *eeprom = context;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/device.h`, `linux/delay.h`, `linux/err.h`, `linux/io.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/nvmem-provider.h`.
- Detected declarations: `struct lpc18xx_eeprom_dev`, `function lpc18xx_eeprom_writel`, `function lpc18xx_eeprom_readl`, `function lpc18xx_eeprom_busywait_until_prog`, `function lpc18xx_eeprom_gather_write`, `function lpc18xx_eeprom_read`, `function lpc18xx_eeprom_probe`, `function lpc18xx_eeprom_remove`.
- 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.