Browse Source

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

Merlijn Wajer 4 years ago
parent
commit
573f0762e8
2 changed files with 18 additions and 6 deletions
  1. 4 6
      drivers/power/axp209.c
  2. 14 0
      include/axp209.h

+ 4 - 6
drivers/power/axp209.c

@@ -81,8 +81,7 @@ int axp_set_aldo2(unsigned int mvolt)
81 81
 	if (rc)
82 82
 		return rc;
83 83
 
84
-	/* LDO2 configuration is in upper 4 bits */
85
-	reg = (reg & 0x0f) | (cfg << 4);
84
+	reg |= AXP209_LDO24_LDO2_SET(reg, cfg);
86 85
 	rc = pmic_bus_write(AXP209_LDO24_VOLTAGE, reg);
87 86
 	if (rc)
88 87
 		return rc;
@@ -100,9 +99,9 @@ int axp_set_aldo3(unsigned int mvolt)
100 99
 					AXP209_OUTPUT_CTRL_LDO3);
101 100
 
102 101
 	if (mvolt == -1)
103
-		cfg = 0x80;	/* determined by LDO3IN pin */
102
+		cfg = AXP209_LDO3_VOLTAGE_FROM_LDO3IN;
104 103
 	else
105
-		cfg = axp209_mvolt_to_cfg(mvolt, 700, 3500, 25);
104
+		cfg = AXP209_LDO3_VOLTAGE_SET(axp209_mvolt_to_cfg(mvolt, 700, 3500, 25));
106 105
 
107 106
 	rc = pmic_bus_write(AXP209_LDO3_VOLTAGE, cfg);
108 107
 	if (rc)
@@ -131,8 +130,7 @@ int axp_set_aldo4(unsigned int mvolt)
131 130
 	if (rc)
132 131
 		return rc;
133 132
 
134
-	/* LDO4 configuration is in lower 4 bits */
135
-	reg = (reg & 0xf0) | (cfg << 0);
133
+	reg |= AXP209_LDO24_LDO4_SET(reg, cfg);
136 134
 	rc = pmic_bus_write(AXP209_LDO24_VOLTAGE, reg);
137 135
 	if (rc)
138 136
 		return rc;

+ 14 - 0
include/axp209.h

@@ -34,6 +34,20 @@ enum axp209_reg {
34 34
 #define AXP209_OUTPUT_CTRL_DCDC2	BIT(4)
35 35
 #define AXP209_OUTPUT_CTRL_LDO3		BIT(6)
36 36
 
37
+#define AXP209_LDO24_LDO2_MASK		0xf0
38
+#define AXP209_LDO24_LDO4_MASK		0x0f
39
+#define AXP209_LDO24_LDO2_SET(reg, cfg)	\
40
+	(((reg) & ~AXP209_LDO24_LDO2_MASK) | \
41
+	(((cfg) << 4) & AXP209_LDO24_LDO2_MASK))
42
+#define AXP209_LDO24_LDO4_SET(reg, cfg)	\
43
+	(((reg) & ~AXP209_LDO24_LDO4_MASK) | \
44
+	(((cfg) << 0) & AXP209_LDO24_LDO4_MASK))
45
+
46
+
47
+#define AXP209_LDO3_VOLTAGE_FROM_LDO3IN	BIT(7)
48
+#define AXP209_LDO3_VOLTAGE_MASK	0x7f
49
+#define AXP209_LDO3_VOLTAGE_SET(x)	((x) & AXP209_LDO3_VOLTAGE_MASK)
50
+
37 51
 #define AXP209_IRQ5_PEK_UP		BIT(6)
38 52
 #define AXP209_IRQ5_PEK_DOWN		BIT(5)
39 53