drivers/regulator/vctrl-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/vctrl-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/vctrl-regulator.c- Extension
.c- Size
- 13527 bytes
- Lines
- 556
- Domain
- Driver Families
- Bucket
- drivers/regulator
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/delay.hlinux/err.hlinux/init.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/regulator/coupler.hlinux/regulator/driver.hlinux/regulator/of_regulator.hlinux/sort.hinternal.h
Detected Declarations
struct vctrl_voltage_rangestruct vctrl_voltage_rangesstruct vctrl_voltage_tablestruct vctrl_datafunction vctrl_calc_ctrl_voltagefunction vctrl_calc_output_voltagefunction vctrl_get_voltagefunction vctrl_set_voltagefunction vctrl_get_voltage_selfunction vctrl_set_voltage_selfunction vctrl_list_voltagefunction vctrl_parse_dtfunction vctrl_cmp_ctrl_uVfunction vctrl_init_vtablefunction vctrl_enablefunction vctrl_disablefunction vctrl_is_enabledfunction vctrl_probe
Annotated Snippet
struct vctrl_voltage_range {
int min_uV;
int max_uV;
};
struct vctrl_voltage_ranges {
struct vctrl_voltage_range ctrl;
struct vctrl_voltage_range out;
};
struct vctrl_voltage_table {
int ctrl;
int out;
int ovp_min_sel;
};
struct vctrl_data {
struct regulator_dev *rdev;
struct regulator_desc desc;
bool enabled;
unsigned int min_slew_down_rate;
unsigned int ovp_threshold;
struct vctrl_voltage_ranges vrange;
struct vctrl_voltage_table *vtable;
unsigned int sel;
};
static int vctrl_calc_ctrl_voltage(struct vctrl_data *vctrl, int out_uV)
{
struct vctrl_voltage_range *ctrl = &vctrl->vrange.ctrl;
struct vctrl_voltage_range *out = &vctrl->vrange.out;
return ctrl->min_uV +
DIV_ROUND_CLOSEST_ULL((s64)(out_uV - out->min_uV) *
(ctrl->max_uV - ctrl->min_uV),
out->max_uV - out->min_uV);
}
static int vctrl_calc_output_voltage(struct vctrl_data *vctrl, int ctrl_uV)
{
struct vctrl_voltage_range *ctrl = &vctrl->vrange.ctrl;
struct vctrl_voltage_range *out = &vctrl->vrange.out;
if (ctrl_uV < 0) {
pr_err("vctrl: failed to get control voltage\n");
return ctrl_uV;
}
if (ctrl_uV < ctrl->min_uV)
return out->min_uV;
if (ctrl_uV > ctrl->max_uV)
return out->max_uV;
return out->min_uV +
DIV_ROUND_CLOSEST_ULL((s64)(ctrl_uV - ctrl->min_uV) *
(out->max_uV - out->min_uV),
ctrl->max_uV - ctrl->min_uV);
}
static int vctrl_get_voltage(struct regulator_dev *rdev)
{
struct vctrl_data *vctrl = rdev_get_drvdata(rdev);
int ctrl_uV;
if (!rdev->supply)
return -EPROBE_DEFER;
ctrl_uV = regulator_get_voltage_rdev(rdev->supply->rdev);
return vctrl_calc_output_voltage(vctrl, ctrl_uV);
}
static int vctrl_set_voltage(struct regulator_dev *rdev,
int req_min_uV, int req_max_uV,
unsigned int *selector)
{
struct vctrl_data *vctrl = rdev_get_drvdata(rdev);
int orig_ctrl_uV;
int uV;
int ret;
if (!rdev->supply)
return -EPROBE_DEFER;
orig_ctrl_uV = regulator_get_voltage_rdev(rdev->supply->rdev);
uV = vctrl_calc_output_voltage(vctrl, orig_ctrl_uV);
if (req_min_uV >= uV || !vctrl->ovp_threshold)
/* voltage rising or no OVP */
Annotation
- Immediate include surface: `linux/delay.h`, `linux/err.h`, `linux/init.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regulator/coupler.h`, `linux/regulator/driver.h`.
- Detected declarations: `struct vctrl_voltage_range`, `struct vctrl_voltage_ranges`, `struct vctrl_voltage_table`, `struct vctrl_data`, `function vctrl_calc_ctrl_voltage`, `function vctrl_calc_output_voltage`, `function vctrl_get_voltage`, `function vctrl_set_voltage`, `function vctrl_get_voltage_sel`, `function vctrl_set_voltage_sel`.
- Atlas domain: Driver Families / drivers/regulator.
- Implementation status: source 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.