drivers/regulator/rt5120-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/rt5120-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/rt5120-regulator.c- Extension
.c- Size
- 11837 bytes
- Lines
- 422
- 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/bits.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/machine.hlinux/regulator/of_regulator.h
Detected Declarations
struct rt5120_privfunction rt5120_buck_set_modefunction rt5120_buck_get_modefunction rt5120_regulator_get_error_flagsfunction rt5120_buck1_set_suspend_voltagefunction rt5120_regulator_set_suspend_enablefunction rt5120_regulator_set_suspend_disablefunction rt5120_buck_of_map_modefunction rt5120_fillin_regulator_descfunction rt5120_of_parse_cbfunction rt5120_parse_regulator_dt_datafunction rt5120_device_property_initfunction rt5120_regulator_probe
Annotated Snippet
struct rt5120_priv {
struct device *dev;
struct regmap *regmap;
struct regulator_desc rdesc[RT5120_MAX_REGULATOR];
};
static int rt5120_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
struct regmap *regmap = rdev_get_regmap(rdev);
int rid = rdev_get_id(rdev);
unsigned int mask = RT5120_FPWM_MASK(rid), val;
switch (mode) {
case REGULATOR_MODE_NORMAL:
val = 0;
break;
case REGULATOR_MODE_FAST:
val = RT5120_FPWM_MASK(rid);
break;
default:
return -EINVAL;
}
return regmap_update_bits(regmap, RT5120_REG_MODECTL, mask, val);
}
static unsigned int rt5120_buck_get_mode(struct regulator_dev *rdev)
{
struct regmap *regmap = rdev_get_regmap(rdev);
int ret, rid = rdev_get_id(rdev);
unsigned int val;
ret = regmap_read(regmap, RT5120_REG_MODECTL, &val);
if (ret)
return REGULATOR_MODE_INVALID;
if (val & RT5120_FPWM_MASK(rid))
return REGULATOR_MODE_FAST;
return REGULATOR_MODE_NORMAL;
}
static int rt5120_regulator_get_error_flags(struct regulator_dev *rdev,
unsigned int *flags)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int stat, hd_stat, cur_flags = 0;
int rid = rdev_get_id(rdev), ret;
/*
* reg 0x03/0x04/0x05 to indicate PG/UV/OV
* use block read to descrease I/O xfer time
*/
ret = regmap_raw_read(regmap, RT5120_REG_PGSTAT, &stat, 3);
if (ret)
return ret;
ret = regmap_read(regmap, RT5120_REG_INTSTAT, &hd_stat);
if (ret)
return ret;
if (!(stat & RT5120_OUTPG_MASK(rid))) {
if (stat & RT5120_OUTUV_MASK(rid))
cur_flags |= REGULATOR_ERROR_UNDER_VOLTAGE;
if (stat & RT5120_OUTOV_MASK(rid))
cur_flags |= REGULATOR_ERROR_REGULATION_OUT;
}
if (hd_stat & RT5120_HOTDIE_MASK)
cur_flags |= REGULATOR_ERROR_OVER_TEMP;
*flags = cur_flags;
return 0;
}
static int rt5120_buck1_set_suspend_voltage(struct regulator_dev *rdev, int uV)
{
struct regmap *regmap = rdev_get_regmap(rdev);
int sel;
if (uV < RT5120_BUCK1_MINUV || uV > RT5120_BUCK1_MAXUV)
return -EINVAL;
sel = (uV - RT5120_BUCK1_MINUV) / RT5120_BUCK1_STEPUV;
return regmap_write(regmap, RT5120_REG_CH1SLPVID, sel);
}
static int rt5120_regulator_set_suspend_enable(struct regulator_dev *rdev)
{
Annotation
- Immediate include surface: `linux/bits.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/regulator/driver.h`, `linux/regulator/machine.h`.
- Detected declarations: `struct rt5120_priv`, `function rt5120_buck_set_mode`, `function rt5120_buck_get_mode`, `function rt5120_regulator_get_error_flags`, `function rt5120_buck1_set_suspend_voltage`, `function rt5120_regulator_set_suspend_enable`, `function rt5120_regulator_set_suspend_disable`, `function rt5120_buck_of_map_mode`, `function rt5120_fillin_regulator_desc`, `function rt5120_of_parse_cb`.
- 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.