Commit 50e0d5e60b0a4c2c9de5ba332be1c36a31d728d3

Authored by Hans de Goede
1 parent 1262a85fe3

sunxi: axp221: Explicitly turn off unused voltages

Explicitly turn off unused voltages, rather then leaving them as is. Likewise
explictly enabled the dcdc convertors, rather then assuming they are already
enabled at boot.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Ian Campbell <ijc@hellion.org.uk>

Showing 4 changed files with 111 additions and 25 deletions Side-by-side Diff

... ... @@ -180,21 +180,11 @@
180 180 power_failed |= axp221_set_dcdc3(1200);
181 181 power_failed |= axp221_set_dcdc4(1200);
182 182 power_failed |= axp221_set_dcdc5(1500);
183   -#if CONFIG_AXP221_DLDO1_VOLT != -1
184 183 power_failed |= axp221_set_dldo1(CONFIG_AXP221_DLDO1_VOLT);
185   -#endif
186   -#if CONFIG_AXP221_DLDO4_VOLT != -1
187 184 power_failed |= axp221_set_dldo4(CONFIG_AXP221_DLDO4_VOLT);
188   -#endif
189   -#if CONFIG_AXP221_ALDO1_VOLT != -1
190 185 power_failed |= axp221_set_aldo1(CONFIG_AXP221_ALDO1_VOLT);
191   -#endif
192   -#if CONFIG_AXP221_ALDO2_VOLT != -1
193 186 power_failed |= axp221_set_aldo2(CONFIG_AXP221_ALDO2_VOLT);
194   -#endif
195   -#if CONFIG_AXP221_ALDO3_VOLT != -1
196 187 power_failed |= axp221_set_aldo3(CONFIG_AXP221_ALDO3_VOLT);
197   -#endif
198 188 #endif
199 189  
200 190 printf("DRAM:");
drivers/power/Kconfig
... ... @@ -19,9 +19,9 @@
19 19 config AXP221_DLDO1_VOLT
20 20 int "axp221 dldo1 voltage"
21 21 depends on AXP221_POWER
22   - default -1
  22 + default 0
23 23 ---help---
24   - Set the voltage (mV) to program the axp221 dldo1 at, set to -1 to
  24 + Set the voltage (mV) to program the axp221 dldo1 at, set to 0 to
25 25 disable dldo1. On sun6i (A31) boards with ethernet this is often used
26 26 to power the ethernet phy. On sun8i (A23) boards this is often used to
27 27 power the wifi.
28 28  
29 29  
30 30  
... ... @@ -29,17 +29,17 @@
29 29 config AXP221_DLDO4_VOLT
30 30 int "axp221 dldo4 voltage"
31 31 depends on AXP221_POWER
32   - default -1
  32 + default 0
33 33 ---help---
34   - Set the voltage (mV) to program the axp221 dldo4 at, set to -1 to
  34 + Set the voltage (mV) to program the axp221 dldo4 at, set to 0 to
35 35 disable dldo4.
36 36  
37 37 config AXP221_ALDO1_VOLT
38 38 int "axp221 aldo1 voltage"
39 39 depends on AXP221_POWER
40   - default -1
  40 + default 0
41 41 ---help---
42   - Set the voltage (mV) to program the axp221 aldo1 at, set to -1 to
  42 + Set the voltage (mV) to program the axp221 aldo1 at, set to 0 to
43 43 disable aldo1. On sun6i (A31) boards which have a wifi module this is
44 44 often used to power the wifi module.
45 45  
... ... @@ -49,7 +49,7 @@
49 49 default 1800 if MACH_SUN6I
50 50 default 2500 if MACH_SUN8I
51 51 ---help---
52   - Set the voltage (mV) to program the axp221 aldo2 at, set to -1 to
  52 + Set the voltage (mV) to program the axp221 aldo2 at, set to 0 to
53 53 disable aldo2. On sun6i (A31) boards this is typically connected to
54 54 VCC-PM, which powers the port M gpios, and should be set to 1.8V.
55 55 On sun8i (A23) this is typically connected to VDD-DLL and must be
... ... @@ -60,7 +60,7 @@
60 60 depends on AXP221_POWER
61 61 default 3000
62 62 ---help---
63   - Set the voltage (mV) to program the axp221 aldo3 at, set to -1 to
  63 + Set the voltage (mV) to program the axp221 aldo3 at, set to 0 to
64 64 disable aldo3. This is typically connected to VCC-PLL and AVCC and
65 65 must be set to 3V.
drivers/power/axp221.c
... ... @@ -80,45 +80,107 @@
80 80 return pmic_bus_write(reg, val);
81 81 }
82 82  
  83 +static int axp221_clrbits(u8 reg, u8 bits)
  84 +{
  85 + int ret;
  86 + u8 val;
  87 +
  88 + ret = pmic_bus_read(reg, &val);
  89 + if (ret)
  90 + return ret;
  91 +
  92 + val &= ~bits;
  93 + return pmic_bus_write(reg, val);
  94 +}
  95 +
83 96 int axp221_set_dcdc1(unsigned int mvolt)
84 97 {
85 98 int ret;
86 99 u8 cfg = axp221_mvolt_to_cfg(mvolt, 1600, 3400, 100);
87 100  
  101 + if (mvolt == 0)
  102 + return axp221_clrbits(AXP221_OUTPUT_CTRL1,
  103 + AXP221_OUTPUT_CTRL1_DCDC1_EN);
  104 +
88 105 ret = pmic_bus_write(AXP221_DCDC1_CTRL, cfg);
89 106 if (ret)
90 107 return ret;
91 108  
92   - return axp221_setbits(AXP221_OUTPUT_CTRL2,
93   - AXP221_OUTPUT_CTRL2_DCDC1_EN);
  109 + ret = axp221_setbits(AXP221_OUTPUT_CTRL2,
  110 + AXP221_OUTPUT_CTRL2_DCDC1SW_EN);
  111 + if (ret)
  112 + return ret;
  113 +
  114 + return axp221_setbits(AXP221_OUTPUT_CTRL1,
  115 + AXP221_OUTPUT_CTRL1_DCDC1_EN);
94 116 }
95 117  
96 118 int axp221_set_dcdc2(unsigned int mvolt)
97 119 {
  120 + int ret;
98 121 u8 cfg = axp221_mvolt_to_cfg(mvolt, 600, 1540, 20);
99 122  
100   - return pmic_bus_write(AXP221_DCDC2_CTRL, cfg);
  123 + if (mvolt == 0)
  124 + return axp221_clrbits(AXP221_OUTPUT_CTRL1,
  125 + AXP221_OUTPUT_CTRL1_DCDC2_EN);
  126 +
  127 + ret = pmic_bus_write(AXP221_DCDC2_CTRL, cfg);
  128 + if (ret)
  129 + return ret;
  130 +
  131 + return axp221_setbits(AXP221_OUTPUT_CTRL1,
  132 + AXP221_OUTPUT_CTRL1_DCDC2_EN);
101 133 }
102 134  
103 135 int axp221_set_dcdc3(unsigned int mvolt)
104 136 {
  137 + int ret;
105 138 u8 cfg = axp221_mvolt_to_cfg(mvolt, 600, 1860, 20);
106 139  
107   - return pmic_bus_write(AXP221_DCDC3_CTRL, cfg);
  140 + if (mvolt == 0)
  141 + return axp221_clrbits(AXP221_OUTPUT_CTRL1,
  142 + AXP221_OUTPUT_CTRL1_DCDC3_EN);
  143 +
  144 + ret = pmic_bus_write(AXP221_DCDC3_CTRL, cfg);
  145 + if (ret)
  146 + return ret;
  147 +
  148 + return axp221_setbits(AXP221_OUTPUT_CTRL1,
  149 + AXP221_OUTPUT_CTRL1_DCDC3_EN);
108 150 }
109 151  
110 152 int axp221_set_dcdc4(unsigned int mvolt)
111 153 {
  154 + int ret;
112 155 u8 cfg = axp221_mvolt_to_cfg(mvolt, 600, 1540, 20);
113 156  
114   - return pmic_bus_write(AXP221_DCDC4_CTRL, cfg);
  157 + if (mvolt == 0)
  158 + return axp221_clrbits(AXP221_OUTPUT_CTRL1,
  159 + AXP221_OUTPUT_CTRL1_DCDC4_EN);
  160 +
  161 + ret = pmic_bus_write(AXP221_DCDC4_CTRL, cfg);
  162 + if (ret)
  163 + return ret;
  164 +
  165 + return axp221_setbits(AXP221_OUTPUT_CTRL1,
  166 + AXP221_OUTPUT_CTRL1_DCDC4_EN);
115 167 }
116 168  
117 169 int axp221_set_dcdc5(unsigned int mvolt)
118 170 {
  171 + int ret;
119 172 u8 cfg = axp221_mvolt_to_cfg(mvolt, 1000, 2550, 50);
120 173  
121   - return pmic_bus_write(AXP221_DCDC5_CTRL, cfg);
  174 + if (mvolt == 0)
  175 + return axp221_clrbits(AXP221_OUTPUT_CTRL1,
  176 + AXP221_OUTPUT_CTRL1_DCDC5_EN);
  177 +
  178 + ret = pmic_bus_write(AXP221_DCDC5_CTRL, cfg);
  179 + if (ret)
  180 + return ret;
  181 +
  182 + return axp221_setbits(AXP221_OUTPUT_CTRL1,
  183 + AXP221_OUTPUT_CTRL1_DCDC5_EN);
122 184 }
123 185  
124 186 int axp221_set_dldo1(unsigned int mvolt)
... ... @@ -126,6 +188,10 @@
126 188 int ret;
127 189 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
128 190  
  191 + if (mvolt == 0)
  192 + return axp221_clrbits(AXP221_OUTPUT_CTRL2,
  193 + AXP221_OUTPUT_CTRL2_DLDO1_EN);
  194 +
129 195 ret = pmic_bus_write(AXP221_DLDO1_CTRL, cfg);
130 196 if (ret)
131 197 return ret;
... ... @@ -139,6 +205,10 @@
139 205 int ret;
140 206 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
141 207  
  208 + if (mvolt == 0)
  209 + return axp221_clrbits(AXP221_OUTPUT_CTRL2,
  210 + AXP221_OUTPUT_CTRL2_DLDO2_EN);
  211 +
142 212 ret = pmic_bus_write(AXP221_DLDO2_CTRL, cfg);
143 213 if (ret)
144 214 return ret;
... ... @@ -152,6 +222,10 @@
152 222 int ret;
153 223 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
154 224  
  225 + if (mvolt == 0)
  226 + return axp221_clrbits(AXP221_OUTPUT_CTRL2,
  227 + AXP221_OUTPUT_CTRL2_DLDO3_EN);
  228 +
155 229 ret = pmic_bus_write(AXP221_DLDO3_CTRL, cfg);
156 230 if (ret)
157 231 return ret;
... ... @@ -165,6 +239,10 @@
165 239 int ret;
166 240 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
167 241  
  242 + if (mvolt == 0)
  243 + return axp221_clrbits(AXP221_OUTPUT_CTRL2,
  244 + AXP221_OUTPUT_CTRL2_DLDO4_EN);
  245 +
168 246 ret = pmic_bus_write(AXP221_DLDO4_CTRL, cfg);
169 247 if (ret)
170 248 return ret;
... ... @@ -178,6 +256,10 @@
178 256 int ret;
179 257 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
180 258  
  259 + if (mvolt == 0)
  260 + return axp221_clrbits(AXP221_OUTPUT_CTRL1,
  261 + AXP221_OUTPUT_CTRL1_ALDO1_EN);
  262 +
181 263 ret = pmic_bus_write(AXP221_ALDO1_CTRL, cfg);
182 264 if (ret)
183 265 return ret;
... ... @@ -191,6 +273,10 @@
191 273 int ret;
192 274 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
193 275  
  276 + if (mvolt == 0)
  277 + return axp221_clrbits(AXP221_OUTPUT_CTRL1,
  278 + AXP221_OUTPUT_CTRL1_ALDO2_EN);
  279 +
194 280 ret = pmic_bus_write(AXP221_ALDO2_CTRL, cfg);
195 281 if (ret)
196 282 return ret;
... ... @@ -203,6 +289,10 @@
203 289 {
204 290 int ret;
205 291 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
  292 +
  293 + if (mvolt == 0)
  294 + return axp221_clrbits(AXP221_OUTPUT_CTRL3,
  295 + AXP221_OUTPUT_CTRL3_ALDO3_EN);
206 296  
207 297 ret = pmic_bus_write(AXP221_ALDO3_CTRL, cfg);
208 298 if (ret)
... ... @@ -17,6 +17,12 @@
17 17 /* Page 0 addresses */
18 18 #define AXP221_CHIP_ID 0x03
19 19 #define AXP221_OUTPUT_CTRL1 0x10
  20 +#define AXP221_OUTPUT_CTRL1_DCDC0_EN (1 << 0)
  21 +#define AXP221_OUTPUT_CTRL1_DCDC1_EN (1 << 1)
  22 +#define AXP221_OUTPUT_CTRL1_DCDC2_EN (1 << 2)
  23 +#define AXP221_OUTPUT_CTRL1_DCDC3_EN (1 << 3)
  24 +#define AXP221_OUTPUT_CTRL1_DCDC4_EN (1 << 4)
  25 +#define AXP221_OUTPUT_CTRL1_DCDC5_EN (1 << 5)
20 26 #define AXP221_OUTPUT_CTRL1_ALDO1_EN (1 << 6)
21 27 #define AXP221_OUTPUT_CTRL1_ALDO2_EN (1 << 7)
22 28 #define AXP221_OUTPUT_CTRL2 0x12
... ... @@ -24,7 +30,7 @@
24 30 #define AXP221_OUTPUT_CTRL2_DLDO2_EN (1 << 4)
25 31 #define AXP221_OUTPUT_CTRL2_DLDO3_EN (1 << 5)
26 32 #define AXP221_OUTPUT_CTRL2_DLDO4_EN (1 << 6)
27   -#define AXP221_OUTPUT_CTRL2_DCDC1_EN (1 << 7)
  33 +#define AXP221_OUTPUT_CTRL2_DCDC1SW_EN (1 << 7)
28 34 #define AXP221_OUTPUT_CTRL3 0x13
29 35 #define AXP221_OUTPUT_CTRL3_ALDO3_EN (1 << 7)
30 36 #define AXP221_DLDO1_CTRL 0x15