]>
git.ipfire.org Git - people/ms/u-boot.git/blob - drivers/power/axp209.c
3 * Henrik Nordstrom <henrik@henriknordstrom.net>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <asm/arch/pmic_bus.h>
12 static u8
axp209_mvolt_to_cfg(int mvolt
, int min
, int max
, int div
)
19 return (mvolt
- min
) / div
;
22 int axp_set_dcdc2(unsigned int mvolt
)
28 return pmic_bus_clrbits(AXP209_OUTPUT_CTRL
,
29 AXP209_OUTPUT_CTRL_DCDC2
);
31 rc
= pmic_bus_setbits(AXP209_OUTPUT_CTRL
, AXP209_OUTPUT_CTRL_DCDC2
);
35 cfg
= axp209_mvolt_to_cfg(mvolt
, 700, 2275, 25);
37 /* Do we really need to be this gentle? It has built-in voltage slope */
38 while ((rc
= pmic_bus_read(AXP209_DCDC2_VOLTAGE
, ¤t
)) == 0 &&
45 rc
= pmic_bus_write(AXP209_DCDC2_VOLTAGE
, current
);
53 int axp_set_dcdc3(unsigned int mvolt
)
55 u8 cfg
= axp209_mvolt_to_cfg(mvolt
, 700, 3500, 25);
59 return pmic_bus_clrbits(AXP209_OUTPUT_CTRL
,
60 AXP209_OUTPUT_CTRL_DCDC3
);
62 rc
= pmic_bus_write(AXP209_DCDC3_VOLTAGE
, cfg
);
66 return pmic_bus_setbits(AXP209_OUTPUT_CTRL
, AXP209_OUTPUT_CTRL_DCDC3
);
69 int axp_set_aldo2(unsigned int mvolt
)
75 return pmic_bus_clrbits(AXP209_OUTPUT_CTRL
,
76 AXP209_OUTPUT_CTRL_LDO2
);
78 cfg
= axp209_mvolt_to_cfg(mvolt
, 1800, 3300, 100);
80 rc
= pmic_bus_read(AXP209_LDO24_VOLTAGE
, ®
);
84 /* LDO2 configuration is in upper 4 bits */
85 reg
= (reg
& 0x0f) | (cfg
<< 4);
86 rc
= pmic_bus_write(AXP209_LDO24_VOLTAGE
, reg
);
90 return pmic_bus_setbits(AXP209_OUTPUT_CTRL
, AXP209_OUTPUT_CTRL_LDO2
);
93 int axp_set_aldo3(unsigned int mvolt
)
99 return pmic_bus_clrbits(AXP209_OUTPUT_CTRL
,
100 AXP209_OUTPUT_CTRL_LDO3
);
103 cfg
= 0x80; /* determined by LDO3IN pin */
105 cfg
= axp209_mvolt_to_cfg(mvolt
, 700, 3500, 25);
107 rc
= pmic_bus_write(AXP209_LDO3_VOLTAGE
, cfg
);
111 return pmic_bus_setbits(AXP209_OUTPUT_CTRL
, AXP209_OUTPUT_CTRL_LDO3
);
114 int axp_set_aldo4(unsigned int mvolt
)
117 static const unsigned int vindex
[] = {
118 1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2500,
119 2700, 2800, 3000, 3100, 3200, 3300
124 return pmic_bus_clrbits(AXP209_OUTPUT_CTRL
,
125 AXP209_OUTPUT_CTRL_LDO4
);
127 /* Translate mvolt to register cfg value, requested <= selected */
128 for (cfg
= 15; vindex
[cfg
] > mvolt
&& cfg
> 0; cfg
--);
130 rc
= pmic_bus_read(AXP209_LDO24_VOLTAGE
, ®
);
134 /* LDO4 configuration is in lower 4 bits */
135 reg
= (reg
& 0xf0) | (cfg
<< 0);
136 rc
= pmic_bus_write(AXP209_LDO24_VOLTAGE
, reg
);
140 return pmic_bus_setbits(AXP209_OUTPUT_CTRL
, AXP209_OUTPUT_CTRL_LDO4
);
148 rc
= pmic_bus_init();
152 rc
= pmic_bus_read(AXP209_CHIP_VERSION
, &ver
);
156 /* Low 4 bits is chip version */
162 /* Mask all interrupts */
163 for (i
= AXP209_IRQ_ENABLE1
; i
<= AXP209_IRQ_ENABLE5
; i
++) {
164 rc
= pmic_bus_write(i
, 0);