1 // SPDX-License-Identifier: GPL-2.0+
3 * AXP221 and AXP223 driver
5 * IMPORTANT when making changes to this file check that the registers
6 * used are the same for the axp221 and axp223.
8 * (C) Copyright 2014 Hans de Goede <hdegoede@redhat.com>
9 * (C) Copyright 2013 Oliver Schinagl <oliver@schinagl.nl>
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_aldo1(unsigned int mvolt
)
121 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
124 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
125 AXP221_OUTPUT_CTRL1_ALDO1_EN
);
127 ret
= pmic_bus_write(AXP221_ALDO1_CTRL
, cfg
);
131 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
132 AXP221_OUTPUT_CTRL1_ALDO1_EN
);
135 int axp_set_aldo2(unsigned int mvolt
)
138 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
141 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL1
,
142 AXP221_OUTPUT_CTRL1_ALDO2_EN
);
144 ret
= pmic_bus_write(AXP221_ALDO2_CTRL
, cfg
);
148 return pmic_bus_setbits(AXP221_OUTPUT_CTRL1
,
149 AXP221_OUTPUT_CTRL1_ALDO2_EN
);
152 int axp_set_aldo3(unsigned int mvolt
)
155 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
158 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL3
,
159 AXP221_OUTPUT_CTRL3_ALDO3_EN
);
161 ret
= pmic_bus_write(AXP221_ALDO3_CTRL
, cfg
);
165 return pmic_bus_setbits(AXP221_OUTPUT_CTRL3
,
166 AXP221_OUTPUT_CTRL3_ALDO3_EN
);
169 int axp_set_dldo(int dldo_num
, unsigned int mvolt
)
171 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
174 if (dldo_num
< 1 || dldo_num
> 4)
178 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2
,
179 AXP221_OUTPUT_CTRL2_DLDO1_EN
<< (dldo_num
- 1));
181 ret
= pmic_bus_write(AXP221_DLDO1_CTRL
+ (dldo_num
- 1), cfg
);
185 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2
,
186 AXP221_OUTPUT_CTRL2_DLDO1_EN
<< (dldo_num
- 1));
189 int axp_set_eldo(int eldo_num
, unsigned int mvolt
)
192 u8 cfg
= axp221_mvolt_to_cfg(mvolt
, 700, 3300, 100);
194 if (eldo_num
< 1 || eldo_num
> 3)
198 return pmic_bus_clrbits(AXP221_OUTPUT_CTRL2
,
199 AXP221_OUTPUT_CTRL2_ELDO1_EN
<< (eldo_num
- 1));
201 ret
= pmic_bus_write(AXP221_ELDO1_CTRL
+ (eldo_num
- 1), cfg
);
205 return pmic_bus_setbits(AXP221_OUTPUT_CTRL2
,
206 AXP221_OUTPUT_CTRL2_ELDO1_EN
<< (eldo_num
- 1));
214 ret
= pmic_bus_init();
218 ret
= pmic_bus_read(AXP221_CHIP_ID
, &axp_chip_id
);
222 if (!(axp_chip_id
== 0x6 || axp_chip_id
== 0x7 || axp_chip_id
== 0x17))
226 * Turn off LDOIO regulators / tri-state GPIO pins, when rebooting
227 * from android these are sometimes on.
229 ret
= pmic_bus_write(AXP_GPIO0_CTRL
, AXP_GPIO_CTRL_INPUT
);
233 ret
= pmic_bus_write(AXP_GPIO1_CTRL
, AXP_GPIO_CTRL_INPUT
);
240 int axp_get_sid(unsigned int *sid
)
242 u8
*dest
= (u8
*)sid
;
245 ret
= pmic_bus_init();
249 ret
= pmic_bus_write(AXP221_PAGE
, 1);
253 for (i
= 0; i
< 16; i
++) {
254 ret
= pmic_bus_read(AXP221_SID
+ i
, &dest
[i
]);
259 pmic_bus_write(AXP221_PAGE
, 0);
261 for (i
= 0; i
< 4; i
++)
262 sid
[i
] = be32_to_cpu(sid
[i
]);
267 int do_poweroff(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
269 pmic_bus_write(AXP221_SHUTDOWN
, AXP221_SHUTDOWN_POWEROFF
);
271 /* infinite loop during shutdown */