diff options
| author | MyungJoo Ham <myungjoo.ham@samsung.com> | 2011-01-11 06:20:05 -0500 |
|---|---|---|
| committer | Samuel Ortiz <sameo@linux.intel.com> | 2011-01-14 06:38:16 -0500 |
| commit | 735a3d9efdc5aeebe201008e6655b235c7f02aeb (patch) | |
| tree | a1083cec498505b1dbd28dd09a73d477965d2d61 | |
| parent | 337ce5d1c5759644cea6c47220ce7e84f0398362 (diff) | |
regulator: Support MAX8998/LP3974 DVS-GPIO
The previous driver did not support BUCK1-DVS3, BUCK1-DVS4, and
BUCK2-DVS2 modes. This patch adds such modes and an option to block
setting buck1/2 voltages out of the preset values.
Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
| -rw-r--r-- | drivers/regulator/max8998.c | 87 | ||||
| -rw-r--r-- | include/linux/mfd/max8998.h | 26 |
2 files changed, 87 insertions, 26 deletions
diff --git a/drivers/regulator/max8998.c b/drivers/regulator/max8998.c index af52ebfc4927..0ec49ca527a8 100644 --- a/drivers/regulator/max8998.c +++ b/drivers/regulator/max8998.c | |||
| @@ -424,6 +424,9 @@ static int max8998_set_voltage_buck(struct regulator_dev *rdev, | |||
| 424 | } | 424 | } |
| 425 | } | 425 | } |
| 426 | 426 | ||
| 427 | if (pdata->buck_voltage_lock) | ||
| 428 | return -EINVAL; | ||
| 429 | |||
| 427 | /* no predefine regulator found */ | 430 | /* no predefine regulator found */ |
| 428 | max8998->buck1_idx = (buck1_last_val % 2) + 2; | 431 | max8998->buck1_idx = (buck1_last_val % 2) + 2; |
| 429 | dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", | 432 | dev_dbg(max8998->dev, "max8998->buck1_idx:%d\n", |
| @@ -451,18 +454,26 @@ buck1_exit: | |||
| 451 | "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n" | 454 | "BUCK2, i:%d buck2_vol1:%d, buck2_vol2:%d\n" |
| 452 | , i, max8998->buck2_vol[0], max8998->buck2_vol[1]); | 455 | , i, max8998->buck2_vol[0], max8998->buck2_vol[1]); |
| 453 | if (gpio_is_valid(pdata->buck2_set3)) { | 456 | if (gpio_is_valid(pdata->buck2_set3)) { |
| 454 | if (max8998->buck2_vol[0] == i) { | 457 | |
| 455 | max8998->buck1_idx = 0; | 458 | /* check if requested voltage */ |
| 456 | buck2_gpio_set(pdata->buck2_set3, 0); | 459 | /* value is already defined */ |
| 457 | } else { | 460 | for (j = 0; j < ARRAY_SIZE(max8998->buck2_vol); j++) { |
| 458 | max8998->buck1_idx = 1; | 461 | if (max8998->buck2_vol[j] == i) { |
| 459 | ret = max8998_get_voltage_register(rdev, ®, | 462 | max8998->buck2_idx = j; |
| 460 | &shift, | 463 | buck2_gpio_set(pdata->buck2_set3, j); |
| 461 | &mask); | 464 | goto buck2_exit; |
| 462 | ret = max8998_write_reg(i2c, reg, i); | 465 | } |
| 463 | max8998->buck2_vol[1] = i; | ||
| 464 | buck2_gpio_set(pdata->buck2_set3, 1); | ||
| 465 | } | 466 | } |
| 467 | |||
| 468 | if (pdata->buck_voltage_lock) | ||
| 469 | return -EINVAL; | ||
| 470 | |||
| 471 | max8998_get_voltage_register(rdev, | ||
| 472 | ®, &shift, &mask); | ||
| 473 | ret = max8998_write_reg(i2c, reg, i); | ||
| 474 | max8998->buck2_vol[max8998->buck2_idx] = i; | ||
| 475 | buck2_gpio_set(pdata->buck2_set3, max8998->buck2_idx); | ||
| 476 | buck2_exit: | ||
| 466 | dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, | 477 | dev_dbg(max8998->dev, "%s: SET3:%d\n", i2c->name, |
| 467 | gpio_get_value(pdata->buck2_set3)); | 478 | gpio_get_value(pdata->buck2_set3)); |
| 468 | } else { | 479 | } else { |
| @@ -707,6 +718,9 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
| 707 | platform_set_drvdata(pdev, max8998); | 718 | platform_set_drvdata(pdev, max8998); |
| 708 | i2c = max8998->iodev->i2c; | 719 | i2c = max8998->iodev->i2c; |
| 709 | 720 | ||
| 721 | max8998->buck1_idx = pdata->buck1_default_idx; | ||
| 722 | max8998->buck2_idx = pdata->buck2_default_idx; | ||
| 723 | |||
| 710 | /* NOTE: */ | 724 | /* NOTE: */ |
| 711 | /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */ | 725 | /* For unused GPIO NOT marked as -1 (thereof equal to 0) WARN_ON */ |
| 712 | /* will be displayed */ | 726 | /* will be displayed */ |
| @@ -739,23 +753,46 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
| 739 | i = 0; | 753 | i = 0; |
| 740 | while (buck12_voltage_map_desc.min + | 754 | while (buck12_voltage_map_desc.min + |
| 741 | buck12_voltage_map_desc.step*i | 755 | buck12_voltage_map_desc.step*i |
| 742 | != (pdata->buck1_max_voltage1 / 1000)) | 756 | < (pdata->buck1_voltage1 / 1000)) |
| 743 | i++; | 757 | i++; |
| 744 | printk(KERN_ERR "i:%d, buck1_idx:%d\n", i, max8998->buck1_idx); | ||
| 745 | max8998->buck1_vol[0] = i; | 758 | max8998->buck1_vol[0] = i; |
| 746 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i); | 759 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE1, i); |
| 760 | if (ret) | ||
| 761 | return ret; | ||
| 747 | 762 | ||
| 748 | /* Set predefined value for BUCK1 register 2 */ | 763 | /* Set predefined value for BUCK1 register 2 */ |
| 749 | i = 0; | 764 | i = 0; |
| 750 | while (buck12_voltage_map_desc.min + | 765 | while (buck12_voltage_map_desc.min + |
| 751 | buck12_voltage_map_desc.step*i | 766 | buck12_voltage_map_desc.step*i |
| 752 | != (pdata->buck1_max_voltage2 / 1000)) | 767 | < (pdata->buck1_voltage2 / 1000)) |
| 753 | i++; | 768 | i++; |
| 754 | 769 | ||
| 755 | max8998->buck1_vol[1] = i; | 770 | max8998->buck1_vol[1] = i; |
| 756 | printk(KERN_ERR "i:%d, buck1_idx:%d\n", i, max8998->buck1_idx); | 771 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i); |
| 757 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE2, i) | 772 | if (ret) |
| 758 | + ret; | 773 | return ret; |
| 774 | |||
| 775 | /* Set predefined value for BUCK1 register 3 */ | ||
| 776 | i = 0; | ||
| 777 | while (buck12_voltage_map_desc.min + | ||
| 778 | buck12_voltage_map_desc.step*i | ||
| 779 | < (pdata->buck1_voltage3 / 1000)) | ||
| 780 | i++; | ||
| 781 | |||
| 782 | max8998->buck1_vol[2] = i; | ||
| 783 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE3, i); | ||
| 784 | if (ret) | ||
| 785 | return ret; | ||
| 786 | |||
| 787 | /* Set predefined value for BUCK1 register 4 */ | ||
| 788 | i = 0; | ||
| 789 | while (buck12_voltage_map_desc.min + | ||
| 790 | buck12_voltage_map_desc.step*i | ||
| 791 | < (pdata->buck1_voltage4 / 1000)) | ||
| 792 | i++; | ||
| 793 | |||
| 794 | max8998->buck1_vol[3] = i; | ||
| 795 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK1_VOLTAGE4, i); | ||
| 759 | if (ret) | 796 | if (ret) |
| 760 | return ret; | 797 | return ret; |
| 761 | 798 | ||
| @@ -772,18 +809,28 @@ static __devinit int max8998_pmic_probe(struct platform_device *pdev) | |||
| 772 | gpio_direction_output(pdata->buck2_set3, | 809 | gpio_direction_output(pdata->buck2_set3, |
| 773 | max8998->buck2_idx & 0x1); | 810 | max8998->buck2_idx & 0x1); |
| 774 | 811 | ||
| 775 | /* BUCK2 - set preset default voltage value to buck2_vol[0] */ | 812 | /* BUCK2 register 1 */ |
| 776 | i = 0; | 813 | i = 0; |
| 777 | while (buck12_voltage_map_desc.min + | 814 | while (buck12_voltage_map_desc.min + |
| 778 | buck12_voltage_map_desc.step*i | 815 | buck12_voltage_map_desc.step*i |
| 779 | != (pdata->buck2_max_voltage / 1000)) | 816 | < (pdata->buck2_voltage1 / 1000)) |
| 780 | i++; | 817 | i++; |
| 781 | printk(KERN_ERR "i:%d, buck2_idx:%d\n", i, max8998->buck2_idx); | ||
| 782 | max8998->buck2_vol[0] = i; | 818 | max8998->buck2_vol[0] = i; |
| 783 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i); | 819 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE1, i); |
| 784 | if (ret) | 820 | if (ret) |
| 785 | return ret; | 821 | return ret; |
| 786 | 822 | ||
| 823 | /* BUCK2 register 2 */ | ||
| 824 | i = 0; | ||
| 825 | while (buck12_voltage_map_desc.min + | ||
| 826 | buck12_voltage_map_desc.step*i | ||
| 827 | < (pdata->buck2_voltage2 / 1000)) | ||
| 828 | i++; | ||
| 829 | printk(KERN_ERR "i2:%d, buck2_idx:%d\n", i, max8998->buck2_idx); | ||
| 830 | max8998->buck2_vol[1] = i; | ||
| 831 | ret = max8998_write_reg(i2c, MAX8998_REG_BUCK2_VOLTAGE2, i); | ||
| 832 | if (ret) | ||
| 833 | return ret; | ||
| 787 | } | 834 | } |
| 788 | 835 | ||
| 789 | for (i = 0; i < pdata->num_regulators; i++) { | 836 | for (i = 0; i < pdata->num_regulators; i++) { |
diff --git a/include/linux/mfd/max8998.h b/include/linux/mfd/max8998.h index c22b9a417c35..61daa167b576 100644 --- a/include/linux/mfd/max8998.h +++ b/include/linux/mfd/max8998.h | |||
| @@ -70,12 +70,20 @@ struct max8998_regulator_data { | |||
| 70 | * @num_regulators: number of regultors used | 70 | * @num_regulators: number of regultors used |
| 71 | * @irq_base: base IRQ number for max8998, required for IRQs | 71 | * @irq_base: base IRQ number for max8998, required for IRQs |
| 72 | * @ono: power onoff IRQ number for max8998 | 72 | * @ono: power onoff IRQ number for max8998 |
| 73 | * @buck1_max_voltage1: BUCK1 maximum alowed voltage register 1 | 73 | * @buck_voltage_lock: Do NOT change the values of the following six |
| 74 | * @buck1_max_voltage2: BUCK1 maximum alowed voltage register 2 | 74 | * registers set by buck?_voltage?. The voltage of BUCK1/2 cannot |
| 75 | * @buck2_max_voltage: BUCK2 maximum alowed voltage | 75 | * be other than the preset values. |
| 76 | * @buck1_voltage1: BUCK1 DVS mode 1 voltage register | ||
| 77 | * @buck1_voltage2: BUCK1 DVS mode 2 voltage register | ||
| 78 | * @buck1_voltage3: BUCK1 DVS mode 3 voltage register | ||
| 79 | * @buck1_voltage4: BUCK1 DVS mode 4 voltage register | ||
| 80 | * @buck2_voltage1: BUCK2 DVS mode 1 voltage register | ||
| 81 | * @buck2_voltage2: BUCK2 DVS mode 2 voltage register | ||
| 76 | * @buck1_set1: BUCK1 gpio pin 1 to set output voltage | 82 | * @buck1_set1: BUCK1 gpio pin 1 to set output voltage |
| 77 | * @buck1_set2: BUCK1 gpio pin 2 to set output voltage | 83 | * @buck1_set2: BUCK1 gpio pin 2 to set output voltage |
| 84 | * @buck1_default_idx: Default for BUCK1 gpio pin 1, 2 | ||
| 78 | * @buck2_set3: BUCK2 gpio pin to set output voltage | 85 | * @buck2_set3: BUCK2 gpio pin to set output voltage |
| 86 | * @buck2_default_idx: Default for BUCK2 gpio pin. | ||
| 79 | * @wakeup: Allow to wake up from suspend | 87 | * @wakeup: Allow to wake up from suspend |
| 80 | * @rtc_delay: LP3974 RTC chip bug that requires delay after a register | 88 | * @rtc_delay: LP3974 RTC chip bug that requires delay after a register |
| 81 | * write before reading it. | 89 | * write before reading it. |
| @@ -85,12 +93,18 @@ struct max8998_platform_data { | |||
| 85 | int num_regulators; | 93 | int num_regulators; |
| 86 | int irq_base; | 94 | int irq_base; |
| 87 | int ono; | 95 | int ono; |
| 88 | int buck1_max_voltage1; | 96 | bool buck_voltage_lock; |
| 89 | int buck1_max_voltage2; | 97 | int buck1_voltage1; |
| 90 | int buck2_max_voltage; | 98 | int buck1_voltage2; |
| 99 | int buck1_voltage3; | ||
| 100 | int buck1_voltage4; | ||
| 101 | int buck2_voltage1; | ||
| 102 | int buck2_voltage2; | ||
| 91 | int buck1_set1; | 103 | int buck1_set1; |
| 92 | int buck1_set2; | 104 | int buck1_set2; |
| 105 | int buck1_default_idx; | ||
| 93 | int buck2_set3; | 106 | int buck2_set3; |
| 107 | int buck2_default_idx; | ||
| 94 | bool wakeup; | 108 | bool wakeup; |
| 95 | bool rtc_delay; | 109 | bool rtc_delay; |
| 96 | }; | 110 | }; |
