162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Regulator driver for Rockchip RK805/RK808/RK818
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
662306a36Sopenharmony_ci * Copyright (c) 2021 Rockchip Electronics Co., Ltd.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Author: Chris Zhong <zyw@rock-chips.com>
962306a36Sopenharmony_ci * Author: Zhang Qing <zhangqing@rock-chips.com>
1062306a36Sopenharmony_ci * Author: Xu Shengfei <xsf@rock-chips.com>
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * Copyright (C) 2016 PHYTEC Messtechnik GmbH
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * Author: Wadim Egorov <w.egorov@phytec.de>
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#include <linux/delay.h>
1862306a36Sopenharmony_ci#include <linux/gpio.h>
1962306a36Sopenharmony_ci#include <linux/module.h>
2062306a36Sopenharmony_ci#include <linux/of.h>
2162306a36Sopenharmony_ci#include <linux/of_gpio.h>
2262306a36Sopenharmony_ci#include <linux/mfd/rk808.h>
2362306a36Sopenharmony_ci#include <linux/platform_device.h>
2462306a36Sopenharmony_ci#include <linux/regulator/driver.h>
2562306a36Sopenharmony_ci#include <linux/regulator/of_regulator.h>
2662306a36Sopenharmony_ci#include <linux/gpio/consumer.h>
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* Field Definitions */
2962306a36Sopenharmony_ci#define RK808_BUCK_VSEL_MASK	0x3f
3062306a36Sopenharmony_ci#define RK808_BUCK4_VSEL_MASK	0xf
3162306a36Sopenharmony_ci#define RK808_LDO_VSEL_MASK	0x1f
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#define RK809_BUCK5_VSEL_MASK		0x7
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define RK817_LDO_VSEL_MASK		0x7f
3662306a36Sopenharmony_ci#define RK817_BOOST_VSEL_MASK		0x7
3762306a36Sopenharmony_ci#define RK817_BUCK_VSEL_MASK		0x7f
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci#define RK818_BUCK_VSEL_MASK		0x3f
4062306a36Sopenharmony_ci#define RK818_BUCK4_VSEL_MASK		0x1f
4162306a36Sopenharmony_ci#define RK818_LDO_VSEL_MASK		0x1f
4262306a36Sopenharmony_ci#define RK818_LDO3_ON_VSEL_MASK		0xf
4362306a36Sopenharmony_ci#define RK818_BOOST_ON_VSEL_MASK	0xe0
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define RK806_DCDC_SLP_REG_OFFSET	0x0A
4662306a36Sopenharmony_ci#define RK806_NLDO_SLP_REG_OFFSET	0x05
4762306a36Sopenharmony_ci#define RK806_PLDO_SLP_REG_OFFSET	0x06
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define RK806_BUCK_SEL_CNT		0xff
5062306a36Sopenharmony_ci#define RK806_LDO_SEL_CNT		0xff
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci/* Ramp rate definitions for buck1 / buck2 only */
5362306a36Sopenharmony_ci#define RK808_RAMP_RATE_OFFSET		3
5462306a36Sopenharmony_ci#define RK808_RAMP_RATE_MASK		(3 << RK808_RAMP_RATE_OFFSET)
5562306a36Sopenharmony_ci#define RK808_RAMP_RATE_2MV_PER_US	(0 << RK808_RAMP_RATE_OFFSET)
5662306a36Sopenharmony_ci#define RK808_RAMP_RATE_4MV_PER_US	(1 << RK808_RAMP_RATE_OFFSET)
5762306a36Sopenharmony_ci#define RK808_RAMP_RATE_6MV_PER_US	(2 << RK808_RAMP_RATE_OFFSET)
5862306a36Sopenharmony_ci#define RK808_RAMP_RATE_10MV_PER_US	(3 << RK808_RAMP_RATE_OFFSET)
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define RK808_DVS2_POL		BIT(2)
6162306a36Sopenharmony_ci#define RK808_DVS1_POL		BIT(1)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */
6462306a36Sopenharmony_ci#define RK808_SLP_REG_OFFSET 1
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */
6762306a36Sopenharmony_ci#define RK808_DVS_REG_OFFSET 2
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci/* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */
7062306a36Sopenharmony_ci#define RK808_SLP_SET_OFF_REG_OFFSET 2
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* max steps for increase voltage of Buck1/2, equal 100mv*/
7362306a36Sopenharmony_ci#define MAX_STEPS_ONE_TIME 8
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define ENABLE_MASK(id)			(BIT(id) | BIT(4 + (id)))
7662306a36Sopenharmony_ci#define DISABLE_VAL(id)			(BIT(4 + (id)))
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define RK817_BOOST_DESC(_id, _match, _supply, _min, _max, _step, _vreg,\
7962306a36Sopenharmony_ci	_vmask, _ereg, _emask, _enval, _disval, _etime, m_drop)		\
8062306a36Sopenharmony_ci	{							\
8162306a36Sopenharmony_ci		.name		= (_match),				\
8262306a36Sopenharmony_ci		.supply_name	= (_supply),				\
8362306a36Sopenharmony_ci		.of_match	= of_match_ptr(_match),			\
8462306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),		\
8562306a36Sopenharmony_ci		.type		= REGULATOR_VOLTAGE,			\
8662306a36Sopenharmony_ci		.id		= (_id),				\
8762306a36Sopenharmony_ci		.n_voltages	= (((_max) - (_min)) / (_step) + 1),	\
8862306a36Sopenharmony_ci		.owner		= THIS_MODULE,				\
8962306a36Sopenharmony_ci		.min_uV		= (_min) * 1000,			\
9062306a36Sopenharmony_ci		.uV_step	= (_step) * 1000,			\
9162306a36Sopenharmony_ci		.vsel_reg	= (_vreg),				\
9262306a36Sopenharmony_ci		.vsel_mask	= (_vmask),				\
9362306a36Sopenharmony_ci		.enable_reg	= (_ereg),				\
9462306a36Sopenharmony_ci		.enable_mask	= (_emask),				\
9562306a36Sopenharmony_ci		.enable_val     = (_enval),				\
9662306a36Sopenharmony_ci		.disable_val     = (_disval),				\
9762306a36Sopenharmony_ci		.enable_time	= (_etime),				\
9862306a36Sopenharmony_ci		.min_dropout_uV = (m_drop) * 1000,			\
9962306a36Sopenharmony_ci		.ops		= &rk817_boost_ops,			\
10062306a36Sopenharmony_ci	}
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci#define RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg,	\
10362306a36Sopenharmony_ci	_vmask, _ereg, _emask, _enval, _disval, _etime, _ops)		\
10462306a36Sopenharmony_ci	{								\
10562306a36Sopenharmony_ci		.name		= (_match),				\
10662306a36Sopenharmony_ci		.supply_name	= (_supply),				\
10762306a36Sopenharmony_ci		.of_match	= of_match_ptr(_match),			\
10862306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),		\
10962306a36Sopenharmony_ci		.type		= REGULATOR_VOLTAGE,			\
11062306a36Sopenharmony_ci		.id		= (_id),				\
11162306a36Sopenharmony_ci		.n_voltages	= (((_max) - (_min)) / (_step) + 1),	\
11262306a36Sopenharmony_ci		.owner		= THIS_MODULE,				\
11362306a36Sopenharmony_ci		.min_uV		= (_min) * 1000,			\
11462306a36Sopenharmony_ci		.uV_step	= (_step) * 1000,			\
11562306a36Sopenharmony_ci		.vsel_reg	= (_vreg),				\
11662306a36Sopenharmony_ci		.vsel_mask	= (_vmask),				\
11762306a36Sopenharmony_ci		.enable_reg	= (_ereg),				\
11862306a36Sopenharmony_ci		.enable_mask	= (_emask),				\
11962306a36Sopenharmony_ci		.enable_val     = (_enval),				\
12062306a36Sopenharmony_ci		.disable_val     = (_disval),				\
12162306a36Sopenharmony_ci		.enable_time	= (_etime),				\
12262306a36Sopenharmony_ci		.ops		= _ops,			\
12362306a36Sopenharmony_ci	}
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci#define RK805_DESC(_id, _match, _supply, _min, _max, _step, _vreg,	\
12662306a36Sopenharmony_ci	_vmask, _ereg, _emask, _etime)					\
12762306a36Sopenharmony_ci	RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg,	\
12862306a36Sopenharmony_ci	_vmask, _ereg, _emask, 0, 0, _etime, &rk805_reg_ops)
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci#define RK806_REGULATOR(_name, _supply_name, _id, _ops,\
13162306a36Sopenharmony_ci			_n_voltages, _vr, _er, _lr, ctrl_bit,\
13262306a36Sopenharmony_ci			_rr, _rm, _rt)\
13362306a36Sopenharmony_ci[_id] = {\
13462306a36Sopenharmony_ci		.name = _name,\
13562306a36Sopenharmony_ci		.supply_name = _supply_name,\
13662306a36Sopenharmony_ci		.of_match = of_match_ptr(_name),\
13762306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),\
13862306a36Sopenharmony_ci		.id = _id,\
13962306a36Sopenharmony_ci		.ops = &_ops,\
14062306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,\
14162306a36Sopenharmony_ci		.n_voltages = _n_voltages,\
14262306a36Sopenharmony_ci		.linear_ranges = _lr,\
14362306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(_lr),\
14462306a36Sopenharmony_ci		.vsel_reg = _vr,\
14562306a36Sopenharmony_ci		.vsel_mask = 0xff,\
14662306a36Sopenharmony_ci		.enable_reg = _er,\
14762306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(ctrl_bit),\
14862306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(ctrl_bit),\
14962306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(ctrl_bit),\
15062306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,\
15162306a36Sopenharmony_ci		.ramp_reg = _rr,\
15262306a36Sopenharmony_ci		.ramp_mask = _rm,\
15362306a36Sopenharmony_ci		.ramp_delay_table = _rt, \
15462306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(_rt), \
15562306a36Sopenharmony_ci		.owner = THIS_MODULE,\
15662306a36Sopenharmony_ci	}
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci#define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg,	\
15962306a36Sopenharmony_ci	_vmask, _ereg, _emask, _etime)					\
16062306a36Sopenharmony_ci	RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg,	\
16162306a36Sopenharmony_ci	_vmask, _ereg, _emask, 0, 0, _etime, &rk808_reg_ops)
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci#define RK817_DESC(_id, _match, _supply, _min, _max, _step, _vreg,	\
16462306a36Sopenharmony_ci	_vmask, _ereg, _emask, _disval, _etime)				\
16562306a36Sopenharmony_ci	RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg,	\
16662306a36Sopenharmony_ci	_vmask, _ereg, _emask, _emask, _disval, _etime, &rk817_reg_ops)
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci#define RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask,	\
16962306a36Sopenharmony_ci	_enval, _disval, _ops)						\
17062306a36Sopenharmony_ci	{								\
17162306a36Sopenharmony_ci		.name		= (_match),				\
17262306a36Sopenharmony_ci		.supply_name	= (_supply),				\
17362306a36Sopenharmony_ci		.of_match	= of_match_ptr(_match),			\
17462306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),		\
17562306a36Sopenharmony_ci		.type		= REGULATOR_VOLTAGE,			\
17662306a36Sopenharmony_ci		.id		= (_id),				\
17762306a36Sopenharmony_ci		.enable_reg	= (_ereg),				\
17862306a36Sopenharmony_ci		.enable_mask	= (_emask),				\
17962306a36Sopenharmony_ci		.enable_val     = (_enval),				\
18062306a36Sopenharmony_ci		.disable_val     = (_disval),				\
18162306a36Sopenharmony_ci		.owner		= THIS_MODULE,				\
18262306a36Sopenharmony_ci		.ops		= _ops					\
18362306a36Sopenharmony_ci	}
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci#define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask,		\
18662306a36Sopenharmony_ci	_disval)							\
18762306a36Sopenharmony_ci	RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask,	\
18862306a36Sopenharmony_ci	_emask, _disval, &rk817_switch_ops)
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci#define RK8XX_DESC_SWITCH(_id, _match, _supply, _ereg, _emask)		\
19162306a36Sopenharmony_ci	RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask,	\
19262306a36Sopenharmony_ci	0, 0, &rk808_switch_ops)
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_cistruct rk8xx_register_bit {
19562306a36Sopenharmony_ci	u8 reg;
19662306a36Sopenharmony_ci	u8 bit;
19762306a36Sopenharmony_ci};
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci#define RK8XX_REG_BIT(_reg, _bit)					\
20062306a36Sopenharmony_ci	{								\
20162306a36Sopenharmony_ci		.reg = _reg,						\
20262306a36Sopenharmony_ci		.bit = BIT(_bit),						\
20362306a36Sopenharmony_ci	}
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_cistruct rk808_regulator_data {
20662306a36Sopenharmony_ci	struct gpio_desc *dvs_gpio[2];
20762306a36Sopenharmony_ci};
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_cistatic const struct linear_range rk808_ldo3_voltage_ranges[] = {
21062306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000),
21162306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0),
21262306a36Sopenharmony_ci};
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci#define RK809_BUCK5_SEL_CNT		(8)
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_cistatic const struct linear_range rk809_buck5_voltage_ranges[] = {
21762306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1500000, 0, 0, 0),
21862306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1800000, 1, 3, 200000),
21962306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(2800000, 4, 5, 200000),
22062306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(3300000, 6, 7, 300000),
22162306a36Sopenharmony_ci};
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci#define RK817_BUCK1_MIN0 500000
22462306a36Sopenharmony_ci#define RK817_BUCK1_MAX0 1500000
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci#define RK817_BUCK1_MIN1 1600000
22762306a36Sopenharmony_ci#define RK817_BUCK1_MAX1 2400000
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci#define RK817_BUCK3_MAX1 3400000
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci#define RK817_BUCK1_STP0 12500
23262306a36Sopenharmony_ci#define RK817_BUCK1_STP1 100000
23362306a36Sopenharmony_ci
23462306a36Sopenharmony_ci#define RK817_BUCK1_SEL0 ((RK817_BUCK1_MAX0 - RK817_BUCK1_MIN0) /\
23562306a36Sopenharmony_ci						  RK817_BUCK1_STP0)
23662306a36Sopenharmony_ci#define RK817_BUCK1_SEL1 ((RK817_BUCK1_MAX1 - RK817_BUCK1_MIN1) /\
23762306a36Sopenharmony_ci						  RK817_BUCK1_STP1)
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci#define RK817_BUCK3_SEL1 ((RK817_BUCK3_MAX1 - RK817_BUCK1_MIN1) /\
24062306a36Sopenharmony_ci						  RK817_BUCK1_STP1)
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci#define RK817_BUCK1_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK1_SEL1 + 1)
24362306a36Sopenharmony_ci#define RK817_BUCK3_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK3_SEL1 + 1)
24462306a36Sopenharmony_ci
24562306a36Sopenharmony_cistatic const struct linear_range rk817_buck1_voltage_ranges[] = {
24662306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
24762306a36Sopenharmony_ci			       RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
24862306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
24962306a36Sopenharmony_ci			       RK817_BUCK1_SEL_CNT, RK817_BUCK1_STP1),
25062306a36Sopenharmony_ci};
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_cistatic const struct linear_range rk817_buck3_voltage_ranges[] = {
25362306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0,
25462306a36Sopenharmony_ci			       RK817_BUCK1_SEL0, RK817_BUCK1_STP0),
25562306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1,
25662306a36Sopenharmony_ci			       RK817_BUCK3_SEL_CNT, RK817_BUCK1_STP1),
25762306a36Sopenharmony_ci};
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_cistatic const unsigned int rk808_buck1_2_ramp_table[] = {
26062306a36Sopenharmony_ci	2000, 4000, 6000, 10000
26162306a36Sopenharmony_ci};
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci/* RK817 RK809 */
26462306a36Sopenharmony_cistatic const unsigned int rk817_buck1_4_ramp_table[] = {
26562306a36Sopenharmony_ci	3000, 6300, 12500, 25000
26662306a36Sopenharmony_ci};
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_cistatic int rk806_set_mode_dcdc(struct regulator_dev *rdev, unsigned int mode)
26962306a36Sopenharmony_ci{
27062306a36Sopenharmony_ci	int rid = rdev_get_id(rdev);
27162306a36Sopenharmony_ci	int ctr_bit, reg;
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci	reg = RK806_POWER_FPWM_EN0 + rid / 8;
27462306a36Sopenharmony_ci	ctr_bit = rid % 8;
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci	switch (mode) {
27762306a36Sopenharmony_ci	case REGULATOR_MODE_FAST:
27862306a36Sopenharmony_ci		return regmap_update_bits(rdev->regmap, reg,
27962306a36Sopenharmony_ci					  PWM_MODE_MSK << ctr_bit,
28062306a36Sopenharmony_ci					  FPWM_MODE << ctr_bit);
28162306a36Sopenharmony_ci	case REGULATOR_MODE_NORMAL:
28262306a36Sopenharmony_ci		return regmap_update_bits(rdev->regmap, reg,
28362306a36Sopenharmony_ci					  PWM_MODE_MSK << ctr_bit,
28462306a36Sopenharmony_ci					  AUTO_PWM_MODE << ctr_bit);
28562306a36Sopenharmony_ci	default:
28662306a36Sopenharmony_ci		dev_err(rdev_get_dev(rdev), "mode unsupported: %u\n", mode);
28762306a36Sopenharmony_ci		return -EINVAL;
28862306a36Sopenharmony_ci	}
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci	return 0;
29162306a36Sopenharmony_ci}
29262306a36Sopenharmony_ci
29362306a36Sopenharmony_cistatic unsigned int rk806_get_mode_dcdc(struct regulator_dev *rdev)
29462306a36Sopenharmony_ci{
29562306a36Sopenharmony_ci	int rid = rdev_get_id(rdev);
29662306a36Sopenharmony_ci	int ctr_bit, reg;
29762306a36Sopenharmony_ci	unsigned int val;
29862306a36Sopenharmony_ci	int err;
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_ci	reg = RK806_POWER_FPWM_EN0 + rid / 8;
30162306a36Sopenharmony_ci	ctr_bit = rid % 8;
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_ci	err = regmap_read(rdev->regmap, reg, &val);
30462306a36Sopenharmony_ci	if (err)
30562306a36Sopenharmony_ci		return err;
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci	if ((val >> ctr_bit) & FPWM_MODE)
30862306a36Sopenharmony_ci		return REGULATOR_MODE_FAST;
30962306a36Sopenharmony_ci	else
31062306a36Sopenharmony_ci		return REGULATOR_MODE_NORMAL;
31162306a36Sopenharmony_ci}
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_cistatic const struct rk8xx_register_bit rk806_dcdc_rate2[] = {
31462306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 0),
31562306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 1),
31662306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 2),
31762306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 3),
31862306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 4),
31962306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 5),
32062306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 6),
32162306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEB, 7),
32262306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEA, 0),
32362306a36Sopenharmony_ci	RK8XX_REG_BIT(0xEA, 1),
32462306a36Sopenharmony_ci};
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_cistatic const unsigned int rk806_ramp_delay_table_dcdc[] = {
32762306a36Sopenharmony_ci	50000, 25000, 12500, 6250, 3125, 1560, 961, 390
32862306a36Sopenharmony_ci};
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_cistatic int rk806_set_ramp_delay_dcdc(struct regulator_dev *rdev, int ramp_delay)
33162306a36Sopenharmony_ci{
33262306a36Sopenharmony_ci	int rid = rdev_get_id(rdev);
33362306a36Sopenharmony_ci	int regval, ramp_value, ret;
33462306a36Sopenharmony_ci
33562306a36Sopenharmony_ci	ret = regulator_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table,
33662306a36Sopenharmony_ci					    rdev->desc->n_ramp_values, &ramp_value);
33762306a36Sopenharmony_ci	if (ret) {
33862306a36Sopenharmony_ci		dev_warn(rdev_get_dev(rdev),
33962306a36Sopenharmony_ci			 "Can't set ramp-delay %u, setting %u\n", ramp_delay,
34062306a36Sopenharmony_ci			 rdev->desc->ramp_delay_table[ramp_value]);
34162306a36Sopenharmony_ci	}
34262306a36Sopenharmony_ci
34362306a36Sopenharmony_ci	regval = ramp_value << (ffs(rdev->desc->ramp_mask) - 1);
34462306a36Sopenharmony_ci
34562306a36Sopenharmony_ci	ret = regmap_update_bits(rdev->regmap, rdev->desc->ramp_reg,
34662306a36Sopenharmony_ci				 rdev->desc->ramp_mask, regval);
34762306a36Sopenharmony_ci	if (ret)
34862306a36Sopenharmony_ci		return ret;
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci	/*
35162306a36Sopenharmony_ci	 * The above is effectively a copy of regulator_set_ramp_delay_regmap(),
35262306a36Sopenharmony_ci	 * but that only stores the lower 2 bits for rk806 DCDC ramp. The MSB must
35362306a36Sopenharmony_ci	 * be stored in a separate register, so this open codes the implementation
35462306a36Sopenharmony_ci	 * to have access to the ramp_value.
35562306a36Sopenharmony_ci	 */
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci	regval = (ramp_value >> 2) & 0x1 ? rk806_dcdc_rate2[rid].bit : 0;
35862306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, rk806_dcdc_rate2[rid].reg,
35962306a36Sopenharmony_ci				  rk806_dcdc_rate2[rid].bit,
36062306a36Sopenharmony_ci				  regval);
36162306a36Sopenharmony_ci}
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_cistatic const unsigned int rk806_ramp_delay_table_ldo[] = {
36462306a36Sopenharmony_ci	100000, 50000, 25000, 12500, 6280, 3120, 1900, 780
36562306a36Sopenharmony_ci};
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_cistatic int rk806_set_suspend_voltage_range(struct regulator_dev *rdev, int reg_offset, int uv)
36862306a36Sopenharmony_ci{
36962306a36Sopenharmony_ci	int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
37062306a36Sopenharmony_ci	unsigned int reg;
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci	if (sel < 0)
37362306a36Sopenharmony_ci		return -EINVAL;
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci	reg = rdev->desc->vsel_reg + reg_offset;
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg, rdev->desc->vsel_mask, sel);
37862306a36Sopenharmony_ci}
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_cistatic int rk806_set_suspend_voltage_range_dcdc(struct regulator_dev *rdev, int uv)
38162306a36Sopenharmony_ci{
38262306a36Sopenharmony_ci	return rk806_set_suspend_voltage_range(rdev, RK806_DCDC_SLP_REG_OFFSET, uv);
38362306a36Sopenharmony_ci}
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_cistatic int rk806_set_suspend_voltage_range_nldo(struct regulator_dev *rdev, int uv)
38662306a36Sopenharmony_ci{
38762306a36Sopenharmony_ci	return rk806_set_suspend_voltage_range(rdev, RK806_NLDO_SLP_REG_OFFSET, uv);
38862306a36Sopenharmony_ci}
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_cistatic int rk806_set_suspend_voltage_range_pldo(struct regulator_dev *rdev, int uv)
39162306a36Sopenharmony_ci{
39262306a36Sopenharmony_ci	return rk806_set_suspend_voltage_range(rdev, RK806_PLDO_SLP_REG_OFFSET, uv);
39362306a36Sopenharmony_ci}
39462306a36Sopenharmony_ci
39562306a36Sopenharmony_cistatic int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev)
39662306a36Sopenharmony_ci{
39762306a36Sopenharmony_ci	struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
39862306a36Sopenharmony_ci	int id = rdev_get_id(rdev);
39962306a36Sopenharmony_ci	struct gpio_desc *gpio = pdata->dvs_gpio[id];
40062306a36Sopenharmony_ci	unsigned int val;
40162306a36Sopenharmony_ci	int ret;
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci	if (!gpio || gpiod_get_value(gpio) == 0)
40462306a36Sopenharmony_ci		return regulator_get_voltage_sel_regmap(rdev);
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci	ret = regmap_read(rdev->regmap,
40762306a36Sopenharmony_ci			  rdev->desc->vsel_reg + RK808_DVS_REG_OFFSET,
40862306a36Sopenharmony_ci			  &val);
40962306a36Sopenharmony_ci	if (ret != 0)
41062306a36Sopenharmony_ci		return ret;
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_ci	val &= rdev->desc->vsel_mask;
41362306a36Sopenharmony_ci	val >>= ffs(rdev->desc->vsel_mask) - 1;
41462306a36Sopenharmony_ci
41562306a36Sopenharmony_ci	return val;
41662306a36Sopenharmony_ci}
41762306a36Sopenharmony_ci
41862306a36Sopenharmony_cistatic int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev *rdev,
41962306a36Sopenharmony_ci					     unsigned sel)
42062306a36Sopenharmony_ci{
42162306a36Sopenharmony_ci	int ret, delta_sel;
42262306a36Sopenharmony_ci	unsigned int old_sel, tmp, val, mask = rdev->desc->vsel_mask;
42362306a36Sopenharmony_ci
42462306a36Sopenharmony_ci	ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
42562306a36Sopenharmony_ci	if (ret != 0)
42662306a36Sopenharmony_ci		return ret;
42762306a36Sopenharmony_ci
42862306a36Sopenharmony_ci	tmp = val & ~mask;
42962306a36Sopenharmony_ci	old_sel = val & mask;
43062306a36Sopenharmony_ci	old_sel >>= ffs(mask) - 1;
43162306a36Sopenharmony_ci	delta_sel = sel - old_sel;
43262306a36Sopenharmony_ci
43362306a36Sopenharmony_ci	/*
43462306a36Sopenharmony_ci	 * If directly modify the register to change the voltage, we will face
43562306a36Sopenharmony_ci	 * the risk of overshoot. Put it into a multi-step, can effectively
43662306a36Sopenharmony_ci	 * avoid this problem, a step is 100mv here.
43762306a36Sopenharmony_ci	 */
43862306a36Sopenharmony_ci	while (delta_sel > MAX_STEPS_ONE_TIME) {
43962306a36Sopenharmony_ci		old_sel += MAX_STEPS_ONE_TIME;
44062306a36Sopenharmony_ci		val = old_sel << (ffs(mask) - 1);
44162306a36Sopenharmony_ci		val |= tmp;
44262306a36Sopenharmony_ci
44362306a36Sopenharmony_ci		/*
44462306a36Sopenharmony_ci		 * i2c is 400kHz (2.5us per bit) and we must transmit _at least_
44562306a36Sopenharmony_ci		 * 3 bytes (24 bits) plus start and stop so 26 bits.  So we've
44662306a36Sopenharmony_ci		 * got more than 65 us between each voltage change and thus
44762306a36Sopenharmony_ci		 * won't ramp faster than ~1500 uV / us.
44862306a36Sopenharmony_ci		 */
44962306a36Sopenharmony_ci		ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
45062306a36Sopenharmony_ci		delta_sel = sel - old_sel;
45162306a36Sopenharmony_ci	}
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci	sel <<= ffs(mask) - 1;
45462306a36Sopenharmony_ci	val = tmp | sel;
45562306a36Sopenharmony_ci	ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val);
45662306a36Sopenharmony_ci
45762306a36Sopenharmony_ci	/*
45862306a36Sopenharmony_ci	 * When we change the voltage register directly, the ramp rate is about
45962306a36Sopenharmony_ci	 * 100000uv/us, wait 1us to make sure the target voltage to be stable,
46062306a36Sopenharmony_ci	 * so we needn't wait extra time after that.
46162306a36Sopenharmony_ci	 */
46262306a36Sopenharmony_ci	udelay(1);
46362306a36Sopenharmony_ci
46462306a36Sopenharmony_ci	return ret;
46562306a36Sopenharmony_ci}
46662306a36Sopenharmony_ci
46762306a36Sopenharmony_cistatic int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev,
46862306a36Sopenharmony_ci					 unsigned sel)
46962306a36Sopenharmony_ci{
47062306a36Sopenharmony_ci	struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
47162306a36Sopenharmony_ci	int id = rdev_get_id(rdev);
47262306a36Sopenharmony_ci	struct gpio_desc *gpio = pdata->dvs_gpio[id];
47362306a36Sopenharmony_ci	unsigned int reg = rdev->desc->vsel_reg;
47462306a36Sopenharmony_ci	unsigned old_sel;
47562306a36Sopenharmony_ci	int ret, gpio_level;
47662306a36Sopenharmony_ci
47762306a36Sopenharmony_ci	if (!gpio)
47862306a36Sopenharmony_ci		return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel);
47962306a36Sopenharmony_ci
48062306a36Sopenharmony_ci	gpio_level = gpiod_get_value(gpio);
48162306a36Sopenharmony_ci	if (gpio_level == 0) {
48262306a36Sopenharmony_ci		reg += RK808_DVS_REG_OFFSET;
48362306a36Sopenharmony_ci		ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &old_sel);
48462306a36Sopenharmony_ci	} else {
48562306a36Sopenharmony_ci		ret = regmap_read(rdev->regmap,
48662306a36Sopenharmony_ci				  reg + RK808_DVS_REG_OFFSET,
48762306a36Sopenharmony_ci				  &old_sel);
48862306a36Sopenharmony_ci	}
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_ci	if (ret != 0)
49162306a36Sopenharmony_ci		return ret;
49262306a36Sopenharmony_ci
49362306a36Sopenharmony_ci	sel <<= ffs(rdev->desc->vsel_mask) - 1;
49462306a36Sopenharmony_ci	sel |= old_sel & ~rdev->desc->vsel_mask;
49562306a36Sopenharmony_ci
49662306a36Sopenharmony_ci	ret = regmap_write(rdev->regmap, reg, sel);
49762306a36Sopenharmony_ci	if (ret)
49862306a36Sopenharmony_ci		return ret;
49962306a36Sopenharmony_ci
50062306a36Sopenharmony_ci	gpiod_set_value(gpio, !gpio_level);
50162306a36Sopenharmony_ci
50262306a36Sopenharmony_ci	return ret;
50362306a36Sopenharmony_ci}
50462306a36Sopenharmony_ci
50562306a36Sopenharmony_cistatic int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev,
50662306a36Sopenharmony_ci				       unsigned int old_selector,
50762306a36Sopenharmony_ci				       unsigned int new_selector)
50862306a36Sopenharmony_ci{
50962306a36Sopenharmony_ci	struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev);
51062306a36Sopenharmony_ci	int id = rdev_get_id(rdev);
51162306a36Sopenharmony_ci	struct gpio_desc *gpio = pdata->dvs_gpio[id];
51262306a36Sopenharmony_ci
51362306a36Sopenharmony_ci	/* if there is no dvs1/2 pin, we don't need wait extra time here. */
51462306a36Sopenharmony_ci	if (!gpio)
51562306a36Sopenharmony_ci		return 0;
51662306a36Sopenharmony_ci
51762306a36Sopenharmony_ci	return regulator_set_voltage_time_sel(rdev, old_selector, new_selector);
51862306a36Sopenharmony_ci}
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_cistatic int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv)
52162306a36Sopenharmony_ci{
52262306a36Sopenharmony_ci	unsigned int reg;
52362306a36Sopenharmony_ci	int sel = regulator_map_voltage_linear(rdev, uv, uv);
52462306a36Sopenharmony_ci
52562306a36Sopenharmony_ci	if (sel < 0)
52662306a36Sopenharmony_ci		return -EINVAL;
52762306a36Sopenharmony_ci
52862306a36Sopenharmony_ci	reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
52962306a36Sopenharmony_ci
53062306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg,
53162306a36Sopenharmony_ci				  rdev->desc->vsel_mask,
53262306a36Sopenharmony_ci				  sel);
53362306a36Sopenharmony_ci}
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_cistatic int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv)
53662306a36Sopenharmony_ci{
53762306a36Sopenharmony_ci	unsigned int reg;
53862306a36Sopenharmony_ci	int sel = regulator_map_voltage_linear_range(rdev, uv, uv);
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_ci	if (sel < 0)
54162306a36Sopenharmony_ci		return -EINVAL;
54262306a36Sopenharmony_ci
54362306a36Sopenharmony_ci	reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
54462306a36Sopenharmony_ci
54562306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg,
54662306a36Sopenharmony_ci				  rdev->desc->vsel_mask,
54762306a36Sopenharmony_ci				  sel);
54862306a36Sopenharmony_ci}
54962306a36Sopenharmony_ci
55062306a36Sopenharmony_cistatic int rk805_set_suspend_enable(struct regulator_dev *rdev)
55162306a36Sopenharmony_ci{
55262306a36Sopenharmony_ci	unsigned int reg;
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_ci	reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
55562306a36Sopenharmony_ci
55662306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg,
55762306a36Sopenharmony_ci				  rdev->desc->enable_mask,
55862306a36Sopenharmony_ci				  rdev->desc->enable_mask);
55962306a36Sopenharmony_ci}
56062306a36Sopenharmony_ci
56162306a36Sopenharmony_cistatic int rk805_set_suspend_disable(struct regulator_dev *rdev)
56262306a36Sopenharmony_ci{
56362306a36Sopenharmony_ci	unsigned int reg;
56462306a36Sopenharmony_ci
56562306a36Sopenharmony_ci	reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
56662306a36Sopenharmony_ci
56762306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg,
56862306a36Sopenharmony_ci				  rdev->desc->enable_mask,
56962306a36Sopenharmony_ci				  0);
57062306a36Sopenharmony_ci}
57162306a36Sopenharmony_ci
57262306a36Sopenharmony_cistatic const struct rk8xx_register_bit rk806_suspend_bits[] = {
57362306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 0),
57462306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 1),
57562306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 2),
57662306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 3),
57762306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 4),
57862306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 5),
57962306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 6),
58062306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 7),
58162306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 6),
58262306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 7),
58362306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 0),
58462306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 1),
58562306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 2),
58662306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 3),
58762306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 4),
58862306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 1),
58962306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 2),
59062306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 3),
59162306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 4),
59262306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 5),
59362306a36Sopenharmony_ci	RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 0),
59462306a36Sopenharmony_ci};
59562306a36Sopenharmony_ci
59662306a36Sopenharmony_cistatic int rk806_set_suspend_enable(struct regulator_dev *rdev)
59762306a36Sopenharmony_ci{
59862306a36Sopenharmony_ci	int rid = rdev_get_id(rdev);
59962306a36Sopenharmony_ci
60062306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg,
60162306a36Sopenharmony_ci				  rk806_suspend_bits[rid].bit,
60262306a36Sopenharmony_ci				  rk806_suspend_bits[rid].bit);
60362306a36Sopenharmony_ci}
60462306a36Sopenharmony_ci
60562306a36Sopenharmony_cistatic int rk806_set_suspend_disable(struct regulator_dev *rdev)
60662306a36Sopenharmony_ci{
60762306a36Sopenharmony_ci	int rid = rdev_get_id(rdev);
60862306a36Sopenharmony_ci
60962306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg,
61062306a36Sopenharmony_ci				  rk806_suspend_bits[rid].bit, 0);
61162306a36Sopenharmony_ci}
61262306a36Sopenharmony_ci
61362306a36Sopenharmony_cistatic int rk808_set_suspend_enable(struct regulator_dev *rdev)
61462306a36Sopenharmony_ci{
61562306a36Sopenharmony_ci	unsigned int reg;
61662306a36Sopenharmony_ci
61762306a36Sopenharmony_ci	reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
61862306a36Sopenharmony_ci
61962306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg,
62062306a36Sopenharmony_ci				  rdev->desc->enable_mask,
62162306a36Sopenharmony_ci				  0);
62262306a36Sopenharmony_ci}
62362306a36Sopenharmony_ci
62462306a36Sopenharmony_cistatic int rk808_set_suspend_disable(struct regulator_dev *rdev)
62562306a36Sopenharmony_ci{
62662306a36Sopenharmony_ci	unsigned int reg;
62762306a36Sopenharmony_ci
62862306a36Sopenharmony_ci	reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET;
62962306a36Sopenharmony_ci
63062306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg,
63162306a36Sopenharmony_ci				  rdev->desc->enable_mask,
63262306a36Sopenharmony_ci				  rdev->desc->enable_mask);
63362306a36Sopenharmony_ci}
63462306a36Sopenharmony_ci
63562306a36Sopenharmony_cistatic int rk817_set_suspend_enable_ctrl(struct regulator_dev *rdev,
63662306a36Sopenharmony_ci					 unsigned int en)
63762306a36Sopenharmony_ci{
63862306a36Sopenharmony_ci	unsigned int reg;
63962306a36Sopenharmony_ci	int id = rdev_get_id(rdev);
64062306a36Sopenharmony_ci	unsigned int id_slp, msk, val;
64162306a36Sopenharmony_ci
64262306a36Sopenharmony_ci	if (id >= RK817_ID_DCDC1 && id <= RK817_ID_DCDC4)
64362306a36Sopenharmony_ci		id_slp = id;
64462306a36Sopenharmony_ci	else if (id >= RK817_ID_LDO1 && id <= RK817_ID_LDO8)
64562306a36Sopenharmony_ci		id_slp = 8 + (id - RK817_ID_LDO1);
64662306a36Sopenharmony_ci	else if (id >= RK817_ID_LDO9 && id <= RK809_ID_SW2)
64762306a36Sopenharmony_ci		id_slp = 4 + (id - RK817_ID_LDO9);
64862306a36Sopenharmony_ci	else
64962306a36Sopenharmony_ci		return -EINVAL;
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_ci	reg = RK817_POWER_SLP_EN_REG(id_slp / 8);
65262306a36Sopenharmony_ci
65362306a36Sopenharmony_ci	msk = BIT(id_slp % 8);
65462306a36Sopenharmony_ci	if (en)
65562306a36Sopenharmony_ci		val = msk;
65662306a36Sopenharmony_ci	else
65762306a36Sopenharmony_ci		val = 0;
65862306a36Sopenharmony_ci
65962306a36Sopenharmony_ci	return regmap_update_bits(rdev->regmap, reg, msk, val);
66062306a36Sopenharmony_ci}
66162306a36Sopenharmony_ci
66262306a36Sopenharmony_cistatic int rk817_set_suspend_enable(struct regulator_dev *rdev)
66362306a36Sopenharmony_ci{
66462306a36Sopenharmony_ci	return rk817_set_suspend_enable_ctrl(rdev, 1);
66562306a36Sopenharmony_ci}
66662306a36Sopenharmony_ci
66762306a36Sopenharmony_cistatic int rk817_set_suspend_disable(struct regulator_dev *rdev)
66862306a36Sopenharmony_ci{
66962306a36Sopenharmony_ci	return rk817_set_suspend_enable_ctrl(rdev, 0);
67062306a36Sopenharmony_ci}
67162306a36Sopenharmony_ci
67262306a36Sopenharmony_cistatic int rk8xx_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode)
67362306a36Sopenharmony_ci{
67462306a36Sopenharmony_ci	unsigned int reg;
67562306a36Sopenharmony_ci
67662306a36Sopenharmony_ci	reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET;
67762306a36Sopenharmony_ci
67862306a36Sopenharmony_ci	switch (mode) {
67962306a36Sopenharmony_ci	case REGULATOR_MODE_FAST:
68062306a36Sopenharmony_ci		return regmap_update_bits(rdev->regmap, reg,
68162306a36Sopenharmony_ci					  PWM_MODE_MSK, FPWM_MODE);
68262306a36Sopenharmony_ci	case REGULATOR_MODE_NORMAL:
68362306a36Sopenharmony_ci		return regmap_update_bits(rdev->regmap, reg,
68462306a36Sopenharmony_ci					  PWM_MODE_MSK, AUTO_PWM_MODE);
68562306a36Sopenharmony_ci	default:
68662306a36Sopenharmony_ci		dev_err(&rdev->dev, "do not support this mode\n");
68762306a36Sopenharmony_ci		return -EINVAL;
68862306a36Sopenharmony_ci	}
68962306a36Sopenharmony_ci
69062306a36Sopenharmony_ci	return 0;
69162306a36Sopenharmony_ci}
69262306a36Sopenharmony_ci
69362306a36Sopenharmony_cistatic int rk8xx_set_mode(struct regulator_dev *rdev, unsigned int mode)
69462306a36Sopenharmony_ci{
69562306a36Sopenharmony_ci	switch (mode) {
69662306a36Sopenharmony_ci	case REGULATOR_MODE_FAST:
69762306a36Sopenharmony_ci		return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
69862306a36Sopenharmony_ci					  PWM_MODE_MSK, FPWM_MODE);
69962306a36Sopenharmony_ci	case REGULATOR_MODE_NORMAL:
70062306a36Sopenharmony_ci		return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg,
70162306a36Sopenharmony_ci					  PWM_MODE_MSK, AUTO_PWM_MODE);
70262306a36Sopenharmony_ci	default:
70362306a36Sopenharmony_ci		dev_err(&rdev->dev, "do not support this mode\n");
70462306a36Sopenharmony_ci		return -EINVAL;
70562306a36Sopenharmony_ci	}
70662306a36Sopenharmony_ci
70762306a36Sopenharmony_ci	return 0;
70862306a36Sopenharmony_ci}
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_cistatic unsigned int rk8xx_get_mode(struct regulator_dev *rdev)
71162306a36Sopenharmony_ci{
71262306a36Sopenharmony_ci	unsigned int val;
71362306a36Sopenharmony_ci	int err;
71462306a36Sopenharmony_ci
71562306a36Sopenharmony_ci	err = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
71662306a36Sopenharmony_ci	if (err)
71762306a36Sopenharmony_ci		return err;
71862306a36Sopenharmony_ci
71962306a36Sopenharmony_ci	if (val & FPWM_MODE)
72062306a36Sopenharmony_ci		return REGULATOR_MODE_FAST;
72162306a36Sopenharmony_ci	else
72262306a36Sopenharmony_ci		return REGULATOR_MODE_NORMAL;
72362306a36Sopenharmony_ci}
72462306a36Sopenharmony_ci
72562306a36Sopenharmony_cistatic int rk8xx_is_enabled_wmsk_regmap(struct regulator_dev *rdev)
72662306a36Sopenharmony_ci{
72762306a36Sopenharmony_ci	unsigned int val;
72862306a36Sopenharmony_ci	int ret;
72962306a36Sopenharmony_ci
73062306a36Sopenharmony_ci	ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val);
73162306a36Sopenharmony_ci	if (ret != 0)
73262306a36Sopenharmony_ci		return ret;
73362306a36Sopenharmony_ci
73462306a36Sopenharmony_ci	/* add write mask bit */
73562306a36Sopenharmony_ci	val |= (rdev->desc->enable_mask & 0xf0);
73662306a36Sopenharmony_ci	val &= rdev->desc->enable_mask;
73762306a36Sopenharmony_ci
73862306a36Sopenharmony_ci	if (rdev->desc->enable_is_inverted) {
73962306a36Sopenharmony_ci		if (rdev->desc->enable_val)
74062306a36Sopenharmony_ci			return val != rdev->desc->enable_val;
74162306a36Sopenharmony_ci		return (val == 0);
74262306a36Sopenharmony_ci	}
74362306a36Sopenharmony_ci	if (rdev->desc->enable_val)
74462306a36Sopenharmony_ci		return val == rdev->desc->enable_val;
74562306a36Sopenharmony_ci	return val != 0;
74662306a36Sopenharmony_ci}
74762306a36Sopenharmony_ci
74862306a36Sopenharmony_cistatic unsigned int rk8xx_regulator_of_map_mode(unsigned int mode)
74962306a36Sopenharmony_ci{
75062306a36Sopenharmony_ci	switch (mode) {
75162306a36Sopenharmony_ci	case 1:
75262306a36Sopenharmony_ci		return REGULATOR_MODE_FAST;
75362306a36Sopenharmony_ci	case 2:
75462306a36Sopenharmony_ci		return REGULATOR_MODE_NORMAL;
75562306a36Sopenharmony_ci	default:
75662306a36Sopenharmony_ci		return REGULATOR_MODE_INVALID;
75762306a36Sopenharmony_ci	}
75862306a36Sopenharmony_ci}
75962306a36Sopenharmony_ci
76062306a36Sopenharmony_cistatic const struct regulator_ops rk805_reg_ops = {
76162306a36Sopenharmony_ci	.list_voltage           = regulator_list_voltage_linear,
76262306a36Sopenharmony_ci	.map_voltage            = regulator_map_voltage_linear,
76362306a36Sopenharmony_ci	.get_voltage_sel        = regulator_get_voltage_sel_regmap,
76462306a36Sopenharmony_ci	.set_voltage_sel        = regulator_set_voltage_sel_regmap,
76562306a36Sopenharmony_ci	.enable                 = regulator_enable_regmap,
76662306a36Sopenharmony_ci	.disable                = regulator_disable_regmap,
76762306a36Sopenharmony_ci	.is_enabled             = regulator_is_enabled_regmap,
76862306a36Sopenharmony_ci	.set_suspend_voltage    = rk808_set_suspend_voltage,
76962306a36Sopenharmony_ci	.set_suspend_enable     = rk805_set_suspend_enable,
77062306a36Sopenharmony_ci	.set_suspend_disable    = rk805_set_suspend_disable,
77162306a36Sopenharmony_ci};
77262306a36Sopenharmony_ci
77362306a36Sopenharmony_cistatic const struct regulator_ops rk805_switch_ops = {
77462306a36Sopenharmony_ci	.enable                 = regulator_enable_regmap,
77562306a36Sopenharmony_ci	.disable                = regulator_disable_regmap,
77662306a36Sopenharmony_ci	.is_enabled             = regulator_is_enabled_regmap,
77762306a36Sopenharmony_ci	.set_suspend_enable     = rk805_set_suspend_enable,
77862306a36Sopenharmony_ci	.set_suspend_disable    = rk805_set_suspend_disable,
77962306a36Sopenharmony_ci};
78062306a36Sopenharmony_ci
78162306a36Sopenharmony_cistatic const struct regulator_ops rk806_ops_dcdc = {
78262306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
78362306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
78462306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
78562306a36Sopenharmony_ci	.set_voltage_sel        = regulator_set_voltage_sel_regmap,
78662306a36Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
78762306a36Sopenharmony_ci	.set_mode		= rk806_set_mode_dcdc,
78862306a36Sopenharmony_ci	.get_mode		= rk806_get_mode_dcdc,
78962306a36Sopenharmony_ci
79062306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
79162306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
79262306a36Sopenharmony_ci	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
79362306a36Sopenharmony_ci
79462306a36Sopenharmony_ci	.set_suspend_mode	= rk806_set_mode_dcdc,
79562306a36Sopenharmony_ci	.set_ramp_delay		= rk806_set_ramp_delay_dcdc,
79662306a36Sopenharmony_ci
79762306a36Sopenharmony_ci	.set_suspend_voltage	= rk806_set_suspend_voltage_range_dcdc,
79862306a36Sopenharmony_ci	.set_suspend_enable	= rk806_set_suspend_enable,
79962306a36Sopenharmony_ci	.set_suspend_disable	= rk806_set_suspend_disable,
80062306a36Sopenharmony_ci};
80162306a36Sopenharmony_ci
80262306a36Sopenharmony_cistatic const struct regulator_ops rk806_ops_nldo = {
80362306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
80462306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
80562306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
80662306a36Sopenharmony_ci	.set_voltage_sel        = regulator_set_voltage_sel_regmap,
80762306a36Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
80862306a36Sopenharmony_ci
80962306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
81062306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
81162306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
81262306a36Sopenharmony_ci
81362306a36Sopenharmony_ci	.set_ramp_delay		= regulator_set_ramp_delay_regmap,
81462306a36Sopenharmony_ci
81562306a36Sopenharmony_ci	.set_suspend_voltage	= rk806_set_suspend_voltage_range_nldo,
81662306a36Sopenharmony_ci	.set_suspend_enable	= rk806_set_suspend_enable,
81762306a36Sopenharmony_ci	.set_suspend_disable	= rk806_set_suspend_disable,
81862306a36Sopenharmony_ci};
81962306a36Sopenharmony_ci
82062306a36Sopenharmony_cistatic const struct regulator_ops rk806_ops_pldo = {
82162306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
82262306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
82362306a36Sopenharmony_ci
82462306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
82562306a36Sopenharmony_ci	.set_voltage_sel        = regulator_set_voltage_sel_regmap,
82662306a36Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
82762306a36Sopenharmony_ci
82862306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
82962306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
83062306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
83162306a36Sopenharmony_ci
83262306a36Sopenharmony_ci	.set_ramp_delay		= regulator_set_ramp_delay_regmap,
83362306a36Sopenharmony_ci
83462306a36Sopenharmony_ci	.set_suspend_voltage	= rk806_set_suspend_voltage_range_pldo,
83562306a36Sopenharmony_ci	.set_suspend_enable	= rk806_set_suspend_enable,
83662306a36Sopenharmony_ci	.set_suspend_disable	= rk806_set_suspend_disable,
83762306a36Sopenharmony_ci};
83862306a36Sopenharmony_ci
83962306a36Sopenharmony_cistatic const struct regulator_ops rk808_buck1_2_ops = {
84062306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
84162306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
84262306a36Sopenharmony_ci	.get_voltage_sel	= rk808_buck1_2_get_voltage_sel_regmap,
84362306a36Sopenharmony_ci	.set_voltage_sel	= rk808_buck1_2_set_voltage_sel,
84462306a36Sopenharmony_ci	.set_voltage_time_sel	= rk808_buck1_2_set_voltage_time_sel,
84562306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
84662306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
84762306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
84862306a36Sopenharmony_ci	.set_ramp_delay		= regulator_set_ramp_delay_regmap,
84962306a36Sopenharmony_ci	.set_suspend_voltage	= rk808_set_suspend_voltage,
85062306a36Sopenharmony_ci	.set_suspend_enable	= rk808_set_suspend_enable,
85162306a36Sopenharmony_ci	.set_suspend_disable	= rk808_set_suspend_disable,
85262306a36Sopenharmony_ci};
85362306a36Sopenharmony_ci
85462306a36Sopenharmony_cistatic const struct regulator_ops rk808_reg_ops = {
85562306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
85662306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
85762306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
85862306a36Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
85962306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
86062306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
86162306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
86262306a36Sopenharmony_ci	.set_suspend_voltage	= rk808_set_suspend_voltage,
86362306a36Sopenharmony_ci	.set_suspend_enable	= rk808_set_suspend_enable,
86462306a36Sopenharmony_ci	.set_suspend_disable	= rk808_set_suspend_disable,
86562306a36Sopenharmony_ci};
86662306a36Sopenharmony_ci
86762306a36Sopenharmony_cistatic const struct regulator_ops rk808_reg_ops_ranges = {
86862306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
86962306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
87062306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
87162306a36Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
87262306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
87362306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
87462306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
87562306a36Sopenharmony_ci	.set_suspend_voltage	= rk808_set_suspend_voltage_range,
87662306a36Sopenharmony_ci	.set_suspend_enable	= rk808_set_suspend_enable,
87762306a36Sopenharmony_ci	.set_suspend_disable	= rk808_set_suspend_disable,
87862306a36Sopenharmony_ci};
87962306a36Sopenharmony_ci
88062306a36Sopenharmony_cistatic const struct regulator_ops rk808_switch_ops = {
88162306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
88262306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
88362306a36Sopenharmony_ci	.is_enabled		= regulator_is_enabled_regmap,
88462306a36Sopenharmony_ci	.set_suspend_enable	= rk808_set_suspend_enable,
88562306a36Sopenharmony_ci	.set_suspend_disable	= rk808_set_suspend_disable,
88662306a36Sopenharmony_ci};
88762306a36Sopenharmony_ci
88862306a36Sopenharmony_cistatic const struct linear_range rk805_buck_1_2_voltage_ranges[] = {
88962306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(712500, 0, 59, 12500),
89062306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1800000, 60, 62, 200000),
89162306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(2300000, 63, 63, 0),
89262306a36Sopenharmony_ci};
89362306a36Sopenharmony_ci
89462306a36Sopenharmony_cistatic const struct regulator_ops rk809_buck5_ops_range = {
89562306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
89662306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
89762306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
89862306a36Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
89962306a36Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
90062306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
90162306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
90262306a36Sopenharmony_ci	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
90362306a36Sopenharmony_ci	.set_suspend_voltage	= rk808_set_suspend_voltage_range,
90462306a36Sopenharmony_ci	.set_suspend_enable	= rk817_set_suspend_enable,
90562306a36Sopenharmony_ci	.set_suspend_disable	= rk817_set_suspend_disable,
90662306a36Sopenharmony_ci};
90762306a36Sopenharmony_ci
90862306a36Sopenharmony_cistatic const struct regulator_ops rk817_reg_ops = {
90962306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
91062306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
91162306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
91262306a36Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
91362306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
91462306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
91562306a36Sopenharmony_ci	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
91662306a36Sopenharmony_ci	.set_suspend_voltage	= rk808_set_suspend_voltage,
91762306a36Sopenharmony_ci	.set_suspend_enable	= rk817_set_suspend_enable,
91862306a36Sopenharmony_ci	.set_suspend_disable	= rk817_set_suspend_disable,
91962306a36Sopenharmony_ci};
92062306a36Sopenharmony_ci
92162306a36Sopenharmony_cistatic const struct regulator_ops rk817_boost_ops = {
92262306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear,
92362306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear,
92462306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
92562306a36Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
92662306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
92762306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
92862306a36Sopenharmony_ci	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
92962306a36Sopenharmony_ci	.set_suspend_enable	= rk817_set_suspend_enable,
93062306a36Sopenharmony_ci	.set_suspend_disable	= rk817_set_suspend_disable,
93162306a36Sopenharmony_ci};
93262306a36Sopenharmony_ci
93362306a36Sopenharmony_cistatic const struct regulator_ops rk817_buck_ops_range = {
93462306a36Sopenharmony_ci	.list_voltage		= regulator_list_voltage_linear_range,
93562306a36Sopenharmony_ci	.map_voltage		= regulator_map_voltage_linear_range,
93662306a36Sopenharmony_ci	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
93762306a36Sopenharmony_ci	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
93862306a36Sopenharmony_ci	.set_voltage_time_sel	= regulator_set_voltage_time_sel,
93962306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
94062306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
94162306a36Sopenharmony_ci	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
94262306a36Sopenharmony_ci	.set_mode		= rk8xx_set_mode,
94362306a36Sopenharmony_ci	.get_mode		= rk8xx_get_mode,
94462306a36Sopenharmony_ci	.set_suspend_mode	= rk8xx_set_suspend_mode,
94562306a36Sopenharmony_ci	.set_ramp_delay		= regulator_set_ramp_delay_regmap,
94662306a36Sopenharmony_ci	.set_suspend_voltage	= rk808_set_suspend_voltage_range,
94762306a36Sopenharmony_ci	.set_suspend_enable	= rk817_set_suspend_enable,
94862306a36Sopenharmony_ci	.set_suspend_disable	= rk817_set_suspend_disable,
94962306a36Sopenharmony_ci};
95062306a36Sopenharmony_ci
95162306a36Sopenharmony_cistatic const struct regulator_ops rk817_switch_ops = {
95262306a36Sopenharmony_ci	.enable			= regulator_enable_regmap,
95362306a36Sopenharmony_ci	.disable		= regulator_disable_regmap,
95462306a36Sopenharmony_ci	.is_enabled		= rk8xx_is_enabled_wmsk_regmap,
95562306a36Sopenharmony_ci	.set_suspend_enable	= rk817_set_suspend_enable,
95662306a36Sopenharmony_ci	.set_suspend_disable	= rk817_set_suspend_disable,
95762306a36Sopenharmony_ci};
95862306a36Sopenharmony_ci
95962306a36Sopenharmony_cistatic const struct regulator_desc rk805_reg[] = {
96062306a36Sopenharmony_ci	{
96162306a36Sopenharmony_ci		.name = "DCDC_REG1",
96262306a36Sopenharmony_ci		.supply_name = "vcc1",
96362306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG1"),
96462306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
96562306a36Sopenharmony_ci		.id = RK805_ID_DCDC1,
96662306a36Sopenharmony_ci		.ops = &rk808_reg_ops_ranges,
96762306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
96862306a36Sopenharmony_ci		.n_voltages = 64,
96962306a36Sopenharmony_ci		.linear_ranges = rk805_buck_1_2_voltage_ranges,
97062306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
97162306a36Sopenharmony_ci		.vsel_reg = RK805_BUCK1_ON_VSEL_REG,
97262306a36Sopenharmony_ci		.vsel_mask = RK818_BUCK_VSEL_MASK,
97362306a36Sopenharmony_ci		.enable_reg = RK805_DCDC_EN_REG,
97462306a36Sopenharmony_ci		.enable_mask = BIT(0),
97562306a36Sopenharmony_ci		.owner = THIS_MODULE,
97662306a36Sopenharmony_ci	}, {
97762306a36Sopenharmony_ci		.name = "DCDC_REG2",
97862306a36Sopenharmony_ci		.supply_name = "vcc2",
97962306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG2"),
98062306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
98162306a36Sopenharmony_ci		.id = RK805_ID_DCDC2,
98262306a36Sopenharmony_ci		.ops = &rk808_reg_ops_ranges,
98362306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
98462306a36Sopenharmony_ci		.n_voltages = 64,
98562306a36Sopenharmony_ci		.linear_ranges = rk805_buck_1_2_voltage_ranges,
98662306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges),
98762306a36Sopenharmony_ci		.vsel_reg = RK805_BUCK2_ON_VSEL_REG,
98862306a36Sopenharmony_ci		.vsel_mask = RK818_BUCK_VSEL_MASK,
98962306a36Sopenharmony_ci		.enable_reg = RK805_DCDC_EN_REG,
99062306a36Sopenharmony_ci		.enable_mask = BIT(1),
99162306a36Sopenharmony_ci		.owner = THIS_MODULE,
99262306a36Sopenharmony_ci	}, {
99362306a36Sopenharmony_ci		.name = "DCDC_REG3",
99462306a36Sopenharmony_ci		.supply_name = "vcc3",
99562306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG3"),
99662306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
99762306a36Sopenharmony_ci		.id = RK805_ID_DCDC3,
99862306a36Sopenharmony_ci		.ops = &rk805_switch_ops,
99962306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
100062306a36Sopenharmony_ci		.n_voltages = 1,
100162306a36Sopenharmony_ci		.enable_reg = RK805_DCDC_EN_REG,
100262306a36Sopenharmony_ci		.enable_mask = BIT(2),
100362306a36Sopenharmony_ci		.owner = THIS_MODULE,
100462306a36Sopenharmony_ci	},
100562306a36Sopenharmony_ci
100662306a36Sopenharmony_ci	RK805_DESC(RK805_ID_DCDC4, "DCDC_REG4", "vcc4", 800, 3400, 100,
100762306a36Sopenharmony_ci		RK805_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK,
100862306a36Sopenharmony_ci		RK805_DCDC_EN_REG, BIT(3), 0),
100962306a36Sopenharmony_ci
101062306a36Sopenharmony_ci	RK805_DESC(RK805_ID_LDO1, "LDO_REG1", "vcc5", 800, 3400, 100,
101162306a36Sopenharmony_ci		RK805_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG,
101262306a36Sopenharmony_ci		BIT(0), 400),
101362306a36Sopenharmony_ci	RK805_DESC(RK805_ID_LDO2, "LDO_REG2", "vcc5", 800, 3400, 100,
101462306a36Sopenharmony_ci		RK805_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG,
101562306a36Sopenharmony_ci		BIT(1), 400),
101662306a36Sopenharmony_ci	RK805_DESC(RK805_ID_LDO3, "LDO_REG3", "vcc6", 800, 3400, 100,
101762306a36Sopenharmony_ci		RK805_LDO3_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG,
101862306a36Sopenharmony_ci		BIT(2), 400),
101962306a36Sopenharmony_ci};
102062306a36Sopenharmony_ci
102162306a36Sopenharmony_cistatic const struct linear_range rk806_buck_voltage_ranges[] = {
102262306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(500000, 0, 160, 6250), /* 500mV ~ 1500mV */
102362306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(1500000, 161, 237, 25000), /* 1500mV ~ 3400mV */
102462306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(3400000, 238, 255, 0),
102562306a36Sopenharmony_ci};
102662306a36Sopenharmony_ci
102762306a36Sopenharmony_cistatic const struct linear_range rk806_ldo_voltage_ranges[] = {
102862306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(500000, 0, 232, 12500), /* 500mV ~ 3400mV */
102962306a36Sopenharmony_ci	REGULATOR_LINEAR_RANGE(3400000, 233, 255, 0), /* 500mV ~ 3400mV */
103062306a36Sopenharmony_ci};
103162306a36Sopenharmony_ci
103262306a36Sopenharmony_cistatic const struct regulator_desc rk806_reg[] = {
103362306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg1", "vcc1", RK806_ID_DCDC1, rk806_ops_dcdc,
103462306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK1_ON_VSEL,
103562306a36Sopenharmony_ci			RK806_POWER_EN0, rk806_buck_voltage_ranges, 0,
103662306a36Sopenharmony_ci			RK806_BUCK1_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
103762306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg2", "vcc2", RK806_ID_DCDC2, rk806_ops_dcdc,
103862306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK2_ON_VSEL,
103962306a36Sopenharmony_ci			RK806_POWER_EN0, rk806_buck_voltage_ranges, 1,
104062306a36Sopenharmony_ci			RK806_BUCK2_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
104162306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg3", "vcc3", RK806_ID_DCDC3, rk806_ops_dcdc,
104262306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK3_ON_VSEL,
104362306a36Sopenharmony_ci			RK806_POWER_EN0, rk806_buck_voltage_ranges, 2,
104462306a36Sopenharmony_ci			RK806_BUCK3_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
104562306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg4", "vcc4", RK806_ID_DCDC4, rk806_ops_dcdc,
104662306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK4_ON_VSEL,
104762306a36Sopenharmony_ci			RK806_POWER_EN0, rk806_buck_voltage_ranges, 3,
104862306a36Sopenharmony_ci			RK806_BUCK4_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
104962306a36Sopenharmony_ci
105062306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg5", "vcc5", RK806_ID_DCDC5, rk806_ops_dcdc,
105162306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK5_ON_VSEL,
105262306a36Sopenharmony_ci			RK806_POWER_EN1, rk806_buck_voltage_ranges, 0,
105362306a36Sopenharmony_ci			RK806_BUCK5_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
105462306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg6", "vcc6", RK806_ID_DCDC6, rk806_ops_dcdc,
105562306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK6_ON_VSEL,
105662306a36Sopenharmony_ci			RK806_POWER_EN1, rk806_buck_voltage_ranges, 1,
105762306a36Sopenharmony_ci			RK806_BUCK6_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
105862306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg7", "vcc7", RK806_ID_DCDC7, rk806_ops_dcdc,
105962306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK7_ON_VSEL,
106062306a36Sopenharmony_ci			RK806_POWER_EN1, rk806_buck_voltage_ranges, 2,
106162306a36Sopenharmony_ci			RK806_BUCK7_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
106262306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg8", "vcc8", RK806_ID_DCDC8, rk806_ops_dcdc,
106362306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK8_ON_VSEL,
106462306a36Sopenharmony_ci			RK806_POWER_EN1, rk806_buck_voltage_ranges, 3,
106562306a36Sopenharmony_ci			RK806_BUCK8_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
106662306a36Sopenharmony_ci
106762306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg9", "vcc9", RK806_ID_DCDC9, rk806_ops_dcdc,
106862306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK9_ON_VSEL,
106962306a36Sopenharmony_ci			RK806_POWER_EN2, rk806_buck_voltage_ranges, 0,
107062306a36Sopenharmony_ci			RK806_BUCK9_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
107162306a36Sopenharmony_ci	RK806_REGULATOR("dcdc-reg10", "vcc10", RK806_ID_DCDC10, rk806_ops_dcdc,
107262306a36Sopenharmony_ci			RK806_BUCK_SEL_CNT, RK806_BUCK10_ON_VSEL,
107362306a36Sopenharmony_ci			RK806_POWER_EN2, rk806_buck_voltage_ranges, 1,
107462306a36Sopenharmony_ci			RK806_BUCK10_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc),
107562306a36Sopenharmony_ci
107662306a36Sopenharmony_ci	RK806_REGULATOR("nldo-reg1", "vcc13", RK806_ID_NLDO1, rk806_ops_nldo,
107762306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_NLDO1_ON_VSEL,
107862306a36Sopenharmony_ci			RK806_POWER_EN3, rk806_ldo_voltage_ranges, 0,
107962306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
108062306a36Sopenharmony_ci	RK806_REGULATOR("nldo-reg2", "vcc13", RK806_ID_NLDO2, rk806_ops_nldo,
108162306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_NLDO2_ON_VSEL,
108262306a36Sopenharmony_ci			RK806_POWER_EN3, rk806_ldo_voltage_ranges, 1,
108362306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
108462306a36Sopenharmony_ci	RK806_REGULATOR("nldo-reg3", "vcc13", RK806_ID_NLDO3, rk806_ops_nldo,
108562306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_NLDO3_ON_VSEL,
108662306a36Sopenharmony_ci			RK806_POWER_EN3, rk806_ldo_voltage_ranges, 2,
108762306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
108862306a36Sopenharmony_ci	RK806_REGULATOR("nldo-reg4", "vcc14", RK806_ID_NLDO4, rk806_ops_nldo,
108962306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_NLDO4_ON_VSEL,
109062306a36Sopenharmony_ci			RK806_POWER_EN3, rk806_ldo_voltage_ranges, 3,
109162306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
109262306a36Sopenharmony_ci
109362306a36Sopenharmony_ci	RK806_REGULATOR("nldo-reg5", "vcc14", RK806_ID_NLDO5, rk806_ops_nldo,
109462306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_NLDO5_ON_VSEL,
109562306a36Sopenharmony_ci			RK806_POWER_EN5, rk806_ldo_voltage_ranges, 2,
109662306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
109762306a36Sopenharmony_ci
109862306a36Sopenharmony_ci	RK806_REGULATOR("pldo-reg1", "vcc11", RK806_ID_PLDO1, rk806_ops_pldo,
109962306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_PLDO1_ON_VSEL,
110062306a36Sopenharmony_ci			RK806_POWER_EN4, rk806_ldo_voltage_ranges, 1,
110162306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
110262306a36Sopenharmony_ci	RK806_REGULATOR("pldo-reg2", "vcc11", RK806_ID_PLDO2, rk806_ops_pldo,
110362306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_PLDO2_ON_VSEL,
110462306a36Sopenharmony_ci			RK806_POWER_EN4, rk806_ldo_voltage_ranges, 2,
110562306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
110662306a36Sopenharmony_ci	RK806_REGULATOR("pldo-reg3", "vcc11", RK806_ID_PLDO3, rk806_ops_pldo,
110762306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_PLDO3_ON_VSEL,
110862306a36Sopenharmony_ci			RK806_POWER_EN4, rk806_ldo_voltage_ranges, 3,
110962306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
111062306a36Sopenharmony_ci
111162306a36Sopenharmony_ci	RK806_REGULATOR("pldo-reg4", "vcc12", RK806_ID_PLDO4, rk806_ops_pldo,
111262306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_PLDO4_ON_VSEL,
111362306a36Sopenharmony_ci			RK806_POWER_EN5, rk806_ldo_voltage_ranges, 0,
111462306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
111562306a36Sopenharmony_ci	RK806_REGULATOR("pldo-reg5", "vcc12", RK806_ID_PLDO5, rk806_ops_pldo,
111662306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_PLDO5_ON_VSEL,
111762306a36Sopenharmony_ci			RK806_POWER_EN5, rk806_ldo_voltage_ranges, 1,
111862306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
111962306a36Sopenharmony_ci
112062306a36Sopenharmony_ci	RK806_REGULATOR("pldo-reg6", "vcca", RK806_ID_PLDO6, rk806_ops_pldo,
112162306a36Sopenharmony_ci			RK806_LDO_SEL_CNT, RK806_PLDO6_ON_VSEL,
112262306a36Sopenharmony_ci			RK806_POWER_EN4, rk806_ldo_voltage_ranges, 0,
112362306a36Sopenharmony_ci			0xEA, 0x38, rk806_ramp_delay_table_ldo),
112462306a36Sopenharmony_ci};
112562306a36Sopenharmony_ci
112662306a36Sopenharmony_ci
112762306a36Sopenharmony_cistatic const struct regulator_desc rk808_reg[] = {
112862306a36Sopenharmony_ci	{
112962306a36Sopenharmony_ci		.name = "DCDC_REG1",
113062306a36Sopenharmony_ci		.supply_name = "vcc1",
113162306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG1"),
113262306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
113362306a36Sopenharmony_ci		.id = RK808_ID_DCDC1,
113462306a36Sopenharmony_ci		.ops = &rk808_buck1_2_ops,
113562306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
113662306a36Sopenharmony_ci		.min_uV = 712500,
113762306a36Sopenharmony_ci		.uV_step = 12500,
113862306a36Sopenharmony_ci		.n_voltages = 64,
113962306a36Sopenharmony_ci		.vsel_reg = RK808_BUCK1_ON_VSEL_REG,
114062306a36Sopenharmony_ci		.vsel_mask = RK808_BUCK_VSEL_MASK,
114162306a36Sopenharmony_ci		.enable_reg = RK808_DCDC_EN_REG,
114262306a36Sopenharmony_ci		.enable_mask = BIT(0),
114362306a36Sopenharmony_ci		.ramp_reg = RK808_BUCK1_CONFIG_REG,
114462306a36Sopenharmony_ci		.ramp_mask = RK808_RAMP_RATE_MASK,
114562306a36Sopenharmony_ci		.ramp_delay_table = rk808_buck1_2_ramp_table,
114662306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk808_buck1_2_ramp_table),
114762306a36Sopenharmony_ci		.owner = THIS_MODULE,
114862306a36Sopenharmony_ci	}, {
114962306a36Sopenharmony_ci		.name = "DCDC_REG2",
115062306a36Sopenharmony_ci		.supply_name = "vcc2",
115162306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG2"),
115262306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
115362306a36Sopenharmony_ci		.id = RK808_ID_DCDC2,
115462306a36Sopenharmony_ci		.ops = &rk808_buck1_2_ops,
115562306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
115662306a36Sopenharmony_ci		.min_uV = 712500,
115762306a36Sopenharmony_ci		.uV_step = 12500,
115862306a36Sopenharmony_ci		.n_voltages = 64,
115962306a36Sopenharmony_ci		.vsel_reg = RK808_BUCK2_ON_VSEL_REG,
116062306a36Sopenharmony_ci		.vsel_mask = RK808_BUCK_VSEL_MASK,
116162306a36Sopenharmony_ci		.enable_reg = RK808_DCDC_EN_REG,
116262306a36Sopenharmony_ci		.enable_mask = BIT(1),
116362306a36Sopenharmony_ci		.ramp_reg = RK808_BUCK2_CONFIG_REG,
116462306a36Sopenharmony_ci		.ramp_mask = RK808_RAMP_RATE_MASK,
116562306a36Sopenharmony_ci		.ramp_delay_table = rk808_buck1_2_ramp_table,
116662306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk808_buck1_2_ramp_table),
116762306a36Sopenharmony_ci		.owner = THIS_MODULE,
116862306a36Sopenharmony_ci	}, {
116962306a36Sopenharmony_ci		.name = "DCDC_REG3",
117062306a36Sopenharmony_ci		.supply_name = "vcc3",
117162306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG3"),
117262306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
117362306a36Sopenharmony_ci		.id = RK808_ID_DCDC3,
117462306a36Sopenharmony_ci		.ops = &rk808_switch_ops,
117562306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
117662306a36Sopenharmony_ci		.n_voltages = 1,
117762306a36Sopenharmony_ci		.enable_reg = RK808_DCDC_EN_REG,
117862306a36Sopenharmony_ci		.enable_mask = BIT(2),
117962306a36Sopenharmony_ci		.owner = THIS_MODULE,
118062306a36Sopenharmony_ci	},
118162306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3300, 100,
118262306a36Sopenharmony_ci		RK808_BUCK4_ON_VSEL_REG, RK808_BUCK4_VSEL_MASK,
118362306a36Sopenharmony_ci		RK808_DCDC_EN_REG, BIT(3), 0),
118462306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100,
118562306a36Sopenharmony_ci		RK808_LDO1_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
118662306a36Sopenharmony_ci		BIT(0), 400),
118762306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100,
118862306a36Sopenharmony_ci		RK808_LDO2_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
118962306a36Sopenharmony_ci		BIT(1), 400),
119062306a36Sopenharmony_ci	{
119162306a36Sopenharmony_ci		.name = "LDO_REG3",
119262306a36Sopenharmony_ci		.supply_name = "vcc7",
119362306a36Sopenharmony_ci		.of_match = of_match_ptr("LDO_REG3"),
119462306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
119562306a36Sopenharmony_ci		.id = RK808_ID_LDO3,
119662306a36Sopenharmony_ci		.ops = &rk808_reg_ops_ranges,
119762306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
119862306a36Sopenharmony_ci		.n_voltages = 16,
119962306a36Sopenharmony_ci		.linear_ranges = rk808_ldo3_voltage_ranges,
120062306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges),
120162306a36Sopenharmony_ci		.vsel_reg = RK808_LDO3_ON_VSEL_REG,
120262306a36Sopenharmony_ci		.vsel_mask = RK808_BUCK4_VSEL_MASK,
120362306a36Sopenharmony_ci		.enable_reg = RK808_LDO_EN_REG,
120462306a36Sopenharmony_ci		.enable_mask = BIT(2),
120562306a36Sopenharmony_ci		.enable_time = 400,
120662306a36Sopenharmony_ci		.owner = THIS_MODULE,
120762306a36Sopenharmony_ci	},
120862306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_LDO4, "LDO_REG4", "vcc9", 1800, 3400, 100,
120962306a36Sopenharmony_ci		RK808_LDO4_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
121062306a36Sopenharmony_ci		BIT(3), 400),
121162306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_LDO5, "LDO_REG5", "vcc9", 1800, 3400, 100,
121262306a36Sopenharmony_ci		RK808_LDO5_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
121362306a36Sopenharmony_ci		BIT(4), 400),
121462306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_LDO6, "LDO_REG6", "vcc10", 800, 2500, 100,
121562306a36Sopenharmony_ci		RK808_LDO6_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
121662306a36Sopenharmony_ci		BIT(5), 400),
121762306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100,
121862306a36Sopenharmony_ci		RK808_LDO7_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
121962306a36Sopenharmony_ci		BIT(6), 400),
122062306a36Sopenharmony_ci	RK8XX_DESC(RK808_ID_LDO8, "LDO_REG8", "vcc11", 1800, 3400, 100,
122162306a36Sopenharmony_ci		RK808_LDO8_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG,
122262306a36Sopenharmony_ci		BIT(7), 400),
122362306a36Sopenharmony_ci	RK8XX_DESC_SWITCH(RK808_ID_SWITCH1, "SWITCH_REG1", "vcc8",
122462306a36Sopenharmony_ci		RK808_DCDC_EN_REG, BIT(5)),
122562306a36Sopenharmony_ci	RK8XX_DESC_SWITCH(RK808_ID_SWITCH2, "SWITCH_REG2", "vcc12",
122662306a36Sopenharmony_ci		RK808_DCDC_EN_REG, BIT(6)),
122762306a36Sopenharmony_ci};
122862306a36Sopenharmony_ci
122962306a36Sopenharmony_cistatic const struct regulator_desc rk809_reg[] = {
123062306a36Sopenharmony_ci	{
123162306a36Sopenharmony_ci		.name = "DCDC_REG1",
123262306a36Sopenharmony_ci		.supply_name = "vcc1",
123362306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG1"),
123462306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
123562306a36Sopenharmony_ci		.id = RK817_ID_DCDC1,
123662306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
123762306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
123862306a36Sopenharmony_ci		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
123962306a36Sopenharmony_ci		.linear_ranges = rk817_buck1_voltage_ranges,
124062306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
124162306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK1_ON_VSEL_REG,
124262306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
124362306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
124462306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
124562306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC1),
124662306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC1),
124762306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC1),
124862306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
124962306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
125062306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
125162306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
125262306a36Sopenharmony_ci		.owner = THIS_MODULE,
125362306a36Sopenharmony_ci	}, {
125462306a36Sopenharmony_ci		.name = "DCDC_REG2",
125562306a36Sopenharmony_ci		.supply_name = "vcc2",
125662306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG2"),
125762306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
125862306a36Sopenharmony_ci		.id = RK817_ID_DCDC2,
125962306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
126062306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
126162306a36Sopenharmony_ci		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
126262306a36Sopenharmony_ci		.linear_ranges = rk817_buck1_voltage_ranges,
126362306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
126462306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK2_ON_VSEL_REG,
126562306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
126662306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
126762306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
126862306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC2),
126962306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC2),
127062306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC2),
127162306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
127262306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
127362306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
127462306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
127562306a36Sopenharmony_ci		.owner = THIS_MODULE,
127662306a36Sopenharmony_ci	}, {
127762306a36Sopenharmony_ci		.name = "DCDC_REG3",
127862306a36Sopenharmony_ci		.supply_name = "vcc3",
127962306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG3"),
128062306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
128162306a36Sopenharmony_ci		.id = RK817_ID_DCDC3,
128262306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
128362306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
128462306a36Sopenharmony_ci		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
128562306a36Sopenharmony_ci		.linear_ranges = rk817_buck1_voltage_ranges,
128662306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
128762306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK3_ON_VSEL_REG,
128862306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
128962306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
129062306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
129162306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC3),
129262306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC3),
129362306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC3),
129462306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
129562306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
129662306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
129762306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
129862306a36Sopenharmony_ci		.owner = THIS_MODULE,
129962306a36Sopenharmony_ci	}, {
130062306a36Sopenharmony_ci		.name = "DCDC_REG4",
130162306a36Sopenharmony_ci		.supply_name = "vcc4",
130262306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG4"),
130362306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
130462306a36Sopenharmony_ci		.id = RK817_ID_DCDC4,
130562306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
130662306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
130762306a36Sopenharmony_ci		.n_voltages = RK817_BUCK3_SEL_CNT + 1,
130862306a36Sopenharmony_ci		.linear_ranges = rk817_buck3_voltage_ranges,
130962306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
131062306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK4_ON_VSEL_REG,
131162306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
131262306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
131362306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
131462306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC4),
131562306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC4),
131662306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC4),
131762306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
131862306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
131962306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
132062306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
132162306a36Sopenharmony_ci		.owner = THIS_MODULE,
132262306a36Sopenharmony_ci	},
132362306a36Sopenharmony_ci	{
132462306a36Sopenharmony_ci		.name = "DCDC_REG5",
132562306a36Sopenharmony_ci		.supply_name = "vcc9",
132662306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG5"),
132762306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
132862306a36Sopenharmony_ci		.id = RK809_ID_DCDC5,
132962306a36Sopenharmony_ci		.ops = &rk809_buck5_ops_range,
133062306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
133162306a36Sopenharmony_ci		.n_voltages = RK809_BUCK5_SEL_CNT,
133262306a36Sopenharmony_ci		.linear_ranges = rk809_buck5_voltage_ranges,
133362306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk809_buck5_voltage_ranges),
133462306a36Sopenharmony_ci		.vsel_reg = RK809_BUCK5_CONFIG(0),
133562306a36Sopenharmony_ci		.vsel_mask = RK809_BUCK5_VSEL_MASK,
133662306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(3),
133762306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(1),
133862306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(1),
133962306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(1),
134062306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
134162306a36Sopenharmony_ci		.owner = THIS_MODULE,
134262306a36Sopenharmony_ci	},
134362306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
134462306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
134562306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(0),
134662306a36Sopenharmony_ci		   DISABLE_VAL(0), 400),
134762306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
134862306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
134962306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(1),
135062306a36Sopenharmony_ci		   DISABLE_VAL(1), 400),
135162306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
135262306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
135362306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(2),
135462306a36Sopenharmony_ci		   DISABLE_VAL(2), 400),
135562306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
135662306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
135762306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(3),
135862306a36Sopenharmony_ci		   DISABLE_VAL(3), 400),
135962306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
136062306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
136162306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(0),
136262306a36Sopenharmony_ci		   DISABLE_VAL(0), 400),
136362306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
136462306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
136562306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(1),
136662306a36Sopenharmony_ci		   DISABLE_VAL(1), 400),
136762306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
136862306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
136962306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(2),
137062306a36Sopenharmony_ci		   DISABLE_VAL(2), 400),
137162306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
137262306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
137362306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(3),
137462306a36Sopenharmony_ci		   DISABLE_VAL(3), 400),
137562306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
137662306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
137762306a36Sopenharmony_ci		   RK817_POWER_EN_REG(3), ENABLE_MASK(0),
137862306a36Sopenharmony_ci		   DISABLE_VAL(0), 400),
137962306a36Sopenharmony_ci	RK817_DESC_SWITCH(RK809_ID_SW1, "SWITCH_REG1", "vcc9",
138062306a36Sopenharmony_ci			  RK817_POWER_EN_REG(3), ENABLE_MASK(2),
138162306a36Sopenharmony_ci			  DISABLE_VAL(2)),
138262306a36Sopenharmony_ci	RK817_DESC_SWITCH(RK809_ID_SW2, "SWITCH_REG2", "vcc8",
138362306a36Sopenharmony_ci			  RK817_POWER_EN_REG(3), ENABLE_MASK(3),
138462306a36Sopenharmony_ci			  DISABLE_VAL(3)),
138562306a36Sopenharmony_ci};
138662306a36Sopenharmony_ci
138762306a36Sopenharmony_cistatic const struct regulator_desc rk817_reg[] = {
138862306a36Sopenharmony_ci	{
138962306a36Sopenharmony_ci		.name = "DCDC_REG1",
139062306a36Sopenharmony_ci		.supply_name = "vcc1",
139162306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG1"),
139262306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
139362306a36Sopenharmony_ci		.id = RK817_ID_DCDC1,
139462306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
139562306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
139662306a36Sopenharmony_ci		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
139762306a36Sopenharmony_ci		.linear_ranges = rk817_buck1_voltage_ranges,
139862306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
139962306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK1_ON_VSEL_REG,
140062306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
140162306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
140262306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC1),
140362306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC1),
140462306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC1),
140562306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC1),
140662306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
140762306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
140862306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
140962306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
141062306a36Sopenharmony_ci		.owner = THIS_MODULE,
141162306a36Sopenharmony_ci	}, {
141262306a36Sopenharmony_ci		.name = "DCDC_REG2",
141362306a36Sopenharmony_ci		.supply_name = "vcc2",
141462306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG2"),
141562306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
141662306a36Sopenharmony_ci		.id = RK817_ID_DCDC2,
141762306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
141862306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
141962306a36Sopenharmony_ci		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
142062306a36Sopenharmony_ci		.linear_ranges = rk817_buck1_voltage_ranges,
142162306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
142262306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK2_ON_VSEL_REG,
142362306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
142462306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
142562306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC2),
142662306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC2),
142762306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC2),
142862306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC2),
142962306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
143062306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
143162306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
143262306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
143362306a36Sopenharmony_ci		.owner = THIS_MODULE,
143462306a36Sopenharmony_ci	}, {
143562306a36Sopenharmony_ci		.name = "DCDC_REG3",
143662306a36Sopenharmony_ci		.supply_name = "vcc3",
143762306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG3"),
143862306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
143962306a36Sopenharmony_ci		.id = RK817_ID_DCDC3,
144062306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
144162306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
144262306a36Sopenharmony_ci		.n_voltages = RK817_BUCK1_SEL_CNT + 1,
144362306a36Sopenharmony_ci		.linear_ranges = rk817_buck1_voltage_ranges,
144462306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges),
144562306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK3_ON_VSEL_REG,
144662306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
144762306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
144862306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC3),
144962306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC3),
145062306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC3),
145162306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC3),
145262306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
145362306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
145462306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
145562306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
145662306a36Sopenharmony_ci		.owner = THIS_MODULE,
145762306a36Sopenharmony_ci	}, {
145862306a36Sopenharmony_ci		.name = "DCDC_REG4",
145962306a36Sopenharmony_ci		.supply_name = "vcc4",
146062306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG4"),
146162306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
146262306a36Sopenharmony_ci		.id = RK817_ID_DCDC4,
146362306a36Sopenharmony_ci		.ops = &rk817_buck_ops_range,
146462306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
146562306a36Sopenharmony_ci		.n_voltages = RK817_BUCK3_SEL_CNT + 1,
146662306a36Sopenharmony_ci		.linear_ranges = rk817_buck3_voltage_ranges,
146762306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges),
146862306a36Sopenharmony_ci		.vsel_reg = RK817_BUCK4_ON_VSEL_REG,
146962306a36Sopenharmony_ci		.vsel_mask = RK817_BUCK_VSEL_MASK,
147062306a36Sopenharmony_ci		.enable_reg = RK817_POWER_EN_REG(0),
147162306a36Sopenharmony_ci		.enable_mask = ENABLE_MASK(RK817_ID_DCDC4),
147262306a36Sopenharmony_ci		.enable_val = ENABLE_MASK(RK817_ID_DCDC4),
147362306a36Sopenharmony_ci		.disable_val = DISABLE_VAL(RK817_ID_DCDC4),
147462306a36Sopenharmony_ci		.ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC4),
147562306a36Sopenharmony_ci		.ramp_mask = RK817_RAMP_RATE_MASK,
147662306a36Sopenharmony_ci		.ramp_delay_table = rk817_buck1_4_ramp_table,
147762306a36Sopenharmony_ci		.n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table),
147862306a36Sopenharmony_ci		.of_map_mode = rk8xx_regulator_of_map_mode,
147962306a36Sopenharmony_ci		.owner = THIS_MODULE,
148062306a36Sopenharmony_ci	},
148162306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25,
148262306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK,
148362306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(0),
148462306a36Sopenharmony_ci		   DISABLE_VAL(0), 400),
148562306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25,
148662306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK,
148762306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(1),
148862306a36Sopenharmony_ci		   DISABLE_VAL(1), 400),
148962306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25,
149062306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK,
149162306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(2),
149262306a36Sopenharmony_ci		   DISABLE_VAL(2), 400),
149362306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25,
149462306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK,
149562306a36Sopenharmony_ci		   RK817_POWER_EN_REG(1), ENABLE_MASK(3),
149662306a36Sopenharmony_ci		   DISABLE_VAL(3), 400),
149762306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25,
149862306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK,
149962306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(0),
150062306a36Sopenharmony_ci		   DISABLE_VAL(0), 400),
150162306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25,
150262306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK,
150362306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(1),
150462306a36Sopenharmony_ci		   DISABLE_VAL(1), 400),
150562306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25,
150662306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK,
150762306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(2),
150862306a36Sopenharmony_ci		   DISABLE_VAL(2), 400),
150962306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25,
151062306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK,
151162306a36Sopenharmony_ci		   RK817_POWER_EN_REG(2), ENABLE_MASK(3),
151262306a36Sopenharmony_ci		   DISABLE_VAL(3), 400),
151362306a36Sopenharmony_ci	RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25,
151462306a36Sopenharmony_ci		   RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK,
151562306a36Sopenharmony_ci		   RK817_POWER_EN_REG(3), ENABLE_MASK(0),
151662306a36Sopenharmony_ci		   DISABLE_VAL(0), 400),
151762306a36Sopenharmony_ci	RK817_BOOST_DESC(RK817_ID_BOOST, "BOOST", "vcc8", 4700, 5400, 100,
151862306a36Sopenharmony_ci			 RK817_BOOST_OTG_CFG, RK817_BOOST_VSEL_MASK,
151962306a36Sopenharmony_ci			 RK817_POWER_EN_REG(3), ENABLE_MASK(1), ENABLE_MASK(1),
152062306a36Sopenharmony_ci		   DISABLE_VAL(1), 400, 3500 - 5400),
152162306a36Sopenharmony_ci	RK817_DESC_SWITCH(RK817_ID_BOOST_OTG_SW, "OTG_SWITCH", "vcc9",
152262306a36Sopenharmony_ci			  RK817_POWER_EN_REG(3), ENABLE_MASK(2),
152362306a36Sopenharmony_ci			  DISABLE_VAL(2)),
152462306a36Sopenharmony_ci};
152562306a36Sopenharmony_ci
152662306a36Sopenharmony_cistatic const struct regulator_desc rk818_reg[] = {
152762306a36Sopenharmony_ci	{
152862306a36Sopenharmony_ci		.name = "DCDC_REG1",
152962306a36Sopenharmony_ci		.supply_name = "vcc1",
153062306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG1"),
153162306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
153262306a36Sopenharmony_ci		.id = RK818_ID_DCDC1,
153362306a36Sopenharmony_ci		.ops = &rk808_reg_ops,
153462306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
153562306a36Sopenharmony_ci		.min_uV = 712500,
153662306a36Sopenharmony_ci		.uV_step = 12500,
153762306a36Sopenharmony_ci		.n_voltages = 64,
153862306a36Sopenharmony_ci		.vsel_reg = RK818_BUCK1_ON_VSEL_REG,
153962306a36Sopenharmony_ci		.vsel_mask = RK818_BUCK_VSEL_MASK,
154062306a36Sopenharmony_ci		.enable_reg = RK818_DCDC_EN_REG,
154162306a36Sopenharmony_ci		.enable_mask = BIT(0),
154262306a36Sopenharmony_ci		.owner = THIS_MODULE,
154362306a36Sopenharmony_ci	}, {
154462306a36Sopenharmony_ci		.name = "DCDC_REG2",
154562306a36Sopenharmony_ci		.supply_name = "vcc2",
154662306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG2"),
154762306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
154862306a36Sopenharmony_ci		.id = RK818_ID_DCDC2,
154962306a36Sopenharmony_ci		.ops = &rk808_reg_ops,
155062306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
155162306a36Sopenharmony_ci		.min_uV = 712500,
155262306a36Sopenharmony_ci		.uV_step = 12500,
155362306a36Sopenharmony_ci		.n_voltages = 64,
155462306a36Sopenharmony_ci		.vsel_reg = RK818_BUCK2_ON_VSEL_REG,
155562306a36Sopenharmony_ci		.vsel_mask = RK818_BUCK_VSEL_MASK,
155662306a36Sopenharmony_ci		.enable_reg = RK818_DCDC_EN_REG,
155762306a36Sopenharmony_ci		.enable_mask = BIT(1),
155862306a36Sopenharmony_ci		.owner = THIS_MODULE,
155962306a36Sopenharmony_ci	}, {
156062306a36Sopenharmony_ci		.name = "DCDC_REG3",
156162306a36Sopenharmony_ci		.supply_name = "vcc3",
156262306a36Sopenharmony_ci		.of_match = of_match_ptr("DCDC_REG3"),
156362306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
156462306a36Sopenharmony_ci		.id = RK818_ID_DCDC3,
156562306a36Sopenharmony_ci		.ops = &rk808_switch_ops,
156662306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
156762306a36Sopenharmony_ci		.n_voltages = 1,
156862306a36Sopenharmony_ci		.enable_reg = RK818_DCDC_EN_REG,
156962306a36Sopenharmony_ci		.enable_mask = BIT(2),
157062306a36Sopenharmony_ci		.owner = THIS_MODULE,
157162306a36Sopenharmony_ci	},
157262306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3600, 100,
157362306a36Sopenharmony_ci		RK818_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK,
157462306a36Sopenharmony_ci		RK818_DCDC_EN_REG, BIT(3), 0),
157562306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_BOOST, "DCDC_BOOST", "boost", 4700, 5400, 100,
157662306a36Sopenharmony_ci		RK818_BOOST_LDO9_ON_VSEL_REG, RK818_BOOST_ON_VSEL_MASK,
157762306a36Sopenharmony_ci		RK818_DCDC_EN_REG, BIT(4), 0),
157862306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100,
157962306a36Sopenharmony_ci		RK818_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
158062306a36Sopenharmony_ci		BIT(0), 400),
158162306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100,
158262306a36Sopenharmony_ci		RK818_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
158362306a36Sopenharmony_ci		BIT(1), 400),
158462306a36Sopenharmony_ci	{
158562306a36Sopenharmony_ci		.name = "LDO_REG3",
158662306a36Sopenharmony_ci		.supply_name = "vcc7",
158762306a36Sopenharmony_ci		.of_match = of_match_ptr("LDO_REG3"),
158862306a36Sopenharmony_ci		.regulators_node = of_match_ptr("regulators"),
158962306a36Sopenharmony_ci		.id = RK818_ID_LDO3,
159062306a36Sopenharmony_ci		.ops = &rk808_reg_ops_ranges,
159162306a36Sopenharmony_ci		.type = REGULATOR_VOLTAGE,
159262306a36Sopenharmony_ci		.n_voltages = 16,
159362306a36Sopenharmony_ci		.linear_ranges = rk808_ldo3_voltage_ranges,
159462306a36Sopenharmony_ci		.n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges),
159562306a36Sopenharmony_ci		.vsel_reg = RK818_LDO3_ON_VSEL_REG,
159662306a36Sopenharmony_ci		.vsel_mask = RK818_LDO3_ON_VSEL_MASK,
159762306a36Sopenharmony_ci		.enable_reg = RK818_LDO_EN_REG,
159862306a36Sopenharmony_ci		.enable_mask = BIT(2),
159962306a36Sopenharmony_ci		.enable_time = 400,
160062306a36Sopenharmony_ci		.owner = THIS_MODULE,
160162306a36Sopenharmony_ci	},
160262306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO4, "LDO_REG4", "vcc8", 1800, 3400, 100,
160362306a36Sopenharmony_ci		RK818_LDO4_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
160462306a36Sopenharmony_ci		BIT(3), 400),
160562306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO5, "LDO_REG5", "vcc7", 1800, 3400, 100,
160662306a36Sopenharmony_ci		RK818_LDO5_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
160762306a36Sopenharmony_ci		BIT(4), 400),
160862306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO6, "LDO_REG6", "vcc8", 800, 2500, 100,
160962306a36Sopenharmony_ci		RK818_LDO6_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
161062306a36Sopenharmony_ci		BIT(5), 400),
161162306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100,
161262306a36Sopenharmony_ci		RK818_LDO7_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
161362306a36Sopenharmony_ci		BIT(6), 400),
161462306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO8, "LDO_REG8", "vcc8", 1800, 3400, 100,
161562306a36Sopenharmony_ci		RK818_LDO8_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG,
161662306a36Sopenharmony_ci		BIT(7), 400),
161762306a36Sopenharmony_ci	RK8XX_DESC(RK818_ID_LDO9, "LDO_REG9", "vcc9", 1800, 3400, 100,
161862306a36Sopenharmony_ci		RK818_BOOST_LDO9_ON_VSEL_REG, RK818_LDO_VSEL_MASK,
161962306a36Sopenharmony_ci		RK818_DCDC_EN_REG, BIT(5), 400),
162062306a36Sopenharmony_ci	RK8XX_DESC_SWITCH(RK818_ID_SWITCH, "SWITCH_REG", "vcc9",
162162306a36Sopenharmony_ci		RK818_DCDC_EN_REG, BIT(6)),
162262306a36Sopenharmony_ci	RK8XX_DESC_SWITCH(RK818_ID_HDMI_SWITCH, "HDMI_SWITCH", "h_5v",
162362306a36Sopenharmony_ci		RK818_H5V_EN_REG, BIT(0)),
162462306a36Sopenharmony_ci	RK8XX_DESC_SWITCH(RK818_ID_OTG_SWITCH, "OTG_SWITCH", "usb",
162562306a36Sopenharmony_ci		RK818_DCDC_EN_REG, BIT(7)),
162662306a36Sopenharmony_ci};
162762306a36Sopenharmony_ci
162862306a36Sopenharmony_cistatic int rk808_regulator_dt_parse_pdata(struct device *dev,
162962306a36Sopenharmony_ci				   struct regmap *map,
163062306a36Sopenharmony_ci				   struct rk808_regulator_data *pdata)
163162306a36Sopenharmony_ci{
163262306a36Sopenharmony_ci	struct device_node *np;
163362306a36Sopenharmony_ci	int tmp, ret = 0, i;
163462306a36Sopenharmony_ci
163562306a36Sopenharmony_ci	np = of_get_child_by_name(dev->of_node, "regulators");
163662306a36Sopenharmony_ci	if (!np)
163762306a36Sopenharmony_ci		return -ENXIO;
163862306a36Sopenharmony_ci
163962306a36Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) {
164062306a36Sopenharmony_ci		pdata->dvs_gpio[i] =
164162306a36Sopenharmony_ci			devm_gpiod_get_index_optional(dev, "dvs", i,
164262306a36Sopenharmony_ci						      GPIOD_OUT_LOW);
164362306a36Sopenharmony_ci		if (IS_ERR(pdata->dvs_gpio[i])) {
164462306a36Sopenharmony_ci			ret = PTR_ERR(pdata->dvs_gpio[i]);
164562306a36Sopenharmony_ci			dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret);
164662306a36Sopenharmony_ci			goto dt_parse_end;
164762306a36Sopenharmony_ci		}
164862306a36Sopenharmony_ci
164962306a36Sopenharmony_ci		if (!pdata->dvs_gpio[i]) {
165062306a36Sopenharmony_ci			dev_info(dev, "there is no dvs%d gpio\n", i);
165162306a36Sopenharmony_ci			continue;
165262306a36Sopenharmony_ci		}
165362306a36Sopenharmony_ci
165462306a36Sopenharmony_ci		tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL;
165562306a36Sopenharmony_ci		ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp,
165662306a36Sopenharmony_ci				gpiod_is_active_low(pdata->dvs_gpio[i]) ?
165762306a36Sopenharmony_ci				0 : tmp);
165862306a36Sopenharmony_ci	}
165962306a36Sopenharmony_ci
166062306a36Sopenharmony_cidt_parse_end:
166162306a36Sopenharmony_ci	of_node_put(np);
166262306a36Sopenharmony_ci	return ret;
166362306a36Sopenharmony_ci}
166462306a36Sopenharmony_ci
166562306a36Sopenharmony_cistatic int rk808_regulator_probe(struct platform_device *pdev)
166662306a36Sopenharmony_ci{
166762306a36Sopenharmony_ci	struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent);
166862306a36Sopenharmony_ci	struct regulator_config config = {};
166962306a36Sopenharmony_ci	struct regulator_dev *rk808_rdev;
167062306a36Sopenharmony_ci	struct rk808_regulator_data *pdata;
167162306a36Sopenharmony_ci	const struct regulator_desc *regulators;
167262306a36Sopenharmony_ci	struct regmap *regmap;
167362306a36Sopenharmony_ci	int ret, i, nregulators;
167462306a36Sopenharmony_ci
167562306a36Sopenharmony_ci	pdev->dev.of_node = pdev->dev.parent->of_node;
167662306a36Sopenharmony_ci	pdev->dev.of_node_reused = true;
167762306a36Sopenharmony_ci
167862306a36Sopenharmony_ci	regmap = dev_get_regmap(pdev->dev.parent, NULL);
167962306a36Sopenharmony_ci	if (!regmap)
168062306a36Sopenharmony_ci		return -ENODEV;
168162306a36Sopenharmony_ci
168262306a36Sopenharmony_ci	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
168362306a36Sopenharmony_ci	if (!pdata)
168462306a36Sopenharmony_ci		return -ENOMEM;
168562306a36Sopenharmony_ci
168662306a36Sopenharmony_ci	ret = rk808_regulator_dt_parse_pdata(&pdev->dev, regmap, pdata);
168762306a36Sopenharmony_ci	if (ret < 0)
168862306a36Sopenharmony_ci		return ret;
168962306a36Sopenharmony_ci
169062306a36Sopenharmony_ci	platform_set_drvdata(pdev, pdata);
169162306a36Sopenharmony_ci
169262306a36Sopenharmony_ci	switch (rk808->variant) {
169362306a36Sopenharmony_ci	case RK805_ID:
169462306a36Sopenharmony_ci		regulators = rk805_reg;
169562306a36Sopenharmony_ci		nregulators = RK805_NUM_REGULATORS;
169662306a36Sopenharmony_ci		break;
169762306a36Sopenharmony_ci	case RK806_ID:
169862306a36Sopenharmony_ci		regulators = rk806_reg;
169962306a36Sopenharmony_ci		nregulators = ARRAY_SIZE(rk806_reg);
170062306a36Sopenharmony_ci		break;
170162306a36Sopenharmony_ci	case RK808_ID:
170262306a36Sopenharmony_ci		regulators = rk808_reg;
170362306a36Sopenharmony_ci		nregulators = RK808_NUM_REGULATORS;
170462306a36Sopenharmony_ci		break;
170562306a36Sopenharmony_ci	case RK809_ID:
170662306a36Sopenharmony_ci		regulators = rk809_reg;
170762306a36Sopenharmony_ci		nregulators = RK809_NUM_REGULATORS;
170862306a36Sopenharmony_ci		break;
170962306a36Sopenharmony_ci	case RK817_ID:
171062306a36Sopenharmony_ci		regulators = rk817_reg;
171162306a36Sopenharmony_ci		nregulators = RK817_NUM_REGULATORS;
171262306a36Sopenharmony_ci		break;
171362306a36Sopenharmony_ci	case RK818_ID:
171462306a36Sopenharmony_ci		regulators = rk818_reg;
171562306a36Sopenharmony_ci		nregulators = RK818_NUM_REGULATORS;
171662306a36Sopenharmony_ci		break;
171762306a36Sopenharmony_ci	default:
171862306a36Sopenharmony_ci		dev_err(&pdev->dev, "unsupported RK8XX ID %lu\n",
171962306a36Sopenharmony_ci			rk808->variant);
172062306a36Sopenharmony_ci		return -EINVAL;
172162306a36Sopenharmony_ci	}
172262306a36Sopenharmony_ci
172362306a36Sopenharmony_ci	config.dev = &pdev->dev;
172462306a36Sopenharmony_ci	config.driver_data = pdata;
172562306a36Sopenharmony_ci	config.regmap = regmap;
172662306a36Sopenharmony_ci
172762306a36Sopenharmony_ci	/* Instantiate the regulators */
172862306a36Sopenharmony_ci	for (i = 0; i < nregulators; i++) {
172962306a36Sopenharmony_ci		rk808_rdev = devm_regulator_register(&pdev->dev,
173062306a36Sopenharmony_ci						     &regulators[i], &config);
173162306a36Sopenharmony_ci		if (IS_ERR(rk808_rdev))
173262306a36Sopenharmony_ci			return dev_err_probe(&pdev->dev, PTR_ERR(rk808_rdev),
173362306a36Sopenharmony_ci					     "failed to register %d regulator\n", i);
173462306a36Sopenharmony_ci	}
173562306a36Sopenharmony_ci
173662306a36Sopenharmony_ci	return 0;
173762306a36Sopenharmony_ci}
173862306a36Sopenharmony_ci
173962306a36Sopenharmony_cistatic struct platform_driver rk808_regulator_driver = {
174062306a36Sopenharmony_ci	.probe = rk808_regulator_probe,
174162306a36Sopenharmony_ci	.driver = {
174262306a36Sopenharmony_ci		.name = "rk808-regulator",
174362306a36Sopenharmony_ci		.probe_type = PROBE_FORCE_SYNCHRONOUS,
174462306a36Sopenharmony_ci	},
174562306a36Sopenharmony_ci};
174662306a36Sopenharmony_ci
174762306a36Sopenharmony_cimodule_platform_driver(rk808_regulator_driver);
174862306a36Sopenharmony_ci
174962306a36Sopenharmony_ciMODULE_DESCRIPTION("regulator driver for the RK805/RK808/RK818 series PMICs");
175062306a36Sopenharmony_ciMODULE_AUTHOR("Tony xie <tony.xie@rock-chips.com>");
175162306a36Sopenharmony_ciMODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
175262306a36Sopenharmony_ciMODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>");
175362306a36Sopenharmony_ciMODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>");
175462306a36Sopenharmony_ciMODULE_AUTHOR("Xu Shengfei <xsf@rock-chips.com>");
175562306a36Sopenharmony_ciMODULE_LICENSE("GPL");
175662306a36Sopenharmony_ciMODULE_ALIAS("platform:rk808-regulator");
1757