drivers/regulator/mt6370-regulator.c

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

File Facts

System
Linux kernel
Corpus path
drivers/regulator/mt6370-regulator.c
Extension
.c
Size
11185 bytes
Lines
392
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 mt6370_priv {
	struct device *dev;
	struct regmap *regmap;
	struct regulator_dev *rdev[MT6370_MAX_IDX];
	bool use_external_ctrl;
};

static const unsigned int mt6370_vpos_ramp_tbl[] = { 8540, 5840, 4830, 3000 };
static const unsigned int mt6370_vneg_ramp_tbl[] = { 10090, 6310, 5050, 3150 };

static int mt6370_get_error_flags(struct regulator_dev *rdev,
				  unsigned int *flags)
{
	struct regmap *regmap = rdev_get_regmap(rdev);
	unsigned int stat_reg, stat, rpt_flags = 0;
	int rid = rdev_get_id(rdev), ret;

	if (rid == MT6370_IDX_VIBLDO)
		stat_reg = MT6370_REG_LDO_STAT;
	else
		stat_reg = MT6370_REG_DB_STAT;

	ret = regmap_read(regmap, stat_reg, &stat);
	if (ret)
		return ret;

	switch (rid) {
	case MT6370_IDX_DSVBOOST:
		if (stat & MT6370_BSTOCP_EVT_MASK)
			rpt_flags |= REGULATOR_ERROR_OVER_CURRENT;
		break;
	case MT6370_IDX_DSVPOS:
		if (stat & MT6370_POSSCP_EVT_MASK)
			rpt_flags |= REGULATOR_ERROR_UNDER_VOLTAGE;

		if (stat & MT6370_POSOCP_EVT_MASK)
			rpt_flags |= REGULATOR_ERROR_OVER_CURRENT;
		break;
	case MT6370_IDX_DSVNEG:
		if (stat & MT6370_NEGSCP_EVT_MASK)
			rpt_flags |= REGULATOR_ERROR_UNDER_VOLTAGE;

		if (stat & MT6370_NEGOCP_EVT_MASK)
			rpt_flags |= REGULATOR_ERROR_OVER_CURRENT;
		break;
	default:
		if (stat & MT6370_LDOOC_EVT_MASK)
			rpt_flags |= REGULATOR_ERROR_OVER_CURRENT;
		break;
	}

	*flags = rpt_flags;
	return 0;
}

static const struct regulator_ops mt6370_dbvboost_ops = {
	.get_voltage_sel = regulator_get_voltage_sel_regmap,
	.set_voltage_sel = regulator_set_voltage_sel_regmap,
	.list_voltage = regulator_list_voltage_linear,
	.get_bypass = regulator_get_bypass_regmap,
	.set_bypass = regulator_set_bypass_regmap,
	.get_error_flags = mt6370_get_error_flags,
};

static const struct regulator_ops mt6370_dbvout_ops = {
	.get_voltage_sel = regulator_get_voltage_sel_regmap,
	.set_voltage_sel = regulator_set_voltage_sel_regmap,
	.list_voltage = regulator_list_voltage_linear,
	.is_enabled = regulator_is_enabled_regmap,
	.enable = regulator_enable_regmap,
	.disable = regulator_disable_regmap,
	.set_active_discharge = regulator_set_active_discharge_regmap,
	.set_ramp_delay = regulator_set_ramp_delay_regmap,
	.get_error_flags = mt6370_get_error_flags,
};

static const struct regulator_ops mt6370_ldo_ops = {
	.get_voltage_sel = regulator_get_voltage_sel_regmap,
	.set_voltage_sel = regulator_set_voltage_sel_regmap,
	.list_voltage = regulator_list_voltage_linear,
	.is_enabled = regulator_is_enabled_regmap,
	.enable = regulator_enable_regmap,
	.disable = regulator_disable_regmap,
	.set_active_discharge = regulator_set_active_discharge_regmap,
	.get_error_flags = mt6370_get_error_flags,
};

static int mt6370_of_parse_cb(struct device_node *np,
			      const struct regulator_desc *desc,
			      struct regulator_config *config)

Annotation

Implementation Notes