GNU Linux-libre 5.10.219-gnu1
[releases.git] / drivers / regulator / bd71828-regulator.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (C) 2019 ROHM Semiconductors
3 // bd71828-regulator.c ROHM BD71828GW-DS1 regulator driver
4 //
5
6 #include <linux/delay.h>
7 #include <linux/err.h>
8 #include <linux/gpio.h>
9 #include <linux/interrupt.h>
10 #include <linux/kernel.h>
11 #include <linux/mfd/rohm-bd71828.h>
12 #include <linux/module.h>
13 #include <linux/of.h>
14 #include <linux/platform_device.h>
15 #include <linux/regmap.h>
16 #include <linux/regulator/driver.h>
17 #include <linux/regulator/machine.h>
18 #include <linux/regulator/of_regulator.h>
19
20 struct reg_init {
21         unsigned int reg;
22         unsigned int mask;
23         unsigned int val;
24 };
25 struct bd71828_regulator_data {
26         struct regulator_desc desc;
27         const struct rohm_dvs_config dvs;
28         const struct reg_init *reg_inits;
29         int reg_init_amnt;
30 };
31
32 static const struct reg_init buck1_inits[] = {
33         /*
34          * DVS Buck voltages can be changed by register values or via GPIO.
35          * Use register accesses by default.
36          */
37         {
38                 .reg = BD71828_REG_PS_CTRL_1,
39                 .mask = BD71828_MASK_DVS_BUCK1_CTRL,
40                 .val = BD71828_DVS_BUCK1_CTRL_I2C,
41         },
42 };
43
44 static const struct reg_init buck2_inits[] = {
45         {
46                 .reg = BD71828_REG_PS_CTRL_1,
47                 .mask = BD71828_MASK_DVS_BUCK2_CTRL,
48                 .val = BD71828_DVS_BUCK2_CTRL_I2C,
49         },
50 };
51
52 static const struct reg_init buck6_inits[] = {
53         {
54                 .reg = BD71828_REG_PS_CTRL_1,
55                 .mask = BD71828_MASK_DVS_BUCK6_CTRL,
56                 .val = BD71828_DVS_BUCK6_CTRL_I2C,
57         },
58 };
59
60 static const struct reg_init buck7_inits[] = {
61         {
62                 .reg = BD71828_REG_PS_CTRL_1,
63                 .mask = BD71828_MASK_DVS_BUCK7_CTRL,
64                 .val = BD71828_DVS_BUCK7_CTRL_I2C,
65         },
66 };
67
68 static const struct linear_range bd71828_buck1267_volts[] = {
69         REGULATOR_LINEAR_RANGE(500000, 0x00, 0xef, 6250),
70         REGULATOR_LINEAR_RANGE(2000000, 0xf0, 0xff, 0),
71 };
72
73 static const struct linear_range bd71828_buck3_volts[] = {
74         REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x0f, 50000),
75         REGULATOR_LINEAR_RANGE(2000000, 0x10, 0x1f, 0),
76 };
77
78 static const struct linear_range bd71828_buck4_volts[] = {
79         REGULATOR_LINEAR_RANGE(1000000, 0x00, 0x1f, 25000),
80         REGULATOR_LINEAR_RANGE(1800000, 0x20, 0x3f, 0),
81 };
82
83 static const struct linear_range bd71828_buck5_volts[] = {
84         REGULATOR_LINEAR_RANGE(2500000, 0x00, 0x0f, 50000),
85         REGULATOR_LINEAR_RANGE(3300000, 0x10, 0x1f, 0),
86 };
87
88 static const struct linear_range bd71828_ldo_volts[] = {
89         REGULATOR_LINEAR_RANGE(800000, 0x00, 0x31, 50000),
90         REGULATOR_LINEAR_RANGE(3300000, 0x32, 0x3f, 0),
91 };
92
93 static int bd71828_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
94 {
95         unsigned int val;
96
97         switch (ramp_delay) {
98         case 1 ... 2500:
99                 val = 0;
100                 break;
101         case 2501 ... 5000:
102                 val = 1;
103                 break;
104         case 5001 ... 10000:
105                 val = 2;
106                 break;
107         case 10001 ... 20000:
108                 val = 3;
109                 break;
110         default:
111                 val = 3;
112                 dev_err(&rdev->dev,
113                         "ramp_delay: %d not supported, setting 20mV/uS",
114                          ramp_delay);
115         }
116
117         /*
118          * On BD71828 the ramp delay level control reg is at offset +2 to
119          * enable reg
120          */
121         return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg + 2,
122                                   BD71828_MASK_RAMP_DELAY,
123                                   val << (ffs(BD71828_MASK_RAMP_DELAY) - 1));
124 }
125
126 static int buck_set_hw_dvs_levels(struct device_node *np,
127                                   const struct regulator_desc *desc,
128                                   struct regulator_config *cfg)
129 {
130         struct bd71828_regulator_data *data;
131
132         data = container_of(desc, struct bd71828_regulator_data, desc);
133
134         return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap);
135 }
136
137 static int ldo6_parse_dt(struct device_node *np,
138                          const struct regulator_desc *desc,
139                          struct regulator_config *cfg)
140 {
141         int ret, i;
142         uint32_t uv = 0;
143         unsigned int en;
144         struct regmap *regmap = cfg->regmap;
145         static const char * const props[] = { "rohm,dvs-run-voltage",
146                                               "rohm,dvs-idle-voltage",
147                                               "rohm,dvs-suspend-voltage",
148                                               "rohm,dvs-lpsr-voltage" };
149         unsigned int mask[] = { BD71828_MASK_RUN_EN, BD71828_MASK_IDLE_EN,
150                                BD71828_MASK_SUSP_EN, BD71828_MASK_LPSR_EN };
151
152         for (i = 0; i < ARRAY_SIZE(props); i++) {
153                 ret = of_property_read_u32(np, props[i], &uv);
154                 if (ret) {
155                         if (ret != -EINVAL)
156                                 return ret;
157                         continue;
158                 }
159                 if (uv)
160                         en = 0xffffffff;
161                 else
162                         en = 0;
163
164                 ret = regmap_update_bits(regmap, desc->enable_reg, mask[i], en);
165                 if (ret)
166                         return ret;
167         }
168         return 0;
169 }
170
171 static const struct regulator_ops bd71828_buck_ops = {
172         .enable = regulator_enable_regmap,
173         .disable = regulator_disable_regmap,
174         .is_enabled = regulator_is_enabled_regmap,
175         .list_voltage = regulator_list_voltage_linear_range,
176         .set_voltage_sel = regulator_set_voltage_sel_regmap,
177         .get_voltage_sel = regulator_get_voltage_sel_regmap,
178 };
179
180 static const struct regulator_ops bd71828_dvs_buck_ops = {
181         .enable = regulator_enable_regmap,
182         .disable = regulator_disable_regmap,
183         .is_enabled = regulator_is_enabled_regmap,
184         .list_voltage = regulator_list_voltage_linear_range,
185         .set_voltage_sel = regulator_set_voltage_sel_regmap,
186         .get_voltage_sel = regulator_get_voltage_sel_regmap,
187         .set_voltage_time_sel = regulator_set_voltage_time_sel,
188         .set_ramp_delay = bd71828_set_ramp_delay,
189 };
190
191 static const struct regulator_ops bd71828_ldo_ops = {
192         .enable = regulator_enable_regmap,
193         .disable = regulator_disable_regmap,
194         .is_enabled = regulator_is_enabled_regmap,
195         .list_voltage = regulator_list_voltage_linear_range,
196         .set_voltage_sel = regulator_set_voltage_sel_regmap,
197         .get_voltage_sel = regulator_get_voltage_sel_regmap,
198 };
199
200 static const struct regulator_ops bd71828_ldo6_ops = {
201         .enable = regulator_enable_regmap,
202         .disable = regulator_disable_regmap,
203         .is_enabled = regulator_is_enabled_regmap,
204 };
205
206 static const struct bd71828_regulator_data bd71828_rdata[] = {
207         {
208                 .desc = {
209                         .name = "buck1",
210                         .of_match = of_match_ptr("BUCK1"),
211                         .regulators_node = of_match_ptr("regulators"),
212                         .id = BD71828_BUCK1,
213                         .ops = &bd71828_dvs_buck_ops,
214                         .type = REGULATOR_VOLTAGE,
215                         .linear_ranges = bd71828_buck1267_volts,
216                         .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
217                         .n_voltages = BD71828_BUCK1267_VOLTS,
218                         .enable_reg = BD71828_REG_BUCK1_EN,
219                         .enable_mask = BD71828_MASK_RUN_EN,
220                         .vsel_reg = BD71828_REG_BUCK1_VOLT,
221                         .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
222                         .owner = THIS_MODULE,
223                         .of_parse_cb = buck_set_hw_dvs_levels,
224                 },
225                 .dvs = {
226                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
227                                      ROHM_DVS_LEVEL_SUSPEND |
228                                      ROHM_DVS_LEVEL_LPSR,
229                         .run_reg = BD71828_REG_BUCK1_VOLT,
230                         .run_mask = BD71828_MASK_BUCK1267_VOLT,
231                         .idle_reg = BD71828_REG_BUCK1_IDLE_VOLT,
232                         .idle_mask = BD71828_MASK_BUCK1267_VOLT,
233                         .idle_on_mask = BD71828_MASK_IDLE_EN,
234                         .suspend_reg = BD71828_REG_BUCK1_SUSP_VOLT,
235                         .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
236                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
237                         /*
238                          * LPSR voltage is same as SUSPEND voltage. Allow
239                          * only enabling/disabling regulator for LPSR state
240                          */
241                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
242                 },
243                 .reg_inits = buck1_inits,
244                 .reg_init_amnt = ARRAY_SIZE(buck1_inits),
245         },
246         {
247                 .desc = {
248                         .name = "buck2",
249                         .of_match = of_match_ptr("BUCK2"),
250                         .regulators_node = of_match_ptr("regulators"),
251                         .id = BD71828_BUCK2,
252                         .ops = &bd71828_dvs_buck_ops,
253                         .type = REGULATOR_VOLTAGE,
254                         .linear_ranges = bd71828_buck1267_volts,
255                         .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
256                         .n_voltages = BD71828_BUCK1267_VOLTS,
257                         .enable_reg = BD71828_REG_BUCK2_EN,
258                         .enable_mask = BD71828_MASK_RUN_EN,
259                         .vsel_reg = BD71828_REG_BUCK2_VOLT,
260                         .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
261                         .owner = THIS_MODULE,
262                         .of_parse_cb = buck_set_hw_dvs_levels,
263                 },
264                 .dvs = {
265                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
266                                      ROHM_DVS_LEVEL_SUSPEND |
267                                      ROHM_DVS_LEVEL_LPSR,
268                         .run_reg = BD71828_REG_BUCK2_VOLT,
269                         .run_mask = BD71828_MASK_BUCK1267_VOLT,
270                         .idle_reg = BD71828_REG_BUCK2_IDLE_VOLT,
271                         .idle_mask = BD71828_MASK_BUCK1267_VOLT,
272                         .idle_on_mask = BD71828_MASK_IDLE_EN,
273                         .suspend_reg = BD71828_REG_BUCK2_SUSP_VOLT,
274                         .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
275                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
276                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
277                         .lpsr_reg = BD71828_REG_BUCK2_SUSP_VOLT,
278                         .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
279                 },
280                 .reg_inits = buck2_inits,
281                 .reg_init_amnt = ARRAY_SIZE(buck2_inits),
282         },
283         {
284                 .desc = {
285                         .name = "buck3",
286                         .of_match = of_match_ptr("BUCK3"),
287                         .regulators_node = of_match_ptr("regulators"),
288                         .id = BD71828_BUCK3,
289                         .ops = &bd71828_buck_ops,
290                         .type = REGULATOR_VOLTAGE,
291                         .linear_ranges = bd71828_buck3_volts,
292                         .n_linear_ranges = ARRAY_SIZE(bd71828_buck3_volts),
293                         .n_voltages = BD71828_BUCK3_VOLTS,
294                         .enable_reg = BD71828_REG_BUCK3_EN,
295                         .enable_mask = BD71828_MASK_RUN_EN,
296                         .vsel_reg = BD71828_REG_BUCK3_VOLT,
297                         .vsel_mask = BD71828_MASK_BUCK3_VOLT,
298                         .owner = THIS_MODULE,
299                         .of_parse_cb = buck_set_hw_dvs_levels,
300                 },
301                 .dvs = {
302                         /*
303                          * BUCK3 only supports single voltage for all states.
304                          * voltage can be individually enabled for each state
305                          * though => allow setting all states to support
306                          * enabling power rail on different states.
307                          */
308                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
309                                      ROHM_DVS_LEVEL_SUSPEND |
310                                      ROHM_DVS_LEVEL_LPSR,
311                         .run_reg = BD71828_REG_BUCK3_VOLT,
312                         .run_mask = BD71828_MASK_BUCK3_VOLT,
313                         .idle_on_mask = BD71828_MASK_IDLE_EN,
314                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
315                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
316                 },
317         },
318         {
319                 .desc = {
320                         .name = "buck4",
321                         .of_match = of_match_ptr("BUCK4"),
322                         .regulators_node = of_match_ptr("regulators"),
323                         .id = BD71828_BUCK4,
324                         .ops = &bd71828_buck_ops,
325                         .type = REGULATOR_VOLTAGE,
326                         .linear_ranges = bd71828_buck4_volts,
327                         .n_linear_ranges = ARRAY_SIZE(bd71828_buck4_volts),
328                         .n_voltages = BD71828_BUCK4_VOLTS,
329                         .enable_reg = BD71828_REG_BUCK4_EN,
330                         .enable_mask = BD71828_MASK_RUN_EN,
331                         .vsel_reg = BD71828_REG_BUCK4_VOLT,
332                         .vsel_mask = BD71828_MASK_BUCK4_VOLT,
333                         .owner = THIS_MODULE,
334                         .of_parse_cb = buck_set_hw_dvs_levels,
335                 },
336                 .dvs = {
337                         /*
338                          * BUCK4 only supports single voltage for all states.
339                          * voltage can be individually enabled for each state
340                          * though => allow setting all states to support
341                          * enabling power rail on different states.
342                          */
343                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
344                                      ROHM_DVS_LEVEL_SUSPEND |
345                                      ROHM_DVS_LEVEL_LPSR,
346                         .run_reg = BD71828_REG_BUCK4_VOLT,
347                         .run_mask = BD71828_MASK_BUCK4_VOLT,
348                         .idle_on_mask = BD71828_MASK_IDLE_EN,
349                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
350                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
351                 },
352         },
353         {
354                 .desc = {
355                         .name = "buck5",
356                         .of_match = of_match_ptr("BUCK5"),
357                         .regulators_node = of_match_ptr("regulators"),
358                         .id = BD71828_BUCK5,
359                         .ops = &bd71828_buck_ops,
360                         .type = REGULATOR_VOLTAGE,
361                         .linear_ranges = bd71828_buck5_volts,
362                         .n_linear_ranges = ARRAY_SIZE(bd71828_buck5_volts),
363                         .n_voltages = BD71828_BUCK5_VOLTS,
364                         .enable_reg = BD71828_REG_BUCK5_EN,
365                         .enable_mask = BD71828_MASK_RUN_EN,
366                         .vsel_reg = BD71828_REG_BUCK5_VOLT,
367                         .vsel_mask = BD71828_MASK_BUCK5_VOLT,
368                         .owner = THIS_MODULE,
369                         .of_parse_cb = buck_set_hw_dvs_levels,
370                 },
371                 .dvs = {
372                         /*
373                          * BUCK5 only supports single voltage for all states.
374                          * voltage can be individually enabled for each state
375                          * though => allow setting all states to support
376                          * enabling power rail on different states.
377                          */
378                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
379                                      ROHM_DVS_LEVEL_SUSPEND |
380                                      ROHM_DVS_LEVEL_LPSR,
381                         .run_reg = BD71828_REG_BUCK5_VOLT,
382                         .run_mask = BD71828_MASK_BUCK5_VOLT,
383                         .idle_on_mask = BD71828_MASK_IDLE_EN,
384                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
385                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
386                 },
387         },
388         {
389                 .desc = {
390                         .name = "buck6",
391                         .of_match = of_match_ptr("BUCK6"),
392                         .regulators_node = of_match_ptr("regulators"),
393                         .id = BD71828_BUCK6,
394                         .ops = &bd71828_dvs_buck_ops,
395                         .type = REGULATOR_VOLTAGE,
396                         .linear_ranges = bd71828_buck1267_volts,
397                         .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
398                         .n_voltages = BD71828_BUCK1267_VOLTS,
399                         .enable_reg = BD71828_REG_BUCK6_EN,
400                         .enable_mask = BD71828_MASK_RUN_EN,
401                         .vsel_reg = BD71828_REG_BUCK6_VOLT,
402                         .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
403                         .owner = THIS_MODULE,
404                         .of_parse_cb = buck_set_hw_dvs_levels,
405                 },
406                 .dvs = {
407                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
408                                      ROHM_DVS_LEVEL_SUSPEND |
409                                      ROHM_DVS_LEVEL_LPSR,
410                         .run_reg = BD71828_REG_BUCK6_VOLT,
411                         .run_mask = BD71828_MASK_BUCK1267_VOLT,
412                         .idle_reg = BD71828_REG_BUCK6_IDLE_VOLT,
413                         .idle_mask = BD71828_MASK_BUCK1267_VOLT,
414                         .idle_on_mask = BD71828_MASK_IDLE_EN,
415                         .suspend_reg = BD71828_REG_BUCK6_SUSP_VOLT,
416                         .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
417                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
418                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
419                         .lpsr_reg = BD71828_REG_BUCK6_SUSP_VOLT,
420                         .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
421                 },
422                 .reg_inits = buck6_inits,
423                 .reg_init_amnt = ARRAY_SIZE(buck6_inits),
424         },
425         {
426                 .desc = {
427                         .name = "buck7",
428                         .of_match = of_match_ptr("BUCK7"),
429                         .regulators_node = of_match_ptr("regulators"),
430                         .id = BD71828_BUCK7,
431                         .ops = &bd71828_dvs_buck_ops,
432                         .type = REGULATOR_VOLTAGE,
433                         .linear_ranges = bd71828_buck1267_volts,
434                         .n_linear_ranges = ARRAY_SIZE(bd71828_buck1267_volts),
435                         .n_voltages = BD71828_BUCK1267_VOLTS,
436                         .enable_reg = BD71828_REG_BUCK7_EN,
437                         .enable_mask = BD71828_MASK_RUN_EN,
438                         .vsel_reg = BD71828_REG_BUCK7_VOLT,
439                         .vsel_mask = BD71828_MASK_BUCK1267_VOLT,
440                         .owner = THIS_MODULE,
441                         .of_parse_cb = buck_set_hw_dvs_levels,
442                 },
443                 .dvs = {
444                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
445                                      ROHM_DVS_LEVEL_SUSPEND |
446                                      ROHM_DVS_LEVEL_LPSR,
447                         .run_reg = BD71828_REG_BUCK7_VOLT,
448                         .run_mask = BD71828_MASK_BUCK1267_VOLT,
449                         .idle_reg = BD71828_REG_BUCK7_IDLE_VOLT,
450                         .idle_mask = BD71828_MASK_BUCK1267_VOLT,
451                         .idle_on_mask = BD71828_MASK_IDLE_EN,
452                         .suspend_reg = BD71828_REG_BUCK7_SUSP_VOLT,
453                         .suspend_mask = BD71828_MASK_BUCK1267_VOLT,
454                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
455                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
456                         .lpsr_reg = BD71828_REG_BUCK7_SUSP_VOLT,
457                         .lpsr_mask = BD71828_MASK_BUCK1267_VOLT,
458                 },
459                 .reg_inits = buck7_inits,
460                 .reg_init_amnt = ARRAY_SIZE(buck7_inits),
461         },
462         {
463                 .desc = {
464                         .name = "ldo1",
465                         .of_match = of_match_ptr("LDO1"),
466                         .regulators_node = of_match_ptr("regulators"),
467                         .id = BD71828_LDO1,
468                         .ops = &bd71828_ldo_ops,
469                         .type = REGULATOR_VOLTAGE,
470                         .linear_ranges = bd71828_ldo_volts,
471                         .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
472                         .n_voltages = BD71828_LDO_VOLTS,
473                         .enable_reg = BD71828_REG_LDO1_EN,
474                         .enable_mask = BD71828_MASK_RUN_EN,
475                         .vsel_reg = BD71828_REG_LDO1_VOLT,
476                         .vsel_mask = BD71828_MASK_LDO_VOLT,
477                         .owner = THIS_MODULE,
478                         .of_parse_cb = buck_set_hw_dvs_levels,
479                 },
480                 .dvs = {
481                         /*
482                          * LDO1 only supports single voltage for all states.
483                          * voltage can be individually enabled for each state
484                          * though => allow setting all states to support
485                          * enabling power rail on different states.
486                          */
487                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
488                                      ROHM_DVS_LEVEL_SUSPEND |
489                                      ROHM_DVS_LEVEL_LPSR,
490                         .run_reg = BD71828_REG_LDO1_VOLT,
491                         .run_mask = BD71828_MASK_LDO_VOLT,
492                         .idle_on_mask = BD71828_MASK_IDLE_EN,
493                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
494                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
495                 },
496         }, {
497                 .desc = {
498                         .name = "ldo2",
499                         .of_match = of_match_ptr("LDO2"),
500                         .regulators_node = of_match_ptr("regulators"),
501                         .id = BD71828_LDO2,
502                         .ops = &bd71828_ldo_ops,
503                         .type = REGULATOR_VOLTAGE,
504                         .linear_ranges = bd71828_ldo_volts,
505                         .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
506                         .n_voltages = BD71828_LDO_VOLTS,
507                         .enable_reg = BD71828_REG_LDO2_EN,
508                         .enable_mask = BD71828_MASK_RUN_EN,
509                         .vsel_reg = BD71828_REG_LDO2_VOLT,
510                         .vsel_mask = BD71828_MASK_LDO_VOLT,
511                         .owner = THIS_MODULE,
512                         .of_parse_cb = buck_set_hw_dvs_levels,
513                 },
514                 .dvs = {
515                         /*
516                          * LDO2 only supports single voltage for all states.
517                          * voltage can be individually enabled for each state
518                          * though => allow setting all states to support
519                          * enabling power rail on different states.
520                          */
521                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
522                                      ROHM_DVS_LEVEL_SUSPEND |
523                                      ROHM_DVS_LEVEL_LPSR,
524                         .run_reg = BD71828_REG_LDO2_VOLT,
525                         .run_mask = BD71828_MASK_LDO_VOLT,
526                         .idle_on_mask = BD71828_MASK_IDLE_EN,
527                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
528                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
529                 },
530         }, {
531                 .desc = {
532                         .name = "ldo3",
533                         .of_match = of_match_ptr("LDO3"),
534                         .regulators_node = of_match_ptr("regulators"),
535                         .id = BD71828_LDO3,
536                         .ops = &bd71828_ldo_ops,
537                         .type = REGULATOR_VOLTAGE,
538                         .linear_ranges = bd71828_ldo_volts,
539                         .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
540                         .n_voltages = BD71828_LDO_VOLTS,
541                         .enable_reg = BD71828_REG_LDO3_EN,
542                         .enable_mask = BD71828_MASK_RUN_EN,
543                         .vsel_reg = BD71828_REG_LDO3_VOLT,
544                         .vsel_mask = BD71828_MASK_LDO_VOLT,
545                         .owner = THIS_MODULE,
546                         .of_parse_cb = buck_set_hw_dvs_levels,
547                 },
548                 .dvs = {
549                         /*
550                          * LDO3 only supports single voltage for all states.
551                          * voltage can be individually enabled for each state
552                          * though => allow setting all states to support
553                          * enabling power rail on different states.
554                          */
555                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
556                                      ROHM_DVS_LEVEL_SUSPEND |
557                                      ROHM_DVS_LEVEL_LPSR,
558                         .run_reg = BD71828_REG_LDO3_VOLT,
559                         .run_mask = BD71828_MASK_LDO_VOLT,
560                         .idle_on_mask = BD71828_MASK_IDLE_EN,
561                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
562                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
563                 },
564
565         }, {
566                 .desc = {
567                         .name = "ldo4",
568                         .of_match = of_match_ptr("LDO4"),
569                         .regulators_node = of_match_ptr("regulators"),
570                         .id = BD71828_LDO4,
571                         .ops = &bd71828_ldo_ops,
572                         .type = REGULATOR_VOLTAGE,
573                         .linear_ranges = bd71828_ldo_volts,
574                         .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
575                         .n_voltages = BD71828_LDO_VOLTS,
576                         .enable_reg = BD71828_REG_LDO4_EN,
577                         .enable_mask = BD71828_MASK_RUN_EN,
578                         .vsel_reg = BD71828_REG_LDO4_VOLT,
579                         .vsel_mask = BD71828_MASK_LDO_VOLT,
580                         .owner = THIS_MODULE,
581                         .of_parse_cb = buck_set_hw_dvs_levels,
582                 },
583                 .dvs = {
584                         /*
585                          * LDO1 only supports single voltage for all states.
586                          * voltage can be individually enabled for each state
587                          * though => allow setting all states to support
588                          * enabling power rail on different states.
589                          */
590                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
591                                      ROHM_DVS_LEVEL_SUSPEND |
592                                      ROHM_DVS_LEVEL_LPSR,
593                         .run_reg = BD71828_REG_LDO4_VOLT,
594                         .run_mask = BD71828_MASK_LDO_VOLT,
595                         .idle_on_mask = BD71828_MASK_IDLE_EN,
596                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
597                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
598                 },
599         }, {
600                 .desc = {
601                         .name = "ldo5",
602                         .of_match = of_match_ptr("LDO5"),
603                         .regulators_node = of_match_ptr("regulators"),
604                         .id = BD71828_LDO5,
605                         .ops = &bd71828_ldo_ops,
606                         .type = REGULATOR_VOLTAGE,
607                         .linear_ranges = bd71828_ldo_volts,
608                         .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
609                         .n_voltages = BD71828_LDO_VOLTS,
610                         .enable_reg = BD71828_REG_LDO5_EN,
611                         .enable_mask = BD71828_MASK_RUN_EN,
612                         .vsel_reg = BD71828_REG_LDO5_VOLT,
613                         .vsel_mask = BD71828_MASK_LDO_VOLT,
614                         .of_parse_cb = buck_set_hw_dvs_levels,
615                         .owner = THIS_MODULE,
616                 },
617                 /*
618                  * LDO5 is special. It can choose vsel settings to be configured
619                  * from 2 different registers (by GPIO).
620                  *
621                  * This driver supports only configuration where
622                  * BD71828_REG_LDO5_VOLT_L is used.
623                  */
624                 .dvs = {
625                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
626                                      ROHM_DVS_LEVEL_SUSPEND |
627                                      ROHM_DVS_LEVEL_LPSR,
628                         .run_reg = BD71828_REG_LDO5_VOLT,
629                         .run_mask = BD71828_MASK_LDO_VOLT,
630                         .idle_on_mask = BD71828_MASK_IDLE_EN,
631                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
632                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
633                 },
634
635         }, {
636                 .desc = {
637                         .name = "ldo6",
638                         .of_match = of_match_ptr("LDO6"),
639                         .regulators_node = of_match_ptr("regulators"),
640                         .id = BD71828_LDO6,
641                         .ops = &bd71828_ldo6_ops,
642                         .type = REGULATOR_VOLTAGE,
643                         .fixed_uV = BD71828_LDO_6_VOLTAGE,
644                         .n_voltages = 1,
645                         .enable_reg = BD71828_REG_LDO6_EN,
646                         .enable_mask = BD71828_MASK_RUN_EN,
647                         .owner = THIS_MODULE,
648                         /*
649                          * LDO6 only supports enable/disable for all states.
650                          * Voltage for LDO6 is fixed.
651                          */
652                         .of_parse_cb = ldo6_parse_dt,
653                 },
654         }, {
655                 .desc = {
656                         /* SNVS LDO in data-sheet */
657                         .name = "ldo7",
658                         .of_match = of_match_ptr("LDO7"),
659                         .regulators_node = of_match_ptr("regulators"),
660                         .id = BD71828_LDO_SNVS,
661                         .ops = &bd71828_ldo_ops,
662                         .type = REGULATOR_VOLTAGE,
663                         .linear_ranges = bd71828_ldo_volts,
664                         .n_linear_ranges = ARRAY_SIZE(bd71828_ldo_volts),
665                         .n_voltages = BD71828_LDO_VOLTS,
666                         .enable_reg = BD71828_REG_LDO7_EN,
667                         .enable_mask = BD71828_MASK_RUN_EN,
668                         .vsel_reg = BD71828_REG_LDO7_VOLT,
669                         .vsel_mask = BD71828_MASK_LDO_VOLT,
670                         .owner = THIS_MODULE,
671                         .of_parse_cb = buck_set_hw_dvs_levels,
672                 },
673                 .dvs = {
674                         /*
675                          * LDO7 only supports single voltage for all states.
676                          * voltage can be individually enabled for each state
677                          * though => allow setting all states to support
678                          * enabling power rail on different states.
679                          */
680                         .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE |
681                                      ROHM_DVS_LEVEL_SUSPEND |
682                                      ROHM_DVS_LEVEL_LPSR,
683                         .run_reg = BD71828_REG_LDO7_VOLT,
684                         .idle_reg = BD71828_REG_LDO7_VOLT,
685                         .suspend_reg = BD71828_REG_LDO7_VOLT,
686                         .lpsr_reg = BD71828_REG_LDO7_VOLT,
687                         .run_mask = BD71828_MASK_LDO_VOLT,
688                         .idle_on_mask = BD71828_MASK_IDLE_EN,
689                         .suspend_on_mask = BD71828_MASK_SUSP_EN,
690                         .lpsr_on_mask = BD71828_MASK_LPSR_EN,
691                 },
692
693         },
694 };
695
696 static int bd71828_probe(struct platform_device *pdev)
697 {
698         struct rohm_regmap_dev *bd71828;
699         int i, j, ret;
700         struct regulator_config config = {
701                 .dev = pdev->dev.parent,
702         };
703
704         bd71828 = dev_get_drvdata(pdev->dev.parent);
705         if (!bd71828) {
706                 dev_err(&pdev->dev, "No MFD driver data\n");
707                 return -EINVAL;
708         }
709
710         config.regmap = bd71828->regmap;
711
712         for (i = 0; i < ARRAY_SIZE(bd71828_rdata); i++) {
713                 struct regulator_dev *rdev;
714                 const struct bd71828_regulator_data *rd;
715
716                 rd = &bd71828_rdata[i];
717                 rdev = devm_regulator_register(&pdev->dev,
718                                                &rd->desc, &config);
719                 if (IS_ERR(rdev)) {
720                         dev_err(&pdev->dev,
721                                 "failed to register %s regulator\n",
722                                 rd->desc.name);
723                         return PTR_ERR(rdev);
724                 }
725                 for (j = 0; j < rd->reg_init_amnt; j++) {
726                         ret = regmap_update_bits(bd71828->regmap,
727                                                  rd->reg_inits[j].reg,
728                                                  rd->reg_inits[j].mask,
729                                                  rd->reg_inits[j].val);
730                         if (ret) {
731                                 dev_err(&pdev->dev,
732                                         "regulator %s init failed\n",
733                                         rd->desc.name);
734                                 return ret;
735                         }
736                 }
737         }
738         return 0;
739 }
740
741 static struct platform_driver bd71828_regulator = {
742         .driver = {
743                 .name = "bd71828-pmic"
744         },
745         .probe = bd71828_probe,
746 };
747
748 module_platform_driver(bd71828_regulator);
749
750 MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
751 MODULE_DESCRIPTION("BD71828 voltage regulator driver");
752 MODULE_LICENSE("GPL");
753 MODULE_ALIAS("platform:bd71828-pmic");