blob: e63581651d69392e110aef822359fce007d59f0b [file] [log] [blame]
Matti Vaittinenba087992018-05-30 11:43:43 +03001// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018 ROHM Semiconductors
Matti Vaittinendd2be632018-09-14 11:32:26 +03003// bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver
Matti Vaittinenba087992018-05-30 11:43:43 +03004
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +03005#include <linux/delay.h>
Matti Vaittinenba087992018-05-30 11:43:43 +03006#include <linux/err.h>
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +03007#include <linux/gpio.h>
Matti Vaittinenba087992018-05-30 11:43:43 +03008#include <linux/interrupt.h>
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +03009#include <linux/kernel.h>
Matti Vaittinen410e8b42018-07-30 14:50:08 +030010#include <linux/mfd/rohm-bd718x7.h>
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +030011#include <linux/module.h>
Matti Vaittinenba087992018-05-30 11:43:43 +030012#include <linux/platform_device.h>
13#include <linux/regulator/driver.h>
14#include <linux/regulator/machine.h>
Matti Vaittinenba087992018-05-30 11:43:43 +030015#include <linux/regulator/of_regulator.h>
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +030016#include <linux/slab.h>
Matti Vaittinenba087992018-05-30 11:43:43 +030017
Matti Vaittinenba087992018-05-30 11:43:43 +030018/*
19 * BUCK1/2/3/4
20 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
21 * 00: 10.00mV/usec 10mV 1uS
22 * 01: 5.00mV/usec 10mV 2uS
23 * 10: 2.50mV/usec 10mV 4uS
24 * 11: 1.25mV/usec 10mV 8uS
25 */
Matti Vaittinendd2be632018-09-14 11:32:26 +030026static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
Matti Vaittinenba087992018-05-30 11:43:43 +030027 int ramp_delay)
28{
Matti Vaittinenba087992018-05-30 11:43:43 +030029 int id = rdev->desc->id;
30 unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;
31
Axel Linbcb047e2018-10-04 15:25:58 +080032 dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
Matti Vaittinenba087992018-05-30 11:43:43 +030033 ramp_delay);
34 switch (ramp_delay) {
35 case 1 ... 1250:
36 ramp_value = BUCK_RAMPRATE_1P25MV;
37 break;
38 case 1251 ... 2500:
39 ramp_value = BUCK_RAMPRATE_2P50MV;
40 break;
41 case 2501 ... 5000:
42 ramp_value = BUCK_RAMPRATE_5P00MV;
43 break;
44 case 5001 ... 10000:
45 ramp_value = BUCK_RAMPRATE_10P00MV;
46 break;
47 default:
48 ramp_value = BUCK_RAMPRATE_10P00MV;
Axel Linbcb047e2018-10-04 15:25:58 +080049 dev_err(&rdev->dev,
Matti Vaittinenba087992018-05-30 11:43:43 +030050 "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
51 rdev->desc->name, ramp_delay);
52 }
53
Axel Linbcb047e2018-10-04 15:25:58 +080054 return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id,
Matti Vaittinenba087992018-05-30 11:43:43 +030055 BUCK_RAMPRATE_MASK, ramp_value << 6);
56}
57
58/* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
59 * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
60 * is changed. Hence we return -EBUSY for these if voltage is changed
61 * when BUCK/LDO is enabled.
62 */
Matti Vaittinen494edd22018-09-14 11:27:46 +030063static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
Matti Vaittinenba087992018-05-30 11:43:43 +030064 unsigned int sel)
65{
Axel Linffdc4982018-06-27 20:40:14 +080066 if (regulator_is_enabled_regmap(rdev))
67 return -EBUSY;
Matti Vaittinenba087992018-05-30 11:43:43 +030068
Axel Linffdc4982018-06-27 20:40:14 +080069 return regulator_set_voltage_sel_regmap(rdev, sel);
Matti Vaittinenba087992018-05-30 11:43:43 +030070}
71
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +030072static int bd718xx_set_voltage_sel_pickable_restricted(
73 struct regulator_dev *rdev, unsigned int sel)
74{
75 if (regulator_is_enabled_regmap(rdev))
76 return -EBUSY;
77
78 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
79}
80
81static struct regulator_ops bd718xx_pickable_range_ldo_ops = {
82 .enable = regulator_enable_regmap,
83 .disable = regulator_disable_regmap,
84 .is_enabled = regulator_is_enabled_regmap,
85 .list_voltage = regulator_list_voltage_pickable_linear_range,
86 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
87 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
88};
89
90static struct regulator_ops bd718xx_pickable_range_buck_ops = {
91 .enable = regulator_enable_regmap,
92 .disable = regulator_disable_regmap,
93 .is_enabled = regulator_is_enabled_regmap,
94 .list_voltage = regulator_list_voltage_pickable_linear_range,
95 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
96 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
97 .set_voltage_time_sel = regulator_set_voltage_time_sel,
98};
99
Matti Vaittinen494edd22018-09-14 11:27:46 +0300100static struct regulator_ops bd718xx_ldo_regulator_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300101 .enable = regulator_enable_regmap,
102 .disable = regulator_disable_regmap,
103 .is_enabled = regulator_is_enabled_regmap,
104 .list_voltage = regulator_list_voltage_linear_range,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300105 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
Matti Vaittinenba087992018-05-30 11:43:43 +0300106 .get_voltage_sel = regulator_get_voltage_sel_regmap,
107};
108
Matti Vaittinen494edd22018-09-14 11:27:46 +0300109static struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300110 .enable = regulator_enable_regmap,
111 .disable = regulator_disable_regmap,
112 .is_enabled = regulator_is_enabled_regmap,
113 .list_voltage = regulator_list_voltage_table,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300114 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
Matti Vaittinenba087992018-05-30 11:43:43 +0300115 .get_voltage_sel = regulator_get_voltage_sel_regmap,
116};
117
Matti Vaittinen494edd22018-09-14 11:27:46 +0300118static struct regulator_ops bd718xx_buck_regulator_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300119 .enable = regulator_enable_regmap,
120 .disable = regulator_disable_regmap,
121 .is_enabled = regulator_is_enabled_regmap,
122 .list_voltage = regulator_list_voltage_linear_range,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300123 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
Matti Vaittinenba087992018-05-30 11:43:43 +0300124 .get_voltage_sel = regulator_get_voltage_sel_regmap,
125 .set_voltage_time_sel = regulator_set_voltage_time_sel,
126};
127
Matti Vaittinen494edd22018-09-14 11:27:46 +0300128static struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300129 .enable = regulator_enable_regmap,
130 .disable = regulator_disable_regmap,
131 .is_enabled = regulator_is_enabled_regmap,
132 .list_voltage = regulator_list_voltage_table,
Axel Lin2e612862018-11-10 11:50:03 +0800133 .map_voltage = regulator_map_voltage_ascend,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300134 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
Matti Vaittinenba087992018-05-30 11:43:43 +0300135 .get_voltage_sel = regulator_get_voltage_sel_regmap,
136 .set_voltage_time_sel = regulator_set_voltage_time_sel,
137};
138
Matti Vaittinen494edd22018-09-14 11:27:46 +0300139static struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300140 .enable = regulator_enable_regmap,
141 .disable = regulator_disable_regmap,
142 .is_enabled = regulator_is_enabled_regmap,
143 .list_voltage = regulator_list_voltage_linear_range,
144 .set_voltage_sel = regulator_set_voltage_sel_regmap,
145 .get_voltage_sel = regulator_get_voltage_sel_regmap,
146 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300147 .set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
Matti Vaittinenba087992018-05-30 11:43:43 +0300148};
149
150/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300151 * BD71837 BUCK1/2/3/4
152 * BD71847 BUCK1/2
Matti Vaittinenba087992018-05-30 11:43:43 +0300153 * 0.70 to 1.30V (10mV step)
154 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300155static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300156 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
157 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
158};
159
160/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300161 * BD71837 BUCK5
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300162 * 0.7V to 1.35V (range 0)
163 * and
164 * 0.675 to 1.325 (range 1)
Matti Vaittinenba087992018-05-30 11:43:43 +0300165 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300166static const struct regulator_linear_range bd71837_buck5_volts[] = {
167 /* Ranges when VOLT_SEL bit is 0 */
Matti Vaittinenba087992018-05-30 11:43:43 +0300168 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
169 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
170 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300171 /* Ranges when VOLT_SEL bit is 1 */
172 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
173 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
174 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300175};
176
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300177/*
178 * Range selector for first 3 linear ranges is 0x0
179 * and 0x1 for last 3 ranges.
180 */
181static const unsigned int bd71837_buck5_volt_range_sel[] = {
182 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
Matti Vaittinen494edd22018-09-14 11:27:46 +0300183};
184
Matti Vaittinenba087992018-05-30 11:43:43 +0300185/*
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300186 * BD71847 BUCK3
187 */
188static const struct regulator_linear_range bd71847_buck3_volts[] = {
189 /* Ranges when VOLT_SEL bits are 00 */
190 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
191 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
192 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
193 /* Ranges when VOLT_SEL bits are 01 */
194 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
195 /* Ranges when VOLT_SEL bits are 11 */
196 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
197 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
198 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
199};
200
201static const unsigned int bd71847_buck3_volt_range_sel[] = {
202 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
203};
204
205static const struct regulator_linear_range bd71847_buck4_volts[] = {
206 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
207 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
208};
209
210static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
211
212/*
Matti Vaittinenba087992018-05-30 11:43:43 +0300213 * BUCK6
214 * 3.0V to 3.3V (step 100mV)
215 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300216static const struct regulator_linear_range bd71837_buck6_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300217 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
218};
219
220/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300221 * BD71837 BUCK7
222 * BD71847 BUCK5
Matti Vaittinenba087992018-05-30 11:43:43 +0300223 * 000 = 1.605V
224 * 001 = 1.695V
225 * 010 = 1.755V
226 * 011 = 1.8V (Initial)
227 * 100 = 1.845V
228 * 101 = 1.905V
229 * 110 = 1.95V
230 * 111 = 1.995V
231 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300232static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300233 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
234};
235
236/*
237 * BUCK8
238 * 0.8V to 1.40V (step 10mV)
239 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300240static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300241 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300242};
243
244/*
245 * LDO1
246 * 3.0 to 3.3V (100mV step)
247 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300248static const struct regulator_linear_range bd718xx_ldo1_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300249 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300250 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300251};
252
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300253static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
254
Matti Vaittinenba087992018-05-30 11:43:43 +0300255/*
256 * LDO2
257 * 0.8 or 0.9V
258 */
Axel Linadb78a82018-06-27 20:40:13 +0800259static const unsigned int ldo_2_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300260 900000, 800000
261};
262
263/*
264 * LDO3
265 * 1.8 to 3.3V (100mV step)
266 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300267static const struct regulator_linear_range bd718xx_ldo3_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300268 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
269};
270
271/*
272 * LDO4
273 * 0.9 to 1.8V (100mV step)
274 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300275static const struct regulator_linear_range bd718xx_ldo4_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300276 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300277};
278
279/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300280 * LDO5 for BD71837
Matti Vaittinenba087992018-05-30 11:43:43 +0300281 * 1.8 to 3.3V (100mV step)
282 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300283static const struct regulator_linear_range bd71837_ldo5_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300284 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
285};
286
287/*
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300288 * LDO5 for BD71837
289 * 1.8 to 3.3V (100mV step)
290 */
291static const struct regulator_linear_range bd71847_ldo5_volts[] = {
292 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
293 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
294};
295
296static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
297
298/*
Matti Vaittinenba087992018-05-30 11:43:43 +0300299 * LDO6
300 * 0.9 to 1.8V (100mV step)
301 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300302static const struct regulator_linear_range bd718xx_ldo6_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300303 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300304};
305
306/*
307 * LDO7
308 * 1.8 to 3.3V (100mV step)
309 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300310static const struct regulator_linear_range bd71837_ldo7_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300311 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
312};
313
Matti Vaittinenba087992018-05-30 11:43:43 +0300314struct reg_init {
315 unsigned int reg;
316 unsigned int mask;
Matti Vaittinen494edd22018-09-14 11:27:46 +0300317 unsigned int val;
318};
319struct bd718xx_regulator_data {
320 struct regulator_desc desc;
321 const struct reg_init init;
322 const struct reg_init *additional_inits;
323 int additional_init_amnt;
324};
325
326/*
327 * There is a HW quirk in BD71837. The shutdown sequence timings for
328 * bucks/LDOs which are controlled via register interface are changed.
329 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
330 * beginning of shut-down sequence. As bucks 6 and 7 are parent
331 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
332 * monitoring to errorneously detect under voltage and force PMIC to
333 * emergency state instead of poweroff. In order to avoid this we
334 * disable voltage monitoring for LDO5 and LDO6
335 */
336static const struct reg_init bd71837_ldo5_inits[] = {
337 {
338 .reg = BD718XX_REG_MVRFLTMASK2,
339 .mask = BD718XX_LDO5_VRMON80,
340 .val = BD718XX_LDO5_VRMON80,
341 },
342};
343
344static const struct reg_init bd71837_ldo6_inits[] = {
345 {
346 .reg = BD718XX_REG_MVRFLTMASK2,
347 .mask = BD718XX_LDO6_VRMON80,
348 .val = BD718XX_LDO6_VRMON80,
349 },
350};
351
352static const struct bd718xx_regulator_data bd71847_regulators[] = {
353 {
354 .desc = {
355 .name = "buck1",
356 .of_match = of_match_ptr("BUCK1"),
357 .regulators_node = of_match_ptr("regulators"),
358 .id = BD718XX_BUCK1,
359 .ops = &bd718xx_dvs_buck_regulator_ops,
360 .type = REGULATOR_VOLTAGE,
361 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
362 .linear_ranges = bd718xx_dvs_buck_volts,
363 .n_linear_ranges =
364 ARRAY_SIZE(bd718xx_dvs_buck_volts),
365 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
366 .vsel_mask = DVS_BUCK_RUN_MASK,
367 .enable_reg = BD718XX_REG_BUCK1_CTRL,
368 .enable_mask = BD718XX_BUCK_EN,
369 .owner = THIS_MODULE,
370 },
371 .init = {
372 .reg = BD718XX_REG_BUCK1_CTRL,
373 .mask = BD718XX_BUCK_SEL,
374 .val = BD718XX_BUCK_SEL,
375 },
376 },
377 {
378 .desc = {
379 .name = "buck2",
380 .of_match = of_match_ptr("BUCK2"),
381 .regulators_node = of_match_ptr("regulators"),
382 .id = BD718XX_BUCK2,
383 .ops = &bd718xx_dvs_buck_regulator_ops,
384 .type = REGULATOR_VOLTAGE,
385 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
386 .linear_ranges = bd718xx_dvs_buck_volts,
387 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
388 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
389 .vsel_mask = DVS_BUCK_RUN_MASK,
390 .enable_reg = BD718XX_REG_BUCK2_CTRL,
391 .enable_mask = BD718XX_BUCK_EN,
392 .owner = THIS_MODULE,
393 },
394 .init = {
395 .reg = BD718XX_REG_BUCK2_CTRL,
396 .mask = BD718XX_BUCK_SEL,
397 .val = BD718XX_BUCK_SEL,
398 },
399 },
400 {
401 .desc = {
402 .name = "buck3",
403 .of_match = of_match_ptr("BUCK3"),
404 .regulators_node = of_match_ptr("regulators"),
405 .id = BD718XX_BUCK3,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300406 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300407 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300408 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
409 .linear_ranges = bd71847_buck3_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300410 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300411 ARRAY_SIZE(bd71847_buck3_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300412 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
413 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300414 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
415 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
416 .linear_range_selectors = bd71847_buck3_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300417 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
418 .enable_mask = BD718XX_BUCK_EN,
419 .owner = THIS_MODULE,
420 },
421 .init = {
422 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
423 .mask = BD718XX_BUCK_SEL,
424 .val = BD718XX_BUCK_SEL,
425 },
426 },
427 {
428 .desc = {
429 .name = "buck4",
430 .of_match = of_match_ptr("BUCK4"),
431 .regulators_node = of_match_ptr("regulators"),
432 .id = BD718XX_BUCK4,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300433 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300434 .type = REGULATOR_VOLTAGE,
435 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300436 .linear_ranges = bd71847_buck4_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300437 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300438 ARRAY_SIZE(bd71847_buck4_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300439 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
440 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
441 .vsel_mask = BD71847_BUCK4_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300442 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
443 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
444 .linear_range_selectors = bd71847_buck4_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300445 .enable_mask = BD718XX_BUCK_EN,
446 .owner = THIS_MODULE,
447 },
448 .init = {
449 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
450 .mask = BD718XX_BUCK_SEL,
451 .val = BD718XX_BUCK_SEL,
452 },
453 },
454 {
455 .desc = {
456 .name = "buck5",
457 .of_match = of_match_ptr("BUCK5"),
Matti Vaittinendd2be632018-09-14 11:32:26 +0300458 .regulators_node = of_match_ptr("regulators"),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300459 .id = BD718XX_BUCK5,
460 .ops = &bd718xx_buck_regulator_nolinear_ops,
461 .type = REGULATOR_VOLTAGE,
462 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
463 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
464 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
465 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
466 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
467 .enable_mask = BD718XX_BUCK_EN,
468 .owner = THIS_MODULE,
469 },
470 .init = {
471 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
472 .mask = BD718XX_BUCK_SEL,
473 .val = BD718XX_BUCK_SEL,
474 },
475 },
476 {
477 .desc = {
478 .name = "buck6",
479 .of_match = of_match_ptr("BUCK6"),
480 .regulators_node = of_match_ptr("regulators"),
481 .id = BD718XX_BUCK6,
482 .ops = &bd718xx_buck_regulator_ops,
483 .type = REGULATOR_VOLTAGE,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300484 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300485 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
486 .n_linear_ranges =
487 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
488 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
489 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
490 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
491 .enable_mask = BD718XX_BUCK_EN,
492 .owner = THIS_MODULE,
493 },
494 .init = {
495 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
496 .mask = BD718XX_BUCK_SEL,
497 .val = BD718XX_BUCK_SEL,
498 },
499 },
500 {
501 .desc = {
502 .name = "ldo1",
503 .of_match = of_match_ptr("LDO1"),
504 .regulators_node = of_match_ptr("regulators"),
505 .id = BD718XX_LDO1,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300506 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300507 .type = REGULATOR_VOLTAGE,
508 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
509 .linear_ranges = bd718xx_ldo1_volts,
510 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
511 .vsel_reg = BD718XX_REG_LDO1_VOLT,
512 .vsel_mask = BD718XX_LDO1_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300513 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
514 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
515 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300516 .enable_reg = BD718XX_REG_LDO1_VOLT,
517 .enable_mask = BD718XX_LDO_EN,
518 .owner = THIS_MODULE,
519 },
520 .init = {
521 .reg = BD718XX_REG_LDO1_VOLT,
522 .mask = BD718XX_LDO_SEL,
523 .val = BD718XX_LDO_SEL,
524 },
525 },
526 {
527 .desc = {
528 .name = "ldo2",
529 .of_match = of_match_ptr("LDO2"),
530 .regulators_node = of_match_ptr("regulators"),
531 .id = BD718XX_LDO2,
532 .ops = &bd718xx_ldo_regulator_nolinear_ops,
533 .type = REGULATOR_VOLTAGE,
534 .volt_table = &ldo_2_volts[0],
535 .vsel_reg = BD718XX_REG_LDO2_VOLT,
536 .vsel_mask = BD718XX_LDO2_MASK,
537 .n_voltages = ARRAY_SIZE(ldo_2_volts),
538 .enable_reg = BD718XX_REG_LDO2_VOLT,
539 .enable_mask = BD718XX_LDO_EN,
540 .owner = THIS_MODULE,
541 },
542 .init = {
543 .reg = BD718XX_REG_LDO2_VOLT,
544 .mask = BD718XX_LDO_SEL,
545 .val = BD718XX_LDO_SEL,
546 },
547 },
548 {
549 .desc = {
550 .name = "ldo3",
551 .of_match = of_match_ptr("LDO3"),
552 .regulators_node = of_match_ptr("regulators"),
553 .id = BD718XX_LDO3,
554 .ops = &bd718xx_ldo_regulator_ops,
555 .type = REGULATOR_VOLTAGE,
556 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
557 .linear_ranges = bd718xx_ldo3_volts,
558 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
559 .vsel_reg = BD718XX_REG_LDO3_VOLT,
560 .vsel_mask = BD718XX_LDO3_MASK,
561 .enable_reg = BD718XX_REG_LDO3_VOLT,
562 .enable_mask = BD718XX_LDO_EN,
563 .owner = THIS_MODULE,
564 },
565 .init = {
566 .reg = BD718XX_REG_LDO3_VOLT,
567 .mask = BD718XX_LDO_SEL,
568 .val = BD718XX_LDO_SEL,
569 },
570 },
571 {
572 .desc = {
573 .name = "ldo4",
574 .of_match = of_match_ptr("LDO4"),
575 .regulators_node = of_match_ptr("regulators"),
576 .id = BD718XX_LDO4,
577 .ops = &bd718xx_ldo_regulator_ops,
578 .type = REGULATOR_VOLTAGE,
579 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
580 .linear_ranges = bd718xx_ldo4_volts,
581 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
582 .vsel_reg = BD718XX_REG_LDO4_VOLT,
583 .vsel_mask = BD718XX_LDO4_MASK,
584 .enable_reg = BD718XX_REG_LDO4_VOLT,
585 .enable_mask = BD718XX_LDO_EN,
586 .owner = THIS_MODULE,
587 },
588 .init = {
589 .reg = BD718XX_REG_LDO4_VOLT,
590 .mask = BD718XX_LDO_SEL,
591 .val = BD718XX_LDO_SEL,
592 },
593 },
594 {
595 .desc = {
596 .name = "ldo5",
597 .of_match = of_match_ptr("LDO5"),
598 .regulators_node = of_match_ptr("regulators"),
599 .id = BD718XX_LDO5,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300600 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300601 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300602 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
603 .linear_ranges = bd71847_ldo5_volts,
604 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300605 .vsel_reg = BD718XX_REG_LDO5_VOLT,
606 .vsel_mask = BD71847_LDO5_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300607 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
608 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
609 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300610 .enable_reg = BD718XX_REG_LDO5_VOLT,
611 .enable_mask = BD718XX_LDO_EN,
612 .owner = THIS_MODULE,
613 },
614 .init = {
615 .reg = BD718XX_REG_LDO5_VOLT,
616 .mask = BD718XX_LDO_SEL,
617 .val = BD718XX_LDO_SEL,
618 },
619 },
620 {
621 .desc = {
622 .name = "ldo6",
623 .of_match = of_match_ptr("LDO6"),
624 .regulators_node = of_match_ptr("regulators"),
625 .id = BD718XX_LDO6,
626 .ops = &bd718xx_ldo_regulator_ops,
627 .type = REGULATOR_VOLTAGE,
628 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
629 .linear_ranges = bd718xx_ldo6_volts,
630 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
631 /* LDO6 is supplied by buck5 */
632 .supply_name = "buck5",
633 .vsel_reg = BD718XX_REG_LDO6_VOLT,
634 .vsel_mask = BD718XX_LDO6_MASK,
635 .enable_reg = BD718XX_REG_LDO6_VOLT,
636 .enable_mask = BD718XX_LDO_EN,
637 .owner = THIS_MODULE,
638 },
639 .init = {
640 .reg = BD718XX_REG_LDO6_VOLT,
641 .mask = BD718XX_LDO_SEL,
642 .val = BD718XX_LDO_SEL,
643 },
644 },
645};
646
647static const struct bd718xx_regulator_data bd71837_regulators[] = {
648 {
649 .desc = {
650 .name = "buck1",
651 .of_match = of_match_ptr("BUCK1"),
652 .regulators_node = of_match_ptr("regulators"),
653 .id = BD718XX_BUCK1,
654 .ops = &bd718xx_dvs_buck_regulator_ops,
655 .type = REGULATOR_VOLTAGE,
656 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
657 .linear_ranges = bd718xx_dvs_buck_volts,
658 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
659 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
660 .vsel_mask = DVS_BUCK_RUN_MASK,
661 .enable_reg = BD718XX_REG_BUCK1_CTRL,
662 .enable_mask = BD718XX_BUCK_EN,
663 .owner = THIS_MODULE,
664 },
665 .init = {
666 .reg = BD718XX_REG_BUCK1_CTRL,
667 .mask = BD718XX_BUCK_SEL,
668 .val = BD718XX_BUCK_SEL,
669 },
670 },
671 {
672 .desc = {
673 .name = "buck2",
674 .of_match = of_match_ptr("BUCK2"),
675 .regulators_node = of_match_ptr("regulators"),
676 .id = BD718XX_BUCK2,
677 .ops = &bd718xx_dvs_buck_regulator_ops,
678 .type = REGULATOR_VOLTAGE,
679 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
680 .linear_ranges = bd718xx_dvs_buck_volts,
681 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
682 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
683 .vsel_mask = DVS_BUCK_RUN_MASK,
684 .enable_reg = BD718XX_REG_BUCK2_CTRL,
685 .enable_mask = BD718XX_BUCK_EN,
686 .owner = THIS_MODULE,
687 },
688 .init = {
689 .reg = BD718XX_REG_BUCK2_CTRL,
690 .mask = BD718XX_BUCK_SEL,
691 .val = BD718XX_BUCK_SEL,
692 },
693 },
694 {
695 .desc = {
696 .name = "buck3",
697 .of_match = of_match_ptr("BUCK3"),
698 .regulators_node = of_match_ptr("regulators"),
699 .id = BD718XX_BUCK3,
700 .ops = &bd718xx_dvs_buck_regulator_ops,
701 .type = REGULATOR_VOLTAGE,
702 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
703 .linear_ranges = bd718xx_dvs_buck_volts,
704 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
705 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
706 .vsel_mask = DVS_BUCK_RUN_MASK,
707 .enable_reg = BD71837_REG_BUCK3_CTRL,
708 .enable_mask = BD718XX_BUCK_EN,
709 .owner = THIS_MODULE,
710 },
711 .init = {
712 .reg = BD71837_REG_BUCK3_CTRL,
713 .mask = BD718XX_BUCK_SEL,
714 .val = BD718XX_BUCK_SEL,
715 },
716 },
717 {
718 .desc = {
719 .name = "buck4",
720 .of_match = of_match_ptr("BUCK4"),
721 .regulators_node = of_match_ptr("regulators"),
722 .id = BD718XX_BUCK4,
723 .ops = &bd718xx_dvs_buck_regulator_ops,
724 .type = REGULATOR_VOLTAGE,
725 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
726 .linear_ranges = bd718xx_dvs_buck_volts,
727 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
728 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
729 .vsel_mask = DVS_BUCK_RUN_MASK,
730 .enable_reg = BD71837_REG_BUCK4_CTRL,
731 .enable_mask = BD718XX_BUCK_EN,
732 .owner = THIS_MODULE,
733 },
734 .init = {
735 .reg = BD71837_REG_BUCK4_CTRL,
736 .mask = BD718XX_BUCK_SEL,
737 .val = BD718XX_BUCK_SEL,
738 },
739 },
740 {
741 .desc = {
742 .name = "buck5",
743 .of_match = of_match_ptr("BUCK5"),
744 .regulators_node = of_match_ptr("regulators"),
745 .id = BD718XX_BUCK5,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300746 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300747 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300748 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
749 .linear_ranges = bd71837_buck5_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300750 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300751 ARRAY_SIZE(bd71837_buck5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300752 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300753 .vsel_mask = BD71837_BUCK5_MASK,
754 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
755 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
756 .linear_range_selectors = bd71837_buck5_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300757 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
758 .enable_mask = BD718XX_BUCK_EN,
759 .owner = THIS_MODULE,
760 },
761 .init = {
762 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
763 .mask = BD718XX_BUCK_SEL,
764 .val = BD718XX_BUCK_SEL,
765 },
766 },
767 {
768 .desc = {
769 .name = "buck6",
770 .of_match = of_match_ptr("BUCK6"),
771 .regulators_node = of_match_ptr("regulators"),
772 .id = BD718XX_BUCK6,
773 .ops = &bd718xx_buck_regulator_ops,
774 .type = REGULATOR_VOLTAGE,
775 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300776 .linear_ranges = bd71837_buck6_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300777 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300778 ARRAY_SIZE(bd71837_buck6_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300779 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
780 .vsel_mask = BD71837_BUCK6_MASK,
781 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
782 .enable_mask = BD718XX_BUCK_EN,
783 .owner = THIS_MODULE,
784 },
785 .init = {
786 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
787 .mask = BD718XX_BUCK_SEL,
788 .val = BD718XX_BUCK_SEL,
789 },
790 },
791 {
792 .desc = {
793 .name = "buck7",
794 .of_match = of_match_ptr("BUCK7"),
795 .regulators_node = of_match_ptr("regulators"),
796 .id = BD718XX_BUCK7,
797 .ops = &bd718xx_buck_regulator_nolinear_ops,
798 .type = REGULATOR_VOLTAGE,
799 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
800 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
801 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
802 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
803 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
804 .enable_mask = BD718XX_BUCK_EN,
805 .owner = THIS_MODULE,
806 },
807 .init = {
808 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
809 .mask = BD718XX_BUCK_SEL,
810 .val = BD718XX_BUCK_SEL,
811 },
812 },
813 {
814 .desc = {
815 .name = "buck8",
816 .of_match = of_match_ptr("BUCK8"),
817 .regulators_node = of_match_ptr("regulators"),
818 .id = BD718XX_BUCK8,
819 .ops = &bd718xx_buck_regulator_ops,
820 .type = REGULATOR_VOLTAGE,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300821 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300822 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
823 .n_linear_ranges =
824 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
825 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
826 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
827 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
828 .enable_mask = BD718XX_BUCK_EN,
829 .owner = THIS_MODULE,
830 },
831 .init = {
832 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
833 .mask = BD718XX_BUCK_SEL,
834 .val = BD718XX_BUCK_SEL,
835 },
836 },
837 {
838 .desc = {
839 .name = "ldo1",
840 .of_match = of_match_ptr("LDO1"),
841 .regulators_node = of_match_ptr("regulators"),
842 .id = BD718XX_LDO1,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300843 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300844 .type = REGULATOR_VOLTAGE,
845 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
846 .linear_ranges = bd718xx_ldo1_volts,
847 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
848 .vsel_reg = BD718XX_REG_LDO1_VOLT,
849 .vsel_mask = BD718XX_LDO1_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300850 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
851 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
852 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300853 .enable_reg = BD718XX_REG_LDO1_VOLT,
854 .enable_mask = BD718XX_LDO_EN,
855 .owner = THIS_MODULE,
856 },
857 .init = {
858 .reg = BD718XX_REG_LDO1_VOLT,
859 .mask = BD718XX_LDO_SEL,
860 .val = BD718XX_LDO_SEL,
861 },
862 },
863 {
864 .desc = {
865 .name = "ldo2",
866 .of_match = of_match_ptr("LDO2"),
867 .regulators_node = of_match_ptr("regulators"),
868 .id = BD718XX_LDO2,
869 .ops = &bd718xx_ldo_regulator_nolinear_ops,
870 .type = REGULATOR_VOLTAGE,
871 .volt_table = &ldo_2_volts[0],
872 .vsel_reg = BD718XX_REG_LDO2_VOLT,
873 .vsel_mask = BD718XX_LDO2_MASK,
874 .n_voltages = ARRAY_SIZE(ldo_2_volts),
875 .enable_reg = BD718XX_REG_LDO2_VOLT,
876 .enable_mask = BD718XX_LDO_EN,
877 .owner = THIS_MODULE,
878 },
879 .init = {
880 .reg = BD718XX_REG_LDO2_VOLT,
881 .mask = BD718XX_LDO_SEL,
882 .val = BD718XX_LDO_SEL,
883 },
884 },
885 {
886 .desc = {
887 .name = "ldo3",
888 .of_match = of_match_ptr("LDO3"),
889 .regulators_node = of_match_ptr("regulators"),
890 .id = BD718XX_LDO3,
891 .ops = &bd718xx_ldo_regulator_ops,
892 .type = REGULATOR_VOLTAGE,
893 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
894 .linear_ranges = bd718xx_ldo3_volts,
895 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
896 .vsel_reg = BD718XX_REG_LDO3_VOLT,
897 .vsel_mask = BD718XX_LDO3_MASK,
898 .enable_reg = BD718XX_REG_LDO3_VOLT,
899 .enable_mask = BD718XX_LDO_EN,
900 .owner = THIS_MODULE,
901 },
902 .init = {
903 .reg = BD718XX_REG_LDO3_VOLT,
904 .mask = BD718XX_LDO_SEL,
905 .val = BD718XX_LDO_SEL,
906 },
907 },
908 {
909 .desc = {
910 .name = "ldo4",
911 .of_match = of_match_ptr("LDO4"),
912 .regulators_node = of_match_ptr("regulators"),
913 .id = BD718XX_LDO4,
914 .ops = &bd718xx_ldo_regulator_ops,
915 .type = REGULATOR_VOLTAGE,
916 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
917 .linear_ranges = bd718xx_ldo4_volts,
918 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
919 .vsel_reg = BD718XX_REG_LDO4_VOLT,
920 .vsel_mask = BD718XX_LDO4_MASK,
921 .enable_reg = BD718XX_REG_LDO4_VOLT,
922 .enable_mask = BD718XX_LDO_EN,
923 .owner = THIS_MODULE,
924 },
925 .init = {
926 .reg = BD718XX_REG_LDO4_VOLT,
927 .mask = BD718XX_LDO_SEL,
928 .val = BD718XX_LDO_SEL,
929 },
930 },
931 {
932 .desc = {
933 .name = "ldo5",
934 .of_match = of_match_ptr("LDO5"),
935 .regulators_node = of_match_ptr("regulators"),
936 .id = BD718XX_LDO5,
937 .ops = &bd718xx_ldo_regulator_ops,
938 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300939 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
940 .linear_ranges = bd71837_ldo5_volts,
941 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300942 /* LDO5 is supplied by buck6 */
943 .supply_name = "buck6",
944 .vsel_reg = BD718XX_REG_LDO5_VOLT,
945 .vsel_mask = BD71837_LDO5_MASK,
946 .enable_reg = BD718XX_REG_LDO5_VOLT,
947 .enable_mask = BD718XX_LDO_EN,
948 .owner = THIS_MODULE,
949 },
950 .init = {
951 .reg = BD718XX_REG_LDO5_VOLT,
952 .mask = BD718XX_LDO_SEL,
953 .val = BD718XX_LDO_SEL,
954 },
955 .additional_inits = bd71837_ldo5_inits,
956 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
957 },
958 {
959 .desc = {
960 .name = "ldo6",
961 .of_match = of_match_ptr("LDO6"),
962 .regulators_node = of_match_ptr("regulators"),
963 .id = BD718XX_LDO6,
964 .ops = &bd718xx_ldo_regulator_ops,
965 .type = REGULATOR_VOLTAGE,
966 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
967 .linear_ranges = bd718xx_ldo6_volts,
968 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
969 /* LDO6 is supplied by buck7 */
970 .supply_name = "buck7",
971 .vsel_reg = BD718XX_REG_LDO6_VOLT,
972 .vsel_mask = BD718XX_LDO6_MASK,
973 .enable_reg = BD718XX_REG_LDO6_VOLT,
974 .enable_mask = BD718XX_LDO_EN,
975 .owner = THIS_MODULE,
976 },
977 .init = {
978 .reg = BD718XX_REG_LDO6_VOLT,
979 .mask = BD718XX_LDO_SEL,
980 .val = BD718XX_LDO_SEL,
981 },
982 .additional_inits = bd71837_ldo6_inits,
983 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
984 },
985 {
986 .desc = {
987 .name = "ldo7",
988 .of_match = of_match_ptr("LDO7"),
989 .regulators_node = of_match_ptr("regulators"),
990 .id = BD718XX_LDO7,
991 .ops = &bd718xx_ldo_regulator_ops,
992 .type = REGULATOR_VOLTAGE,
993 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
994 .linear_ranges = bd71837_ldo7_volts,
995 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
996 .vsel_reg = BD71837_REG_LDO7_VOLT,
997 .vsel_mask = BD71837_LDO7_MASK,
998 .enable_reg = BD71837_REG_LDO7_VOLT,
999 .enable_mask = BD718XX_LDO_EN,
1000 .owner = THIS_MODULE,
1001 },
1002 .init = {
1003 .reg = BD71837_REG_LDO7_VOLT,
1004 .mask = BD718XX_LDO_SEL,
1005 .val = BD718XX_LDO_SEL,
1006 },
1007 },
1008};
1009
1010struct bd718xx_pmic_inits {
Geert Uytterhoevende226eb2018-10-28 17:09:22 +01001011 const struct bd718xx_regulator_data *r_datas;
Matti Vaittinen494edd22018-09-14 11:27:46 +03001012 unsigned int r_amount;
Matti Vaittinenba087992018-05-30 11:43:43 +03001013};
1014
Matti Vaittinendd2be632018-09-14 11:32:26 +03001015static int bd718xx_probe(struct platform_device *pdev)
Matti Vaittinenba087992018-05-30 11:43:43 +03001016{
Axel Linbcb047e2018-10-04 15:25:58 +08001017 struct bd718xx *mfd;
Matti Vaittinenba087992018-05-30 11:43:43 +03001018 struct regulator_config config = { 0 };
Matti Vaittinen494edd22018-09-14 11:27:46 +03001019 struct bd718xx_pmic_inits pmic_regulators[] = {
1020 [BD718XX_TYPE_BD71837] = {
Geert Uytterhoevende226eb2018-10-28 17:09:22 +01001021 .r_datas = bd71837_regulators,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001022 .r_amount = ARRAY_SIZE(bd71837_regulators),
1023 },
1024 [BD718XX_TYPE_BD71847] = {
Geert Uytterhoevende226eb2018-10-28 17:09:22 +01001025 .r_datas = bd71847_regulators,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001026 .r_amount = ARRAY_SIZE(bd71847_regulators),
1027 },
Matti Vaittinenba087992018-05-30 11:43:43 +03001028 };
1029
Matti Vaittinen494edd22018-09-14 11:27:46 +03001030 int i, j, err;
Matti Vaittinenba087992018-05-30 11:43:43 +03001031
Axel Linbcb047e2018-10-04 15:25:58 +08001032 mfd = dev_get_drvdata(pdev->dev.parent);
1033 if (!mfd) {
Matti Vaittinenba087992018-05-30 11:43:43 +03001034 dev_err(&pdev->dev, "No MFD driver data\n");
1035 err = -EINVAL;
1036 goto err;
1037 }
Axel Linbcb047e2018-10-04 15:25:58 +08001038
1039 if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
1040 !pmic_regulators[mfd->chip_type].r_datas) {
Matti Vaittinen494edd22018-09-14 11:27:46 +03001041 dev_err(&pdev->dev, "Unsupported chip type\n");
1042 err = -EINVAL;
1043 goto err;
1044 }
1045
Matti Vaittinenba087992018-05-30 11:43:43 +03001046 /* Register LOCK release */
Axel Linbcb047e2018-10-04 15:25:58 +08001047 err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
Matti Vaittinenba087992018-05-30 11:43:43 +03001048 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1049 if (err) {
Axel Linbcb047e2018-10-04 15:25:58 +08001050 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
Matti Vaittinenba087992018-05-30 11:43:43 +03001051 goto err;
1052 } else {
Axel Linbcb047e2018-10-04 15:25:58 +08001053 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
Matti Vaittinen494edd22018-09-14 11:27:46 +03001054 BD718XX_REG_REGLOCK);
Matti Vaittinenba087992018-05-30 11:43:43 +03001055 }
1056
Matti Vaittinene770b182018-11-07 15:41:26 +02001057 /* At poweroff transition PMIC HW disables EN bit for regulators but
1058 * leaves SEL bit untouched. So if state transition from POWEROFF
1059 * is done to SNVS - then all power rails controlled by SW (having
1060 * SEL bit set) stay disabled as EN is cleared. This may result boot
1061 * failure if any crucial systems are powered by these rails.
1062 *
1063 * Change the next stage from poweroff to be READY instead of SNVS
1064 * for all reset types because OTP loading at READY will clear SEL
1065 * bit allowing HW defaults for power rails to be used
1066 */
1067 err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1,
1068 BD718XX_ON_REQ_POWEROFF_MASK |
1069 BD718XX_SWRESET_POWEROFF_MASK |
1070 BD718XX_WDOG_POWEROFF_MASK |
1071 BD718XX_KEY_L_POWEROFF_MASK,
1072 BD718XX_POWOFF_TO_RDY);
1073 if (err) {
1074 dev_err(&pdev->dev, "Failed to change reset target\n");
1075 goto err;
1076 } else {
1077 dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n");
1078 }
1079
Axel Linbcb047e2018-10-04 15:25:58 +08001080 for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
Matti Vaittinen823f18f2018-08-29 15:36:10 +03001081
Matti Vaittinen494edd22018-09-14 11:27:46 +03001082 const struct regulator_desc *desc;
Matti Vaittinenba087992018-05-30 11:43:43 +03001083 struct regulator_dev *rdev;
Matti Vaittinen494edd22018-09-14 11:27:46 +03001084 const struct bd718xx_regulator_data *r;
Matti Vaittinenba087992018-05-30 11:43:43 +03001085
Geert Uytterhoevende226eb2018-10-28 17:09:22 +01001086 r = &pmic_regulators[mfd->chip_type].r_datas[i];
Matti Vaittinen494edd22018-09-14 11:27:46 +03001087 desc = &r->desc;
Matti Vaittinenba087992018-05-30 11:43:43 +03001088
Matti Vaittinenba087992018-05-30 11:43:43 +03001089 config.dev = pdev->dev.parent;
Axel Linbcb047e2018-10-04 15:25:58 +08001090 config.regmap = mfd->regmap;
Matti Vaittinenba087992018-05-30 11:43:43 +03001091
1092 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1093 if (IS_ERR(rdev)) {
Axel Linbcb047e2018-10-04 15:25:58 +08001094 dev_err(&pdev->dev,
Matti Vaittinenba087992018-05-30 11:43:43 +03001095 "failed to register %s regulator\n",
1096 desc->name);
1097 err = PTR_ERR(rdev);
1098 goto err;
1099 }
1100 /* Regulator register gets the regulator constraints and
1101 * applies them (set_machine_constraints). This should have
1102 * turned the control register(s) to correct values and we
1103 * can now switch the control from PMIC state machine to the
1104 * register interface
1105 */
Axel Linbcb047e2018-10-04 15:25:58 +08001106 err = regmap_update_bits(mfd->regmap, r->init.reg,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001107 r->init.mask, r->init.val);
Matti Vaittinenba087992018-05-30 11:43:43 +03001108 if (err) {
Axel Linbcb047e2018-10-04 15:25:58 +08001109 dev_err(&pdev->dev,
Matti Vaittinenba087992018-05-30 11:43:43 +03001110 "Failed to write BUCK/LDO SEL bit for (%s)\n",
1111 desc->name);
1112 goto err;
1113 }
Matti Vaittinen494edd22018-09-14 11:27:46 +03001114 for (j = 0; j < r->additional_init_amnt; j++) {
Axel Linbcb047e2018-10-04 15:25:58 +08001115 err = regmap_update_bits(mfd->regmap,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001116 r->additional_inits[j].reg,
1117 r->additional_inits[j].mask,
1118 r->additional_inits[j].val);
1119 if (err) {
Axel Linbcb047e2018-10-04 15:25:58 +08001120 dev_err(&pdev->dev,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001121 "Buck (%s) initialization failed\n",
1122 desc->name);
1123 goto err;
1124 }
1125 }
Matti Vaittinenba087992018-05-30 11:43:43 +03001126 }
1127
Matti Vaittinenba087992018-05-30 11:43:43 +03001128err:
1129 return err;
1130}
1131
Matti Vaittinendd2be632018-09-14 11:32:26 +03001132static struct platform_driver bd718xx_regulator = {
Matti Vaittinenba087992018-05-30 11:43:43 +03001133 .driver = {
Matti Vaittinen494edd22018-09-14 11:27:46 +03001134 .name = "bd718xx-pmic",
Matti Vaittinenba087992018-05-30 11:43:43 +03001135 },
Matti Vaittinendd2be632018-09-14 11:32:26 +03001136 .probe = bd718xx_probe,
Matti Vaittinenba087992018-05-30 11:43:43 +03001137};
1138
Matti Vaittinendd2be632018-09-14 11:32:26 +03001139module_platform_driver(bd718xx_regulator);
Matti Vaittinenba087992018-05-30 11:43:43 +03001140
1141MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
Matti Vaittinendd2be632018-09-14 11:32:26 +03001142MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
Matti Vaittinenba087992018-05-30 11:43:43 +03001143MODULE_LICENSE("GPL");