[U-Boot] [PATCH 2/5] power: axp: merge separate DLDO functions into 1

Chen-Yu Tsai wens at csie.org
Tue Jan 12 07:42:37 CET 2016


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 at csie.org>
---
 board/sunxi/board.c    |  8 ++---
 drivers/power/axp221.c | 88 ++++++++++++--------------------------------------
 include/axp_pmic.h     |  5 +--
 3 files changed, 25 insertions(+), 76 deletions(-)

diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index 386e2e0..85f01fd 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -460,10 +460,10 @@ void sunxi_board_init(void)
 #endif
 
 #ifdef CONFIG_AXP221_POWER
-	power_failed |= axp_set_dldo1(CONFIG_AXP_DLDO1_VOLT);
-	power_failed |= axp_set_dldo2(CONFIG_AXP_DLDO2_VOLT);
-	power_failed |= axp_set_dldo3(CONFIG_AXP_DLDO3_VOLT);
-	power_failed |= axp_set_dldo4(CONFIG_AXP_DLDO4_VOLT);
+	power_failed |= axp_set_dldo(1, CONFIG_AXP_DLDO1_VOLT);
+	power_failed |= axp_set_dldo(2, CONFIG_AXP_DLDO2_VOLT);
+	power_failed |= axp_set_dldo(3, CONFIG_AXP_DLDO3_VOLT);
+	power_failed |= axp_set_dldo(4, CONFIG_AXP_DLDO4_VOLT);
 	power_failed |= axp_set_eldo(1, CONFIG_AXP_ELDO1_VOLT);
 	power_failed |= axp_set_eldo(2, CONFIG_AXP_ELDO2_VOLT);
 	power_failed |= axp_set_eldo(3, CONFIG_AXP_ELDO3_VOLT);
diff --git a/drivers/power/axp221.c b/drivers/power/axp221.c
index 65802e4..e0cbf79 100644
--- a/drivers/power/axp221.c
+++ b/drivers/power/axp221.c
@@ -115,74 +115,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;
@@ -234,6 +166,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;
diff --git a/include/axp_pmic.h b/include/axp_pmic.h
index 3b01c49..0f14683 100644
--- a/include/axp_pmic.h
+++ b/include/axp_pmic.h
@@ -29,10 +29,7 @@ int axp_set_aldo1(unsigned int mvolt);
 int axp_set_aldo2(unsigned int mvolt);
 int axp_set_aldo3(unsigned int mvolt);
 int axp_set_aldo4(unsigned int mvolt);
-int axp_set_dldo1(unsigned int mvolt);
-int axp_set_dldo2(unsigned int mvolt);
-int axp_set_dldo3(unsigned int mvolt);
-int axp_set_dldo4(unsigned int mvolt);
+int axp_set_dldo(int dldo_num, unsigned int mvolt);
 int axp_set_eldo(int eldo_num, unsigned int mvolt);
 int axp_init(void);
 int axp_get_sid(unsigned int *sid);
-- 
2.6.4



More information about the U-Boot mailing list