Skip to contentSkip to conversation

rockchip: Port IO-domain driver for RK3568 from linux

PATCH In review Jonas Karlman 2 participants 11 messages Aug 21, 2023 – Sep 27, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover rockchip: Port IO-domain driver for RK3568 from linux

This series port the IO-domain driver for RK3568 from linux. It is necessary for the IO-domain setting of the SoC to match the voltage supplied by the regulators.

The driver auto probe after bind and configures IO-domain based on the voltage reported by the regulators. This fixes issues observed while working on the GMAC driver for RK3568 devices. The IO-domain setting default to 3v3, however some vccio domains may be supplied by 1v8.

This series also add a minimal generic RK356x board that only enable eMMC and SD-card node and keep the IO-domain driver disabled. The generic board can be used to boot from eMMC/SD-card on boards that follow reference board design.

Changes in v2:
- Include patch to return correct voltage for switchout converters
- Simplify code that return correct voltage for buck converters
- Add a minimal generic RK356x board with IO-domain driver disabled.
- Collect r-b tags

Patch 1 adds protection so that regulator autoset only happens one time. Patch 2-3 fixes rk8xx buck/switchout regulator driver to report correct voltage.
Patch 4 adds the IO-domain driver.
Patch 5 adds the minimal generic RK3566/RK3568 board.

This series can also be found at [1]

[1] https://github.com/Kwiboo/u-boot-rockchip/commits/rk3568-io-domain-v2

Jonas Karlman (3):
power: regulator: Only run autoset once for each regulator
rockchip: Port IO-domain driver for RK3568 from linux
rockchip: board: Add minimal generic RK3566/RK3568 board

Joseph Chen (1):
regulator: rk8xx: Return correct voltage for buck converters

shengfei Xu (1):
regulator: rk8xx: Return correct voltage for switchout converters

 arch/arm/dts/rk3568-generic-u-boot.dtsi    |  14 ++
 arch/arm/dts/rk3568-generic.dts            |  38 +++++
 board/rockchip/evb_rk3568/MAINTAINERS      |   7 +
 configs/generic-rk3568_defconfig           |  64 ++++++++
 doc/board/rockchip/rockchip.rst            |   1 +
 drivers/misc/Kconfig                       |   9 ++
 drivers/misc/Makefile                      |   1 +
 drivers/misc/rockchip-io-domain.c          | 167 +++++++++++++++++++++
 drivers/power/regulator/regulator-uclass.c |  18 ++-
 drivers/power/regulator/rk8xx.c            |  95 +++++++-----
 include/power/regulator.h                  |   1 +
 11 files changed, 375 insertions(+), 40 deletions(-)
 create mode 100644 arch/arm/dts/rk3568-generic-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3568-generic.dts
 create mode 100644 configs/generic-rk3568_defconfig
 create mode 100644 drivers/misc/rockchip-io-domain.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/5 power: regulator: Only run autoset once for each regulator

With the commit 4fcba5d556b4 ("regulator: implement basic reference counter"), keeping regulator enablement in balance become more important. Calling regulator_autoset multiple times on a fixed regulator increase the enable count for each call, resulting in an unbalanced enable count.

Introduce a AUTOSET_DONE flag and use it to mark that autoset has run for the regulator. Return -EALREADY on any subsequent call to autoset.

This fixes so that the enable count is only ever increased by one per regulator for autoset.

Fixes 4fcba5d556b4 ("regulator: implement basic reference counter")

---
Cc: Svyatoslav Ryhel <[email protected]>
---
v2:
- No change

 drivers/power/regulator/regulator-uclass.c | 18 ++++++++++++++----
 include/power/regulator.h                  |  1 +
 2 files changed, 15 insertions(+), 4 deletions(-)
drivers/power/regulator/regulator-uclass.c +14 -4
index 3a6ba69f6d5f..77d101f262e2 100644
@@ -293,6 +293,9 @@ int regulator_autoset(struct udevice *dev)
 
 	uc_pdata = dev_get_uclass_plat(dev);
 
+	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_DONE)
+		return -EALREADY;
+
 	ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
 	if (ret == -ENOSYS)
 		ret = 0;
@@ -306,11 +309,15 @@ int regulator_autoset(struct udevice *dev)
 			return ret;
 	}
 
-	if (!uc_pdata->always_on && !uc_pdata->boot_on)
-		return -EMEDIUMTYPE;
+	if (!uc_pdata->always_on && !uc_pdata->boot_on) {
+		ret = -EMEDIUMTYPE;
+		goto out;
+	}
 
-	if (uc_pdata->type == REGULATOR_TYPE_FIXED)
-		return regulator_set_enable(dev, true);
+	if (uc_pdata->type == REGULATOR_TYPE_FIXED) {
+		ret = regulator_set_enable(dev, true);
+		goto out;
+	}
 
 	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
 		ret = regulator_set_value(dev, uc_pdata->min_uV);
@@ -322,6 +329,9 @@ int regulator_autoset(struct udevice *dev)
 	if (!ret)
 		ret = regulator_set_enable(dev, true);
 
+out:
+	uc_pdata->flags |= REGULATOR_FLAG_AUTOSET_DONE;
+
 	return ret;
 }
 
include/power/regulator.h +1 -0
index ff1bfc2435ae..200652cb3d7a 100644
@@ -134,6 +134,7 @@ struct dm_regulator_mode {
 enum regulator_flag {
 	REGULATOR_FLAG_AUTOSET_UV	= 1 << 0,
 	REGULATOR_FLAG_AUTOSET_UA	= 1 << 1,
+	REGULATOR_FLAG_AUTOSET_DONE	= 1 << 2,
 };
 
 /**
Signature · 1 line
2.41.0
Reviewed-by on v2 1/5
#2 lore raw

Re: [PATCH v2 1/5] power: regulator: Only run autoset once for each regulator

Quoted 5 lines · Jonas Karlman

With the commit 4fcba5d556b4 ("regulator: implement basic reference counter"), keeping regulator enablement in balance become more important. Calling regulator_autoset multiple times on a fixed regulator increase the enable count for each call, resulting in an unbalanced enable count.

Quoted 8 lines

Introduce a AUTOSET_DONE flag and use it to mark that autoset has run for the regulator. Return -EALREADY on any subsequent call to autoset.

This fixes so that the enable count is only ever increased by one per regulator for autoset.

Fixes 4fcba5d556b4 ("regulator: implement basic reference counter")

Thanks,
- Kever

Quoted 66 lines

---
Cc: Svyatoslav Ryhel <[email protected]>
---
v2:
- No change

  drivers/power/regulator/regulator-uclass.c | 18 ++++++++++++++----
  include/power/regulator.h                  |  1 +
  2 files changed, 15 insertions(+), 4 deletions(-)
drivers/power/regulator/regulator-uclass.c +14 -4
index 3a6ba69f6d5f..77d101f262e2 100644
@@ -293,6 +293,9 @@ int regulator_autoset(struct udevice *dev)
 
  	uc_pdata = dev_get_uclass_plat(dev);
 
+	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_DONE)
+		return -EALREADY;
+
  	ret = regulator_set_suspend_enable(dev, uc_pdata->suspend_on);
  	if (ret == -ENOSYS)
  		ret = 0;
@@ -306,11 +309,15 @@ int regulator_autoset(struct udevice *dev)
  			return ret;
  	}
 
-	if (!uc_pdata->always_on && !uc_pdata->boot_on)
-		return -EMEDIUMTYPE;
+	if (!uc_pdata->always_on && !uc_pdata->boot_on) {
+		ret = -EMEDIUMTYPE;
+		goto out;
+	}
 
-	if (uc_pdata->type == REGULATOR_TYPE_FIXED)
-		return regulator_set_enable(dev, true);
+	if (uc_pdata->type == REGULATOR_TYPE_FIXED) {
+		ret = regulator_set_enable(dev, true);
+		goto out;
+	}
 
  	if (uc_pdata->flags & REGULATOR_FLAG_AUTOSET_UV)
  		ret = regulator_set_value(dev, uc_pdata->min_uV);
@@ -322,6 +329,9 @@ int regulator_autoset(struct udevice *dev)
  	if (!ret)
  		ret = regulator_set_enable(dev, true);
 
+out:
+	uc_pdata->flags |= REGULATOR_FLAG_AUTOSET_DONE;
+
  	return ret;
  }
 
include/power/regulator.h +1 -0
index ff1bfc2435ae..200652cb3d7a 100644
@@ -134,6 +134,7 @@ struct dm_regulator_mode {
  enum regulator_flag {
  	REGULATOR_FLAG_AUTOSET_UV	= 1 << 0,
  	REGULATOR_FLAG_AUTOSET_UA	= 1 << 1,
+	REGULATOR_FLAG_AUTOSET_DONE	= 1 << 2,
  };
 
  /**
#3 lore raw

PATCH v2 2/5 regulator: rk8xx: Return correct voltage for buck converters

In reply to Jonas Karlman

From: Joseph Chen <[email protected]>

Information from the first range group is always used to calculate the voltage returned for buck converters. This may result in wrong voltage reported back to the regulator_get_value caller.

Traverse all the possible BUCK ranges to fix this issue.

Fixes addd062beacc ("power: pmic: rk816: support rk816 pmic")
Fixes b62280745e55 ("power: pmic: rk805: support rk805 pmic")
Fixes b4a35574b38d ("power: pmic: rk817: support rk817 pmic")
Fixes ee30068fa574 ("power: pmic: rk809: support rk809 pmic")
[[email protected]: fix checkpatch error, simplify buck get_value, update commit message]

---
v2:
- Simplify locating correct rk8xx_reg_info
- Update max_sel to include range up to and including vsel_mask
- Drop range_num
- Collect r-b tag

 drivers/power/regulator/rk8xx.c | 76 +++++++++++++++++----------------
 1 file changed, 40 insertions(+), 36 deletions(-)
drivers/power/regulator/rk8xx.c +40 -36
index e95640a39b0a..9444daa85c19 100644
@@ -88,62 +88,63 @@ struct rk8xx_reg_info {
 	u8 config_reg;
 	u8 vsel_mask;
 	u8 min_sel;
+	u8 max_sel;
 };
 
 static const struct rk8xx_reg_info rk808_buck[] = {
-	{ 712500,   12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK808_BUCK_VSEL_MASK, },
-	{ 712500,   12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK808_BUCK_VSEL_MASK, },
-	{ 712500,   12500, NA,		      NA,		  REG_BUCK3_CONFIG, RK808_BUCK_VSEL_MASK, },
-	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK808_BUCK4_VSEL_MASK, },
+	{  712500,  12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK808_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{  712500,  12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK808_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{      NA,     NA,		  NA,		      NA, REG_BUCK3_CONFIG,		       NA,   NA,   NA },
+	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK808_BUCK4_VSEL_MASK, 0x00, 0x0f },
 };
 
 static const struct rk8xx_reg_info rk816_buck[] = {
 	/* buck 1 */
-	{  712500,  12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, },
-	{ 1800000, 200000, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x3c, },
-	{ 2300000,      0, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x3f, },
+	{  712500,  12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3b },
+	{ 1800000, 200000, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3c, 0x3e },
+	{ 2300000,	0, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3f, 0x3f },
 	/* buck 2 */
-	{  712500,  12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, },
-	{ 1800000, 200000, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x3c, },
-	{ 2300000,      0, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x3f, },
+	{  712500,  12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3b },
+	{ 1800000, 200000, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3c, 0x3e },
+	{ 2300000,	0, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3f, 0x3f },
 	/* buck 3 */
-	{ 712500,   12500, NA,		      NA,		  REG_BUCK3_CONFIG, RK818_BUCK_VSEL_MASK, },
+	{      NA,     NA,		  NA,		      NA, REG_BUCK3_CONFIG,                    NA,   NA,   NA },
 	/* buck 4 */
-	{  800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, },
+	{  800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, 0x00, 0x1f },
 };
 
 static const struct rk8xx_reg_info rk809_buck5[] = {
 	/* buck 5 */
-	{ 1500000,	0, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x00, },
-	{ 1800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x01, },
-	{ 2800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x04, },
-	{ 3300000, 300000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x06, },
+	{ 1500000,	0, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x00, 0x00 },
+	{ 1800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x01, 0x03 },
+	{ 2800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x04, 0x05 },
+	{ 3300000, 300000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x06, 0x07 },
 };
 
 static const struct rk8xx_reg_info rk817_buck[] = {
 	/* buck 1 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 2400000,	0, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x59, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x50, 0x58 },
+	{ 2400000,	0, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x59, 0x7f },
 	/* buck 2 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 2400000,	0, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x59, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x50, 0x58 },
+	{ 2400000,	0, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x59, 0x7f },
 	/* buck 3 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 2400000,	0, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x59, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x50, 0x58 },
+	{ 2400000,	0, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x59, 0x7f },
 	/* buck 4 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 3400000,	0, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x63, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x50, 0x62 },
+	{ 3400000,	0, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x63, 0x7f },
 };
 
 static const struct rk8xx_reg_info rk818_buck[] = {
-	{ 712500,   12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, },
-	{ 712500,   12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, },
-	{ 712500,   12500, NA,		      NA,		  REG_BUCK3_CONFIG, RK818_BUCK_VSEL_MASK, },
-	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, },
+	{ 712500,   12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{ 712500,   12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{     NA,      NA,		  NA,		      NA, REG_BUCK3_CONFIG,		       NA,   NA,   NA },
+	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, 0x00, 0x1f },
 };
 
 #ifdef ENABLE_DRIVER
@@ -706,7 +707,6 @@ static int _ldo_get_suspend_enable(struct udevice *pmic, int ldo)
 static int buck_get_value(struct udevice *dev)
 {
 	int buck = dev->driver_data - 1;
-	/* We assume level-1 voltage is enough for usage in U-Boot */
 	const struct rk8xx_reg_info *info = get_buck_reg(dev->parent, buck, 0);
 	int mask = info->vsel_mask;
 	int ret, val;
@@ -717,9 +717,12 @@ static int buck_get_value(struct udevice *dev)
 	ret = pmic_reg_read(dev->parent, info->vsel_reg);
 	if (ret < 0)
 		return ret;
+
 	val = ret & mask;
+	while (val > info->max_sel)
+		info++;
 
-	return info->min_uv + val * info->step_uv;
+	return info->min_uv + (val - info->min_sel) * info->step_uv;
 }
 
 static int buck_set_value(struct udevice *dev, int uvolt)
@@ -732,7 +735,6 @@ static int buck_set_value(struct udevice *dev, int uvolt)
 static int buck_get_suspend_value(struct udevice *dev)
 {
 	int buck = dev->driver_data - 1;
-	/* We assume level-1 voltage is enough for usage in U-Boot */
 	const struct rk8xx_reg_info *info = get_buck_reg(dev->parent, buck, 0);
 	int mask = info->vsel_mask;
 	int ret, val;
@@ -745,8 +747,10 @@ static int buck_get_suspend_value(struct udevice *dev)
 		return ret;
 
 	val = ret & mask;
+	while (val > info->max_sel)
+		info++;
 
-	return info->min_uv + val * info->step_uv;
+	return info->min_uv + (val - info->min_sel) * info->step_uv;
 }
 
 static int buck_set_suspend_value(struct udevice *dev, int uvolt)
Signature · 1 line
2.41.0
Reviewed-by on v2 2/5
#4 lore raw

Re: [PATCH v2 2/5] regulator: rk8xx: Return correct voltage for buck converters

Quoted 8 lines · Jonas Karlman

From: Joseph Chen <[email protected]>

Information from the first range group is always used to calculate the voltage returned for buck converters. This may result in wrong voltage reported back to the regulator_get_value caller.

Traverse all the possible BUCK ranges to fix this issue.

Quoted 8 lines
Fixes addd062beacc ("power: pmic: rk816: support rk816 pmic")
Fixes b62280745e55 ("power: pmic: rk805: support rk805 pmic")
Fixes b4a35574b38d ("power: pmic: rk817: support rk817 pmic")
Fixes ee30068fa574 ("power: pmic: rk809: support rk809 pmic")
[[email protected]: fix checkpatch error, simplify buck get_value, update commit message]

Thanks,
- Kever

Quoted 152 lines

---
v2:
- Simplify locating correct rk8xx_reg_info
- Update max_sel to include range up to and including vsel_mask
- Drop range_num
- Collect r-b tag

  drivers/power/regulator/rk8xx.c | 76 +++++++++++++++++----------------
  1 file changed, 40 insertions(+), 36 deletions(-)
drivers/power/regulator/rk8xx.c +40 -36
index e95640a39b0a..9444daa85c19 100644
@@ -88,62 +88,63 @@ struct rk8xx_reg_info {
  	u8 config_reg;
  	u8 vsel_mask;
  	u8 min_sel;
+	u8 max_sel;
  };
 
  static const struct rk8xx_reg_info rk808_buck[] = {
-	{ 712500,   12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK808_BUCK_VSEL_MASK, },
-	{ 712500,   12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK808_BUCK_VSEL_MASK, },
-	{ 712500,   12500, NA,		      NA,		  REG_BUCK3_CONFIG, RK808_BUCK_VSEL_MASK, },
-	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK808_BUCK4_VSEL_MASK, },
+	{  712500,  12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK808_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{  712500,  12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK808_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{      NA,     NA,		  NA,		      NA, REG_BUCK3_CONFIG,		       NA,   NA,   NA },
+	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK808_BUCK4_VSEL_MASK, 0x00, 0x0f },
  };
 
  static const struct rk8xx_reg_info rk816_buck[] = {
  	/* buck 1 */
-	{  712500,  12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, },
-	{ 1800000, 200000, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x3c, },
-	{ 2300000,      0, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x3f, },
+	{  712500,  12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3b },
+	{ 1800000, 200000, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3c, 0x3e },
+	{ 2300000,	0, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3f, 0x3f },
  	/* buck 2 */
-	{  712500,  12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, },
-	{ 1800000, 200000, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x3c, },
-	{ 2300000,      0, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x3f, },
+	{  712500,  12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3b },
+	{ 1800000, 200000, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3c, 0x3e },
+	{ 2300000,	0, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x3f, 0x3f },
  	/* buck 3 */
-	{ 712500,   12500, NA,		      NA,		  REG_BUCK3_CONFIG, RK818_BUCK_VSEL_MASK, },
+	{      NA,     NA,		  NA,		      NA, REG_BUCK3_CONFIG,                    NA,   NA,   NA },
  	/* buck 4 */
-	{  800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, },
+	{  800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, 0x00, 0x1f },
  };
 
  static const struct rk8xx_reg_info rk809_buck5[] = {
  	/* buck 5 */
-	{ 1500000,	0, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x00, },
-	{ 1800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x01, },
-	{ 2800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x04, },
-	{ 3300000, 300000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x06, },
+	{ 1500000,	0, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x00, 0x00 },
+	{ 1800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x01, 0x03 },
+	{ 2800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x04, 0x05 },
+	{ 3300000, 300000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x06, 0x07 },
  };
 
  static const struct rk8xx_reg_info rk817_buck[] = {
  	/* buck 1 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 2400000,	0, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x59, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x50, 0x58 },
+	{ 2400000,	0, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x59, 0x7f },
  	/* buck 2 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 2400000,	0, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x59, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x50, 0x58 },
+	{ 2400000,	0, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x59, 0x7f },
  	/* buck 3 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 2400000,	0, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x59, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x50, 0x58 },
+	{ 2400000,	0, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x59, 0x7f },
  	/* buck 4 */
-	{  500000,  12500, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x00, },
-	{ 1500000, 100000, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x50, },
-	{ 3400000,	0, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x63, },
+	{  500000,  12500, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x00, 0x4f },
+	{ 1500000, 100000, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x50, 0x62 },
+	{ 3400000,	0, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x63, 0x7f },
  };
 
  static const struct rk8xx_reg_info rk818_buck[] = {
-	{ 712500,   12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, },
-	{ 712500,   12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, },
-	{ 712500,   12500, NA,		      NA,		  REG_BUCK3_CONFIG, RK818_BUCK_VSEL_MASK, },
-	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, },
+	{ 712500,   12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{ 712500,   12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG,  RK818_BUCK_VSEL_MASK, 0x00, 0x3f },
+	{     NA,      NA,		  NA,		      NA, REG_BUCK3_CONFIG,		       NA,   NA,   NA },
+	{ 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, 0x00, 0x1f },
  };
 
  #ifdef ENABLE_DRIVER
@@ -706,7 +707,6 @@ static int _ldo_get_suspend_enable(struct udevice *pmic, int ldo)
  static int buck_get_value(struct udevice *dev)
  {
  	int buck = dev->driver_data - 1;
-	/* We assume level-1 voltage is enough for usage in U-Boot */
  	const struct rk8xx_reg_info *info = get_buck_reg(dev->parent, buck, 0);
  	int mask = info->vsel_mask;
  	int ret, val;
@@ -717,9 +717,12 @@ static int buck_get_value(struct udevice *dev)
  	ret = pmic_reg_read(dev->parent, info->vsel_reg);
  	if (ret < 0)
  		return ret;
+
  	val = ret & mask;
+	while (val > info->max_sel)
+		info++;
 
-	return info->min_uv + val * info->step_uv;
+	return info->min_uv + (val - info->min_sel) * info->step_uv;
  }
 
  static int buck_set_value(struct udevice *dev, int uvolt)
@@ -732,7 +735,6 @@ static int buck_set_value(struct udevice *dev, int uvolt)
  static int buck_get_suspend_value(struct udevice *dev)
  {
  	int buck = dev->driver_data - 1;
-	/* We assume level-1 voltage is enough for usage in U-Boot */
  	const struct rk8xx_reg_info *info = get_buck_reg(dev->parent, buck, 0);
  	int mask = info->vsel_mask;
  	int ret, val;
@@ -745,8 +747,10 @@ static int buck_get_suspend_value(struct udevice *dev)
  		return ret;
 
  	val = ret & mask;
+	while (val > info->max_sel)
+		info++;
 
-	return info->min_uv + val * info->step_uv;
+	return info->min_uv + (val - info->min_sel) * info->step_uv;
  }
 
  static int buck_set_suspend_value(struct udevice *dev, int uvolt)
#5 lore raw

PATCH v2 3/5 regulator: rk8xx: Return correct voltage for switchout converters

In reply to Jonas Karlman

From: shengfei Xu <[email protected]>

The voltage value for switchout converters is always reported as 0 uV. When the switch is enabled, it's voltage is same as input supply.

Fix this by implementing get_value for switchout converters.

Fixes ee30068fa574 ("power: pmic: rk809: support rk809 pmic")
[[email protected]: fix checkpatch error, update commit message]

---
v2:
- New patch

 drivers/power/regulator/rk8xx.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/power/regulator/rk8xx.c +19 -0
index 9444daa85c19..e80bd6c37230 100644
@@ -1032,6 +1032,25 @@ static int switch_get_suspend_enable(struct udevice *dev)
  */
 static int switch_get_value(struct udevice *dev)
 {
+	static const char * const supply_name_rk809[] = {
+		"vcc9-supply",
+		"vcc8-supply",
+	};
+	struct rk8xx_priv *priv = dev_get_priv(dev->parent);
+	struct udevice *supply;
+	int id = dev->driver_data - 1;
+
+	if (!switch_get_enable(dev))
+		return 0;
+
+	if (priv->variant == RK809_ID) {
+		if (!uclass_get_device_by_phandle(UCLASS_REGULATOR,
+						  dev->parent,
+						  supply_name_rk809[id],
+						  &supply))
+			return regulator_get_value(supply);
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.41.0
Reviewed-by on v2 3/5
#6 lore raw

Re: [PATCH v2 3/5] regulator: rk8xx: Return correct voltage for switchout converters

Quoted 11 lines · Jonas Karlman

From: shengfei Xu <[email protected]>

The voltage value for switchout converters is always reported as 0 uV. When the switch is enabled, it's voltage is same as input supply.

Fix this by implementing get_value for switchout converters.

Fixes ee30068fa574 ("power: pmic: rk809: support rk809 pmic")
[[email protected]: fix checkpatch error, update commit message]

Thanks,
- Kever

Quoted 37 lines

---
v2:
- New patch

  drivers/power/regulator/rk8xx.c | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)
drivers/power/regulator/rk8xx.c +19 -0
index 9444daa85c19..e80bd6c37230 100644
@@ -1032,6 +1032,25 @@ static int switch_get_suspend_enable(struct udevice *dev)
   */
  static int switch_get_value(struct udevice *dev)
  {
+	static const char * const supply_name_rk809[] = {
+		"vcc9-supply",
+		"vcc8-supply",
+	};
+	struct rk8xx_priv *priv = dev_get_priv(dev->parent);
+	struct udevice *supply;
+	int id = dev->driver_data - 1;
+
+	if (!switch_get_enable(dev))
+		return 0;
+
+	if (priv->variant == RK809_ID) {
+		if (!uclass_get_device_by_phandle(UCLASS_REGULATOR,
+						  dev->parent,
+						  supply_name_rk809[id],
+						  &supply))
+			return regulator_get_value(supply);
+	}
+
  	return 0;
  }
 
#7 lore raw

PATCH v2 4/5 rockchip: Port IO-domain driver for RK3568 from linux

In reply to Jonas Karlman

Port the Rockchip IO-domain driver for RK3568 from linux.

The driver auto probe after bind to configure IO-domain based on the regulator voltage. Compared to the linux driver this driver is not notified about regulator voltage changes and only configure IO-domain based on the initial voltage autoset by the regulator.

It is not recommended to enable MMC_IO_VOLTAGE or the mmc signal voltage and IO-domain may end up out of sync.

Based on the linux commit 28b05a64e47c ("soc: rockchip: io-domain: add rk3568 support").

---
Cc: Jianqun Xu <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: Doug Anderson <[email protected]>
---
v2:
- Add probe after bind comment
- Drop parenthesis
- Collect r-b tag

 drivers/misc/Kconfig              |   9 ++
 drivers/misc/Makefile             |   1 +
 drivers/misc/rockchip-io-domain.c | 167 ++++++++++++++++++++++++++++++
 3 files changed, 177 insertions(+)
 create mode 100644 drivers/misc/rockchip-io-domain.c
drivers/misc/Kconfig +9 -0
index b9f5c7a37aed..d160ce693939 100644
@@ -101,6 +101,15 @@ config ROCKCHIP_OTP
 	  addressing and a length or through child-nodes that are generated
 	  based on the e-fuse map retrieved from the DTS.
 
+config ROCKCHIP_IODOMAIN
+	bool "Rockchip IO-domain driver support"
+	depends on DM_REGULATOR && ARCH_ROCKCHIP
+	default y if ROCKCHIP_RK3568
+	help
+	  Enable support for IO-domains in Rockchip SoCs. It is necessary
+	  for the IO-domain setting of the SoC to match the voltage supplied
+	  by the regulators.
+
 config SIFIVE_OTP
 	bool "SiFive eMemory OTP driver"
 	depends on MISC
drivers/misc/Makefile +1 -0
index fd8805f34bd9..b67b82358a6c 100644
@@ -69,6 +69,7 @@ obj-$(CONFIG_SANDBOX) += qfw_sandbox.o
 endif
 obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
 obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
+obj-$(CONFIG_$(SPL_TPL_)ROCKCHIP_IODOMAIN) += rockchip-io-domain.o
 obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
 obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
 obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
drivers/misc/rockchip-io-domain.c new file +167 -0

167 lines not on this page · raw message

Signature · 1 line
2.41.0
Reviewed-by on v2 4/5
#8 lore raw
Quoted 13 lines · Jonas Karlman

Port the Rockchip IO-domain driver for RK3568 from linux.

The driver auto probe after bind to configure IO-domain based on the regulator voltage. Compared to the linux driver this driver is not notified about regulator voltage changes and only configure IO-domain based on the initial voltage autoset by the regulator.

It is not recommended to enable MMC_IO_VOLTAGE or the mmc signal voltage and IO-domain may end up out of sync.

Based on the linux commit 28b05a64e47c ("soc: rockchip: io-domain: add rk3568 support").

Quoted 6 lines

---
Cc: Jianqun Xu <[email protected]>
Cc: Heiko Stuebner <[email protected]>
Cc: Doug Anderson <[email protected]>

Thanks,
- Kever

Quoted 217 lines

---
v2:
- Add probe after bind comment
- Drop parenthesis
- Collect r-b tag

  drivers/misc/Kconfig              |   9 ++
  drivers/misc/Makefile             |   1 +
  drivers/misc/rockchip-io-domain.c | 167 ++++++++++++++++++++++++++++++
  3 files changed, 177 insertions(+)

create mode 100644 drivers/misc/rockchip-io-domain.c

drivers/misc/Kconfig +9 -0
index b9f5c7a37aed..d160ce693939 100644
@@ -101,6 +101,15 @@ config ROCKCHIP_OTP
  	  addressing and a length or through child-nodes that are generated
  	  based on the e-fuse map retrieved from the DTS.
 
+config ROCKCHIP_IODOMAIN
+	bool "Rockchip IO-domain driver support"
+	depends on DM_REGULATOR && ARCH_ROCKCHIP
+	default y if ROCKCHIP_RK3568
+	help
+	  Enable support for IO-domains in Rockchip SoCs. It is necessary
+	  for the IO-domain setting of the SoC to match the voltage supplied
+	  by the regulators.
+
  config SIFIVE_OTP
  	bool "SiFive eMemory OTP driver"
  	depends on MISC
drivers/misc/Makefile +1 -0
index fd8805f34bd9..b67b82358a6c 100644
@@ -69,6 +69,7 @@ obj-$(CONFIG_SANDBOX) += qfw_sandbox.o
  endif
  obj-$(CONFIG_ROCKCHIP_EFUSE) += rockchip-efuse.o
  obj-$(CONFIG_ROCKCHIP_OTP) += rockchip-otp.o
+obj-$(CONFIG_$(SPL_TPL_)ROCKCHIP_IODOMAIN) += rockchip-io-domain.o
  obj-$(CONFIG_SANDBOX) += syscon_sandbox.o misc_sandbox.o
  obj-$(CONFIG_SIFIVE_OTP) += sifive-otp.o
  obj-$(CONFIG_SMSC_LPC47M) += smsc_lpc47m.o
drivers/misc/rockchip-io-domain.c new file +167 -0
new file mode 100644
index 000000000000..3f6227f993f9
@@ -0,0 +1,167 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Rockchip IO Voltage Domain driver
+ *
+ * Ported from linux drivers/soc/rockchip/io-domain.c
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/device_compat.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <power/regulator.h>
+
+#define MAX_SUPPLIES		16
+
+/*
+ * The max voltage for 1.8V and 3.3V come from the Rockchip datasheet under
+ * "Recommended Operating Conditions" for "Digital GPIO".   When the typical
+ * is 3.3V the max is 3.6V.  When the typical is 1.8V the max is 1.98V.
+ *
+ * They are used like this:
+ * - If the voltage on a rail is above the "1.8" voltage (1.98V) we'll tell the
+ *   SoC we're at 3.3.
+ * - If the voltage on a rail is above the "3.3" voltage (3.6V) we'll consider
+ *   that to be an error.
+ */
+#define MAX_VOLTAGE_1_8		1980000
+#define MAX_VOLTAGE_3_3		3600000
+
+#define RK3568_PMU_GRF_IO_VSEL0		0x0140
+#define RK3568_PMU_GRF_IO_VSEL1		0x0144
+#define RK3568_PMU_GRF_IO_VSEL2		0x0148
+
+struct rockchip_iodomain_soc_data {
+	int grf_offset;
+	const char *supply_names[MAX_SUPPLIES];
+	int (*write)(struct regmap *grf, int idx, int uV);
+};
+
+static int rk3568_iodomain_write(struct regmap *grf, int idx, int uV)
+{
+	u32 is_3v3 = uV > MAX_VOLTAGE_1_8;
+	u32 val0, val1;
+	int b;
+
+	switch (idx) {
+	case 0: /* pmuio1 */
+		break;
+	case 1: /* pmuio2 */
+		b = idx;
+		val0 = BIT(16 + b) | (is_3v3 ? 0 : BIT(b));
+		b = idx + 4;
+		val1 = BIT(16 + b) | (is_3v3 ? BIT(b) : 0);
+
+		regmap_write(grf, RK3568_PMU_GRF_IO_VSEL2, val0);
+		regmap_write(grf, RK3568_PMU_GRF_IO_VSEL2, val1);
+		break;
+	case 3: /* vccio2 */
+		break;
+	case 2: /* vccio1 */
+	case 4: /* vccio3 */
+	case 5: /* vccio4 */
+	case 6: /* vccio5 */
+	case 7: /* vccio6 */
+	case 8: /* vccio7 */
+		b = idx - 1;
+		val0 = BIT(16 + b) | (is_3v3 ? 0 : BIT(b));
+		val1 = BIT(16 + b) | (is_3v3 ? BIT(b) : 0);
+
+		regmap_write(grf, RK3568_PMU_GRF_IO_VSEL0, val0);
+		regmap_write(grf, RK3568_PMU_GRF_IO_VSEL1, val1);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static const struct rockchip_iodomain_soc_data soc_data_rk3568_pmu = {
+	.grf_offset = 0x140,
+	.supply_names = {
+		NULL,
+		"pmuio2-supply",
+		"vccio1-supply",
+		NULL,
+		"vccio3-supply",
+		"vccio4-supply",
+		"vccio5-supply",
+		"vccio6-supply",
+		"vccio7-supply",
+	},
+	.write = rk3568_iodomain_write,
+};
+
+static const struct udevice_id rockchip_iodomain_ids[] = {
+	{
+		.compatible = "rockchip,rk3568-pmu-io-voltage-domain",
+		.data = (ulong)&soc_data_rk3568_pmu,
+	},
+	{ }
+};
+
+static int rockchip_iodomain_bind(struct udevice *dev)
+{
+	/*
+	 * According to the Hardware Design Guide, IO-domain configuration must
+	 * be consistent with the power supply voltage (1.8V or 3.3V).
+	 * Probe after bind to configure IO-domain voltage early during boot.
+	 */
+	dev_or_flags(dev, DM_FLAG_PROBE_AFTER_BIND);
+
+	return 0;
+}
+
+static int rockchip_iodomain_probe(struct udevice *dev)
+{
+	struct rockchip_iodomain_soc_data *soc_data =
+		(struct rockchip_iodomain_soc_data *)dev_get_driver_data(dev);
+	struct regmap *grf;
+	int ret;
+
+	grf = syscon_get_regmap(dev_get_parent(dev));
+	if (IS_ERR(grf))
+		return PTR_ERR(grf);
+
+	for (int i = 0; i < MAX_SUPPLIES; i++) {
+		const char *supply_name = soc_data->supply_names[i];
+		struct udevice *reg;
+		int uV;
+
+		if (!supply_name)
+			continue;
+
+		ret = device_get_supply_regulator(dev, supply_name, &reg);
+		if (ret)
+			continue;
+
+		ret = regulator_autoset(reg);
+		if (ret && ret != -EALREADY && ret != -EMEDIUMTYPE &&
+		    ret != -ENOSYS)
+			continue;
+
+		uV = regulator_get_value(reg);
+		if (uV <= 0)
+			continue;
+
+		if (uV > MAX_VOLTAGE_3_3) {
+			dev_crit(dev, "%s: %d uV is too high. May damage SoC!\n",
+				 supply_name, uV);
+			continue;
+		}
+
+		soc_data->write(grf, i, uV);
+	}
+
+	return 0;
+}
+
+U_BOOT_DRIVER(rockchip_iodomain) = {
+	.name = "rockchip_iodomain",
+	.id = UCLASS_NOP,
+	.of_match = rockchip_iodomain_ids,
+	.bind = rockchip_iodomain_bind,
+	.probe = rockchip_iodomain_probe,
+};
#9 lore raw

PATCH v2 5/5 rockchip: board: Add minimal generic RK3566/RK3568 board

In reply to Jonas Karlman

Add a minimal generic RK3566/RK3568 board that only have eMMC and SDMMC enabled. This defconfig can be used to boot from eMMC or SD-card on most RK3566/RK3568 boards that follow reference board design.

---
v2:
- New patch

 arch/arm/dts/rk3568-generic-u-boot.dtsi | 14 ++++++
 arch/arm/dts/rk3568-generic.dts         | 38 +++++++++++++++
 board/rockchip/evb_rk3568/MAINTAINERS   |  7 +++
 configs/generic-rk3568_defconfig        | 64 +++++++++++++++++++++++++
 doc/board/rockchip/rockchip.rst         |  1 +
 5 files changed, 124 insertions(+)
 create mode 100644 arch/arm/dts/rk3568-generic-u-boot.dtsi
 create mode 100644 arch/arm/dts/rk3568-generic.dts
 create mode 100644 configs/generic-rk3568_defconfig
arch/arm/dts/rk3568-generic-u-boot.dtsi new file +14 -0
new file mode 100644
index 000000000000..90022580a13b
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+
+#include "rk356x-u-boot.dtsi"
+
+/ {
+	chosen {
+		stdout-path = &uart2;
+	};
+};
+
+&uart2 {
+	bootph-pre-ram;
+	clock-frequency = <24000000>;
+};
arch/arm/dts/rk3568-generic.dts new file +38 -0
new file mode 100644
index 000000000000..1006ea55bb98
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Minimal generic DT for RK3566/RK3568 with eMMC and SD-card enabled
+ */
+
+/dts-v1/;
+#include "rk356x.dtsi"
+
+/ {
+	model = "Generic RK3566/RK3568";
+	compatible = "rockchip,rk3568";
+
+	chosen: chosen {
+		stdout-path = "serial2:1500000n8";
+	};
+};
+
+&sdhci {
+	bus-width = <8>;
+	cap-mmc-highspeed;
+	non-removable;
+	pinctrl-names = "default";
+	pinctrl-0 = <&emmc_bus8 &emmc_clk &emmc_cmd>;
+	status = "okay";
+};
+
+&sdmmc0 {
+	bus-width = <4>;
+	cap-sd-highspeed;
+	disable-wp;
+	pinctrl-names = "default";
+	pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd>;
+	status = "okay";
+};
+
+&uart2 {
+	status = "okay";
+};
board/rockchip/evb_rk3568/MAINTAINERS +7 -0
index cc9eb432a8b5..fa8d1190931d 100644
@@ -7,6 +7,13 @@ F:	configs/evb-rk3568_defconfig
 F:	arch/arm/dts/rk3568-evb-u-boot.dtsi
 F:	arch/arm/dts/rk3568-evb.dts
 
+GENERIC-RK3568
+M:	Jonas Karlman <[email protected]>
+S:	Maintained
+F:	configs/generic-rk3568_defconfig
+F:	arch/arm/dts/rk3568-generic.dts
+F:	arch/arm/dts/rk3568-generic-u-boot.dtsi
+
 LUBANCAT-2
 M:	Andy Yan <[email protected]>
 S:	Maintained
configs/generic-rk3568_defconfig new file +64 -0

64 lines not on this page · raw message

doc/board/rockchip/rockchip.rst +1 -0
index de9fe8e642b1..183a9e4aa699 100644
@@ -104,6 +104,7 @@ List of mainline supported Rockchip boards:
      - EmbedFire LubanCat 2 (lubancat-2-rk3568)
      - FriendlyElec NanoPi R5C (nanopi-r5c-rk3568)
      - FriendlyElec NanoPi R5S (nanopi-r5s-rk3568)
+     - Generic RK3566/RK3568 (generic-rk3568)
      - Hardkernel ODROID-M1 (odroid-m1-rk3568)
      - Radxa E25 Carrier Board (radxa-e25-rk3568)
      - Radxa ROCK 3 Model A (rock-3a-rk3568)
Signature · 1 line
2.41.0
Reviewed-by on v2 5/5
#10 lore raw

Re: [PATCH v2 5/5] rockchip: board: Add minimal generic RK3566/RK3568 board

Quoted 5 lines · Jonas Karlman

Add a minimal generic RK3566/RK3568 board that only have eMMC and SDMMC enabled. This defconfig can be used to boot from eMMC or SD-card on most RK3566/RK3568 boards that follow reference board design.

Thanks,
- Kever

Quoted 178 lines

---
v2:
- New patch

  arch/arm/dts/rk3568-generic-u-boot.dtsi | 14 ++++++
  arch/arm/dts/rk3568-generic.dts         | 38 +++++++++++++++
  board/rockchip/evb_rk3568/MAINTAINERS   |  7 +++
  configs/generic-rk3568_defconfig        | 64 +++++++++++++++++++++++++
  doc/board/rockchip/rockchip.rst         |  1 +
  5 files changed, 124 insertions(+)

create mode 100644 arch/arm/dts/rk3568-generic-u-boot.dtsi create mode 100644 arch/arm/dts/rk3568-generic.dts create mode 100644 configs/generic-rk3568_defconfig

arch/arm/dts/rk3568-generic-u-boot.dtsi new file +14 -0
new file mode 100644
index 000000000000..90022580a13b
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+
+#include "rk356x-u-boot.dtsi"
+
+/ {
+	chosen {
+		stdout-path = &uart2;
+	};
+};
+
+&uart2 {
+	bootph-pre-ram;
+	clock-frequency = <24000000>;
+};
arch/arm/dts/rk3568-generic.dts new file +38 -0
new file mode 100644
index 000000000000..1006ea55bb98
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
+/*
+ * Minimal generic DT for RK3566/RK3568 with eMMC and SD-card enabled
+ */
+
+/dts-v1/;
+#include "rk356x.dtsi"
+
+/ {
+	model = "Generic RK3566/RK3568";
+	compatible = "rockchip,rk3568";
+
+	chosen: chosen {
+		stdout-path = "serial2:1500000n8";
+	};
+};
+
+&sdhci {
+	bus-width = <8>;
+	cap-mmc-highspeed;
+	non-removable;
+	pinctrl-names = "default";
+	pinctrl-0 = <&emmc_bus8 &emmc_clk &emmc_cmd>;
+	status = "okay";
+};
+
+&sdmmc0 {
+	bus-width = <4>;
+	cap-sd-highspeed;
+	disable-wp;
+	pinctrl-names = "default";
+	pinctrl-0 = <&sdmmc0_bus4 &sdmmc0_clk &sdmmc0_cmd>;
+	status = "okay";
+};
+
+&uart2 {
+	status = "okay";
+};
board/rockchip/evb_rk3568/MAINTAINERS +7 -0
index cc9eb432a8b5..fa8d1190931d 100644
@@ -7,6 +7,13 @@ F:	configs/evb-rk3568_defconfig
  F:	arch/arm/dts/rk3568-evb-u-boot.dtsi
  F:	arch/arm/dts/rk3568-evb.dts
 
+GENERIC-RK3568
+M:	Jonas Karlman <[email protected]>
+S:	Maintained
+F:	configs/generic-rk3568_defconfig
+F:	arch/arm/dts/rk3568-generic.dts
+F:	arch/arm/dts/rk3568-generic-u-boot.dtsi
+
  LUBANCAT-2
  M:	Andy Yan <[email protected]>
  S:	Maintained
configs/generic-rk3568_defconfig new file +64 -0
new file mode 100644
index 000000000000..8f0a9c8c449f
@@ -0,0 +1,64 @@
+CONFIG_ARM=y
+CONFIG_SKIP_LOWLEVEL_INIT=y
+CONFIG_COUNTER_FREQUENCY=24000000
+CONFIG_ARCH_ROCKCHIP=y
+CONFIG_TEXT_BASE=0x00a00000
+CONFIG_SPL_LIBCOMMON_SUPPORT=y
+CONFIG_SPL_LIBGENERIC_SUPPORT=y
+CONFIG_NR_DRAM_BANKS=2
+CONFIG_HAS_CUSTOM_SYS_INIT_SP_ADDR=y
+CONFIG_CUSTOM_SYS_INIT_SP_ADDR=0xc00000
+CONFIG_DEFAULT_DEVICE_TREE="rk3568-generic"
+CONFIG_ROCKCHIP_RK3568=y
+CONFIG_SPL_ROCKCHIP_COMMON_BOARD=y
+CONFIG_SPL_SERIAL=y
+CONFIG_SPL_STACK_R_ADDR=0x600000
+CONFIG_SPL_STACK=0x400000
+CONFIG_DEBUG_UART_BASE=0xFE660000
+CONFIG_DEBUG_UART_CLOCK=24000000
+CONFIG_SYS_LOAD_ADDR=0xc00800
+CONFIG_DEBUG_UART=y
+CONFIG_FIT=y
+CONFIG_FIT_VERBOSE=y
+CONFIG_SPL_FIT_SIGNATURE=y
+CONFIG_SPL_LOAD_FIT=y
+CONFIG_LEGACY_IMAGE_FORMAT=y
+CONFIG_DEFAULT_FDT_FILE="rockchip/rk3568-generic.dtb"
+# CONFIG_DISPLAY_CPUINFO is not set
+CONFIG_DISPLAY_BOARDINFO_LATE=y
+CONFIG_SPL_MAX_SIZE=0x40000
+CONFIG_SPL_PAD_TO=0x7f8000
+CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
+CONFIG_SPL_BSS_START_ADDR=0x4000000
+CONFIG_SPL_BSS_MAX_SIZE=0x4000
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
+CONFIG_SPL_STACK_R=y
+CONFIG_SPL_ATF=y
+CONFIG_CMD_GPIO=y
+CONFIG_CMD_GPT=y
+CONFIG_CMD_MMC=y
+# CONFIG_CMD_SETEXPR is not set
+# CONFIG_SPL_DOS_PARTITION is not set
+CONFIG_SPL_OF_CONTROL=y
+CONFIG_OF_LIVE=y
+CONFIG_OF_SPL_REMOVE_PROPS="pinctrl-0 pinctrl-names clock-names interrupt-parent assigned-clocks assigned-clock-rates assigned-clock-parents"
+CONFIG_SPL_DM_SEQ_ALIAS=y
+CONFIG_SPL_REGMAP=y
+CONFIG_SPL_SYSCON=y
+CONFIG_SPL_CLK=y
+CONFIG_ROCKCHIP_GPIO=y
+CONFIG_MISC=y
+# CONFIG_ROCKCHIP_IODOMAIN is not set
+CONFIG_SUPPORT_EMMC_RPMB=y
+CONFIG_MMC_DW=y
+CONFIG_MMC_DW_ROCKCHIP=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_SDMA=y
+CONFIG_MMC_SDHCI_ROCKCHIP=y
+CONFIG_SPL_RAM=y
+CONFIG_BAUDRATE=1500000
+CONFIG_DEBUG_UART_SHIFT=2
+CONFIG_SYS_NS16550_MEM32=y
+CONFIG_SYSRESET=y
+CONFIG_ERRNO_STR=y
doc/board/rockchip/rockchip.rst +1 -0
index de9fe8e642b1..183a9e4aa699 100644
@@ -104,6 +104,7 @@ List of mainline supported Rockchip boards:
       - EmbedFire LubanCat 2 (lubancat-2-rk3568)
       - FriendlyElec NanoPi R5C (nanopi-r5c-rk3568)
       - FriendlyElec NanoPi R5S (nanopi-r5s-rk3568)
+     - Generic RK3566/RK3568 (generic-rk3568)
       - Hardkernel ODROID-M1 (odroid-m1-rk3568)
       - Radxa E25 Carrier Board (radxa-e25-rk3568)
       - Radxa ROCK 3 Model A (rock-3a-rk3568)