drivers/base/regmap/regcache.c
Source file repositories/reference/linux-study-clean/drivers/base/regmap/regcache.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/base/regmap/regcache.c- Extension
.c- Size
- 20394 bytes
- Lines
- 893
- Domain
- Driver Families
- Bucket
- drivers/base
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/bsearch.hlinux/device.hlinux/export.hlinux/slab.hlinux/sort.htrace.hinternal.h
Detected Declarations
function regcache_defaults_cmpfunction regcache_sort_defaultsfunction regcache_count_cacheable_registersfunction regcache_hw_initfunction regcache_hw_exitfunction regcache_initfunction regcache_exitfunction regcache_readfunction regcache_writefunction regcache_reg_needs_syncfunction regcache_default_syncfunction rbtree_allfunction regcache_syncfunction regcache_sync_regionfunction regcache_drop_regionfunction regcache_cache_onlyfunction regcache_mark_dirtyfunction regcache_cache_bypassfunction regcache_reg_cachedfunction regcache_set_valfunction regcache_get_valfunction regcache_default_cmpfunction regcache_lookup_regfunction regcache_reg_presentfunction regcache_sync_valfunction regcache_sync_block_singlefunction regcache_sync_block_raw_flushfunction regcache_sync_block_rawfunction regcache_sync_blockexport regcache_sort_defaultsexport regcache_syncexport regcache_sync_regionexport regcache_drop_regionexport regcache_cache_onlyexport regcache_mark_dirtyexport regcache_cache_bypassexport regcache_reg_cached
Annotated Snippet
if (ret == 0) {
map->reg_defaults_raw = tmp_buf;
map->cache_free = true;
} else {
kfree(tmp_buf);
}
}
/* fill the reg_defaults */
for (unsigned int i = 0, j = 0; i < map->num_reg_defaults_raw; i++) {
reg = i * map->reg_stride;
if (!regmap_readable(map, reg))
continue;
if (regmap_volatile(map, reg))
continue;
if (map->reg_defaults_raw) {
val = regcache_get_val(map, map->reg_defaults_raw, i);
} else {
bool cache_bypass = map->cache_bypass;
map->cache_bypass = true;
ret = regmap_read(map, reg, &val);
map->cache_bypass = cache_bypass;
if (ret != 0) {
dev_err(map->dev, "Failed to read %x: %d\n",
reg, ret);
return ret;
}
}
map->reg_defaults[j].reg = reg;
map->reg_defaults[j].def = val;
j++;
}
return 0;
}
static void regcache_hw_exit(struct regmap *map)
{
if (map->cache_free)
kfree(map->reg_defaults_raw);
}
int regcache_init(struct regmap *map, const struct regmap_config *config)
{
int count = 0;
int ret;
int i;
void *tmp_buf;
if (map->cache_type == REGCACHE_NONE) {
if (config->reg_defaults || config->num_reg_defaults_raw)
dev_warn(map->dev,
"No cache used with register defaults set!\n");
map->cache_bypass = true;
return 0;
}
if (config->reg_defaults && !config->num_reg_defaults) {
dev_err(map->dev,
"Register defaults are set without the number!\n");
return -EINVAL;
}
if (config->num_reg_defaults && !config->reg_defaults) {
dev_err(map->dev,
"Register defaults number are set without the reg!\n");
return -EINVAL;
}
for (i = 0; i < config->num_reg_defaults; i++)
if (config->reg_defaults[i].reg % map->reg_stride)
return -EINVAL;
for (i = 0; i < ARRAY_SIZE(cache_types); i++)
if (cache_types[i]->type == map->cache_type)
break;
if (i == ARRAY_SIZE(cache_types)) {
dev_err(map->dev, "Could not match cache type: %d\n",
map->cache_type);
return -EINVAL;
}
map->num_reg_defaults = config->num_reg_defaults;
Annotation
- Immediate include surface: `linux/bsearch.h`, `linux/device.h`, `linux/export.h`, `linux/slab.h`, `linux/sort.h`, `trace.h`, `internal.h`.
- Detected declarations: `function regcache_defaults_cmp`, `function regcache_sort_defaults`, `function regcache_count_cacheable_registers`, `function regcache_hw_init`, `function regcache_hw_exit`, `function regcache_init`, `function regcache_exit`, `function regcache_read`, `function regcache_write`, `function regcache_reg_needs_sync`.
- Atlas domain: Driver Families / drivers/base.
- Implementation status: integration 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.