Skip to contentSkip to conversation

rockchip: Fix PCIe and NVMe support on RK3568

PATCH Superseded Jonas Karlman 2 participants 20 messages Apr 22, 2023 – May 9, 2023

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover rockchip: Fix PCIe and NVMe support on RK3568

This series fixes and enables PCIe and NVMe support on RK3568. It depends on prior series by Eugen Hristev, [1] and [2] that adds PCIe support on RK3588 and also [3] that add basic reference counting to gpio regulators.

Patch 1-2 fixes main issue in the driver to be usable on RK3568. Patch 3 fixes a long wait time during probe when no device is attached. Patch 4 hides BARs of the root complex that could claim the entire memory region during PCI autoconfig.
Patch 5 adds support for the gpios prop to the fixed regulators driver. Patch 6 adds a missing clock to the clock driver.
Patch 7 enables PCIe and NVMe support on rk3568-rock-3a. Patch 8 updates the device tree with new reg and ranges values.

For a clean apply of patch 7, the series at [4] may be needed.

I have tested that a Samsung 970 EVO NVMe is detected on a ROCK 3A,

  BusDevFun  VendorId   DeviceId   Device Class       Sub-Class
  01.00.00   0x1d87     0x3566     Bridge device           0x04
  02.00.00   0x144d     0xa808     Mass storage controller 0x08

and I have also verified that the network controller continues to be detected on a ROCK 5B.

  BusDevFun  VendorId   DeviceId   Device Class       Sub-Class
  00.00.00   0x1d87     0x3588     Bridge device           0x04
  01.00.00   0x10ec     0x8125     Network controller      0x00

This series can also be found at [5].

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[3] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[4] https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
[5] https://github.com/Kwiboo/u-boot-rockchip/commits/rk3568-pcie-v1

Jonas Karlman (8):
pci: pcie_dw_rockchip: Get config region from reg prop
pci: pcie_dw_rockchip: Use regulator_set_enable_if_allowed
pci: pcie_dw_rockchip: Speed up link probe
pci: pcie_dw_rockchip: Hide BARs of the root complex
regulator: fixed: Add support for gpios prop
rockchip: clk: clk_rk3568: Add CLK_PCIEPHY2_REF support
rockchip: rk3568-rock-3a: Enable PCIe and NVMe support
rockchip: rk356x: Update PCIe config, IO and memory regions

 arch/arm/dts/rk3568-rock-3a-u-boot.dtsi |  14 +++
 arch/arm/dts/rk3568.dtsi                |  14 +--
 arch/arm/dts/rk356x.dtsi                |   7 +-
 configs/rock-3a-rk3568_defconfig        |   4 +
 drivers/clk/rockchip/clk_rk3568.c       |   1 +
 drivers/pci/pcie_dw_common.c            |  10 +-
 drivers/pci/pcie_dw_rockchip.c          | 128 +++++++++++++++---------
 drivers/power/regulator/fixed.c         |   5 +-
 8 files changed, 123 insertions(+), 60 deletions(-)
Signature · 1 line
2.40.0
#1 lore raw

PATCH 1/8 pci: pcie_dw_rockchip: Get config region from reg prop

Get the config region to use from the reg prop. Also check the return value from dev_read_addr_index correctly. And update the referenced region index used in comment.

---
 drivers/pci/pcie_dw_common.c   | 10 ++++++----
 drivers/pci/pcie_dw_rockchip.c | 15 +++++++++++----
 2 files changed, 17 insertions(+), 8 deletions(-)
drivers/pci/pcie_dw_common.c +6 -4
index 9f8b016d1149..74fb6df412c7 100644
@@ -141,9 +141,9 @@ static uintptr_t set_cfg_address(struct pcie_dw *pcie,
 
 	/*
 	 * Not accessing root port configuration space?
-	 * Region #0 is used for Outbound CFG space access.
+	 * Region #1 is used for Outbound CFG space access.
 	 * Direction = Outbound
-	 * Region Index = 0
+	 * Region Index = 1
 	 */
 	d = PCI_MASK_BUS(d);
 	d = PCI_ADD_BUS(bus, d);
@@ -328,8 +328,10 @@ void pcie_dw_setup_host(struct pcie_dw *pci)
 			pci->prefetch.bus_start = hose->regions[ret].bus_start;  /* PREFETCH_bus_addr */
 			pci->prefetch.size = hose->regions[ret].size;	    /* PREFETCH size */
 		} else if (hose->regions[ret].flags == PCI_REGION_SYS_MEMORY) {
-			pci->cfg_base = (void *)(pci->io.phys_start - pci->io.size);
-			pci->cfg_size = pci->io.size;
+			if (!pci->cfg_base) {
+				pci->cfg_base = (void *)(pci->io.phys_start - pci->io.size);
+				pci->cfg_size = pci->io.size;
+			}
 		} else {
 			dev_err(pci->dev, "invalid flags type!\n");
 		}
drivers/pci/pcie_dw_rockchip.c +11 -4
index 60c74bea24b2..225af400ba70 100644
@@ -355,17 +355,24 @@ static int rockchip_pcie_parse_dt(struct udevice *dev)
 	int ret;
 
 	priv->dw.dbi_base = (void *)dev_read_addr_index(dev, 0);
-	if (!priv->dw.dbi_base)
-		return -ENODEV;
+	if ((fdt_addr_t)priv->dw.dbi_base == FDT_ADDR_T_NONE)
+		return -EINVAL;
 
 	dev_dbg(dev, "DBI address is 0x%p\n", priv->dw.dbi_base);
 
 	priv->apb_base = (void *)dev_read_addr_index(dev, 1);
-	if (!priv->apb_base)
-		return -ENODEV;
+	if ((fdt_addr_t)priv->apb_base == FDT_ADDR_T_NONE)
+		return -EINVAL;
 
 	dev_dbg(dev, "APB address is 0x%p\n", priv->apb_base);
 
+	priv->dw.cfg_base =
+		(void *)dev_read_addr_size_index(dev, 2, &priv->dw.cfg_size);
+	if ((fdt_addr_t)priv->dw.cfg_base == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	dev_dbg(dev, "CFG address is 0x%p\n", priv->dw.cfg_base);
+
 	ret = gpio_request_by_name(dev, "reset-gpios", 0,
 				   &priv->rst_gpio, GPIOD_IS_OUT);
 	if (ret) {
Signature · 1 line
2.40.0
Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] pci: pcie_dw_rockchip: Get config region from reg prop

Quoted 5 lines · Jonas Karlman

Get the config region to use from the reg prop. Also check the return value from dev_read_addr_index correctly. And update the referenced region index used in comment.

Thanks,
- Kever

Quoted 67 lines
---
  drivers/pci/pcie_dw_common.c   | 10 ++++++----
  drivers/pci/pcie_dw_rockchip.c | 15 +++++++++++----
  2 files changed, 17 insertions(+), 8 deletions(-)
drivers/pci/pcie_dw_common.c +6 -4
index 9f8b016d1149..74fb6df412c7 100644
@@ -141,9 +141,9 @@ static uintptr_t set_cfg_address(struct pcie_dw *pcie,
 
  	/*
  	 * Not accessing root port configuration space?
-	 * Region #0 is used for Outbound CFG space access.
+	 * Region #1 is used for Outbound CFG space access.
  	 * Direction = Outbound
-	 * Region Index = 0
+	 * Region Index = 1
  	 */
  	d = PCI_MASK_BUS(d);
  	d = PCI_ADD_BUS(bus, d);
@@ -328,8 +328,10 @@ void pcie_dw_setup_host(struct pcie_dw *pci)
  			pci->prefetch.bus_start = hose->regions[ret].bus_start;  /* PREFETCH_bus_addr */
  			pci->prefetch.size = hose->regions[ret].size;	    /* PREFETCH size */
  		} else if (hose->regions[ret].flags == PCI_REGION_SYS_MEMORY) {
-			pci->cfg_base = (void *)(pci->io.phys_start - pci->io.size);
-			pci->cfg_size = pci->io.size;
+			if (!pci->cfg_base) {
+				pci->cfg_base = (void *)(pci->io.phys_start - pci->io.size);
+				pci->cfg_size = pci->io.size;
+			}
  		} else {
  			dev_err(pci->dev, "invalid flags type!\n");
  		}
drivers/pci/pcie_dw_rockchip.c +11 -4
index 60c74bea24b2..225af400ba70 100644
@@ -355,17 +355,24 @@ static int rockchip_pcie_parse_dt(struct udevice *dev)
  	int ret;
 
  	priv->dw.dbi_base = (void *)dev_read_addr_index(dev, 0);
-	if (!priv->dw.dbi_base)
-		return -ENODEV;
+	if ((fdt_addr_t)priv->dw.dbi_base == FDT_ADDR_T_NONE)
+		return -EINVAL;
 
  	dev_dbg(dev, "DBI address is 0x%p\n", priv->dw.dbi_base);
 
  	priv->apb_base = (void *)dev_read_addr_index(dev, 1);
-	if (!priv->apb_base)
-		return -ENODEV;
+	if ((fdt_addr_t)priv->apb_base == FDT_ADDR_T_NONE)
+		return -EINVAL;
 
  	dev_dbg(dev, "APB address is 0x%p\n", priv->apb_base);
 
+	priv->dw.cfg_base =
+		(void *)dev_read_addr_size_index(dev, 2, &priv->dw.cfg_size);
+	if ((fdt_addr_t)priv->dw.cfg_base == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	dev_dbg(dev, "CFG address is 0x%p\n", priv->dw.cfg_base);
+
  	ret = gpio_request_by_name(dev, "reset-gpios", 0,
  				   &priv->rst_gpio, GPIOD_IS_OUT);
  	if (ret) {
#3 lore raw

PATCH 2/8 pci: pcie_dw_rockchip: Use regulator_set_enable_if_allowed

In reply to Jonas Karlman

The vpcie3v3 regulator is typically a fixed regulator controlled using gpio. Change to use enable and disable calls on the regulator instead of trying to set a voltage value.

---
 drivers/pci/pcie_dw_rockchip.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/pci/pcie_dw_rockchip.c +7 -10
index 225af400ba70..a5b900f95981 100644
@@ -288,21 +288,16 @@ static int rockchip_pcie_init_port(struct udevice *dev)
 	struct rk_pcie *priv = dev_get_priv(dev);
 
 	/* Set power and maybe external ref clk input */
-	if (priv->vpcie3v3) {
-		ret = regulator_set_value(priv->vpcie3v3, 3300000);
-		if (ret) {
-			dev_err(priv->dw.dev, "failed to enable vpcie3v3 (ret=%d)\n",
-				ret);
-			return ret;
-		}
+	ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
+	if (ret && ret != -ENOSYS) {
+		dev_err(dev, "failed to enable vpcie3v3 (ret=%d)\n", ret);
+		return ret;
 	}
 
-	udelay(MACRO_US * 1000);
-
 	ret = generic_phy_init(&priv->phy);
 	if (ret) {
 		dev_err(dev, "failed to init phy (ret=%d)\n", ret);
-		return ret;
+		goto err_disable_regulator;
 	}
 
 	ret = generic_phy_power_on(&priv->phy);
@@ -345,6 +340,8 @@ err_power_off_phy:
 	generic_phy_power_off(&priv->phy);
 err_exit_phy:
 	generic_phy_exit(&priv->phy);
+err_disable_regulator:
+	regulator_set_enable_if_allowed(priv->vpcie3v3, false);
 
 	return ret;
 }
Signature · 1 line
2.40.0
#4 lore raw

Re: [PATCH 2/8] pci: pcie_dw_rockchip: Use regulator_set_enable_if_allowed

Hi Jonas,

Quoted 21 lines · Jonas Karlman

The vpcie3v3 regulator is typically a fixed regulator controlled using gpio. Change to use enable and disable calls on the regulator instead of trying to set a voltage value.

---
  drivers/pci/pcie_dw_rockchip.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)
drivers/pci/pcie_dw_rockchip.c +0 -4
index 225af400ba70..a5b900f95981 100644
@@ -288,21 +288,16 @@ static int rockchip_pcie_init_port(struct udevice *dev)
  	struct rk_pcie *priv = dev_get_priv(dev);
 
  	/* Set power and maybe external ref clk input */
-	if (priv->vpcie3v3) {
-		ret = regulator_set_value(priv->vpcie3v3, 3300000);
-		if (ret) {
-			dev_err(priv->dw.dev, "failed to enable vpcie3v3 (ret=%d)\n",

drivers/pci/pcie_dw_rockchip.c static int rockchip_pcie_init_port(struct udevice *dev) · line 300

Quoted 10 lines
drivers/pci/pcie_dw_rockchip.c +4 -4
-				ret);
-			return ret;
-		}
+	ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
+	if (ret && ret != -ENOSYS) {
+		dev_err(dev, "failed to enable vpcie3v3 (ret=%d)\n", ret);
+		return ret;
  	}
 
-	udelay(MACRO_US * 1000);

Why remove this udelay?

This may help the power stable before we can access pcie phy.

Thanks,

- Kever

Quoted 18 lines
drivers/pci/pcie_dw_rockchip.c +3 -2
-
  	ret = generic_phy_init(&priv->phy);
  	if (ret) {
  		dev_err(dev, "failed to init phy (ret=%d)\n", ret);
-		return ret;
+		goto err_disable_regulator;
  	}
 
  	ret = generic_phy_power_on(&priv->phy);
@@ -345,6 +340,8 @@ err_power_off_phy:
  	generic_phy_power_off(&priv->phy);
  err_exit_phy:
  	generic_phy_exit(&priv->phy);
+err_disable_regulator:
+	regulator_set_enable_if_allowed(priv->vpcie3v3, false);
 
  	return ret;
  }
#5 lore raw

Re: [PATCH 2/8] pci: pcie_dw_rockchip: Use regulator_set_enable_if_allowed

Hi Kever,

Quoted 33 lines · Kever Yang

Hi Jonas,

Quoted 30 lines · Jonas Karlman

The vpcie3v3 regulator is typically a fixed regulator controlled using gpio. Change to use enable and disable calls on the regulator instead of trying to set a voltage value.

---
  drivers/pci/pcie_dw_rockchip.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)
drivers/pci/pcie_dw_rockchip.c +4 -7
index 225af400ba70..a5b900f95981 100644
@@ -288,21 +288,16 @@ static int rockchip_pcie_init_port(struct udevice *dev)
  	struct rk_pcie *priv = dev_get_priv(dev);
 
  	/* Set power and maybe external ref clk input */
-	if (priv->vpcie3v3) {
-		ret = regulator_set_value(priv->vpcie3v3, 3300000);
-		if (ret) {
-			dev_err(priv->dw.dev, "failed to enable vpcie3v3 (ret=%d)\n",
-				ret);
-			return ret;
-		}
+	ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
+	if (ret && ret != -ENOSYS) {
+		dev_err(dev, "failed to enable vpcie3v3 (ret=%d)\n", ret);
+		return ret;
  	}
 
Quoted 5 lines

drivers/pci/pcie_dw_rockchip.c static int rockchip_pcie_init_port(struct udevice *dev) · line 300

Quoted 1 line
drivers/pci/pcie_dw_rockchip.c +0 -1
-	udelay(MACRO_US * 1000);

Why remove this udelay?

This may help the power stable before we can access pcie phy.

I removed this to closer match the linux driver, if a delay is needed it can be added using e.g. the startup-delay-us prop of a fixed regulator.

startup-delay-us:
description: startup time in microseconds

Based on testing on Rock 3A, CM3, Quartz64, SoQuartz, Odroid-M1 and Rock 5B a delay using startup-delay-us did not seem necessary.

Regards,
Jonas

Quoted 23 lines

Thanks,

- Kever

Quoted 18 lines
drivers/pci/pcie_dw_rockchip.c +3 -2
-
  	ret = generic_phy_init(&priv->phy);
  	if (ret) {
  		dev_err(dev, "failed to init phy (ret=%d)\n", ret);
-		return ret;
+		goto err_disable_regulator;
  	}
 
  	ret = generic_phy_power_on(&priv->phy);
@@ -345,6 +340,8 @@ err_power_off_phy:
  	generic_phy_power_off(&priv->phy);
  err_exit_phy:
  	generic_phy_exit(&priv->phy);
+err_disable_regulator:
+	regulator_set_enable_if_allowed(priv->vpcie3v3, false);
 
  	return ret;
  }
#6 lore raw

PATCH 3/8 pci: pcie_dw_rockchip: Speed up link probe

In reply to Jonas Karlman

Use a similar pattern and delay values as the linux mainline driver to speed up failing when nothing is connected.

Reduce fail speed from around 5+ seconds down to around one second on a Radxa ROCK 3 Model A, where pcie2x1 is probed before pcie3x2 M2 slot.

---
 drivers/pci/pcie_dw_rockchip.c | 68 ++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 31 deletions(-)
drivers/pci/pcie_dw_rockchip.c +37 -31
index a5b900f95981..fd3da47272b3 100644
@@ -61,9 +61,6 @@ struct rk_pcie {
 #define PCIE_CLIENT_DBG_TRANSITION_DATA	0xffff0000
 #define PCIE_CLIENT_DBF_EN		0xffff0003
 
-/* Parameters for the waiting for #perst signal */
-#define MACRO_US			1000
-
 static int rk_pcie_read(void __iomem *addr, int size, u32 *val)
 {
 	if ((uintptr_t)addr & (size - 1)) {
@@ -242,43 +239,46 @@ static int rk_pcie_link_up(struct rk_pcie *priv, u32 cap_speed)
 	/* DW pre link configurations */
 	rk_pcie_configure(priv, cap_speed);
 
-	/* Rest the device */
-	if (dm_gpio_is_valid(&priv->rst_gpio)) {
-		dm_gpio_set_value(&priv->rst_gpio, 0);
-		/*
-		 * Minimal is 100ms from spec but we see
-		 * some wired devices need much more, such as 600ms.
-		 * Add a enough delay to cover all cases.
-		 */
-		udelay(MACRO_US * 1000);
-		dm_gpio_set_value(&priv->rst_gpio, 1);
-	}
-
 	rk_pcie_disable_ltssm(priv);
 	rk_pcie_link_status_clear(priv);
 	rk_pcie_enable_debug(priv);
 
+	/* Reset the device */
+	if (dm_gpio_is_valid(&priv->rst_gpio))
+		dm_gpio_set_value(&priv->rst_gpio, 0);
+
 	/* Enable LTSSM */
 	rk_pcie_enable_ltssm(priv);
 
-	for (retries = 0; retries < 5; retries++) {
-		if (is_link_up(priv)) {
-			dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
-				 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
-			rk_pcie_debug_dump(priv);
-			return 0;
-		}
-
-		dev_info(priv->dw.dev, "PCIe Linking... LTSSM is 0x%x\n",
-			 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
-		rk_pcie_debug_dump(priv);
-		udelay(MACRO_US * 1000);
+	/*
+	 * PCIe requires the refclk to be stable for 100ms prior to releasing
+	 * PERST. See table 2-4 in section 2.6.2 AC Specifications of the PCI
+	 * Express Card Electromechanical Specification, 1.1. However, we don't
+	 * know if the refclk is coming from RC's PHY or external OSC. If it's
+	 * from RC, so enabling LTSSM is the just right place to release #PERST.
+	 */
+	mdelay(100);
+	if (dm_gpio_is_valid(&priv->rst_gpio))
+		dm_gpio_set_value(&priv->rst_gpio, 1);
+
+	/* Check if the link is up or not */
+	for (retries = 0; retries < 10; retries++) {
+		if (is_link_up(priv))
+			break;
+
+		mdelay(100);
+	}
+
+	if (retries >= 10) {
+		dev_err(priv->dw.dev, "PCIe-%d Link Fail\n",
+			dev_seq(priv->dw.dev));
+		return -EIO;
 	}
 
-	dev_err(priv->dw.dev, "PCIe-%d Link Fail\n", dev_seq(priv->dw.dev));
-	/* Link maybe in Gen switch recovery but we need to wait more 1s */
-	udelay(MACRO_US * 1000);
-	return -EIO;
+	dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
+		 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
+	rk_pcie_debug_dump(priv);
+	return 0;
 }
 
 static int rockchip_pcie_init_port(struct udevice *dev)
@@ -287,6 +287,12 @@ static int rockchip_pcie_init_port(struct udevice *dev)
 	u32 val;
 	struct rk_pcie *priv = dev_get_priv(dev);
 
+	ret = reset_assert_bulk(&priv->rsts);
+	if (ret) {
+		dev_err(dev, "failed to assert resets (ret=%d)\n", ret);
+		return ret;
+	}
+
 	/* Set power and maybe external ref clk input */
 	ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
 	if (ret && ret != -ENOSYS) {
Signature · 1 line
2.40.0
#7 lore raw

Re: [PATCH 3/8] pci: pcie_dw_rockchip: Speed up link probe

Hi Jonas,

Quoted 28 lines · Jonas Karlman

Use a similar pattern and delay values as the linux mainline driver to speed up failing when nothing is connected.

Reduce fail speed from around 5+ seconds down to around one second on a Radxa ROCK 3 Model A, where pcie2x1 is probed before pcie3x2 M2 slot.

---
  drivers/pci/pcie_dw_rockchip.c | 68 ++++++++++++++++++----------------
  1 file changed, 37 insertions(+), 31 deletions(-)
drivers/pci/pcie_dw_rockchip.c +0 -3
index a5b900f95981..fd3da47272b3 100644
@@ -61,9 +61,6 @@ struct rk_pcie {
  #define PCIE_CLIENT_DBG_TRANSITION_DATA	0xffff0000
  #define PCIE_CLIENT_DBF_EN		0xffff0003
 
-/* Parameters for the waiting for #perst signal */
-#define MACRO_US			1000
-
  static int rk_pcie_read(void __iomem *addr, int size, u32 *val)
  {
  	if ((uintptr_t)addr & (size - 1)) {
@@ -242,43 +239,46 @@ static int rk_pcie_link_up(struct rk_pcie *priv, u32 cap_speed)
  	/* DW pre link configurations */
  	rk_pcie_configure(priv, cap_speed);

drivers/pci/pcie_dw_rockchip.c static int rk_pcie_link_up(struct rk_pcie *priv, u32 cap_speed) · line 253

Quoted 10 lines
drivers/pci/pcie_dw_rockchip.c +0 -9
 
-	/* Rest the device */
-	if (dm_gpio_is_valid(&priv->rst_gpio)) {
-		dm_gpio_set_value(&priv->rst_gpio, 0);
-		/*
-		 * Minimal is 100ms from spec but we see
-		 * some wired devices need much more, such as 600ms.
-		 * Add a enough delay to cover all cases.
-		 */
-		udelay(MACRO_US * 1000);

This delay has been changed.

Quoted 24 lines
drivers/pci/pcie_dw_rockchip.c +4 -13
-		dm_gpio_set_value(&priv->rst_gpio, 1);
-	}
-
  	rk_pcie_disable_ltssm(priv);
  	rk_pcie_link_status_clear(priv);
  	rk_pcie_enable_debug(priv);
 
+	/* Reset the device */
+	if (dm_gpio_is_valid(&priv->rst_gpio))
+		dm_gpio_set_value(&priv->rst_gpio, 0);
+
  	/* Enable LTSSM */
  	rk_pcie_enable_ltssm(priv);
 
-	for (retries = 0; retries < 5; retries++) {
-		if (is_link_up(priv)) {
-			dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
-				 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
-			rk_pcie_debug_dump(priv);
-			return 0;
-		}
-
-		dev_info(priv->dw.dev, "PCIe Linking... LTSSM is 0x%x\n",
-			 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));

drivers/pci/pcie_dw_rockchip.c static int rk_pcie_link_up(struct rk_pcie *priv, u32 cap_speed) · line 260

Quoted 10 lines
drivers/pci/pcie_dw_rockchip.c +8 -2
-		rk_pcie_debug_dump(priv);
-		udelay(MACRO_US * 1000);
+	/*
+	 * PCIe requires the refclk to be stable for 100ms prior to releasing
+	 * PERST. See table 2-4 in section 2.6.2 AC Specifications of the PCI
+	 * Express Card Electromechanical Specification, 1.1. However, we don't
+	 * know if the refclk is coming from RC's PHY or external OSC. If it's
+	 * from RC, so enabling LTSSM is the just right place to release #PERST.
+	 */
+	mdelay(100);

There is a common about this delay, the spec is 100ms, but some device on the public market

may not work with this delay, it's better to keep previous delay value.

Thanks,

- Kever

Quoted 41 lines
drivers/pci/pcie_dw_rockchip.c +25 -4
+	if (dm_gpio_is_valid(&priv->rst_gpio))
+		dm_gpio_set_value(&priv->rst_gpio, 1);
+
+	/* Check if the link is up or not */
+	for (retries = 0; retries < 10; retries++) {
+		if (is_link_up(priv))
+			break;
+
+		mdelay(100);
+	}
+
+	if (retries >= 10) {
+		dev_err(priv->dw.dev, "PCIe-%d Link Fail\n",
+			dev_seq(priv->dw.dev));
+		return -EIO;
  	}
 
-	dev_err(priv->dw.dev, "PCIe-%d Link Fail\n", dev_seq(priv->dw.dev));
-	/* Link maybe in Gen switch recovery but we need to wait more 1s */
-	udelay(MACRO_US * 1000);
-	return -EIO;
+	dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
+		 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
+	rk_pcie_debug_dump(priv);
+	return 0;
  }
 
  static int rockchip_pcie_init_port(struct udevice *dev)
@@ -287,6 +287,12 @@ static int rockchip_pcie_init_port(struct udevice *dev)
  	u32 val;
  	struct rk_pcie *priv = dev_get_priv(dev);
 
+	ret = reset_assert_bulk(&priv->rsts);
+	if (ret) {
+		dev_err(dev, "failed to assert resets (ret=%d)\n", ret);
+		return ret;
+	}
+
  	/* Set power and maybe external ref clk input */
  	ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
  	if (ret && ret != -ENOSYS) {
#8 lore raw

Re: [PATCH 3/8] pci: pcie_dw_rockchip: Speed up link probe

Hi Kever,

Quoted 82 lines · Kever Yang

Hi Jonas,

Quoted 28 lines · Jonas Karlman

Use a similar pattern and delay values as the linux mainline driver to speed up failing when nothing is connected.

Reduce fail speed from around 5+ seconds down to around one second on a Radxa ROCK 3 Model A, where pcie2x1 is probed before pcie3x2 M2 slot.

---
  drivers/pci/pcie_dw_rockchip.c | 68 ++++++++++++++++++----------------
  1 file changed, 37 insertions(+), 31 deletions(-)
drivers/pci/pcie_dw_rockchip.c +0 -3
index a5b900f95981..fd3da47272b3 100644
@@ -61,9 +61,6 @@ struct rk_pcie {
  #define PCIE_CLIENT_DBG_TRANSITION_DATA	0xffff0000
  #define PCIE_CLIENT_DBF_EN		0xffff0003
 
-/* Parameters for the waiting for #perst signal */
-#define MACRO_US			1000
-
  static int rk_pcie_read(void __iomem *addr, int size, u32 *val)
  {
  	if ((uintptr_t)addr & (size - 1)) {
@@ -242,43 +239,46 @@ static int rk_pcie_link_up(struct rk_pcie *priv, u32 cap_speed)
  	/* DW pre link configurations */
  	rk_pcie_configure(priv, cap_speed);

drivers/pci/pcie_dw_rockchip.c static int rk_pcie_link_up(struct rk_pcie *priv, u32 cap_speed) · line 253

Quoted 10 lines
drivers/pci/pcie_dw_rockchip.c +0 -9
 
-	/* Rest the device */
-	if (dm_gpio_is_valid(&priv->rst_gpio)) {
-		dm_gpio_set_value(&priv->rst_gpio, 0);
-		/*
-		 * Minimal is 100ms from spec but we see
-		 * some wired devices need much more, such as 600ms.
-		 * Add a enough delay to cover all cases.
-		 */
-		udelay(MACRO_US * 1000);

This delay has been changed.

Quoted 24 lines
drivers/pci/pcie_dw_rockchip.c +4 -13
-		dm_gpio_set_value(&priv->rst_gpio, 1);
-	}
-
  	rk_pcie_disable_ltssm(priv);
  	rk_pcie_link_status_clear(priv);
  	rk_pcie_enable_debug(priv);
 
+	/* Reset the device */
+	if (dm_gpio_is_valid(&priv->rst_gpio))
+		dm_gpio_set_value(&priv->rst_gpio, 0);
+
  	/* Enable LTSSM */
  	rk_pcie_enable_ltssm(priv);
 
-	for (retries = 0; retries < 5; retries++) {
-		if (is_link_up(priv)) {
-			dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
-				 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
-			rk_pcie_debug_dump(priv);
-			return 0;
-		}
-
-		dev_info(priv->dw.dev, "PCIe Linking... LTSSM is 0x%x\n",
-			 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));

drivers/pci/pcie_dw_rockchip.c static int rk_pcie_link_up(struct rk_pcie *priv, u32 cap_speed) · line 260

Quoted 10 lines
drivers/pci/pcie_dw_rockchip.c +8 -2
-		rk_pcie_debug_dump(priv);
-		udelay(MACRO_US * 1000);
+	/*
+	 * PCIe requires the refclk to be stable for 100ms prior to releasing
+	 * PERST. See table 2-4 in section 2.6.2 AC Specifications of the PCI
+	 * Express Card Electromechanical Specification, 1.1. However, we don't
+	 * know if the refclk is coming from RC's PHY or external OSC. If it's
+	 * from RC, so enabling LTSSM is the just right place to release #PERST.
+	 */
+	mdelay(100);

There is a common about this delay, the spec is 100ms, but some device on the public market

Quoted 1 line

may not work with this delay, it's better to keep previous delay value.

The old delays are very excessive and do not seem to be necessary, they have also been changed in vendor u-boot in e.g. following commit:

https://github.com/rockchip-linux/u-boot/commit/92d3587863d327e3b48e0eaf5c37db8e7f614b36

Instead, I copied the config/reset order and same delay values used by the linux driver and it seem to work much better after these changes.

Does anybody know what devices was having issues that the old comment was referring to? The devices I was able to test did not see any issue.

Regards,
Jonas

Quoted 47 lines

Thanks,

- Kever

Quoted 41 lines
drivers/pci/pcie_dw_rockchip.c +25 -4
+	if (dm_gpio_is_valid(&priv->rst_gpio))
+		dm_gpio_set_value(&priv->rst_gpio, 1);
+
+	/* Check if the link is up or not */
+	for (retries = 0; retries < 10; retries++) {
+		if (is_link_up(priv))
+			break;
+
+		mdelay(100);
+	}
+
+	if (retries >= 10) {
+		dev_err(priv->dw.dev, "PCIe-%d Link Fail\n",
+			dev_seq(priv->dw.dev));
+		return -EIO;
  	}
 
-	dev_err(priv->dw.dev, "PCIe-%d Link Fail\n", dev_seq(priv->dw.dev));
-	/* Link maybe in Gen switch recovery but we need to wait more 1s */
-	udelay(MACRO_US * 1000);
-	return -EIO;
+	dev_info(priv->dw.dev, "PCIe Link up, LTSSM is 0x%x\n",
+		 rk_pcie_readl_apb(priv, PCIE_CLIENT_LTSSM_STATUS));
+	rk_pcie_debug_dump(priv);
+	return 0;
  }
 
  static int rockchip_pcie_init_port(struct udevice *dev)
@@ -287,6 +287,12 @@ static int rockchip_pcie_init_port(struct udevice *dev)
  	u32 val;
  	struct rk_pcie *priv = dev_get_priv(dev);
 
+	ret = reset_assert_bulk(&priv->rsts);
+	if (ret) {
+		dev_err(dev, "failed to assert resets (ret=%d)\n", ret);
+		return ret;
+	}
+
  	/* Set power and maybe external ref clk input */
  	ret = regulator_set_enable_if_allowed(priv->vpcie3v3, true);
  	if (ret && ret != -ENOSYS) {
#9 lore raw

PATCH 4/8 pci: pcie_dw_rockchip: Hide BARs of the root complex

In reply to Jonas Karlman

PCI Autoconfig read the Root Complex BARs and try to claim the entire 1 GiB memory region on RK3568, leaving no space for any attached device.

Return an invalid value during config read of Root Complex BARs during autoconfig to work around such issue.

---
 drivers/pci/pcie_dw_rockchip.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/pci/pcie_dw_rockchip.c +27 -1
index fd3da47272b3..924ecb93e963 100644
@@ -146,6 +146,32 @@ static inline void rk_pcie_writel_apb(struct rk_pcie *rk_pcie, u32 reg,
 	__rk_pcie_write_apb(rk_pcie, rk_pcie->apb_base, reg, 0x4, val);
 }
 
+/**
+ * The BARs of bridge should be hidden during enumeration to avoid
+ * allocation of the entire memory region by PCIe core on RK3568.
+ */
+static bool rk_pcie_hide_rc_bar(struct pcie_dw *pcie, pci_dev_t bdf,
+				uint offset)
+{
+	int bus = PCI_BUS(bdf) - pcie->first_busno;
+
+	return bus == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	       offset >= PCI_BASE_ADDRESS_0 && offset <= PCI_BASE_ADDRESS_1;
+}
+
+static int rk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
+			       uint offset, ulong *valuep,
+			       enum pci_size_t size)
+{
+	struct pcie_dw *pcie = dev_get_priv(bus);
+	int ret = pcie_dw_read_config(bus, bdf, offset, valuep, size);
+
+	if (!ret && rk_pcie_hide_rc_bar(pcie, bdf, offset))
+		*valuep = pci_get_ff(size);
+
+	return ret;
+}
+
 /**
  * rk_pcie_configure() - Configure link capabilities and speed
  *
@@ -476,7 +502,7 @@ rockchip_pcie_probe_err_init_port:
 }
 
 static const struct dm_pci_ops rockchip_pcie_ops = {
-	.read_config	= pcie_dw_read_config,
+	.read_config	= rk_pcie_read_config,
 	.write_config	= pcie_dw_write_config,
 };
 
Signature · 1 line
2.40.0
#10 lore raw

Re: [PATCH 4/8] pci: pcie_dw_rockchip: Hide BARs of the root complex

Hi Jonas,

Quoted 5 lines · Jonas Karlman

PCI Autoconfig read the Root Complex BARs and try to claim the entire 1 GiB memory region on RK3568, leaving no space for any attached device.

Return an invalid value during config read of Root Complex BARs during autoconfig to work around such issue.

Could you share the error message without this workaround?

I think the driver can works without this patch, the 1GiB memory BAR will assigned fail

and has no affect to BAR allocate for attached device.

Thanks,

- Kever

Quoted 52 lines
---
  drivers/pci/pcie_dw_rockchip.c | 28 +++++++++++++++++++++++++++-
  1 file changed, 27 insertions(+), 1 deletion(-)
drivers/pci/pcie_dw_rockchip.c +27 -1
index fd3da47272b3..924ecb93e963 100644
@@ -146,6 +146,32 @@ static inline void rk_pcie_writel_apb(struct rk_pcie *rk_pcie, u32 reg,
  	__rk_pcie_write_apb(rk_pcie, rk_pcie->apb_base, reg, 0x4, val);
  }
 
+/**
+ * The BARs of bridge should be hidden during enumeration to avoid
+ * allocation of the entire memory region by PCIe core on RK3568.
+ */
+static bool rk_pcie_hide_rc_bar(struct pcie_dw *pcie, pci_dev_t bdf,
+				uint offset)
+{
+	int bus = PCI_BUS(bdf) - pcie->first_busno;
+
+	return bus == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	       offset >= PCI_BASE_ADDRESS_0 && offset <= PCI_BASE_ADDRESS_1;
+}
+
+static int rk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
+			       uint offset, ulong *valuep,
+			       enum pci_size_t size)
+{
+	struct pcie_dw *pcie = dev_get_priv(bus);
+	int ret = pcie_dw_read_config(bus, bdf, offset, valuep, size);
+
+	if (!ret && rk_pcie_hide_rc_bar(pcie, bdf, offset))
+		*valuep = pci_get_ff(size);
+
+	return ret;
+}
+
  /**
   * rk_pcie_configure() - Configure link capabilities and speed
   *
@@ -476,7 +502,7 @@ rockchip_pcie_probe_err_init_port:
  }
 
  static const struct dm_pci_ops rockchip_pcie_ops = {
-	.read_config	= pcie_dw_read_config,
+	.read_config	= rk_pcie_read_config,
  	.write_config	= pcie_dw_write_config,
  };
 
#11 lore raw

Re: [PATCH 4/8] pci: pcie_dw_rockchip: Hide BARs of the root complex

Hi Kever,

Quoted 9 lines · Kever Yang

Hi Jonas,

Quoted 5 lines · Jonas Karlman

PCI Autoconfig read the Root Complex BARs and try to claim the entire 1 GiB memory region on RK3568, leaving no space for any attached device.

Return an invalid value during config read of Root Complex BARs during autoconfig to work around such issue.

Quoted 7 lines

Could you share the error message without this workaround?

I think the driver can works without this patch, the 1GiB memory BAR will assigned fail

and has no affect to BAR allocate for attached device.

Both BAR0 and BAR1 of the Root Complex on RK3568 report that it wants 1 GiB allocations (value=c0000000). On RK3588 the Root Complex BARs was entirely skipped (value=0).

The 1 GiB memory BAR assignment used to fail when a 0x0-0x3fffffff pci range was used, because u-boot would skip initial 4 KiB and instead use 0x1000-0x3fffffff as the pci range.

https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/pci/pci_auto_common.c#L28

With the change to use a 0x40000000-0x7fffffff pci range, the first 1 GiB allocation instead succeed and consume the entire usable range, leaving allocation for BAR1 of the Root Complex and BARs for any attached devices to fail.

I did not find any hw reg that could be used to control the returned value for the BAR0/1 or the Root Complex, value c0000000 was always read back.

With this change to mask BAR0 and BAR1 for Root Complex on RK3568, the entire pci range is available for BARs of any attached device.

Regards,
Jonas

Quoted 57 lines

Thanks,

- Kever

Quoted 52 lines
---
  drivers/pci/pcie_dw_rockchip.c | 28 +++++++++++++++++++++++++++-
  1 file changed, 27 insertions(+), 1 deletion(-)
drivers/pci/pcie_dw_rockchip.c +27 -1
index fd3da47272b3..924ecb93e963 100644
@@ -146,6 +146,32 @@ static inline void rk_pcie_writel_apb(struct rk_pcie *rk_pcie, u32 reg,
  	__rk_pcie_write_apb(rk_pcie, rk_pcie->apb_base, reg, 0x4, val);
  }
 
+/**
+ * The BARs of bridge should be hidden during enumeration to avoid
+ * allocation of the entire memory region by PCIe core on RK3568.
+ */
+static bool rk_pcie_hide_rc_bar(struct pcie_dw *pcie, pci_dev_t bdf,
+				uint offset)
+{
+	int bus = PCI_BUS(bdf) - pcie->first_busno;
+
+	return bus == 0 && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+	       offset >= PCI_BASE_ADDRESS_0 && offset <= PCI_BASE_ADDRESS_1;
+}
+
+static int rk_pcie_read_config(const struct udevice *bus, pci_dev_t bdf,
+			       uint offset, ulong *valuep,
+			       enum pci_size_t size)
+{
+	struct pcie_dw *pcie = dev_get_priv(bus);
+	int ret = pcie_dw_read_config(bus, bdf, offset, valuep, size);
+
+	if (!ret && rk_pcie_hide_rc_bar(pcie, bdf, offset))
+		*valuep = pci_get_ff(size);
+
+	return ret;
+}
+
  /**
   * rk_pcie_configure() - Configure link capabilities and speed
   *
@@ -476,7 +502,7 @@ rockchip_pcie_probe_err_init_port:
  }
 
  static const struct dm_pci_ops rockchip_pcie_ops = {
-	.read_config	= pcie_dw_read_config,
+	.read_config	= rk_pcie_read_config,
  	.write_config	= pcie_dw_write_config,
  };
 
#12 lore raw

PATCH 5/8 regulator: fixed: Add support for gpios prop

In reply to Jonas Karlman

The commit 12df2c182ccb ("regulator: dt-bindings: fixed-regulator: allow gpios property") in linux v6.3-rc1 added support for use of either a gpios or gpio prop with a fixed-regulator.

This adds support for the new gpios prop to the fixed-regulator driver.

---
 drivers/power/regulator/fixed.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/regulator/fixed.c +4 -1
index ad3b4b98d667..fcfb467a46e3 100644
@@ -25,6 +25,7 @@ static int fixed_regulator_of_to_plat(struct udevice *dev)
 {
 	struct dm_regulator_uclass_plat *uc_pdata;
 	struct regulator_common_plat *plat;
+	bool gpios;
 
 	plat = dev_get_plat(dev);
 	uc_pdata = dev_get_uclass_plat(dev);
@@ -33,7 +34,9 @@ static int fixed_regulator_of_to_plat(struct udevice *dev)
 
 	uc_pdata->type = REGULATOR_TYPE_FIXED;
 
-	return regulator_common_of_to_plat(dev, plat, "gpio");
+	gpios = dev_read_bool(dev, "gpios");
+	return regulator_common_of_to_plat(dev, plat,
+					   gpios ? "gpios" : "gpio");
 }
 
 static int fixed_regulator_get_value(struct udevice *dev)
Signature · 1 line
2.40.0
Reviewed-by on v1 5/8
#13 lore raw

Re: [PATCH 5/8] regulator: fixed: Add support for gpios prop

Quoted 7 lines · Jonas Karlman

The commit 12df2c182ccb ("regulator: dt-bindings: fixed-regulator: allow gpios property") in linux v6.3-rc1 added support for use of either a gpios or gpio prop with a fixed-regulator.

This adds support for the new gpios prop to the fixed-regulator driver.

Thanks,
- Kever

Quoted 27 lines
---
  drivers/power/regulator/fixed.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/power/regulator/fixed.c +4 -1
index ad3b4b98d667..fcfb467a46e3 100644
@@ -25,6 +25,7 @@ static int fixed_regulator_of_to_plat(struct udevice *dev)
  {
  	struct dm_regulator_uclass_plat *uc_pdata;
  	struct regulator_common_plat *plat;
+	bool gpios;
 
  	plat = dev_get_plat(dev);
  	uc_pdata = dev_get_uclass_plat(dev);
@@ -33,7 +34,9 @@ static int fixed_regulator_of_to_plat(struct udevice *dev)
 
  	uc_pdata->type = REGULATOR_TYPE_FIXED;
 
-	return regulator_common_of_to_plat(dev, plat, "gpio");
+	gpios = dev_read_bool(dev, "gpios");
+	return regulator_common_of_to_plat(dev, plat,
+					   gpios ? "gpios" : "gpio");
  }
 
  static int fixed_regulator_get_value(struct udevice *dev)
#14 lore raw

PATCH 6/8 rockchip: clk: clk_rk3568: Add CLK_PCIEPHY2_REF support

In reply to Jonas Karlman

Add dummy support for the CLK_PCIEPHY2_REF clock.

---
 drivers/clk/rockchip/clk_rk3568.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clk/rockchip/clk_rk3568.c +1 -0
index cefc263971a6..c8e688789e4c 100644
@@ -427,6 +427,7 @@ static ulong rk3568_pmuclk_set_rate(struct clk *clk, ulong rate)
 		break;
 	case CLK_PCIEPHY0_REF:
 	case CLK_PCIEPHY1_REF:
+	case CLK_PCIEPHY2_REF:
 		return 0;
 	default:
 		return -ENOENT;
Signature · 1 line
2.40.0
Reviewed-by on v1 6/8
#15 lore raw

Re: [PATCH 6/8] rockchip: clk: clk_rk3568: Add CLK_PCIEPHY2_REF support

Quoted 3 lines · Jonas Karlman

Add dummy support for the CLK_PCIEPHY2_REF clock.

Thanks,
- Kever

Quoted 16 lines
---
  drivers/clk/rockchip/clk_rk3568.c | 1 +
  1 file changed, 1 insertion(+)
drivers/clk/rockchip/clk_rk3568.c +1 -0
index cefc263971a6..c8e688789e4c 100644
@@ -427,6 +427,7 @@ static ulong rk3568_pmuclk_set_rate(struct clk *clk, ulong rate)
  		break;
  	case CLK_PCIEPHY0_REF:
  	case CLK_PCIEPHY1_REF:
+	case CLK_PCIEPHY2_REF:
  		return 0;
  	default:
  		return -ENOENT;
#16 lore raw

PATCH 7/8 rockchip: rk3568-rock-3a: Enable PCIe and NVMe support

In reply to Jonas Karlman

Add missing pinctrl and defconfig options to enable PCIe and NVMe support on Radxa ROCK 3 Model A.

---
 arch/arm/dts/rk3568-rock-3a-u-boot.dtsi | 14 ++++++++++++++
 configs/rock-3a-rk3568_defconfig        |  4 ++++
 2 files changed, 18 insertions(+)
arch/arm/dts/rk3568-rock-3a-u-boot.dtsi +14 -0
index 8abee24c02c3..f3ee50949cc0 100644
@@ -19,6 +19,12 @@
 
 &pinctrl {
 	bootph-pre-ram;
+
+	pcie {
+		pcie3x2_reset_h: pcie3x2-reset-h {
+			rockchip,pins = <2 RK_PD6 RK_FUNC_GPIO &pcfg_pull_none>;
+		};
+	};
 };
 
 &pcfg_pull_up {
@@ -73,6 +79,14 @@
 	bootph-pre-ram;
 };
 
+&pcie2x1 {
+	pinctrl-0 = <&pcie20m1_pins &pcie_reset_h>;
+};
+
+&pcie3x2 {
+	pinctrl-0 = <&pcie30x2m1_pins &pcie3x2_reset_h>;
+};
+
 &sfc {
 	bootph-pre-ram;
 	u-boot,spl-sfc-no-dma;
configs/rock-3a-rk3568_defconfig +4 -0
index 64864a300153..9d725b82a96a 100644
@@ -46,6 +46,7 @@ CONFIG_CMD_GPIO=y
 CONFIG_CMD_GPT=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
 # CONFIG_CMD_SETEXPR is not set
 CONFIG_CMD_PMIC=y
@@ -70,6 +71,9 @@ CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_SPI_FLASH_XTX=y
 CONFIG_ETH_DESIGNWARE=y
 CONFIG_GMAC_ROCKCHIP=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_PCIE_DW_ROCKCHIP=y
 CONFIG_PHY_ROCKCHIP_INNO_USB2=y
 CONFIG_PHY_ROCKCHIP_NANENG_COMBOPHY=y
 CONFIG_SPL_PINCTRL=y
Signature · 1 line
2.40.0
#17 lore raw

Re: [PATCH 7/8] rockchip: rk3568-rock-3a: Enable PCIe and NVMe support

Hi Jonas,

Quoted 27 lines · Jonas Karlman

Add missing pinctrl and defconfig options to enable PCIe and NVMe support on Radxa ROCK 3 Model A.

---
  arch/arm/dts/rk3568-rock-3a-u-boot.dtsi | 14 ++++++++++++++
  configs/rock-3a-rk3568_defconfig        |  4 ++++
  2 files changed, 18 insertions(+)
arch/arm/dts/rk3568-rock-3a-u-boot.dtsi +6 -0
index 8abee24c02c3..f3ee50949cc0 100644
@@ -19,6 +19,12 @@
 
  &pinctrl {
  	bootph-pre-ram;
+
+	pcie {
+		pcie3x2_reset_h: pcie3x2-reset-h {
+			rockchip,pins = <2 RK_PD6 RK_FUNC_GPIO &pcfg_pull_none>;
+		};
+	};
  };
 
  &pcfg_pull_up {

arch/arm/dts/rk3568-rock-3a-u-boot.dtsi line 88

Quoted 10 lines
arch/arm/dts/rk3568-rock-3a-u-boot.dtsi +7 -0
@@ -73,6 +79,14 @@
  	bootph-pre-ram;
  };
 
+&pcie2x1 {
+	pinctrl-0 = <&pcie20m1_pins &pcie_reset_h>;
+};
+
+&pcie3x2 {
+	pinctrl-0 = <&pcie30x2m1_pins &pcie3x2_reset_h>;
+};

    Did you really met issue without this patch?

    The pcie using GPIO for reset and other function instead of pcie function, and these GPIOs's default

setting is GPIO, so they should work by default.

Thanks,

- Kever

Quoted 26 lines
arch/arm/dts/rk3568-rock-3a-u-boot.dtsi +1 -0
+
  &sfc {
  	bootph-pre-ram;
  	u-boot,spl-sfc-no-dma;
configs/rock-3a-rk3568_defconfig +4 -0
index 64864a300153..9d725b82a96a 100644
@@ -46,6 +46,7 @@ CONFIG_CMD_GPIO=y
  CONFIG_CMD_GPT=y
  CONFIG_CMD_I2C=y
  CONFIG_CMD_MMC=y
+CONFIG_CMD_PCI=y
  CONFIG_CMD_USB=y
  # CONFIG_CMD_SETEXPR is not set
  CONFIG_CMD_PMIC=y
@@ -70,6 +71,9 @@ CONFIG_SPI_FLASH_MACRONIX=y
  CONFIG_SPI_FLASH_XTX=y
  CONFIG_ETH_DESIGNWARE=y
  CONFIG_GMAC_ROCKCHIP=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_PCIE_DW_ROCKCHIP=y
  CONFIG_PHY_ROCKCHIP_INNO_USB2=y
  CONFIG_PHY_ROCKCHIP_NANENG_COMBOPHY=y
  CONFIG_SPL_PINCTRL=y
#18 lore raw

PATCH 8/8 rockchip: rk356x: Update PCIe config, IO and memory regions

In reply to Jonas Karlman

Update config, IO and memory regions used based on [1] with pcie3x2 config reg size corrected from 16 to 1 MiB.

[1] https://lore.kernel.org/lkml/[email protected]/

---
 arch/arm/dts/rk3568.dtsi | 14 ++++++++------
 arch/arm/dts/rk356x.dtsi |  7 ++++---
 2 files changed, 12 insertions(+), 9 deletions(-)
arch/arm/dts/rk3568.dtsi +8 -6
index ba67b58f05b7..f1be76a54ceb 100644
@@ -94,9 +94,10 @@
 		power-domains = <&power RK3568_PD_PIPE>;
 		reg = <0x3 0xc0400000 0x0 0x00400000>,
 		      <0x0 0xfe270000 0x0 0x00010000>,
-		      <0x3 0x7f000000 0x0 0x01000000>;
-		ranges = <0x01000000 0x0 0x3ef00000 0x3 0x7ef00000 0x0 0x00100000>,
-			 <0x02000000 0x0 0x00000000 0x3 0x40000000 0x0 0x3ef00000>;
+		      <0x0 0xf2000000 0x0 0x00100000>;
+		ranges = <0x01000000 0x0 0xf2100000 0x0 0xf2100000 0x0 0x00100000>,
+			 <0x02000000 0x0 0xf2200000 0x0 0xf2200000 0x0 0x01e00000>,
+			 <0x03000000 0x0 0x40000000 0x3 0x40000000 0x0 0x40000000>;
 		reg-names = "dbi", "apb", "config";
 		resets = <&cru SRST_PCIE30X1_POWERUP>;
 		reset-names = "pipe";
@@ -146,9 +147,10 @@
 		power-domains = <&power RK3568_PD_PIPE>;
 		reg = <0x3 0xc0800000 0x0 0x00400000>,
 		      <0x0 0xfe280000 0x0 0x00010000>,
-		      <0x3 0xbf000000 0x0 0x01000000>;
-		ranges = <0x01000000 0x0 0x3ef00000 0x3 0xbef00000 0x0 0x00100000>,
-			 <0x02000000 0x0 0x00000000 0x3 0x80000000 0x0 0x3ef00000>;
+		      <0x0 0xf0000000 0x0 0x00100000>;
+		ranges = <0x01000000 0x0 0xf0100000 0x0 0xf0100000 0x0 0x00100000>,
+			 <0x02000000 0x0 0xf0200000 0x0 0xf0200000 0x0 0x01e00000>,
+			 <0x03000000 0x0 0x40000000 0x3 0x80000000 0x0 0x40000000>;
 		reg-names = "dbi", "apb", "config";
 		resets = <&cru SRST_PCIE30X2_POWERUP>;
 		reset-names = "pipe";
arch/arm/dts/rk356x.dtsi +4 -3
index 6492ace0de6b..e0591c194bec 100644
@@ -951,7 +951,7 @@
 		compatible = "rockchip,rk3568-pcie";
 		reg = <0x3 0xc0000000 0x0 0x00400000>,
 		      <0x0 0xfe260000 0x0 0x00010000>,
-		      <0x3 0x3f000000 0x0 0x01000000>;
+		      <0x0 0xf4000000 0x0 0x00100000>;
 		reg-names = "dbi", "apb", "config";
 		interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
 			     <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>,
@@ -980,8 +980,9 @@
 		phys = <&combphy2 PHY_TYPE_PCIE>;
 		phy-names = "pcie-phy";
 		power-domains = <&power RK3568_PD_PIPE>;
-		ranges = <0x01000000 0x0 0x3ef00000 0x3 0x3ef00000 0x0 0x00100000
-			  0x02000000 0x0 0x00000000 0x3 0x00000000 0x0 0x3ef00000>;
+		ranges = <0x01000000 0x0 0xf4100000 0x0 0xf4100000 0x0 0x00100000>,
+			 <0x02000000 0x0 0xf4200000 0x0 0xf4200000 0x0 0x01e00000>,
+			 <0x03000000 0x0 0x40000000 0x3 0x00000000 0x0 0x40000000>;
 		resets = <&cru SRST_PCIE20_POWERUP>;
 		reset-names = "pipe";
 		#address-cells = <3>;
Signature · 1 line
2.40.0
Reviewed-by on v1 8/8
#19 lore raw

Re: [PATCH 8/8] rockchip: rk356x: Update PCIe config, IO and memory regions

Quoted 6 lines · Jonas Karlman

Update config, IO and memory regions used based on [1] with pcie3x2 config reg size corrected from 16 to 1 MiB.

[1] https://lore.kernel.org/lkml/[email protected]/

Thanks,
- Kever

Quoted 62 lines
---
  arch/arm/dts/rk3568.dtsi | 14 ++++++++------
  arch/arm/dts/rk356x.dtsi |  7 ++++---
  2 files changed, 12 insertions(+), 9 deletions(-)
arch/arm/dts/rk3568.dtsi +8 -6
index ba67b58f05b7..f1be76a54ceb 100644
@@ -94,9 +94,10 @@
  		power-domains = <&power RK3568_PD_PIPE>;
  		reg = <0x3 0xc0400000 0x0 0x00400000>,
  		      <0x0 0xfe270000 0x0 0x00010000>,
-		      <0x3 0x7f000000 0x0 0x01000000>;
-		ranges = <0x01000000 0x0 0x3ef00000 0x3 0x7ef00000 0x0 0x00100000>,
-			 <0x02000000 0x0 0x00000000 0x3 0x40000000 0x0 0x3ef00000>;
+		      <0x0 0xf2000000 0x0 0x00100000>;
+		ranges = <0x01000000 0x0 0xf2100000 0x0 0xf2100000 0x0 0x00100000>,
+			 <0x02000000 0x0 0xf2200000 0x0 0xf2200000 0x0 0x01e00000>,
+			 <0x03000000 0x0 0x40000000 0x3 0x40000000 0x0 0x40000000>;
  		reg-names = "dbi", "apb", "config";
  		resets = <&cru SRST_PCIE30X1_POWERUP>;
  		reset-names = "pipe";
@@ -146,9 +147,10 @@
  		power-domains = <&power RK3568_PD_PIPE>;
  		reg = <0x3 0xc0800000 0x0 0x00400000>,
  		      <0x0 0xfe280000 0x0 0x00010000>,
-		      <0x3 0xbf000000 0x0 0x01000000>;
-		ranges = <0x01000000 0x0 0x3ef00000 0x3 0xbef00000 0x0 0x00100000>,
-			 <0x02000000 0x0 0x00000000 0x3 0x80000000 0x0 0x3ef00000>;
+		      <0x0 0xf0000000 0x0 0x00100000>;
+		ranges = <0x01000000 0x0 0xf0100000 0x0 0xf0100000 0x0 0x00100000>,
+			 <0x02000000 0x0 0xf0200000 0x0 0xf0200000 0x0 0x01e00000>,
+			 <0x03000000 0x0 0x40000000 0x3 0x80000000 0x0 0x40000000>;
  		reg-names = "dbi", "apb", "config";
  		resets = <&cru SRST_PCIE30X2_POWERUP>;
  		reset-names = "pipe";
arch/arm/dts/rk356x.dtsi +4 -3
index 6492ace0de6b..e0591c194bec 100644
@@ -951,7 +951,7 @@
  		compatible = "rockchip,rk3568-pcie";
  		reg = <0x3 0xc0000000 0x0 0x00400000>,
  		      <0x0 0xfe260000 0x0 0x00010000>,
-		      <0x3 0x3f000000 0x0 0x01000000>;
+		      <0x0 0xf4000000 0x0 0x00100000>;
  		reg-names = "dbi", "apb", "config";
  		interrupts = <GIC_SPI 75 IRQ_TYPE_LEVEL_HIGH>,
  			     <GIC_SPI 74 IRQ_TYPE_LEVEL_HIGH>,
@@ -980,8 +980,9 @@
  		phys = <&combphy2 PHY_TYPE_PCIE>;
  		phy-names = "pcie-phy";
  		power-domains = <&power RK3568_PD_PIPE>;
-		ranges = <0x01000000 0x0 0x3ef00000 0x3 0x3ef00000 0x0 0x00100000
-			  0x02000000 0x0 0x00000000 0x3 0x00000000 0x0 0x3ef00000>;
+		ranges = <0x01000000 0x0 0xf4100000 0x0 0xf4100000 0x0 0x00100000>,
+			 <0x02000000 0x0 0xf4200000 0x0 0xf4200000 0x0 0x01e00000>,
+			 <0x03000000 0x0 0x40000000 0x3 0x00000000 0x0 0x40000000>;
  		resets = <&cru SRST_PCIE20_POWERUP>;
  		reset-names = "pipe";
  		#address-cells = <3>;