回复: [PATCH 2/4] board: add support for Milk-V Mars CM

2024-05-06 Thread Minda Chen


> 
> On 30.04.24 11:59, E Shattow wrote:
> > On Tue, Apr 30, 2024 at 12:18 AM Heinrich Schuchardt
> >  wrote:
> >>
> >> On 30.04.24 00:46, E Shattow wrote:
> >>> On Sun, Apr 28, 2024 at 9:13 AM Emil Renner Berthing
> >>>  wrote:
> 
>  Heinrich Schuchardt wrote:
> > We already support the VisionFive 2 and the Milk-V Mars board by
> > patching the VisionFive 2 device tree. With this patch the same is
> > done for the Milk-V Mars CM.
> 
>  Hi Heinrich.
> 
>  Thanks for the patch. As far as I can tell the Milk-V
>  documentation[1] is pretty consistent in calling the version without eMMC
> "Milk-V Mars CM Lite"
>  and the version with eMMC just "Milk-V Mars CM". So I'd prefer the
>  model, compatible and filenames suggested below.
> 
>  [1]:
>  https://milkv.io/docs/mars/compute-module/introduction#design-philo
>  sophy
> 
> >>>
> >>> Are there any actual differences that need representation in the dtb
> >>> file for downstream OS different from Milk-V Mars to Milk-V Mars CM
> >>> (or CM Lite)?
> >>>
> >>> I did find this vendor repo commit "kernel: dts reconfig sdio0 for
> >>> SDCard version"
> >>> https://github.com/milkv-mars/mars-buildroot-sdk/commit/042ea0659899
> >>> 5db99dd252ee439c42b9c1a9 but it does not seem necessary in
> >>> mainline Linux, SD Card is working without changes.
> >>>
> >>> It was necessary for U-Boot and the Mars CM Lite with SD Card to
> >>> apply s/GPIO62/GPIO22/ as in the vendor commit "u-boot: configure
> >>> sdio0 as mars-cm sdcard version"
> >>> https://github.com/milkv-mars/mars-buildroot-sdk/commit/880a249518f7
> >>> 2ecf1e2947dfeb2c66e5035fce90
> >>
> >> This is what is patched in fdt_fixup_marc().
> >
> > That's the Mars fixup with a conditional for the s/GPIO62/GPIO22/ of
> > CM Lite;  which Linux seems not to mind either way so long as this was
> > done at the U-Boot phase, it is functional for eMMC/SD mmc access with
> > unmodified visionfive2 1.3b dtb (GPIO62 pinmux) from Linux.
> >
> > It is not clear to me why in vendor U-Boot this is s/GPIO62/GPIO22/
> > but in vendor Linux kernel this is s/GPIO62/GPIO24/ ? It seems not
> > needed (in Linux).
> 
> According to the schematics GPIO22 is connected to SD_PWR_ON on the the
> low speed connector both on the Mars CM and the Mars CM Lite. GPIO62 is
> connected to SDMMC_RST_N on the eMMC. Both the SD-card and the eMMC
> are connected to SDI0. This is why only one of them can be usable.
> 
> GPIO024 is used for the MIPI camera interface.
> 
> I guess unless you reset the SD-card or eMMC GPIO062 and GPI022 are not used
> and this is why Linux is working in both configurations.
> 
> >
> >>
> >>>
> >>> Then also there is some mention about PMIC and renamed i2c
> >>> reference, already obsolete. That's all, is there more to it?
> >>> Possibly a dtb for Mars is enough to also be used on Mars CM and Mars 
> >>> Lite?
> >>
> >> Looking at the schematics the biggest difference between the Mars and
> >> the Mars CM (Lite) is on the USB side. The Mars board has USB 3.0 via
> >> a PCIe lane and a VIA VL805/806 while the Mars CM has USB directly
> >> via the SoC.
> >>
> >> To add USB support for the Mars CM we will need an adapted device-tree.
> >
> > Mars also needs this direct-to-SoC USB support, as its USB ports are a
> > mix of VL805 and directly via the SoC. This can be the same for Mars
> > and Mars CM/Lite.
> 
> The schematics say:
> 
> "One USB Controller only, supports either USB 2.0 or USB 3.0."
> 
> This sounds to me like you cannot have both in functional state.
> 
> Maybe Minda or Hal know more?
> 
> Best regards
> 
> Heinrich
> 
usb 3.0 PHY and PCIe0 using the same PHY. (2 PCIe + USB 2.0 or 1PCIe + USB 
3.0/2.0)
Now I have upstreamed the usb controller driver.

> >
> > See this photo from
> > https://milkv.io/docs/mars/getting-started/bootloader what highlights
> > this direct SoC USB port of Milk-V Mars:
> > https://milkv.io/assets/images/mars-usb-port-a-b48fe1ff1003539d42bf5e1
> > dde1725a3.jpg
> >
> > The over-current errata
> > https://doc-en.rvspace.org/VisionFive2/DG_USB/JH7110_SDK/usb_overcurre
> > nt_debug.html suggests "please modify the above settings during the
> > U-Boot phase".
> >
> > -E
> >
> >>
> >> Best regards
> >>
> >> Heinrich
> >>>
> > Signed-off-by: Heinrich Schuchardt
> > 
> > ---
> >board/starfive/visionfive2/spl.c  | 27
> ++-
> >.../visionfive2/starfive_visionfive2.c| 11 +++-
> >2 files changed, 36 insertions(+), 2 deletions(-)
> >
> > diff --git a/board/starfive/visionfive2/spl.c
> > b/board/starfive/visionfive2/spl.c
> > index 45848db6d8b..bb0f28d7aad 100644
> > --- a/board/starfive/visionfive2/spl.c
> > +++ b/board/starfive/visionfive2/spl.c
> > @@ -129,6 +129,29 @@ void spl_fdt_fixup_mars(void *fdt)
> > }
> >}
> >
> > +void spl_fdt_fixup_marc(void *fdt) {
> > + const char *compat;
> 

[PATCH v1 7/7] MAINTAINERS: Update Starfive visionfive2 maintain files.

2024-05-04 Thread Minda Chen
Add USB related files to Starfive visionfive2 MAINTAINERS.

Signed-off-by: Minda Chen 
---
 board/starfive/visionfive2/MAINTAINERS | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/board/starfive/visionfive2/MAINTAINERS 
b/board/starfive/visionfive2/MAINTAINERS
index d7f638f9b4..1faf83f581 100644
--- a/board/starfive/visionfive2/MAINTAINERS
+++ b/board/starfive/visionfive2/MAINTAINERS
@@ -6,3 +6,5 @@ F:  board/starfive/visionfive2/
 F: include/configs/starfive-visionfive2.h
 F: configs/starfive_visionfive2_defconfig
 F: drivers/pci/pcie_starfive_jh7110.c
+F: drivers/phy/starfive/
+F: drivers/usb/cdns3/cdns3-starfive.c
-- 
2.17.1



[PATCH v1 6/7] dts: starfive: Add JH7110 Cadence USB dts node

2024-05-04 Thread Minda Chen
Add Jh7110 Cadence USB dts node, Visionfive2 default setting
is USB 2.0 device.

Signed-off-by: Minda Chen 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi |  5 ++
 arch/riscv/dts/jh7110.dtsi| 52 +++
 2 files changed, 57 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index e11babc1cd..44785bbee3 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -378,3 +378,8 @@
};
};
 };
+
+_cdns3 {
+   dr_mode = "peripheral";
+   status = "okay";
+};
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index 2cdc683d49..1eee924e1d 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -371,6 +371,58 @@
status = "disabled";
};
 
+   usb0: usb@1010 {
+   compatible = "starfive,jh7110-usb";
+   ranges = <0x0 0x0 0x1010 0x10>;
+   #address-cells = <1>;
+   #size-cells = <1>;
+   starfive,stg-syscon = <_syscon 0x4>;
+   clocks = < JH7110_STGCLK_USB_LPM>,
+< JH7110_STGCLK_USB_STB>,
+< JH7110_STGCLK_USB_APB>,
+< JH7110_STGCLK_USB_AXI>,
+< JH7110_STGCLK_USB_UTMI_APB>;
+   clock-names = "lpm", "stb", "apb", "axi", "utmi_apb";
+   resets = < JH7110_STGRST_USB_PWRUP>,
+< JH7110_STGRST_USB_APB>,
+< JH7110_STGRST_USB_AXI>,
+< JH7110_STGRST_USB_UTMI_APB>;
+   reset-names = "pwrup", "apb", "axi", "utmi_apb";
+
+   usb_cdns3: usb@0 {
+   compatible = "cdns,usb3";
+   reg = <0x0 0x1>,
+ <0x1 0x1>,
+ <0x2 0x1>;
+   reg-names = "otg", "xhci", "dev";
+   interrupts = <100>, <108>, <110>;
+   interrupt-names = "host", "peripheral", "otg";
+   phys = <>;
+   phy-names = "cdns3,usb2-phy";
+   };
+   };
+
+   usbphy0: phy@1020 {
+   compatible = "starfive,jh7110-usb-phy";
+   reg = <0x0 0x1020 0x0 0x1>;
+   clocks = < JH7110_SYSCLK_USB_125M>,
+< JH7110_STGCLK_USB_APP_125>;
+   clock-names = "125m", "app_125m";
+   #phy-cells = <0>;
+   };
+
+   pciephy0: phy@1021 {
+   compatible = "starfive,jh7110-pcie-phy";
+   reg = <0x0 0x1021 0x0 0x1>;
+   #phy-cells = <0>;
+   };
+
+   pciephy1: phy@1022 {
+   compatible = "starfive,jh7110-pcie-phy";
+   reg = <0x0 0x1022 0x0 0x1>;
+   #phy-cells = <0>;
+   };
+
stgcrg: clock-controller@1023 {
compatible = "starfive,jh7110-stgcrg";
reg = <0x0 0x1023 0x0 0x1>;
-- 
2.17.1



[PATCH v1 5/7] configs: starfive: Add visionfive2 cadence USB configuration

2024-05-04 Thread Minda Chen
Add cadence USB confiuration.

Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 3bbd1dbd67..444ddd508d 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -68,6 +68,7 @@ CONFIG_SYS_EEPROM_SIZE=512
 CONFIG_SYS_EEPROM_PAGE_WRITE_BITS=4
 CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=5
 CONFIG_CMD_MEMINFO=y
+# CONFIG_CMD_BIND is not set
 CONFIG_CMD_I2C=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_USB=y
@@ -111,6 +112,8 @@ CONFIG_NVME_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PCIE_STARFIVE_JH7110=y
+CONFIG_PHY_STARFIVE_JH7110_PCIE=y
+CONFIG_PHY_STARFIVE_JH7110_USB2=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
@@ -126,13 +129,19 @@ CONFIG_CADENCE_QSPI=y
 CONFIG_SYSRESET=y
 CONFIG_TIMER_EARLY=y
 CONFIG_USB=y
+CONFIG_DM_USB_GADGET=y
 CONFIG_USB_XHCI_HCD=y
 CONFIG_USB_XHCI_PCI=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_PCI=y
 CONFIG_USB_OHCI_HCD=y
 CONFIG_USB_OHCI_PCI=y
+CONFIG_USB_CDNS3=y
+CONFIG_USB_CDNS3_GADGET=y
+CONFIG_USB_CDNS3_HOST=y
+# CONFIG_USB_CDNS3_TI is not set
 CONFIG_USB_KEYBOARD=y
+CONFIG_USB_GADGET=y
 # CONFIG_WATCHDOG is not set
 # CONFIG_WATCHDOG_AUTOSTART is not set
 CONFIG_WDT=y
-- 
2.17.1



[PATCH v1 4/7] usb: cdns: starfive: Add cdns USB driver

2024-05-04 Thread Minda Chen
Add cdns USB3 wrapper driver.

Signed-off-by: Minda Chen 
---
 drivers/usb/cdns3/Kconfig  |   7 ++
 drivers/usb/cdns3/Makefile |   2 +
 drivers/usb/cdns3/cdns3-starfive.c | 184 +
 3 files changed, 193 insertions(+)
 create mode 100644 drivers/usb/cdns3/cdns3-starfive.c

diff --git a/drivers/usb/cdns3/Kconfig b/drivers/usb/cdns3/Kconfig
index 35b61497d9..f8f363982b 100644
--- a/drivers/usb/cdns3/Kconfig
+++ b/drivers/usb/cdns3/Kconfig
@@ -55,4 +55,11 @@ config USB_CDNS3_TI
help
  Say 'Y' here if you are building for Texas Instruments
  platforms that contain Cadence USB3 controller core. E.g.: J721e.
+
+config USB_CDNS3_STARFIVE
+   tristate "Cadence USB3 support on Starfive platforms"
+   default USB_CDNS3
+   help
+ Say 'Y' here if you are building for Starfive platforms
+ that contain Cadence USB3 controller core. E.g.: JH7110.
 endif
diff --git a/drivers/usb/cdns3/Makefile b/drivers/usb/cdns3/Makefile
index 18d7190755..03d1eadb2f 100644
--- a/drivers/usb/cdns3/Makefile
+++ b/drivers/usb/cdns3/Makefile
@@ -9,3 +9,5 @@ cdns3-$(CONFIG_$(SPL_)USB_CDNS3_GADGET) += gadget.o ep0.o
 cdns3-$(CONFIG_$(SPL_)USB_CDNS3_HOST)  += host.o
 
 obj-$(CONFIG_USB_CDNS3_TI) += cdns3-ti.o
+
+obj-$(CONFIG_USB_CDNS3_STARFIVE)   += cdns3-starfive.o
diff --git a/drivers/usb/cdns3/cdns3-starfive.c 
b/drivers/usb/cdns3/cdns3-starfive.c
new file mode 100644
index 00..efda47e2a5
--- /dev/null
+++ b/drivers/usb/cdns3/cdns3-starfive.c
@@ -0,0 +1,184 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * cdns3-starfive.c - StarFive specific Glue layer for Cadence USB Controller
+ *
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ *
+ * Author: Minda Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+
+#define USB_STRAP_HOST BIT(17)
+#define USB_STRAP_DEVICE   BIT(18)
+#define USB_STRAP_MASK GENMASK(18, 16)
+
+#define USB_SUSPENDM_HOST  BIT(19)
+#define USB_SUSPENDM_MASK  BIT(19)
+
+#define USB_MISC_CFG_MASK  GENMASK(23, 20)
+#define USB_SUSPENDM_BYPS  BIT(20)
+#define USB_PLL_EN BIT(22)
+#define USB_REFCLK_MODEBIT(23)
+
+struct cdns_starfive {
+   struct udevice *dev;
+   struct regmap *stg_syscon;
+   struct reset_ctl_bulk resets;
+   struct clk_bulk clks;
+   u32 stg_usb_mode;
+   enum usb_dr_mode mode;
+};
+
+static void cdns_mode_init(struct cdns_starfive *data, enum usb_dr_mode mode)
+{
+   regmap_update_bits(data->stg_syscon, data->stg_usb_mode,
+  USB_MISC_CFG_MASK,
+  USB_SUSPENDM_BYPS | USB_PLL_EN | USB_REFCLK_MODE);
+
+   switch (mode) {
+   case USB_DR_MODE_HOST:
+   regmap_update_bits(data->stg_syscon,
+  data->stg_usb_mode,
+  USB_STRAP_MASK,
+  USB_STRAP_HOST);
+   regmap_update_bits(data->stg_syscon,
+  data->stg_usb_mode,
+  USB_SUSPENDM_MASK,
+  USB_SUSPENDM_HOST);
+   break;
+
+   case USB_DR_MODE_PERIPHERAL:
+   regmap_update_bits(data->stg_syscon, data->stg_usb_mode,
+  USB_STRAP_MASK, USB_STRAP_DEVICE);
+   regmap_update_bits(data->stg_syscon, data->stg_usb_mode,
+  USB_SUSPENDM_MASK, 0);
+   break;
+   default:
+   break;
+   }
+}
+
+static void cdns_clk_rst_deinit(struct cdns_starfive *data)
+{
+   reset_assert_bulk(>resets);
+   clk_disable_bulk(>clks);
+}
+
+static int cdns_clk_rst_init(struct cdns_starfive *data)
+{
+   int ret;
+
+   ret = clk_get_bulk(data->dev, >clks);
+   if (ret)
+   return ret;
+
+   ret = reset_get_bulk(data->dev, >resets);
+   if (ret)
+   goto err_clk;
+
+   ret = clk_enable_bulk(>clks);
+   if (ret)
+   goto err_en_clk;
+
+   ret = reset_deassert_bulk(>resets);
+   if (ret)
+   goto err_reset;
+
+   return 0;
+
+err_reset:
+   clk_disable_bulk(>clks);
+err_en_clk:
+   reset_release_bulk(>resets);
+err_clk:
+   clk_release_bulk(>clks);
+
+   return ret;
+}
+
+static int cdns_starfive_get_syscon(struct cdns_starfive *data)
+{
+   struct ofnode_phandle_args phandle;
+   int ret;
+
+   ret = dev_read_phandle_with_args(data->dev, "starfive,stg-syscon", 
NULL, 1, 0,
+);
+
+   if (ret < 0) {
+   dev_err(data->dev, &qu

[PATCH v1 3/7] phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver

2024-05-04 Thread Minda Chen
Add Starfive JH7110 PCIe 2.0 PHY driver, which is generic
PHY driver and can be used as USB 3.0 driver.

Signed-off-by: Minda Chen 
---
 drivers/phy/starfive/Kconfig   |   6 +
 drivers/phy/starfive/Makefile  |   1 +
 drivers/phy/starfive/phy-jh7110-pcie.c | 211 +
 3 files changed, 218 insertions(+)
 create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.c

diff --git a/drivers/phy/starfive/Kconfig b/drivers/phy/starfive/Kconfig
index 5d78fde12e..eaebb2b47d 100644
--- a/drivers/phy/starfive/Kconfig
+++ b/drivers/phy/starfive/Kconfig
@@ -4,6 +4,12 @@
 
 menu "Starfive PHY driver"
 
+config PHY_STARFIVE_JH7110_PCIE
+bool "Starfive JH7110 PCIe 2.0 PHY driver"
+select PHY
+help
+  Enable this to support the Starfive PCIE 2.0/USB 3.0 PHY.
+
 config PHY_STARFIVE_JH7110_USB2
bool "Starfive JH7110 USB 2.0 PHY driver"
select PHY
diff --git a/drivers/phy/starfive/Makefile b/drivers/phy/starfive/Makefile
index a405a75e34..82f25aa21b 100644
--- a/drivers/phy/starfive/Makefile
+++ b/drivers/phy/starfive/Makefile
@@ -3,4 +3,5 @@
 # Copyright (C) 2023 Starfive
 #
 
+obj-$(CONFIG_PHY_STARFIVE_JH7110_PCIE) += phy-jh7110-pcie.o
 obj-$(CONFIG_PHY_STARFIVE_JH7110_USB2) += phy-jh7110-usb2.o
diff --git a/drivers/phy/starfive/phy-jh7110-pcie.c 
b/drivers/phy/starfive/phy-jh7110-pcie.c
new file mode 100644
index 00..e875d6e0f4
--- /dev/null
+++ b/drivers/phy/starfive/phy-jh7110-pcie.c
@@ -0,0 +1,211 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * StarFive JH7110 PCIe 2.0 PHY driver
+ *
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ * Author: Minda Chen 
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PCIE_KVCO_LEVEL_OFF0x28
+#define PCIE_USB3_PHY_PLL_CTL_OFF  0x7c
+#define PCIE_KVCO_TUNE_SIGNAL_OFF  0x80
+#define PCIE_USB3_PHY_ENABLE   BIT(4)
+#define PHY_KVCO_FINE_TUNE_LEVEL   0x91
+#define PHY_KVCO_FINE_TUNE_SIGNALS 0xc
+
+#define USB_PDRSTN_SPLIT   BIT(17)
+
+#define PCIE_PHY_MODE  BIT(20)
+#define PCIE_PHY_MODE_MASK GENMASK(21, 20)
+#define PCIE_USB3_BUS_WIDTH_MASK   GENMASK(3, 2)
+#define PCIE_USB3_BUS_WIDTHBIT(3)
+#define PCIE_USB3_RATE_MASKGENMASK(6, 5)
+#define PCIE_USB3_RX_STANDBY_MASK  BIT(7)
+#define PCIE_USB3_PHY_ENABLE   BIT(4)
+
+struct jh7110_pcie_phy {
+   struct phy *phy;
+   struct regmap *stg_syscon;
+   struct regmap *sys_syscon;
+   void __iomem *regs;
+   u32 sys_phy_connect;
+   u32 stg_pcie_mode;
+   u32 stg_pcie_usb;
+   enum phy_mode mode;
+};
+
+static int phy_usb3_mode_set(struct jh7110_pcie_phy *data)
+{
+   if (!data->stg_syscon || !data->sys_syscon) {
+   dev_err(data->phy->dev, "doesn't support usb3 mode\n");
+   return -EINVAL;
+   }
+
+   regmap_update_bits(data->stg_syscon, data->stg_pcie_mode,
+  PCIE_PHY_MODE_MASK, PCIE_PHY_MODE);
+   regmap_update_bits(data->stg_syscon, data->stg_pcie_usb,
+  PCIE_USB3_BUS_WIDTH_MASK, 0);
+   regmap_update_bits(data->stg_syscon, data->stg_pcie_usb,
+  PCIE_USB3_PHY_ENABLE, PCIE_USB3_PHY_ENABLE);
+
+   /* Connect usb 3.0 phy mode */
+   regmap_update_bits(data->sys_syscon, data->sys_phy_connect,
+  USB_PDRSTN_SPLIT, 0);
+
+   /* Configuare spread-spectrum mode: down-spread-spectrum */
+   writel(PCIE_USB3_PHY_ENABLE, data->regs + PCIE_USB3_PHY_PLL_CTL_OFF);
+
+   return 0;
+}
+
+static void phy_pcie_mode_set(struct jh7110_pcie_phy *data)
+{
+   u32 val;
+
+   /* default is PCIe mode */
+   if (!data->stg_syscon || !data->sys_syscon)
+   return;
+
+   regmap_update_bits(data->stg_syscon, data->stg_pcie_mode,
+  PCIE_PHY_MODE_MASK, 0);
+   regmap_update_bits(data->stg_syscon, data->stg_pcie_usb,
+  PCIE_USB3_BUS_WIDTH_MASK,
+  PCIE_USB3_BUS_WIDTH);
+   regmap_update_bits(data->stg_syscon, data->stg_pcie_usb,
+  PCIE_USB3_PHY_ENABLE, 0);
+
+   regmap_update_bits(data->sys_syscon, data->sys_phy_connect,
+  USB_PDRSTN_SPLIT, 0);
+
+   val = readl(data->regs + PCIE_USB3_PHY_PLL_CTL_OFF);
+   val &= ~PCIE_USB3_PHY_ENABLE;
+   writel(val, data->regs + PCIE_USB3_PHY_PLL_CTL_OFF);
+}
+
+static void phy_kvco_gain_set(struct jh7110_pcie_phy *phy)
+{
+   /* PCIe Multi-PHY PLL KVCO Gain fine tune settings: */
+   writel(PHY_KVCO_FINE_TUNE_LEVEL, phy->regs + PCIE_KVCO_LEVEL_OFF);
+   writel(PHY_KVCO_FINE_TUNE_SIGNALS, phy->regs + 
PCIE_KVCO_TUNE_SIGNAL_OFF);
+}
+
+static int jh7110_pcie_

[PATCH v1 2/7] phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver

2024-05-04 Thread Minda Chen
Add Starfive JH7110 USB 2.0 PHY driver, which is generic
PHY driver.

Signed-off-by: Minda Chen 
---
 drivers/phy/Kconfig|   1 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/starfive/Kconfig   |  13 +++
 drivers/phy/starfive/Makefile  |   6 ++
 drivers/phy/starfive/phy-jh7110-usb2.c | 135 +
 5 files changed, 156 insertions(+)
 create mode 100644 drivers/phy/starfive/Kconfig
 create mode 100644 drivers/phy/starfive/Makefile
 create mode 100644 drivers/phy/starfive/phy-jh7110-usb2.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 8f767877e7..0c4d63a01f 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -307,5 +307,6 @@ source "drivers/phy/cadence/Kconfig"
 source "drivers/phy/ti/Kconfig"
 source "drivers/phy/qcom/Kconfig"
 source "drivers/phy/renesas/Kconfig"
+source "drivers/phy/starfive/Kconfig"
 
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 7a2b764492..6ac867350c 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -44,3 +44,4 @@ obj-y += cadence/
 obj-y += ti/
 obj-y += qcom/
 obj-y += renesas/
+obj-y += starfive/
diff --git a/drivers/phy/starfive/Kconfig b/drivers/phy/starfive/Kconfig
new file mode 100644
index 00..5d78fde12e
--- /dev/null
+++ b/drivers/phy/starfive/Kconfig
@@ -0,0 +1,13 @@
+#
+# Phy drivers for Starfive platforms
+#
+
+menu "Starfive PHY driver"
+
+config PHY_STARFIVE_JH7110_USB2
+   bool "Starfive JH7110 USB 2.0 PHY driver"
+   select PHY
+   help
+ Enable this to support the Starfive USB 2.0 PHY.
+
+endmenu
diff --git a/drivers/phy/starfive/Makefile b/drivers/phy/starfive/Makefile
new file mode 100644
index 00..a405a75e34
--- /dev/null
+++ b/drivers/phy/starfive/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2023 Starfive
+#
+
+obj-$(CONFIG_PHY_STARFIVE_JH7110_USB2) += phy-jh7110-usb2.o
diff --git a/drivers/phy/starfive/phy-jh7110-usb2.c 
b/drivers/phy/starfive/phy-jh7110-usb2.c
new file mode 100644
index 00..ffbd96d721
--- /dev/null
+++ b/drivers/phy/starfive/phy-jh7110-usb2.c
@@ -0,0 +1,135 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * StarFive JH7110 USB 2.0 PHY driver
+ *
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ * Author: Minda Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define USB_LS_KEEPALIVE_OFF   0x4
+#define USB_LS_KEEPALIVE_ENABLEBIT(4)
+
+struct jh7110_usb2_phy {
+   struct phy *phy;
+   void __iomem *regs;
+   struct clk *usb_125m_clk;
+   struct clk *app_125m;
+   enum phy_mode mode;
+};
+
+static void usb2_set_ls_keepalive(struct jh7110_usb2_phy *phy, bool set)
+{
+   unsigned int val;
+
+   /* Host mode enable the LS speed keep-alive signal */
+   val = readl(phy->regs + USB_LS_KEEPALIVE_OFF);
+   if (set)
+   val |= USB_LS_KEEPALIVE_ENABLE;
+   else
+   val &= ~USB_LS_KEEPALIVE_ENABLE;
+
+   writel(val, phy->regs + USB_LS_KEEPALIVE_OFF);
+}
+
+static int usb2_phy_set_mode(struct phy *_phy,
+enum phy_mode mode, int submode)
+{
+   struct udevice *dev = _phy->dev;
+   struct jh7110_usb2_phy *phy = dev_get_priv(dev);
+
+   switch (mode) {
+   case PHY_MODE_USB_HOST:
+   case PHY_MODE_USB_DEVICE:
+   case PHY_MODE_USB_OTG:
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   if (mode != phy->mode) {
+   dev_dbg(dev, "Changing phy to %d\n", mode);
+   phy->mode = mode;
+   usb2_set_ls_keepalive(phy, (mode != PHY_MODE_USB_DEVICE));
+   }
+
+   return 0;
+}
+
+static int jh7110_usb2_phy_init(struct phy *_phy)
+{
+   struct udevice *dev = _phy->dev;
+   struct jh7110_usb2_phy *phy = dev_get_priv(dev);
+   int ret;
+
+   ret = clk_prepare_enable(phy->app_125m);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
+static int jh7110_usb2_phy_exit(struct phy *_phy)
+{
+   struct udevice *dev = _phy->dev;
+   struct jh7110_usb2_phy *phy = dev_get_priv(dev);
+
+   clk_disable_unprepare(phy->app_125m);
+
+   return 0;
+}
+
+struct phy_ops jh7110_usb2_phy_ops = {
+   .init = jh7110_usb2_phy_init,
+   .exit = jh7110_usb2_phy_exit,
+   .set_mode = usb2_phy_set_mode,
+};
+
+int jh7110_usb2_phy_probe(struct udevice *dev)
+{
+   struct jh7110_usb2_phy *phy = dev_get_priv(dev);
+
+   phy->regs = dev_read_addr_ptr(dev);
+
+   if (!phy->regs)
+   return -EINVAL;
+
+   phy->usb_125m_clk = devm_clk_get(dev, "125m");
+   if (IS_ERR(phy->usb_125m_clk)) {
+   dev_err(dev, "Failed to get 125m clock\n&q

[PATCH v1 1/7] usb: cdns3: Set USB PHY mode in cdns3_probe()

2024-05-04 Thread Minda Chen
USB PHY maybe need to set PHY mode in different USB
dr mode. So translate to generic PHY mode and call
generic_phy_set_mode().

Signed-off-by: Minda Chen 
---
 drivers/usb/cdns3/core.c | 17 +
 1 file changed, 17 insertions(+)

diff --git a/drivers/usb/cdns3/core.c b/drivers/usb/cdns3/core.c
index 12a741c6ea..c1a61471f9 100644
--- a/drivers/usb/cdns3/core.c
+++ b/drivers/usb/cdns3/core.c
@@ -321,6 +321,7 @@ static int cdns3_probe(struct cdns3 *cdns)
 {
struct udevice *dev = cdns->dev;
int ret;
+   int mode = PHY_MODE_INVALID;
 
cdns->xhci_regs = dev_remap_addr_name(dev, "xhci");
if (!cdns->xhci_regs)
@@ -372,6 +373,22 @@ static int cdns3_probe(struct cdns3 *cdns)
if (ret)
return ret;
 
+   if (cdns->dr_mode == USB_DR_MODE_HOST)
+   mode = PHY_MODE_USB_HOST;
+   else if (cdns->dr_mode == USB_DR_MODE_PERIPHERAL)
+   mode = PHY_MODE_USB_DEVICE;
+   else if (cdns->dr_mode == USB_DR_MODE_OTG)
+   mode = PHY_MODE_USB_OTG;
+
+   if (mode != PHY_MODE_INVALID) {
+   ret = generic_phy_set_mode(>usb2_phy, mode, 0);
+   if (ret)
+   return ret;
+   ret = generic_phy_set_mode(>usb3_phy, mode, 0);
+   if (ret)
+   return ret;
+   }
+
dev_dbg(dev, "Cadence USB3 core: probe succeed\n");
 
return 0;
-- 
2.17.1



[PATCH v1 0/7] Add Starfive JH7110 Cadence USB driver

2024-05-04 Thread Minda Chen
Add Starfive JH7110 Cadence USB driver and related PHY driver.
So the codes can be used in visionfive2 and milkv 7110 board.

The driver is almost the same with kernel driver.

patch1: Add set phy mode function in cdns3 core driver
which is used by Starfive.

patch2-3: USB and PCIe 2.0 (usb 3.0) PHY drivier
patch4: Cadence USB wrapper driver.
patch5-7 dts, config and maintainers update.

Minda Chen (7):
  usb: cdns3: Set USB PHY mode in cdns3_probe()
  phy: starfive: Add Starfive JH7110 USB 2.0 PHY driver
  phy: starfive: Add Starfive JH7110 PCIe 2.0 PHY driver
  usb: cdns: starfive: Add cdns USB driver
  configs: starfive: Add visionfive2 cadence USB configuration
  dts: starfive: Add JH7110 Cadence USB dts node
  MAINTAINERS: Update Starfive visionfive2 maintain files.

 .../dts/jh7110-starfive-visionfive-2.dtsi |   5 +
 arch/riscv/dts/jh7110.dtsi|  52 +
 board/starfive/visionfive2/MAINTAINERS|   2 +
 configs/starfive_visionfive2_defconfig|   9 +
 drivers/phy/Kconfig   |   1 +
 drivers/phy/Makefile  |   1 +
 drivers/phy/starfive/Kconfig  |  19 ++
 drivers/phy/starfive/Makefile |   7 +
 drivers/phy/starfive/phy-jh7110-pcie.c| 211 ++
 drivers/phy/starfive/phy-jh7110-usb2.c| 135 +++
 drivers/usb/cdns3/Kconfig |   7 +
 drivers/usb/cdns3/Makefile|   2 +
 drivers/usb/cdns3/cdns3-starfive.c| 184 +++
 drivers/usb/cdns3/core.c  |  17 ++
 14 files changed, 652 insertions(+)
 create mode 100644 drivers/phy/starfive/Kconfig
 create mode 100644 drivers/phy/starfive/Makefile
 create mode 100644 drivers/phy/starfive/phy-jh7110-pcie.c
 create mode 100644 drivers/phy/starfive/phy-jh7110-usb2.c
 create mode 100644 drivers/usb/cdns3/cdns3-starfive.c


base-commit: 174ac987655c888017c82df1883c0c2ea0dc2495
-- 
2.17.1



Re: [PATCH v2 4/6] board: starfive: support Milk-V Mars board

2024-04-01 Thread Minda Chen
> 
> On 4/1/24 17:28, Aurelien Jarno wrote:
> > On 2024-03-28 17:01, Heinrich Schuchardt wrote:
> >> On 24.03.24 16:00, Aurelien Jarno wrote:
> >>> On 2024-03-21 19:11, Heinrich Schuchardt wrote:
>  The differences between the Milk-V Mars board and the VisionFive 2
>  board are small enough that we can support both using the same U-Boot
> build.
> 
>  * The model and compatible property are taken from proposed Linux
> patches.
>  * The EEPROM is atmel,24c02 according to the vendor U-Boot.
>  * The second Ethernet port is not available.
> >>>
> >>>   From the device tree that have been submitted to the kernel [1] it
> >>> seems another difference is that there is a CD gpio for mmc1.
> >>
> >> Thank you for reviewing.
> >>
> >> On all of Milk-V Mars, VisionFive 2 1.2B, and 1.3A I see GPIO 41
> >> level changing when removing or inserting an SD card using U-Boot
> >> command 'gpio status -a'. So this seems not to be Milk-V specific.
> >>
> >> Could you, please, check.
> >
> > This already have been answered by others, thanks.
> >
> >>>   From the schematics, it also seems that the usb0 port is not in
> >>> peripheral mode, but in host mode. That said on the submitted kernel
> >>> device tree it seems simply disabled.
> >>
> >> All three blue-colored USB 3.0 ports are able to read an SD-card in U-Boot.
> >>
> >> The black port provides 5V but I could not make it work.
> >>
> >> On the schema I found:
> >>
> >> USB20: Do not support OTG mode and AVSS_USB0-AVSS_USB2 attached to
> ground.
> >>
> >> Could you, please, specify which node in the device-tree you want to
> >> disable. I cannot see anything disabled for usb@1010 and usb@0 in
> >> the kernel device-tree.
> >
> > Disclaimer, I have no such board, but I remember people on IRC trying
> > to use the device tree from the VF2 on a Milk-V Mars and getting an
> > error with the USB being in a wrong mode.
> >
> > The difference I have noticed is not a node but the dr_mode property:
> >
> >  {
> >  dr_mode = "peripheral";
> >  status = "okay";
> > };
> 
> Thanks Aurelien for the explanation.
> 
> The node usb@1010 (aka usb0) does not exist in the U-Boot
> VisionFive2 device-tree, yet. There isn't any dr_mode property either.
> 
> We will have to consider this node once we merge the Linux device-tree.
> 
> Best regards
> 
> Heinrich
> 
usb@1010 is cadence usb controller. In VF2, dr mode is usb peripheral and 
seldom used in u-boot. So the cadence usb wrapper codes not in uboot upstream.
I don't know the dr mode in milkv 7110 board. But if it its dr mode is host, I 
think I
need develop cadence usb wrapper code upstream.

Minda 
> >
> > This does not appear on the patches submitted on the Linux side for
> > the MilkV Mars.
> >
> > Aurelien
> >



Re: [PATCH 1/1] riscv: starfive: MMC card detect

2024-03-29 Thread Minda Chen



> 
> The VisionFive 2 board uses GPIO 41 as card detect as documented in
> https://doc-en.rvspace.org/VisionFive2/PDF/SCH_RV002_V1.2A_20221216.pdf.
> 
> Signed-off-by: Heinrich Schuchardt 
> ---
>  arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
> b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
> index f2c6bec9298..e11babc1cde 100644
> --- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
> +++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
> @@ -298,7 +298,7 @@
>   pinctrl-0 = <_pins>;
>   no-sdio;
>   no-mmc;
> - broken-cd;
> + cd-gpios = < 41 GPIO_ACTIVE_LOW>;
>   cap-sd-highspeed;
>   post-power-on-delay-ms = <200>;
>   status = "okay";
> --
> 2.43.0

Acked-by: Minda Chen 


回复: [PATCH v2 0/6] riscv: add support for Milk-V Mars board

2024-03-24 Thread Minda Chen


> 
> The Milk-V Mars board is technically very close to the StarFive VisionFive 2
> board.
> 
> With this patch series the VisionFive 2 U-Boot SPL will detect that it is 
> running on
> a Milk-V board and patch the device-tree accordingly.
> This is the same approach that has been taken to handle the differences
> between the Visionfive 2 1.2B and 1.3A revisions.
> 
> v2:
>   do not set default fdt for VisionFive 2
>   do not overwrite /soc/i2c@1205/eeprom@50/compatible
> 

Hi Heinrich
I will test this series patch first. Next version please cc Hal,He will help
to review this series patch.

Minda 

> *** BLURB HERE ***
> 
> Heinrich Schuchardt (6):
>   riscv: do not set default fdt for VisionFive 2
>   eeprom: starfive: function get_product_id_from_eeprom()
>   riscv: set fdtfile on Milk-V Mars
>   board: starfive: support Milk-V Mars board
>   riscv: starfive: avoid including common.h
>   doc: describe Milk-V Mars board
> 
>  arch/riscv/include/asm/arch-jh7110/eeprom.h   |   9 ++
>  board/starfive/visionfive2/spl.c  | 100 ++--
>  .../visionfive2/starfive_visionfive2.c|  48 +---
>  .../visionfive2/visionfive2-i2c-eeprom.c  |   9 +-
>  configs/starfive_visionfive2_defconfig|   1 -
>  doc/board/starfive/index.rst  |   1 +
>  doc/board/starfive/milk-v_mars.rst| 111 ++
>  doc/board/starfive/visionfive2.rst|  18 +++
>  8 files changed, 268 insertions(+), 29 deletions(-)  create mode 100644
> doc/board/starfive/milk-v_mars.rst
> 
> --
> 2.43.0



[PATCH v1 2/2] board: starfive: maintainer: Add visionfive2 PCIe driver

2024-03-07 Thread Minda Chen
Add PCIe driver file to visionfive2 board MAINTAINERS list.

Signed-off-by: Minda Chen 
---
 board/starfive/visionfive2/MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/board/starfive/visionfive2/MAINTAINERS 
b/board/starfive/visionfive2/MAINTAINERS
index 5056e9c713..d7f638f9b4 100644
--- a/board/starfive/visionfive2/MAINTAINERS
+++ b/board/starfive/visionfive2/MAINTAINERS
@@ -5,3 +5,4 @@ F:  arch/riscv/include/asm/arch-jh7110/
 F: board/starfive/visionfive2/
 F: include/configs/starfive-visionfive2.h
 F: configs/starfive_visionfive2_defconfig
+F: drivers/pci/pcie_starfive_jh7110.c
-- 
2.17.1



[PATCH v1 1/2] board: starfive: Update maintainer of VisionFive v2 board

2024-03-07 Thread Minda Chen
Update the maintainer of Starfive VisionFive v2 board.

Signed-off-by: Minda Chen 
---
 board/starfive/visionfive2/MAINTAINERS | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/starfive/visionfive2/MAINTAINERS 
b/board/starfive/visionfive2/MAINTAINERS
index 600ff9575b..5056e9c713 100644
--- a/board/starfive/visionfive2/MAINTAINERS
+++ b/board/starfive/visionfive2/MAINTAINERS
@@ -1,5 +1,5 @@
 STARFIVE JH7110 VISIONFIVE2 BOARD
-M: Yanhong Wang 
+M: Minda Chen 
 S: Maintained
 F: arch/riscv/include/asm/arch-jh7110/
 F: board/starfive/visionfive2/
-- 
2.17.1



Re: [PATCH v1] usb: xhci: Check return value of wait for TRB_TRANSFER event

2023-10-18 Thread Minda Chen



On 2023/10/18 18:55, Marek Vasut wrote:
> On 10/18/23 12:16, Minda Chen wrote:
>>
>>
>> On 2023/10/18 18:11, Marek Vasut wrote:
>>> On 10/18/23 05:46, Minda Chen wrote:
>>>>
>>>>
>>>> On 2023/10/18 10:35, Marek Vasut wrote:
>>>>> On 10/18/23 03:22, Minda Chen wrote:
>>>>>>
>>>>>>
>>>>>> On 2023/10/17 19:20, Marek Vasut wrote:
>>>>>>> On 10/17/23 08:20, Minda Chen wrote:
>>>>>>>> xhci_wait_for_event() waiting TRB_TRANSFER event may return
>>>>>>>> NULL. Checking the return value to avoid crash.
>>>>>>>>
>>>>>>>> Signed-off-by: Minda Chen 
>>>>>>>
>>>>>>> How did you trigger this error ? Is there a reproducer ? Details please 
>>>>>>> ...
>>>>>>
>>>>>> While Scanning a lenovo usb2.0 udisk, not 100 % reproduce
>>>>>
>>>>> Can you include Linux
>>>>>
>>>>> lsusb -vvv
>>>>>
>>>>> output for this device and include that information in the commit message 
>>>>> ? (or the U-Boot info below, that works too, just please add it into the 
>>>>> commit message, it is important for future reference).
>>>>>
>>>> OK, I will add lsusb -vvv Linux udisk message and crash dump info to 
>>>> commit message
>>>
>>> Thank you
>>>
>>>>>> This is log.
>>>>>>
>>>>>> StarFive # usb reset
>>>>>> resetting USB...
>>>>>> Bus xhci_pci: Register 5000420 NbrPorts 5
>>>>>> Starting the controller
>>>>>> USB XHCI 1.00
>>>>>> scanning bus xhci_pci for devices... WARN halted endpoint, queueing URB 
>>>>>> anyway.
>>>>>> Unexpected XHCI event TRB, skipping... (f77141f0  1300 
>>>>>> 02008401)
>>>>>> Unhandled exception: Load access fault
>>>>>> EPC: f7f563c6 RA: f7f563c6 TVAL: 000c
>>>>>> EPC: 4024a3c6 RA: 4024a3c6 reloc adjusted
>>>>>
>>>>> Where does the crash point to in code, can you disassemble the PC pointer 
>>>>> ? (or maybe you can use scripts/decodecode I think)
>>>>>
>>>> OK, I will add EPC pointer disassemble  to commit message
>>>
>>> This part probably doesn't need to be in the commit message. I'd like to 
>>> know where the crash occurred in the code.
>>
>>
>> 4024a376 :
>> {
>>  4024a376:   7179    addi    sp,sp,-48
>>  4024a378:   f406    sd  ra,40(sp)
>>  4024a37a:   f022    sd  s0,32(sp)
>>  4024a37c:   ec26    sd  s1,24(sp)
>>  4024a37e:   e84a    sd  s2,16(sp)
>>  4024a380:   e44e    sd  s3,8(sp)
>>  4024a382:   e052    sd  s4,0(sp)
>>  4024a384:   89ae    mv  s3,a1
>>  4024a386:   84aa    mv  s1,a0
>>  struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
>>  4024a388:   8c4fe0ef    jal ra,4024844c 
>>  struct xhci_ring *ring =  
>> ctrl->devs[udev->slot_id]->eps[ep_index].ring;
>>  4024a38c:   6785    lui a5,0x1
>>  4024a38e:   94be    add s1,s1,a5
>>  4024a390:   9444a603    lw  a2,-1724(s1)
>>  4024a394:   00198713    addi    a4,s3,1
>>  4024a398:   0712    slli    a4,a4,0x4
>>  4024a39a:   02061793    slli    a5,a2,0x20
>>  4024a39e:   9381    srli    a5,a5,0x20
>>  4024a3a0:   07c9    addi    a5,a5,18
>>  4024a3a2:   078e    slli    a5,a5,0x3
>>  4024a3a4:   97aa    add a5,a5,a0
>>  4024a3a6:   679c    ld  a5,8(a5)
>>  xhci_queue_command(ctrl, NULL, udev->slot_id, ep_index, 
>> TRB_STOP_RING);
>>  4024a3a8:   2981    sext.w  s3,s3
>>  4024a3aa:   86ce    mv  a3,s3
>>  struct xhci_ring *ring =  
>> ctrl->devs[udev->slot_id]->eps[ep_index].ring;
>>  4024a3ac:   97ba    add a5,a5,a4
>>  xhci_q

Re: [PATCH v1] usb: xhci: Check return value of wait for TRB_TRANSFER event

2023-10-18 Thread Minda Chen



On 2023/10/18 18:11, Marek Vasut wrote:
> On 10/18/23 05:46, Minda Chen wrote:
>>
>>
>> On 2023/10/18 10:35, Marek Vasut wrote:
>>> On 10/18/23 03:22, Minda Chen wrote:
>>>>
>>>>
>>>> On 2023/10/17 19:20, Marek Vasut wrote:
>>>>> On 10/17/23 08:20, Minda Chen wrote:
>>>>>> xhci_wait_for_event() waiting TRB_TRANSFER event may return
>>>>>> NULL. Checking the return value to avoid crash.
>>>>>>
>>>>>> Signed-off-by: Minda Chen 
>>>>>
>>>>> How did you trigger this error ? Is there a reproducer ? Details please 
>>>>> ...
>>>>
>>>> While Scanning a lenovo usb2.0 udisk, not 100 % reproduce
>>>
>>> Can you include Linux
>>>
>>> lsusb -vvv
>>>
>>> output for this device and include that information in the commit message ? 
>>> (or the U-Boot info below, that works too, just please add it into the 
>>> commit message, it is important for future reference).
>>>
>> OK, I will add lsusb -vvv Linux udisk message and crash dump info to commit 
>> message
> 
> Thank you
> 
>>>> This is log.
>>>>
>>>> StarFive # usb reset
>>>> resetting USB...
>>>> Bus xhci_pci: Register 5000420 NbrPorts 5
>>>> Starting the controller
>>>> USB XHCI 1.00
>>>> scanning bus xhci_pci for devices... WARN halted endpoint, queueing URB 
>>>> anyway.
>>>> Unexpected XHCI event TRB, skipping... (f77141f0  1300 
>>>> 02008401)
>>>> Unhandled exception: Load access fault
>>>> EPC: f7f563c6 RA: f7f563c6 TVAL: 000c
>>>> EPC: 4024a3c6 RA: 4024a3c6 reloc adjusted
>>>
>>> Where does the crash point to in code, can you disassemble the PC pointer ? 
>>> (or maybe you can use scripts/decodecode I think)
>>>
>> OK, I will add EPC pointer disassemble  to commit message
> 
> This part probably doesn't need to be in the commit message. I'd like to know 
> where the crash occurred in the code.


4024a376 :
{
4024a376:   7179addisp,sp,-48
4024a378:   f406sd  ra,40(sp)
4024a37a:   f022sd  s0,32(sp)
4024a37c:   ec26sd  s1,24(sp)
4024a37e:   e84asd  s2,16(sp)
4024a380:   e44esd  s3,8(sp)
4024a382:   e052sd  s4,0(sp)
4024a384:   89aemv  s3,a1
4024a386:   84aamv  s1,a0
struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
4024a388:   8c4fe0efjal ra,4024844c 
struct xhci_ring *ring =  ctrl->devs[udev->slot_id]->eps[ep_index].ring;
4024a38c:   6785lui a5,0x1
4024a38e:   94beadd s1,s1,a5
4024a390:   9444a603lw  a2,-1724(s1)
4024a394:   00198713addia4,s3,1
4024a398:   0712sllia4,a4,0x4
4024a39a:   02061793sllia5,a2,0x20
4024a39e:   9381srlia5,a5,0x20
4024a3a0:   07c9addia5,a5,18
4024a3a2:   078esllia5,a5,0x3
4024a3a4:   97aaadd a5,a5,a0
4024a3a6:   679cld  a5,8(a5)
xhci_queue_command(ctrl, NULL, udev->slot_id, ep_index, TRB_STOP_RING);
4024a3a8:   2981sext.w  s3,s3
4024a3aa:   86cemv  a3,s3
struct xhci_ring *ring =  ctrl->devs[udev->slot_id]->eps[ep_index].ring;
4024a3ac:   97baadd a5,a5,a4
xhci_queue_command(ctrl, NULL, udev->slot_id, ep_index, TRB_STOP_RING);
4024a3ae:   4581li  a1,0
4024a3b0:   473dli  a4,15
struct xhci_ring *ring =  ctrl->devs[udev->slot_id]->eps[ep_index].ring;
4024a3b2:   0087ba03ld  s4,8(a5) # 1008 
<_start-0x401feff8>
struct xhci_ctrl *ctrl = xhci_get_ctrl(udev);
4024a3b6:   842amv  s0,a0
xhci_queue_command(ctrl, NULL, udev->slot_id, ep_index, TRB_STOP_RING);
4024a3b8:   d75ff0efjal ra,4024a12c 
event = xhci_wait_for_event(ctrl, TRB_TRANSFER);
4024a3bc:   02000593li  a1,32
4024a3c0:   8522mv  a0,s0
4024a3c2:   ebdff0efjal ra,4024a27e 

field = le32_to_cpu(event->trans_event.flags);
epc-> 4024a3c6:   455clw  a5,12(a0) 
BUG_ON(TRB_TO_SLOT_ID(field) != udev->slot_id);
4024a3c8:   9444a703lw  a4,-1724(s1)
field = le32_to_cpu(event->trans_event.flags);
4024a3cc:   0007891bsext.w  s2,a5



Re: [PATCH v1] usb: xhci: Check return value of wait for TRB_TRANSFER event

2023-10-17 Thread Minda Chen



On 2023/10/18 10:35, Marek Vasut wrote:
> On 10/18/23 03:22, Minda Chen wrote:
>>
>>
>> On 2023/10/17 19:20, Marek Vasut wrote:
>>> On 10/17/23 08:20, Minda Chen wrote:
>>>> xhci_wait_for_event() waiting TRB_TRANSFER event may return
>>>> NULL. Checking the return value to avoid crash.
>>>>
>>>> Signed-off-by: Minda Chen 
>>>
>>> How did you trigger this error ? Is there a reproducer ? Details please ...
>>
>> While Scanning a lenovo usb2.0 udisk, not 100 % reproduce
> 
> Can you include Linux
> 
> lsusb -vvv
> 
> output for this device and include that information in the commit message ? 
> (or the U-Boot info below, that works too, just please add it into the commit 
> message, it is important for future reference).
> 
OK, I will add lsusb -vvv Linux udisk message and crash dump info to commit 
message
>> This is log.
>>
>> StarFive # usb reset
>> resetting USB...
>> Bus xhci_pci: Register 5000420 NbrPorts 5
>> Starting the controller
>> USB XHCI 1.00
>> scanning bus xhci_pci for devices... WARN halted endpoint, queueing URB 
>> anyway.
>> Unexpected XHCI event TRB, skipping... (f77141f0  1300 02008401)
>> Unhandled exception: Load access fault
>> EPC: f7f563c6 RA: f7f563c6 TVAL: 000c
>> EPC: 4024a3c6 RA: 4024a3c6 reloc adjusted
> 
> Where does the crash point to in code, can you disassemble the PC pointer ? 
> (or maybe you can use scripts/decodecode I think)
> 
OK, I will add EPC pointer disassemble  to commit message
>> SP:  f76f9a60 GP:  f76fbdd0 TP:  0001
>> T0:  f76fa168 T1:  00ff T2:  0016
>> S0:  f7712fc0 S1:  f76fb100 A0:  
>> A1:   A2:  f77145d0 A3:  f7714590
>> A4:   A5:  0020 A6:  000f
>> A7:  0100 S2:   S3:  
>> S4:  f7717050 S5:  f7717050 S6:  8383
>> S7:  f76f9dc0 S8:  00ff S9:  0001
>> S10: f76f9ba0 S11: 00010c04 T3:  0010
>> T4:  0006 T5:  0080 T6:  f76fa231
> 
> [...]
> 
>> 3: Mass Storage,  USB Revision 2.0
>>   - Generic Mass Storage 31097778XB15113405
>>   - Class: (from Interface) Mass Storage
>>   - PacketSize: 64  Configurations: 1
>>   - Vendor: 0x17ef  Product 0x38ac Version 1.0
>>     Configuration: 1
>>     - Interfaces: 1 Bus Powered 200mA
>>   Interface: 0
>>   - Alternate Setting 0, Endpoints: 2
>>   - Class Mass Storage, Transp. SCSI, Bulk only
>>   - Endpoint 1 Out Bulk MaxPacket 512
>>   - Endpoint 2 In Bulk MaxPacket 512
>>
>> StarFive # usb storage
>>    Device 0: Vendor:  Rev: 8.07 Prod: Lenovo SX1 64G
>>  Type: Removable Hard Disk
>>  Capacity: 6.0 MB = 58.5 GB (12288 x 512)
> 
> [...]


Re: [PATCH v1] usb: xhci: Check return value of wait for TRB_TRANSFER event

2023-10-17 Thread Minda Chen



On 2023/10/17 19:20, Marek Vasut wrote:
> On 10/17/23 08:20, Minda Chen wrote:
>> xhci_wait_for_event() waiting TRB_TRANSFER event may return
>> NULL. Checking the return value to avoid crash.
>>
>> Signed-off-by: Minda Chen 
> 
> How did you trigger this error ? Is there a reproducer ? Details please ...

While Scanning a lenovo usb2.0 udisk, not 100 % reproduce

This is log.

StarFive # usb reset
resetting USB...
Bus xhci_pci: Register 5000420 NbrPorts 5
Starting the controller
USB XHCI 1.00
scanning bus xhci_pci for devices... WARN halted endpoint, queueing URB anyway.
Unexpected XHCI event TRB, skipping... (f77141f0  1300 02008401)
Unhandled exception: Load access fault
EPC: f7f563c6 RA: f7f563c6 TVAL: 000c
EPC: 4024a3c6 RA: 4024a3c6 reloc adjusted

SP:  f76f9a60 GP:  f76fbdd0 TP:  0001
T0:  f76fa168 T1:  00ff T2:  0016
S0:  f7712fc0 S1:  f76fb100 A0:  
A1:   A2:  f77145d0 A3:  f7714590
A4:   A5:  0020 A6:  000f
A7:  0100 S2:   S3:  
S4:  f7717050 S5:  f7717050 S6:  8383
S7:  f76f9dc0 S8:  00ff S9:  0001
S10: f76f9ba0 S11: 00010c04 T3:  0010
T4:  0006 T5:  0080 T6:  f76fa231

Code: 842a f0ef d75f 0593 0200 8522 f0ef ebdf (455c) 


This is USB info and storage info 

StarFive # 
1: Hub,  USB Revision 3.0
 - U-Boot XHCI Host Controller 
 - Class: Hub
 - PacketSize: 512  Configurations: 1
 - Vendor: 0x  Product 0x Version 1.0
   Configuration: 1
   - Interfaces: 1 Self Powered 0mA
 Interface: 0
 - Alternate Setting 0, Endpoints: 1
 - Class Hub
 - Endpoint 1 In Interrupt MaxPacket 8 Interval 255ms

2: Hub,  USB Revision 2.10
 -  USB2.0 Hub 
 - Class: Hub
 - PacketSize: 64  Configurations: 1
 - Vendor: 0x2109  Product 0x3431 Version 4.32
   Configuration: 1
   - Interfaces: 1 Self Powered Remote Wakeup 100mA
 Interface: 0
 - Alternate Setting 0, Endpoints: 1
 - Class Hub
 - Endpoint 1 In Interrupt MaxPacket 1 Interval 12ms

3: Mass Storage,  USB Revision 2.0
 - Generic Mass Storage 31097778XB15113405
 - Class: (from Interface) Mass Storage
 - PacketSize: 64  Configurations: 1
 - Vendor: 0x17ef  Product 0x38ac Version 1.0
   Configuration: 1
   - Interfaces: 1 Bus Powered 200mA
 Interface: 0
 - Alternate Setting 0, Endpoints: 2
 - Class Mass Storage, Transp. SCSI, Bulk only
 - Endpoint 1 Out Bulk MaxPacket 512
 - Endpoint 2 In Bulk MaxPacket 512

StarFive # usb storage
  Device 0: Vendor:  Rev: 8.07 Prod: Lenovo SX1 64G  
Type: Removable Hard Disk
Capacity: 6.0 MB = 58.5 GB (12288 x 512)
StarFive # 


[PATCH v1] usb: xhci: Check return value of wait for TRB_TRANSFER event

2023-10-17 Thread Minda Chen
xhci_wait_for_event() waiting TRB_TRANSFER event may return
NULL. Checking the return value to avoid crash.

Signed-off-by: Minda Chen 
---
 drivers/usb/host/xhci-ring.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index c8260cbdf9..5f02ff0769 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -544,6 +544,8 @@ static void abort_td(struct usb_device *udev, int ep_index)
xhci_queue_command(ctrl, 0, udev->slot_id, ep_index, TRB_STOP_RING);
 
event = xhci_wait_for_event(ctrl, TRB_TRANSFER);
+   if (!event)
+   return;
field = le32_to_cpu(event->trans_event.flags);
BUG_ON(TRB_TO_SLOT_ID(field) != udev->slot_id);
BUG_ON(TRB_TO_EP_INDEX(field) != ep_index);
-- 
2.17.1



[RESEND,v1 2/4] riscv: dts: starfive: Enable pcie0 dts node

2023-08-07 Thread Minda Chen
In StarFive VF2 board. pcie0 connect to VTI usb controller.
Enable it to support usb host.

Signed-off-by: Minda Chen 
---
 arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index bf7fdb4dd6..e40f57a150 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -311,7 +311,7 @@
 
  {
reset-gpios = < 26 GPIO_ACTIVE_LOW>;
-   status = "disabled";
+   status = "okay";
 };
 
  {
-- 
2.17.1



[RESEND, v1 3/4] riscv: starfive: Add SYS_CACHE_SHIFT_6 to enable SYS_CACHELINE_SIZE

2023-08-07 Thread Minda Chen
Some device driver need SYS_CACHELINE_SIZE macro. Add StarFive
SYS_CACHE_SHIFT_6 to enable it.

Signed-off-by: Minda Chen 
---
 arch/riscv/cpu/jh7110/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/cpu/jh7110/Kconfig b/arch/riscv/cpu/jh7110/Kconfig
index 4d9581165b..c1d3e6ada2 100644
--- a/arch/riscv/cpu/jh7110/Kconfig
+++ b/arch/riscv/cpu/jh7110/Kconfig
@@ -13,6 +13,7 @@ config STARFIVE_JH7110
select SUPPORT_SPL
select SPL_RAM if SPL
select SPL_STARFIVE_DDR
+   select SYS_CACHE_SHIFT_6
select PINCTRL_STARFIVE_JH7110
imply MMC
imply MMC_BROKEN_CD
-- 
2.17.1



[RESEND, v1 4/4] configs: riscv: starfive: Add VF2 PCIe USB3 XHCI support

2023-08-07 Thread Minda Chen
Add XHCI_PCI to enable usb3-host functions.
Also add usb command and keyboard config.

Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 5d8a8e28cb..a70ada394f 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -65,6 +65,7 @@ CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=5
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_PCI=y
+CONFIG_CMD_USB=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
@@ -111,3 +112,7 @@ CONFIG_PINCTRL_STARFIVE=y
 CONFIG_SYS_NS16550=y
 CONFIG_CADENCE_QSPI=y
 CONFIG_TIMER_EARLY=y
+CONFIG_USB=y
+CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_XHCI_PCI=y
+CONFIG_USB_KEYBOARD=y
-- 
2.17.1



[RESEND,v1 0/4] Add StarFive VF2 USB host support.

2023-08-07 Thread Minda Chen
StarFive VF2 VLI usb-host controller connect to pcie0 RC.
Enable pcie0 first the enable USB function.

patch1 is Get the correct ECAM offset in multiple PCIe RC.
patch2 is enable pcie0 dts node.
patch3 is enable SYS_CACHELINE_SIZE
patch4 is Add VF2 USB related configuration.

Minda Chen (4):
  pci: plda: Get correct ECAM offset in multiple PCIe RC case
  riscv: dts: starfive: Enable pcie0 dts node
  riscv: starfive: Add SYS_CACHE_SHIFT_6 to enable SYS_CACHELINE_SIZE
  configs: riscv: starfive: Add VF2 PCIe USB3 XHCI support

 arch/riscv/cpu/jh7110/Kconfig| 1 +
 arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi | 2 +-
 configs/starfive_visionfive2_defconfig   | 5 +
 drivers/pci/pcie_plda_common.c   | 5 +++--
 4 files changed, 10 insertions(+), 3 deletions(-)

base-commit: 38dedebc547f795efc3daad17f7c013c515e1285
-- 
2.17.1



[RESEND, v1 1/4] pci: plda: Get correct ECAM offset in multiple PCIe RC case

2023-08-07 Thread Minda Chen
Get the correct ECAM offset and record the secondary bus
number in Multiple RC case.

Signed-off-by: Minda Chen 
---
 drivers/pci/pcie_plda_common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pcie_plda_common.c b/drivers/pci/pcie_plda_common.c
index 005b92616a..cd74bb4711 100644
--- a/drivers/pci/pcie_plda_common.c
+++ b/drivers/pci/pcie_plda_common.c
@@ -36,8 +36,8 @@ static int plda_pcie_conf_address(const struct udevice *udev, 
pci_dev_t bdf,
  uint offset, void **paddr)
 {
struct pcie_plda *priv = dev_get_priv(udev);
-   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf),
-PCI_FUNC(bdf), offset);
+   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf) - dev_seq(udev),
+PCI_DEV(bdf), PCI_FUNC(bdf), offset);
 
if (!plda_pcie_addr_valid(priv, bdf))
return -ENODEV;
@@ -71,6 +71,7 @@ int plda_pcie_config_write(struct udevice *udev, pci_dev_t 
bdf,
(offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8))) {
priv->sec_busno =
((offset == PCI_PRIMARY_BUS) ? (value >> 8) : value) & 
0xff;
+   priv->sec_busno += dev_seq(udev);
debug("Secondary bus number was changed to %d\n",
  priv->sec_busno);
}
-- 
2.17.1



Re: [PATCH v1 3/4] riscv: starfive: Add SYS_CACHE_SHIFT_6 to enable SYS_CACHE_LINE_SIZE

2023-08-02 Thread Minda Chen



On 2023/8/3 12:49, Bin Meng wrote:
> On Thu, Aug 3, 2023 at 11:22 AM Minda Chen  
> wrote:
>>
>> Some devices need SYS_CACHE_LINE_SIZE macro. Add StarFive
>> SYS_CACHE_SHIFT_6 to enable it.
>>
>> Signed-off-by: Minda Chen 
>> ---
>>  arch/riscv/Kconfig | 1 +
>>  1 file changed, 1 insertion(+)
>>
>> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
>> index 867cbcbe74..15da2a8559 100644
>> --- a/arch/riscv/Kconfig
>> +++ b/arch/riscv/Kconfig
>> @@ -26,6 +26,7 @@ config TARGET_SIFIVE_UNMATCHED
>>
>>  config TARGET_STARFIVE_VISIONFIVE2
>> bool "Support StarFive VisionFive2 Board"
>> +   select SYS_CACHE_SHIFT_6
>>
>>  config TARGET_TH1520_LPI4A
>> bool "Support Sipeed's TH1520 Lichee PI 4A Board"
> 
> This needs to go into arch/riscv/cpu/jh7110/Kconfig::STARFIVE_JH7110
> 
> Regards,
> Bin
ok, thanks


[PATCH v1 0/4] Add VF2 USB host support.

2023-08-02 Thread Minda Chen
StarFive VF2 VTI usb-host controller connect to pcie0 RC.
Enable pcie0 first the enable USB function.

patch1 is Get the correct ECAM offset in multiple PCIe RC.
patch2 is enable pcie0 dts node.
patch3 is enable SYS_CACHE_LINE_SIZE
patch4 is Add VF2 USB related configuration.

Minda Chen (4):
  pci: plda: Get correct ECAM offset in multiple PCIe RC case
  riscv: dts: starfive: Enable pcie0 dts node
  riscv: starfive: Add SYS_CACHE_SHIFT_6 to enable SYS_CACHE_LINE_SIZE
  configs: riscv: starfive: Add VF2 PCIe XHCI config support

 arch/riscv/Kconfig   | 1 +
 arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi | 2 +-
 configs/starfive_visionfive2_defconfig   | 5 +
 drivers/pci/pcie_plda_common.c   | 5 +++--
 4 files changed, 10 insertions(+), 3 deletions(-)

base-commit: 38dedebc547f795efc3daad17f7c013c515e1285
-- 
2.17.1



[PATCH v1 4/4] configs: riscv: starfive: Add VF2 PCIe XHCI config support

2023-08-02 Thread Minda Chen
Add PCI_XHCI support to enable usb3-host functions.
Also add usb command and keyboard config.

Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 5d8a8e28cb..a70ada394f 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -65,6 +65,7 @@ CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=5
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_PCI=y
+CONFIG_CMD_USB=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
@@ -111,3 +112,7 @@ CONFIG_PINCTRL_STARFIVE=y
 CONFIG_SYS_NS16550=y
 CONFIG_CADENCE_QSPI=y
 CONFIG_TIMER_EARLY=y
+CONFIG_USB=y
+CONFIG_USB_XHCI_HCD=y
+CONFIG_USB_XHCI_PCI=y
+CONFIG_USB_KEYBOARD=y
-- 
2.17.1



[PATCH v1 3/4] riscv: starfive: Add SYS_CACHE_SHIFT_6 to enable SYS_CACHE_LINE_SIZE

2023-08-02 Thread Minda Chen
Some devices need SYS_CACHE_LINE_SIZE macro. Add StarFive
SYS_CACHE_SHIFT_6 to enable it.

Signed-off-by: Minda Chen 
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 867cbcbe74..15da2a8559 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -26,6 +26,7 @@ config TARGET_SIFIVE_UNMATCHED
 
 config TARGET_STARFIVE_VISIONFIVE2
bool "Support StarFive VisionFive2 Board"
+   select SYS_CACHE_SHIFT_6
 
 config TARGET_TH1520_LPI4A
bool "Support Sipeed's TH1520 Lichee PI 4A Board"
-- 
2.17.1



[PATCH v1 1/4] pci: plda: Get correct ECAM offset in multiple PCIe RC case

2023-08-02 Thread Minda Chen
Get the correct ECAM offset and record the secondary bus
number in Multiple RC case.

Signed-off-by: Minda Chen 
---
 drivers/pci/pcie_plda_common.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/pcie_plda_common.c b/drivers/pci/pcie_plda_common.c
index 005b92616a..cd74bb4711 100644
--- a/drivers/pci/pcie_plda_common.c
+++ b/drivers/pci/pcie_plda_common.c
@@ -36,8 +36,8 @@ static int plda_pcie_conf_address(const struct udevice *udev, 
pci_dev_t bdf,
  uint offset, void **paddr)
 {
struct pcie_plda *priv = dev_get_priv(udev);
-   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf),
-PCI_FUNC(bdf), offset);
+   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf) - dev_seq(udev),
+PCI_DEV(bdf), PCI_FUNC(bdf), offset);
 
if (!plda_pcie_addr_valid(priv, bdf))
return -ENODEV;
@@ -71,6 +71,7 @@ int plda_pcie_config_write(struct udevice *udev, pci_dev_t 
bdf,
(offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8))) {
priv->sec_busno =
((offset == PCI_PRIMARY_BUS) ? (value >> 8) : value) & 
0xff;
+   priv->sec_busno += dev_seq(udev);
debug("Secondary bus number was changed to %d\n",
  priv->sec_busno);
}
-- 
2.17.1



[PATCH v1 2/4] riscv: dts: starfive: Enable pcie0 dts node

2023-08-02 Thread Minda Chen
In StarFive VF2 board. pcie0 connect to VTI usb controller.
Enable it to support usb host.

Signed-off-by: Minda Chen 
---
 arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index bf7fdb4dd6..e40f57a150 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -311,7 +311,7 @@
 
  {
reset-gpios = < 26 GPIO_ACTIVE_LOW>;
-   status = "disabled";
+   status = "okay";
 };
 
  {
-- 
2.17.1



Re: [PULL] u-boot-riscv/master

2023-08-02 Thread Minda Chen



On 2023/8/2 17:31, Leo Liang wrote:
> Hi Bin,
> 
> On Wed, Aug 02, 2023 at 02:27:29PM +0800, Bin Meng wrote:
>> Hi Leo,
>> 
>> On Wed, Aug 2, 2023 at 1:49 PM Leo Liang  wrote:
>> >
>> > Hi Tom,
>> >
>> > The following changes since commit 
>> > 7755b2200777f72dca87dd169138e95f011bbcb9:
>> >
>> >   Merge tag 'x86-pull-20230801' of 
>> > https://source.denx.de/u-boot/custodians/u-boot-x86 (2023-08-01 11:57:55 
>> > -0400)
>> >
>> > are available in the Git repository at:
>> >
>> >   https://source.denx.de/u-boot/custodians/u-boot-riscv.git
>> >
>> > for you to fetch changes up to 093bd0354e5b947b0bd634bf5ed4041ba075b57d:
>> >
>> >   acpi: Add missing RISC-V acpi_table header (2023-08-02 11:02:33 +0800)
>> >
>> > CI result shows no issue: 
>> > https://source.denx.de/u-boot/custodians/u-boot-riscv/-/pipelines/17177
>> >
>> > 
>> >
>> > + Fix compilation error for CI when enabling RTL8169 driver
>> > + Fix compilation error for pci_mmc.c by adding acpi_table header file
>> > + Support StarFive JH7110 PCIe driver
>> > + Enable PCI on Unmatched board
>> >
>> > 
>> >
>> > Heinrich Schuchardt (2):
>> >   riscv: sifive: initialize PCI on Unmatched
>> >   acpi: Add missing RISC-V acpi_table header
>> >
>> > Mason Huo (3):
>> >   starfive: pci: Add StarFive JH7110 pcie driver
>> >   configs: starfive-jh7110: Add support for PCIe host driver
>> >   riscv: dts: starfive: Enable PCIe host controller
>> >
>> > Minda Chen (5):
>> >   i2c: designware: Add Kconfig for designware_i2c_pci.c
>> >   net: rtl8169: Fix compile warning in rtl8169
>> >   net: rtl8169: Fix DMA minimal aligned compile warning in RISC-V
>> >   net: rtl8169: Add one device ID 0x8161
>> >   configs: starfive-jh7110: Add CONFIG_RTL8169
>> >
>> 
>> Looks the second half of this series is missed?
>> https://patchwork.ozlabs.org/project/uboot/list/?series=365237
>> 
>> Regards,
>> Bin
> 
> Thanks for the reminder!
> I did omit this second half of the series by accident!
> I will re-send the PR again ASAP!
> 
> Best regards,
> Leo
Hi Leo and Bin
Thanks!


Re: [PATCH v8 1/4] i2c: designware: Add Kconfig for designware_i2c_pci.c

2023-08-01 Thread Minda Chen



On 2023/7/26 11:07, Leo Liang wrote:
> On Tue, Jul 25, 2023 at 05:46:47PM +0800, Minda Chen wrote:
>> As the Designware_i2c_pci.c uses ACPI APIs, If some SoCs (StarFive
>> JH7110) contain Designware i2c and PCI but do not use ACPI,
>> This file will be can't be compiled. So add a new Kconfig for
>> designware_i2c_pci.c, which depends on ACPIGEN
>> 
>> Signed-off-by: Minda Chen 
>> ---
>>  drivers/i2c/Kconfig  | 9 +
>>  drivers/i2c/Makefile | 4 +---
>>  2 files changed, 10 insertions(+), 3 deletions(-)
> 
> Reviewed-by: Leo Yu-Chi Liang 

Thanks. Does this patch require Heiko review? 


[PATCH v7 0/4] Add StarFive JH7110 PCIe drvier support

2023-07-25 Thread Minda Chen
These PCIe series patches are based on the JH7110 RISC-V SoC and VisionFive V2 
board.

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

patch1 is for fixing the compile error in designware_i2c_pci.c
while enable designware i2c and PCI.

previous patch version

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
v2: 
https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/
v3: 
https://patchwork.ozlabs.org/project/uboot/cover/20230329100143.10724-1-minda.c...@starfivetech.com/
v4: 
https://patchwork.ozlabs.org/project/uboot/cover/20230411010209.76561-1-minda.c...@starfivetech.com/
v5: 
https://patchwork.ozlabs.org/project/uboot/cover/20230423105859.125764-1-minda.c...@starfivetech.com/
v6: 
https://patchwork.ozlabs.org/project/uboot/cover/20230509082617.119018-1-minda.c...@starfivetech.com/
v7: 
https://patchwork.ozlabs.org/project/uboot/cover/20230720112333.9255-1-minda.c...@starfivetech.com/

changes
  v8
   patch1: Add Kconfig for designware_i2c_pci.c

  v7
   Add patch1 to fix compiling error while enable PCI.
   patch 2 and patch 3 rebase to latest mainline codes.

  v6
   patch 3
1. Change one VisionFive2 config file.
   patch 4
1. remove the pcie interrupt-controller. interrupts setting revert to 
origin.

setting.
  v5
   patch 2
1. split PLDA controller driver codes to pcie_plda_common.c
2. correct the codes of record secondary number. 
   patch 4
1. change the pcie dtsi config. make them the same with kernel.
 
  v4
   patch 2
1. Remove the IDS_REVISION_ID macros.
2. Replace sec_busno to first_busno in starfive_pcie
3. Remove starfive_pcie_off_conf function.
4. Replace "imply" to "depends on" in PCIe Kconfig.
5 .Check sec_busno in starfive_pcie_addr_valid.
 
  v3
   patch 2
1. remove the read vendor ID delay
2. remove starfive_pcie_hide_rc_bar function. do not hide host
bridge BAR write.
3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
4. Add comments for bus and address limitation reason in function
   starfive_pcie_addr_valid
5. Change the multiple line comments in Line 373
6. Using gpio_request_by_name to get PCIe reset gpio,and using
   dm_gpio_set_value set GPIO value.
  patch 3
1. support PCIeboth 12a and 13b vf2 board.  
  patch 4
1. reset dts change to reset-gpio.

  v2
   1. remove clock commit. The pcie clocks change has been includeded in [1].
   2. Using GENMASK marco1 in patch1.
   3. remove the syscon dts node in patch3. The syscon dts dts node has been
  included in [1]. 


Mason Huo (3):
  starfive: pci: Add StarFive JH7110 pcie driver
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

Minda Chen (1):
  i2c: designware: Add Kconfig for designware_i2c_pci.c

 .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
 arch/riscv/dts/jh7110.dtsi|  74 
 configs/starfive_visionfive2_defconfig|   7 +
 drivers/i2c/Kconfig   |   9 +
 drivers/i2c/Makefile  |   4 +-
 drivers/pci/Kconfig   |  13 +
 drivers/pci/Makefile  |   2 +
 drivers/pci/pcie_plda_common.c| 116 +++
 drivers/pci/pcie_plda_common.h| 118 +++
 drivers/pci/pcie_starfive_jh7110.c| 317 ++
 10 files changed, 668 insertions(+), 3 deletions(-)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c


base-commit: e6e67bb9e0a40f3eb3c87d16935192821987c3e0
-- 
2.17.1



[PATCH v8 1/4] i2c: designware: Add Kconfig for designware_i2c_pci.c

2023-07-25 Thread Minda Chen
As the Designware_i2c_pci.c uses ACPI APIs, If some SoCs (StarFive
JH7110) contain Designware i2c and PCI but do not use ACPI,
This file will be can't be compiled. So add a new Kconfig for
designware_i2c_pci.c, which depends on ACPIGEN

Signed-off-by: Minda Chen 
---
 drivers/i2c/Kconfig  | 9 +
 drivers/i2c/Makefile | 4 +---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 5e81698143..4c76fd7e41 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -231,6 +231,15 @@ config SYS_I2C_DW
  controller is used in various SoCs, e.g. the ST SPEAr, Altera
  SoCFPGA, Synopsys ARC700 and some Intel x86 SoCs.
 
+config SYS_I2C_DW_PCI
+   bool "Designware PCI I2C Controller"
+   depends on SYS_I2C_DW && PCI && ACPIGEN
+   default y
+   help
+ Say yes here to select the Designware PCI I2C Host Controller.
+ This PCI I2C controller is the base on Desigware I2C host
+ controller.
+
 config SYS_I2C_AST2600
 bool "AST2600 I2C Controller"
 depends on DM_I2C && ARCH_ASPEED
diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 99545df2e5..d5b85f398d 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -18,9 +18,7 @@ obj-$(CONFIG_SYS_I2C_CADENCE) += i2c-cdns.o
 obj-$(CONFIG_SYS_I2C_CA) += i2c-cortina.o
 obj-$(CONFIG_SYS_I2C_DAVINCI) += davinci_i2c.o
 obj-$(CONFIG_SYS_I2C_DW) += designware_i2c.o
-ifdef CONFIG_PCI
-obj-$(CONFIG_SYS_I2C_DW) += designware_i2c_pci.o
-endif
+obj-$(CONFIG_SYS_I2C_DW_PCI) += designware_i2c_pci.o
 obj-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o
 obj-$(CONFIG_SYS_I2C_IHS) += ihs_i2c.o
 obj-$(CONFIG_SYS_I2C_INTEL) += intel_i2c.o
-- 
2.17.1



[PATCH v8 4/4] riscv: dts: starfive: Enable PCIe host controller

2023-07-25 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
Reviewed-by: Leo Yu-Chi Liang 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi | 11 +++
 arch/riscv/dts/jh7110.dtsi| 74 +++
 2 files changed, 85 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index 710b082766..54a147c7d0 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -7,6 +7,7 @@
 
 #include "jh7110.dtsi"
 #include 
+#include 
 / {
aliases {
serial0 = 
@@ -308,6 +309,16 @@
};
 };
 
+ {
+   reset-gpios = < 26 GPIO_ACTIVE_LOW>;
+   status = "disabled";
+};
+
+ {
+   reset-gpios = < 28 GPIO_ACTIVE_LOW>;
+   status = "okay";
+};
+
  {
assigned-clocks = < JH7110_SYSCLK_CPU_ROOT>,
  < JH7110_SYSCLK_BUS_ROOT>,
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index 58e332e9d7..72d0251da6 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -638,5 +638,79 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   pcie0: pcie@2b00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2b00 0x0 0x100
+  0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3000  0x0 0x3000 
0x0 0x0800>,
+<0xc300  0x9 0x  0x9 0x 
0x0 0x4000>;
+   interrupts = <56>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   msi-parent = <>;
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0xc0 0xc4 0x130 
0x1b8>;
+   bus-range = <0x0 0xff>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_STG_AXI>,
+< JH7110_STGCLK_PCIE0_TL>,
+< JH7110_STGCLK_PCIE0_AXI>,
+< JH7110_STGCLK_PCIE0_APB>;
+   clock-names = "noc", "tl", "axi", "apb";
+   resets = < JH7110_STGRST_PCIE0_MST0>,
+< JH7110_STGRST_PCIE0_SLV0>,
+< JH7110_STGRST_PCIE0_SLV>,
+< JH7110_STGRST_PCIE0_BRG>,
+< JH7110_STGRST_PCIE0_CORE>,
+< JH7110_STGRST_PCIE0_APB>;
+   reset-names = "mst0", "slv0", "slv", "brg",
+ "core", "apb";
+   status = "disabled";
+   };
+
+   pcie1: pcie@2c00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2c00 0x0 0x100
+  0x9 0xc000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3800  0x0 0x3800 
0x0 0x0800>,
+<0xc300  0x9 0x8000  0x9 0x8000 
0x0 0x4000>;
+   interrupts = <57>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   msi-parent = <>;
+   device_type = &

[PATCH v8 2/4] starfive: pci: Add StarFive JH7110 pcie driver

2023-07-25 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, Also add PLDA
PCIe controller common driver functions.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
Acked-by: Pali Rohár 
Reviewed-by: Leo Yu-Chi Liang 
---
 drivers/pci/Kconfig|  13 ++
 drivers/pci/Makefile   |   2 +
 drivers/pci/pcie_plda_common.c | 116 +++
 drivers/pci/pcie_plda_common.h | 118 +++
 drivers/pci/pcie_starfive_jh7110.c | 317 +
 5 files changed, 566 insertions(+)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 84a2ae951f..fa21d60ce9 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -387,4 +387,17 @@ config PCIE_XILINX_NWL
 Say 'Y' here if you want support for Xilinx / AMD NWL PCIe
 controller as Root Port.
 
+config PCIE_PLDA_COMMON
+   bool
+
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   select PCIE_PLDA_COMMON
+   imply STARFIVE_JH7110
+   imply CLK_JH7110
+   imply RESET_JH7110
+   help
+ Say Y here if you want to enable PLDA XpressRich PCIe controller
+ support on StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 11f60c6991..a712a317a3 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -50,3 +50,5 @@ obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
 obj-$(CONFIG_PCIE_XILINX_NWL) += pcie-xilinx-nwl.o
+obj-$(CONFIG_PCIE_PLDA_COMMON) += pcie_plda_common.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_plda_common.c b/drivers/pci/pcie_plda_common.c
new file mode 100644
index 00..005b92616a
--- /dev/null
+++ b/drivers/pci/pcie_plda_common.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * PLDA XpressRich PCIe host controller common functions.
+ *
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "pcie_plda_common.h"
+
+static bool plda_pcie_addr_valid(struct pcie_plda *plda, pci_dev_t bdf)
+{
+   /*
+* Single device limitation.
+* PCIe controller contain HW issue that secondary bus of
+* host bridge emumerate duplicate devices.
+* Only can access device 0 in secondary bus.
+*/
+   if (PCI_BUS(bdf) == plda->sec_busno && PCI_DEV(bdf) > 0)
+   return false;
+
+   return true;
+}
+
+static int plda_pcie_conf_address(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, void **paddr)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf),
+PCI_FUNC(bdf), offset);
+
+   if (!plda_pcie_addr_valid(priv, bdf))
+   return -ENODEV;
+
+   *paddr = (void *)(priv->cfg_base + where);
+   return 0;
+}
+
+int plda_pcie_config_read(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, ulong *valuep,
+ enum pci_size_t size)
+{
+   return pci_generic_mmap_read_config(udev, plda_pcie_conf_address,
+   bdf, offset, valuep, size);
+}
+
+int plda_pcie_config_write(struct udevice *udev, pci_dev_t bdf,
+  uint offset, ulong value,
+  enum pci_size_t size)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int ret;
+
+   ret = pci_generic_mmap_write_config(udev, plda_pcie_conf_address,
+   bdf, offset, value, size);
+
+   /* record secondary bus number */
+   if (!ret && PCI_BUS(bdf) == dev_seq(udev) &&
+   PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+   (offset == PCI_SECONDARY_BUS ||
+   (offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8))) {
+   priv->sec_busno =
+   ((offset == PCI_PRIMARY_BUS) ? (value >> 8) : value) & 
0xff;
+   debug("Secondary bus number was changed to %d\n",
+ priv->sec_busno);
+   }
+   return ret;
+}
+
+int plda_pcie_set_atr_entry(struct pcie_plda *plda, phys_addr_t src_addr,
+   phys_addr_t trsl_addr, phys_size_t window_size,
+   int trsl_param)
+{
+   void __iomem *base =
+   plda->reg_base + XR3PCI_ATR_AXI4_SLV0;
+
+   /* Support AXI4 Slave 0 Address Translation 

[PATCH v8 3/4] configs: starfive-jh7110: Add support for PCIe host driver

2023-07-25 Thread Minda Chen
From: Mason Huo 

Add PCIe host driver and nvme driver in configure file.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
Reviewed-by: Leo Yu-Chi Liang 
---
 configs/starfive_visionfive2_defconfig | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 570a1f53a1..ad701132fa 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -19,6 +19,8 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
+CONFIG_PCI=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -62,6 +64,7 @@ CONFIG_SYS_EEPROM_PAGE_WRITE_BITS=4
 CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=5
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
@@ -92,6 +95,10 @@ CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_STARFIVE=y
 CONFIG_RGMII=y
 CONFIG_RMII=y
+CONFIG_NVME_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
+CONFIG_PCIE_STARFIVE_JH7110=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



Re: [PATCH v7 1/4] i2c: designware: Add CONFIG_ACPIGEN limitation to designware_i2c_pci.c

2023-07-20 Thread Minda Chen



On 2023/7/21 3:42, Simon Glass wrote:
> Hi,
> 
> On Thu, 20 Jul 2023 at 05:24, Minda Chen  wrote:
>>
>> As the designware_i2c_pci.c uses ACPI APIs, If some SoCs (StarFive
>> JH7110) contain designware i2c and PCI but do not use ACPI,
>> This file will be can't be compiled. So add ACPIGEN to
>> designware_i2c_pci.c
>>
>> Signed-off-by: Minda Chen 
>> ---
>>  drivers/i2c/Makefile | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
>> index 99545df2e5..92b1ec6bc3 100644
>> --- a/drivers/i2c/Makefile
>> +++ b/drivers/i2c/Makefile
>> @@ -18,9 +18,11 @@ obj-$(CONFIG_SYS_I2C_CADENCE) += i2c-cdns.o
>>  obj-$(CONFIG_SYS_I2C_CA) += i2c-cortina.o
>>  obj-$(CONFIG_SYS_I2C_DAVINCI) += davinci_i2c.o
>>  obj-$(CONFIG_SYS_I2C_DW) += designware_i2c.o
>> +ifdef CONFIG_ACPIGEN
> 
> You should use Kconfig to see SYS_I2C_DW depends on ACPIGEN. You might
> need a separate I2C_DW_PCI Kconfig.
> 
I think so.

I can add Kconfig like this.
config SYS_I2C_DW_PCI
bool "Designware PCI I2C Controller"
depends on SYS_I2C_DW && PCI && APIGEN
default y

> But that sounds bad to me. Why does it have to generate ACPI tables?
> It should work fine without that.
> 
designware_i2c_pci.c contain ACPI and lpss related codes.
>>  ifdef CONFIG_PCI
>>  obj-$(CONFIG_SYS_I2C_DW) += designware_i2c_pci.o
>>  endif
>> +endif
>>  obj-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o
>>  obj-$(CONFIG_SYS_I2C_IHS) += ihs_i2c.o
>>  obj-$(CONFIG_SYS_I2C_INTEL) += intel_i2c.o
>> --
>> 2.17.1
>>
> 
> Regards,
> Simon


[PATCH v2 3/4] net: rtl8169: Add one device ID 0x8161

2023-07-20 Thread Minda Chen
Add rtl8169 NIC device ID and reorder the device ID.

Signed-off-by: Minda Chen 
---
 drivers/net/rtl8169.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 34e4cff1e9..963702777c 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -353,10 +353,11 @@ static const unsigned int rtl8169_rx_config =
 (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
 
 static struct pci_device_id supported[] = {
+   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8125) },
+   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169) },
-   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8125) },
{}
 };
 
@@ -1051,8 +1052,9 @@ static int rtl8169_eth_probe(struct udevice *dev)
int ret;
 
switch (pplat->device) {
-   case 0x8168:
case 0x8125:
+   case 0x8161:
+   case 0x8168:
region = 2;
break;
default:
-- 
2.17.1



[PATCH v2 0/4] Fix rtl8169 compile warning and add a new device ID

2023-07-20 Thread Minda Chen
StarFive JH7110 uboot support PCIe and using rtl8169 network adapter
PCIe device. But compile warning in rtl8169 driver cause CI test fail.
So commit this patch set to fix it, Also a new device ID to adjust the
PCI bar regions in rtl8169.

The StarFive JH7110 PCIe driver link, patch 4 rely on this.
https://patchwork.ozlabs.org/project/uboot/cover/20230720112333.9255-1-minda.c...@starfivetech.com/

previous version:
[1] 
https://patchwork.ozlabs.org/project/uboot/cover/20230621090540.119313-1-minda.c...@starfivetech.com/

change:
v2: patch 1- 3 modify the commit messages.
rebase to latest mainline codes.

patch 1 is fix make pointer from integer warning.
 eg: /home/minda/vf2/visionfive/u-boot/drivers/net/rtl8169.c:103:52: warning:
passing argument 2 of ‘writew’ makes pointer from integer without a cast 
[-Wint-conversion]
patch 2 fix RISC-V 8169 descriptor less than DMA min aligned size warning
patch 3 add new device ID
patch 4 enable 8169 in JH7110 SoC configs file.

Minda Chen (4):
  net: rtl8169: Fix compile warning in rtl8169
  net: rtl8169: Fix DMA minimal aligned compile warning in RISC-V
  net: rtl8169: Add one device ID 0x8161
  configs: starfive-jh7110: Add CONFIG_RTL8169

 configs/starfive_visionfive2_defconfig |  1 +
 drivers/net/rtl8169.c  | 22 +-
 2 files changed, 14 insertions(+), 9 deletions(-)


base-commit: e6e67bb9e0a40f3eb3c87d16935192821987c3e0
-- 
2.17.1



[PATCH v2 4/4] configs: starfive-jh7110: Add CONFIG_RTL8169

2023-07-20 Thread Minda Chen
Add PCIe device rtl8169 net adapter driver support.

Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 59e39c6f9b..7fc1569b59 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -95,6 +95,7 @@ CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_STARFIVE=y
 CONFIG_RGMII=y
 CONFIG_RMII=y
+CONFIG_RTL8169=y
 CONFIG_NVME_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 # CONFIG_PCI_PNP is not set
-- 
2.17.1



[PATCH v2 1/4] net: rtl8169: Fix compile warning in rtl8169

2023-07-20 Thread Minda Chen
While compiling rtl8169.c, There are many "make pointer from
integer without a cast" compile warnings. fix them with
adding cast.

Signed-off-by: Minda Chen 
---
 drivers/net/rtl8169.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 2276a465e7..dcba51590d 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -96,12 +96,12 @@ static int media[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, 
-1 };
 #define TX_TIMEOUT  (6*HZ)
 
 /* write/read MMIO register. Notice: {read,write}[wl] do the necessary 
swapping */
-#define RTL_W8(reg, val8)  writeb((val8), ioaddr + (reg))
-#define RTL_W16(reg, val16)writew((val16), ioaddr + (reg))
-#define RTL_W32(reg, val32)writel((val32), ioaddr + (reg))
-#define RTL_R8(reg)readb(ioaddr + (reg))
-#define RTL_R16(reg)   readw(ioaddr + (reg))
-#define RTL_R32(reg)   readl(ioaddr + (reg))
+#define RTL_W8(reg, val8)  writeb((val8), (void *)(ioaddr + (reg)))
+#define RTL_W16(reg, val16)writew((val16), (void *)(ioaddr + (reg)))
+#define RTL_W32(reg, val32)writel((val32), (void *)(ioaddr + (reg)))
+#define RTL_R8(reg)readb((void *)(ioaddr + (reg)))
+#define RTL_R16(reg)   readw((void *)(ioaddr + (reg)))
+#define RTL_R32(reg)   readl((void *)(ioaddr + (reg)))
 
 #define bus_to_phys(a) pci_mem_to_phys((pci_dev_t)(unsigned long)dev->priv, \
(pci_addr_t)(unsigned long)a)
-- 
2.17.1



[PATCH v2 2/4] net: rtl8169: Fix DMA minimal aligned compile warning in RISC-V

2023-07-20 Thread Minda Chen
For RISC-V architeture, hardware maintain the dcache coherency.
Software do not flush the cache. So even cache-line size larger
than descriptor size, driver can work.

Signed-off-by: Minda Chen 
---
 drivers/net/rtl8169.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index dcba51590d..34e4cff1e9 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -311,10 +311,12 @@ static unsigned char rxdata[RX_BUF_LEN];
  *
  * This can be fixed by defining CONFIG_SYS_NONCACHED_MEMORY which will cause
  * the driver to allocate descriptors from a pool of non-cached memory.
+ *
+ * Hardware maintain D-cache coherency in RISC-V architecture.
  */
 #if RTL8169_DESC_SIZE < ARCH_DMA_MINALIGN
 #if !defined(CONFIG_SYS_NONCACHED_MEMORY) && \
-   !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) && !defined(CONFIG_X86)
+   !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) && !defined(CONFIG_X86) && 
!defined(CONFIG_RISCV)
 #warning cache-line size is larger than descriptor size
 #endif
 #endif
-- 
2.17.1



[PATCH v7 2/4] starfive: pci: Add StarFive JH7110 pcie driver

2023-07-20 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, Also add PLDA
PCIe controller common driver functions.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
Acked-by: Pali Rohár 
---
 drivers/pci/Kconfig|  13 ++
 drivers/pci/Makefile   |   2 +
 drivers/pci/pcie_plda_common.c | 116 +++
 drivers/pci/pcie_plda_common.h | 118 +++
 drivers/pci/pcie_starfive_jh7110.c | 317 +
 5 files changed, 566 insertions(+)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 84a2ae951f..fa21d60ce9 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -387,4 +387,17 @@ config PCIE_XILINX_NWL
 Say 'Y' here if you want support for Xilinx / AMD NWL PCIe
 controller as Root Port.
 
+config PCIE_PLDA_COMMON
+   bool
+
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   select PCIE_PLDA_COMMON
+   imply STARFIVE_JH7110
+   imply CLK_JH7110
+   imply RESET_JH7110
+   help
+ Say Y here if you want to enable PLDA XpressRich PCIe controller
+ support on StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 11f60c6991..a712a317a3 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -50,3 +50,5 @@ obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
 obj-$(CONFIG_PCIE_XILINX_NWL) += pcie-xilinx-nwl.o
+obj-$(CONFIG_PCIE_PLDA_COMMON) += pcie_plda_common.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_plda_common.c b/drivers/pci/pcie_plda_common.c
new file mode 100644
index 00..005b92616a
--- /dev/null
+++ b/drivers/pci/pcie_plda_common.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * PLDA XpressRich PCIe host controller common functions.
+ *
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "pcie_plda_common.h"
+
+static bool plda_pcie_addr_valid(struct pcie_plda *plda, pci_dev_t bdf)
+{
+   /*
+* Single device limitation.
+* PCIe controller contain HW issue that secondary bus of
+* host bridge emumerate duplicate devices.
+* Only can access device 0 in secondary bus.
+*/
+   if (PCI_BUS(bdf) == plda->sec_busno && PCI_DEV(bdf) > 0)
+   return false;
+
+   return true;
+}
+
+static int plda_pcie_conf_address(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, void **paddr)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf),
+PCI_FUNC(bdf), offset);
+
+   if (!plda_pcie_addr_valid(priv, bdf))
+   return -ENODEV;
+
+   *paddr = (void *)(priv->cfg_base + where);
+   return 0;
+}
+
+int plda_pcie_config_read(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, ulong *valuep,
+ enum pci_size_t size)
+{
+   return pci_generic_mmap_read_config(udev, plda_pcie_conf_address,
+   bdf, offset, valuep, size);
+}
+
+int plda_pcie_config_write(struct udevice *udev, pci_dev_t bdf,
+  uint offset, ulong value,
+  enum pci_size_t size)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int ret;
+
+   ret = pci_generic_mmap_write_config(udev, plda_pcie_conf_address,
+   bdf, offset, value, size);
+
+   /* record secondary bus number */
+   if (!ret && PCI_BUS(bdf) == dev_seq(udev) &&
+   PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+   (offset == PCI_SECONDARY_BUS ||
+   (offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8))) {
+   priv->sec_busno =
+   ((offset == PCI_PRIMARY_BUS) ? (value >> 8) : value) & 
0xff;
+   debug("Secondary bus number was changed to %d\n",
+ priv->sec_busno);
+   }
+   return ret;
+}
+
+int plda_pcie_set_atr_entry(struct pcie_plda *plda, phys_addr_t src_addr,
+   phys_addr_t trsl_addr, phys_size_t window_size,
+   int trsl_param)
+{
+   void __iomem *base =
+   plda->reg_base + XR3PCI_ATR_AXI4_SLV0;
+
+   /* Support AXI4 Slave 0 Address Translation Tables 0-7. */
+   if (plda->

[PATCH v7 1/4] i2c: designware: Add CONFIG_ACPIGEN limitation to designware_i2c_pci.c

2023-07-20 Thread Minda Chen
As the designware_i2c_pci.c uses ACPI APIs, If some SoCs (StarFive
JH7110) contain designware i2c and PCI but do not use ACPI,
This file will be can't be compiled. So add ACPIGEN to
designware_i2c_pci.c

Signed-off-by: Minda Chen 
---
 drivers/i2c/Makefile | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/i2c/Makefile b/drivers/i2c/Makefile
index 99545df2e5..92b1ec6bc3 100644
--- a/drivers/i2c/Makefile
+++ b/drivers/i2c/Makefile
@@ -18,9 +18,11 @@ obj-$(CONFIG_SYS_I2C_CADENCE) += i2c-cdns.o
 obj-$(CONFIG_SYS_I2C_CA) += i2c-cortina.o
 obj-$(CONFIG_SYS_I2C_DAVINCI) += davinci_i2c.o
 obj-$(CONFIG_SYS_I2C_DW) += designware_i2c.o
+ifdef CONFIG_ACPIGEN
 ifdef CONFIG_PCI
 obj-$(CONFIG_SYS_I2C_DW) += designware_i2c_pci.o
 endif
+endif
 obj-$(CONFIG_SYS_I2C_FSL) += fsl_i2c.o
 obj-$(CONFIG_SYS_I2C_IHS) += ihs_i2c.o
 obj-$(CONFIG_SYS_I2C_INTEL) += intel_i2c.o
-- 
2.17.1



[PATCH v7 4/4] riscv: dts: starfive: Enable PCIe host controller

2023-07-20 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi | 11 +++
 arch/riscv/dts/jh7110.dtsi| 74 +++
 2 files changed, 85 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index 710b082766..54a147c7d0 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -7,6 +7,7 @@
 
 #include "jh7110.dtsi"
 #include 
+#include 
 / {
aliases {
serial0 = 
@@ -308,6 +309,16 @@
};
 };
 
+ {
+   reset-gpios = < 26 GPIO_ACTIVE_LOW>;
+   status = "disabled";
+};
+
+ {
+   reset-gpios = < 28 GPIO_ACTIVE_LOW>;
+   status = "okay";
+};
+
  {
assigned-clocks = < JH7110_SYSCLK_CPU_ROOT>,
  < JH7110_SYSCLK_BUS_ROOT>,
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index 58e332e9d7..72d0251da6 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -638,5 +638,79 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   pcie0: pcie@2b00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2b00 0x0 0x100
+  0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3000  0x0 0x3000 
0x0 0x0800>,
+<0xc300  0x9 0x  0x9 0x 
0x0 0x4000>;
+   interrupts = <56>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   msi-parent = <>;
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0xc0 0xc4 0x130 
0x1b8>;
+   bus-range = <0x0 0xff>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_STG_AXI>,
+< JH7110_STGCLK_PCIE0_TL>,
+< JH7110_STGCLK_PCIE0_AXI>,
+< JH7110_STGCLK_PCIE0_APB>;
+   clock-names = "noc", "tl", "axi", "apb";
+   resets = < JH7110_STGRST_PCIE0_MST0>,
+< JH7110_STGRST_PCIE0_SLV0>,
+< JH7110_STGRST_PCIE0_SLV>,
+< JH7110_STGRST_PCIE0_BRG>,
+< JH7110_STGRST_PCIE0_CORE>,
+< JH7110_STGRST_PCIE0_APB>;
+   reset-names = "mst0", "slv0", "slv", "brg",
+ "core", "apb";
+   status = "disabled";
+   };
+
+   pcie1: pcie@2c00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2c00 0x0 0x100
+  0x9 0xc000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3800  0x0 0x3800 
0x0 0x0800>,
+<0xc300  0x9 0x8000  0x9 0x8000 
0x0 0x4000>;
+   interrupts = <57>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   msi-parent = <>;
+   device_type = "pci";
+

[PATCH v7 3/4] configs: starfive-jh7110: Add support for PCIe host driver

2023-07-20 Thread Minda Chen
From: Mason Huo 

Add PCIe host driver and nvme driver in configure file.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 8 
 1 file changed, 8 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 570a1f53a1..59e39c6f9b 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -19,6 +19,8 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
+CONFIG_PCI=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -62,6 +64,7 @@ CONFIG_SYS_EEPROM_PAGE_WRITE_BITS=4
 CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS=5
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_I2C=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_OF_BOARD=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
@@ -92,6 +95,11 @@ CONFIG_DWC_ETH_QOS=y
 CONFIG_DWC_ETH_QOS_STARFIVE=y
 CONFIG_RGMII=y
 CONFIG_RMII=y
+CONFIG_NVME_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+# CONFIG_PCI_PNP is not set
+CONFIG_PCI_REGION_MULTI_ENTRY=y
+CONFIG_PCIE_STARFIVE_JH7110=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



[PATCH v7 0/4] Add StarFive JH7110 PCIe drvier support

2023-07-20 Thread Minda Chen
These PCIe series patches are based on the JH7110 RISC-V SoC and VisionFive V2 
board.

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

patch1 is for fixing the compile error in designware_i2c_pci.c
while enable designware i2c and PCI.

previous patch version

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
v2: 
https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/
v3: 
https://patchwork.ozlabs.org/project/uboot/cover/20230329100143.10724-1-minda.c...@starfivetech.com/
v4: 
https://patchwork.ozlabs.org/project/uboot/cover/20230411010209.76561-1-minda.c...@starfivetech.com/
v5: 
https://patchwork.ozlabs.org/project/uboot/cover/20230423105859.125764-1-minda.c...@starfivetech.com/
v6: 
https://patchwork.ozlabs.org/project/uboot/cover/20230509082617.119018-1-minda.c...@starfivetech.com/

changes
  v7
   Add patch1 to fix compiling error while enable PCI.
   patch 2 and patch 3 rebase to latest mainline codes.

  v6
   patch 3
1. Change one VisionFive2 config file.
   patch 4
1. remove the pcie interrupt-controller. interrupts setting revert to 
origin.

setting.
  v5
   patch 2
1. split PLDA controller driver codes to pcie_plda_common.c
2. correct the codes of record secondary number. 
   patch 4
1. change the pcie dtsi config. make them the same with kernel.
 
  v4
   patch 2
1. Remove the IDS_REVISION_ID macros.
2. Replace sec_busno to first_busno in starfive_pcie
3. Remove starfive_pcie_off_conf function.
4. Replace "imply" to "depends on" in PCIe Kconfig.
5 .Check sec_busno in starfive_pcie_addr_valid.
 
  v3
   patch 2
1. remove the read vendor ID delay
2. remove starfive_pcie_hide_rc_bar function. do not hide host
bridge BAR write.
3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
4. Add comments for bus and address limitation reason in function
   starfive_pcie_addr_valid
5. Change the multiple line comments in Line 373
6. Using gpio_request_by_name to get PCIe reset gpio,and using
   dm_gpio_set_value set GPIO value.
  patch 3
1. support PCIeboth 12a and 13b vf2 board.  
  patch 4
1. reset dts change to reset-gpio.

  v2
   1. remove clock commit. The pcie clocks change has been includeded in [1].
   2. Using GENMASK marco1 in patch1.
   3. remove the syscon dts node in patch3. The syscon dts dts node has been
  included in [1]. 


Mason Huo (3):
  starfive: pci: Add StarFive JH7110 pcie driver
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

Minda Chen (1):
  i2c: designware: Add CONFIG_ACPIGEN limitation to designware_i2c_pci.c

 .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
 arch/riscv/dts/jh7110.dtsi|  74 
 configs/starfive_visionfive2_defconfig|   8 +
 drivers/i2c/Makefile  |   2 +
 drivers/pci/Kconfig   |  13 +
 drivers/pci/Makefile  |   2 +
 drivers/pci/pcie_plda_common.c| 116 +++
 drivers/pci/pcie_plda_common.h| 118 +++
 drivers/pci/pcie_starfive_jh7110.c| 317 ++
 9 files changed, 661 insertions(+)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c


base-commit: e6e67bb9e0a40f3eb3c87d16935192821987c3e0
-- 
2.17.1



Re: [PATCH v1 0/4] Fix rtl8169 compile warning and add a new device ID

2023-07-04 Thread Minda Chen


Hi Joe and Ramon

 Sorry to disturb you. Could you please review this patchset. Thanks

On 2023/6/21 17:05, Minda Chen wrote:
> StarFive JH7110 uboot support PCIe and using rtl8169 network adapter
> PCIe device. But compile warning in rtl8169 driver cause CI test fail.
> So commit this patch set to fix it, Also a new device ID to adjust the
> PCI bar regions in rtl8169.
> 
> The StarFive JH7110 PCIe driver link:
> https://patchwork.ozlabs.org/project/uboot/cover/20230509082617.119018-1-minda.c...@starfivetech.com/
> 
> patch 1 is fix make pointer from integer warning.
>  eg: /home/minda/vf2/visionfive/u-boot/drivers/net/rtl8169.c:103:52: warning:
> passing argument 2 of ‘writew’ makes pointer from integer without a cast 
> [-Wint-conversion]
> patch 2 fix RISC-V 8169 descriptor less than DMA min aligned size warning
> patch 3 add new device ID
> patch 4 enable 8169 in JH7110 SoC configs file.
> 
> Minda Chen (4):
>   net: rtl8169: Fix compile warning in rtl8169 network adapter
>   net: rtl8169: Fix DMA min aligned compile warning in riscv
>   net: rtl8169: Add one more device ID
>   configs: starfive-jh7110: Add CONFIG_RTL8169
> 
>  configs/starfive_visionfive2_defconfig |  1 +
>  drivers/net/rtl8169.c  | 22 +-
>  2 files changed, 14 insertions(+), 9 deletions(-)
> 
> 
> base-commit: 50842b217fef505a0ec6662cc2acdc55d0bb23c5


[PATCH v1 3/4] net: rtl8169: Add one more device ID

2023-06-21 Thread Minda Chen
Add the NIC device ID and adjust the PCI bar regions.

Signed-off-by: Minda Chen 
---
 drivers/net/rtl8169.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 34e4cff1e9..963702777c 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -353,10 +353,11 @@ static const unsigned int rtl8169_rx_config =
 (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
 
 static struct pci_device_id supported[] = {
+   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8125) },
+   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168) },
{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169) },
-   { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8125) },
{}
 };
 
@@ -1051,8 +1052,9 @@ static int rtl8169_eth_probe(struct udevice *dev)
int ret;
 
switch (pplat->device) {
-   case 0x8168:
case 0x8125:
+   case 0x8161:
+   case 0x8168:
region = 2;
break;
default:
-- 
2.17.1



[PATCH v1 4/4] configs: starfive-jh7110: Add CONFIG_RTL8169

2023-06-21 Thread Minda Chen
Add PCIe device rtl8169 net adapter driver support.

Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index ffbc4b9476..360160200f 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -66,6 +66,7 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



[PATCH v1 2/4] net: rtl8169: Fix DMA min aligned compile warning in riscv

2023-06-21 Thread Minda Chen
Fix rtl8169 descriptor less the DMA min aligned compile warning
for RISC-V SoC platform.

Signed-off-by: Minda Chen 
---
 drivers/net/rtl8169.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index dcba51590d..34e4cff1e9 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -311,10 +311,12 @@ static unsigned char rxdata[RX_BUF_LEN];
  *
  * This can be fixed by defining CONFIG_SYS_NONCACHED_MEMORY which will cause
  * the driver to allocate descriptors from a pool of non-cached memory.
+ *
+ * Hardware maintain D-cache coherency in RISC-V architecture.
  */
 #if RTL8169_DESC_SIZE < ARCH_DMA_MINALIGN
 #if !defined(CONFIG_SYS_NONCACHED_MEMORY) && \
-   !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) && !defined(CONFIG_X86)
+   !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) && !defined(CONFIG_X86) && 
!defined(CONFIG_RISCV)
 #warning cache-line size is larger than descriptor size
 #endif
 #endif
-- 
2.17.1



[PATCH v1 0/4] Fix rtl8169 compile warning and add a new device ID

2023-06-21 Thread Minda Chen
StarFive JH7110 uboot support PCIe and using rtl8169 network adapter
PCIe device. But compile warning in rtl8169 driver cause CI test fail.
So commit this patch set to fix it, Also a new device ID to adjust the
PCI bar regions in rtl8169.

The StarFive JH7110 PCIe driver link:
https://patchwork.ozlabs.org/project/uboot/cover/20230509082617.119018-1-minda.c...@starfivetech.com/

patch 1 is fix make pointer from integer warning.
 eg: /home/minda/vf2/visionfive/u-boot/drivers/net/rtl8169.c:103:52: warning:
passing argument 2 of ‘writew’ makes pointer from integer without a cast 
[-Wint-conversion]
patch 2 fix RISC-V 8169 descriptor less than DMA min aligned size warning
patch 3 add new device ID
patch 4 enable 8169 in JH7110 SoC configs file.

Minda Chen (4):
  net: rtl8169: Fix compile warning in rtl8169 network adapter
  net: rtl8169: Fix DMA min aligned compile warning in riscv
  net: rtl8169: Add one more device ID
  configs: starfive-jh7110: Add CONFIG_RTL8169

 configs/starfive_visionfive2_defconfig |  1 +
 drivers/net/rtl8169.c  | 22 +-
 2 files changed, 14 insertions(+), 9 deletions(-)


base-commit: 50842b217fef505a0ec6662cc2acdc55d0bb23c5
-- 
2.17.1



[PATCH v1 1/4] net: rtl8169: Fix compile warning in rtl8169 network adapter

2023-06-21 Thread Minda Chen
Fix make pointer from integer without a cast compile warning.

Signed-off-by: Minda Chen 
---
 drivers/net/rtl8169.c | 12 ++--
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/rtl8169.c b/drivers/net/rtl8169.c
index 2276a465e7..dcba51590d 100644
--- a/drivers/net/rtl8169.c
+++ b/drivers/net/rtl8169.c
@@ -96,12 +96,12 @@ static int media[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, 
-1 };
 #define TX_TIMEOUT  (6*HZ)
 
 /* write/read MMIO register. Notice: {read,write}[wl] do the necessary 
swapping */
-#define RTL_W8(reg, val8)  writeb((val8), ioaddr + (reg))
-#define RTL_W16(reg, val16)writew((val16), ioaddr + (reg))
-#define RTL_W32(reg, val32)writel((val32), ioaddr + (reg))
-#define RTL_R8(reg)readb(ioaddr + (reg))
-#define RTL_R16(reg)   readw(ioaddr + (reg))
-#define RTL_R32(reg)   readl(ioaddr + (reg))
+#define RTL_W8(reg, val8)  writeb((val8), (void *)(ioaddr + (reg)))
+#define RTL_W16(reg, val16)writew((val16), (void *)(ioaddr + (reg)))
+#define RTL_W32(reg, val32)writel((val32), (void *)(ioaddr + (reg)))
+#define RTL_R8(reg)readb((void *)(ioaddr + (reg)))
+#define RTL_R16(reg)   readw((void *)(ioaddr + (reg)))
+#define RTL_R32(reg)   readl((void *)(ioaddr + (reg)))
 
 #define bus_to_phys(a) pci_mem_to_phys((pci_dev_t)(unsigned long)dev->priv, \
(pci_addr_t)(unsigned long)a)
-- 
2.17.1



Re: [PATCH v6 0/3] Add StarFive JH7110 PCIe drvier support

2023-06-16 Thread Minda Chen



On 2023/6/16 16:42, Leo Liang wrote:
> Hi Minda,
> 
> On Thu, Jun 01, 2023 at 09:07:14AM +0800, Minda Chen wrote:
>> 
>> Hi Rick and Leo
>> Could you review these series patches? Thanks.
>> Since patch 1 was acked by Pali, Does it mean patch 1 is accepted? 
> 
> I think acked-by means that the patch is considered good enough to be merged.
> 
> Aside from that, your patchset caused CI error by enabling the RTL8169 driver.
> Could you take a look at it ? 
> (https://source.denx.de/u-boot/custodians/u-boot-riscv/-/jobs/638021)
> It's mostly compilation warnings that are being treated as errors.
> The patchset looks good to me, I could merge the patchset as soon as the CI 
> errors are fixed!
> 
> Thanks & best regards,
> Leo
> 
Thanks. I will commit another patch to fix the warning.
 
>> On 2023/5/9 16:26, Minda Chen wrote:
>> > These PCIe series patches are based on the JH7110 RISC-V SoC and 
>> > VisionFive V2 board.
>> > 
>> > The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
>> > The PCIe dts configuation includes all these setting.
>> > 
>> > The PCIe drivers codes has been tested on the VisionFive V2 boards.
>> > The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.
>> > 
>> > previous patch version
>> > 
>> > v1: 
>> > https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
>> > v2: 
>> > https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/
>> > v3: 
>> > https://patchwork.ozlabs.org/project/uboot/cover/20230329100143.10724-1-minda.c...@starfivetech.com/
>> > v4: 
>> > https://patchwork.ozlabs.org/project/uboot/cover/20230411010209.76561-1-minda.c...@starfivetech.com/
>> > v5: 
>> > https://patchwork.ozlabs.org/project/uboot/cover/20230423105859.125764-1-minda.c...@starfivetech.com/
>> > 
>> > changes
>> >   v6
>> >patch 2
>> > 1. Change one VisionFive2 config file.
>> >patch 3
>> > 1. remove the pcie interrupt-controller. interrupts setting revert to 
>> > origin.
>> > 
>> > setting.
>> >   v5
>> >patch 1
>> > 1. split PLDA controller driver codes to pcie_plda_common.c
>> > 2. correct the codes of record secondary number. 
>> >patch 3
>> > 1. change the pcie dtsi config. make them the same with kernel.
>> >  
>> >   v4
>> >patch 1
>> > 1. Remove the IDS_REVISION_ID macros.
>> > 2. Replace sec_busno to first_busno in starfive_pcie
>> > 3. Remove starfive_pcie_off_conf function.
>> > 4. Replace "imply" to "depends on" in PCIe Kconfig.
>> > 5 .Check sec_busno in starfive_pcie_addr_valid.
>> >  
>> >   v3
>> >patch 1
>> > 1. remove the read vendor ID delay
>> > 2. remove starfive_pcie_hide_rc_bar function. do not hide host
>> > bridge BAR write.
>> > 3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
>> > 4. Add comments for bus and address limitation reason in function
>> >starfive_pcie_addr_valid
>> > 5. Change the multiple line comments in Line 373
>> > 6. Using gpio_request_by_name to get PCIe reset gpio,and using
>> >dm_gpio_set_value set GPIO value.
>> >   patch 2
>> > 1. support PCIeboth 12a and 13b vf2 board.  
>> >   patch 3
>> > 1. reset dts change to reset-gpio.
>> > 
>> >   v2
>> >1. remove clock commit. The pcie clocks change has been includeded in 
>> > [1].
>> >2. Using GENMASK marco1 in patch1.
>> >3. remove the syscon dts node in patch3. The syscon dts dts node has 
>> > been
>> >   included in [1]. 
>> > 
>> > 
>> > Mason Huo (3):
>> >   starfive: pci: Add StarFive JH7110 pcie driver
>> >   configs: starfive-jh7110: Add support for PCIe host driver
>> >   riscv: dts: starfive: Enable PCIe host controller
>> > 
>> >  .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
>> >  arch/riscv/dts/jh7110.dtsi|  74 
>> >  configs/starfive_visionfive2_defconfig|  10 +
>> >  drivers/pci/Kconfig   |  13 +
>> >  drivers/pci/Makefile  |   2 +
>> >  drivers/pci/pcie_plda_common.c| 116 +++
>> >  drivers/pci/pcie_plda_common.h| 118 +++
>> >  drivers/pci/pcie_starfive_jh7110.c| 317 ++
>> >  8 files changed, 661 insertions(+)
>> >  create mode 100644 drivers/pci/pcie_plda_common.c
>> >  create mode 100644 drivers/pci/pcie_plda_common.h
>> >  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>> > 
>> > 
>> > base-commit: c9c2c95d4cd27fe0cd41fe13a863899d268f973c


Re: [PATCH v6 0/3] Add StarFive JH7110 PCIe drvier support

2023-05-31 Thread Minda Chen


Hi Rick and Leo
Could you review these series patches? Thanks.
Since patch 1 was acked by Pali, Does it mean patch 1 is accepted?

On 2023/5/9 16:26, Minda Chen wrote:
> These PCIe series patches are based on the JH7110 RISC-V SoC and VisionFive 
> V2 board.
> 
> The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
> The PCIe dts configuation includes all these setting.
> 
> The PCIe drivers codes has been tested on the VisionFive V2 boards.
> The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.
> 
> previous patch version
> 
> v1: 
> https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
> v2: 
> https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/
> v3: 
> https://patchwork.ozlabs.org/project/uboot/cover/20230329100143.10724-1-minda.c...@starfivetech.com/
> v4: 
> https://patchwork.ozlabs.org/project/uboot/cover/20230411010209.76561-1-minda.c...@starfivetech.com/
> v5: 
> https://patchwork.ozlabs.org/project/uboot/cover/20230423105859.125764-1-minda.c...@starfivetech.com/
> 
> changes
>   v6
>patch 2
> 1. Change one VisionFive2 config file.
>patch 3
> 1. remove the pcie interrupt-controller. interrupts setting revert to 
> origin.
> 
> setting.
>   v5
>patch 1
> 1. split PLDA controller driver codes to pcie_plda_common.c
> 2. correct the codes of record secondary number. 
>patch 3
> 1. change the pcie dtsi config. make them the same with kernel.
>  
>   v4
>patch 1
> 1. Remove the IDS_REVISION_ID macros.
> 2. Replace sec_busno to first_busno in starfive_pcie
> 3. Remove starfive_pcie_off_conf function.
> 4. Replace "imply" to "depends on" in PCIe Kconfig.
> 5 .Check sec_busno in starfive_pcie_addr_valid.
>  
>   v3
>patch 1
> 1. remove the read vendor ID delay
> 2. remove starfive_pcie_hide_rc_bar function. do not hide host
> bridge BAR write.
> 3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
> 4. Add comments for bus and address limitation reason in function
>starfive_pcie_addr_valid
> 5. Change the multiple line comments in Line 373
> 6. Using gpio_request_by_name to get PCIe reset gpio,and using
>dm_gpio_set_value set GPIO value.
>   patch 2
> 1. support PCIeboth 12a and 13b vf2 board.  
>   patch 3
> 1. reset dts change to reset-gpio.
> 
>   v2
>1. remove clock commit. The pcie clocks change has been includeded in [1].
>2. Using GENMASK marco1 in patch1.
>3. remove the syscon dts node in patch3. The syscon dts dts node has been
>   included in [1]. 
> 
> 
> Mason Huo (3):
>   starfive: pci: Add StarFive JH7110 pcie driver
>   configs: starfive-jh7110: Add support for PCIe host driver
>   riscv: dts: starfive: Enable PCIe host controller
> 
>  .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
>  arch/riscv/dts/jh7110.dtsi|  74 
>  configs/starfive_visionfive2_defconfig|  10 +
>  drivers/pci/Kconfig   |  13 +
>  drivers/pci/Makefile  |   2 +
>  drivers/pci/pcie_plda_common.c| 116 +++
>  drivers/pci/pcie_plda_common.h| 118 +++
>  drivers/pci/pcie_starfive_jh7110.c| 317 ++
>  8 files changed, 661 insertions(+)
>  create mode 100644 drivers/pci/pcie_plda_common.c
>  create mode 100644 drivers/pci/pcie_plda_common.h
>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
> 
> 
> base-commit: c9c2c95d4cd27fe0cd41fe13a863899d268f973c


[PATCH v6 3/3] riscv: dts: starfive: Enable PCIe host controller

2023-05-09 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.
Also add JH7110 stg syscon configuration.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi | 11 +++
 arch/riscv/dts/jh7110.dtsi| 74 +++
 2 files changed, 85 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index c6b6dfa940..12245576ac 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -7,6 +7,7 @@
 
 #include "jh7110.dtsi"
 #include 
+#include 
 / {
aliases {
serial0 = 
@@ -300,6 +301,16 @@
};
 };
 
+ {
+   reset-gpios = < 26 GPIO_ACTIVE_LOW>;
+   status = "disabled";
+};
+
+ {
+   reset-gpios = < 28 GPIO_ACTIVE_LOW>;
+   status = "okay";
+};
+
  {
assigned-clocks = < JH7110_SYSCLK_CPU_ROOT>,
  < JH7110_SYSCLK_BUS_ROOT>,
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index bd60879615..c7b071e743 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -569,5 +569,79 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   pcie0: pcie@2b00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2b00 0x0 0x100
+  0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3000  0x0 0x3000 
0x0 0x0800>,
+<0xc300  0x9 0x  0x9 0x 
0x0 0x4000>;
+   interrupts = <56>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   msi-parent = <>;
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0xc0 0xc4 0x130 
0x1b8>;
+   bus-range = <0x0 0xff>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_STG_AXI>,
+< JH7110_STGCLK_PCIE0_TL>,
+< JH7110_STGCLK_PCIE0_AXI>,
+< JH7110_STGCLK_PCIE0_APB>;
+   clock-names = "noc", "tl", "axi", "apb";
+   resets = < JH7110_STGRST_PCIE0_MST0>,
+< JH7110_STGRST_PCIE0_SLV0>,
+< JH7110_STGRST_PCIE0_SLV>,
+< JH7110_STGRST_PCIE0_BRG>,
+< JH7110_STGRST_PCIE0_CORE>,
+< JH7110_STGRST_PCIE0_APB>;
+   reset-names = "mst0", "slv0", "slv", "brg",
+ "core", "apb";
+   status = "disabled";
+   };
+
+   pcie1: pcie@2c00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2c00 0x0 0x100
+  0x9 0xc000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3800  0x0 0x3800 
0x0 0x0800>,
+<0xc300  0x9 0x8000  0x9 0x8000 
0x0 0x4000>;
+   interrupts = <57>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   msi-parent = <>;
+   device_type = &

[PATCH v6 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-05-09 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, Also add PLDA
PCIe controller common driver functions.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
Acked-by: Pali Rohár 
---
 drivers/pci/Kconfig|  13 ++
 drivers/pci/Makefile   |   2 +
 drivers/pci/pcie_plda_common.c | 116 +++
 drivers/pci/pcie_plda_common.h | 118 +++
 drivers/pci/pcie_starfive_jh7110.c | 317 +
 5 files changed, 566 insertions(+)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index ef328d2652..f2c5f0be63 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -374,4 +374,17 @@ config PCIE_UNIPHIER
  Say Y here if you want to enable PCIe controller support on
  UniPhier SoCs.
 
+config PCIE_PLDA_COMMON
+   bool
+
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   select PCIE_PLDA_COMMON
+   imply STARFIVE_JH7110
+   imply CLK_JH7110
+   imply RESET_JH7110
+   help
+ Say Y here if you want to enable PLDA XpressRich PCIe controller
+ support on StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 49506e7ba5..5a6974f013 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -49,3 +49,5 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
 obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
+obj-$(CONFIG_PCIE_PLDA_COMMON) += pcie_plda_common.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_plda_common.c b/drivers/pci/pcie_plda_common.c
new file mode 100644
index 00..005b92616a
--- /dev/null
+++ b/drivers/pci/pcie_plda_common.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * PLDA XpressRich PCIe host controller common functions.
+ *
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "pcie_plda_common.h"
+
+static bool plda_pcie_addr_valid(struct pcie_plda *plda, pci_dev_t bdf)
+{
+   /*
+* Single device limitation.
+* PCIe controller contain HW issue that secondary bus of
+* host bridge emumerate duplicate devices.
+* Only can access device 0 in secondary bus.
+*/
+   if (PCI_BUS(bdf) == plda->sec_busno && PCI_DEV(bdf) > 0)
+   return false;
+
+   return true;
+}
+
+static int plda_pcie_conf_address(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, void **paddr)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf),
+PCI_FUNC(bdf), offset);
+
+   if (!plda_pcie_addr_valid(priv, bdf))
+   return -ENODEV;
+
+   *paddr = (void *)(priv->cfg_base + where);
+   return 0;
+}
+
+int plda_pcie_config_read(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, ulong *valuep,
+ enum pci_size_t size)
+{
+   return pci_generic_mmap_read_config(udev, plda_pcie_conf_address,
+   bdf, offset, valuep, size);
+}
+
+int plda_pcie_config_write(struct udevice *udev, pci_dev_t bdf,
+  uint offset, ulong value,
+  enum pci_size_t size)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int ret;
+
+   ret = pci_generic_mmap_write_config(udev, plda_pcie_conf_address,
+   bdf, offset, value, size);
+
+   /* record secondary bus number */
+   if (!ret && PCI_BUS(bdf) == dev_seq(udev) &&
+   PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+   (offset == PCI_SECONDARY_BUS ||
+   (offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8))) {
+   priv->sec_busno =
+   ((offset == PCI_PRIMARY_BUS) ? (value >> 8) : value) & 
0xff;
+   debug("Secondary bus number was changed to %d\n",
+ priv->sec_busno);
+   }
+   return ret;
+}
+
+int plda_pcie_set_atr_entry(struct pcie_plda *plda, phys_addr_t src_addr,
+   phys_addr_t trsl_addr, phys_size_t window_size,
+   int trsl_param)
+{
+   void __iomem *base =
+   plda->reg_base + XR3PCI_ATR_AXI4_SLV0;
+
+   /* Support AXI4 Slave 0 Address Translation Tables 0-7. */
+   if (plda->atr_table

[PATCH v6 0/3] Add StarFive JH7110 PCIe drvier support

2023-05-09 Thread Minda Chen
These PCIe series patches are based on the JH7110 RISC-V SoC and VisionFive V2 
board.

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

previous patch version

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
v2: 
https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/
v3: 
https://patchwork.ozlabs.org/project/uboot/cover/20230329100143.10724-1-minda.c...@starfivetech.com/
v4: 
https://patchwork.ozlabs.org/project/uboot/cover/20230411010209.76561-1-minda.c...@starfivetech.com/
v5: 
https://patchwork.ozlabs.org/project/uboot/cover/20230423105859.125764-1-minda.c...@starfivetech.com/

changes
  v6
   patch 2
1. Change one VisionFive2 config file.
   patch 3
1. remove the pcie interrupt-controller. interrupts setting revert to 
origin.

setting.
  v5
   patch 1
1. split PLDA controller driver codes to pcie_plda_common.c
2. correct the codes of record secondary number. 
   patch 3
1. change the pcie dtsi config. make them the same with kernel.
 
  v4
   patch 1
1. Remove the IDS_REVISION_ID macros.
2. Replace sec_busno to first_busno in starfive_pcie
3. Remove starfive_pcie_off_conf function.
4. Replace "imply" to "depends on" in PCIe Kconfig.
5 .Check sec_busno in starfive_pcie_addr_valid.
 
  v3
   patch 1
1. remove the read vendor ID delay
2. remove starfive_pcie_hide_rc_bar function. do not hide host
bridge BAR write.
3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
4. Add comments for bus and address limitation reason in function
   starfive_pcie_addr_valid
5. Change the multiple line comments in Line 373
6. Using gpio_request_by_name to get PCIe reset gpio,and using
   dm_gpio_set_value set GPIO value.
  patch 2
1. support PCIeboth 12a and 13b vf2 board.  
  patch 3
1. reset dts change to reset-gpio.

  v2
   1. remove clock commit. The pcie clocks change has been includeded in [1].
   2. Using GENMASK marco1 in patch1.
   3. remove the syscon dts node in patch3. The syscon dts dts node has been
  included in [1]. 


Mason Huo (3):
  starfive: pci: Add StarFive JH7110 pcie driver
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

 .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
 arch/riscv/dts/jh7110.dtsi|  74 
 configs/starfive_visionfive2_defconfig|  10 +
 drivers/pci/Kconfig   |  13 +
 drivers/pci/Makefile  |   2 +
 drivers/pci/pcie_plda_common.c| 116 +++
 drivers/pci/pcie_plda_common.h| 118 +++
 drivers/pci/pcie_starfive_jh7110.c| 317 ++
 8 files changed, 661 insertions(+)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c


base-commit: c9c2c95d4cd27fe0cd41fe13a863899d268f973c
-- 
2.17.1



[PATCH v6 2/3] configs: starfive-jh7110: Add support for PCIe host driver

2023-05-09 Thread Minda Chen
From: Mason Huo 

also add the nvme driver and rtl8169 support.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 550d0ff3ab..ea798919be 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -49,9 +50,12 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
+CONFIG_CMD_PCI=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,12 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
+CONFIG_PCIE_STARFIVE_JH7110=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



[PATCH v5 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-04-23 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, Also add PLDA
PCIe controller common driver functions.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 drivers/pci/Kconfig|  13 ++
 drivers/pci/Makefile   |   2 +
 drivers/pci/pcie_plda_common.c | 116 +++
 drivers/pci/pcie_plda_common.h | 118 +++
 drivers/pci/pcie_starfive_jh7110.c | 317 +
 5 files changed, 566 insertions(+)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index ef328d2652..f2c5f0be63 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -374,4 +374,17 @@ config PCIE_UNIPHIER
  Say Y here if you want to enable PCIe controller support on
  UniPhier SoCs.
 
+config PCIE_PLDA_COMMON
+   bool
+
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   select PCIE_PLDA_COMMON
+   imply STARFIVE_JH7110
+   imply CLK_JH7110
+   imply RESET_JH7110
+   help
+ Say Y here if you want to enable PLDA XpressRich PCIe controller
+ support on StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 49506e7ba5..5a6974f013 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -49,3 +49,5 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
 obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
+obj-$(CONFIG_PCIE_PLDA_COMMON) += pcie_plda_common.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_plda_common.c b/drivers/pci/pcie_plda_common.c
new file mode 100644
index 00..005b92616a
--- /dev/null
+++ b/drivers/pci/pcie_plda_common.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * PLDA XpressRich PCIe host controller common functions.
+ *
+ * Copyright (C) 2023 StarFive Technology Co., Ltd.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "pcie_plda_common.h"
+
+static bool plda_pcie_addr_valid(struct pcie_plda *plda, pci_dev_t bdf)
+{
+   /*
+* Single device limitation.
+* PCIe controller contain HW issue that secondary bus of
+* host bridge emumerate duplicate devices.
+* Only can access device 0 in secondary bus.
+*/
+   if (PCI_BUS(bdf) == plda->sec_busno && PCI_DEV(bdf) > 0)
+   return false;
+
+   return true;
+}
+
+static int plda_pcie_conf_address(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, void **paddr)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf),
+PCI_FUNC(bdf), offset);
+
+   if (!plda_pcie_addr_valid(priv, bdf))
+   return -ENODEV;
+
+   *paddr = (void *)(priv->cfg_base + where);
+   return 0;
+}
+
+int plda_pcie_config_read(const struct udevice *udev, pci_dev_t bdf,
+ uint offset, ulong *valuep,
+ enum pci_size_t size)
+{
+   return pci_generic_mmap_read_config(udev, plda_pcie_conf_address,
+   bdf, offset, valuep, size);
+}
+
+int plda_pcie_config_write(struct udevice *udev, pci_dev_t bdf,
+  uint offset, ulong value,
+  enum pci_size_t size)
+{
+   struct pcie_plda *priv = dev_get_priv(udev);
+   int ret;
+
+   ret = pci_generic_mmap_write_config(udev, plda_pcie_conf_address,
+   bdf, offset, value, size);
+
+   /* record secondary bus number */
+   if (!ret && PCI_BUS(bdf) == dev_seq(udev) &&
+   PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) == 0 &&
+   (offset == PCI_SECONDARY_BUS ||
+   (offset == PCI_PRIMARY_BUS && size != PCI_SIZE_8))) {
+   priv->sec_busno =
+   ((offset == PCI_PRIMARY_BUS) ? (value >> 8) : value) & 
0xff;
+   debug("Secondary bus number was changed to %d\n",
+ priv->sec_busno);
+   }
+   return ret;
+}
+
+int plda_pcie_set_atr_entry(struct pcie_plda *plda, phys_addr_t src_addr,
+   phys_addr_t trsl_addr, phys_size_t window_size,
+   int trsl_param)
+{
+   void __iomem *base =
+   plda->reg_base + XR3PCI_ATR_AXI4_SLV0;
+
+   /* Support AXI4 Slave 0 Address Translation Tables 0-7. */
+   if (plda->atr_table

[PATCH v5 3/3] riscv: dts: starfive: Enable PCIe host controller

2023-04-23 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.
Also add JH7110 stg syscon configuration.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi | 11 +++
 arch/riscv/dts/jh7110.dtsi| 88 +++
 2 files changed, 99 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index c6b6dfa940..12245576ac 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -7,6 +7,7 @@
 
 #include "jh7110.dtsi"
 #include 
+#include 
 / {
aliases {
serial0 = 
@@ -300,6 +301,16 @@
};
 };
 
+ {
+   reset-gpios = < 26 GPIO_ACTIVE_LOW>;
+   status = "disabled";
+};
+
+ {
+   reset-gpios = < 28 GPIO_ACTIVE_LOW>;
+   status = "okay";
+};
+
  {
assigned-clocks = < JH7110_SYSCLK_CPU_ROOT>,
  < JH7110_SYSCLK_BUS_ROOT>,
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index bd60879615..f210dfc99c 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -569,5 +569,93 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   pcie0: pcie@2b00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2b00 0x0 0x100
+  0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3000  0x0 0x3000 
0x0 0x0800>,
+<0xc300  0x9 0x  0x9 0x 
0x0 0x4000>;
+   interrupts = <56>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1 _intc0 0x1>,
+   <0x0 0x0 0x0 0x2 _intc0 0x2>,
+   <0x0 0x0 0x0 0x3 _intc0 0x3>,
+   <0x0 0x0 0x0 0x4 _intc0 0x4>;
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0xc0 0xc4 0x130 
0x1b8>;
+   bus-range = <0x0 0xff>;
+   msi-parent = <>;
+   msi-controller;
+   clocks = < JH7110_SYSCLK_NOC_BUS_STG_AXI>,
+< JH7110_STGCLK_PCIE0_TL>,
+< JH7110_STGCLK_PCIE0_AXI>,
+< JH7110_STGCLK_PCIE0_APB>;
+   clock-names = "noc", "tl", "axi", "apb";
+   resets = < JH7110_STGRST_PCIE0_MST0>,
+< JH7110_STGRST_PCIE0_SLV0>,
+< JH7110_STGRST_PCIE0_SLV>,
+< JH7110_STGRST_PCIE0_BRG>,
+< JH7110_STGRST_PCIE0_CORE>,
+< JH7110_STGRST_PCIE0_APB>;
+   reset-names = "mst0", "slv0", "slv", "brg",
+ "core", "apb";
+   status = "disabled";
+
+   pcie_intc0: interrupt-controller {
+   #address-cells = <0>;
+   #interrupt-cells = <1>;
+   interrupt-controller;
+   };
+   };
+
+   pcie1: pcie@2c00 {
+   compatible = "starfive,jh7110-pcie";
+   reg = <0x0 0x2c00 0x0 0x100
+  0x9 0xc000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   ranges = <0x8200  0x0 0x3800  0x0 0x3800 
0x0 0x0800>,
+<0xc300  0x9 0x8000  0x9 0x8000 
0x0 0x4000>;
+   interrupts = <57>;
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   int

[PATCH v5 2/3] configs: starfive-jh7110: Add support for PCIe host driver

2023-04-23 Thread Minda Chen
From: Mason Huo 

also add the nvme driver and rtl8169 support.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_12a_defconfig | 10 ++
 configs/starfive_visionfive2_13b_defconfig | 10 ++
 2 files changed, 20 insertions(+)

diff --git a/configs/starfive_visionfive2_12a_defconfig 
b/configs/starfive_visionfive2_12a_defconfig
index e0f98292ff..bd5b25f9d4 100644
--- a/configs/starfive_visionfive2_12a_defconfig
+++ b/configs/starfive_visionfive2_12a_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -49,9 +50,12 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
+CONFIG_CMD_PCI=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,12 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
+CONFIG_PCIE_STARFIVE_JH7110=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
diff --git a/configs/starfive_visionfive2_13b_defconfig 
b/configs/starfive_visionfive2_13b_defconfig
index 550d0ff3ab..7247992796 100644
--- a/configs/starfive_visionfive2_13b_defconfig
+++ b/configs/starfive_visionfive2_13b_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -50,8 +51,11 @@ CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,12 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
+CONFIG_PCIE_STARFIVE_JH7110=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



[PATCH v5 0/3] Add StarFive JH7110 PCIe drvier support

2023-04-23 Thread Minda Chen
This patchset needs to apply after patchset in [1]. These PCIe series patches
are based on the JH7110 RISC-V SoC and VisionFive V2 board.

[1] 
https://patchwork.ozlabs.org/project/uboot/cover/20230329034224.26545-1-yanhong.w...@starfivetech.com

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

previous patch version

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
v2: 
https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/
v3: 
https://patchwork.ozlabs.org/project/uboot/cover/20230329100143.10724-1-minda.c...@starfivetech.com/
v4: 
https://patchwork.ozlabs.org/project/uboot/cover/20230411010209.76561-1-minda.c...@starfivetech.com/

changes
  v5
   patch 1
1. split PLDA controller driver codes to pcie_plda_common.c
2. correct the codes of record secondary number. 
   patch 3
1. change the pcie dtsi config. make them the same with kernel.
 
  v4
   patch 1
1. Remove the IDS_REVISION_ID macros.
2. Replace sec_busno to first_busno in starfive_pcie
3. Remove starfive_pcie_off_conf function.
4. Replace "imply" to "depends on" in PCIe Kconfig.
5 .Check sec_busno in starfive_pcie_addr_valid.
 
  v3
   patch 1
1. remove the read vendor ID delay
2. remove starfive_pcie_hide_rc_bar function. do not hide host
bridge BAR write.
3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
4. Add comments for bus and address limitation reason in function
   starfive_pcie_addr_valid
5. Change the multiple line comments in Line 373
6. Using gpio_request_by_name to get PCIe reset gpio,and using
   dm_gpio_set_value set GPIO value.
  patch 2
1. support PCIeboth 12a and 13b vf2 board.  
  patch 3
1. reset dts change to reset-gpio.

  v2
   1. remove clock commit. The pcie clocks change has been includeded in [1].
   2. Using GENMASK marco1 in patch1.
   3. remove the syscon dts node in patch3. The syscon dts dts node has been
  included in [1]. 


Mason Huo (3):
  starfive: pci: Add StarFive JH7110 pcie driver
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

 .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
 arch/riscv/dts/jh7110.dtsi|  88 +
 configs/starfive_visionfive2_12a_defconfig|  10 +
 configs/starfive_visionfive2_13b_defconfig|  10 +
 drivers/pci/Kconfig   |  13 +
 drivers/pci/Makefile  |   2 +
 drivers/pci/pcie_plda_common.c| 116 +++
 drivers/pci/pcie_plda_common.h| 118 +++
 drivers/pci/pcie_starfive_jh7110.c| 317 ++
 9 files changed, 685 insertions(+)
 create mode 100644 drivers/pci/pcie_plda_common.c
 create mode 100644 drivers/pci/pcie_plda_common.h
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c


base-commit: 41a88ad529b3943b1e465846eb24fe2c29203e35
-- 
2.17.1



Re: [PATCH v4 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-04-12 Thread Minda Chen



On 2023/4/12 5:29, Pali Rohár wrote:
> Hello!
> 
> On Tuesday 11 April 2023 09:02:07 Minda Chen wrote:
>> +int starfive_pcie_config_write(struct udevice *udev, pci_dev_t bdf,
>> +   uint offset, ulong value,
>> +   enum pci_size_t size)
>> +{
>> +struct starfive_pcie *priv = dev_get_priv(udev);
>> +int ret;
>> +
>> +ret = pci_generic_mmap_write_config(udev, starfive_pcie_conf_address,
>> +bdf, offset, value, size);
>> +
>> +if (!ret && offset == PCI_SECONDARY_BUS) {
>> +priv->sec_busno = value & 0xff;
>> +debug("Secondary bus number was changed to %d\n",
>> +  priv->sec_busno);
>> +}
> 
> This block of code contains two issues:
> 
> 1) If secondary bus is changed by the 16-bit or 32-bit write operation
>then this condition does not catch it.
> 
> 2) priv->sec_busno is used just for checking if driver is going to
>access device on secondary bus of the Root Port. But this code
>updates priv->sec_busno also for write to _any_ device on any bus,
>not just when updating Root Port device. So it breaks support for
>non-trivial PCIe hierarchy which contains e.g. PCIe switch (e.g. when
>changing configuration of the virtual PCI-to-PCI bridge device of
>PCIe switch, which is behind the secondary bus of the Root Port).
> 
> So you need something like this:
> 
> if (!ret &&
> PCI_BUS(bdf) == dev_seq(udev) && PCI_DEV(bdf) == 0 && PCI_FUNC(bdf) 
> == 0 &&
> (offset == PCI_SECONDARY_BUS || (offset == PCI_PRIMARY_BUS && size != 
> PCI_SIZE_8)) {
> priv->sec_busno = ((offset == PCI_PRIMARY_BUS) ? (value >> 8) : 
> value) & 0xff;
> debug("Secondary bus number was changed to %d\n", pcie->sec_busno);
> }
> 
> You have to update priv->sec_busno only when write request is for the
> Root Port. And you need to catch also 16-bit or 32-bit write operation
> to the PCI_PRIMARY_BUS register. It is because PCI_SECONDARY_BUS reg
> is (PCI_PRIMARY_BUS+2) and (PCI_SECONDARY_BUS & ~3) == PCI_PRIMARY_BUS
> 
I will change like this. Thank you very much.
>> +return ret;
>> +}


Re: [PATCH v4 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-04-12 Thread Minda Chen



On 2023/4/11 13:20, Bin Meng wrote:
> On Tue, Apr 11, 2023 at 11:53 AM Minda Chen  
> wrote:
>>
>>
>>
>> On 2023/4/11 10:55, Bin Meng wrote:
>> > On Tue, Apr 11, 2023 at 9:03 AM Minda Chen  
>> > wrote:
>> >>
>> >> From: Mason Huo 
>> >>
>> >> Add pcie driver for StarFive JH7110, the driver depends on
>> >> starfive gpio, pinctrl, clk and reset driver to do init.
>> >>
>> >> Several devices are tested:
>> >> a) M.2 NVMe SSD
>> >> b) Realtek 8169 Ethernet adapter.
>> >>
>> >> Signed-off-by: Mason Huo 
>> >> Signed-off-by: Minda Chen 
>> >> ---
>> >>  drivers/pci/Kconfig|   9 +
>> >>  drivers/pci/Makefile   |   1 +
>> >>  drivers/pci/pcie_starfive_jh7110.c | 465 +
>> >>  3 files changed, 475 insertions(+)
>> >>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>> >>
>> >> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> >> index ef328d2652..f37b6baa25 100644
>> >> --- a/drivers/pci/Kconfig
>> >> +++ b/drivers/pci/Kconfig
>> >> @@ -374,4 +374,13 @@ config PCIE_UNIPHIER
>> >>   Say Y here if you want to enable PCIe controller support on
>> >>   UniPhier SoCs.
>> >>
>> >> +config PCIE_STARFIVE_JH7110
>> >> +   bool "Enable Starfive JH7110 PCIe driver"
>> >> +   imply STARFIVE_JH7110
>> >> +   imply CLK_JH7110
>> >> +   imply RESET_JH7110
>> >> +   help
>> >> + Say Y here if you want to enable PCIe controller support on
>> >> + StarFive JH7110 SoC.
>> >> +
>> >>  endif
>> >> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
>> >> index 49506e7ba5..bbe3323bb5 100644
>> >> --- a/drivers/pci/Makefile
>> >> +++ b/drivers/pci/Makefile
>> >> @@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
>> >>  obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
>> >>  obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
>> >>  obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
>> >> +obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
>> >> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
>> >> b/drivers/pci/pcie_starfive_jh7110.c
>> >> new file mode 100644
>> >> index 00..130181013e
>> >> --- /dev/null
>> >> +++ b/drivers/pci/pcie_starfive_jh7110.c
>> >> @@ -0,0 +1,465 @@
>> >> +// SPDX-License-Identifier: GPL-2.0+
>> >> +/*
>> >> + * StarFive PLDA PCIe host controller driver
>> >> + *
>> >> + * Copyright (c) 2023 Starfive, Inc.
>> >> + * Author: Mason Huo 
>> >> + *
>> >> + */
>> >> +
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +
>> >> +DECLARE_GLOBAL_DATA_PTR;
>> >> +
>> >> +#define GEN_SETTINGS   0x80
>> >> +#define PCIE_PCI_IDS   0x9C
>> >> +#define PCIE_WINROM0xFC
>> >> +#define PMSG_SUPPORT_RX0x3F0
>> >> +#define PCI_MISC   0xB4
>> >> +
>> >> +#define PLDA_EP_ENABLE 0
>> >> +#define PLDA_RP_ENABLE 1
>> >> +
>> >> +#define IDS_CLASS_CODE_SHIFT   8
>> >> +
>> >> +#define PREF_MEM_WIN_64_SUPPORTBIT(3)
>> >> +#define PMSG_LTR_SUPPORT   BIT(2)
>> >> +#define PLDA_FUNCTION_DIS  BIT(15)
>> >> +#define PLDA_FUNC_NUM  4
>> >> +#define PLDA_PHY_FUNC_SHIFT9
>> >> +
>> >> +#define XR3PCI_ATR_AXI4_SLV0   0x800
>> >> +#define XR3PCI_ATR_SRC_ADDR_LOW0x0
>> >> +#define XR3PCI_ATR_SRC_ADDR_HIGH   0x4
>> >> +#define XR3PCI

Re: [PATCH v4 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-04-10 Thread Minda Chen



On 2023/4/11 10:55, Bin Meng wrote:
> On Tue, Apr 11, 2023 at 9:03 AM Minda Chen  
> wrote:
>>
>> From: Mason Huo 
>>
>> Add pcie driver for StarFive JH7110, the driver depends on
>> starfive gpio, pinctrl, clk and reset driver to do init.
>>
>> Several devices are tested:
>> a) M.2 NVMe SSD
>> b) Realtek 8169 Ethernet adapter.
>>
>> Signed-off-by: Mason Huo 
>> Signed-off-by: Minda Chen 
>> ---
>>  drivers/pci/Kconfig|   9 +
>>  drivers/pci/Makefile   |   1 +
>>  drivers/pci/pcie_starfive_jh7110.c | 465 +
>>  3 files changed, 475 insertions(+)
>>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>>
>> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> index ef328d2652..f37b6baa25 100644
>> --- a/drivers/pci/Kconfig
>> +++ b/drivers/pci/Kconfig
>> @@ -374,4 +374,13 @@ config PCIE_UNIPHIER
>>   Say Y here if you want to enable PCIe controller support on
>>   UniPhier SoCs.
>>
>> +config PCIE_STARFIVE_JH7110
>> +   bool "Enable Starfive JH7110 PCIe driver"
>> +   imply STARFIVE_JH7110
>> +   imply CLK_JH7110
>> +   imply RESET_JH7110
>> +   help
>> + Say Y here if you want to enable PCIe controller support on
>> + StarFive JH7110 SoC.
>> +
>>  endif
>> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
>> index 49506e7ba5..bbe3323bb5 100644
>> --- a/drivers/pci/Makefile
>> +++ b/drivers/pci/Makefile
>> @@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
>>  obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
>>  obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
>>  obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
>> +obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
>> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
>> b/drivers/pci/pcie_starfive_jh7110.c
>> new file mode 100644
>> index 00..130181013e
>> --- /dev/null
>> +++ b/drivers/pci/pcie_starfive_jh7110.c
>> @@ -0,0 +1,465 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * StarFive PLDA PCIe host controller driver
>> + *
>> + * Copyright (c) 2023 Starfive, Inc.
>> + * Author: Mason Huo 
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +DECLARE_GLOBAL_DATA_PTR;
>> +
>> +#define GEN_SETTINGS   0x80
>> +#define PCIE_PCI_IDS   0x9C
>> +#define PCIE_WINROM0xFC
>> +#define PMSG_SUPPORT_RX0x3F0
>> +#define PCI_MISC   0xB4
>> +
>> +#define PLDA_EP_ENABLE 0
>> +#define PLDA_RP_ENABLE 1
>> +
>> +#define IDS_CLASS_CODE_SHIFT   8
>> +
>> +#define PREF_MEM_WIN_64_SUPPORTBIT(3)
>> +#define PMSG_LTR_SUPPORT   BIT(2)
>> +#define PLDA_FUNCTION_DIS  BIT(15)
>> +#define PLDA_FUNC_NUM  4
>> +#define PLDA_PHY_FUNC_SHIFT9
>> +
>> +#define XR3PCI_ATR_AXI4_SLV0   0x800
>> +#define XR3PCI_ATR_SRC_ADDR_LOW0x0
>> +#define XR3PCI_ATR_SRC_ADDR_HIGH   0x4
>> +#define XR3PCI_ATR_TRSL_ADDR_LOW   0x8
>> +#define XR3PCI_ATR_TRSL_ADDR_HIGH  0xc
>> +#define XR3PCI_ATR_TRSL_PARAM  0x10
>> +#define XR3PCI_ATR_TABLE_OFFSET0x20
>> +#define XR3PCI_ATR_MAX_TABLE_NUM   8
>> +
>> +#define XR3PCI_ATR_SRC_WIN_SIZE_SHIFT  1
>> +#define XR3PCI_ATR_SRC_ADDR_MASK   GENMASK(31, 12)
>> +#define XR3PCI_ATR_TRSL_ADDR_MASK  GENMASK(31, 12)
>> +#define XR3_PCI_ECAM_SIZE  28
>> +#define XR3PCI_ATR_TRSL_DIRBIT(22)
>> +/* IDs used in the XR3PCI_ATR_TRSL_PARAM */
>> +#define XR3PCI_ATR_TRSLID_PCIE_MEMORY  0x0
>> +#define XR3PCI_ATR_TRSLID_PCIE_CONFIG  0x1
>> +
>> +/* system control */
>> +#define STG_SYSCON_K_RP_NEP_MASK   BIT(8)
>> +#define STG_SYSCON_AXI4_SLVL_ARFUNC_MASK   GENMASK(22, 8)
>> +#define STG_SYSCON_AXI4_SLVL_ARFUNC_SHIFT  8
>> +#define STG_SYSCON_AXI4_SLVL_AWFUNC_MASK   GENMASK(14, 0)
>> +#define STG_SYSCON_CLKREQ_MASK BIT(22)
>> 

[PATCH v4 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-04-10 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, the driver depends on
starfive gpio, pinctrl, clk and reset driver to do init.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 drivers/pci/Kconfig|   9 +
 drivers/pci/Makefile   |   1 +
 drivers/pci/pcie_starfive_jh7110.c | 465 +
 3 files changed, 475 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index ef328d2652..f37b6baa25 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -374,4 +374,13 @@ config PCIE_UNIPHIER
  Say Y here if you want to enable PCIe controller support on
  UniPhier SoCs.
 
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   imply STARFIVE_JH7110
+   imply CLK_JH7110
+   imply RESET_JH7110
+   help
+ Say Y here if you want to enable PCIe controller support on
+ StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 49506e7ba5..bbe3323bb5 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
 obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_starfive_jh7110.c 
b/drivers/pci/pcie_starfive_jh7110.c
new file mode 100644
index 00..130181013e
--- /dev/null
+++ b/drivers/pci/pcie_starfive_jh7110.c
@@ -0,0 +1,465 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * StarFive PLDA PCIe host controller driver
+ *
+ * Copyright (c) 2023 Starfive, Inc.
+ * Author: Mason Huo 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define GEN_SETTINGS   0x80
+#define PCIE_PCI_IDS   0x9C
+#define PCIE_WINROM0xFC
+#define PMSG_SUPPORT_RX0x3F0
+#define PCI_MISC   0xB4
+
+#define PLDA_EP_ENABLE 0
+#define PLDA_RP_ENABLE 1
+
+#define IDS_CLASS_CODE_SHIFT   8
+
+#define PREF_MEM_WIN_64_SUPPORTBIT(3)
+#define PMSG_LTR_SUPPORT   BIT(2)
+#define PLDA_FUNCTION_DIS  BIT(15)
+#define PLDA_FUNC_NUM  4
+#define PLDA_PHY_FUNC_SHIFT9
+
+#define XR3PCI_ATR_AXI4_SLV0   0x800
+#define XR3PCI_ATR_SRC_ADDR_LOW0x0
+#define XR3PCI_ATR_SRC_ADDR_HIGH   0x4
+#define XR3PCI_ATR_TRSL_ADDR_LOW   0x8
+#define XR3PCI_ATR_TRSL_ADDR_HIGH  0xc
+#define XR3PCI_ATR_TRSL_PARAM  0x10
+#define XR3PCI_ATR_TABLE_OFFSET0x20
+#define XR3PCI_ATR_MAX_TABLE_NUM   8
+
+#define XR3PCI_ATR_SRC_WIN_SIZE_SHIFT  1
+#define XR3PCI_ATR_SRC_ADDR_MASK   GENMASK(31, 12)
+#define XR3PCI_ATR_TRSL_ADDR_MASK  GENMASK(31, 12)
+#define XR3_PCI_ECAM_SIZE  28
+#define XR3PCI_ATR_TRSL_DIRBIT(22)
+/* IDs used in the XR3PCI_ATR_TRSL_PARAM */
+#define XR3PCI_ATR_TRSLID_PCIE_MEMORY  0x0
+#define XR3PCI_ATR_TRSLID_PCIE_CONFIG  0x1
+
+/* system control */
+#define STG_SYSCON_K_RP_NEP_MASK   BIT(8)
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_MASK   GENMASK(22, 8)
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_SHIFT  8
+#define STG_SYSCON_AXI4_SLVL_AWFUNC_MASK   GENMASK(14, 0)
+#define STG_SYSCON_CLKREQ_MASK BIT(22)
+#define STG_SYSCON_CKREF_SRC_SHIFT 18
+#define STG_SYSCON_CKREF_SRC_MASK  GENMASK(19, 18)
+
+struct starfive_pcie {
+   struct udevice *dev;
+
+   void __iomem *reg_base;
+   void __iomem *cfg_base;
+
+   struct regmap *regmap;
+   u32 stg_arfun;
+   u32 stg_awfun;
+   u32 stg_rp_nep;
+
+   struct clk_bulk clks;
+   struct reset_ctl_bulk   rsts;
+   struct gpio_descreset_gpio;
+
+   int atr_table_num;
+   int sec_busno;
+};
+
+static bool starfive_pcie_addr_valid(pci_dev_t bdf, struct starfive_pcie *priv)
+{
+   /*
+* Single device limitation.
+* For JH7110 SoC limitation, one bus can only connnect one device.
+* And PCIe controller contain HW issue that secondary bus of
+* host bridge emumerate duplicate devices.
+* Only can access device 0 in secondary bus.
+*/
+   if (PCI_BUS(bdf) == priv->sec_busno && PCI_DEV(bdf) > 0)
+   return false;
+
+   return true;
+}
+
+static int starfive_pcie_conf_address(const struct udevice *udev, pci_dev_t 
bdf,
+ uint offset, void **paddr)
+{
+   struct starfive_p

[PATCH v4 3/3] riscv: dts: starfive: Enable PCIe host controller

2023-04-10 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.
Also add JH7110 stg syscon configuration.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi | 11 +++
 arch/riscv/dts/jh7110.dtsi| 74 +++
 2 files changed, 85 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index c6b6dfa940..12245576ac 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -7,6 +7,7 @@
 
 #include "jh7110.dtsi"
 #include 
+#include 
 / {
aliases {
serial0 = 
@@ -300,6 +301,16 @@
};
 };
 
+ {
+   reset-gpios = < 26 GPIO_ACTIVE_LOW>;
+   status = "disabled";
+};
+
+ {
+   reset-gpios = < 28 GPIO_ACTIVE_LOW>;
+   status = "okay";
+};
+
  {
assigned-clocks = < JH7110_SYSCLK_CPU_ROOT>,
  < JH7110_SYSCLK_BUS_ROOT>,
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index bd60879615..eaf8035a61 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -569,5 +569,79 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   pcie0: pcie@2B00 {
+   compatible = "starfive,jh7110-pcie";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   reg = <0x0 0x2B00 0x0 0x100>,
+ <0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0xc0 0xc4 0x130>;
+   bus-range = <0x0 0xff>;
+   ranges = <0x8200  0x0 0x3000  0x0 0x3000 
0x0 0x0800>,
+   <0xc300  0x9 0x  0x9 0x 0x0 
0x4000>;
+   msi-parent = <>;
+   interrupts = <56>;
+   interrupt-controller;
+   interrupt-names = "msi";
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   resets = < JH7110_STGRST_PCIE0_MST0>,
+< JH7110_STGRST_PCIE0_SLV0>,
+< JH7110_STGRST_PCIE0_SLV>,
+< JH7110_STGRST_PCIE0_BRG>,
+< JH7110_STGRST_PCIE0_CORE>,
+< JH7110_STGRST_PCIE0_APB>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_STG_AXI>,
+< JH7110_STGCLK_PCIE0_TL>,
+< JH7110_STGCLK_PCIE0_AXI>,
+< JH7110_STGCLK_PCIE0_APB>;
+   clock-names = "noc_bus_stg_axi", "pcie0_tl", 
"pcie0_axi", "pcie0_apb";
+   status = "disabled";
+   };
+
+   pcie1: pcie@2C00 {
+   compatible = "starfive,jh7110-pcie";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   reg = <0x0 0x2C00 0x0 0x100>,
+ <0x9 0xc000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0x270 0x274 0x2e0>;
+   bus-range = <0x0 0xff>;
+   ranges = <0x8200  0x0 0x3800  0x0 0x3800 
0x0 0x0800>,
+   <0xc300  0x9 0x8000  0x9 0x8000 0x0 
0x4000>;
+   msi-parent = <>;
+   interrupts = <57>;
+   interrupt-controller;
+   interrupt-names = "msi";
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0

[PATCH v4 0/3] Add StarFive JH7110 PCIe drvier support

2023-04-10 Thread Minda Chen
This patchset needs to apply after patchset in [1]. These PCIe series patches
are based on the JH7110 RISC-V SoC and VisionFive V2 board.

[1] 
https://patchwork.ozlabs.org/project/uboot/cover/20230329034224.26545-1-yanhong.w...@starfivetech.com

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

previous patch version

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
v2: 
https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/
v3: 
https://patchwork.ozlabs.org/project/uboot/cover/20230329100143.10724-1-minda.c...@starfivetech.com/

changes
  v4
   patch 1
1. Remove the IDS_REVISION_ID macros.
2. Replace sec_busno to first_busno in starfive_pcie
3. Remove starfive_pcie_off_conf function.
4. Replace "imply" to "depends on" in PCIe Kconfig.
5 .Check sec_busno in starfive_pcie_addr_valid.
 
  v3
   patch 1
1. remove the read vendor ID delay
2. remove starfive_pcie_hide_rc_bar function. do not hide host
bridge BAR write.
3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
4. Add comments for bus and address limitation reason in function
   starfive_pcie_addr_valid
5. Change the multiple line comments in Line 373
6. Using gpio_request_by_name to get PCIe reset gpio,and using
   dm_gpio_set_value set GPIO value.
  patch 2
1. support PCIeboth 12a and 13b vf2 board.  
  patch 3
1. reset dts change to reset-gpio.

  v2
   1. remove clock commit. The pcie clocks change has been includeded in [1].
   2. Using GENMASK marco1 in patch1.
   3. remove the syscon dts node in patch3. The syscon dts dts node has been
  included in [1]. 

---
Mason Huo (3):
  starfive: pci: Add StarFive JH7110 pcie driver
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

 .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
 arch/riscv/dts/jh7110.dtsi|  74 +++
 configs/starfive_visionfive2_12a_defconfig|  10 +
 configs/starfive_visionfive2_13b_defconfig|  10 +
 drivers/pci/Kconfig   |   9 +
 drivers/pci/Makefile  |   1 +
 drivers/pci/pcie_starfive_jh7110.c| 465 ++
 7 files changed, 580 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c


base-commit: 41a88ad529b3943b1e465846eb24fe2c29203e35
prerequisite-patch-id: a84452ba131408ff842b65ae19a3a05f64b3ff60
prerequisite-patch-id: 4abb46d56dbaf36017b2866688f31a73c2cacd0d
prerequisite-patch-id: ef5e9d61f7392c7d2e5321aa8a10996ca8eae5fc
prerequisite-patch-id: 26dfdb401d680ecd9449acf09131cf4790e987b7
prerequisite-patch-id: a0cfa5d8cdb49bbe9d4739afa90991f882950881
prerequisite-patch-id: 61ceecb41cfd9029bfb267f7b7c5330a2d7e5edc
prerequisite-patch-id: d834ece14ffb525b8c3e661e78736692f33fca9b
prerequisite-patch-id: 88c9f9637335fdc4107d42db67b9110c9b73ead3
prerequisite-patch-id: ebc26ed3f97f7babc0fc805152acb578f5eff922
prerequisite-patch-id: e85a9ca22facac4d5b5562a2708b7332478d6db4
prerequisite-patch-id: ff5bd799e4cb905fef6cf1cd0ce757980e1d34b7
prerequisite-patch-id: a341d4e8a8e25cb711309123939235fcb3c10c1a
prerequisite-patch-id: 749e4eafb431857ee2bec4ac8e78a682f6a57588
prerequisite-patch-id: d4a3666ce2e7135402537cea60e9e6f0435230bf
prerequisite-patch-id: fa8ad1bfce7d6ab74ad63ff8d31dff3c2ccb5e43
prerequisite-patch-id: cc352634b8dfaf2d4243819362326a579e010c94
prerequisite-patch-id: 8e0fa3d987020ca06e22401bc4c69f834c38c3dc
-- 
2.17.1



[PATCH v4 2/3] configs: starfive-jh7110: Add support for PCIe host driver

2023-04-10 Thread Minda Chen
From: Mason Huo 

also add the nvme driver and rtl8169 support.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_12a_defconfig | 10 ++
 configs/starfive_visionfive2_13b_defconfig | 10 ++
 2 files changed, 20 insertions(+)

diff --git a/configs/starfive_visionfive2_12a_defconfig 
b/configs/starfive_visionfive2_12a_defconfig
index e0f98292ff..bd5b25f9d4 100644
--- a/configs/starfive_visionfive2_12a_defconfig
+++ b/configs/starfive_visionfive2_12a_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -49,9 +50,12 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
+CONFIG_CMD_PCI=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,12 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
+CONFIG_PCIE_STARFIVE_JH7110=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
diff --git a/configs/starfive_visionfive2_13b_defconfig 
b/configs/starfive_visionfive2_13b_defconfig
index 550d0ff3ab..7247992796 100644
--- a/configs/starfive_visionfive2_13b_defconfig
+++ b/configs/starfive_visionfive2_13b_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -50,8 +51,11 @@ CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,12 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
+CONFIG_PCIE_STARFIVE_JH7110=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



Re: [PATCH v3 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-04-07 Thread Minda Chen



On 2023/3/31 20:59, Pali Rohár wrote:
> On Friday 31 March 2023 18:35:00 Minda Chen wrote:
>> On 2023/3/30 1:27, Pali Rohár wrote:
>> > Hello!
>> > 
>> > On Wednesday 29 March 2023 18:01:41 Minda Chen wrote:
>> >> + /* PCIe PCI Standard Configuration Identification Settings. */
>> >> + value = (PCI_CLASS_BRIDGE_PCI_NORMAL << IDS_CLASS_CODE_SHIFT) | 
>> >> IDS_REVISION_ID;
>> >> + writel(value, priv->reg_base + PCIE_PCI_IDS);
>> > 
>> > This looks like configuration of the PCI_CLASS_REVISION read-only
>> > register. Is there any reason why you are removing the original
>> > "revision" information by hardcoded IDS_REVISION_ID constant?
>> > 
>> This register is not read-only register, consist  resion ID and class code.
>>  Bit [39:32]: Revision ID
>>  Bit [63:40]: Class code
> 
> I mean that this "priv->reg_base + PCIE_PCI_IDS" read-write register
> configures what is visible when reading read-only standard PCI register
> PCI_CLASS_REVISION.
> 
> PCIe Root Port is by definition of PCI-to-PCI Bridge class and therefore
> reading from PCI_CLASS_REVISION must return PCI_CLASS_BRIDGE_PCI_* value.
> This is required by PCIe spec.
> 
> With above driver init code it looks like that your PCIe controller does
> not set correct value into PCI_CLASS_REVISION register after power-on
> and manually setting correct value via "priv->reg_base + PCIE_PCI_IDS"
> is a workaround.
> 
> Hopefully it is a more clear what I mean in my previous email.
> 

> Also mvebu controller has this issue and has similar workaround in
> pci_mvebu.c driver.
> 
>> And the register reset value is zero, Our PCIe version is 2.0. So set value 
>> 2.
>> Maybe I will add comment to  this.
> 
> Well, Revision ID (low 8 bits of PCI_CLASS_REVISION) is the extension to
> the vendor / device id register. It is not version of PCIe standard.
> 
> I would expect that this Vendor ID, Device ID and Revision ID values are
> not being changed by the driver as they identify PCI and PCIe devices.
I am sorry. It is PCIe controller IP revision ID. I have make a mistake for it.
So zero value is correct. I will remove writing IDS_REVISION_ID value.


Re: [PATCH v3 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-31 Thread Minda Chen



On 2023/3/30 1:27, Pali Rohár wrote:
> Hello!
> 
> On Wednesday 29 March 2023 18:01:41 Minda Chen wrote:
>> From: Mason Huo 
>> 
>> Add pcie driver for StarFive JH7110, the driver depends on
>> starfive gpio, pinctrl, clk and reset driver to do init.
>> 
>> Several devices are tested:
>> a) M.2 NVMe SSD
>> b) Realtek 8169 Ethernet adapter.
>> 
>> Signed-off-by: Mason Huo 
>> Signed-off-by: Minda Chen 
>> ---
>>  drivers/pci/Kconfig|  11 +
>>  drivers/pci/Makefile   |   1 +
>>  drivers/pci/pcie_starfive_jh7110.c | 463 +
>>  3 files changed, 475 insertions(+)
>>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>> 
>> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> index ef328d2652..e7b0ff5bc3 100644
>> --- a/drivers/pci/Kconfig
>> +++ b/drivers/pci/Kconfig
>> @@ -374,4 +374,15 @@ config PCIE_UNIPHIER
>>Say Y here if you want to enable PCIe controller support on
>>UniPhier SoCs.
>>  
>> +config PCIE_STARFIVE_JH7110
>> +bool "Enable Starfive JH7110 PCIe driver"
>> +depends on STARFIVE_JH7110
>> +depends on PINCTRL_STARFIVE_JH7110
>> +depends on CLK_JH7110
>> +depends on RESET_JH7110
> 
> There is no direct hard dependency on on these 4 symbols (or at least I
> do not see any in include header files). So to allow compile time
> checks, change it to just soft dependency by switching from "depends" to
> "imply" keyword.
> 
ok, I will change this.
>> +default y
>> +help
>> +  Say Y here if you want to enable PCIe controller support on
>> +  StarFive JH7110 SoC.
>> +
>>  endif
> ...
>> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
>> b/drivers/pci/pcie_starfive_jh7110.c
>> new file mode 100644
>> index 00..1005ed9919
>> --- /dev/null
>> +++ b/drivers/pci/pcie_starfive_jh7110.c
> ...
>> +static int starfive_pcie_off_conf(pci_dev_t bdf, uint offset)
>> +{
>> +unsigned int bus = PCI_BUS(bdf);
>> +unsigned int dev = PCI_DEV(bdf);
>> +unsigned int func = PCI_FUNC(bdf);
>> +
>> +return PCIE_ECAM_OFFSET(bus, dev, func, offset);
> 
> This function is used just on one place, it is pretty straightforward
> and nothing starfive_pcie-specific. Just directly inline it into
> starfive_pcie_conf_address() function?
> 
>   int where = PCIE_ECAM_OFFSET(PCI_BUS(bdf), PCI_DEV(bdf), PCI_FUNC(bdf), 
> offset);
> 
ok, thanks
>> +}
>> +
>> +static int starfive_pcie_addr_valid(pci_dev_t bdf, int first_busno)
>> +{
>> +/*
>> + * Single device limitation.
>> + * For JH7110 SoC limitation, one bus can only connnect one device.
>> + * And PCIe controller contain HW issue that non-root host bridge
>> + * bus emumerate duplicate devices.
>> + * Only can access device 0 in Bus 1 host bridge.
>> + */
>> +if ((PCI_BUS(bdf) != first_busno) && (PCI_DEV(bdf) > 0))
>> +return 0;
> 
> In v2 discussion you wrote that the issue with duplicate devices is on
> the bus 1, which is secondary bus - the bus behind the root port.
> 
> So check against root port bus (first_busno) is not correct, you need to
> check it against bus behind the root port (secondary bus).
> 
> Current check completely filters all devices with numbers higher than 0
> behind the secondary bus, which completely breaks support for PCIe
> switches. Moreover behind PCIe switch can be anything with more
> complicated topology.
> 
> That secondary bus number is dynamically allocated / assigned by U-Boot
> core code, so you need to check PCI_SECONDARY_BUS register of the root
> port.
> 
> In pci_mvebu.c is this value cached in "->sec_busno" member. You can
> reuse this pattern.
> 
> You probably want this kind of check:
> 
>   if (PCI_BUS(bdf) == priv->sec_busno && PCI_DEV(bdf) > 0)
> return false;
>   else
> return true;
> 
OK, thanks, I will record secondary busno according PCI_SECONDARY_BUS  register
> Also comment "non-root host bridge bus" is strange. Bus of the host
> bridge is always the root one. You probably want to write the bus
> immediately behind the root bus / host bridge OR the secondary bus of
> the host bridge.
> 
ok
>> +return 1;
>> +}
>> +
>> +static int starfive_pcie_conf_address(const struct udevice *udev, pci_dev_t 
>> bdf,
>> +  uint offset, void **paddr)
>> +{
>> +struct starfiv

[PATCH v3 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-29 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, the driver depends on
starfive gpio, pinctrl, clk and reset driver to do init.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 drivers/pci/Kconfig|  11 +
 drivers/pci/Makefile   |   1 +
 drivers/pci/pcie_starfive_jh7110.c | 463 +
 3 files changed, 475 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index ef328d2652..e7b0ff5bc3 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -374,4 +374,15 @@ config PCIE_UNIPHIER
  Say Y here if you want to enable PCIe controller support on
  UniPhier SoCs.
 
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   depends on STARFIVE_JH7110
+   depends on PINCTRL_STARFIVE_JH7110
+   depends on CLK_JH7110
+   depends on RESET_JH7110
+   default y
+   help
+ Say Y here if you want to enable PCIe controller support on
+ StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 49506e7ba5..bbe3323bb5 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
 obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_starfive_jh7110.c 
b/drivers/pci/pcie_starfive_jh7110.c
new file mode 100644
index 00..1005ed9919
--- /dev/null
+++ b/drivers/pci/pcie_starfive_jh7110.c
@@ -0,0 +1,463 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * StarFive PLDA PCIe host controller driver
+ *
+ * Copyright (c) 2023 Starfive, Inc.
+ * Author: Mason Huo 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define GEN_SETTINGS   0x80
+#define PCIE_PCI_IDS   0x9C
+#define PCIE_WINROM0xFC
+#define PMSG_SUPPORT_RX0x3F0
+#define PCI_MISC   0xB4
+
+#define PLDA_EP_ENABLE 0
+#define PLDA_RP_ENABLE 1
+
+#define IDS_REVISION_ID0x02
+#define IDS_CLASS_CODE_SHIFT   8
+
+#define PREF_MEM_WIN_64_SUPPORTBIT(3)
+#define PMSG_LTR_SUPPORT   BIT(2)
+#define PLDA_FUNCTION_DIS  BIT(15)
+#define PLDA_FUNC_NUM  4
+#define PLDA_PHY_FUNC_SHIFT9
+
+#define XR3PCI_ATR_AXI4_SLV0   0x800
+#define XR3PCI_ATR_SRC_ADDR_LOW0x0
+#define XR3PCI_ATR_SRC_ADDR_HIGH   0x4
+#define XR3PCI_ATR_TRSL_ADDR_LOW   0x8
+#define XR3PCI_ATR_TRSL_ADDR_HIGH  0xc
+#define XR3PCI_ATR_TRSL_PARAM  0x10
+#define XR3PCI_ATR_TABLE_OFFSET0x20
+#define XR3PCI_ATR_MAX_TABLE_NUM   8
+
+#define XR3PCI_ATR_SRC_WIN_SIZE_SHIFT  1
+#define XR3PCI_ATR_SRC_ADDR_MASK   GENMASK(31, 12)
+#define XR3PCI_ATR_TRSL_ADDR_MASK  GENMASK(31, 12)
+#define XR3_PCI_ECAM_SIZE  28
+#define XR3PCI_ATR_TRSL_DIRBIT(22)
+/* IDs used in the XR3PCI_ATR_TRSL_PARAM */
+#define XR3PCI_ATR_TRSLID_PCIE_MEMORY  0x0
+#define XR3PCI_ATR_TRSLID_PCIE_CONFIG  0x1
+
+/* system control */
+#define STG_SYSCON_K_RP_NEP_MASK   BIT(8)
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_MASK   GENMASK(22, 8)
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_SHIFT  8
+#define STG_SYSCON_AXI4_SLVL_AWFUNC_MASK   GENMASK(14, 0)
+#define STG_SYSCON_CLKREQ_MASK BIT(22)
+#define STG_SYSCON_CKREF_SRC_SHIFT 18
+#define STG_SYSCON_CKREF_SRC_MASK  GENMASK(19, 18)
+
+struct starfive_pcie {
+   struct udevice *dev;
+
+   void __iomem *reg_base;
+   void __iomem *cfg_base;
+
+   struct regmap *regmap;
+   u32 stg_arfun;
+   u32 stg_awfun;
+   u32 stg_rp_nep;
+
+   struct clk_bulk clks;
+   struct reset_ctl_bulk   rsts;
+   struct gpio_descreset_gpio;
+
+   int atr_table_num;
+   int first_busno;
+};
+
+static int starfive_pcie_off_conf(pci_dev_t bdf, uint offset)
+{
+   unsigned int bus = PCI_BUS(bdf);
+   unsigned int dev = PCI_DEV(bdf);
+   unsigned int func = PCI_FUNC(bdf);
+
+   return PCIE_ECAM_OFFSET(bus, dev, func, offset);
+}
+
+static int starfive_pcie_addr_valid(pci_dev_t bdf, int first_busno)
+{
+   /*
+* Single device limitation.
+* For JH7110 SoC limitation, one bus can only connnect one device.
+* And PCIe controller contain HW issue that non-root host bridge
+* bus emumerate duplicate devices.
+

[PATCH v3 3/3] riscv: dts: starfive: Enable PCIe host controller

2023-03-29 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.
Also add JH7110 stg syscon configuration.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi | 11 +++
 arch/riscv/dts/jh7110.dtsi| 74 +++
 2 files changed, 85 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index c6b6dfa940..12245576ac 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -7,6 +7,7 @@
 
 #include "jh7110.dtsi"
 #include 
+#include 
 / {
aliases {
serial0 = 
@@ -300,6 +301,16 @@
};
 };
 
+ {
+   reset-gpios = < 26 GPIO_ACTIVE_LOW>;
+   status = "disabled";
+};
+
+ {
+   reset-gpios = < 28 GPIO_ACTIVE_LOW>;
+   status = "okay";
+};
+
  {
assigned-clocks = < JH7110_SYSCLK_CPU_ROOT>,
  < JH7110_SYSCLK_BUS_ROOT>,
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index bd60879615..eaf8035a61 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -569,5 +569,79 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   pcie0: pcie@2B00 {
+   compatible = "starfive,jh7110-pcie";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   reg = <0x0 0x2B00 0x0 0x100>,
+ <0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0xc0 0xc4 0x130>;
+   bus-range = <0x0 0xff>;
+   ranges = <0x8200  0x0 0x3000  0x0 0x3000 
0x0 0x0800>,
+   <0xc300  0x9 0x  0x9 0x 0x0 
0x4000>;
+   msi-parent = <>;
+   interrupts = <56>;
+   interrupt-controller;
+   interrupt-names = "msi";
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   resets = < JH7110_STGRST_PCIE0_MST0>,
+< JH7110_STGRST_PCIE0_SLV0>,
+< JH7110_STGRST_PCIE0_SLV>,
+< JH7110_STGRST_PCIE0_BRG>,
+< JH7110_STGRST_PCIE0_CORE>,
+< JH7110_STGRST_PCIE0_APB>;
+   clocks = < JH7110_SYSCLK_NOC_BUS_STG_AXI>,
+< JH7110_STGCLK_PCIE0_TL>,
+< JH7110_STGCLK_PCIE0_AXI>,
+< JH7110_STGCLK_PCIE0_APB>;
+   clock-names = "noc_bus_stg_axi", "pcie0_tl", 
"pcie0_axi", "pcie0_apb";
+   status = "disabled";
+   };
+
+   pcie1: pcie@2C00 {
+   compatible = "starfive,jh7110-pcie";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   reg = <0x0 0x2C00 0x0 0x100>,
+ <0x9 0xc000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0x270 0x274 0x2e0>;
+   bus-range = <0x0 0xff>;
+   ranges = <0x8200  0x0 0x3800  0x0 0x3800 
0x0 0x0800>,
+   <0xc300  0x9 0x8000  0x9 0x8000 0x0 
0x4000>;
+   msi-parent = <>;
+   interrupts = <57>;
+   interrupt-controller;
+   interrupt-names = "msi";
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0

[PATCH v3 2/3] configs: starfive-jh7110: Add support for PCIe host driver

2023-03-29 Thread Minda Chen
From: Mason Huo 

also add the nvme driver and rtl8169 support.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_12a_defconfig | 9 +
 configs/starfive_visionfive2_13b_defconfig | 9 +
 2 files changed, 18 insertions(+)

diff --git a/configs/starfive_visionfive2_12a_defconfig 
b/configs/starfive_visionfive2_12a_defconfig
index e0f98292ff..2a7563743b 100644
--- a/configs/starfive_visionfive2_12a_defconfig
+++ b/configs/starfive_visionfive2_12a_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -49,9 +50,12 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
+CONFIG_CMD_PCI=y
 CONFIG_CMD_MEMINFO=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,11 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
diff --git a/configs/starfive_visionfive2_13b_defconfig 
b/configs/starfive_visionfive2_13b_defconfig
index 550d0ff3ab..98d23d9461 100644
--- a/configs/starfive_visionfive2_13b_defconfig
+++ b/configs/starfive_visionfive2_13b_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -50,8 +51,11 @@ CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,11 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



[PATCH v3 0/3] Add StarFive JH7110 PCIe drvier support

2023-03-29 Thread Minda Chen
This patchset needs to apply after patchset in [1]. These PCIe series patches
are based on the JH7110 RISC-V SoC and VisionFive V2 board.

[1] 
https://patchwork.ozlabs.org/project/uboot/cover/20230329034224.26545-1-yanhong.w...@starfivetech.com

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

previous patch version

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/
v2: 
https://patchwork.ozlabs.org/project/uboot/cover/20230308054833.95730-1-minda.c...@starfivetech.com/

changes
  v2
   1. remove clock commit. The pcie clocks change has been includeded in [1].
   2. Using GENMASK marco1 in patch1.
   3. remove the syscon dts node in patch3. The syscon dts dts node has been
  included in [1]. 

  v3
   patch 1
1. remove the read vendor ID delay
2. remove starfive_pcie_hide_rc_bar function. do not hide host
bridge BAR write.
3. Using PCIE_ECAM_OFFSET and PCI_CLASS_BRIDGE_PCI_NORMAL macros.
4. Add comments for bus and address limitation reason in function
   starfive_pcie_addr_valid
5. Change the multiple line comments in Line 373
6. Using gpio_request_by_name to get PCIe reset gpio,and using
   dm_gpio_set_value set GPIO value.
  patch 2
1. support PCIeboth 12a and 13b vf2 board.  
  patch 3
1. reset dts change to reset-gpio.

---

The JH7110 minimal system patchset upstream is in progress.
PCIe driver patches is based on this patchset.

The JH7110 minimal system patchset details are listed in [1].

For more JH7110 and visionFive v2 information and support,
you can visit RVspace wiki[2].

[2] https://wiki.rvspace.org/

Mason Huo (3):
  starfive: pci: Add StarFive JH7110 pcie driver
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

 .../dts/jh7110-starfive-visionfive-2.dtsi |  11 +
 arch/riscv/dts/jh7110.dtsi|  74 +++
 configs/starfive_visionfive2_12a_defconfig|   9 +
 configs/starfive_visionfive2_13b_defconfig|   9 +
 drivers/pci/Kconfig   |  11 +
 drivers/pci/Makefile  |   1 +
 drivers/pci/pcie_starfive_jh7110.c| 463 ++
 7 files changed, 578 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c


base-commit: 41a88ad529b3943b1e465846eb24fe2c29203e35
prerequisite-patch-id: a84452ba131408ff842b65ae19a3a05f64b3ff60
prerequisite-patch-id: 4abb46d56dbaf36017b2866688f31a73c2cacd0d
prerequisite-patch-id: ef5e9d61f7392c7d2e5321aa8a10996ca8eae5fc
prerequisite-patch-id: 26dfdb401d680ecd9449acf09131cf4790e987b7
prerequisite-patch-id: a0cfa5d8cdb49bbe9d4739afa90991f882950881
prerequisite-patch-id: 61ceecb41cfd9029bfb267f7b7c5330a2d7e5edc
prerequisite-patch-id: d834ece14ffb525b8c3e661e78736692f33fca9b
prerequisite-patch-id: 88c9f9637335fdc4107d42db67b9110c9b73ead3
prerequisite-patch-id: ebc26ed3f97f7babc0fc805152acb578f5eff922
prerequisite-patch-id: e85a9ca22facac4d5b5562a2708b7332478d6db4
prerequisite-patch-id: ff5bd799e4cb905fef6cf1cd0ce757980e1d34b7
prerequisite-patch-id: a341d4e8a8e25cb711309123939235fcb3c10c1a
prerequisite-patch-id: 749e4eafb431857ee2bec4ac8e78a682f6a57588
prerequisite-patch-id: d4a3666ce2e7135402537cea60e9e6f0435230bf
prerequisite-patch-id: fa8ad1bfce7d6ab74ad63ff8d31dff3c2ccb5e43
prerequisite-patch-id: cc352634b8dfaf2d4243819362326a579e010c94
prerequisite-patch-id: 8e0fa3d987020ca06e22401bc4c69f834c38c3dc
-- 
2.17.1



Re: [PATCH v2 3/3] riscv: dts: starfive: Enable PCIe host controller

2023-03-26 Thread Minda Chen



On 2023/3/25 21:22, Pali Rohár wrote:
> On Wednesday 08 March 2023 13:48:33 Minda Chen wrote:
>> From: Mason Huo 
>> 
>> Enable and add pinctrl configuration for PCIe host controller.
>> Also add JH7110 stg syscon configuration.
>> 
>> Signed-off-by: Mason Huo 
>> Signed-off-by: Minda Chen 
>> ---
>>  .../dts/jh7110-starfive-visionfive-2.dtsi | 99 +++
>>  arch/riscv/dts/jh7110.dtsi| 75 ++
>>  2 files changed, 174 insertions(+)
>> 
>> diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
>> b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
>> index e669c2a26a..995f842a6b 100644
>> --- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
>> +++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
>> @@ -178,6 +178,87 @@
>>  slew-rate = <0>;
>>  };
>>  };
>> +
>> +pcie0_perst_default: pcie0_perst_default {
>> +perst-pins {
>> +pinmux = > GPI_NONE)>;
>> +drive-strength = <2>;
>> +input-disable;
>> +input-schmitt-disable;
>> +slew-rate = <0>;
>> +};
>> +};
>> +
>> +pcie0_perst_active: pcie0_perst_active {
>> +perst-pins {
>> +pinmux = > GPI_NONE)>;
>> +drive-strength = <2>;
>> +input-disable;
>> +input-schmitt-disable;
>> +slew-rate = <0>;
>> +};
>> +};
> ...
>> + {
>> +pinctrl-names = "perst-default", "perst-active", "wake-default", 
>> "clkreq-default";
>> +pinctrl-0 = <_perst_default>;
>> +pinctrl-1 = <_perst_active>;
>> +pinctrl-2 = <_wake_default>;
>> +pinctrl-3 = <_clkreq_default>;
>> +status = "disabled";
>> +};
> 
> This is not correct declaration of PERST# signal. You should define in
>  node "reset-gpios" property with plain gpio definition with
> active state.
> 
> "reset-gpios" is standard PCIe property for controlling PERST# signal
> over GPIO. Look for example into drivers/pci/pci-aardvark.c and
> arch/arm/dts/armada-3720-espressobin.dtsi files how it is used.

OK, I will change this, thanks


Re: [PATCH v2 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-26 Thread Minda Chen



On 2023/3/25 20:31, Pali Rohár wrote:
> On Friday 24 March 2023 18:57:33 Minda Chen wrote:
>> On 2023/3/24 2:19, Pali Rohár wrote:
>> > On Thursday 23 March 2023 18:51:38 Minda Chen wrote:
>> >> On 2023/3/11 1:42, Pali Rohár wrote:
>> >> > On Friday 10 March 2023 18:36:44 Minda Chen wrote:
>> >> >> On 2023/3/8 15:31, Pali Rohár wrote:
>> >> >> > Hello! See few comments below.
>> >> >> > 
>> >> >> > On Wednesday 08 March 2023 13:48:31 Minda Chen wrote:
>> >> >> >> From: Mason Huo 
>> >> >> >> 
>> >> >> >> Add pcie driver for StarFive JH7110, the driver depends on
>> >> >> >> starfive gpio, pinctrl, clk and reset driver to do init.
>> >> >> >> 
>> >> >> >> Several devices are tested:
>> >> >> >> a) M.2 NVMe SSD
>> >> >> >> b) Realtek 8169 Ethernet adapter.
>> >> >> >> 
>> >> >> >> Signed-off-by: Mason Huo 
>> >> >> >> Signed-off-by: Minda Chen 
>> >> >> >> ---
>> >> >> >>  drivers/pci/Kconfig|  11 +
>> >> >> >>  drivers/pci/Makefile   |   1 +
>> >> >> >>  drivers/pci/pcie_starfive_jh7110.c | 478 
>> >> >> >> +
>> >> >> >>  3 files changed, 490 insertions(+)
>> >> >> >>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>> >> >> >> 
>> >> >> >> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> >> >> >> index ef328d2652..e7b0ff5bc3 100644
>> >> >> >> --- a/drivers/pci/Kconfig
>> >> >> >> +++ b/drivers/pci/Kconfig
>> >> >> >> @@ -374,4 +374,15 @@ config PCIE_UNIPHIER
>> >> >> >>   Say Y here if you want to enable PCIe controller support on
>> >> >> >>   UniPhier SoCs.
>> >> >> >>  
>> >> >> >> +config PCIE_STARFIVE_JH7110
>> >> >> >> +   bool "Enable Starfive JH7110 PCIe driver"
>> >> >> >> +   depends on STARFIVE_JH7110
>> >> >> >> +   depends on PINCTRL_STARFIVE_JH7110
>> >> >> >> +   depends on CLK_JH7110
>> >> >> >> +   depends on RESET_JH7110
>> >> >> >> +   default y
>> >> >> >> +   help
>> >> >> >> + Say Y here if you want to enable PCIe controller support on
>> >> >> >> + StarFive JH7110 SoC.
>> >> >> >> +
>> >> >> >>  endif
>> >> >> >> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
>> >> >> >> index 49506e7ba5..bbe3323bb5 100644
>> >> >> >> --- a/drivers/pci/Makefile
>> >> >> >> +++ b/drivers/pci/Makefile
>> >> >> >> @@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
>> >> >> >>  obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
>> >> >> >>  obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
>> >> >> >>  obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
>> >> >> >> +obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
>> >> >> >> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
>> >> >> >> b/drivers/pci/pcie_starfive_jh7110.c
>> >> >> >> new file mode 100644
>> >> >> >> index 00..5ccef1ef02
>> >> >> >> --- /dev/null
>> >> >> >> +++ b/drivers/pci/pcie_starfive_jh7110.c
>> >> >> >> @@ -0,0 +1,478 @@
>> >> >> >> +// SPDX-License-Identifier: GPL-2.0+
>> >> >> >> +/*
>> >> >> >> + * StarFive PLDA PCIe host controller driver
>> >> >> >> + *
>> >> >> >> + * Copyright (c) 2023 Starfive, Inc.
>> >> >> >> + * Author: Mason Huo 
>> >> >> >> + *
>> >> >> >> + */
>> >> >> >> +
>> >> >> >> +#include 
>> >> >> >> +#include 
>> >> >> >> +#include 
>> >> >> >> +#i

Re: [PATCH v2 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-24 Thread Minda Chen



On 2023/3/24 2:19, Pali Rohár wrote:
> On Thursday 23 March 2023 18:51:38 Minda Chen wrote:
>> On 2023/3/11 1:42, Pali Rohár wrote:
>> > On Friday 10 March 2023 18:36:44 Minda Chen wrote:
>> >> On 2023/3/8 15:31, Pali Rohár wrote:
>> >> > Hello! See few comments below.
>> >> > 
>> >> > On Wednesday 08 March 2023 13:48:31 Minda Chen wrote:
>> >> >> From: Mason Huo 
>> >> >> 
>> >> >> Add pcie driver for StarFive JH7110, the driver depends on
>> >> >> starfive gpio, pinctrl, clk and reset driver to do init.
>> >> >> 
>> >> >> Several devices are tested:
>> >> >> a) M.2 NVMe SSD
>> >> >> b) Realtek 8169 Ethernet adapter.
>> >> >> 
>> >> >> Signed-off-by: Mason Huo 
>> >> >> Signed-off-by: Minda Chen 
>> >> >> ---
>> >> >>  drivers/pci/Kconfig|  11 +
>> >> >>  drivers/pci/Makefile   |   1 +
>> >> >>  drivers/pci/pcie_starfive_jh7110.c | 478 +
>> >> >>  3 files changed, 490 insertions(+)
>> >> >>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>> >> >> 
>> >> >> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> >> >> index ef328d2652..e7b0ff5bc3 100644
>> >> >> --- a/drivers/pci/Kconfig
>> >> >> +++ b/drivers/pci/Kconfig
>> >> >> @@ -374,4 +374,15 @@ config PCIE_UNIPHIER
>> >> >>  Say Y here if you want to enable PCIe controller support on
>> >> >>  UniPhier SoCs.
>> >> >>  
>> >> >> +config PCIE_STARFIVE_JH7110
>> >> >> +  bool "Enable Starfive JH7110 PCIe driver"
>> >> >> +  depends on STARFIVE_JH7110
>> >> >> +  depends on PINCTRL_STARFIVE_JH7110
>> >> >> +  depends on CLK_JH7110
>> >> >> +  depends on RESET_JH7110
>> >> >> +  default y
>> >> >> +  help
>> >> >> +Say Y here if you want to enable PCIe controller support on
>> >> >> +StarFive JH7110 SoC.
>> >> >> +
>> >> >>  endif
>> >> >> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
>> >> >> index 49506e7ba5..bbe3323bb5 100644
>> >> >> --- a/drivers/pci/Makefile
>> >> >> +++ b/drivers/pci/Makefile
>> >> >> @@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
>> >> >>  obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
>> >> >>  obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
>> >> >>  obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
>> >> >> +obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
>> >> >> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
>> >> >> b/drivers/pci/pcie_starfive_jh7110.c
>> >> >> new file mode 100644
>> >> >> index 00..5ccef1ef02
>> >> >> --- /dev/null
>> >> >> +++ b/drivers/pci/pcie_starfive_jh7110.c
>> >> >> @@ -0,0 +1,478 @@
>> >> >> +// SPDX-License-Identifier: GPL-2.0+
>> >> >> +/*
>> >> >> + * StarFive PLDA PCIe host controller driver
>> >> >> + *
>> >> >> + * Copyright (c) 2023 Starfive, Inc.
>> >> >> + * Author: Mason Huo 
>> >> >> + *
>> >> >> + */
>> >> >> +
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +#include 
>> >> >> +
>> >> >> +DECLARE_GLOBAL_DATA_PTR;
>> >> >> +
>> >> >> +#define GEN_SETTINGS  0x80
>> >> >> +#define PCIE_PCI_IDS  0x9C
>> >> >> +

Re: [PATCH v2 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-23 Thread Minda Chen



On 2023/3/11 1:42, Pali Rohár wrote:
> On Friday 10 March 2023 18:36:44 Minda Chen wrote:
>> On 2023/3/8 15:31, Pali Rohár wrote:
>> > Hello! See few comments below.
>> > 
>> > On Wednesday 08 March 2023 13:48:31 Minda Chen wrote:
>> >> From: Mason Huo 
>> >> 
>> >> Add pcie driver for StarFive JH7110, the driver depends on
>> >> starfive gpio, pinctrl, clk and reset driver to do init.
>> >> 
>> >> Several devices are tested:
>> >> a) M.2 NVMe SSD
>> >> b) Realtek 8169 Ethernet adapter.
>> >> 
>> >> Signed-off-by: Mason Huo 
>> >> Signed-off-by: Minda Chen 
>> >> ---
>> >>  drivers/pci/Kconfig|  11 +
>> >>  drivers/pci/Makefile   |   1 +
>> >>  drivers/pci/pcie_starfive_jh7110.c | 478 +
>> >>  3 files changed, 490 insertions(+)
>> >>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>> >> 
>> >> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> >> index ef328d2652..e7b0ff5bc3 100644
>> >> --- a/drivers/pci/Kconfig
>> >> +++ b/drivers/pci/Kconfig
>> >> @@ -374,4 +374,15 @@ config PCIE_UNIPHIER
>> >> Say Y here if you want to enable PCIe controller support on
>> >> UniPhier SoCs.
>> >>  
>> >> +config PCIE_STARFIVE_JH7110
>> >> + bool "Enable Starfive JH7110 PCIe driver"
>> >> + depends on STARFIVE_JH7110
>> >> + depends on PINCTRL_STARFIVE_JH7110
>> >> + depends on CLK_JH7110
>> >> + depends on RESET_JH7110
>> >> + default y
>> >> + help
>> >> +   Say Y here if you want to enable PCIe controller support on
>> >> +   StarFive JH7110 SoC.
>> >> +
>> >>  endif
>> >> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
>> >> index 49506e7ba5..bbe3323bb5 100644
>> >> --- a/drivers/pci/Makefile
>> >> +++ b/drivers/pci/Makefile
>> >> @@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
>> >>  obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
>> >>  obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
>> >>  obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
>> >> +obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
>> >> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
>> >> b/drivers/pci/pcie_starfive_jh7110.c
>> >> new file mode 100644
>> >> index 00..5ccef1ef02
>> >> --- /dev/null
>> >> +++ b/drivers/pci/pcie_starfive_jh7110.c
>> >> @@ -0,0 +1,478 @@
>> >> +// SPDX-License-Identifier: GPL-2.0+
>> >> +/*
>> >> + * StarFive PLDA PCIe host controller driver
>> >> + *
>> >> + * Copyright (c) 2023 Starfive, Inc.
>> >> + * Author: Mason Huo 
>> >> + *
>> >> + */
>> >> +
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +#include 
>> >> +
>> >> +DECLARE_GLOBAL_DATA_PTR;
>> >> +
>> >> +#define GEN_SETTINGS 0x80
>> >> +#define PCIE_PCI_IDS 0x9C
>> >> +#define PCIE_WINROM  0xFC
>> >> +#define PMSG_SUPPORT_RX  0x3F0
>> >> +#define PCI_MISC 0xB4
>> >> +
>> >> +#define PLDA_EP_ENABLE   0
>> >> +#define PLDA_RP_ENABLE   1
>> >> +
>> >> +#define IDS_REVISION_ID  0x02
>> >> +#define IDS_PCI_TO_PCI_BRIDGE0x060400
>> >> +#define IDS_CLASS_CODE_SHIFT 8
>> > 
>> > Please do not duplicate standard PCI macros and constants. In U-Boot
>> > they are already available in include/pci_ids.h header file.
>> > 
>> ok
>> >> +#define PREF_MEM_WIN_64_SUPPORT  BIT(3)
>> >> +#define PMSG_LTR_SUPPORT BIT(2)
>> >> +#define PLDA_FUNCTION_DISBIT(15)
>> >> +#define PLDA_FUNC

Re: [PATCH v2 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-10 Thread Minda Chen



On 2023/3/8 15:31, Pali Rohár wrote:
> Hello! See few comments below.
> 
> On Wednesday 08 March 2023 13:48:31 Minda Chen wrote:
>> From: Mason Huo 
>> 
>> Add pcie driver for StarFive JH7110, the driver depends on
>> starfive gpio, pinctrl, clk and reset driver to do init.
>> 
>> Several devices are tested:
>> a) M.2 NVMe SSD
>> b) Realtek 8169 Ethernet adapter.
>> 
>> Signed-off-by: Mason Huo 
>> Signed-off-by: Minda Chen 
>> ---
>>  drivers/pci/Kconfig|  11 +
>>  drivers/pci/Makefile   |   1 +
>>  drivers/pci/pcie_starfive_jh7110.c | 478 +
>>  3 files changed, 490 insertions(+)
>>  create mode 100644 drivers/pci/pcie_starfive_jh7110.c
>> 
>> diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
>> index ef328d2652..e7b0ff5bc3 100644
>> --- a/drivers/pci/Kconfig
>> +++ b/drivers/pci/Kconfig
>> @@ -374,4 +374,15 @@ config PCIE_UNIPHIER
>>Say Y here if you want to enable PCIe controller support on
>>UniPhier SoCs.
>>  
>> +config PCIE_STARFIVE_JH7110
>> +bool "Enable Starfive JH7110 PCIe driver"
>> +depends on STARFIVE_JH7110
>> +depends on PINCTRL_STARFIVE_JH7110
>> +depends on CLK_JH7110
>> +depends on RESET_JH7110
>> +default y
>> +help
>> +  Say Y here if you want to enable PCIe controller support on
>> +  StarFive JH7110 SoC.
>> +
>>  endif
>> diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
>> index 49506e7ba5..bbe3323bb5 100644
>> --- a/drivers/pci/Makefile
>> +++ b/drivers/pci/Makefile
>> @@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
>>  obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
>>  obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
>>  obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
>> +obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
>> diff --git a/drivers/pci/pcie_starfive_jh7110.c 
>> b/drivers/pci/pcie_starfive_jh7110.c
>> new file mode 100644
>> index 00..5ccef1ef02
>> --- /dev/null
>> +++ b/drivers/pci/pcie_starfive_jh7110.c
>> @@ -0,0 +1,478 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +/*
>> + * StarFive PLDA PCIe host controller driver
>> + *
>> + * Copyright (c) 2023 Starfive, Inc.
>> + * Author: Mason Huo 
>> + *
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +DECLARE_GLOBAL_DATA_PTR;
>> +
>> +#define GEN_SETTINGS0x80
>> +#define PCIE_PCI_IDS0x9C
>> +#define PCIE_WINROM 0xFC
>> +#define PMSG_SUPPORT_RX 0x3F0
>> +#define PCI_MISC0xB4
>> +
>> +#define PLDA_EP_ENABLE  0
>> +#define PLDA_RP_ENABLE  1
>> +
>> +#define IDS_REVISION_ID 0x02
>> +#define IDS_PCI_TO_PCI_BRIDGE   0x060400
>> +#define IDS_CLASS_CODE_SHIFT8
> 
> Please do not duplicate standard PCI macros and constants. In U-Boot
> they are already available in include/pci_ids.h header file.
> 
ok
>> +#define PREF_MEM_WIN_64_SUPPORT BIT(3)
>> +#define PMSG_LTR_SUPPORTBIT(2)
>> +#define PLDA_FUNCTION_DIS   BIT(15)
>> +#define PLDA_FUNC_NUM   4
>> +#define PLDA_PHY_FUNC_SHIFT 9
>> +
>> +#define XR3PCI_ATR_AXI4_SLV00x800
>> +#define XR3PCI_ATR_SRC_ADDR_LOW 0x0
>> +#define XR3PCI_ATR_SRC_ADDR_HIGH0x4
>> +#define XR3PCI_ATR_TRSL_ADDR_LOW0x8
>> +#define XR3PCI_ATR_TRSL_ADDR_HIGH   0xc
>> +#define XR3PCI_ATR_TRSL_PARAM   0x10
>> +#define XR3PCI_ATR_TABLE_OFFSET 0x20
>> +#define XR3PCI_ATR_MAX_TABLE_NUM8
>> +
>> +#define XR3PCI_ATR_SRC_WIN_SIZE_SHIFT   1
>> +#define XR3PCI_ATR_SRC_ADDR_MASKGENMASK(31, 12)
>> +#define XR3PCI_ATR_TRSL_ADDR_MASK   GENMASK(31, 12)
>> +#define XR3_PCI_ECAM_SIZE   28
>> +#define XR3PCI_ATR_TRSL_DIR BIT(22)
>> +/* IDs used in the XR3PCI_ATR_TRSL_PARAM */
>> +#define XR3PCI_ATR_TRSLID_PCIE_MEMORY   0x0
>> +#define XR3PCI_ATR_TRSLID_PCIE_CONFIG   0x1
>> +
>> +#define ECA

[PATCH v2 1/3] starfive: pci: Add StarFive JH7110 pcie driver

2023-03-07 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, the driver depends on
starfive gpio, pinctrl, clk and reset driver to do init.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 drivers/pci/Kconfig|  11 +
 drivers/pci/Makefile   |   1 +
 drivers/pci/pcie_starfive_jh7110.c | 478 +
 3 files changed, 490 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index ef328d2652..e7b0ff5bc3 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -374,4 +374,15 @@ config PCIE_UNIPHIER
  Say Y here if you want to enable PCIe controller support on
  UniPhier SoCs.
 
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   depends on STARFIVE_JH7110
+   depends on PINCTRL_STARFIVE_JH7110
+   depends on CLK_JH7110
+   depends on RESET_JH7110
+   default y
+   help
+ Say Y here if you want to enable PCIe controller support on
+ StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index 49506e7ba5..bbe3323bb5 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
 obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_starfive_jh7110.c 
b/drivers/pci/pcie_starfive_jh7110.c
new file mode 100644
index 00..5ccef1ef02
--- /dev/null
+++ b/drivers/pci/pcie_starfive_jh7110.c
@@ -0,0 +1,478 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * StarFive PLDA PCIe host controller driver
+ *
+ * Copyright (c) 2023 Starfive, Inc.
+ * Author: Mason Huo 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define GEN_SETTINGS   0x80
+#define PCIE_PCI_IDS   0x9C
+#define PCIE_WINROM0xFC
+#define PMSG_SUPPORT_RX0x3F0
+#define PCI_MISC   0xB4
+
+#define PLDA_EP_ENABLE 0
+#define PLDA_RP_ENABLE 1
+
+#define IDS_REVISION_ID0x02
+#define IDS_PCI_TO_PCI_BRIDGE  0x060400
+#define IDS_CLASS_CODE_SHIFT   8
+
+#define PREF_MEM_WIN_64_SUPPORTBIT(3)
+#define PMSG_LTR_SUPPORT   BIT(2)
+#define PLDA_FUNCTION_DIS  BIT(15)
+#define PLDA_FUNC_NUM  4
+#define PLDA_PHY_FUNC_SHIFT9
+
+#define XR3PCI_ATR_AXI4_SLV0   0x800
+#define XR3PCI_ATR_SRC_ADDR_LOW0x0
+#define XR3PCI_ATR_SRC_ADDR_HIGH   0x4
+#define XR3PCI_ATR_TRSL_ADDR_LOW   0x8
+#define XR3PCI_ATR_TRSL_ADDR_HIGH  0xc
+#define XR3PCI_ATR_TRSL_PARAM  0x10
+#define XR3PCI_ATR_TABLE_OFFSET0x20
+#define XR3PCI_ATR_MAX_TABLE_NUM   8
+
+#define XR3PCI_ATR_SRC_WIN_SIZE_SHIFT  1
+#define XR3PCI_ATR_SRC_ADDR_MASK   GENMASK(31, 12)
+#define XR3PCI_ATR_TRSL_ADDR_MASK  GENMASK(31, 12)
+#define XR3_PCI_ECAM_SIZE  28
+#define XR3PCI_ATR_TRSL_DIRBIT(22)
+/* IDs used in the XR3PCI_ATR_TRSL_PARAM */
+#define XR3PCI_ATR_TRSLID_PCIE_MEMORY  0x0
+#define XR3PCI_ATR_TRSLID_PCIE_CONFIG  0x1
+
+#define ECAM_BUS_SHIFT 20
+#define ECAM_DEV_SHIFT 15
+#define ECAM_FUNC_SHIFT12
+/* Secondary bus number offset in config space */
+#define PCI_SECONDARY_BUS  0x19
+
+/* system control */
+#define STG_SYSCON_K_RP_NEP_MASK   BIT(8)
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_MASK   GENMASK(22, 8)
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_SHIFT  8
+#define STG_SYSCON_AXI4_SLVL_AWFUNC_MASK   GENMASK(14, 0)
+#define STG_SYSCON_CLKREQ_MASK BIT(22)
+#define STG_SYSCON_CKREF_SRC_SHIFT 18
+#define STG_SYSCON_CKREF_SRC_MASK  GENMASK(19, 18)
+
+struct starfive_pcie {
+   struct udevice *dev;
+
+   void __iomem *reg_base;
+   void __iomem *cfg_base;
+
+   struct regmap *regmap;
+   u32 stg_arfun;
+   u32 stg_awfun;
+   u32 stg_rp_nep;
+
+   struct clk_bulk clks;
+   struct reset_ctl_bulk   rsts;
+
+   int atr_table_num;
+   int first_busno;
+};
+
+static int starfive_pcie_addr_valid(pci_dev_t bdf, int first_busno)
+{
+   if ((PCI_BUS(bdf) == first_busno) && (PCI_DEV(bdf) > 0))
+   return 0;
+   if ((PCI_BUS(bdf) == first_busno + 1) && (PCI_DEV(bdf) > 0))
+   return 0;
+
+   return 1;
+}
+
+static int starfive_pcie_off

[PATCH v2 2/3] configs: starfive-jh7110: Add support for PCIe host driver

2023-03-07 Thread Minda Chen
From: Mason Huo 

also add the nvme driver and rtl8169 support.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 550d0ff3ab..98d23d9461 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -16,6 +16,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -50,8 +51,11 @@ CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SPL_CLK_JH7110=y
@@ -65,6 +69,11 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_SPL_PINCTRL=y
-- 
2.17.1



[PATCH v2 0/3] Add StarFive JH7110 PCIe drvier support

2023-03-07 Thread Minda Chen
This patchset needs to apply after patchset in [1]. These PCIe series patches
are based on the JH7110 RISC-V SoC and VisionFive V2 board.

[1] 
https://patchwork.ozlabs.org/project/uboot/cover/20230303032432.7837-1-yanhong.w...@starfivetech.com/

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

previous patch version

v1: 
https://patchwork.ozlabs.org/project/uboot/cover/20230223105240.15180-1-minda.c...@starfivetech.com/

changes
v1->v2
   1. remove clock commit. The pcie clocks change has been includeded in [1].
   2. Using GENMASK marco1 in patch1.
   3. remove the syscon dts node in patch3. The syscon dts dts node has been
  included in [1]. 

---

The JH7110 minimal system patchset upstream is in progress.
PCIe driver patches is based on this patchset.

The JH7110 minimal system patchset details are listed in [1].

For more JH7110 and visionFive v2 information and support,
you can visit RVspace wiki[2].

[2] https://wiki.rvspace.org/

Mason Huo (3):
  starfive: pci: Add StarFive JH7110 pcie driver
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

 .../dts/jh7110-starfive-visionfive-2.dtsi |  99 
 arch/riscv/dts/jh7110.dtsi|  75 +++
 configs/starfive_visionfive2_defconfig|   9 +
 drivers/pci/Kconfig   |  11 +
 drivers/pci/Makefile  |   1 +
 drivers/pci/pcie_starfive_jh7110.c| 478 ++
 6 files changed, 673 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c


base-commit: b0eda49bc9b00503366f2ec431be0178caf9e9b5
prerequisite-patch-id: a84452ba131408ff842b65ae19a3a05f64b3ff60
prerequisite-patch-id: bb320a2102f46d2b2d08b4467cbcdb92050767b8
prerequisite-patch-id: ef5e9d61f7392c7d2e5321aa8a10996ca8eae5fc
prerequisite-patch-id: 26dfdb401d680ecd9449acf09131cf4790e987b7
prerequisite-patch-id: a0cfa5d8cdb49bbe9d4739afa90991f882950881
prerequisite-patch-id: a0509f01172e24b3d163f4701496b0349435bdc0
prerequisite-patch-id: d834ece14ffb525b8c3e661e78736692f33fca9b
prerequisite-patch-id: aa95c1c047d0b7dae469586873a42932d613411d
prerequisite-patch-id: ebc26ed3f97f7babc0fc805152acb578f5eff922
prerequisite-patch-id: 81a83d6fc1e71ce190f9151577deb0c5cd382a20
prerequisite-patch-id: ff5bd799e4cb905fef6cf1cd0ce757980e1d34b7
prerequisite-patch-id: a341d4e8a8e25cb711309123939235fcb3c10c1a
prerequisite-patch-id: 749e4eafb431857ee2bec4ac8e78a682f6a57588
prerequisite-patch-id: 04cd7779c7464c7be683cd2718baee8c6554791d
prerequisite-patch-id: 25cb7c602018ec89abce43d8835926ac3356f5db
prerequisite-patch-id: cf1af96990b01e1025ec50d0b49c79f92f64f352
prerequisite-patch-id: cc5878da5f03e7e1d2c15e88537fd2a93bf47e53
-- 
2.17.1



[PATCH v2 3/3] riscv: dts: starfive: Enable PCIe host controller

2023-03-07 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.
Also add JH7110 stg syscon configuration.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 .../dts/jh7110-starfive-visionfive-2.dtsi | 99 +++
 arch/riscv/dts/jh7110.dtsi| 75 ++
 2 files changed, 174 insertions(+)

diff --git a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi 
b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
index e669c2a26a..995f842a6b 100644
--- a/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
+++ b/arch/riscv/dts/jh7110-starfive-visionfive-2.dtsi
@@ -178,6 +178,87 @@
slew-rate = <0>;
};
};
+
+   pcie0_perst_default: pcie0_perst_default {
+   perst-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-disable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
+   pcie0_perst_active: pcie0_perst_active {
+   perst-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-disable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
+   pcie0_wake_default: pcie0_wake_default {
+   wake-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-enable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
+   pcie0_clkreq_default: pcie0_clkreq_default {
+   clkreq-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-enable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
+   pcie1_perst_default: pcie1_perst_default {
+   perst-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-disable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
+   pcie1_perst_active: pcie1_perst_active {
+   perst-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-disable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
+   pcie1_wake_default: pcie1_wake_default {
+   wake-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-enable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
+   pcie1_clkreq_default: pcie1_clkreq_default {
+   clkreq-pins {
+   pinmux = ;
+   drive-strength = <2>;
+   input-enable;
+   input-schmitt-disable;
+   slew-rate = <0>;
+   };
+   };
+
 };
 
  {
@@ -234,6 +315,24 @@
};
 };
 
+ {
+   pinctrl-names = "perst-default", "perst-active", "wake-default", 
"clkreq-default";
+   pinctrl-0 = <_perst_default>;
+   pinctrl-1 = <_perst_active>;
+   pinctrl-2 = <_wake_default>;
+   pinctrl-3 = <_clkreq_default>;
+   status = "disabled";
+};
+
+ {
+   pinctrl-names = "perst-default", "perst-active", "wake-default", 
"clkreq-default";
+   pinctrl-0 = <_perst_default>;
+   pinctrl-1 = <_perst_active>;
+   pinctrl-2 = <_wake_default>;
+   pinctrl-3 = <_clkreq_default>;
+   status = "okay";
+};
+
  {
assigned-clocks = < JH7110_SYSCLK_CPU_ROOT>,
  < JH7110_SYSCLK_BUS_ROOT>,
diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index d3e9f92987..e43296c9d5 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -578,5 +578,80 @@
gpio-controller;
#gpio-cells = <2>;
};
+
+   pcie0: pcie@2B00 {
+   compatible = "starfive,jh7110-pcie";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   reg = <0x0 0x2B00 0x0 0x100>,
+ <0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg&quo

[PATCH 3/4] configs: starfive-jh7110: Add support for PCIe host driver

2023-02-23 Thread Minda Chen
From: Mason Huo 

also add the nvme driver and rtl8169 support.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 configs/starfive_visionfive2_defconfig | 9 +
 1 file changed, 9 insertions(+)

diff --git a/configs/starfive_visionfive2_defconfig 
b/configs/starfive_visionfive2_defconfig
index 54ae6b2a43..8e38201858 100644
--- a/configs/starfive_visionfive2_defconfig
+++ b/configs/starfive_visionfive2_defconfig
@@ -11,6 +11,7 @@ CONFIG_SPL=y
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x8200
+CONFIG_SYS_PCI_64BIT=y
 CONFIG_TARGET_STARFIVE_VISIONFIVE2=y
 CONFIG_SPL_OPENSBI_LOAD_ADDR=0x4000
 CONFIG_ARCH_RV64I=y
@@ -45,8 +46,11 @@ CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x400
 CONFIG_CMD_MEMINFO=y
+CONFIG_CMD_PCI=y
 CONFIG_CMD_TFTPPUT=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
+CONFIG_REGMAP=y
+CONFIG_SYSCON=y
 CONFIG_SPL_CLK_COMPOSITE_CCF=y
 CONFIG_CLK_CCF=y
 CONFIG_CLK_COMPOSITE_CCF=y
@@ -61,6 +65,11 @@ CONFIG_SPI_FLASH_EON=y
 CONFIG_SPI_FLASH_GIGADEVICE=y
 CONFIG_SPI_FLASH_ISSI=y
 CONFIG_SPI_FLASH_MACRONIX=y
+CONFIG_RTL8169=y
+CONFIG_NVME_PCI=y
+CONFIG_PCI=y
+CONFIG_DM_PCI_COMPAT=y
+CONFIG_PCI_REGION_MULTI_ENTRY=y
 CONFIG_PINCTRL=y
 CONFIG_PINCONF=y
 CONFIG_PINCTRL_STARFIVE=y
-- 
2.17.1



[PATCH 4/4] riscv: dts: starfive: Enable PCIe host controller

2023-02-23 Thread Minda Chen
From: Mason Huo 

Enable and add pinctrl configuration for PCIe host controller.
Also add JH7110 stg syscon configuration.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 arch/riscv/dts/jh7110.dtsi  |  79 ++
 arch/riscv/dts/starfive_visionfive2.dts | 104 
 2 files changed, 183 insertions(+)

diff --git a/arch/riscv/dts/jh7110.dtsi b/arch/riscv/dts/jh7110.dtsi
index 49d34b85af..6f37d107e3 100644
--- a/arch/riscv/dts/jh7110.dtsi
+++ b/arch/riscv/dts/jh7110.dtsi
@@ -493,5 +493,84 @@
#address-cells = <1>;
#size-cells = <0>;
};
+
+   pcie0: pcie@2B00 {
+   compatible = "starfive,jh7110-pcie";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   reg = <0x0 0x2B00 0x0 0x100>,
+ <0x9 0x4000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0xc0 0xc4 0x130>;
+   bus-range = <0x0 0xff>;
+   ranges = <0x8200  0x0 0x3000  0x0 0x3000 
0x0 0x0800>,
+   <0xc300  0x9 0x  0x9 0x 0x0 
0x4000>;
+   msi-parent = <>;
+   interrupts = <56>;
+   interrupt-controller;
+   interrupt-names = "msi";
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   resets = < JH7110_STGRST_PCIE0_MST0>,
+< JH7110_STGRST_PCIE0_SLV0>,
+< JH7110_STGRST_PCIE0_SLV>,
+< JH7110_STGRST_PCIE0_BRG>,
+< JH7110_STGRST_PCIE0_CORE>,
+< JH7110_STGRST_PCIE0_APB>;
+   reset-names = "rst_mst0", "rst_slv0", "rst_slv",
+ "rst_brg", "rst_core", "rst_apb";
+   clocks = < JH7110_SYSCLK_NOC_BUS_STG_AXI>,
+< JH7110_STGCLK_PCIE0_TL>,
+< JH7110_STGCLK_PCIE0_AXI>,
+< JH7110_STGCLK_PCIE0_APB>;
+   clock-names = "noc", "tl", "axi_mst0", "apb";
+   status = "disabled";
+   };
+
+   pcie1: pcie@2C00 {
+   compatible = "starfive,jh7110-pcie";
+   #address-cells = <3>;
+   #size-cells = <2>;
+   #interrupt-cells = <1>;
+   reg = <0x0 0x2C00 0x0 0x100>,
+ <0x9 0xc000 0x0 0x1000>;
+   reg-names = "reg", "config";
+   device_type = "pci";
+   starfive,stg-syscon = <_syscon 0x270 0x274 0x2e0>;
+   bus-range = <0x0 0xff>;
+   ranges = <0x8200  0x0 0x3800  0x0 0x3800 
0x0 0x0800>,
+   <0xc300  0x9 0x8000  0x9 0x8000 0x0 
0x4000>;
+   msi-parent = <>;
+   interrupts = <57>;
+   interrupt-controller;
+   interrupt-names = "msi";
+   interrupt-parent = <>;
+   interrupt-map-mask = <0x0 0x0 0x0 0x7>;
+   interrupt-map = <0x0 0x0 0x0 0x1  0x1>,
+   <0x0 0x0 0x0 0x2  0x2>,
+   <0x0 0x0 0x0 0x3  0x3>,
+   <0x0 0x0 0x0 0x4  0x4>;
+   resets = < JH7110_STGRST_PCIE1_MST0>,
+< JH7110_STGRST_PCIE1_SLV0>,
+< JH7110_STGRST_PCIE1_SLV>,
+< JH7110_STGRST_PCIE1_BRG>,
+< JH7110_STGR

[PATCH 1/4] starfive: pci: Add StarFive JH7110 pcie driver

2023-02-23 Thread Minda Chen
From: Mason Huo 

Add pcie driver for StarFive JH7110, the driver depends on
starfive gpio, pinctrl, clk and reset driver to do init.

Several devices are tested:
a) M.2 NVMe SSD
b) Realtek 8169 Ethernet adapter.

Signed-off-by: Mason Huo 
Signed-off-by: Minda Chen 
---
 drivers/pci/Kconfig|  11 +
 drivers/pci/Makefile   |   1 +
 drivers/pci/pcie_starfive_jh7110.c | 482 +
 3 files changed, 494 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index a3b662fb13..da9290204b 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -365,4 +365,15 @@ config PCIE_UNIPHIER
  Say Y here if you want to enable PCIe controller support on
  UniPhier SoCs.
 
+config PCIE_STARFIVE_JH7110
+   bool "Enable Starfive JH7110 PCIe driver"
+   depends on STARFIVE_JH7110
+   depends on PINCTRL_STARFIVE_JH7110
+   depends on CLK_JH7110
+   depends on RESET_JH7110
+   default y
+   help
+ Say Y here if you want to enable PCIe controller support on
+ StarFive JH7110 SoC.
+
 endif
diff --git a/drivers/pci/Makefile b/drivers/pci/Makefile
index dd1ad91ced..92a92409ab 100644
--- a/drivers/pci/Makefile
+++ b/drivers/pci/Makefile
@@ -49,3 +49,4 @@ obj-$(CONFIG_PCI_OCTEONTX) += pci_octeontx.o
 obj-$(CONFIG_PCIE_OCTEON) += pcie_octeon.o
 obj-$(CONFIG_PCIE_DW_SIFIVE) += pcie_dw_sifive.o
 obj-$(CONFIG_PCIE_UNIPHIER) += pcie_uniphier.o
+obj-$(CONFIG_PCIE_STARFIVE_JH7110) += pcie_starfive_jh7110.o
diff --git a/drivers/pci/pcie_starfive_jh7110.c 
b/drivers/pci/pcie_starfive_jh7110.c
new file mode 100644
index 00..1f14352dfb
--- /dev/null
+++ b/drivers/pci/pcie_starfive_jh7110.c
@@ -0,0 +1,482 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * StarFive PLDA PCIe host controller driver
+ *
+ * Copyright (c) 2023 Starfive, Inc.
+ * Author: Mason Huo 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define GEN_SETTINGS   0x80
+#define PCIE_PCI_IDS   0x9C
+#define PCIE_WINROM0xFC
+#define PMSG_SUPPORT_RX0x3F0
+#define PCI_MISC   0xB4
+
+#define PLDA_EP_ENABLE 0
+#define PLDA_RP_ENABLE 1
+
+#define IDS_REVISION_ID0x02
+#define IDS_PCI_TO_PCI_BRIDGE  0x060400
+#define IDS_CLASS_CODE_SHIFT   8
+
+#define PREF_MEM_WIN_64_SUPPORTBIT(3)
+#define PMSG_LTR_SUPPORT   BIT(2)
+#define PLDA_FUNCTION_DIS  BIT(15)
+#define PLDA_FUNC_NUM  4
+#define PLDA_PHY_FUNC_SHIFT9
+
+#define XR3PCI_ATR_AXI4_SLV0   0x800
+#define XR3PCI_ATR_SRC_ADDR_LOW0x0
+#define XR3PCI_ATR_SRC_ADDR_HIGH   0x4
+#define XR3PCI_ATR_TRSL_ADDR_LOW   0x8
+#define XR3PCI_ATR_TRSL_ADDR_HIGH  0xc
+#define XR3PCI_ATR_TRSL_PARAM  0x10
+#define XR3PCI_ATR_TABLE_OFFSET0x20
+#define XR3PCI_ATR_MAX_TABLE_NUM   8
+
+#define XR3PCI_ATR_SRC_WIN_SIZE_SHIFT  1
+#define XR3PCI_ATR_SRC_ADDR_MASK   0xf000
+#define XR3PCI_ATR_TRSL_ADDR_MASK  0xf000
+#define XR3_PCI_ECAM_SIZE  28
+#define XR3PCI_ATR_TRSL_DIRBIT(22)
+/* IDs used in the XR3PCI_ATR_TRSL_PARAM */
+#define XR3PCI_ATR_TRSLID_PCIE_MEMORY  0x0
+#define XR3PCI_ATR_TRSLID_PCIE_CONFIG  0x1
+
+#define ECAM_BUS_SHIFT 20
+#define ECAM_DEV_SHIFT 15
+#define ECAM_FUNC_SHIFT12
+/* Secondary bus number offset in config space */
+#define PCI_SECONDARY_BUS  0x19
+
+/* system control */
+#define STG_SYSCON_K_RP_NEP_SHIFT  8
+#define STG_SYSCON_K_RP_NEP_MASK   0x100
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_MASK   0x7FFF00
+#define STG_SYSCON_AXI4_SLVL_ARFUNC_SHIFT  8
+#define STG_SYSCON_AXI4_SLVL_AWFUNC_MASK   0x7FFF
+#define STG_SYSCON_AXI4_SLVL_AWFUNC_SHIFT  0
+#define STG_SYSCON_CLKREQ_SHIFT22
+#define STG_SYSCON_CLKREQ_MASK 0x40
+#define STG_SYSCON_CKREF_SRC_SHIFT 18
+#define STG_SYSCON_CKREF_SRC_MASK  0xC
+
+struct starfive_pcie {
+   struct udevice *dev;
+
+   void __iomem *reg_base;
+   void __iomem *cfg_base;
+
+   struct regmap *regmap;
+   u32 stg_arfun;
+   u32 stg_awfun;
+   u32 stg_rp_nep;
+
+   struct clk_bulk clks;
+   struct reset_ctl_bulk   rsts;
+
+   int atr_table_num;
+   int first_busno;
+};
+
+static int starfive_pcie_addr_valid(pci_dev_t bdf, int first_busno)
+{
+   if ((PCI_BUS(bdf) == first_busno) && (PCI_DEV(bdf) > 0))
+   return 0;
+   if ((PCI_BUS(bdf) == first_busno + 1)

[PATCH 2/4] clk: starfive: Add PCIe clocks for PCIe controller

2023-02-23 Thread Minda Chen
From: Mason Huo 

Add the stg clocks for StarFive JH7110 PCIe controller.

Signed-off-by: Mason Huo  
Signed-off-by: Minda Chen 
---
 drivers/clk/starfive/clk-jh7110.c | 27 +++
 1 file changed, 27 insertions(+)

diff --git a/drivers/clk/starfive/clk-jh7110.c 
b/drivers/clk/starfive/clk-jh7110.c
index a904852cab..7cfed7b847 100644
--- a/drivers/clk/starfive/clk-jh7110.c
+++ b/drivers/clk/starfive/clk-jh7110.c
@@ -305,6 +305,10 @@ static int jh7110_syscrg_init(struct udevice *dev)
clk_dm(JH7110_SYSCLK_AON_APB,
   starfive_clk_fix_factor(priv->reg,
   "aon_apb", "apb_bus_func", 1, 1));
+   clk_dm(JH7110_SYSCLK_NOCSTG_BUS,
+  starfive_clk_divider(priv->reg,
+   "nocstg_bus", "bus_root",
+   OFFSET(JH7110_SYSCLK_NOCSTG_BUS), 3));
clk_dm(JH7110_SYSCLK_QSPI_AHB,
   starfive_clk_gate(priv->reg,
 "qspi_ahb", "ahb1",
@@ -342,6 +346,11 @@ static int jh7110_syscrg_init(struct udevice *dev)
   starfive_clk_divider(priv->reg,
"usb_125m", "gmacusb_root",
OFFSET(JH7110_SYSCLK_USB_125M), 4));
+   clk_dm(JH7110_SYSCLK_NOC_BUS_STG_AXI,
+  starfive_clk_gate(priv->reg,
+"noc_bus_stg_axi",
+"nocstg_bus",
+ OFFSET(JH7110_SYSCLK_NOC_BUS_STG_AXI)));
clk_dm(JH7110_SYSCLK_GMAC1_AHB,
   starfive_clk_gate(priv->reg,
 "gmac1_ahb", "ahb0",
@@ -512,6 +521,24 @@ static int jh7110_stgcrg_init(struct udevice *dev)
clk_dm(JH7110_STGCLK_USB_REFCLK,
   starfive_clk_divider(priv->reg, "usb_refclk", "osc",
STGOFFSET(JH7110_STGCLK_USB_REFCLK), 2));
+   clk_dm(JH7110_STGCLK_PCIE0_TL,
+  starfive_clk_gate(priv->reg, "pcie0_tl", "stg_axiahb",
+STGOFFSET(JH7110_STGCLK_PCIE0_TL)));
+   clk_dm(JH7110_STGCLK_PCIE0_AXI,
+  starfive_clk_gate(priv->reg, "pcie0_axi_mst0", "stg_axiahb",
+STGOFFSET(JH7110_STGCLK_PCIE0_AXI)));
+   clk_dm(JH7110_STGCLK_PCIE0_APB,
+  starfive_clk_gate(priv->reg, "pcie0_apb", "stg_apb",
+STGOFFSET(JH7110_STGCLK_PCIE0_APB)));
+   clk_dm(JH7110_STGCLK_PCIE1_TL,
+  starfive_clk_gate(priv->reg, "pcie1_tl", "stg_axiahb",
+STGOFFSET(JH7110_STGCLK_PCIE1_TL)));
+   clk_dm(JH7110_STGCLK_PCIE1_AXI,
+  starfive_clk_gate(priv->reg, "pcie1_axi_mst0", "stg_axiahb",
+STGOFFSET(JH7110_STGCLK_PCIE1_AXI)));
+   clk_dm(JH7110_STGCLK_PCIE1_APB,
+  starfive_clk_gate(priv->reg, "pcie1_apb", "stg_apb",
+STGOFFSET(JH7110_STGCLK_PCIE1_APB)));
return 0;
 }
 
-- 
2.17.1



[PATCH 0/4] Add StarFive JH7110 PCIe drvier support

2023-02-23 Thread Minda Chen
This patchset needs to apply after patchset in [1]. These PCIe series patches
are based on the JH7110 RISC-V SoC and VisionFive V2 board.

The PCIe driver depends on gpio, pinctrl, clk and reset driver to do init.
The PCIe dts configuation includes all these setting.

The PCIe drivers codes has been tested on the VisionFive V2 boards.
The test devices includes M.2 NVMe SSD and Realtek 8169 Ethernet adapter.

Mason Huo (4):
  starfive: pci: Add StarFive JH7110 pcie driver
  clk: starfive: Add PCIe clocks for PCIe controller
  configs: starfive-jh7110: Add support for PCIe host driver
  riscv: dts: starfive: Enable PCIe host controller

The JH7110 minimal system patchset upstream is in progress.
PCIe driver patches is based on this patchset.

The JH7110 minimal system patchset details are listed in [1].

[1] 
https://patchwork.ozlabs.org/project/uboot/cover/20230118081132.31403-1-yanhong.w...@starfivetech.com/

For more JH7110 and visionFive v2 information and support,
you can visit RVspace wiki[2].

[2] https://wiki.rvspace.org/

 arch/riscv/dts/jh7110.dtsi  |  79 
 arch/riscv/dts/starfive_visionfive2.dts | 104 +
 configs/starfive_visionfive2_defconfig  |   9 +
 drivers/clk/starfive/clk-jh7110.c   |  27 ++
 drivers/pci/Kconfig |  11 +
 drivers/pci/Makefile|   1 +
 drivers/pci/pcie_starfive_jh7110.c  | 482 
 7 files changed, 713 insertions(+)
 create mode 100644 drivers/pci/pcie_starfive_jh7110.c

-- 
2.17.1