drivers/regulator/max77838-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/max77838-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/max77838-regulator.c- Extension
.c- Size
- 6065 bytes
- Lines
- 222
- 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/kernel.hlinux/module.hlinux/init.hlinux/err.hlinux/of.hlinux/platform_device.hlinux/regulator/driver.hlinux/regulator/of_regulator.hlinux/i2c.hlinux/regmap.h
Detected Declarations
struct max77838_regulator_infoenum max77838_registersenum max77838_regulatorsfunction max77838_read_device_idfunction max77838_i2c_probe
Annotated Snippet
struct max77838_regulator_info {
struct regmap *regmap;
};
static const struct regmap_config max77838_regmap_config = {
.reg_bits = 8,
.val_bits = 8,
.max_register = MAX77838_REG_BUCK_VOUT,
};
static const struct regulator_ops max77838_regulator_ops = {
.enable = regulator_enable_regmap,
.disable = regulator_disable_regmap,
.is_enabled = regulator_is_enabled_regmap,
.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 const struct regulator_desc max77838_regulators_desc[] = {
MAX77838_LDO(1),
MAX77838_LDO(2),
MAX77838_LDO(3),
MAX77838_LDO(4),
MAX77838_BUCK_DESC,
};
static int max77838_read_device_id(struct regmap *regmap, struct device *dev)
{
unsigned int device_id;
int ret;
ret = regmap_read(regmap, MAX77838_REG_DEVICE_ID, &device_id);
if (!ret)
dev_dbg(dev, "DEVICE_ID: 0x%x\n", device_id);
return ret;
}
static int max77838_i2c_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
struct max77838_regulator_info *info;
struct regulator_config config = {};
struct regulator_dev *rdev;
struct regmap *regmap;
int i;
info = devm_kzalloc(dev, sizeof(struct max77838_regulator_info),
GFP_KERNEL);
if (!info)
return -ENOMEM;
regmap = devm_regmap_init_i2c(client, &max77838_regmap_config);
if (IS_ERR(regmap)) {
dev_err(dev, "Failed to allocate regmap!\n");
return PTR_ERR(regmap);
}
info->regmap = regmap;
i2c_set_clientdata(client, info);
config.dev = dev;
config.regmap = regmap;
config.driver_data = info;
for (i = 0; i < MAX77838_MAX_REGULATORS; i++) {
rdev = devm_regulator_register(dev,
&max77838_regulators_desc[i],
&config);
if (IS_ERR(rdev)) {
dev_err(dev, "Failed to register regulator!\n");
return PTR_ERR(rdev);
}
}
return max77838_read_device_id(regmap, dev);
}
static const struct of_device_id __maybe_unused max77838_of_match[] = {
{ .compatible = "maxim,max77838" },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, max77838_of_match);
static const struct i2c_device_id max77838_id[] = {
{ "max77838-regulator" },
{ /* sentinel */ }
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/err.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regulator/driver.h`, `linux/regulator/of_regulator.h`.
- Detected declarations: `struct max77838_regulator_info`, `enum max77838_registers`, `enum max77838_regulators`, `function max77838_read_device_id`, `function max77838_i2c_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.