diff mbox

[U-Boot,4/4] power: regulator: rk808: add rk818 support

Message ID 1492745648-1642-5-git-send-email-jacob-chen@iotwrt.com
State Superseded
Delegated to: Jaehoon Chung
Headers show

Commit Message

Jacob Chen April 21, 2017, 3:34 a.m. UTC
Add support for the rk818 regulator. The regulator module consists
of 4 DCDCs, 9 LDOs, 1 switch and 1 BOOST converter which is used to
power OTG and HDMI5V.

TODO: I don't know how to deal with BOOST and LDO9,
so just ignore them now.


Signed-off-by: Jacob Chen <jacob-chen@iotwrt.com>
---

 drivers/power/regulator/rk808.c | 55 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 51 insertions(+), 4 deletions(-)

Comments

Wadim Egorov April 21, 2017, 7:59 a.m. UTC | #1
Hi Jacob,


Am 21.04.2017 um 05:34 schrieb Jacob Chen:
> Add support for the rk818 regulator. The regulator module consists
> of 4 DCDCs, 9 LDOs, 1 switch and 1 BOOST converter which is used to
> power OTG and HDMI5V.
>
> TODO: I don't know how to deal with BOOST and LDO9,
> so just ignore them now.

you can handle the boost converter the same way you handle the buck
converters.
And there is nothing special about LDO9.

Regards,
Wadim
Simon Glass April 29, 2017, 12:26 a.m. UTC | #2
On 20 April 2017 at 21:34, Jacob Chen <jacob-chen@iotwrt.com> wrote:
> Add support for the rk818 regulator. The regulator module consists
> of 4 DCDCs, 9 LDOs, 1 switch and 1 BOOST converter which is used to
> power OTG and HDMI5V.
>
> TODO: I don't know how to deal with BOOST and LDO9,
> so just ignore them now.
>
>
> Signed-off-by: Jacob Chen <jacob-chen@iotwrt.com>
> ---
>
>  drivers/power/regulator/rk808.c | 55 ++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 51 insertions(+), 4 deletions(-)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/drivers/power/regulator/rk808.c b/drivers/power/regulator/rk808.c
index 441806c..71ab76e 100644
--- a/drivers/power/regulator/rk808.c
+++ b/drivers/power/regulator/rk808.c
@@ -25,6 +25,12 @@ 
 #define RK808_BUCK4_VSEL_MASK	0xf
 #define RK808_LDO_VSEL_MASK	0x1f
 
+#define RK818_BUCK_VSEL_MASK		0x3f
+#define RK818_BUCK4_VSEL_MASK		0x1f
+#define RK818_LDO_VSEL_MASK		0x1f
+#define RK818_LDO3_ON_VSEL_MASK		0xf
+#define RK818_BOOST_ON_VSEL_MASK	0xe0
+
 struct rk808_reg_info {
 	uint min_uv;
 	uint step_uv;
@@ -50,10 +56,51 @@  static const struct rk808_reg_info rk808_ldo[] = {
 	{ 1800000, 100000, REG_LDO8_ON_VSEL, RK808_LDO_VSEL_MASK, },
 };
 
+static const struct rk808_reg_info rk818_buck[] = {
+	{ 712500, 12500, REG_BUCK1_ON_VSEL, RK818_BUCK_VSEL_MASK, },
+	{ 712500, 12500, REG_BUCK2_ON_VSEL, RK818_BUCK_VSEL_MASK, },
+	{ 712500, 12500, -1, RK818_BUCK_VSEL_MASK, },
+	{ 1800000, 100000, REG_BUCK4_ON_VSEL, RK818_BUCK4_VSEL_MASK, },
+};
+
+static const struct rk808_reg_info rk818_ldo[] = {
+	{ 1800000, 100000, REG_LDO1_ON_VSEL, RK818_LDO_VSEL_MASK, },
+	{ 1800000, 100000, REG_LDO2_ON_VSEL, RK818_LDO_VSEL_MASK, },
+	{ 800000, 100000, REG_LDO3_ON_VSEL, RK818_LDO3_ON_VSEL_MASK, },
+	{ 1800000, 100000, REG_LDO4_ON_VSEL, RK818_LDO_VSEL_MASK, },
+	{ 1800000, 100000, REG_LDO5_ON_VSEL, RK818_LDO_VSEL_MASK, },
+	{ 800000, 100000, REG_LDO6_ON_VSEL, RK818_LDO_VSEL_MASK, },
+	{ 800000, 100000, REG_LDO7_ON_VSEL, RK818_LDO_VSEL_MASK, },
+	{ 1800000, 100000, REG_LDO8_ON_VSEL, RK818_LDO_VSEL_MASK, },
+};
+
+static const struct rk808_reg_info *get_buck_reg(struct udevice *pmic,
+					     int num)
+{
+	struct rk808_priv *rk808 = dev_get_priv(pmic);
+	switch (rk808->variant) {
+	case RK818_ID:
+		return &rk818_buck[num];
+	default:
+		return &rk808_buck[num];
+	}
+}
+
+static const struct rk808_reg_info *get_ldo_reg(struct udevice *pmic,
+					     int num)
+{
+	struct rk808_priv *rk808 = dev_get_priv(pmic);
+	switch (rk808->variant) {
+	case RK818_ID:
+		return &rk818_ldo[num - 1];
+	default:
+		return &rk808_ldo[num - 1];
+	}
+}
 
 static int _buck_set_value(struct udevice *pmic, int buck, int uvolt)
 {
-	const struct rk808_reg_info *info = &rk808_buck[buck - 1];
+	const struct rk808_reg_info *info = get_buck_reg(pmic, buck - 1);
 	int mask = info->vsel_mask;
 	int val;
 
@@ -89,7 +136,7 @@  static int _buck_set_enable(struct udevice *pmic, int buck, bool enable)
 static int buck_get_value(struct udevice *dev)
 {
 	int buck = dev->driver_data - 1;
-	const struct rk808_reg_info *info = &rk808_buck[buck];
+	const struct rk808_reg_info *info = get_buck_reg(dev->parent, buck);
 	int mask = info->vsel_mask;
 	int ret, val;
 
@@ -135,7 +182,7 @@  static bool buck_get_enable(struct udevice *dev)
 static int ldo_get_value(struct udevice *dev)
 {
 	int ldo = dev->driver_data - 1;
-	const struct rk808_reg_info *info = &rk808_ldo[ldo];
+	const struct rk808_reg_info *info = get_ldo_reg(dev->parent, ldo);
 	int mask = info->vsel_mask;
 	int ret, val;
 
@@ -152,7 +199,7 @@  static int ldo_get_value(struct udevice *dev)
 static int ldo_set_value(struct udevice *dev, int uvolt)
 {
 	int ldo = dev->driver_data - 1;
-	const struct rk808_reg_info *info = &rk808_ldo[ldo];
+	const struct rk808_reg_info *info = get_ldo_reg(dev->parent, ldo);
 	int mask = info->vsel_mask;
 	int val;