drivers/regulator/pv88060-regulator.c

Source file repositories/reference/linux-study-clean/drivers/regulator/pv88060-regulator.c

File Facts

System
Linux kernel
Corpus path
drivers/regulator/pv88060-regulator.c
Extension
.c
Size
9963 bytes
Lines
391
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 pv88060_regulator {
	struct regulator_desc desc;
	unsigned int conf;		/* buck configuration register */
};

struct pv88060 {
	struct device *dev;
	struct regmap *regmap;
	struct regulator_dev *rdev[PV88060_MAX_REGULATORS];
};

static const struct regmap_config pv88060_regmap_config = {
	.reg_bits = 8,
	.val_bits = 8,
};

/* Current limits array (in uA) for BUCK1
 * Entry indexes corresponds to register values.
 */

static const unsigned int pv88060_buck1_limits[] = {
	1496000, 2393000, 3291000, 4189000
};

static unsigned int pv88060_buck_get_mode(struct regulator_dev *rdev)
{
	struct pv88060_regulator *info = rdev_get_drvdata(rdev);
	unsigned int data;
	int ret, mode = 0;

	ret = regmap_read(rdev->regmap, info->conf, &data);
	if (ret < 0)
		return ret;

	switch (data & PV88060_BUCK_MODE_MASK) {
	case PV88060_BUCK_MODE_SYNC:
		mode = REGULATOR_MODE_FAST;
		break;
	case PV88060_BUCK_MODE_AUTO:
		mode = REGULATOR_MODE_NORMAL;
		break;
	case PV88060_BUCK_MODE_SLEEP:
		mode = REGULATOR_MODE_STANDBY;
		break;
	}

	return mode;
}

static int pv88060_buck_set_mode(struct regulator_dev *rdev,
					unsigned int mode)
{
	struct pv88060_regulator *info = rdev_get_drvdata(rdev);
	int val = 0;

	switch (mode) {
	case REGULATOR_MODE_FAST:
		val = PV88060_BUCK_MODE_SYNC;
		break;
	case REGULATOR_MODE_NORMAL:
		val = PV88060_BUCK_MODE_AUTO;
		break;
	case REGULATOR_MODE_STANDBY:
		val = PV88060_BUCK_MODE_SLEEP;
		break;
	default:
		return -EINVAL;
	}

	return regmap_update_bits(rdev->regmap, info->conf,
					PV88060_BUCK_MODE_MASK, val);
}

static const struct regulator_ops pv88060_buck_ops = {
	.get_mode = pv88060_buck_get_mode,
	.set_mode = pv88060_buck_set_mode,
	.enable = regulator_enable_regmap,
	.disable = regulator_disable_regmap,
	.is_enabled = regulator_is_enabled_regmap,
	.set_voltage_sel = regulator_set_voltage_sel_regmap,
	.get_voltage_sel = regulator_get_voltage_sel_regmap,
	.list_voltage = regulator_list_voltage_linear,
	.set_current_limit = regulator_set_current_limit_regmap,
	.get_current_limit = regulator_get_current_limit_regmap,
};

static const struct regulator_ops pv88060_ldo_ops = {
	.enable = regulator_enable_regmap,
	.disable = regulator_disable_regmap,
	.is_enabled = regulator_is_enabled_regmap,

Annotation

Implementation Notes