drivers/regulator/of_regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/of_regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/of_regulator.c- Extension
.c- Size
- 26443 bytes
- Lines
- 988
- Domain
- Driver Families
- Bucket
- drivers/regulator
- 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/module.hlinux/slab.hlinux/of.hlinux/regulator/machine.hlinux/regulator/driver.hlinux/regulator/of_regulator.hinternal.h
Detected Declarations
struct devm_of_regulator_matchesfunction fill_limitfunction of_get_regulator_prot_limitsfunction of_get_regulation_constraintsfunction devm_of_regulator_put_matchesfunction of_regulator_matchfunction for_each_child_of_nodefunction for_each_available_child_of_nodefunction for_each_child_of_nodefunction put_devicefunction PTR_ERRfunction PTR_ERRfunction of_get_n_coupledfunction of_coupling_find_nodefunction of_check_coupling_datafunction of_parse_coupled_regulatorfunction is_supply_namefunction of_regulator_bulk_get_allexport of_get_regulator_init_dataexport of_regulator_matchexport of_regulator_getexport of_regulator_get_optionalexport of_regulator_bulk_get_all
Annotated Snippet
struct devm_of_regulator_matches {
struct of_regulator_match *matches;
unsigned int num_matches;
};
static void devm_of_regulator_put_matches(struct device *dev, void *res)
{
struct devm_of_regulator_matches *devm_matches = res;
int i;
for (i = 0; i < devm_matches->num_matches; i++)
of_node_put(devm_matches->matches[i].of_node);
}
/**
* of_regulator_match - extract multiple regulator init data from device tree.
* @dev: device requesting the data
* @node: parent device node of the regulators
* @matches: match table for the regulators
* @num_matches: number of entries in match table
*
* This function uses a match table specified by the regulator driver to
* parse regulator init data from the device tree. @node is expected to
* contain a set of child nodes, each providing the init data for one
* regulator. The data parsed from a child node will be matched to a regulator
* based on either the deprecated property regulator-compatible if present,
* or otherwise the child node's name. Note that the match table is modified
* in place and an additional of_node reference is taken for each matched
* regulator.
*
* Return: The number of matches found or a negative error number on failure.
*/
int of_regulator_match(struct device *dev, struct device_node *node,
struct of_regulator_match *matches,
unsigned int num_matches)
{
unsigned int count = 0;
unsigned int i;
const char *name;
struct device_node *child;
struct devm_of_regulator_matches *devm_matches;
if (!dev || !node)
return -EINVAL;
devm_matches = devres_alloc(devm_of_regulator_put_matches,
sizeof(struct devm_of_regulator_matches),
GFP_KERNEL);
if (!devm_matches)
return -ENOMEM;
devm_matches->matches = matches;
devm_matches->num_matches = num_matches;
devres_add(dev, devm_matches);
for (i = 0; i < num_matches; i++) {
struct of_regulator_match *match = &matches[i];
match->init_data = NULL;
match->of_node = NULL;
}
for_each_child_of_node(node, child) {
name = of_get_property(child,
"regulator-compatible", NULL);
if (!name)
name = child->name;
for (i = 0; i < num_matches; i++) {
struct of_regulator_match *match = &matches[i];
if (match->of_node)
continue;
if (strcmp(match->name, name))
continue;
match->init_data =
of_get_regulator_init_data(dev, child,
match->desc);
if (!match->init_data) {
dev_err(dev,
"failed to parse DT for regulator %pOFn\n",
child);
of_node_put(child);
goto err_put;
}
match->of_node = of_node_get(child);
count++;
break;
}
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/of.h`, `linux/regulator/machine.h`, `linux/regulator/driver.h`, `linux/regulator/of_regulator.h`, `internal.h`.
- Detected declarations: `struct devm_of_regulator_matches`, `function fill_limit`, `function of_get_regulator_prot_limits`, `function of_get_regulation_constraints`, `function devm_of_regulator_put_matches`, `function of_regulator_match`, `function for_each_child_of_node`, `function for_each_available_child_of_node`, `function for_each_child_of_node`, `function put_device`.
- Atlas domain: Driver Families / drivers/regulator.
- 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.