blob: d2522d4e1505f2ab74e4d03bb49a73c8e1c0926b [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 Vaittinen494edd22018-09-14 11:27:46 +030018struct bd718xx_pmic {
19 struct bd718xx_regulator_data *rdata;
Matti Vaittinendd2be632018-09-14 11:32:26 +030020 struct bd718xx *mfd;
Matti Vaittinenba087992018-05-30 11:43:43 +030021 struct platform_device *pdev;
Matti Vaittinen494edd22018-09-14 11:27:46 +030022 struct regulator_dev *rdev[BD718XX_REGULATOR_AMOUNT];
Matti Vaittinenba087992018-05-30 11:43:43 +030023};
24
25/*
26 * BUCK1/2/3/4
27 * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting
28 * 00: 10.00mV/usec 10mV 1uS
29 * 01: 5.00mV/usec 10mV 2uS
30 * 10: 2.50mV/usec 10mV 4uS
31 * 11: 1.25mV/usec 10mV 8uS
32 */
Matti Vaittinendd2be632018-09-14 11:32:26 +030033static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev,
Matti Vaittinenba087992018-05-30 11:43:43 +030034 int ramp_delay)
35{
Matti Vaittinen494edd22018-09-14 11:27:46 +030036 struct bd718xx_pmic *pmic = rdev_get_drvdata(rdev);
Matti Vaittinendd2be632018-09-14 11:32:26 +030037 struct bd718xx *mfd = pmic->mfd;
Matti Vaittinenba087992018-05-30 11:43:43 +030038 int id = rdev->desc->id;
39 unsigned int ramp_value = BUCK_RAMPRATE_10P00MV;
40
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +030041 dev_dbg(&pmic->pdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1,
Matti Vaittinenba087992018-05-30 11:43:43 +030042 ramp_delay);
43 switch (ramp_delay) {
44 case 1 ... 1250:
45 ramp_value = BUCK_RAMPRATE_1P25MV;
46 break;
47 case 1251 ... 2500:
48 ramp_value = BUCK_RAMPRATE_2P50MV;
49 break;
50 case 2501 ... 5000:
51 ramp_value = BUCK_RAMPRATE_5P00MV;
52 break;
53 case 5001 ... 10000:
54 ramp_value = BUCK_RAMPRATE_10P00MV;
55 break;
56 default:
57 ramp_value = BUCK_RAMPRATE_10P00MV;
58 dev_err(&pmic->pdev->dev,
59 "%s: ramp_delay: %d not supported, setting 10000mV//us\n",
60 rdev->desc->name, ramp_delay);
61 }
62
Matti Vaittinen494edd22018-09-14 11:27:46 +030063 return regmap_update_bits(mfd->regmap, BD718XX_REG_BUCK1_CTRL + id,
Matti Vaittinenba087992018-05-30 11:43:43 +030064 BUCK_RAMPRATE_MASK, ramp_value << 6);
65}
66
67/* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed.
68 * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage
69 * is changed. Hence we return -EBUSY for these if voltage is changed
70 * when BUCK/LDO is enabled.
71 */
Matti Vaittinen494edd22018-09-14 11:27:46 +030072static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev,
Matti Vaittinenba087992018-05-30 11:43:43 +030073 unsigned int sel)
74{
Axel Linffdc4982018-06-27 20:40:14 +080075 if (regulator_is_enabled_regmap(rdev))
76 return -EBUSY;
Matti Vaittinenba087992018-05-30 11:43:43 +030077
Axel Linffdc4982018-06-27 20:40:14 +080078 return regulator_set_voltage_sel_regmap(rdev, sel);
Matti Vaittinenba087992018-05-30 11:43:43 +030079}
80
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +030081static int bd718xx_set_voltage_sel_pickable_restricted(
82 struct regulator_dev *rdev, unsigned int sel)
83{
84 if (regulator_is_enabled_regmap(rdev))
85 return -EBUSY;
86
87 return regulator_set_voltage_sel_pickable_regmap(rdev, sel);
88}
89
90static struct regulator_ops bd718xx_pickable_range_ldo_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};
98
99static struct regulator_ops bd718xx_pickable_range_buck_ops = {
100 .enable = regulator_enable_regmap,
101 .disable = regulator_disable_regmap,
102 .is_enabled = regulator_is_enabled_regmap,
103 .list_voltage = regulator_list_voltage_pickable_linear_range,
104 .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted,
105 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
106 .set_voltage_time_sel = regulator_set_voltage_time_sel,
107};
108
Matti Vaittinen494edd22018-09-14 11:27:46 +0300109static struct regulator_ops bd718xx_ldo_regulator_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_linear_range,
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_ldo_regulator_nolinear_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_table,
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};
126
Matti Vaittinen494edd22018-09-14 11:27:46 +0300127static struct regulator_ops bd718xx_buck_regulator_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300128 .enable = regulator_enable_regmap,
129 .disable = regulator_disable_regmap,
130 .is_enabled = regulator_is_enabled_regmap,
131 .list_voltage = regulator_list_voltage_linear_range,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300132 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
Matti Vaittinenba087992018-05-30 11:43:43 +0300133 .get_voltage_sel = regulator_get_voltage_sel_regmap,
134 .set_voltage_time_sel = regulator_set_voltage_time_sel,
135};
136
Matti Vaittinen494edd22018-09-14 11:27:46 +0300137static struct regulator_ops bd718xx_buck_regulator_nolinear_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300138 .enable = regulator_enable_regmap,
139 .disable = regulator_disable_regmap,
140 .is_enabled = regulator_is_enabled_regmap,
141 .list_voltage = regulator_list_voltage_table,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300142 .set_voltage_sel = bd718xx_set_voltage_sel_restricted,
Matti Vaittinenba087992018-05-30 11:43:43 +0300143 .get_voltage_sel = regulator_get_voltage_sel_regmap,
144 .set_voltage_time_sel = regulator_set_voltage_time_sel,
145};
146
Matti Vaittinen494edd22018-09-14 11:27:46 +0300147static struct regulator_ops bd718xx_dvs_buck_regulator_ops = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300148 .enable = regulator_enable_regmap,
149 .disable = regulator_disable_regmap,
150 .is_enabled = regulator_is_enabled_regmap,
151 .list_voltage = regulator_list_voltage_linear_range,
152 .set_voltage_sel = regulator_set_voltage_sel_regmap,
153 .get_voltage_sel = regulator_get_voltage_sel_regmap,
154 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300155 .set_ramp_delay = bd718xx_buck1234_set_ramp_delay,
Matti Vaittinenba087992018-05-30 11:43:43 +0300156};
157
158/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300159 * BD71837 BUCK1/2/3/4
160 * BD71847 BUCK1/2
Matti Vaittinenba087992018-05-30 11:43:43 +0300161 * 0.70 to 1.30V (10mV step)
162 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300163static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300164 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000),
165 REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0),
166};
167
168/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300169 * BD71837 BUCK5
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300170 * 0.7V to 1.35V (range 0)
171 * and
172 * 0.675 to 1.325 (range 1)
Matti Vaittinenba087992018-05-30 11:43:43 +0300173 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300174static const struct regulator_linear_range bd71837_buck5_volts[] = {
175 /* Ranges when VOLT_SEL bit is 0 */
Matti Vaittinenba087992018-05-30 11:43:43 +0300176 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
177 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
178 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300179 /* Ranges when VOLT_SEL bit is 1 */
180 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
181 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
182 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300183};
184
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300185/*
186 * Range selector for first 3 linear ranges is 0x0
187 * and 0x1 for last 3 ranges.
188 */
189static const unsigned int bd71837_buck5_volt_range_sel[] = {
190 0x0, 0x0, 0x0, 0x80, 0x80, 0x80
Matti Vaittinen494edd22018-09-14 11:27:46 +0300191};
192
Matti Vaittinenba087992018-05-30 11:43:43 +0300193/*
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300194 * BD71847 BUCK3
195 */
196static const struct regulator_linear_range bd71847_buck3_volts[] = {
197 /* Ranges when VOLT_SEL bits are 00 */
198 REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000),
199 REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000),
200 REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000),
201 /* Ranges when VOLT_SEL bits are 01 */
202 REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000),
203 /* Ranges when VOLT_SEL bits are 11 */
204 REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000),
205 REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000),
206 REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000),
207};
208
209static const unsigned int bd71847_buck3_volt_range_sel[] = {
210 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80
211};
212
213static const struct regulator_linear_range bd71847_buck4_volts[] = {
214 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
215 REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000),
216};
217
218static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 };
219
220/*
Matti Vaittinenba087992018-05-30 11:43:43 +0300221 * BUCK6
222 * 3.0V to 3.3V (step 100mV)
223 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300224static const struct regulator_linear_range bd71837_buck6_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300225 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
226};
227
228/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300229 * BD71837 BUCK7
230 * BD71847 BUCK5
Matti Vaittinenba087992018-05-30 11:43:43 +0300231 * 000 = 1.605V
232 * 001 = 1.695V
233 * 010 = 1.755V
234 * 011 = 1.8V (Initial)
235 * 100 = 1.845V
236 * 101 = 1.905V
237 * 110 = 1.95V
238 * 111 = 1.995V
239 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300240static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300241 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000
242};
243
244/*
245 * BUCK8
246 * 0.8V to 1.40V (step 10mV)
247 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300248static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300249 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300250};
251
252/*
253 * LDO1
254 * 3.0 to 3.3V (100mV step)
255 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300256static const struct regulator_linear_range bd718xx_ldo1_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300257 REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000),
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300258 REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300259};
260
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300261static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 };
262
Matti Vaittinenba087992018-05-30 11:43:43 +0300263/*
264 * LDO2
265 * 0.8 or 0.9V
266 */
Axel Linadb78a82018-06-27 20:40:13 +0800267static const unsigned int ldo_2_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300268 900000, 800000
269};
270
271/*
272 * LDO3
273 * 1.8 to 3.3V (100mV step)
274 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300275static const struct regulator_linear_range bd718xx_ldo3_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300276 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
277};
278
279/*
280 * LDO4
281 * 0.9 to 1.8V (100mV step)
282 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300283static const struct regulator_linear_range bd718xx_ldo4_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300284 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300285};
286
287/*
Matti Vaittinen494edd22018-09-14 11:27:46 +0300288 * LDO5 for BD71837
Matti Vaittinenba087992018-05-30 11:43:43 +0300289 * 1.8 to 3.3V (100mV step)
290 */
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300291static const struct regulator_linear_range bd71837_ldo5_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300292 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
293};
294
295/*
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300296 * LDO5 for BD71837
297 * 1.8 to 3.3V (100mV step)
298 */
299static const struct regulator_linear_range bd71847_ldo5_volts[] = {
300 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
301 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000),
302};
303
304static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 };
305
306/*
Matti Vaittinenba087992018-05-30 11:43:43 +0300307 * LDO6
308 * 0.9 to 1.8V (100mV step)
309 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300310static const struct regulator_linear_range bd718xx_ldo6_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300311 REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000),
Matti Vaittinenba087992018-05-30 11:43:43 +0300312};
313
314/*
315 * LDO7
316 * 1.8 to 3.3V (100mV step)
317 */
Matti Vaittinen494edd22018-09-14 11:27:46 +0300318static const struct regulator_linear_range bd71837_ldo7_volts[] = {
Matti Vaittinenba087992018-05-30 11:43:43 +0300319 REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000),
320};
321
Matti Vaittinenba087992018-05-30 11:43:43 +0300322struct reg_init {
323 unsigned int reg;
324 unsigned int mask;
Matti Vaittinen494edd22018-09-14 11:27:46 +0300325 unsigned int val;
326};
327struct bd718xx_regulator_data {
328 struct regulator_desc desc;
329 const struct reg_init init;
330 const struct reg_init *additional_inits;
331 int additional_init_amnt;
332};
333
334/*
335 * There is a HW quirk in BD71837. The shutdown sequence timings for
336 * bucks/LDOs which are controlled via register interface are changed.
337 * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the
338 * beginning of shut-down sequence. As bucks 6 and 7 are parent
339 * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage
340 * monitoring to errorneously detect under voltage and force PMIC to
341 * emergency state instead of poweroff. In order to avoid this we
342 * disable voltage monitoring for LDO5 and LDO6
343 */
344static const struct reg_init bd71837_ldo5_inits[] = {
345 {
346 .reg = BD718XX_REG_MVRFLTMASK2,
347 .mask = BD718XX_LDO5_VRMON80,
348 .val = BD718XX_LDO5_VRMON80,
349 },
350};
351
352static const struct reg_init bd71837_ldo6_inits[] = {
353 {
354 .reg = BD718XX_REG_MVRFLTMASK2,
355 .mask = BD718XX_LDO6_VRMON80,
356 .val = BD718XX_LDO6_VRMON80,
357 },
358};
359
360static const struct bd718xx_regulator_data bd71847_regulators[] = {
361 {
362 .desc = {
363 .name = "buck1",
364 .of_match = of_match_ptr("BUCK1"),
365 .regulators_node = of_match_ptr("regulators"),
366 .id = BD718XX_BUCK1,
367 .ops = &bd718xx_dvs_buck_regulator_ops,
368 .type = REGULATOR_VOLTAGE,
369 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
370 .linear_ranges = bd718xx_dvs_buck_volts,
371 .n_linear_ranges =
372 ARRAY_SIZE(bd718xx_dvs_buck_volts),
373 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
374 .vsel_mask = DVS_BUCK_RUN_MASK,
375 .enable_reg = BD718XX_REG_BUCK1_CTRL,
376 .enable_mask = BD718XX_BUCK_EN,
377 .owner = THIS_MODULE,
378 },
379 .init = {
380 .reg = BD718XX_REG_BUCK1_CTRL,
381 .mask = BD718XX_BUCK_SEL,
382 .val = BD718XX_BUCK_SEL,
383 },
384 },
385 {
386 .desc = {
387 .name = "buck2",
388 .of_match = of_match_ptr("BUCK2"),
389 .regulators_node = of_match_ptr("regulators"),
390 .id = BD718XX_BUCK2,
391 .ops = &bd718xx_dvs_buck_regulator_ops,
392 .type = REGULATOR_VOLTAGE,
393 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
394 .linear_ranges = bd718xx_dvs_buck_volts,
395 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
396 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
397 .vsel_mask = DVS_BUCK_RUN_MASK,
398 .enable_reg = BD718XX_REG_BUCK2_CTRL,
399 .enable_mask = BD718XX_BUCK_EN,
400 .owner = THIS_MODULE,
401 },
402 .init = {
403 .reg = BD718XX_REG_BUCK2_CTRL,
404 .mask = BD718XX_BUCK_SEL,
405 .val = BD718XX_BUCK_SEL,
406 },
407 },
408 {
409 .desc = {
410 .name = "buck3",
411 .of_match = of_match_ptr("BUCK3"),
412 .regulators_node = of_match_ptr("regulators"),
413 .id = BD718XX_BUCK3,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300414 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300415 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300416 .n_voltages = BD71847_BUCK3_VOLTAGE_NUM,
417 .linear_ranges = bd71847_buck3_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300418 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300419 ARRAY_SIZE(bd71847_buck3_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300420 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
421 .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300422 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
423 .vsel_range_mask = BD71847_BUCK3_RANGE_MASK,
424 .linear_range_selectors = bd71847_buck3_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300425 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
426 .enable_mask = BD718XX_BUCK_EN,
427 .owner = THIS_MODULE,
428 },
429 .init = {
430 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
431 .mask = BD718XX_BUCK_SEL,
432 .val = BD718XX_BUCK_SEL,
433 },
434 },
435 {
436 .desc = {
437 .name = "buck4",
438 .of_match = of_match_ptr("BUCK4"),
439 .regulators_node = of_match_ptr("regulators"),
440 .id = BD718XX_BUCK4,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300441 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300442 .type = REGULATOR_VOLTAGE,
443 .n_voltages = BD71847_BUCK4_VOLTAGE_NUM,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300444 .linear_ranges = bd71847_buck4_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300445 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300446 ARRAY_SIZE(bd71847_buck4_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300447 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
448 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
449 .vsel_mask = BD71847_BUCK4_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300450 .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
451 .vsel_range_mask = BD71847_BUCK4_RANGE_MASK,
452 .linear_range_selectors = bd71847_buck4_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300453 .enable_mask = BD718XX_BUCK_EN,
454 .owner = THIS_MODULE,
455 },
456 .init = {
457 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
458 .mask = BD718XX_BUCK_SEL,
459 .val = BD718XX_BUCK_SEL,
460 },
461 },
462 {
463 .desc = {
464 .name = "buck5",
465 .of_match = of_match_ptr("BUCK5"),
Matti Vaittinendd2be632018-09-14 11:32:26 +0300466 .regulators_node = of_match_ptr("regulators"),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300467 .id = BD718XX_BUCK5,
468 .ops = &bd718xx_buck_regulator_nolinear_ops,
469 .type = REGULATOR_VOLTAGE,
470 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
471 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
472 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
473 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
474 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
475 .enable_mask = BD718XX_BUCK_EN,
476 .owner = THIS_MODULE,
477 },
478 .init = {
479 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
480 .mask = BD718XX_BUCK_SEL,
481 .val = BD718XX_BUCK_SEL,
482 },
483 },
484 {
485 .desc = {
486 .name = "buck6",
487 .of_match = of_match_ptr("BUCK6"),
488 .regulators_node = of_match_ptr("regulators"),
489 .id = BD718XX_BUCK6,
490 .ops = &bd718xx_buck_regulator_ops,
491 .type = REGULATOR_VOLTAGE,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300492 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300493 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
494 .n_linear_ranges =
495 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
496 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
497 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
498 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
499 .enable_mask = BD718XX_BUCK_EN,
500 .owner = THIS_MODULE,
501 },
502 .init = {
503 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
504 .mask = BD718XX_BUCK_SEL,
505 .val = BD718XX_BUCK_SEL,
506 },
507 },
508 {
509 .desc = {
510 .name = "ldo1",
511 .of_match = of_match_ptr("LDO1"),
512 .regulators_node = of_match_ptr("regulators"),
513 .id = BD718XX_LDO1,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300514 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300515 .type = REGULATOR_VOLTAGE,
516 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
517 .linear_ranges = bd718xx_ldo1_volts,
518 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
519 .vsel_reg = BD718XX_REG_LDO1_VOLT,
520 .vsel_mask = BD718XX_LDO1_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300521 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
522 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
523 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300524 .enable_reg = BD718XX_REG_LDO1_VOLT,
525 .enable_mask = BD718XX_LDO_EN,
526 .owner = THIS_MODULE,
527 },
528 .init = {
529 .reg = BD718XX_REG_LDO1_VOLT,
530 .mask = BD718XX_LDO_SEL,
531 .val = BD718XX_LDO_SEL,
532 },
533 },
534 {
535 .desc = {
536 .name = "ldo2",
537 .of_match = of_match_ptr("LDO2"),
538 .regulators_node = of_match_ptr("regulators"),
539 .id = BD718XX_LDO2,
540 .ops = &bd718xx_ldo_regulator_nolinear_ops,
541 .type = REGULATOR_VOLTAGE,
542 .volt_table = &ldo_2_volts[0],
543 .vsel_reg = BD718XX_REG_LDO2_VOLT,
544 .vsel_mask = BD718XX_LDO2_MASK,
545 .n_voltages = ARRAY_SIZE(ldo_2_volts),
546 .enable_reg = BD718XX_REG_LDO2_VOLT,
547 .enable_mask = BD718XX_LDO_EN,
548 .owner = THIS_MODULE,
549 },
550 .init = {
551 .reg = BD718XX_REG_LDO2_VOLT,
552 .mask = BD718XX_LDO_SEL,
553 .val = BD718XX_LDO_SEL,
554 },
555 },
556 {
557 .desc = {
558 .name = "ldo3",
559 .of_match = of_match_ptr("LDO3"),
560 .regulators_node = of_match_ptr("regulators"),
561 .id = BD718XX_LDO3,
562 .ops = &bd718xx_ldo_regulator_ops,
563 .type = REGULATOR_VOLTAGE,
564 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
565 .linear_ranges = bd718xx_ldo3_volts,
566 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
567 .vsel_reg = BD718XX_REG_LDO3_VOLT,
568 .vsel_mask = BD718XX_LDO3_MASK,
569 .enable_reg = BD718XX_REG_LDO3_VOLT,
570 .enable_mask = BD718XX_LDO_EN,
571 .owner = THIS_MODULE,
572 },
573 .init = {
574 .reg = BD718XX_REG_LDO3_VOLT,
575 .mask = BD718XX_LDO_SEL,
576 .val = BD718XX_LDO_SEL,
577 },
578 },
579 {
580 .desc = {
581 .name = "ldo4",
582 .of_match = of_match_ptr("LDO4"),
583 .regulators_node = of_match_ptr("regulators"),
584 .id = BD718XX_LDO4,
585 .ops = &bd718xx_ldo_regulator_ops,
586 .type = REGULATOR_VOLTAGE,
587 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
588 .linear_ranges = bd718xx_ldo4_volts,
589 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
590 .vsel_reg = BD718XX_REG_LDO4_VOLT,
591 .vsel_mask = BD718XX_LDO4_MASK,
592 .enable_reg = BD718XX_REG_LDO4_VOLT,
593 .enable_mask = BD718XX_LDO_EN,
594 .owner = THIS_MODULE,
595 },
596 .init = {
597 .reg = BD718XX_REG_LDO4_VOLT,
598 .mask = BD718XX_LDO_SEL,
599 .val = BD718XX_LDO_SEL,
600 },
601 },
602 {
603 .desc = {
604 .name = "ldo5",
605 .of_match = of_match_ptr("LDO5"),
606 .regulators_node = of_match_ptr("regulators"),
607 .id = BD718XX_LDO5,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300608 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300609 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300610 .n_voltages = BD71847_LDO5_VOLTAGE_NUM,
611 .linear_ranges = bd71847_ldo5_volts,
612 .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300613 .vsel_reg = BD718XX_REG_LDO5_VOLT,
614 .vsel_mask = BD71847_LDO5_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300615 .vsel_range_reg = BD718XX_REG_LDO5_VOLT,
616 .vsel_range_mask = BD71847_LDO5_RANGE_MASK,
617 .linear_range_selectors = bd71847_ldo5_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300618 .enable_reg = BD718XX_REG_LDO5_VOLT,
619 .enable_mask = BD718XX_LDO_EN,
620 .owner = THIS_MODULE,
621 },
622 .init = {
623 .reg = BD718XX_REG_LDO5_VOLT,
624 .mask = BD718XX_LDO_SEL,
625 .val = BD718XX_LDO_SEL,
626 },
627 },
628 {
629 .desc = {
630 .name = "ldo6",
631 .of_match = of_match_ptr("LDO6"),
632 .regulators_node = of_match_ptr("regulators"),
633 .id = BD718XX_LDO6,
634 .ops = &bd718xx_ldo_regulator_ops,
635 .type = REGULATOR_VOLTAGE,
636 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
637 .linear_ranges = bd718xx_ldo6_volts,
638 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
639 /* LDO6 is supplied by buck5 */
640 .supply_name = "buck5",
641 .vsel_reg = BD718XX_REG_LDO6_VOLT,
642 .vsel_mask = BD718XX_LDO6_MASK,
643 .enable_reg = BD718XX_REG_LDO6_VOLT,
644 .enable_mask = BD718XX_LDO_EN,
645 .owner = THIS_MODULE,
646 },
647 .init = {
648 .reg = BD718XX_REG_LDO6_VOLT,
649 .mask = BD718XX_LDO_SEL,
650 .val = BD718XX_LDO_SEL,
651 },
652 },
653};
654
655static const struct bd718xx_regulator_data bd71837_regulators[] = {
656 {
657 .desc = {
658 .name = "buck1",
659 .of_match = of_match_ptr("BUCK1"),
660 .regulators_node = of_match_ptr("regulators"),
661 .id = BD718XX_BUCK1,
662 .ops = &bd718xx_dvs_buck_regulator_ops,
663 .type = REGULATOR_VOLTAGE,
664 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
665 .linear_ranges = bd718xx_dvs_buck_volts,
666 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
667 .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN,
668 .vsel_mask = DVS_BUCK_RUN_MASK,
669 .enable_reg = BD718XX_REG_BUCK1_CTRL,
670 .enable_mask = BD718XX_BUCK_EN,
671 .owner = THIS_MODULE,
672 },
673 .init = {
674 .reg = BD718XX_REG_BUCK1_CTRL,
675 .mask = BD718XX_BUCK_SEL,
676 .val = BD718XX_BUCK_SEL,
677 },
678 },
679 {
680 .desc = {
681 .name = "buck2",
682 .of_match = of_match_ptr("BUCK2"),
683 .regulators_node = of_match_ptr("regulators"),
684 .id = BD718XX_BUCK2,
685 .ops = &bd718xx_dvs_buck_regulator_ops,
686 .type = REGULATOR_VOLTAGE,
687 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
688 .linear_ranges = bd718xx_dvs_buck_volts,
689 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
690 .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN,
691 .vsel_mask = DVS_BUCK_RUN_MASK,
692 .enable_reg = BD718XX_REG_BUCK2_CTRL,
693 .enable_mask = BD718XX_BUCK_EN,
694 .owner = THIS_MODULE,
695 },
696 .init = {
697 .reg = BD718XX_REG_BUCK2_CTRL,
698 .mask = BD718XX_BUCK_SEL,
699 .val = BD718XX_BUCK_SEL,
700 },
701 },
702 {
703 .desc = {
704 .name = "buck3",
705 .of_match = of_match_ptr("BUCK3"),
706 .regulators_node = of_match_ptr("regulators"),
707 .id = BD718XX_BUCK3,
708 .ops = &bd718xx_dvs_buck_regulator_ops,
709 .type = REGULATOR_VOLTAGE,
710 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
711 .linear_ranges = bd718xx_dvs_buck_volts,
712 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
713 .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN,
714 .vsel_mask = DVS_BUCK_RUN_MASK,
715 .enable_reg = BD71837_REG_BUCK3_CTRL,
716 .enable_mask = BD718XX_BUCK_EN,
717 .owner = THIS_MODULE,
718 },
719 .init = {
720 .reg = BD71837_REG_BUCK3_CTRL,
721 .mask = BD718XX_BUCK_SEL,
722 .val = BD718XX_BUCK_SEL,
723 },
724 },
725 {
726 .desc = {
727 .name = "buck4",
728 .of_match = of_match_ptr("BUCK4"),
729 .regulators_node = of_match_ptr("regulators"),
730 .id = BD718XX_BUCK4,
731 .ops = &bd718xx_dvs_buck_regulator_ops,
732 .type = REGULATOR_VOLTAGE,
733 .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM,
734 .linear_ranges = bd718xx_dvs_buck_volts,
735 .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts),
736 .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN,
737 .vsel_mask = DVS_BUCK_RUN_MASK,
738 .enable_reg = BD71837_REG_BUCK4_CTRL,
739 .enable_mask = BD718XX_BUCK_EN,
740 .owner = THIS_MODULE,
741 },
742 .init = {
743 .reg = BD71837_REG_BUCK4_CTRL,
744 .mask = BD718XX_BUCK_SEL,
745 .val = BD718XX_BUCK_SEL,
746 },
747 },
748 {
749 .desc = {
750 .name = "buck5",
751 .of_match = of_match_ptr("BUCK5"),
752 .regulators_node = of_match_ptr("regulators"),
753 .id = BD718XX_BUCK5,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300754 .ops = &bd718xx_pickable_range_buck_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300755 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300756 .n_voltages = BD71837_BUCK5_VOLTAGE_NUM,
757 .linear_ranges = bd71837_buck5_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300758 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300759 ARRAY_SIZE(bd71837_buck5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300760 .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300761 .vsel_mask = BD71837_BUCK5_MASK,
762 .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT,
763 .vsel_range_mask = BD71837_BUCK5_RANGE_MASK,
764 .linear_range_selectors = bd71837_buck5_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300765 .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
766 .enable_mask = BD718XX_BUCK_EN,
767 .owner = THIS_MODULE,
768 },
769 .init = {
770 .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL,
771 .mask = BD718XX_BUCK_SEL,
772 .val = BD718XX_BUCK_SEL,
773 },
774 },
775 {
776 .desc = {
777 .name = "buck6",
778 .of_match = of_match_ptr("BUCK6"),
779 .regulators_node = of_match_ptr("regulators"),
780 .id = BD718XX_BUCK6,
781 .ops = &bd718xx_buck_regulator_ops,
782 .type = REGULATOR_VOLTAGE,
783 .n_voltages = BD71837_BUCK6_VOLTAGE_NUM,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300784 .linear_ranges = bd71837_buck6_volts,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300785 .n_linear_ranges =
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300786 ARRAY_SIZE(bd71837_buck6_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300787 .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT,
788 .vsel_mask = BD71837_BUCK6_MASK,
789 .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
790 .enable_mask = BD718XX_BUCK_EN,
791 .owner = THIS_MODULE,
792 },
793 .init = {
794 .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL,
795 .mask = BD718XX_BUCK_SEL,
796 .val = BD718XX_BUCK_SEL,
797 },
798 },
799 {
800 .desc = {
801 .name = "buck7",
802 .of_match = of_match_ptr("BUCK7"),
803 .regulators_node = of_match_ptr("regulators"),
804 .id = BD718XX_BUCK7,
805 .ops = &bd718xx_buck_regulator_nolinear_ops,
806 .type = REGULATOR_VOLTAGE,
807 .volt_table = &bd718xx_3rd_nodvs_buck_volts[0],
808 .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts),
809 .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT,
810 .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK,
811 .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
812 .enable_mask = BD718XX_BUCK_EN,
813 .owner = THIS_MODULE,
814 },
815 .init = {
816 .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL,
817 .mask = BD718XX_BUCK_SEL,
818 .val = BD718XX_BUCK_SEL,
819 },
820 },
821 {
822 .desc = {
823 .name = "buck8",
824 .of_match = of_match_ptr("BUCK8"),
825 .regulators_node = of_match_ptr("regulators"),
826 .id = BD718XX_BUCK8,
827 .ops = &bd718xx_buck_regulator_ops,
828 .type = REGULATOR_VOLTAGE,
Matti Vaittinendd2be632018-09-14 11:32:26 +0300829 .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300830 .linear_ranges = bd718xx_4th_nodvs_buck_volts,
831 .n_linear_ranges =
832 ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts),
833 .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT,
834 .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK,
835 .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
836 .enable_mask = BD718XX_BUCK_EN,
837 .owner = THIS_MODULE,
838 },
839 .init = {
840 .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL,
841 .mask = BD718XX_BUCK_SEL,
842 .val = BD718XX_BUCK_SEL,
843 },
844 },
845 {
846 .desc = {
847 .name = "ldo1",
848 .of_match = of_match_ptr("LDO1"),
849 .regulators_node = of_match_ptr("regulators"),
850 .id = BD718XX_LDO1,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300851 .ops = &bd718xx_pickable_range_ldo_ops,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300852 .type = REGULATOR_VOLTAGE,
853 .n_voltages = BD718XX_LDO1_VOLTAGE_NUM,
854 .linear_ranges = bd718xx_ldo1_volts,
855 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts),
856 .vsel_reg = BD718XX_REG_LDO1_VOLT,
857 .vsel_mask = BD718XX_LDO1_MASK,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300858 .vsel_range_reg = BD718XX_REG_LDO1_VOLT,
859 .vsel_range_mask = BD718XX_LDO1_RANGE_MASK,
860 .linear_range_selectors = bd718xx_ldo1_volt_range_sel,
Matti Vaittinen494edd22018-09-14 11:27:46 +0300861 .enable_reg = BD718XX_REG_LDO1_VOLT,
862 .enable_mask = BD718XX_LDO_EN,
863 .owner = THIS_MODULE,
864 },
865 .init = {
866 .reg = BD718XX_REG_LDO1_VOLT,
867 .mask = BD718XX_LDO_SEL,
868 .val = BD718XX_LDO_SEL,
869 },
870 },
871 {
872 .desc = {
873 .name = "ldo2",
874 .of_match = of_match_ptr("LDO2"),
875 .regulators_node = of_match_ptr("regulators"),
876 .id = BD718XX_LDO2,
877 .ops = &bd718xx_ldo_regulator_nolinear_ops,
878 .type = REGULATOR_VOLTAGE,
879 .volt_table = &ldo_2_volts[0],
880 .vsel_reg = BD718XX_REG_LDO2_VOLT,
881 .vsel_mask = BD718XX_LDO2_MASK,
882 .n_voltages = ARRAY_SIZE(ldo_2_volts),
883 .enable_reg = BD718XX_REG_LDO2_VOLT,
884 .enable_mask = BD718XX_LDO_EN,
885 .owner = THIS_MODULE,
886 },
887 .init = {
888 .reg = BD718XX_REG_LDO2_VOLT,
889 .mask = BD718XX_LDO_SEL,
890 .val = BD718XX_LDO_SEL,
891 },
892 },
893 {
894 .desc = {
895 .name = "ldo3",
896 .of_match = of_match_ptr("LDO3"),
897 .regulators_node = of_match_ptr("regulators"),
898 .id = BD718XX_LDO3,
899 .ops = &bd718xx_ldo_regulator_ops,
900 .type = REGULATOR_VOLTAGE,
901 .n_voltages = BD718XX_LDO3_VOLTAGE_NUM,
902 .linear_ranges = bd718xx_ldo3_volts,
903 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts),
904 .vsel_reg = BD718XX_REG_LDO3_VOLT,
905 .vsel_mask = BD718XX_LDO3_MASK,
906 .enable_reg = BD718XX_REG_LDO3_VOLT,
907 .enable_mask = BD718XX_LDO_EN,
908 .owner = THIS_MODULE,
909 },
910 .init = {
911 .reg = BD718XX_REG_LDO3_VOLT,
912 .mask = BD718XX_LDO_SEL,
913 .val = BD718XX_LDO_SEL,
914 },
915 },
916 {
917 .desc = {
918 .name = "ldo4",
919 .of_match = of_match_ptr("LDO4"),
920 .regulators_node = of_match_ptr("regulators"),
921 .id = BD718XX_LDO4,
922 .ops = &bd718xx_ldo_regulator_ops,
923 .type = REGULATOR_VOLTAGE,
924 .n_voltages = BD718XX_LDO4_VOLTAGE_NUM,
925 .linear_ranges = bd718xx_ldo4_volts,
926 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts),
927 .vsel_reg = BD718XX_REG_LDO4_VOLT,
928 .vsel_mask = BD718XX_LDO4_MASK,
929 .enable_reg = BD718XX_REG_LDO4_VOLT,
930 .enable_mask = BD718XX_LDO_EN,
931 .owner = THIS_MODULE,
932 },
933 .init = {
934 .reg = BD718XX_REG_LDO4_VOLT,
935 .mask = BD718XX_LDO_SEL,
936 .val = BD718XX_LDO_SEL,
937 },
938 },
939 {
940 .desc = {
941 .name = "ldo5",
942 .of_match = of_match_ptr("LDO5"),
943 .regulators_node = of_match_ptr("regulators"),
944 .id = BD718XX_LDO5,
945 .ops = &bd718xx_ldo_regulator_ops,
946 .type = REGULATOR_VOLTAGE,
Matti Vaittinena4bfc2c2018-09-14 11:33:11 +0300947 .n_voltages = BD71837_LDO5_VOLTAGE_NUM,
948 .linear_ranges = bd71837_ldo5_volts,
949 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts),
Matti Vaittinen494edd22018-09-14 11:27:46 +0300950 /* LDO5 is supplied by buck6 */
951 .supply_name = "buck6",
952 .vsel_reg = BD718XX_REG_LDO5_VOLT,
953 .vsel_mask = BD71837_LDO5_MASK,
954 .enable_reg = BD718XX_REG_LDO5_VOLT,
955 .enable_mask = BD718XX_LDO_EN,
956 .owner = THIS_MODULE,
957 },
958 .init = {
959 .reg = BD718XX_REG_LDO5_VOLT,
960 .mask = BD718XX_LDO_SEL,
961 .val = BD718XX_LDO_SEL,
962 },
963 .additional_inits = bd71837_ldo5_inits,
964 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits),
965 },
966 {
967 .desc = {
968 .name = "ldo6",
969 .of_match = of_match_ptr("LDO6"),
970 .regulators_node = of_match_ptr("regulators"),
971 .id = BD718XX_LDO6,
972 .ops = &bd718xx_ldo_regulator_ops,
973 .type = REGULATOR_VOLTAGE,
974 .n_voltages = BD718XX_LDO6_VOLTAGE_NUM,
975 .linear_ranges = bd718xx_ldo6_volts,
976 .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts),
977 /* LDO6 is supplied by buck7 */
978 .supply_name = "buck7",
979 .vsel_reg = BD718XX_REG_LDO6_VOLT,
980 .vsel_mask = BD718XX_LDO6_MASK,
981 .enable_reg = BD718XX_REG_LDO6_VOLT,
982 .enable_mask = BD718XX_LDO_EN,
983 .owner = THIS_MODULE,
984 },
985 .init = {
986 .reg = BD718XX_REG_LDO6_VOLT,
987 .mask = BD718XX_LDO_SEL,
988 .val = BD718XX_LDO_SEL,
989 },
990 .additional_inits = bd71837_ldo6_inits,
991 .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits),
992 },
993 {
994 .desc = {
995 .name = "ldo7",
996 .of_match = of_match_ptr("LDO7"),
997 .regulators_node = of_match_ptr("regulators"),
998 .id = BD718XX_LDO7,
999 .ops = &bd718xx_ldo_regulator_ops,
1000 .type = REGULATOR_VOLTAGE,
1001 .n_voltages = BD71837_LDO7_VOLTAGE_NUM,
1002 .linear_ranges = bd71837_ldo7_volts,
1003 .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts),
1004 .vsel_reg = BD71837_REG_LDO7_VOLT,
1005 .vsel_mask = BD71837_LDO7_MASK,
1006 .enable_reg = BD71837_REG_LDO7_VOLT,
1007 .enable_mask = BD718XX_LDO_EN,
1008 .owner = THIS_MODULE,
1009 },
1010 .init = {
1011 .reg = BD71837_REG_LDO7_VOLT,
1012 .mask = BD718XX_LDO_SEL,
1013 .val = BD718XX_LDO_SEL,
1014 },
1015 },
1016};
1017
1018struct bd718xx_pmic_inits {
1019 const struct bd718xx_regulator_data (*r_datas)[];
1020 unsigned int r_amount;
Matti Vaittinenba087992018-05-30 11:43:43 +03001021};
1022
Matti Vaittinendd2be632018-09-14 11:32:26 +03001023static int bd718xx_probe(struct platform_device *pdev)
Matti Vaittinenba087992018-05-30 11:43:43 +03001024{
Matti Vaittinen494edd22018-09-14 11:27:46 +03001025 struct bd718xx_pmic *pmic;
Matti Vaittinenba087992018-05-30 11:43:43 +03001026 struct regulator_config config = { 0 };
Matti Vaittinen494edd22018-09-14 11:27:46 +03001027 struct bd718xx_pmic_inits pmic_regulators[] = {
1028 [BD718XX_TYPE_BD71837] = {
1029 .r_datas = &bd71837_regulators,
1030 .r_amount = ARRAY_SIZE(bd71837_regulators),
1031 },
1032 [BD718XX_TYPE_BD71847] = {
1033 .r_datas = &bd71847_regulators,
1034 .r_amount = ARRAY_SIZE(bd71847_regulators),
1035 },
Matti Vaittinenba087992018-05-30 11:43:43 +03001036 };
1037
Matti Vaittinen494edd22018-09-14 11:27:46 +03001038 int i, j, err;
Matti Vaittinenba087992018-05-30 11:43:43 +03001039
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +03001040 pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL);
Matti Vaittinenba087992018-05-30 11:43:43 +03001041 if (!pmic)
1042 return -ENOMEM;
1043
Matti Vaittinenba087992018-05-30 11:43:43 +03001044 pmic->pdev = pdev;
1045 pmic->mfd = dev_get_drvdata(pdev->dev.parent);
1046
1047 if (!pmic->mfd) {
1048 dev_err(&pdev->dev, "No MFD driver data\n");
1049 err = -EINVAL;
1050 goto err;
1051 }
Matti Vaittinen494edd22018-09-14 11:27:46 +03001052 if (pmic->mfd->chip_type >= BD718XX_TYPE_AMOUNT ||
1053 !pmic_regulators[pmic->mfd->chip_type].r_datas) {
1054 dev_err(&pdev->dev, "Unsupported chip type\n");
1055 err = -EINVAL;
1056 goto err;
1057 }
1058
Matti Vaittinenba087992018-05-30 11:43:43 +03001059 platform_set_drvdata(pdev, pmic);
Matti Vaittinenba087992018-05-30 11:43:43 +03001060
1061 /* Register LOCK release */
Matti Vaittinen494edd22018-09-14 11:27:46 +03001062 err = regmap_update_bits(pmic->mfd->regmap, BD718XX_REG_REGLOCK,
Matti Vaittinenba087992018-05-30 11:43:43 +03001063 (REGLOCK_PWRSEQ | REGLOCK_VREG), 0);
1064 if (err) {
1065 dev_err(&pmic->pdev->dev, "Failed to unlock PMIC (%d)\n", err);
1066 goto err;
1067 } else {
Matti Vaittinenc9dc4cf2018-06-28 14:22:23 +03001068 dev_dbg(&pmic->pdev->dev, "Unlocked lock register 0x%x\n",
Matti Vaittinen494edd22018-09-14 11:27:46 +03001069 BD718XX_REG_REGLOCK);
Matti Vaittinenba087992018-05-30 11:43:43 +03001070 }
1071
Matti Vaittinen494edd22018-09-14 11:27:46 +03001072 for (i = 0; i < pmic_regulators[pmic->mfd->chip_type].r_amount; i++) {
Matti Vaittinen823f18f2018-08-29 15:36:10 +03001073
Matti Vaittinen494edd22018-09-14 11:27:46 +03001074 const struct regulator_desc *desc;
Matti Vaittinenba087992018-05-30 11:43:43 +03001075 struct regulator_dev *rdev;
Matti Vaittinen494edd22018-09-14 11:27:46 +03001076 const struct bd718xx_regulator_data *r;
Matti Vaittinenba087992018-05-30 11:43:43 +03001077
Matti Vaittinen494edd22018-09-14 11:27:46 +03001078 r = &(*pmic_regulators[pmic->mfd->chip_type].r_datas)[i];
1079 desc = &r->desc;
Matti Vaittinenba087992018-05-30 11:43:43 +03001080
Matti Vaittinenba087992018-05-30 11:43:43 +03001081 config.dev = pdev->dev.parent;
1082 config.driver_data = pmic;
1083 config.regmap = pmic->mfd->regmap;
1084
1085 rdev = devm_regulator_register(&pdev->dev, desc, &config);
1086 if (IS_ERR(rdev)) {
1087 dev_err(pmic->mfd->dev,
1088 "failed to register %s regulator\n",
1089 desc->name);
1090 err = PTR_ERR(rdev);
1091 goto err;
1092 }
1093 /* Regulator register gets the regulator constraints and
1094 * applies them (set_machine_constraints). This should have
1095 * turned the control register(s) to correct values and we
1096 * can now switch the control from PMIC state machine to the
1097 * register interface
1098 */
Matti Vaittinen494edd22018-09-14 11:27:46 +03001099 err = regmap_update_bits(pmic->mfd->regmap, r->init.reg,
1100 r->init.mask, r->init.val);
Matti Vaittinenba087992018-05-30 11:43:43 +03001101 if (err) {
1102 dev_err(&pmic->pdev->dev,
1103 "Failed to write BUCK/LDO SEL bit for (%s)\n",
1104 desc->name);
1105 goto err;
1106 }
Matti Vaittinen494edd22018-09-14 11:27:46 +03001107 for (j = 0; j < r->additional_init_amnt; j++) {
1108 err = regmap_update_bits(pmic->mfd->regmap,
1109 r->additional_inits[j].reg,
1110 r->additional_inits[j].mask,
1111 r->additional_inits[j].val);
1112 if (err) {
1113 dev_err(&pmic->pdev->dev,
1114 "Buck (%s) initialization failed\n",
1115 desc->name);
1116 goto err;
1117 }
1118 }
Matti Vaittinenba087992018-05-30 11:43:43 +03001119
1120 pmic->rdev[i] = rdev;
1121 }
1122
Matti Vaittinenba087992018-05-30 11:43:43 +03001123err:
1124 return err;
1125}
1126
Matti Vaittinendd2be632018-09-14 11:32:26 +03001127static struct platform_driver bd718xx_regulator = {
Matti Vaittinenba087992018-05-30 11:43:43 +03001128 .driver = {
Matti Vaittinen494edd22018-09-14 11:27:46 +03001129 .name = "bd718xx-pmic",
Matti Vaittinenba087992018-05-30 11:43:43 +03001130 },
Matti Vaittinendd2be632018-09-14 11:32:26 +03001131 .probe = bd718xx_probe,
Matti Vaittinenba087992018-05-30 11:43:43 +03001132};
1133
Matti Vaittinendd2be632018-09-14 11:32:26 +03001134module_platform_driver(bd718xx_regulator);
Matti Vaittinenba087992018-05-30 11:43:43 +03001135
1136MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>");
Matti Vaittinendd2be632018-09-14 11:32:26 +03001137MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver");
Matti Vaittinenba087992018-05-30 11:43:43 +03001138MODULE_LICENSE("GPL");