drivers/regulator/rt6160-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/rt6160-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/rt6160-regulator.c- Extension
.c- Size
- 8538 bytes
- Lines
- 336
- 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/delay.hlinux/gpio/consumer.hlinux/i2c.hlinux/kernel.hlinux/module.hlinux/property.hlinux/regmap.hlinux/regulator/driver.hlinux/regulator/of_regulator.h
Detected Declarations
struct rt6160_privfunction rt6160_enablefunction rt6160_disablefunction rt6160_is_enabledfunction rt6160_set_modefunction rt6160_get_modefunction rt6160_set_suspend_voltagefunction rt6160_get_error_flagsfunction rt6160_of_map_modefunction rt6160_is_accessible_regfunction rt6160_is_volatile_regfunction rt6160_probe
Annotated Snippet
struct rt6160_priv {
struct regulator_desc desc;
struct gpio_desc *enable_gpio;
struct regmap *regmap;
bool enable_state;
uint8_t devid;
};
static const unsigned int rt6160_ramp_tables[] = {
1000, 2500, 5000, 10000
};
static int rt6160_enable(struct regulator_dev *rdev)
{
struct rt6160_priv *priv = rdev_get_drvdata(rdev);
if (!priv->enable_gpio)
return 0;
gpiod_set_value_cansleep(priv->enable_gpio, 1);
priv->enable_state = true;
usleep_range(RT6160_I2CRDY_TIMEUS, RT6160_I2CRDY_TIMEUS + 100);
regcache_cache_only(priv->regmap, false);
return regcache_sync(priv->regmap);
}
static int rt6160_disable(struct regulator_dev *rdev)
{
struct rt6160_priv *priv = rdev_get_drvdata(rdev);
if (!priv->enable_gpio)
return -EINVAL;
/* Mark regcache as dirty and cache only before HW disabled */
regcache_cache_only(priv->regmap, true);
regcache_mark_dirty(priv->regmap);
priv->enable_state = false;
gpiod_set_value_cansleep(priv->enable_gpio, 0);
return 0;
}
static int rt6160_is_enabled(struct regulator_dev *rdev)
{
struct rt6160_priv *priv = rdev_get_drvdata(rdev);
return priv->enable_state ? 1 : 0;
}
static int rt6160_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_FAST:
mode_val = RT6160_FPWM_MASK;
break;
case REGULATOR_MODE_NORMAL:
mode_val = 0;
break;
default:
dev_err(&rdev->dev, "mode not supported\n");
return -EINVAL;
}
return regmap_update_bits(regmap, RT6160_REG_CNTL, RT6160_FPWM_MASK, mode_val);
}
static unsigned int rt6160_get_mode(struct regulator_dev *rdev)
{
struct regmap *regmap = rdev_get_regmap(rdev);
unsigned int val;
int ret;
ret = regmap_read(regmap, RT6160_REG_CNTL, &val);
if (ret)
return ret;
if (val & RT6160_FPWM_MASK)
return REGULATOR_MODE_FAST;
return REGULATOR_MODE_NORMAL;
}
static int rt6160_set_suspend_voltage(struct regulator_dev *rdev, int uV)
{
Annotation
- Immediate include surface: `linux/delay.h`, `linux/gpio/consumer.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/module.h`, `linux/property.h`, `linux/regmap.h`, `linux/regulator/driver.h`.
- Detected declarations: `struct rt6160_priv`, `function rt6160_enable`, `function rt6160_disable`, `function rt6160_is_enabled`, `function rt6160_set_mode`, `function rt6160_get_mode`, `function rt6160_set_suspend_voltage`, `function rt6160_get_error_flags`, `function rt6160_of_map_mode`, `function rt6160_is_accessible_reg`.
- 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.