drivers/regulator/mcp16502.c
Source file repositories/reference/linux-study-clean/drivers/regulator/mcp16502.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/regulator/mcp16502.c- Extension
.c- Size
- 16101 bytes
- Lines
- 604
- 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/i2c.hlinux/init.hlinux/kernel.hlinux/module.hlinux/of.hlinux/regmap.hlinux/regulator/driver.hlinux/suspend.hlinux/gpio/consumer.h
Detected Declarations
struct mcp16502enum mcp16502_regfunction mcp16502_of_map_modefunction mcp16502_gpio_set_modefunction mcp16502_get_regfunction mcp16502_get_modefunction _mcp16502_set_modefunction mcp16502_set_modefunction mcp16502_get_statusfunction mcp16502_set_voltage_time_selfunction mcp16502_suspend_get_target_regfunction mcp16502_set_suspend_voltagefunction mcp16502_set_suspend_modefunction mcp16502_set_suspend_enablefunction mcp16502_set_suspend_disablefunction mcp16502_probefunction mcp16502_suspend_noirqfunction mcp16502_resume_noirq
Annotated Snippet
struct mcp16502 {
struct gpio_desc *lpm;
};
/*
* mcp16502_gpio_set_mode() - set the GPIO corresponding value
*
* Used to prepare transitioning into hibernate or resuming from it.
*/
static void mcp16502_gpio_set_mode(struct mcp16502 *mcp, int mode)
{
switch (mode) {
case MCP16502_OPMODE_ACTIVE:
gpiod_set_value(mcp->lpm, 0);
break;
case MCP16502_OPMODE_LPM:
case MCP16502_OPMODE_HIB:
gpiod_set_value(mcp->lpm, 1);
break;
default:
pr_err("%s: %d invalid\n", __func__, mode);
}
}
/*
* mcp16502_get_reg() - get the PMIC's state configuration register for opmode
*
* @rdev: the regulator whose register we are searching
* @opmode: the PMIC's operating mode ACTIVE, Low-power, Hibernate
*/
static int mcp16502_get_state_reg(struct regulator_dev *rdev, int opmode)
{
switch (opmode) {
case MCP16502_OPMODE_ACTIVE:
return MCP16502_REG_BASE(rdev_get_id(rdev), A);
case MCP16502_OPMODE_LPM:
return MCP16502_REG_BASE(rdev_get_id(rdev), LPM);
case MCP16502_OPMODE_HIB:
return MCP16502_REG_BASE(rdev_get_id(rdev), HIB);
default:
return -EINVAL;
}
}
/*
* mcp16502_get_mode() - return the current operating mode of a regulator
*
* Note: all functions that are not part of entering/exiting standby/suspend
* use the Active mode registers.
*
* Note: this is different from the PMIC's operatig mode, it is the
* MODE bit from the regulator's register.
*/
static unsigned int mcp16502_get_mode(struct regulator_dev *rdev)
{
unsigned int val;
int ret, reg;
reg = mcp16502_get_state_reg(rdev, MCP16502_OPMODE_ACTIVE);
if (reg < 0)
return reg;
ret = regmap_read(rdev->regmap, reg, &val);
if (ret)
return ret;
switch (val & MCP16502_MODE) {
case MCP16502_MODE_FPWM:
return REGULATOR_MODE_NORMAL;
case MCP16502_MODE_AUTO_PFM:
return REGULATOR_MODE_IDLE;
default:
return REGULATOR_MODE_INVALID;
}
}
/*
* _mcp16502_set_mode() - helper for set_mode and set_suspend_mode
*
* @rdev: the regulator for which we are setting the mode
* @mode: the regulator's mode (the one from MODE bit)
* @opmode: the PMIC's operating mode: Active/Low-power/Hibernate
*/
static int _mcp16502_set_mode(struct regulator_dev *rdev, unsigned int mode,
unsigned int op_mode)
{
int val;
int reg;
reg = mcp16502_get_state_reg(rdev, op_mode);
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/regmap.h`, `linux/regulator/driver.h`, `linux/suspend.h`.
- Detected declarations: `struct mcp16502`, `enum mcp16502_reg`, `function mcp16502_of_map_mode`, `function mcp16502_gpio_set_mode`, `function mcp16502_get_reg`, `function mcp16502_get_mode`, `function _mcp16502_set_mode`, `function mcp16502_set_mode`, `function mcp16502_get_status`, `function mcp16502_set_voltage_time_sel`.
- 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.