drivers/misc/eeprom/m24lr.c
Source file repositories/reference/linux-study-clean/drivers/misc/eeprom/m24lr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/eeprom/m24lr.c- Extension
.c- Size
- 16063 bytes
- Lines
- 607
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/device.hlinux/i2c.hlinux/module.hlinux/nvmem-provider.hlinux/of.hlinux/of_device.hlinux/regmap.h
Detected Declarations
struct m24lr_chipstruct m24lrfunction readsfunction m24lr_regmap_writefunction m24lr_readfunction m24lr_writefunction m24lr_write_passfunction m24lr_read_reg_lefunction m24lr_nvmem_readfunction m24lr_nvmem_writefunction m24lr_ctl_sss_readfunction m24lr_ctl_sss_writefunction new_pass_storefunction unlock_storefunction uid_showfunction total_sectors_showfunction m24lr_probefunction m24lr_remove
Annotated Snippet
struct m24lr_chip {
unsigned int sss_len;
unsigned int page_size;
unsigned int eeprom_size;
};
/**
* struct m24lr - core driver data for M24LR chip control
* @uid: 64 bits unique identifier stored in the device
* @sss_len: the length of the sss region
* @page_size: chip-specific limit on the maximum number of bytes allowed
* in a single write operation.
* @eeprom_size: size of the EEPROM in byte
* @ctl_regmap: regmap interface for accessing the system parameter sector
* @eeprom_regmap: regmap interface for accessing the EEPROM
* @lock: mutex to synchronize operations to the device
*
* Central data structure holding the state and resources used by the
* M24LR device driver.
*/
struct m24lr {
u64 uid;
unsigned int sss_len;
unsigned int page_size;
unsigned int eeprom_size;
struct regmap *ctl_regmap;
struct regmap *eeprom_regmap;
struct mutex lock; /* synchronize operations to the device */
};
static const struct regmap_range m24lr_ctl_vo_ranges[] = {
regmap_reg_range(0, 63),
};
static const struct regmap_access_table m24lr_ctl_vo_table = {
.yes_ranges = m24lr_ctl_vo_ranges,
.n_yes_ranges = ARRAY_SIZE(m24lr_ctl_vo_ranges),
};
static const struct regmap_config m24lr_ctl_regmap_conf = {
.name = "m24lr_ctl",
.reg_stride = 1,
.reg_bits = 16,
.val_bits = 8,
.disable_locking = false,
.cache_type = REGCACHE_RBTREE,/* Flat can't be used, there's huge gap */
.volatile_table = &m24lr_ctl_vo_table,
};
/* Chip descriptor for M24LR04E-R variant */
static const struct m24lr_chip m24lr04e_r_chip = {
.page_size = 4,
.eeprom_size = 512,
.sss_len = 4,
};
/* Chip descriptor for M24LR16E-R variant */
static const struct m24lr_chip m24lr16e_r_chip = {
.page_size = 4,
.eeprom_size = 2048,
.sss_len = 16,
};
/* Chip descriptor for M24LR64E-R variant */
static const struct m24lr_chip m24lr64e_r_chip = {
.page_size = 4,
.eeprom_size = 8192,
.sss_len = 64,
};
static const struct i2c_device_id m24lr_ids[] = {
{ "m24lr04e-r", (kernel_ulong_t)&m24lr04e_r_chip},
{ "m24lr16e-r", (kernel_ulong_t)&m24lr16e_r_chip},
{ "m24lr64e-r", (kernel_ulong_t)&m24lr64e_r_chip},
{ }
};
MODULE_DEVICE_TABLE(i2c, m24lr_ids);
static const struct of_device_id m24lr_of_match[] = {
{ .compatible = "st,m24lr04e-r", .data = &m24lr04e_r_chip},
{ .compatible = "st,m24lr16e-r", .data = &m24lr16e_r_chip},
{ .compatible = "st,m24lr64e-r", .data = &m24lr64e_r_chip},
{ }
};
MODULE_DEVICE_TABLE(of, m24lr_of_match);
/**
* m24lr_regmap_read - read data using regmap with retry on failure
* @regmap: regmap instance for the device
* @buf: buffer to store the read data
Annotation
- Immediate include surface: `linux/device.h`, `linux/i2c.h`, `linux/module.h`, `linux/nvmem-provider.h`, `linux/of.h`, `linux/of_device.h`, `linux/regmap.h`.
- Detected declarations: `struct m24lr_chip`, `struct m24lr`, `function reads`, `function m24lr_regmap_write`, `function m24lr_read`, `function m24lr_write`, `function m24lr_write_pass`, `function m24lr_read_reg_le`, `function m24lr_nvmem_read`, `function m24lr_nvmem_write`.
- Atlas domain: Driver Families / drivers/misc.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.