diff options
author | Krzysztof Kozlowski <k.kozlowski@samsung.com> | 2014-10-27 08:11:48 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2014-10-28 18:31:59 -0400 |
commit | 68c5d1868bfed0643eb4d2c608cead41f6bf4132 (patch) | |
tree | 0ac495989823cccb57cf56e7de4ef632ee5aea4d | |
parent | 7636f19c26a9c4174a139ded0d5216ea5d40b830 (diff) |
regulator: max77686: Store opmode non-shifted
Introduce simple helper for calculating the shift for OPMODE field in
registers. This allows storing the current value of opmode in
non-shifted form and simplifies a little set_suspend_disable and enable
functions. Additionally this will allow adding support LDOs to the
existing set_suspend_disable function.
Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
Suggested-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Reviewed-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/regulator/max77686.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/drivers/regulator/max77686.c b/drivers/regulator/max77686.c index db01c09e98f5..0c1541754e8c 100644 --- a/drivers/regulator/max77686.c +++ b/drivers/regulator/max77686.c | |||
@@ -85,20 +85,32 @@ struct max77686_data { | |||
85 | unsigned int opmode[MAX77686_REGULATORS]; | 85 | unsigned int opmode[MAX77686_REGULATORS]; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | static unsigned int max77686_get_opmode_shift(int id) | ||
89 | { | ||
90 | switch (id) { | ||
91 | case MAX77686_BUCK1: | ||
92 | case MAX77686_BUCK5 ... MAX77686_BUCK9: | ||
93 | return 0; | ||
94 | case MAX77686_BUCK2 ... MAX77686_BUCK4: | ||
95 | return MAX77686_OPMODE_BUCK234_SHIFT; | ||
96 | default: | ||
97 | /* all LDOs */ | ||
98 | return MAX77686_OPMODE_SHIFT; | ||
99 | } | ||
100 | } | ||
101 | |||
88 | /* Some BUCKS supports Normal[ON/OFF] mode during suspend */ | 102 | /* Some BUCKS supports Normal[ON/OFF] mode during suspend */ |
89 | static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev) | 103 | static int max77686_buck_set_suspend_disable(struct regulator_dev *rdev) |
90 | { | 104 | { |
91 | unsigned int val; | 105 | unsigned int val, shift; |
92 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); | 106 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
93 | int ret, id = rdev_get_id(rdev); | 107 | int ret, id = rdev_get_id(rdev); |
94 | 108 | ||
95 | if (id == MAX77686_BUCK1) | 109 | shift = max77686_get_opmode_shift(id); |
96 | val = MAX77686_OFF_PWRREQ; | 110 | val = MAX77686_OFF_PWRREQ; |
97 | else | ||
98 | val = MAX77686_OFF_PWRREQ << MAX77686_OPMODE_BUCK234_SHIFT; | ||
99 | 111 | ||
100 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | 112 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
101 | rdev->desc->enable_mask, val); | 113 | rdev->desc->enable_mask, val << shift); |
102 | if (ret) | 114 | if (ret) |
103 | return ret; | 115 | return ret; |
104 | 116 | ||
@@ -120,10 +132,10 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev, | |||
120 | 132 | ||
121 | switch (mode) { | 133 | switch (mode) { |
122 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ | 134 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ |
123 | val = MAX77686_LDO_LOWPOWER_PWRREQ << MAX77686_OPMODE_SHIFT; | 135 | val = MAX77686_LDO_LOWPOWER_PWRREQ; |
124 | break; | 136 | break; |
125 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ | 137 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ |
126 | val = MAX77686_NORMAL << MAX77686_OPMODE_SHIFT; | 138 | val = MAX77686_NORMAL; |
127 | break; | 139 | break; |
128 | default: | 140 | default: |
129 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", | 141 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", |
@@ -132,7 +144,8 @@ static int max77686_set_suspend_mode(struct regulator_dev *rdev, | |||
132 | } | 144 | } |
133 | 145 | ||
134 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | 146 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
135 | rdev->desc->enable_mask, val); | 147 | rdev->desc->enable_mask, |
148 | val << MAX77686_OPMODE_SHIFT); | ||
136 | if (ret) | 149 | if (ret) |
137 | return ret; | 150 | return ret; |
138 | 151 | ||
@@ -150,13 +163,13 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, | |||
150 | 163 | ||
151 | switch (mode) { | 164 | switch (mode) { |
152 | case REGULATOR_MODE_STANDBY: /* switch off */ | 165 | case REGULATOR_MODE_STANDBY: /* switch off */ |
153 | val = MAX77686_OFF_PWRREQ << MAX77686_OPMODE_SHIFT; | 166 | val = MAX77686_OFF_PWRREQ; |
154 | break; | 167 | break; |
155 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ | 168 | case REGULATOR_MODE_IDLE: /* ON in LP Mode */ |
156 | val = MAX77686_LDO_LOWPOWER_PWRREQ << MAX77686_OPMODE_SHIFT; | 169 | val = MAX77686_LDO_LOWPOWER_PWRREQ; |
157 | break; | 170 | break; |
158 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ | 171 | case REGULATOR_MODE_NORMAL: /* ON in Normal Mode */ |
159 | val = MAX77686_NORMAL << MAX77686_OPMODE_SHIFT; | 172 | val = MAX77686_NORMAL; |
160 | break; | 173 | break; |
161 | default: | 174 | default: |
162 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", | 175 | pr_warn("%s: regulator_suspend_mode : 0x%x not supported\n", |
@@ -165,7 +178,8 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, | |||
165 | } | 178 | } |
166 | 179 | ||
167 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | 180 | ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
168 | rdev->desc->enable_mask, val); | 181 | rdev->desc->enable_mask, |
182 | val << MAX77686_OPMODE_SHIFT); | ||
169 | if (ret) | 183 | if (ret) |
170 | return ret; | 184 | return ret; |
171 | 185 | ||
@@ -176,10 +190,14 @@ static int max77686_ldo_set_suspend_mode(struct regulator_dev *rdev, | |||
176 | static int max77686_enable(struct regulator_dev *rdev) | 190 | static int max77686_enable(struct regulator_dev *rdev) |
177 | { | 191 | { |
178 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); | 192 | struct max77686_data *max77686 = rdev_get_drvdata(rdev); |
193 | unsigned int shift; | ||
194 | int id = rdev_get_id(rdev); | ||
195 | |||
196 | shift = max77686_get_opmode_shift(id); | ||
179 | 197 | ||
180 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | 198 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
181 | rdev->desc->enable_mask, | 199 | rdev->desc->enable_mask, |
182 | max77686->opmode[rdev_get_id(rdev)]); | 200 | max77686->opmode[id] << shift); |
183 | } | 201 | } |
184 | 202 | ||
185 | static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) | 203 | static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
@@ -495,7 +513,8 @@ static int max77686_pmic_probe(struct platform_device *pdev) | |||
495 | config.init_data = pdata->regulators[i].initdata; | 513 | config.init_data = pdata->regulators[i].initdata; |
496 | config.of_node = pdata->regulators[i].of_node; | 514 | config.of_node = pdata->regulators[i].of_node; |
497 | 515 | ||
498 | max77686->opmode[i] = regulators[i].enable_mask; | 516 | max77686->opmode[i] = regulators[i].enable_mask >> |
517 | max77686_get_opmode_shift(i); | ||
499 | rdev = devm_regulator_register(&pdev->dev, | 518 | rdev = devm_regulator_register(&pdev->dev, |
500 | ®ulators[i], &config); | 519 | ®ulators[i], &config); |
501 | if (IS_ERR(rdev)) { | 520 | if (IS_ERR(rdev)) { |