2 * AXP809 driver based on AXP221 driver
5 * (C) Copyright 2016 Chen-Yu Tsai <wens@csie.org>
8 * (C) Copyright 2014 Hans de Goede <hdegoede@redhat.com>
9 * (C) Copyright 2013 Oliver Schinagl <oliver@schinagl.nl>
11 * SPDX-License-Identifier: GPL-2.0+
16 #include <asm/arch/gpio.h>
17 #include <asm/arch/pmic_bus.h>
20 static u8 axp809_mvolt_to_cfg(int mvolt, int min, int max, int div)
27 return (mvolt - min) / div;
30 int axp_set_dcdc1(unsigned int mvolt)
33 u8 cfg = axp809_mvolt_to_cfg(mvolt, 1600, 3400, 100);
36 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL1,
37 AXP809_OUTPUT_CTRL1_DCDC1_EN);
39 ret = pmic_bus_write(AXP809_DCDC1_CTRL, cfg);
43 ret = pmic_bus_setbits(AXP809_OUTPUT_CTRL2,
44 AXP809_OUTPUT_CTRL2_DC1SW_EN);
48 return pmic_bus_setbits(AXP809_OUTPUT_CTRL1,
49 AXP809_OUTPUT_CTRL1_DCDC1_EN);
52 int axp_set_dcdc2(unsigned int mvolt)
55 u8 cfg = axp809_mvolt_to_cfg(mvolt, 600, 1540, 20);
58 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL1,
59 AXP809_OUTPUT_CTRL1_DCDC2_EN);
61 ret = pmic_bus_write(AXP809_DCDC2_CTRL, cfg);
65 return pmic_bus_setbits(AXP809_OUTPUT_CTRL1,
66 AXP809_OUTPUT_CTRL1_DCDC2_EN);
69 int axp_set_dcdc3(unsigned int mvolt)
72 u8 cfg = axp809_mvolt_to_cfg(mvolt, 600, 1860, 20);
75 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL1,
76 AXP809_OUTPUT_CTRL1_DCDC3_EN);
78 ret = pmic_bus_write(AXP809_DCDC3_CTRL, cfg);
82 return pmic_bus_setbits(AXP809_OUTPUT_CTRL1,
83 AXP809_OUTPUT_CTRL1_DCDC3_EN);
86 int axp_set_dcdc4(unsigned int mvolt)
89 u8 cfg = axp809_mvolt_to_cfg(mvolt, 600, 1540, 20);
92 cfg = 0x30 + axp809_mvolt_to_cfg(mvolt, 1800, 2600, 100);
95 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL1,
96 AXP809_OUTPUT_CTRL1_DCDC4_EN);
98 ret = pmic_bus_write(AXP809_DCDC5_CTRL, cfg);
102 return pmic_bus_setbits(AXP809_OUTPUT_CTRL1,
103 AXP809_OUTPUT_CTRL1_DCDC4_EN);
106 int axp_set_dcdc5(unsigned int mvolt)
109 u8 cfg = axp809_mvolt_to_cfg(mvolt, 1000, 2550, 50);
112 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL1,
113 AXP809_OUTPUT_CTRL1_DCDC5_EN);
115 ret = pmic_bus_write(AXP809_DCDC5_CTRL, cfg);
119 return pmic_bus_setbits(AXP809_OUTPUT_CTRL1,
120 AXP809_OUTPUT_CTRL1_DCDC5_EN);
123 int axp_set_aldo(int aldo_num, unsigned int mvolt)
128 if (aldo_num < 1 || aldo_num > 3)
131 if (mvolt == 0 && aldo_num == 3)
132 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL2,
133 AXP809_OUTPUT_CTRL2_ALDO3_EN);
135 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL1,
136 AXP809_OUTPUT_CTRL1_ALDO1_EN << (aldo_num - 1));
138 cfg = axp809_mvolt_to_cfg(mvolt, 700, 3300, 100);
139 ret = pmic_bus_write(AXP809_ALDO1_CTRL + (aldo_num - 1), cfg);
144 return pmic_bus_setbits(AXP809_OUTPUT_CTRL2,
145 AXP809_OUTPUT_CTRL2_ALDO3_EN);
146 return pmic_bus_setbits(AXP809_OUTPUT_CTRL1,
147 AXP809_OUTPUT_CTRL1_ALDO1_EN << (aldo_num - 1));
150 /* TODO: re-work other AXP drivers to consolidate ALDO functions. */
151 int axp_set_aldo1(unsigned int mvolt)
153 return axp_set_aldo(1, mvolt);
156 int axp_set_aldo2(unsigned int mvolt)
158 return axp_set_aldo(2, mvolt);
161 int axp_set_aldo3(unsigned int mvolt)
163 return axp_set_aldo(3, mvolt);
166 int axp_set_dldo(int dldo_num, unsigned int mvolt)
168 u8 cfg = axp809_mvolt_to_cfg(mvolt, 700, 3300, 100);
171 if (dldo_num < 1 || dldo_num > 2)
175 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL2,
176 AXP809_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1));
178 if (dldo_num == 1 && mvolt > 3300)
179 cfg += 1 + axp809_mvolt_to_cfg(mvolt, 3400, 4200, 200);
180 ret = pmic_bus_write(AXP809_DLDO1_CTRL + (dldo_num - 1), cfg);
184 return pmic_bus_setbits(AXP809_OUTPUT_CTRL2,
185 AXP809_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1));
188 int axp_set_eldo(int eldo_num, unsigned int mvolt)
191 u8 cfg = axp809_mvolt_to_cfg(mvolt, 700, 3300, 100);
193 if (eldo_num < 1 || eldo_num > 3)
197 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL2,
198 AXP809_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1));
200 ret = pmic_bus_write(AXP809_ELDO1_CTRL + (eldo_num - 1), cfg);
204 return pmic_bus_setbits(AXP809_OUTPUT_CTRL2,
205 AXP809_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1));
208 int axp_set_sw(bool on)
211 return pmic_bus_setbits(AXP809_OUTPUT_CTRL2,
212 AXP809_OUTPUT_CTRL2_SWOUT_EN);
214 return pmic_bus_clrbits(AXP809_OUTPUT_CTRL2,
215 AXP809_OUTPUT_CTRL2_SWOUT_EN);
220 return pmic_bus_init();
223 int do_poweroff(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
225 pmic_bus_write(AXP809_SHUTDOWN, AXP809_SHUTDOWN_POWEROFF);
227 /* infinite loop during shutdown */