drivers/regulator/aw37503-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/aw37503-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/aw37503-regulator.c- Extension
.c- Size
- 6352 bytes
- Lines
- 241
- 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/err.hlinux/gpio/consumer.hlinux/i2c.hlinux/module.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/machine.h
Detected Declarations
struct aw37503_reg_pdatastruct aw37503_regulatorfunction aw37503_regulator_enablefunction aw37503_regulator_disablefunction aw37503_regulator_is_enabledfunction aw37503_of_parse_cbfunction aw37503_probe
Annotated Snippet
struct aw37503_reg_pdata {
struct gpio_desc *en_gpiod;
int ena_gpio_state;
};
struct aw37503_regulator {
struct device *dev;
struct aw37503_reg_pdata reg_pdata[AW37503_MAX_REGULATORS];
};
static int aw37503_regulator_enable(struct regulator_dev *rdev)
{
struct aw37503_regulator *chip = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
struct aw37503_reg_pdata *rpdata = &chip->reg_pdata[id];
int ret;
if (!IS_ERR(rpdata->en_gpiod)) {
gpiod_set_value_cansleep(rpdata->en_gpiod, 1);
rpdata->ena_gpio_state = 1;
}
/* Hardware automatically enable discharge bit in enable */
if (rdev->constraints->active_discharge ==
REGULATOR_ACTIVE_DISCHARGE_DISABLE) {
ret = regulator_set_active_discharge_regmap(rdev, false);
if (ret < 0) {
dev_err(chip->dev, "Failed to disable active discharge: %d\n",
ret);
return ret;
}
}
return 0;
}
static int aw37503_regulator_disable(struct regulator_dev *rdev)
{
struct aw37503_regulator *chip = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
struct aw37503_reg_pdata *rpdata = &chip->reg_pdata[id];
if (!IS_ERR(rpdata->en_gpiod)) {
gpiod_set_value_cansleep(rpdata->en_gpiod, 0);
rpdata->ena_gpio_state = 0;
}
return 0;
}
static int aw37503_regulator_is_enabled(struct regulator_dev *rdev)
{
struct aw37503_regulator *chip = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
struct aw37503_reg_pdata *rpdata = &chip->reg_pdata[id];
if (!IS_ERR(rpdata->en_gpiod))
return rpdata->ena_gpio_state;
return 1;
}
static const struct regulator_ops aw37503_regulator_ops = {
.enable = aw37503_regulator_enable,
.disable = aw37503_regulator_disable,
.is_enabled = aw37503_regulator_is_enabled,
.list_voltage = regulator_list_voltage_linear,
.map_voltage = regulator_map_voltage_linear,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.set_active_discharge = regulator_set_active_discharge_regmap,
};
static int aw37503_of_parse_cb(struct device_node *np,
const struct regulator_desc *desc,
struct regulator_config *config)
{
struct aw37503_regulator *chip = config->driver_data;
struct aw37503_reg_pdata *rpdata = &chip->reg_pdata[desc->id];
int ret;
rpdata->en_gpiod = devm_fwnode_gpiod_get(chip->dev, of_fwnode_handle(np),
"enable", GPIOD_OUT_LOW,
"enable");
if (IS_ERR(rpdata->en_gpiod)) {
ret = PTR_ERR(rpdata->en_gpiod);
/* Ignore the error other than probe defer */
if (ret == -EPROBE_DEFER)
Annotation
- Immediate include surface: `linux/err.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/module.h`, `linux/regmap.h`, `linux/regulator/driver.h`, `linux/regulator/machine.h`.
- Detected declarations: `struct aw37503_reg_pdata`, `struct aw37503_regulator`, `function aw37503_regulator_enable`, `function aw37503_regulator_disable`, `function aw37503_regulator_is_enabled`, `function aw37503_of_parse_cb`, `function aw37503_probe`.
- 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.