aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/max8998.c
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@gmail.com>2012-06-16 21:34:29 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-06-23 07:18:08 -0400
commitbaae019efe84b6d2c6d5e7e7e1c9cfa130ad6b2a (patch)
tree5e39064b91d80a5295a42fe13f93ecd951f15583 /drivers/regulator/max8998.c
parent9a0fbb627cfa86303b8eb57377f536c64812cc85 (diff)
regulator: max8998: Convert to set_voltage_sel and regulator_map_voltage_linear
Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/max8998.c')
-rw-r--r--drivers/regulator/max8998.c97
1 files changed, 27 insertions, 70 deletions
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c
index 105dafca3369..a1fa26613494 100644
--- a/drivers/regulator/max8998.c
+++ b/drivers/regulator/max8998.c
@@ -276,41 +276,18 @@ static int max8998_get_voltage_sel(struct regulator_dev *rdev)
276 return val; 276 return val;
277} 277}
278 278
279static int max8998_set_voltage_ldo(struct regulator_dev *rdev, 279static int max8998_set_voltage_ldo_sel(struct regulator_dev *rdev,
280 int min_uV, int max_uV, unsigned *selector) 280 unsigned selector)
281{ 281{
282 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 282 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
283 struct i2c_client *i2c = max8998->iodev->i2c; 283 struct i2c_client *i2c = max8998->iodev->i2c;
284 int min_vol = min_uV / 1000, max_vol = max_uV / 1000; 284 int reg, shift = 0, mask, ret;
285 const struct voltage_map_desc *desc;
286 int ldo = rdev_get_id(rdev);
287 int reg, shift = 0, mask, ret, i;
288
289 if (ldo >= ARRAY_SIZE(ldo_voltage_map))
290 return -EINVAL;
291
292 desc = ldo_voltage_map[ldo];
293 if (desc == NULL)
294 return -EINVAL;
295
296 if (max_vol < desc->min || min_vol > desc->max)
297 return -EINVAL;
298
299 if (min_vol < desc->min)
300 min_vol = desc->min;
301
302 i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
303
304 if (desc->min + desc->step*i > max_vol)
305 return -EINVAL;
306
307 *selector = i;
308 285
309 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 286 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
310 if (ret) 287 if (ret)
311 return ret; 288 return ret;
312 289
313 ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift); 290 ret = max8998_update_reg(i2c, reg, selector<<shift, mask<<shift);
314 291
315 return ret; 292 return ret;
316} 293}
@@ -326,41 +303,18 @@ static inline void buck2_gpio_set(int gpio, int v)
326 gpio_set_value(gpio, v & 0x1); 303 gpio_set_value(gpio, v & 0x1);
327} 304}
328 305
329static int max8998_set_voltage_buck(struct regulator_dev *rdev, 306static int max8998_set_voltage_buck_sel(struct regulator_dev *rdev,
330 int min_uV, int max_uV, unsigned *selector) 307 unsigned selector)
331{ 308{
332 struct max8998_data *max8998 = rdev_get_drvdata(rdev); 309 struct max8998_data *max8998 = rdev_get_drvdata(rdev);
333 struct max8998_platform_data *pdata = 310 struct max8998_platform_data *pdata =
334 dev_get_platdata(max8998->iodev->dev); 311 dev_get_platdata(max8998->iodev->dev);
335 struct i2c_client *i2c = max8998->iodev->i2c; 312 struct i2c_client *i2c = max8998->iodev->i2c;
336 int min_vol = min_uV / 1000, max_vol = max_uV / 1000;
337 const struct voltage_map_desc *desc;
338 int buck = rdev_get_id(rdev); 313 int buck = rdev_get_id(rdev);
339 int reg, shift = 0, mask, ret; 314 int reg, shift = 0, mask, ret;
340 int i, j, previous_sel; 315 int j, previous_sel;
341 static u8 buck1_last_val; 316 static u8 buck1_last_val;
342 317
343 if (buck >= ARRAY_SIZE(ldo_voltage_map))
344 return -EINVAL;
345
346 desc = ldo_voltage_map[buck];
347
348 if (desc == NULL)
349 return -EINVAL;
350
351 if (max_vol < desc->min || min_vol > desc->max)
352 return -EINVAL;
353
354 if (min_vol < desc->min)
355 min_vol = desc->min;
356
357 i = DIV_ROUND_UP(min_vol - desc->min, desc->step);
358
359 if (desc->min + desc->step*i > max_vol)
360 return -EINVAL;
361
362 *selector = i;
363
364 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask); 318 ret = max8998_get_voltage_register(rdev, &reg, &shift, &mask);
365 if (ret) 319 if (ret)
366 return ret; 320 return ret;
@@ -369,19 +323,19 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
369 323
370 /* Check if voltage needs to be changed */ 324 /* Check if voltage needs to be changed */
371 /* if previous_voltage equal new voltage, return */ 325 /* if previous_voltage equal new voltage, return */
372 if (previous_sel == i) { 326 if (previous_sel == selector) {
373 dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n", 327 dev_dbg(max8998->dev, "No voltage change, old:%d, new:%d\n",
374 regulator_list_voltage_linear(rdev, previous_sel), 328 regulator_list_voltage_linear(rdev, previous_sel),
375 regulator_list_voltage_linear(rdev, i)); 329 regulator_list_voltage_linear(rdev, selector));
376 return ret; 330 return ret;
377 } 331 }
378 332
379 switch (buck) { 333 switch (buck) {
380 case MAX8998_BUCK1: 334 case MAX8998_BUCK1:
381 dev_dbg(max8998->dev, 335 dev_dbg(max8998->dev,
382 "BUCK1, i:%d, buck1_vol1:%d, buck1_vol2:%d\n" 336 "BUCK1, selector:%d, buck1_vol1:%d, buck1_vol2:%d\n"
383 "buck1_vol3:%d, buck1_vol4:%d\n", 337 "buck1_vol3:%d, buck1_vol4:%d\n",
384 i, max8998->buck1_vol[0], max8998->buck1_vol[1], 338 selector, max8998->buck1_vol[0], max8998->buck1_vol[1],
385 max8998->buck1_vol[2], max8998->buck1_vol[3]); 339 max8998->buck1_vol[2], max8998->buck1_vol[3]);
386 340
387 if (gpio_is_valid(pdata->buck1_set1) && 341 if (gpio_is_valid(pdata->buck1_set1) &&
@@ -390,7 +344,7 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
390 /* check if requested voltage */ 344 /* check if requested voltage */
391 /* value is already defined */ 345 /* value is already defined */
392 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) { 346 for (j = 0; j < ARRAY_SIZE(max8998->buck1_vol); j++) {
393 if (max8998->buck1_vol[j] == i) { 347 if (max8998->buck1_vol[j] == selector) {
394 max8998->buck1_idx = j; 348 max8998->buck1_idx = j;
395 buck1_gpio_set(pdata->buck1_set1, 349 buck1_gpio_set(pdata->buck1_set1,
396 pdata->buck1_set2, j); 350 pdata->buck1_set2, j);
@@ -405,11 +359,11 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev,
405 max8998->buck1_idx = (buck1_last_val % 2) + 2; 359 max8998->buck1_idx = (buck1_last_val % 2) + 2;
406 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", 360 dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n",
407 max8998->buck1_idx); 361 max8998->buck1_idx);
408 max8998->buck1_vol[max8998->buck1_idx] = i; 362 max8998->buck1_vol[max8998->buck1_idx] = selector;
409 ret = max8998_get_voltage_register(rdev, &reg, 363 ret = max8998_get_voltage_register(rdev, &reg,
410 &shift, 364 &shift,
411 &mask); 365 &mask);
412 ret = max8998_write_reg(i2c, reg, i); 366 ret = max8998_write_reg(i2c, reg, selector);
413 buck1_gpio_set(pdata->buck1_set1, 367 buck1_gpio_set(pdata->buck1_set1,
414 pdata->buck1_set2, max8998->buck1_idx); 368 pdata->buck1_set2, max8998->buck1_idx);
415 buck1_last_val++; 369 buck1_last_val++;
@@ -419,20 +373,20 @@ buck1_exit:
419 gpio_get_value(pdata->buck1_set2)); 373 gpio_get_value(pdata->buck1_set2));
420 break; 374 break;
421 } else { 375 } else {
422 ret = max8998_write_reg(i2c, reg, i); 376 ret = max8998_write_reg(i2c, reg, selector);
423 } 377 }
424 break; 378 break;
425 379
426 case MAX8998_BUCK2: 380 case MAX8998_BUCK2:
427 dev_dbg(max8998->dev, 381 dev_dbg(max8998->dev,
428 "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n" 382 "BUCK2, selector:%d buck2_vol1:%d, buck2_vol2:%d\n",
429 , i, max8998->buck2_vol[0], max8998->buck2_vol[1]); 383 selector, max8998->buck2_vol[0], max8998->buck2_vol[1]);
430 if (gpio_is_valid(pdata->buck2_set3)) { 384 if (gpio_is_valid(pdata->buck2_set3)) {
431 385
432 /* check if requested voltage */ 386 /* check if requested voltage */
433 /* value is already defined */ 387 /* value is already defined */
434 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { 388 for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) {
435 if (max8998->buck2_vol[j] == i) { 389 if (max8998->buck2_vol[j] == selector) {
436 max8998->buck2_idx = j; 390 max8998->buck2_idx = j;
437 buck2_gpio_set(pdata->buck2_set3, j); 391 buck2_gpio_set(pdata->buck2_set3, j);
438 goto buck2_exit; 392 goto buck2_exit;
@@ -444,20 +398,21 @@ buck1_exit:
444 398
445 max8998_get_voltage_register(rdev, 399 max8998_get_voltage_register(rdev,
446 &reg, &shift, &mask); 400 &reg, &shift, &mask);
447 ret = max8998_write_reg(i2c, reg, i); 401 ret = max8998_write_reg(i2c, reg, selector);
448 max8998->buck2_vol[max8998->buck2_idx] = i; 402 max8998->buck2_vol[max8998->buck2_idx] = selector;
449 buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx); 403 buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx);
450buck2_exit: 404buck2_exit:
451 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, 405 dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name,
452 gpio_get_value(pdata->buck2_set3)); 406 gpio_get_value(pdata->buck2_set3));
453 } else { 407 } else {
454 ret = max8998_write_reg(i2c, reg, i); 408 ret = max8998_write_reg(i2c, reg, selector);
455 } 409 }
456 break; 410 break;
457 411
458 case MAX8998_BUCK3: 412 case MAX8998_BUCK3:
459 case MAX8998_BUCK4: 413 case MAX8998_BUCK4:
460 ret = max8998_update_reg(i2c, reg, i<<shift, mask<<shift); 414 ret = max8998_update_reg(i2c, reg, selector<<shift,
415 mask<<shift);
461 break; 416 break;
462 } 417 }
463 418
@@ -499,22 +454,24 @@ static int max8998_set_voltage_buck_time_sel(struct regulator_dev *rdev,
499 454
500static struct regulator_ops max8998_ldo_ops = { 455static struct regulator_ops max8998_ldo_ops = {
501 .list_voltage = regulator_list_voltage_linear, 456 .list_voltage = regulator_list_voltage_linear,
457 .map_voltage = regulator_map_voltage_linear,
502 .is_enabled = max8998_ldo_is_enabled, 458 .is_enabled = max8998_ldo_is_enabled,
503 .enable = max8998_ldo_enable, 459 .enable = max8998_ldo_enable,
504 .disable = max8998_ldo_disable, 460 .disable = max8998_ldo_disable,
505 .get_voltage_sel = max8998_get_voltage_sel, 461 .get_voltage_sel = max8998_get_voltage_sel,
506 .set_voltage = max8998_set_voltage_ldo, 462 .set_voltage_sel = max8998_set_voltage_ldo_sel,
507 .set_suspend_enable = max8998_ldo_enable, 463 .set_suspend_enable = max8998_ldo_enable,
508 .set_suspend_disable = max8998_ldo_disable, 464 .set_suspend_disable = max8998_ldo_disable,
509}; 465};
510 466
511static struct regulator_ops max8998_buck_ops = { 467static struct regulator_ops max8998_buck_ops = {
512 .list_voltage = regulator_list_voltage_linear, 468 .list_voltage = regulator_list_voltage_linear,
469 .map_voltage = regulator_map_voltage_linear,
513 .is_enabled = max8998_ldo_is_enabled, 470 .is_enabled = max8998_ldo_is_enabled,
514 .enable = max8998_ldo_enable, 471 .enable = max8998_ldo_enable,
515 .disable = max8998_ldo_disable, 472 .disable = max8998_ldo_disable,
516 .get_voltage_sel = max8998_get_voltage_sel, 473 .get_voltage_sel = max8998_get_voltage_sel,
517 .set_voltage = max8998_set_voltage_buck, 474 .set_voltage_sel = max8998_set_voltage_buck_sel,
518 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel, 475 .set_voltage_time_sel = max8998_set_voltage_buck_time_sel,
519 .set_suspend_enable = max8998_ldo_enable, 476 .set_suspend_enable = max8998_ldo_enable,
520 .set_suspend_disable = max8998_ldo_disable, 477 .set_suspend_disable = max8998_ldo_disable,