2 * AXP221 and AXP223 driver
4 * IMPORTANT when making changes to this file check that the registers
5 * used are the same for the axp221 and axp223.
7 * (C) Copyright 2014 Hans de Goede <hdegoede@redhat.com>
8 * (C) Copyright 2013 Oliver Schinagl <oliver@schinagl.nl>
10 * SPDX-License-Identifier: GPL-2.0+
15 #include <asm/arch/pmic_bus.h>
18 static u8 axp221_mvolt_to_cfg(int mvolt, int min, int max, int div)
25 return (mvolt - min) / div;
28 int axp_set_dcdc1(unsigned int mvolt)
31 u8 cfg = axp221_mvolt_to_cfg(mvolt, 1600, 3400, 100);
34 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1,
35 AXP221_OUTPUT_CTRL1_DCDC1_EN);
37 ret = pmic_bus_write(AXP221_DCDC1_CTRL, cfg);
41 ret = pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
42 AXP221_OUTPUT_CTRL2_DCDC1SW_EN);
46 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1,
47 AXP221_OUTPUT_CTRL1_DCDC1_EN);
50 int axp_set_dcdc2(unsigned int mvolt)
53 u8 cfg = axp221_mvolt_to_cfg(mvolt, 600, 1540, 20);
56 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1,
57 AXP221_OUTPUT_CTRL1_DCDC2_EN);
59 ret = pmic_bus_write(AXP221_DCDC2_CTRL, cfg);
63 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1,
64 AXP221_OUTPUT_CTRL1_DCDC2_EN);
67 int axp_set_dcdc3(unsigned int mvolt)
70 u8 cfg = axp221_mvolt_to_cfg(mvolt, 600, 1860, 20);
73 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1,
74 AXP221_OUTPUT_CTRL1_DCDC3_EN);
76 ret = pmic_bus_write(AXP221_DCDC3_CTRL, cfg);
80 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1,
81 AXP221_OUTPUT_CTRL1_DCDC3_EN);
84 int axp_set_dcdc4(unsigned int mvolt)
87 u8 cfg = axp221_mvolt_to_cfg(mvolt, 600, 1540, 20);
90 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1,
91 AXP221_OUTPUT_CTRL1_DCDC4_EN);
93 ret = pmic_bus_write(AXP221_DCDC4_CTRL, cfg);
97 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1,
98 AXP221_OUTPUT_CTRL1_DCDC4_EN);
101 int axp_set_dcdc5(unsigned int mvolt)
104 u8 cfg = axp221_mvolt_to_cfg(mvolt, 1000, 2550, 50);
107 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1,
108 AXP221_OUTPUT_CTRL1_DCDC5_EN);
110 ret = pmic_bus_write(AXP221_DCDC5_CTRL, cfg);
114 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1,
115 AXP221_OUTPUT_CTRL1_DCDC5_EN);
118 int axp_set_dldo1(unsigned int mvolt)
121 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
124 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
125 AXP221_OUTPUT_CTRL2_DLDO1_EN);
127 ret = pmic_bus_write(AXP221_DLDO1_CTRL, cfg);
131 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
132 AXP221_OUTPUT_CTRL2_DLDO1_EN);
135 int axp_set_dldo2(unsigned int mvolt)
138 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
141 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
142 AXP221_OUTPUT_CTRL2_DLDO2_EN);
144 ret = pmic_bus_write(AXP221_DLDO2_CTRL, cfg);
148 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
149 AXP221_OUTPUT_CTRL2_DLDO2_EN);
152 int axp_set_dldo3(unsigned int mvolt)
155 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
158 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
159 AXP221_OUTPUT_CTRL2_DLDO3_EN);
161 ret = pmic_bus_write(AXP221_DLDO3_CTRL, cfg);
165 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
166 AXP221_OUTPUT_CTRL2_DLDO3_EN);
169 int axp_set_dldo4(unsigned int mvolt)
172 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
175 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2,
176 AXP221_OUTPUT_CTRL2_DLDO4_EN);
178 ret = pmic_bus_write(AXP221_DLDO4_CTRL, cfg);
182 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2,
183 AXP221_OUTPUT_CTRL2_DLDO4_EN);
186 int axp_set_aldo1(unsigned int mvolt)
189 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
192 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1,
193 AXP221_OUTPUT_CTRL1_ALDO1_EN);
195 ret = pmic_bus_write(AXP221_ALDO1_CTRL, cfg);
199 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1,
200 AXP221_OUTPUT_CTRL1_ALDO1_EN);
203 int axp_set_aldo2(unsigned int mvolt)
206 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
209 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1,
210 AXP221_OUTPUT_CTRL1_ALDO2_EN);
212 ret = pmic_bus_write(AXP221_ALDO2_CTRL, cfg);
216 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1,
217 AXP221_OUTPUT_CTRL1_ALDO2_EN);
220 int axp_set_aldo3(unsigned int mvolt)
223 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
226 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL3,
227 AXP221_OUTPUT_CTRL3_ALDO3_EN);
229 ret = pmic_bus_write(AXP221_ALDO3_CTRL, cfg);
233 return pmic_bus_setbits(AXP221_OUTPUT_CTRL3,
234 AXP221_OUTPUT_CTRL3_ALDO3_EN);
237 int axp_set_eldo(int eldo_num, unsigned int mvolt)
240 u8 cfg = axp221_mvolt_to_cfg(mvolt, 700, 3300, 100);
245 addr = AXP221_ELDO3_CTRL;
246 bits = AXP221_OUTPUT_CTRL2_ELDO3_EN;
249 addr = AXP221_ELDO2_CTRL;
250 bits = AXP221_OUTPUT_CTRL2_ELDO2_EN;
253 addr = AXP221_ELDO1_CTRL;
254 bits = AXP221_OUTPUT_CTRL2_ELDO1_EN;
261 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2, bits);
263 ret = pmic_bus_write(addr, cfg);
267 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2, bits);
275 ret = pmic_bus_init();
279 ret = pmic_bus_read(AXP221_CHIP_ID, &axp_chip_id);
283 if (!(axp_chip_id == 0x6 || axp_chip_id == 0x7 || axp_chip_id == 0x17))
289 int axp_get_sid(unsigned int *sid)
291 u8 *dest = (u8 *)sid;
294 ret = pmic_bus_init();
298 ret = pmic_bus_write(AXP221_PAGE, 1);
302 for (i = 0; i < 16; i++) {
303 ret = pmic_bus_read(AXP221_SID + i, &dest[i]);
308 pmic_bus_write(AXP221_PAGE, 0);
310 for (i = 0; i < 4; i++)
311 sid[i] = be32_to_cpu(sid[i]);