Skip to content

Commit

Permalink
regulator: helpers: Modify helpers enabling multi-bit control
Browse files Browse the repository at this point in the history
This patch extends the regulator helpers to account for device that use
multiple bits for control when using regmap enable/disable/bypass ops.

The actual regulator helpers wrongly assume that the regulator control
is always performed using single bits, using in the regulator_desc
struct only two parameters *_reg and *_mask defining register and mask
for control.

This patch extends this struct and introduces the helpers to take into
account devices where control is performed using multiple bits and
specific multi-bit values are used for enabling/disabling/bypassing the
regulator.

Signed-off-by: Carlo Caione <carlo@caione.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Carlo Caione authored and Mark Brown committed Mar 6, 2014
1 parent 38dbfb5 commit ca5d1b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
48 changes: 32 additions & 16 deletions drivers/regulator/helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ int regulator_is_enabled_regmap(struct regulator_dev *rdev)
if (ret != 0)
return ret;

if (rdev->desc->enable_is_inverted)
return (val & rdev->desc->enable_mask) == 0;
else
return (val & rdev->desc->enable_mask) != 0;
val &= rdev->desc->enable_mask;

if (rdev->desc->enable_is_inverted) {
if (rdev->desc->enable_val)
return val != rdev->desc->enable_val;
return val == 0;
} else {
if (rdev->desc->enable_val)
return val == rdev->desc->enable_val;
return val != 0;
}
}
EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);

Expand All @@ -57,10 +64,13 @@ int regulator_enable_regmap(struct regulator_dev *rdev)
{
unsigned int val;

if (rdev->desc->enable_is_inverted)
val = 0;
else
val = rdev->desc->enable_mask;
if (rdev->desc->enable_is_inverted) {
val = rdev->desc->disable_val;
} else {
val = rdev->desc->enable_val;
if (!val)
val = rdev->desc->enable_mask;
}

return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, val);
Expand All @@ -80,10 +90,13 @@ int regulator_disable_regmap(struct regulator_dev *rdev)
{
unsigned int val;

if (rdev->desc->enable_is_inverted)
val = rdev->desc->enable_mask;
else
val = 0;
if (rdev->desc->enable_is_inverted) {
val = rdev->desc->enable_val;
if (!val)
val = rdev->desc->enable_mask;
} else {
val = rdev->desc->disable_val;
}

return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
rdev->desc->enable_mask, val);
Expand Down Expand Up @@ -419,10 +432,13 @@ int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable)
{
unsigned int val;

if (enable)
val = rdev->desc->bypass_mask;
else
val = 0;
if (enable) {
val = rdev->desc->bypass_val_on;
if (!val)
val = rdev->desc->bypass_mask;
} else {
val = rdev->desc->bypass_val_off;
}

return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg,
rdev->desc->bypass_mask, val);
Expand Down
8 changes: 8 additions & 0 deletions include/linux/regulator/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ enum regulator_type {
* output when using regulator_set_voltage_sel_regmap
* @enable_reg: Register for control when using regmap enable/disable ops
* @enable_mask: Mask for control when using regmap enable/disable ops
* @enable_val: Enabling value for control when using regmap enable/disable ops
* @disable_val: Disabling value for control when using regmap enable/disable ops
* @enable_is_inverted: A flag to indicate set enable_mask bits to disable
* when using regulator_enable_regmap and friends APIs.
* @bypass_reg: Register for control when using regmap set_bypass
* @bypass_mask: Mask for control when using regmap set_bypass
* @bypass_val_on: Enabling value for control when using regmap set_bypass
* @bypass_val_off: Disabling value for control when using regmap set_bypass
*
* @enable_time: Time taken for initial enable of regulator (in uS).
*/
Expand Down Expand Up @@ -263,9 +267,13 @@ struct regulator_desc {
unsigned int apply_bit;
unsigned int enable_reg;
unsigned int enable_mask;
unsigned int enable_val;
unsigned int disable_val;
bool enable_is_inverted;
unsigned int bypass_reg;
unsigned int bypass_mask;
unsigned int bypass_val_on;
unsigned int bypass_val_off;

unsigned int enable_time;
};
Expand Down

0 comments on commit ca5d1b3

Please sign in to comment.