drivers/regulator/bq257xx-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/bq257xx-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/bq257xx-regulator.c- Extension
.c- Size
- 5012 bytes
- Lines
- 186
- 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/bitfield.hlinux/err.hlinux/gpio/consumer.hlinux/mfd/bq257xx.hlinux/of.hlinux/platform_device.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
struct bq257xx_reg_datafunction bq25703_vbus_get_cur_limitfunction bq25703_vbus_set_cur_limitfunction bq25703_vbus_enablefunction bq25703_vbus_disablefunction bq257xx_reg_dt_parse_gpiofunction bq257xx_regulator_probe
Annotated Snippet
struct bq257xx_reg_data {
struct regulator_dev *bq257xx_reg;
struct gpio_desc *otg_en_gpio;
struct regulator_desc desc;
};
static int bq25703_vbus_get_cur_limit(struct regulator_dev *rdev)
{
struct regmap *regmap = rdev_get_regmap(rdev);
int ret;
unsigned int reg;
ret = regmap_read(regmap, BQ25703_OTG_CURRENT, ®);
if (ret)
return ret;
return FIELD_GET(BQ25703_OTG_CUR_MASK, reg) * BQ25703_OTG_CUR_STEP_UA;
}
/*
* Check if the minimum current and maximum current requested are
* sane values, then set the register accordingly.
*/
static int bq25703_vbus_set_cur_limit(struct regulator_dev *rdev,
int min_uA, int max_uA)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int reg;
if ((min_uA > BQ25703_OTG_CUR_MAX_UA) || (max_uA < 0))
return -EINVAL;
reg = (max_uA / BQ25703_OTG_CUR_STEP_UA);
/* Catch rounding errors since our step is 50000uA. */
if ((reg * BQ25703_OTG_CUR_STEP_UA) < min_uA)
return -EINVAL;
return regmap_write(regmap, BQ25703_OTG_CURRENT,
FIELD_PREP(BQ25703_OTG_CUR_MASK, reg));
}
static int bq25703_vbus_enable(struct regulator_dev *rdev)
{
struct bq257xx_reg_data *pdata = rdev_get_drvdata(rdev);
if (pdata->otg_en_gpio)
gpiod_set_value_cansleep(pdata->otg_en_gpio, 1);
return regulator_enable_regmap(rdev);
}
static int bq25703_vbus_disable(struct regulator_dev *rdev)
{
struct bq257xx_reg_data *pdata = rdev_get_drvdata(rdev);
if (pdata->otg_en_gpio)
gpiod_set_value_cansleep(pdata->otg_en_gpio, 0);
return regulator_disable_regmap(rdev);
}
static const struct regulator_ops bq25703_vbus_ops = {
.enable = bq25703_vbus_enable,
.disable = bq25703_vbus_disable,
.is_enabled = regulator_is_enabled_regmap,
.list_voltage = regulator_list_voltage_linear,
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.get_current_limit = bq25703_vbus_get_cur_limit,
.set_current_limit = bq25703_vbus_set_cur_limit,
};
static const struct regulator_desc bq25703_vbus_desc = {
.name = "vbus",
.of_match = of_match_ptr("vbus"),
.regulators_node = of_match_ptr("regulators"),
.type = REGULATOR_VOLTAGE,
.owner = THIS_MODULE,
.ops = &bq25703_vbus_ops,
.min_uV = BQ25703_OTG_VOLT_MIN_UV,
.uV_step = BQ25703_OTG_VOLT_STEP_UV,
.n_voltages = BQ25703_OTG_VOLT_NUM_VOLT,
.enable_mask = BQ25703_EN_OTG_MASK,
.enable_reg = BQ25703_CHARGE_OPTION_3,
.enable_val = BQ25703_EN_OTG_MASK,
.disable_val = 0,
.vsel_reg = BQ25703_OTG_VOLT,
.vsel_mask = BQ25703_OTG_VOLT_MASK,
};
/* Get optional GPIO for OTG regulator enable. */
static void bq257xx_reg_dt_parse_gpio(struct platform_device *pdev)
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/err.h`, `linux/gpio/consumer.h`, `linux/mfd/bq257xx.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/regulator/driver.h`.
- Detected declarations: `struct bq257xx_reg_data`, `function bq25703_vbus_get_cur_limit`, `function bq25703_vbus_set_cur_limit`, `function bq25703_vbus_enable`, `function bq25703_vbus_disable`, `function bq257xx_reg_dt_parse_gpio`, `function bq257xx_regulator_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.