.. | .. |
---|
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 | | - */ |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
| 2 | +// |
---|
| 3 | +// Device driver for regulators in Hi6421 IC |
---|
| 4 | +// |
---|
| 5 | +// Copyright (c) <2011-2014> HiSilicon Technologies Co., Ltd. |
---|
| 6 | +// http://www.hisilicon.com |
---|
| 7 | +// Copyright (c) <2013-2014> Linaro Ltd. |
---|
| 8 | +// https://www.linaro.org |
---|
| 9 | +// |
---|
| 10 | +// Author: Guodong Xu <guodong.xu@linaro.org> |
---|
15 | 11 | |
---|
16 | 12 | #include <linux/slab.h> |
---|
17 | 13 | #include <linux/device.h> |
---|
.. | .. |
---|
78 | 74 | HI6421_NUM_REGULATORS, |
---|
79 | 75 | }; |
---|
80 | 76 | |
---|
81 | | -#define HI6421_REGULATOR_OF_MATCH(_name, id) \ |
---|
82 | | -{ \ |
---|
83 | | - .name = #_name, \ |
---|
84 | | - .driver_data = (void *) HI6421_##id, \ |
---|
85 | | -} |
---|
86 | | - |
---|
87 | | -static struct of_regulator_match hi6421_regulator_match[] = { |
---|
88 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout0, LDO0), |
---|
89 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout1, LDO1), |
---|
90 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout2, LDO2), |
---|
91 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout3, LDO3), |
---|
92 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout4, LDO4), |
---|
93 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout5, LDO5), |
---|
94 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout6, LDO6), |
---|
95 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout7, LDO7), |
---|
96 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout8, LDO8), |
---|
97 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout9, LDO9), |
---|
98 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout10, LDO10), |
---|
99 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout11, LDO11), |
---|
100 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout12, LDO12), |
---|
101 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout13, LDO13), |
---|
102 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout14, LDO14), |
---|
103 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout15, LDO15), |
---|
104 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout16, LDO16), |
---|
105 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout17, LDO17), |
---|
106 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout18, LDO18), |
---|
107 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout19, LDO19), |
---|
108 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout20, LDO20), |
---|
109 | | - HI6421_REGULATOR_OF_MATCH(hi6421_vout_audio, LDOAUDIO), |
---|
110 | | - HI6421_REGULATOR_OF_MATCH(hi6421_buck0, BUCK0), |
---|
111 | | - HI6421_REGULATOR_OF_MATCH(hi6421_buck1, BUCK1), |
---|
112 | | - HI6421_REGULATOR_OF_MATCH(hi6421_buck2, BUCK2), |
---|
113 | | - HI6421_REGULATOR_OF_MATCH(hi6421_buck3, BUCK3), |
---|
114 | | - HI6421_REGULATOR_OF_MATCH(hi6421_buck4, BUCK4), |
---|
115 | | - HI6421_REGULATOR_OF_MATCH(hi6421_buck5, BUCK5), |
---|
116 | | -}; |
---|
117 | | - |
---|
118 | 77 | /* LDO 0, 4~7, 9~14, 16~20 have same voltage table. */ |
---|
119 | 78 | static const unsigned int ldo_0_voltages[] = { |
---|
120 | 79 | 1500000, 1800000, 2400000, 2500000, |
---|
.. | .. |
---|
128 | 87 | }; |
---|
129 | 88 | |
---|
130 | 89 | /* Ranges are sorted in ascending order. */ |
---|
131 | | -static const struct regulator_linear_range ldo_audio_volt_range[] = { |
---|
| 90 | +static const struct linear_range ldo_audio_volt_range[] = { |
---|
132 | 91 | REGULATOR_LINEAR_RANGE(2800000, 0, 3, 50000), |
---|
133 | 92 | REGULATOR_LINEAR_RANGE(3000000, 4, 7, 100000), |
---|
134 | 93 | }; |
---|
.. | .. |
---|
157 | 116 | #define HI6421_LDO_ENABLE_TIME (350) |
---|
158 | 117 | /* |
---|
159 | 118 | * _id - LDO id name string |
---|
| 119 | + * _match - of match name string |
---|
160 | 120 | * v_table - voltage table |
---|
161 | 121 | * vreg - voltage select register |
---|
162 | 122 | * vmask - voltage select mask |
---|
.. | .. |
---|
166 | 126 | * ecomask - eco mode mask |
---|
167 | 127 | * ecoamp - eco mode load uppler limit in uA |
---|
168 | 128 | */ |
---|
169 | | -#define HI6421_LDO(_id, v_table, vreg, vmask, ereg, emask, \ |
---|
| 129 | +#define HI6421_LDO(_id, _match, v_table, vreg, vmask, ereg, emask, \ |
---|
170 | 130 | odelay, ecomask, ecoamp) \ |
---|
171 | 131 | [HI6421_##_id] = { \ |
---|
172 | 132 | .desc = { \ |
---|
173 | 133 | .name = #_id, \ |
---|
| 134 | + .of_match = of_match_ptr(#_match), \ |
---|
| 135 | + .regulators_node = of_match_ptr("regulators"), \ |
---|
174 | 136 | .ops = &hi6421_ldo_ops, \ |
---|
175 | 137 | .type = REGULATOR_VOLTAGE, \ |
---|
176 | 138 | .id = HI6421_##_id, \ |
---|
.. | .. |
---|
191 | 153 | /* HI6421 LDO1~3 are linear voltage regulators at fixed uV_step |
---|
192 | 154 | * |
---|
193 | 155 | * _id - LDO id name string |
---|
| 156 | + * _match - of match name string |
---|
194 | 157 | * _min_uV - minimum voltage supported in uV |
---|
195 | 158 | * n_volt - number of votages available |
---|
196 | 159 | * vstep - voltage increase in each linear step in uV |
---|
.. | .. |
---|
202 | 165 | * ecomask - eco mode mask |
---|
203 | 166 | * ecoamp - eco mode load uppler limit in uA |
---|
204 | 167 | */ |
---|
205 | | -#define HI6421_LDO_LINEAR(_id, _min_uV, n_volt, vstep, vreg, vmask, \ |
---|
| 168 | +#define HI6421_LDO_LINEAR(_id, _match, _min_uV, n_volt, vstep, vreg, vmask,\ |
---|
206 | 169 | ereg, emask, odelay, ecomask, ecoamp) \ |
---|
207 | 170 | [HI6421_##_id] = { \ |
---|
208 | 171 | .desc = { \ |
---|
209 | 172 | .name = #_id, \ |
---|
| 173 | + .of_match = of_match_ptr(#_match), \ |
---|
| 174 | + .regulators_node = of_match_ptr("regulators"), \ |
---|
210 | 175 | .ops = &hi6421_ldo_linear_ops, \ |
---|
211 | 176 | .type = REGULATOR_VOLTAGE, \ |
---|
212 | 177 | .id = HI6421_##_id, \ |
---|
.. | .. |
---|
228 | 193 | /* HI6421 LDOAUDIO is a linear voltage regulator with two 4-step ranges |
---|
229 | 194 | * |
---|
230 | 195 | * _id - LDO id name string |
---|
| 196 | + * _match - of match name string |
---|
231 | 197 | * n_volt - number of votages available |
---|
232 | | - * volt_ranges - array of regulator_linear_range |
---|
| 198 | + * volt_ranges - array of linear_range |
---|
233 | 199 | * vstep - voltage increase in each linear step in uV |
---|
234 | 200 | * vreg - voltage select register |
---|
235 | 201 | * vmask - voltage select mask |
---|
.. | .. |
---|
239 | 205 | * ecomask - eco mode mask |
---|
240 | 206 | * ecoamp - eco mode load uppler limit in uA |
---|
241 | 207 | */ |
---|
242 | | -#define HI6421_LDO_LINEAR_RANGE(_id, n_volt, volt_ranges, vreg, vmask, \ |
---|
| 208 | +#define HI6421_LDO_LINEAR_RANGE(_id, _match, n_volt, volt_ranges, vreg, vmask,\ |
---|
243 | 209 | ereg, emask, odelay, ecomask, ecoamp) \ |
---|
244 | 210 | [HI6421_##_id] = { \ |
---|
245 | 211 | .desc = { \ |
---|
246 | 212 | .name = #_id, \ |
---|
| 213 | + .of_match = of_match_ptr(#_match), \ |
---|
| 214 | + .regulators_node = of_match_ptr("regulators"), \ |
---|
247 | 215 | .ops = &hi6421_ldo_linear_range_ops, \ |
---|
248 | 216 | .type = REGULATOR_VOLTAGE, \ |
---|
249 | 217 | .id = HI6421_##_id, \ |
---|
.. | .. |
---|
265 | 233 | /* HI6421 BUCK0/1/2 are linear voltage regulators at fixed uV_step |
---|
266 | 234 | * |
---|
267 | 235 | * _id - BUCK0/1/2 id name string |
---|
| 236 | + * _match - of match name string |
---|
268 | 237 | * vreg - voltage select register |
---|
269 | 238 | * vmask - voltage select mask |
---|
270 | 239 | * ereg - enable register |
---|
.. | .. |
---|
273 | 242 | * etime - enable time |
---|
274 | 243 | * odelay - off/on delay time in uS |
---|
275 | 244 | */ |
---|
276 | | -#define HI6421_BUCK012(_id, vreg, vmask, ereg, emask, sleepmask, \ |
---|
| 245 | +#define HI6421_BUCK012(_id, _match, vreg, vmask, ereg, emask, sleepmask,\ |
---|
277 | 246 | etime, odelay) \ |
---|
278 | 247 | [HI6421_##_id] = { \ |
---|
279 | 248 | .desc = { \ |
---|
280 | 249 | .name = #_id, \ |
---|
| 250 | + .of_match = of_match_ptr(#_match), \ |
---|
| 251 | + .regulators_node = of_match_ptr("regulators"), \ |
---|
281 | 252 | .ops = &hi6421_buck012_ops, \ |
---|
282 | 253 | .type = REGULATOR_VOLTAGE, \ |
---|
283 | 254 | .id = HI6421_##_id, \ |
---|
.. | .. |
---|
299 | 270 | * that it supports SLEEP mode, so has different .ops. |
---|
300 | 271 | * |
---|
301 | 272 | * _id - LDO id name string |
---|
| 273 | + * _match - of match name string |
---|
302 | 274 | * v_table - voltage table |
---|
303 | 275 | * vreg - voltage select register |
---|
304 | 276 | * vmask - voltage select mask |
---|
.. | .. |
---|
307 | 279 | * odelay - off/on delay time in uS |
---|
308 | 280 | * sleepmask - mask of sleep mode |
---|
309 | 281 | */ |
---|
310 | | -#define HI6421_BUCK345(_id, v_table, vreg, vmask, ereg, emask, \ |
---|
| 282 | +#define HI6421_BUCK345(_id, _match, v_table, vreg, vmask, ereg, emask, \ |
---|
311 | 283 | odelay, sleepmask) \ |
---|
312 | 284 | [HI6421_##_id] = { \ |
---|
313 | 285 | .desc = { \ |
---|
314 | 286 | .name = #_id, \ |
---|
| 287 | + .of_match = of_match_ptr(#_match), \ |
---|
| 288 | + .regulators_node = of_match_ptr("regulators"), \ |
---|
315 | 289 | .ops = &hi6421_buck345_ops, \ |
---|
316 | 290 | .type = REGULATOR_VOLTAGE, \ |
---|
317 | 291 | .id = HI6421_##_id, \ |
---|
.. | .. |
---|
331 | 305 | /* HI6421 regulator information */ |
---|
332 | 306 | static struct hi6421_regulator_info |
---|
333 | 307 | hi6421_regulator_info[HI6421_NUM_REGULATORS] = { |
---|
334 | | - HI6421_LDO(LDO0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10, |
---|
| 308 | + HI6421_LDO(LDO0, hi6421_vout0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10, |
---|
335 | 309 | 10000, 0x20, 8000), |
---|
336 | | - HI6421_LDO_LINEAR(LDO1, 1700000, 4, 100000, 0x21, 0x03, 0x21, 0x10, |
---|
337 | | - 10000, 0x20, 5000), |
---|
338 | | - HI6421_LDO_LINEAR(LDO2, 1050000, 8, 50000, 0x22, 0x07, 0x22, 0x10, |
---|
339 | | - 20000, 0x20, 8000), |
---|
340 | | - HI6421_LDO_LINEAR(LDO3, 1050000, 8, 50000, 0x23, 0x07, 0x23, 0x10, |
---|
341 | | - 20000, 0x20, 8000), |
---|
342 | | - HI6421_LDO(LDO4, ldo_0_voltages, 0x24, 0x07, 0x24, 0x10, |
---|
| 310 | + HI6421_LDO_LINEAR(LDO1, hi6421_vout1, 1700000, 4, 100000, 0x21, 0x03, |
---|
| 311 | + 0x21, 0x10, 10000, 0x20, 5000), |
---|
| 312 | + HI6421_LDO_LINEAR(LDO2, hi6421_vout2, 1050000, 8, 50000, 0x22, 0x07, |
---|
| 313 | + 0x22, 0x10, 20000, 0x20, 8000), |
---|
| 314 | + HI6421_LDO_LINEAR(LDO3, hi6421_vout3, 1050000, 8, 50000, 0x23, 0x07, |
---|
| 315 | + 0x23, 0x10, 20000, 0x20, 8000), |
---|
| 316 | + HI6421_LDO(LDO4, hi6421_vout4, ldo_0_voltages, 0x24, 0x07, 0x24, 0x10, |
---|
343 | 317 | 20000, 0x20, 8000), |
---|
344 | | - HI6421_LDO(LDO5, ldo_0_voltages, 0x25, 0x07, 0x25, 0x10, |
---|
| 318 | + HI6421_LDO(LDO5, hi6421_vout5, ldo_0_voltages, 0x25, 0x07, 0x25, 0x10, |
---|
345 | 319 | 20000, 0x20, 8000), |
---|
346 | | - HI6421_LDO(LDO6, ldo_0_voltages, 0x26, 0x07, 0x26, 0x10, |
---|
| 320 | + HI6421_LDO(LDO6, hi6421_vout6, ldo_0_voltages, 0x26, 0x07, 0x26, 0x10, |
---|
347 | 321 | 20000, 0x20, 8000), |
---|
348 | | - HI6421_LDO(LDO7, ldo_0_voltages, 0x27, 0x07, 0x27, 0x10, |
---|
| 322 | + HI6421_LDO(LDO7, hi6421_vout7, ldo_0_voltages, 0x27, 0x07, 0x27, 0x10, |
---|
349 | 323 | 20000, 0x20, 5000), |
---|
350 | | - HI6421_LDO(LDO8, ldo_8_voltages, 0x28, 0x07, 0x28, 0x10, |
---|
| 324 | + HI6421_LDO(LDO8, hi6421_vout8, ldo_8_voltages, 0x28, 0x07, 0x28, 0x10, |
---|
351 | 325 | 20000, 0x20, 8000), |
---|
352 | | - HI6421_LDO(LDO9, ldo_0_voltages, 0x29, 0x07, 0x29, 0x10, |
---|
| 326 | + HI6421_LDO(LDO9, hi6421_vout9, ldo_0_voltages, 0x29, 0x07, 0x29, 0x10, |
---|
353 | 327 | 40000, 0x20, 8000), |
---|
354 | | - HI6421_LDO(LDO10, ldo_0_voltages, 0x2a, 0x07, 0x2a, 0x10, |
---|
| 328 | + HI6421_LDO(LDO10, hi6421_vout10, ldo_0_voltages, 0x2a, 0x07, 0x2a, 0x10, |
---|
355 | 329 | 40000, 0x20, 8000), |
---|
356 | | - HI6421_LDO(LDO11, ldo_0_voltages, 0x2b, 0x07, 0x2b, 0x10, |
---|
| 330 | + HI6421_LDO(LDO11, hi6421_vout11, ldo_0_voltages, 0x2b, 0x07, 0x2b, 0x10, |
---|
357 | 331 | 40000, 0x20, 8000), |
---|
358 | | - HI6421_LDO(LDO12, ldo_0_voltages, 0x2c, 0x07, 0x2c, 0x10, |
---|
| 332 | + HI6421_LDO(LDO12, hi6421_vout12, ldo_0_voltages, 0x2c, 0x07, 0x2c, 0x10, |
---|
359 | 333 | 40000, 0x20, 8000), |
---|
360 | | - HI6421_LDO(LDO13, ldo_0_voltages, 0x2d, 0x07, 0x2d, 0x10, |
---|
| 334 | + HI6421_LDO(LDO13, hi6421_vout13, ldo_0_voltages, 0x2d, 0x07, 0x2d, 0x10, |
---|
361 | 335 | 40000, 0x20, 8000), |
---|
362 | | - HI6421_LDO(LDO14, ldo_0_voltages, 0x2e, 0x07, 0x2e, 0x10, |
---|
| 336 | + HI6421_LDO(LDO14, hi6421_vout14, ldo_0_voltages, 0x2e, 0x07, 0x2e, 0x10, |
---|
363 | 337 | 40000, 0x20, 8000), |
---|
364 | | - HI6421_LDO(LDO15, ldo_8_voltages, 0x2f, 0x07, 0x2f, 0x10, |
---|
| 338 | + HI6421_LDO(LDO15, hi6421_vout15, ldo_8_voltages, 0x2f, 0x07, 0x2f, 0x10, |
---|
365 | 339 | 40000, 0x20, 8000), |
---|
366 | | - HI6421_LDO(LDO16, ldo_0_voltages, 0x30, 0x07, 0x30, 0x10, |
---|
| 340 | + HI6421_LDO(LDO16, hi6421_vout16, ldo_0_voltages, 0x30, 0x07, 0x30, 0x10, |
---|
367 | 341 | 40000, 0x20, 8000), |
---|
368 | | - HI6421_LDO(LDO17, ldo_0_voltages, 0x31, 0x07, 0x31, 0x10, |
---|
| 342 | + HI6421_LDO(LDO17, hi6421_vout17, ldo_0_voltages, 0x31, 0x07, 0x31, 0x10, |
---|
369 | 343 | 40000, 0x20, 8000), |
---|
370 | | - HI6421_LDO(LDO18, ldo_0_voltages, 0x32, 0x07, 0x32, 0x10, |
---|
| 344 | + HI6421_LDO(LDO18, hi6421_vout18, ldo_0_voltages, 0x32, 0x07, 0x32, 0x10, |
---|
371 | 345 | 40000, 0x20, 8000), |
---|
372 | | - HI6421_LDO(LDO19, ldo_0_voltages, 0x33, 0x07, 0x33, 0x10, |
---|
| 346 | + HI6421_LDO(LDO19, hi6421_vout19, ldo_0_voltages, 0x33, 0x07, 0x33, 0x10, |
---|
373 | 347 | 40000, 0x20, 8000), |
---|
374 | | - HI6421_LDO(LDO20, ldo_0_voltages, 0x34, 0x07, 0x34, 0x10, |
---|
| 348 | + HI6421_LDO(LDO20, hi6421_vout20, ldo_0_voltages, 0x34, 0x07, 0x34, 0x10, |
---|
375 | 349 | 40000, 0x20, 8000), |
---|
376 | | - HI6421_LDO_LINEAR_RANGE(LDOAUDIO, 8, ldo_audio_volt_range, 0x36, |
---|
377 | | - 0x70, 0x36, 0x01, 40000, 0x02, 5000), |
---|
378 | | - HI6421_BUCK012(BUCK0, 0x0d, 0x7f, 0x0c, 0x01, 0x10, 400, 20000), |
---|
379 | | - HI6421_BUCK012(BUCK1, 0x0f, 0x7f, 0x0e, 0x01, 0x10, 400, 20000), |
---|
380 | | - HI6421_BUCK012(BUCK2, 0x11, 0x7f, 0x10, 0x01, 0x10, 350, 100), |
---|
381 | | - HI6421_BUCK345(BUCK3, buck_3_voltages, 0x13, 0x07, 0x12, 0x01, |
---|
382 | | - 20000, 0x10), |
---|
383 | | - HI6421_BUCK345(BUCK4, buck_4_voltages, 0x15, 0x07, 0x14, 0x01, |
---|
384 | | - 20000, 0x10), |
---|
385 | | - HI6421_BUCK345(BUCK5, buck_5_voltages, 0x17, 0x07, 0x16, 0x01, |
---|
386 | | - 20000, 0x10), |
---|
| 350 | + HI6421_LDO_LINEAR_RANGE(LDOAUDIO, hi6421_vout_audio, 8, |
---|
| 351 | + ldo_audio_volt_range, 0x36, 0x70, 0x36, 0x01, |
---|
| 352 | + 40000, 0x02, 5000), |
---|
| 353 | + HI6421_BUCK012(BUCK0, hi6421_buck0, 0x0d, 0x7f, 0x0c, 0x01, 0x10, 400, |
---|
| 354 | + 20000), |
---|
| 355 | + HI6421_BUCK012(BUCK1, hi6421_buck1, 0x0f, 0x7f, 0x0e, 0x01, 0x10, 400, |
---|
| 356 | + 20000), |
---|
| 357 | + HI6421_BUCK012(BUCK2, hi6421_buck2, 0x11, 0x7f, 0x10, 0x01, 0x10, 350, |
---|
| 358 | + 100), |
---|
| 359 | + HI6421_BUCK345(BUCK3, hi6421_buck3, buck_3_voltages, 0x13, 0x07, 0x12, |
---|
| 360 | + 0x01, 20000, 0x10), |
---|
| 361 | + HI6421_BUCK345(BUCK4, hi6421_buck4, buck_4_voltages, 0x15, 0x07, 0x14, |
---|
| 362 | + 0x01, 20000, 0x10), |
---|
| 363 | + HI6421_BUCK345(BUCK5, hi6421_buck5, buck_5_voltages, 0x17, 0x07, 0x16, |
---|
| 364 | + 0x01, 20000, 0x10), |
---|
387 | 365 | }; |
---|
388 | 366 | |
---|
389 | 367 | static int hi6421_regulator_enable(struct regulator_dev *rdev) |
---|
390 | 368 | { |
---|
391 | | - struct hi6421_regulator_pdata *pdata; |
---|
| 369 | + struct hi6421_regulator_pdata *pdata = rdev_get_drvdata(rdev); |
---|
392 | 370 | |
---|
393 | | - pdata = dev_get_drvdata(rdev->dev.parent); |
---|
394 | 371 | /* hi6421 spec requires regulator enablement must be serialized: |
---|
395 | 372 | * - Because when BUCK, LDO switching from off to on, it will have |
---|
396 | 373 | * a huge instantaneous current; so you can not turn on two or |
---|
.. | .. |
---|
407 | 384 | |
---|
408 | 385 | static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev) |
---|
409 | 386 | { |
---|
410 | | - struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); |
---|
411 | | - u32 reg_val; |
---|
| 387 | + struct hi6421_regulator_info *info; |
---|
| 388 | + unsigned int reg_val; |
---|
412 | 389 | |
---|
| 390 | + info = container_of(rdev->desc, struct hi6421_regulator_info, desc); |
---|
413 | 391 | regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val); |
---|
414 | 392 | if (reg_val & info->mode_mask) |
---|
415 | 393 | return REGULATOR_MODE_IDLE; |
---|
.. | .. |
---|
419 | 397 | |
---|
420 | 398 | static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev) |
---|
421 | 399 | { |
---|
422 | | - struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); |
---|
423 | | - u32 reg_val; |
---|
| 400 | + struct hi6421_regulator_info *info; |
---|
| 401 | + unsigned int reg_val; |
---|
424 | 402 | |
---|
| 403 | + info = container_of(rdev->desc, struct hi6421_regulator_info, desc); |
---|
425 | 404 | regmap_read(rdev->regmap, rdev->desc->enable_reg, ®_val); |
---|
426 | 405 | if (reg_val & info->mode_mask) |
---|
427 | 406 | return REGULATOR_MODE_STANDBY; |
---|
.. | .. |
---|
432 | 411 | static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev, |
---|
433 | 412 | unsigned int mode) |
---|
434 | 413 | { |
---|
435 | | - struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); |
---|
436 | | - u32 new_mode; |
---|
| 414 | + struct hi6421_regulator_info *info; |
---|
| 415 | + unsigned int new_mode; |
---|
437 | 416 | |
---|
| 417 | + info = container_of(rdev->desc, struct hi6421_regulator_info, desc); |
---|
438 | 418 | switch (mode) { |
---|
439 | 419 | case REGULATOR_MODE_NORMAL: |
---|
440 | 420 | new_mode = 0; |
---|
.. | .. |
---|
456 | 436 | static int hi6421_regulator_buck_set_mode(struct regulator_dev *rdev, |
---|
457 | 437 | unsigned int mode) |
---|
458 | 438 | { |
---|
459 | | - struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); |
---|
460 | | - u32 new_mode; |
---|
| 439 | + struct hi6421_regulator_info *info; |
---|
| 440 | + unsigned int new_mode; |
---|
461 | 441 | |
---|
| 442 | + info = container_of(rdev->desc, struct hi6421_regulator_info, desc); |
---|
462 | 443 | switch (mode) { |
---|
463 | 444 | case REGULATOR_MODE_NORMAL: |
---|
464 | 445 | new_mode = 0; |
---|
.. | .. |
---|
481 | 462 | hi6421_regulator_ldo_get_optimum_mode(struct regulator_dev *rdev, |
---|
482 | 463 | int input_uV, int output_uV, int load_uA) |
---|
483 | 464 | { |
---|
484 | | - struct hi6421_regulator_info *info = rdev_get_drvdata(rdev); |
---|
| 465 | + struct hi6421_regulator_info *info; |
---|
| 466 | + |
---|
| 467 | + info = container_of(rdev->desc, struct hi6421_regulator_info, desc); |
---|
485 | 468 | |
---|
486 | 469 | if (load_uA > info->eco_microamp) |
---|
487 | 470 | return REGULATOR_MODE_NORMAL; |
---|
.. | .. |
---|
552 | 535 | .set_mode = hi6421_regulator_buck_set_mode, |
---|
553 | 536 | }; |
---|
554 | 537 | |
---|
555 | | -static int hi6421_regulator_register(struct platform_device *pdev, |
---|
556 | | - struct regmap *rmap, |
---|
557 | | - struct regulator_init_data *init_data, |
---|
558 | | - int id, struct device_node *np) |
---|
559 | | -{ |
---|
560 | | - struct hi6421_regulator_info *info = NULL; |
---|
561 | | - struct regulator_config config = { }; |
---|
562 | | - struct regulator_dev *rdev; |
---|
563 | | - |
---|
564 | | - /* assign per-regulator data */ |
---|
565 | | - info = &hi6421_regulator_info[id]; |
---|
566 | | - |
---|
567 | | - config.dev = &pdev->dev; |
---|
568 | | - config.init_data = init_data; |
---|
569 | | - config.driver_data = info; |
---|
570 | | - config.regmap = rmap; |
---|
571 | | - config.of_node = np; |
---|
572 | | - |
---|
573 | | - /* register regulator with framework */ |
---|
574 | | - rdev = devm_regulator_register(&pdev->dev, &info->desc, &config); |
---|
575 | | - if (IS_ERR(rdev)) { |
---|
576 | | - dev_err(&pdev->dev, "failed to register regulator %s\n", |
---|
577 | | - info->desc.name); |
---|
578 | | - return PTR_ERR(rdev); |
---|
579 | | - } |
---|
580 | | - |
---|
581 | | - return 0; |
---|
582 | | -} |
---|
583 | | - |
---|
584 | 538 | static int hi6421_regulator_probe(struct platform_device *pdev) |
---|
585 | 539 | { |
---|
586 | | - struct device *dev = &pdev->dev; |
---|
587 | | - struct device_node *np; |
---|
588 | | - struct hi6421_pmic *pmic; |
---|
| 540 | + struct hi6421_pmic *pmic = dev_get_drvdata(pdev->dev.parent); |
---|
589 | 541 | struct hi6421_regulator_pdata *pdata; |
---|
590 | | - int i, ret = 0; |
---|
| 542 | + struct hi6421_regulator_info *info; |
---|
| 543 | + struct regulator_config config = { }; |
---|
| 544 | + struct regulator_dev *rdev; |
---|
| 545 | + int i; |
---|
591 | 546 | |
---|
592 | 547 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
---|
593 | 548 | if (!pdata) |
---|
594 | 549 | return -ENOMEM; |
---|
595 | 550 | mutex_init(&pdata->lock); |
---|
596 | | - platform_set_drvdata(pdev, pdata); |
---|
597 | | - |
---|
598 | | - np = of_get_child_by_name(dev->parent->of_node, "regulators"); |
---|
599 | | - if (!np) |
---|
600 | | - return -ENODEV; |
---|
601 | | - |
---|
602 | | - ret = of_regulator_match(dev, np, |
---|
603 | | - hi6421_regulator_match, |
---|
604 | | - ARRAY_SIZE(hi6421_regulator_match)); |
---|
605 | | - of_node_put(np); |
---|
606 | | - if (ret < 0) { |
---|
607 | | - dev_err(dev, "Error parsing regulator init data: %d\n", ret); |
---|
608 | | - return ret; |
---|
609 | | - } |
---|
610 | | - |
---|
611 | | - pmic = dev_get_drvdata(dev->parent); |
---|
612 | 551 | |
---|
613 | 552 | for (i = 0; i < ARRAY_SIZE(hi6421_regulator_info); i++) { |
---|
614 | | - ret = hi6421_regulator_register(pdev, pmic->regmap, |
---|
615 | | - hi6421_regulator_match[i].init_data, i, |
---|
616 | | - hi6421_regulator_match[i].of_node); |
---|
617 | | - if (ret) |
---|
618 | | - return ret; |
---|
| 553 | + /* assign per-regulator data */ |
---|
| 554 | + info = &hi6421_regulator_info[i]; |
---|
| 555 | + |
---|
| 556 | + config.dev = pdev->dev.parent; |
---|
| 557 | + config.driver_data = pdata; |
---|
| 558 | + config.regmap = pmic->regmap; |
---|
| 559 | + |
---|
| 560 | + rdev = devm_regulator_register(&pdev->dev, &info->desc, |
---|
| 561 | + &config); |
---|
| 562 | + if (IS_ERR(rdev)) { |
---|
| 563 | + dev_err(&pdev->dev, "failed to register regulator %s\n", |
---|
| 564 | + info->desc.name); |
---|
| 565 | + return PTR_ERR(rdev); |
---|
| 566 | + } |
---|
619 | 567 | } |
---|
620 | 568 | |
---|
621 | 569 | return 0; |
---|