drivers/regulator/max20411-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/max20411-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/max20411-regulator.c- Extension
.c- Size
- 4444 bytes
- Lines
- 166
- 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/gpio/consumer.hlinux/i2c.hlinux/module.hlinux/of_platform.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/machine.hlinux/regulator/of_regulator.h
Detected Declarations
struct max20411function max20411_enable_timefunction max20411_probe
Annotated Snippet
struct max20411 {
struct device *dev;
struct device_node *of_node;
struct regulator_desc desc;
struct regulator_dev *rdev;
struct regmap *regmap;
};
static const unsigned int max20411_slew_rates[] = { 13100, 6600, 3300, 1600 };
static int max20411_enable_time(struct regulator_dev *rdev)
{
int voltage, rate, ret;
unsigned int val;
/* get voltage */
ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
if (ret)
return ret;
val &= rdev->desc->vsel_mask;
voltage = regulator_list_voltage_linear(rdev, val);
/* get rate */
ret = regmap_read(rdev->regmap, MAX20411_SLEW_OFFSET, &val);
if (ret)
return ret;
val = FIELD_GET(MAX20411_SLEW_SR_MASK, val);
rate = max20411_slew_rates[val];
return DIV_ROUND_UP(voltage, rate);
}
static const struct regmap_config max20411_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = 0xe,
};
static const struct regulator_ops max20411_ops = {
.get_voltage_sel = regulator_get_voltage_sel_regmap,
.set_voltage_sel = regulator_set_voltage_sel_regmap,
.list_voltage = regulator_list_voltage_linear,
.enable_time = max20411_enable_time,
};
static const struct regulator_desc max20411_desc = {
.ops = &max20411_ops,
.owner = THIS_MODULE,
.type = REGULATOR_VOLTAGE,
.supply_name = "vin",
.name = "max20411",
/*
* voltage = 0.24375V + selector * 6.25mV
* with valid selector between 41 to 165 (0.5V to 1.275V)
*/
.min_uV = MAX20411_BASE_UV,
.uV_step = MAX20411_UV_STEP,
.linear_min_sel = MAX20411_MIN_SEL,
.n_voltages = MAX20411_MAX_SEL + 1,
.vsel_reg = MAX20411_VID_OFFSET,
.vsel_mask = MAX20411_VID_MASK,
.ramp_reg = MAX20411_SLEW_OFFSET,
.ramp_mask = MAX20411_SLEW_DVS_MASK,
.ramp_delay_table = max20411_slew_rates,
.n_ramp_values = ARRAY_SIZE(max20411_slew_rates),
};
static int max20411_probe(struct i2c_client *client)
{
struct regulator_init_data *init_data;
struct device *dev = &client->dev;
struct regulator_config cfg = {};
struct max20411 *max20411;
max20411 = devm_kzalloc(dev, sizeof(*max20411), GFP_KERNEL);
if (!max20411)
return -ENOMEM;
max20411->regmap = devm_regmap_init_i2c(client, &max20411_regmap_config);
if (IS_ERR(max20411->regmap)) {
dev_err(dev, "Failed to allocate regmap!\n");
return PTR_ERR(max20411->regmap);
}
max20411->dev = dev;
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/module.h`, `linux/of_platform.h`, `linux/regmap.h`, `linux/regulator/driver.h`, `linux/regulator/machine.h`.
- Detected declarations: `struct max20411`, `function max20411_enable_time`, `function max20411_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.