Skip to contentSkip to conversation

amlogic: vim3: add support for dynamic PCIe enable

PATCH Superseded Neil Armstrong 2 participants 7 messages Sep 18, 2020

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover amlogic: vim3: add support for dynamic PCIe enable

The VIM3 on-board MCU can mux the PCIe/USB3.0 shared differential lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between an USB3.0 Type A connector and a M.2 Key M slot.
The PHY driving these differential lines is shared between the USB3.0 controller and the PCIe Controller, thus only a single controller can use it.

This serie adds a VIM3 specific board support and adds this dynamic switching right before booting Linux.

Neil Armstrong (4):
ARM: dts: sync amlogic G12A/SM1 DT from Linux 5.9-rc1
board: amlogic: add a vim3 specific board support
configs: vim3: use the vim3 board support
board: amlogic: vim3: add support for dynamic PCIe enable

 arch/arm/dts/meson-g12-common.dtsi            |  55 ++++---
 arch/arm/dts/meson-g12b-odroid-n2.dts         | 136 +++++++++++++++++-
 arch/arm/dts/meson-khadas-vim3.dtsi           |  26 +++-
 arch/arm/dts/meson-sm1-khadas-vim3l.dts       |  92 ++++++++++++
 arch/arm/dts/meson-sm1-odroid-c4.dts          |  88 ++++++++++++
 board/amlogic/vim3/MAINTAINERS                |   9 ++
 board/amlogic/vim3/Makefile                   |   6 +
 board/amlogic/vim3/vim3.c                     | 136 ++++++++++++++++++
 board/amlogic/w400/MAINTAINERS                |   4 -
 configs/khadas-vim3_defconfig                 |   5 +-
 configs/khadas-vim3l_defconfig                |   5 +-
 include/dt-bindings/clock/g12a-clkc.h         |   2 +
 .../dt-bindings/sound/meson-g12a-toacodec.h   |  10 ++
 13 files changed, 544 insertions(+), 30 deletions(-)
 create mode 100644 board/amlogic/vim3/MAINTAINERS
 create mode 100644 board/amlogic/vim3/Makefile
 create mode 100644 board/amlogic/vim3/vim3.c
 create mode 100644 include/dt-bindings/sound/meson-g12a-toacodec.h
Signature · 1 line
2.22.0
#1 lore raw

PATCH 1/4 ARM: dts: sync amlogic G12A/SM1 DT from Linux 5.9-rc1

This imports the G12A & SM1 SoC and boards DT changes from the Linux commit 9123e3a74ec7 ("Linux 5.9-rc1").

---
 arch/arm/dts/meson-g12-common.dtsi            |  55 ++++---
 arch/arm/dts/meson-g12b-odroid-n2.dts         | 136 +++++++++++++++++-
 arch/arm/dts/meson-khadas-vim3.dtsi           |  26 +++-
 arch/arm/dts/meson-sm1-khadas-vim3l.dts       |  92 ++++++++++++
 arch/arm/dts/meson-sm1-odroid-c4.dts          |  88 ++++++++++++
 include/dt-bindings/clock/g12a-clkc.h         |   2 +
 .../dt-bindings/sound/meson-g12a-toacodec.h   |  10 ++
 7 files changed, 385 insertions(+), 24 deletions(-)
 create mode 100644 include/dt-bindings/sound/meson-g12a-toacodec.h
arch/arm/dts/meson-g12-common.dtsi +38 -17
index 593a006f4b..1e83ec5b8c 100644
@@ -52,6 +52,39 @@
 		secure-monitor = <&sm>;
 	};
 
+	gpu_opp_table: gpu-opp-table {
+		compatible = "operating-points-v2";
+
+		opp-124999998 {
+			opp-hz = /bits/ 64 <124999998>;
+			opp-microvolt = <800000>;
+		};
+		opp-249999996 {
+			opp-hz = /bits/ 64 <249999996>;
+			opp-microvolt = <800000>;
+		};
+		opp-285714281 {
+			opp-hz = /bits/ 64 <285714281>;
+			opp-microvolt = <800000>;
+		};
+		opp-399999994 {
+			opp-hz = /bits/ 64 <399999994>;
+			opp-microvolt = <800000>;
+		};
+		opp-499999992 {
+			opp-hz = /bits/ 64 <499999992>;
+			opp-microvolt = <800000>;
+		};
+		opp-666666656 {
+			opp-hz = /bits/ 64 <666666656>;
+			opp-microvolt = <800000>;
+		};
+		opp-799999987 {
+			opp-hz = /bits/ 64 <799999987>;
+			opp-microvolt = <800000>;
+		};
+	};
+
 	psci {
 		compatible = "arm,psci-1.0";
 		method = "smc";
@@ -185,8 +218,10 @@
 			interrupt-names = "macirq";
 			clocks = <&clkc CLKID_ETH>,
 				 <&clkc CLKID_FCLK_DIV2>,
-				 <&clkc CLKID_MPLL2>;
-			clock-names = "stmmaceth", "clkin0", "clkin1";
+				 <&clkc CLKID_MPLL2>,
+				 <&clkc CLKID_FCLK_DIV2>;
+			clock-names = "stmmaceth", "clkin0", "clkin1",
+				      "timing-adjustment";
 			rx-fifo-depth = <4096>;
 			tx-fifo-depth = <2048>;
 			status = "disabled";
@@ -2360,21 +2395,7 @@
 			interrupt-names = "job", "mmu", "gpu";
 			clocks = <&clkc CLKID_MALI>;
 			resets = <&reset RESET_DVALIN_CAPB3>, <&reset RESET_DVALIN>;
-
-			/*
-			 * Mali clocking is provided by two identical clock paths
-			 * MALI_0 and MALI_1 muxed to a single clock by a glitch
-			 * free mux to safely change frequency while running.
-			 */
-			assigned-clocks = <&clkc CLKID_MALI_0_SEL>,
-					  <&clkc CLKID_MALI_0>,
-					  <&clkc CLKID_MALI>; /* Glitch free mux */
-			assigned-clock-parents = <&clkc CLKID_FCLK_DIV2P5>,
-						 <0>, /* Do Nothing */
-						 <&clkc CLKID_MALI_0>;
-			assigned-clock-rates = <0>, /* Do Nothing */
-					       <800000000>,
-					       <0>; /* Do Nothing */
+			operating-points-v2 = <&gpu_opp_table>;
 			#cooling-cells = <2>;
 		};
 	};
arch/arm/dts/meson-g12b-odroid-n2.dts +131 -5

198 lines not on this page · raw message

arch/arm/dts/meson-khadas-vim3.dtsi +24 -2
index 1ef1e3672b..94f75b4465 100644
@@ -183,6 +183,23 @@
 	hdmi-phandle = <&hdmi_tx>;
 };
 
+&cpu_thermal {
+	trips {
+		cpu_active: cpu-active {
+			temperature = <80000>; /* millicelsius */
+			hysteresis = <2000>; /* millicelsius */
+			type = "active";
+		};
+	};
+
+	cooling-maps {
+		map {
+			trip = <&cpu_active>;
+			cooling-device = <&khadas_mcu THERMAL_NO_LIMIT THERMAL_NO_LIMIT>;
+		};
+	};
+};
+
 &ext_mdio {
 	external_phy: ethernet-phy at 0 {
 		/* Realtek RTL8211F (0x001cc916) */
@@ -222,6 +239,12 @@
 	pinctrl-0 = <&i2c_ao_sck_pins>, <&i2c_ao_sda_pins>;
 	pinctrl-names = "default";
 
+	khadas_mcu: system-controller at 18 {
+		compatible = "khadas,mcu";
+		reg = <0x18>;
+		#cooling-cells = <2>;
+	};
+
 	gpio_expander: gpio-controller at 20 {
 		compatible = "ti,tca6408";
 		reg = <0x20>;
@@ -270,7 +293,6 @@
 
 	bus-width = <4>;
 	cap-sd-highspeed;
-	sd-uhs-sdr50;
 	max-frequency = <100000000>;
 
 	non-removable;
@@ -337,7 +359,7 @@
 	pinctrl-0 = <&nor_pins>;
 	pinctrl-names = "default";
 
-	w25q32: spi-flash at 0 {
+	w25q128: spi-flash at 0 {
 		#address-cells = <1>;
 		#size-cells = <1>;
 		compatible = "winbond,w25q128fw", "jedec,spi-nor";
arch/arm/dts/meson-sm1-khadas-vim3l.dts +92 -0

118 lines not on this page · raw message

arch/arm/dts/meson-sm1-odroid-c4.dts +88 -0

112 lines not on this page · raw message

include/dt-bindings/clock/g12a-clkc.h +2 -0
index b0d65d73db..40d49940d8 100644
@@ -145,5 +145,7 @@
 #define CLKID_CPU3_CLK				255
 #define CLKID_SPICC0_SCLK			258
 #define CLKID_SPICC1_SCLK			261
+#define CLKID_NNA_AXI_CLK			264
+#define CLKID_NNA_CORE_CLK			267
 
 #endif /* __G12A_CLKC_H */
include/dt-bindings/sound/meson-g12a-toacodec.h new file +10 -0
new file mode 100644
index 0000000000..69d7a75592
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __DT_MESON_G12A_TOACODEC_H
+#define __DT_MESON_G12A_TOACODEC_H
+
+#define TOACODEC_IN_A	0
+#define TOACODEC_IN_B	1
+#define TOACODEC_IN_C	2
+#define TOACODEC_OUT	3
+
+#endif /* __DT_MESON_G12A_TOACODEC_H */
Signature · 1 line
2.22.0
#2 lore raw

PATCH 2/4 board: amlogic: add a vim3 specific board support

In reply to Neil Armstrong

The VIM3 will need a specific code to enable PCIe if enabled in the MCU, thus add a specific board support for VIM3 & VIM3L.

---
 board/amlogic/vim3/MAINTAINERS |  9 +++++++++
 board/amlogic/vim3/Makefile    |  6 ++++++
 board/amlogic/vim3/vim3.c      | 20 ++++++++++++++++++++
 board/amlogic/w400/MAINTAINERS |  4 ----
 4 files changed, 35 insertions(+), 4 deletions(-)
 create mode 100644 board/amlogic/vim3/MAINTAINERS
 create mode 100644 board/amlogic/vim3/Makefile
 create mode 100644 board/amlogic/vim3/vim3.c
board/amlogic/vim3/MAINTAINERS new file +9 -0
new file mode 100644
index 0000000000..92b426f66d
@@ -0,0 +1,9 @@
+VIM3
+M:	Neil Armstrong <[email protected]>
+S:	Maintained
+L:	u-boot-amlogic at groups.io
+F:	board/amlogic/vim3/
+F:	configs/khadas-vim3_defconfig
+F:	configs/khadas-vim3l_defconfig
+F:	doc/board/amlogic/khadas-vim3.rst
+F:	doc/board/amlogic/khadas-vim3l.rst
board/amlogic/vim3/Makefile new file +6 -0
new file mode 100644
index 0000000000..c515077302
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# (C) Copyright 2020 BayLibre, SAS
+# Author: Neil Armstrong <[email protected]>
+
+obj-y	:= vim3.o
board/amlogic/vim3/vim3.c new file +20 -0
new file mode 100644
index 0000000000..02d8cd0ce0
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 BayLibre, SAS
+ * Author: Neil Armstrong <[email protected]>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <env_internal.h>
+#include <init.h>
+#include <net.h>
+#include <asm/io.h>
+#include <asm/arch/eth.h>
+
+int misc_init_r(void)
+{
+	meson_eth_init(PHY_INTERFACE_MODE_RGMII, 0);
+
+	return 0;
+}
board/amlogic/w400/MAINTAINERS +0 -4
index a1b0ac8636..991590d9f2 100644
@@ -3,8 +3,4 @@ M:	Neil Armstrong <[email protected]>
 S:	Maintained
 L:	u-boot-amlogic at groups.io
 F:	board/amlogic/w400/
-F:	configs/khadas-vim3_defconfig
-F:	configs/khadas-vim3l_defconfig
 F:	doc/board/amlogic/w400.rst
-F:	doc/board/amlogic/khadas-vim3.rst
-F:	doc/board/amlogic/khadas-vim3l.rst
Signature · 1 line
2.22.0
#3 lore raw

PATCH 3/4 configs: vim3: use the vim3 board support

In reply to Neil Armstrong

Use the newly added VIM3 board support instead of the generic W400.

---
 configs/khadas-vim3_defconfig  | 2 +-
 configs/khadas-vim3l_defconfig | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
configs/khadas-vim3_defconfig +1 -1
index a39e0f9c9f..ee5990426d 100644
@@ -1,5 +1,5 @@
 CONFIG_ARM=y
-CONFIG_SYS_BOARD="w400"
+CONFIG_SYS_BOARD="vim3"
 CONFIG_ARCH_MESON=y
 CONFIG_SYS_TEXT_BASE=0x01000000
 CONFIG_NR_DRAM_BANKS=1
configs/khadas-vim3l_defconfig +1 -1
index 57cc383b9d..5729d339e9 100644
@@ -1,5 +1,5 @@
 CONFIG_ARM=y
-CONFIG_SYS_BOARD="w400"
+CONFIG_SYS_BOARD="vim3"
 CONFIG_ARCH_MESON=y
 CONFIG_SYS_TEXT_BASE=0x01000000
 CONFIG_NR_DRAM_BANKS=1
Signature · 1 line
2.22.0
#4 lore raw

PATCH 4/4 board: amlogic: vim3: add support for dynamic PCIe enable

In reply to Neil Armstrong

The VIM3 on-board MCU can mux the PCIe/USB3.0 shared differential lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between an USB3.0 Type A connector and a M.2 Key M slot.
The PHY driving these differential lines is shared between the USB3.0 controller and the PCIe Controller, thus only a single controller can use it.

This adds this dynamic switching right before booting Linux.

---
 board/amlogic/vim3/vim3.c      | 116 +++++++++++++++++++++++++++++++++
 configs/khadas-vim3_defconfig  |   3 +
 configs/khadas-vim3l_defconfig |   3 +
 3 files changed, 122 insertions(+)
board/amlogic/vim3/vim3.c +116 -0
index 02d8cd0ce0..cf730fa0d1 100644
@@ -11,6 +11,122 @@
 #include <net.h>
 #include <asm/io.h>
 #include <asm/arch/eth.h>
+#include <i2c.h>
+#include "khadas-mcu.h"
+
+/*
+ * The VIM3 on-board  MCU can mux the PCIe/USB3.0 shared differential
+ * lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between
+ * an USB3.0 Type A connector and a M.2 Key M slot.
+ * The PHY driving these differential lines is shared between
+ * the USB3.0 controller and the PCIe Controller, thus only
+ * a single controller can use it.
+ */
+int meson_ft_board_setup(void *blob, struct bd_info *bd)
+{
+	struct udevice *bus, *dev;
+	int node, i2c_node, ret;
+	unsigned int i2c_addr;
+	u32 *val;
+
+	/* Find I2C device */
+	node = fdt_node_offset_by_compatible(gd->fdt_blob, -1, "khadas,mcu");
+	if (node < 0) {
+		printf("vim3: cannot find khadas,mcu node\n");
+		return 0;
+	}
+
+	/* Get addr */
+	val = (u32 *)fdt_getprop(gd->fdt_blob, node, "reg", NULL);
+	if (!val) {
+		printf("vim3: cannot find khadas,mcu node i2c addr\n");
+		return 0;
+	}
+	i2c_addr = fdt32_to_cpu(*val);
+
+	/* Get i2c device */
+	i2c_node = fdt_parent_offset(gd->fdt_blob, node);
+	if (node < 0) {
+		printf("vim3: cannot find khadas,mcu i2c node\n");
+		return 0;
+	}
+
+	ret = uclass_get_device_by_of_offset(UCLASS_I2C, i2c_node, &bus);
+	if (ret < 0) {
+		printf("vim3: cannot find i2c bus (%d)\n", ret);
+		return 0;
+	}
+
+	ret = i2c_get_chip(bus, i2c_addr, 1, &dev);
+	if (ret < 0) {
+		printf("vim3: cannot find i2c chip (%d)\n", ret);
+		return 0;
+	}
+
+	/* Read USB_PCIE_SWITCH_REG */
+	ret = dm_i2c_reg_read(dev, KHADAS_MCU_USB_PCIE_SWITCH_REG);
+	if (ret < 0) {
+		printf("vim3: failed to read i2c reg (%d)\n", ret);
+		return 0;
+	}
+	debug("MCU_USB_PCIE_SWITCH_REG: %d\n", ret);
+
+	/*
+	 * If in PCIe mode, alter DT
+	 * 0?Enable USB3.0?Disable PCIE, 1?Disable USB3.0, Enable PCIE
+	 */
+	if (ret > 0) {
+		static char data[32] __aligned(4);
+		const void *ptmp;
+		int len;
+
+		/* Find USB node */
+		node = fdt_node_offset_by_compatible(blob, -1, "amlogic,meson-g12a-usb-ctrl");
+		if (node < 0) {
+			printf("vim3: cannot find amlogic,meson-g12a-usb-ctrl node\n");
+			return 0;
+		}
+
+		/* Update PHY names (mandatory to disable USB3.0) */
+		len = strlcpy(data, "usb2-phy0", 32) + 1;
+		len += strlcpy(&data[len], "usb2-phy1", 32 - len) + 1;
+		ret = fdt_setprop(blob, node, "phy-names", data, len);
+		if (ret < 0) {
+			printf("vim3: failed to update usb phy names property (%d)\n", ret);
+			return 0;
+		}
+
+		/* Update PHY list, by keeping the 2 first entries (optional) */
+		ptmp = fdt_getprop(blob, node, "phys", &len);
+		if (ptmp) {
+			memcpy(data, ptmp, min(2 * sizeof(u32), len));
+
+			ret = fdt_setprop(blob, node, "phys", data, min(2 * sizeof(u32), len));
+			if (ret < 0)
+				printf("vim3: failed to update usb phys property (%d)\n", ret);
+		} else
+			printf("vim3: cannot find usb node phys property\n");
+
+		/* Find PCIe node */
+		node = fdt_node_offset_by_compatible(blob, -1, "amlogic,g12a-pcie");
+		if (node < 0) {
+			printf("vim3: cannot find amlogic,g12a-pcie node\n");
+			return 0;
+		}
+
+		/* Enable PCIe */
+		len = strlcpy(data, "okay", 32);
+		ret = fdt_setprop(blob, node, "status", data, len);
+		if (ret < 0) {
+			printf("vim3: failed to enable pcie node (%d)\n", ret);
+			return 0;
+		}
+
+		printf("vim3: successfully enabled PCIe\n");
+	}
+
+	return 0;
+}
 
 int misc_init_r(void)
 {
configs/khadas-vim3_defconfig +3 -0
index ee5990426d..df2d5bda5b 100644
@@ -17,6 +17,7 @@ CONFIG_MISC_INIT_R=y
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_IMI is not set
 CONFIG_CMD_GPIO=y
+CONFIG_CMD_I2C=y
 # CONFIG_CMD_LOADS is not set
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
@@ -28,6 +29,8 @@ CONFIG_CMD_REGULATOR=y
 CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_MESON=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_MESON_GX=y
 CONFIG_MTD=y
configs/khadas-vim3l_defconfig +3 -0
index 5729d339e9..39e74c3ccb 100644
@@ -17,6 +17,7 @@ CONFIG_MISC_INIT_R=y
 # CONFIG_CMD_BDI is not set
 # CONFIG_CMD_IMI is not set
 CONFIG_CMD_GPIO=y
+CONFIG_CMD_I2C=y
 # CONFIG_CMD_LOADS is not set
 CONFIG_CMD_MMC=y
 CONFIG_CMD_SF_TEST=y
@@ -28,6 +29,8 @@ CONFIG_CMD_REGULATOR=y
 CONFIG_OF_CONTROL=y
 CONFIG_SYS_RELOC_GD_ENV_ADDR=y
 CONFIG_NET_RANDOM_ETHADDR=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_MESON=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_MESON_GX=y
 CONFIG_MTD=y
Signature · 1 line
2.22.0
maintainer
#5 lore raw

PATCH 4/4 board: amlogic: vim3: add support for dynamic PCIe enable

Quoted 21 lines · Neil Armstrong

The VIM3 on-board MCU can mux the PCIe/USB3.0 shared differential lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between an USB3.0 Type A connector and a M.2 Key M slot.
The PHY driving these differential lines is shared between the USB3.0 controller and the PCIe Controller, thus only a single controller can use it.

This adds this dynamic switching right before booting Linux.

---
 board/amlogic/vim3/vim3.c      | 116 +++++++++++++++++++++++++++++++++
 configs/khadas-vim3_defconfig  |   3 +
 configs/khadas-vim3l_defconfig |   3 +
 3 files changed, 122 insertions(+)
board/amlogic/vim3/vim3.c +0 -0
index 02d8cd0ce0..cf730fa0d1 100644

board/amlogic/vim3/vim3.c line 15

Quoted 5 lines
board/amlogic/vim3/vim3.c +2 -0
@@ -11,6 +11,122 @@
 #include <net.h>
 #include <asm/io.h>
 #include <asm/arch/eth.h>
+#include <i2c.h>
+#include "khadas-mcu.h"

This file doesn't exist in this series, so it doesn't compile.

Copying it from Linux, it compiles and works fine.

Kevin

maintainer
#6 lore raw

cover amlogic: vim3: add support for dynamic PCIe enable

In reply to Neil Armstrong
Quoted 9 lines · Neil Armstrong

The VIM3 on-board MCU can mux the PCIe/USB3.0 shared differential lines using a FUSB340TMX USB 3.1 SuperSpeed Data Switch between an USB3.0 Type A connector and a M.2 Key M slot.
The PHY driving these differential lines is shared between the USB3.0 controller and the PCIe Controller, thus only a single controller can use it.

This serie adds a VIM3 specific board support and adds this dynamic switching right before booting Linux.

Tested on khadas vim3

Kevin