drivers/regulator/mp886x.c
Source file repositories/reference/linux-study-clean/drivers/regulator/mp886x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/mp886x.c- Extension
.c- Size
- 8831 bytes
- Lines
- 371
- 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/gpio/consumer.hlinux/i2c.hlinux/module.hlinux/of.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
struct mp886x_cfg_infostruct mp886x_device_infofunction mp886x_set_switch_freqfunction mp886x_set_modefunction mp886x_get_modefunction mp8869_set_voltage_selfunction mp8869_scalefunction mp8869_get_voltage_selfunction mp8867_set_voltage_selfunction mp8867_get_voltage_selfunction mp886x_regulator_registerfunction mp886x_i2c_probe
Annotated Snippet
struct mp886x_cfg_info {
const struct regulator_ops *rops;
const unsigned int slew_rates[8];
const int switch_freq[4];
const u8 fs_reg;
const u8 fs_shift;
};
struct mp886x_device_info {
struct device *dev;
struct regulator_desc desc;
struct regulator_init_data *regulator;
struct gpio_desc *en_gpio;
const struct mp886x_cfg_info *ci;
u32 r[2];
unsigned int sel;
};
static void mp886x_set_switch_freq(struct mp886x_device_info *di,
struct regmap *regmap,
u32 freq)
{
const struct mp886x_cfg_info *ci = di->ci;
int i;
for (i = 0; i < ARRAY_SIZE(ci->switch_freq); i++) {
if (freq == ci->switch_freq[i]) {
regmap_update_bits(regmap, ci->fs_reg,
0x3 << ci->fs_shift, i << ci->fs_shift);
return;
}
}
dev_err(di->dev, "invalid frequency %d\n", freq);
}
static int mp886x_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
switch (mode) {
case REGULATOR_MODE_FAST:
regmap_update_bits(rdev->regmap, MP886X_SYSCNTLREG1,
MP886X_MODE, MP886X_MODE);
break;
case REGULATOR_MODE_NORMAL:
regmap_update_bits(rdev->regmap, MP886X_SYSCNTLREG1,
MP886X_MODE, 0);
break;
default:
return -EINVAL;
}
return 0;
}
static unsigned int mp886x_get_mode(struct regulator_dev *rdev)
{
u32 val;
int ret;
ret = regmap_read(rdev->regmap, MP886X_SYSCNTLREG1, &val);
if (ret < 0)
return ret;
if (val & MP886X_MODE)
return REGULATOR_MODE_FAST;
else
return REGULATOR_MODE_NORMAL;
}
static int mp8869_set_voltage_sel(struct regulator_dev *rdev, unsigned int sel)
{
int ret;
ret = regmap_update_bits(rdev->regmap, MP886X_SYSCNTLREG1,
MP886X_GO, MP886X_GO);
if (ret < 0)
return ret;
sel <<= ffs(rdev->desc->vsel_mask) - 1;
return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
MP886X_V_BOOT | rdev->desc->vsel_mask, sel);
}
static inline unsigned int mp8869_scale(unsigned int uv, u32 r1, u32 r2)
{
u32 tmp = uv * r1 / r2;
return uv + tmp;
}
static int mp8869_get_voltage_sel(struct regulator_dev *rdev)
{
Annotation
- Immediate include surface: `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/module.h`, `linux/of.h`, `linux/regmap.h`, `linux/regulator/driver.h`, `linux/regulator/of_regulator.h`.
- Detected declarations: `struct mp886x_cfg_info`, `struct mp886x_device_info`, `function mp886x_set_switch_freq`, `function mp886x_set_mode`, `function mp886x_get_mode`, `function mp8869_set_voltage_sel`, `function mp8869_scale`, `function mp8869_get_voltage_sel`, `function mp8867_set_voltage_sel`, `function mp8867_get_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.