Skip to contentSkip to conversation

ARM: khadas-vim3: enable PCIe and NVMe

PATCH New Neil Armstrong 1 participant 7 messages Apr 8, 2021 – Apr 16, 2021

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

cover ARM: khadas-vim3: enable PCIe and NVMe

This adds the missing bits to enable PCIe and NVMe support in U-Boot for the Khadas VIM3 & VIM3L board.

This serie depends on [1].

[1] https://patchwork.ozlabs.org/project/uboot/cover/20210325144921.1791892-1-narmstrong at baylibre.com/

Neil Armstrong (5):
clk: meson-g12a: add PCIe gates
phy: meson-g12a-usb3-pcie: add support for PCIe ops
arm: dts: meson-khadas-vim3: enable PCIe in U-boot
configs: khadas-vim3: enable PCIe and NVMe
configs: meson64: add NVME boot target

 arch/arm/dts/meson-khadas-vim3-u-boot.dtsi |  4 ++
 configs/khadas-vim3_defconfig              |  5 ++
 configs/khadas-vim3l_defconfig             |  5 ++
 drivers/clk/meson/g12a.c                   |  2 +
 drivers/phy/meson-g12a-usb3-pcie.c         | 81 ++++++++++++++++++++--
 include/configs/meson64.h                  |  7 ++
 6 files changed, 100 insertions(+), 4 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/5 clk: meson-g12a: add PCIe gates

Add missing gates used for PCIe.

---
 drivers/clk/meson/g12a.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clk/meson/g12a.c +2 -0
index 5058db1a47..e4fed8ddfb 100644
@@ -120,7 +120,9 @@ static struct meson_gate gates[NUM_CLKS] = {
 	MESON_GATE(CLKID_SD_EMMC_C, HHI_GCLK_MPEG0, 26),
 	MESON_GATE(CLKID_ETH, HHI_GCLK_MPEG1, 3),
 	MESON_GATE(CLKID_UART1, HHI_GCLK_MPEG1, 16),
+	MESON_GATE(CLKID_PCIE_COMB, HHI_GCLK_MPEG1, 24),
 	MESON_GATE(CLKID_USB, HHI_GCLK_MPEG1, 25),
+	MESON_GATE(CLKID_PCIE_PHY, HHI_GCLK_MPEG1, 27),
 	MESON_GATE(CLKID_HTX_PCLK, HHI_GCLK_MPEG2, 4),
 	MESON_GATE(CLKID_USB1_DDR_BRIDGE, HHI_GCLK_MPEG2, 8),
 	MESON_GATE(CLKID_VPU_INTR, HHI_GCLK_MPEG2, 25),
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/5 phy: meson-g12a-usb3-pcie: add support for PCIe ops

In reply to Neil Armstrong

Add the PCIe part of the G12A USB3 PCIe Combo PHY driver.

---
 drivers/phy/meson-g12a-usb3-pcie.c | 81 ++++++++++++++++++++++++++++--
 1 file changed, 77 insertions(+), 4 deletions(-)
drivers/phy/meson-g12a-usb3-pcie.c +77 -4
index 0433d93474..8f72b5a6a7 100644
@@ -23,6 +23,9 @@
 #include <linux/compat.h>
 #include <linux/bitfield.h>
 
+#define PHY_TYPE_PCIE           2
+#define PHY_TYPE_USB3           4
+
 #define PHY_R0							0x00
 	#define PHY_R0_PCIE_POWER_STATE				GENMASK(4, 0)
 	#define PHY_R0_PCIE_USB3_SWITCH				GENMASK(6, 5)
@@ -55,6 +58,8 @@
 	#define PHY_R5_PHY_CR_ACK				BIT(16)
 	#define PHY_R5_PHY_BS_OUT				BIT(17)
 
+#define PCIE_RESET_DELAY					500
+
 struct phy_g12a_usb3_pcie_priv {
 	struct regmap		*regmap;
 #if CONFIG_IS_ENABLED(CLK)
@@ -202,8 +207,6 @@ static int phy_meson_g12a_usb3_init(struct phy *phy)
 	unsigned int data;
 	int ret;
 
-	/* TOFIX Handle PCIE mode */
-
 	ret = reset_assert_bulk(&priv->resets);
 	udelay(1);
 	ret |= reset_deassert_bulk(&priv->resets);
@@ -296,9 +299,79 @@ static int phy_meson_g12a_usb3_exit(struct phy *phy)
 	return reset_assert_bulk(&priv->resets);
 }
 
+static int phy_meson_g12a_usb3_pcie_init(struct phy *phy)
+{
+	if (phy->id == PHY_TYPE_USB3)
+		return phy_meson_g12a_usb3_init(phy);
+
+	return 0;
+}
+
+static int phy_meson_g12a_usb3_pcie_exit(struct phy *phy)
+{
+	if (phy->id == PHY_TYPE_USB3)
+		return phy_meson_g12a_usb3_exit(phy);
+
+	return 0;
+}
+
+static int phy_meson_g12a_usb3_pcie_power_on(struct phy *phy)
+{
+	struct phy_g12a_usb3_pcie_priv *priv = dev_get_priv(phy->dev);
+
+	if (phy->id == PHY_TYPE_USB3)
+		return 0;
+
+	regmap_update_bits(priv->regmap, PHY_R0,
+			   PHY_R0_PCIE_POWER_STATE,
+			   FIELD_PREP(PHY_R0_PCIE_POWER_STATE, 0x1c));
+
+	return 0;
+}
+
+static int phy_meson_g12a_usb3_pcie_power_off(struct phy *phy)
+{
+	struct phy_g12a_usb3_pcie_priv *priv = dev_get_priv(phy->dev);
+
+	if (phy->id == PHY_TYPE_USB3)
+		return 0;
+
+	regmap_update_bits(priv->regmap, PHY_R0,
+			   PHY_R0_PCIE_POWER_STATE,
+			   FIELD_PREP(PHY_R0_PCIE_POWER_STATE, 0x1d));
+
+	return 0;
+}
+
+static int phy_meson_g12a_usb3_pcie_reset(struct phy *phy)
+{
+	struct phy_g12a_usb3_pcie_priv *priv = dev_get_priv(phy->dev);
+	int ret;
+
+	if (phy->id == PHY_TYPE_USB3)
+		return 0;
+
+	ret = reset_assert_bulk(&priv->resets);
+	if (ret)
+		return ret;
+
+	udelay(PCIE_RESET_DELAY);
+
+	ret = reset_deassert_bulk(&priv->resets);
+	if (ret)
+		return ret;
+
+	udelay(PCIE_RESET_DELAY);
+
+	return 0;
+}
+
 struct phy_ops meson_g12a_usb3_pcie_phy_ops = {
-	.init = phy_meson_g12a_usb3_init,
-	.exit = phy_meson_g12a_usb3_exit,
+	.init = phy_meson_g12a_usb3_pcie_init,
+	.exit = phy_meson_g12a_usb3_pcie_exit,
+	.power_on = phy_meson_g12a_usb3_pcie_power_on,
+	.power_off = phy_meson_g12a_usb3_pcie_power_off,
+	.reset = phy_meson_g12a_usb3_pcie_reset,
 };
 
 int meson_g12a_usb3_pcie_phy_probe(struct udevice *dev)
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/5 arm: dts: meson-khadas-vim3: enable PCIe in U-boot

In reply to Neil Armstrong

Enable PCIe by default in u-boot, this should eventually be made dynamic in the runtime board config depending on the MCU configuration.

---
 arch/arm/dts/meson-khadas-vim3-u-boot.dtsi | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/dts/meson-khadas-vim3-u-boot.dtsi +4 -0
index 81fd5be378..24dbf8ca2c 100644
@@ -10,6 +10,10 @@
 	};
 };
 
+&pcie {
+	status = "okay";
+};
+
 &sd_emmc_c {
 	status = "okay";
 	pinctrl-0 = <&emmc_ctrl_pins>, <&emmc_data_4b_pins>, <&emmc_ds_pins>;
Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/5 configs: khadas-vim3: enable PCIe and NVMe

In reply to Neil Armstrong

Now we have PCIe, let's also enable NVMe to access an eventual NVMe SSDs connected on the M.2 slot.

---
 configs/khadas-vim3_defconfig  | 5 +++++
 configs/khadas-vim3l_defconfig | 5 +++++
 2 files changed, 10 insertions(+)
configs/khadas-vim3_defconfig +5 -0
index bc17430569..5bf821bd38 100644
@@ -85,3 +85,8 @@ CONFIG_BMP_16BPP=y
 CONFIG_BMP_24BPP=y
 CONFIG_BMP_32BPP=y
 CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_PCI=y
+CONFIG_CMD_PCI=y
+CONFIG_DM_PCI=y
+CONFIG_PCIE_DW_MESON=y
+CONFIG_NVME=y
configs/khadas-vim3l_defconfig +5 -0
index c1877922c7..f066eb8c61 100644
@@ -85,3 +85,8 @@ CONFIG_BMP_16BPP=y
 CONFIG_BMP_24BPP=y
 CONFIG_BMP_32BPP=y
 CONFIG_OF_LIBFDT_OVERLAY=y
+CONFIG_PCI=y
+CONFIG_CMD_PCI=y
+CONFIG_DM_PCI=y
+CONFIG_PCIE_DW_MESON=y
+CONFIG_NVME=y
Signature · 1 line
2.25.1
#5 lore raw

PATCH 5/5 configs: meson64: add NVME boot target

In reply to Neil Armstrong

Let's add a boot target for NVMe so we can do a full boot over NVMe.

---
 include/configs/meson64.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/configs/meson64.h +7 -0
index 7e97f89052..17ebccd2c4 100644
@@ -58,6 +58,12 @@
 #define BOOT_TARGET_DEVICES_USB(func)
 #endif
 
+#ifdef CONFIG_CMD_NVME
+	#define BOOT_TARGET_NVME(func) func(NVME, nvme, 0)
+#else
+	#define BOOT_TARGET_NVME(func)
+#endif
+
 #ifndef BOOT_TARGET_DEVICES
 #define BOOT_TARGET_DEVICES(func) \
 	func(ROMUSB, romusb, na)  \
@@ -65,6 +71,7 @@
 	func(MMC, mmc, 1) \
 	func(MMC, mmc, 2) \
 	BOOT_TARGET_DEVICES_USB(func) \
+	BOOT_TARGET_NVME(func) \
 	func(PXE, pxe, na) \
 	func(DHCP, dhcp, na)
 #endif
Signature · 1 line
2.25.1
#6 lore raw

cover ARM: khadas-vim3: enable PCIe and NVMe

In reply to Neil Armstrong
Quoted 14 lines · Neil Armstrong

This adds the missing bits to enable PCIe and NVMe support in U-Boot for the Khadas VIM3 & VIM3L board.

This serie depends on [1].

[1] https://patchwork.ozlabs.org/project/uboot/cover/20210325144921.1791892-1-narmstrong at baylibre.com/

Neil Armstrong (5):
clk: meson-g12a: add PCIe gates
phy: meson-g12a-usb3-pcie: add support for PCIe ops
arm: dts: meson-khadas-vim3: enable PCIe in U-boot
configs: khadas-vim3: enable PCIe and NVMe
configs: meson64: add NVME boot target

Quoted 8 lines
 arch/arm/dts/meson-khadas-vim3-u-boot.dtsi |  4 ++
 configs/khadas-vim3_defconfig              |  5 ++
 configs/khadas-vim3l_defconfig             |  5 ++
 drivers/clk/meson/g12a.c                   |  2 +
 drivers/phy/meson-g12a-usb3-pcie.c         | 81 ++++++++++++++++++++--
 include/configs/meson64.h                  |  7 ++
 6 files changed, 100 insertions(+), 4 deletions(-)

Applied to u-boot-amlogic