drivers/regulator/helpers.c
Source file repositories/reference/linux-study-clean/drivers/regulator/helpers.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/helpers.c- Extension
.c- Size
- 26780 bytes
- Lines
- 1004
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/delay.hlinux/err.hlinux/export.hlinux/kernel.hlinux/regmap.hlinux/regulator/consumer.hlinux/regulator/driver.hinternal.h
Detected Declarations
function regulator_is_enabled_regmapfunction enablefunction disablefunction regulator_range_selector_to_indexfunction regulator_get_voltage_sel_pickable_regmapfunction write_separate_vsel_and_rangefunction regulator_set_voltage_sel_pickable_regmapfunction regulator_get_voltage_sel_regmapfunction regulator_set_voltage_sel_regmapfunction set_voltage_selfunction map_voltagefunction map_voltagefunction map_voltagefunction map_voltagefunction regulator_desc_list_voltage_linearfunction list_voltagefunction list_voltagefunction regulator_desc_list_voltage_linear_rangefunction list_voltagefunction list_voltagefunction regulator_set_bypass_regmapfunction regulator_set_soft_start_regmapfunction regulator_set_pull_down_regmapfunction regulator_get_bypass_regmapfunction regulator_set_active_discharge_regmapfunction regulator_set_current_limit_regmapfunction regulator_get_current_limit_regmapfunction regulator_bulk_set_supply_namesfunction regulator_is_equalfunction regulator_find_closest_biggerfunction regulator_set_ramp_delay_regmapexport regulator_is_enabled_regmapexport regulator_enable_regmapexport regulator_disable_regmapexport regulator_get_voltage_sel_pickable_regmapexport regulator_set_voltage_sel_pickable_regmapexport regulator_get_voltage_sel_regmapexport regulator_set_voltage_sel_regmapexport regulator_map_voltage_iterateexport regulator_map_voltage_ascendexport regulator_map_voltage_linearexport regulator_map_voltage_linear_rangeexport regulator_map_voltage_pickable_linear_rangeexport regulator_desc_list_voltage_linearexport regulator_list_voltage_linearexport regulator_list_voltage_pickable_linear_rangeexport regulator_desc_list_voltage_linear_rangeexport regulator_list_voltage_linear_range
Annotated Snippet
if (ret < best_val && ret >= min_uV && ret <= max_uV) {
best_val = ret;
selector = i;
}
}
if (best_val != INT_MAX)
return selector;
else
return -EINVAL;
}
EXPORT_SYMBOL_GPL(regulator_map_voltage_iterate);
/**
* regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
*
* @rdev: Regulator to operate on
* @min_uV: Lower bound for voltage
* @max_uV: Upper bound for voltage
*
* Drivers that have ascendant voltage list can use this as their
* map_voltage() operation.
*/
int regulator_map_voltage_ascend(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
int i, ret;
for (i = 0; i < rdev->desc->n_voltages; i++) {
ret = rdev->desc->ops->list_voltage(rdev, i);
if (ret < 0)
continue;
if (ret > max_uV)
break;
if (ret >= min_uV && ret <= max_uV)
return i;
}
return -EINVAL;
}
EXPORT_SYMBOL_GPL(regulator_map_voltage_ascend);
/**
* regulator_map_voltage_linear - map_voltage() for simple linear mappings
*
* @rdev: Regulator to operate on
* @min_uV: Lower bound for voltage
* @max_uV: Upper bound for voltage
*
* Drivers providing min_uV and uV_step in their regulator_desc can
* use this as their map_voltage() operation.
*/
int regulator_map_voltage_linear(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
int ret, voltage;
/* Allow uV_step to be 0 for fixed voltage */
if (rdev->desc->n_voltages == 1 && rdev->desc->uV_step == 0) {
if (min_uV <= rdev->desc->min_uV && rdev->desc->min_uV <= max_uV)
return 0;
else
return -EINVAL;
}
if (!rdev->desc->uV_step) {
BUG_ON(!rdev->desc->uV_step);
return -EINVAL;
}
if (min_uV < rdev->desc->min_uV)
min_uV = rdev->desc->min_uV;
ret = DIV_ROUND_UP(min_uV - rdev->desc->min_uV, rdev->desc->uV_step);
if (ret < 0)
return ret;
ret += rdev->desc->linear_min_sel;
/* Map back into a voltage to verify we're still in bounds */
voltage = rdev->desc->ops->list_voltage(rdev, ret);
if (voltage < min_uV || voltage > max_uV)
return -EINVAL;
return ret;
}
EXPORT_SYMBOL_GPL(regulator_map_voltage_linear);
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/delay.h`, `linux/err.h`, `linux/export.h`, `linux/kernel.h`, `linux/regmap.h`, `linux/regulator/consumer.h`, `linux/regulator/driver.h`.
- Detected declarations: `function regulator_is_enabled_regmap`, `function enable`, `function disable`, `function regulator_range_selector_to_index`, `function regulator_get_voltage_sel_pickable_regmap`, `function write_separate_vsel_and_range`, `function regulator_set_voltage_sel_pickable_regmap`, `function regulator_get_voltage_sel_regmap`, `function regulator_set_voltage_sel_regmap`, `function set_voltage_sel`.
- 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.