aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/helpers.c
diff options
context:
space:
mode:
authorCarlo Caione <carlo@caione.org>2014-03-05 16:11:29 -0500
committerMark Brown <broonie@linaro.org>2014-03-06 04:30:10 -0500
commitca5d1b3524b4d90a2e2f1f71583c1dca6b96fd92 (patch)
treeacf10cbf9247ec8d7f8437faa9ba154a1fb8665e /drivers/regulator/helpers.c
parent38dbfb59d1175ef458d006556061adeaa8751b72 (diff)
regulator: helpers: Modify helpers enabling multi-bit control
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>
Diffstat (limited to 'drivers/regulator/helpers.c')
-rw-r--r--drivers/regulator/helpers.c48
1 files changed, 32 insertions, 16 deletions
diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c
index e221a271ba56..cbc39096c78d 100644
--- a/drivers/regulator/helpers.c
+++ b/drivers/regulator/helpers.c
@@ -37,10 +37,17 @@ int regulator_is_enabled_regmap(struct regulator_dev *rdev)
37 if (ret != 0) 37 if (ret != 0)
38 return ret; 38 return ret;
39 39
40 if (rdev->desc->enable_is_inverted) 40 val &= rdev->desc->enable_mask;
41 return (val & rdev->desc->enable_mask) == 0; 41
42 else 42 if (rdev->desc->enable_is_inverted) {
43 return (val & rdev->desc->enable_mask) != 0; 43 if (rdev->desc->enable_val)
44 return val != rdev->desc->enable_val;
45 return val == 0;
46 } else {
47 if (rdev->desc->enable_val)
48 return val == rdev->desc->enable_val;
49 return val != 0;
50 }
44} 51}
45EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap); 52EXPORT_SYMBOL_GPL(regulator_is_enabled_regmap);
46 53
@@ -57,10 +64,13 @@ int regulator_enable_regmap(struct regulator_dev *rdev)
57{ 64{
58 unsigned int val; 65 unsigned int val;
59 66
60 if (rdev->desc->enable_is_inverted) 67 if (rdev->desc->enable_is_inverted) {
61 val = 0; 68 val = rdev->desc->disable_val;
62 else 69 } else {
63 val = rdev->desc->enable_mask; 70 val = rdev->desc->enable_val;
71 if (!val)
72 val = rdev->desc->enable_mask;
73 }
64 74
65 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 75 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
66 rdev->desc->enable_mask, val); 76 rdev->desc->enable_mask, val);
@@ -80,10 +90,13 @@ int regulator_disable_regmap(struct regulator_dev *rdev)
80{ 90{
81 unsigned int val; 91 unsigned int val;
82 92
83 if (rdev->desc->enable_is_inverted) 93 if (rdev->desc->enable_is_inverted) {
84 val = rdev->desc->enable_mask; 94 val = rdev->desc->enable_val;
85 else 95 if (!val)
86 val = 0; 96 val = rdev->desc->enable_mask;
97 } else {
98 val = rdev->desc->disable_val;
99 }
87 100
88 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 101 return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,
89 rdev->desc->enable_mask, val); 102 rdev->desc->enable_mask, val);
@@ -419,10 +432,13 @@ int regulator_set_bypass_regmap(struct regulator_dev *rdev, bool enable)
419{ 432{
420 unsigned int val; 433 unsigned int val;
421 434
422 if (enable) 435 if (enable) {
423 val = rdev->desc->bypass_mask; 436 val = rdev->desc->bypass_val_on;
424 else 437 if (!val)
425 val = 0; 438 val = rdev->desc->bypass_mask;
439 } else {
440 val = rdev->desc->bypass_val_off;
441 }
426 442
427 return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg, 443 return regmap_update_bits(rdev->regmap, rdev->desc->bypass_reg,
428 rdev->desc->bypass_mask, val); 444 rdev->desc->bypass_mask, val);