summaryrefslogtreecommitdiff
path: root/drivers/power/axp221.c
diff options
context:
space:
mode:
authorChen-Yu Tsai <wens@csie.org>2016-01-12 14:42:37 +0800
committerHans de Goede <hdegoede@redhat.com>2016-01-26 16:20:05 +0100
commit3517a27ddb1d12154e263a4f0bf91b4b76c21536 (patch)
treeadab661007148d024d556fb5d5eef791de3784e0 /drivers/power/axp221.c
parentc2caf65da5d15f8e21a4438104360caa8fbb6b7f (diff)
power: axp: merge separate DLDO functions into 1
Instead of one function for each DLDO regulator, make 1 function that takes an extra "index". Since the control bits for the DLDO regulators are contiguous, this makes the function very simple. This removes a lot of duplicate code. Signed-off-by: Chen-Yu Tsai <wens@csie.org> Acked-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Diffstat (limited to 'drivers/power/axp221.c')
-rw-r--r--drivers/power/axp221.c88
1 files changed, 20 insertions, 68 deletions
diff --git a/drivers/power/axp221.c b/drivers/power/axp221.c
index 8acadf0f9c5..cb1f88b185c 100644
--- a/drivers/power/axp221.c
+++ b/drivers/power/axp221.c
@@ -116,74 +116,6 @@ int axp_set_dcdc5(unsigned int mvolt)
AXP221_OUTPUT_CTRL1_DCDC5_EN);
}
-int axp_set_dldo1(unsigned int mvolt)
-{
- int ret;
- u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
-
- if (mvolt == 0)
- return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO1_EN);
-
- ret = pmic_bus_write(AXP221_DLDO1_CTRL, cfg);
- if (ret)
- return ret;
-
- return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO1_EN);
-}
-
-int axp_set_dldo2(unsigned int mvolt)
-{
- int ret;
- u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
-
- if (mvolt == 0)
- return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO2_EN);
-
- ret = pmic_bus_write(AXP221_DLDO2_CTRL, cfg);
- if (ret)
- return ret;
-
- return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO2_EN);
-}
-
-int axp_set_dldo3(unsigned int mvolt)
-{
- int ret;
- u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
-
- if (mvolt == 0)
- return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO3_EN);
-
- ret = pmic_bus_write(AXP221_DLDO3_CTRL, cfg);
- if (ret)
- return ret;
-
- return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO3_EN);
-}
-
-int axp_set_dldo4(unsigned int mvolt)
-{
- int ret;
- u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
-
- if (mvolt == 0)
- return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO4_EN);
-
- ret = pmic_bus_write(AXP221_DLDO4_CTRL, cfg);
- if (ret)
- return ret;
-
- return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
- AXP221_OUTPUT_CTRL2_DLDO4_EN);
-}
-
int axp_set_aldo1(unsigned int mvolt)
{
int ret;
@@ -235,6 +167,26 @@ int axp_set_aldo3(unsigned int mvolt)
AXP221_OUTPUT_CTRL3_ALDO3_EN);
}
+int axp_set_dldo(int dldo_num, unsigned int mvolt)
+{
+ u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
+ int ret;
+
+ if (dldo_num < 1 || dldo_num > 4)
+ return -EINVAL;
+
+ if (mvolt == 0)
+ return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
+ AXP221_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1));
+
+ ret = pmic_bus_write(AXP221_DLDO1_CTRL + (dldo_num - 1), cfg);
+ if (ret)
+ return ret;
+
+ return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
+ AXP221_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1));
+}
+
int axp_set_eldo(int eldo_num, unsigned int mvolt)
{
int ret;