drivers/regulator/mt6316-regulator.c
Source file repositories/reference/linux-study-clean/drivers/regulator/mt6316-regulator.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/mt6316-regulator.c- Extension
.c- Size
- 9660 bytes
- Lines
- 346
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/of.hlinux/regmap.hlinux/spmi.hlinux/regulator/driver.hlinux/regulator/machine.hlinux/regulator/of_regulator.h
Detected Declarations
struct mt6316_regulator_infoenum mt6316_typefunction mt6316_be9_to_cpufunction mt6316_cpu_to_be9function mt6316_map_modefunction mt6316_vreg_enable_setclrfunction mt6316_vreg_disable_setclrfunction mt6316_regulator_set_voltage_selfunction mt6316_regulator_get_voltage_selfunction mt6316_regulator_get_statusfunction mt6316_regulator_get_modefunction mt6316_regulator_set_modefunction mt6316_regulator_probe
Annotated Snippet
struct mt6316_regulator_info {
struct regulator_desc desc;
u16 debug_reg;
u16 lp_mode_reg;
u16 lp_mode_mask;
u16 modeset_reg;
u16 modeset_mask;
};
#define MT6316_BUCK(match, vreg_id, min, max, step, vs_reg) \
{ \
.desc = { \
.name = match, \
.of_match = of_match_ptr(match), \
.ops = &mt6316_vreg_setclr_ops, \
.type = REGULATOR_VOLTAGE, \
.owner = THIS_MODULE, \
.n_voltages = (max - min) / step + 1, \
.min_uV = min, \
.uV_step = step, \
.enable_reg = MT6316_BUCK_TOP_CON0, \
.enable_mask = BIT(vreg_id - 1), \
.vsel_reg = vs_reg, \
.vsel_mask = MT6316_VSEL_MASK, \
.of_map_mode = mt6316_map_mode, \
}, \
.lp_mode_reg = MT6316_BUCK_TOP_CON1, \
.lp_mode_mask = BIT(vreg_id - 1), \
.modeset_reg = MT6316_BUCK_TOP_4PHASE_TOP_ANA_CON0, \
.modeset_mask = BIT(vreg_id - 1), \
.debug_reg = MT6316_VBUCK##vreg_id##_DBG, \
}
/* Values in some MT6316 registers are big endian, 9 bits long... */
static inline u16 mt6316_be9_to_cpu(u16 val)
{
return ((val >> 8) & BIT(0)) | ((val & GENMASK(7, 0)) << 1);
}
static inline u16 mt6316_cpu_to_be9(u16 val)
{
return ((val & BIT(0)) << 8) | (val >> 1);
}
static unsigned int mt6316_map_mode(u32 mode)
{
switch (mode) {
case MT6316_BUCK_MODE_AUTO:
return REGULATOR_MODE_NORMAL;
case MT6316_BUCK_MODE_FORCE_PWM:
return REGULATOR_MODE_FAST;
case MT6316_BUCK_MODE_LP:
return REGULATOR_MODE_IDLE;
default:
return REGULATOR_MODE_INVALID;
}
}
static int mt6316_vreg_enable_setclr(struct regulator_dev *rdev)
{
return regmap_write(rdev->regmap, rdev->desc->enable_reg + EN_SET_OFFSET,
rdev->desc->enable_mask);
}
static int mt6316_vreg_disable_setclr(struct regulator_dev *rdev)
{
return regmap_write(rdev->regmap, rdev->desc->enable_reg + EN_CLR_OFFSET,
rdev->desc->enable_mask);
}
static int mt6316_regulator_set_voltage_sel(struct regulator_dev *rdev, unsigned int selector)
{
u16 val = mt6316_cpu_to_be9(selector);
return regmap_bulk_write(rdev->regmap, rdev->desc->vsel_reg, &val, sizeof(val));
}
static int mt6316_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
u16 val;
int ret;
ret = regmap_bulk_read(rdev->regmap, rdev->desc->vsel_reg, &val, sizeof(val));
if (ret)
return ret;
return mt6316_be9_to_cpu(val & rdev->desc->vsel_mask);
}
static int mt6316_regulator_get_status(struct regulator_dev *rdev)
Annotation
- Immediate include surface: `linux/module.h`, `linux/of.h`, `linux/regmap.h`, `linux/spmi.h`, `linux/regulator/driver.h`, `linux/regulator/machine.h`, `linux/regulator/of_regulator.h`.
- Detected declarations: `struct mt6316_regulator_info`, `enum mt6316_type`, `function mt6316_be9_to_cpu`, `function mt6316_cpu_to_be9`, `function mt6316_map_mode`, `function mt6316_vreg_enable_setclr`, `function mt6316_vreg_disable_setclr`, `function mt6316_regulator_set_voltage_sel`, `function mt6316_regulator_get_voltage_sel`, `function mt6316_regulator_get_status`.
- 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.