hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/drivers/regulator/hi6421-regulator.c
....@@ -1,17 +1,13 @@
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>
1511
1612 #include <linux/slab.h>
1713 #include <linux/device.h>
....@@ -78,43 +74,6 @@
7874 HI6421_NUM_REGULATORS,
7975 };
8076
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
-
11877 /* LDO 0, 4~7, 9~14, 16~20 have same voltage table. */
11978 static const unsigned int ldo_0_voltages[] = {
12079 1500000, 1800000, 2400000, 2500000,
....@@ -128,7 +87,7 @@
12887 };
12988
13089 /* 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[] = {
13291 REGULATOR_LINEAR_RANGE(2800000, 0, 3, 50000),
13392 REGULATOR_LINEAR_RANGE(3000000, 4, 7, 100000),
13493 };
....@@ -157,6 +116,7 @@
157116 #define HI6421_LDO_ENABLE_TIME (350)
158117 /*
159118 * _id - LDO id name string
119
+ * _match - of match name string
160120 * v_table - voltage table
161121 * vreg - voltage select register
162122 * vmask - voltage select mask
....@@ -166,11 +126,13 @@
166126 * ecomask - eco mode mask
167127 * ecoamp - eco mode load uppler limit in uA
168128 */
169
-#define HI6421_LDO(_id, v_table, vreg, vmask, ereg, emask, \
129
+#define HI6421_LDO(_id, _match, v_table, vreg, vmask, ereg, emask, \
170130 odelay, ecomask, ecoamp) \
171131 [HI6421_##_id] = { \
172132 .desc = { \
173133 .name = #_id, \
134
+ .of_match = of_match_ptr(#_match), \
135
+ .regulators_node = of_match_ptr("regulators"), \
174136 .ops = &hi6421_ldo_ops, \
175137 .type = REGULATOR_VOLTAGE, \
176138 .id = HI6421_##_id, \
....@@ -191,6 +153,7 @@
191153 /* HI6421 LDO1~3 are linear voltage regulators at fixed uV_step
192154 *
193155 * _id - LDO id name string
156
+ * _match - of match name string
194157 * _min_uV - minimum voltage supported in uV
195158 * n_volt - number of votages available
196159 * vstep - voltage increase in each linear step in uV
....@@ -202,11 +165,13 @@
202165 * ecomask - eco mode mask
203166 * ecoamp - eco mode load uppler limit in uA
204167 */
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,\
206169 ereg, emask, odelay, ecomask, ecoamp) \
207170 [HI6421_##_id] = { \
208171 .desc = { \
209172 .name = #_id, \
173
+ .of_match = of_match_ptr(#_match), \
174
+ .regulators_node = of_match_ptr("regulators"), \
210175 .ops = &hi6421_ldo_linear_ops, \
211176 .type = REGULATOR_VOLTAGE, \
212177 .id = HI6421_##_id, \
....@@ -228,8 +193,9 @@
228193 /* HI6421 LDOAUDIO is a linear voltage regulator with two 4-step ranges
229194 *
230195 * _id - LDO id name string
196
+ * _match - of match name string
231197 * n_volt - number of votages available
232
- * volt_ranges - array of regulator_linear_range
198
+ * volt_ranges - array of linear_range
233199 * vstep - voltage increase in each linear step in uV
234200 * vreg - voltage select register
235201 * vmask - voltage select mask
....@@ -239,11 +205,13 @@
239205 * ecomask - eco mode mask
240206 * ecoamp - eco mode load uppler limit in uA
241207 */
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,\
243209 ereg, emask, odelay, ecomask, ecoamp) \
244210 [HI6421_##_id] = { \
245211 .desc = { \
246212 .name = #_id, \
213
+ .of_match = of_match_ptr(#_match), \
214
+ .regulators_node = of_match_ptr("regulators"), \
247215 .ops = &hi6421_ldo_linear_range_ops, \
248216 .type = REGULATOR_VOLTAGE, \
249217 .id = HI6421_##_id, \
....@@ -265,6 +233,7 @@
265233 /* HI6421 BUCK0/1/2 are linear voltage regulators at fixed uV_step
266234 *
267235 * _id - BUCK0/1/2 id name string
236
+ * _match - of match name string
268237 * vreg - voltage select register
269238 * vmask - voltage select mask
270239 * ereg - enable register
....@@ -273,11 +242,13 @@
273242 * etime - enable time
274243 * odelay - off/on delay time in uS
275244 */
276
-#define HI6421_BUCK012(_id, vreg, vmask, ereg, emask, sleepmask, \
245
+#define HI6421_BUCK012(_id, _match, vreg, vmask, ereg, emask, sleepmask,\
277246 etime, odelay) \
278247 [HI6421_##_id] = { \
279248 .desc = { \
280249 .name = #_id, \
250
+ .of_match = of_match_ptr(#_match), \
251
+ .regulators_node = of_match_ptr("regulators"), \
281252 .ops = &hi6421_buck012_ops, \
282253 .type = REGULATOR_VOLTAGE, \
283254 .id = HI6421_##_id, \
....@@ -299,6 +270,7 @@
299270 * that it supports SLEEP mode, so has different .ops.
300271 *
301272 * _id - LDO id name string
273
+ * _match - of match name string
302274 * v_table - voltage table
303275 * vreg - voltage select register
304276 * vmask - voltage select mask
....@@ -307,11 +279,13 @@
307279 * odelay - off/on delay time in uS
308280 * sleepmask - mask of sleep mode
309281 */
310
-#define HI6421_BUCK345(_id, v_table, vreg, vmask, ereg, emask, \
282
+#define HI6421_BUCK345(_id, _match, v_table, vreg, vmask, ereg, emask, \
311283 odelay, sleepmask) \
312284 [HI6421_##_id] = { \
313285 .desc = { \
314286 .name = #_id, \
287
+ .of_match = of_match_ptr(#_match), \
288
+ .regulators_node = of_match_ptr("regulators"), \
315289 .ops = &hi6421_buck345_ops, \
316290 .type = REGULATOR_VOLTAGE, \
317291 .id = HI6421_##_id, \
....@@ -331,66 +305,69 @@
331305 /* HI6421 regulator information */
332306 static struct hi6421_regulator_info
333307 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,
335309 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,
343317 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,
345319 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,
347321 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,
349323 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,
351325 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,
353327 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,
355329 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,
357331 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,
359333 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,
361335 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,
363337 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,
365339 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,
367341 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,
369343 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,
371345 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,
373347 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,
375349 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),
387365 };
388366
389367 static int hi6421_regulator_enable(struct regulator_dev *rdev)
390368 {
391
- struct hi6421_regulator_pdata *pdata;
369
+ struct hi6421_regulator_pdata *pdata = rdev_get_drvdata(rdev);
392370
393
- pdata = dev_get_drvdata(rdev->dev.parent);
394371 /* hi6421 spec requires regulator enablement must be serialized:
395372 * - Because when BUCK, LDO switching from off to on, it will have
396373 * a huge instantaneous current; so you can not turn on two or
....@@ -407,9 +384,10 @@
407384
408385 static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev)
409386 {
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;
412389
390
+ info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
413391 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val);
414392 if (reg_val & info->mode_mask)
415393 return REGULATOR_MODE_IDLE;
....@@ -419,9 +397,10 @@
419397
420398 static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev)
421399 {
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;
424402
403
+ info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
425404 regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val);
426405 if (reg_val & info->mode_mask)
427406 return REGULATOR_MODE_STANDBY;
....@@ -432,9 +411,10 @@
432411 static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev,
433412 unsigned int mode)
434413 {
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;
437416
417
+ info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
438418 switch (mode) {
439419 case REGULATOR_MODE_NORMAL:
440420 new_mode = 0;
....@@ -456,9 +436,10 @@
456436 static int hi6421_regulator_buck_set_mode(struct regulator_dev *rdev,
457437 unsigned int mode)
458438 {
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;
461441
442
+ info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
462443 switch (mode) {
463444 case REGULATOR_MODE_NORMAL:
464445 new_mode = 0;
....@@ -481,7 +462,9 @@
481462 hi6421_regulator_ldo_get_optimum_mode(struct regulator_dev *rdev,
482463 int input_uV, int output_uV, int load_uA)
483464 {
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);
485468
486469 if (load_uA > info->eco_microamp)
487470 return REGULATOR_MODE_NORMAL;
....@@ -552,70 +535,35 @@
552535 .set_mode = hi6421_regulator_buck_set_mode,
553536 };
554537
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
-
584538 static int hi6421_regulator_probe(struct platform_device *pdev)
585539 {
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);
589541 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;
591546
592547 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
593548 if (!pdata)
594549 return -ENOMEM;
595550 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);
612551
613552 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
+ }
619567 }
620568
621569 return 0;