forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/regulator/da9063-regulator.c
....@@ -1,18 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0+
2
+//
3
+// Regulator driver for DA9063 PMIC series
4
+//
5
+// Copyright 2012 Dialog Semiconductors Ltd.
6
+// Copyright 2013 Philipp Zabel, Pengutronix
7
+//
8
+// Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
19
2
-/*
3
- * Regulator driver for DA9063 PMIC series
4
- *
5
- * Copyright 2012 Dialog Semiconductors Ltd.
6
- * Copyright 2013 Philipp Zabel, Pengutronix
7
- *
8
- * Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com>
9
- *
10
- * This program is free software; you can redistribute it and/or modify it
11
- * under the terms of the GNU General Public License as published by the
12
- * Free Software Foundation; either version 2 of the License, or (at your
13
- * option) any later version.
14
- *
15
- */
1610 #include <linux/kernel.h>
1711 #include <linux/module.h>
1812 #include <linux/init.h>
....@@ -25,7 +19,6 @@
2519 #include <linux/regulator/machine.h>
2620 #include <linux/regulator/of_regulator.h>
2721 #include <linux/mfd/da9063/core.h>
28
-#include <linux/mfd/da9063/pdata.h>
2922 #include <linux/mfd/da9063/registers.h>
3023
3124
....@@ -34,13 +27,52 @@
3427 REG_FIELD(_reg, __builtin_ffs((int)_mask) - 1, \
3528 sizeof(unsigned int) * 8 - __builtin_clz((_mask)) - 1)
3629
30
+/* DA9063 and DA9063L regulator IDs */
31
+enum {
32
+ /* BUCKs */
33
+ DA9063_ID_BCORE1,
34
+ DA9063_ID_BCORE2,
35
+ DA9063_ID_BPRO,
36
+ DA9063_ID_BMEM,
37
+ DA9063_ID_BIO,
38
+ DA9063_ID_BPERI,
39
+
40
+ /* BCORE1 and BCORE2 in merged mode */
41
+ DA9063_ID_BCORES_MERGED,
42
+ /* BMEM and BIO in merged mode */
43
+ DA9063_ID_BMEM_BIO_MERGED,
44
+ /* When two BUCKs are merged, they cannot be reused separately */
45
+
46
+ /* LDOs on both DA9063 and DA9063L */
47
+ DA9063_ID_LDO3,
48
+ DA9063_ID_LDO7,
49
+ DA9063_ID_LDO8,
50
+ DA9063_ID_LDO9,
51
+ DA9063_ID_LDO11,
52
+
53
+ /* DA9063-only LDOs */
54
+ DA9063_ID_LDO1,
55
+ DA9063_ID_LDO2,
56
+ DA9063_ID_LDO4,
57
+ DA9063_ID_LDO5,
58
+ DA9063_ID_LDO6,
59
+ DA9063_ID_LDO10,
60
+};
61
+
62
+/* Old regulator platform data */
63
+struct da9063_regulator_data {
64
+ int id;
65
+ struct regulator_init_data *initdata;
66
+};
67
+
68
+struct da9063_regulators_pdata {
69
+ unsigned int n_regulators;
70
+ struct da9063_regulator_data *regulator_data;
71
+};
72
+
3773 /* Regulator capabilities and registers description */
3874 struct da9063_regulator_info {
3975 struct regulator_desc desc;
40
-
41
- /* Current limiting */
42
- unsigned n_current_limits;
43
- const int *current_limits;
4476
4577 /* DA9063 main register fields */
4678 struct reg_field mode; /* buck mode of operation */
....@@ -48,7 +80,6 @@
4880 struct reg_field sleep;
4981 struct reg_field suspend_sleep;
5082 unsigned int suspend_vsel_reg;
51
- struct reg_field ilimit;
5283
5384 /* DA9063 event detection bit */
5485 struct reg_field oc_event;
....@@ -69,19 +100,23 @@
69100 .desc.vsel_mask = DA9063_V##regl_name##_MASK, \
70101 .desc.linear_min_sel = DA9063_V##regl_name##_BIAS, \
71102 .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_LDO_SL), \
103
+ .suspend = BFIELD(DA9063_REG_##regl_name##_CONT, DA9063_LDO_CONF), \
72104 .suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_LDO_SL), \
73105 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B
74106
75107 /* Macros for voltage DC/DC converters (BUCKs) */
76
-#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array) \
108
+#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array, \
109
+ creg, cmask) \
77110 .desc.id = chip##_ID_##regl_name, \
78111 .desc.name = __stringify(chip##_##regl_name), \
79112 .desc.ops = &da9063_buck_ops, \
80113 .desc.min_uV = (min_mV) * 1000, \
81114 .desc.uV_step = (step_mV) * 1000, \
82115 .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \
83
- .current_limits = limits_array, \
84
- .n_current_limits = ARRAY_SIZE(limits_array)
116
+ .desc.csel_reg = (creg), \
117
+ .desc.csel_mask = (cmask), \
118
+ .desc.curr_table = limits_array, \
119
+ .desc.n_current_limits = ARRAY_SIZE(limits_array)
85120
86121 #define DA9063_BUCK_COMMON_FIELDS(regl_name) \
87122 .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \
....@@ -90,6 +125,7 @@
90125 .desc.vsel_mask = DA9063_VBUCK_MASK, \
91126 .desc.linear_min_sel = DA9063_VBUCK_BIAS, \
92127 .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_BUCK_SL), \
128
+ .suspend = BFIELD(DA9063_REG_##regl_name##_CONT, DA9063_BUCK_CONF), \
93129 .suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_BUCK_SL), \
94130 .suspend_vsel_reg = DA9063_REG_V##regl_name##_B, \
95131 .mode = BFIELD(DA9063_REG_##regl_name##_CFG, DA9063_BUCK_MODE_MASK)
....@@ -97,7 +133,7 @@
97133 /* Defines asignment of regulators info table to chip model */
98134 struct da9063_dev_model {
99135 const struct da9063_regulator_info *regulator_info;
100
- unsigned n_regulators;
136
+ unsigned int n_regulators;
101137 enum da9063_type type;
102138 };
103139
....@@ -112,14 +148,13 @@
112148 struct regmap_field *suspend;
113149 struct regmap_field *sleep;
114150 struct regmap_field *suspend_sleep;
115
- struct regmap_field *ilimit;
116151 };
117152
118153 /* Encapsulates all information for the regulators driver */
119154 struct da9063_regulators {
120
- unsigned n_regulators;
155
+ unsigned int n_regulators;
121156 /* Array size to be defined during init. Keep at end. */
122
- struct da9063_regulator regulator[0];
157
+ struct da9063_regulator regulator[];
123158 };
124159
125160 /* BUCK modes for DA9063 */
....@@ -132,71 +167,46 @@
132167
133168 /* Regulator operations */
134169
135
-/* Current limits array (in uA) for BCORE1, BCORE2, BPRO.
136
- Entry indexes corresponds to register values. */
137
-static const int da9063_buck_a_limits[] = {
170
+/*
171
+ * Current limits array (in uA) for BCORE1, BCORE2, BPRO.
172
+ * Entry indexes corresponds to register values.
173
+ */
174
+static const unsigned int da9063_buck_a_limits[] = {
138175 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000,
139176 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000
140177 };
141178
142
-/* Current limits array (in uA) for BMEM, BIO, BPERI.
143
- Entry indexes corresponds to register values. */
144
-static const int da9063_buck_b_limits[] = {
179
+/*
180
+ * Current limits array (in uA) for BMEM, BIO, BPERI.
181
+ * Entry indexes corresponds to register values.
182
+ */
183
+static const unsigned int da9063_buck_b_limits[] = {
145184 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000,
146185 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000
147186 };
148187
149
-/* Current limits array (in uA) for merged BCORE1 and BCORE2.
150
- Entry indexes corresponds to register values. */
151
-static const int da9063_bcores_merged_limits[] = {
188
+/*
189
+ * Current limits array (in uA) for merged BCORE1 and BCORE2.
190
+ * Entry indexes corresponds to register values.
191
+ */
192
+static const unsigned int da9063_bcores_merged_limits[] = {
152193 1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000,
153194 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000
154195 };
155196
156
-/* Current limits array (in uA) for merged BMEM and BIO.
157
- Entry indexes corresponds to register values. */
158
-static const int da9063_bmem_bio_merged_limits[] = {
197
+/*
198
+ * Current limits array (in uA) for merged BMEM and BIO.
199
+ * Entry indexes corresponds to register values.
200
+ */
201
+static const unsigned int da9063_bmem_bio_merged_limits[] = {
159202 3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000,
160203 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000
161204 };
162205
163
-static int da9063_set_current_limit(struct regulator_dev *rdev,
164
- int min_uA, int max_uA)
206
+static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
165207 {
166208 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
167
- const struct da9063_regulator_info *rinfo = regl->info;
168
- int n, tval;
169
-
170
- for (n = 0; n < rinfo->n_current_limits; n++) {
171
- tval = rinfo->current_limits[n];
172
- if (tval >= min_uA && tval <= max_uA)
173
- return regmap_field_write(regl->ilimit, n);
174
- }
175
-
176
- return -EINVAL;
177
-}
178
-
179
-static int da9063_get_current_limit(struct regulator_dev *rdev)
180
-{
181
- struct da9063_regulator *regl = rdev_get_drvdata(rdev);
182
- const struct da9063_regulator_info *rinfo = regl->info;
183
- unsigned int sel;
184
- int ret;
185
-
186
- ret = regmap_field_read(regl->ilimit, &sel);
187
- if (ret < 0)
188
- return ret;
189
-
190
- if (sel >= rinfo->n_current_limits)
191
- sel = rinfo->n_current_limits - 1;
192
-
193
- return rinfo->current_limits[sel];
194
-}
195
-
196
-static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned mode)
197
-{
198
- struct da9063_regulator *regl = rdev_get_drvdata(rdev);
199
- unsigned val;
209
+ unsigned int val;
200210
201211 switch (mode) {
202212 case REGULATOR_MODE_FAST:
....@@ -221,11 +231,10 @@
221231 * There are 3 modes to map to: FAST, NORMAL, and STANDBY.
222232 */
223233
224
-static unsigned da9063_buck_get_mode(struct regulator_dev *rdev)
234
+static unsigned int da9063_buck_get_mode(struct regulator_dev *rdev)
225235 {
226236 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
227
- struct regmap_field *field;
228
- unsigned int val, mode = 0;
237
+ unsigned int val;
229238 int ret;
230239
231240 ret = regmap_field_read(regl->mode, &val);
....@@ -235,7 +244,6 @@
235244 switch (val) {
236245 default:
237246 case BUCK_MODE_MANUAL:
238
- mode = REGULATOR_MODE_FAST | REGULATOR_MODE_STANDBY;
239247 /* Sleep flag bit decides the mode */
240248 break;
241249 case BUCK_MODE_SLEEP:
....@@ -246,27 +254,14 @@
246254 return REGULATOR_MODE_NORMAL;
247255 }
248256
249
- /* Detect current regulator state */
250
- ret = regmap_field_read(regl->suspend, &val);
251
- if (ret < 0)
252
- return 0;
253
-
254
- /* Read regulator mode from proper register, depending on state */
255
- if (val)
256
- field = regl->suspend_sleep;
257
- else
258
- field = regl->sleep;
259
-
260
- ret = regmap_field_read(field, &val);
257
+ ret = regmap_field_read(regl->sleep, &val);
261258 if (ret < 0)
262259 return 0;
263260
264261 if (val)
265
- mode &= REGULATOR_MODE_STANDBY;
262
+ return REGULATOR_MODE_STANDBY;
266263 else
267
- mode &= REGULATOR_MODE_NORMAL | REGULATOR_MODE_FAST;
268
-
269
- return mode;
264
+ return REGULATOR_MODE_FAST;
270265 }
271266
272267 /*
....@@ -274,10 +269,10 @@
274269 * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state.
275270 */
276271
277
-static int da9063_ldo_set_mode(struct regulator_dev *rdev, unsigned mode)
272
+static int da9063_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
278273 {
279274 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
280
- unsigned val;
275
+ unsigned int val;
281276
282277 switch (mode) {
283278 case REGULATOR_MODE_NORMAL:
....@@ -293,24 +288,12 @@
293288 return regmap_field_write(regl->sleep, val);
294289 }
295290
296
-static unsigned da9063_ldo_get_mode(struct regulator_dev *rdev)
291
+static unsigned int da9063_ldo_get_mode(struct regulator_dev *rdev)
297292 {
298293 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
299
- struct regmap_field *field;
300294 int ret, val;
301295
302
- /* Detect current regulator state */
303
- ret = regmap_field_read(regl->suspend, &val);
304
- if (ret < 0)
305
- return 0;
306
-
307
- /* Read regulator mode from proper register, depending on state */
308
- if (val)
309
- field = regl->suspend_sleep;
310
- else
311
- field = regl->sleep;
312
-
313
- ret = regmap_field_read(field, &val);
296
+ ret = regmap_field_read(regl->sleep, &val);
314297 if (ret < 0)
315298 return 0;
316299
....@@ -386,7 +369,8 @@
386369 return regmap_field_write(regl->suspend, 0);
387370 }
388371
389
-static int da9063_buck_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
372
+static int da9063_buck_set_suspend_mode(struct regulator_dev *rdev,
373
+ unsigned int mode)
390374 {
391375 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
392376 int val;
....@@ -408,10 +392,11 @@
408392 return regmap_field_write(regl->mode, val);
409393 }
410394
411
-static int da9063_ldo_set_suspend_mode(struct regulator_dev *rdev, unsigned mode)
395
+static int da9063_ldo_set_suspend_mode(struct regulator_dev *rdev,
396
+ unsigned int mode)
412397 {
413398 struct da9063_regulator *regl = rdev_get_drvdata(rdev);
414
- unsigned val;
399
+ unsigned int val;
415400
416401 switch (mode) {
417402 case REGULATOR_MODE_NORMAL:
....@@ -434,8 +419,8 @@
434419 .get_voltage_sel = regulator_get_voltage_sel_regmap,
435420 .set_voltage_sel = regulator_set_voltage_sel_regmap,
436421 .list_voltage = regulator_list_voltage_linear,
437
- .set_current_limit = da9063_set_current_limit,
438
- .get_current_limit = da9063_get_current_limit,
422
+ .set_current_limit = regulator_set_current_limit_regmap,
423
+ .get_current_limit = regulator_get_current_limit_regmap,
439424 .set_mode = da9063_buck_set_mode,
440425 .get_mode = da9063_buck_get_mode,
441426 .get_status = da9063_buck_get_status,
....@@ -465,121 +450,94 @@
465450 static const struct da9063_regulator_info da9063_regulator_info[] = {
466451 {
467452 DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570,
468
- da9063_buck_a_limits),
453
+ da9063_buck_a_limits,
454
+ DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK),
469455 DA9063_BUCK_COMMON_FIELDS(BCORE1),
470
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
471
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
472
- DA9063_BCORE1_ILIM_MASK),
473456 },
474457 {
475458 DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570,
476
- da9063_buck_a_limits),
459
+ da9063_buck_a_limits,
460
+ DA9063_REG_BUCK_ILIM_C, DA9063_BCORE2_ILIM_MASK),
477461 DA9063_BUCK_COMMON_FIELDS(BCORE2),
478
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE2_SEL),
479
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
480
- DA9063_BCORE2_ILIM_MASK),
481462 },
482463 {
483464 DA9063_BUCK(DA9063, BPRO, 530, 10, 1800,
484
- da9063_buck_a_limits),
465
+ da9063_buck_a_limits,
466
+ DA9063_REG_BUCK_ILIM_B, DA9063_BPRO_ILIM_MASK),
485467 DA9063_BUCK_COMMON_FIELDS(BPRO),
486
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPRO_SEL),
487
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
488
- DA9063_BPRO_ILIM_MASK),
489468 },
490469 {
491470 DA9063_BUCK(DA9063, BMEM, 800, 20, 3340,
492
- da9063_buck_b_limits),
471
+ da9063_buck_b_limits,
472
+ DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK),
493473 DA9063_BUCK_COMMON_FIELDS(BMEM),
494
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
495
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
496
- DA9063_BMEM_ILIM_MASK),
497474 },
498475 {
499476 DA9063_BUCK(DA9063, BIO, 800, 20, 3340,
500
- da9063_buck_b_limits),
477
+ da9063_buck_b_limits,
478
+ DA9063_REG_BUCK_ILIM_A, DA9063_BIO_ILIM_MASK),
501479 DA9063_BUCK_COMMON_FIELDS(BIO),
502
- .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VBIO_SEL),
503
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
504
- DA9063_BIO_ILIM_MASK),
505480 },
506481 {
507482 DA9063_BUCK(DA9063, BPERI, 800, 20, 3340,
508
- da9063_buck_b_limits),
483
+ da9063_buck_b_limits,
484
+ DA9063_REG_BUCK_ILIM_B, DA9063_BPERI_ILIM_MASK),
509485 DA9063_BUCK_COMMON_FIELDS(BPERI),
510
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBPERI_SEL),
511
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_B,
512
- DA9063_BPERI_ILIM_MASK),
513486 },
514487 {
515488 DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570,
516
- da9063_bcores_merged_limits),
489
+ da9063_bcores_merged_limits,
490
+ DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK),
517491 /* BCORES_MERGED uses the same register fields as BCORE1 */
518492 DA9063_BUCK_COMMON_FIELDS(BCORE1),
519
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBCORE1_SEL),
520
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_C,
521
- DA9063_BCORE1_ILIM_MASK),
522493 },
523494 {
524495 DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340,
525
- da9063_bmem_bio_merged_limits),
496
+ da9063_bmem_bio_merged_limits,
497
+ DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK),
526498 /* BMEM_BIO_MERGED uses the same register fields as BMEM */
527499 DA9063_BUCK_COMMON_FIELDS(BMEM),
528
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VBMEM_SEL),
529
- .ilimit = BFIELD(DA9063_REG_BUCK_ILIM_A,
530
- DA9063_BMEM_ILIM_MASK),
531500 },
532501 {
533502 DA9063_LDO(DA9063, LDO3, 900, 20, 3440),
534
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO3_SEL),
535503 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO3_LIM),
536504 },
537505 {
538506 DA9063_LDO(DA9063, LDO7, 900, 50, 3600),
539
- .suspend = BFIELD(DA9063_REG_LDO7_CONT, DA9063_VLDO7_SEL),
540507 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO7_LIM),
541508 },
542509 {
543510 DA9063_LDO(DA9063, LDO8, 900, 50, 3600),
544
- .suspend = BFIELD(DA9063_REG_LDO8_CONT, DA9063_VLDO8_SEL),
545511 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO8_LIM),
546512 },
547513 {
548514 DA9063_LDO(DA9063, LDO9, 950, 50, 3600),
549
- .suspend = BFIELD(DA9063_REG_LDO9_CONT, DA9063_VLDO9_SEL),
550515 },
551516 {
552517 DA9063_LDO(DA9063, LDO11, 900, 50, 3600),
553
- .suspend = BFIELD(DA9063_REG_LDO11_CONT, DA9063_VLDO11_SEL),
554518 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO11_LIM),
555519 },
556520
557521 /* The following LDOs are present only on DA9063, not on DA9063L */
558522 {
559523 DA9063_LDO(DA9063, LDO1, 600, 20, 1860),
560
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO1_SEL),
561524 },
562525 {
563526 DA9063_LDO(DA9063, LDO2, 600, 20, 1860),
564
- .suspend = BFIELD(DA9063_REG_DVC_1, DA9063_VLDO2_SEL),
565527 },
566528 {
567529 DA9063_LDO(DA9063, LDO4, 900, 20, 3440),
568
- .suspend = BFIELD(DA9063_REG_DVC_2, DA9063_VLDO4_SEL),
569530 .oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO4_LIM),
570531 },
571532 {
572533 DA9063_LDO(DA9063, LDO5, 900, 50, 3600),
573
- .suspend = BFIELD(DA9063_REG_LDO5_CONT, DA9063_VLDO5_SEL),
574534 },
575535 {
576536 DA9063_LDO(DA9063, LDO6, 900, 50, 3600),
577
- .suspend = BFIELD(DA9063_REG_LDO6_CONT, DA9063_VLDO6_SEL),
578537 },
579538
580539 {
581540 DA9063_LDO(DA9063, LDO10, 900, 50, 3600),
582
- .suspend = BFIELD(DA9063_REG_LDO10_CONT, DA9063_VLDO10_SEL),
583541 },
584542 };
585543
....@@ -604,7 +562,7 @@
604562 struct da9063_regulators *regulators = data;
605563 struct da9063 *hw = regulators->regulator[0].hw;
606564 struct da9063_regulator *regl;
607
- int bits, i , ret;
565
+ int bits, i, ret;
608566
609567 ret = regmap_read(hw->regmap, DA9063_REG_STATUS_D, &bits);
610568 if (ret < 0)
....@@ -615,9 +573,10 @@
615573 if (regl->info->oc_event.reg != DA9063_REG_STATUS_D)
616574 continue;
617575
618
- if (BIT(regl->info->oc_event.lsb) & bits)
576
+ if (BIT(regl->info->oc_event.lsb) & bits) {
619577 regulator_notifier_call_chain(regl->rdev,
620578 REGULATOR_EVENT_OVER_CURRENT, NULL);
579
+ }
621580 }
622581
623582 return IRQ_HANDLED;
....@@ -639,7 +598,6 @@
639598 return NULL;
640599 }
641600
642
-#ifdef CONFIG_OF
643601 static struct of_regulator_match da9063_matches[] = {
644602 [DA9063_ID_BCORE1] = { .name = "bcore1" },
645603 [DA9063_ID_BCORE2] = { .name = "bcore2" },
....@@ -717,20 +675,10 @@
717675 *da9063_reg_matches = da9063_matches;
718676 return pdata;
719677 }
720
-#else
721
-static struct da9063_regulators_pdata *da9063_parse_regulators_dt(
722
- struct platform_device *pdev,
723
- struct of_regulator_match **da9063_reg_matches)
724
-{
725
- *da9063_reg_matches = NULL;
726
- return ERR_PTR(-ENODEV);
727
-}
728
-#endif
729678
730679 static int da9063_regulator_probe(struct platform_device *pdev)
731680 {
732681 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent);
733
- struct da9063_pdata *da9063_pdata = dev_get_platdata(da9063->dev);
734682 struct of_regulator_match *da9063_reg_matches = NULL;
735683 struct da9063_regulators_pdata *regl_pdata;
736684 const struct da9063_dev_model *model;
....@@ -739,13 +687,8 @@
739687 struct regulator_config config;
740688 bool bcores_merged, bmem_bio_merged;
741689 int id, irq, n, n_regulators, ret, val;
742
- size_t size;
743690
744
- regl_pdata = da9063_pdata ? da9063_pdata->regulators_pdata : NULL;
745
-
746
- if (!regl_pdata)
747
- regl_pdata = da9063_parse_regulators_dt(pdev,
748
- &da9063_reg_matches);
691
+ regl_pdata = da9063_parse_regulators_dt(pdev, &da9063_reg_matches);
749692
750693 if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) {
751694 dev_err(&pdev->dev,
....@@ -784,9 +727,8 @@
784727 n_regulators--; /* remove BMEM_BIO_MERGED */
785728
786729 /* Allocate memory required by usable regulators */
787
- size = sizeof(struct da9063_regulators) +
788
- n_regulators * sizeof(struct da9063_regulator);
789
- regulators = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
730
+ regulators = devm_kzalloc(&pdev->dev, struct_size(regulators,
731
+ regulator, n_regulators), GFP_KERNEL);
790732 if (!regulators)
791733 return -ENOMEM;
792734
....@@ -835,21 +777,33 @@
835777 regl->desc.type = REGULATOR_VOLTAGE;
836778 regl->desc.owner = THIS_MODULE;
837779
838
- if (regl->info->mode.reg)
780
+ if (regl->info->mode.reg) {
839781 regl->mode = devm_regmap_field_alloc(&pdev->dev,
840782 da9063->regmap, regl->info->mode);
841
- if (regl->info->suspend.reg)
783
+ if (IS_ERR(regl->mode))
784
+ return PTR_ERR(regl->mode);
785
+ }
786
+
787
+ if (regl->info->suspend.reg) {
842788 regl->suspend = devm_regmap_field_alloc(&pdev->dev,
843789 da9063->regmap, regl->info->suspend);
844
- if (regl->info->sleep.reg)
790
+ if (IS_ERR(regl->suspend))
791
+ return PTR_ERR(regl->suspend);
792
+ }
793
+
794
+ if (regl->info->sleep.reg) {
845795 regl->sleep = devm_regmap_field_alloc(&pdev->dev,
846796 da9063->regmap, regl->info->sleep);
847
- if (regl->info->suspend_sleep.reg)
797
+ if (IS_ERR(regl->sleep))
798
+ return PTR_ERR(regl->sleep);
799
+ }
800
+
801
+ if (regl->info->suspend_sleep.reg) {
848802 regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev,
849
- da9063->regmap, regl->info->suspend_sleep);
850
- if (regl->info->ilimit.reg)
851
- regl->ilimit = devm_regmap_field_alloc(&pdev->dev,
852
- da9063->regmap, regl->info->ilimit);
803
+ da9063->regmap, regl->info->suspend_sleep);
804
+ if (IS_ERR(regl->suspend_sleep))
805
+ return PTR_ERR(regl->suspend_sleep);
806
+ }
853807
854808 /* Register regulator */
855809 memset(&config, 0, sizeof(config));
....@@ -873,21 +827,17 @@
873827
874828 /* LDOs overcurrent event support */
875829 irq = platform_get_irq_byname(pdev, "LDO_LIM");
876
- if (irq < 0) {
877
- dev_err(&pdev->dev, "Failed to get IRQ.\n");
830
+ if (irq < 0)
878831 return irq;
879
- }
880832
881833 ret = devm_request_threaded_irq(&pdev->dev, irq,
882834 NULL, da9063_ldo_lim_event,
883835 IRQF_TRIGGER_LOW | IRQF_ONESHOT,
884836 "LDO_LIM", regulators);
885
- if (ret) {
837
+ if (ret)
886838 dev_err(&pdev->dev, "Failed to request LDO_LIM IRQ.\n");
887
- return ret;
888
- }
889839
890
- return 0;
840
+ return ret;
891841 }
892842
893843 static struct platform_driver da9063_regulator_driver = {