drivers/mfd/syscon.c
Source file repositories/reference/linux-study-clean/drivers/mfd/syscon.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/mfd/syscon.c- Extension
.c- Size
- 8957 bytes
- Lines
- 363
- Domain
- Driver Families
- Bucket
- drivers/mfd
- 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.
- 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/cleanup.hlinux/clk.hlinux/err.hlinux/hwspinlock.hlinux/list.hlinux/mutex.hlinux/of.hlinux/of_address.hlinux/regmap.hlinux/reset.hlinux/mfd/syscon.hlinux/slab.h
Detected Declarations
struct sysconfunction list_for_each_entryfunction of_syscon_register_regmapfunction list_for_each_entryfunction device_node_to_regmapfunction syscon_node_to_regmapfunction syscon_regmap_lookup_by_phandleexport of_syscon_register_regmapexport device_node_to_regmapexport syscon_node_to_regmapexport syscon_regmap_lookup_by_compatibleexport syscon_regmap_lookup_by_phandleexport syscon_regmap_lookup_by_phandle_argsexport syscon_regmap_lookup_by_phandle_optional
Annotated Snippet
struct syscon {
struct device_node *np;
struct regmap *regmap;
struct reset_control *reset;
struct list_head list;
};
static const struct regmap_config syscon_regmap_config = {
.reg_bits = 32,
.val_bits = 32,
.reg_stride = 4,
};
static struct syscon *of_syscon_register(struct device_node *np, bool check_res)
{
struct clk *clk;
struct regmap *regmap;
void __iomem *base;
u32 reg_io_width;
int ret;
struct regmap_config syscon_config = syscon_regmap_config;
struct resource res;
struct reset_control *reset;
resource_size_t res_size;
WARN_ON(!mutex_is_locked(&syscon_list_lock));
struct syscon *syscon __free(kfree) = kzalloc_obj(*syscon);
if (!syscon)
return ERR_PTR(-ENOMEM);
if (of_address_to_resource(np, 0, &res))
return ERR_PTR(-ENOMEM);
base = of_iomap(np, 0);
if (!base)
return ERR_PTR(-ENOMEM);
/* Parse the device's DT node for an endianness specification */
if (of_property_read_bool(np, "big-endian"))
syscon_config.val_format_endian = REGMAP_ENDIAN_BIG;
else if (of_property_read_bool(np, "little-endian"))
syscon_config.val_format_endian = REGMAP_ENDIAN_LITTLE;
else if (of_property_read_bool(np, "native-endian"))
syscon_config.val_format_endian = REGMAP_ENDIAN_NATIVE;
/*
* search for reg-io-width property in DT. If it is not provided,
* default to 4 bytes. regmap_init_mmio will return an error if values
* are invalid so there is no need to check them here.
*/
ret = of_property_read_u32(np, "reg-io-width", ®_io_width);
if (ret)
reg_io_width = 4;
ret = of_hwspin_lock_get_id(np, 0);
if (ret > 0 || (IS_ENABLED(CONFIG_HWSPINLOCK) && ret == 0)) {
syscon_config.use_hwlock = true;
syscon_config.hwlock_id = ret;
syscon_config.hwlock_mode = HWLOCK_IRQSTATE;
} else if (ret < 0) {
switch (ret) {
case -ENOENT:
/* Ignore missing hwlock, it's optional. */
break;
default:
pr_err("Failed to retrieve valid hwlock: %d\n", ret);
fallthrough;
case -EPROBE_DEFER:
goto err_regmap;
}
}
res_size = resource_size(&res);
if (res_size < reg_io_width) {
ret = -EFAULT;
goto err_regmap;
}
syscon_config.name = kasprintf(GFP_KERNEL, "%pOFn@%pa", np, &res.start);
if (!syscon_config.name) {
ret = -ENOMEM;
goto err_regmap;
}
syscon_config.reg_stride = reg_io_width;
syscon_config.val_bits = reg_io_width * 8;
syscon_config.max_register = res_size - reg_io_width;
if (!syscon_config.max_register)
syscon_config.max_register_is_0 = true;
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/clk.h`, `linux/err.h`, `linux/hwspinlock.h`, `linux/list.h`, `linux/mutex.h`, `linux/of.h`, `linux/of_address.h`.
- Detected declarations: `struct syscon`, `function list_for_each_entry`, `function of_syscon_register_regmap`, `function list_for_each_entry`, `function device_node_to_regmap`, `function syscon_node_to_regmap`, `function syscon_regmap_lookup_by_phandle`, `export of_syscon_register_regmap`, `export device_node_to_regmap`, `export syscon_node_to_regmap`.
- Atlas domain: Driver Families / drivers/mfd.
- Implementation status: integration 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.