1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Regulator driver for Rockchip RK805/RK808/RK818
4 *
5 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
6 * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
7 *
8 * Author: Chris Zhong <zyw@rock-chips.com>
9 * Author: Zhang Qing <zhangqing@rock-chips.com>
10 * Author: Xu Shengfei <xsf@rock-chips.com>
11 *
12 * Copyright (C) 2016 PHYTEC Messtechnik GmbH
13 *
14 * Author: Wadim Egorov <w.egorov@phytec.de>
15 */
16
17 #include <linux/delay.h>
18 #include <linux/module.h>
19 #include <linux/of.h>
20 #include <linux/mfd/rk808.h>
21 #include <linux/platform_device.h>
22 #include <linux/regulator/driver.h>
23 #include <linux/regulator/of_regulator.h>
24 #include <linux/gpio/consumer.h>
25
26 /* Field Definitions */
27 #define RK808_BUCK_VSEL_MASK 0x3f
28 #define RK808_BUCK4_VSEL_MASK 0xf
29 #define RK808_LDO_VSEL_MASK 0x1f
30
31 #define RK809_BUCK5_VSEL_MASK 0x7
32
33 #define RK817_LDO_VSEL_MASK 0x7f
34 #define RK817_BOOST_VSEL_MASK 0x7
35 #define RK817_BUCK_VSEL_MASK 0x7f
36
37 #define RK818_BUCK_VSEL_MASK 0x3f
38 #define RK818_BUCK4_VSEL_MASK 0x1f
39 #define RK818_LDO_VSEL_MASK 0x1f
40 #define RK818_LDO3_ON_VSEL_MASK 0xf
41 #define RK818_BOOST_ON_VSEL_MASK 0xe0
42
43 #define RK806_DCDC_SLP_REG_OFFSET 0x0A
44 #define RK806_NLDO_SLP_REG_OFFSET 0x05
45 #define RK806_PLDO_SLP_REG_OFFSET 0x06
46
47 #define RK806_BUCK_SEL_CNT 0xff
48 #define RK806_LDO_SEL_CNT 0xff
49
50 /* Ramp rate definitions for buck1 / buck2 only */
51 #define RK808_RAMP_RATE_OFFSET 3
52 #define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET)
53 #define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET)
54 #define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET)
55 #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET)
56 #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET)
57
58 #define RK808_DVS2_POL BIT(2)
59 #define RK808_DVS1_POL BIT(1)
60
61 /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */
62 #define RK808_SLP_REG_OFFSET 1
63
64 /* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */
65 #define RK808_DVS_REG_OFFSET 2
66
67 /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */
68 #define RK808_SLP_SET_OFF_REG_OFFSET 2
69
70 /* max steps for increase voltage of Buck1/2, equal 100mv*/
71 #define MAX_STEPS_ONE_TIME 8
72
73 #define ENABLE_MASK(id) (BIT(id) | BIT(4 + (id)))
74 #define DISABLE_VAL(id) (BIT(4 + (id)))
75
76 #define RK817_BOOST_DESC(_id, _match, _supply, _min, _max, _step, _vreg,\
77 _vmask, _ereg, _emask, _enval, _disval, _etime, m_drop) \
78 { \
79 .name = (_match), \
80 .supply_name = (_supply), \
81 .of_match = of_match_ptr(_match), \
82 .regulators_node = of_match_ptr("regulators"), \
83 .type = REGULATOR_VOLTAGE, \
84 .id = (_id), \
85 .n_voltages = (((_max) - (_min)) / (_step) + 1), \
86 .owner = THIS_MODULE, \
87 .min_uV = (_min) * 1000, \
88 .uV_step = (_step) * 1000, \
89 .vsel_reg = (_vreg), \
90 .vsel_mask = (_vmask), \
91 .enable_reg = (_ereg), \
92 .enable_mask = (_emask), \
93 .enable_val = (_enval), \
94 .disable_val = (_disval), \
95 .enable_time = (_etime), \
96 .min_dropout_uV = (m_drop) * 1000, \
97 .ops = &rk817_boost_ops, \
98 }
99
100 #define RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
101 _vmask, _ereg, _emask, _enval, _disval, _etime, _ops) \
102 { \
103 .name = (_match), \
104 .supply_name = (_supply), \
105 .of_match = of_match_ptr(_match), \
106 .regulators_node = of_match_ptr("regulators"), \
107 .type = REGULATOR_VOLTAGE, \
108 .id = (_id), \
109 .n_voltages = (((_max) - (_min)) / (_step) + 1), \
110 .owner = THIS_MODULE, \
111 .min_uV = (_min) * 1000, \
112 .uV_step = (_step) * 1000, \
113 .vsel_reg = (_vreg), \
114 .vsel_mask = (_vmask), \
115 .enable_reg = (_ereg), \
116 .enable_mask = (_emask), \
117 .enable_val = (_enval), \
118 .disable_val = (_disval), \
119 .enable_time = (_etime), \
120 .ops = _ops, \
121 }
122
123 #define RK805_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
124 _vmask, _ereg, _emask, _etime) \
125 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
126 _vmask, _ereg, _emask, 0, 0, _etime, &rk805_reg_ops)
127
128 #define RK806_REGULATOR(_name, _supply_name, _id, _ops,\
129 _n_voltages, _vr, _er, _lr, ctrl_bit,\
130 _rr, _rm, _rt)\
131 [_id] = {\
132 .name = _name,\
133 .supply_name = _supply_name,\
134 .of_match = of_match_ptr(_name),\
135 .regulators_node = of_match_ptr("regulators"),\
136 .id = _id,\
137 .ops = &_ops,\
138 .type = REGULATOR_VOLTAGE,\
139 .n_voltages = _n_voltages,\
140 .linear_ranges = _lr,\
141 .n_linear_ranges = ARRAY_SIZE(_lr),\
142 .vsel_reg = _vr,\
143 .vsel_mask = 0xff,\
144 .enable_reg = _er,\
145 .enable_mask = ENABLE_MASK(ctrl_bit),\
146 .enable_val = ENABLE_MASK(ctrl_bit),\
147 .disable_val = DISABLE_VAL(ctrl_bit),\
148 .of_map_mode = rk8xx_regulator_of_map_mode,\
149 .ramp_reg = _rr,\
150 .ramp_mask = _rm,\
151 .ramp_delay_table = _rt, \
152 .n_ramp_values = ARRAY_SIZE(_rt), \
153 .owner = THIS_MODULE,\
154 }
155
156 #define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
157 _vmask, _ereg, _emask, _etime) \
158 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
159 _vmask, _ereg, _emask, 0, 0, _etime, &rk808_reg_ops)
160
161 #define RK816_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
162 _vmask, _ereg, _emask, _disval, _etime) \
163 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
164 _vmask, _ereg, _emask, _emask, _disval, _etime, &rk816_reg_ops)
165
166 #define RK817_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
167 _vmask, _ereg, _emask, _disval, _etime) \
168 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
169 _vmask, _ereg, _emask, _emask, _disval, _etime, &rk817_reg_ops)
170
171 #define RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
172 _enval, _disval, _ops) \
173 { \
174 .name = (_match), \
175 .supply_name = (_supply), \
176 .of_match = of_match_ptr(_match), \
177 .regulators_node = of_match_ptr("regulators"), \
178 .type = REGULATOR_VOLTAGE, \
179 .id = (_id), \
180 .enable_reg = (_ereg), \
181 .enable_mask = (_emask), \
182 .enable_val = (_enval), \
183 .disable_val = (_disval), \
184 .owner = THIS_MODULE, \
185 .ops = _ops \
186 }
187
188 #define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask, \
189 _disval) \
190 RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
191 _emask, _disval, &rk817_switch_ops)
192
193 #define RK8XX_DESC_SWITCH(_id, _match, _supply, _ereg, _emask) \
194 RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
195 0, 0, &rk808_switch_ops)
196
197 struct rk8xx_register_bit {
198 u8 reg;
199 u8 bit;
200 };
201
202 #define RK8XX_REG_BIT(_reg, _bit) \
203 { \
204 .reg = _reg, \
205 .bit = BIT(_bit), \
206 }
207
208 struct rk808_regulator_data {
209 struct gpio_desc *dvs_gpio[2];
210 };
211
212 static const struct linear_range rk808_ldo3_voltage_ranges[] = {
213 REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000),
214 REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
215 };
216
217 #define RK809_BUCK5_SEL_CNT (8)
218
219 static const struct linear_range rk809_buck5_voltage_ranges[] = {
220 REGULATOR_LINEAR_RANGE(1500000, 0, 0, 0),
221 REGULATOR_LINEAR_RANGE(1800000, 1, 3, 200000),
222 REGULATOR_LINEAR_RANGE(2800000, 4, 5, 200000),
223 REGULATOR_LINEAR_RANGE(3300000, 6, 7, 300000),
224 };
225
226 #define RK817_BUCK1_MIN0 500000
227 #define RK817_BUCK1_MAX0 1500000
228
229 #define RK817_BUCK1_MIN1 1600000
230 #define RK817_BUCK1_MAX1 2400000
231
232 #define RK817_BUCK3_MAX1 3400000
233
234 #define RK817_BUCK1_STP0 12500
235 #define RK817_BUCK1_STP1 100000
236
237 #define RK817_BUCK1_SEL0 ((RK817_BUCK1_MAX0 - RK817_BUCK1_MIN0) /\
238 RK817_BUCK1_STP0)
239 #define RK817_BUCK1_SEL1 ((RK817_BUCK1_MAX1 - RK817_BUCK1_MIN1) /\
240 RK817_BUCK1_STP1)
241
242 #define RK817_BUCK3_SEL1 ((RK817_BUCK3_MAX1 - RK817_BUCK1_MIN1) /\
243 RK817_BUCK1_STP1)
244
245 #define RK817_BUCK1_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK1_SEL1 + 1)
246 #define RK817_BUCK3_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK3_SEL1 + 1)
247
248 static const struct linear_range rk817_buck1_voltage_ranges[] = {
249 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
250 RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
251 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
252 RK817_BUCK1_SEL_CNT, RK817_BUCK1_STP1),
253 };
254
255 static const struct linear_range rk817_buck3_voltage_ranges[] = {
256 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
257 RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
258 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
259 RK817_BUCK3_SEL_CNT, RK817_BUCK1_STP1),
260 };
261
262 static const unsigned int rk808_buck1_2_ramp_table[] = {
263 2000, 4000, 6000, 10000
264 };
265
266 /* RK817/RK809/RK816 (buck 1/2 only) */
267 static const unsigned int rk817_buck1_4_ramp_table[] = {
268 3000, 6300, 12500, 25000
269 };
270
rk806_set_mode_dcdc(struct regulator_dev * rdev,unsigned int mode)271 static int rk806_set_mode_dcdc(struct regulator_dev *rdev, unsigned int mode)
272 {
273 int rid = rdev_get_id(rdev);
274 int ctr_bit, reg;
275
276 reg = RK806_POWER_FPWM_EN0 + rid / 8;
277 ctr_bit = rid % 8;
278
279 switch (mode) {
280 case REGULATOR_MODE_FAST:
281 return regmap_update_bits(rdev->regmap, reg,
282 PWM_MODE_MSK << ctr_bit,
283 FPWM_MODE << ctr_bit);
284 case REGULATOR_MODE_NORMAL:
285 return regmap_update_bits(rdev->regmap, reg,
286 PWM_MODE_MSK << ctr_bit,
287 AUTO_PWM_MODE << ctr_bit);
288 default:
289 dev_err(rdev_get_dev(rdev), "mode unsupported: %u\n", mode);
290 return -EINVAL;
291 }
292
293 return 0;
294 }
295
rk806_get_mode_dcdc(struct regulator_dev * rdev)296 static unsigned int rk806_get_mode_dcdc(struct regulator_dev *rdev)
297 {
298 int rid = rdev_get_id(rdev);
299 int ctr_bit, reg;
300 unsigned int val;
301 int err;
302
303 reg = RK806_POWER_FPWM_EN0 + rid / 8;
304 ctr_bit = rid % 8;
305
306 err = regmap_read(rdev->regmap, reg, &val);
307 if (err)
308 return err;
309
310 if ((val >> ctr_bit) & FPWM_MODE)
311 return REGULATOR_MODE_FAST;
312 else
313 return REGULATOR_MODE_NORMAL;
314 }
315
316 static const struct rk8xx_register_bit rk806_dcdc_rate2[] = {
317 RK8XX_REG_BIT(0xEB, 0),
318 RK8XX_REG_BIT(0xEB, 1),
319 RK8XX_REG_BIT(0xEB, 2),
320 RK8XX_REG_BIT(0xEB, 3),
321 RK8XX_REG_BIT(0xEB, 4),
322 RK8XX_REG_BIT(0xEB, 5),
323 RK8XX_REG_BIT(0xEB, 6),
324 RK8XX_REG_BIT(0xEB, 7),
325 RK8XX_REG_BIT(0xEA, 0),
326 RK8XX_REG_BIT(0xEA, 1),
327 };
328
329 static const unsigned int rk806_ramp_delay_table_dcdc[] = {
330 50000, 25000, 12500, 6250, 3125, 1560, 961, 390
331 };
332
rk806_set_ramp_delay_dcdc(struct regulator_dev * rdev,int ramp_delay)333 static int rk806_set_ramp_delay_dcdc(struct regulator_dev *rdev, int ramp_delay)
334 {
335 int rid = rdev_get_id(rdev);
336 int regval, ramp_value, ret;
337
338 ret = regulator_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
339 rdev->desc->n_ramp_values, &ramp_value);
340 if (ret) {
341 dev_warn(rdev_get_dev(rdev),
342 "Can't set ramp-delay %u, setting %u\n", ramp_delay,
343 rdev->desc->ramp_delay_table[ramp_value]);
344 }
345
346 regval = ramp_value << (ffs(rdev->desc->ramp_mask) - 1);
347
348 ret = regmap_update_bits(rdev->regmap, rdev->desc->ramp_reg,
349 rdev->desc->ramp_mask, regval);
350 if (ret)
351 return ret;
352
353 /*
354 * The above is effectively a copy of regulator_set_ramp_delay_regmap(),
355 * but that only stores the lower 2 bits for rk806 DCDC ramp. The MSB must
356 * be stored in a separate register, so this open codes the implementation
357 * to have access to the ramp_value.
358 */
359
360 regval = (ramp_value >> 2) & 0x1 ? rk806_dcdc_rate2[rid].bit : 0;
361 return regmap_update_bits(rdev->regmap, rk806_dcdc_rate2[rid].reg,
362 rk806_dcdc_rate2[rid].bit,
363 regval);
364 }
365
366 static const unsigned int rk806_ramp_delay_table_ldo[] = {
367 100000, 50000, 25000, 12500, 6280, 3120, 1900, 780
368 };
369
rk806_set_suspend_voltage_range(struct regulator_dev * rdev,int reg_offset,int uv)370 static int rk806_set_suspend_voltage_range(struct regulator_dev *rdev, int reg_offset, int uv)
371 {
372 int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
373 unsigned int reg;
374
375 if (sel < 0)
376 return -EINVAL;
377
378 reg = rdev->desc->vsel_reg + reg_offset;
379
380 return regmap_update_bits(rdev->regmap, reg, rdev->desc->vsel_mask, sel);
381 }
382
rk806_set_suspend_voltage_range_dcdc(struct regulator_dev * rdev,int uv)383 static int rk806_set_suspend_voltage_range_dcdc(struct regulator_dev *rdev, int uv)
384 {
385 return rk806_set_suspend_voltage_range(rdev, RK806_DCDC_SLP_REG_OFFSET, uv);
386 }
387
rk806_set_suspend_voltage_range_nldo(struct regulator_dev * rdev,int uv)388 static int rk806_set_suspend_voltage_range_nldo(struct regulator_dev *rdev, int uv)
389 {
390 return rk806_set_suspend_voltage_range(rdev, RK806_NLDO_SLP_REG_OFFSET, uv);
391 }
392
rk806_set_suspend_voltage_range_pldo(struct regulator_dev * rdev,int uv)393 static int rk806_set_suspend_voltage_range_pldo(struct regulator_dev *rdev, int uv)
394 {
395 return rk806_set_suspend_voltage_range(rdev, RK806_PLDO_SLP_REG_OFFSET, uv);
396 }
397
rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev * rdev)398 static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
399 {
400 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
401 int id = rdev_get_id(rdev);
402 struct gpio_desc *gpio = pdata->dvs_gpio[id];
403 unsigned int val;
404 int ret;
405
406 if (!gpio || gpiod_get_value(gpio) == 0)
407 return regulator_get_voltage_sel_regmap(rdev);
408
409 ret = regmap_read(rdev->regmap,
410 rdev->desc->vsel_reg + RK808_DVS_REG_OFFSET,
411 &val);
412 if (ret != 0)
413 return ret;
414
415 val &= rdev->desc->vsel_mask;
416 val >>= ffs(rdev->desc->vsel_mask) - 1;
417
418 return val;
419 }
420
rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev * rdev,unsigned sel)421 static int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev *rdev,
422 unsigned sel)
423 {
424 int ret, delta_sel;
425 unsigned int old_sel, tmp, val, mask = rdev->desc->vsel_mask;
426
427 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
428 if (ret != 0)
429 return ret;
430
431 tmp = val & ~mask;
432 old_sel = val & mask;
433 old_sel >>= ffs(mask) - 1;
434 delta_sel = sel - old_sel;
435
436 /*
437 * If directly modify the register to change the voltage, we will face
438 * the risk of overshoot. Put it into a multi-step, can effectively
439 * avoid this problem, a step is 100mv here.
440 */
441 while (delta_sel > MAX_STEPS_ONE_TIME) {
442 old_sel += MAX_STEPS_ONE_TIME;
443 val = old_sel << (ffs(mask) - 1);
444 val |= tmp;
445
446 /*
447 * i2c is 400kHz (2.5us per bit) and we must transmit _at least_
448 * 3 bytes (24 bits) plus start and stop so 26 bits. So we've
449 * got more than 65 us between each voltage change and thus
450 * won't ramp faster than ~1500 uV / us.
451 */
452 ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
453 delta_sel = sel - old_sel;
454 }
455
456 sel <<= ffs(mask) - 1;
457 val = tmp | sel;
458 ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
459
460 /*
461 * When we change the voltage register directly, the ramp rate is about
462 * 100000uv/us, wait 1us to make sure the target voltage to be stable,
463 * so we needn't wait extra time after that.
464 */
465 udelay(1);
466
467 return ret;
468 }
469
rk808_buck1_2_set_voltage_sel(struct regulator_dev * rdev,unsigned sel)470 static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev,
471 unsigned sel)
472 {
473 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
474 int id = rdev_get_id(rdev);
475 struct gpio_desc *gpio = pdata->dvs_gpio[id];
476 unsigned int reg = rdev->desc->vsel_reg;
477 unsigned old_sel;
478 int ret, gpio_level;
479
480 if (!gpio)
481 return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel);
482
483 gpio_level = gpiod_get_value(gpio);
484 if (gpio_level == 0) {
485 reg += RK808_DVS_REG_OFFSET;
486 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &old_sel);
487 } else {
488 ret = regmap_read(rdev->regmap,
489 reg + RK808_DVS_REG_OFFSET,
490 &old_sel);
491 }
492
493 if (ret != 0)
494 return ret;
495
496 sel <<= ffs(rdev->desc->vsel_mask) - 1;
497 sel |= old_sel & ~rdev->desc->vsel_mask;
498
499 ret = regmap_write(rdev->regmap, reg, sel);
500 if (ret)
501 return ret;
502
503 gpiod_set_value(gpio, !gpio_level);
504
505 return ret;
506 }
507
rk808_buck1_2_set_voltage_time_sel(struct regulator_dev * rdev,unsigned int old_selector,unsigned int new_selector)508 static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
509 unsigned int old_selector,
510 unsigned int new_selector)
511 {
512 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
513 int id = rdev_get_id(rdev);
514 struct gpio_desc *gpio = pdata->dvs_gpio[id];
515
516 /* if there is no dvs1/2 pin, we don't need wait extra time here. */
517 if (!gpio)
518 return 0;
519
520 return regulator_set_voltage_time_sel(rdev, old_selector, new_selector);
521 }
522
rk808_set_suspend_voltage(struct regulator_dev * rdev,int uv)523 static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
524 {
525 unsigned int reg;
526 int sel = regulator_map_voltage_linear(rdev, uv, uv);
527
528 if (sel < 0)
529 return -EINVAL;
530
531 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
532
533 return regmap_update_bits(rdev->regmap, reg,
534 rdev->desc->vsel_mask,
535 sel);
536 }
537
rk808_set_suspend_voltage_range(struct regulator_dev * rdev,int uv)538 static int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv)
539 {
540 unsigned int reg;
541 int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
542 int ret;
543
544 if (sel < 0)
545 return -EINVAL;
546
547 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
548
549 ret = regmap_update_bits(rdev->regmap, reg,
550 rdev->desc->vsel_mask,
551 sel);
552 if (ret)
553 return ret;
554
555 if (rdev->desc->apply_bit)
556 ret = regmap_update_bits(rdev->regmap, rdev->desc->apply_reg,
557 rdev->desc->apply_bit,
558 rdev->desc->apply_bit);
559
560 return ret;
561 }
562
rk805_set_suspend_enable(struct regulator_dev * rdev)563 static int rk805_set_suspend_enable(struct regulator_dev *rdev)
564 {
565 unsigned int reg;
566
567 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
568
569 return regmap_update_bits(rdev->regmap, reg,
570 rdev->desc->enable_mask,
571 rdev->desc->enable_mask);
572 }
573
rk805_set_suspend_disable(struct regulator_dev * rdev)574 static int rk805_set_suspend_disable(struct regulator_dev *rdev)
575 {
576 unsigned int reg;
577
578 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
579
580 return regmap_update_bits(rdev->regmap, reg,
581 rdev->desc->enable_mask,
582 0);
583 }
584
585 static const struct rk8xx_register_bit rk806_suspend_bits[] = {
586 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 0),
587 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 1),
588 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 2),
589 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 3),
590 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 4),
591 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 5),
592 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 6),
593 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 7),
594 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 6),
595 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 7),
596 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 0),
597 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 1),
598 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 2),
599 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 3),
600 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 4),
601 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 1),
602 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 2),
603 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 3),
604 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 4),
605 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 5),
606 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 0),
607 };
608
rk806_set_suspend_enable(struct regulator_dev * rdev)609 static int rk806_set_suspend_enable(struct regulator_dev *rdev)
610 {
611 int rid = rdev_get_id(rdev);
612
613 return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg,
614 rk806_suspend_bits[rid].bit,
615 rk806_suspend_bits[rid].bit);
616 }
617
rk806_set_suspend_disable(struct regulator_dev * rdev)618 static int rk806_set_suspend_disable(struct regulator_dev *rdev)
619 {
620 int rid = rdev_get_id(rdev);
621
622 return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg,
623 rk806_suspend_bits[rid].bit, 0);
624 }
625
rk808_set_suspend_enable(struct regulator_dev * rdev)626 static int rk808_set_suspend_enable(struct regulator_dev *rdev)
627 {
628 unsigned int reg;
629
630 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
631
632 return regmap_update_bits(rdev->regmap, reg,
633 rdev->desc->enable_mask,
634 0);
635 }
636
rk808_set_suspend_disable(struct regulator_dev * rdev)637 static int rk808_set_suspend_disable(struct regulator_dev *rdev)
638 {
639 unsigned int reg;
640
641 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
642
643 return regmap_update_bits(rdev->regmap, reg,
644 rdev->desc->enable_mask,
645 rdev->desc->enable_mask);
646 }
647
648 static const struct rk8xx_register_bit rk816_suspend_bits[] = {
649 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 0),
650 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 1),
651 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 2),
652 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 3),
653 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 0),
654 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 1),
655 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 2),
656 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 3),
657 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 4),
658 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 5),
659 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 5),
660 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 6),
661 };
662
rk816_set_suspend_enable(struct regulator_dev * rdev)663 static int rk816_set_suspend_enable(struct regulator_dev *rdev)
664 {
665 int rid = rdev_get_id(rdev);
666
667 return regmap_update_bits(rdev->regmap, rk816_suspend_bits[rid].reg,
668 rk816_suspend_bits[rid].bit,
669 rk816_suspend_bits[rid].bit);
670 }
671
rk816_set_suspend_disable(struct regulator_dev * rdev)672 static int rk816_set_suspend_disable(struct regulator_dev *rdev)
673 {
674 int rid = rdev_get_id(rdev);
675
676 return regmap_update_bits(rdev->regmap, rk816_suspend_bits[rid].reg,
677 rk816_suspend_bits[rid].bit, 0);
678 }
679
rk817_set_suspend_enable_ctrl(struct regulator_dev * rdev,unsigned int en)680 static int rk817_set_suspend_enable_ctrl(struct regulator_dev *rdev,
681 unsigned int en)
682 {
683 unsigned int reg;
684 int id = rdev_get_id(rdev);
685 unsigned int id_slp, msk, val;
686
687 if (id >= RK817_ID_DCDC1 && id <= RK817_ID_DCDC4)
688 id_slp = id;
689 else if (id >= RK817_ID_LDO1 && id <= RK817_ID_LDO8)
690 id_slp = 8 + (id - RK817_ID_LDO1);
691 else if (id >= RK817_ID_LDO9 && id <= RK809_ID_SW2)
692 id_slp = 4 + (id - RK817_ID_LDO9);
693 else
694 return -EINVAL;
695
696 reg = RK817_POWER_SLP_EN_REG(id_slp / 8);
697
698 msk = BIT(id_slp % 8);
699 if (en)
700 val = msk;
701 else
702 val = 0;
703
704 return regmap_update_bits(rdev->regmap, reg, msk, val);
705 }
706
rk817_set_suspend_enable(struct regulator_dev * rdev)707 static int rk817_set_suspend_enable(struct regulator_dev *rdev)
708 {
709 return rk817_set_suspend_enable_ctrl(rdev, 1);
710 }
711
rk817_set_suspend_disable(struct regulator_dev * rdev)712 static int rk817_set_suspend_disable(struct regulator_dev *rdev)
713 {
714 return rk817_set_suspend_enable_ctrl(rdev, 0);
715 }
716
rk8xx_set_suspend_mode(struct regulator_dev * rdev,unsigned int mode)717 static int rk8xx_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode)
718 {
719 unsigned int reg;
720
721 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
722
723 switch (mode) {
724 case REGULATOR_MODE_FAST:
725 return regmap_update_bits(rdev->regmap, reg,
726 PWM_MODE_MSK, FPWM_MODE);
727 case REGULATOR_MODE_NORMAL:
728 return regmap_update_bits(rdev->regmap, reg,
729 PWM_MODE_MSK, AUTO_PWM_MODE);
730 default:
731 dev_err(&rdev->dev, "do not support this mode\n");
732 return -EINVAL;
733 }
734
735 return 0;
736 }
737
rk8xx_set_mode(struct regulator_dev * rdev,unsigned int mode)738 static int rk8xx_set_mode(struct regulator_dev *rdev, unsigned int mode)
739 {
740 switch (mode) {
741 case REGULATOR_MODE_FAST:
742 return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
743 PWM_MODE_MSK, FPWM_MODE);
744 case REGULATOR_MODE_NORMAL:
745 return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
746 PWM_MODE_MSK, AUTO_PWM_MODE);
747 default:
748 dev_err(&rdev->dev, "do not support this mode\n");
749 return -EINVAL;
750 }
751
752 return 0;
753 }
754
rk8xx_get_mode(struct regulator_dev * rdev)755 static unsigned int rk8xx_get_mode(struct regulator_dev *rdev)
756 {
757 unsigned int val;
758 int err;
759
760 err = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
761 if (err)
762 return err;
763
764 if (val & FPWM_MODE)
765 return REGULATOR_MODE_FAST;
766 else
767 return REGULATOR_MODE_NORMAL;
768 }
769
rk8xx_is_enabled_wmsk_regmap(struct regulator_dev * rdev)770 static int rk8xx_is_enabled_wmsk_regmap(struct regulator_dev *rdev)
771 {
772 unsigned int val;
773 int ret;
774
775 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
776 if (ret != 0)
777 return ret;
778
779 /* add write mask bit */
780 val |= (rdev->desc->enable_mask & 0xf0);
781 val &= rdev->desc->enable_mask;
782
783 if (rdev->desc->enable_is_inverted) {
784 if (rdev->desc->enable_val)
785 return val != rdev->desc->enable_val;
786 return (val == 0);
787 }
788 if (rdev->desc->enable_val)
789 return val == rdev->desc->enable_val;
790 return val != 0;
791 }
792
rk8xx_regulator_of_map_mode(unsigned int mode)793 static unsigned int rk8xx_regulator_of_map_mode(unsigned int mode)
794 {
795 switch (mode) {
796 case 1:
797 return REGULATOR_MODE_FAST;
798 case 2:
799 return REGULATOR_MODE_NORMAL;
800 default:
801 return REGULATOR_MODE_INVALID;
802 }
803 }
804
805 static const struct regulator_ops rk805_reg_ops = {
806 .list_voltage = regulator_list_voltage_linear,
807 .map_voltage = regulator_map_voltage_linear,
808 .get_voltage_sel = regulator_get_voltage_sel_regmap,
809 .set_voltage_sel = regulator_set_voltage_sel_regmap,
810 .enable = regulator_enable_regmap,
811 .disable = regulator_disable_regmap,
812 .is_enabled = regulator_is_enabled_regmap,
813 .set_suspend_voltage = rk808_set_suspend_voltage,
814 .set_suspend_enable = rk805_set_suspend_enable,
815 .set_suspend_disable = rk805_set_suspend_disable,
816 };
817
818 static const struct regulator_ops rk805_switch_ops = {
819 .enable = regulator_enable_regmap,
820 .disable = regulator_disable_regmap,
821 .is_enabled = regulator_is_enabled_regmap,
822 .set_suspend_enable = rk805_set_suspend_enable,
823 .set_suspend_disable = rk805_set_suspend_disable,
824 };
825
826 static const struct regulator_ops rk806_ops_dcdc = {
827 .list_voltage = regulator_list_voltage_linear_range,
828 .map_voltage = regulator_map_voltage_linear_range,
829 .get_voltage_sel = regulator_get_voltage_sel_regmap,
830 .set_voltage_sel = regulator_set_voltage_sel_regmap,
831 .set_voltage_time_sel = regulator_set_voltage_time_sel,
832 .set_mode = rk806_set_mode_dcdc,
833 .get_mode = rk806_get_mode_dcdc,
834
835 .enable = regulator_enable_regmap,
836 .disable = regulator_disable_regmap,
837 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
838
839 .set_suspend_mode = rk806_set_mode_dcdc,
840 .set_ramp_delay = rk806_set_ramp_delay_dcdc,
841
842 .set_suspend_voltage = rk806_set_suspend_voltage_range_dcdc,
843 .set_suspend_enable = rk806_set_suspend_enable,
844 .set_suspend_disable = rk806_set_suspend_disable,
845 };
846
847 static const struct regulator_ops rk806_ops_nldo = {
848 .list_voltage = regulator_list_voltage_linear_range,
849 .map_voltage = regulator_map_voltage_linear_range,
850 .get_voltage_sel = regulator_get_voltage_sel_regmap,
851 .set_voltage_sel = regulator_set_voltage_sel_regmap,
852 .set_voltage_time_sel = regulator_set_voltage_time_sel,
853
854 .enable = regulator_enable_regmap,
855 .disable = regulator_disable_regmap,
856 .is_enabled = regulator_is_enabled_regmap,
857
858 .set_ramp_delay = regulator_set_ramp_delay_regmap,
859
860 .set_suspend_voltage = rk806_set_suspend_voltage_range_nldo,
861 .set_suspend_enable = rk806_set_suspend_enable,
862 .set_suspend_disable = rk806_set_suspend_disable,
863 };
864
865 static const struct regulator_ops rk806_ops_pldo = {
866 .list_voltage = regulator_list_voltage_linear_range,
867 .map_voltage = regulator_map_voltage_linear_range,
868
869 .get_voltage_sel = regulator_get_voltage_sel_regmap,
870 .set_voltage_sel = regulator_set_voltage_sel_regmap,
871 .set_voltage_time_sel = regulator_set_voltage_time_sel,
872
873 .enable = regulator_enable_regmap,
874 .disable = regulator_disable_regmap,
875 .is_enabled = regulator_is_enabled_regmap,
876
877 .set_ramp_delay = regulator_set_ramp_delay_regmap,
878
879 .set_suspend_voltage = rk806_set_suspend_voltage_range_pldo,
880 .set_suspend_enable = rk806_set_suspend_enable,
881 .set_suspend_disable = rk806_set_suspend_disable,
882 };
883
884 static const struct regulator_ops rk808_buck1_2_ops = {
885 .list_voltage = regulator_list_voltage_linear,
886 .map_voltage = regulator_map_voltage_linear,
887 .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap,
888 .set_voltage_sel = rk808_buck1_2_set_voltage_sel,
889 .set_voltage_time_sel = rk808_buck1_2_set_voltage_time_sel,
890 .enable = regulator_enable_regmap,
891 .disable = regulator_disable_regmap,
892 .is_enabled = regulator_is_enabled_regmap,
893 .set_ramp_delay = regulator_set_ramp_delay_regmap,
894 .set_suspend_voltage = rk808_set_suspend_voltage,
895 .set_suspend_enable = rk808_set_suspend_enable,
896 .set_suspend_disable = rk808_set_suspend_disable,
897 };
898
899 static const struct regulator_ops rk808_reg_ops = {
900 .list_voltage = regulator_list_voltage_linear,
901 .map_voltage = regulator_map_voltage_linear,
902 .get_voltage_sel = regulator_get_voltage_sel_regmap,
903 .set_voltage_sel = regulator_set_voltage_sel_regmap,
904 .enable = regulator_enable_regmap,
905 .disable = regulator_disable_regmap,
906 .is_enabled = regulator_is_enabled_regmap,
907 .set_suspend_voltage = rk808_set_suspend_voltage,
908 .set_suspend_enable = rk808_set_suspend_enable,
909 .set_suspend_disable = rk808_set_suspend_disable,
910 };
911
912 static const struct regulator_ops rk808_reg_ops_ranges = {
913 .list_voltage = regulator_list_voltage_linear_range,
914 .map_voltage = regulator_map_voltage_linear_range,
915 .get_voltage_sel = regulator_get_voltage_sel_regmap,
916 .set_voltage_sel = regulator_set_voltage_sel_regmap,
917 .enable = regulator_enable_regmap,
918 .disable = regulator_disable_regmap,
919 .is_enabled = regulator_is_enabled_regmap,
920 .set_suspend_voltage = rk808_set_suspend_voltage_range,
921 .set_suspend_enable = rk808_set_suspend_enable,
922 .set_suspend_disable = rk808_set_suspend_disable,
923 };
924
925 static const struct regulator_ops rk808_switch_ops = {
926 .enable = regulator_enable_regmap,
927 .disable = regulator_disable_regmap,
928 .is_enabled = regulator_is_enabled_regmap,
929 .set_suspend_enable = rk808_set_suspend_enable,
930 .set_suspend_disable = rk808_set_suspend_disable,
931 };
932
933 static const struct linear_range rk805_buck_1_2_voltage_ranges[] = {
934 REGULATOR_LINEAR_RANGE(712500, 0, 59, 12500),
935 REGULATOR_LINEAR_RANGE(1800000, 60, 62, 200000),
936 REGULATOR_LINEAR_RANGE(2300000, 63, 63, 0),
937 };
938
939 static const struct regulator_ops rk809_buck5_ops_range = {
940 .list_voltage = regulator_list_voltage_linear_range,
941 .map_voltage = regulator_map_voltage_linear_range,
942 .get_voltage_sel = regulator_get_voltage_sel_regmap,
943 .set_voltage_sel = regulator_set_voltage_sel_regmap,
944 .set_voltage_time_sel = regulator_set_voltage_time_sel,
945 .enable = regulator_enable_regmap,
946 .disable = regulator_disable_regmap,
947 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
948 .set_suspend_voltage = rk808_set_suspend_voltage_range,
949 .set_suspend_enable = rk817_set_suspend_enable,
950 .set_suspend_disable = rk817_set_suspend_disable,
951 };
952
953 static const struct regulator_ops rk816_buck1_2_ops_ranges = {
954 .list_voltage = regulator_list_voltage_linear_range,
955 .map_voltage = regulator_map_voltage_linear_range,
956 .get_voltage_sel = regulator_get_voltage_sel_regmap,
957 .set_voltage_sel = regulator_set_voltage_sel_regmap,
958 .set_voltage_time_sel = regulator_set_voltage_time_sel,
959 .enable = regulator_enable_regmap,
960 .disable = regulator_disable_regmap,
961 .is_enabled = regulator_is_enabled_regmap,
962 .set_mode = rk8xx_set_mode,
963 .get_mode = rk8xx_get_mode,
964 .set_suspend_mode = rk8xx_set_suspend_mode,
965 .set_ramp_delay = regulator_set_ramp_delay_regmap,
966 .set_suspend_voltage = rk808_set_suspend_voltage_range,
967 .set_suspend_enable = rk816_set_suspend_enable,
968 .set_suspend_disable = rk816_set_suspend_disable,
969 };
970
971 static const struct regulator_ops rk816_buck4_ops_ranges = {
972 .list_voltage = regulator_list_voltage_linear_range,
973 .map_voltage = regulator_map_voltage_linear_range,
974 .get_voltage_sel = regulator_get_voltage_sel_regmap,
975 .set_voltage_sel = regulator_set_voltage_sel_regmap,
976 .set_voltage_time_sel = regulator_set_voltage_time_sel,
977 .enable = regulator_enable_regmap,
978 .disable = regulator_disable_regmap,
979 .is_enabled = regulator_is_enabled_regmap,
980 .set_mode = rk8xx_set_mode,
981 .get_mode = rk8xx_get_mode,
982 .set_suspend_mode = rk8xx_set_suspend_mode,
983 .set_suspend_voltage = rk808_set_suspend_voltage_range,
984 .set_suspend_enable = rk816_set_suspend_enable,
985 .set_suspend_disable = rk816_set_suspend_disable,
986 };
987
988 static const struct regulator_ops rk816_reg_ops = {
989 .list_voltage = regulator_list_voltage_linear,
990 .map_voltage = regulator_map_voltage_linear,
991 .get_voltage_sel = regulator_get_voltage_sel_regmap,
992 .set_voltage_sel = regulator_set_voltage_sel_regmap,
993 .enable = regulator_enable_regmap,
994 .disable = regulator_disable_regmap,
995 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
996 .set_suspend_voltage = rk808_set_suspend_voltage,
997 .set_suspend_enable = rk816_set_suspend_enable,
998 .set_suspend_disable = rk816_set_suspend_disable,
999 };
1000
1001 static const struct regulator_ops rk817_reg_ops = {
1002 .list_voltage = regulator_list_voltage_linear,
1003 .map_voltage = regulator_map_voltage_linear,
1004 .get_voltage_sel = regulator_get_voltage_sel_regmap,
1005 .set_voltage_sel = regulator_set_voltage_sel_regmap,
1006 .enable = regulator_enable_regmap,
1007 .disable = regulator_disable_regmap,
1008 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
1009 .set_suspend_voltage = rk808_set_suspend_voltage,
1010 .set_suspend_enable = rk817_set_suspend_enable,
1011 .set_suspend_disable = rk817_set_suspend_disable,
1012 };
1013
1014 static const struct regulator_ops rk817_boost_ops = {
1015 .list_voltage = regulator_list_voltage_linear,
1016 .map_voltage = regulator_map_voltage_linear,
1017 .get_voltage_sel = regulator_get_voltage_sel_regmap,
1018 .set_voltage_sel = regulator_set_voltage_sel_regmap,
1019 .enable = regulator_enable_regmap,
1020 .disable = regulator_disable_regmap,
1021 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
1022 .set_suspend_enable = rk817_set_suspend_enable,
1023 .set_suspend_disable = rk817_set_suspend_disable,
1024 };
1025
1026 static const struct regulator_ops rk817_buck_ops_range = {
1027 .list_voltage = regulator_list_voltage_linear_range,
1028 .map_voltage = regulator_map_voltage_linear_range,
1029 .get_voltage_sel = regulator_get_voltage_sel_regmap,
1030 .set_voltage_sel = regulator_set_voltage_sel_regmap,
1031 .set_voltage_time_sel = regulator_set_voltage_time_sel,
1032 .enable = regulator_enable_regmap,
1033 .disable = regulator_disable_regmap,
1034 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
1035 .set_mode = rk8xx_set_mode,
1036 .get_mode = rk8xx_get_mode,
1037 .set_suspend_mode = rk8xx_set_suspend_mode,
1038 .set_ramp_delay = regulator_set_ramp_delay_regmap,
1039 .set_suspend_voltage = rk808_set_suspend_voltage_range,
1040 .set_suspend_enable = rk817_set_suspend_enable,
1041 .set_suspend_disable = rk817_set_suspend_disable,
1042 };
1043
1044 static const struct regulator_ops rk817_switch_ops = {
1045 .enable = regulator_enable_regmap,
1046 .disable = regulator_disable_regmap,
1047 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
1048 .set_suspend_enable = rk817_set_suspend_enable,
1049 .set_suspend_disable = rk817_set_suspend_disable,
1050 };
1051
1052 static const struct regulator_desc rk805_reg[] = {
1053 {
1054 .name = "DCDC_REG1",
1055 .supply_name = "vcc1",
1056 .of_match = of_match_ptr("DCDC_REG1"),
1057 .regulators_node = of_match_ptr("regulators"),
1058 .id = RK805_ID_DCDC1,
1059 .ops = &rk808_reg_ops_ranges,
1060 .type = REGULATOR_VOLTAGE,
1061 .n_voltages = 64,
1062 .linear_ranges = rk805_buck_1_2_voltage_ranges,
1063 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
1064 .vsel_reg = RK805_BUCK1_ON_VSEL_REG,
1065 .vsel_mask = RK818_BUCK_VSEL_MASK,
1066 .enable_reg = RK805_DCDC_EN_REG,
1067 .enable_mask = BIT(0),
1068 .owner = THIS_MODULE,
1069 }, {
1070 .name = "DCDC_REG2",
1071 .supply_name = "vcc2",
1072 .of_match = of_match_ptr("DCDC_REG2"),
1073 .regulators_node = of_match_ptr("regulators"),
1074 .id = RK805_ID_DCDC2,
1075 .ops = &rk808_reg_ops_ranges,
1076 .type = REGULATOR_VOLTAGE,
1077 .n_voltages = 64,
1078 .linear_ranges = rk805_buck_1_2_voltage_ranges,
1079 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
1080 .vsel_reg = RK805_BUCK2_ON_VSEL_REG,
1081 .vsel_mask = RK818_BUCK_VSEL_MASK,
1082 .enable_reg = RK805_DCDC_EN_REG,
1083 .enable_mask = BIT(1),
1084 .owner = THIS_MODULE,
1085 }, {
1086 .name = "DCDC_REG3",
1087 .supply_name = "vcc3",
1088 .of_match = of_match_ptr("DCDC_REG3"),
1089 .regulators_node = of_match_ptr("regulators"),
1090 .id = RK805_ID_DCDC3,
1091 .ops = &rk805_switch_ops,
1092 .type = REGULATOR_VOLTAGE,
1093 .n_voltages = 1,
1094 .enable_reg = RK805_DCDC_EN_REG,
1095 .enable_mask = BIT(2),
1096 .owner = THIS_MODULE,
1097 },
1098
1099 RK805_DESC(RK805_ID_DCDC4, "DCDC_REG4", "vcc4", 800, 3400, 100,
1100 RK805_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK,
1101 RK805_DCDC_EN_REG, BIT(3), 0),
1102
1103 RK805_DESC(RK805_ID_LDO1, "LDO_REG1", "vcc5", 800, 3400, 100,
1104 RK805_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG,
1105 BIT(0), 400),
1106 RK805_DESC(RK805_ID_LDO2, "LDO_REG2", "vcc5", 800, 3400, 100,
1107 RK805_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG,
1108 BIT(1), 400),
1109 RK805_DESC(RK805_ID_LDO3, "LDO_REG3", "vcc6", 800, 3400, 100,
1110 RK805_LDO3_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG,
1111 BIT(2), 400),
1112 };
1113
1114 static const struct linear_range rk806_buck_voltage_ranges[] = {
1115 REGULATOR_LINEAR_RANGE(500000, 0, 159, 6250), /* 500mV ~ 1500mV */
1116 REGULATOR_LINEAR_RANGE(1500000, 160, 235, 25000), /* 1500mV ~ 3400mV */
1117 REGULATOR_LINEAR_RANGE(3400000, 236, 255, 0),
1118 };
1119
1120 static const struct linear_range rk806_ldo_voltage_ranges[] = {
1121 REGULATOR_LINEAR_RANGE(500000, 0, 231, 12500), /* 500mV ~ 3400mV */
1122 REGULATOR_LINEAR_RANGE(3400000, 232, 255, 0),
1123 };
1124
1125 static const struct regulator_desc rk806_reg[] = {
1126 RK806_REGULATOR("dcdc-reg1", "vcc1", RK806_ID_DCDC1, rk806_ops_dcdc,
1127 RK806_BUCK_SEL_CNT, RK806_BUCK1_ON_VSEL,
1128 RK806_POWER_EN0, rk806_buck_voltage_ranges, 0,
1129 RK806_BUCK1_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1130 RK806_REGULATOR("dcdc-reg2", "vcc2", RK806_ID_DCDC2, rk806_ops_dcdc,
1131 RK806_BUCK_SEL_CNT, RK806_BUCK2_ON_VSEL,
1132 RK806_POWER_EN0, rk806_buck_voltage_ranges, 1,
1133 RK806_BUCK2_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1134 RK806_REGULATOR("dcdc-reg3", "vcc3", RK806_ID_DCDC3, rk806_ops_dcdc,
1135 RK806_BUCK_SEL_CNT, RK806_BUCK3_ON_VSEL,
1136 RK806_POWER_EN0, rk806_buck_voltage_ranges, 2,
1137 RK806_BUCK3_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1138 RK806_REGULATOR("dcdc-reg4", "vcc4", RK806_ID_DCDC4, rk806_ops_dcdc,
1139 RK806_BUCK_SEL_CNT, RK806_BUCK4_ON_VSEL,
1140 RK806_POWER_EN0, rk806_buck_voltage_ranges, 3,
1141 RK806_BUCK4_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1142
1143 RK806_REGULATOR("dcdc-reg5", "vcc5", RK806_ID_DCDC5, rk806_ops_dcdc,
1144 RK806_BUCK_SEL_CNT, RK806_BUCK5_ON_VSEL,
1145 RK806_POWER_EN1, rk806_buck_voltage_ranges, 0,
1146 RK806_BUCK5_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1147 RK806_REGULATOR("dcdc-reg6", "vcc6", RK806_ID_DCDC6, rk806_ops_dcdc,
1148 RK806_BUCK_SEL_CNT, RK806_BUCK6_ON_VSEL,
1149 RK806_POWER_EN1, rk806_buck_voltage_ranges, 1,
1150 RK806_BUCK6_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1151 RK806_REGULATOR("dcdc-reg7", "vcc7", RK806_ID_DCDC7, rk806_ops_dcdc,
1152 RK806_BUCK_SEL_CNT, RK806_BUCK7_ON_VSEL,
1153 RK806_POWER_EN1, rk806_buck_voltage_ranges, 2,
1154 RK806_BUCK7_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1155 RK806_REGULATOR("dcdc-reg8", "vcc8", RK806_ID_DCDC8, rk806_ops_dcdc,
1156 RK806_BUCK_SEL_CNT, RK806_BUCK8_ON_VSEL,
1157 RK806_POWER_EN1, rk806_buck_voltage_ranges, 3,
1158 RK806_BUCK8_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1159
1160 RK806_REGULATOR("dcdc-reg9", "vcc9", RK806_ID_DCDC9, rk806_ops_dcdc,
1161 RK806_BUCK_SEL_CNT, RK806_BUCK9_ON_VSEL,
1162 RK806_POWER_EN2, rk806_buck_voltage_ranges, 0,
1163 RK806_BUCK9_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1164 RK806_REGULATOR("dcdc-reg10", "vcc10", RK806_ID_DCDC10, rk806_ops_dcdc,
1165 RK806_BUCK_SEL_CNT, RK806_BUCK10_ON_VSEL,
1166 RK806_POWER_EN2, rk806_buck_voltage_ranges, 1,
1167 RK806_BUCK10_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
1168
1169 RK806_REGULATOR("nldo-reg1", "vcc13", RK806_ID_NLDO1, rk806_ops_nldo,
1170 RK806_LDO_SEL_CNT, RK806_NLDO1_ON_VSEL,
1171 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 0,
1172 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1173 RK806_REGULATOR("nldo-reg2", "vcc13", RK806_ID_NLDO2, rk806_ops_nldo,
1174 RK806_LDO_SEL_CNT, RK806_NLDO2_ON_VSEL,
1175 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 1,
1176 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1177 RK806_REGULATOR("nldo-reg3", "vcc13", RK806_ID_NLDO3, rk806_ops_nldo,
1178 RK806_LDO_SEL_CNT, RK806_NLDO3_ON_VSEL,
1179 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 2,
1180 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1181 RK806_REGULATOR("nldo-reg4", "vcc14", RK806_ID_NLDO4, rk806_ops_nldo,
1182 RK806_LDO_SEL_CNT, RK806_NLDO4_ON_VSEL,
1183 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 3,
1184 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1185
1186 RK806_REGULATOR("nldo-reg5", "vcc14", RK806_ID_NLDO5, rk806_ops_nldo,
1187 RK806_LDO_SEL_CNT, RK806_NLDO5_ON_VSEL,
1188 RK806_POWER_EN5, rk806_ldo_voltage_ranges, 2,
1189 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1190
1191 RK806_REGULATOR("pldo-reg1", "vcc11", RK806_ID_PLDO1, rk806_ops_pldo,
1192 RK806_LDO_SEL_CNT, RK806_PLDO1_ON_VSEL,
1193 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 1,
1194 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1195 RK806_REGULATOR("pldo-reg2", "vcc11", RK806_ID_PLDO2, rk806_ops_pldo,
1196 RK806_LDO_SEL_CNT, RK806_PLDO2_ON_VSEL,
1197 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 2,
1198 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1199 RK806_REGULATOR("pldo-reg3", "vcc11", RK806_ID_PLDO3, rk806_ops_pldo,
1200 RK806_LDO_SEL_CNT, RK806_PLDO3_ON_VSEL,
1201 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 3,
1202 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1203
1204 RK806_REGULATOR("pldo-reg4", "vcc12", RK806_ID_PLDO4, rk806_ops_pldo,
1205 RK806_LDO_SEL_CNT, RK806_PLDO4_ON_VSEL,
1206 RK806_POWER_EN5, rk806_ldo_voltage_ranges, 0,
1207 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1208 RK806_REGULATOR("pldo-reg5", "vcc12", RK806_ID_PLDO5, rk806_ops_pldo,
1209 RK806_LDO_SEL_CNT, RK806_PLDO5_ON_VSEL,
1210 RK806_POWER_EN5, rk806_ldo_voltage_ranges, 1,
1211 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1212
1213 RK806_REGULATOR("pldo-reg6", "vcca", RK806_ID_PLDO6, rk806_ops_pldo,
1214 RK806_LDO_SEL_CNT, RK806_PLDO6_ON_VSEL,
1215 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 0,
1216 0xEA, 0x38, rk806_ramp_delay_table_ldo),
1217 };
1218
1219
1220 static const struct regulator_desc rk808_reg[] = {
1221 {
1222 .name = "DCDC_REG1",
1223 .supply_name = "vcc1",
1224 .of_match = of_match_ptr("DCDC_REG1"),
1225 .regulators_node = of_match_ptr("regulators"),
1226 .id = RK808_ID_DCDC1,
1227 .ops = &rk808_buck1_2_ops,
1228 .type = REGULATOR_VOLTAGE,
1229 .min_uV = 712500,
1230 .uV_step = 12500,
1231 .n_voltages = 64,
1232 .vsel_reg = RK808_BUCK1_ON_VSEL_REG,
1233 .vsel_mask = RK808_BUCK_VSEL_MASK,
1234 .enable_reg = RK808_DCDC_EN_REG,
1235 .enable_mask = BIT(0),
1236 .ramp_reg = RK808_BUCK1_CONFIG_REG,
1237 .ramp_mask = RK808_RAMP_RATE_MASK,
1238 .ramp_delay_table = rk808_buck1_2_ramp_table,
1239 .n_ramp_values = ARRAY_SIZE(rk808_buck1_2_ramp_table),
1240 .owner = THIS_MODULE,
1241 }, {
1242 .name = "DCDC_REG2",
1243 .supply_name = "vcc2",
1244 .of_match = of_match_ptr("DCDC_REG2"),
1245 .regulators_node = of_match_ptr("regulators"),
1246 .id = RK808_ID_DCDC2,
1247 .ops = &rk808_buck1_2_ops,
1248 .type = REGULATOR_VOLTAGE,
1249 .min_uV = 712500,
1250 .uV_step = 12500,
1251 .n_voltages = 64,
1252 .vsel_reg = RK808_BUCK2_ON_VSEL_REG,
1253 .vsel_mask = RK808_BUCK_VSEL_MASK,
1254 .enable_reg = RK808_DCDC_EN_REG,
1255 .enable_mask = BIT(1),
1256 .ramp_reg = RK808_BUCK2_CONFIG_REG,
1257 .ramp_mask = RK808_RAMP_RATE_MASK,
1258 .ramp_delay_table = rk808_buck1_2_ramp_table,
1259 .n_ramp_values = ARRAY_SIZE(rk808_buck1_2_ramp_table),
1260 .owner = THIS_MODULE,
1261 }, {
1262 .name = "DCDC_REG3",
1263 .supply_name = "vcc3",
1264 .of_match = of_match_ptr("DCDC_REG3"),
1265 .regulators_node = of_match_ptr("regulators"),
1266 .id = RK808_ID_DCDC3,
1267 .ops = &rk808_switch_ops,
1268 .type = REGULATOR_VOLTAGE,
1269 .n_voltages = 1,
1270 .enable_reg = RK808_DCDC_EN_REG,
1271 .enable_mask = BIT(2),
1272 .owner = THIS_MODULE,
1273 },
1274 RK8XX_DESC(RK808_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3300, 100,
1275 RK808_BUCK4_ON_VSEL_REG, RK808_BUCK4_VSEL_MASK,
1276 RK808_DCDC_EN_REG, BIT(3), 0),
1277 RK8XX_DESC(RK808_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100,
1278 RK808_LDO1_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
1279 BIT(0), 400),
1280 RK8XX_DESC(RK808_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100,
1281 RK808_LDO2_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
1282 BIT(1), 400),
1283 {
1284 .name = "LDO_REG3",
1285 .supply_name = "vcc7",
1286 .of_match = of_match_ptr("LDO_REG3"),
1287 .regulators_node = of_match_ptr("regulators"),
1288 .id = RK808_ID_LDO3,
1289 .ops = &rk808_reg_ops_ranges,
1290 .type = REGULATOR_VOLTAGE,
1291 .n_voltages = 16,
1292 .linear_ranges = rk808_ldo3_voltage_ranges,
1293 .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges),
1294 .vsel_reg = RK808_LDO3_ON_VSEL_REG,
1295 .vsel_mask = RK808_BUCK4_VSEL_MASK,
1296 .enable_reg = RK808_LDO_EN_REG,
1297 .enable_mask = BIT(2),
1298 .enable_time = 400,
1299 .owner = THIS_MODULE,
1300 },
1301 RK8XX_DESC(RK808_ID_LDO4, "LDO_REG4", "vcc9", 1800, 3400, 100,
1302 RK808_LDO4_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
1303 BIT(3), 400),
1304 RK8XX_DESC(RK808_ID_LDO5, "LDO_REG5", "vcc9", 1800, 3400, 100,
1305 RK808_LDO5_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
1306 BIT(4), 400),
1307 RK8XX_DESC(RK808_ID_LDO6, "LDO_REG6", "vcc10", 800, 2500, 100,
1308 RK808_LDO6_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
1309 BIT(5), 400),
1310 RK8XX_DESC(RK808_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100,
1311 RK808_LDO7_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
1312 BIT(6), 400),
1313 RK8XX_DESC(RK808_ID_LDO8, "LDO_REG8", "vcc11", 1800, 3400, 100,
1314 RK808_LDO8_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
1315 BIT(7), 400),
1316 RK8XX_DESC_SWITCH(RK808_ID_SWITCH1, "SWITCH_REG1", "vcc8",
1317 RK808_DCDC_EN_REG, BIT(5)),
1318 RK8XX_DESC_SWITCH(RK808_ID_SWITCH2, "SWITCH_REG2", "vcc12",
1319 RK808_DCDC_EN_REG, BIT(6)),
1320 };
1321
1322 static const struct regulator_desc rk809_reg[] = {
1323 {
1324 .name = "DCDC_REG1",
1325 .supply_name = "vcc1",
1326 .of_match = of_match_ptr("DCDC_REG1"),
1327 .regulators_node = of_match_ptr("regulators"),
1328 .id = RK817_ID_DCDC1,
1329 .ops = &rk817_buck_ops_range,
1330 .type = REGULATOR_VOLTAGE,
1331 .n_voltages = RK817_BUCK1_SEL_CNT + 1,
1332 .linear_ranges = rk817_buck1_voltage_ranges,
1333 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
1334 .vsel_reg = RK817_BUCK1_ON_VSEL_REG,
1335 .vsel_mask = RK817_BUCK_VSEL_MASK,
1336 .enable_reg = RK817_POWER_EN_REG(0),
1337 .enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
1338 .enable_val = ENABLE_MASK(RK817_ID_DCDC1),
1339 .disable_val = DISABLE_VAL(RK817_ID_DCDC1),
1340 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC1),
1341 .ramp_mask = RK817_RAMP_RATE_MASK,
1342 .ramp_delay_table = rk817_buck1_4_ramp_table,
1343 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1344 .of_map_mode = rk8xx_regulator_of_map_mode,
1345 .owner = THIS_MODULE,
1346 }, {
1347 .name = "DCDC_REG2",
1348 .supply_name = "vcc2",
1349 .of_match = of_match_ptr("DCDC_REG2"),
1350 .regulators_node = of_match_ptr("regulators"),
1351 .id = RK817_ID_DCDC2,
1352 .ops = &rk817_buck_ops_range,
1353 .type = REGULATOR_VOLTAGE,
1354 .n_voltages = RK817_BUCK1_SEL_CNT + 1,
1355 .linear_ranges = rk817_buck1_voltage_ranges,
1356 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
1357 .vsel_reg = RK817_BUCK2_ON_VSEL_REG,
1358 .vsel_mask = RK817_BUCK_VSEL_MASK,
1359 .enable_reg = RK817_POWER_EN_REG(0),
1360 .enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
1361 .enable_val = ENABLE_MASK(RK817_ID_DCDC2),
1362 .disable_val = DISABLE_VAL(RK817_ID_DCDC2),
1363 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC2),
1364 .ramp_mask = RK817_RAMP_RATE_MASK,
1365 .ramp_delay_table = rk817_buck1_4_ramp_table,
1366 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1367 .of_map_mode = rk8xx_regulator_of_map_mode,
1368 .owner = THIS_MODULE,
1369 }, {
1370 .name = "DCDC_REG3",
1371 .supply_name = "vcc3",
1372 .of_match = of_match_ptr("DCDC_REG3"),
1373 .regulators_node = of_match_ptr("regulators"),
1374 .id = RK817_ID_DCDC3,
1375 .ops = &rk817_buck_ops_range,
1376 .type = REGULATOR_VOLTAGE,
1377 .n_voltages = RK817_BUCK1_SEL_CNT + 1,
1378 .linear_ranges = rk817_buck1_voltage_ranges,
1379 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
1380 .vsel_reg = RK817_BUCK3_ON_VSEL_REG,
1381 .vsel_mask = RK817_BUCK_VSEL_MASK,
1382 .apply_reg = RK817_POWER_CONFIG,
1383 .apply_bit = RK817_BUCK3_FB_RES_INTER,
1384 .enable_reg = RK817_POWER_EN_REG(0),
1385 .enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
1386 .enable_val = ENABLE_MASK(RK817_ID_DCDC3),
1387 .disable_val = DISABLE_VAL(RK817_ID_DCDC3),
1388 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC3),
1389 .ramp_mask = RK817_RAMP_RATE_MASK,
1390 .ramp_delay_table = rk817_buck1_4_ramp_table,
1391 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1392 .of_map_mode = rk8xx_regulator_of_map_mode,
1393 .owner = THIS_MODULE,
1394 }, {
1395 .name = "DCDC_REG4",
1396 .supply_name = "vcc4",
1397 .of_match = of_match_ptr("DCDC_REG4"),
1398 .regulators_node = of_match_ptr("regulators"),
1399 .id = RK817_ID_DCDC4,
1400 .ops = &rk817_buck_ops_range,
1401 .type = REGULATOR_VOLTAGE,
1402 .n_voltages = RK817_BUCK3_SEL_CNT + 1,
1403 .linear_ranges = rk817_buck3_voltage_ranges,
1404 .n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
1405 .vsel_reg = RK817_BUCK4_ON_VSEL_REG,
1406 .vsel_mask = RK817_BUCK_VSEL_MASK,
1407 .enable_reg = RK817_POWER_EN_REG(0),
1408 .enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
1409 .enable_val = ENABLE_MASK(RK817_ID_DCDC4),
1410 .disable_val = DISABLE_VAL(RK817_ID_DCDC4),
1411 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC4),
1412 .ramp_mask = RK817_RAMP_RATE_MASK,
1413 .ramp_delay_table = rk817_buck1_4_ramp_table,
1414 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1415 .of_map_mode = rk8xx_regulator_of_map_mode,
1416 .owner = THIS_MODULE,
1417 },
1418 {
1419 .name = "DCDC_REG5",
1420 .supply_name = "vcc9",
1421 .of_match = of_match_ptr("DCDC_REG5"),
1422 .regulators_node = of_match_ptr("regulators"),
1423 .id = RK809_ID_DCDC5,
1424 .ops = &rk809_buck5_ops_range,
1425 .type = REGULATOR_VOLTAGE,
1426 .n_voltages = RK809_BUCK5_SEL_CNT,
1427 .linear_ranges = rk809_buck5_voltage_ranges,
1428 .n_linear_ranges = ARRAY_SIZE(rk809_buck5_voltage_ranges),
1429 .vsel_reg = RK809_BUCK5_CONFIG(0),
1430 .vsel_mask = RK809_BUCK5_VSEL_MASK,
1431 .enable_reg = RK817_POWER_EN_REG(3),
1432 .enable_mask = ENABLE_MASK(1),
1433 .enable_val = ENABLE_MASK(1),
1434 .disable_val = DISABLE_VAL(1),
1435 .of_map_mode = rk8xx_regulator_of_map_mode,
1436 .owner = THIS_MODULE,
1437 },
1438 RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
1439 RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
1440 RK817_POWER_EN_REG(1), ENABLE_MASK(0),
1441 DISABLE_VAL(0), 400),
1442 RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
1443 RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
1444 RK817_POWER_EN_REG(1), ENABLE_MASK(1),
1445 DISABLE_VAL(1), 400),
1446 RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
1447 RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
1448 RK817_POWER_EN_REG(1), ENABLE_MASK(2),
1449 DISABLE_VAL(2), 400),
1450 RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
1451 RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
1452 RK817_POWER_EN_REG(1), ENABLE_MASK(3),
1453 DISABLE_VAL(3), 400),
1454 RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
1455 RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
1456 RK817_POWER_EN_REG(2), ENABLE_MASK(0),
1457 DISABLE_VAL(0), 400),
1458 RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
1459 RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
1460 RK817_POWER_EN_REG(2), ENABLE_MASK(1),
1461 DISABLE_VAL(1), 400),
1462 RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
1463 RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
1464 RK817_POWER_EN_REG(2), ENABLE_MASK(2),
1465 DISABLE_VAL(2), 400),
1466 RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
1467 RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
1468 RK817_POWER_EN_REG(2), ENABLE_MASK(3),
1469 DISABLE_VAL(3), 400),
1470 RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
1471 RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
1472 RK817_POWER_EN_REG(3), ENABLE_MASK(0),
1473 DISABLE_VAL(0), 400),
1474 RK817_DESC_SWITCH(RK809_ID_SW1, "SWITCH_REG1", "vcc9",
1475 RK817_POWER_EN_REG(3), ENABLE_MASK(2),
1476 DISABLE_VAL(2)),
1477 RK817_DESC_SWITCH(RK809_ID_SW2, "SWITCH_REG2", "vcc8",
1478 RK817_POWER_EN_REG(3), ENABLE_MASK(3),
1479 DISABLE_VAL(3)),
1480 };
1481
1482 static const struct linear_range rk816_buck_4_voltage_ranges[] = {
1483 REGULATOR_LINEAR_RANGE(800000, 0, 26, 100000),
1484 REGULATOR_LINEAR_RANGE(3500000, 27, 31, 0),
1485 };
1486
1487 static const struct regulator_desc rk816_reg[] = {
1488 {
1489 .name = "dcdc1",
1490 .supply_name = "vcc1",
1491 .of_match = of_match_ptr("dcdc1"),
1492 .regulators_node = of_match_ptr("regulators"),
1493 .id = RK816_ID_DCDC1,
1494 .ops = &rk816_buck1_2_ops_ranges,
1495 .type = REGULATOR_VOLTAGE,
1496 .n_voltages = 64,
1497 .linear_ranges = rk805_buck_1_2_voltage_ranges,
1498 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
1499 .vsel_reg = RK818_BUCK1_ON_VSEL_REG,
1500 .vsel_mask = RK818_BUCK_VSEL_MASK,
1501 .apply_reg = RK816_DCDC_EN_REG2,
1502 .apply_bit = RK816_BUCK_DVS_CONFIRM,
1503 .enable_reg = RK816_DCDC_EN_REG1,
1504 .enable_mask = BIT(4) | BIT(0),
1505 .enable_val = BIT(4) | BIT(0),
1506 .disable_val = BIT(4),
1507 .ramp_reg = RK818_BUCK1_CONFIG_REG,
1508 .ramp_mask = RK808_RAMP_RATE_MASK,
1509 .ramp_delay_table = rk817_buck1_4_ramp_table,
1510 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1511 .of_map_mode = rk8xx_regulator_of_map_mode,
1512 .owner = THIS_MODULE,
1513 }, {
1514 .name = "dcdc2",
1515 .supply_name = "vcc2",
1516 .of_match = of_match_ptr("dcdc2"),
1517 .regulators_node = of_match_ptr("regulators"),
1518 .id = RK816_ID_DCDC2,
1519 .ops = &rk816_buck1_2_ops_ranges,
1520 .type = REGULATOR_VOLTAGE,
1521 .n_voltages = 64,
1522 .linear_ranges = rk805_buck_1_2_voltage_ranges,
1523 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
1524 .vsel_reg = RK818_BUCK2_ON_VSEL_REG,
1525 .vsel_mask = RK818_BUCK_VSEL_MASK,
1526 .apply_reg = RK816_DCDC_EN_REG2,
1527 .apply_bit = RK816_BUCK_DVS_CONFIRM,
1528 .enable_reg = RK816_DCDC_EN_REG1,
1529 .enable_mask = BIT(5) | BIT(1),
1530 .enable_val = BIT(5) | BIT(1),
1531 .disable_val = BIT(5),
1532 .ramp_reg = RK818_BUCK2_CONFIG_REG,
1533 .ramp_mask = RK808_RAMP_RATE_MASK,
1534 .ramp_delay_table = rk817_buck1_4_ramp_table,
1535 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1536 .of_map_mode = rk8xx_regulator_of_map_mode,
1537 .owner = THIS_MODULE,
1538 }, {
1539 .name = "dcdc3",
1540 .supply_name = "vcc3",
1541 .of_match = of_match_ptr("dcdc3"),
1542 .regulators_node = of_match_ptr("regulators"),
1543 .id = RK816_ID_DCDC3,
1544 .ops = &rk808_switch_ops,
1545 .type = REGULATOR_VOLTAGE,
1546 .n_voltages = 1,
1547 .enable_reg = RK816_DCDC_EN_REG1,
1548 .enable_mask = BIT(6) | BIT(2),
1549 .enable_val = BIT(6) | BIT(2),
1550 .disable_val = BIT(6),
1551 .of_map_mode = rk8xx_regulator_of_map_mode,
1552 .owner = THIS_MODULE,
1553 }, {
1554 .name = "dcdc4",
1555 .supply_name = "vcc4",
1556 .of_match = of_match_ptr("dcdc4"),
1557 .regulators_node = of_match_ptr("regulators"),
1558 .id = RK816_ID_DCDC4,
1559 .ops = &rk816_buck4_ops_ranges,
1560 .type = REGULATOR_VOLTAGE,
1561 .n_voltages = 32,
1562 .linear_ranges = rk816_buck_4_voltage_ranges,
1563 .n_linear_ranges = ARRAY_SIZE(rk816_buck_4_voltage_ranges),
1564 .vsel_reg = RK818_BUCK4_ON_VSEL_REG,
1565 .vsel_mask = RK818_BUCK4_VSEL_MASK,
1566 .enable_reg = RK816_DCDC_EN_REG1,
1567 .enable_mask = BIT(7) | BIT(3),
1568 .enable_val = BIT(7) | BIT(3),
1569 .disable_val = BIT(7),
1570 .of_map_mode = rk8xx_regulator_of_map_mode,
1571 .owner = THIS_MODULE,
1572 },
1573 RK816_DESC(RK816_ID_LDO1, "ldo1", "vcc5", 800, 3400, 100,
1574 RK818_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1575 RK816_LDO_EN_REG1, ENABLE_MASK(0), DISABLE_VAL(0), 400),
1576 RK816_DESC(RK816_ID_LDO2, "ldo2", "vcc5", 800, 3400, 100,
1577 RK818_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1578 RK816_LDO_EN_REG1, ENABLE_MASK(1), DISABLE_VAL(1), 400),
1579 RK816_DESC(RK816_ID_LDO3, "ldo3", "vcc5", 800, 3400, 100,
1580 RK818_LDO3_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1581 RK816_LDO_EN_REG1, ENABLE_MASK(2), DISABLE_VAL(2), 400),
1582 RK816_DESC(RK816_ID_LDO4, "ldo4", "vcc6", 800, 3400, 100,
1583 RK818_LDO4_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1584 RK816_LDO_EN_REG1, ENABLE_MASK(3), DISABLE_VAL(3), 400),
1585 RK816_DESC(RK816_ID_LDO5, "ldo5", "vcc6", 800, 3400, 100,
1586 RK818_LDO5_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1587 RK816_LDO_EN_REG2, ENABLE_MASK(0), DISABLE_VAL(0), 400),
1588 RK816_DESC(RK816_ID_LDO6, "ldo6", "vcc6", 800, 3400, 100,
1589 RK818_LDO6_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1590 RK816_LDO_EN_REG2, ENABLE_MASK(1), DISABLE_VAL(1), 400),
1591 };
1592
1593 static const struct regulator_desc rk817_reg[] = {
1594 {
1595 .name = "DCDC_REG1",
1596 .supply_name = "vcc1",
1597 .of_match = of_match_ptr("DCDC_REG1"),
1598 .regulators_node = of_match_ptr("regulators"),
1599 .id = RK817_ID_DCDC1,
1600 .ops = &rk817_buck_ops_range,
1601 .type = REGULATOR_VOLTAGE,
1602 .n_voltages = RK817_BUCK1_SEL_CNT + 1,
1603 .linear_ranges = rk817_buck1_voltage_ranges,
1604 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
1605 .vsel_reg = RK817_BUCK1_ON_VSEL_REG,
1606 .vsel_mask = RK817_BUCK_VSEL_MASK,
1607 .enable_reg = RK817_POWER_EN_REG(0),
1608 .enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
1609 .enable_val = ENABLE_MASK(RK817_ID_DCDC1),
1610 .disable_val = DISABLE_VAL(RK817_ID_DCDC1),
1611 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC1),
1612 .ramp_mask = RK817_RAMP_RATE_MASK,
1613 .ramp_delay_table = rk817_buck1_4_ramp_table,
1614 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1615 .of_map_mode = rk8xx_regulator_of_map_mode,
1616 .owner = THIS_MODULE,
1617 }, {
1618 .name = "DCDC_REG2",
1619 .supply_name = "vcc2",
1620 .of_match = of_match_ptr("DCDC_REG2"),
1621 .regulators_node = of_match_ptr("regulators"),
1622 .id = RK817_ID_DCDC2,
1623 .ops = &rk817_buck_ops_range,
1624 .type = REGULATOR_VOLTAGE,
1625 .n_voltages = RK817_BUCK1_SEL_CNT + 1,
1626 .linear_ranges = rk817_buck1_voltage_ranges,
1627 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
1628 .vsel_reg = RK817_BUCK2_ON_VSEL_REG,
1629 .vsel_mask = RK817_BUCK_VSEL_MASK,
1630 .enable_reg = RK817_POWER_EN_REG(0),
1631 .enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
1632 .enable_val = ENABLE_MASK(RK817_ID_DCDC2),
1633 .disable_val = DISABLE_VAL(RK817_ID_DCDC2),
1634 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC2),
1635 .ramp_mask = RK817_RAMP_RATE_MASK,
1636 .ramp_delay_table = rk817_buck1_4_ramp_table,
1637 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1638 .of_map_mode = rk8xx_regulator_of_map_mode,
1639 .owner = THIS_MODULE,
1640 }, {
1641 .name = "DCDC_REG3",
1642 .supply_name = "vcc3",
1643 .of_match = of_match_ptr("DCDC_REG3"),
1644 .regulators_node = of_match_ptr("regulators"),
1645 .id = RK817_ID_DCDC3,
1646 .ops = &rk817_buck_ops_range,
1647 .type = REGULATOR_VOLTAGE,
1648 .n_voltages = RK817_BUCK1_SEL_CNT + 1,
1649 .linear_ranges = rk817_buck1_voltage_ranges,
1650 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
1651 .vsel_reg = RK817_BUCK3_ON_VSEL_REG,
1652 .vsel_mask = RK817_BUCK_VSEL_MASK,
1653 .enable_reg = RK817_POWER_EN_REG(0),
1654 .enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
1655 .enable_val = ENABLE_MASK(RK817_ID_DCDC3),
1656 .disable_val = DISABLE_VAL(RK817_ID_DCDC3),
1657 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC3),
1658 .ramp_mask = RK817_RAMP_RATE_MASK,
1659 .ramp_delay_table = rk817_buck1_4_ramp_table,
1660 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1661 .of_map_mode = rk8xx_regulator_of_map_mode,
1662 .owner = THIS_MODULE,
1663 }, {
1664 .name = "DCDC_REG4",
1665 .supply_name = "vcc4",
1666 .of_match = of_match_ptr("DCDC_REG4"),
1667 .regulators_node = of_match_ptr("regulators"),
1668 .id = RK817_ID_DCDC4,
1669 .ops = &rk817_buck_ops_range,
1670 .type = REGULATOR_VOLTAGE,
1671 .n_voltages = RK817_BUCK3_SEL_CNT + 1,
1672 .linear_ranges = rk817_buck3_voltage_ranges,
1673 .n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
1674 .vsel_reg = RK817_BUCK4_ON_VSEL_REG,
1675 .vsel_mask = RK817_BUCK_VSEL_MASK,
1676 .enable_reg = RK817_POWER_EN_REG(0),
1677 .enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
1678 .enable_val = ENABLE_MASK(RK817_ID_DCDC4),
1679 .disable_val = DISABLE_VAL(RK817_ID_DCDC4),
1680 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC4),
1681 .ramp_mask = RK817_RAMP_RATE_MASK,
1682 .ramp_delay_table = rk817_buck1_4_ramp_table,
1683 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
1684 .of_map_mode = rk8xx_regulator_of_map_mode,
1685 .owner = THIS_MODULE,
1686 },
1687 RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
1688 RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
1689 RK817_POWER_EN_REG(1), ENABLE_MASK(0),
1690 DISABLE_VAL(0), 400),
1691 RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
1692 RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
1693 RK817_POWER_EN_REG(1), ENABLE_MASK(1),
1694 DISABLE_VAL(1), 400),
1695 RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
1696 RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
1697 RK817_POWER_EN_REG(1), ENABLE_MASK(2),
1698 DISABLE_VAL(2), 400),
1699 RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
1700 RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
1701 RK817_POWER_EN_REG(1), ENABLE_MASK(3),
1702 DISABLE_VAL(3), 400),
1703 RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
1704 RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
1705 RK817_POWER_EN_REG(2), ENABLE_MASK(0),
1706 DISABLE_VAL(0), 400),
1707 RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
1708 RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
1709 RK817_POWER_EN_REG(2), ENABLE_MASK(1),
1710 DISABLE_VAL(1), 400),
1711 RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
1712 RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
1713 RK817_POWER_EN_REG(2), ENABLE_MASK(2),
1714 DISABLE_VAL(2), 400),
1715 RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
1716 RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
1717 RK817_POWER_EN_REG(2), ENABLE_MASK(3),
1718 DISABLE_VAL(3), 400),
1719 RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
1720 RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
1721 RK817_POWER_EN_REG(3), ENABLE_MASK(0),
1722 DISABLE_VAL(0), 400),
1723 RK817_BOOST_DESC(RK817_ID_BOOST, "BOOST", "vcc8", 4700, 5400, 100,
1724 RK817_BOOST_OTG_CFG, RK817_BOOST_VSEL_MASK,
1725 RK817_POWER_EN_REG(3), ENABLE_MASK(1), ENABLE_MASK(1),
1726 DISABLE_VAL(1), 400, 3500 - 5400),
1727 RK817_DESC_SWITCH(RK817_ID_BOOST_OTG_SW, "OTG_SWITCH", "vcc9",
1728 RK817_POWER_EN_REG(3), ENABLE_MASK(2),
1729 DISABLE_VAL(2)),
1730 };
1731
1732 static const struct regulator_desc rk818_reg[] = {
1733 {
1734 .name = "DCDC_REG1",
1735 .supply_name = "vcc1",
1736 .of_match = of_match_ptr("DCDC_REG1"),
1737 .regulators_node = of_match_ptr("regulators"),
1738 .id = RK818_ID_DCDC1,
1739 .ops = &rk808_reg_ops,
1740 .type = REGULATOR_VOLTAGE,
1741 .min_uV = 712500,
1742 .uV_step = 12500,
1743 .n_voltages = 64,
1744 .vsel_reg = RK818_BUCK1_ON_VSEL_REG,
1745 .vsel_mask = RK818_BUCK_VSEL_MASK,
1746 .enable_reg = RK818_DCDC_EN_REG,
1747 .enable_mask = BIT(0),
1748 .owner = THIS_MODULE,
1749 }, {
1750 .name = "DCDC_REG2",
1751 .supply_name = "vcc2",
1752 .of_match = of_match_ptr("DCDC_REG2"),
1753 .regulators_node = of_match_ptr("regulators"),
1754 .id = RK818_ID_DCDC2,
1755 .ops = &rk808_reg_ops,
1756 .type = REGULATOR_VOLTAGE,
1757 .min_uV = 712500,
1758 .uV_step = 12500,
1759 .n_voltages = 64,
1760 .vsel_reg = RK818_BUCK2_ON_VSEL_REG,
1761 .vsel_mask = RK818_BUCK_VSEL_MASK,
1762 .enable_reg = RK818_DCDC_EN_REG,
1763 .enable_mask = BIT(1),
1764 .owner = THIS_MODULE,
1765 }, {
1766 .name = "DCDC_REG3",
1767 .supply_name = "vcc3",
1768 .of_match = of_match_ptr("DCDC_REG3"),
1769 .regulators_node = of_match_ptr("regulators"),
1770 .id = RK818_ID_DCDC3,
1771 .ops = &rk808_switch_ops,
1772 .type = REGULATOR_VOLTAGE,
1773 .n_voltages = 1,
1774 .enable_reg = RK818_DCDC_EN_REG,
1775 .enable_mask = BIT(2),
1776 .owner = THIS_MODULE,
1777 },
1778 RK8XX_DESC(RK818_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3600, 100,
1779 RK818_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK,
1780 RK818_DCDC_EN_REG, BIT(3), 0),
1781 RK8XX_DESC(RK818_ID_BOOST, "DCDC_BOOST", "boost", 4700, 5400, 100,
1782 RK818_BOOST_LDO9_ON_VSEL_REG, RK818_BOOST_ON_VSEL_MASK,
1783 RK818_DCDC_EN_REG, BIT(4), 0),
1784 RK8XX_DESC(RK818_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100,
1785 RK818_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
1786 BIT(0), 400),
1787 RK8XX_DESC(RK818_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100,
1788 RK818_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
1789 BIT(1), 400),
1790 {
1791 .name = "LDO_REG3",
1792 .supply_name = "vcc7",
1793 .of_match = of_match_ptr("LDO_REG3"),
1794 .regulators_node = of_match_ptr("regulators"),
1795 .id = RK818_ID_LDO3,
1796 .ops = &rk808_reg_ops_ranges,
1797 .type = REGULATOR_VOLTAGE,
1798 .n_voltages = 16,
1799 .linear_ranges = rk808_ldo3_voltage_ranges,
1800 .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges),
1801 .vsel_reg = RK818_LDO3_ON_VSEL_REG,
1802 .vsel_mask = RK818_LDO3_ON_VSEL_MASK,
1803 .enable_reg = RK818_LDO_EN_REG,
1804 .enable_mask = BIT(2),
1805 .enable_time = 400,
1806 .owner = THIS_MODULE,
1807 },
1808 RK8XX_DESC(RK818_ID_LDO4, "LDO_REG4", "vcc8", 1800, 3400, 100,
1809 RK818_LDO4_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
1810 BIT(3), 400),
1811 RK8XX_DESC(RK818_ID_LDO5, "LDO_REG5", "vcc7", 1800, 3400, 100,
1812 RK818_LDO5_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
1813 BIT(4), 400),
1814 RK8XX_DESC(RK818_ID_LDO6, "LDO_REG6", "vcc8", 800, 2500, 100,
1815 RK818_LDO6_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
1816 BIT(5), 400),
1817 RK8XX_DESC(RK818_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100,
1818 RK818_LDO7_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
1819 BIT(6), 400),
1820 RK8XX_DESC(RK818_ID_LDO8, "LDO_REG8", "vcc8", 1800, 3400, 100,
1821 RK818_LDO8_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
1822 BIT(7), 400),
1823 RK8XX_DESC(RK818_ID_LDO9, "LDO_REG9", "vcc9", 1800, 3400, 100,
1824 RK818_BOOST_LDO9_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
1825 RK818_DCDC_EN_REG, BIT(5), 400),
1826 RK8XX_DESC_SWITCH(RK818_ID_SWITCH, "SWITCH_REG", "vcc9",
1827 RK818_DCDC_EN_REG, BIT(6)),
1828 RK8XX_DESC_SWITCH(RK818_ID_HDMI_SWITCH, "HDMI_SWITCH", "h_5v",
1829 RK818_H5V_EN_REG, BIT(0)),
1830 RK8XX_DESC_SWITCH(RK818_ID_OTG_SWITCH, "OTG_SWITCH", "usb",
1831 RK818_DCDC_EN_REG, BIT(7)),
1832 };
1833
rk808_regulator_dt_parse_pdata(struct device * dev,struct regmap * map,struct rk808_regulator_data * pdata)1834 static int rk808_regulator_dt_parse_pdata(struct device *dev,
1835 struct regmap *map,
1836 struct rk808_regulator_data *pdata)
1837 {
1838 struct device_node *np;
1839 int tmp, ret = 0, i;
1840
1841 np = of_get_child_by_name(dev->of_node, "regulators");
1842 if (!np)
1843 return -ENXIO;
1844
1845 for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) {
1846 pdata->dvs_gpio[i] =
1847 devm_gpiod_get_index_optional(dev, "dvs", i,
1848 GPIOD_OUT_LOW);
1849 if (IS_ERR(pdata->dvs_gpio[i])) {
1850 ret = PTR_ERR(pdata->dvs_gpio[i]);
1851 dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret);
1852 goto dt_parse_end;
1853 }
1854
1855 if (!pdata->dvs_gpio[i]) {
1856 dev_info(dev, "there is no dvs%d gpio\n", i);
1857 continue;
1858 }
1859
1860 tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL;
1861 ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp,
1862 gpiod_is_active_low(pdata->dvs_gpio[i]) ?
1863 0 : tmp);
1864 }
1865
1866 dt_parse_end:
1867 of_node_put(np);
1868 return ret;
1869 }
1870
rk808_regulator_probe(struct platform_device * pdev)1871 static int rk808_regulator_probe(struct platform_device *pdev)
1872 {
1873 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
1874 struct regulator_config config = {};
1875 struct regulator_dev *rk808_rdev;
1876 struct rk808_regulator_data *pdata;
1877 const struct regulator_desc *regulators;
1878 struct regmap *regmap;
1879 int ret, i, nregulators;
1880
1881 pdev->dev.of_node = pdev->dev.parent->of_node;
1882 pdev->dev.of_node_reused = true;
1883
1884 regmap = dev_get_regmap(pdev->dev.parent, NULL);
1885 if (!regmap)
1886 return -ENODEV;
1887
1888 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1889 if (!pdata)
1890 return -ENOMEM;
1891
1892 ret = rk808_regulator_dt_parse_pdata(&pdev->dev, regmap, pdata);
1893 if (ret < 0)
1894 return ret;
1895
1896 platform_set_drvdata(pdev, pdata);
1897
1898 switch (rk808->variant) {
1899 case RK805_ID:
1900 regulators = rk805_reg;
1901 nregulators = RK805_NUM_REGULATORS;
1902 break;
1903 case RK806_ID:
1904 regulators = rk806_reg;
1905 nregulators = ARRAY_SIZE(rk806_reg);
1906 break;
1907 case RK808_ID:
1908 regulators = rk808_reg;
1909 nregulators = RK808_NUM_REGULATORS;
1910 break;
1911 case RK809_ID:
1912 regulators = rk809_reg;
1913 nregulators = RK809_NUM_REGULATORS;
1914 break;
1915 case RK816_ID:
1916 regulators = rk816_reg;
1917 nregulators = ARRAY_SIZE(rk816_reg);
1918 break;
1919 case RK817_ID:
1920 regulators = rk817_reg;
1921 nregulators = RK817_NUM_REGULATORS;
1922 break;
1923 case RK818_ID:
1924 regulators = rk818_reg;
1925 nregulators = RK818_NUM_REGULATORS;
1926 break;
1927 default:
1928 dev_err(&pdev->dev, "unsupported RK8XX ID %lu\n",
1929 rk808->variant);
1930 return -EINVAL;
1931 }
1932
1933 config.dev = &pdev->dev;
1934 config.driver_data = pdata;
1935 config.regmap = regmap;
1936
1937 /* Instantiate the regulators */
1938 for (i = 0; i < nregulators; i++) {
1939 rk808_rdev = devm_regulator_register(&pdev->dev,
1940 ®ulators[i], &config);
1941 if (IS_ERR(rk808_rdev))
1942 return dev_err_probe(&pdev->dev, PTR_ERR(rk808_rdev),
1943 "failed to register %d regulator\n", i);
1944 }
1945
1946 return 0;
1947 }
1948
1949 static struct platform_driver rk808_regulator_driver = {
1950 .probe = rk808_regulator_probe,
1951 .driver = {
1952 .name = "rk808-regulator",
1953 .probe_type = PROBE_FORCE_SYNCHRONOUS,
1954 },
1955 };
1956
1957 module_platform_driver(rk808_regulator_driver);
1958
1959 MODULE_DESCRIPTION("regulator driver for the RK805/RK808/RK818 series PMICs");
1960 MODULE_AUTHOR("Tony xie <tony.xie@rock-chips.com>");
1961 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
1962 MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
1963 MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
1964 MODULE_AUTHOR("Xu Shengfei <xsf@rock-chips.com>");
1965 MODULE_LICENSE("GPL");
1966 MODULE_ALIAS("platform:rk808-regulator");
1967