power: axp221: Remove switch case to simplify axp_set_eldo
The ELDO enable bits and registers are contiguous for axp221. Instead
of a switch case testing against the index, just use the index to shift
the bit or register offset.
Signed-off-by: Chen-Yu Tsai <wens@csie.org>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
diff --git a/drivers/power/axp221.c b/drivers/power/axp221.c
index cb1f88b..727ab09 100644
--- a/drivers/power/axp221.c
+++ b/drivers/power/axp221.c
@@ -191,33 +191,20 @@
{
int ret;
u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
- u8 addr, bits;
- switch (eldo_num) {
- case 3:
- addr = AXP221_ELDO3_CTRL;
- bits = AXP221_OUTPUT_CTRL2_ELDO3_EN;
- break;
- case 2:
- addr = AXP221_ELDO2_CTRL;
- bits = AXP221_OUTPUT_CTRL2_ELDO2_EN;
- break;
- case 1:
- addr = AXP221_ELDO1_CTRL;
- bits = AXP221_OUTPUT_CTRL2_ELDO1_EN;
- break;
- default:
+ if (eldo_num < 1 || eldo_num > 3)
return -EINVAL;
- }
if (mvolt == 0)
- return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2, bits);
+ return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
+ AXP221_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1));
- ret = pmic_bus_write(addr, cfg);
+ ret = pmic_bus_write(AXP221_ELDO1_CTRL + (eldo_num - 1), cfg);
if (ret)
return ret;
- return pmic_bus_setbits(AXP221_OUTPUT_CTRL2, bits);
+ return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
+ AXP221_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1));
}
int axp_init(void)