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
7 * Author: Chris Zhong <zyw@rock-chips.com>
8 * Author: Zhang Qing <zhangqing@rock-chips.com>
10 * Copyright (C) 2016 PHYTEC Messtechnik GmbH
12 * Author: Wadim Egorov <w.egorov@phytec.de>
15 #include <linux/delay.h>
16 #include <linux/gpio.h>
17 #include <linux/i2c.h>
18 #include <linux/module.h>
19 #include <linux/of_device.h>
20 #include <linux/of_gpio.h>
21 #include <linux/mfd/rk808.h>
22 #include <linux/regulator/driver.h>
23 #include <linux/regulator/of_regulator.h>
24 #include <linux/gpio/consumer.h>
26 /* Field Definitions */
27 #define RK808_BUCK_VSEL_MASK 0x3f
28 #define RK808_BUCK4_VSEL_MASK 0xf
29 #define RK808_LDO_VSEL_MASK 0x1f
31 #define RK809_BUCK5_VSEL_MASK 0x7
33 #define RK817_LDO_VSEL_MASK 0x7f
34 #define RK817_BOOST_VSEL_MASK 0x7
35 #define RK817_BUCK_VSEL_MASK 0x7f
37 #define RK818_BUCK_VSEL_MASK 0x3f
38 #define RK818_BUCK4_VSEL_MASK 0x1f
39 #define RK818_LDO_VSEL_MASK 0x1f
40 #define RK818_LDO3_ON_VSEL_MASK 0xf
41 #define RK818_BOOST_ON_VSEL_MASK 0xe0
43 /* Ramp rate definitions for buck1 / buck2 only */
44 #define RK808_RAMP_RATE_OFFSET 3
45 #define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET)
46 #define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET)
47 #define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET)
48 #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET)
49 #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET)
51 #define RK808_DVS2_POL BIT(2)
52 #define RK808_DVS1_POL BIT(1)
54 /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */
55 #define RK808_SLP_REG_OFFSET 1
57 /* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */
58 #define RK808_DVS_REG_OFFSET 2
60 /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */
61 #define RK808_SLP_SET_OFF_REG_OFFSET 2
63 /* max steps for increase voltage of Buck1/2, equal 100mv*/
64 #define MAX_STEPS_ONE_TIME 8
66 #define ENABLE_MASK(id) (BIT(id) | BIT(4 + (id)))
67 #define DISABLE_VAL(id) (BIT(4 + (id)))
69 #define RK817_BOOST_DESC(_id, _match, _supply, _min, _max, _step, _vreg,\
70 _vmask, _ereg, _emask, _enval, _disval, _etime, m_drop) \
73 .supply_name = (_supply), \
74 .of_match = of_match_ptr(_match), \
75 .regulators_node = of_match_ptr("regulators"), \
76 .type = REGULATOR_VOLTAGE, \
78 .n_voltages = (((_max) - (_min)) / (_step) + 1), \
79 .owner = THIS_MODULE, \
80 .min_uV = (_min) * 1000, \
81 .uV_step = (_step) * 1000, \
82 .vsel_reg = (_vreg), \
83 .vsel_mask = (_vmask), \
84 .enable_reg = (_ereg), \
85 .enable_mask = (_emask), \
86 .enable_val = (_enval), \
87 .disable_val = (_disval), \
88 .enable_time = (_etime), \
89 .min_dropout_uV = (m_drop) * 1000, \
90 .ops = &rk817_boost_ops, \
93 #define RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
94 _vmask, _ereg, _emask, _enval, _disval, _etime, _ops) \
97 .supply_name = (_supply), \
98 .of_match = of_match_ptr(_match), \
99 .regulators_node = of_match_ptr("regulators"), \
100 .type = REGULATOR_VOLTAGE, \
102 .n_voltages = (((_max) - (_min)) / (_step) + 1), \
103 .owner = THIS_MODULE, \
104 .min_uV = (_min) * 1000, \
105 .uV_step = (_step) * 1000, \
106 .vsel_reg = (_vreg), \
107 .vsel_mask = (_vmask), \
108 .enable_reg = (_ereg), \
109 .enable_mask = (_emask), \
110 .enable_val = (_enval), \
111 .disable_val = (_disval), \
112 .enable_time = (_etime), \
116 #define RK805_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
117 _vmask, _ereg, _emask, _etime) \
118 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
119 _vmask, _ereg, _emask, 0, 0, _etime, &rk805_reg_ops)
121 #define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
122 _vmask, _ereg, _emask, _etime) \
123 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
124 _vmask, _ereg, _emask, 0, 0, _etime, &rk808_reg_ops)
126 #define RK817_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \
127 _vmask, _ereg, _emask, _disval, _etime) \
128 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \
129 _vmask, _ereg, _emask, _emask, _disval, _etime, &rk817_reg_ops)
131 #define RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
132 _enval, _disval, _ops) \
135 .supply_name = (_supply), \
136 .of_match = of_match_ptr(_match), \
137 .regulators_node = of_match_ptr("regulators"), \
138 .type = REGULATOR_VOLTAGE, \
140 .enable_reg = (_ereg), \
141 .enable_mask = (_emask), \
142 .enable_val = (_enval), \
143 .disable_val = (_disval), \
144 .owner = THIS_MODULE, \
148 #define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask, \
150 RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
151 _emask, _disval, &rk817_switch_ops)
153 #define RK8XX_DESC_SWITCH(_id, _match, _supply, _ereg, _emask) \
154 RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \
155 0, 0, &rk808_switch_ops)
157 struct rk808_regulator_data
{
158 struct gpio_desc
*dvs_gpio
[2];
161 static const int rk808_buck_config_regs
[] = {
162 RK808_BUCK1_CONFIG_REG
,
163 RK808_BUCK2_CONFIG_REG
,
164 RK808_BUCK3_CONFIG_REG
,
165 RK808_BUCK4_CONFIG_REG
,
168 static const struct linear_range rk808_ldo3_voltage_ranges
[] = {
169 REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000),
170 REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
173 #define RK809_BUCK5_SEL_CNT (8)
175 static const struct linear_range rk809_buck5_voltage_ranges
[] = {
176 REGULATOR_LINEAR_RANGE(1500000, 0, 0, 0),
177 REGULATOR_LINEAR_RANGE(1800000, 1, 3, 200000),
178 REGULATOR_LINEAR_RANGE(2800000, 4, 5, 200000),
179 REGULATOR_LINEAR_RANGE(3300000, 6, 7, 300000),
182 #define RK817_BUCK1_MIN0 500000
183 #define RK817_BUCK1_MAX0 1500000
185 #define RK817_BUCK1_MIN1 1600000
186 #define RK817_BUCK1_MAX1 2400000
188 #define RK817_BUCK3_MAX1 3400000
190 #define RK817_BUCK1_STP0 12500
191 #define RK817_BUCK1_STP1 100000
193 #define RK817_BUCK1_SEL0 ((RK817_BUCK1_MAX0 - RK817_BUCK1_MIN0) /\
195 #define RK817_BUCK1_SEL1 ((RK817_BUCK1_MAX1 - RK817_BUCK1_MIN1) /\
198 #define RK817_BUCK3_SEL1 ((RK817_BUCK3_MAX1 - RK817_BUCK1_MIN1) /\
201 #define RK817_BUCK1_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK1_SEL1 + 1)
202 #define RK817_BUCK3_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK3_SEL1 + 1)
204 static const struct linear_range rk817_buck1_voltage_ranges
[] = {
205 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0
, 0,
206 RK817_BUCK1_SEL0
, RK817_BUCK1_STP0
),
207 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1
, RK817_BUCK1_SEL0
+ 1,
208 RK817_BUCK1_SEL_CNT
, RK817_BUCK1_STP1
),
211 static const struct linear_range rk817_buck3_voltage_ranges
[] = {
212 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0
, 0,
213 RK817_BUCK1_SEL0
, RK817_BUCK1_STP0
),
214 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1
, RK817_BUCK1_SEL0
+ 1,
215 RK817_BUCK3_SEL_CNT
, RK817_BUCK1_STP1
),
218 static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev
*rdev
)
220 struct rk808_regulator_data
*pdata
= rdev_get_drvdata(rdev
);
221 int id
= rdev_get_id(rdev
);
222 struct gpio_desc
*gpio
= pdata
->dvs_gpio
[id
];
226 if (!gpio
|| gpiod_get_value(gpio
) == 0)
227 return regulator_get_voltage_sel_regmap(rdev
);
229 ret
= regmap_read(rdev
->regmap
,
230 rdev
->desc
->vsel_reg
+ RK808_DVS_REG_OFFSET
,
235 val
&= rdev
->desc
->vsel_mask
;
236 val
>>= ffs(rdev
->desc
->vsel_mask
) - 1;
241 static int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev
*rdev
,
245 unsigned int old_sel
, tmp
, val
, mask
= rdev
->desc
->vsel_mask
;
247 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->vsel_reg
, &val
);
252 old_sel
= val
& mask
;
253 old_sel
>>= ffs(mask
) - 1;
254 delta_sel
= sel
- old_sel
;
257 * If directly modify the register to change the voltage, we will face
258 * the risk of overshoot. Put it into a multi-step, can effectively
259 * avoid this problem, a step is 100mv here.
261 while (delta_sel
> MAX_STEPS_ONE_TIME
) {
262 old_sel
+= MAX_STEPS_ONE_TIME
;
263 val
= old_sel
<< (ffs(mask
) - 1);
267 * i2c is 400kHz (2.5us per bit) and we must transmit _at least_
268 * 3 bytes (24 bits) plus start and stop so 26 bits. So we've
269 * got more than 65 us between each voltage change and thus
270 * won't ramp faster than ~1500 uV / us.
272 ret
= regmap_write(rdev
->regmap
, rdev
->desc
->vsel_reg
, val
);
273 delta_sel
= sel
- old_sel
;
276 sel
<<= ffs(mask
) - 1;
278 ret
= regmap_write(rdev
->regmap
, rdev
->desc
->vsel_reg
, val
);
281 * When we change the voltage register directly, the ramp rate is about
282 * 100000uv/us, wait 1us to make sure the target voltage to be stable,
283 * so we needn't wait extra time after that.
290 static int rk808_buck1_2_set_voltage_sel(struct regulator_dev
*rdev
,
293 struct rk808_regulator_data
*pdata
= rdev_get_drvdata(rdev
);
294 int id
= rdev_get_id(rdev
);
295 struct gpio_desc
*gpio
= pdata
->dvs_gpio
[id
];
296 unsigned int reg
= rdev
->desc
->vsel_reg
;
301 return rk808_buck1_2_i2c_set_voltage_sel(rdev
, sel
);
303 gpio_level
= gpiod_get_value(gpio
);
304 if (gpio_level
== 0) {
305 reg
+= RK808_DVS_REG_OFFSET
;
306 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->vsel_reg
, &old_sel
);
308 ret
= regmap_read(rdev
->regmap
,
309 reg
+ RK808_DVS_REG_OFFSET
,
316 sel
<<= ffs(rdev
->desc
->vsel_mask
) - 1;
317 sel
|= old_sel
& ~rdev
->desc
->vsel_mask
;
319 ret
= regmap_write(rdev
->regmap
, reg
, sel
);
323 gpiod_set_value(gpio
, !gpio_level
);
328 static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev
*rdev
,
329 unsigned int old_selector
,
330 unsigned int new_selector
)
332 struct rk808_regulator_data
*pdata
= rdev_get_drvdata(rdev
);
333 int id
= rdev_get_id(rdev
);
334 struct gpio_desc
*gpio
= pdata
->dvs_gpio
[id
];
336 /* if there is no dvs1/2 pin, we don't need wait extra time here. */
340 return regulator_set_voltage_time_sel(rdev
, old_selector
, new_selector
);
343 static int rk808_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
345 unsigned int ramp_value
= RK808_RAMP_RATE_10MV_PER_US
;
346 unsigned int reg
= rk808_buck_config_regs
[rdev_get_id(rdev
)];
348 switch (ramp_delay
) {
350 ramp_value
= RK808_RAMP_RATE_2MV_PER_US
;
353 ramp_value
= RK808_RAMP_RATE_4MV_PER_US
;
356 ramp_value
= RK808_RAMP_RATE_6MV_PER_US
;
361 pr_warn("%s ramp_delay: %d not supported, setting 10000\n",
362 rdev
->desc
->name
, ramp_delay
);
365 return regmap_update_bits(rdev
->regmap
, reg
,
366 RK808_RAMP_RATE_MASK
, ramp_value
);
372 static int rk817_set_ramp_delay(struct regulator_dev
*rdev
, int ramp_delay
)
374 unsigned int ramp_value
= RK817_RAMP_RATE_25MV_PER_US
;
375 unsigned int reg
= RK817_BUCK_CONFIG_REG(rdev_get_id(rdev
));
377 switch (ramp_delay
) {
379 ramp_value
= RK817_RAMP_RATE_3MV_PER_US
;
382 ramp_value
= RK817_RAMP_RATE_6_3MV_PER_US
;
385 ramp_value
= RK817_RAMP_RATE_12_5MV_PER_US
;
387 case 12501 ... 25000:
391 "%s ramp_delay: %d not supported, setting 25000\n",
392 rdev
->desc
->name
, ramp_delay
);
395 return regmap_update_bits(rdev
->regmap
, reg
,
396 RK817_RAMP_RATE_MASK
, ramp_value
);
399 static int rk808_set_suspend_voltage(struct regulator_dev
*rdev
, int uv
)
402 int sel
= regulator_map_voltage_linear(rdev
, uv
, uv
);
407 reg
= rdev
->desc
->vsel_reg
+ RK808_SLP_REG_OFFSET
;
409 return regmap_update_bits(rdev
->regmap
, reg
,
410 rdev
->desc
->vsel_mask
,
414 static int rk808_set_suspend_voltage_range(struct regulator_dev
*rdev
, int uv
)
417 int sel
= regulator_map_voltage_linear_range(rdev
, uv
, uv
);
422 reg
= rdev
->desc
->vsel_reg
+ RK808_SLP_REG_OFFSET
;
424 return regmap_update_bits(rdev
->regmap
, reg
,
425 rdev
->desc
->vsel_mask
,
429 static int rk805_set_suspend_enable(struct regulator_dev
*rdev
)
433 reg
= rdev
->desc
->enable_reg
+ RK808_SLP_SET_OFF_REG_OFFSET
;
435 return regmap_update_bits(rdev
->regmap
, reg
,
436 rdev
->desc
->enable_mask
,
437 rdev
->desc
->enable_mask
);
440 static int rk805_set_suspend_disable(struct regulator_dev
*rdev
)
444 reg
= rdev
->desc
->enable_reg
+ RK808_SLP_SET_OFF_REG_OFFSET
;
446 return regmap_update_bits(rdev
->regmap
, reg
,
447 rdev
->desc
->enable_mask
,
451 static int rk808_set_suspend_enable(struct regulator_dev
*rdev
)
455 reg
= rdev
->desc
->enable_reg
+ RK808_SLP_SET_OFF_REG_OFFSET
;
457 return regmap_update_bits(rdev
->regmap
, reg
,
458 rdev
->desc
->enable_mask
,
462 static int rk808_set_suspend_disable(struct regulator_dev
*rdev
)
466 reg
= rdev
->desc
->enable_reg
+ RK808_SLP_SET_OFF_REG_OFFSET
;
468 return regmap_update_bits(rdev
->regmap
, reg
,
469 rdev
->desc
->enable_mask
,
470 rdev
->desc
->enable_mask
);
473 static int rk817_set_suspend_enable_ctrl(struct regulator_dev
*rdev
,
477 int id
= rdev_get_id(rdev
);
478 unsigned int id_slp
, msk
, val
;
480 if (id
>= RK817_ID_DCDC1
&& id
<= RK817_ID_DCDC4
)
482 else if (id
>= RK817_ID_LDO1
&& id
<= RK817_ID_LDO8
)
483 id_slp
= 8 + (id
- RK817_ID_LDO1
);
484 else if (id
>= RK817_ID_LDO9
&& id
<= RK809_ID_SW2
)
485 id_slp
= 4 + (id
- RK817_ID_LDO9
);
489 reg
= RK817_POWER_SLP_EN_REG(id_slp
/ 8);
491 msk
= BIT(id_slp
% 8);
497 return regmap_update_bits(rdev
->regmap
, reg
, msk
, val
);
500 static int rk817_set_suspend_enable(struct regulator_dev
*rdev
)
502 return rk817_set_suspend_enable_ctrl(rdev
, 1);
505 static int rk817_set_suspend_disable(struct regulator_dev
*rdev
)
507 return rk817_set_suspend_enable_ctrl(rdev
, 0);
510 static int rk8xx_set_suspend_mode(struct regulator_dev
*rdev
, unsigned int mode
)
514 reg
= rdev
->desc
->vsel_reg
+ RK808_SLP_REG_OFFSET
;
517 case REGULATOR_MODE_FAST
:
518 return regmap_update_bits(rdev
->regmap
, reg
,
519 PWM_MODE_MSK
, FPWM_MODE
);
520 case REGULATOR_MODE_NORMAL
:
521 return regmap_update_bits(rdev
->regmap
, reg
,
522 PWM_MODE_MSK
, AUTO_PWM_MODE
);
524 dev_err(&rdev
->dev
, "do not support this mode\n");
531 static int rk8xx_set_mode(struct regulator_dev
*rdev
, unsigned int mode
)
534 case REGULATOR_MODE_FAST
:
535 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->vsel_reg
,
536 PWM_MODE_MSK
, FPWM_MODE
);
537 case REGULATOR_MODE_NORMAL
:
538 return regmap_update_bits(rdev
->regmap
, rdev
->desc
->vsel_reg
,
539 PWM_MODE_MSK
, AUTO_PWM_MODE
);
541 dev_err(&rdev
->dev
, "do not support this mode\n");
548 static unsigned int rk8xx_get_mode(struct regulator_dev
*rdev
)
553 err
= regmap_read(rdev
->regmap
, rdev
->desc
->vsel_reg
, &val
);
558 return REGULATOR_MODE_FAST
;
560 return REGULATOR_MODE_NORMAL
;
563 static int rk8xx_is_enabled_wmsk_regmap(struct regulator_dev
*rdev
)
568 ret
= regmap_read(rdev
->regmap
, rdev
->desc
->enable_reg
, &val
);
572 /* add write mask bit */
573 val
|= (rdev
->desc
->enable_mask
& 0xf0);
574 val
&= rdev
->desc
->enable_mask
;
576 if (rdev
->desc
->enable_is_inverted
) {
577 if (rdev
->desc
->enable_val
)
578 return val
!= rdev
->desc
->enable_val
;
581 if (rdev
->desc
->enable_val
)
582 return val
== rdev
->desc
->enable_val
;
586 static unsigned int rk8xx_regulator_of_map_mode(unsigned int mode
)
590 return REGULATOR_MODE_FAST
;
592 return REGULATOR_MODE_NORMAL
;
594 return REGULATOR_MODE_INVALID
;
598 static const struct regulator_ops rk805_reg_ops
= {
599 .list_voltage
= regulator_list_voltage_linear
,
600 .map_voltage
= regulator_map_voltage_linear
,
601 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
602 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
603 .enable
= regulator_enable_regmap
,
604 .disable
= regulator_disable_regmap
,
605 .is_enabled
= regulator_is_enabled_regmap
,
606 .set_suspend_voltage
= rk808_set_suspend_voltage
,
607 .set_suspend_enable
= rk805_set_suspend_enable
,
608 .set_suspend_disable
= rk805_set_suspend_disable
,
611 static const struct regulator_ops rk805_switch_ops
= {
612 .enable
= regulator_enable_regmap
,
613 .disable
= regulator_disable_regmap
,
614 .is_enabled
= regulator_is_enabled_regmap
,
615 .set_suspend_enable
= rk805_set_suspend_enable
,
616 .set_suspend_disable
= rk805_set_suspend_disable
,
619 static const struct regulator_ops rk808_buck1_2_ops
= {
620 .list_voltage
= regulator_list_voltage_linear
,
621 .map_voltage
= regulator_map_voltage_linear
,
622 .get_voltage_sel
= rk808_buck1_2_get_voltage_sel_regmap
,
623 .set_voltage_sel
= rk808_buck1_2_set_voltage_sel
,
624 .set_voltage_time_sel
= rk808_buck1_2_set_voltage_time_sel
,
625 .enable
= regulator_enable_regmap
,
626 .disable
= regulator_disable_regmap
,
627 .is_enabled
= regulator_is_enabled_regmap
,
628 .set_ramp_delay
= rk808_set_ramp_delay
,
629 .set_suspend_voltage
= rk808_set_suspend_voltage
,
630 .set_suspend_enable
= rk808_set_suspend_enable
,
631 .set_suspend_disable
= rk808_set_suspend_disable
,
634 static const struct regulator_ops rk808_reg_ops
= {
635 .list_voltage
= regulator_list_voltage_linear
,
636 .map_voltage
= regulator_map_voltage_linear
,
637 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
638 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
639 .enable
= regulator_enable_regmap
,
640 .disable
= regulator_disable_regmap
,
641 .is_enabled
= regulator_is_enabled_regmap
,
642 .set_suspend_voltage
= rk808_set_suspend_voltage
,
643 .set_suspend_enable
= rk808_set_suspend_enable
,
644 .set_suspend_disable
= rk808_set_suspend_disable
,
647 static const struct regulator_ops rk808_reg_ops_ranges
= {
648 .list_voltage
= regulator_list_voltage_linear_range
,
649 .map_voltage
= regulator_map_voltage_linear_range
,
650 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
651 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
652 .enable
= regulator_enable_regmap
,
653 .disable
= regulator_disable_regmap
,
654 .is_enabled
= regulator_is_enabled_regmap
,
655 .set_suspend_voltage
= rk808_set_suspend_voltage_range
,
656 .set_suspend_enable
= rk808_set_suspend_enable
,
657 .set_suspend_disable
= rk808_set_suspend_disable
,
660 static const struct regulator_ops rk808_switch_ops
= {
661 .enable
= regulator_enable_regmap
,
662 .disable
= regulator_disable_regmap
,
663 .is_enabled
= regulator_is_enabled_regmap
,
664 .set_suspend_enable
= rk808_set_suspend_enable
,
665 .set_suspend_disable
= rk808_set_suspend_disable
,
668 static const struct linear_range rk805_buck_1_2_voltage_ranges
[] = {
669 REGULATOR_LINEAR_RANGE(712500, 0, 59, 12500),
670 REGULATOR_LINEAR_RANGE(1800000, 60, 62, 200000),
671 REGULATOR_LINEAR_RANGE(2300000, 63, 63, 0),
674 static const struct regulator_ops rk809_buck5_ops_range
= {
675 .list_voltage
= regulator_list_voltage_linear_range
,
676 .map_voltage
= regulator_map_voltage_linear_range
,
677 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
678 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
679 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
680 .enable
= regulator_enable_regmap
,
681 .disable
= regulator_disable_regmap
,
682 .is_enabled
= rk8xx_is_enabled_wmsk_regmap
,
683 .set_suspend_voltage
= rk808_set_suspend_voltage_range
,
684 .set_suspend_enable
= rk817_set_suspend_enable
,
685 .set_suspend_disable
= rk817_set_suspend_disable
,
688 static const struct regulator_ops rk817_reg_ops
= {
689 .list_voltage
= regulator_list_voltage_linear
,
690 .map_voltage
= regulator_map_voltage_linear
,
691 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
692 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
693 .enable
= regulator_enable_regmap
,
694 .disable
= regulator_disable_regmap
,
695 .is_enabled
= rk8xx_is_enabled_wmsk_regmap
,
696 .set_suspend_voltage
= rk808_set_suspend_voltage
,
697 .set_suspend_enable
= rk817_set_suspend_enable
,
698 .set_suspend_disable
= rk817_set_suspend_disable
,
701 static const struct regulator_ops rk817_boost_ops
= {
702 .list_voltage
= regulator_list_voltage_linear
,
703 .map_voltage
= regulator_map_voltage_linear
,
704 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
705 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
706 .enable
= regulator_enable_regmap
,
707 .disable
= regulator_disable_regmap
,
708 .is_enabled
= rk8xx_is_enabled_wmsk_regmap
,
709 .set_suspend_enable
= rk817_set_suspend_enable
,
710 .set_suspend_disable
= rk817_set_suspend_disable
,
713 static const struct regulator_ops rk817_buck_ops_range
= {
714 .list_voltage
= regulator_list_voltage_linear_range
,
715 .map_voltage
= regulator_map_voltage_linear_range
,
716 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
717 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
718 .set_voltage_time_sel
= regulator_set_voltage_time_sel
,
719 .enable
= regulator_enable_regmap
,
720 .disable
= regulator_disable_regmap
,
721 .is_enabled
= rk8xx_is_enabled_wmsk_regmap
,
722 .set_mode
= rk8xx_set_mode
,
723 .get_mode
= rk8xx_get_mode
,
724 .set_suspend_mode
= rk8xx_set_suspend_mode
,
725 .set_ramp_delay
= rk817_set_ramp_delay
,
726 .set_suspend_voltage
= rk808_set_suspend_voltage_range
,
727 .set_suspend_enable
= rk817_set_suspend_enable
,
728 .set_suspend_disable
= rk817_set_suspend_disable
,
731 static const struct regulator_ops rk817_switch_ops
= {
732 .enable
= regulator_enable_regmap
,
733 .disable
= regulator_disable_regmap
,
734 .is_enabled
= rk8xx_is_enabled_wmsk_regmap
,
735 .set_suspend_enable
= rk817_set_suspend_enable
,
736 .set_suspend_disable
= rk817_set_suspend_disable
,
739 static const struct regulator_desc rk805_reg
[] = {
742 .supply_name
= "vcc1",
743 .of_match
= of_match_ptr("DCDC_REG1"),
744 .regulators_node
= of_match_ptr("regulators"),
745 .id
= RK805_ID_DCDC1
,
746 .ops
= &rk808_reg_ops_ranges
,
747 .type
= REGULATOR_VOLTAGE
,
749 .linear_ranges
= rk805_buck_1_2_voltage_ranges
,
750 .n_linear_ranges
= ARRAY_SIZE(rk805_buck_1_2_voltage_ranges
),
751 .vsel_reg
= RK805_BUCK1_ON_VSEL_REG
,
752 .vsel_mask
= RK818_BUCK_VSEL_MASK
,
753 .enable_reg
= RK805_DCDC_EN_REG
,
754 .enable_mask
= BIT(0),
755 .owner
= THIS_MODULE
,
758 .supply_name
= "vcc2",
759 .of_match
= of_match_ptr("DCDC_REG2"),
760 .regulators_node
= of_match_ptr("regulators"),
761 .id
= RK805_ID_DCDC2
,
762 .ops
= &rk808_reg_ops_ranges
,
763 .type
= REGULATOR_VOLTAGE
,
765 .linear_ranges
= rk805_buck_1_2_voltage_ranges
,
766 .n_linear_ranges
= ARRAY_SIZE(rk805_buck_1_2_voltage_ranges
),
767 .vsel_reg
= RK805_BUCK2_ON_VSEL_REG
,
768 .vsel_mask
= RK818_BUCK_VSEL_MASK
,
769 .enable_reg
= RK805_DCDC_EN_REG
,
770 .enable_mask
= BIT(1),
771 .owner
= THIS_MODULE
,
774 .supply_name
= "vcc3",
775 .of_match
= of_match_ptr("DCDC_REG3"),
776 .regulators_node
= of_match_ptr("regulators"),
777 .id
= RK805_ID_DCDC3
,
778 .ops
= &rk805_switch_ops
,
779 .type
= REGULATOR_VOLTAGE
,
781 .enable_reg
= RK805_DCDC_EN_REG
,
782 .enable_mask
= BIT(2),
783 .owner
= THIS_MODULE
,
786 RK805_DESC(RK805_ID_DCDC4
, "DCDC_REG4", "vcc4", 800, 3400, 100,
787 RK805_BUCK4_ON_VSEL_REG
, RK818_BUCK4_VSEL_MASK
,
788 RK805_DCDC_EN_REG
, BIT(3), 0),
790 RK805_DESC(RK805_ID_LDO1
, "LDO_REG1", "vcc5", 800, 3400, 100,
791 RK805_LDO1_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK805_LDO_EN_REG
,
793 RK805_DESC(RK805_ID_LDO2
, "LDO_REG2", "vcc5", 800, 3400, 100,
794 RK805_LDO2_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK805_LDO_EN_REG
,
796 RK805_DESC(RK805_ID_LDO3
, "LDO_REG3", "vcc6", 800, 3400, 100,
797 RK805_LDO3_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK805_LDO_EN_REG
,
801 static const struct regulator_desc rk808_reg
[] = {
804 .supply_name
= "vcc1",
805 .of_match
= of_match_ptr("DCDC_REG1"),
806 .regulators_node
= of_match_ptr("regulators"),
807 .id
= RK808_ID_DCDC1
,
808 .ops
= &rk808_buck1_2_ops
,
809 .type
= REGULATOR_VOLTAGE
,
813 .vsel_reg
= RK808_BUCK1_ON_VSEL_REG
,
814 .vsel_mask
= RK808_BUCK_VSEL_MASK
,
815 .enable_reg
= RK808_DCDC_EN_REG
,
816 .enable_mask
= BIT(0),
817 .owner
= THIS_MODULE
,
820 .supply_name
= "vcc2",
821 .of_match
= of_match_ptr("DCDC_REG2"),
822 .regulators_node
= of_match_ptr("regulators"),
823 .id
= RK808_ID_DCDC2
,
824 .ops
= &rk808_buck1_2_ops
,
825 .type
= REGULATOR_VOLTAGE
,
829 .vsel_reg
= RK808_BUCK2_ON_VSEL_REG
,
830 .vsel_mask
= RK808_BUCK_VSEL_MASK
,
831 .enable_reg
= RK808_DCDC_EN_REG
,
832 .enable_mask
= BIT(1),
833 .owner
= THIS_MODULE
,
836 .supply_name
= "vcc3",
837 .of_match
= of_match_ptr("DCDC_REG3"),
838 .regulators_node
= of_match_ptr("regulators"),
839 .id
= RK808_ID_DCDC3
,
840 .ops
= &rk808_switch_ops
,
841 .type
= REGULATOR_VOLTAGE
,
843 .enable_reg
= RK808_DCDC_EN_REG
,
844 .enable_mask
= BIT(2),
845 .owner
= THIS_MODULE
,
847 RK8XX_DESC(RK808_ID_DCDC4
, "DCDC_REG4", "vcc4", 1800, 3300, 100,
848 RK808_BUCK4_ON_VSEL_REG
, RK808_BUCK4_VSEL_MASK
,
849 RK808_DCDC_EN_REG
, BIT(3), 0),
850 RK8XX_DESC(RK808_ID_LDO1
, "LDO_REG1", "vcc6", 1800, 3400, 100,
851 RK808_LDO1_ON_VSEL_REG
, RK808_LDO_VSEL_MASK
, RK808_LDO_EN_REG
,
853 RK8XX_DESC(RK808_ID_LDO2
, "LDO_REG2", "vcc6", 1800, 3400, 100,
854 RK808_LDO2_ON_VSEL_REG
, RK808_LDO_VSEL_MASK
, RK808_LDO_EN_REG
,
858 .supply_name
= "vcc7",
859 .of_match
= of_match_ptr("LDO_REG3"),
860 .regulators_node
= of_match_ptr("regulators"),
862 .ops
= &rk808_reg_ops_ranges
,
863 .type
= REGULATOR_VOLTAGE
,
865 .linear_ranges
= rk808_ldo3_voltage_ranges
,
866 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo3_voltage_ranges
),
867 .vsel_reg
= RK808_LDO3_ON_VSEL_REG
,
868 .vsel_mask
= RK808_BUCK4_VSEL_MASK
,
869 .enable_reg
= RK808_LDO_EN_REG
,
870 .enable_mask
= BIT(2),
872 .owner
= THIS_MODULE
,
874 RK8XX_DESC(RK808_ID_LDO4
, "LDO_REG4", "vcc9", 1800, 3400, 100,
875 RK808_LDO4_ON_VSEL_REG
, RK808_LDO_VSEL_MASK
, RK808_LDO_EN_REG
,
877 RK8XX_DESC(RK808_ID_LDO5
, "LDO_REG5", "vcc9", 1800, 3400, 100,
878 RK808_LDO5_ON_VSEL_REG
, RK808_LDO_VSEL_MASK
, RK808_LDO_EN_REG
,
880 RK8XX_DESC(RK808_ID_LDO6
, "LDO_REG6", "vcc10", 800, 2500, 100,
881 RK808_LDO6_ON_VSEL_REG
, RK808_LDO_VSEL_MASK
, RK808_LDO_EN_REG
,
883 RK8XX_DESC(RK808_ID_LDO7
, "LDO_REG7", "vcc7", 800, 2500, 100,
884 RK808_LDO7_ON_VSEL_REG
, RK808_LDO_VSEL_MASK
, RK808_LDO_EN_REG
,
886 RK8XX_DESC(RK808_ID_LDO8
, "LDO_REG8", "vcc11", 1800, 3400, 100,
887 RK808_LDO8_ON_VSEL_REG
, RK808_LDO_VSEL_MASK
, RK808_LDO_EN_REG
,
889 RK8XX_DESC_SWITCH(RK808_ID_SWITCH1
, "SWITCH_REG1", "vcc8",
890 RK808_DCDC_EN_REG
, BIT(5)),
891 RK8XX_DESC_SWITCH(RK808_ID_SWITCH2
, "SWITCH_REG2", "vcc12",
892 RK808_DCDC_EN_REG
, BIT(6)),
895 static const struct regulator_desc rk809_reg
[] = {
898 .supply_name
= "vcc1",
899 .of_match
= of_match_ptr("DCDC_REG1"),
900 .regulators_node
= of_match_ptr("regulators"),
901 .id
= RK817_ID_DCDC1
,
902 .ops
= &rk817_buck_ops_range
,
903 .type
= REGULATOR_VOLTAGE
,
904 .n_voltages
= RK817_BUCK1_SEL_CNT
+ 1,
905 .linear_ranges
= rk817_buck1_voltage_ranges
,
906 .n_linear_ranges
= ARRAY_SIZE(rk817_buck1_voltage_ranges
),
907 .vsel_reg
= RK817_BUCK1_ON_VSEL_REG
,
908 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
909 .enable_reg
= RK817_POWER_EN_REG(0),
910 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC1
),
911 .enable_val
= ENABLE_MASK(RK817_ID_DCDC1
),
912 .disable_val
= DISABLE_VAL(RK817_ID_DCDC1
),
913 .of_map_mode
= rk8xx_regulator_of_map_mode
,
914 .owner
= THIS_MODULE
,
917 .supply_name
= "vcc2",
918 .of_match
= of_match_ptr("DCDC_REG2"),
919 .regulators_node
= of_match_ptr("regulators"),
920 .id
= RK817_ID_DCDC2
,
921 .ops
= &rk817_buck_ops_range
,
922 .type
= REGULATOR_VOLTAGE
,
923 .n_voltages
= RK817_BUCK1_SEL_CNT
+ 1,
924 .linear_ranges
= rk817_buck1_voltage_ranges
,
925 .n_linear_ranges
= ARRAY_SIZE(rk817_buck1_voltage_ranges
),
926 .vsel_reg
= RK817_BUCK2_ON_VSEL_REG
,
927 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
928 .enable_reg
= RK817_POWER_EN_REG(0),
929 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC2
),
930 .enable_val
= ENABLE_MASK(RK817_ID_DCDC2
),
931 .disable_val
= DISABLE_VAL(RK817_ID_DCDC2
),
932 .of_map_mode
= rk8xx_regulator_of_map_mode
,
933 .owner
= THIS_MODULE
,
936 .supply_name
= "vcc3",
937 .of_match
= of_match_ptr("DCDC_REG3"),
938 .regulators_node
= of_match_ptr("regulators"),
939 .id
= RK817_ID_DCDC3
,
940 .ops
= &rk817_buck_ops_range
,
941 .type
= REGULATOR_VOLTAGE
,
942 .n_voltages
= RK817_BUCK1_SEL_CNT
+ 1,
943 .linear_ranges
= rk817_buck1_voltage_ranges
,
944 .n_linear_ranges
= ARRAY_SIZE(rk817_buck1_voltage_ranges
),
945 .vsel_reg
= RK817_BUCK3_ON_VSEL_REG
,
946 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
947 .enable_reg
= RK817_POWER_EN_REG(0),
948 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC3
),
949 .enable_val
= ENABLE_MASK(RK817_ID_DCDC3
),
950 .disable_val
= DISABLE_VAL(RK817_ID_DCDC3
),
951 .of_map_mode
= rk8xx_regulator_of_map_mode
,
952 .owner
= THIS_MODULE
,
955 .supply_name
= "vcc4",
956 .of_match
= of_match_ptr("DCDC_REG4"),
957 .regulators_node
= of_match_ptr("regulators"),
958 .id
= RK817_ID_DCDC4
,
959 .ops
= &rk817_buck_ops_range
,
960 .type
= REGULATOR_VOLTAGE
,
961 .n_voltages
= RK817_BUCK3_SEL_CNT
+ 1,
962 .linear_ranges
= rk817_buck3_voltage_ranges
,
963 .n_linear_ranges
= ARRAY_SIZE(rk817_buck3_voltage_ranges
),
964 .vsel_reg
= RK817_BUCK4_ON_VSEL_REG
,
965 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
966 .enable_reg
= RK817_POWER_EN_REG(0),
967 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC4
),
968 .enable_val
= ENABLE_MASK(RK817_ID_DCDC4
),
969 .disable_val
= DISABLE_VAL(RK817_ID_DCDC4
),
970 .of_map_mode
= rk8xx_regulator_of_map_mode
,
971 .owner
= THIS_MODULE
,
975 .supply_name
= "vcc9",
976 .of_match
= of_match_ptr("DCDC_REG5"),
977 .regulators_node
= of_match_ptr("regulators"),
978 .id
= RK809_ID_DCDC5
,
979 .ops
= &rk809_buck5_ops_range
,
980 .type
= REGULATOR_VOLTAGE
,
981 .n_voltages
= RK809_BUCK5_SEL_CNT
,
982 .linear_ranges
= rk809_buck5_voltage_ranges
,
983 .n_linear_ranges
= ARRAY_SIZE(rk809_buck5_voltage_ranges
),
984 .vsel_reg
= RK809_BUCK5_CONFIG(0),
985 .vsel_mask
= RK809_BUCK5_VSEL_MASK
,
986 .enable_reg
= RK817_POWER_EN_REG(3),
987 .enable_mask
= ENABLE_MASK(1),
988 .enable_val
= ENABLE_MASK(1),
989 .disable_val
= DISABLE_VAL(1),
990 .of_map_mode
= rk8xx_regulator_of_map_mode
,
991 .owner
= THIS_MODULE
,
993 RK817_DESC(RK817_ID_LDO1
, "LDO_REG1", "vcc5", 600, 3400, 25,
994 RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK
,
995 RK817_POWER_EN_REG(1), ENABLE_MASK(0),
996 DISABLE_VAL(0), 400),
997 RK817_DESC(RK817_ID_LDO2
, "LDO_REG2", "vcc5", 600, 3400, 25,
998 RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK
,
999 RK817_POWER_EN_REG(1), ENABLE_MASK(1),
1000 DISABLE_VAL(1), 400),
1001 RK817_DESC(RK817_ID_LDO3
, "LDO_REG3", "vcc5", 600, 3400, 25,
1002 RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK
,
1003 RK817_POWER_EN_REG(1), ENABLE_MASK(2),
1004 DISABLE_VAL(2), 400),
1005 RK817_DESC(RK817_ID_LDO4
, "LDO_REG4", "vcc6", 600, 3400, 25,
1006 RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK
,
1007 RK817_POWER_EN_REG(1), ENABLE_MASK(3),
1008 DISABLE_VAL(3), 400),
1009 RK817_DESC(RK817_ID_LDO5
, "LDO_REG5", "vcc6", 600, 3400, 25,
1010 RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK
,
1011 RK817_POWER_EN_REG(2), ENABLE_MASK(0),
1012 DISABLE_VAL(0), 400),
1013 RK817_DESC(RK817_ID_LDO6
, "LDO_REG6", "vcc6", 600, 3400, 25,
1014 RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK
,
1015 RK817_POWER_EN_REG(2), ENABLE_MASK(1),
1016 DISABLE_VAL(1), 400),
1017 RK817_DESC(RK817_ID_LDO7
, "LDO_REG7", "vcc7", 600, 3400, 25,
1018 RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK
,
1019 RK817_POWER_EN_REG(2), ENABLE_MASK(2),
1020 DISABLE_VAL(2), 400),
1021 RK817_DESC(RK817_ID_LDO8
, "LDO_REG8", "vcc7", 600, 3400, 25,
1022 RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK
,
1023 RK817_POWER_EN_REG(2), ENABLE_MASK(3),
1024 DISABLE_VAL(3), 400),
1025 RK817_DESC(RK817_ID_LDO9
, "LDO_REG9", "vcc7", 600, 3400, 25,
1026 RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK
,
1027 RK817_POWER_EN_REG(3), ENABLE_MASK(0),
1028 DISABLE_VAL(0), 400),
1029 RK817_DESC_SWITCH(RK809_ID_SW1
, "SWITCH_REG1", "vcc9",
1030 RK817_POWER_EN_REG(3), ENABLE_MASK(2),
1032 RK817_DESC_SWITCH(RK809_ID_SW2
, "SWITCH_REG2", "vcc8",
1033 RK817_POWER_EN_REG(3), ENABLE_MASK(3),
1037 static const struct regulator_desc rk817_reg
[] = {
1039 .name
= "DCDC_REG1",
1040 .supply_name
= "vcc1",
1041 .of_match
= of_match_ptr("DCDC_REG1"),
1042 .regulators_node
= of_match_ptr("regulators"),
1043 .id
= RK817_ID_DCDC1
,
1044 .ops
= &rk817_buck_ops_range
,
1045 .type
= REGULATOR_VOLTAGE
,
1046 .n_voltages
= RK817_BUCK1_SEL_CNT
+ 1,
1047 .linear_ranges
= rk817_buck1_voltage_ranges
,
1048 .n_linear_ranges
= ARRAY_SIZE(rk817_buck1_voltage_ranges
),
1049 .vsel_reg
= RK817_BUCK1_ON_VSEL_REG
,
1050 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
1051 .enable_reg
= RK817_POWER_EN_REG(0),
1052 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC1
),
1053 .enable_val
= ENABLE_MASK(RK817_ID_DCDC1
),
1054 .disable_val
= DISABLE_VAL(RK817_ID_DCDC1
),
1055 .of_map_mode
= rk8xx_regulator_of_map_mode
,
1056 .owner
= THIS_MODULE
,
1058 .name
= "DCDC_REG2",
1059 .supply_name
= "vcc2",
1060 .of_match
= of_match_ptr("DCDC_REG2"),
1061 .regulators_node
= of_match_ptr("regulators"),
1062 .id
= RK817_ID_DCDC2
,
1063 .ops
= &rk817_buck_ops_range
,
1064 .type
= REGULATOR_VOLTAGE
,
1065 .n_voltages
= RK817_BUCK1_SEL_CNT
+ 1,
1066 .linear_ranges
= rk817_buck1_voltage_ranges
,
1067 .n_linear_ranges
= ARRAY_SIZE(rk817_buck1_voltage_ranges
),
1068 .vsel_reg
= RK817_BUCK2_ON_VSEL_REG
,
1069 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
1070 .enable_reg
= RK817_POWER_EN_REG(0),
1071 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC2
),
1072 .enable_val
= ENABLE_MASK(RK817_ID_DCDC2
),
1073 .disable_val
= DISABLE_VAL(RK817_ID_DCDC2
),
1074 .of_map_mode
= rk8xx_regulator_of_map_mode
,
1075 .owner
= THIS_MODULE
,
1077 .name
= "DCDC_REG3",
1078 .supply_name
= "vcc3",
1079 .of_match
= of_match_ptr("DCDC_REG3"),
1080 .regulators_node
= of_match_ptr("regulators"),
1081 .id
= RK817_ID_DCDC3
,
1082 .ops
= &rk817_buck_ops_range
,
1083 .type
= REGULATOR_VOLTAGE
,
1084 .n_voltages
= RK817_BUCK1_SEL_CNT
+ 1,
1085 .linear_ranges
= rk817_buck1_voltage_ranges
,
1086 .n_linear_ranges
= ARRAY_SIZE(rk817_buck1_voltage_ranges
),
1087 .vsel_reg
= RK817_BUCK3_ON_VSEL_REG
,
1088 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
1089 .enable_reg
= RK817_POWER_EN_REG(0),
1090 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC3
),
1091 .enable_val
= ENABLE_MASK(RK817_ID_DCDC3
),
1092 .disable_val
= DISABLE_VAL(RK817_ID_DCDC3
),
1093 .of_map_mode
= rk8xx_regulator_of_map_mode
,
1094 .owner
= THIS_MODULE
,
1096 .name
= "DCDC_REG4",
1097 .supply_name
= "vcc4",
1098 .of_match
= of_match_ptr("DCDC_REG4"),
1099 .regulators_node
= of_match_ptr("regulators"),
1100 .id
= RK817_ID_DCDC4
,
1101 .ops
= &rk817_buck_ops_range
,
1102 .type
= REGULATOR_VOLTAGE
,
1103 .n_voltages
= RK817_BUCK3_SEL_CNT
+ 1,
1104 .linear_ranges
= rk817_buck3_voltage_ranges
,
1105 .n_linear_ranges
= ARRAY_SIZE(rk817_buck3_voltage_ranges
),
1106 .vsel_reg
= RK817_BUCK4_ON_VSEL_REG
,
1107 .vsel_mask
= RK817_BUCK_VSEL_MASK
,
1108 .enable_reg
= RK817_POWER_EN_REG(0),
1109 .enable_mask
= ENABLE_MASK(RK817_ID_DCDC4
),
1110 .enable_val
= ENABLE_MASK(RK817_ID_DCDC4
),
1111 .disable_val
= DISABLE_VAL(RK817_ID_DCDC4
),
1112 .of_map_mode
= rk8xx_regulator_of_map_mode
,
1113 .owner
= THIS_MODULE
,
1115 RK817_DESC(RK817_ID_LDO1
, "LDO_REG1", "vcc5", 600, 3400, 25,
1116 RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK
,
1117 RK817_POWER_EN_REG(1), ENABLE_MASK(0),
1118 DISABLE_VAL(0), 400),
1119 RK817_DESC(RK817_ID_LDO2
, "LDO_REG2", "vcc5", 600, 3400, 25,
1120 RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK
,
1121 RK817_POWER_EN_REG(1), ENABLE_MASK(1),
1122 DISABLE_VAL(1), 400),
1123 RK817_DESC(RK817_ID_LDO3
, "LDO_REG3", "vcc5", 600, 3400, 25,
1124 RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK
,
1125 RK817_POWER_EN_REG(1), ENABLE_MASK(2),
1126 DISABLE_VAL(2), 400),
1127 RK817_DESC(RK817_ID_LDO4
, "LDO_REG4", "vcc6", 600, 3400, 25,
1128 RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK
,
1129 RK817_POWER_EN_REG(1), ENABLE_MASK(3),
1130 DISABLE_VAL(3), 400),
1131 RK817_DESC(RK817_ID_LDO5
, "LDO_REG5", "vcc6", 600, 3400, 25,
1132 RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK
,
1133 RK817_POWER_EN_REG(2), ENABLE_MASK(0),
1134 DISABLE_VAL(0), 400),
1135 RK817_DESC(RK817_ID_LDO6
, "LDO_REG6", "vcc6", 600, 3400, 25,
1136 RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK
,
1137 RK817_POWER_EN_REG(2), ENABLE_MASK(1),
1138 DISABLE_VAL(1), 400),
1139 RK817_DESC(RK817_ID_LDO7
, "LDO_REG7", "vcc7", 600, 3400, 25,
1140 RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK
,
1141 RK817_POWER_EN_REG(2), ENABLE_MASK(2),
1142 DISABLE_VAL(2), 400),
1143 RK817_DESC(RK817_ID_LDO8
, "LDO_REG8", "vcc7", 600, 3400, 25,
1144 RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK
,
1145 RK817_POWER_EN_REG(2), ENABLE_MASK(3),
1146 DISABLE_VAL(3), 400),
1147 RK817_DESC(RK817_ID_LDO9
, "LDO_REG9", "vcc7", 600, 3400, 25,
1148 RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK
,
1149 RK817_POWER_EN_REG(3), ENABLE_MASK(0),
1150 DISABLE_VAL(0), 400),
1151 RK817_BOOST_DESC(RK817_ID_BOOST
, "BOOST", "vcc8", 4700, 5400, 100,
1152 RK817_BOOST_OTG_CFG
, RK817_BOOST_VSEL_MASK
,
1153 RK817_POWER_EN_REG(3), ENABLE_MASK(1), ENABLE_MASK(1),
1154 DISABLE_VAL(1), 400, 3500 - 5400),
1155 RK817_DESC_SWITCH(RK817_ID_BOOST_OTG_SW
, "OTG_SWITCH", "vcc9",
1156 RK817_POWER_EN_REG(3), ENABLE_MASK(2),
1160 static const struct regulator_desc rk818_reg
[] = {
1162 .name
= "DCDC_REG1",
1163 .supply_name
= "vcc1",
1164 .of_match
= of_match_ptr("DCDC_REG1"),
1165 .regulators_node
= of_match_ptr("regulators"),
1166 .id
= RK818_ID_DCDC1
,
1167 .ops
= &rk808_reg_ops
,
1168 .type
= REGULATOR_VOLTAGE
,
1172 .vsel_reg
= RK818_BUCK1_ON_VSEL_REG
,
1173 .vsel_mask
= RK818_BUCK_VSEL_MASK
,
1174 .enable_reg
= RK818_DCDC_EN_REG
,
1175 .enable_mask
= BIT(0),
1176 .owner
= THIS_MODULE
,
1178 .name
= "DCDC_REG2",
1179 .supply_name
= "vcc2",
1180 .of_match
= of_match_ptr("DCDC_REG2"),
1181 .regulators_node
= of_match_ptr("regulators"),
1182 .id
= RK818_ID_DCDC2
,
1183 .ops
= &rk808_reg_ops
,
1184 .type
= REGULATOR_VOLTAGE
,
1188 .vsel_reg
= RK818_BUCK2_ON_VSEL_REG
,
1189 .vsel_mask
= RK818_BUCK_VSEL_MASK
,
1190 .enable_reg
= RK818_DCDC_EN_REG
,
1191 .enable_mask
= BIT(1),
1192 .owner
= THIS_MODULE
,
1194 .name
= "DCDC_REG3",
1195 .supply_name
= "vcc3",
1196 .of_match
= of_match_ptr("DCDC_REG3"),
1197 .regulators_node
= of_match_ptr("regulators"),
1198 .id
= RK818_ID_DCDC3
,
1199 .ops
= &rk808_switch_ops
,
1200 .type
= REGULATOR_VOLTAGE
,
1202 .enable_reg
= RK818_DCDC_EN_REG
,
1203 .enable_mask
= BIT(2),
1204 .owner
= THIS_MODULE
,
1206 RK8XX_DESC(RK818_ID_DCDC4
, "DCDC_REG4", "vcc4", 1800, 3600, 100,
1207 RK818_BUCK4_ON_VSEL_REG
, RK818_BUCK4_VSEL_MASK
,
1208 RK818_DCDC_EN_REG
, BIT(3), 0),
1209 RK8XX_DESC(RK818_ID_BOOST
, "DCDC_BOOST", "boost", 4700, 5400, 100,
1210 RK818_BOOST_LDO9_ON_VSEL_REG
, RK818_BOOST_ON_VSEL_MASK
,
1211 RK818_DCDC_EN_REG
, BIT(4), 0),
1212 RK8XX_DESC(RK818_ID_LDO1
, "LDO_REG1", "vcc6", 1800, 3400, 100,
1213 RK818_LDO1_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK818_LDO_EN_REG
,
1215 RK8XX_DESC(RK818_ID_LDO2
, "LDO_REG2", "vcc6", 1800, 3400, 100,
1216 RK818_LDO2_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK818_LDO_EN_REG
,
1220 .supply_name
= "vcc7",
1221 .of_match
= of_match_ptr("LDO_REG3"),
1222 .regulators_node
= of_match_ptr("regulators"),
1223 .id
= RK818_ID_LDO3
,
1224 .ops
= &rk808_reg_ops_ranges
,
1225 .type
= REGULATOR_VOLTAGE
,
1227 .linear_ranges
= rk808_ldo3_voltage_ranges
,
1228 .n_linear_ranges
= ARRAY_SIZE(rk808_ldo3_voltage_ranges
),
1229 .vsel_reg
= RK818_LDO3_ON_VSEL_REG
,
1230 .vsel_mask
= RK818_LDO3_ON_VSEL_MASK
,
1231 .enable_reg
= RK818_LDO_EN_REG
,
1232 .enable_mask
= BIT(2),
1234 .owner
= THIS_MODULE
,
1236 RK8XX_DESC(RK818_ID_LDO4
, "LDO_REG4", "vcc8", 1800, 3400, 100,
1237 RK818_LDO4_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK818_LDO_EN_REG
,
1239 RK8XX_DESC(RK818_ID_LDO5
, "LDO_REG5", "vcc7", 1800, 3400, 100,
1240 RK818_LDO5_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK818_LDO_EN_REG
,
1242 RK8XX_DESC(RK818_ID_LDO6
, "LDO_REG6", "vcc8", 800, 2500, 100,
1243 RK818_LDO6_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK818_LDO_EN_REG
,
1245 RK8XX_DESC(RK818_ID_LDO7
, "LDO_REG7", "vcc7", 800, 2500, 100,
1246 RK818_LDO7_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK818_LDO_EN_REG
,
1248 RK8XX_DESC(RK818_ID_LDO8
, "LDO_REG8", "vcc8", 1800, 3400, 100,
1249 RK818_LDO8_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
, RK818_LDO_EN_REG
,
1251 RK8XX_DESC(RK818_ID_LDO9
, "LDO_REG9", "vcc9", 1800, 3400, 100,
1252 RK818_BOOST_LDO9_ON_VSEL_REG
, RK818_LDO_VSEL_MASK
,
1253 RK818_DCDC_EN_REG
, BIT(5), 400),
1254 RK8XX_DESC_SWITCH(RK818_ID_SWITCH
, "SWITCH_REG", "vcc9",
1255 RK818_DCDC_EN_REG
, BIT(6)),
1256 RK8XX_DESC_SWITCH(RK818_ID_HDMI_SWITCH
, "HDMI_SWITCH", "h_5v",
1257 RK818_H5V_EN_REG
, BIT(0)),
1258 RK8XX_DESC_SWITCH(RK818_ID_OTG_SWITCH
, "OTG_SWITCH", "usb",
1259 RK818_DCDC_EN_REG
, BIT(7)),
1262 static int rk808_regulator_dt_parse_pdata(struct device
*dev
,
1263 struct device
*client_dev
,
1265 struct rk808_regulator_data
*pdata
)
1267 struct device_node
*np
;
1268 int tmp
, ret
= 0, i
;
1270 np
= of_get_child_by_name(client_dev
->of_node
, "regulators");
1274 for (i
= 0; i
< ARRAY_SIZE(pdata
->dvs_gpio
); i
++) {
1275 pdata
->dvs_gpio
[i
] =
1276 devm_gpiod_get_index_optional(client_dev
, "dvs", i
,
1278 if (IS_ERR(pdata
->dvs_gpio
[i
])) {
1279 ret
= PTR_ERR(pdata
->dvs_gpio
[i
]);
1280 dev_err(dev
, "failed to get dvs%d gpio (%d)\n", i
, ret
);
1284 if (!pdata
->dvs_gpio
[i
]) {
1285 dev_info(dev
, "there is no dvs%d gpio\n", i
);
1289 tmp
= i
? RK808_DVS2_POL
: RK808_DVS1_POL
;
1290 ret
= regmap_update_bits(map
, RK808_IO_POL_REG
, tmp
,
1291 gpiod_is_active_low(pdata
->dvs_gpio
[i
]) ?
1300 static int rk808_regulator_probe(struct platform_device
*pdev
)
1302 struct rk808
*rk808
= dev_get_drvdata(pdev
->dev
.parent
);
1303 struct i2c_client
*client
= rk808
->i2c
;
1304 struct regulator_config config
= {};
1305 struct regulator_dev
*rk808_rdev
;
1306 struct rk808_regulator_data
*pdata
;
1307 const struct regulator_desc
*regulators
;
1308 int ret
, i
, nregulators
;
1310 pdata
= devm_kzalloc(&pdev
->dev
, sizeof(*pdata
), GFP_KERNEL
);
1314 ret
= rk808_regulator_dt_parse_pdata(&pdev
->dev
, &client
->dev
,
1315 rk808
->regmap
, pdata
);
1319 platform_set_drvdata(pdev
, pdata
);
1321 switch (rk808
->variant
) {
1323 regulators
= rk805_reg
;
1324 nregulators
= RK805_NUM_REGULATORS
;
1327 regulators
= rk808_reg
;
1328 nregulators
= RK808_NUM_REGULATORS
;
1331 regulators
= rk809_reg
;
1332 nregulators
= RK809_NUM_REGULATORS
;
1335 regulators
= rk817_reg
;
1336 nregulators
= RK817_NUM_REGULATORS
;
1339 regulators
= rk818_reg
;
1340 nregulators
= RK818_NUM_REGULATORS
;
1343 dev_err(&client
->dev
, "unsupported RK8XX ID %lu\n",
1348 config
.dev
= &client
->dev
;
1349 config
.driver_data
= pdata
;
1350 config
.regmap
= rk808
->regmap
;
1352 /* Instantiate the regulators */
1353 for (i
= 0; i
< nregulators
; i
++) {
1354 rk808_rdev
= devm_regulator_register(&pdev
->dev
,
1355 ®ulators
[i
], &config
);
1356 if (IS_ERR(rk808_rdev
)) {
1357 dev_err(&client
->dev
,
1358 "failed to register %d regulator\n", i
);
1359 return PTR_ERR(rk808_rdev
);
1366 static struct platform_driver rk808_regulator_driver
= {
1367 .probe
= rk808_regulator_probe
,
1369 .name
= "rk808-regulator"
1373 module_platform_driver(rk808_regulator_driver
);
1375 MODULE_DESCRIPTION("regulator driver for the RK805/RK808/RK818 series PMICs");
1376 MODULE_AUTHOR("Tony xie <tony.xie@rock-chips.com>");
1377 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
1378 MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
1379 MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
1380 MODULE_LICENSE("GPL");
1381 MODULE_ALIAS("platform:rk808-regulator");