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.

Dependency Surface

Detected Declarations

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

Implementation Notes