drivers/regulator/rt5759-regulator.c

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

File Facts

System
Linux kernel
Corpus path
drivers/regulator/rt5759-regulator.c
Extension
.c
Size
9373 bytes
Lines
372
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 rt5759_priv {
	struct device *dev;
	struct regmap *regmap;
	struct regulator_desc desc;
	unsigned long chip_type;
};

static int rt5759_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_NORMAL:
		mode_val = 0;
		break;
	case REGULATOR_MODE_FAST:
		mode_val = RT5759_FPWM_MASK;
		break;
	default:
		return -EINVAL;
	}

	return regmap_update_bits(regmap, RT5759_REG_STATUS, RT5759_FPWM_MASK,
				  mode_val);
}

static unsigned int rt5759_get_mode(struct regulator_dev *rdev)
{
	struct regmap *regmap = rdev_get_regmap(rdev);
	unsigned int regval;
	int ret;

	ret = regmap_read(regmap, RT5759_REG_DCDCCTRL, &regval);
	if (ret)
		return REGULATOR_MODE_INVALID;

	if (regval & RT5759_FPWM_MASK)
		return REGULATOR_MODE_FAST;

	return REGULATOR_MODE_NORMAL;
}

static int rt5759_get_error_flags(struct regulator_dev *rdev,
				  unsigned int *flags)
{
	struct regmap *regmap = rdev_get_regmap(rdev);
	unsigned int status, events = 0;
	int ret;

	ret = regmap_read(regmap, RT5759_REG_STATUS, &status);
	if (ret)
		return ret;

	if (status & RT5759_OT_MASK)
		events |= REGULATOR_ERROR_OVER_TEMP;

	if (status & RT5759_UV_MASK)
		events |= REGULATOR_ERROR_UNDER_VOLTAGE;

	*flags = events;
	return 0;
}

static int rt5759_set_ocp(struct regulator_dev *rdev, int lim_uA, int severity,
			  bool enable)
{
	struct regmap *regmap = rdev_get_regmap(rdev);
	int ocp_lvl[] = { 9800000, 10800000, 11800000 };
	unsigned int ocp_regval;
	int i;

	/* Only support over current protection parameter */
	if (severity != REGULATOR_SEVERITY_PROT)
		return 0;

	if (enable) {
		/* Default ocp level is 10.8A */
		if (lim_uA == 0)
			lim_uA = 10800000;

		for (i = 0; i < ARRAY_SIZE(ocp_lvl); i++) {
			if (lim_uA <= ocp_lvl[i])
				break;
		}

		if (i == ARRAY_SIZE(ocp_lvl))
			i = ARRAY_SIZE(ocp_lvl) - 1;

		ocp_regval = i + 1;

Annotation

Implementation Notes