blob: 3a47e0372e77c81248efc6bf04e7fb832d5b59ac [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,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300133 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
Matti Vaittinenba087992018-05-30 11:43:43 +0300134 .get_voltage_sel = regulator_get_voltage_sel_regmap,
135 .set_voltage_time_sel = regulator_set_voltage_time_sel,
136};
137
Matti Vaittinen494edd22018-09-14 11:27:46 +0300138static struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300139 .enable = regulator_enable_regmap,
140 .disable = regulator_disable_regmap,
141 .is_enabled = regulator_is_enabled_regmap,
142 .list_voltage = regulator_list_voltage_linear_range,
143 .set_voltage_sel = regulator_set_voltage_sel_regmap,
144 .get_voltage_sel = regulator_get_voltage_sel_regmap,
145 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300146 .set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
Matti Vaittinenba087992018-05-30 11:43:43 +0300147};
148
149/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300150 * BD71837 BUCK1/2/3/4
151 * BD71847 BUCK1/2
Matti Vaittinenba087992018-05-30 11:43:43 +0300152 * 0.70 to 1.30V (10mV step)
153 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300154static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300155 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
156 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
157};
158
159/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300160 * BD71837 BUCK5
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300161 * 0.7V to 1.35V (range 0)
162 * and
163 * 0.675 to 1.325 (range 1)
Matti Vaittinenba087992018-05-30 11:43:43 +0300164 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300165static const struct regulator_linear_range bd71837_buck5_volts[] = {
166 /* Ranges when VOLT_SEL bit is 0 */
Matti Vaittinenba087992018-05-30 11:43:43 +0300167 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
168 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
169 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300170 /* Ranges when VOLT_SEL bit is 1 */
171 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
172 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
173 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300174};
175
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300176/*
177 * Range selector for first 3 linear ranges is 0x0
178 * and 0x1 for last 3 ranges.
179 */
180static const unsigned int bd71837_buck5_volt_range_sel[] = {
181 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
Matti Vaittinen494edd22018-09-14 11:27:46 +0300182};
183
Matti Vaittinenba087992018-05-30 11:43:43 +0300184/*
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300185 * BD71847 BUCK3
186 */
187static const struct regulator_linear_range bd71847_buck3_volts[] = {
188 /* Ranges when VOLT_SEL bits are 00 */
189 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
190 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
191 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
192 /* Ranges when VOLT_SEL bits are 01 */
193 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
194 /* Ranges when VOLT_SEL bits are 11 */
195 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
196 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
197 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
198};
199
200static const unsigned int bd71847_buck3_volt_range_sel[] = {
201 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
202};
203
204static const struct regulator_linear_range bd71847_buck4_volts[] = {
205 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
206 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
207};
208
209static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
210
211/*
Matti Vaittinenba087992018-05-30 11:43:43 +0300212 * BUCK6
213 * 3.0V to 3.3V (step 100mV)
214 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300215static const struct regulator_linear_range bd71837_buck6_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300216 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
217};
218
219/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300220 * BD71837 BUCK7
221 * BD71847 BUCK5
Matti Vaittinenba087992018-05-30 11:43:43 +0300222 * 000 = 1.605V
223 * 001 = 1.695V
224 * 010 = 1.755V
225 * 011 = 1.8V (Initial)
226 * 100 = 1.845V
227 * 101 = 1.905V
228 * 110 = 1.95V
229 * 111 = 1.995V
230 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300231static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300232 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
233};
234
235/*
236 * BUCK8
237 * 0.8V to 1.40V (step 10mV)
238 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300239static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300240 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300241};
242
243/*
244 * LDO1
245 * 3.0 to 3.3V (100mV step)
246 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300247static const struct regulator_linear_range bd718xx_ldo1_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300248 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300249 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300250};
251
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300252static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
253
Matti Vaittinenba087992018-05-30 11:43:43 +0300254/*
255 * LDO2
256 * 0.8 or 0.9V
257 */
Axel Linadb78a82018-06-27 20:40:13 +0800258static const unsigned int ldo_2_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300259 900000, 800000
260};
261
262/*
263 * LDO3
264 * 1.8 to 3.3V (100mV step)
265 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300266static const struct regulator_linear_range bd718xx_ldo3_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300267 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
268};
269
270/*
271 * LDO4
272 * 0.9 to 1.8V (100mV step)
273 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300274static const struct regulator_linear_range bd718xx_ldo4_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300275 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300276};
277
278/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300279 * LDO5 for BD71837
Matti Vaittinenba087992018-05-30 11:43:43 +0300280 * 1.8 to 3.3V (100mV step)
281 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300282static const struct regulator_linear_range bd71837_ldo5_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300283 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
284};
285
286/*
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300287 * LDO5 for BD71837
288 * 1.8 to 3.3V (100mV step)
289 */
290static const struct regulator_linear_range bd71847_ldo5_volts[] = {
291 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
292 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
293};
294
295static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
296
297/*
Matti Vaittinenba087992018-05-30 11:43:43 +0300298 * LDO6
299 * 0.9 to 1.8V (100mV step)
300 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300301static const struct regulator_linear_range bd718xx_ldo6_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300302 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300303};
304
305/*
306 * LDO7
307 * 1.8 to 3.3V (100mV step)
308 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300309static const struct regulator_linear_range bd71837_ldo7_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300310 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
311};
312
Matti Vaittinenba087992018-05-30 11:43:43 +0300313struct reg_init {
314 unsigned int reg;
315 unsigned int mask;
Matti Vaittinen494edd22018-09-14 11:27:46 +0300316 unsigned int val;
317};
318struct bd718xx_regulator_data {
319 struct regulator_desc desc;
320 const struct reg_init init;
321 const struct reg_init *additional_inits;
322 int additional_init_amnt;
323};
324
325/*
326 * There is a HW quirk in BD71837. The shutdown sequence timings for
327 * bucks/LDOs which are controlled via register interface are changed.
328 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
329 * beginning of shut-down sequence. As bucks 6 and 7 are parent
330 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
331 * monitoring to errorneously detect under voltage and force PMIC to
332 * emergency state instead of poweroff. In order to avoid this we
333 * disable voltage monitoring for LDO5 and LDO6
334 */
335static const struct reg_init bd71837_ldo5_inits[] = {
336 {
337 .reg = BD718XX_REG_MVRFLTMASK2,
338 .mask = BD718XX_LDO5_VRMON80,
339 .val = BD718XX_LDO5_VRMON80,
340 },
341};
342
343static const struct reg_init bd71837_ldo6_inits[] = {
344 {
345 .reg = BD718XX_REG_MVRFLTMASK2,
346 .mask = BD718XX_LDO6_VRMON80,
347 .val = BD718XX_LDO6_VRMON80,
348 },
349};
350
351static const struct bd718xx_regulator_data bd71847_regulators[] = {
352 {
353 .desc = {
354 .name = "buck1",
355 .of_match = of_match_ptr("BUCK1"),
356 .regulators_node = of_match_ptr("regulators"),
357 .id = BD718XX_BUCK1,
358 .ops = &bd718xx_dvs_buck_regulator_ops,
359 .type = REGULATOR_VOLTAGE,
360 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
361 .linear_ranges = bd718xx_dvs_buck_volts,
362 .n_linear_ranges =
363 ARRAY_SIZE(bd718xx_dvs_buck_volts),
364 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
365 .vsel_mask = DVS_BUCK_RUN_MASK,
366 .enable_reg = BD718XX_REG_BUCK1_CTRL,
367 .enable_mask = BD718XX_BUCK_EN,
368 .owner = THIS_MODULE,
369 },
370 .init = {
371 .reg = BD718XX_REG_BUCK1_CTRL,
372 .mask = BD718XX_BUCK_SEL,
373 .val = BD718XX_BUCK_SEL,
374 },
375 },
376 {
377 .desc = {
378 .name = "buck2",
379 .of_match = of_match_ptr("BUCK2"),
380 .regulators_node = of_match_ptr("regulators"),
381 .id = BD718XX_BUCK2,
382 .ops = &bd718xx_dvs_buck_regulator_ops,
383 .type = REGULATOR_VOLTAGE,
384 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
385 .linear_ranges = bd718xx_dvs_buck_volts,
386 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
387 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
388 .vsel_mask = DVS_BUCK_RUN_MASK,
389 .enable_reg = BD718XX_REG_BUCK2_CTRL,
390 .enable_mask = BD718XX_BUCK_EN,
391 .owner = THIS_MODULE,
392 },
393 .init = {
394 .reg = BD718XX_REG_BUCK2_CTRL,
395 .mask = BD718XX_BUCK_SEL,
396 .val = BD718XX_BUCK_SEL,
397 },
398 },
399 {
400 .desc = {
401 .name = "buck3",
402 .of_match = of_match_ptr("BUCK3"),
403 .regulators_node = of_match_ptr("regulators"),
404 .id = BD718XX_BUCK3,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300405 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300406 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300407 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
408 .linear_ranges = bd71847_buck3_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300409 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300410 ARRAY_SIZE(bd71847_buck3_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300411 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
412 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300413 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
414 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
415 .linear_range_selectors = bd71847_buck3_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300416 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
417 .enable_mask = BD718XX_BUCK_EN,
418 .owner = THIS_MODULE,
419 },
420 .init = {
421 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
422 .mask = BD718XX_BUCK_SEL,
423 .val = BD718XX_BUCK_SEL,
424 },
425 },
426 {
427 .desc = {
428 .name = "buck4",
429 .of_match = of_match_ptr("BUCK4"),
430 .regulators_node = of_match_ptr("regulators"),
431 .id = BD718XX_BUCK4,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300432 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300433 .type = REGULATOR_VOLTAGE,
434 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300435 .linear_ranges = bd71847_buck4_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300436 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300437 ARRAY_SIZE(bd71847_buck4_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300438 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
439 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
440 .vsel_mask = BD71847_BUCK4_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300441 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
442 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
443 .linear_range_selectors = bd71847_buck4_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300444 .enable_mask = BD718XX_BUCK_EN,
445 .owner = THIS_MODULE,
446 },
447 .init = {
448 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
449 .mask = BD718XX_BUCK_SEL,
450 .val = BD718XX_BUCK_SEL,
451 },
452 },
453 {
454 .desc = {
455 .name = "buck5",
456 .of_match = of_match_ptr("BUCK5"),
Matti Vaittinendd2be632018-09-14 11:32:26 +0300457 .regulators_node = of_match_ptr("regulators"),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300458 .id = BD718XX_BUCK5,
459 .ops = &bd718xx_buck_regulator_nolinear_ops,
460 .type = REGULATOR_VOLTAGE,
461 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
462 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
463 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
464 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
465 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
466 .enable_mask = BD718XX_BUCK_EN,
467 .owner = THIS_MODULE,
468 },
469 .init = {
470 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
471 .mask = BD718XX_BUCK_SEL,
472 .val = BD718XX_BUCK_SEL,
473 },
474 },
475 {
476 .desc = {
477 .name = "buck6",
478 .of_match = of_match_ptr("BUCK6"),
479 .regulators_node = of_match_ptr("regulators"),
480 .id = BD718XX_BUCK6,
481 .ops = &bd718xx_buck_regulator_ops,
482 .type = REGULATOR_VOLTAGE,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300483 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300484 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
485 .n_linear_ranges =
486 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
487 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
488 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
489 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
490 .enable_mask = BD718XX_BUCK_EN,
491 .owner = THIS_MODULE,
492 },
493 .init = {
494 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
495 .mask = BD718XX_BUCK_SEL,
496 .val = BD718XX_BUCK_SEL,
497 },
498 },
499 {
500 .desc = {
501 .name = "ldo1",
502 .of_match = of_match_ptr("LDO1"),
503 .regulators_node = of_match_ptr("regulators"),
504 .id = BD718XX_LDO1,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300505 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300506 .type = REGULATOR_VOLTAGE,
507 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
508 .linear_ranges = bd718xx_ldo1_volts,
509 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
510 .vsel_reg = BD718XX_REG_LDO1_VOLT,
511 .vsel_mask = BD718XX_LDO1_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300512 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
513 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
514 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300515 .enable_reg = BD718XX_REG_LDO1_VOLT,
516 .enable_mask = BD718XX_LDO_EN,
517 .owner = THIS_MODULE,
518 },
519 .init = {
520 .reg = BD718XX_REG_LDO1_VOLT,
521 .mask = BD718XX_LDO_SEL,
522 .val = BD718XX_LDO_SEL,
523 },
524 },
525 {
526 .desc = {
527 .name = "ldo2",
528 .of_match = of_match_ptr("LDO2"),
529 .regulators_node = of_match_ptr("regulators"),
530 .id = BD718XX_LDO2,
531 .ops = &bd718xx_ldo_regulator_nolinear_ops,
532 .type = REGULATOR_VOLTAGE,
533 .volt_table = &ldo_2_volts[0],
534 .vsel_reg = BD718XX_REG_LDO2_VOLT,
535 .vsel_mask = BD718XX_LDO2_MASK,
536 .n_voltages = ARRAY_SIZE(ldo_2_volts),
537 .enable_reg = BD718XX_REG_LDO2_VOLT,
538 .enable_mask = BD718XX_LDO_EN,
539 .owner = THIS_MODULE,
540 },
541 .init = {
542 .reg = BD718XX_REG_LDO2_VOLT,
543 .mask = BD718XX_LDO_SEL,
544 .val = BD718XX_LDO_SEL,
545 },
546 },
547 {
548 .desc = {
549 .name = "ldo3",
550 .of_match = of_match_ptr("LDO3"),
551 .regulators_node = of_match_ptr("regulators"),
552 .id = BD718XX_LDO3,
553 .ops = &bd718xx_ldo_regulator_ops,
554 .type = REGULATOR_VOLTAGE,
555 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
556 .linear_ranges = bd718xx_ldo3_volts,
557 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
558 .vsel_reg = BD718XX_REG_LDO3_VOLT,
559 .vsel_mask = BD718XX_LDO3_MASK,
560 .enable_reg = BD718XX_REG_LDO3_VOLT,
561 .enable_mask = BD718XX_LDO_EN,
562 .owner = THIS_MODULE,
563 },
564 .init = {
565 .reg = BD718XX_REG_LDO3_VOLT,
566 .mask = BD718XX_LDO_SEL,
567 .val = BD718XX_LDO_SEL,
568 },
569 },
570 {
571 .desc = {
572 .name = "ldo4",
573 .of_match = of_match_ptr("LDO4"),
574 .regulators_node = of_match_ptr("regulators"),
575 .id = BD718XX_LDO4,
576 .ops = &bd718xx_ldo_regulator_ops,
577 .type = REGULATOR_VOLTAGE,
578 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
579 .linear_ranges = bd718xx_ldo4_volts,
580 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
581 .vsel_reg = BD718XX_REG_LDO4_VOLT,
582 .vsel_mask = BD718XX_LDO4_MASK,
583 .enable_reg = BD718XX_REG_LDO4_VOLT,
584 .enable_mask = BD718XX_LDO_EN,
585 .owner = THIS_MODULE,
586 },
587 .init = {
588 .reg = BD718XX_REG_LDO4_VOLT,
589 .mask = BD718XX_LDO_SEL,
590 .val = BD718XX_LDO_SEL,
591 },
592 },
593 {
594 .desc = {
595 .name = "ldo5",
596 .of_match = of_match_ptr("LDO5"),
597 .regulators_node = of_match_ptr("regulators"),
598 .id = BD718XX_LDO5,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300599 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300600 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300601 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
602 .linear_ranges = bd71847_ldo5_volts,
603 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300604 .vsel_reg = BD718XX_REG_LDO5_VOLT,
605 .vsel_mask = BD71847_LDO5_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300606 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
607 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
608 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300609 .enable_reg = BD718XX_REG_LDO5_VOLT,
610 .enable_mask = BD718XX_LDO_EN,
611 .owner = THIS_MODULE,
612 },
613 .init = {
614 .reg = BD718XX_REG_LDO5_VOLT,
615 .mask = BD718XX_LDO_SEL,
616 .val = BD718XX_LDO_SEL,
617 },
618 },
619 {
620 .desc = {
621 .name = "ldo6",
622 .of_match = of_match_ptr("LDO6"),
623 .regulators_node = of_match_ptr("regulators"),
624 .id = BD718XX_LDO6,
625 .ops = &bd718xx_ldo_regulator_ops,
626 .type = REGULATOR_VOLTAGE,
627 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
628 .linear_ranges = bd718xx_ldo6_volts,
629 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
630 /* LDO6 is supplied by buck5 */
631 .supply_name = "buck5",
632 .vsel_reg = BD718XX_REG_LDO6_VOLT,
633 .vsel_mask = BD718XX_LDO6_MASK,
634 .enable_reg = BD718XX_REG_LDO6_VOLT,
635 .enable_mask = BD718XX_LDO_EN,
636 .owner = THIS_MODULE,
637 },
638 .init = {
639 .reg = BD718XX_REG_LDO6_VOLT,
640 .mask = BD718XX_LDO_SEL,
641 .val = BD718XX_LDO_SEL,
642 },
643 },
644};
645
646static const struct bd718xx_regulator_data bd71837_regulators[] = {
647 {
648 .desc = {
649 .name = "buck1",
650 .of_match = of_match_ptr("BUCK1"),
651 .regulators_node = of_match_ptr("regulators"),
652 .id = BD718XX_BUCK1,
653 .ops = &bd718xx_dvs_buck_regulator_ops,
654 .type = REGULATOR_VOLTAGE,
655 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
656 .linear_ranges = bd718xx_dvs_buck_volts,
657 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
658 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
659 .vsel_mask = DVS_BUCK_RUN_MASK,
660 .enable_reg = BD718XX_REG_BUCK1_CTRL,
661 .enable_mask = BD718XX_BUCK_EN,
662 .owner = THIS_MODULE,
663 },
664 .init = {
665 .reg = BD718XX_REG_BUCK1_CTRL,
666 .mask = BD718XX_BUCK_SEL,
667 .val = BD718XX_BUCK_SEL,
668 },
669 },
670 {
671 .desc = {
672 .name = "buck2",
673 .of_match = of_match_ptr("BUCK2"),
674 .regulators_node = of_match_ptr("regulators"),
675 .id = BD718XX_BUCK2,
676 .ops = &bd718xx_dvs_buck_regulator_ops,
677 .type = REGULATOR_VOLTAGE,
678 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
679 .linear_ranges = bd718xx_dvs_buck_volts,
680 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
681 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
682 .vsel_mask = DVS_BUCK_RUN_MASK,
683 .enable_reg = BD718XX_REG_BUCK2_CTRL,
684 .enable_mask = BD718XX_BUCK_EN,
685 .owner = THIS_MODULE,
686 },
687 .init = {
688 .reg = BD718XX_REG_BUCK2_CTRL,
689 .mask = BD718XX_BUCK_SEL,
690 .val = BD718XX_BUCK_SEL,
691 },
692 },
693 {
694 .desc = {
695 .name = "buck3",
696 .of_match = of_match_ptr("BUCK3"),
697 .regulators_node = of_match_ptr("regulators"),
698 .id = BD718XX_BUCK3,
699 .ops = &bd718xx_dvs_buck_regulator_ops,
700 .type = REGULATOR_VOLTAGE,
701 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
702 .linear_ranges = bd718xx_dvs_buck_volts,
703 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
704 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
705 .vsel_mask = DVS_BUCK_RUN_MASK,
706 .enable_reg = BD71837_REG_BUCK3_CTRL,
707 .enable_mask = BD718XX_BUCK_EN,
708 .owner = THIS_MODULE,
709 },
710 .init = {
711 .reg = BD71837_REG_BUCK3_CTRL,
712 .mask = BD718XX_BUCK_SEL,
713 .val = BD718XX_BUCK_SEL,
714 },
715 },
716 {
717 .desc = {
718 .name = "buck4",
719 .of_match = of_match_ptr("BUCK4"),
720 .regulators_node = of_match_ptr("regulators"),
721 .id = BD718XX_BUCK4,
722 .ops = &bd718xx_dvs_buck_regulator_ops,
723 .type = REGULATOR_VOLTAGE,
724 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
725 .linear_ranges = bd718xx_dvs_buck_volts,
726 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
727 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
728 .vsel_mask = DVS_BUCK_RUN_MASK,
729 .enable_reg = BD71837_REG_BUCK4_CTRL,
730 .enable_mask = BD718XX_BUCK_EN,
731 .owner = THIS_MODULE,
732 },
733 .init = {
734 .reg = BD71837_REG_BUCK4_CTRL,
735 .mask = BD718XX_BUCK_SEL,
736 .val = BD718XX_BUCK_SEL,
737 },
738 },
739 {
740 .desc = {
741 .name = "buck5",
742 .of_match = of_match_ptr("BUCK5"),
743 .regulators_node = of_match_ptr("regulators"),
744 .id = BD718XX_BUCK5,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300745 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300746 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300747 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
748 .linear_ranges = bd71837_buck5_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300749 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300750 ARRAY_SIZE(bd71837_buck5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300751 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300752 .vsel_mask = BD71837_BUCK5_MASK,
753 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
754 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
755 .linear_range_selectors = bd71837_buck5_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300756 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
757 .enable_mask = BD718XX_BUCK_EN,
758 .owner = THIS_MODULE,
759 },
760 .init = {
761 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
762 .mask = BD718XX_BUCK_SEL,
763 .val = BD718XX_BUCK_SEL,
764 },
765 },
766 {
767 .desc = {
768 .name = "buck6",
769 .of_match = of_match_ptr("BUCK6"),
770 .regulators_node = of_match_ptr("regulators"),
771 .id = BD718XX_BUCK6,
772 .ops = &bd718xx_buck_regulator_ops,
773 .type = REGULATOR_VOLTAGE,
774 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300775 .linear_ranges = bd71837_buck6_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300776 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300777 ARRAY_SIZE(bd71837_buck6_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300778 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
779 .vsel_mask = BD71837_BUCK6_MASK,
780 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
781 .enable_mask = BD718XX_BUCK_EN,
782 .owner = THIS_MODULE,
783 },
784 .init = {
785 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
786 .mask = BD718XX_BUCK_SEL,
787 .val = BD718XX_BUCK_SEL,
788 },
789 },
790 {
791 .desc = {
792 .name = "buck7",
793 .of_match = of_match_ptr("BUCK7"),
794 .regulators_node = of_match_ptr("regulators"),
795 .id = BD718XX_BUCK7,
796 .ops = &bd718xx_buck_regulator_nolinear_ops,
797 .type = REGULATOR_VOLTAGE,
798 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
799 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
800 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
801 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
802 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
803 .enable_mask = BD718XX_BUCK_EN,
804 .owner = THIS_MODULE,
805 },
806 .init = {
807 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
808 .mask = BD718XX_BUCK_SEL,
809 .val = BD718XX_BUCK_SEL,
810 },
811 },
812 {
813 .desc = {
814 .name = "buck8",
815 .of_match = of_match_ptr("BUCK8"),
816 .regulators_node = of_match_ptr("regulators"),
817 .id = BD718XX_BUCK8,
818 .ops = &bd718xx_buck_regulator_ops,
819 .type = REGULATOR_VOLTAGE,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300820 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300821 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
822 .n_linear_ranges =
823 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
824 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
825 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
826 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
827 .enable_mask = BD718XX_BUCK_EN,
828 .owner = THIS_MODULE,
829 },
830 .init = {
831 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
832 .mask = BD718XX_BUCK_SEL,
833 .val = BD718XX_BUCK_SEL,
834 },
835 },
836 {
837 .desc = {
838 .name = "ldo1",
839 .of_match = of_match_ptr("LDO1"),
840 .regulators_node = of_match_ptr("regulators"),
841 .id = BD718XX_LDO1,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300842 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300843 .type = REGULATOR_VOLTAGE,
844 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
845 .linear_ranges = bd718xx_ldo1_volts,
846 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
847 .vsel_reg = BD718XX_REG_LDO1_VOLT,
848 .vsel_mask = BD718XX_LDO1_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300849 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
850 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
851 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300852 .enable_reg = BD718XX_REG_LDO1_VOLT,
853 .enable_mask = BD718XX_LDO_EN,
854 .owner = THIS_MODULE,
855 },
856 .init = {
857 .reg = BD718XX_REG_LDO1_VOLT,
858 .mask = BD718XX_LDO_SEL,
859 .val = BD718XX_LDO_SEL,
860 },
861 },
862 {
863 .desc = {
864 .name = "ldo2",
865 .of_match = of_match_ptr("LDO2"),
866 .regulators_node = of_match_ptr("regulators"),
867 .id = BD718XX_LDO2,
868 .ops = &bd718xx_ldo_regulator_nolinear_ops,
869 .type = REGULATOR_VOLTAGE,
870 .volt_table = &ldo_2_volts[0],
871 .vsel_reg = BD718XX_REG_LDO2_VOLT,
872 .vsel_mask = BD718XX_LDO2_MASK,
873 .n_voltages = ARRAY_SIZE(ldo_2_volts),
874 .enable_reg = BD718XX_REG_LDO2_VOLT,
875 .enable_mask = BD718XX_LDO_EN,
876 .owner = THIS_MODULE,
877 },
878 .init = {
879 .reg = BD718XX_REG_LDO2_VOLT,
880 .mask = BD718XX_LDO_SEL,
881 .val = BD718XX_LDO_SEL,
882 },
883 },
884 {
885 .desc = {
886 .name = "ldo3",
887 .of_match = of_match_ptr("LDO3"),
888 .regulators_node = of_match_ptr("regulators"),
889 .id = BD718XX_LDO3,
890 .ops = &bd718xx_ldo_regulator_ops,
891 .type = REGULATOR_VOLTAGE,
892 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
893 .linear_ranges = bd718xx_ldo3_volts,
894 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
895 .vsel_reg = BD718XX_REG_LDO3_VOLT,
896 .vsel_mask = BD718XX_LDO3_MASK,
897 .enable_reg = BD718XX_REG_LDO3_VOLT,
898 .enable_mask = BD718XX_LDO_EN,
899 .owner = THIS_MODULE,
900 },
901 .init = {
902 .reg = BD718XX_REG_LDO3_VOLT,
903 .mask = BD718XX_LDO_SEL,
904 .val = BD718XX_LDO_SEL,
905 },
906 },
907 {
908 .desc = {
909 .name = "ldo4",
910 .of_match = of_match_ptr("LDO4"),
911 .regulators_node = of_match_ptr("regulators"),
912 .id = BD718XX_LDO4,
913 .ops = &bd718xx_ldo_regulator_ops,
914 .type = REGULATOR_VOLTAGE,
915 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
916 .linear_ranges = bd718xx_ldo4_volts,
917 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
918 .vsel_reg = BD718XX_REG_LDO4_VOLT,
919 .vsel_mask = BD718XX_LDO4_MASK,
920 .enable_reg = BD718XX_REG_LDO4_VOLT,
921 .enable_mask = BD718XX_LDO_EN,
922 .owner = THIS_MODULE,
923 },
924 .init = {
925 .reg = BD718XX_REG_LDO4_VOLT,
926 .mask = BD718XX_LDO_SEL,
927 .val = BD718XX_LDO_SEL,
928 },
929 },
930 {
931 .desc = {
932 .name = "ldo5",
933 .of_match = of_match_ptr("LDO5"),
934 .regulators_node = of_match_ptr("regulators"),
935 .id = BD718XX_LDO5,
936 .ops = &bd718xx_ldo_regulator_ops,
937 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300938 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
939 .linear_ranges = bd71837_ldo5_volts,
940 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300941 /* LDO5 is supplied by buck6 */
942 .supply_name = "buck6",
943 .vsel_reg = BD718XX_REG_LDO5_VOLT,
944 .vsel_mask = BD71837_LDO5_MASK,
945 .enable_reg = BD718XX_REG_LDO5_VOLT,
946 .enable_mask = BD718XX_LDO_EN,
947 .owner = THIS_MODULE,
948 },
949 .init = {
950 .reg = BD718XX_REG_LDO5_VOLT,
951 .mask = BD718XX_LDO_SEL,
952 .val = BD718XX_LDO_SEL,
953 },
954 .additional_inits = bd71837_ldo5_inits,
955 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
956 },
957 {
958 .desc = {
959 .name = "ldo6",
960 .of_match = of_match_ptr("LDO6"),
961 .regulators_node = of_match_ptr("regulators"),
962 .id = BD718XX_LDO6,
963 .ops = &bd718xx_ldo_regulator_ops,
964 .type = REGULATOR_VOLTAGE,
965 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
966 .linear_ranges = bd718xx_ldo6_volts,
967 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
968 /* LDO6 is supplied by buck7 */
969 .supply_name = "buck7",
970 .vsel_reg = BD718XX_REG_LDO6_VOLT,
971 .vsel_mask = BD718XX_LDO6_MASK,
972 .enable_reg = BD718XX_REG_LDO6_VOLT,
973 .enable_mask = BD718XX_LDO_EN,
974 .owner = THIS_MODULE,
975 },
976 .init = {
977 .reg = BD718XX_REG_LDO6_VOLT,
978 .mask = BD718XX_LDO_SEL,
979 .val = BD718XX_LDO_SEL,
980 },
981 .additional_inits = bd71837_ldo6_inits,
982 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
983 },
984 {
985 .desc = {
986 .name = "ldo7",
987 .of_match = of_match_ptr("LDO7"),
988 .regulators_node = of_match_ptr("regulators"),
989 .id = BD718XX_LDO7,
990 .ops = &bd718xx_ldo_regulator_ops,
991 .type = REGULATOR_VOLTAGE,
992 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
993 .linear_ranges = bd71837_ldo7_volts,
994 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
995 .vsel_reg = BD71837_REG_LDO7_VOLT,
996 .vsel_mask = BD71837_LDO7_MASK,
997 .enable_reg = BD71837_REG_LDO7_VOLT,
998 .enable_mask = BD718XX_LDO_EN,
999 .owner = THIS_MODULE,
1000 },
1001 .init = {
1002 .reg = BD71837_REG_LDO7_VOLT,
1003 .mask = BD718XX_LDO_SEL,
1004 .val = BD718XX_LDO_SEL,
1005 },
1006 },
1007};
1008
1009struct bd718xx_pmic_inits {
1010 const struct bd718xx_regulator_data (*r_datas)[];
1011 unsigned int r_amount;
Matti Vaittinenba087992018-05-30 11:43:43 +03001012};
1013
Matti Vaittinendd2be632018-09-14 11:32:26 +03001014static int bd718xx_probe(struct platform_device *pdev)
Matti Vaittinenba087992018-05-30 11:43:43 +03001015{
Axel Linbcb047e2018-10-04 15:25:58 +08001016 struct bd718xx *mfd;
Matti Vaittinenba087992018-05-30 11:43:43 +03001017 struct regulator_config config = { 0 };
Matti Vaittinen494edd22018-09-14 11:27:46 +03001018 struct bd718xx_pmic_inits pmic_regulators[] = {
1019 [BD718XX_TYPE_BD71837] = {
1020 .r_datas = &bd71837_regulators,
1021 .r_amount = ARRAY_SIZE(bd71837_regulators),
1022 },
1023 [BD718XX_TYPE_BD71847] = {
1024 .r_datas = &bd71847_regulators,
1025 .r_amount = ARRAY_SIZE(bd71847_regulators),
1026 },
Matti Vaittinenba087992018-05-30 11:43:43 +03001027 };
1028
Matti Vaittinen494edd22018-09-14 11:27:46 +03001029 int i, j, err;
Matti Vaittinenba087992018-05-30 11:43:43 +03001030
Axel Linbcb047e2018-10-04 15:25:58 +08001031 mfd = dev_get_drvdata(pdev->dev.parent);
1032 if (!mfd) {
Matti Vaittinenba087992018-05-30 11:43:43 +03001033 dev_err(&pdev->dev, "No MFD driver data\n");
1034 err = -EINVAL;
1035 goto err;
1036 }
Axel Linbcb047e2018-10-04 15:25:58 +08001037
1038 if (mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
1039 !pmic_regulators[mfd->chip_type].r_datas) {
Matti Vaittinen494edd22018-09-14 11:27:46 +03001040 dev_err(&pdev->dev, "Unsupported chip type\n");
1041 err = -EINVAL;
1042 goto err;
1043 }
1044
Matti Vaittinenba087992018-05-30 11:43:43 +03001045 /* Register LOCK release */
Axel Linbcb047e2018-10-04 15:25:58 +08001046 err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK,
Matti Vaittinenba087992018-05-30 11:43:43 +03001047 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1048 if (err) {
Axel Linbcb047e2018-10-04 15:25:58 +08001049 dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err);
Matti Vaittinenba087992018-05-30 11:43:43 +03001050 goto err;
1051 } else {
Axel Linbcb047e2018-10-04 15:25:58 +08001052 dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n",
Matti Vaittinen494edd22018-09-14 11:27:46 +03001053 BD718XX_REG_REGLOCK);
Matti Vaittinenba087992018-05-30 11:43:43 +03001054 }
1055
Axel Linbcb047e2018-10-04 15:25:58 +08001056 for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) {
Matti Vaittinen823f18f2018-08-29 15:36:10 +03001057
Matti Vaittinen494edd22018-09-14 11:27:46 +03001058 const struct regulator_desc *desc;
Matti Vaittinenba087992018-05-30 11:43:43 +03001059 struct regulator_dev *rdev;
Matti Vaittinen494edd22018-09-14 11:27:46 +03001060 const struct bd718xx_regulator_data *r;
Matti Vaittinenba087992018-05-30 11:43:43 +03001061
Axel Linbcb047e2018-10-04 15:25:58 +08001062 r = &(*pmic_regulators[mfd->chip_type].r_datas)[i];
Matti Vaittinen494edd22018-09-14 11:27:46 +03001063 desc = &r->desc;
Matti Vaittinenba087992018-05-30 11:43:43 +03001064
Matti Vaittinenba087992018-05-30 11:43:43 +03001065 config.dev = pdev->dev.parent;
Axel Linbcb047e2018-10-04 15:25:58 +08001066 config.regmap = mfd->regmap;
Matti Vaittinenba087992018-05-30 11:43:43 +03001067
1068 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1069 if (IS_ERR(rdev)) {
Axel Linbcb047e2018-10-04 15:25:58 +08001070 dev_err(&pdev->dev,
Matti Vaittinenba087992018-05-30 11:43:43 +03001071 "failed to register %s regulator\n",
1072 desc->name);
1073 err = PTR_ERR(rdev);
1074 goto err;
1075 }
1076 /* Regulator register gets the regulator constraints and
1077 * applies them (set_machine_constraints). This should have
1078 * turned the control register(s) to correct values and we
1079 * can now switch the control from PMIC state machine to the
1080 * register interface
1081 */
Axel Linbcb047e2018-10-04 15:25:58 +08001082 err = regmap_update_bits(mfd->regmap, r->init.reg,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001083 r->init.mask, r->init.val);
Matti Vaittinenba087992018-05-30 11:43:43 +03001084 if (err) {
Axel Linbcb047e2018-10-04 15:25:58 +08001085 dev_err(&pdev->dev,
Matti Vaittinenba087992018-05-30 11:43:43 +03001086 "Failed to write BUCK/LDO SEL bit for (%s)\n",
1087 desc->name);
1088 goto err;
1089 }
Matti Vaittinen494edd22018-09-14 11:27:46 +03001090 for (j = 0; j < r->additional_init_amnt; j++) {
Axel Linbcb047e2018-10-04 15:25:58 +08001091 err = regmap_update_bits(mfd->regmap,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001092 r->additional_inits[j].reg,
1093 r->additional_inits[j].mask,
1094 r->additional_inits[j].val);
1095 if (err) {
Axel Linbcb047e2018-10-04 15:25:58 +08001096 dev_err(&pdev->dev,
Matti Vaittinen494edd22018-09-14 11:27:46 +03001097 "Buck (%s) initialization failed\n",
1098 desc->name);
1099 goto err;
1100 }
1101 }
Matti Vaittinenba087992018-05-30 11:43:43 +03001102 }
1103
Matti Vaittinenba087992018-05-30 11:43:43 +03001104err:
1105 return err;
1106}
1107
Matti Vaittinendd2be632018-09-14 11:32:26 +03001108static struct platform_driver bd718xx_regulator = {
Matti Vaittinenba087992018-05-30 11:43:43 +03001109 .driver = {
Matti Vaittinen494edd22018-09-14 11:27:46 +03001110 .name = "bd718xx-pmic",
Matti Vaittinenba087992018-05-30 11:43:43 +03001111 },
Matti Vaittinendd2be632018-09-14 11:32:26 +03001112 .probe = bd718xx_probe,
Matti Vaittinenba087992018-05-30 11:43:43 +03001113};
1114
Matti Vaittinendd2be632018-09-14 11:32:26 +03001115module_platform_driver(bd718xx_regulator);
Matti Vaittinenba087992018-05-30 11:43:43 +03001116
1117MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
Matti Vaittinendd2be632018-09-14 11:32:26 +03001118MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
Matti Vaittinenba087992018-05-30 11:43:43 +03001119MODULE_LICENSE("GPL");