drivers/regulator/rt6245-regulator.c

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

File Facts

System
Linux kernel
Corpus path
drivers/regulator/rt6245-regulator.c
Extension
.c
Size
6879 bytes
Lines
256
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 rt6245_priv {
	struct gpio_desc *enable_gpio;
	bool enable_state;
};

static int rt6245_enable(struct regulator_dev *rdev)
{
	struct rt6245_priv *priv = rdev_get_drvdata(rdev);
	struct regmap *regmap = rdev_get_regmap(rdev);
	int ret;

	if (!priv->enable_gpio)
		return 0;

	gpiod_direction_output(priv->enable_gpio, 1);
	usleep_range(RT6245_ENTIME_IN_US, RT6245_ENTIME_IN_US + 1000);

	regcache_cache_only(regmap, false);
	ret = regcache_sync(regmap);
	if (ret)
		return ret;

	priv->enable_state = true;
	return 0;
}

static int rt6245_disable(struct regulator_dev *rdev)
{
	struct rt6245_priv *priv = rdev_get_drvdata(rdev);
	struct regmap *regmap = rdev_get_regmap(rdev);

	if (!priv->enable_gpio)
		return -EINVAL;

	regcache_cache_only(regmap, true);
	regcache_mark_dirty(regmap);

	gpiod_direction_output(priv->enable_gpio, 0);

	priv->enable_state = false;
	return 0;
}

static int rt6245_is_enabled(struct regulator_dev *rdev)
{
	struct rt6245_priv *priv = rdev_get_drvdata(rdev);

	return priv->enable_state ? 1 : 0;
}

static const struct regulator_ops rt6245_regulator_ops = {
	.list_voltage = regulator_list_voltage_linear,
	.set_voltage_sel = regulator_set_voltage_sel_regmap,
	.get_voltage_sel = regulator_get_voltage_sel_regmap,
	.set_ramp_delay = regulator_set_ramp_delay_regmap,
	.enable = rt6245_enable,
	.disable = rt6245_disable,
	.is_enabled = rt6245_is_enabled,
};

/* ramp delay dividend is 12500 uV/uS, and divisor from 1 to 8 */
static const unsigned int rt6245_ramp_delay_table[] = {
	12500, 6250, 4167, 3125, 2500, 2083, 1786, 1562
};

static const struct regulator_desc rt6245_regulator_desc = {
	.name = "rt6245-regulator",
	.ops = &rt6245_regulator_ops,
	.type = REGULATOR_VOLTAGE,
	.min_uV = RT6245_VOUT_MINUV,
	.uV_step = RT6245_VOUT_STEPUV,
	.n_voltages = RT6245_NUM_VOUT,
	.ramp_delay_table = rt6245_ramp_delay_table,
	.n_ramp_values = ARRAY_SIZE(rt6245_ramp_delay_table),
	.owner = THIS_MODULE,
	.vsel_reg = RT6245_VIRT_VOUT,
	.vsel_mask = RT6245_VOUT_MASK,
	.ramp_reg = RT6245_VIRT_SLEWRATE,
	.ramp_mask = RT6245_SLEW_MASK,
};

static int rt6245_init_device_properties(struct device *dev)
{
	const struct {
		const char *name;
		unsigned int reg;
	} rt6245_props[] = {
		{ "richtek,oc-level-select",  RT6245_VIRT_OCLIMIT },
		{ "richtek,ot-level-select", RT6245_VIRT_OTLEVEL },
		{ "richtek,pgdly-time-select", RT6245_VIRT_PGDLYTIME },

Annotation

Implementation Notes