]>
Commit | Line | Data |
---|---|---|
ba08799e MV |
1 | // SPDX-License-Identifier: GPL-2.0 |
2 | // Copyright (C) 2018 ROHM Semiconductors | |
dd2be639 | 3 | // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver |
ba08799e | 4 | |
c9dc4cfa | 5 | #include <linux/delay.h> |
ba08799e MV |
6 | #include <linux/err.h> |
7 | #include <linux/interrupt.h> | |
c9dc4cfa | 8 | #include <linux/kernel.h> |
410e8b4f | 9 | #include <linux/mfd/rohm-bd718x7.h> |
c9dc4cfa | 10 | #include <linux/module.h> |
9cce7244 | 11 | #include <linux/of.h> |
ba08799e MV |
12 | #include <linux/platform_device.h> |
13 | #include <linux/regulator/driver.h> | |
14 | #include <linux/regulator/machine.h> | |
ba08799e | 15 | #include <linux/regulator/of_regulator.h> |
c9dc4cfa | 16 | #include <linux/slab.h> |
ba08799e | 17 | |
ba08799e MV |
18 | /* |
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 | */ | |
dd2be639 | 26 | static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev, |
ba08799e MV |
27 | int ramp_delay) |
28 | { | |
0a245f0e AL |
29 | int id = rdev_get_id(rdev); |
30 | unsigned int ramp_value; | |
ba08799e | 31 | |
bcb047eb | 32 | dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1, |
ba08799e MV |
33 | 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; | |
bcb047eb | 49 | dev_err(&rdev->dev, |
ba08799e MV |
50 | "%s: ramp_delay: %d not supported, setting 10000mV//us\n", |
51 | rdev->desc->name, ramp_delay); | |
52 | } | |
53 | ||
bcb047eb | 54 | return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id, |
ba08799e MV |
55 | BUCK_RAMPRATE_MASK, ramp_value << 6); |
56 | } | |
57 | ||
f0ca7b24 MV |
58 | /* |
59 | * On BD71837 (not on BD71847, BD71850, ...) | |
60 | * Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed. | |
ba08799e MV |
61 | * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage |
62 | * is changed. Hence we return -EBUSY for these if voltage is changed | |
63 | * when BUCK/LDO is enabled. | |
f0ca7b24 | 64 | * |
9bcbabaf MV |
65 | * On BD71847, BD71850, ... The LDO voltage can be changed when LDO is |
66 | * enabled. But if voltage is increased the LDO power-good monitoring | |
67 | * must be disabled for the duration of changing + 1mS to ensure voltage | |
68 | * has reached the higher level before HW does next under voltage detection | |
69 | * cycle. | |
ba08799e | 70 | */ |
9bcbabaf | 71 | static int bd71837_set_voltage_sel_restricted(struct regulator_dev *rdev, |
ba08799e MV |
72 | unsigned int sel) |
73 | { | |
ffdc4984 AL |
74 | if (regulator_is_enabled_regmap(rdev)) |
75 | return -EBUSY; | |
ba08799e | 76 | |
ffdc4984 | 77 | return regulator_set_voltage_sel_regmap(rdev, sel); |
ba08799e MV |
78 | } |
79 | ||
9bcbabaf MV |
80 | static void voltage_change_done(struct regulator_dev *rdev, unsigned int sel, |
81 | unsigned int *mask) | |
82 | { | |
83 | int ret; | |
84 | ||
85 | if (*mask) { | |
86 | /* | |
87 | * Let's allow scheduling as we use I2C anyways. We just need to | |
88 | * guarantee minimum of 1ms sleep - it shouldn't matter if we | |
89 | * exceed it due to the scheduling. | |
90 | */ | |
91 | msleep(1); | |
92 | /* | |
93 | * Note for next hacker. The PWRGOOD should not be masked on | |
94 | * BD71847 so we will just unconditionally enable detection | |
95 | * when voltage is set. | |
96 | * If someone want's to disable PWRGOOD he must implement | |
97 | * caching and restoring the old value here. I am not | |
98 | * aware of such use-cases so for the sake of the simplicity | |
99 | * we just always enable PWRGOOD here. | |
100 | */ | |
101 | ret = regmap_update_bits(rdev->regmap, BD718XX_REG_MVRFLTMASK2, | |
102 | *mask, 0); | |
103 | if (ret) | |
104 | dev_err(&rdev->dev, | |
105 | "Failed to re-enable voltage monitoring (%d)\n", | |
106 | ret); | |
107 | } | |
108 | } | |
109 | ||
110 | static int voltage_change_prepare(struct regulator_dev *rdev, unsigned int sel, | |
111 | unsigned int *mask) | |
112 | { | |
113 | int ret; | |
114 | ||
115 | *mask = 0; | |
116 | if (regulator_is_enabled_regmap(rdev)) { | |
117 | int now, new; | |
118 | ||
119 | now = rdev->desc->ops->get_voltage_sel(rdev); | |
120 | if (now < 0) | |
121 | return now; | |
122 | ||
123 | now = rdev->desc->ops->list_voltage(rdev, now); | |
124 | if (now < 0) | |
125 | return now; | |
126 | ||
127 | new = rdev->desc->ops->list_voltage(rdev, sel); | |
128 | if (new < 0) | |
129 | return new; | |
130 | ||
131 | /* | |
132 | * If we increase LDO voltage when LDO is enabled we need to | |
133 | * disable the power-good detection until voltage has reached | |
134 | * the new level. According to HW colleagues the maximum time | |
135 | * it takes is 1000us. I assume that on systems with light load | |
136 | * this might be less - and we could probably use DT to give | |
137 | * system specific delay value if performance matters. | |
138 | * | |
139 | * Well, knowing we use I2C here and can add scheduling delays | |
140 | * I don't think it is worth the hassle and I just add fixed | |
141 | * 1ms sleep here (and allow scheduling). If this turns out to | |
142 | * be a problem we can change it to delay and make the delay | |
143 | * time configurable. | |
144 | */ | |
145 | if (new > now) { | |
146 | int ldo_offset = rdev->desc->id - BD718XX_LDO1; | |
147 | ||
148 | *mask = BD718XX_LDO1_VRMON80 << ldo_offset; | |
149 | ret = regmap_update_bits(rdev->regmap, | |
150 | BD718XX_REG_MVRFLTMASK2, | |
151 | *mask, *mask); | |
152 | if (ret) { | |
153 | dev_err(&rdev->dev, | |
154 | "Failed to stop voltage monitoring\n"); | |
155 | return ret; | |
156 | } | |
157 | } | |
158 | } | |
159 | ||
160 | return 0; | |
161 | } | |
162 | ||
163 | static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev, | |
164 | unsigned int sel) | |
165 | { | |
166 | int ret; | |
167 | int mask; | |
168 | ||
169 | ret = voltage_change_prepare(rdev, sel, &mask); | |
170 | if (ret) | |
171 | return ret; | |
172 | ||
173 | ret = regulator_set_voltage_sel_regmap(rdev, sel); | |
174 | voltage_change_done(rdev, sel, &mask); | |
175 | ||
176 | return ret; | |
177 | } | |
178 | ||
a4bfc2c2 MV |
179 | static int bd718xx_set_voltage_sel_pickable_restricted( |
180 | struct regulator_dev *rdev, unsigned int sel) | |
9bcbabaf MV |
181 | { |
182 | int ret; | |
183 | int mask; | |
184 | ||
185 | ret = voltage_change_prepare(rdev, sel, &mask); | |
186 | if (ret) | |
187 | return ret; | |
188 | ||
189 | ret = regulator_set_voltage_sel_pickable_regmap(rdev, sel); | |
190 | voltage_change_done(rdev, sel, &mask); | |
191 | ||
192 | return ret; | |
193 | } | |
194 | ||
195 | static int bd71837_set_voltage_sel_pickable_restricted( | |
196 | struct regulator_dev *rdev, unsigned int sel) | |
a4bfc2c2 MV |
197 | { |
198 | if (regulator_is_enabled_regmap(rdev)) | |
199 | return -EBUSY; | |
200 | ||
201 | return regulator_set_voltage_sel_pickable_regmap(rdev, sel); | |
202 | } | |
203 | ||
704c5c01 | 204 | static const struct regulator_ops bd718xx_pickable_range_ldo_ops = { |
a4bfc2c2 MV |
205 | .enable = regulator_enable_regmap, |
206 | .disable = regulator_disable_regmap, | |
207 | .is_enabled = regulator_is_enabled_regmap, | |
208 | .list_voltage = regulator_list_voltage_pickable_linear_range, | |
209 | .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted, | |
210 | .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, | |
9bcbabaf MV |
211 | |
212 | }; | |
213 | ||
214 | static const struct regulator_ops bd71837_pickable_range_ldo_ops = { | |
215 | .enable = regulator_enable_regmap, | |
216 | .disable = regulator_disable_regmap, | |
217 | .is_enabled = regulator_is_enabled_regmap, | |
218 | .list_voltage = regulator_list_voltage_pickable_linear_range, | |
219 | .set_voltage_sel = bd71837_set_voltage_sel_pickable_restricted, | |
220 | .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, | |
a4bfc2c2 MV |
221 | }; |
222 | ||
704c5c01 | 223 | static const struct regulator_ops bd718xx_pickable_range_buck_ops = { |
f0ca7b24 MV |
224 | .enable = regulator_enable_regmap, |
225 | .disable = regulator_disable_regmap, | |
226 | .is_enabled = regulator_is_enabled_regmap, | |
227 | .list_voltage = regulator_list_voltage_pickable_linear_range, | |
228 | .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap, | |
229 | .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, | |
230 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
231 | }; | |
232 | ||
233 | static const struct regulator_ops bd71837_pickable_range_buck_ops = { | |
a4bfc2c2 MV |
234 | .enable = regulator_enable_regmap, |
235 | .disable = regulator_disable_regmap, | |
236 | .is_enabled = regulator_is_enabled_regmap, | |
237 | .list_voltage = regulator_list_voltage_pickable_linear_range, | |
9bcbabaf | 238 | .set_voltage_sel = bd71837_set_voltage_sel_pickable_restricted, |
a4bfc2c2 MV |
239 | .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, |
240 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
241 | }; | |
242 | ||
9bcbabaf MV |
243 | static const struct regulator_ops bd71837_ldo_regulator_ops = { |
244 | .enable = regulator_enable_regmap, | |
245 | .disable = regulator_disable_regmap, | |
246 | .is_enabled = regulator_is_enabled_regmap, | |
247 | .list_voltage = regulator_list_voltage_linear_range, | |
248 | .set_voltage_sel = bd71837_set_voltage_sel_restricted, | |
249 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
250 | }; | |
251 | ||
704c5c01 | 252 | static const struct regulator_ops bd718xx_ldo_regulator_ops = { |
ba08799e MV |
253 | .enable = regulator_enable_regmap, |
254 | .disable = regulator_disable_regmap, | |
255 | .is_enabled = regulator_is_enabled_regmap, | |
256 | .list_voltage = regulator_list_voltage_linear_range, | |
494edd26 | 257 | .set_voltage_sel = bd718xx_set_voltage_sel_restricted, |
ba08799e MV |
258 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
259 | }; | |
260 | ||
9bcbabaf MV |
261 | static const struct regulator_ops bd71837_ldo_regulator_nolinear_ops = { |
262 | .enable = regulator_enable_regmap, | |
263 | .disable = regulator_disable_regmap, | |
264 | .is_enabled = regulator_is_enabled_regmap, | |
265 | .list_voltage = regulator_list_voltage_table, | |
266 | .set_voltage_sel = bd71837_set_voltage_sel_restricted, | |
267 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
268 | }; | |
269 | ||
704c5c01 | 270 | static const struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = { |
ba08799e MV |
271 | .enable = regulator_enable_regmap, |
272 | .disable = regulator_disable_regmap, | |
273 | .is_enabled = regulator_is_enabled_regmap, | |
274 | .list_voltage = regulator_list_voltage_table, | |
494edd26 | 275 | .set_voltage_sel = bd718xx_set_voltage_sel_restricted, |
ba08799e MV |
276 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
277 | }; | |
278 | ||
704c5c01 | 279 | static const struct regulator_ops bd718xx_buck_regulator_ops = { |
f0ca7b24 MV |
280 | .enable = regulator_enable_regmap, |
281 | .disable = regulator_disable_regmap, | |
282 | .is_enabled = regulator_is_enabled_regmap, | |
283 | .list_voltage = regulator_list_voltage_linear_range, | |
284 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
285 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
286 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
287 | }; | |
288 | ||
289 | static const struct regulator_ops bd71837_buck_regulator_ops = { | |
ba08799e MV |
290 | .enable = regulator_enable_regmap, |
291 | .disable = regulator_disable_regmap, | |
292 | .is_enabled = regulator_is_enabled_regmap, | |
293 | .list_voltage = regulator_list_voltage_linear_range, | |
9bcbabaf | 294 | .set_voltage_sel = bd71837_set_voltage_sel_restricted, |
ba08799e MV |
295 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
296 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
297 | }; | |
298 | ||
704c5c01 | 299 | static const struct regulator_ops bd718xx_buck_regulator_nolinear_ops = { |
f0ca7b24 MV |
300 | .enable = regulator_enable_regmap, |
301 | .disable = regulator_disable_regmap, | |
302 | .is_enabled = regulator_is_enabled_regmap, | |
303 | .list_voltage = regulator_list_voltage_table, | |
304 | .map_voltage = regulator_map_voltage_ascend, | |
305 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
306 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
307 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
308 | }; | |
309 | ||
310 | static const struct regulator_ops bd71837_buck_regulator_nolinear_ops = { | |
ba08799e MV |
311 | .enable = regulator_enable_regmap, |
312 | .disable = regulator_disable_regmap, | |
313 | .is_enabled = regulator_is_enabled_regmap, | |
314 | .list_voltage = regulator_list_voltage_table, | |
2e61286d | 315 | .map_voltage = regulator_map_voltage_ascend, |
494edd26 | 316 | .set_voltage_sel = bd718xx_set_voltage_sel_restricted, |
ba08799e MV |
317 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
318 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
319 | }; | |
320 | ||
704c5c01 | 321 | static const struct regulator_ops bd718xx_dvs_buck_regulator_ops = { |
ba08799e MV |
322 | .enable = regulator_enable_regmap, |
323 | .disable = regulator_disable_regmap, | |
324 | .is_enabled = regulator_is_enabled_regmap, | |
325 | .list_voltage = regulator_list_voltage_linear_range, | |
326 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | |
327 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | |
328 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | |
dd2be639 | 329 | .set_ramp_delay = bd718xx_buck1234_set_ramp_delay, |
ba08799e MV |
330 | }; |
331 | ||
332 | /* | |
494edd26 MV |
333 | * BD71837 BUCK1/2/3/4 |
334 | * BD71847 BUCK1/2 | |
ba08799e MV |
335 | * 0.70 to 1.30V (10mV step) |
336 | */ | |
60ab7f41 | 337 | static const struct linear_range bd718xx_dvs_buck_volts[] = { |
ba08799e MV |
338 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000), |
339 | REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0), | |
340 | }; | |
341 | ||
342 | /* | |
494edd26 | 343 | * BD71837 BUCK5 |
a4bfc2c2 MV |
344 | * 0.7V to 1.35V (range 0) |
345 | * and | |
346 | * 0.675 to 1.325 (range 1) | |
347 | */ | |
60ab7f41 | 348 | static const struct linear_range bd71837_buck5_volts[] = { |
a4bfc2c2 MV |
349 | /* Ranges when VOLT_SEL bit is 0 */ |
350 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), | |
351 | REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), | |
352 | REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), | |
353 | /* Ranges when VOLT_SEL bit is 1 */ | |
354 | REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), | |
355 | REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), | |
356 | REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), | |
357 | }; | |
358 | ||
359 | /* | |
360 | * Range selector for first 3 linear ranges is 0x0 | |
361 | * and 0x1 for last 3 ranges. | |
362 | */ | |
363 | static const unsigned int bd71837_buck5_volt_range_sel[] = { | |
364 | 0x0, 0x0, 0x0, 0x80, 0x80, 0x80 | |
365 | }; | |
366 | ||
367 | /* | |
494edd26 | 368 | * BD71847 BUCK3 |
ba08799e | 369 | */ |
60ab7f41 | 370 | static const struct linear_range bd71847_buck3_volts[] = { |
a4bfc2c2 | 371 | /* Ranges when VOLT_SEL bits are 00 */ |
ba08799e MV |
372 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), |
373 | REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), | |
374 | REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), | |
a4bfc2c2 MV |
375 | /* Ranges when VOLT_SEL bits are 01 */ |
376 | REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000), | |
377 | /* Ranges when VOLT_SEL bits are 11 */ | |
378 | REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), | |
379 | REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), | |
380 | REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), | |
381 | }; | |
382 | ||
383 | static const unsigned int bd71847_buck3_volt_range_sel[] = { | |
384 | 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80 | |
ba08799e MV |
385 | }; |
386 | ||
60ab7f41 | 387 | static const struct linear_range bd71847_buck4_volts[] = { |
494edd26 | 388 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
a4bfc2c2 | 389 | REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000), |
494edd26 MV |
390 | }; |
391 | ||
a4bfc2c2 MV |
392 | static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 }; |
393 | ||
ba08799e MV |
394 | /* |
395 | * BUCK6 | |
396 | * 3.0V to 3.3V (step 100mV) | |
397 | */ | |
60ab7f41 | 398 | static const struct linear_range bd71837_buck6_volts[] = { |
ba08799e MV |
399 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
400 | }; | |
401 | ||
402 | /* | |
494edd26 MV |
403 | * BD71837 BUCK7 |
404 | * BD71847 BUCK5 | |
ba08799e MV |
405 | * 000 = 1.605V |
406 | * 001 = 1.695V | |
407 | * 010 = 1.755V | |
408 | * 011 = 1.8V (Initial) | |
409 | * 100 = 1.845V | |
410 | * 101 = 1.905V | |
411 | * 110 = 1.95V | |
412 | * 111 = 1.995V | |
413 | */ | |
494edd26 | 414 | static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = { |
ba08799e MV |
415 | 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000 |
416 | }; | |
417 | ||
418 | /* | |
419 | * BUCK8 | |
420 | * 0.8V to 1.40V (step 10mV) | |
421 | */ | |
60ab7f41 | 422 | static const struct linear_range bd718xx_4th_nodvs_buck_volts[] = { |
ba08799e | 423 | REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000), |
ba08799e MV |
424 | }; |
425 | ||
426 | /* | |
427 | * LDO1 | |
428 | * 3.0 to 3.3V (100mV step) | |
429 | */ | |
60ab7f41 | 430 | static const struct linear_range bd718xx_ldo1_volts[] = { |
ba08799e | 431 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
a4bfc2c2 | 432 | REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000), |
ba08799e MV |
433 | }; |
434 | ||
a4bfc2c2 MV |
435 | static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 }; |
436 | ||
ba08799e MV |
437 | /* |
438 | * LDO2 | |
439 | * 0.8 or 0.9V | |
440 | */ | |
adb78a8e | 441 | static const unsigned int ldo_2_volts[] = { |
ba08799e MV |
442 | 900000, 800000 |
443 | }; | |
444 | ||
445 | /* | |
446 | * LDO3 | |
447 | * 1.8 to 3.3V (100mV step) | |
448 | */ | |
60ab7f41 | 449 | static const struct linear_range bd718xx_ldo3_volts[] = { |
ba08799e MV |
450 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
451 | }; | |
452 | ||
453 | /* | |
454 | * LDO4 | |
455 | * 0.9 to 1.8V (100mV step) | |
456 | */ | |
60ab7f41 | 457 | static const struct linear_range bd718xx_ldo4_volts[] = { |
ba08799e | 458 | REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), |
ba08799e MV |
459 | }; |
460 | ||
461 | /* | |
494edd26 | 462 | * LDO5 for BD71837 |
ba08799e MV |
463 | * 1.8 to 3.3V (100mV step) |
464 | */ | |
60ab7f41 | 465 | static const struct linear_range bd71837_ldo5_volts[] = { |
ba08799e MV |
466 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
467 | }; | |
468 | ||
a4bfc2c2 MV |
469 | /* |
470 | * LDO5 for BD71837 | |
471 | * 1.8 to 3.3V (100mV step) | |
472 | */ | |
60ab7f41 | 473 | static const struct linear_range bd71847_ldo5_volts[] = { |
a4bfc2c2 MV |
474 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
475 | REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000), | |
476 | }; | |
477 | ||
478 | static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 }; | |
479 | ||
ba08799e MV |
480 | /* |
481 | * LDO6 | |
482 | * 0.9 to 1.8V (100mV step) | |
483 | */ | |
60ab7f41 | 484 | static const struct linear_range bd718xx_ldo6_volts[] = { |
ba08799e | 485 | REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), |
ba08799e MV |
486 | }; |
487 | ||
488 | /* | |
489 | * LDO7 | |
490 | * 1.8 to 3.3V (100mV step) | |
491 | */ | |
60ab7f41 | 492 | static const struct linear_range bd71837_ldo7_volts[] = { |
ba08799e MV |
493 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
494 | }; | |
495 | ||
494edd26 MV |
496 | struct reg_init { |
497 | unsigned int reg; | |
498 | unsigned int mask; | |
499 | unsigned int val; | |
500 | }; | |
501 | struct bd718xx_regulator_data { | |
502 | struct regulator_desc desc; | |
21b72156 | 503 | const struct rohm_dvs_config dvs; |
494edd26 MV |
504 | const struct reg_init init; |
505 | const struct reg_init *additional_inits; | |
506 | int additional_init_amnt; | |
507 | }; | |
508 | ||
509 | /* | |
510 | * There is a HW quirk in BD71837. The shutdown sequence timings for | |
511 | * bucks/LDOs which are controlled via register interface are changed. | |
512 | * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the | |
513 | * beginning of shut-down sequence. As bucks 6 and 7 are parent | |
514 | * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage | |
515 | * monitoring to errorneously detect under voltage and force PMIC to | |
516 | * emergency state instead of poweroff. In order to avoid this we | |
517 | * disable voltage monitoring for LDO5 and LDO6 | |
518 | */ | |
519 | static const struct reg_init bd71837_ldo5_inits[] = { | |
520 | { | |
521 | .reg = BD718XX_REG_MVRFLTMASK2, | |
522 | .mask = BD718XX_LDO5_VRMON80, | |
523 | .val = BD718XX_LDO5_VRMON80, | |
524 | }, | |
525 | }; | |
526 | ||
527 | static const struct reg_init bd71837_ldo6_inits[] = { | |
528 | { | |
529 | .reg = BD718XX_REG_MVRFLTMASK2, | |
530 | .mask = BD718XX_LDO6_VRMON80, | |
531 | .val = BD718XX_LDO6_VRMON80, | |
532 | }, | |
533 | }; | |
534 | ||
21b72156 | 535 | static int buck_set_hw_dvs_levels(struct device_node *np, |
049369d4 MV |
536 | const struct regulator_desc *desc, |
537 | struct regulator_config *cfg) | |
538 | { | |
21b72156 | 539 | struct bd718xx_regulator_data *data; |
049369d4 | 540 | |
21b72156 | 541 | data = container_of(desc, struct bd718xx_regulator_data, desc); |
049369d4 | 542 | |
21b72156 | 543 | return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap); |
049369d4 MV |
544 | } |
545 | ||
494edd26 MV |
546 | static const struct bd718xx_regulator_data bd71847_regulators[] = { |
547 | { | |
548 | .desc = { | |
549 | .name = "buck1", | |
550 | .of_match = of_match_ptr("BUCK1"), | |
551 | .regulators_node = of_match_ptr("regulators"), | |
552 | .id = BD718XX_BUCK1, | |
553 | .ops = &bd718xx_dvs_buck_regulator_ops, | |
554 | .type = REGULATOR_VOLTAGE, | |
555 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
556 | .linear_ranges = bd718xx_dvs_buck_volts, | |
557 | .n_linear_ranges = | |
558 | ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
559 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
560 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
561 | .enable_reg = BD718XX_REG_BUCK1_CTRL, | |
562 | .enable_mask = BD718XX_BUCK_EN, | |
563 | .owner = THIS_MODULE, | |
21b72156 MV |
564 | .of_parse_cb = buck_set_hw_dvs_levels, |
565 | }, | |
566 | .dvs = { | |
567 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE | | |
568 | ROHM_DVS_LEVEL_SUSPEND, | |
569 | .run_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
570 | .run_mask = DVS_BUCK_RUN_MASK, | |
571 | .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE, | |
572 | .idle_mask = DVS_BUCK_RUN_MASK, | |
573 | .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP, | |
574 | .suspend_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
575 | }, |
576 | .init = { | |
577 | .reg = BD718XX_REG_BUCK1_CTRL, | |
578 | .mask = BD718XX_BUCK_SEL, | |
579 | .val = BD718XX_BUCK_SEL, | |
580 | }, | |
581 | }, | |
ba08799e | 582 | { |
494edd26 MV |
583 | .desc = { |
584 | .name = "buck2", | |
585 | .of_match = of_match_ptr("BUCK2"), | |
586 | .regulators_node = of_match_ptr("regulators"), | |
587 | .id = BD718XX_BUCK2, | |
588 | .ops = &bd718xx_dvs_buck_regulator_ops, | |
589 | .type = REGULATOR_VOLTAGE, | |
590 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
591 | .linear_ranges = bd718xx_dvs_buck_volts, | |
592 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
593 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
594 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
595 | .enable_reg = BD718XX_REG_BUCK2_CTRL, | |
596 | .enable_mask = BD718XX_BUCK_EN, | |
597 | .owner = THIS_MODULE, | |
21b72156 MV |
598 | .of_parse_cb = buck_set_hw_dvs_levels, |
599 | }, | |
600 | .dvs = { | |
601 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE, | |
602 | .run_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
603 | .run_mask = DVS_BUCK_RUN_MASK, | |
604 | .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE, | |
605 | .idle_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
606 | }, |
607 | .init = { | |
608 | .reg = BD718XX_REG_BUCK2_CTRL, | |
609 | .mask = BD718XX_BUCK_SEL, | |
610 | .val = BD718XX_BUCK_SEL, | |
611 | }, | |
ba08799e MV |
612 | }, |
613 | { | |
494edd26 MV |
614 | .desc = { |
615 | .name = "buck3", | |
616 | .of_match = of_match_ptr("BUCK3"), | |
617 | .regulators_node = of_match_ptr("regulators"), | |
618 | .id = BD718XX_BUCK3, | |
a4bfc2c2 | 619 | .ops = &bd718xx_pickable_range_buck_ops, |
494edd26 | 620 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
621 | .n_voltages = BD71847_BUCK3_VOLTAGE_NUM, |
622 | .linear_ranges = bd71847_buck3_volts, | |
494edd26 | 623 | .n_linear_ranges = |
a4bfc2c2 | 624 | ARRAY_SIZE(bd71847_buck3_volts), |
494edd26 MV |
625 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
626 | .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK, | |
a4bfc2c2 MV |
627 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
628 | .vsel_range_mask = BD71847_BUCK3_RANGE_MASK, | |
629 | .linear_range_selectors = bd71847_buck3_volt_range_sel, | |
494edd26 MV |
630 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
631 | .enable_mask = BD718XX_BUCK_EN, | |
632 | .owner = THIS_MODULE, | |
633 | }, | |
634 | .init = { | |
635 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, | |
636 | .mask = BD718XX_BUCK_SEL, | |
637 | .val = BD718XX_BUCK_SEL, | |
638 | }, | |
ba08799e MV |
639 | }, |
640 | { | |
494edd26 MV |
641 | .desc = { |
642 | .name = "buck4", | |
643 | .of_match = of_match_ptr("BUCK4"), | |
644 | .regulators_node = of_match_ptr("regulators"), | |
645 | .id = BD718XX_BUCK4, | |
a4bfc2c2 | 646 | .ops = &bd718xx_pickable_range_buck_ops, |
494edd26 MV |
647 | .type = REGULATOR_VOLTAGE, |
648 | .n_voltages = BD71847_BUCK4_VOLTAGE_NUM, | |
a4bfc2c2 | 649 | .linear_ranges = bd71847_buck4_volts, |
494edd26 | 650 | .n_linear_ranges = |
a4bfc2c2 | 651 | ARRAY_SIZE(bd71847_buck4_volts), |
494edd26 MV |
652 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
653 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, | |
654 | .vsel_mask = BD71847_BUCK4_MASK, | |
a4bfc2c2 MV |
655 | .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
656 | .vsel_range_mask = BD71847_BUCK4_RANGE_MASK, | |
657 | .linear_range_selectors = bd71847_buck4_volt_range_sel, | |
494edd26 MV |
658 | .enable_mask = BD718XX_BUCK_EN, |
659 | .owner = THIS_MODULE, | |
660 | }, | |
661 | .init = { | |
662 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, | |
663 | .mask = BD718XX_BUCK_SEL, | |
664 | .val = BD718XX_BUCK_SEL, | |
665 | }, | |
ba08799e MV |
666 | }, |
667 | { | |
494edd26 MV |
668 | .desc = { |
669 | .name = "buck5", | |
670 | .of_match = of_match_ptr("BUCK5"), | |
dd2be639 | 671 | .regulators_node = of_match_ptr("regulators"), |
494edd26 MV |
672 | .id = BD718XX_BUCK5, |
673 | .ops = &bd718xx_buck_regulator_nolinear_ops, | |
674 | .type = REGULATOR_VOLTAGE, | |
675 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], | |
676 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), | |
677 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, | |
678 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, | |
679 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
680 | .enable_mask = BD718XX_BUCK_EN, | |
681 | .owner = THIS_MODULE, | |
682 | }, | |
683 | .init = { | |
684 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
685 | .mask = BD718XX_BUCK_SEL, | |
686 | .val = BD718XX_BUCK_SEL, | |
687 | }, | |
ba08799e MV |
688 | }, |
689 | { | |
494edd26 MV |
690 | .desc = { |
691 | .name = "buck6", | |
692 | .of_match = of_match_ptr("BUCK6"), | |
693 | .regulators_node = of_match_ptr("regulators"), | |
694 | .id = BD718XX_BUCK6, | |
695 | .ops = &bd718xx_buck_regulator_ops, | |
696 | .type = REGULATOR_VOLTAGE, | |
dd2be639 | 697 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
494edd26 MV |
698 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
699 | .n_linear_ranges = | |
700 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), | |
701 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, | |
702 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, | |
703 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
704 | .enable_mask = BD718XX_BUCK_EN, | |
705 | .owner = THIS_MODULE, | |
706 | }, | |
707 | .init = { | |
708 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
709 | .mask = BD718XX_BUCK_SEL, | |
710 | .val = BD718XX_BUCK_SEL, | |
711 | }, | |
ba08799e MV |
712 | }, |
713 | { | |
494edd26 MV |
714 | .desc = { |
715 | .name = "ldo1", | |
716 | .of_match = of_match_ptr("LDO1"), | |
717 | .regulators_node = of_match_ptr("regulators"), | |
718 | .id = BD718XX_LDO1, | |
a4bfc2c2 | 719 | .ops = &bd718xx_pickable_range_ldo_ops, |
494edd26 MV |
720 | .type = REGULATOR_VOLTAGE, |
721 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, | |
722 | .linear_ranges = bd718xx_ldo1_volts, | |
723 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), | |
724 | .vsel_reg = BD718XX_REG_LDO1_VOLT, | |
725 | .vsel_mask = BD718XX_LDO1_MASK, | |
a4bfc2c2 MV |
726 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
727 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, | |
728 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, | |
494edd26 MV |
729 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
730 | .enable_mask = BD718XX_LDO_EN, | |
731 | .owner = THIS_MODULE, | |
732 | }, | |
733 | .init = { | |
734 | .reg = BD718XX_REG_LDO1_VOLT, | |
735 | .mask = BD718XX_LDO_SEL, | |
736 | .val = BD718XX_LDO_SEL, | |
737 | }, | |
ba08799e MV |
738 | }, |
739 | { | |
494edd26 MV |
740 | .desc = { |
741 | .name = "ldo2", | |
742 | .of_match = of_match_ptr("LDO2"), | |
743 | .regulators_node = of_match_ptr("regulators"), | |
744 | .id = BD718XX_LDO2, | |
745 | .ops = &bd718xx_ldo_regulator_nolinear_ops, | |
746 | .type = REGULATOR_VOLTAGE, | |
747 | .volt_table = &ldo_2_volts[0], | |
748 | .vsel_reg = BD718XX_REG_LDO2_VOLT, | |
749 | .vsel_mask = BD718XX_LDO2_MASK, | |
750 | .n_voltages = ARRAY_SIZE(ldo_2_volts), | |
751 | .enable_reg = BD718XX_REG_LDO2_VOLT, | |
752 | .enable_mask = BD718XX_LDO_EN, | |
753 | .owner = THIS_MODULE, | |
754 | }, | |
755 | .init = { | |
756 | .reg = BD718XX_REG_LDO2_VOLT, | |
757 | .mask = BD718XX_LDO_SEL, | |
758 | .val = BD718XX_LDO_SEL, | |
759 | }, | |
ba08799e MV |
760 | }, |
761 | { | |
494edd26 MV |
762 | .desc = { |
763 | .name = "ldo3", | |
764 | .of_match = of_match_ptr("LDO3"), | |
765 | .regulators_node = of_match_ptr("regulators"), | |
766 | .id = BD718XX_LDO3, | |
767 | .ops = &bd718xx_ldo_regulator_ops, | |
768 | .type = REGULATOR_VOLTAGE, | |
769 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, | |
770 | .linear_ranges = bd718xx_ldo3_volts, | |
771 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), | |
772 | .vsel_reg = BD718XX_REG_LDO3_VOLT, | |
773 | .vsel_mask = BD718XX_LDO3_MASK, | |
774 | .enable_reg = BD718XX_REG_LDO3_VOLT, | |
775 | .enable_mask = BD718XX_LDO_EN, | |
776 | .owner = THIS_MODULE, | |
777 | }, | |
778 | .init = { | |
779 | .reg = BD718XX_REG_LDO3_VOLT, | |
780 | .mask = BD718XX_LDO_SEL, | |
781 | .val = BD718XX_LDO_SEL, | |
782 | }, | |
ba08799e MV |
783 | }, |
784 | { | |
494edd26 MV |
785 | .desc = { |
786 | .name = "ldo4", | |
787 | .of_match = of_match_ptr("LDO4"), | |
788 | .regulators_node = of_match_ptr("regulators"), | |
789 | .id = BD718XX_LDO4, | |
790 | .ops = &bd718xx_ldo_regulator_ops, | |
791 | .type = REGULATOR_VOLTAGE, | |
792 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, | |
793 | .linear_ranges = bd718xx_ldo4_volts, | |
794 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), | |
795 | .vsel_reg = BD718XX_REG_LDO4_VOLT, | |
796 | .vsel_mask = BD718XX_LDO4_MASK, | |
797 | .enable_reg = BD718XX_REG_LDO4_VOLT, | |
798 | .enable_mask = BD718XX_LDO_EN, | |
799 | .owner = THIS_MODULE, | |
800 | }, | |
801 | .init = { | |
802 | .reg = BD718XX_REG_LDO4_VOLT, | |
803 | .mask = BD718XX_LDO_SEL, | |
804 | .val = BD718XX_LDO_SEL, | |
805 | }, | |
ba08799e MV |
806 | }, |
807 | { | |
494edd26 MV |
808 | .desc = { |
809 | .name = "ldo5", | |
810 | .of_match = of_match_ptr("LDO5"), | |
811 | .regulators_node = of_match_ptr("regulators"), | |
812 | .id = BD718XX_LDO5, | |
a4bfc2c2 | 813 | .ops = &bd718xx_pickable_range_ldo_ops, |
494edd26 | 814 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
815 | .n_voltages = BD71847_LDO5_VOLTAGE_NUM, |
816 | .linear_ranges = bd71847_ldo5_volts, | |
817 | .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts), | |
494edd26 MV |
818 | .vsel_reg = BD718XX_REG_LDO5_VOLT, |
819 | .vsel_mask = BD71847_LDO5_MASK, | |
a4bfc2c2 MV |
820 | .vsel_range_reg = BD718XX_REG_LDO5_VOLT, |
821 | .vsel_range_mask = BD71847_LDO5_RANGE_MASK, | |
822 | .linear_range_selectors = bd71847_ldo5_volt_range_sel, | |
494edd26 MV |
823 | .enable_reg = BD718XX_REG_LDO5_VOLT, |
824 | .enable_mask = BD718XX_LDO_EN, | |
825 | .owner = THIS_MODULE, | |
826 | }, | |
827 | .init = { | |
828 | .reg = BD718XX_REG_LDO5_VOLT, | |
829 | .mask = BD718XX_LDO_SEL, | |
830 | .val = BD718XX_LDO_SEL, | |
831 | }, | |
ba08799e MV |
832 | }, |
833 | { | |
494edd26 MV |
834 | .desc = { |
835 | .name = "ldo6", | |
836 | .of_match = of_match_ptr("LDO6"), | |
837 | .regulators_node = of_match_ptr("regulators"), | |
838 | .id = BD718XX_LDO6, | |
839 | .ops = &bd718xx_ldo_regulator_ops, | |
840 | .type = REGULATOR_VOLTAGE, | |
841 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, | |
842 | .linear_ranges = bd718xx_ldo6_volts, | |
843 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), | |
844 | /* LDO6 is supplied by buck5 */ | |
845 | .supply_name = "buck5", | |
846 | .vsel_reg = BD718XX_REG_LDO6_VOLT, | |
847 | .vsel_mask = BD718XX_LDO6_MASK, | |
848 | .enable_reg = BD718XX_REG_LDO6_VOLT, | |
849 | .enable_mask = BD718XX_LDO_EN, | |
850 | .owner = THIS_MODULE, | |
851 | }, | |
852 | .init = { | |
853 | .reg = BD718XX_REG_LDO6_VOLT, | |
854 | .mask = BD718XX_LDO_SEL, | |
855 | .val = BD718XX_LDO_SEL, | |
856 | }, | |
857 | }, | |
858 | }; | |
859 | ||
860 | static const struct bd718xx_regulator_data bd71837_regulators[] = { | |
861 | { | |
862 | .desc = { | |
863 | .name = "buck1", | |
864 | .of_match = of_match_ptr("BUCK1"), | |
865 | .regulators_node = of_match_ptr("regulators"), | |
866 | .id = BD718XX_BUCK1, | |
867 | .ops = &bd718xx_dvs_buck_regulator_ops, | |
868 | .type = REGULATOR_VOLTAGE, | |
869 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
870 | .linear_ranges = bd718xx_dvs_buck_volts, | |
871 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
872 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
873 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
874 | .enable_reg = BD718XX_REG_BUCK1_CTRL, | |
875 | .enable_mask = BD718XX_BUCK_EN, | |
876 | .owner = THIS_MODULE, | |
21b72156 MV |
877 | .of_parse_cb = buck_set_hw_dvs_levels, |
878 | }, | |
879 | .dvs = { | |
880 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE | | |
881 | ROHM_DVS_LEVEL_SUSPEND, | |
882 | .run_reg = BD718XX_REG_BUCK1_VOLT_RUN, | |
883 | .run_mask = DVS_BUCK_RUN_MASK, | |
884 | .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE, | |
885 | .idle_mask = DVS_BUCK_RUN_MASK, | |
886 | .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP, | |
887 | .suspend_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
888 | }, |
889 | .init = { | |
890 | .reg = BD718XX_REG_BUCK1_CTRL, | |
891 | .mask = BD718XX_BUCK_SEL, | |
892 | .val = BD718XX_BUCK_SEL, | |
893 | }, | |
894 | }, | |
895 | { | |
896 | .desc = { | |
897 | .name = "buck2", | |
898 | .of_match = of_match_ptr("BUCK2"), | |
899 | .regulators_node = of_match_ptr("regulators"), | |
900 | .id = BD718XX_BUCK2, | |
901 | .ops = &bd718xx_dvs_buck_regulator_ops, | |
902 | .type = REGULATOR_VOLTAGE, | |
903 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
904 | .linear_ranges = bd718xx_dvs_buck_volts, | |
905 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
906 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
907 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
908 | .enable_reg = BD718XX_REG_BUCK2_CTRL, | |
909 | .enable_mask = BD718XX_BUCK_EN, | |
910 | .owner = THIS_MODULE, | |
21b72156 MV |
911 | .of_parse_cb = buck_set_hw_dvs_levels, |
912 | }, | |
913 | .dvs = { | |
914 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE, | |
915 | .run_reg = BD718XX_REG_BUCK2_VOLT_RUN, | |
916 | .run_mask = DVS_BUCK_RUN_MASK, | |
917 | .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE, | |
918 | .idle_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
919 | }, |
920 | .init = { | |
921 | .reg = BD718XX_REG_BUCK2_CTRL, | |
922 | .mask = BD718XX_BUCK_SEL, | |
923 | .val = BD718XX_BUCK_SEL, | |
924 | }, | |
925 | }, | |
926 | { | |
927 | .desc = { | |
928 | .name = "buck3", | |
929 | .of_match = of_match_ptr("BUCK3"), | |
930 | .regulators_node = of_match_ptr("regulators"), | |
931 | .id = BD718XX_BUCK3, | |
932 | .ops = &bd718xx_dvs_buck_regulator_ops, | |
933 | .type = REGULATOR_VOLTAGE, | |
934 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
935 | .linear_ranges = bd718xx_dvs_buck_volts, | |
936 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
937 | .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN, | |
938 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
939 | .enable_reg = BD71837_REG_BUCK3_CTRL, | |
940 | .enable_mask = BD718XX_BUCK_EN, | |
941 | .owner = THIS_MODULE, | |
21b72156 MV |
942 | .of_parse_cb = buck_set_hw_dvs_levels, |
943 | }, | |
944 | .dvs = { | |
945 | .level_map = ROHM_DVS_LEVEL_RUN, | |
946 | .run_reg = BD71837_REG_BUCK3_VOLT_RUN, | |
947 | .run_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
948 | }, |
949 | .init = { | |
950 | .reg = BD71837_REG_BUCK3_CTRL, | |
951 | .mask = BD718XX_BUCK_SEL, | |
952 | .val = BD718XX_BUCK_SEL, | |
953 | }, | |
954 | }, | |
955 | { | |
956 | .desc = { | |
957 | .name = "buck4", | |
958 | .of_match = of_match_ptr("BUCK4"), | |
959 | .regulators_node = of_match_ptr("regulators"), | |
960 | .id = BD718XX_BUCK4, | |
961 | .ops = &bd718xx_dvs_buck_regulator_ops, | |
962 | .type = REGULATOR_VOLTAGE, | |
963 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, | |
964 | .linear_ranges = bd718xx_dvs_buck_volts, | |
965 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), | |
966 | .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN, | |
967 | .vsel_mask = DVS_BUCK_RUN_MASK, | |
968 | .enable_reg = BD71837_REG_BUCK4_CTRL, | |
969 | .enable_mask = BD718XX_BUCK_EN, | |
970 | .owner = THIS_MODULE, | |
21b72156 MV |
971 | .of_parse_cb = buck_set_hw_dvs_levels, |
972 | }, | |
973 | .dvs = { | |
974 | .level_map = ROHM_DVS_LEVEL_RUN, | |
975 | .run_reg = BD71837_REG_BUCK4_VOLT_RUN, | |
976 | .run_mask = DVS_BUCK_RUN_MASK, | |
494edd26 MV |
977 | }, |
978 | .init = { | |
979 | .reg = BD71837_REG_BUCK4_CTRL, | |
980 | .mask = BD718XX_BUCK_SEL, | |
981 | .val = BD718XX_BUCK_SEL, | |
982 | }, | |
ba08799e MV |
983 | }, |
984 | { | |
494edd26 MV |
985 | .desc = { |
986 | .name = "buck5", | |
987 | .of_match = of_match_ptr("BUCK5"), | |
988 | .regulators_node = of_match_ptr("regulators"), | |
989 | .id = BD718XX_BUCK5, | |
f0ca7b24 | 990 | .ops = &bd71837_pickable_range_buck_ops, |
494edd26 | 991 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
992 | .n_voltages = BD71837_BUCK5_VOLTAGE_NUM, |
993 | .linear_ranges = bd71837_buck5_volts, | |
494edd26 | 994 | .n_linear_ranges = |
a4bfc2c2 | 995 | ARRAY_SIZE(bd71837_buck5_volts), |
494edd26 | 996 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
a4bfc2c2 MV |
997 | .vsel_mask = BD71837_BUCK5_MASK, |
998 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, | |
999 | .vsel_range_mask = BD71837_BUCK5_RANGE_MASK, | |
1000 | .linear_range_selectors = bd71837_buck5_volt_range_sel, | |
494edd26 MV |
1001 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
1002 | .enable_mask = BD718XX_BUCK_EN, | |
1003 | .owner = THIS_MODULE, | |
1004 | }, | |
1005 | .init = { | |
1006 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, | |
1007 | .mask = BD718XX_BUCK_SEL, | |
1008 | .val = BD718XX_BUCK_SEL, | |
1009 | }, | |
ba08799e MV |
1010 | }, |
1011 | { | |
494edd26 MV |
1012 | .desc = { |
1013 | .name = "buck6", | |
1014 | .of_match = of_match_ptr("BUCK6"), | |
1015 | .regulators_node = of_match_ptr("regulators"), | |
1016 | .id = BD718XX_BUCK6, | |
f0ca7b24 | 1017 | .ops = &bd71837_buck_regulator_ops, |
494edd26 MV |
1018 | .type = REGULATOR_VOLTAGE, |
1019 | .n_voltages = BD71837_BUCK6_VOLTAGE_NUM, | |
a4bfc2c2 | 1020 | .linear_ranges = bd71837_buck6_volts, |
494edd26 | 1021 | .n_linear_ranges = |
a4bfc2c2 | 1022 | ARRAY_SIZE(bd71837_buck6_volts), |
494edd26 MV |
1023 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
1024 | .vsel_mask = BD71837_BUCK6_MASK, | |
1025 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, | |
1026 | .enable_mask = BD718XX_BUCK_EN, | |
1027 | .owner = THIS_MODULE, | |
1028 | }, | |
1029 | .init = { | |
1030 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, | |
1031 | .mask = BD718XX_BUCK_SEL, | |
1032 | .val = BD718XX_BUCK_SEL, | |
1033 | }, | |
ba08799e MV |
1034 | }, |
1035 | { | |
494edd26 MV |
1036 | .desc = { |
1037 | .name = "buck7", | |
1038 | .of_match = of_match_ptr("BUCK7"), | |
1039 | .regulators_node = of_match_ptr("regulators"), | |
1040 | .id = BD718XX_BUCK7, | |
f0ca7b24 | 1041 | .ops = &bd71837_buck_regulator_nolinear_ops, |
494edd26 MV |
1042 | .type = REGULATOR_VOLTAGE, |
1043 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], | |
1044 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), | |
1045 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, | |
1046 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, | |
1047 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
1048 | .enable_mask = BD718XX_BUCK_EN, | |
1049 | .owner = THIS_MODULE, | |
1050 | }, | |
1051 | .init = { | |
1052 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, | |
1053 | .mask = BD718XX_BUCK_SEL, | |
1054 | .val = BD718XX_BUCK_SEL, | |
1055 | }, | |
ba08799e MV |
1056 | }, |
1057 | { | |
494edd26 MV |
1058 | .desc = { |
1059 | .name = "buck8", | |
1060 | .of_match = of_match_ptr("BUCK8"), | |
1061 | .regulators_node = of_match_ptr("regulators"), | |
1062 | .id = BD718XX_BUCK8, | |
f0ca7b24 | 1063 | .ops = &bd71837_buck_regulator_ops, |
494edd26 | 1064 | .type = REGULATOR_VOLTAGE, |
dd2be639 | 1065 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
494edd26 MV |
1066 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
1067 | .n_linear_ranges = | |
1068 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), | |
1069 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, | |
1070 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, | |
1071 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
1072 | .enable_mask = BD718XX_BUCK_EN, | |
1073 | .owner = THIS_MODULE, | |
1074 | }, | |
1075 | .init = { | |
1076 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, | |
1077 | .mask = BD718XX_BUCK_SEL, | |
1078 | .val = BD718XX_BUCK_SEL, | |
1079 | }, | |
1080 | }, | |
1081 | { | |
1082 | .desc = { | |
1083 | .name = "ldo1", | |
1084 | .of_match = of_match_ptr("LDO1"), | |
1085 | .regulators_node = of_match_ptr("regulators"), | |
1086 | .id = BD718XX_LDO1, | |
9bcbabaf | 1087 | .ops = &bd71837_pickable_range_ldo_ops, |
494edd26 MV |
1088 | .type = REGULATOR_VOLTAGE, |
1089 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, | |
1090 | .linear_ranges = bd718xx_ldo1_volts, | |
1091 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), | |
1092 | .vsel_reg = BD718XX_REG_LDO1_VOLT, | |
1093 | .vsel_mask = BD718XX_LDO1_MASK, | |
a4bfc2c2 MV |
1094 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
1095 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, | |
1096 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, | |
494edd26 MV |
1097 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
1098 | .enable_mask = BD718XX_LDO_EN, | |
1099 | .owner = THIS_MODULE, | |
1100 | }, | |
1101 | .init = { | |
1102 | .reg = BD718XX_REG_LDO1_VOLT, | |
1103 | .mask = BD718XX_LDO_SEL, | |
1104 | .val = BD718XX_LDO_SEL, | |
1105 | }, | |
1106 | }, | |
1107 | { | |
1108 | .desc = { | |
1109 | .name = "ldo2", | |
1110 | .of_match = of_match_ptr("LDO2"), | |
1111 | .regulators_node = of_match_ptr("regulators"), | |
1112 | .id = BD718XX_LDO2, | |
9bcbabaf | 1113 | .ops = &bd71837_ldo_regulator_nolinear_ops, |
494edd26 MV |
1114 | .type = REGULATOR_VOLTAGE, |
1115 | .volt_table = &ldo_2_volts[0], | |
1116 | .vsel_reg = BD718XX_REG_LDO2_VOLT, | |
1117 | .vsel_mask = BD718XX_LDO2_MASK, | |
1118 | .n_voltages = ARRAY_SIZE(ldo_2_volts), | |
1119 | .enable_reg = BD718XX_REG_LDO2_VOLT, | |
1120 | .enable_mask = BD718XX_LDO_EN, | |
1121 | .owner = THIS_MODULE, | |
1122 | }, | |
1123 | .init = { | |
1124 | .reg = BD718XX_REG_LDO2_VOLT, | |
1125 | .mask = BD718XX_LDO_SEL, | |
1126 | .val = BD718XX_LDO_SEL, | |
1127 | }, | |
1128 | }, | |
1129 | { | |
1130 | .desc = { | |
1131 | .name = "ldo3", | |
1132 | .of_match = of_match_ptr("LDO3"), | |
1133 | .regulators_node = of_match_ptr("regulators"), | |
1134 | .id = BD718XX_LDO3, | |
9bcbabaf | 1135 | .ops = &bd71837_ldo_regulator_ops, |
494edd26 MV |
1136 | .type = REGULATOR_VOLTAGE, |
1137 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, | |
1138 | .linear_ranges = bd718xx_ldo3_volts, | |
1139 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), | |
1140 | .vsel_reg = BD718XX_REG_LDO3_VOLT, | |
1141 | .vsel_mask = BD718XX_LDO3_MASK, | |
1142 | .enable_reg = BD718XX_REG_LDO3_VOLT, | |
1143 | .enable_mask = BD718XX_LDO_EN, | |
1144 | .owner = THIS_MODULE, | |
1145 | }, | |
1146 | .init = { | |
1147 | .reg = BD718XX_REG_LDO3_VOLT, | |
1148 | .mask = BD718XX_LDO_SEL, | |
1149 | .val = BD718XX_LDO_SEL, | |
1150 | }, | |
1151 | }, | |
1152 | { | |
1153 | .desc = { | |
1154 | .name = "ldo4", | |
1155 | .of_match = of_match_ptr("LDO4"), | |
1156 | .regulators_node = of_match_ptr("regulators"), | |
1157 | .id = BD718XX_LDO4, | |
9bcbabaf | 1158 | .ops = &bd71837_ldo_regulator_ops, |
494edd26 MV |
1159 | .type = REGULATOR_VOLTAGE, |
1160 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, | |
1161 | .linear_ranges = bd718xx_ldo4_volts, | |
1162 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), | |
1163 | .vsel_reg = BD718XX_REG_LDO4_VOLT, | |
1164 | .vsel_mask = BD718XX_LDO4_MASK, | |
1165 | .enable_reg = BD718XX_REG_LDO4_VOLT, | |
1166 | .enable_mask = BD718XX_LDO_EN, | |
1167 | .owner = THIS_MODULE, | |
1168 | }, | |
1169 | .init = { | |
1170 | .reg = BD718XX_REG_LDO4_VOLT, | |
1171 | .mask = BD718XX_LDO_SEL, | |
1172 | .val = BD718XX_LDO_SEL, | |
1173 | }, | |
1174 | }, | |
1175 | { | |
1176 | .desc = { | |
1177 | .name = "ldo5", | |
1178 | .of_match = of_match_ptr("LDO5"), | |
1179 | .regulators_node = of_match_ptr("regulators"), | |
1180 | .id = BD718XX_LDO5, | |
9bcbabaf | 1181 | .ops = &bd71837_ldo_regulator_ops, |
494edd26 | 1182 | .type = REGULATOR_VOLTAGE, |
a4bfc2c2 MV |
1183 | .n_voltages = BD71837_LDO5_VOLTAGE_NUM, |
1184 | .linear_ranges = bd71837_ldo5_volts, | |
1185 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts), | |
494edd26 MV |
1186 | /* LDO5 is supplied by buck6 */ |
1187 | .supply_name = "buck6", | |
1188 | .vsel_reg = BD718XX_REG_LDO5_VOLT, | |
1189 | .vsel_mask = BD71837_LDO5_MASK, | |
1190 | .enable_reg = BD718XX_REG_LDO5_VOLT, | |
1191 | .enable_mask = BD718XX_LDO_EN, | |
1192 | .owner = THIS_MODULE, | |
1193 | }, | |
1194 | .init = { | |
1195 | .reg = BD718XX_REG_LDO5_VOLT, | |
1196 | .mask = BD718XX_LDO_SEL, | |
1197 | .val = BD718XX_LDO_SEL, | |
1198 | }, | |
1199 | .additional_inits = bd71837_ldo5_inits, | |
1200 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits), | |
1201 | }, | |
1202 | { | |
1203 | .desc = { | |
1204 | .name = "ldo6", | |
1205 | .of_match = of_match_ptr("LDO6"), | |
1206 | .regulators_node = of_match_ptr("regulators"), | |
1207 | .id = BD718XX_LDO6, | |
9bcbabaf | 1208 | .ops = &bd71837_ldo_regulator_ops, |
494edd26 MV |
1209 | .type = REGULATOR_VOLTAGE, |
1210 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, | |
1211 | .linear_ranges = bd718xx_ldo6_volts, | |
1212 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), | |
1213 | /* LDO6 is supplied by buck7 */ | |
1214 | .supply_name = "buck7", | |
1215 | .vsel_reg = BD718XX_REG_LDO6_VOLT, | |
1216 | .vsel_mask = BD718XX_LDO6_MASK, | |
1217 | .enable_reg = BD718XX_REG_LDO6_VOLT, | |
1218 | .enable_mask = BD718XX_LDO_EN, | |
1219 | .owner = THIS_MODULE, | |
1220 | }, | |
1221 | .init = { | |
1222 | .reg = BD718XX_REG_LDO6_VOLT, | |
1223 | .mask = BD718XX_LDO_SEL, | |
1224 | .val = BD718XX_LDO_SEL, | |
1225 | }, | |
1226 | .additional_inits = bd71837_ldo6_inits, | |
1227 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits), | |
1228 | }, | |
1229 | { | |
1230 | .desc = { | |
1231 | .name = "ldo7", | |
1232 | .of_match = of_match_ptr("LDO7"), | |
1233 | .regulators_node = of_match_ptr("regulators"), | |
1234 | .id = BD718XX_LDO7, | |
9bcbabaf | 1235 | .ops = &bd71837_ldo_regulator_ops, |
494edd26 MV |
1236 | .type = REGULATOR_VOLTAGE, |
1237 | .n_voltages = BD71837_LDO7_VOLTAGE_NUM, | |
1238 | .linear_ranges = bd71837_ldo7_volts, | |
1239 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts), | |
1240 | .vsel_reg = BD71837_REG_LDO7_VOLT, | |
1241 | .vsel_mask = BD71837_LDO7_MASK, | |
1242 | .enable_reg = BD71837_REG_LDO7_VOLT, | |
1243 | .enable_mask = BD718XX_LDO_EN, | |
1244 | .owner = THIS_MODULE, | |
1245 | }, | |
1246 | .init = { | |
1247 | .reg = BD71837_REG_LDO7_VOLT, | |
1248 | .mask = BD718XX_LDO_SEL, | |
1249 | .val = BD718XX_LDO_SEL, | |
1250 | }, | |
ba08799e MV |
1251 | }, |
1252 | }; | |
1253 | ||
dd2be639 | 1254 | static int bd718xx_probe(struct platform_device *pdev) |
ba08799e | 1255 | { |
bcb047eb | 1256 | struct bd718xx *mfd; |
ba08799e | 1257 | struct regulator_config config = { 0 }; |
494edd26 | 1258 | int i, j, err; |
049369d4 | 1259 | bool use_snvs; |
b389ceae AL |
1260 | const struct bd718xx_regulator_data *reg_data; |
1261 | unsigned int num_reg_data; | |
1b1c26b2 | 1262 | enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; |
ba08799e | 1263 | |
bcb047eb AL |
1264 | mfd = dev_get_drvdata(pdev->dev.parent); |
1265 | if (!mfd) { | |
ba08799e MV |
1266 | dev_err(&pdev->dev, "No MFD driver data\n"); |
1267 | err = -EINVAL; | |
1268 | goto err; | |
1269 | } | |
bcb047eb | 1270 | |
af32f3a4 | 1271 | switch (chip) { |
b389ceae AL |
1272 | case ROHM_CHIP_TYPE_BD71837: |
1273 | reg_data = bd71837_regulators; | |
1274 | num_reg_data = ARRAY_SIZE(bd71837_regulators); | |
1275 | break; | |
1276 | case ROHM_CHIP_TYPE_BD71847: | |
1277 | reg_data = bd71847_regulators; | |
1278 | num_reg_data = ARRAY_SIZE(bd71847_regulators); | |
1279 | break; | |
1280 | default: | |
494edd26 MV |
1281 | dev_err(&pdev->dev, "Unsupported chip type\n"); |
1282 | err = -EINVAL; | |
1283 | goto err; | |
1284 | } | |
1285 | ||
ba08799e | 1286 | /* Register LOCK release */ |
2a6a7aac | 1287 | err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK, |
ba08799e MV |
1288 | (REGLOCK_PWRSEQ | REGLOCK_VREG), 0); |
1289 | if (err) { | |
bcb047eb | 1290 | dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err); |
ba08799e MV |
1291 | goto err; |
1292 | } else { | |
bcb047eb | 1293 | dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", |
494edd26 | 1294 | BD718XX_REG_REGLOCK); |
823f18f8 MV |
1295 | } |
1296 | ||
049369d4 MV |
1297 | use_snvs = of_property_read_bool(pdev->dev.parent->of_node, |
1298 | "rohm,reset-snvs-powered"); | |
1299 | ||
1300 | /* | |
e770b18b MV |
1301 | * Change the next stage from poweroff to be READY instead of SNVS |
1302 | * for all reset types because OTP loading at READY will clear SEL | |
1303 | * bit allowing HW defaults for power rails to be used | |
1304 | */ | |
049369d4 | 1305 | if (!use_snvs) { |
2a6a7aac MV |
1306 | err = regmap_update_bits(mfd->chip.regmap, |
1307 | BD718XX_REG_TRANS_COND1, | |
049369d4 MV |
1308 | BD718XX_ON_REQ_POWEROFF_MASK | |
1309 | BD718XX_SWRESET_POWEROFF_MASK | | |
1310 | BD718XX_WDOG_POWEROFF_MASK | | |
1311 | BD718XX_KEY_L_POWEROFF_MASK, | |
1312 | BD718XX_POWOFF_TO_RDY); | |
1313 | if (err) { | |
1314 | dev_err(&pdev->dev, "Failed to change reset target\n"); | |
1315 | goto err; | |
1316 | } else { | |
1317 | dev_dbg(&pdev->dev, | |
1318 | "Changed all resets from SVNS to READY\n"); | |
1319 | } | |
e770b18b MV |
1320 | } |
1321 | ||
b389ceae | 1322 | for (i = 0; i < num_reg_data; i++) { |
ba08799e | 1323 | |
494edd26 | 1324 | const struct regulator_desc *desc; |
ba08799e | 1325 | struct regulator_dev *rdev; |
494edd26 | 1326 | const struct bd718xx_regulator_data *r; |
ba08799e | 1327 | |
b389ceae | 1328 | r = ®_data[i]; |
494edd26 | 1329 | desc = &r->desc; |
ba08799e | 1330 | |
ba08799e | 1331 | config.dev = pdev->dev.parent; |
2a6a7aac | 1332 | config.regmap = mfd->chip.regmap; |
ba08799e MV |
1333 | |
1334 | rdev = devm_regulator_register(&pdev->dev, desc, &config); | |
1335 | if (IS_ERR(rdev)) { | |
bcb047eb | 1336 | dev_err(&pdev->dev, |
ba08799e MV |
1337 | "failed to register %s regulator\n", |
1338 | desc->name); | |
1339 | err = PTR_ERR(rdev); | |
1340 | goto err; | |
1341 | } | |
049369d4 MV |
1342 | |
1343 | /* | |
1344 | * Regulator register gets the regulator constraints and | |
ba08799e MV |
1345 | * applies them (set_machine_constraints). This should have |
1346 | * turned the control register(s) to correct values and we | |
1347 | * can now switch the control from PMIC state machine to the | |
1348 | * register interface | |
049369d4 MV |
1349 | * |
1350 | * At poweroff transition PMIC HW disables EN bit for | |
1351 | * regulators but leaves SEL bit untouched. So if state | |
1352 | * transition from POWEROFF is done to SNVS - then all power | |
1353 | * rails controlled by SW (having SEL bit set) stay disabled | |
1354 | * as EN is cleared. This will result boot failure if any | |
1355 | * crucial systems are powered by these rails. We don't | |
1356 | * enable SW control for crucial regulators if snvs state is | |
1357 | * used | |
ba08799e | 1358 | */ |
049369d4 MV |
1359 | if (!use_snvs || !rdev->constraints->always_on || |
1360 | !rdev->constraints->boot_on) { | |
2a6a7aac | 1361 | err = regmap_update_bits(mfd->chip.regmap, r->init.reg, |
049369d4 MV |
1362 | r->init.mask, r->init.val); |
1363 | if (err) { | |
1364 | dev_err(&pdev->dev, | |
1365 | "Failed to take control for (%s)\n", | |
1366 | desc->name); | |
1367 | goto err; | |
1368 | } | |
ba08799e | 1369 | } |
494edd26 | 1370 | for (j = 0; j < r->additional_init_amnt; j++) { |
2a6a7aac | 1371 | err = regmap_update_bits(mfd->chip.regmap, |
494edd26 MV |
1372 | r->additional_inits[j].reg, |
1373 | r->additional_inits[j].mask, | |
1374 | r->additional_inits[j].val); | |
1375 | if (err) { | |
bcb047eb | 1376 | dev_err(&pdev->dev, |
494edd26 MV |
1377 | "Buck (%s) initialization failed\n", |
1378 | desc->name); | |
1379 | goto err; | |
1380 | } | |
1381 | } | |
ba08799e MV |
1382 | } |
1383 | ||
ba08799e MV |
1384 | err: |
1385 | return err; | |
1386 | } | |
1387 | ||
1b1c26b2 MV |
1388 | static const struct platform_device_id bd718x7_pmic_id[] = { |
1389 | { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 }, | |
1390 | { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 }, | |
1391 | { }, | |
1392 | }; | |
1393 | MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id); | |
1394 | ||
dd2be639 | 1395 | static struct platform_driver bd718xx_regulator = { |
ba08799e | 1396 | .driver = { |
494edd26 | 1397 | .name = "bd718xx-pmic", |
ba08799e | 1398 | }, |
dd2be639 | 1399 | .probe = bd718xx_probe, |
1b1c26b2 | 1400 | .id_table = bd718x7_pmic_id, |
ba08799e MV |
1401 | }; |
1402 | ||
dd2be639 | 1403 | module_platform_driver(bd718xx_regulator); |
ba08799e MV |
1404 | |
1405 | MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); | |
dd2be639 | 1406 | MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver"); |
ba08799e | 1407 | MODULE_LICENSE("GPL"); |
95bddd8b | 1408 | MODULE_ALIAS("platform:bd718xx-pmic"); |