drivers/nvmem/core.c
Source file repositories/reference/linux-study-clean/drivers/nvmem/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/nvmem/core.c- Extension
.c- Size
- 51414 bytes
- Lines
- 2195
- Domain
- Driver Families
- Bucket
- drivers/nvmem
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/export.hlinux/fs.hlinux/idr.hlinux/init.hlinux/kref.hlinux/module.hlinux/nvmem-consumer.hlinux/nvmem-provider.hlinux/gpio/consumer.hlinux/of.hlinux/slab.hinternals.h
Detected Declarations
struct nvmem_cell_entrystruct nvmem_cellfunction __nvmem_reg_readfunction __nvmem_reg_writefunction nvmem_access_with_keepoutsfunction nvmem_reg_readfunction nvmem_reg_writefunction type_showfunction force_ro_showfunction force_ro_storefunction bin_attr_nvmem_readfunction bin_attr_nvmem_writefunction nvmem_bin_attr_get_umodefunction nvmem_bin_attr_is_visiblefunction nvmem_bin_attr_sizefunction nvmem_attr_is_visiblefunction nvmem_cell_attr_readfunction nvmem_setup_compatfunction nvmem_sysfs_remove_compatfunction nvmem_populate_sysfs_cellsfunction nvmem_sysfs_setup_compatfunction nvmem_sysfs_remove_compatfunction nvmem_cell_entry_dropfunction nvmem_device_remove_all_cellsfunction nvmem_cell_entry_addfunction nvmem_cell_info_to_nvmem_cell_entry_nodupfunction nvmem_cell_info_to_nvmem_cell_entryfunction nvmem_add_one_cellfunction nvmem_add_cellsfunction nvmem_register_notifierfunction nvmem_unregister_notifierfunction nvmem_find_cell_entry_by_namefunction nvmem_validate_keepoutsfunction keepoutsfunction nvmem_add_cells_from_dtfunction for_each_child_of_node_scopedfunction nvmem_add_cells_from_legacy_offunction nvmem_add_cells_from_fixed_layoutfunction nvmem_layout_registerfunction nvmem_layout_unregisterfunction nvmem_registerfunction nvmem_device_releasefunction nvmem_unregisterfunction devm_nvmem_unregisterfunction devm_nvmem_registerfunction intfunction __nvmem_device_putfunction of_nvmem_device_get
Annotated Snippet
static const struct bus_type nvmem_bus_type = {
.name = "nvmem",
};
static void nvmem_cell_entry_drop(struct nvmem_cell_entry *cell)
{
blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_REMOVE, cell);
mutex_lock(&nvmem_mutex);
list_del(&cell->node);
mutex_unlock(&nvmem_mutex);
of_node_put(cell->np);
kfree_const(cell->name);
kfree(cell);
}
static void nvmem_device_remove_all_cells(const struct nvmem_device *nvmem)
{
struct nvmem_cell_entry *cell, *p;
list_for_each_entry_safe(cell, p, &nvmem->cells, node)
nvmem_cell_entry_drop(cell);
}
static void nvmem_cell_entry_add(struct nvmem_cell_entry *cell)
{
mutex_lock(&nvmem_mutex);
list_add_tail(&cell->node, &cell->nvmem->cells);
mutex_unlock(&nvmem_mutex);
blocking_notifier_call_chain(&nvmem_notifier, NVMEM_CELL_ADD, cell);
}
static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem,
const struct nvmem_cell_info *info,
struct nvmem_cell_entry *cell)
{
cell->nvmem = nvmem;
cell->offset = info->offset;
cell->raw_len = info->raw_len ?: info->bytes;
cell->bytes = info->bytes;
cell->name = info->name;
cell->read_post_process = info->read_post_process;
cell->priv = info->priv;
cell->bit_offset = info->bit_offset;
cell->nbits = info->nbits;
cell->np = info->np;
if (cell->nbits) {
cell->bytes = DIV_ROUND_UP(cell->nbits + cell->bit_offset,
BITS_PER_BYTE);
cell->raw_len = ALIGN(cell->bytes, nvmem->word_size);
}
if (!IS_ALIGNED(cell->offset, nvmem->stride)) {
dev_err(&nvmem->dev,
"cell %s unaligned to nvmem stride %d\n",
cell->name ?: "<unknown>", nvmem->stride);
return -EINVAL;
}
if (!IS_ALIGNED(cell->raw_len, nvmem->word_size)) {
dev_err(&nvmem->dev,
"cell %s raw len %zd unaligned to nvmem word size %d\n",
cell->name ?: "<unknown>", cell->raw_len,
nvmem->word_size);
if (info->raw_len)
return -EINVAL;
cell->raw_len = ALIGN(cell->raw_len, nvmem->word_size);
}
return 0;
}
static int nvmem_cell_info_to_nvmem_cell_entry(struct nvmem_device *nvmem,
const struct nvmem_cell_info *info,
struct nvmem_cell_entry *cell)
{
int err;
err = nvmem_cell_info_to_nvmem_cell_entry_nodup(nvmem, info, cell);
if (err)
return err;
cell->name = kstrdup_const(info->name, GFP_KERNEL);
if (!cell->name)
return -ENOMEM;
return 0;
Annotation
- Immediate include surface: `linux/device.h`, `linux/export.h`, `linux/fs.h`, `linux/idr.h`, `linux/init.h`, `linux/kref.h`, `linux/module.h`, `linux/nvmem-consumer.h`.
- Detected declarations: `struct nvmem_cell_entry`, `struct nvmem_cell`, `function __nvmem_reg_read`, `function __nvmem_reg_write`, `function nvmem_access_with_keepouts`, `function nvmem_reg_read`, `function nvmem_reg_write`, `function type_show`, `function force_ro_show`, `function force_ro_store`.
- Atlas domain: Driver Families / drivers/nvmem.
- Implementation status: pattern 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.