drivers/regulator/bd718x7-regulator.c

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

File Facts

System
Linux kernel
Corpus path
drivers/regulator/bd718x7-regulator.c
Extension
.c
Size
54840 bytes
Lines
1840
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 reg_init {
	unsigned int reg;
	unsigned int mask;
	unsigned int val;
};
struct bd718xx_regulator_data {
	struct regulator_desc desc;
	const struct rohm_dvs_config dvs;
	const struct reg_init init;
	const struct reg_init *additional_inits;
	int additional_init_amnt;
};

static int bd718x7_xvp_sanity_check(struct regulator_dev *rdev, int lim_uV,
				    int severity)
{
	/*
	 * BD71837/47/50 ... (ICs supported by this driver) do not provide
	 * warnings, only protection
	 */
	if (severity != REGULATOR_SEVERITY_PROT) {
		dev_err(&rdev->dev,
			"Unsupported Under Voltage protection level\n");
		return -EINVAL;
	}

	/*
	 * And protection limit is not changeable. It can only be enabled
	 * or disabled
	 */
	if (lim_uV)
		return -EINVAL;

	return 0;
}

static int bd718x7_set_ldo_uvp(struct regulator_dev *rdev, int lim_uV,
			       int severity, bool enable)
{
	int ldo_offset = rdev->desc->id - BD718XX_LDO1;
	int prot_bit, ret;

	ret = bd718x7_xvp_sanity_check(rdev, lim_uV, severity);
	if (ret)
		return ret;

	prot_bit = BD718XX_LDO1_VRMON80 << ldo_offset;

	if (enable)
		return regmap_clear_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
					 prot_bit);

	return regmap_set_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2,
			       prot_bit);
}

static int bd718x7_get_buck_prot_reg(int id, int *reg)
{

	if (id > BD718XX_BUCK8) {
		WARN_ON(id > BD718XX_BUCK8);
		return -EINVAL;
	}

	if (id > BD718XX_BUCK4)
		*reg = BD718XX_REG_MVRFLTMASK0;
	else
		*reg = BD718XX_REG_MVRFLTMASK1;

	return 0;
}

static int bd718x7_get_buck_ovp_info(int id, int *reg, int *bit)
{
	int ret;

	ret = bd718x7_get_buck_prot_reg(id, reg);
	if (ret)
		return ret;

	*bit = BIT((id % 4) * 2 + 1);

	return 0;
}

static int bd718x7_get_buck_uvp_info(int id, int *reg, int *bit)
{
	int ret;

	ret = bd718x7_get_buck_prot_reg(id, reg);

Annotation

Implementation Notes