diff options
author | Guodong Xu <guodong.xu@linaro.org> | 2014-08-13 07:33:42 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-08-16 17:58:15 -0400 |
commit | 87ca186f7eb663fc5e52b65452a91fe0fec170a0 (patch) | |
tree | caeb09468cf072bd94f6a78e58c18f50e065e348 | |
parent | 871f565055ed232e5751da18a331b73e8254adaf (diff) |
regulator: add driver for hi6421 voltage regulator
Add driver support for HiSilicon Hi6421 voltage regulators.
Two rules for regulator enabling are defined in hi6421 spec:
1) Between disable and enable of each regulator (LDOs or BUCKs), there must
be a protection gap. Use @off_on_delay of regulator core to implement this.
2) No two regulators can be enabled at the same time. Use mutex in
hi6421_regulator_pdata to ensure this. A protection gap of 100us is added
into each LDO/BUCK's .enable_time.
Signed-off-by: Guodong Xu <guodong.xu@linaro.org>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | drivers/regulator/Kconfig | 10 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
-rw-r--r-- | drivers/regulator/hi6421-regulator.c | 657 |
3 files changed, 668 insertions, 0 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 2dc8289e5dba..e6b98ed4c12f 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -240,6 +240,16 @@ config REGULATOR_GPIO | |||
240 | and the platform has to provide a mapping of GPIO-states | 240 | and the platform has to provide a mapping of GPIO-states |
241 | to target volts/amps. | 241 | to target volts/amps. |
242 | 242 | ||
243 | config REGULATOR_HI6421 | ||
244 | tristate "HiSilicon Hi6421 PMIC voltage regulator support" | ||
245 | depends on MFD_HI6421_PMIC && OF | ||
246 | help | ||
247 | This driver provides support for the voltage regulators on the | ||
248 | HiSilicon Hi6421 PMU / Codec IC. | ||
249 | Hi6421 is a multi-function device which, on regulator part, provides | ||
250 | 21 general purpose LDOs, 3 dedicated LDOs, and 5 BUCKs. All | ||
251 | of them come with support to either ECO (idle) or sleep mode. | ||
252 | |||
243 | config REGULATOR_ISL6271A | 253 | config REGULATOR_ISL6271A |
244 | tristate "Intersil ISL6271A Power regulator" | 254 | tristate "Intersil ISL6271A Power regulator" |
245 | depends on I2C | 255 | depends on I2C |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index aa4a6aa7b558..5513e2c141b1 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -32,6 +32,7 @@ obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o | |||
32 | obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o | 32 | obj-$(CONFIG_REGULATOR_DB8500_PRCMU) += db8500-prcmu.o |
33 | obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o | 33 | obj-$(CONFIG_REGULATOR_FAN53555) += fan53555.o |
34 | obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o | 34 | obj-$(CONFIG_REGULATOR_GPIO) += gpio-regulator.o |
35 | obj-$(CONFIG_REGULATOR_HI6421) += hi6421-regulator.o | ||
35 | obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o | 36 | obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o |
36 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o | 37 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o |
37 | obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o | 38 | obj-$(CONFIG_REGULATOR_LP3972) += lp3972.o |
diff --git a/drivers/regulator/hi6421-regulator.c b/drivers/regulator/hi6421-regulator.c new file mode 100644 index 000000000000..b40851eb5466 --- /dev/null +++ b/drivers/regulator/hi6421-regulator.c | |||
@@ -0,0 +1,657 @@ | |||
1 | /* | ||
2 | * Device driver for regulators in Hi6421 IC | ||
3 | * | ||
4 | * Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. | ||
5 | * http://www.hisilicon.com | ||
6 | * Copyright (c) <2013-2014> Linaro Ltd. | ||
7 | * http://www.linaro.org | ||
8 | * | ||
9 | * Author: Guodong Xu <guodong.xu@linaro.org> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License version 2 as | ||
13 | * published by the Free Software Foundation. | ||
14 | */ | ||
15 | |||
16 | #include <linux/slab.h> | ||
17 | #include <linux/device.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/err.h> | ||
20 | #include <linux/io.h> | ||
21 | #include <linux/jiffies.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/of.h> | ||
24 | #include <linux/of_device.h> | ||
25 | #include <linux/of_address.h> | ||
26 | #include <linux/regmap.h> | ||
27 | #include <linux/regulator/driver.h> | ||
28 | #include <linux/regulator/machine.h> | ||
29 | #include <linux/regulator/of_regulator.h> | ||
30 | #include <linux/mfd/hi6421-pmic.h> | ||
31 | #include <linux/delay.h> | ||
32 | #include <linux/time.h> | ||
33 | |||
34 | /* | ||
35 | * struct hi6421_regulator_pdata - Hi6421 regulator data of platform device | ||
36 | * @lock: mutex to serialize regulator enable | ||
37 | */ | ||
38 | struct hi6421_regulator_pdata { | ||
39 | struct mutex lock; | ||
40 | }; | ||
41 | |||
42 | /* | ||
43 | * struct hi6421_regulator_info - hi6421 regulator information | ||
44 | * @dev: device pointer | ||
45 | * @desc: regulator description | ||
46 | * @regulator: regulator device | ||
47 | * @mode_mask: ECO mode bitmask of LDOs; for BUCKs, this masks sleep | ||
48 | * @eco_microamp: eco mode load upper limit (in mA), valid for LDOs only | ||
49 | * @valid_modes_mask: valid operating modes | ||
50 | */ | ||
51 | struct hi6421_regulator_info { | ||
52 | struct device *dev; | ||
53 | struct regulator_desc desc; | ||
54 | struct regulator_dev *regulator; | ||
55 | u8 mode_mask; | ||
56 | u32 eco_microamp; | ||
57 | unsigned int valid_modes_mask; | ||
58 | }; | ||
59 | |||
60 | /* HI6421 regulators */ | ||
61 | enum hi6421_regulator_id { | ||
62 | HI6421_LDO0, | ||
63 | HI6421_LDO1, | ||
64 | HI6421_LDO2, | ||
65 | HI6421_LDO3, | ||
66 | HI6421_LDO4, | ||
67 | HI6421_LDO5, | ||
68 | HI6421_LDO6, | ||
69 | HI6421_LDO7, | ||
70 | HI6421_LDO8, | ||
71 | HI6421_LDO9, | ||
72 | HI6421_LDO10, | ||
73 | HI6421_LDO11, | ||
74 | HI6421_LDO12, | ||
75 | HI6421_LDO13, | ||
76 | HI6421_LDO14, | ||
77 | HI6421_LDO15, | ||
78 | HI6421_LDO16, | ||
79 | HI6421_LDO17, | ||
80 | HI6421_LDO18, | ||
81 | HI6421_LDO19, | ||
82 | HI6421_LDO20, | ||
83 | HI6421_LDOAUDIO, | ||
84 | HI6421_BUCK0, | ||
85 | HI6421_BUCK1, | ||
86 | HI6421_BUCK2, | ||
87 | HI6421_BUCK3, | ||
88 | HI6421_BUCK4, | ||
89 | HI6421_BUCK5, | ||
90 | HI6421_NUM_REGULATORS, | ||
91 | }; | ||
92 | |||
93 | #define HI6421_REGULATOR_OF_MATCH(_name, id) \ | ||
94 | { \ | ||
95 | .name = #_name, \ | ||
96 | .driver_data = (void *) HI6421_##id, \ | ||
97 | } | ||
98 | |||
99 | static struct of_regulator_match hi6421_regulator_match[] = { | ||
100 | HI6421_REGULATOR_OF_MATCH(hi6421_vout0, LDO0), | ||
101 | HI6421_REGULATOR_OF_MATCH(hi6421_vout1, LDO1), | ||
102 | HI6421_REGULATOR_OF_MATCH(hi6421_vout2, LDO2), | ||
103 | HI6421_REGULATOR_OF_MATCH(hi6421_vout3, LDO3), | ||
104 | HI6421_REGULATOR_OF_MATCH(hi6421_vout4, LDO4), | ||
105 | HI6421_REGULATOR_OF_MATCH(hi6421_vout5, LDO5), | ||
106 | HI6421_REGULATOR_OF_MATCH(hi6421_vout6, LDO6), | ||
107 | HI6421_REGULATOR_OF_MATCH(hi6421_vout7, LDO7), | ||
108 | HI6421_REGULATOR_OF_MATCH(hi6421_vout8, LDO8), | ||
109 | HI6421_REGULATOR_OF_MATCH(hi6421_vout9, LDO9), | ||
110 | HI6421_REGULATOR_OF_MATCH(hi6421_vout10, LDO10), | ||
111 | HI6421_REGULATOR_OF_MATCH(hi6421_vout11, LDO11), | ||
112 | HI6421_REGULATOR_OF_MATCH(hi6421_vout12, LDO12), | ||
113 | HI6421_REGULATOR_OF_MATCH(hi6421_vout13, LDO13), | ||
114 | HI6421_REGULATOR_OF_MATCH(hi6421_vout14, LDO14), | ||
115 | HI6421_REGULATOR_OF_MATCH(hi6421_vout15, LDO15), | ||
116 | HI6421_REGULATOR_OF_MATCH(hi6421_vout16, LDO16), | ||
117 | HI6421_REGULATOR_OF_MATCH(hi6421_vout17, LDO17), | ||
118 | HI6421_REGULATOR_OF_MATCH(hi6421_vout18, LDO18), | ||
119 | HI6421_REGULATOR_OF_MATCH(hi6421_vout19, LDO19), | ||
120 | HI6421_REGULATOR_OF_MATCH(hi6421_vout20, LDO20), | ||
121 | HI6421_REGULATOR_OF_MATCH(hi6421_vout_audio, LDOAUDIO), | ||
122 | HI6421_REGULATOR_OF_MATCH(hi6421_buck0, BUCK0), | ||
123 | HI6421_REGULATOR_OF_MATCH(hi6421_buck1, BUCK1), | ||
124 | HI6421_REGULATOR_OF_MATCH(hi6421_buck2, BUCK2), | ||
125 | HI6421_REGULATOR_OF_MATCH(hi6421_buck3, BUCK3), | ||
126 | HI6421_REGULATOR_OF_MATCH(hi6421_buck4, BUCK4), | ||
127 | HI6421_REGULATOR_OF_MATCH(hi6421_buck5, BUCK5), | ||
128 | }; | ||
129 | |||
130 | /* LDO 0, 4~7, 9~14, 16~20 have same voltage table. */ | ||
131 | static const unsigned int ldo_0_voltages[] = { | ||
132 | 1500000, 1800000, 2400000, 2500000, | ||
133 | 2600000, 2700000, 2850000, 3000000, | ||
134 | }; | ||
135 | |||
136 | /* LDO 8, 15 have same voltage table. */ | ||
137 | static const unsigned int ldo_8_voltages[] = { | ||
138 | 1500000, 1800000, 2400000, 2600000, | ||
139 | 2700000, 2850000, 3000000, 3300000, | ||
140 | }; | ||
141 | |||
142 | /* Ranges are sorted in ascending order. */ | ||
143 | static const struct regulator_linear_range ldo_audio_volt_range[] = { | ||
144 | REGULATOR_LINEAR_RANGE(2800000, 0, 3, 50000), | ||
145 | REGULATOR_LINEAR_RANGE(3000000, 4, 7, 100000), | ||
146 | }; | ||
147 | |||
148 | static const unsigned int buck_3_voltages[] = { | ||
149 | 950000, 1050000, 1100000, 1117000, | ||
150 | 1134000, 1150000, 1167000, 1200000, | ||
151 | }; | ||
152 | |||
153 | static const unsigned int buck_4_voltages[] = { | ||
154 | 1150000, 1200000, 1250000, 1350000, | ||
155 | 1700000, 1800000, 1900000, 2000000, | ||
156 | }; | ||
157 | |||
158 | static const unsigned int buck_5_voltages[] = { | ||
159 | 1150000, 1200000, 1250000, 1350000, | ||
160 | 1600000, 1700000, 1800000, 1900000, | ||
161 | }; | ||
162 | |||
163 | static const struct regulator_ops hi6421_ldo_ops; | ||
164 | static const struct regulator_ops hi6421_ldo_linear_ops; | ||
165 | static const struct regulator_ops hi6421_ldo_linear_range_ops; | ||
166 | static const struct regulator_ops hi6421_buck012_ops; | ||
167 | static const struct regulator_ops hi6421_buck345_ops; | ||
168 | |||
169 | #define HI6421_LDO_ENABLE_TIME (350) | ||
170 | /* | ||
171 | * _id - LDO id name string | ||
172 | * v_table - voltage table | ||
173 | * vreg - voltage select register | ||
174 | * vmask - voltage select mask | ||
175 | * ereg - enable register | ||
176 | * emask - enable mask | ||
177 | * odelay - off/on delay time in uS | ||
178 | * ecomask - eco mode mask | ||
179 | * ecoamp - eco mode load uppler limit in mA | ||
180 | */ | ||
181 | #define HI6421_LDO(_id, v_table, vreg, vmask, ereg, emask, \ | ||
182 | odelay, ecomask, ecoamp) \ | ||
183 | [HI6421_##_id] = { \ | ||
184 | .desc = { \ | ||
185 | .name = #_id, \ | ||
186 | .ops = &hi6421_ldo_ops, \ | ||
187 | .type = REGULATOR_VOLTAGE, \ | ||
188 | .id = HI6421_##_id, \ | ||
189 | .owner = THIS_MODULE, \ | ||
190 | .n_voltages = ARRAY_SIZE(v_table), \ | ||
191 | .volt_table = v_table, \ | ||
192 | .vsel_reg = HI6421_REG_TO_BUS_ADDR(vreg), \ | ||
193 | .vsel_mask = vmask, \ | ||
194 | .enable_reg = HI6421_REG_TO_BUS_ADDR(ereg), \ | ||
195 | .enable_mask = emask, \ | ||
196 | .enable_time = HI6421_LDO_ENABLE_TIME, \ | ||
197 | .off_on_delay = odelay, \ | ||
198 | }, \ | ||
199 | .mode_mask = ecomask, \ | ||
200 | .eco_microamp = ecoamp, \ | ||
201 | .valid_modes_mask = (REGULATOR_MODE_NORMAL \ | ||
202 | | REGULATOR_MODE_IDLE), \ | ||
203 | } | ||
204 | |||
205 | /* HI6421 LDO1~3 are linear voltage regulators at fixed uV_step | ||
206 | * | ||
207 | * _id - LDO id name string | ||
208 | * _min_uV - minimum voltage supported in uV | ||
209 | * n_volt - number of votages available | ||
210 | * vstep - voltage increase in each linear step in uV | ||
211 | * vreg - voltage select register | ||
212 | * vmask - voltage select mask | ||
213 | * ereg - enable register | ||
214 | * emask - enable mask | ||
215 | * odelay - off/on delay time in uS | ||
216 | * ecomask - eco mode mask | ||
217 | * ecoamp - eco mode load uppler limit in mA | ||
218 | */ | ||
219 | #define HI6421_LDO_LINEAR(_id, _min_uV, n_volt, vstep, vreg, vmask, \ | ||
220 | ereg, emask, odelay, ecomask, ecoamp) \ | ||
221 | [HI6421_##_id] = { \ | ||
222 | .desc = { \ | ||
223 | .name = #_id, \ | ||
224 | .ops = &hi6421_ldo_linear_ops, \ | ||
225 | .type = REGULATOR_VOLTAGE, \ | ||
226 | .id = HI6421_##_id, \ | ||
227 | .owner = THIS_MODULE, \ | ||
228 | .min_uV = _min_uV, \ | ||
229 | .n_voltages = n_volt, \ | ||
230 | .uV_step = vstep, \ | ||
231 | .vsel_reg = HI6421_REG_TO_BUS_ADDR(vreg), \ | ||
232 | .vsel_mask = vmask, \ | ||
233 | .enable_reg = HI6421_REG_TO_BUS_ADDR(ereg), \ | ||
234 | .enable_mask = emask, \ | ||
235 | .enable_time = HI6421_LDO_ENABLE_TIME, \ | ||
236 | .off_on_delay = odelay, \ | ||
237 | }, \ | ||
238 | .mode_mask = ecomask, \ | ||
239 | .eco_microamp = ecoamp, \ | ||
240 | .valid_modes_mask = (REGULATOR_MODE_NORMAL \ | ||
241 | | REGULATOR_MODE_IDLE), \ | ||
242 | } | ||
243 | |||
244 | /* HI6421 LDOAUDIO is a linear voltage regulator with two 4-step ranges | ||
245 | * | ||
246 | * _id - LDO id name string | ||
247 | * n_volt - number of votages available | ||
248 | * volt_ranges - array of regulator_linear_range | ||
249 | * vstep - voltage increase in each linear step in uV | ||
250 | * vreg - voltage select register | ||
251 | * vmask - voltage select mask | ||
252 | * ereg - enable register | ||
253 | * emask - enable mask | ||
254 | * odelay - off/on delay time in uS | ||
255 | * ecomask - eco mode mask | ||
256 | * ecoamp - eco mode load uppler limit in mA | ||
257 | */ | ||
258 | #define HI6421_LDO_LINEAR_RANGE(_id, n_volt, volt_ranges, vreg, vmask, \ | ||
259 | ereg, emask, odelay, ecomask, ecoamp) \ | ||
260 | [HI6421_##_id] = { \ | ||
261 | .desc = { \ | ||
262 | .name = #_id, \ | ||
263 | .ops = &hi6421_ldo_linear_range_ops, \ | ||
264 | .type = REGULATOR_VOLTAGE, \ | ||
265 | .id = HI6421_##_id, \ | ||
266 | .owner = THIS_MODULE, \ | ||
267 | .n_voltages = n_volt, \ | ||
268 | .linear_ranges = volt_ranges, \ | ||
269 | .n_linear_ranges = ARRAY_SIZE(volt_ranges), \ | ||
270 | .vsel_reg = HI6421_REG_TO_BUS_ADDR(vreg), \ | ||
271 | .vsel_mask = vmask, \ | ||
272 | .enable_reg = HI6421_REG_TO_BUS_ADDR(ereg), \ | ||
273 | .enable_mask = emask, \ | ||
274 | .enable_time = HI6421_LDO_ENABLE_TIME, \ | ||
275 | .off_on_delay = odelay, \ | ||
276 | }, \ | ||
277 | .mode_mask = ecomask, \ | ||
278 | .eco_microamp = ecoamp, \ | ||
279 | .valid_modes_mask = (REGULATOR_MODE_NORMAL \ | ||
280 | | REGULATOR_MODE_IDLE), \ | ||
281 | } | ||
282 | |||
283 | /* HI6421 BUCK0/1/2 are linear voltage regulators at fixed uV_step | ||
284 | * | ||
285 | * _id - BUCK0/1/2 id name string | ||
286 | * vreg - voltage select register | ||
287 | * vmask - voltage select mask | ||
288 | * ereg - enable register | ||
289 | * emask - enable mask | ||
290 | * sleepmask - mask of sleep mode | ||
291 | * etime - enable time | ||
292 | * odelay - off/on delay time in uS | ||
293 | */ | ||
294 | #define HI6421_BUCK012(_id, vreg, vmask, ereg, emask, sleepmask, \ | ||
295 | etime, odelay) \ | ||
296 | [HI6421_##_id] = { \ | ||
297 | .desc = { \ | ||
298 | .name = #_id, \ | ||
299 | .ops = &hi6421_buck012_ops, \ | ||
300 | .type = REGULATOR_VOLTAGE, \ | ||
301 | .id = HI6421_##_id, \ | ||
302 | .owner = THIS_MODULE, \ | ||
303 | .min_uV = 700000, \ | ||
304 | .n_voltages = 128, \ | ||
305 | .uV_step = 7086, \ | ||
306 | .vsel_reg = HI6421_REG_TO_BUS_ADDR(vreg), \ | ||
307 | .vsel_mask = vmask, \ | ||
308 | .enable_reg = HI6421_REG_TO_BUS_ADDR(ereg), \ | ||
309 | .enable_mask = emask, \ | ||
310 | .enable_time = etime, \ | ||
311 | .off_on_delay = odelay, \ | ||
312 | }, \ | ||
313 | .mode_mask = sleepmask, \ | ||
314 | .valid_modes_mask = (REGULATOR_MODE_NORMAL \ | ||
315 | | REGULATOR_MODE_STANDBY), \ | ||
316 | } | ||
317 | |||
318 | /* HI6421 BUCK3/4/5 share similar configurations as LDOs, with exception | ||
319 | * that it supports SLEEP mode, so has different .ops. | ||
320 | * | ||
321 | * _id - LDO id name string | ||
322 | * v_table - voltage table | ||
323 | * vreg - voltage select register | ||
324 | * vmask - voltage select mask | ||
325 | * ereg - enable register | ||
326 | * emask - enable mask | ||
327 | * odelay - off/on delay time in uS | ||
328 | * sleepmask - mask of sleep mode | ||
329 | */ | ||
330 | #define HI6421_BUCK345(_id, v_table, vreg, vmask, ereg, emask, \ | ||
331 | odelay, sleepmask) \ | ||
332 | [HI6421_##_id] = { \ | ||
333 | .desc = { \ | ||
334 | .name = #_id, \ | ||
335 | .ops = &hi6421_buck345_ops, \ | ||
336 | .type = REGULATOR_VOLTAGE, \ | ||
337 | .id = HI6421_##_id, \ | ||
338 | .owner = THIS_MODULE, \ | ||
339 | .n_voltages = ARRAY_SIZE(v_table), \ | ||
340 | .volt_table = v_table, \ | ||
341 | .vsel_reg = HI6421_REG_TO_BUS_ADDR(vreg), \ | ||
342 | .vsel_mask = vmask, \ | ||
343 | .enable_reg = HI6421_REG_TO_BUS_ADDR(ereg), \ | ||
344 | .enable_mask = emask, \ | ||
345 | .enable_time = HI6421_LDO_ENABLE_TIME, \ | ||
346 | .off_on_delay = odelay, \ | ||
347 | }, \ | ||
348 | .mode_mask = sleepmask, \ | ||
349 | .valid_modes_mask = (REGULATOR_MODE_NORMAL \ | ||
350 | | REGULATOR_MODE_STANDBY), \ | ||
351 | } | ||
352 | |||
353 | /* HI6421 regulator information */ | ||
354 | static struct hi6421_regulator_info | ||
355 | hi6421_regulator_info[HI6421_NUM_REGULATORS] = { | ||
356 | HI6421_LDO(LDO0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10, | ||
357 | 10000, 0x20, 8000), | ||
358 | HI6421_LDO_LINEAR(LDO1, 1700000, 4, 100000, 0x21, 0x03, 0x21, 0x10, | ||
359 | 10000, 0x20, 5000), | ||
360 | HI6421_LDO_LINEAR(LDO2, 1050000, 8, 50000, 0x22, 0x07, 0x22, 0x10, | ||
361 | 20000, 0x20, 8000), | ||
362 | HI6421_LDO_LINEAR(LDO3, 1050000, 8, 50000, 0x23, 0x07, 0x23, 0x10, | ||
363 | 20000, 0x20, 8000), | ||
364 | HI6421_LDO(LDO4, ldo_0_voltages, 0x24, 0x07, 0x24, 0x10, | ||
365 | 20000, 0x20, 8000), | ||
366 | HI6421_LDO(LDO5, ldo_0_voltages, 0x25, 0x07, 0x25, 0x10, | ||
367 | 20000, 0x20, 8000), | ||
368 | HI6421_LDO(LDO6, ldo_0_voltages, 0x26, 0x07, 0x26, 0x10, | ||
369 | 20000, 0x20, 8000), | ||
370 | HI6421_LDO(LDO7, ldo_0_voltages, 0x27, 0x07, 0x27, 0x10, | ||
371 | 20000, 0x20, 5000), | ||
372 | HI6421_LDO(LDO8, ldo_8_voltages, 0x28, 0x07, 0x28, 0x10, | ||
373 | 20000, 0x20, 8000), | ||
374 | HI6421_LDO(LDO9, ldo_0_voltages, 0x29, 0x07, 0x29, 0x10, | ||
375 | 40000, 0x20, 8000), | ||
376 | HI6421_LDO(LDO10, ldo_0_voltages, 0x2a, 0x07, 0x2a, 0x10, | ||
377 | 40000, 0x20, 8000), | ||
378 | HI6421_LDO(LDO11, ldo_0_voltages, 0x2b, 0x07, 0x2b, 0x10, | ||
379 | 40000, 0x20, 8000), | ||
380 | HI6421_LDO(LDO12, ldo_0_voltages, 0x2c, 0x07, 0x2c, 0x10, | ||
381 | 40000, 0x20, 8000), | ||
382 | HI6421_LDO(LDO13, ldo_0_voltages, 0x2d, 0x07, 0x2d, 0x10, | ||
383 | 40000, 0x20, 8000), | ||
384 | HI6421_LDO(LDO14, ldo_0_voltages, 0x2e, 0x07, 0x2e, 0x10, | ||
385 | 40000, 0x20, 8000), | ||
386 | HI6421_LDO(LDO15, ldo_8_voltages, 0x2f, 0x07, 0x2f, 0x10, | ||
387 | 40000, 0x20, 8000), | ||
388 | HI6421_LDO(LDO16, ldo_0_voltages, 0x30, 0x07, 0x30, 0x10, | ||
389 | 40000, 0x20, 8000), | ||
390 | HI6421_LDO(LDO17, ldo_0_voltages, 0x31, 0x07, 0x31, 0x10, | ||
391 | 40000, 0x20, 8000), | ||
392 | HI6421_LDO(LDO18, ldo_0_voltages, 0x32, 0x07, 0x32, 0x10, | ||
393 | 40000, 0x20, 8000), | ||
394 | HI6421_LDO(LDO19, ldo_0_voltages, 0x33, 0x07, 0x33, 0x10, | ||
395 | 40000, 0x20, 8000), | ||
396 | HI6421_LDO(LDO20, ldo_0_voltages, 0x34, 0x07, 0x34, 0x10, | ||
397 | 40000, 0x20, 8000), | ||
398 | HI6421_LDO_LINEAR_RANGE(LDOAUDIO, 8, ldo_audio_volt_range, 0x36, | ||
399 | 0x70, 0x36, 0x01, 40000, 0x02, 5000), | ||
400 | HI6421_BUCK012(BUCK0, 0x0d, 0x7f, 0x0c, 0x01, 0x10, 400, 20000), | ||
401 | HI6421_BUCK012(BUCK1, 0x0f, 0x7f, 0x0e, 0x01, 0x10, 400, 20000), | ||
402 | HI6421_BUCK012(BUCK2, 0x11, 0x7f, 0x10, 0x01, 0x10, 350, 100), | ||
403 | HI6421_BUCK345(BUCK3, buck_3_voltages, 0x13, 0x07, 0x12, 0x01, | ||
404 | 20000, 0x10), | ||
405 | HI6421_BUCK345(BUCK4, buck_4_voltages, 0x15, 0x07, 0x14, 0x01, | ||
406 | 20000, 0x10), | ||
407 | HI6421_BUCK345(BUCK5, buck_5_voltages, 0x17, 0x07, 0x16, 0x01, | ||
408 | 20000, 0x10), | ||
409 | }; | ||
410 | |||
411 | static int hi6421_regulator_enable(struct regulator_dev *rdev) | ||
412 | { | ||
413 | struct hi6421_regulator_pdata *pdata; | ||
414 | |||
415 | pdata = dev_get_drvdata(rdev->dev.parent); | ||
416 | /* hi6421 spec requires regulator enablement must be serialized: | ||
417 | * - Because when BUCK, LDO switching from off to on, it will have | ||
418 | * a huge instantaneous current; so you can not turn on two or | ||
419 | * more LDO or BUCKs simultaneously, or it may burn the chip. | ||
420 | */ | ||
421 | mutex_lock(&pdata->lock); | ||
422 | |||
423 | /* call regulator regmap helper */ | ||
424 | regulator_enable_regmap(rdev); | ||
425 | |||
426 | mutex_unlock(&pdata->lock); | ||
427 | return 0; | ||
428 | } | ||
429 | |||
430 | static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev) | ||
431 | { | ||
432 | struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); | ||
433 | u32 reg_val; | ||
434 | |||
435 | regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val); | ||
436 | if (reg_val & info->mode_mask) | ||
437 | return REGULATOR_MODE_IDLE; | ||
438 | else | ||
439 | return REGULATOR_MODE_NORMAL; | ||
440 | } | ||
441 | |||
442 | static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev) | ||
443 | { | ||
444 | struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); | ||
445 | u32 reg_val; | ||
446 | |||
447 | regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val); | ||
448 | if (reg_val & info->mode_mask) | ||
449 | return REGULATOR_MODE_STANDBY; | ||
450 | else | ||
451 | return REGULATOR_MODE_NORMAL; | ||
452 | } | ||
453 | |||
454 | static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev, | ||
455 | unsigned int mode) | ||
456 | { | ||
457 | struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); | ||
458 | u32 new_mode; | ||
459 | |||
460 | switch (mode) { | ||
461 | case REGULATOR_MODE_NORMAL: | ||
462 | new_mode = 0; | ||
463 | break; | ||
464 | case REGULATOR_MODE_IDLE: | ||
465 | new_mode = info->mode_mask; | ||
466 | break; | ||
467 | default: | ||
468 | return -EINVAL; | ||
469 | } | ||
470 | |||
471 | /* set mode */ | ||
472 | regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | ||
473 | info->mode_mask, new_mode); | ||
474 | |||
475 | return 0; | ||
476 | } | ||
477 | |||
478 | static int hi6421_regulator_buck_set_mode(struct regulator_dev *rdev, | ||
479 | unsigned int mode) | ||
480 | { | ||
481 | struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); | ||
482 | u32 new_mode; | ||
483 | |||
484 | switch (mode) { | ||
485 | case REGULATOR_MODE_NORMAL: | ||
486 | new_mode = 0; | ||
487 | break; | ||
488 | case REGULATOR_MODE_STANDBY: | ||
489 | new_mode = info->mode_mask; | ||
490 | break; | ||
491 | default: | ||
492 | return -EINVAL; | ||
493 | } | ||
494 | |||
495 | /* set mode */ | ||
496 | regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, | ||
497 | info->mode_mask, new_mode); | ||
498 | |||
499 | return 0; | ||
500 | } | ||
501 | |||
502 | unsigned int hi6421_regulator_ldo_get_optimum_mode(struct regulator_dev *rdev, | ||
503 | int input_uV, int output_uV, int load_uA) | ||
504 | { | ||
505 | struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); | ||
506 | |||
507 | if (load_uA > info->eco_microamp) | ||
508 | return REGULATOR_MODE_NORMAL; | ||
509 | else | ||
510 | return REGULATOR_MODE_IDLE; | ||
511 | } | ||
512 | |||
513 | static const struct regulator_ops hi6421_ldo_ops = { | ||
514 | .is_enabled = regulator_is_enabled_regmap, | ||
515 | .enable = hi6421_regulator_enable, | ||
516 | .disable = regulator_disable_regmap, | ||
517 | .list_voltage = regulator_list_voltage_table, | ||
518 | .map_voltage = regulator_map_voltage_ascend, | ||
519 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
520 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
521 | .get_mode = hi6421_regulator_ldo_get_mode, | ||
522 | .set_mode = hi6421_regulator_ldo_set_mode, | ||
523 | .get_optimum_mode = hi6421_regulator_ldo_get_optimum_mode, | ||
524 | }; | ||
525 | |||
526 | static const struct regulator_ops hi6421_ldo_linear_ops = { | ||
527 | .is_enabled = regulator_is_enabled_regmap, | ||
528 | .enable = hi6421_regulator_enable, | ||
529 | .disable = regulator_disable_regmap, | ||
530 | .list_voltage = regulator_list_voltage_linear, | ||
531 | .map_voltage = regulator_map_voltage_linear, | ||
532 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
533 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
534 | .get_mode = hi6421_regulator_ldo_get_mode, | ||
535 | .set_mode = hi6421_regulator_ldo_set_mode, | ||
536 | .get_optimum_mode = hi6421_regulator_ldo_get_optimum_mode, | ||
537 | }; | ||
538 | |||
539 | static const struct regulator_ops hi6421_ldo_linear_range_ops = { | ||
540 | .is_enabled = regulator_is_enabled_regmap, | ||
541 | .enable = hi6421_regulator_enable, | ||
542 | .disable = regulator_disable_regmap, | ||
543 | .list_voltage = regulator_list_voltage_linear_range, | ||
544 | .map_voltage = regulator_map_voltage_linear_range, | ||
545 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
546 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
547 | .get_mode = hi6421_regulator_ldo_get_mode, | ||
548 | .set_mode = hi6421_regulator_ldo_set_mode, | ||
549 | .get_optimum_mode = hi6421_regulator_ldo_get_optimum_mode, | ||
550 | }; | ||
551 | |||
552 | static const struct regulator_ops hi6421_buck012_ops = { | ||
553 | .is_enabled = regulator_is_enabled_regmap, | ||
554 | .enable = hi6421_regulator_enable, | ||
555 | .disable = regulator_disable_regmap, | ||
556 | .list_voltage = regulator_list_voltage_linear, | ||
557 | .map_voltage = regulator_map_voltage_linear, | ||
558 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
559 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
560 | .get_mode = hi6421_regulator_buck_get_mode, | ||
561 | .set_mode = hi6421_regulator_buck_set_mode, | ||
562 | }; | ||
563 | |||
564 | static const struct regulator_ops hi6421_buck345_ops = { | ||
565 | .is_enabled = regulator_is_enabled_regmap, | ||
566 | .enable = hi6421_regulator_enable, | ||
567 | .disable = regulator_disable_regmap, | ||
568 | .list_voltage = regulator_list_voltage_table, | ||
569 | .map_voltage = regulator_map_voltage_ascend, | ||
570 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
571 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
572 | .get_mode = hi6421_regulator_buck_get_mode, | ||
573 | .set_mode = hi6421_regulator_buck_set_mode, | ||
574 | }; | ||
575 | |||
576 | static int hi6421_regulator_register(struct platform_device *pdev, | ||
577 | struct regmap *rmap, | ||
578 | struct regulator_init_data *init_data, | ||
579 | int id, struct device_node *np) | ||
580 | { | ||
581 | struct hi6421_regulator_info *info = NULL; | ||
582 | struct regulator_config config = { }; | ||
583 | |||
584 | /* assign per-regulator data */ | ||
585 | info = &hi6421_regulator_info[id]; | ||
586 | info->dev = &pdev->dev; | ||
587 | |||
588 | config.dev = &pdev->dev; | ||
589 | config.init_data = init_data; | ||
590 | config.driver_data = info; | ||
591 | config.regmap = rmap; | ||
592 | config.of_node = np; | ||
593 | |||
594 | /* register regulator with framework */ | ||
595 | info->regulator = devm_regulator_register(&pdev->dev, &info->desc, | ||
596 | &config); | ||
597 | if (IS_ERR(info->regulator)) { | ||
598 | dev_err(&pdev->dev, "failed to register regulator %s\n", | ||
599 | info->desc.name); | ||
600 | return PTR_ERR(info->regulator); | ||
601 | } | ||
602 | |||
603 | return 0; | ||
604 | } | ||
605 | |||
606 | static int hi6421_regulator_probe(struct platform_device *pdev) | ||
607 | { | ||
608 | struct device *dev = &pdev->dev; | ||
609 | struct device_node *np; | ||
610 | struct hi6421_pmic *pmic; | ||
611 | struct hi6421_regulator_pdata *pdata; | ||
612 | int i, ret = 0; | ||
613 | |||
614 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
615 | if (!pdata) | ||
616 | return -ENOMEM; | ||
617 | mutex_init(&pdata->lock); | ||
618 | platform_set_drvdata(pdev, pdata); | ||
619 | |||
620 | np = of_get_child_by_name(dev->parent->of_node, "regulators"); | ||
621 | if (!np) | ||
622 | return -ENODEV; | ||
623 | |||
624 | ret = of_regulator_match(dev, np, | ||
625 | hi6421_regulator_match, | ||
626 | ARRAY_SIZE(hi6421_regulator_match)); | ||
627 | of_node_put(np); | ||
628 | if (ret < 0) { | ||
629 | dev_err(dev, "Error parsing regulator init data: %d\n", ret); | ||
630 | return ret; | ||
631 | } | ||
632 | |||
633 | pmic = dev_get_drvdata(dev->parent); | ||
634 | |||
635 | for (i = 0; i < ARRAY_SIZE(hi6421_regulator_info); i++) { | ||
636 | ret = hi6421_regulator_register(pdev, pmic->regmap, | ||
637 | hi6421_regulator_match[i].init_data, i, | ||
638 | hi6421_regulator_match[i].of_node); | ||
639 | if (ret) | ||
640 | return ret; | ||
641 | } | ||
642 | |||
643 | return 0; | ||
644 | } | ||
645 | |||
646 | static struct platform_driver hi6421_regulator_driver = { | ||
647 | .driver = { | ||
648 | .name = "hi6421-regulator", | ||
649 | .owner = THIS_MODULE, | ||
650 | }, | ||
651 | .probe = hi6421_regulator_probe, | ||
652 | }; | ||
653 | module_platform_driver(hi6421_regulator_driver); | ||
654 | |||
655 | MODULE_AUTHOR("Guodong Xu <guodong.xu@linaro.org>"); | ||
656 | MODULE_DESCRIPTION("Hi6421 regulator driver"); | ||
657 | MODULE_LICENSE("GPL v2"); | ||