drivers/regulator/pwm-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/pwm-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/pwm-regulator.c- Extension
.c- Size
- 11929 bytes
- Lines
- 445
- 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/module.hlinux/init.hlinux/err.hlinux/platform_device.hlinux/regulator/driver.hlinux/regulator/machine.hlinux/regulator/of_regulator.hlinux/of.hlinux/pwm.hlinux/gpio/consumer.h
Detected Declarations
struct pwm_continuous_reg_datastruct pwm_regulator_datastruct pwm_voltagesfunction pwm_regulator_init_statefunction pwm_regulator_get_voltage_selfunction pwm_regulator_set_voltage_selfunction pwm_regulator_list_voltagefunction pwm_regulator_enablefunction pwm_regulator_disablefunction pwm_regulator_is_enabledfunction pwm_regulator_get_voltagefunction pwm_regulator_set_voltagefunction pwm_regulator_init_tablefunction pwm_regulator_init_continuousfunction pwm_regulator_init_boot_onfunction pwm_regulator_probe
Annotated Snippet
struct pwm_continuous_reg_data {
unsigned int min_uV_dutycycle;
unsigned int max_uV_dutycycle;
unsigned int dutycycle_unit;
};
struct pwm_regulator_data {
/* Shared */
struct pwm_device *pwm;
/* Voltage table */
struct pwm_voltages *duty_cycle_table;
/* Continuous mode info */
struct pwm_continuous_reg_data continuous;
/* regulator descriptor */
struct regulator_desc desc;
int state;
/* Enable GPIO */
struct gpio_desc *enb_gpio;
};
struct pwm_voltages {
unsigned int uV;
unsigned int dutycycle;
};
/*
* Voltage table call-backs
*/
static void pwm_regulator_init_state(struct regulator_dev *rdev)
{
struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
struct pwm_state pwm_state;
unsigned int dutycycle;
int i;
pwm_get_state(drvdata->pwm, &pwm_state);
dutycycle = pwm_get_relative_duty_cycle(&pwm_state, 100);
for (i = 0; i < rdev->desc->n_voltages; i++) {
if (dutycycle == drvdata->duty_cycle_table[i].dutycycle) {
drvdata->state = i;
return;
}
}
}
static int pwm_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
if (drvdata->state < 0)
pwm_regulator_init_state(rdev);
return drvdata->state;
}
static int pwm_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned selector)
{
struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
struct pwm_state pstate;
int ret;
pwm_init_state(drvdata->pwm, &pstate);
pwm_set_relative_duty_cycle(&pstate,
drvdata->duty_cycle_table[selector].dutycycle, 100);
ret = pwm_apply_might_sleep(drvdata->pwm, &pstate);
if (ret) {
dev_err(&rdev->dev, "Failed to configure PWM: %d\n", ret);
return ret;
}
drvdata->state = selector;
return 0;
}
static int pwm_regulator_list_voltage(struct regulator_dev *rdev,
unsigned selector)
{
struct pwm_regulator_data *drvdata = rdev_get_drvdata(rdev);
if (selector >= rdev->desc->n_voltages)
return -EINVAL;
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/err.h`, `linux/platform_device.h`, `linux/regulator/driver.h`, `linux/regulator/machine.h`, `linux/regulator/of_regulator.h`, `linux/of.h`.
- Detected declarations: `struct pwm_continuous_reg_data`, `struct pwm_regulator_data`, `struct pwm_voltages`, `function pwm_regulator_init_state`, `function pwm_regulator_get_voltage_sel`, `function pwm_regulator_set_voltage_sel`, `function pwm_regulator_list_voltage`, `function pwm_regulator_enable`, `function pwm_regulator_disable`, `function pwm_regulator_is_enabled`.
- 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.