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