drivers/misc/eeprom/ee1004.c
Source file repositories/reference/linux-study-clean/drivers/misc/eeprom/ee1004.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/eeprom/ee1004.c- Extension
.c- Size
- 8829 bytes
- Lines
- 353
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/i2c.hlinux/init.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/nvmem-provider.h
Detected Declarations
function ee1004_get_current_pagefunction ee1004_set_current_pagefunction ee1004_eeprom_readfunction ee1004_readfunction ee1004_probe_temp_sensorfunction ee1004_cleanupfunction ee1004_cleanup_bus_datafunction ee1004_init_bus_datafunction ee1004_probe
Annotated Snippet
if (!ee1004_bus_data[i].adap) {
ee1004_bus_data[i].adap = adap;
return ee1004_bus_data + i;
}
return NULL;
}
static int ee1004_get_current_page(struct ee1004_bus_data *bd)
{
int err;
err = i2c_smbus_read_byte(bd->set_page[0]);
if (err == -ENXIO) {
/* Nack means page 1 is selected */
return 1;
}
if (err < 0) {
/* Anything else is a real error, bail out */
return err;
}
/* Ack means page 0 is selected, returned value meaningless */
return 0;
}
static int ee1004_set_current_page(struct i2c_client *client, int page)
{
struct ee1004_bus_data *bd = i2c_get_clientdata(client);
int ret;
if (page == bd->current_page)
return 0;
/* Data is ignored */
ret = i2c_smbus_write_byte(bd->set_page[page], 0x00);
/*
* Don't give up just yet. Some memory modules will select the page
* but not ack the command. Check which page is selected now.
*/
if (ret == -ENXIO && ee1004_get_current_page(bd) == page)
ret = 0;
if (ret < 0) {
dev_err(&client->dev, "Failed to select page %d (%d)\n", page, ret);
return ret;
}
dev_dbg(&client->dev, "Selected page %d\n", page);
bd->current_page = page;
return 0;
}
static ssize_t ee1004_eeprom_read(struct i2c_client *client, char *buf,
unsigned int offset, size_t count)
{
int status, page;
page = offset >> EE1004_PAGE_SHIFT;
offset &= (1 << EE1004_PAGE_SHIFT) - 1;
status = ee1004_set_current_page(client, page);
if (status)
return status;
/* Can't cross page boundaries */
if (offset + count > EE1004_PAGE_SIZE)
count = EE1004_PAGE_SIZE - offset;
if (count > I2C_SMBUS_BLOCK_MAX)
count = I2C_SMBUS_BLOCK_MAX;
return i2c_smbus_read_i2c_block_data_or_emulated(client, offset, count, buf);
}
static int ee1004_read(void *priv, unsigned int off, void *val, size_t count)
{
struct i2c_client *client = priv;
char *buf = val;
int ret;
if (unlikely(!count))
return count;
if (off + count > EE1004_EEPROM_SIZE)
return -EINVAL;
/*
* Read data from chip, protecting against concurrent access to
* other EE1004 SPD EEPROMs on the same adapter.
Annotation
- Immediate include surface: `linux/device.h`, `linux/i2c.h`, `linux/init.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/mutex.h`, `linux/nvmem-provider.h`.
- Detected declarations: `function ee1004_get_current_page`, `function ee1004_set_current_page`, `function ee1004_eeprom_read`, `function ee1004_read`, `function ee1004_probe_temp_sensor`, `function ee1004_cleanup`, `function ee1004_cleanup_bus_data`, `function ee1004_init_bus_data`, `function ee1004_probe`.
- 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.