Skip to contentSkip to conversation

Add support for MediaTek MT7988 SoC

PATCH In review Weijie Gao 6 participants 39 messages Jul 19, 2023 – Aug 10, 2023

Subsystems (13)
lore
Share & tools
lore

Weijie Gao

author
#0 lore raw

cover Add support for MediaTek MT7988 SoC

This patch series add support for MediaTek MT7988 SoC with its reference boards and related drivers.

This patch series add basic boot support on eMMC/SD/SPI-NOR/SPI-NAND for these boards. The clock, pinctrl drivers and the SoC initializaton code are also included.

Product spec for MT7988:
https://www.mediatek.com/products/broadband-wifi/mediatek-filogic-880

Weijie Gao (29):
arm: mediatek: retrieve ram_base from dts node for armv8 platform
board: mediatek: update config headers
spi: mtk_spim: get spi clk rate only once
spi: mtk_spim: clear IRQ enable bits
serial: mtk: initial priv data before using
reset: mediatek: check malloc return valaue before use
i2c: mediatek: fix I2C usability for MT7981
arm: dts: enable i2c support for MediaTek MT7981
pwm: mtk: add support for MediaTek MT7988 SoC
clk: mediatek: add clock driver support for MediaTek MT7988 SoC
reset: mediatek: add reset definition for MediaTek MT7988 SoC
pinctrl: mediatek: convert most definitions to const
pinctrl: mediatek: fix the return value in driving configuration
functions
pinctrl: mediatek: add pinmux_set ops support
pinctrl: mediatek: add pinctrl driver for MT7988 SoC
net: mediatek: connect switch to PSE only when starting eth is
requested
net: mediatek: optimize the switch reset delay wait time
net: mediatek: fix direct MDIO clause 45 access via SoC
net: mediatek: add missing static qualifier
net: mediatek: add support for SGMII 1Gbps auto-negotiation mode
arm: dts: medaitek: convert gmac link mode to 2500base-x
net: mediatek: add support for GMAC/USB3 PHY mux mode for MT7981
arm: dts: mediatek: add infracfg registers to support GMAC/USB3 Co-PHY
net: mediatek: add USXGMII support
net: mediatek: add support for NETSYS v3
net: mediatek: add support for MediaTek MT7988 SoC
tools: mtk_image: use uint32_t for ghf header magic and version
arm: mediatek: add support for MediaTek MT7988 SoC
board: mediatek: add MT7988 reference boards

 arch/arm/dts/Makefile                         |    2 +
 arch/arm/dts/mt7622-bananapi-bpi-r64.dts      |    4 +-
 arch/arm/dts/mt7622-rfb.dts                   |    4 +-
 arch/arm/dts/mt7629-rfb.dts                   |    4 +-
 arch/arm/dts/mt7981-emmc-rfb.dts              |    9 +-
 arch/arm/dts/mt7981-rfb.dts                   |    9 +-
 arch/arm/dts/mt7981-sd-rfb.dts                |    9 +-
 arch/arm/dts/mt7981.dtsi                      |   21 +
 arch/arm/dts/mt7986a-bpi-r3-sd.dts            |    5 +
 arch/arm/dts/mt7986a-rfb.dts                  |    9 +-
 arch/arm/dts/mt7986a-sd-rfb.dts               |    9 +-
 arch/arm/dts/mt7986b-rfb.dts                  |    9 +-
 arch/arm/dts/mt7986b-sd-rfb.dts               |    9 +-
 arch/arm/dts/mt7988-rfb.dts                   |  182 +++
 arch/arm/dts/mt7988-sd-rfb.dts                |  134 ++
 arch/arm/dts/mt7988-u-boot.dtsi               |   25 +
 arch/arm/dts/mt7988.dtsi                      |  391 +++++
 arch/arm/mach-mediatek/Kconfig                |   13 +-
 arch/arm/mach-mediatek/Makefile               |    1 +
 arch/arm/mach-mediatek/mt7622/init.c          |   13 +-
 arch/arm/mach-mediatek/mt7981/init.c          |   11 +-
 arch/arm/mach-mediatek/mt7986/init.c          |   11 +-
 arch/arm/mach-mediatek/mt7988/Makefile        |    4 +
 arch/arm/mach-mediatek/mt7988/init.c          |   63 +
 arch/arm/mach-mediatek/mt7988/lowlevel_init.S |   30 +
 board/mediatek/mt7622/mt7622_rfb.c            |    1 -
 board/mediatek/mt7988/MAINTAINERS             |    7 +
 board/mediatek/mt7988/Makefile                |    3 +
 board/mediatek/mt7988/mt7988_rfb.c            |   10 +
 configs/mt7988_rfb_defconfig                  |   83 ++
 configs/mt7988_sd_rfb_defconfig               |   71 +
 drivers/clk/mediatek/Makefile                 |    1 +
 drivers/clk/mediatek/clk-mt7988.c             | 1123 +++++++++++++++
 drivers/i2c/mtk_i2c.c                         |   45 +-
 drivers/net/mtk_eth.c                         |  572 +++++++-
 drivers/net/mtk_eth.h                         |   69 +
 drivers/pinctrl/mediatek/Kconfig              |    4 +
 drivers/pinctrl/mediatek/Makefile             |    1 +
 drivers/pinctrl/mediatek/pinctrl-mt7622.c     |  474 +++---
 drivers/pinctrl/mediatek/pinctrl-mt7623.c     |  650 ++++-----
 drivers/pinctrl/mediatek/pinctrl-mt7629.c     |  174 +--
 drivers/pinctrl/mediatek/pinctrl-mt7981.c     |  270 ++--
 drivers/pinctrl/mediatek/pinctrl-mt7986.c     |  145 +-
 drivers/pinctrl/mediatek/pinctrl-mt7988.c     | 1274 +++++++++++++++++
 drivers/pinctrl/mediatek/pinctrl-mt8512.c     |   24 +-
 drivers/pinctrl/mediatek/pinctrl-mt8516.c     |   18 +-
 drivers/pinctrl/mediatek/pinctrl-mt8518.c     |   20 +-
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c |   22 +-
 drivers/pinctrl/mediatek/pinctrl-mtk-common.h |    8 +-
 drivers/pwm/pwm-mtk.c                         |    7 +
 drivers/reset/reset-mediatek.c                |    3 +
 drivers/serial/serial_mtk.c                   |    1 +
 drivers/spi/mtk_spim.c                        |   24 +-
 include/configs/mt7620.h                      |    3 +-
 include/configs/mt7621.h                      |    6 +-
 include/configs/mt7622.h                      |   10 -
 include/configs/mt7623.h                      |    8 -
 include/configs/mt7628.h                      |    5 +-
 include/configs/mt7629.h                      |   13 +-
 include/configs/mt7981.h                      |    9 -
 include/configs/mt7986.h                      |    9 -
 include/configs/mt7988.h                      |   14 +
 include/dt-bindings/clock/mt7988-clk.h        |  349 +++++
 include/dt-bindings/reset/mt7988-reset.h      |   31 +
 tools/mtk_image.c                             |   10 +-
 tools/mtk_image.h                             |    6 +-
 66 files changed, 5533 insertions(+), 1025 deletions(-)
 create mode 100644 arch/arm/dts/mt7988-rfb.dts
 create mode 100644 arch/arm/dts/mt7988-sd-rfb.dts
 create mode 100644 arch/arm/dts/mt7988-u-boot.dtsi
 create mode 100644 arch/arm/dts/mt7988.dtsi
 create mode 100644 arch/arm/mach-mediatek/mt7988/Makefile
 create mode 100644 arch/arm/mach-mediatek/mt7988/init.c
 create mode 100644 arch/arm/mach-mediatek/mt7988/lowlevel_init.S
 create mode 100644 board/mediatek/mt7988/MAINTAINERS
 create mode 100644 board/mediatek/mt7988/Makefile
 create mode 100644 board/mediatek/mt7988/mt7988_rfb.c
 create mode 100644 configs/mt7988_rfb_defconfig
 create mode 100644 configs/mt7988_sd_rfb_defconfig
 create mode 100644 drivers/clk/mediatek/clk-mt7988.c
 create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7988.c
 create mode 100644 include/configs/mt7988.h
 create mode 100644 include/dt-bindings/clock/mt7988-clk.h
 create mode 100644 include/dt-bindings/reset/mt7988-reset.h
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH 2/29 board: mediatek: update config headers

Remove unused information from include/configs/mtxxxx.h

---
 include/configs/mt7620.h |  3 +--
 include/configs/mt7621.h |  6 ++----
 include/configs/mt7623.h |  8 --------
 include/configs/mt7628.h |  5 ++---
 include/configs/mt7629.h | 13 +------------
 5 files changed, 6 insertions(+), 29 deletions(-)
include/configs/mt7620.h +1 -2
index d5bd492634..d69d35fa96 100644
@@ -10,10 +10,9 @@
 
 #define CFG_SYS_SDRAM_BASE		0x80000000
 
-#define CFG_SYS_INIT_SP_OFFSET	0x400000
+#define CFG_SYS_INIT_SP_OFFSET		0x400000
 
 /* SPL */
-
 #define CFG_SYS_UBOOT_START		CONFIG_TEXT_BASE
 
 /* Dummy value */
include/configs/mt7621.h +2 -4
index a9574940d4..bf2bc2d45c 100644
@@ -12,13 +12,11 @@
 
 #define CFG_MAX_MEM_MAPPED		0x1c000000
 
-#define CFG_SYS_INIT_SP_OFFSET	0x800000
+#define CFG_SYS_INIT_SP_OFFSET		0x800000
 
 /* MMC */
 #define MMC_SUPPORTS_TUNING
 
-/* NAND */
-
 /* Serial SPL */
 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL)
 #define CFG_SYS_NS16550_CLK		50000000
@@ -26,7 +24,7 @@
 #endif
 
 /* Serial common */
-#define CFG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200, \
+#define CFG_SYS_BAUDRATE_TABLE		{ 9600, 19200, 38400, 57600, 115200, \
 					  230400, 460800, 921600 }
 
 /* Dummy value */
include/configs/mt7623.h +0 -8
index db12377b00..fca234a1dc 100644
@@ -11,12 +11,6 @@
 
 #include <linux/sizes.h>
 
-/* Miscellaneous configurable options */
-
-/* Environment */
-
-/* Preloader -> Uboot */
-
 /* MMC */
 #define MMC_SUPPORTS_TUNING
 
@@ -32,8 +26,6 @@
 	"fdt_addr_r=" FDT_HIGH "\0"			\
 	"fdtfile=" CONFIG_DEFAULT_FDT_FILE "\0"
 
-/* Ethernet */
-
 #ifdef CONFIG_DISTRO_DEFAULTS
 
 #define BOOT_TARGET_DEVICES(func)	\
include/configs/mt7628.h +2 -3
index 9df2715fc7..0ac376d33c 100644
@@ -10,7 +10,7 @@
 
 #define CFG_SYS_SDRAM_BASE		0x80000000
 
-#define CFG_SYS_INIT_SP_OFFSET	0x80000
+#define CFG_SYS_INIT_SP_OFFSET		0x80000
 
 /* Serial SPL */
 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL)
@@ -19,11 +19,10 @@
 #endif
 
 /* Serial common */
-#define CFG_SYS_BAUDRATE_TABLE	{ 9600, 19200, 38400, 57600, 115200, \
+#define CFG_SYS_BAUDRATE_TABLE		{ 9600, 19200, 38400, 57600, 115200, \
 					  230400, 460800, 921600 }
 
 /* SPL */
-
 #define CFG_SYS_UBOOT_START		CONFIG_TEXT_BASE
 
 /* Dummy value */
include/configs/mt7629.h +1 -12
index f6ab486fa2..59cdd22a1c 100644
@@ -9,21 +9,10 @@
 #ifndef __MT7629_H
 #define __MT7629_H
 
-#include <linux/sizes.h>
-
-/* Miscellaneous configurable options */
-
-/* Environment */
-
+/* SPL */
 #define CFG_SYS_UBOOT_BASE		(0x30000000 + CONFIG_SPL_PAD_TO)
 
-/* SPL -> Uboot */
-
-/* UBoot -> Kernel */
-
 /* DRAM */
 #define CFG_SYS_SDRAM_BASE		0x40000000
 
-/* Ethernet */
-
 #endif
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH 3/29 spi: mtk_spim: get spi clk rate only once

In reply to Weijie Gao

We don't really need to switch clk rate during operating SPIM controller. Get clk rate only once at driver probing.

---
 drivers/spi/mtk_spim.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
drivers/spi/mtk_spim.c +13 -8
index ebb8ee8ef4..3a742d160c 100644
@@ -137,6 +137,8 @@ struct mtk_spim_capability {
  * @state:		Controller state
  * @sel_clk:		Pad clock
  * @spi_clk:		Core clock
+ * @pll_clk_rate:	Controller's PLL source clock rate, which is different
+ *			from SPI bus clock rate
  * @xfer_len:		Current length of data for transfer
  * @hw_cap:		Controller capabilities
  * @tick_dly:		Used to postpone SPI sampling time
@@ -149,6 +151,7 @@ struct mtk_spim_priv {
 	void __iomem *base;
 	u32 state;
 	struct clk sel_clk, spi_clk;
+	u32 pll_clk_rate;
 	u32 xfer_len;
 	struct mtk_spim_capability hw_cap;
 	u32 tick_dly;
@@ -253,11 +256,10 @@ static int mtk_spim_hw_init(struct spi_slave *slave)
 static void mtk_spim_prepare_transfer(struct mtk_spim_priv *priv,
 				      u32 speed_hz)
 {
-	u32 spi_clk_hz, div, sck_time, cs_time, reg_val;
+	u32 div, sck_time, cs_time, reg_val;
 
-	spi_clk_hz = clk_get_rate(&priv->spi_clk);
-	if (speed_hz <= spi_clk_hz / 4)
-		div = DIV_ROUND_UP(spi_clk_hz, speed_hz);
+	if (speed_hz <= priv->pll_clk_rate / 4)
+		div = DIV_ROUND_UP(priv->pll_clk_rate, speed_hz);
 	else
 		div = 4;
 
@@ -404,7 +406,7 @@ static int mtk_spim_transfer_wait(struct spi_slave *slave,
 {
 	struct udevice *bus = dev_get_parent(slave->dev);
 	struct mtk_spim_priv *priv = dev_get_priv(bus);
-	u32 sck_l, sck_h, spi_bus_clk, clk_count, reg;
+	u32 sck_l, sck_h, clk_count, reg;
 	ulong us = 1;
 	int ret = 0;
 
@@ -413,12 +415,11 @@ static int mtk_spim_transfer_wait(struct spi_slave *slave,
 	else
 		clk_count = op->data.nbytes;
 
-	spi_bus_clk = clk_get_rate(&priv->spi_clk);
 	sck_l = readl(priv->base + SPI_CFG2_REG) >> SPI_CFG2_SCK_LOW_OFFSET;
 	sck_h = readl(priv->base + SPI_CFG2_REG) & SPI_CFG2_SCK_HIGH_MASK;
-	do_div(spi_bus_clk, sck_l + sck_h + 2);
+	do_div(priv->pll_clk_rate, sck_l + sck_h + 2);
 
-	us = CLK_TO_US(spi_bus_clk, clk_count * 8);
+	us = CLK_TO_US(priv->pll_clk_rate, clk_count * 8);
 	us += 1000 * 1000; /* 1s tolerance */
 
 	if (us > UINT_MAX)
@@ -662,6 +663,10 @@ static int mtk_spim_probe(struct udevice *dev)
 	clk_enable(&priv->sel_clk);
 	clk_enable(&priv->spi_clk);
 
+	priv->pll_clk_rate = clk_get_rate(&priv->spi_clk);
+	if (priv->pll_clk_rate == 0)
+		return -EINVAL;
+
 	return 0;
 }
 
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/29 arm: mediatek: retrieve ram_base from dts node for armv8 platform

In reply to Weijie Gao

Now we use fdtdec_setup_mem_size_base() to get DRAM base from fdt ram node and update gd->ram_base. CFG_SYS_SDRAM_BASE is unused and will be removed.

Also, since mt7622 always passes fdt to linux kernel, there's no need to assign value to gd->bd->bi_boot_params.

---
 arch/arm/dts/mt7981-emmc-rfb.dts     |  5 +++++
 arch/arm/dts/mt7981-rfb.dts          |  5 +++++
 arch/arm/dts/mt7981-sd-rfb.dts       |  5 +++++
 arch/arm/dts/mt7986a-bpi-r3-sd.dts   |  5 +++++
 arch/arm/dts/mt7986a-rfb.dts         |  5 +++++
 arch/arm/dts/mt7986a-sd-rfb.dts      |  5 +++++
 arch/arm/dts/mt7986b-rfb.dts         |  5 +++++
 arch/arm/dts/mt7986b-sd-rfb.dts      |  5 +++++
 arch/arm/mach-mediatek/mt7622/init.c | 13 +++++++++----
 arch/arm/mach-mediatek/mt7981/init.c | 11 +++++++++--
 arch/arm/mach-mediatek/mt7986/init.c | 11 +++++++++--
 board/mediatek/mt7622/mt7622_rfb.c   |  1 -
 include/configs/mt7622.h             | 10 ----------
 include/configs/mt7981.h             |  9 ---------
 include/configs/mt7986.h             |  9 ---------
 15 files changed, 67 insertions(+), 37 deletions(-)
arch/arm/dts/mt7981-emmc-rfb.dts +5 -0
index 2b7eae99ce..a0913c5b7c 100644
@@ -18,6 +18,11 @@
 		tick-timer = &timer0;
 	};
 
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x10000000>;
+	};
+
 	reg_3p3v: regulator-3p3v {
 		  compatible = "regulator-fixed";
 		  regulator-name = "fixed-3.3V";
arch/arm/dts/mt7981-rfb.dts +5 -0
index 5559ace953..1dc90ac63f 100644
@@ -17,6 +17,11 @@
 		stdout-path = &uart0;
 		tick-timer = &timer0;
 	};
+
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x10000000>;
+	};
 };
 
 &uart0 {
arch/arm/dts/mt7981-sd-rfb.dts +5 -0
index 34ac227ecf..05f3fdb5ef 100644
@@ -18,6 +18,11 @@
 		tick-timer = &timer0;
 	};
 
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x10000000>;
+	};
+
 	reg_3p3v: regulator-3p3v {
 		  compatible = "regulator-fixed";
 		  regulator-name = "fixed-3.3V";
arch/arm/dts/mt7986a-bpi-r3-sd.dts +5 -0
index 4d12440fa3..15256302b8 100644
@@ -19,6 +19,11 @@
 		tick-timer = &timer0;
 	};
 
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x80000000>;
+	};
+
 	reg_3p3v: regulator-3p3v {
 		compatible = "regulator-fixed";
 		regulator-name = "fixed-3.3V";
arch/arm/dts/mt7986a-rfb.dts +5 -0
index 80def57e1a..dce85d8277 100644
@@ -18,6 +18,11 @@
 		tick-timer = &timer0;
 	};
 
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x10000000>;
+	};
+
 	reg_1p8v: regulator-1p8v {
 		compatible = "regulator-fixed";
 		regulator-name = "fixed-1.8V";
arch/arm/dts/mt7986a-sd-rfb.dts +5 -0
index 5807c5d5cc..7f32607589 100644
@@ -19,6 +19,11 @@
 		tick-timer = &timer0;
 	};
 
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x10000000>;
+	};
+
 	reg_3p3v: regulator-3p3v {
 		compatible = "regulator-fixed";
 		regulator-name = "fixed-3.3V";
arch/arm/dts/mt7986b-rfb.dts +5 -0
index 0c4e3e878f..3349e38a90 100644
@@ -18,6 +18,11 @@
 		tick-timer = &timer0;
 	};
 
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x10000000>;
+	};
+
 	reg_3p3v: regulator-3p3v {
 		compatible = "regulator-fixed";
 		regulator-name = "fixed-3.3V";
arch/arm/dts/mt7986b-sd-rfb.dts +5 -0
index 48f9320e7a..6c9203332b 100644
@@ -19,6 +19,11 @@
 		tick-timer = &timer0;
 	};
 
+	memory@40000000 {
+		device_type = "memory";
+		reg = <0x40000000 0x10000000>;
+	};
+
 	reg_3p3v: regulator-3p3v {
 		compatible = "regulator-fixed";
 		regulator-name = "fixed-3.3V";
arch/arm/mach-mediatek/mt7622/init.c +9 -4
index e501907b53..1190fd5eb0 100644
@@ -4,11 +4,14 @@
  * Author: Sam Shih <[email protected]>
  */
 
-#include <common.h>
 #include <fdtdec.h>
 #include <init.h>
 #include <asm/armv8/mmu.h>
-#include <asm/cache.h>
+#include <asm/global_data.h>
+#include <asm/u-boot.h>
+#include <linux/sizes.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 int print_cpuinfo(void)
 {
@@ -20,11 +23,13 @@ int dram_init(void)
 {
 	int ret;
 
-	ret = fdtdec_setup_memory_banksize();
+	ret = fdtdec_setup_mem_size_base();
 	if (ret)
 		return ret;
-	return fdtdec_setup_mem_size_base();
 
+	gd->ram_size = get_ram_size((void *)gd->ram_base, SZ_2G);
+
+	return 0;
 }
 
 void reset_cpu(void)
arch/arm/mach-mediatek/mt7981/init.c +9 -2
index 3c921d6ad5..862f0ca479 100644
@@ -4,18 +4,25 @@
  * Author: Sam Shih <[email protected]>
  */
 
-#include <cpu_func.h>
+#include <fdtdec.h>
 #include <init.h>
 #include <asm/armv8/mmu.h>
 #include <asm/system.h>
 #include <asm/global_data.h>
+#include <asm/u-boot.h>
 #include <linux/sizes.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init(void)
 {
-	gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, SZ_2G);
+	int ret;
+
+	ret = fdtdec_setup_mem_size_base();
+	if (ret)
+		return ret;
+
+	gd->ram_size = get_ram_size((void *)gd->ram_base, SZ_1G);
 
 	return 0;
 }
arch/arm/mach-mediatek/mt7986/init.c +9 -2
index 9d0c0cdcd0..905a3ab4e2 100644
@@ -4,18 +4,25 @@
  * Author: Sam Shih <[email protected]>
  */
 
-#include <cpu_func.h>
+#include <fdtdec.h>
 #include <init.h>
 #include <asm/armv8/mmu.h>
 #include <asm/system.h>
 #include <asm/global_data.h>
+#include <asm/u-boot.h>
 #include <linux/sizes.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init(void)
 {
-	gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, SZ_2G);
+	int ret;
+
+	ret = fdtdec_setup_mem_size_base();
+	if (ret)
+		return ret;
+
+	gd->ram_size = get_ram_size((void *)gd->ram_base, SZ_2G);
 
 	return 0;
 }
board/mediatek/mt7622/mt7622_rfb.c +0 -1
index ff233e920a..2cc73bc35d 100644
@@ -14,7 +14,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int board_init(void)
 {
-	gd->bd->bi_boot_params = CFG_SYS_SDRAM_BASE + 0x100;
 	return 0;
 }
 
include/configs/mt7622.h +0 -10
index 6541512953..4a056954bf 100644
@@ -9,14 +9,4 @@
 #ifndef __MT7622_H
 #define __MT7622_H
 
-/* Uboot definition */
-#define CFG_SYS_UBOOT_BASE                   CONFIG_TEXT_BASE
-
-/* SPL -> Uboot */
-#define CFG_SYS_UBOOT_START		CONFIG_TEXT_BASE
-/* DRAM */
-#define CFG_SYS_SDRAM_BASE		0x40000000
-
-/* Ethernet */
-
 #endif
include/configs/mt7981.h +0 -9
index 14c885ec55..a6d647edc4 100644
@@ -9,13 +9,4 @@
 #ifndef __MT7981_H
 #define __MT7981_H
 
-/* Uboot definition */
-#define CFG_SYS_UBOOT_BASE		CONFIG_TEXT_BASE
-
-/* SPL -> Uboot */
-#define CFG_SYS_UBOOT_START		CONFIG_TEXT_BASE
-
-/* DRAM */
-#define CFG_SYS_SDRAM_BASE		0x40000000
-
 #endif
include/configs/mt7986.h +0 -9
index 0c41af1fc3..090b4c6833 100644
@@ -9,13 +9,4 @@
 #ifndef __MT7986_H
 #define __MT7986_H
 
-/* Uboot definition */
-#define CFG_SYS_UBOOT_BASE		CONFIG_TEXT_BASE
-
-/* SPL -> Uboot */
-#define CFG_SYS_UBOOT_START		CONFIG_TEXT_BASE
-
-/* DRAM */
-#define CFG_SYS_SDRAM_BASE		0x40000000
-
 #endif
Signature · 1 line
2.17.1
author
#5 lore raw

PATCH 4/29 spi: mtk_spim: clear IRQ enable bits

In reply to Weijie Gao

In u-boot we don't use IRQ. Instead, we poll busy bit in SPI_STATUS.

However these IRQ enable bits may be set in previous boot stage (BootROM).

If we leave these bits not cleared, although u-boot has disabled IRQ and nothing will happen, the linux kernel may encounter panic during initializing the spim driver due to IRQ event happens before IRQ handler is properly setup.

This patch clear IRQ bits to prevent this from happening.

---
 drivers/spi/mtk_spim.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/spi/mtk_spim.c +3 -0
index 3a742d160c..418e586b91 100644
@@ -242,6 +242,9 @@ static int mtk_spim_hw_init(struct spi_slave *slave)
 			reg_val &= ~SPI_CMD_SAMPLE_SEL;
 	}
 
+	/* Disable interrupt enable for pause mode & normal mode */
+	reg_val &= ~(SPI_CMD_PAUSE_IE | SPI_CMD_FINISH_IE);
+
 	/* disable dma mode */
 	reg_val &= ~(SPI_CMD_TX_DMA | SPI_CMD_RX_DMA);
 
Signature · 1 line
2.17.1
author
#7 lore raw

PATCH 5/29 serial: mtk: initial priv data before using

In reply to Weijie Gao

This patch ensures driver private data being fully initialized in _debug_uart_init which is not covered by .priv_auto ops.

---
 drivers/serial/serial_mtk.c | 1 +
 1 file changed, 1 insertion(+)
drivers/serial/serial_mtk.c +1 -0
index ded7346a13..2dffa14ea7 100644
@@ -439,6 +439,7 @@ static inline void _debug_uart_init(void)
 {
 	struct mtk_serial_priv priv;
 
+	memset(&priv, 0, sizeof(struct mtk_serial_priv));
 	priv.regs = (void *) CONFIG_VAL(DEBUG_UART_BASE);
 	priv.fixed_clk_rate = CONFIG_DEBUG_UART_CLOCK;
 
Signature · 1 line
2.17.1
author
#9 lore raw

PATCH 6/29 reset: mediatek: check malloc return valaue before use

In reply to Weijie Gao

This patch add missing return value check for allocating the driver's private data. -ENOMEM will be returned if malloc() fails.

---
 drivers/reset/reset-mediatek.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/reset/reset-mediatek.c +3 -0
index 8b62d91777..97ed221f73 100644
@@ -79,6 +79,9 @@ int mediatek_reset_bind(struct udevice *pdev, u32 regofs, u32 num_regs)
 		return ret;
 
 	priv = malloc(sizeof(struct mediatek_reset_priv));
+	if (!priv)
+		return -ENOMEM;
+
 	priv->regofs = regofs;
 	priv->nr_resets = num_regs * 32;
 	dev_set_priv(rst_dev, priv);
Signature · 1 line
2.17.1
author
#10 lore raw

PATCH 7/29 i2c: mediatek: fix I2C usability for MT7981

In reply to Weijie Gao

MT7981 actually uses MediaTek I2C controller v3 instead of v1. This patch adds support for I2C controller v3 fix fixes the I2C usability for MT7981.

---
 drivers/i2c/mtk_i2c.c | 45 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)
drivers/i2c/mtk_i2c.c +43 -2
index 5528bcd7cc..2f331d3216 100644
@@ -183,9 +183,36 @@ static const uint mt_i2c_regs_v2[] = {
 	[REG_DCM_EN] = 0xf88,
 };
 
+static const uint mt_i2c_regs_v3[] = {
+	[REG_PORT] = 0x0,
+	[REG_INTR_MASK] = 0x8,
+	[REG_INTR_STAT] = 0xc,
+	[REG_CONTROL] = 0x10,
+	[REG_TRANSFER_LEN] = 0x14,
+	[REG_TRANSAC_LEN] = 0x18,
+	[REG_DELAY_LEN] = 0x1c,
+	[REG_TIMING] = 0x20,
+	[REG_START] = 0x24,
+	[REG_EXT_CONF] = 0x28,
+	[REG_LTIMING] = 0x2c,
+	[REG_HS] = 0x30,
+	[REG_IO_CONFIG] = 0x34,
+	[REG_FIFO_ADDR_CLR] = 0x38,
+	[REG_TRANSFER_LEN_AUX] = 0x44,
+	[REG_CLOCK_DIV] = 0x48,
+	[REG_SOFTRESET] = 0x50,
+	[REG_SLAVE_ADDR] = 0x94,
+	[REG_DEBUGSTAT] = 0xe4,
+	[REG_DEBUGCTRL] = 0xe8,
+	[REG_FIFO_STAT] = 0xf4,
+	[REG_FIFO_THRESH] = 0xf8,
+	[REG_DCM_EN] = 0xf88,
+};
+
 struct mtk_i2c_soc_data {
 	const uint *regs;
 	uint dma_sync: 1;
+	uint ltiming_adjust: 1;
 };
 
 struct mtk_i2c_priv {
@@ -401,6 +428,10 @@ static int mtk_i2c_set_speed(struct udevice *dev, uint speed)
 				(sample_cnt << HS_SAMPLE_OFFSET) |
 				(step_cnt << HS_STEP_OFFSET);
 		i2c_writel(priv, REG_HS, high_speed_reg);
+		if (priv->soc_data->ltiming_adjust) {
+			timing_reg = (sample_cnt << 12) | (step_cnt << 9);
+			i2c_writel(priv, REG_LTIMING, timing_reg);
+		}
 	} else {
 		ret = mtk_i2c_calculate_speed(clk_src, priv->speed,
 					      &step_cnt, &sample_cnt);
@@ -412,7 +443,12 @@ static int mtk_i2c_set_speed(struct udevice *dev, uint speed)
 		high_speed_reg = I2C_TIME_CLR_VALUE;
 		i2c_writel(priv, REG_TIMING, timing_reg);
 		i2c_writel(priv, REG_HS, high_speed_reg);
+		if (priv->soc_data->ltiming_adjust) {
+			timing_reg = (sample_cnt << 6) | step_cnt;
+			i2c_writel(priv, REG_LTIMING, timing_reg);
+		}
 	}
+
 exit:
 	if (mtk_i2c_clk_disable(priv))
 		return log_msg_ret("set_speed disable clk", -1);
@@ -725,7 +761,6 @@ static int mtk_i2c_probe(struct udevice *dev)
 		return log_msg_ret("probe enable clk", -1);
 
 	mtk_i2c_init_hw(priv);
-
 	if (mtk_i2c_clk_disable(priv))
 		return log_msg_ret("probe disable clk", -1);
 
@@ -750,31 +785,37 @@ static int mtk_i2c_deblock(struct udevice *dev)
 static const struct mtk_i2c_soc_data mt76xx_soc_data = {
 	.regs = mt_i2c_regs_v1,
 	.dma_sync = 0,
+	.ltiming_adjust = 0,
 };
 
 static const struct mtk_i2c_soc_data mt7981_soc_data = {
-	.regs = mt_i2c_regs_v1,
+	.regs = mt_i2c_regs_v3,
 	.dma_sync = 1,
+	.ltiming_adjust = 1,
 };
 
 static const struct mtk_i2c_soc_data mt7986_soc_data = {
 	.regs = mt_i2c_regs_v1,
 	.dma_sync = 1,
+	.ltiming_adjust = 0,
 };
 
 static const struct mtk_i2c_soc_data mt8183_soc_data = {
 	.regs = mt_i2c_regs_v2,
 	.dma_sync = 1,
+	.ltiming_adjust = 0,
 };
 
 static const struct mtk_i2c_soc_data mt8518_soc_data = {
 	.regs = mt_i2c_regs_v1,
 	.dma_sync = 0,
+	.ltiming_adjust = 0,
 };
 
 static const struct mtk_i2c_soc_data mt8512_soc_data = {
 	.regs = mt_i2c_regs_v1,
 	.dma_sync = 1,
+	.ltiming_adjust = 0,
 };
 
 static const struct dm_i2c_ops mtk_i2c_ops = {
Signature · 1 line
2.17.1
author
#12 lore raw

PATCH 8/29 arm: dts: enable i2c support for MediaTek MT7981

In reply to Weijie Gao

This patch enables i2c support for MediaTek MT7981

---
 arch/arm/dts/mt7981.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm/dts/mt7981.dtsi +14 -0
index 2c8ef14f98..2053e2ca00 100644
@@ -152,6 +152,20 @@
 		status = "disabled";
 	};
 
+	i2c0: i2c@11007000 {
+		compatible = "mediatek,mt7981-i2c";
+		reg = <0x11007000 0x1000>,
+		      <0x10217080 0x80>;
+		interrupts = <GIC_SPI 136 IRQ_TYPE_LEVEL_HIGH>;
+		clock-div = <1>;
+		clocks = <&infracfg_ao CK_INFRA_I2CO_CK>,
+			 <&infracfg_ao CK_INFRA_AP_DMA_CK>;
+		clock-names = "main", "dma";
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "disabled";
+	};
+
 	uart0: serial@11002000 {
 		compatible = "mediatek,hsuart";
 		reg = <0x11002000 0x400>;
Signature · 1 line
2.17.1
author
#13 lore raw

PATCH 9/29 pwm: mtk: add support for MediaTek MT7988 SoC

In reply to Weijie Gao

This patch adds PWM support for MediaTek MT7988 SoC.

---
 drivers/pwm/pwm-mtk.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/pwm/pwm-mtk.c +7 -0
index 605142eab0..11e7444019 100644
@@ -205,12 +205,19 @@ static const struct mtk_pwm_soc mt7986_data = {
 	.reg_ver = PWM_REG_V1,
 };
 
+static const struct mtk_pwm_soc mt7988_data = {
+	.num_pwms = 8,
+	.pwm45_fixup = false,
+	.reg_ver = PWM_REG_V2,
+};
+
 static const struct udevice_id mtk_pwm_ids[] = {
 	{ .compatible = "mediatek,mt7622-pwm", .data = (ulong)&mt7622_data },
 	{ .compatible = "mediatek,mt7623-pwm", .data = (ulong)&mt7623_data },
 	{ .compatible = "mediatek,mt7629-pwm", .data = (ulong)&mt7629_data },
 	{ .compatible = "mediatek,mt7981-pwm", .data = (ulong)&mt7981_data },
 	{ .compatible = "mediatek,mt7986-pwm", .data = (ulong)&mt7986_data },
+	{ .compatible = "mediatek,mt7988-pwm", .data = (ulong)&mt7988_data },
 	{ }
 };
 
Signature · 1 line
2.17.1
author
#15 lore raw

PATCH 11/29 reset: mediatek: add reset definition for MediaTek MT7988 SoC

In reply to Weijie Gao

This patch adds reset bits for MediaTek MT7988

---
 include/dt-bindings/reset/mt7988-reset.h | 31 ++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 include/dt-bindings/reset/mt7988-reset.h
include/dt-bindings/reset/mt7988-reset.h new file +31 -0
new file mode 100644
index 0000000000..d30011f941
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 MediaTek Inc.
+ */
+
+#ifndef _DT_BINDINGS_MTK_RESET_H_
+#define _DT_BINDINGS_MTK_RESET_H_
+
+/* ETHDMA Subsystem resets */
+#define ETHDMA_FE_RST			6
+#define ETHDMA_PMTR_RST			8
+#define ETHDMA_GMAC_RST			23
+#define ETHDMA_WDMA0_RST		24
+#define ETHDMA_WDMA1_RST		25
+#define ETHDMA_WDMA2_RST		26
+#define ETHDMA_PPE0_RST			29
+#define ETHDMA_PPE1_RST			30
+#define ETHDMA_PPE2_RST			31
+
+/* ETHWARP Subsystem resets */
+#define ETHWARP_GSW_RST			9
+#define ETHWARP_EIP197_RST		10
+#define ETHWARP_WOCPU0_RST		32
+#define ETHWARP_WOCPU1_RST		33
+#define ETHWARP_WOCPU2_RST		34
+#define ETHWARP_WOX_NET_MUX_RST		35
+#define ETHWARP_WED0_RST		36
+#define ETHWARP_WED1_RST		37
+#define ETHWARP_WED2_RST		38
+
+#endif /* _DT_BINDINGS_MTK_RESET_H_ */
Signature · 1 line
2.17.1
author
#14 lore raw

PATCH 10/29 clk: mediatek: add clock driver support for MediaTek MT7988 SoC

In reply to Weijie Gao

This patch adds clock driver support for MediaTek MT7988 SoC

---
 drivers/clk/mediatek/Makefile          |    1 +
 drivers/clk/mediatek/clk-mt7988.c      | 1123 ++++++++++++++++++++++++
 include/dt-bindings/clock/mt7988-clk.h |  349 ++++++++
 3 files changed, 1473 insertions(+)
 create mode 100644 drivers/clk/mediatek/clk-mt7988.c
 create mode 100644 include/dt-bindings/clock/mt7988-clk.h
drivers/clk/mediatek/Makefile +1 -0
index 1decf31a77..e74c6f9780 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_TARGET_MT7622) += clk-mt7622.o
 obj-$(CONFIG_TARGET_MT7629) += clk-mt7629.o
 obj-$(CONFIG_TARGET_MT7986) += clk-mt7986.o
 obj-$(CONFIG_TARGET_MT7981) += clk-mt7981.o
+obj-$(CONFIG_TARGET_MT7988) += clk-mt7988.o
 obj-$(CONFIG_TARGET_MT8183) += clk-mt8183.o
 obj-$(CONFIG_TARGET_MT8516) += clk-mt8516.o
 obj-$(CONFIG_TARGET_MT8518) += clk-mt8518.o
drivers/clk/mediatek/clk-mt7988.c new file +1123 -0

1,123 lines not on this page · raw message

include/dt-bindings/clock/mt7988-clk.h new file +349 -0

349 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#17 lore raw

PATCH 13/29 pinctrl: mediatek: fix the return value in driving configuration functions

In reply to Weijie Gao

The original mediatek pinctrl functions for driving configuration 'mtk_pinconf_drive_set_*' do not return -ENOSUPP even if input parameters are not supported.
This patch fixes the return value in those functions.

---
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +2 -2
index 1caca3496c..623a094c39 100644
@@ -513,7 +513,7 @@ int mtk_pinconf_drive_set_v0(struct udevice *dev, u32 pin, u32 arg)
 			return err;
 	}
 
-	return 0;
+	return err;
 }
 
 int mtk_pinconf_drive_set_v1(struct udevice *dev, u32 pin, u32 arg)
@@ -531,7 +531,7 @@ int mtk_pinconf_drive_set_v1(struct udevice *dev, u32 pin, u32 arg)
 			return err;
 	}
 
-	return 0;
+	return err;
 }
 
 int mtk_pinconf_drive_set(struct udevice *dev, u32 pin, u32 arg)
Signature · 1 line
2.17.1
author
#18 lore raw

PATCH 14/29 pinctrl: mediatek: add pinmux_set ops support

In reply to Weijie Gao

This patch adds pinmux_set ops for mediatek pinctrl framework

---
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +14 -0
index 623a094c39..0baef57c1c 100644
@@ -304,6 +304,19 @@ static const char *mtk_get_function_name(struct udevice *dev,
 	return priv->soc->funcs[selector].name;
 }
 
+static int mtk_pinmux_set(struct udevice *dev, unsigned int pin_selector,
+			  unsigned int func_selector)
+{
+	int err;
+
+	err = mtk_hw_set_value(dev, pin_selector, PINCTRL_PIN_REG_MODE,
+			       func_selector);
+	if (err)
+		return err;
+
+	return 0;
+}
+
 static int mtk_pinmux_group_set(struct udevice *dev,
 				unsigned int group_selector,
 				unsigned int func_selector)
@@ -647,6 +660,7 @@ const struct pinctrl_ops mtk_pinctrl_ops = {
 	.get_group_name = mtk_get_group_name,
 	.get_functions_count = mtk_get_functions_count,
 	.get_function_name = mtk_get_function_name,
+	.pinmux_set = mtk_pinmux_set,
 	.pinmux_group_set = mtk_pinmux_group_set,
 #if CONFIG_IS_ENABLED(PINCONF)
 	.pinconf_num_params = ARRAY_SIZE(mtk_conf_params),
Signature · 1 line
2.17.1
author
#19 lore raw

PATCH 15/29 pinctrl: mediatek: add pinctrl driver for MT7988 SoC

In reply to Weijie Gao

This patch adds pinctrl and gpio support for MT7988 SoC

---
 drivers/pinctrl/mediatek/Kconfig          |    4 +
 drivers/pinctrl/mediatek/Makefile         |    1 +
 drivers/pinctrl/mediatek/pinctrl-mt7988.c | 1274 +++++++++++++++++++++
 3 files changed, 1279 insertions(+)
 create mode 100644 drivers/pinctrl/mediatek/pinctrl-mt7988.c
drivers/pinctrl/mediatek/Kconfig +4 -0
index 27e8998e59..34d23cece5 100644
@@ -24,6 +24,10 @@ config PINCTRL_MT7986
 	bool "MT7986 SoC pinctrl driver"
 	select PINCTRL_MTK
 
+config PINCTRL_MT7988
+	bool "MT7988 SoC pinctrl driver"
+	select PINCTRL_MTK
+
 config PINCTRL_MT8512
 	bool "MT8512 SoC pinctrl driver"
 	select PINCTRL_MTK
drivers/pinctrl/mediatek/Makefile +1 -0
index 6e733759f5..de39d1ea43 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_PINCTRL_MT7623) += pinctrl-mt7623.o
 obj-$(CONFIG_PINCTRL_MT7629) += pinctrl-mt7629.o
 obj-$(CONFIG_PINCTRL_MT7981) += pinctrl-mt7981.o
 obj-$(CONFIG_PINCTRL_MT7986) += pinctrl-mt7986.o
+obj-$(CONFIG_PINCTRL_MT7988) += pinctrl-mt7988.o
 obj-$(CONFIG_PINCTRL_MT8512) += pinctrl-mt8512.o
 obj-$(CONFIG_PINCTRL_MT8516) += pinctrl-mt8516.o
 obj-$(CONFIG_PINCTRL_MT8518) += pinctrl-mt8518.o
drivers/pinctrl/mediatek/pinctrl-mt7988.c new file +1274 -0

1,274 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#21 lore raw

PATCH 17/29 net: mediatek: optimize the switch reset delay wait time

In reply to Weijie Gao

Not all switches requires 1 second delay after deasserting reset. MT7531 requires only maximum 200ms.

This patch defines dedicated reset wait time for each switch chip, and will significantly improve the boot time for boards using MT7531.

---
 drivers/net/mtk_eth.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/net/mtk_eth.c +5 -2
index 90f1d2591b..cd72070ff6 100644
@@ -127,6 +127,7 @@ struct mtk_eth_priv {
 	u32 mt753x_smi_addr;
 	u32 mt753x_phy_base;
 	u32 mt753x_pmcr;
+	u32 mt753x_reset_wait_time;
 
 	struct gpio_desc rst_gpio;
 	int mcm;
@@ -943,12 +944,12 @@ int mt753x_switch_init(struct mtk_eth_priv *priv)
 		reset_assert(&priv->rst_mcm);
 		udelay(1000);
 		reset_deassert(&priv->rst_mcm);
-		mdelay(1000);
+		mdelay(priv->mt753x_reset_wait_time);
 	} else if (dm_gpio_is_valid(&priv->rst_gpio)) {
 		dm_gpio_set_value(&priv->rst_gpio, 0);
 		udelay(1000);
 		dm_gpio_set_value(&priv->rst_gpio, 1);
-		mdelay(1000);
+		mdelay(priv->mt753x_reset_wait_time);
 	}
 
 	ret = priv->switch_init(priv);
@@ -1528,11 +1529,13 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 			priv->switch_init = mt7530_setup;
 			priv->switch_mac_control = mt7530_mac_control;
 			priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
+			priv->mt753x_reset_wait_time = 1000;
 		} else if (!strcmp(str, "mt7531")) {
 			priv->sw = SW_MT7531;
 			priv->switch_init = mt7531_setup;
 			priv->switch_mac_control = mt7531_mac_control;
 			priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
+			priv->mt753x_reset_wait_time = 200;
 		} else {
 			printf("error: unsupported switch\n");
 			return -EINVAL;
Signature · 1 line
2.17.1
author
#20 lore raw

PATCH 16/29 net: mediatek: connect switch to PSE only when starting eth is requested

In reply to Weijie Gao

So far the switch is initialized in probe stage and is connected to PSE unconditionally. This will cause all packets being flooded to PSE and may cause PSE hang before entering linux.

This patch changes the connection between switch and PSE:
- Still initialize switch in probe stage, but disconnect it with PSE
- Connect switch with PSE on eth start
- Disconnect on eth stop

---
 drivers/net/mtk_eth.c | 44 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 3 deletions(-)
drivers/net/mtk_eth.c +41 -3
index 4c9fb266c7..90f1d2591b 100644
@@ -123,8 +123,10 @@ struct mtk_eth_priv {
 
 	enum mtk_switch sw;
 	int (*switch_init)(struct mtk_eth_priv *priv);
+	void (*switch_mac_control)(struct mtk_eth_priv *priv, bool enable);
 	u32 mt753x_smi_addr;
 	u32 mt753x_phy_base;
+	u32 mt753x_pmcr;
 
 	struct gpio_desc rst_gpio;
 	int mcm;
@@ -613,6 +615,16 @@ static int mt7530_pad_clk_setup(struct mtk_eth_priv *priv, int mode)
 	return 0;
 }
 
+static void mt7530_mac_control(struct mtk_eth_priv *priv, bool enable)
+{
+	u32 pmcr = FORCE_MODE;
+
+	if (enable)
+		pmcr = priv->mt753x_pmcr;
+
+	mt753x_reg_write(priv, PMCR_REG(6), pmcr);
+}
+
 static int mt7530_setup(struct mtk_eth_priv *priv)
 {
 	u16 phy_addr, phy_val;
@@ -663,11 +675,14 @@ static int mt7530_setup(struct mtk_eth_priv *priv)
 	      FORCE_DPX | FORCE_LINK;
 
 	/* MT7530 Port6: Forced 1000M/FD, FC disabled */
-	mt753x_reg_write(priv, PMCR_REG(6), val);
+	priv->mt753x_pmcr = val;
 
 	/* MT7530 Port5: Forced link down */
 	mt753x_reg_write(priv, PMCR_REG(5), FORCE_MODE);
 
+	/* Keep MAC link down before starting eth */
+	mt753x_reg_write(priv, PMCR_REG(6), FORCE_MODE);
+
 	/* MT7530 Port6: Set to RGMII */
 	mt753x_reg_rmw(priv, MT7530_P6ECR, P6_INTF_MODE_M, P6_INTF_MODE_RGMII);
 
@@ -823,6 +838,17 @@ static void mt7531_phy_setting(struct mtk_eth_priv *priv)
 	}
 }
 
+static void mt7531_mac_control(struct mtk_eth_priv *priv, bool enable)
+{
+	u32 pmcr = FORCE_MODE_LNK;
+
+	if (enable)
+		pmcr = priv->mt753x_pmcr;
+
+	mt753x_reg_write(priv, PMCR_REG(5), pmcr);
+	mt753x_reg_write(priv, PMCR_REG(6), pmcr);
+}
+
 static int mt7531_setup(struct mtk_eth_priv *priv)
 {
 	u16 phy_addr, phy_val;
@@ -882,8 +908,11 @@ static int mt7531_setup(struct mtk_eth_priv *priv)
 	       (SPEED_1000M << FORCE_SPD_S) | FORCE_DPX |
 	       FORCE_LINK;
 
-	mt753x_reg_write(priv, PMCR_REG(5), pmcr);
-	mt753x_reg_write(priv, PMCR_REG(6), pmcr);
+	priv->mt753x_pmcr = pmcr;
+
+	/* Keep MAC link down before starting eth */
+	mt753x_reg_write(priv, PMCR_REG(5), FORCE_MODE_LNK);
+	mt753x_reg_write(priv, PMCR_REG(6), FORCE_MODE_LNK);
 
 	/* Turn on PHYs */
 	for (i = 0; i < MT753X_NUM_PHYS; i++) {
@@ -1227,6 +1256,9 @@ static int mtk_eth_start(struct udevice *dev)
 
 	mtk_eth_fifo_init(priv);
 
+	if (priv->switch_mac_control)
+		priv->switch_mac_control(priv, true);
+
 	/* Start PHY */
 	if (priv->sw == SW_NONE) {
 		ret = mtk_phy_start(priv);
@@ -1245,6 +1277,9 @@ static void mtk_eth_stop(struct udevice *dev)
 {
 	struct mtk_eth_priv *priv = dev_get_priv(dev);
 
+	if (priv->switch_mac_control)
+		priv->switch_mac_control(priv, false);
+
 	mtk_pdma_rmw(priv, PDMA_GLO_CFG_REG,
 		     TX_WB_DDONE | RX_DMA_EN | TX_DMA_EN, 0);
 	udelay(500);
@@ -1484,16 +1519,19 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 	/* check for switch first, otherwise phy will be used */
 	priv->sw = SW_NONE;
 	priv->switch_init = NULL;
+	priv->switch_mac_control = NULL;
 	str = dev_read_string(dev, "mediatek,switch");
 
 	if (str) {
 		if (!strcmp(str, "mt7530")) {
 			priv->sw = SW_MT7530;
 			priv->switch_init = mt7530_setup;
+			priv->switch_mac_control = mt7530_mac_control;
 			priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
 		} else if (!strcmp(str, "mt7531")) {
 			priv->sw = SW_MT7531;
 			priv->switch_init = mt7531_setup;
+			priv->switch_mac_control = mt7531_mac_control;
 			priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
 		} else {
 			printf("error: unsupported switch\n");
Signature · 1 line
2.17.1
author
#22 lore raw

PATCH 18/29 net: mediatek: fix direct MDIO clause 45 access via SoC

In reply to Weijie Gao

The original direct MDIO clause 45 access via SoC is missing the data output. This patch adds it back to ensure MDIO clause 45 can work properly for external PHYs.

---
 drivers/net/mtk_eth.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mtk_eth.c +2 -2
index cd72070ff6..61a1c29e36 100644
@@ -198,7 +198,7 @@ static int mtk_mii_rw(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 data,
 	      (((u32)phy << MDIO_PHY_ADDR_S) & MDIO_PHY_ADDR_M) |
 	      (((u32)reg << MDIO_REG_ADDR_S) & MDIO_REG_ADDR_M);
 
-	if (cmd == MDIO_CMD_WRITE)
+	if (cmd == MDIO_CMD_WRITE || cmd == MDIO_CMD_ADDR)
 		val |= data & MDIO_RW_DATA_M;
 
 	mtk_gmac_write(priv, GMAC_PIAC_REG, val | PHY_ACS_ST);
@@ -210,7 +210,7 @@ static int mtk_mii_rw(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 data,
 		return ret;
 	}
 
-	if (cmd == MDIO_CMD_READ) {
+	if (cmd == MDIO_CMD_READ || cmd == MDIO_CMD_READ_C45) {
 		val = mtk_gmac_read(priv, GMAC_PIAC_REG);
 		return val & MDIO_RW_DATA_M;
 	}
Signature · 1 line
2.17.1
author
#23 lore raw

PATCH 19/29 net: mediatek: add missing static qualifier

In reply to Weijie Gao

mt7531_mmd_ind_read and mt753x_switch_init are defined without static. Since they're not used outside this file, we should add them back.

fixup to add static qualifier

---
 drivers/net/mtk_eth.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/mtk_eth.c +3 -2
index 61a1c29e36..2b4a862695 100644
@@ -436,7 +436,8 @@ static int mt7531_mii_ind_write(struct mtk_eth_priv *priv, u8 phy, u8 reg,
 			     MDIO_ST_C22);
 }
 
-int mt7531_mmd_ind_read(struct mtk_eth_priv *priv, u8 addr, u8 devad, u16 reg)
+static int mt7531_mmd_ind_read(struct mtk_eth_priv *priv, u8 addr, u8 devad,
+			       u16 reg)
 {
 	u8 phy_addr;
 	int ret;
@@ -934,7 +935,7 @@ static int mt7531_setup(struct mtk_eth_priv *priv)
 	return 0;
 }
 
-int mt753x_switch_init(struct mtk_eth_priv *priv)
+static int mt753x_switch_init(struct mtk_eth_priv *priv)
 {
 	int ret;
 	int i;
Signature · 1 line
2.17.1
author
#24 lore raw

PATCH 20/29 net: mediatek: add support for SGMII 1Gbps auto-negotiation mode

In reply to Weijie Gao

Existing SGMII support of mtk-eth is actually a MediaTek-specific 2.5Gbps high-speed SGMII (HSGMII) which does not support auto-negotiation mode.

This patch adds SGMII 1Gbps auto-negotiation mode and rename the existing HSGMII to 2500basex.

---
 drivers/net/mtk_eth.c | 46 +++++++++++++++++++++++++++++++++++++------
 drivers/net/mtk_eth.h |  2 ++
 2 files changed, 42 insertions(+), 6 deletions(-)
drivers/net/mtk_eth.c +40 -6
index 2b4a862695..e0064276d0 100644
@@ -893,7 +893,7 @@ static int mt7531_setup(struct mtk_eth_priv *priv)
 		if (!port5_sgmii)
 			mt7531_port_rgmii_init(priv, 5);
 		break;
-	case PHY_INTERFACE_MODE_SGMII:
+	case PHY_INTERFACE_MODE_2500BASEX:
 		mt7531_port_sgmii_init(priv, 6);
 		if (port5_sgmii)
 			mt7531_port_sgmii_init(priv, 5);
@@ -986,6 +986,7 @@ static void mtk_phy_link_adjust(struct mtk_eth_priv *priv)
 	      (MAC_RX_PKT_LEN_1536 << MAC_RX_PKT_LEN_S) |
 	      MAC_MODE | FORCE_MODE |
 	      MAC_TX_EN | MAC_RX_EN |
+	      DEL_RXFIFO_CLR |
 	      BKOFF_EN | BACKPR_EN;
 
 	switch (priv->phydev->speed) {
@@ -996,6 +997,7 @@ static void mtk_phy_link_adjust(struct mtk_eth_priv *priv)
 		mcr |= (SPEED_100M << FORCE_SPD_S);
 		break;
 	case SPEED_1000:
+	case SPEED_2500:
 		mcr |= (SPEED_1000M << FORCE_SPD_S);
 		break;
 	};
@@ -1048,7 +1050,8 @@ static int mtk_phy_start(struct mtk_eth_priv *priv)
 		return 0;
 	}
 
-	mtk_phy_link_adjust(priv);
+	if (!priv->force_mode)
+		mtk_phy_link_adjust(priv);
 
 	debug("Speed: %d, %s duplex%s\n", phydev->speed,
 	      (phydev->duplex) ? "full" : "half",
@@ -1076,7 +1079,31 @@ static int mtk_phy_probe(struct udevice *dev)
 	return 0;
 }
 
-static void mtk_sgmii_init(struct mtk_eth_priv *priv)
+static void mtk_sgmii_an_init(struct mtk_eth_priv *priv)
+{
+	/* Set SGMII GEN1 speed(1G) */
+	clrsetbits_le32(priv->sgmii_base + priv->soc->ana_rgc3,
+			SGMSYS_SPEED_2500, 0);
+
+	/* Enable SGMII AN */
+	setbits_le32(priv->sgmii_base + SGMSYS_PCS_CONTROL_1,
+		     SGMII_AN_ENABLE);
+
+	/* SGMII AN mode setting */
+	writel(SGMII_AN_MODE, priv->sgmii_base + SGMSYS_SGMII_MODE);
+
+	/* SGMII PN SWAP setting */
+	if (priv->pn_swap) {
+		setbits_le32(priv->sgmii_base + SGMSYS_QPHY_WRAP_CTRL,
+			     SGMII_PN_SWAP_TX_RX);
+	}
+
+	/* Release PHYA power down state */
+	clrsetbits_le32(priv->sgmii_base + SGMSYS_QPHY_PWR_STATE_CTRL,
+			SGMII_PHYA_PWD, 0);
+}
+
+static void mtk_sgmii_force_init(struct mtk_eth_priv *priv)
 {
 	/* Set SGMII GEN2 speed(2.5G) */
 	setbits_le32(priv->sgmii_base + priv->soc->ana_rgc3,
@@ -1111,10 +1138,14 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)
 		ge_mode = GE_MODE_RGMII;
 		break;
 	case PHY_INTERFACE_MODE_SGMII:
+	case PHY_INTERFACE_MODE_2500BASEX:
 		ge_mode = GE_MODE_RGMII;
 		mtk_ethsys_rmw(priv, ETHSYS_SYSCFG0_REG, SYSCFG0_SGMII_SEL_M,
 			       SYSCFG0_SGMII_SEL(priv->gmac_id));
-		mtk_sgmii_init(priv);
+		if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII)
+			mtk_sgmii_an_init(priv);
+		else
+			mtk_sgmii_force_init(priv);
 		break;
 	case PHY_INTERFACE_MODE_MII:
 	case PHY_INTERFACE_MODE_GMII:
@@ -1148,6 +1179,7 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)
 			mcr |= SPEED_100M << FORCE_SPD_S;
 			break;
 		case SPEED_1000:
+		case SPEED_2500:
 			mcr |= SPEED_1000M << FORCE_SPD_S;
 			break;
 		}
@@ -1490,13 +1522,15 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 		priv->duplex = ofnode_read_bool(subnode, "full-duplex");
 
 		if (priv->speed != SPEED_10 && priv->speed != SPEED_100 &&
-		    priv->speed != SPEED_1000) {
+		    priv->speed != SPEED_1000 && priv->speed != SPEED_2500 &&
+		    priv->speed != SPEED_10000) {
 			printf("error: no valid speed set in fixed-link\n");
 			return -EINVAL;
 		}
 	}
 
-	if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII) {
+	if (priv->phy_interface == PHY_INTERFACE_MODE_SGMII ||
+	    priv->phy_interface == PHY_INTERFACE_MODE_2500BASEX) {
 		/* get corresponding sgmii phandle */
 		ret = dev_read_phandle_with_args(dev, "mediatek,sgmiisys",
 						 NULL, 0, 0, &args);
drivers/net/mtk_eth.h +2 -0
index 1382ccbeb2..320266cd82 100644
@@ -69,6 +69,7 @@ enum mkt_eth_capabilities {
 #define SGMII_AN_RESTART		BIT(9)
 
 #define SGMSYS_SGMII_MODE		0x20
+#define SGMII_AN_MODE			0x31120103
 #define SGMII_FORCE_MODE		0x31120019
 
 #define SGMSYS_QPHY_PWR_STATE_CTRL	0xe8
@@ -168,6 +169,7 @@ enum mkt_eth_capabilities {
 #define FORCE_MODE			BIT(15)
 #define MAC_TX_EN			BIT(14)
 #define MAC_RX_EN			BIT(13)
+#define DEL_RXFIFO_CLR			BIT(12)
 #define BKOFF_EN			BIT(9)
 #define BACKPR_EN			BIT(8)
 #define FORCE_RX_FC			BIT(5)
Signature · 1 line
2.17.1
author
#25 lore raw

PATCH 21/29 arm: dts: medaitek: convert gmac link mode to 2500base-x

In reply to Weijie Gao

Now that individual 2.5Gbps SGMII support has been added to mtk-eth, all boards that use 2.5Gbps link with mt7531 must be converted to use "2500base-x" instead of "sgmii".

---
 arch/arm/dts/mt7622-bananapi-bpi-r64.dts | 4 ++--
 arch/arm/dts/mt7622-rfb.dts              | 4 ++--
 arch/arm/dts/mt7629-rfb.dts              | 4 ++--
 arch/arm/dts/mt7981-emmc-rfb.dts         | 4 ++--
 arch/arm/dts/mt7981-rfb.dts              | 4 ++--
 arch/arm/dts/mt7981-sd-rfb.dts           | 4 ++--
 arch/arm/dts/mt7986a-rfb.dts             | 4 ++--
 arch/arm/dts/mt7986a-sd-rfb.dts          | 4 ++--
 arch/arm/dts/mt7986b-rfb.dts             | 4 ++--
 arch/arm/dts/mt7986b-sd-rfb.dts          | 4 ++--
 10 files changed, 20 insertions(+), 20 deletions(-)
arch/arm/dts/mt7622-bananapi-bpi-r64.dts +2 -2
index 7c55744ac7..717baf26d3 100644
@@ -224,12 +224,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 54 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7622-rfb.dts +2 -2
index 886a133e05..321de75ae3 100644
@@ -233,12 +233,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 54 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7629-rfb.dts +2 -2
index 82f6a34162..f347725f2f 100644
@@ -25,12 +25,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 28 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7981-emmc-rfb.dts +2 -2
index a0913c5b7c..9aa7cd8f6e 100644
@@ -46,12 +46,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 39 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7981-rfb.dts +2 -2
index 1dc90ac63f..22a022acb6 100644
@@ -37,12 +37,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 39 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7981-sd-rfb.dts +2 -2
index 05f3fdb5ef..7d70808404 100644
@@ -46,12 +46,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 39 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7986a-rfb.dts +2 -2
index dce85d8277..e5c9be7da8 100644
@@ -55,12 +55,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 5 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7986a-sd-rfb.dts +2 -2
index 7f32607589..4f8fa70ec9 100644
@@ -47,12 +47,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 5 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7986b-rfb.dts +2 -2
index 3349e38a90..8196845a12 100644
@@ -46,12 +46,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 5 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
arch/arm/dts/mt7986b-sd-rfb.dts +2 -2
index 6c9203332b..ec80a2fb71 100644
@@ -47,12 +47,12 @@
 &eth {
 	status = "okay";
 	mediatek,gmac-id = <0>;
-	phy-mode = "sgmii";
+	phy-mode = "2500base-x";
 	mediatek,switch = "mt7531";
 	reset-gpios = <&gpio 5 GPIO_ACTIVE_HIGH>;
 
 	fixed-link {
-		speed = <1000>;
+		speed = <2500>;
 		full-duplex;
 	};
 };
Signature · 1 line
2.17.1
author
#30 lore raw

PATCH 22/29 net: mediatek: add support for GMAC/USB3 PHY mux mode for MT7981

In reply to Weijie Gao

MT7981 has its GMAC2 PHY shared with USB3. To enable GMAC2, mux register must be set to connect the SGMII phy to GMAC2.

---
 drivers/net/mtk_eth.c | 33 ++++++++++++++++++++++++++++++++-
 drivers/net/mtk_eth.h | 16 ++++++++++++++++
 2 files changed, 48 insertions(+), 1 deletion(-)
drivers/net/mtk_eth.c +32 -1
index e0064276d0..064b4a41db 100644
@@ -103,6 +103,8 @@ struct mtk_eth_priv {
 
 	struct regmap *ethsys_regmap;
 
+	struct regmap *infra_regmap;
+
 	struct mii_dev *mdio_bus;
 	int (*mii_read)(struct mtk_eth_priv *priv, u8 phy, u8 reg);
 	int (*mii_write)(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 val);
@@ -186,6 +188,17 @@ static void mtk_ethsys_rmw(struct mtk_eth_priv *priv, u32 reg, u32 clr,
 	regmap_write(priv->ethsys_regmap, reg, val);
 }
 
+static void mtk_infra_rmw(struct mtk_eth_priv *priv, u32 reg, u32 clr,
+			  u32 set)
+{
+	uint val;
+
+	regmap_read(priv->infra_regmap, reg, &val);
+	val &= ~clr;
+	val |= set;
+	regmap_write(priv->infra_regmap, reg, val);
+}
+
 /* Direct MDIO clause 22/45 access via SoC */
 static int mtk_mii_rw(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 data,
 		      u32 cmd, u32 st)
@@ -1139,6 +1152,11 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)
 		break;
 	case PHY_INTERFACE_MODE_SGMII:
 	case PHY_INTERFACE_MODE_2500BASEX:
+		if (MTK_HAS_CAPS(priv->soc->caps, MTK_GMAC2_U3_QPHY)) {
+			mtk_infra_rmw(priv, USB_PHY_SWITCH_REG, QPHY_SEL_MASK,
+				      SGMII_QPHY_SEL);
+		}
+
 		ge_mode = GE_MODE_RGMII;
 		mtk_ethsys_rmw(priv, ETHSYS_SYSCFG0_REG, SYSCFG0_SGMII_SEL_M,
 			       SYSCFG0_SGMII_SEL(priv->gmac_id));
@@ -1497,6 +1515,19 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 	if (IS_ERR(priv->ethsys_regmap))
 		return PTR_ERR(priv->ethsys_regmap);
 
+	if (MTK_HAS_CAPS(priv->soc->caps, MTK_INFRA)) {
+		/* get corresponding infracfg phandle */
+		ret = dev_read_phandle_with_args(dev, "mediatek,infracfg",
+						 NULL, 0, 0, &args);
+
+		if (ret)
+			return ret;
+
+		priv->infra_regmap = syscon_node_to_regmap(args.node);
+		if (IS_ERR(priv->infra_regmap))
+			return PTR_ERR(priv->infra_regmap);
+	}
+
 	/* Reset controllers */
 	ret = reset_get_by_name(dev, "fe", &priv->rst_fe);
 	if (ret) {
@@ -1614,7 +1645,7 @@ static const struct mtk_soc_data mt7986_data = {
 };
 
 static const struct mtk_soc_data mt7981_data = {
-	.caps = MT7986_CAPS,
+	.caps = MT7981_CAPS,
 	.ana_rgc3 = 0x128,
 	.pdma_base = PDMA_V2_BASE,
 	.txd_size = sizeof(struct mtk_tx_dma_v2),
drivers/net/mtk_eth.h +16 -0
index 320266cd82..519986c01e 100644
@@ -15,27 +15,38 @@
 enum mkt_eth_capabilities {
 	MTK_TRGMII_BIT,
 	MTK_TRGMII_MT7621_CLK_BIT,
+	MTK_U3_COPHY_V2_BIT,
+	MTK_INFRA_BIT,
 	MTK_NETSYS_V2_BIT,
 
 	/* PATH BITS */
 	MTK_ETH_PATH_GMAC1_TRGMII_BIT,
+	MTK_ETH_PATH_GMAC2_SGMII_BIT,
 };
 
 #define MTK_TRGMII			BIT(MTK_TRGMII_BIT)
 #define MTK_TRGMII_MT7621_CLK		BIT(MTK_TRGMII_MT7621_CLK_BIT)
+#define MTK_U3_COPHY_V2			BIT(MTK_U3_COPHY_V2_BIT)
+#define MTK_INFRA			BIT(MTK_INFRA_BIT)
 #define MTK_NETSYS_V2			BIT(MTK_NETSYS_V2_BIT)
 
 /* Supported path present on SoCs */
 #define MTK_ETH_PATH_GMAC1_TRGMII	BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
 
+#define MTK_ETH_PATH_GMAC2_SGMII	BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT)
+
 #define MTK_GMAC1_TRGMII	(MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII)
 
+#define MTK_GMAC2_U3_QPHY	(MTK_ETH_PATH_GMAC2_SGMII | MTK_U3_COPHY_V2 | MTK_INFRA)
+
 #define MTK_HAS_CAPS(caps, _x)		(((caps) & (_x)) == (_x))
 
 #define MT7621_CAPS  (MTK_GMAC1_TRGMII | MTK_TRGMII_MT7621_CLK)
 
 #define MT7623_CAPS  (MTK_GMAC1_TRGMII)
 
+#define MT7981_CAPS  (MTK_GMAC2_U3_QPHY | MTK_NETSYS_V2)
+
 #define MT7986_CAPS  (MTK_NETSYS_V2)
 
 /* Frame Engine Register Bases */
@@ -56,6 +67,11 @@ enum mkt_eth_capabilities {
 #define ETHSYS_CLKCFG0_REG		0x2c
 #define ETHSYS_TRGMII_CLK_SEL362_5	BIT(11)
 
+/* Top misc registers */
+#define USB_PHY_SWITCH_REG		0x218
+#define QPHY_SEL_MASK			0x3
+#define SGMII_QPHY_SEL			0x2
+
 /* SYSCFG0_GE_MODE: GE Modes */
 #define GE_MODE_RGMII			0
 #define GE_MODE_MII			1
Signature · 1 line
2.17.1
author
#31 lore raw

PATCH 23/29 arm: dts: mediatek: add infracfg registers to support GMAC/USB3 Co-PHY

In reply to Weijie Gao

This patch adds infracfg to eth node to support enabling GMAC2.

---
 arch/arm/dts/mt7981.dtsi | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/dts/mt7981.dtsi +7 -0
index 2053e2ca00..7aaa7770f8 100644
@@ -237,6 +237,7 @@
 		reset-names = "fe";
 		mediatek,ethsys = <&ethsys>;
 		mediatek,sgmiisys = <&sgmiisys0>;
+		mediatek,infracfg = <&topmisc>;
 		#address-cells = <1>;
 		#size-cells = <0>;
 		status = "disabled";
@@ -255,6 +256,12 @@
 		#clock-cells = <1>;
 	};
 
+	topmisc: topmisc@11d10000 {
+		compatible = "mediatek,mt7981-topmisc", "syscon";
+		reg = <0x11d10000 0x10000>;
+		#clock-cells = <1>;
+	};
+
 	spi0: spi@1100a000 {
 		compatible = "mediatek,ipm-spi";
 		reg = <0x1100a000 0x100>;
Signature · 1 line
2.17.1
author
#32 lore raw

PATCH 24/29 net: mediatek: add USXGMII support

In reply to Weijie Gao

This patch adds support for USXGMII of SoC.

---
 drivers/net/mtk_eth.c | 230 +++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mtk_eth.h |  24 +++++
 2 files changed, 251 insertions(+), 3 deletions(-)
drivers/net/mtk_eth.c +227 -3
index 064b4a41db..c99ab5dbea 100644
@@ -105,6 +105,11 @@ struct mtk_eth_priv {
 
 	struct regmap *infra_regmap;
 
+	struct regmap *usxgmii_regmap;
+	struct regmap *xfi_pextp_regmap;
+	struct regmap *xfi_pll_regmap;
+	struct regmap *toprgu_regmap;
+
 	struct mii_dev *mdio_bus;
 	int (*mii_read)(struct mtk_eth_priv *priv, u8 phy, u8 reg);
 	int (*mii_write)(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 val);
@@ -989,6 +994,42 @@ static int mt753x_switch_init(struct mtk_eth_priv *priv)
 	return 0;
 }
 
+static void mtk_xphy_link_adjust(struct mtk_eth_priv *priv)
+{
+	u16 lcl_adv = 0, rmt_adv = 0;
+	u8 flowctrl;
+	u32 mcr;
+
+	mcr = mtk_gmac_read(priv, XGMAC_PORT_MCR(priv->gmac_id));
+	mcr &= ~(XGMAC_FORCE_TX_FC | XGMAC_FORCE_RX_FC);
+
+	if (priv->phydev->duplex) {
+		if (priv->phydev->pause)
+			rmt_adv = LPA_PAUSE_CAP;
+		if (priv->phydev->asym_pause)
+			rmt_adv |= LPA_PAUSE_ASYM;
+
+		if (priv->phydev->advertising & ADVERTISED_Pause)
+			lcl_adv |= ADVERTISE_PAUSE_CAP;
+		if (priv->phydev->advertising & ADVERTISED_Asym_Pause)
+			lcl_adv |= ADVERTISE_PAUSE_ASYM;
+
+		flowctrl = mii_resolve_flowctrl_fdx(lcl_adv, rmt_adv);
+
+		if (flowctrl & FLOW_CTRL_TX)
+			mcr |= XGMAC_FORCE_TX_FC;
+		if (flowctrl & FLOW_CTRL_RX)
+			mcr |= XGMAC_FORCE_RX_FC;
+
+		debug("rx pause %s, tx pause %s\n",
+		      flowctrl & FLOW_CTRL_RX ? "enabled" : "disabled",
+		      flowctrl & FLOW_CTRL_TX ? "enabled" : "disabled");
+	}
+
+	mcr &= ~(XGMAC_TRX_DISABLE);
+	mtk_gmac_write(priv, XGMAC_PORT_MCR(priv->gmac_id), mcr);
+}
+
 static void mtk_phy_link_adjust(struct mtk_eth_priv *priv)
 {
 	u16 lcl_adv = 0, rmt_adv = 0;
@@ -1063,8 +1104,12 @@ static int mtk_phy_start(struct mtk_eth_priv *priv)
 		return 0;
 	}
 
-	if (!priv->force_mode)
-		mtk_phy_link_adjust(priv);
+	if (!priv->force_mode) {
+		if (priv->phy_interface == PHY_INTERFACE_MODE_USXGMII)
+			mtk_xphy_link_adjust(priv);
+		else
+			mtk_phy_link_adjust(priv);
+	}
 
 	debug("Speed: %d, %s duplex%s\n", phydev->speed,
 	      (phydev->duplex) ? "full" : "half",
@@ -1140,6 +1185,112 @@ static void mtk_sgmii_force_init(struct mtk_eth_priv *priv)
 			SGMII_PHYA_PWD, 0);
 }
 
+static void mtk_xfi_pll_enable(struct mtk_eth_priv *priv)
+{
+	u32 val = 0;
+
+	/* Add software workaround for USXGMII PLL TCL issue */
+	regmap_write(priv->xfi_pll_regmap, XFI_PLL_ANA_GLB8,
+		     RG_XFI_PLL_ANA_SWWA);
+
+	regmap_read(priv->xfi_pll_regmap, XFI_PLL_DIG_GLB8, &val);
+	val |= RG_XFI_PLL_EN;
+	regmap_write(priv->xfi_pll_regmap, XFI_PLL_DIG_GLB8, val);
+}
+
+static void mtk_usxgmii_reset(struct mtk_eth_priv *priv)
+{
+	switch (priv->gmac_id) {
+	case 1:
+		regmap_write(priv->toprgu_regmap, 0xFC, 0x0000A004);
+		regmap_write(priv->toprgu_regmap, 0x18, 0x88F0A004);
+		regmap_write(priv->toprgu_regmap, 0xFC, 0x00000000);
+		regmap_write(priv->toprgu_regmap, 0x18, 0x88F00000);
+		regmap_write(priv->toprgu_regmap, 0x18, 0x00F00000);
+		break;
+	case 2:
+		regmap_write(priv->toprgu_regmap, 0xFC, 0x00005002);
+		regmap_write(priv->toprgu_regmap, 0x18, 0x88F05002);
+		regmap_write(priv->toprgu_regmap, 0xFC, 0x00000000);
+		regmap_write(priv->toprgu_regmap, 0x18, 0x88F00000);
+		regmap_write(priv->toprgu_regmap, 0x18, 0x00F00000);
+		break;
+	}
+
+	mdelay(10);
+}
+
+static void mtk_usxgmii_setup_phya_an_10000(struct mtk_eth_priv *priv)
+{
+	regmap_write(priv->usxgmii_regmap, 0x810, 0x000FFE6D);
+	regmap_write(priv->usxgmii_regmap, 0x818, 0x07B1EC7B);
+	regmap_write(priv->usxgmii_regmap, 0x80C, 0x30000000);
+	ndelay(1020);
+	regmap_write(priv->usxgmii_regmap, 0x80C, 0x10000000);
+	ndelay(1020);
+	regmap_write(priv->usxgmii_regmap, 0x80C, 0x00000000);
+
+	regmap_write(priv->xfi_pextp_regmap, 0x9024, 0x00C9071C);
+	regmap_write(priv->xfi_pextp_regmap, 0x2020, 0xAA8585AA);
+	regmap_write(priv->xfi_pextp_regmap, 0x2030, 0x0C020707);
+	regmap_write(priv->xfi_pextp_regmap, 0x2034, 0x0E050F0F);
+	regmap_write(priv->xfi_pextp_regmap, 0x2040, 0x00140032);
+	regmap_write(priv->xfi_pextp_regmap, 0x50F0, 0x00C014AA);
+	regmap_write(priv->xfi_pextp_regmap, 0x50E0, 0x3777C12B);
+	regmap_write(priv->xfi_pextp_regmap, 0x506C, 0x005F9CFF);
+	regmap_write(priv->xfi_pextp_regmap, 0x5070, 0x9D9DFAFA);
+	regmap_write(priv->xfi_pextp_regmap, 0x5074, 0x27273F3F);
+	regmap_write(priv->xfi_pextp_regmap, 0x5078, 0xA7883C68);
+	regmap_write(priv->xfi_pextp_regmap, 0x507C, 0x11661166);
+	regmap_write(priv->xfi_pextp_regmap, 0x5080, 0x0E000AAF);
+	regmap_write(priv->xfi_pextp_regmap, 0x5084, 0x08080D0D);
+	regmap_write(priv->xfi_pextp_regmap, 0x5088, 0x02030909);
+	regmap_write(priv->xfi_pextp_regmap, 0x50E4, 0x0C0C0000);
+	regmap_write(priv->xfi_pextp_regmap, 0x50E8, 0x04040000);
+	regmap_write(priv->xfi_pextp_regmap, 0x50EC, 0x0F0F0C06);
+	regmap_write(priv->xfi_pextp_regmap, 0x50A8, 0x506E8C8C);
+	regmap_write(priv->xfi_pextp_regmap, 0x6004, 0x18190000);
+	regmap_write(priv->xfi_pextp_regmap, 0x00F8, 0x01423342);
+	regmap_write(priv->xfi_pextp_regmap, 0x00F4, 0x80201F20);
+	regmap_write(priv->xfi_pextp_regmap, 0x0030, 0x00050C00);
+	regmap_write(priv->xfi_pextp_regmap, 0x0070, 0x02002800);
+	ndelay(1020);
+	regmap_write(priv->xfi_pextp_regmap, 0x30B0, 0x00000020);
+	regmap_write(priv->xfi_pextp_regmap, 0x3028, 0x00008A01);
+	regmap_write(priv->xfi_pextp_regmap, 0x302C, 0x0000A884);
+	regmap_write(priv->xfi_pextp_regmap, 0x3024, 0x00083002);
+	regmap_write(priv->xfi_pextp_regmap, 0x3010, 0x00022220);
+	regmap_write(priv->xfi_pextp_regmap, 0x5064, 0x0F020A01);
+	regmap_write(priv->xfi_pextp_regmap, 0x50B4, 0x06100600);
+	regmap_write(priv->xfi_pextp_regmap, 0x3048, 0x40704000);
+	regmap_write(priv->xfi_pextp_regmap, 0x3050, 0xA8000000);
+	regmap_write(priv->xfi_pextp_regmap, 0x3054, 0x000000AA);
+	regmap_write(priv->xfi_pextp_regmap, 0x306C, 0x00000F00);
+	regmap_write(priv->xfi_pextp_regmap, 0xA060, 0x00040000);
+	regmap_write(priv->xfi_pextp_regmap, 0x90D0, 0x00000001);
+	regmap_write(priv->xfi_pextp_regmap, 0x0070, 0x0200E800);
+	udelay(150);
+	regmap_write(priv->xfi_pextp_regmap, 0x0070, 0x0200C111);
+	ndelay(1020);
+	regmap_write(priv->xfi_pextp_regmap, 0x0070, 0x0200C101);
+	udelay(15);
+	regmap_write(priv->xfi_pextp_regmap, 0x0070, 0x0202C111);
+	ndelay(1020);
+	regmap_write(priv->xfi_pextp_regmap, 0x0070, 0x0202C101);
+	udelay(100);
+	regmap_write(priv->xfi_pextp_regmap, 0x30B0, 0x00000030);
+	regmap_write(priv->xfi_pextp_regmap, 0x00F4, 0x80201F00);
+	regmap_write(priv->xfi_pextp_regmap, 0x3040, 0x30000000);
+	udelay(400);
+}
+
+static void mtk_usxgmii_an_init(struct mtk_eth_priv *priv)
+{
+	mtk_xfi_pll_enable(priv);
+	mtk_usxgmii_reset(priv);
+	mtk_usxgmii_setup_phya_an_10000(priv);
+}
+
 static void mtk_mac_init(struct mtk_eth_priv *priv)
 {
 	int i, ge_mode = 0;
@@ -1222,6 +1373,36 @@ static void mtk_mac_init(struct mtk_eth_priv *priv)
 	}
 }
 
+static void mtk_xmac_init(struct mtk_eth_priv *priv)
+{
+	u32 sts;
+
+	switch (priv->phy_interface) {
+	case PHY_INTERFACE_MODE_USXGMII:
+		mtk_usxgmii_an_init(priv);
+		break;
+	default:
+		break;
+	}
+
+	/* Set GMAC to the correct mode */
+	mtk_ethsys_rmw(priv, ETHSYS_SYSCFG0_REG,
+		       SYSCFG0_GE_MODE_M << SYSCFG0_GE_MODE_S(priv->gmac_id),
+		       0);
+
+	if (priv->gmac_id == 1) {
+		mtk_infra_rmw(priv, TOPMISC_NETSYS_PCS_MUX,
+			      NETSYS_PCS_MUX_MASK, MUX_G2_USXGMII_SEL);
+	} else if (priv->gmac_id == 2) {
+		sts = mtk_gmac_read(priv, XGMAC_STS(priv->gmac_id));
+		sts |= XGMAC_FORCE_LINK;
+		mtk_gmac_write(priv, XGMAC_STS(priv->gmac_id), sts);
+	}
+
+	/* Force GMAC link down */
+	mtk_gmac_write(priv, GMAC_PORT_MCR(priv->gmac_id), FORCE_MODE);
+}
+
 static void mtk_eth_fifo_init(struct mtk_eth_priv *priv)
 {
 	char *pkt_base = priv->pkt_pool;
@@ -1463,7 +1644,10 @@ static int mtk_eth_probe(struct udevice *dev)
 				ARCH_DMA_MINALIGN);
 
 	/* Set MAC mode */
-	mtk_mac_init(priv);
+	if (priv->phy_interface == PHY_INTERFACE_MODE_USXGMII)
+		mtk_xmac_init(priv);
+	else
+		mtk_mac_init(priv);
 
 	/* Probe phy if switch is not specified */
 	if (priv->sw == SW_NONE)
@@ -1581,6 +1765,46 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 		}
 
 		priv->pn_swap = ofnode_read_bool(args.node, "pn_swap");
+	} else if (priv->phy_interface == PHY_INTERFACE_MODE_USXGMII) {
+		/* get corresponding usxgmii phandle */
+		ret = dev_read_phandle_with_args(dev, "mediatek,usxgmiisys",
+						 NULL, 0, 0, &args);
+		if (ret)
+			return ret;
+
+		priv->usxgmii_regmap = syscon_node_to_regmap(args.node);
+		if (IS_ERR(priv->usxgmii_regmap))
+			return PTR_ERR(priv->usxgmii_regmap);
+
+		/* get corresponding xfi_pextp phandle */
+		ret = dev_read_phandle_with_args(dev, "mediatek,xfi_pextp",
+						 NULL, 0, 0, &args);
+		if (ret)
+			return ret;
+
+		priv->xfi_pextp_regmap = syscon_node_to_regmap(args.node);
+		if (IS_ERR(priv->xfi_pextp_regmap))
+			return PTR_ERR(priv->xfi_pextp_regmap);
+
+		/* get corresponding xfi_pll phandle */
+		ret = dev_read_phandle_with_args(dev, "mediatek,xfi_pll",
+						 NULL, 0, 0, &args);
+		if (ret)
+			return ret;
+
+		priv->xfi_pll_regmap = syscon_node_to_regmap(args.node);
+		if (IS_ERR(priv->xfi_pll_regmap))
+			return PTR_ERR(priv->xfi_pll_regmap);
+
+		/* get corresponding toprgu phandle */
+		ret = dev_read_phandle_with_args(dev, "mediatek,toprgu",
+						 NULL, 0, 0, &args);
+		if (ret)
+			return ret;
+
+		priv->toprgu_regmap = syscon_node_to_regmap(args.node);
+		if (IS_ERR(priv->toprgu_regmap))
+			return PTR_ERR(priv->toprgu_regmap);
 	}
 
 	/* check for switch first, otherwise phy will be used */
drivers/net/mtk_eth.h +24 -0
index 519986c01e..4c2a7a8b40 100644
@@ -68,6 +68,11 @@ enum mkt_eth_capabilities {
 #define ETHSYS_TRGMII_CLK_SEL362_5	BIT(11)
 
 /* Top misc registers */
+#define TOPMISC_NETSYS_PCS_MUX		0x84
+#define NETSYS_PCS_MUX_MASK		GENMASK(1, 0)
+#define MUX_G2_USXGMII_SEL		BIT(1)
+#define MUX_HSGMII1_G1_SEL		BIT(0)
+
 #define USB_PHY_SWITCH_REG		0x218
 #define QPHY_SEL_MASK			0x3
 #define SGMII_QPHY_SEL			0x2
@@ -98,6 +103,15 @@ enum mkt_eth_capabilities {
 #define SGMSYS_GEN2_SPEED_V2		0x128
 #define SGMSYS_SPEED_2500		BIT(2)
 
+/* USXGMII subsystem config registers */
+/* Register to control USXGMII XFI PLL digital */
+#define XFI_PLL_DIG_GLB8		0x08
+#define RG_XFI_PLL_EN			BIT(31)
+
+/* Register to control USXGMII XFI PLL analog */
+#define XFI_PLL_ANA_GLB8		0x108
+#define RG_XFI_PLL_ANA_SWWA		0x02283248
+
 /* Frame Engine Registers */
 #define FE_GLO_MISC_REG			0x124
 #define PDMA_VER_V2			BIT(4)
@@ -221,6 +235,16 @@ enum mkt_eth_capabilities {
 #define TD_DM_DRVP_S			0
 #define TD_DM_DRVP_M			0x0f
 
+/* XGMAC Status Registers */
+#define XGMAC_STS(x)			(((x) == 2) ? 0x001C : 0x000C)
+#define XGMAC_FORCE_LINK		BIT(15)
+
+/* XGMAC Registers */
+#define XGMAC_PORT_MCR(x)		(0x2000 + (((x) - 1) * 0x1000))
+#define XGMAC_TRX_DISABLE		0xf
+#define XGMAC_FORCE_TX_FC		BIT(5)
+#define XGMAC_FORCE_RX_FC		BIT(4)
+
 /* MT7530 Registers */
 
 #define PCR_REG(p)			(0x2004 + (p) * 0x100)
Signature · 1 line
2.17.1
author
#33 lore raw

PATCH 25/29 net: mediatek: add support for NETSYS v3

In reply to Weijie Gao

This patch adds support for NETSYS v3 hardware. Comparing to NETSYS v2, NETSYS v3 has three GMACs.

---
 drivers/net/mtk_eth.c | 49 ++++++++++++++++++++++++++++++++-----------
 drivers/net/mtk_eth.h |  7 +++++++
 2 files changed, 44 insertions(+), 12 deletions(-)
drivers/net/mtk_eth.c +37 -12
index c99ab5dbea..e0dc180e3c 100644
@@ -76,6 +76,7 @@ enum mtk_switch {
  * @caps			Flags shown the extra capability for the SoC
  * @ana_rgc3:			The offset for register ANA_RGC3 related to
  *				sgmiisys syscon
+ * @gdma_count:			Number of GDMAs
  * @pdma_base:			Register base of PDMA block
  * @txd_size:			Tx DMA descriptor size.
  * @rxd_size:			Rx DMA descriptor size.
@@ -83,6 +84,7 @@ enum mtk_switch {
 struct mtk_soc_data {
 	u32 caps;
 	u32 ana_rgc3;
+	u32 gdma_count;
 	u32 pdma_base;
 	u32 txd_size;
 	u32 rxd_size;
@@ -159,7 +161,9 @@ static void mtk_gdma_write(struct mtk_eth_priv *priv, int no, u32 reg,
 {
 	u32 gdma_base;
 
-	if (no == 1)
+	if (no == 2)
+		gdma_base = GDMA3_BASE;
+	else if (no == 1)
 		gdma_base = GDMA2_BASE;
 	else
 		gdma_base = GDMA1_BASE;
@@ -1429,7 +1433,10 @@ static void mtk_eth_fifo_init(struct mtk_eth_priv *priv)
 		txd->txd1 = virt_to_phys(pkt_base);
 		txd->txd2 = PDMA_TXD2_DDONE | PDMA_TXD2_LS0;
 
-		if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2))
+		if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3))
+			txd->txd5 = PDMA_V2_TXD5_FPORT_SET(priv->gmac_id == 2 ?
+							   15 : priv->gmac_id + 1);
+		else if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2))
 			txd->txd5 = PDMA_V2_TXD5_FPORT_SET(priv->gmac_id + 1);
 		else
 			txd->txd4 = PDMA_V1_TXD4_FPORT_SET(priv->gmac_id + 1);
@@ -1442,7 +1449,8 @@ static void mtk_eth_fifo_init(struct mtk_eth_priv *priv)
 
 		rxd->rxd1 = virt_to_phys(pkt_base);
 
-		if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2))
+		if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2) ||
+		    MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3))
 			rxd->rxd2 = PDMA_V2_RXD2_PLEN0_SET(PKTSIZE_ALIGN);
 		else
 			rxd->rxd2 = PDMA_V1_RXD2_PLEN0_SET(PKTSIZE_ALIGN);
@@ -1466,7 +1474,7 @@ static void mtk_eth_fifo_init(struct mtk_eth_priv *priv)
 static int mtk_eth_start(struct udevice *dev)
 {
 	struct mtk_eth_priv *priv = dev_get_priv(dev);
-	int ret;
+	int i, ret;
 
 	/* Reset FE */
 	reset_assert(&priv->rst_fe);
@@ -1474,16 +1482,24 @@ static int mtk_eth_start(struct udevice *dev)
 	reset_deassert(&priv->rst_fe);
 	mdelay(10);
 
-	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2))
+	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2) ||
+	    MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3))
 		setbits_le32(priv->fe_base + FE_GLO_MISC_REG, PDMA_VER_V2);
 
 	/* Packets forward to PDMA */
 	mtk_gdma_write(priv, priv->gmac_id, GDMA_IG_CTRL_REG, GDMA_FWD_TO_CPU);
 
-	if (priv->gmac_id == 0)
-		mtk_gdma_write(priv, 1, GDMA_IG_CTRL_REG, GDMA_FWD_DISCARD);
-	else
-		mtk_gdma_write(priv, 0, GDMA_IG_CTRL_REG, GDMA_FWD_DISCARD);
+	for (i = 0; i < priv->soc->gdma_count; i++) {
+		if (i == priv->gmac_id)
+			continue;
+
+		mtk_gdma_write(priv, i, GDMA_IG_CTRL_REG, GDMA_FWD_DISCARD);
+	}
+
+	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3)) {
+		mtk_gdma_write(priv, priv->gmac_id, GDMA_EG_CTRL_REG,
+			       GDMA_CPU_BRIDGE_EN);
+	}
 
 	udelay(500);
 
@@ -1557,7 +1573,8 @@ static int mtk_eth_send(struct udevice *dev, void *packet, int length)
 	flush_dcache_range((ulong)pkt_base, (ulong)pkt_base +
 			   roundup(length, ARCH_DMA_MINALIGN));
 
-	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2))
+	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2) ||
+	    MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3))
 		txd->txd2 = PDMA_TXD2_LS0 | PDMA_V2_TXD2_SDL0_SET(length);
 	else
 		txd->txd2 = PDMA_TXD2_LS0 | PDMA_V1_TXD2_SDL0_SET(length);
@@ -1583,7 +1600,8 @@ static int mtk_eth_recv(struct udevice *dev, int flags, uchar **packetp)
 		return -EAGAIN;
 	}
 
-	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2))
+	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2) ||
+	    MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3))
 		length = PDMA_V2_RXD2_PLEN0_GET(rxd->rxd2);
 	else
 		length = PDMA_V1_RXD2_PLEN0_GET(rxd->rxd2);
@@ -1606,7 +1624,8 @@ static int mtk_eth_free_pkt(struct udevice *dev, uchar *packet, int length)
 
 	rxd = priv->rx_ring_noc + idx * priv->soc->rxd_size;
 
-	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2))
+	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V2) ||
+	    MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3))
 		rxd->rxd2 = PDMA_V2_RXD2_PLEN0_SET(PKTSIZE_ALIGN);
 	else
 		rxd->rxd2 = PDMA_V1_RXD2_PLEN0_SET(PKTSIZE_ALIGN);
@@ -1863,6 +1882,7 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 static const struct mtk_soc_data mt7986_data = {
 	.caps = MT7986_CAPS,
 	.ana_rgc3 = 0x128,
+	.gdma_count = 2,
 	.pdma_base = PDMA_V2_BASE,
 	.txd_size = sizeof(struct mtk_tx_dma_v2),
 	.rxd_size = sizeof(struct mtk_rx_dma_v2),
@@ -1871,6 +1891,7 @@ static const struct mtk_soc_data mt7986_data = {
 static const struct mtk_soc_data mt7981_data = {
 	.caps = MT7981_CAPS,
 	.ana_rgc3 = 0x128,
+	.gdma_count = 2,
 	.pdma_base = PDMA_V2_BASE,
 	.txd_size = sizeof(struct mtk_tx_dma_v2),
 	.rxd_size = sizeof(struct mtk_rx_dma_v2),
@@ -1878,6 +1899,7 @@ static const struct mtk_soc_data mt7981_data = {
 
 static const struct mtk_soc_data mt7629_data = {
 	.ana_rgc3 = 0x128,
+	.gdma_count = 2,
 	.pdma_base = PDMA_V1_BASE,
 	.txd_size = sizeof(struct mtk_tx_dma),
 	.rxd_size = sizeof(struct mtk_rx_dma),
@@ -1885,6 +1907,7 @@ static const struct mtk_soc_data mt7629_data = {
 
 static const struct mtk_soc_data mt7623_data = {
 	.caps = MT7623_CAPS,
+	.gdma_count = 2,
 	.pdma_base = PDMA_V1_BASE,
 	.txd_size = sizeof(struct mtk_tx_dma),
 	.rxd_size = sizeof(struct mtk_rx_dma),
@@ -1892,6 +1915,7 @@ static const struct mtk_soc_data mt7623_data = {
 
 static const struct mtk_soc_data mt7622_data = {
 	.ana_rgc3 = 0x2028,
+	.gdma_count = 2,
 	.pdma_base = PDMA_V1_BASE,
 	.txd_size = sizeof(struct mtk_tx_dma),
 	.rxd_size = sizeof(struct mtk_rx_dma),
@@ -1899,6 +1923,7 @@ static const struct mtk_soc_data mt7622_data = {
 
 static const struct mtk_soc_data mt7621_data = {
 	.caps = MT7621_CAPS,
+	.gdma_count = 2,
 	.pdma_base = PDMA_V1_BASE,
 	.txd_size = sizeof(struct mtk_tx_dma),
 	.rxd_size = sizeof(struct mtk_rx_dma),
drivers/net/mtk_eth.h +7 -0
index 4c2a7a8b40..5e628e0cb7 100644
@@ -18,6 +18,7 @@ enum mkt_eth_capabilities {
 	MTK_U3_COPHY_V2_BIT,
 	MTK_INFRA_BIT,
 	MTK_NETSYS_V2_BIT,
+	MTK_NETSYS_V3_BIT,
 
 	/* PATH BITS */
 	MTK_ETH_PATH_GMAC1_TRGMII_BIT,
@@ -29,6 +30,7 @@ enum mkt_eth_capabilities {
 #define MTK_U3_COPHY_V2			BIT(MTK_U3_COPHY_V2_BIT)
 #define MTK_INFRA			BIT(MTK_INFRA_BIT)
 #define MTK_NETSYS_V2			BIT(MTK_NETSYS_V2_BIT)
+#define MTK_NETSYS_V3			BIT(MTK_NETSYS_V3_BIT)
 
 /* Supported path present on SoCs */
 #define MTK_ETH_PATH_GMAC1_TRGMII	BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT)
@@ -52,8 +54,10 @@ enum mkt_eth_capabilities {
 /* Frame Engine Register Bases */
 #define PDMA_V1_BASE			0x0800
 #define PDMA_V2_BASE			0x6000
+#define PDMA_V3_BASE			0x6800
 #define GDMA1_BASE			0x0500
 #define GDMA2_BASE			0x1500
+#define GDMA3_BASE			0x0540
 #define GMAC_BASE			0x10000
 
 /* Ethernet subsystem registers */
@@ -153,6 +157,9 @@ enum mkt_eth_capabilities {
 #define UN_DP_S				0
 #define UN_DP_M				0x0f
 
+#define GDMA_EG_CTRL_REG		0x004
+#define GDMA_CPU_BRIDGE_EN		BIT(31)
+
 #define GDMA_MAC_LSB_REG		0x008
 
 #define GDMA_MAC_MSB_REG		0x00c
Signature · 1 line
2.17.1
author
#34 lore raw

PATCH 26/29 net: mediatek: add support for MediaTek MT7988 SoC

In reply to Weijie Gao

This patch adds support for MediaTek MT7988.

MT7988 features MediaTek NETSYS v3, including three GMACs, and two of them supports 10Gbps USXGMII.

MT7988 embeds a MT7531 switch (not MCM) which supports accessing internal registers through MMIO instead of MDIO.

---
 drivers/net/mtk_eth.c | 158 +++++++++++++++++++++++++++++++++++++++++-
 drivers/net/mtk_eth.h |  20 ++++++
 2 files changed, 177 insertions(+), 1 deletion(-)
drivers/net/mtk_eth.c +157 -1
index e0dc180e3c..d4111e73df 100644
@@ -54,6 +54,16 @@
 	(DP_PDMA << MC_DP_S) | \
 	(DP_PDMA << UN_DP_S))
 
+#define GDMA_BRIDGE_TO_CPU \
+	(0xC0000000 | \
+	GDM_ICS_EN | \
+	GDM_TCS_EN | \
+	GDM_UCS_EN | \
+	(DP_PDMA << MYMAC_DP_S) | \
+	(DP_PDMA << BC_DP_S) | \
+	(DP_PDMA << MC_DP_S) | \
+	(DP_PDMA << UN_DP_S))
+
 #define GDMA_FWD_DISCARD \
 	(0x20000000 | \
 	GDM_ICS_EN | \
@@ -68,7 +78,8 @@
 enum mtk_switch {
 	SW_NONE,
 	SW_MT7530,
-	SW_MT7531
+	SW_MT7531,
+	SW_MT7988,
 };
 
 /* struct mtk_soc_data -	This is the structure holding all differences
@@ -102,6 +113,7 @@ struct mtk_eth_priv {
 	void __iomem *fe_base;
 	void __iomem *gmac_base;
 	void __iomem *sgmii_base;
+	void __iomem *gsw_base;
 
 	struct regmap *ethsys_regmap;
 
@@ -171,6 +183,11 @@ static void mtk_gdma_write(struct mtk_eth_priv *priv, int no, u32 reg,
 	writel(val, priv->fe_base + gdma_base + reg);
 }
 
+static void mtk_fe_rmw(struct mtk_eth_priv *priv, u32 reg, u32 clr, u32 set)
+{
+	clrsetbits_le32(priv->fe_base + reg, clr, set);
+}
+
 static u32 mtk_gmac_read(struct mtk_eth_priv *priv, u32 reg)
 {
 	return readl(priv->gmac_base + reg);
@@ -208,6 +225,16 @@ static void mtk_infra_rmw(struct mtk_eth_priv *priv, u32 reg, u32 clr,
 	regmap_write(priv->infra_regmap, reg, val);
 }
 
+static u32 mtk_gsw_read(struct mtk_eth_priv *priv, u32 reg)
+{
+	return readl(priv->gsw_base + reg);
+}
+
+static void mtk_gsw_write(struct mtk_eth_priv *priv, u32 reg, u32 val)
+{
+	writel(val, priv->gsw_base + reg);
+}
+
 /* Direct MDIO clause 22/45 access via SoC */
 static int mtk_mii_rw(struct mtk_eth_priv *priv, u8 phy, u8 reg, u16 data,
 		      u32 cmd, u32 st)
@@ -342,6 +369,11 @@ static int mt753x_reg_read(struct mtk_eth_priv *priv, u32 reg, u32 *data)
 {
 	int ret, low_word, high_word;
 
+	if (priv->sw == SW_MT7988) {
+		*data = mtk_gsw_read(priv, reg);
+		return 0;
+	}
+
 	/* Write page address */
 	ret = mtk_mii_write(priv, priv->mt753x_smi_addr, 0x1f, reg >> 6);
 	if (ret)
@@ -367,6 +399,11 @@ static int mt753x_reg_write(struct mtk_eth_priv *priv, u32 reg, u32 data)
 {
 	int ret;
 
+	if (priv->sw == SW_MT7988) {
+		mtk_gsw_write(priv, reg, data);
+		return 0;
+	}
+
 	/* Write page address */
 	ret = mtk_mii_write(priv, priv->mt753x_smi_addr, 0x1f, reg >> 6);
 	if (ret)
@@ -537,6 +574,7 @@ static int mtk_mdio_register(struct udevice *dev)
 		priv->mmd_write = mtk_mmd_ind_write;
 		break;
 	case SW_MT7531:
+	case SW_MT7988:
 		priv->mii_read = mt7531_mii_ind_read;
 		priv->mii_write = mt7531_mii_ind_write;
 		priv->mmd_read = mt7531_mmd_ind_read;
@@ -957,6 +995,103 @@ static int mt7531_setup(struct mtk_eth_priv *priv)
 	return 0;
 }
 
+static void mt7988_phy_setting(struct mtk_eth_priv *priv)
+{
+	u16 val;
+	u32 i;
+
+	for (i = 0; i < MT753X_NUM_PHYS; i++) {
+		/* Enable HW auto downshift */
+		priv->mii_write(priv, i, 0x1f, 0x1);
+		val = priv->mii_read(priv, i, PHY_EXT_REG_14);
+		val |= PHY_EN_DOWN_SHFIT;
+		priv->mii_write(priv, i, PHY_EXT_REG_14, val);
+
+		/* PHY link down power saving enable */
+		val = priv->mii_read(priv, i, PHY_EXT_REG_17);
+		val |= PHY_LINKDOWN_POWER_SAVING_EN;
+		priv->mii_write(priv, i, PHY_EXT_REG_17, val);
+	}
+}
+
+static void mt7988_mac_control(struct mtk_eth_priv *priv, bool enable)
+{
+	u32 pmcr = FORCE_MODE_LNK;
+
+	if (enable)
+		pmcr = priv->mt753x_pmcr;
+
+	mt753x_reg_write(priv, PMCR_REG(6), pmcr);
+}
+
+static int mt7988_setup(struct mtk_eth_priv *priv)
+{
+	u16 phy_addr, phy_val;
+	u32 pmcr;
+	int i;
+
+	priv->gsw_base = regmap_get_range(priv->ethsys_regmap, 0) + GSW_BASE;
+
+	priv->mt753x_phy_base = (priv->mt753x_smi_addr + 1) &
+				MT753X_SMI_ADDR_MASK;
+
+	/* Turn off PHYs */
+	for (i = 0; i < MT753X_NUM_PHYS; i++) {
+		phy_addr = MT753X_PHY_ADDR(priv->mt753x_phy_base, i);
+		phy_val = priv->mii_read(priv, phy_addr, MII_BMCR);
+		phy_val |= BMCR_PDOWN;
+		priv->mii_write(priv, phy_addr, MII_BMCR, phy_val);
+	}
+
+	switch (priv->phy_interface) {
+	case PHY_INTERFACE_MODE_USXGMII:
+		/* Use CPU bridge instead of actual USXGMII path */
+
+		/* Set GDM1 no drop */
+		mtk_fe_rmw(priv, PSE_NO_DROP_CFG_REG, 0, PSE_NO_DROP_GDM1);
+
+		/* Enable GDM1 to GSW CPU bridge */
+		mtk_gmac_rmw(priv, GMAC_MAC_MISC_REG, 0, BIT(0));
+
+		/* XGMAC force link up */
+		mtk_gmac_rmw(priv, GMAC_XGMAC_STS_REG, 0, P1_XGMAC_FORCE_LINK);
+
+		/* Setup GSW CPU bridge IPG */
+		mtk_gmac_rmw(priv, GMAC_GSW_CFG_REG, GSWTX_IPG_M | GSWRX_IPG_M,
+			     (0xB << GSWTX_IPG_S) | (0xB << GSWRX_IPG_S));
+		break;
+	default:
+		printf("Error: MT7988 GSW does not support %s interface\n",
+		       phy_string_for_interface(priv->phy_interface));
+		break;
+	}
+
+	pmcr = MT7988_FORCE_MODE |
+	       (IPG_96BIT_WITH_SHORT_IPG << IPG_CFG_S) |
+	       MAC_MODE | MAC_TX_EN | MAC_RX_EN |
+	       BKOFF_EN | BACKPR_EN |
+	       FORCE_RX_FC | FORCE_TX_FC |
+	       (SPEED_1000M << FORCE_SPD_S) | FORCE_DPX |
+	       FORCE_LINK;
+
+	priv->mt753x_pmcr = pmcr;
+
+	/* Keep MAC link down before starting eth */
+	mt753x_reg_write(priv, PMCR_REG(6), FORCE_MODE_LNK);
+
+	/* Turn on PHYs */
+	for (i = 0; i < MT753X_NUM_PHYS; i++) {
+		phy_addr = MT753X_PHY_ADDR(priv->mt753x_phy_base, i);
+		phy_val = priv->mii_read(priv, phy_addr, MII_BMCR);
+		phy_val &= ~BMCR_PDOWN;
+		priv->mii_write(priv, phy_addr, MII_BMCR, phy_val);
+	}
+
+	mt7988_phy_setting(priv);
+
+	return 0;
+}
+
 static int mt753x_switch_init(struct mtk_eth_priv *priv)
 {
 	int ret;
@@ -1497,6 +1632,11 @@ static int mtk_eth_start(struct udevice *dev)
 	}
 
 	if (MTK_HAS_CAPS(priv->soc->caps, MTK_NETSYS_V3)) {
+		if (priv->sw == SW_MT7988 && priv->gmac_id == 0) {
+			mtk_gdma_write(priv, priv->gmac_id, GDMA_IG_CTRL_REG,
+				       GDMA_BRIDGE_TO_CPU);
+		}
+
 		mtk_gdma_write(priv, priv->gmac_id, GDMA_EG_CTRL_REG,
 			       GDMA_CPU_BRIDGE_EN);
 	}
@@ -1845,6 +1985,12 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 			priv->switch_mac_control = mt7531_mac_control;
 			priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
 			priv->mt753x_reset_wait_time = 200;
+		} else if (!strcmp(str, "mt7988")) {
+			priv->sw = SW_MT7988;
+			priv->switch_init = mt7988_setup;
+			priv->switch_mac_control = mt7988_mac_control;
+			priv->mt753x_smi_addr = MT753X_DFL_SMI_ADDR;
+			priv->mt753x_reset_wait_time = 50;
 		} else {
 			printf("error: unsupported switch\n");
 			return -EINVAL;
@@ -1879,6 +2025,15 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 	return 0;
 }
 
+static const struct mtk_soc_data mt7988_data = {
+	.caps = MT7988_CAPS,
+	.ana_rgc3 = 0x128,
+	.gdma_count = 3,
+	.pdma_base = PDMA_V3_BASE,
+	.txd_size = sizeof(struct mtk_tx_dma_v2),
+	.rxd_size = sizeof(struct mtk_rx_dma_v2),
+};
+
 static const struct mtk_soc_data mt7986_data = {
 	.caps = MT7986_CAPS,
 	.ana_rgc3 = 0x128,
@@ -1930,6 +2085,7 @@ static const struct mtk_soc_data mt7621_data = {
 };
 
 static const struct udevice_id mtk_eth_ids[] = {
+	{ .compatible = "mediatek,mt7988-eth", .data = (ulong)&mt7988_data },
 	{ .compatible = "mediatek,mt7986-eth", .data = (ulong)&mt7986_data },
 	{ .compatible = "mediatek,mt7981-eth", .data = (ulong)&mt7981_data },
 	{ .compatible = "mediatek,mt7629-eth", .data = (ulong)&mt7629_data },
drivers/net/mtk_eth.h +20 -0
index 5e628e0cb7..491cac56a8 100644
@@ -51,6 +51,8 @@ enum mkt_eth_capabilities {
 
 #define MT7986_CAPS  (MTK_NETSYS_V2)
 
+#define MT7988_CAPS  (MTK_NETSYS_V3 | MTK_INFRA)
+
 /* Frame Engine Register Bases */
 #define PDMA_V1_BASE			0x0800
 #define PDMA_V2_BASE			0x6000
@@ -59,6 +61,7 @@ enum mkt_eth_capabilities {
 #define GDMA2_BASE			0x1500
 #define GDMA3_BASE			0x0540
 #define GMAC_BASE			0x10000
+#define GSW_BASE			0x20000
 
 /* Ethernet subsystem registers */
 
@@ -117,6 +120,9 @@ enum mkt_eth_capabilities {
 #define RG_XFI_PLL_ANA_SWWA		0x02283248
 
 /* Frame Engine Registers */
+#define PSE_NO_DROP_CFG_REG		0x108
+#define PSE_NO_DROP_GDM1		BIT(1)
+
 #define FE_GLO_MISC_REG			0x124
 #define PDMA_VER_V2			BIT(4)
 
@@ -187,6 +193,17 @@ enum mkt_eth_capabilities {
 #define MDIO_RW_DATA_S			0
 #define MDIO_RW_DATA_M			0xffff
 
+#define GMAC_XGMAC_STS_REG		0x000c
+#define P1_XGMAC_FORCE_LINK		BIT(15)
+
+#define GMAC_MAC_MISC_REG		0x0010
+
+#define GMAC_GSW_CFG_REG		0x0080
+#define GSWTX_IPG_M			0xF0000
+#define GSWTX_IPG_S			16
+#define GSWRX_IPG_M			0xF
+#define GSWRX_IPG_S			0
+
 /* MDIO_CMD: MDIO commands */
 #define MDIO_CMD_ADDR			0
 #define MDIO_CMD_WRITE			1
@@ -285,6 +302,9 @@ enum mkt_eth_capabilities {
 					FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
 					FORCE_MODE_DPX   | FORCE_MODE_SPD | \
 					FORCE_MODE_LNK
+#define MT7988_FORCE_MODE		FORCE_MODE_TX_FC | FORCE_MODE_RX_FC | \
+					FORCE_MODE_DPX   | FORCE_MODE_SPD | \
+					FORCE_MODE_LNK
 
 /* MT7531 SGMII Registers */
 #define MT7531_SGMII_REG_BASE		0x5000
Signature · 1 line
2.17.1
author
#35 lore raw

PATCH 27/29 tools: mtk_image: use uint32_t for ghf header magic and version

In reply to Weijie Gao

This patch converts magic and version fields of ghf common header to one field with the type of uint32_t to make this header flexible for futher updates.

---
 tools/mtk_image.c | 10 ++++++----
 tools/mtk_image.h |  6 +++---
 2 files changed, 9 insertions(+), 7 deletions(-)
tools/mtk_image.c +6 -4
index 30f54c8e8d..1b1aed5992 100644
@@ -542,11 +542,13 @@ static void put_brom_layout_header(struct brom_layout_header *hdr, int type)
 	hdr->type = cpu_to_le32(type);
 }
 
-static void put_ghf_common_header(struct gfh_common_header *gfh, int size,
-				  int type, int ver)
+static void put_ghf_common_header(struct gfh_common_header *gfh, uint16_t size,
+				  uint16_t type, uint8_t ver)
 {
-	memcpy(gfh->magic, GFH_HEADER_MAGIC, sizeof(gfh->magic));
-	gfh->version = ver;
+	uint32_t magic_version = GFH_HEADER_MAGIC |
+				 (uint32_t)ver << GFH_HEADER_VERSION_SHIFT;
+
+	gfh->magic_version = cpu_to_le32(magic_version);
 	gfh->size = cpu_to_le16(size);
 	gfh->type = cpu_to_le16(type);
 }
tools/mtk_image.h +3 -3
index fad9372100..54a838de86 100644
@@ -63,13 +63,13 @@ struct gen_device_header {
 
 /* BootROM header definitions */
 struct gfh_common_header {
-	uint8_t magic[3];
-	uint8_t version;
+	uint32_t magic_version;
 	uint16_t size;
 	uint16_t type;
 };
 
-#define GFH_HEADER_MAGIC	"MMM"
+#define GFH_HEADER_MAGIC		0x4D4D4D
+#define GFH_HEADER_VERSION_SHIFT	24
 
 #define GFH_TYPE_FILE_INFO	0
 #define GFH_TYPE_BL_INFO	1
Signature · 1 line
2.17.1
author
#36 lore raw

PATCH 28/29 arm: mediatek: add support for MediaTek MT7988 SoC

In reply to Weijie Gao

This patch adds basic support for MediaTek MT7988 SoC. This includes files that will initialize the SoC after boot and its device tree.

---
 arch/arm/dts/mt7988-u-boot.dtsi               |  25 ++
 arch/arm/dts/mt7988.dtsi                      | 391 ++++++++++++++++++
 arch/arm/mach-mediatek/Kconfig                |  13 +-
 arch/arm/mach-mediatek/Makefile               |   1 +
 arch/arm/mach-mediatek/mt7988/Makefile        |   4 +
 arch/arm/mach-mediatek/mt7988/init.c          |  63 +++
 arch/arm/mach-mediatek/mt7988/lowlevel_init.S |  30 ++
 7 files changed, 526 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/mt7988-u-boot.dtsi
 create mode 100644 arch/arm/dts/mt7988.dtsi
 create mode 100644 arch/arm/mach-mediatek/mt7988/Makefile
 create mode 100644 arch/arm/mach-mediatek/mt7988/init.c
 create mode 100644 arch/arm/mach-mediatek/mt7988/lowlevel_init.S
arch/arm/dts/mt7988-u-boot.dtsi new file +25 -0
new file mode 100644
index 0000000000..43e00a36ef
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 MediaTek Inc.
+ * Author: Sam Shih <[email protected]>
+ */
+
+&system_clk {
+	bootph-all;
+};
+
+&spi_clk {
+	bootph-all;
+};
+
+&uart0 {
+	bootph-all;
+};
+
+&uart1 {
+	bootph-all;
+};
+
+&uart2 {
+	bootph-all;
+};
arch/arm/dts/mt7988.dtsi new file +391 -0

391 lines not on this page · raw message

arch/arm/mach-mediatek/Kconfig +12 -1
index 04aa2fd97f..8971e2d2b0 100644
@@ -58,6 +58,15 @@ config TARGET_MT7986
 	  including UART, SPI, SPI flash, USB3.0, MMC, NAND, SNFI, PWM, PCIe,
 	  Gigabit Ethernet, I2C, built-in 4x4 Wi-Fi, and PCIe.
 
+config TARGET_MT7988
+	bool "MediaTek MT7988 SoC"
+	select ARM64
+	select CPU
+	help
+	  The MediaTek MT7988 is a ARM64-based SoC with a quad-core Cortex-A73.
+	  including UART, SPI, SPI flash, USB3.0, MMC, NAND, SNFI, PWM, PCIe,
+	  10 Gigabit Ethernet , I2C, and PCIe.
+
 config TARGET_MT8183
 	bool "MediaTek MT8183 SoC"
 	select ARM64
@@ -104,6 +113,7 @@ config SYS_BOARD
 	default "mt7629" if TARGET_MT7629
 	default "mt7981" if TARGET_MT7981
 	default "mt7986" if TARGET_MT7986
+	default "mt7988" if TARGET_MT7988
 	default "mt8183" if TARGET_MT8183
 	default "mt8512" if TARGET_MT8512
 	default "mt8516" if TARGET_MT8516
@@ -121,6 +131,7 @@ config SYS_CONFIG_NAME
 	default "mt7629" if TARGET_MT7629
 	default "mt7981" if TARGET_MT7981
 	default "mt7986" if TARGET_MT7986
+	default "mt7988" if TARGET_MT7988
 	default "mt8183" if TARGET_MT8183
 	default "mt8512" if TARGET_MT8512
 	default "mt8516" if TARGET_MT8516
@@ -135,7 +146,7 @@ config MTK_BROM_HEADER_INFO
 	string
 	default "media=nor" if TARGET_MT8518 || TARGET_MT8512 || TARGET_MT7629 || TARGET_MT7622
 	default "media=emmc" if TARGET_MT8516 || TARGET_MT8365 || TARGET_MT8183
-	default "media=snand;nandinfo=2k+64" if TARGET_MT7981 || TARGET_MT7986
+	default "media=snand;nandinfo=2k+64" if TARGET_MT7981 || TARGET_MT7986 || TARGET_MT7988
 	default "lk=1" if TARGET_MT7623
 
 endif
arch/arm/mach-mediatek/Makefile +1 -0
index fc85293f71..71aa341e34 100644
@@ -9,6 +9,7 @@ obj-$(CONFIG_TARGET_MT7623) += mt7623/
 obj-$(CONFIG_TARGET_MT7629) += mt7629/
 obj-$(CONFIG_TARGET_MT7981) += mt7981/
 obj-$(CONFIG_TARGET_MT7986) += mt7986/
+obj-$(CONFIG_TARGET_MT7988) += mt7988/
 obj-$(CONFIG_TARGET_MT8183) += mt8183/
 obj-$(CONFIG_TARGET_MT8516) += mt8516/
 obj-$(CONFIG_TARGET_MT8518) += mt8518/
arch/arm/mach-mediatek/mt7988/Makefile new file +4 -0
new file mode 100644
index 0000000000..007eb4a367
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier:	GPL-2.0
+
+obj-y += init.o
+obj-y += lowlevel_init.o
arch/arm/mach-mediatek/mt7988/init.c new file +63 -0

63 lines not on this page · raw message

arch/arm/mach-mediatek/mt7988/lowlevel_init.S new file +30 -0
new file mode 100644
index 0000000000..2ae3cc4848
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ * Author: Sam Shih <[email protected]>
+ */
+
+/*
+ * Switch from AArch64 EL2 to AArch32 EL2
+ * @param inputs:
+ * x0: argument, zero
+ * x1: machine nr
+ * x2: fdt address
+ * x3: input argument
+ * x4: kernel entry point
+ * @param outputs for secure firmware:
+ * x0: function id
+ * x1: kernel entry point
+ * x2: machine nr
+ * x3: fdt address
+*/
+
+.global armv8_el2_to_aarch32
+armv8_el2_to_aarch32:
+	mov     x3, x2
+	mov     x2, x1
+	mov     x1, x4
+	mov	x4, #0
+	ldr x0, =0x82000200
+	SMC #0
+	ret
Signature · 1 line
2.17.1
author
#37 lore raw

PATCH 29/29 board: mediatek: add MT7988 reference boards

In reply to Weijie Gao

This patch adds general board files based on MT7988 SoCs.

MT7988 uses one mmc controller for booting from both SD and eMMC, and the pins of mmc controller booting from SD are also shared with one of spi controllers.
So two configs are need for these boot types:

1. mt7988_rfb_defconfig - SPI-NOR, SPI-NAND and eMMC
2. mt7988_sd_rfb_defconfig - SPI-NAND and SD

---
 arch/arm/dts/Makefile              |   2 +
 arch/arm/dts/mt7988-rfb.dts        | 182 +++++++++++++++++++++++++++++
 arch/arm/dts/mt7988-sd-rfb.dts     | 134 +++++++++++++++++++++
 board/mediatek/mt7988/MAINTAINERS  |   7 ++
 board/mediatek/mt7988/Makefile     |   3 +
 board/mediatek/mt7988/mt7988_rfb.c |  10 ++
 configs/mt7988_rfb_defconfig       |  83 +++++++++++++
 configs/mt7988_sd_rfb_defconfig    |  71 +++++++++++
 include/configs/mt7988.h           |  14 +++
 9 files changed, 506 insertions(+)
 create mode 100644 arch/arm/dts/mt7988-rfb.dts
 create mode 100644 arch/arm/dts/mt7988-sd-rfb.dts
 create mode 100644 board/mediatek/mt7988/MAINTAINERS
 create mode 100644 board/mediatek/mt7988/Makefile
 create mode 100644 board/mediatek/mt7988/mt7988_rfb.c
 create mode 100644 configs/mt7988_rfb_defconfig
 create mode 100644 configs/mt7988_sd_rfb_defconfig
 create mode 100644 include/configs/mt7988.h
arch/arm/dts/Makefile +2 -0
index 07b26df275..92d0b377d6 100644
@@ -1323,6 +1323,8 @@ dtb-$(CONFIG_ARCH_MEDIATEK) += \
 	mt7986b-sd-rfb.dtb \
 	mt7986a-emmc-rfb.dtb \
 	mt7986b-emmc-rfb.dtb \
+	mt7988-rfb.dtb \
+	mt7988-sd-rfb.dtb \
 	mt8183-pumpkin.dtb \
 	mt8512-bm1-emmc.dtb \
 	mt8516-pumpkin.dtb \
arch/arm/dts/mt7988-rfb.dts new file +182 -0

182 lines not on this page · raw message

arch/arm/dts/mt7988-sd-rfb.dts new file +134 -0

134 lines not on this page · raw message

board/mediatek/mt7988/MAINTAINERS new file +7 -0
new file mode 100644
index 0000000000..a45bfff26c
@@ -0,0 +1,7 @@
+MT7988
+M:	Sam Shih <[email protected]>
+S:	Maintained
+F:	board/mediatek/mt7988
+F:	include/configs/mt7988.h
+F:	configs/mt7988_rfb_defconfig
+F:	configs/mt7988_sd_rfb_defconfig
board/mediatek/mt7988/Makefile new file +3 -0
new file mode 100644
index 0000000000..f1249ab371
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier:	GPL-2.0
+
+obj-y	+= mt7988_rfb.o
board/mediatek/mt7988/mt7988_rfb.c new file +10 -0
new file mode 100644
index 0000000000..846c715ca0
@@ -0,0 +1,10 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2022 MediaTek Inc.
+ * Author: Sam Shih <[email protected]>
+ */
+
+int board_init(void)
+{
+	return 0;
+}
configs/mt7988_rfb_defconfig new file +83 -0

83 lines not on this page · raw message

configs/mt7988_sd_rfb_defconfig new file +71 -0

71 lines not on this page · raw message

include/configs/mt7988.h new file +14 -0
new file mode 100644
index 0000000000..e63825a5a1
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Configuration for MediaTek MT7988 SoC
+ *
+ * Copyright (C) 2022 MediaTek Inc.
+ * Author: Sam Shih <[email protected]>
+ */
+
+#ifndef __MT7988_H
+#define __MT7988_H
+
+#define CFG_MAX_MEM_MAPPED		0xC0000000
+
+#endif
Signature · 1 line
2.17.1
Reviewed-by on v1 4/29
#6 lore raw

Re: [PATCH 04/29] spi: mtk_spim: clear IRQ enable bits

In reply to Weijie Gao
Quoted 10 lines · Weijie Gao

In u-boot we don't use IRQ. Instead, we poll busy bit in SPI_STATUS.

However these IRQ enable bits may be set in previous boot stage (BootROM).

If we leave these bits not cleared, although u-boot has disabled IRQ and nothing will happen, the linux kernel may encounter panic during initializing the spim driver due to IRQ event happens before IRQ handler is properly setup.

Quoted 5 lines

This patch clear IRQ bits to prevent this from happening.

---

Reviewed-by on v1 5/29
#8 lore raw

Re: [PATCH 05/29] serial: mtk: initial priv data before using

In reply to Weijie Gao
Quoted 14 lines · Weijie Gao

This patch ensures driver private data being fully initialized in _debug_uart_init which is not covered by .priv_auto ops.

---
  drivers/serial/serial_mtk.c | 1 +
  1 file changed, 1 insertion(+)
drivers/serial/serial_mtk.c +0 -0
index ded7346a13..2dffa14ea7 100644

drivers/serial/serial_mtk.c static inline void _debug_uart_init(void) · line 445

Quoted 7 lines
drivers/serial/serial_mtk.c +1 -0
@@ -439,6 +439,7 @@ static inline void _debug_uart_init(void)
  {
  	struct mtk_serial_priv priv;
 
+	memset(&priv, 0, sizeof(struct mtk_serial_priv));
  	priv.regs = (void *) CONFIG_VAL(DEBUG_UART_BASE);
  	priv.fixed_clk_rate = CONFIG_DEBUG_UART_CLOCK;
 

Thanks,
Stefan

#26 lore raw

Aw: [PATCH 21/29] arm: dts: medaitek: convert gmac link mode to 2500base-x

In reply to Weijie Gao

Hi,

thank you very much for your work on mt7988 support and faster than expected ;) Nice to see that ethernet-support is already included, i see some changes to mt753x..

I will try out this series as fast as possible.

Quoted 5 lines

Gesendet: Mittwoch, 19. Juli 2023 um 11:17 Uhr
Von: "Weijie Gao" <[email protected]>
An: [email protected]
Cc: "GSS_MTK_Uboot_upstream" <[email protected]>, "Daniel Golle" <[email protected]>, "Frank Wunderlich" <[email protected]>, "Weijie Gao" <[email protected]>
Betreff: [PATCH 21/29] arm: dts: medaitek: convert gmac link mode to 2500base-x

so far only noticed a typo (medaitek => mediatek) in this part here

regards Frank

Quoted 5 lines

Now that individual 2.5Gbps SGMII support has been added to mtk-eth, all boards that use 2.5Gbps link with mt7531 must be converted to use "2500base-x" instead of "sgmii".

#27 lore raw

Aw: [PATCH 21/29] arm: dts: medaitek: convert gmac link mode to 2500base-x

In reply to Weijie Gao

Hi

Quoted 11 lines

Gesendet: Mittwoch, 19. Juli 2023 um 11:17 Uhr
Von: "Weijie Gao" <[email protected]>
An: [email protected]
Cc: "GSS_MTK_Uboot_upstream" <[email protected]>, "Daniel Golle" <[email protected]>, "Frank Wunderlich" <[email protected]>, "Weijie Gao" <[email protected]>
Betreff: [PATCH 21/29] arm: dts: medaitek: convert gmac link mode to 2500base-x

Now that individual 2.5Gbps SGMII support has been added to mtk-eth, all boards that use 2.5Gbps link with mt7531 must be converted to use "2500base-x" instead of "sgmii".

Quoted 11 lines
---
 arch/arm/dts/mt7622-bananapi-bpi-r64.dts | 4 ++--
 arch/arm/dts/mt7622-rfb.dts              | 4 ++--
 arch/arm/dts/mt7629-rfb.dts              | 4 ++--
 arch/arm/dts/mt7981-emmc-rfb.dts         | 4 ++--
 arch/arm/dts/mt7981-rfb.dts              | 4 ++--
 arch/arm/dts/mt7981-sd-rfb.dts           | 4 ++--
 arch/arm/dts/mt7986a-rfb.dts             | 4 ++--
 arch/arm/dts/mt7986a-sd-rfb.dts          | 4 ++--
 arch/arm/dts/mt7986b-rfb.dts             | 4 ++--
 arch/arm/dts/mt7986b-sd-rfb.dts          | 4 ++--

you miss arch/arm/dts/mt7986a-bpi-r3-sd.dts here which was added in 2023.07

i tested series on Bananapi-R4/mt7988, sdcard and network-support (many thx for this) works so far (not tested i2c, spi and others yet), also have not done tests on my other boards yet.

noticed some build-warnings from the pinctrl-patch which are not critical, but should be fixed.

e.g. this (seems for each call of PINCTRL_PIN_GROUP)

drivers/pinctrl/mediatek/pinctrl-mt7988.c:1148:42: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
1148 | PINCTRL_PIN_GROUP("net_wo1_uart_txd_1", mt7988_net_wo1_uart_txd_1),

      |                                          ^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/pinctrl/mediatek/pinctrl-mtk-common.h:31:3: note: in definition of macro 'PINCTRL_PIN_GROUP'
   31 |   id##_funcs,      \
      |   ^~

regards Frank

author
#16 lore raw

PATCH 12/29 pinctrl: mediatek: convert most definitions to const

In reply to Weijie Gao

There exists a situation of the mediatek pinctrl driver that may return wrong pin function value for the pinmux driver:
- All pin function arrays are defined without const
- Some pin function arrays contain all-zero value, e.g.:
static int mt7622_spi_funcs[] = { 0, 0, 0, 0, 0, 0, };
- These arrays will be put into .bss section during compilation
- .bss section has no "a" attribute and does not exist in the final binary file after objcopy.
- FDT binary blob is appended to the u-boot binary, which occupies the .bss section.
- During board_f stage, .bss has not been initialized, and contains the data of FDT, which is not full-zero data.
- pinctrl driver is initialized in board_f stage, and it will get wrong data if another driver is going to set default pinctrl.

Since pinmux information and soc data are only meant to be read-only, thus should be declared as const. This will force all pinctrl data being put into .rodata section. Since .rodata has "a" attribute, even the all-zero data will be allocated and filled with correct value in to u-boot binary.

---
 drivers/pinctrl/mediatek/pinctrl-mt7622.c     | 474 ++++++-------
 drivers/pinctrl/mediatek/pinctrl-mt7623.c     | 650 +++++++++---------
 drivers/pinctrl/mediatek/pinctrl-mt7629.c     | 174 ++---
 drivers/pinctrl/mediatek/pinctrl-mt7981.c     | 270 ++++----
 drivers/pinctrl/mediatek/pinctrl-mt7986.c     | 145 ++--
 drivers/pinctrl/mediatek/pinctrl-mt8512.c     |  24 +-
 drivers/pinctrl/mediatek/pinctrl-mt8516.c     |  18 +-
 drivers/pinctrl/mediatek/pinctrl-mt8518.c     |  20 +-
 drivers/pinctrl/mediatek/pinctrl-mtk-common.c |   4 +-
 drivers/pinctrl/mediatek/pinctrl-mtk-common.h |   8 +-
 10 files changed, 898 insertions(+), 889 deletions(-)
drivers/pinctrl/mediatek/pinctrl-mt7622.c +238 -236
index bf4e9a28e9..114f2602b2 100644
@@ -233,283 +233,285 @@ static const struct mtk_pin_desc mt7622_pins[] = {
  */
 
 /* EMMC */
-static int mt7622_emmc_pins[] = { 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, };
-static int mt7622_emmc_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
+static const int mt7622_emmc_pins[] = {
+	40, 41, 42, 43, 44, 45, 47, 48, 49, 50, };
+static const int mt7622_emmc_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
 
-static int mt7622_emmc_rst_pins[] = { 37, };
-static int mt7622_emmc_rst_funcs[] = { 1, };
+static const int mt7622_emmc_rst_pins[] = { 37, };
+static const int mt7622_emmc_rst_funcs[] = { 1, };
 
 /* LED for EPHY */
-static int mt7622_ephy_leds_pins[] = { 86, 91, 92, 93, 94, };
-static int mt7622_ephy_leds_funcs[] = { 0, 0, 0, 0, 0, };
-static int mt7622_ephy0_led_pins[] = { 86, };
-static int mt7622_ephy0_led_funcs[] = { 0, };
-static int mt7622_ephy1_led_pins[] = { 91, };
-static int mt7622_ephy1_led_funcs[] = { 2, };
-static int mt7622_ephy2_led_pins[] = { 92, };
-static int mt7622_ephy2_led_funcs[] = { 2, };
-static int mt7622_ephy3_led_pins[] = { 93, };
-static int mt7622_ephy3_led_funcs[] = { 2, };
-static int mt7622_ephy4_led_pins[] = { 94, };
-static int mt7622_ephy4_led_funcs[] = { 2, };
+static const int mt7622_ephy_leds_pins[] = { 86, 91, 92, 93, 94, };
+static const int mt7622_ephy_leds_funcs[] = { 0, 0, 0, 0, 0, };
+static const int mt7622_ephy0_led_pins[] = { 86, };
+static const int mt7622_ephy0_led_funcs[] = { 0, };
+static const int mt7622_ephy1_led_pins[] = { 91, };
+static const int mt7622_ephy1_led_funcs[] = { 2, };
+static const int mt7622_ephy2_led_pins[] = { 92, };
+static const int mt7622_ephy2_led_funcs[] = { 2, };
+static const int mt7622_ephy3_led_pins[] = { 93, };
+static const int mt7622_ephy3_led_funcs[] = { 2, };
+static const int mt7622_ephy4_led_pins[] = { 94, };
+static const int mt7622_ephy4_led_funcs[] = { 2, };
 
 /* Embedded Switch */
-static int mt7622_esw_pins[] = { 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
-				 62, 63, 64, 65, 66, 67, 68, 69, 70, };
-static int mt7622_esw_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-				  0, 0, 0, 0, 0, 0, 0, 0, 0, };
-static int mt7622_esw_p0_p1_pins[] = { 51, 52, 53, 54, 55, 56, 57, 58, };
-static int mt7622_esw_p0_p1_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
-static int mt7622_esw_p2_p3_p4_pins[] = { 59, 60, 61, 62, 63, 64, 65, 66, 67,
-					  68, 69, 70, };
-static int mt7622_esw_p2_p3_p4_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0,
-					   0, 0, 0, };
+static const int mt7622_esw_pins[] = {
+	51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
+	69, 70, };
+static const int mt7622_esw_funcs[] = {
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
+static const int mt7622_esw_p0_p1_pins[] = { 51, 52, 53, 54, 55, 56, 57, 58, };
+static const int mt7622_esw_p0_p1_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, };
+static const int mt7622_esw_p2_p3_p4_pins[] = {
+	59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, };
+static const int mt7622_esw_p2_p3_p4_funcs[] = {
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
 /* RGMII via ESW */
-static int mt7622_rgmii_via_esw_pins[] = { 59, 60, 61, 62, 63, 64, 65, 66,
-					   67, 68, 69, 70, };
-static int mt7622_rgmii_via_esw_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-					    0, };
+static const int mt7622_rgmii_via_esw_pins[] = {
+	59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, };
+static const int mt7622_rgmii_via_esw_funcs[] = {
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
 
 /* RGMII via GMAC1 */
-static int mt7622_rgmii_via_gmac1_pins[] = { 59, 60, 61, 62, 63, 64, 65, 66,
-					     67, 68, 69, 70, };
-static int mt7622_rgmii_via_gmac1_funcs[] = { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-					      2, };
+static const int mt7622_rgmii_via_gmac1_pins[] = {
+	59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, };
+static const int mt7622_rgmii_via_gmac1_funcs[] = {
+	2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, };
 
 /* RGMII via GMAC2 */
-static int mt7622_rgmii_via_gmac2_pins[] = { 25, 26, 27, 28, 29, 30, 31, 32,
-					     33, 34, 35, 36, };
-static int mt7622_rgmii_via_gmac2_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-					      0, };
+static const int mt7622_rgmii_via_gmac2_pins[] = {
+	25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, };
+static const int mt7622_rgmii_via_gmac2_funcs[] = {
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
 
 /* I2C */
-static int mt7622_i2c0_pins[] = { 14, 15, };
-static int mt7622_i2c0_funcs[] = { 0, 0, };
-static int mt7622_i2c1_0_pins[] = { 55, 56, };
-static int mt7622_i2c1_0_funcs[] = { 0, 0, };
-static int mt7622_i2c1_1_pins[] = { 73, 74, };
-static int mt7622_i2c1_1_funcs[] = { 3, 3, };
-static int mt7622_i2c1_2_pins[] = { 87, 88, };
-static int mt7622_i2c1_2_funcs[] = { 0, 0, };
-static int mt7622_i2c2_0_pins[] = { 57, 58, };
-static int mt7622_i2c2_0_funcs[] = { 0, 0, };
-static int mt7622_i2c2_1_pins[] = { 75, 76, };
-static int mt7622_i2c2_1_funcs[] = { 3, 3, };
-static int mt7622_i2c2_2_pins[] = { 89, 90, };
-static int mt7622_i2c2_2_funcs[] = { 0, 0, };
+static const int mt7622_i2c0_pins[] = { 14, 15, };
+static const int mt7622_i2c0_funcs[] = { 0, 0, };
+static const int mt7622_i2c1_0_pins[] = { 55, 56, };
+static const int mt7622_i2c1_0_funcs[] = { 0, 0, };
+static const int mt7622_i2c1_1_pins[] = { 73, 74, };
+static const int mt7622_i2c1_1_funcs[] = { 3, 3, };
+static const int mt7622_i2c1_2_pins[] = { 87, 88, };
+static const int mt7622_i2c1_2_funcs[] = { 0, 0, };
+static const int mt7622_i2c2_0_pins[] = { 57, 58, };
+static const int mt7622_i2c2_0_funcs[] = { 0, 0, };
+static const int mt7622_i2c2_1_pins[] = { 75, 76, };
+static const int mt7622_i2c2_1_funcs[] = { 3, 3, };
+static const int mt7622_i2c2_2_pins[] = { 89, 90, };
+static const int mt7622_i2c2_2_funcs[] = { 0, 0, };
 
 /* I2S */
-static int mt7622_i2s_in_mclk_bclk_ws_pins[] = { 3, 4, 5, };
-static int mt7622_i2s_in_mclk_bclk_ws_funcs[] = { 3, 3, 0, };
-static int mt7622_i2s1_in_data_pins[] = { 1, };
-static int mt7622_i2s1_in_data_funcs[] = { 0, };
-static int mt7622_i2s2_in_data_pins[] = { 16, };
-static int mt7622_i2s2_in_data_funcs[] = { 0, };
-static int mt7622_i2s3_in_data_pins[] = { 17, };
-static int mt7622_i2s3_in_data_funcs[] = { 0, };
-static int mt7622_i2s4_in_data_pins[] = { 18, };
-static int mt7622_i2s4_in_data_funcs[] = { 0, };
-static int mt7622_i2s_out_mclk_bclk_ws_pins[] = { 3, 4, 5, };
-static int mt7622_i2s_out_mclk_bclk_ws_funcs[] = { 0, 0, 0, };
-static int mt7622_i2s1_out_data_pins[] = { 2, };
-static int mt7622_i2s1_out_data_funcs[] = { 0, };
-static int mt7622_i2s2_out_data_pins[] = { 19, };
-static int mt7622_i2s2_out_data_funcs[] = { 0, };
-static int mt7622_i2s3_out_data_pins[] = { 20, };
-static int mt7622_i2s3_out_data_funcs[] = { 0, };
-static int mt7622_i2s4_out_data_pins[] = { 21, };
-static int mt7622_i2s4_out_data_funcs[] = { 0, };
+static const int mt7622_i2s_in_mclk_bclk_ws_pins[] = { 3, 4, 5, };
+static const int mt7622_i2s_in_mclk_bclk_ws_funcs[] = { 3, 3, 0, };
+static const int mt7622_i2s1_in_data_pins[] = { 1, };
+static const int mt7622_i2s1_in_data_funcs[] = { 0, };
+static const int mt7622_i2s2_in_data_pins[] = { 16, };
+static const int mt7622_i2s2_in_data_funcs[] = { 0, };
+static const int mt7622_i2s3_in_data_pins[] = { 17, };
+static const int mt7622_i2s3_in_data_funcs[] = { 0, };
+static const int mt7622_i2s4_in_data_pins[] = { 18, };
+static const int mt7622_i2s4_in_data_funcs[] = { 0, };
+static const int mt7622_i2s_out_mclk_bclk_ws_pins[] = { 3, 4, 5, };
+static const int mt7622_i2s_out_mclk_bclk_ws_funcs[] = { 0, 0, 0, };
+static const int mt7622_i2s1_out_data_pins[] = { 2, };
+static const int mt7622_i2s1_out_data_funcs[] = { 0, };
+static const int mt7622_i2s2_out_data_pins[] = { 19, };
+static const int mt7622_i2s2_out_data_funcs[] = { 0, };
+static const int mt7622_i2s3_out_data_pins[] = { 20, };
+static const int mt7622_i2s3_out_data_funcs[] = { 0, };
+static const int mt7622_i2s4_out_data_pins[] = { 21, };
+static const int mt7622_i2s4_out_data_funcs[] = { 0, };
 
 /* IR */
-static int mt7622_ir_0_tx_pins[] = { 16, };
-static int mt7622_ir_0_tx_funcs[] = { 4, };
-static int mt7622_ir_1_tx_pins[] = { 59, };
-static int mt7622_ir_1_tx_funcs[] = { 5, };
-static int mt7622_ir_2_tx_pins[] = { 99, };
-static int mt7622_ir_2_tx_funcs[] = { 3, };
-static int mt7622_ir_0_rx_pins[] = { 17, };
-static int mt7622_ir_0_rx_funcs[] = { 4, };
-static int mt7622_ir_1_rx_pins[] = { 60, };
-static int mt7622_ir_1_rx_funcs[] = { 5, };
-static int mt7622_ir_2_rx_pins[] = { 100, };
-static int mt7622_ir_2_rx_funcs[] = { 3, };
+static const int mt7622_ir_0_tx_pins[] = { 16, };
+static const int mt7622_ir_0_tx_funcs[] = { 4, };
+static const int mt7622_ir_1_tx_pins[] = { 59, };
+static const int mt7622_ir_1_tx_funcs[] = { 5, };
+static const int mt7622_ir_2_tx_pins[] = { 99, };
+static const int mt7622_ir_2_tx_funcs[] = { 3, };
+static const int mt7622_ir_0_rx_pins[] = { 17, };
+static const int mt7622_ir_0_rx_funcs[] = { 4, };
+static const int mt7622_ir_1_rx_pins[] = { 60, };
+static const int mt7622_ir_1_rx_funcs[] = { 5, };
+static const int mt7622_ir_2_rx_pins[] = { 100, };
+static const int mt7622_ir_2_rx_funcs[] = { 3, };
 
 /* MDIO */
-static int mt7622_mdc_mdio_pins[] = { 23, 24, };
-static int mt7622_mdc_mdio_funcs[] = { 0, 0, };
+static const int mt7622_mdc_mdio_pins[] = { 23, 24, };
+static const int mt7622_mdc_mdio_funcs[] = { 0, 0, };
 
 /* PCIE */
-static int mt7622_pcie0_0_waken_pins[] = { 14, };
-static int mt7622_pcie0_0_waken_funcs[] = { 2, };
-static int mt7622_pcie0_0_clkreq_pins[] = { 15, };
-static int mt7622_pcie0_0_clkreq_funcs[] = { 2, };
-static int mt7622_pcie0_1_waken_pins[] = { 79, };
-static int mt7622_pcie0_1_waken_funcs[] = { 4, };
-static int mt7622_pcie0_1_clkreq_pins[] = { 80, };
-static int mt7622_pcie0_1_clkreq_funcs[] = { 4, };
-static int mt7622_pcie1_0_waken_pins[] = { 14, };
-static int mt7622_pcie1_0_waken_funcs[] = { 3, };
-static int mt7622_pcie1_0_clkreq_pins[] = { 15, };
-static int mt7622_pcie1_0_clkreq_funcs[] = { 3, };
-
-static int mt7622_pcie0_pad_perst_pins[] = { 83, };
-static int mt7622_pcie0_pad_perst_funcs[] = { 0, };
-static int mt7622_pcie1_pad_perst_pins[] = { 84, };
-static int mt7622_pcie1_pad_perst_funcs[] = { 0, };
+static const int mt7622_pcie0_0_waken_pins[] = { 14, };
+static const int mt7622_pcie0_0_waken_funcs[] = { 2, };
+static const int mt7622_pcie0_0_clkreq_pins[] = { 15, };
+static const int mt7622_pcie0_0_clkreq_funcs[] = { 2, };
+static const int mt7622_pcie0_1_waken_pins[] = { 79, };
+static const int mt7622_pcie0_1_waken_funcs[] = { 4, };
+static const int mt7622_pcie0_1_clkreq_pins[] = { 80, };
+static const int mt7622_pcie0_1_clkreq_funcs[] = { 4, };
+static const int mt7622_pcie1_0_waken_pins[] = { 14, };
+static const int mt7622_pcie1_0_waken_funcs[] = { 3, };
+static const int mt7622_pcie1_0_clkreq_pins[] = { 15, };
+static const int mt7622_pcie1_0_clkreq_funcs[] = { 3, };
+
+static const int mt7622_pcie0_pad_perst_pins[] = { 83, };
+static const int mt7622_pcie0_pad_perst_funcs[] = { 0, };
+static const int mt7622_pcie1_pad_perst_pins[] = { 84, };
+static const int mt7622_pcie1_pad_perst_funcs[] = { 0, };
 
 /* PMIC bus */
-static int mt7622_pmic_bus_pins[] = { 71, 72, };
-static int mt7622_pmic_bus_funcs[] = { 0, 0, };
+static const int mt7622_pmic_bus_pins[] = { 71, 72, };
+static const int mt7622_pmic_bus_funcs[] = { 0, 0, };
 
 /* Parallel NAND */
-static int mt7622_pnand_pins[] = { 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
-				   48, 49, 50, };
-static int mt7622_pnand_funcs[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-				    0, };
+static const int mt7622_pnand_pins[] = {
+	37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, };
+static const int mt7622_pnand_funcs[] = {
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, };
 
 /* PWM */
-static int mt7622_pwm_ch1_0_pins[] = { 51, };
-static int mt7622_pwm_ch1_0_funcs[] = { 3, };
-static int mt7622_pwm_ch1_1_pins[] = { 73, };
-static int mt7622_pwm_ch1_1_funcs[] = { 4, };
-static int mt7622_pwm_ch1_2_pins[] = { 95, };
-static int mt7622_pwm_ch1_2_funcs[] = { 0, };
-static int mt7622_pwm_ch2_0_pins[] = { 52, };
-static int mt7622_pwm_ch2_0_funcs[] = { 3, };
-static int mt7622_pwm_ch2_1_pins[] = { 74, };
-static int mt7622_pwm_ch2_1_funcs[] = { 4, };
-static int mt7622_pwm_ch2_2_pins[] = { 96, };
-static int mt7622_pwm_ch2_2_funcs[] = { 0, };
-static int mt7622_pwm_ch3_0_pins[] = { 53, };
-static int mt7622_pwm_ch3_0_funcs[] = { 3, };
-static int mt7622_pwm_ch3_1_pins[] = { 75, };
-static int mt7622_pwm_ch3_1_funcs[] = { 4, };
-static int mt7622_pwm_ch3_2_pins[] = { 97, };
-static int mt7622_pwm_ch3_2_funcs[] = { 0, };
-static int mt7622_pwm_ch4_0_pins[] = { 54, };
-static int mt7622_pwm_ch4_0_funcs[] = { 3, };
-static int mt7622_pwm_ch4_1_pins[] = { 67, };
-static int mt7622_pwm_ch4_1_funcs[] = { 3, };
-static int mt7622_pwm_ch4_2_pins[] = { 76, };
-static int mt7622_pwm_ch4_2_funcs[] = { 4, };
-static int mt7622_pwm_ch4_3_pins[] = { 98, };
-static int mt7622_pwm_ch4_3_funcs[] = { 0, };
-static int mt7622_pwm_ch5_0_pins[] = { 68, };
-static int mt7622_pwm_ch5_0_funcs[] = { 3, };
-static int mt7622_pwm_ch5_1_pins[] = { 77, };
-static int mt7622_pwm_ch5_1_funcs[] = { 4, };
-static int mt7622_pwm_ch5_2_pins[] = { 99, };
-static int mt7622_pwm_ch5_2_funcs[] = { 0, };
-static int mt7622_pwm_ch6_0_pins[] = { 69, };
-static int mt7622_pwm_ch6_0_funcs[] = { 3, };
-static int mt7622_pwm_ch6_1_pins[] = { 78, };
-static int mt7622_pwm_ch6_1_funcs[] = { 4, };
-static int mt7622_pwm_ch6_2_pins[] = { 81, };
-static int mt7622_pwm_ch6_2_funcs[] = { 4, };
-static int mt7622_pwm_ch6_3_pins[] = { 100, };
-static int mt7622_pwm_ch6_3_funcs[] = { 0, };
-static int mt7622_pwm_ch7_0_pins[] = { 70, };
-static int mt7622_pwm_ch7_0_funcs[] = { 3, };
-static int mt7622_pwm_ch7_1_pins[] = { 82, };
-static int mt7622_pwm_ch7_1_funcs[] = { 4, };
-static int mt7622_pwm_ch7_2_pins[] = { 101, };
-static int mt7622_pwm_ch7_2_funcs[] = { 0, };
+static const int mt7622_pwm_ch1_0_pins[] = { 51, };
+static const int mt7622_pwm_ch1_0_funcs[] = { 3, };
+static const int mt7622_pwm_ch1_1_pins[] = { 73, };
+static const int mt7622_pwm_ch1_1_funcs[] = { 4, };
+static const int mt7622_pwm_ch1_2_pins[] = { 95, };
+static const int mt7622_pwm_ch1_2_funcs[] = { 0, };
+static const int mt7622_pwm_ch2_0_pins[] = { 52, };
+static const int mt7622_pwm_ch2_0_funcs[] = { 3, };
+static const int mt7622_pwm_ch2_1_pins[] = { 74, };
+static const int mt7622_pwm_ch2_1_funcs[] = { 4, };
+static const int mt7622_pwm_ch2_2_pins[] = { 96, };
+static const int mt7622_pwm_ch2_2_funcs[] = { 0, };
+static const int mt7622_pwm_ch3_0_pins[] = { 53, };
+static const int mt7622_pwm_ch3_0_funcs[] = { 3, };
+static const int mt7622_pwm_ch3_1_pins[] = { 75, };
+static const int mt7622_pwm_ch3_1_funcs[] = { 4, };
+static const int mt7622_pwm_ch3_2_pins[] = { 97, };
+static const int mt7622_pwm_ch3_2_funcs[] = { 0, };
+static const int mt7622_pwm_ch4_0_pins[] = { 54, };
+static const int mt7622_pwm_ch4_0_funcs[] = { 3, };
+static const int mt7622_pwm_ch4_1_pins[] = { 67, };
+static const int mt7622_pwm_ch4_1_funcs[] = { 3, };
+static const int mt7622_pwm_ch4_2_pins[] = { 76, };
+static const int mt7622_pwm_ch4_2_funcs[] = { 4, };
+static const int mt7622_pwm_ch4_3_pins[] = { 98, };
+static const int mt7622_pwm_ch4_3_funcs[] = { 0, };
+static const int mt7622_pwm_ch5_0_pins[] = { 68, };
+static const int mt7622_pwm_ch5_0_funcs[] = { 3, };
+static const int mt7622_pwm_ch5_1_pins[] = { 77, };
+static const int mt7622_pwm_ch5_1_funcs[] = { 4, };
+static const int mt7622_pwm_ch5_2_pins[] = { 99, };
+static const int mt7622_pwm_ch5_2_funcs[] = { 0, };
+static const int mt7622_pwm_ch6_0_pins[] = { 69, };
+static const int mt7622_pwm_ch6_0_funcs[] = { 3, };
+static const int mt7622_pwm_ch6_1_pins[] = { 78, };
+static const int mt7622_pwm_ch6_1_funcs[] = { 4, };
+static const int mt7622_pwm_ch6_2_pins[] = { 81, };
+static const int mt7622_pwm_ch6_2_funcs[] = { 4, };
+static const int mt7622_pwm_ch6_3_pins[] = { 100, };
+static const int mt7622_pwm_ch6_3_funcs[] = { 0, };
+static const int mt7622_pwm_ch7_0_pins[] = { 70, };
+static const int mt7622_pwm_ch7_0_funcs[] = { 3, };
+static const int mt7622_pwm_ch7_1_pins[] = { 82, };
+static const int mt7622_pwm_ch7_1_funcs[] = { 4, };
+static const int mt7622_pwm_ch7_2_pins[] = { 101, };
+static const int mt7622_pwm_ch7_2_funcs[] = { 0, };
 
 /* SD */
-static int mt7622_sd_0_pins[] = { 16, 17, 18, 19, 20, 21, };
-static int mt7622_sd_0_funcs[] = { 2, 2, 2, 2, 2, 2, };
-static int mt7622_sd_1_pins[] = { 25, 26, 27, 28, 29, 30, };
-static int mt7622_sd_1_funcs[] = { 2, 2, 2, 2, 2, 2, };
+static const int mt7622_sd_0_pins[] = { 16, 17, 18, 19, 20, 21, };
+static const int mt7622_sd_0_funcs[] = { 2, 2, 2, 2, 2, 2, };
+static const int mt7622_sd_1_pins[] = { 25, 26, 27, 28, 29, 30, };
+static const int mt7622_sd_1_funcs[] = { 2, 2, 2, 2, 2, 2, };
 
 /* Serial NAND */
-static int mt7622_snfi_pins[] = { 8, 9, 10, 11, 12, 13, };
-static int mt7622_snfi_funcs[] = { 2, 2, 2, 2, 2, 2, };
+static const int mt7622_snfi_pins[] = { 8, 9, 10, 11, 12, 13, };
+static const int mt7622_snfi_funcs[] = { 2, 2, 2, 2, 2, 2, };
 
 /* SPI NOR */
-static int mt7622_spi_pins[] = { 8, 9, 10, 11, 12, 13 };
-static int mt7622_spi_funcs[] = { 0, 0, 0, 0, 0, 0, };
+static const int mt7622_spi_pins[] = { 8, 9, 10, 11, 12, 13 };
+static const int mt7622_spi_funcs[] = { 0, 0, 0, 0, 0, 0, };
 
 /* SPIC */
-static int mt7622_spic0_0_pins[] = { 63, 64, 65, 66, };
-static int mt7622_spic0_0_funcs[] = { 4, 4, 4, 4, };
-static int mt7622_spic0_1_pins[] = { 79, 80, 81, 82, };
-static int mt7622_spic0_1_funcs[] = { 3, 3, 3, 3, };
-static int mt7622_spic1_0_pins[] = { 67, 68, 69, 70, };
-static int mt7622_spic1_0_funcs[] = { 4, 4, 4, 4, };
-static int mt7622_spic1_1_pins[] = { 73, 74, 75, 76, };
-static int mt7622_spic1_1_funcs[] = { 0, 0, 0, 0, };
-static int mt7622_spic2_0_pins[] = { 10, 11, 12, 13, };
-static int mt7622_spic2_0_funcs[] = { 0, 0, 0, 0, };
-static int mt7622_spic2_0_wp_hold_pins[] = { 8, 9, };
-static int mt7622_spic2_0_wp_hold_funcs[] = { 0, 0, };
+static const int mt7622_spic0_0_pins[] = { 63, 64, 65, 66, };
+static const int mt7622_spic0_0_funcs[] = { 4, 4, 4, 4, };
+static const int mt7622_spic0_1_pins[] = { 79, 80, 81, 82, };
+static const int mt7622_spic0_1_funcs[] = { 3, 3, 3, 3, };
+static const int mt7622_spic1_0_pins[] = { 67, 68, 69, 70, };
+static const int mt7622_spic1_0_funcs[] = { 4, 4, 4, 4, };
+static const int mt7622_spic1_1_pins[] = { 73, 74, 75, 76, };
+static const int mt7622_spic1_1_funcs[] = { 0, 0, 0, 0, };
+static const int mt7622_spic2_0_pins[] = { 10, 11, 12, 13, };
+static const int mt7622_spic2_0_funcs[] = { 0, 0, 0, 0, };
+static const int mt7622_spic2_0_wp_hold_pins[] = { 8, 9, };
+static const int mt7622_spic2_0_wp_hold_funcs[] = { 0, 0, };
 
 /* TDM */
-static int mt7622_tdm_0_out_mclk_bclk_ws_pins[] = { 8, 9, 10, };
-static int mt7622_tdm_0_out_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
-static int mt7622_tdm_0_in_mclk_bclk_ws_pins[] = { 11, 12, 13, };
-static int mt7622_tdm_0_in_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
-static int mt7622_tdm_0_out_data_pins[] = { 20, };
-static int mt7622_tdm_0_out_data_funcs[] = { 3, };
-static int mt7622_tdm_0_in_data_pins[] = { 21, };
-static int mt7622_tdm_0_in_data_funcs[] = { 3, };
-static int mt7622_tdm_1_out_mclk_bclk_ws_pins[] = { 57, 58, 59, };
-static int mt7622_tdm_1_out_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
-static int mt7622_tdm_1_in_mclk_bclk_ws_pins[] = { 60, 61, 62, };
-static int mt7622_tdm_1_in_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
-static int mt7622_tdm_1_out_data_pins[] = { 55, };
-static int mt7622_tdm_1_out_data_funcs[] = { 3, };
-static int mt7622_tdm_1_in_data_pins[] = { 56, };
-static int mt7622_tdm_1_in_data_funcs[] = { 3, };
+static const int mt7622_tdm_0_out_mclk_bclk_ws_pins[] = { 8, 9, 10, };
+static const int mt7622_tdm_0_out_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
+static const int mt7622_tdm_0_in_mclk_bclk_ws_pins[] = { 11, 12, 13, };
+static const int mt7622_tdm_0_in_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
+static const int mt7622_tdm_0_out_data_pins[] = { 20, };
+static const int mt7622_tdm_0_out_data_funcs[] = { 3, };
+static const int mt7622_tdm_0_in_data_pins[] = { 21, };
+static const int mt7622_tdm_0_in_data_funcs[] = { 3, };
+static const int mt7622_tdm_1_out_mclk_bclk_ws_pins[] = { 57, 58, 59, };
+static const int mt7622_tdm_1_out_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
+static const int mt7622_tdm_1_in_mclk_bclk_ws_pins[] = { 60, 61, 62, };
+static const int mt7622_tdm_1_in_mclk_bclk_ws_funcs[] = { 3, 3, 3, };
+static const int mt7622_tdm_1_out_data_pins[] = { 55, };
+static const int mt7622_tdm_1_out_data_funcs[] = { 3, };
+static const int mt7622_tdm_1_in_data_pins[] = { 56, };
+static const int mt7622_tdm_1_in_data_funcs[] = { 3, };
 
 /* UART */
-static int mt7622_uart0_0_tx_rx_pins[] = { 6, 7, };
-static int mt7622_uart0_0_tx_rx_funcs[] = { 0, 0, };
-static int mt7622_uart1_0_tx_rx_pins[] = { 55, 56, };
-static int mt7622_uart1_0_tx_rx_funcs[] = { 2, 2, };
-static int mt7622_uart1_0_rts_cts_pins[] = { 57, 58, };
-static int mt7622_uart1_0_rts_cts_funcs[] = { 2, 2, };
-static int mt7622_uart1_1_tx_rx_pins[] = { 73, 74, };
-static int mt7622_uart1_1_tx_rx_funcs[] = { 2, 2, };
-static int mt7622_uart1_1_rts_cts_pins[] = { 75, 76, };
-static int mt7622_uart1_1_rts_cts_funcs[] = { 2, 2, };
-static int mt7622_uart2_0_tx_rx_pins[] = { 3, 4, };
-static int mt7622_uart2_0_tx_rx_funcs[] = { 2, 2, };
-static int mt7622_uart2_0_rts_cts_pins[] = { 1, 2, };
-static int mt7622_uart2_0_rts_cts_funcs[] = { 2, 2, };
-static int mt7622_uart2_1_tx_rx_pins[] = { 51, 52, };
-static int mt7622_uart2_1_tx_rx_funcs[] = { 0, 0, };
-static int mt7622_uart2_1_rts_cts_pins[] = { 53, 54, };
-static int mt7622_uart2_1_rts_cts_funcs[] = { 0, 0, };
-static int mt7622_uart2_2_tx_rx_pins[] = { 59, 60, };
-static int mt7622_uart2_2_tx_rx_funcs[] = { 4, 4, };
-static int mt7622_uart2_2_rts_cts_pins[] = { 61, 62, };
-static int mt7622_uart2_2_rts_cts_funcs[] = { 4, 4, };
-static int mt7622_uart2_3_tx_rx_pins[] = { 95, 96, };
-static int mt7622_uart2_3_tx_rx_funcs[] = { 3, 3, };
-static int mt7622_uart3_0_tx_rx_pins[] = { 57, 58, };
-static int mt7622_uart3_0_tx_rx_funcs[] = { 5, 5, };
-static int mt7622_uart3_1_tx_rx_pins[] = { 81, 82, };
-static int mt7622_uart3_1_tx_rx_funcs[] = { 0, 0, };
-static int mt7622_uart3_1_rts_cts_pins[] = { 79, 80, };
-static int mt7622_uart3_1_rts_cts_funcs[] = { 0, 0, };
-static int mt7622_uart4_0_tx_rx_pins[] = { 61, 62, };
-static int mt7622_uart4_0_tx_rx_funcs[] = { 5, 5, };
-static int mt7622_uart4_1_tx_rx_pins[] = { 91, 92, };
-static int mt7622_uart4_1_tx_rx_funcs[] = { 0, 0, };
-static int mt7622_uart4_1_rts_cts_pins[] = { 93, 94 };
-static int mt7622_uart4_1_rts_cts_funcs[] = { 0, 0, };
-static int mt7622_uart4_2_tx_rx_pins[] = { 97, 98, };
-static int mt7622_uart4_2_tx_rx_funcs[] = { 2, 2, };
-static int mt7622_uart4_2_rts_cts_pins[] = { 95, 96 };
-static int mt7622_uart4_2_rts_cts_funcs[] = { 2, 2, };
+static const int mt7622_uart0_0_tx_rx_pins[] = { 6, 7, };
+static const int mt7622_uart0_0_tx_rx_funcs[] = { 0, 0, };
+static const int mt7622_uart1_0_tx_rx_pins[] = { 55, 56, };
+static const int mt7622_uart1_0_tx_rx_funcs[] = { 2, 2, };
+static const int mt7622_uart1_0_rts_cts_pins[] = { 57, 58, };
+static const int mt7622_uart1_0_rts_cts_funcs[] = { 2, 2, };
+static const int mt7622_uart1_1_tx_rx_pins[] = { 73, 74, };
+static const int mt7622_uart1_1_tx_rx_funcs[] = { 2, 2, };
+static const int mt7622_uart1_1_rts_cts_pins[] = { 75, 76, };
+static const int mt7622_uart1_1_rts_cts_funcs[] = { 2, 2, };
+static const int mt7622_uart2_0_tx_rx_pins[] = { 3, 4, };
+static const int mt7622_uart2_0_tx_rx_funcs[] = { 2, 2, };
+static const int mt7622_uart2_0_rts_cts_pins[] = { 1, 2, };
+static const int mt7622_uart2_0_rts_cts_funcs[] = { 2, 2, };
+static const int mt7622_uart2_1_tx_rx_pins[] = { 51, 52, };
+static const int mt7622_uart2_1_tx_rx_funcs[] = { 0, 0, };
+static const int mt7622_uart2_1_rts_cts_pins[] = { 53, 54, };
+static const int mt7622_uart2_1_rts_cts_funcs[] = { 0, 0, };
+static const int mt7622_uart2_2_tx_rx_pins[] = { 59, 60, };
+static const int mt7622_uart2_2_tx_rx_funcs[] = { 4, 4, };
+static const int mt7622_uart2_2_rts_cts_pins[] = { 61, 62, };
+static const int mt7622_uart2_2_rts_cts_funcs[] = { 4, 4, };
+static const int mt7622_uart2_3_tx_rx_pins[] = { 95, 96, };
+static const int mt7622_uart2_3_tx_rx_funcs[] = { 3, 3, };
+static const int mt7622_uart3_0_tx_rx_pins[] = { 57, 58, };
+static const int mt7622_uart3_0_tx_rx_funcs[] = { 5, 5, };
+static const int mt7622_uart3_1_tx_rx_pins[] = { 81, 82, };
+static const int mt7622_uart3_1_tx_rx_funcs[] = { 0, 0, };
+static const int mt7622_uart3_1_rts_cts_pins[] = { 79, 80, };
+static const int mt7622_uart3_1_rts_cts_funcs[] = { 0, 0, };
+static const int mt7622_uart4_0_tx_rx_pins[] = { 61, 62, };
+static const int mt7622_uart4_0_tx_rx_funcs[] = { 5, 5, };
+static const int mt7622_uart4_1_tx_rx_pins[] = { 91, 92, };
+static const int mt7622_uart4_1_tx_rx_funcs[] = { 0, 0, };
+static const int mt7622_uart4_1_rts_cts_pins[] = { 93, 94 };
+static const int mt7622_uart4_1_rts_cts_funcs[] = { 0, 0, };
+static const int mt7622_uart4_2_tx_rx_pins[] = { 97, 98, };
+static const int mt7622_uart4_2_tx_rx_funcs[] = { 2, 2, };
+static const int mt7622_uart4_2_rts_cts_pins[] = { 95, 96 };
+static const int mt7622_uart4_2_rts_cts_funcs[] = { 2, 2, };
 
 /* Watchdog */
-static int mt7622_watchdog_pins[] = { 78, };
-static int mt7622_watchdog_funcs[] = { 0, };
+static const int mt7622_watchdog_pins[] = { 78, };
+static const int mt7622_watchdog_funcs[] = { 0, };
 
 /* WLAN LED */
-static int mt7622_wled_pins[] = { 85, };
-static int mt7622_wled_funcs[] = { 0, };
+static const int mt7622_wled_pins[] = { 85, };
+static const int mt7622_wled_funcs[] = { 0, };
 
 static const struct mtk_group_desc mt7622_groups[] = {
 	PINCTRL_PIN_GROUP("emmc", mt7622_emmc),
@@ -719,7 +721,7 @@ static const struct mtk_function_desc mt7622_functions[] = {
 	{"watchdog", mt7622_wdt_groups, ARRAY_SIZE(mt7622_wdt_groups)},
 };
 
-static struct mtk_pinctrl_soc mt7622_data = {
+static const struct mtk_pinctrl_soc mt7622_data = {
 	.name = "mt7622_pinctrl",
 	.reg_cal = mt7622_reg_cals,
 	.pins = mt7622_pins,
drivers/pinctrl/mediatek/pinctrl-mt7623.c +325 -325

709 lines not on this page · raw message

drivers/pinctrl/mediatek/pinctrl-mt7629.c +87 -87

212 lines not on this page · raw message

drivers/pinctrl/mediatek/pinctrl-mt7981.c +137 -133

386 lines not on this page · raw message

drivers/pinctrl/mediatek/pinctrl-mt7986.c +74 -71

195 lines not on this page · raw message

drivers/pinctrl/mediatek/pinctrl-mt8512.c +12 -12
index 3d9c0abe36..bc5fb83ac6 100644
@@ -315,12 +315,12 @@ static const struct mtk_pin_desc mt8512_pins[] = {
  */
 
 /* UART */
-static int mt8512_uart0_0_rxd_txd_pins[]		= { 52, 53, };
-static int mt8512_uart0_0_rxd_txd_funcs[]		= {  1,  1, };
-static int mt8512_uart1_0_rxd_txd_pins[]		= { 54, 55, };
-static int mt8512_uart1_0_rxd_txd_funcs[]		= {  1,  1, };
-static int mt8512_uart2_0_rxd_txd_pins[]		= { 28, 29, };
-static int mt8512_uart2_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8512_uart0_0_rxd_txd_pins[]		= { 52, 53, };
+static const int mt8512_uart0_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8512_uart1_0_rxd_txd_pins[]		= { 54, 55, };
+static const int mt8512_uart1_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8512_uart2_0_rxd_txd_pins[]		= { 28, 29, };
+static const int mt8512_uart2_0_rxd_txd_funcs[]		= {  1,  1, };
 
 /* Joint those groups owning the same capability in user point of view which
  * allows that people tend to use through the device tree.
@@ -330,13 +330,13 @@ static const char *const mt8512_uart_groups[] = { "uart0_0_rxd_txd",
 						"uart2_0_rxd_txd", };
 
 /* SNAND */
-static int mt8512_snfi_pins[] = { 71, 76, 77, 78, 79, 80, };
-static int mt8512_snfi_funcs[] = { 3, 3, 3, 3, 3, 3, };
+static const int mt8512_snfi_pins[] = { 71, 76, 77, 78, 79, 80, };
+static const int mt8512_snfi_funcs[] = { 3, 3, 3, 3, 3, 3, };
 
 /* MMC0 */
-static int mt8512_msdc0_pins[] = { 76, 77, 78, 79, 80, 81, 82, 83, 84,
-				   85, 86, };
-static int mt8512_msdc0_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
+static const int mt8512_msdc0_pins[] = { 76, 77, 78, 79, 80, 81, 82, 83, 84,
+					 85, 86, };
+static const int mt8512_msdc0_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
 
 static const struct mtk_group_desc mt8512_groups[] = {
 	PINCTRL_PIN_GROUP("uart0_0_rxd_txd", mt8512_uart0_0_rxd_txd),
@@ -356,7 +356,7 @@ static const struct mtk_function_desc mt8512_functions[] = {
 	{"snand", mt8512_msdc_groups, ARRAY_SIZE(mt8512_msdc_groups)},
 };
 
-static struct mtk_pinctrl_soc mt8512_data = {
+static const struct mtk_pinctrl_soc mt8512_data = {
 	.name = "mt8512_pinctrl",
 	.reg_cal = mt8512_reg_cals,
 	.pins = mt8512_pins,
drivers/pinctrl/mediatek/pinctrl-mt8516.c +9 -9
index 6f94f762d9..7487d6f060 100644
@@ -326,12 +326,12 @@ static const struct mtk_pin_desc mt8516_pins[] = {
  */
 
 /* UART */
-static int mt8516_uart0_0_rxd_txd_pins[]		= { 62, 63, };
-static int mt8516_uart0_0_rxd_txd_funcs[]		= {  1,  1, };
-static int mt8516_uart1_0_rxd_txd_pins[]		= { 64, 65, };
-static int mt8516_uart1_0_rxd_txd_funcs[]		= {  1,  1, };
-static int mt8516_uart2_0_rxd_txd_pins[]		= { 34, 35, };
-static int mt8516_uart2_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8516_uart0_0_rxd_txd_pins[]		= { 62, 63, };
+static const int mt8516_uart0_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8516_uart1_0_rxd_txd_pins[]		= { 64, 65, };
+static const int mt8516_uart1_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8516_uart2_0_rxd_txd_pins[]		= { 34, 35, };
+static const int mt8516_uart2_0_rxd_txd_funcs[]		= {  1,  1, };
 
 /* Joint those groups owning the same capability in user point of view which
  * allows that people tend to use through the device tree.
@@ -341,9 +341,9 @@ static const char *const mt8516_uart_groups[] = { "uart0_0_rxd_txd",
 						"uart2_0_rxd_txd", };
 
 /* MMC0 */
-static int mt8516_msdc0_pins[] = { 110, 111, 112, 113, 114, 115, 116, 117, 118,
-				   119, 120, };
-static int mt8516_msdc0_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
+static const int mt8516_msdc0_pins[] = { 110, 111, 112, 113, 114, 115, 116, 117,
+					 118, 119, 120, };
+static const int mt8516_msdc0_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
 
 static const struct mtk_group_desc mt8516_groups[] = {
 	PINCTRL_PIN_GROUP("uart0_0_rxd_txd", mt8516_uart0_0_rxd_txd),
drivers/pinctrl/mediatek/pinctrl-mt8518.c +10 -10
index ed51bd3bbc..66fcfdff14 100644
@@ -346,12 +346,12 @@ static const struct mtk_pin_desc mt8518_pins[] = {
  */
 
 /* UART */
-static int mt8518_uart0_0_rxd_txd_pins[]		= { 104, 105, };
-static int mt8518_uart0_0_rxd_txd_funcs[]		= {  1,  1, };
-static int mt8518_uart1_0_rxd_txd_pins[]		= { 52, 53, };
-static int mt8518_uart1_0_rxd_txd_funcs[]		= {  1,  1, };
-static int mt8518_uart2_0_rxd_txd_pins[]		= { 106, 107, };
-static int mt8518_uart2_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8518_uart0_0_rxd_txd_pins[]		= { 104, 105, };
+static const int mt8518_uart0_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8518_uart1_0_rxd_txd_pins[]		= { 52, 53, };
+static const int mt8518_uart1_0_rxd_txd_funcs[]		= {  1,  1, };
+static const int mt8518_uart2_0_rxd_txd_pins[]		= { 106, 107, };
+static const int mt8518_uart2_0_rxd_txd_funcs[]		= {  1,  1, };
 
 /* Joint those groups owning the same capability in user point of view which
  * allows that people tend to use through the device tree.
@@ -361,9 +361,9 @@ static const char *const mt8518_uart_groups[] = { "uart0_0_rxd_txd",
 						"uart2_0_rxd_txd", };
 
 /* MMC0 */
-static int mt8518_msdc0_pins[] = { 3, 4, 5, 6, 7, 8, 9, 10, 11,
-				   12, 13, };
-static int mt8518_msdc0_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
+static const int mt8518_msdc0_pins[] = { 3, 4, 5, 6, 7, 8, 9, 10, 11,
+					 12, 13, };
+static const int mt8518_msdc0_funcs[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, };
 
 static const struct mtk_group_desc mt8518_groups[] = {
 	PINCTRL_PIN_GROUP("uart0_0_rxd_txd", mt8518_uart0_0_rxd_txd),
@@ -380,7 +380,7 @@ static const struct mtk_function_desc mt8518_functions[] = {
 	{"msdc", mt8518_msdc_groups, ARRAY_SIZE(mt8518_msdc_groups)},
 };
 
-static struct mtk_pinctrl_soc mt8518_data = {
+static const struct mtk_pinctrl_soc mt8518_data = {
 	.name = "mt8518_pinctrl",
 	.reg_cal = mt8518_reg_cals,
 	.pins = mt8518_pins,
drivers/pinctrl/mediatek/pinctrl-mtk-common.c +2 -2
index 5a4d58b327..1caca3496c 100644
@@ -314,7 +314,7 @@ static int mtk_pinmux_group_set(struct udevice *dev,
 	int i;
 
 	for (i = 0; i < grp->num_pins; i++) {
-		int *pin_modes = grp->data;
+		const int *pin_modes = grp->data;
 
 		mtk_hw_set_value(dev, grp->pins[i], PINCTRL_PIN_REG_MODE,
 				 pin_modes[i]);
@@ -769,7 +769,7 @@ static int mtk_gpiochip_register(struct udevice *parent)
 #endif
 
 int mtk_pinctrl_common_probe(struct udevice *dev,
-			     struct mtk_pinctrl_soc *soc)
+			     const struct mtk_pinctrl_soc *soc)
 {
 	struct mtk_pinctrl_priv *priv = dev_get_priv(dev);
 	int ret = 0;
drivers/pinctrl/mediatek/pinctrl-mtk-common.h +4 -4
index 0d9596fa72..c948b80843 100644
@@ -174,9 +174,9 @@ struct mtk_pin_desc {
  */
 struct mtk_group_desc {
 	const char *name;
-	int *pins;
+	const int *pins;
 	int num_pins;
-	void *data;
+	const void *data;
 };
 
 /**
@@ -233,7 +233,7 @@ struct mtk_pinctrl_soc {
  */
 struct mtk_pinctrl_priv {
 	void __iomem *base[MAX_BASE_CALC];
-	struct mtk_pinctrl_soc *soc;
+	const struct mtk_pinctrl_soc *soc;
 };
 
 extern const struct pinctrl_ops mtk_pinctrl_ops;
@@ -242,7 +242,7 @@ extern const struct pinctrl_ops mtk_pinctrl_ops;
 void mtk_rmw(struct udevice *dev, u32 reg, u32 mask, u32 set);
 void mtk_i_rmw(struct udevice *dev, u8 i, u32 reg, u32 mask, u32 set);
 int mtk_pinctrl_common_probe(struct udevice *dev,
-			     struct mtk_pinctrl_soc *soc);
+			     const struct mtk_pinctrl_soc *soc);
 
 #if CONFIG_IS_ENABLED(PINCONF)
 
Signature · 1 line
2.17.1
#28 lore raw

Re: Aw: [PATCH 21/29] arm: dts: medaitek: convert gmac link mode to 2500base-x

In reply to Frank Wunderlich
Quoted 28 lines · Frank Wunderlich

Hi

Quoted 4 lines

Gesendet: Mittwoch, 19. Juli 2023 um 11:17 Uhr
Von: "Weijie Gao" <[email protected]>
An: [email protected]
Cc: "GSS_MTK_Uboot_upstream" <[email protected]>,

"Daniel Golle" <[email protected]>, "Frank Wunderlich" < [email protected]>, "Weijie Gao" <[email protected]>

Quoted 1 line

Betreff: [PATCH 21/29] arm: dts: medaitek: convert gmac link mode

to 2500base-x

Quoted 6 lines

Now that individual 2.5Gbps SGMII support has been added to mtk-eth, all boards that use 2.5Gbps link with mt7531 must be converted to use "2500base-x" instead of "sgmii".

Quoted 11 lines
---
 arch/arm/dts/mt7622-bananapi-bpi-r64.dts | 4 ++--
 arch/arm/dts/mt7622-rfb.dts              | 4 ++--
 arch/arm/dts/mt7629-rfb.dts              | 4 ++--
 arch/arm/dts/mt7981-emmc-rfb.dts         | 4 ++--
 arch/arm/dts/mt7981-rfb.dts              | 4 ++--
 arch/arm/dts/mt7981-sd-rfb.dts           | 4 ++--
 arch/arm/dts/mt7986a-rfb.dts             | 4 ++--
 arch/arm/dts/mt7986a-sd-rfb.dts          | 4 ++--
 arch/arm/dts/mt7986b-rfb.dts             | 4 ++--
 arch/arm/dts/mt7986b-sd-rfb.dts          | 4 ++--
Quoted 2 lines

you miss arch/arm/dts/mt7986a-bpi-r3-sd.dts here which was added in 2023.07

Oh. I'll add it in v2.

Quoted 15 lines

i tested series on Bananapi-R4/mt7988, sdcard and network-support (many thx for this) works so far (not tested i2c, spi and others yet), also have not done tests on my other boards yet.

noticed some build-warnings from the pinctrl-patch which are not critical, but should be fixed.

e.g. this (seems for each call of PINCTRL_PIN_GROUP)

drivers/pinctrl/mediatek/pinctrl-mt7988.c:1148:42: warning:
initialization discards 'const' qualifier from pointer target type [- Wdiscarded-qualifiers]
1148 | PINCTRL_PIN_GROUP("net_wo1_uart_txd_1",
mt7988_net_wo1_uart_txd_1),

Quoted 7 lines
      |                                          ^~~~~~~~~~~~~~~~~~~~
~~~~~
drivers/pinctrl/mediatek/pinctrl-mtk-common.h:31:3: note: in
definition of macro 'PINCTRL_PIN_GROUP'
   31 |   id##_funcs,      \
      |   ^~

This is due to on of the patch was missing because its size exceeds 100KB. Please refer to:

https://patchwork.ozlabs.org/project/uboot/patch/7c0cfbdeb17abcf805138eb69be583d5a068231b.1689756363.git.weijie.gao@mediatek.com/

I have to split it into two patches in v2.

Quoted 2 lines

regards Frank

#29 lore raw

Aw: Re: [PATCH 21/29] arm: dts: medaitek: convert gmac link mode to 2500base-x

Gesendet: Donnerstag, 20. Juli 2023 um 02:58 Uhr
Von: "Weijie Gao (高惟杰)" <[email protected]>

Quoted 19 lines
Quoted 12 lines · Frank Wunderlich

noticed some build-warnings from the pinctrl-patch which are not critical, but should be fixed.

e.g. this (seems for each call of PINCTRL_PIN_GROUP)

drivers/pinctrl/mediatek/pinctrl-mt7988.c:1148:42: warning:
initialization discards 'const' qualifier from pointer target type [- Wdiscarded-qualifiers]
1148 | PINCTRL_PIN_GROUP("net_wo1_uart_txd_1",
mt7988_net_wo1_uart_txd_1),

Quoted 6 lines
      |                                          ^~~~~~~~~~~~~~~~~~~~
~~~~~
drivers/pinctrl/mediatek/pinctrl-mtk-common.h:31:3: note: in
definition of macro 'PINCTRL_PIN_GROUP'
   31 |   id##_funcs,      \
      |   ^~
Quoted 5 lines

This is due to on of the patch was missing because its size exceeds 100KB. Please refer to:
https://patchwork.ozlabs.org/project/uboot/patch/7c0cfbdeb17abcf805138eb69be583d5a068231b.1689756363.git.weijie.gao@mediatek.com/

I have to split it into two patches in v2.

indeed, part 12 was missing in my series-export from patchwork...all clean after applying it. thx for pointing to it.

regards Frank

#38 lore raw
In reply to Weijie Gao
Quoted 8 lines · Weijie Gao

This patch series add support for MediaTek MT7988 SoC with its reference boards and related drivers.

This patch series add basic boot support on eMMC/SD/SPI-NOR/SPI-NAND for these boards. The clock, pinctrl drivers and the SoC initializaton code are also included.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
Reviewed-by on v1 7/29
#11 lore raw

Re: [PATCH 07/29] i2c: mediatek: fix I2C usability for MT7981

In reply to Weijie Gao

Hello Weijie Gao

Quoted 9 lines · Weijie Gao

MT7981 actually uses MediaTek I2C controller v3 instead of v1. This patch adds support for I2C controller v3 fix fixes the I2C usability for MT7981.

---
 drivers/i2c/mtk_i2c.c | 45 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]