]>
Commit | Line | Data |
---|---|---|
813c7372 | 1 | /* |
2 | * AXP818 driver based on AXP221 driver | |
3 | * | |
4 | * | |
5 | * (C) Copyright 2015 Vishnu Patekar <[email protected]> | |
6 | * | |
7 | * Based on axp221.c | |
8 | * (C) Copyright 2014 Hans de Goede <[email protected]> | |
9 | * (C) Copyright 2013 Oliver Schinagl <[email protected]> | |
10 | * | |
11 | * SPDX-License-Identifier: GPL-2.0+ | |
12 | */ | |
13 | ||
14 | #include <common.h> | |
15 | #include <errno.h> | |
16 | #include <asm/arch/gpio.h> | |
17 | #include <asm/arch/pmic_bus.h> | |
18 | #include <axp_pmic.h> | |
19 | ||
20 | static u8 axp818_mvolt_to_cfg(int mvolt, int min, int max, int div) | |
21 | { | |
22 | if (mvolt < min) | |
23 | mvolt = min; | |
24 | else if (mvolt > max) | |
25 | mvolt = max; | |
26 | ||
27 | return (mvolt - min) / div; | |
28 | } | |
29 | ||
30 | int axp_set_dcdc1(unsigned int mvolt) | |
31 | { | |
32 | int ret; | |
33 | u8 cfg = axp818_mvolt_to_cfg(mvolt, 1600, 3400, 100); | |
34 | ||
35 | if (mvolt == 0) | |
36 | return pmic_bus_clrbits(AXP818_OUTPUT_CTRL1, | |
37 | AXP818_OUTPUT_CTRL1_DCDC1_EN); | |
38 | ||
39 | ret = pmic_bus_write(AXP818_DCDC1_CTRL, cfg); | |
40 | if (ret) | |
41 | return ret; | |
42 | ||
43 | return pmic_bus_setbits(AXP818_OUTPUT_CTRL1, | |
44 | AXP818_OUTPUT_CTRL1_DCDC1_EN); | |
45 | } | |
46 | ||
47 | int axp_set_dcdc2(unsigned int mvolt) | |
48 | { | |
49 | int ret; | |
50 | u8 cfg; | |
51 | ||
52 | if (mvolt >= 1220) | |
53 | cfg = 70 + axp818_mvolt_to_cfg(mvolt, 1220, 1300, 20); | |
54 | else | |
55 | cfg = axp818_mvolt_to_cfg(mvolt, 500, 1200, 10); | |
56 | ||
57 | if (mvolt == 0) | |
58 | return pmic_bus_clrbits(AXP818_OUTPUT_CTRL1, | |
59 | AXP818_OUTPUT_CTRL1_DCDC2_EN); | |
60 | ||
61 | ret = pmic_bus_write(AXP818_DCDC2_CTRL, cfg); | |
62 | if (ret) | |
63 | return ret; | |
64 | ||
65 | return pmic_bus_setbits(AXP818_OUTPUT_CTRL1, | |
66 | AXP818_OUTPUT_CTRL1_DCDC2_EN); | |
67 | } | |
68 | ||
69 | int axp_set_dcdc3(unsigned int mvolt) | |
70 | { | |
71 | int ret; | |
72 | u8 cfg; | |
73 | ||
74 | if (mvolt >= 1220) | |
75 | cfg = 70 + axp818_mvolt_to_cfg(mvolt, 1220, 1300, 20); | |
76 | else | |
77 | cfg = axp818_mvolt_to_cfg(mvolt, 500, 1200, 10); | |
78 | ||
79 | if (mvolt == 0) | |
80 | return pmic_bus_clrbits(AXP818_OUTPUT_CTRL1, | |
81 | AXP818_OUTPUT_CTRL1_DCDC3_EN); | |
82 | ||
83 | ret = pmic_bus_write(AXP818_DCDC3_CTRL, cfg); | |
84 | if (ret) | |
85 | return ret; | |
86 | ||
87 | return pmic_bus_setbits(AXP818_OUTPUT_CTRL1, | |
88 | AXP818_OUTPUT_CTRL1_DCDC3_EN); | |
89 | } | |
90 | ||
91 | int axp_set_dcdc5(unsigned int mvolt) | |
92 | { | |
93 | int ret; | |
94 | u8 cfg; | |
95 | ||
96 | if (mvolt >= 1140) | |
97 | cfg = 32 + axp818_mvolt_to_cfg(mvolt, 1140, 1840, 20); | |
98 | else | |
99 | cfg = axp818_mvolt_to_cfg(mvolt, 800, 1120, 10); | |
100 | ||
101 | if (mvolt == 0) | |
102 | return pmic_bus_clrbits(AXP818_OUTPUT_CTRL1, | |
103 | AXP818_OUTPUT_CTRL1_DCDC5_EN); | |
104 | ||
105 | ret = pmic_bus_write(AXP818_DCDC5_CTRL, cfg); | |
106 | if (ret) | |
107 | return ret; | |
108 | ||
109 | return pmic_bus_setbits(AXP818_OUTPUT_CTRL1, | |
110 | AXP818_OUTPUT_CTRL1_DCDC5_EN); | |
111 | } | |
112 | ||
0509efb7 CYT |
113 | int axp_set_dldo(int dldo_num, unsigned int mvolt) |
114 | { | |
115 | int ret; | |
116 | u8 cfg; | |
117 | ||
118 | if (dldo_num < 1 || dldo_num > 4) | |
119 | return -EINVAL; | |
120 | ||
121 | if (mvolt == 0) | |
122 | return pmic_bus_clrbits(AXP818_OUTPUT_CTRL2, | |
123 | AXP818_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1)); | |
124 | ||
125 | cfg = axp818_mvolt_to_cfg(mvolt, 700, 3300, 100); | |
126 | if (dldo_num == 2 && mvolt > 3300) | |
127 | cfg += 1 + axp818_mvolt_to_cfg(mvolt, 3400, 4200, 200); | |
128 | ret = pmic_bus_write(AXP818_ELDO1_CTRL + (dldo_num - 1), cfg); | |
129 | if (ret) | |
130 | return ret; | |
131 | ||
132 | return pmic_bus_setbits(AXP818_OUTPUT_CTRL2, | |
133 | AXP818_OUTPUT_CTRL2_DLDO1_EN << (dldo_num - 1)); | |
134 | } | |
135 | ||
136 | int axp_set_eldo(int eldo_num, unsigned int mvolt) | |
137 | { | |
138 | int ret; | |
139 | u8 cfg; | |
140 | ||
141 | if (eldo_num < 1 || eldo_num > 3) | |
142 | return -EINVAL; | |
143 | ||
144 | if (mvolt == 0) | |
145 | return pmic_bus_clrbits(AXP818_OUTPUT_CTRL2, | |
146 | AXP818_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1)); | |
147 | ||
148 | cfg = axp818_mvolt_to_cfg(mvolt, 700, 1900, 50); | |
149 | ret = pmic_bus_write(AXP818_ELDO1_CTRL + (eldo_num - 1), cfg); | |
150 | if (ret) | |
151 | return ret; | |
152 | ||
153 | return pmic_bus_setbits(AXP818_OUTPUT_CTRL2, | |
154 | AXP818_OUTPUT_CTRL2_ELDO1_EN << (eldo_num - 1)); | |
155 | } | |
156 | ||
813c7372 | 157 | int axp_init(void) |
158 | { | |
159 | u8 axp_chip_id; | |
160 | int ret; | |
161 | ||
162 | ret = pmic_bus_init(); | |
163 | if (ret) | |
164 | return ret; | |
165 | ||
166 | ret = pmic_bus_read(AXP818_CHIP_ID, &axp_chip_id); | |
167 | if (ret) | |
168 | return ret; | |
169 | ||
170 | if (!(axp_chip_id == 0x51)) | |
171 | return -ENODEV; | |
172 | else | |
173 | return ret; | |
174 | ||
175 | return 0; | |
176 | } |