Skip to content

Commit cd6dffb

Browse files
committed
regulator: core: Provide standard enable operations for regmap users
Since the enable(), disable() and is_enabled() operations for most regmap based regulators come down to reading and updating a single register bit we can factor out the code and allow these drivers to just define which bit to update using the enable_reg and enable_mask fields in their desc and then use operations provided by the core. As well as the code saving this opens the door to future optimisation of the bulk operations - if the core can realise that we are updating a single register for multiple regulators then it should be able to combine these updates into a single physical operation. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@ti.com>
1 parent 633b6fc commit cd6dffb

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

‎drivers/regulator/core.c‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,61 @@ int regulator_disable_deferred(struct regulator *regulator, int ms)
17251725
}
17261726
EXPORT_SYMBOL_GPL(regulator_disable_deferred);
17271727

1728+
/**
1729+
* regulator_is_enabled_regmap - standard is_enabled() for regmap users
1730+
*
1731+
* @rdev: regulator to operate on
1732+
*
1733+
* Regulators that use regmap for their register I/O can set the
1734+
* enable_reg and enable_mask fields in their descriptor and then use
1735+
* this as their is_enabled operation, saving some code.
1736+
*/
1737+
int regulator_is_enabled_regmap(struct regulator_dev *rdev)
1738+
{
1739+
unsigned int val;
1740+
int ret;
1741+
1742+
ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
1743+
if (ret != 0)
1744+
return ret;
1745+
1746+
return (val & rdev->desc->enable_mask) != 0;
1747+
}
1748+
EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
1749+
1750+
/**
1751+
* regulator_enable_regmap - standard enable() for regmap users
1752+
*
1753+
* @rdev: regulator to operate on
1754+
*
1755+
* Regulators that use regmap for their register I/O can set the
1756+
* enable_reg and enable_mask fields in their descriptor and then use
1757+
* this as their enable() operation, saving some code.
1758+
*/
1759+
int regulator_enable_regmap(struct regulator_dev *rdev)
1760+
{
1761+
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
1762+
rdev->desc->enable_mask,
1763+
rdev->desc->enable_mask);
1764+
}
1765+
EXPORT_SYMBOL_GPL(regulator_enable_regmap);
1766+
1767+
/**
1768+
* regulator_disable_regmap - standard disable() for regmap users
1769+
*
1770+
* @rdev: regulator to operate on
1771+
*
1772+
* Regulators that use regmap for their register I/O can set the
1773+
* enable_reg and enable_mask fields in their descriptor and then use
1774+
* this as their disable() operation, saving some code.
1775+
*/
1776+
int regulator_disable_regmap(struct regulator_dev *rdev)
1777+
{
1778+
return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
1779+
rdev->desc->enable_mask, 0);
1780+
}
1781+
EXPORT_SYMBOL_GPL(regulator_disable_regmap);
1782+
17281783
static int _regulator_is_enabled(struct regulator_dev *rdev)
17291784
{
17301785
/* If we don't know then assume that the regulator is always on */

‎include/linux/regulator/driver.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ enum regulator_type {
167167
168168
* @vsel_reg: Register for selector when using regulator_regmap_X_voltage_
169169
* @vsel_mask: Mask for register bitfield used for selector
170+
* @enable_reg: Register for control when using regmap enable/disable ops
171+
* @enable_mask: Mask for control when using regmap enable/disable ops
170172
*/
171173
struct regulator_desc {
172174
const char *name;
@@ -180,6 +182,8 @@ struct regulator_desc {
180182

181183
unsigned int vsel_reg;
182184
unsigned int vsel_mask;
185+
unsigned int enable_reg;
186+
unsigned int enable_mask;
183187
};
184188

185189
/**
@@ -258,6 +262,9 @@ int regulator_mode_to_status(unsigned int);
258262

259263
int regulator_get_voltage_sel_regmap(struct regulator_dev *rdev);
260264
int regulator_set_voltage_sel_regmap(struct regulator_dev *rdev, unsigned sel);
265+
int regulator_is_enabled_regmap(struct regulator_dev *rdev);
266+
int regulator_enable_regmap(struct regulator_dev *rdev);
267+
int regulator_disable_regmap(struct regulator_dev *rdev);
261268

262269
void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
263270

0 commit comments

Comments
 (0)