aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/da903x.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-05-14 22:06:27 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-05-15 13:32:57 -0400
commitc972a029483ac5a546a6405e30e4eede6fbd19f9 (patch)
treec0cd758984c1a84bbc07f8ad99d5935879e1bd0a /drivers/regulator/da903x.c
parent70b4e7862d604aa6ae30a772830670bf7288ec42 (diff)
regulator: da903x: Convert to set_voltage_sel and map_voltage
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/da903x.c')
-rw-r--r--drivers/regulator/da903x.c110
1 files changed, 54 insertions, 56 deletions
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index 3a0d0800374e..6e78ef1667fb 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -101,21 +101,14 @@ static inline int check_range(struct da903x_regulator_info *info,
101} 101}
102 102
103/* DA9030/DA9034 common operations */ 103/* DA9030/DA9034 common operations */
104static int da903x_set_ldo_voltage(struct regulator_dev *rdev, 104static int da903x_set_ldo_voltage_sel(struct regulator_dev *rdev,
105 int min_uV, int max_uV, unsigned *selector) 105 unsigned selector)
106{ 106{
107 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 107 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
108 struct device *da9034_dev = to_da903x_dev(rdev); 108 struct device *da9034_dev = to_da903x_dev(rdev);
109 uint8_t val, mask; 109 uint8_t val, mask;
110 110
111 if (check_range(info, min_uV, max_uV)) { 111 val = selector << info->vol_shift;
112 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
113 return -EINVAL;
114 }
115
116 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
117 *selector = val;
118 val <<= info->vol_shift;
119 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 112 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
120 113
121 return da903x_update(da9034_dev, info->vol_reg, val, mask); 114 return da903x_update(da9034_dev, info->vol_reg, val, mask);
@@ -171,23 +164,15 @@ static int da903x_is_enabled(struct regulator_dev *rdev)
171} 164}
172 165
173/* DA9030 specific operations */ 166/* DA9030 specific operations */
174static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev, 167static int da9030_set_ldo1_15_voltage_sel(struct regulator_dev *rdev,
175 int min_uV, int max_uV, 168 unsigned selector)
176 unsigned *selector)
177{ 169{
178 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 170 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
179 struct device *da903x_dev = to_da903x_dev(rdev); 171 struct device *da903x_dev = to_da903x_dev(rdev);
180 uint8_t val, mask; 172 uint8_t val, mask;
181 int ret; 173 int ret;
182 174
183 if (check_range(info, min_uV, max_uV)) { 175 val = selector << info->vol_shift;
184 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
185 return -EINVAL;
186 }
187
188 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
189 *selector = val;
190 val <<= info->vol_shift;
191 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 176 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
192 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */ 177 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
193 mask |= DA9030_LDO_UNLOCK_MASK; 178 mask |= DA9030_LDO_UNLOCK_MASK;
@@ -200,14 +185,24 @@ static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
200 return da903x_update(da903x_dev, info->vol_reg, val, mask); 185 return da903x_update(da903x_dev, info->vol_reg, val, mask);
201} 186}
202 187
203static int da9030_set_ldo14_voltage(struct regulator_dev *rdev, 188static int da9030_set_ldo14_voltage_sel(struct regulator_dev *rdev,
204 int min_uV, int max_uV, 189 unsigned selector)
205 unsigned *selector)
206{ 190{
207 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 191 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
208 struct device *da903x_dev = to_da903x_dev(rdev); 192 struct device *da903x_dev = to_da903x_dev(rdev);
209 uint8_t val, mask; 193 uint8_t val, mask;
210 int thresh; 194
195 val = selector << info->vol_shift;
196 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
197
198 return da903x_update(da903x_dev, info->vol_reg, val, mask);
199}
200
201static int da9030_map_ldo14_voltage(struct regulator_dev *rdev,
202 int min_uV, int max_uV)
203{
204 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
205 int thresh, sel;
211 206
212 if (check_range(info, min_uV, max_uV)) { 207 if (check_range(info, min_uV, max_uV)) {
213 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); 208 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
@@ -216,17 +211,13 @@ static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
216 211
217 thresh = (info->max_uV + info->desc.min_uV) / 2; 212 thresh = (info->max_uV + info->desc.min_uV) / 2;
218 if (min_uV < thresh) { 213 if (min_uV < thresh) {
219 val = DIV_ROUND_UP(thresh - min_uV, info->desc.uV_step); 214 sel = DIV_ROUND_UP(thresh - min_uV, info->desc.uV_step);
220 val |= 0x4; 215 sel |= 0x4;
221 } else { 216 } else {
222 val = DIV_ROUND_UP(min_uV - thresh, info->desc.uV_step); 217 sel = DIV_ROUND_UP(min_uV - thresh, info->desc.uV_step);
223 } 218 }
224 219
225 *selector = val; 220 return sel;
226 val <<= info->vol_shift;
227 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
228
229 return da903x_update(da903x_dev, info->vol_reg, val, mask);
230} 221}
231 222
232static int da9030_get_ldo14_voltage_sel(struct regulator_dev *rdev) 223static int da9030_get_ldo14_voltage_sel(struct regulator_dev *rdev)
@@ -266,22 +257,15 @@ static int da9030_list_ldo14_voltage(struct regulator_dev *rdev,
266} 257}
267 258
268/* DA9034 specific operations */ 259/* DA9034 specific operations */
269static int da9034_set_dvc_voltage(struct regulator_dev *rdev, 260static int da9034_set_dvc_voltage_sel(struct regulator_dev *rdev,
270 int min_uV, int max_uV, unsigned *selector) 261 unsigned selector)
271{ 262{
272 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 263 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
273 struct device *da9034_dev = to_da903x_dev(rdev); 264 struct device *da9034_dev = to_da903x_dev(rdev);
274 uint8_t val, mask; 265 uint8_t val, mask;
275 int ret; 266 int ret;
276 267
277 if (check_range(info, min_uV, max_uV)) { 268 val = selector << info->vol_shift;
278 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
279 return -EINVAL;
280 }
281
282 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
283 *selector = val;
284 val <<= info->vol_shift;
285 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 269 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
286 270
287 ret = da903x_update(da9034_dev, info->vol_reg, val, mask); 271 ret = da903x_update(da9034_dev, info->vol_reg, val, mask);
@@ -293,25 +277,34 @@ static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
293 return ret; 277 return ret;
294} 278}
295 279
296static int da9034_set_ldo12_voltage(struct regulator_dev *rdev, 280static int da9034_set_ldo12_voltage_sel(struct regulator_dev *rdev,
297 int min_uV, int max_uV, unsigned *selector) 281 unsigned selector)
298{ 282{
299 struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 283 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
300 struct device *da9034_dev = to_da903x_dev(rdev); 284 struct device *da9034_dev = to_da903x_dev(rdev);
301 uint8_t val, mask; 285 uint8_t val, mask;
302 286
287 val = selector << info->vol_shift;
288 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
289
290 return da903x_update(da9034_dev, info->vol_reg, val, mask);
291}
292
293static int da9034_map_ldo12_voltage(struct regulator_dev *rdev,
294 int min_uV, int max_uV)
295{
296 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
297 int sel;
298
303 if (check_range(info, min_uV, max_uV)) { 299 if (check_range(info, min_uV, max_uV)) {
304 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV); 300 pr_err("invalid voltage range (%d, %d) uV\n", min_uV, max_uV);
305 return -EINVAL; 301 return -EINVAL;
306 } 302 }
307 303
308 val = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step); 304 sel = DIV_ROUND_UP(min_uV - info->desc.min_uV, info->desc.uV_step);
309 val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); 305 sel = (sel >= 20) ? sel - 12 : ((sel > 7) ? 8 : sel);
310 *selector = val;
311 val <<= info->vol_shift;
312 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
313 306
314 return da903x_update(da9034_dev, info->vol_reg, val, mask); 307 return sel;
315} 308}
316 309
317static int da9034_get_ldo12_voltage_sel(struct regulator_dev *rdev) 310static int da9034_get_ldo12_voltage_sel(struct regulator_dev *rdev)
@@ -349,9 +342,10 @@ static int da9034_list_ldo12_voltage(struct regulator_dev *rdev,
349} 342}
350 343
351static struct regulator_ops da903x_regulator_ldo_ops = { 344static struct regulator_ops da903x_regulator_ldo_ops = {
352 .set_voltage = da903x_set_ldo_voltage, 345 .set_voltage_sel = da903x_set_ldo_voltage_sel,
353 .get_voltage_sel = da903x_get_voltage_sel, 346 .get_voltage_sel = da903x_get_voltage_sel,
354 .list_voltage = regulator_list_voltage_linear, 347 .list_voltage = regulator_list_voltage_linear,
348 .map_voltage = regulator_map_voltage_linear,
355 .enable = da903x_enable, 349 .enable = da903x_enable,
356 .disable = da903x_disable, 350 .disable = da903x_disable,
357 .is_enabled = da903x_is_enabled, 351 .is_enabled = da903x_is_enabled,
@@ -359,9 +353,10 @@ static struct regulator_ops da903x_regulator_ldo_ops = {
359 353
360/* NOTE: this is dedicated for the insane DA9030 LDO14 */ 354/* NOTE: this is dedicated for the insane DA9030 LDO14 */
361static struct regulator_ops da9030_regulator_ldo14_ops = { 355static struct regulator_ops da9030_regulator_ldo14_ops = {
362 .set_voltage = da9030_set_ldo14_voltage, 356 .set_voltage_sel = da9030_set_ldo14_voltage_sel,
363 .get_voltage_sel = da9030_get_ldo14_voltage_sel, 357 .get_voltage_sel = da9030_get_ldo14_voltage_sel,
364 .list_voltage = da9030_list_ldo14_voltage, 358 .list_voltage = da9030_list_ldo14_voltage,
359 .map_voltage = da9030_map_ldo14_voltage,
365 .enable = da903x_enable, 360 .enable = da903x_enable,
366 .disable = da903x_disable, 361 .disable = da903x_disable,
367 .is_enabled = da903x_is_enabled, 362 .is_enabled = da903x_is_enabled,
@@ -369,18 +364,20 @@ static struct regulator_ops da9030_regulator_ldo14_ops = {
369 364
370/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */ 365/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */
371static struct regulator_ops da9030_regulator_ldo1_15_ops = { 366static struct regulator_ops da9030_regulator_ldo1_15_ops = {
372 .set_voltage = da9030_set_ldo1_15_voltage, 367 .set_voltage_sel = da9030_set_ldo1_15_voltage_sel,
373 .get_voltage_sel = da903x_get_voltage_sel, 368 .get_voltage_sel = da903x_get_voltage_sel,
374 .list_voltage = regulator_list_voltage_linear, 369 .list_voltage = regulator_list_voltage_linear,
370 .map_voltage = regulator_map_voltage_linear,
375 .enable = da903x_enable, 371 .enable = da903x_enable,
376 .disable = da903x_disable, 372 .disable = da903x_disable,
377 .is_enabled = da903x_is_enabled, 373 .is_enabled = da903x_is_enabled,
378}; 374};
379 375
380static struct regulator_ops da9034_regulator_dvc_ops = { 376static struct regulator_ops da9034_regulator_dvc_ops = {
381 .set_voltage = da9034_set_dvc_voltage, 377 .set_voltage_sel = da9034_set_dvc_voltage_sel,
382 .get_voltage_sel = da903x_get_voltage_sel, 378 .get_voltage_sel = da903x_get_voltage_sel,
383 .list_voltage = regulator_list_voltage_linear, 379 .list_voltage = regulator_list_voltage_linear,
380 .map_voltage = regulator_map_voltage_linear,
384 .enable = da903x_enable, 381 .enable = da903x_enable,
385 .disable = da903x_disable, 382 .disable = da903x_disable,
386 .is_enabled = da903x_is_enabled, 383 .is_enabled = da903x_is_enabled,
@@ -388,9 +385,10 @@ static struct regulator_ops da9034_regulator_dvc_ops = {
388 385
389/* NOTE: this is dedicated for the insane LDO12 */ 386/* NOTE: this is dedicated for the insane LDO12 */
390static struct regulator_ops da9034_regulator_ldo12_ops = { 387static struct regulator_ops da9034_regulator_ldo12_ops = {
391 .set_voltage = da9034_set_ldo12_voltage, 388 .set_voltage_sel = da9034_set_ldo12_voltage_sel,
392 .get_voltage_sel = da9034_get_ldo12_voltage_sel, 389 .get_voltage_sel = da9034_get_ldo12_voltage_sel,
393 .list_voltage = da9034_list_ldo12_voltage, 390 .list_voltage = da9034_list_ldo12_voltage,
391 .map_voltage = da9034_map_ldo12_voltage,
394 .enable = da903x_enable, 392 .enable = da903x_enable,
395 .disable = da903x_disable, 393 .disable = da903x_disable,
396 .is_enabled = da903x_is_enabled, 394 .is_enabled = da903x_is_enabled,