drivers/regulator/rt5759-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/rt5759-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/rt5759-regulator.c- Extension
.c- Size
- 9373 bytes
- Lines
- 372
- 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/i2c.hlinux/kernel.hlinux/module.hlinux/of.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
struct rt5759_privfunction rt5759_set_modefunction rt5759_get_modefunction rt5759_get_error_flagsfunction rt5759_set_ocpfunction rt5759_set_otpfunction rt5759_of_map_modefunction rt5759_regulator_registerfunction rt5759_init_device_propertyfunction rt5759_manufacturer_checkfunction rt5759_is_accessible_regfunction rt5759_probe
Annotated Snippet
struct rt5759_priv {
struct device *dev;
struct regmap *regmap;
struct regulator_desc desc;
unsigned long chip_type;
};
static int rt5759_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int mode_val;
switch (mode) {
case REGULATOR_MODE_NORMAL:
mode_val = 0;
break;
case REGULATOR_MODE_FAST:
mode_val = RT5759_FPWM_MASK;
break;
default:
return -EINVAL;
}
return regmap_update_bits(regmap, RT5759_REG_STATUS, RT5759_FPWM_MASK,
mode_val);
}
static unsigned int rt5759_get_mode(struct regulator_dev *rdev)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int regval;
int ret;
ret = regmap_read(regmap, RT5759_REG_DCDCCTRL, ®val);
if (ret)
return REGULATOR_MODE_INVALID;
if (regval & RT5759_FPWM_MASK)
return REGULATOR_MODE_FAST;
return REGULATOR_MODE_NORMAL;
}
static int rt5759_get_error_flags(struct regulator_dev *rdev,
unsigned int *flags)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int status, events = 0;
int ret;
ret = regmap_read(regmap, RT5759_REG_STATUS, &status);
if (ret)
return ret;
if (status & RT5759_OT_MASK)
events |= REGULATOR_ERROR_OVER_TEMP;
if (status & RT5759_UV_MASK)
events |= REGULATOR_ERROR_UNDER_VOLTAGE;
*flags = events;
return 0;
}
static int rt5759_set_ocp(struct regulator_dev *rdev, int lim_uA, int severity,
bool enable)
{
struct regmap *regmap = rdev_get_regmap(rdev);
int ocp_lvl[] = { 9800000, 10800000, 11800000 };
unsigned int ocp_regval;
int i;
/* Only support over current protection parameter */
if (severity != REGULATOR_SEVERITY_PROT)
return 0;
if (enable) {
/* Default ocp level is 10.8A */
if (lim_uA == 0)
lim_uA = 10800000;
for (i = 0; i < ARRAY_SIZE(ocp_lvl); i++) {
if (lim_uA <= ocp_lvl[i])
break;
}
if (i == ARRAY_SIZE(ocp_lvl))
i = ARRAY_SIZE(ocp_lvl) - 1;
ocp_regval = i + 1;
Annotation
- Immediate include surface: `linux/bits.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/regmap.h`, `linux/regulator/driver.h`, `linux/regulator/of_regulator.h`.
- Detected declarations: `struct rt5759_priv`, `function rt5759_set_mode`, `function rt5759_get_mode`, `function rt5759_get_error_flags`, `function rt5759_set_ocp`, `function rt5759_set_otp`, `function rt5759_of_map_mode`, `function rt5759_regulator_register`, `function rt5759_init_device_property`, `function rt5759_manufacturer_check`.
- 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.