1 // SPDX-License-Identifier: GPL-2.0-only
3 * Regulator driver for Rockchip RK805/RK808/RK818
5 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
6 * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
8 * Author: Chris Zhong <zyw@rock-chips.com>
9 * Author: Zhang Qing <zhangqing@rock-chips.com>
10 * Author: Xu Shengfei <xsf@rock-chips.com>
12 * Copyright (C) 2016 PHYTEC Messtechnik GmbH
14 * Author: Wadim Egorov <w.egorov@phytec.de>
17 #include <linux/delay.h>
18 #include <linux/gpio.h>
19 #include <linux/module.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>
28 /* Field Definitions */
29 #define RK808_BUCK_VSEL_MASK 0x3f
30 #define RK808_BUCK4_VSEL_MASK 0xf
31 #define RK808_LDO_VSEL_MASK 0x1f
33 #define RK809_BUCK5_VSEL_MASK 0x7
35 #define RK817_LDO_VSEL_MASK 0x7f
36 #define RK817_BOOST_VSEL_MASK 0x7
37 #define RK817_BUCK_VSEL_MASK 0x7f
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
45 #define RK806_DCDC_SLP_REG_OFFSET 0x0A
46 #define RK806_NLDO_SLP_REG_OFFSET 0x05
47 #define RK806_PLDO_SLP_REG_OFFSET 0x06
49 #define RK806_BUCK_SEL_CNT 0xff
50 #define RK806_LDO_SEL_CNT 0xff
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)
60 #define RK808_DVS2_POL BIT(2)
61 #define RK808_DVS1_POL BIT(1)
63 /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */
64 #define RK808_SLP_REG_OFFSET 1
66 /* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */
67 #define RK808_DVS_REG_OFFSET 2
69 /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */
70 #define RK808_SLP_SET_OFF_REG_OFFSET 2
72 /* max steps for increase voltage of Buck1/2, equal 100mv*/
73 #define MAX_STEPS_ONE_TIME 8
75 #define ENABLE_MASK(id) (BIT(id) | BIT(4 + (id)))
76 #define DISABLE_VAL(id) (BIT(4 + (id)))
78 #define RK817_BOOST_DESC(_id, _match, _supply, _min, _max, _step, _vreg,\
79 _vmask, _ereg, _emask, _enval, _disval, _etime, m_drop) \
82 .supply_name = (_supply), \
83 .of_match = of_match_ptr(_match), \
84 .regulators_node = of_match_ptr("regulators"), \
85 .type = REGULATOR_VOLTAGE, \
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, \
102 #define RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
103 _vmask, _ereg, _emask, _enval, _disval, _etime, _ops) \
106 .supply_name = (_supply), \
107 .of_match = of_match_ptr(_match), \
108 .regulators_node = of_match_ptr("regulators"), \
109 .type = REGULATOR_VOLTAGE, \
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), \
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)
130 #define RK806_REGULATOR(_name, _supply_name, _id, _ops,\
131 _n_voltages, _vr, _er, _lr, ctrl_bit,\
135 .supply_name = _supply_name,\
136 .of_match = of_match_ptr(_name),\
137 .regulators_node = of_match_ptr("regulators"),\
140 .type = REGULATOR_VOLTAGE,\
141 .n_voltages = _n_voltages,\
142 .linear_ranges = _lr,\
143 .n_linear_ranges = ARRAY_SIZE(_lr),\
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,\
153 .ramp_delay_table = _rt, \
154 .n_ramp_values = ARRAY_SIZE(_rt), \
155 .owner = THIS_MODULE,\
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)
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)
168 #define RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
169 _enval, _disval, _ops) \
172 .supply_name = (_supply), \
173 .of_match = of_match_ptr(_match), \
174 .regulators_node = of_match_ptr("regulators"), \
175 .type = REGULATOR_VOLTAGE, \
177 .enable_reg = (_ereg), \
178 .enable_mask = (_emask), \
179 .enable_val = (_enval), \
180 .disable_val = (_disval), \
181 .owner = THIS_MODULE, \
185 #define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask, \
187 RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
188 _emask, _disval, &rk817_switch_ops)
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)
194 struct rk8xx_register_bit {
199 #define RK8XX_REG_BIT(_reg, _bit) \
205 struct rk808_regulator_data {
206 struct gpio_desc *dvs_gpio[2];
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),
214 #define RK809_BUCK5_SEL_CNT (8)
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),
223 #define RK817_BUCK1_MIN0 500000
224 #define RK817_BUCK1_MAX0 1500000
226 #define RK817_BUCK1_MIN1 1600000
227 #define RK817_BUCK1_MAX1 2400000
229 #define RK817_BUCK3_MAX1 3400000
231 #define RK817_BUCK1_STP0 12500
232 #define RK817_BUCK1_STP1 100000
234 #define RK817_BUCK1_SEL0 ((RK817_BUCK1_MAX0 - RK817_BUCK1_MIN0) /\
236 #define RK817_BUCK1_SEL1 ((RK817_BUCK1_MAX1 - RK817_BUCK1_MIN1) /\
239 #define RK817_BUCK3_SEL1 ((RK817_BUCK3_MAX1 - RK817_BUCK1_MIN1) /\
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)
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),
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),
259 static const unsigned int rk808_buck1_2_ramp_table[] = {
260 2000, 4000, 6000, 10000
264 static const unsigned int rk817_buck1_4_ramp_table[] = {
265 3000, 6300, 12500, 25000
268 static int rk806_set_mode_dcdc(struct regulator_dev *rdev, unsigned int mode)
270 int rid = rdev_get_id(rdev);
273 reg = RK806_POWER_FPWM_EN0 + rid / 8;
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);
286 dev_err(rdev_get_dev(rdev), "mode unsupported: %u\n", mode);
293 static unsigned int rk806_get_mode_dcdc(struct regulator_dev *rdev)
295 int rid = rdev_get_id(rdev);
300 reg = RK806_POWER_FPWM_EN0 + rid / 8;
303 err = regmap_read(rdev->regmap, reg, &val);
307 if ((val >> ctr_bit) & FPWM_MODE)
308 return REGULATOR_MODE_FAST;
310 return REGULATOR_MODE_NORMAL;
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),
326 static const unsigned int rk806_ramp_delay_table_dcdc[] = {
327 50000, 25000, 12500, 6250, 3125, 1560, 961, 390
330 static int rk806_set_ramp_delay_dcdc(struct regulator_dev *rdev, int ramp_delay)
332 int rid = rdev_get_id(rdev);
333 int regval, ramp_value, ret;
335 ret = regulator_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
336 rdev->desc->n_ramp_values, &ramp_value);
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]);
343 regval = ramp_value << (ffs(rdev->desc->ramp_mask) - 1);
345 ret = regmap_update_bits(rdev->regmap, rdev->desc->ramp_reg,
346 rdev->desc->ramp_mask, regval);
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.
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,
363 static const unsigned int rk806_ramp_delay_table_ldo[] = {
364 100000, 50000, 25000, 12500, 6280, 3120, 1900, 780
367 static int rk806_set_suspend_voltage_range(struct regulator_dev *rdev, int reg_offset, int uv)
369 int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
375 reg = rdev->desc->vsel_reg + reg_offset;
377 return regmap_update_bits(rdev->regmap, reg, rdev->desc->vsel_mask, sel);
380 static int rk806_set_suspend_voltage_range_dcdc(struct regulator_dev *rdev, int uv)
382 return rk806_set_suspend_voltage_range(rdev, RK806_DCDC_SLP_REG_OFFSET, uv);
385 static int rk806_set_suspend_voltage_range_nldo(struct regulator_dev *rdev, int uv)
387 return rk806_set_suspend_voltage_range(rdev, RK806_NLDO_SLP_REG_OFFSET, uv);
390 static int rk806_set_suspend_voltage_range_pldo(struct regulator_dev *rdev, int uv)
392 return rk806_set_suspend_voltage_range(rdev, RK806_PLDO_SLP_REG_OFFSET, uv);
395 static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
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];
403 if (!gpio || gpiod_get_value(gpio) == 0)
404 return regulator_get_voltage_sel_regmap(rdev);
406 ret = regmap_read(rdev->regmap,
407 rdev->desc->vsel_reg + RK808_DVS_REG_OFFSET,
412 val &= rdev->desc->vsel_mask;
413 val >>= ffs(rdev->desc->vsel_mask) - 1;
418 static int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev *rdev,
422 unsigned int old_sel, tmp, val, mask = rdev->desc->vsel_mask;
424 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
429 old_sel = val & mask;
430 old_sel >>= ffs(mask) - 1;
431 delta_sel = sel - old_sel;
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.
438 while (delta_sel > MAX_STEPS_ONE_TIME) {
439 old_sel += MAX_STEPS_ONE_TIME;
440 val = old_sel << (ffs(mask) - 1);
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.
449 ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
450 delta_sel = sel - old_sel;
453 sel <<= ffs(mask) - 1;
455 ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
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.
467 static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev,
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;
478 return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel);
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);
485 ret = regmap_read(rdev->regmap,
486 reg + RK808_DVS_REG_OFFSET,
493 sel <<= ffs(rdev->desc->vsel_mask) - 1;
494 sel |= old_sel & ~rdev->desc->vsel_mask;
496 ret = regmap_write(rdev->regmap, reg, sel);
500 gpiod_set_value(gpio, !gpio_level);
505 static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
506 unsigned int old_selector,
507 unsigned int new_selector)
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];
513 /* if there is no dvs1/2 pin, we don't need wait extra time here. */
517 return regulator_set_voltage_time_sel(rdev, old_selector, new_selector);
520 static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
523 int sel = regulator_map_voltage_linear(rdev, uv, uv);
528 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
530 return regmap_update_bits(rdev->regmap, reg,
531 rdev->desc->vsel_mask,
535 static int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv)
538 int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
543 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
545 return regmap_update_bits(rdev->regmap, reg,
546 rdev->desc->vsel_mask,
550 static int rk805_set_suspend_enable(struct regulator_dev *rdev)
554 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
556 return regmap_update_bits(rdev->regmap, reg,
557 rdev->desc->enable_mask,
558 rdev->desc->enable_mask);
561 static int rk805_set_suspend_disable(struct regulator_dev *rdev)
565 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
567 return regmap_update_bits(rdev->regmap, reg,
568 rdev->desc->enable_mask,
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),
596 static int rk806_set_suspend_enable(struct regulator_dev *rdev)
598 int rid = rdev_get_id(rdev);
600 return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg,
601 rk806_suspend_bits[rid].bit,
602 rk806_suspend_bits[rid].bit);
605 static int rk806_set_suspend_disable(struct regulator_dev *rdev)
607 int rid = rdev_get_id(rdev);
609 return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg,
610 rk806_suspend_bits[rid].bit, 0);
613 static int rk808_set_suspend_enable(struct regulator_dev *rdev)
617 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
619 return regmap_update_bits(rdev->regmap, reg,
620 rdev->desc->enable_mask,
624 static int rk808_set_suspend_disable(struct regulator_dev *rdev)
628 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
630 return regmap_update_bits(rdev->regmap, reg,
631 rdev->desc->enable_mask,
632 rdev->desc->enable_mask);
635 static int rk817_set_suspend_enable_ctrl(struct regulator_dev *rdev,
639 int id = rdev_get_id(rdev);
640 unsigned int id_slp, msk, val;
642 if (id >= RK817_ID_DCDC1 && id <= RK817_ID_DCDC4)
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);
651 reg = RK817_POWER_SLP_EN_REG(id_slp / 8);
653 msk = BIT(id_slp % 8);
659 return regmap_update_bits(rdev->regmap, reg, msk, val);
662 static int rk817_set_suspend_enable(struct regulator_dev *rdev)
664 return rk817_set_suspend_enable_ctrl(rdev, 1);
667 static int rk817_set_suspend_disable(struct regulator_dev *rdev)
669 return rk817_set_suspend_enable_ctrl(rdev, 0);
672 static int rk8xx_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode)
676 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
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);
686 dev_err(&rdev->dev, "do not support this mode\n");
693 static int rk8xx_set_mode(struct regulator_dev *rdev, unsigned int 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);
703 dev_err(&rdev->dev, "do not support this mode\n");
710 static unsigned int rk8xx_get_mode(struct regulator_dev *rdev)
715 err = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
720 return REGULATOR_MODE_FAST;
722 return REGULATOR_MODE_NORMAL;
725 static int rk8xx_is_enabled_wmsk_regmap(struct regulator_dev *rdev)
730 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
734 /* add write mask bit */
735 val |= (rdev->desc->enable_mask & 0xf0);
736 val &= rdev->desc->enable_mask;
738 if (rdev->desc->enable_is_inverted) {
739 if (rdev->desc->enable_val)
740 return val != rdev->desc->enable_val;
743 if (rdev->desc->enable_val)
744 return val == rdev->desc->enable_val;
748 static unsigned int rk8xx_regulator_of_map_mode(unsigned int mode)
752 return REGULATOR_MODE_FAST;
754 return REGULATOR_MODE_NORMAL;
756 return REGULATOR_MODE_INVALID;
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,
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,
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,
790 .enable = regulator_enable_regmap,
791 .disable = regulator_disable_regmap,
792 .is_enabled = rk8xx_is_enabled_wmsk_regmap,
794 .set_suspend_mode = rk806_set_mode_dcdc,
795 .set_ramp_delay = rk806_set_ramp_delay_dcdc,
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,
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,
809 .enable = regulator_enable_regmap,
810 .disable = regulator_disable_regmap,
811 .is_enabled = regulator_is_enabled_regmap,
813 .set_ramp_delay = regulator_set_ramp_delay_regmap,
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,
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,
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,
828 .enable = regulator_enable_regmap,
829 .disable = regulator_disable_regmap,
830 .is_enabled = regulator_is_enabled_regmap,
832 .set_ramp_delay = regulator_set_ramp_delay_regmap,
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,
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,
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,
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,
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,
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),
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,
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,
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,
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,
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,
959 static const struct regulator_desc rk805_reg[] = {
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,
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,
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,
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,
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,
1001 .enable_reg = RK805_DCDC_EN_REG,
1002 .enable_mask = BIT(2),
1003 .owner = THIS_MODULE,
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),
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,
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,
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,
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),
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 */
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),
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),
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),
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),
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),
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),
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),
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),
1127 static const struct regulator_desc rk808_reg[] = {
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,
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,
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,
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,
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,
1177 .enable_reg = RK808_DCDC_EN_REG,
1178 .enable_mask = BIT(2),
1179 .owner = THIS_MODULE,
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,
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,
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,
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),
1206 .owner = THIS_MODULE,
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,
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,
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,
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,
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,
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)),
1229 static const struct regulator_desc rk809_reg[] = {
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,
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,
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,
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,
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,
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),
1382 RK817_DESC_SWITCH(RK809_ID_SW2, "SWITCH_REG2", "vcc8",
1383 RK817_POWER_EN_REG(3), ENABLE_MASK(3),
1387 static const struct regulator_desc rk817_reg[] = {
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,
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,
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,
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,
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),
1526 static const struct regulator_desc rk818_reg[] = {
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,
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,
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,
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,
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,
1568 .enable_reg = RK818_DCDC_EN_REG,
1569 .enable_mask = BIT(2),
1570 .owner = THIS_MODULE,
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,
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,
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,
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),
1600 .owner = THIS_MODULE,
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,
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,
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,
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,
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,
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)),
1628 static int rk808_regulator_dt_parse_pdata(struct device *dev,
1630 struct rk808_regulator_data *pdata)
1632 struct device_node *np;
1633 int tmp, ret = 0, i;
1635 np = of_get_child_by_name(dev->of_node, "regulators");
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,
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);
1649 if (!pdata->dvs_gpio[i]) {
1650 dev_info(dev, "there is no dvs%d gpio\n", i);
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]) ?
1665 static int rk808_regulator_probe(struct platform_device *pdev)
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;
1675 pdev->dev.of_node = pdev->dev.parent->of_node;
1676 pdev->dev.of_node_reused = true;
1678 regmap = dev_get_regmap(pdev->dev.parent, NULL);
1682 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1686 ret = rk808_regulator_dt_parse_pdata(&pdev->dev, regmap, pdata);
1690 platform_set_drvdata(pdev, pdata);
1692 switch (rk808->variant) {
1694 regulators = rk805_reg;
1695 nregulators = RK805_NUM_REGULATORS;
1698 regulators = rk806_reg;
1699 nregulators = ARRAY_SIZE(rk806_reg);
1702 regulators = rk808_reg;
1703 nregulators = RK808_NUM_REGULATORS;
1706 regulators = rk809_reg;
1707 nregulators = RK809_NUM_REGULATORS;
1710 regulators = rk817_reg;
1711 nregulators = RK817_NUM_REGULATORS;
1714 regulators = rk818_reg;
1715 nregulators = RK818_NUM_REGULATORS;
1718 dev_err(&pdev->dev, "unsupported RK8XX ID %lu\n",
1723 config.dev = &pdev->dev;
1724 config.driver_data = pdata;
1725 config.regmap = regmap;
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);
1739 static struct platform_driver rk808_regulator_driver = {
1740 .probe = rk808_regulator_probe,
1742 .name = "rk808-regulator",
1743 .probe_type = PROBE_FORCE_SYNCHRONOUS,
1747 module_platform_driver(rk808_regulator_driver);
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");