From: Olliver Schinagl <[email protected]>

The AXP209 has a few 'magisc-ish' values that are better served with
clear defines.

Signed-off-by: Olliver Schinagl <[email protected]>
Signed-off-by: Priit Laes <[email protected]>
Acked-by: Maxime Ripard <[email protected]>
---
 drivers/power/axp209.c | 14 +++++++-------
 include/axp209.h       | 13 +++++++++++++
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/power/axp209.c b/drivers/power/axp209.c
index e13c762..819b168 100644
--- a/drivers/power/axp209.c
+++ b/drivers/power/axp209.c
@@ -81,8 +81,7 @@ int axp_set_aldo2(unsigned int mvolt)
        if (rc)
                return rc;
 
-       /* LDO2 configuration is in upper 4 bits */
-       reg = (reg & 0x0f) | (cfg << 4);
+       reg |= AXP209_LDO24_LDO2_SET(reg, cfg);
        rc = pmic_bus_write(AXP209_LDO24_VOLTAGE, reg);
        if (rc)
                return rc;
@@ -99,10 +98,12 @@ int axp_set_aldo3(unsigned int mvolt)
                return pmic_bus_clrbits(AXP209_OUTPUT_CTRL,
                                        AXP209_OUTPUT_CTRL_LDO3);
 
-       if (mvolt == -1)
-               cfg = 0x80;     /* determined by LDO3IN pin */
-       else
+       if (mvolt == -1) {
+               cfg = AXP209_LDO3_VOLTAGE_FROM_LDO3IN;
+       } else {
                cfg = axp209_mvolt_to_cfg(mvolt, 700, 3500, 25);
+               cfg = AXP209_LDO3_VOLTAGE_SET(cfg);
+       }
 
        rc = pmic_bus_write(AXP209_LDO3_VOLTAGE, cfg);
        if (rc)
@@ -131,8 +132,7 @@ int axp_set_aldo4(unsigned int mvolt)
        if (rc)
                return rc;
 
-       /* LDO4 configuration is in lower 4 bits */
-       reg = (reg & 0xf0) | (cfg << 0);
+       reg |= AXP209_LDO24_LDO4_SET(reg, cfg);
        rc = pmic_bus_write(AXP209_LDO24_VOLTAGE, reg);
        if (rc)
                return rc;
diff --git a/include/axp209.h b/include/axp209.h
index 43e3873..dc27d65 100644
--- a/include/axp209.h
+++ b/include/axp209.h
@@ -34,6 +34,19 @@ enum axp209_reg {
 #define AXP209_OUTPUT_CTRL_DCDC2       BIT(4)
 #define AXP209_OUTPUT_CTRL_LDO3                BIT(6)
 
+#define AXP209_LDO24_LDO2_MASK         0xf0
+#define AXP209_LDO24_LDO4_MASK         0x0f
+#define AXP209_LDO24_LDO2_SET(reg, cfg)        \
+       (((reg) & ~AXP209_LDO24_LDO2_MASK) | \
+       (((cfg) << 4) & AXP209_LDO24_LDO2_MASK))
+#define AXP209_LDO24_LDO4_SET(reg, cfg)        \
+       (((reg) & ~AXP209_LDO24_LDO4_MASK) | \
+       (((cfg) << 0) & AXP209_LDO24_LDO4_MASK))
+
+#define AXP209_LDO3_VOLTAGE_FROM_LDO3IN        BIT(7)
+#define AXP209_LDO3_VOLTAGE_MASK       0x7f
+#define AXP209_LDO3_VOLTAGE_SET(x)     ((x) & AXP209_LDO3_VOLTAGE_MASK)
+
 #define AXP209_IRQ5_PEK_UP             BIT(6)
 #define AXP209_IRQ5_PEK_DOWN           BIT(5)
 
-- 
git-series 0.9.1

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to