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.

Dependency Surface

Detected Declarations

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

Implementation Notes