diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-07-11 07:44:13 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-07-12 13:05:15 -0400 |
commit | faa95fde43f758d0a9e0e3d8751dac79aae1f08d (patch) | |
tree | b5a74300502be94a5cb9d7235d71f8cedd2a7d91 /drivers/regulator | |
parent | cb74685ecb394f8af48a9c49c0a5db2ab5383c33 (diff) |
regulator: tps65910: Remvoe tps65910_reg_[read|modify_bits|read_locked|write_locked] functions
The tps65910 mfd driver has been converted to regmap APIs.
This patch adds tps65910_reg_update_bits() in include/linux/mfd/tps65910.h.
Thus we can use tps65910_reg_read/tps65910_reg_write/tps65910_reg_update_bits
directly and remove tps65910_reg_[read|modify_bits|read_locked|write_locked]
functions. With this change, we can also remove the mutex in struct tps65910_reg.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Tested-by: Laxman Dewangan <ldewangan@nvidia.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/tps65910-regulator.c | 184 |
1 files changed, 73 insertions, 111 deletions
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c index 64c93e0005b1..d2ba066c0957 100644 --- a/drivers/regulator/tps65910-regulator.c +++ b/drivers/regulator/tps65910-regulator.c | |||
@@ -296,7 +296,6 @@ struct tps65910_reg { | |||
296 | struct tps65910 *mfd; | 296 | struct tps65910 *mfd; |
297 | struct regulator_dev **rdev; | 297 | struct regulator_dev **rdev; |
298 | struct tps_info **info; | 298 | struct tps_info **info; |
299 | struct mutex mutex; | ||
300 | int num_regulators; | 299 | int num_regulators; |
301 | int mode; | 300 | int mode; |
302 | int (*get_ctrl_reg)(int); | 301 | int (*get_ctrl_reg)(int); |
@@ -304,71 +303,6 @@ struct tps65910_reg { | |||
304 | unsigned int board_ext_control[TPS65910_NUM_REGS]; | 303 | unsigned int board_ext_control[TPS65910_NUM_REGS]; |
305 | }; | 304 | }; |
306 | 305 | ||
307 | static inline int tps65910_read(struct tps65910_reg *pmic, u8 reg) | ||
308 | { | ||
309 | unsigned int val; | ||
310 | int err; | ||
311 | |||
312 | err = tps65910_reg_read(pmic->mfd, reg, &val); | ||
313 | if (err) | ||
314 | return err; | ||
315 | |||
316 | return val; | ||
317 | } | ||
318 | |||
319 | static int tps65910_modify_bits(struct tps65910_reg *pmic, u8 reg, | ||
320 | u8 set_mask, u8 clear_mask) | ||
321 | { | ||
322 | int err, data; | ||
323 | |||
324 | mutex_lock(&pmic->mutex); | ||
325 | |||
326 | data = tps65910_read(pmic, reg); | ||
327 | if (data < 0) { | ||
328 | dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg); | ||
329 | err = data; | ||
330 | goto out; | ||
331 | } | ||
332 | |||
333 | data &= ~clear_mask; | ||
334 | data |= set_mask; | ||
335 | err = tps65910_reg_write(pmic->mfd, reg, data); | ||
336 | if (err) | ||
337 | dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg); | ||
338 | |||
339 | out: | ||
340 | mutex_unlock(&pmic->mutex); | ||
341 | return err; | ||
342 | } | ||
343 | |||
344 | static int tps65910_reg_read_locked(struct tps65910_reg *pmic, u8 reg) | ||
345 | { | ||
346 | int data; | ||
347 | |||
348 | mutex_lock(&pmic->mutex); | ||
349 | |||
350 | data = tps65910_read(pmic, reg); | ||
351 | if (data < 0) | ||
352 | dev_err(pmic->mfd->dev, "Read from reg 0x%x failed\n", reg); | ||
353 | |||
354 | mutex_unlock(&pmic->mutex); | ||
355 | return data; | ||
356 | } | ||
357 | |||
358 | static int tps65910_reg_write_locked(struct tps65910_reg *pmic, u8 reg, u8 val) | ||
359 | { | ||
360 | int err; | ||
361 | |||
362 | mutex_lock(&pmic->mutex); | ||
363 | |||
364 | err = tps65910_reg_write(pmic->mfd, reg, val); | ||
365 | if (err < 0) | ||
366 | dev_err(pmic->mfd->dev, "Write for reg 0x%x failed\n", reg); | ||
367 | |||
368 | mutex_unlock(&pmic->mutex); | ||
369 | return err; | ||
370 | } | ||
371 | |||
372 | static int tps65910_get_ctrl_register(int id) | 306 | static int tps65910_get_ctrl_register(int id) |
373 | { | 307 | { |
374 | switch (id) { | 308 | switch (id) { |
@@ -449,8 +383,9 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) | |||
449 | 383 | ||
450 | switch (mode) { | 384 | switch (mode) { |
451 | case REGULATOR_MODE_NORMAL: | 385 | case REGULATOR_MODE_NORMAL: |
452 | return tps65910_modify_bits(pmic, reg, LDO_ST_ON_BIT, | 386 | return tps65910_reg_update_bits(pmic->mfd, reg, |
453 | LDO_ST_MODE_BIT); | 387 | LDO_ST_MODE_BIT | LDO_ST_ON_BIT, |
388 | LDO_ST_ON_BIT); | ||
454 | case REGULATOR_MODE_IDLE: | 389 | case REGULATOR_MODE_IDLE: |
455 | value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT; | 390 | value = LDO_ST_ON_BIT | LDO_ST_MODE_BIT; |
456 | return tps65910_reg_set_bits(mfd, reg, value); | 391 | return tps65910_reg_set_bits(mfd, reg, value); |
@@ -464,15 +399,15 @@ static int tps65910_set_mode(struct regulator_dev *dev, unsigned int mode) | |||
464 | static unsigned int tps65910_get_mode(struct regulator_dev *dev) | 399 | static unsigned int tps65910_get_mode(struct regulator_dev *dev) |
465 | { | 400 | { |
466 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 401 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
467 | int reg, value, id = rdev_get_id(dev); | 402 | int ret, reg, value, id = rdev_get_id(dev); |
468 | 403 | ||
469 | reg = pmic->get_ctrl_reg(id); | 404 | reg = pmic->get_ctrl_reg(id); |
470 | if (reg < 0) | 405 | if (reg < 0) |
471 | return reg; | 406 | return reg; |
472 | 407 | ||
473 | value = tps65910_reg_read_locked(pmic, reg); | 408 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
474 | if (value < 0) | 409 | if (ret < 0) |
475 | return value; | 410 | return ret; |
476 | 411 | ||
477 | if (!(value & LDO_ST_ON_BIT)) | 412 | if (!(value & LDO_ST_ON_BIT)) |
478 | return REGULATOR_MODE_STANDBY; | 413 | return REGULATOR_MODE_STANDBY; |
@@ -485,33 +420,51 @@ static unsigned int tps65910_get_mode(struct regulator_dev *dev) | |||
485 | static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) | 420 | static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) |
486 | { | 421 | { |
487 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 422 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
488 | int id = rdev_get_id(dev); | 423 | int ret, id = rdev_get_id(dev); |
489 | int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; | 424 | int opvsel = 0, srvsel = 0, vselmax = 0, mult = 0, sr = 0; |
490 | 425 | ||
491 | switch (id) { | 426 | switch (id) { |
492 | case TPS65910_REG_VDD1: | 427 | case TPS65910_REG_VDD1: |
493 | opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_OP); | 428 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_OP, &opvsel); |
494 | mult = tps65910_reg_read_locked(pmic, TPS65910_VDD1); | 429 | if (ret < 0) |
430 | return ret; | ||
431 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1, &mult); | ||
432 | if (ret < 0) | ||
433 | return ret; | ||
495 | mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT; | 434 | mult = (mult & VDD1_VGAIN_SEL_MASK) >> VDD1_VGAIN_SEL_SHIFT; |
496 | srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD1_SR); | 435 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD1_SR, &srvsel); |
436 | if (ret < 0) | ||
437 | return ret; | ||
497 | sr = opvsel & VDD1_OP_CMD_MASK; | 438 | sr = opvsel & VDD1_OP_CMD_MASK; |
498 | opvsel &= VDD1_OP_SEL_MASK; | 439 | opvsel &= VDD1_OP_SEL_MASK; |
499 | srvsel &= VDD1_SR_SEL_MASK; | 440 | srvsel &= VDD1_SR_SEL_MASK; |
500 | vselmax = 75; | 441 | vselmax = 75; |
501 | break; | 442 | break; |
502 | case TPS65910_REG_VDD2: | 443 | case TPS65910_REG_VDD2: |
503 | opvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_OP); | 444 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_OP, &opvsel); |
504 | mult = tps65910_reg_read_locked(pmic, TPS65910_VDD2); | 445 | if (ret < 0) |
446 | return ret; | ||
447 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2, &mult); | ||
448 | if (ret < 0) | ||
449 | return ret; | ||
505 | mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT; | 450 | mult = (mult & VDD2_VGAIN_SEL_MASK) >> VDD2_VGAIN_SEL_SHIFT; |
506 | srvsel = tps65910_reg_read_locked(pmic, TPS65910_VDD2_SR); | 451 | ret = tps65910_reg_read(pmic->mfd, TPS65910_VDD2_SR, &srvsel); |
452 | if (ret < 0) | ||
453 | return ret; | ||
507 | sr = opvsel & VDD2_OP_CMD_MASK; | 454 | sr = opvsel & VDD2_OP_CMD_MASK; |
508 | opvsel &= VDD2_OP_SEL_MASK; | 455 | opvsel &= VDD2_OP_SEL_MASK; |
509 | srvsel &= VDD2_SR_SEL_MASK; | 456 | srvsel &= VDD2_SR_SEL_MASK; |
510 | vselmax = 75; | 457 | vselmax = 75; |
511 | break; | 458 | break; |
512 | case TPS65911_REG_VDDCTRL: | 459 | case TPS65911_REG_VDDCTRL: |
513 | opvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_OP); | 460 | ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_OP, |
514 | srvsel = tps65910_reg_read_locked(pmic, TPS65911_VDDCTRL_SR); | 461 | &opvsel); |
462 | if (ret < 0) | ||
463 | return ret; | ||
464 | ret = tps65910_reg_read(pmic->mfd, TPS65911_VDDCTRL_SR, | ||
465 | &srvsel); | ||
466 | if (ret < 0) | ||
467 | return ret; | ||
515 | sr = opvsel & VDDCTRL_OP_CMD_MASK; | 468 | sr = opvsel & VDDCTRL_OP_CMD_MASK; |
516 | opvsel &= VDDCTRL_OP_SEL_MASK; | 469 | opvsel &= VDDCTRL_OP_SEL_MASK; |
517 | srvsel &= VDDCTRL_SR_SEL_MASK; | 470 | srvsel &= VDDCTRL_SR_SEL_MASK; |
@@ -545,15 +498,15 @@ static int tps65910_get_voltage_dcdc_sel(struct regulator_dev *dev) | |||
545 | static int tps65910_get_voltage_sel(struct regulator_dev *dev) | 498 | static int tps65910_get_voltage_sel(struct regulator_dev *dev) |
546 | { | 499 | { |
547 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 500 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
548 | int reg, value, id = rdev_get_id(dev); | 501 | int ret, reg, value, id = rdev_get_id(dev); |
549 | 502 | ||
550 | reg = pmic->get_ctrl_reg(id); | 503 | reg = pmic->get_ctrl_reg(id); |
551 | if (reg < 0) | 504 | if (reg < 0) |
552 | return reg; | 505 | return reg; |
553 | 506 | ||
554 | value = tps65910_reg_read_locked(pmic, reg); | 507 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
555 | if (value < 0) | 508 | if (ret < 0) |
556 | return value; | 509 | return ret; |
557 | 510 | ||
558 | switch (id) { | 511 | switch (id) { |
559 | case TPS65910_REG_VIO: | 512 | case TPS65910_REG_VIO: |
@@ -583,12 +536,14 @@ static int tps65910_get_voltage_vdd3(struct regulator_dev *dev) | |||
583 | static int tps65911_get_voltage_sel(struct regulator_dev *dev) | 536 | static int tps65911_get_voltage_sel(struct regulator_dev *dev) |
584 | { | 537 | { |
585 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); | 538 | struct tps65910_reg *pmic = rdev_get_drvdata(dev); |
586 | int id = rdev_get_id(dev); | 539 | int ret, id = rdev_get_id(dev); |
587 | u8 value, reg; | 540 | unsigned int value, reg; |
588 | 541 | ||
589 | reg = pmic->get_ctrl_reg(id); | 542 | reg = pmic->get_ctrl_reg(id); |
590 | 543 | ||
591 | value = tps65910_reg_read_locked(pmic, reg); | 544 | ret = tps65910_reg_read(pmic->mfd, reg, &value); |
545 | if (ret < 0) | ||
546 | return ret; | ||
592 | 547 | ||
593 | switch (id) { | 548 | switch (id) { |
594 | case TPS65911_REG_LDO1: | 549 | case TPS65911_REG_LDO1: |
@@ -630,10 +585,10 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, | |||
630 | dcdc_mult--; | 585 | dcdc_mult--; |
631 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; | 586 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; |
632 | 587 | ||
633 | tps65910_modify_bits(pmic, TPS65910_VDD1, | 588 | tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD1, |
634 | (dcdc_mult << VDD1_VGAIN_SEL_SHIFT), | 589 | VDD1_VGAIN_SEL_MASK, |
635 | VDD1_VGAIN_SEL_MASK); | 590 | dcdc_mult << VDD1_VGAIN_SEL_SHIFT); |
636 | tps65910_reg_write_locked(pmic, TPS65910_VDD1_OP, vsel); | 591 | tps65910_reg_write(pmic->mfd, TPS65910_VDD1_OP, vsel); |
637 | break; | 592 | break; |
638 | case TPS65910_REG_VDD2: | 593 | case TPS65910_REG_VDD2: |
639 | dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; | 594 | dcdc_mult = (selector / VDD1_2_NUM_VOLT_FINE) + 1; |
@@ -641,14 +596,14 @@ static int tps65910_set_voltage_dcdc_sel(struct regulator_dev *dev, | |||
641 | dcdc_mult--; | 596 | dcdc_mult--; |
642 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; | 597 | vsel = (selector % VDD1_2_NUM_VOLT_FINE) + 3; |
643 | 598 | ||
644 | tps65910_modify_bits(pmic, TPS65910_VDD2, | 599 | tps65910_reg_update_bits(pmic->mfd, TPS65910_VDD2, |
645 | (dcdc_mult << VDD2_VGAIN_SEL_SHIFT), | 600 | VDD1_VGAIN_SEL_MASK, |
646 | VDD1_VGAIN_SEL_MASK); | 601 | dcdc_mult << VDD2_VGAIN_SEL_SHIFT); |
647 | tps65910_reg_write_locked(pmic, TPS65910_VDD2_OP, vsel); | 602 | tps65910_reg_write(pmic->mfd, TPS65910_VDD2_OP, vsel); |
648 | break; | 603 | break; |
649 | case TPS65911_REG_VDDCTRL: | 604 | case TPS65911_REG_VDDCTRL: |
650 | vsel = selector + 3; | 605 | vsel = selector + 3; |
651 | tps65910_reg_write_locked(pmic, TPS65911_VDDCTRL_OP, vsel); | 606 | tps65910_reg_write(pmic->mfd, TPS65911_VDDCTRL_OP, vsel); |
652 | } | 607 | } |
653 | 608 | ||
654 | return 0; | 609 | return 0; |
@@ -674,8 +629,8 @@ static int tps65910_set_voltage_sel(struct regulator_dev *dev, | |||
674 | case TPS65910_REG_VAUX2: | 629 | case TPS65910_REG_VAUX2: |
675 | case TPS65910_REG_VAUX33: | 630 | case TPS65910_REG_VAUX33: |
676 | case TPS65910_REG_VMMC: | 631 | case TPS65910_REG_VMMC: |
677 | return tps65910_modify_bits(pmic, reg, | 632 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, |
678 | (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); | 633 | selector << LDO_SEL_SHIFT); |
679 | } | 634 | } |
680 | 635 | ||
681 | return -EINVAL; | 636 | return -EINVAL; |
@@ -695,18 +650,18 @@ static int tps65911_set_voltage_sel(struct regulator_dev *dev, | |||
695 | case TPS65911_REG_LDO1: | 650 | case TPS65911_REG_LDO1: |
696 | case TPS65911_REG_LDO2: | 651 | case TPS65911_REG_LDO2: |
697 | case TPS65911_REG_LDO4: | 652 | case TPS65911_REG_LDO4: |
698 | return tps65910_modify_bits(pmic, reg, | 653 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO1_SEL_MASK, |
699 | (selector << LDO_SEL_SHIFT), LDO1_SEL_MASK); | 654 | selector << LDO_SEL_SHIFT); |
700 | case TPS65911_REG_LDO3: | 655 | case TPS65911_REG_LDO3: |
701 | case TPS65911_REG_LDO5: | 656 | case TPS65911_REG_LDO5: |
702 | case TPS65911_REG_LDO6: | 657 | case TPS65911_REG_LDO6: |
703 | case TPS65911_REG_LDO7: | 658 | case TPS65911_REG_LDO7: |
704 | case TPS65911_REG_LDO8: | 659 | case TPS65911_REG_LDO8: |
705 | return tps65910_modify_bits(pmic, reg, | 660 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO3_SEL_MASK, |
706 | (selector << LDO_SEL_SHIFT), LDO3_SEL_MASK); | 661 | selector << LDO_SEL_SHIFT); |
707 | case TPS65910_REG_VIO: | 662 | case TPS65910_REG_VIO: |
708 | return tps65910_modify_bits(pmic, reg, | 663 | return tps65910_reg_update_bits(pmic->mfd, reg, LDO_SEL_MASK, |
709 | (selector << LDO_SEL_SHIFT), LDO_SEL_MASK); | 664 | selector << LDO_SEL_SHIFT); |
710 | } | 665 | } |
711 | 666 | ||
712 | return -EINVAL; | 667 | return -EINVAL; |
@@ -918,19 +873,27 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic, | |||
918 | (tps65910_chip_id(mfd) == TPS65911))) { | 873 | (tps65910_chip_id(mfd) == TPS65911))) { |
919 | int op_reg_add = pmic->get_ctrl_reg(id) + 1; | 874 | int op_reg_add = pmic->get_ctrl_reg(id) + 1; |
920 | int sr_reg_add = pmic->get_ctrl_reg(id) + 2; | 875 | int sr_reg_add = pmic->get_ctrl_reg(id) + 2; |
921 | int opvsel = tps65910_reg_read_locked(pmic, op_reg_add); | 876 | int opvsel, srvsel; |
922 | int srvsel = tps65910_reg_read_locked(pmic, sr_reg_add); | 877 | |
878 | ret = tps65910_reg_read(pmic->mfd, op_reg_add, &opvsel); | ||
879 | if (ret < 0) | ||
880 | return ret; | ||
881 | ret = tps65910_reg_read(pmic->mfd, sr_reg_add, &srvsel); | ||
882 | if (ret < 0) | ||
883 | return ret; | ||
884 | |||
923 | if (opvsel & VDD1_OP_CMD_MASK) { | 885 | if (opvsel & VDD1_OP_CMD_MASK) { |
924 | u8 reg_val = srvsel & VDD1_OP_SEL_MASK; | 886 | u8 reg_val = srvsel & VDD1_OP_SEL_MASK; |
925 | ret = tps65910_reg_write_locked(pmic, op_reg_add, | 887 | |
926 | reg_val); | 888 | ret = tps65910_reg_write(pmic->mfd, op_reg_add, |
889 | reg_val); | ||
927 | if (ret < 0) { | 890 | if (ret < 0) { |
928 | dev_err(mfd->dev, | 891 | dev_err(mfd->dev, |
929 | "Error in configuring op register\n"); | 892 | "Error in configuring op register\n"); |
930 | return ret; | 893 | return ret; |
931 | } | 894 | } |
932 | } | 895 | } |
933 | ret = tps65910_reg_write_locked(pmic, sr_reg_add, 0); | 896 | ret = tps65910_reg_write(pmic->mfd, sr_reg_add, 0); |
934 | if (ret < 0) { | 897 | if (ret < 0) { |
935 | dev_err(mfd->dev, "Error in settting sr register\n"); | 898 | dev_err(mfd->dev, "Error in settting sr register\n"); |
936 | return ret; | 899 | return ret; |
@@ -1100,7 +1063,6 @@ static __devinit int tps65910_probe(struct platform_device *pdev) | |||
1100 | return -ENOMEM; | 1063 | return -ENOMEM; |
1101 | } | 1064 | } |
1102 | 1065 | ||
1103 | mutex_init(&pmic->mutex); | ||
1104 | pmic->mfd = tps65910; | 1066 | pmic->mfd = tps65910; |
1105 | platform_set_drvdata(pdev, pmic); | 1067 | platform_set_drvdata(pdev, pmic); |
1106 | 1068 | ||