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+
16 #include <asm/arch/pmic_bus.h>
19 static u8
axp221_mvolt_to_cfg(int mvolt
, int min
, int max
, int div
)
26 return (mvolt
- min
) / div
;
29 int axp_set_dcdc1(unsigned int mvolt
)
32 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 1600, 3400, 100);
35 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
36 AXP221_OUTPUT_CTRL1_DCDC1_EN
);
38 ret
= pmic_bus_write(AXP221_DCDC1_CTRL
, cfg
);
42 ret
= pmic_bus_setbits(AXP221_OUTPUT_CTRL2
,
43 AXP221_OUTPUT_CTRL2_DCDC1SW_EN
);
47 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
48 AXP221_OUTPUT_CTRL1_DCDC1_EN
);
51 int axp_set_dcdc2(unsigned int mvolt
)
54 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 600, 1540, 20);
57 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
58 AXP221_OUTPUT_CTRL1_DCDC2_EN
);
60 ret
= pmic_bus_write(AXP221_DCDC2_CTRL
, cfg
);
64 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
65 AXP221_OUTPUT_CTRL1_DCDC2_EN
);
68 int axp_set_dcdc3(unsigned int mvolt
)
71 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 600, 1860, 20);
74 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
75 AXP221_OUTPUT_CTRL1_DCDC3_EN
);
77 ret
= pmic_bus_write(AXP221_DCDC3_CTRL
, cfg
);
81 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
82 AXP221_OUTPUT_CTRL1_DCDC3_EN
);
85 int axp_set_dcdc4(unsigned int mvolt
)
88 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 600, 1540, 20);
91 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
92 AXP221_OUTPUT_CTRL1_DCDC4_EN
);
94 ret
= pmic_bus_write(AXP221_DCDC4_CTRL
, cfg
);
98 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
99 AXP221_OUTPUT_CTRL1_DCDC4_EN
);
102 int axp_set_dcdc5(unsigned int mvolt
)
105 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 1000, 2550, 50);
108 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
109 AXP221_OUTPUT_CTRL1_DCDC5_EN
);
111 ret
= pmic_bus_write(AXP221_DCDC5_CTRL
, cfg
);
115 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
116 AXP221_OUTPUT_CTRL1_DCDC5_EN
);
119 int axp_set_dldo1(unsigned int mvolt
)
122 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
125 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2
,
126 AXP221_OUTPUT_CTRL2_DLDO1_EN
);
128 ret
= pmic_bus_write(AXP221_DLDO1_CTRL
, cfg
);
132 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2
,
133 AXP221_OUTPUT_CTRL2_DLDO1_EN
);
136 int axp_set_dldo2(unsigned int mvolt
)
139 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
142 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2
,
143 AXP221_OUTPUT_CTRL2_DLDO2_EN
);
145 ret
= pmic_bus_write(AXP221_DLDO2_CTRL
, cfg
);
149 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2
,
150 AXP221_OUTPUT_CTRL2_DLDO2_EN
);
153 int axp_set_dldo3(unsigned int mvolt
)
156 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
159 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2
,
160 AXP221_OUTPUT_CTRL2_DLDO3_EN
);
162 ret
= pmic_bus_write(AXP221_DLDO3_CTRL
, cfg
);
166 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2
,
167 AXP221_OUTPUT_CTRL2_DLDO3_EN
);
170 int axp_set_dldo4(unsigned int mvolt
)
173 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
176 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2
,
177 AXP221_OUTPUT_CTRL2_DLDO4_EN
);
179 ret
= pmic_bus_write(AXP221_DLDO4_CTRL
, cfg
);
183 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2
,
184 AXP221_OUTPUT_CTRL2_DLDO4_EN
);
187 int axp_set_aldo1(unsigned int mvolt
)
190 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
193 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
194 AXP221_OUTPUT_CTRL1_ALDO1_EN
);
196 ret
= pmic_bus_write(AXP221_ALDO1_CTRL
, cfg
);
200 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
201 AXP221_OUTPUT_CTRL1_ALDO1_EN
);
204 int axp_set_aldo2(unsigned int mvolt
)
207 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
210 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
211 AXP221_OUTPUT_CTRL1_ALDO2_EN
);
213 ret
= pmic_bus_write(AXP221_ALDO2_CTRL
, cfg
);
217 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
218 AXP221_OUTPUT_CTRL1_ALDO2_EN
);
221 int axp_set_aldo3(unsigned int mvolt
)
224 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
227 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL3
,
228 AXP221_OUTPUT_CTRL3_ALDO3_EN
);
230 ret
= pmic_bus_write(AXP221_ALDO3_CTRL
, cfg
);
234 return pmic_bus_setbits(AXP221_OUTPUT_CTRL3
,
235 AXP221_OUTPUT_CTRL3_ALDO3_EN
);
238 int axp_set_eldo(int eldo_num
, unsigned int mvolt
)
241 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
246 addr
= AXP221_ELDO3_CTRL
;
247 bits
= AXP221_OUTPUT_CTRL2_ELDO3_EN
;
250 addr
= AXP221_ELDO2_CTRL
;
251 bits
= AXP221_OUTPUT_CTRL2_ELDO2_EN
;
254 addr
= AXP221_ELDO1_CTRL
;
255 bits
= AXP221_OUTPUT_CTRL2_ELDO1_EN
;
262 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2
, bits
);
264 ret
= pmic_bus_write(addr
, cfg
);
268 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2
, bits
);
276 ret
= pmic_bus_init();
280 ret
= pmic_bus_read(AXP221_CHIP_ID
, &axp_chip_id
);
284 if (!(axp_chip_id
== 0x6 || axp_chip_id
== 0x7 || axp_chip_id
== 0x17))
290 int axp_get_sid(unsigned int *sid
)
292 u8
*dest
= (u8
*)sid
;
295 ret
= pmic_bus_init();
299 ret
= pmic_bus_write(AXP221_PAGE
, 1);
303 for (i
= 0; i
< 16; i
++) {
304 ret
= pmic_bus_read(AXP221_SID
+ i
, &dest
[i
]);
309 pmic_bus_write(AXP221_PAGE
, 0);
311 for (i
= 0; i
< 4; i
++)
312 sid
[i
] = be32_to_cpu(sid
[i
]);
317 int do_poweroff(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
319 pmic_bus_write(AXP221_SHUTDOWN
, AXP221_SHUTDOWN_POWEROFF
);
321 /* infinite loop during shutdown */