Skip to contentSkip to conversation

Add support for MediaTek MT7621 SoC

PATCH Superseded Weijie Gao 4 participants 23 messages Nov 19, 2021 – Dec 31, 2021

Subsystems (15)

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Weijie Gao

author
#0 lore raw

v2 cover Add support for MediaTek MT7621 SoC

This series will add support for MediaTek MT7621 SoC with two reference boards and related drivers.

The MediaTek MT7621 is a network processor integrating a dual-core dual-threaded MIPS 1004Kc processor running at a normal frequency of 880MHz. This chip can be found in many wireless routers.

This series add all basic drivers which are useful in u-boot, like usb, sdxc, ethernet, spi, nand and serial.

Currently this patch series only supports building the ram-bootable image as it needs the preloader from MediaTek SDK.

Thanks,
Weijie

v2 changes:
- Add a kconfig for max supported ram size
- Remove network configs from default config file
- Add config file for mt7621-rfb boards

Weijie Gao (14):
mips: mtmips: add support for MediaTek MT7621 SoC
mips: mtmips: add two reference boards for mt7621
clk: mtmips: add clock driver for MediaTek MT7621 SoC
reset: mtmips: add reset controller support for MediaTek MT7621 SoC
pinctrl: mtmips: add support for MediaTek MT7621 SoC
nand: raw: add support for MediaTek MT7621 SoC
usb: xhci-mtk: add support for MediaTek MT7621 SoC
phy: mtk-tphy: add support for MediaTek MT7621 SoC
spi: add support for MediaTek MT7621 SoC
gpio: add support for MediaTek MT7621 SoC
watchdog: add support for MediaTek MT7621 SoC
mmc: mediatek: add support for MediaTek MT7621 SoC
net: mediatek: add support for MediaTek MT7621 SoC
MAINTAINERS: update maintainer for MediaTek MIPS platform

 MAINTAINERS                                   |    5 +
 arch/mips/dts/Makefile                        |    2 +
 arch/mips/dts/mediatek,mt7621-nand-rfb.dts    |   52 +
 arch/mips/dts/mediatek,mt7621-rfb.dts         |   68 +
 arch/mips/dts/mt7621.dtsi                     |  372 ++++++
 arch/mips/mach-mtmips/Kconfig                 |   34 +-
 arch/mips/mach-mtmips/Makefile                |    5 +
 arch/mips/mach-mtmips/cpu.c                   |    2 +-
 arch/mips/mach-mtmips/mt7621/Kconfig          |   43 +
 arch/mips/mach-mtmips/mt7621/Makefile         |    5 +
 arch/mips/mach-mtmips/mt7621/compat.c         |   21 +
 arch/mips/mach-mtmips/mt7621/init.c           |  156 +++
 arch/mips/mach-mtmips/mt7621/mt7621.h         |  204 +++
 arch/mips/mach-mtmips/mt7621/serial.c         |   23 +
 board/mediatek/mt7621/MAINTAINERS             |    9 +
 board/mediatek/mt7621/Makefile                |    3 +
 board/mediatek/mt7621/board.c                 |    6 +
 configs/mt7621_nand_rfb_ramboot_defconfig     |   72 +
 configs/mt7621_rfb_ramboot_defconfig          |   75 ++
 drivers/clk/mtmips/Makefile                   |    1 +
 drivers/clk/mtmips/clk-mt7621.c               |  260 ++++
 drivers/gpio/Kconfig                          |    2 +-
 drivers/mmc/mtk-sd.c                          |   13 +
 drivers/mtd/nand/raw/Kconfig                  |   11 +
 drivers/mtd/nand/raw/Makefile                 |    1 +
 drivers/mtd/nand/raw/mt7621_nand.c            | 1189 +++++++++++++++++
 drivers/net/mtk_eth.c                         |   27 +-
 drivers/net/mtk_eth.h                         |    8 +
 drivers/phy/Kconfig                           |    2 +-
 drivers/pinctrl/mtmips/Kconfig                |    9 +
 drivers/pinctrl/mtmips/Makefile               |    1 +
 drivers/pinctrl/mtmips/pinctrl-mt7621.c       |  307 +++++
 .../pinctrl/mtmips/pinctrl-mtmips-common.c    |    4 +-
 .../pinctrl/mtmips/pinctrl-mtmips-common.h    |   12 +
 drivers/spi/Kconfig                           |    2 +-
 drivers/usb/host/Kconfig                      |    2 +-
 drivers/watchdog/Kconfig                      |    2 +-
 include/configs/mt7621-rfb.h                  |   18 +
 include/configs/mt7621.h                      |   36 +
 include/dt-bindings/clock/mt7621-clk.h        |   42 +
 include/dt-bindings/reset/mt7621-reset.h      |   38 +
 41 files changed, 3126 insertions(+), 18 deletions(-)
 create mode 100644 arch/mips/dts/mediatek,mt7621-nand-rfb.dts
 create mode 100644 arch/mips/dts/mediatek,mt7621-rfb.dts
 create mode 100644 arch/mips/dts/mt7621.dtsi
 create mode 100644 arch/mips/mach-mtmips/mt7621/Kconfig
 create mode 100644 arch/mips/mach-mtmips/mt7621/Makefile
 create mode 100644 arch/mips/mach-mtmips/mt7621/compat.c
 create mode 100644 arch/mips/mach-mtmips/mt7621/init.c
 create mode 100644 arch/mips/mach-mtmips/mt7621/mt7621.h
 create mode 100644 arch/mips/mach-mtmips/mt7621/serial.c
 create mode 100644 board/mediatek/mt7621/MAINTAINERS
 create mode 100644 board/mediatek/mt7621/Makefile
 create mode 100644 board/mediatek/mt7621/board.c
 create mode 100644 configs/mt7621_nand_rfb_ramboot_defconfig
 create mode 100644 configs/mt7621_rfb_ramboot_defconfig
 create mode 100644 drivers/clk/mtmips/clk-mt7621.c
 create mode 100644 drivers/mtd/nand/raw/mt7621_nand.c
 create mode 100644 drivers/pinctrl/mtmips/pinctrl-mt7621.c
 create mode 100644 include/configs/mt7621-rfb.h
 create mode 100644 include/configs/mt7621.h
 create mode 100644 include/dt-bindings/clock/mt7621-clk.h
 create mode 100644 include/dt-bindings/reset/mt7621-reset.h
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH v2 1/14 mips: mtmips: add support for MediaTek MT7621 SoC

This patch adds support for MediaTek MT7621 SoC.
All files are dedicated for u-boot.

Currently only ramboot is supported.
The default build target is u-boot-lzma.img.
This file can be booted using bootm command, or be used as a payload of the SDK preloader of MT7621.

The specification of this chip:
https://www.mediatek.com/products/homenetworking/mt7621

---
v2 changes:
Add a kconfig for max supported ram size
Remove network configs from default config file

---
 arch/mips/dts/mt7621.dtsi             | 372 ++++++++++++++++++++++++++
 arch/mips/mach-mtmips/Kconfig         |  34 ++-
 arch/mips/mach-mtmips/Makefile        |   5 +
 arch/mips/mach-mtmips/cpu.c           |   2 +-
 arch/mips/mach-mtmips/mt7621/Kconfig  |  23 ++
 arch/mips/mach-mtmips/mt7621/Makefile |   5 +
 arch/mips/mach-mtmips/mt7621/compat.c |  21 ++
 arch/mips/mach-mtmips/mt7621/init.c   | 156 +++++++++++
 arch/mips/mach-mtmips/mt7621/mt7621.h | 204 ++++++++++++++
 arch/mips/mach-mtmips/mt7621/serial.c |  23 ++
 include/configs/mt7621.h              |  36 +++
 11 files changed, 876 insertions(+), 5 deletions(-)
 create mode 100644 arch/mips/dts/mt7621.dtsi
 create mode 100644 arch/mips/mach-mtmips/mt7621/Kconfig
 create mode 100644 arch/mips/mach-mtmips/mt7621/Makefile
 create mode 100644 arch/mips/mach-mtmips/mt7621/compat.c
 create mode 100644 arch/mips/mach-mtmips/mt7621/init.c
 create mode 100644 arch/mips/mach-mtmips/mt7621/mt7621.h
 create mode 100644 arch/mips/mach-mtmips/mt7621/serial.c
 create mode 100644 include/configs/mt7621.h
arch/mips/dts/mt7621.dtsi new file +372 -0
new file mode 100644
index 0000000000..c09350b370
@@ -0,0 +1,372 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 MediaTek Inc. All rights reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#include <dt-bindings/clock/mt7621-clk.h>
+#include <dt-bindings/reset/mt7621-reset.h>
+#include <dt-bindings/phy/phy.h>
+
+/ {
+	#address-cells = <1>;
+	#size-cells = <1>;
+	compatible = "mediatek,mt7621-soc";
+
+	cpus {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		cpu@0 {
+			device_type = "cpu";
+			compatible = "mips,mips1004Kc";
+			reg = <0>;
+		};
+
+		cpu@1 {
+			device_type = "cpu";
+			compatible = "mips,mips1004Kc";
+			reg = <0>;
+		};
+	};
+
+	clk48m: clk48m@0 {
+		compatible = "fixed-clock";
+
+		clock-frequency = <48000000>;
+
+		#clock-cells = <0>;
+	};
+
+	clk50m: clk50m@0 {
+		compatible = "fixed-clock";
+
+		clock-frequency = <50000000>;
+
+		#clock-cells = <0>;
+	};
+
+	sysc: sysc@1e000000 {
+		compatible = "mediatek,mt7621-sysc", "syscon";
+		reg = <0x1e000000 0x100>;
+	};
+
+	clkctrl: clkctrl@1e000030 {
+		compatible = "mediatek,mt7621-clk";
+		mediatek,sysc = <&sysc>;
+		mediatek,memc = <&memc>;
+
+		#clock-cells = <1>;
+		u-boot,dm-pre-reloc;
+	};
+
+	rstctrl: rstctrl@1e000034 {
+		compatible = "mediatek,mtmips-reset";
+		reg = <0x1e000034 0x4>;
+		#reset-cells = <1>;
+	};
+
+	reboot: resetctl-reboot {
+		compatible = "resetctl-reboot";
+
+		resets = <&rstctrl RST_SYS>;
+		reset-names = "sysreset";
+	};
+
+	memc: memc@1e005000 {
+		compatible = "mediatek,mt7621-memc", "syscon";
+		reg = <0x1e005000 0x1000>;
+	};
+
+	pinctrl: pinctrl@1e000060 {
+		compatible = "mediatek,mt7621-pinctrl";
+		reg = <0x1e000048 0x30>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&state_default>;
+
+		state_default: pin_state {
+			uart1 {
+				groups = "uart1";
+				function = "uart";
+			};
+
+			gpios {
+				groups = "i2c", "uart3", "pcie reset";
+				function = "gpio";
+			};
+
+			jtag {
+				groups = "jtag";
+				function = "jtag";
+			};
+
+			wdt {
+				groups = "wdt";
+				function = "wdt rst";
+			};
+		};
+
+		uart1_pins: uart1_pins {
+			groups = "uart1";
+			function = "uart";
+		};
+
+		uart2_pins: uart2_pins {
+			groups = "uart2";
+			function = "uart";
+		};
+
+		uart3_pins: uart3_pins {
+			groups = "uart3";
+			function = "uart";
+		};
+
+		sdxc_pins: sdxc_pins {
+			groups = "sdxc";
+			function = "sdxc";
+		};
+
+		spi_pins: spi_pins {
+			groups = "spi";
+			function = "spi";
+		};
+
+		eth_pins: eth_pins {
+			mdio_pins {
+				groups = "mdio";
+				function = "mdio";
+			};
+
+			rgmii1_pins {
+				groups = "rgmii1";
+				function = "rgmii";
+			};
+
+			esw_pins {
+				groups = "esw int";
+				function = "esw int";
+			};
+
+			mdio_pconf {
+				groups = "mdio";
+				drive-strength = <2>;
+			};
+		};
+	};
+
+	watchdog: watchdog@1e000100 {
+		compatible = "mediatek,mt7621-wdt";
+		reg = <0x1e000100 0x40>;
+
+		resets = <&rstctrl RST_TIMER>;
+		reset-names = "wdt";
+
+		status = "disabled";
+	};
+
+	gpio: gpio@1e000600 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		compatible = "mtk,mt7621-gpio";
+		reg = <0x1e000600 0x100>;
+
+		resets = <&rstctrl RST_PIO>;
+		reset-names = "pio";
+
+		gpio0: bank@0 {
+			reg = <0>;
+			compatible = "mtk,mt7621-gpio-bank";
+			gpio-controller;
+			#gpio-cells = <2>;
+		};
+
+		gpio1: bank@1 {
+			reg = <1>;
+			compatible = "mtk,mt7621-gpio-bank";
+			gpio-controller;
+			#gpio-cells = <2>;
+		};
+
+		gpio2: bank@2 {
+			reg = <2>;
+			compatible = "mtk,mt7621-gpio-bank";
+			gpio-controller;
+			#gpio-cells = <2>;
+		};
+	};
+
+	spi: spi@1e000b00 {
+		compatible = "ralink,mt7621-spi";
+		reg = <0x1e000b00 0x40>;
+
+		status = "disabled";
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&spi_pins>;
+
+		resets = <&rstctrl RST_SPI>;
+		reset-names = "spi";
+
+		clocks = <&clkctrl CLK_SPI>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+
+	uart0: uart1@1e000c00 {
+		compatible = "mediatek,hsuart", "ns16550a";
+		reg = <0x1e000c00 0x100>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&uart1_pins>;
+
+		clocks = <&clkctrl CLK_UART1>;
+
+		resets = <&rstctrl RST_UART1>;
+
+		reg-shift = <2>;
+	};
+
+	uart1: uart2@1e000d00 {
+		compatible = "mediatek,hsuart", "ns16550a";
+		reg = <0x1e000d00 0x100>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&uart2_pins>;
+
+		clocks = <&clkctrl CLK_UART2>;
+
+		resets = <&rstctrl RST_UART2>;
+
+		reg-shift = <2>;
+
+		status = "disabled";
+	};
+
+	uart2: uart3@1e000e00 {
+		compatible = "mediatek,hsuart", "ns16550a";
+		reg = <0x1e000e00 0x100>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&uart3_pins>;
+
+		clocks = <&clkctrl CLK_UART3>;
+
+		resets = <&rstctrl RST_UART3>;
+
+		reg-shift = <2>;
+
+		status = "disabled";
+	};
+
+	eth: eth@1e100000 {
+		compatible = "mediatek,mt7621-eth";
+		reg = <0x1e100000 0x20000>;
+		mediatek,ethsys = <&sysc>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&eth_pins>;
+
+		resets = <&rstctrl RST_FE>, <&rstctrl RST_GMAC>, <&rstctrl RST_MCM>;
+		reset-names = "fe", "gmac", "mcm";
+
+		clocks = <&clkctrl CLK_GMAC>,
+			 <&clkctrl CLK_FE>;
+		clock-names = "gmac", "fe";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		mediatek,gmac-id = <0>;
+		phy-mode = "rgmii";
+		mediatek,switch = "mt7530";
+		mediatek,mcm;
+
+		fixed-link {
+			speed = <1000>;
+			full-duplex;
+		};
+	};
+
+	mmc: mmc@1e130000 {
+		compatible = "mediatek,mt7621-mmc";
+		reg = <0x1e130000 0x4000>;
+
+		status = "disabled";
+
+		bus-width = <4>;
+		builtin-cd = <1>;
+		r_smpl = <1>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&sdxc_pins>;
+
+		clocks = <&clk50m>, <&clkctrl CLK_SDXC>;
+		clock-names = "source", "hclk";
+
+		resets = <&rstctrl RST_SDXC>;
+	};
+
+	ssusb: usb@1e1c0000 {
+		compatible = "mediatek,mt7621-xhci", "mediatek,mtk-xhci";
+		reg = <0x1e1c0000 0x1000>, <0x1e1d0700 0x100>;
+		reg-names = "mac", "ippc";
+
+		/* power-domains = <&scpsys MT7629_POWER_DOMAIN_HIF1>; */
+
+		clocks = <&clk48m>, <&clk48m>;
+		clock-names = "sys_ck", "ref_ck";
+
+		phys = <&u2port0 PHY_TYPE_USB2>,
+		       <&u3port0 PHY_TYPE_USB3>,
+		       <&u2port1 PHY_TYPE_USB2>;
+
+		status = "disabled";
+	};
+
+	u3phy: usb-phy@1e1d0000 {
+		compatible = "mediatek,mt7621-u3phy",
+			     "mediatek,generic-tphy-v1";
+		reg = <0x1e1d0000 0x700>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+		status = "disabled";
+
+		u2port0: usb-phy@1e1d0800 {
+			reg = <0x1e1d0800 0x0100>;
+			#phy-cells = <1>;
+			clocks = <&clk48m>;
+			clock-names = "ref";
+		};
+
+		u3port0: usb-phy@1e1d0900 {
+			reg = <0x1e1d0900 0x0100>;
+			#phy-cells = <1>;
+		};
+
+		u2port1: usb-phy@1e1d1000 {
+			reg = <0x1e1d1000 0x0100>;
+			#phy-cells = <1>;
+			clocks = <&clk48m>;
+			clock-names = "ref";
+		};
+	};
+
+	i2c: i2c@1e000900 {
+		compatible = "i2c-gpio";
+
+		status = "disabled";
+
+		i2c-gpio,delay-us = <3>;
+
+		gpios = <&gpio0 3 1>, /* PIN3 as SDA */
+			<&gpio0 4 1>; /* PIN4 as CLK */
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
+};
arch/mips/mach-mtmips/Kconfig +30 -4
index 151b004603..a73e9f8bd8 100644
@@ -9,6 +9,7 @@ config SYS_MALLOC_F_LEN
 
 config SYS_SOC
 	default "mt7620" if SOC_MT7620
+	default "mt7621" if SOC_MT7621
 	default "mt7628" if SOC_MT7628
 
 config SYS_DCACHE_SIZE
@@ -18,25 +19,36 @@ config SYS_DCACHE_LINE_SIZE
 	default 32
 
 config SYS_ICACHE_SIZE
-	default 65536
+	default 65536 if SOC_MT7620 || SOC_MT7628
+	default 32768 if SOC_MT7621
 
 config SYS_ICACHE_LINE_SIZE
 	default 32
 
 config SYS_TEXT_BASE
-	default 0x9c000000 if !SPL
-	default 0x80200000 if SPL
+	default 0x9c000000 if !SPL && !SOC_MT7621
+	default 0x80200000 if SPL || SOC_MT7621
 
 config SPL_TEXT_BASE
-	default 0x9c000000
+	default 0x9c000000 if !SOC_MT7621
+	default 0x80100000 if SOC_MT7621
+
+config TPL_TEXT_BASE
+	default 0xbfc00000 if SOC_MT7621
 
 config SPL_PAYLOAD
 	default "u-boot-lzma.img" if SPL_LZMA
 
 config BUILD_TARGET
+	default "u-boot-lzma.img" if SOC_MT7621 # Only ramboot is supported now
 	default "u-boot-with-spl.bin" if SPL
 	default "u-boot.bin"
 
+config MAX_MEM_SIZE
+	int
+	default 256 if SOC_MT7620 || SOC_MT7628
+	default 512 if SOC_MT7621
+
 choice
 	prompt "MediaTek MIPS SoC select"
 
@@ -55,6 +67,19 @@ config SOC_MT7620
 	help
 	  This supports MediaTek MT7620.
 
+config SOC_MT7621
+	bool "MT7621"
+	select MIPS_CM
+	select MIPS_L2_CACHE
+	select SYS_CACHE_SHIFT_5
+	select SYS_MIPS_CACHE_INIT_RAM_LOAD
+	select PINCTRL_MT7621
+	select MTK_SERIAL
+	select REGMAP
+	select SYSCON
+	help
+	  This supports MediaTek MT7621.
+
 config SOC_MT7628
 	bool "MT7628"
 	select SYS_CACHE_SHIFT_5
@@ -80,6 +105,7 @@ config SOC_MT7628
 endchoice
 
 source "arch/mips/mach-mtmips/mt7620/Kconfig"
+source "arch/mips/mach-mtmips/mt7621/Kconfig"
 source "arch/mips/mach-mtmips/mt7628/Kconfig"
 
 endmenu
arch/mips/mach-mtmips/Makefile +5 -0
index 4909b47ef2..9ab882dee0 100644
@@ -1,9 +1,14 @@
 # SPDX-License-Identifier: GPL-2.0+
 
 obj-y += cpu.o
+
+ifneq ($(CONFIG_SOC_MT7621),y)
 obj-y += ddr_init.o
 obj-y += ddr_cal.o
+endif
+
 obj-$(CONFIG_SPL_BUILD) += spl.o
 
 obj-$(CONFIG_SOC_MT7620) += mt7620/
+obj-$(CONFIG_SOC_MT7621) += mt7621/
 obj-$(CONFIG_SOC_MT7628) += mt7628/
arch/mips/mach-mtmips/cpu.c +1 -1
index a4b5cff61d..f1e9022738 100644
@@ -16,7 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int dram_init(void)
 {
-	gd->ram_size = get_ram_size((void *)KSEG1, SZ_256M);
+	gd->ram_size = get_ram_size((void *)KSEG1, CONFIG_MAX_MEM_SIZE << 20);
 
 	return 0;
 }
arch/mips/mach-mtmips/mt7621/Kconfig new file +23 -0
new file mode 100644
index 0000000000..6948bee31b
@@ -0,0 +1,23 @@
+
+if SOC_MT7621
+
+config DEBUG_UART_BOARD_INIT
+	default y
+
+choice
+	prompt "Board select"
+
+endchoice
+
+config SYS_CONFIG_NAME
+	string "Board configuration name"
+	default "mt7621" if  BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
+
+config SYS_BOARD
+	string "Board name"
+	default "mt7621" if  BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
+
+config SYS_VENDOR
+	default "mediatek" if BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
+
+endif
arch/mips/mach-mtmips/mt7621/Makefile new file +5 -0
new file mode 100644
index 0000000000..adb48ffe37
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += init.o
+obj-y += serial.o
+obj-y += compat.o
arch/mips/mach-mtmips/mt7621/compat.c new file +21 -0
new file mode 100644
index 0000000000..ae2dd263f7
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 MediaTek Inc. All rights reserved.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#include <malloc.h>
+#include <asm/io.h>
+#include <asm/addrspace.h>
+
+/* This is used for the mtk-eth driver */
+phys_addr_t noncached_alloc(size_t size, size_t align)
+{
+	void *ptr = memalign(align, ALIGN(size, align));
+
+	if (!ptr)
+		return 0;
+
+	return KSEG1ADDR((ulong)ptr);
+}
arch/mips/mach-mtmips/mt7621/init.c new file +156 -0

156 lines not on this page · raw message

arch/mips/mach-mtmips/mt7621/mt7621.h new file +204 -0

204 lines not on this page · raw message

arch/mips/mach-mtmips/mt7621/serial.c new file +23 -0
new file mode 100644
index 0000000000..393188abce
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#include <asm/io.h>
+#include <asm/addrspace.h>
+#include "mt7621.h"
+
+void board_debug_uart_init(void)
+{
+	void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
+
+#if CONFIG_DEBUG_UART_BASE == 0xbe000c00 /* KSEG1ADDR(UART1_BASE) */
+	clrbits_32(base + SYSCTL_GPIOMODE_REG, UART1_MODE);
+#elif CONFIG_DEBUG_UART_BASE == 0xbe000d00 /* KSEG1ADDR(UART2_BASE) */
+	clrbits_32(base + SYSCTL_GPIOMODE_REG, UART2_MODE_M);
+#elif CONFIG_DEBUG_UART_BASE == 0xbe000e00 /* KSEG1ADDR(UART3_BASE) */
+	clrbits_32(base + SYSCTL_GPIOMODE_REG, UART3_MODE_M);
+#endif
+}
include/configs/mt7621.h new file +36 -0
new file mode 100644
index 0000000000..c3da1ad423
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#ifndef __CONFIG_MT7621_H
+#define __CONFIG_MT7621_H
+
+#define CONFIG_SYS_HZ			1000
+#define CONFIG_SYS_MIPS_TIMER_FREQ	440000000
+
+#define CONFIG_SYS_MONITOR_BASE		CONFIG_SYS_TEXT_BASE
+
+#define CONFIG_SYS_BOOTPARAMS_LEN	0x20000
+
+#define CONFIG_SYS_SDRAM_BASE		0x80000000
+
+#define CONFIG_VERY_BIG_RAM
+#define CONFIG_MAX_MEM_MAPPED		0x1c000000
+
+#define CONFIG_SYS_INIT_SP_OFFSET	0x80000
+
+#define CONFIG_SYS_BOOTM_LEN		0x2000000
+
+#define CONFIG_SYS_MAXARGS		16
+#define CONFIG_SYS_CBSIZE		1024
+
+/* MMC */
+#define MMC_SUPPORTS_TUNING
+
+/* NAND */
+#define CONFIG_SYS_MAX_NAND_DEVICE	1
+
+#endif /* __CONFIG_MT7621_H */
Signature · 1 line
2.17.1
author
#2 lore raw

PATCH v2 2/14 mips: mtmips: add two reference boards for mt7621

In reply to Weijie Gao

The mt7621_rfb board supports integrated giga PHYs plus one external giga PHYs. It also has up to 512MiB DDR3, 16MB SPI-NOR, 3 mini PCI-e x1 slots, SDXC and USB.

The mt7621_nand_rfb board is almost the same as mt7621_rfb board, but it uses NAND flash and SDXC is not available.

---
v2 changes:
Add config file for mt7621-rfb boards

---
 arch/mips/dts/Makefile                     |  2 +
 arch/mips/dts/mediatek,mt7621-nand-rfb.dts | 52 +++++++++++++++
 arch/mips/dts/mediatek,mt7621-rfb.dts      | 68 ++++++++++++++++++++
 arch/mips/mach-mtmips/mt7621/Kconfig       | 20 ++++++
 board/mediatek/mt7621/MAINTAINERS          |  9 +++
 board/mediatek/mt7621/Makefile             |  3 +
 board/mediatek/mt7621/board.c              |  6 ++
 configs/mt7621_nand_rfb_ramboot_defconfig  | 72 +++++++++++++++++++++
 configs/mt7621_rfb_ramboot_defconfig       | 75 ++++++++++++++++++++++
 include/configs/mt7621-rfb.h               | 18 ++++++
 10 files changed, 325 insertions(+)
 create mode 100644 arch/mips/dts/mediatek,mt7621-nand-rfb.dts
 create mode 100644 arch/mips/dts/mediatek,mt7621-rfb.dts
 create mode 100644 board/mediatek/mt7621/MAINTAINERS
 create mode 100644 board/mediatek/mt7621/Makefile
 create mode 100644 board/mediatek/mt7621/board.c
 create mode 100644 configs/mt7621_nand_rfb_ramboot_defconfig
 create mode 100644 configs/mt7621_rfb_ramboot_defconfig
 create mode 100644 include/configs/mt7621-rfb.h
arch/mips/dts/Makefile +2 -0
index 215283cfa0..1ef5a28e93 100644
@@ -16,6 +16,8 @@ dtb-$(CONFIG_BOARD_COMTREND_WAP5813N) += comtrend,wap-5813n.dtb
 dtb-$(CONFIG_BOARD_HUAWEI_HG556A) += huawei,hg556a.dtb
 dtb-$(CONFIG_BOARD_MT7620_RFB) += mediatek,mt7620-rfb.dtb
 dtb-$(CONFIG_BOARD_MT7620_MT7530_RFB) += mediatek,mt7620-mt7530-rfb.dtb
+dtb-$(CONFIG_BOARD_MT7621_RFB) += mediatek,mt7621-rfb.dtb
+dtb-$(CONFIG_BOARD_MT7621_NAND_RFB) += mediatek,mt7621-nand-rfb.dtb
 dtb-$(CONFIG_BOARD_MT7628_RFB) += mediatek,mt7628-rfb.dtb
 dtb-$(CONFIG_BOARD_GARDENA_SMART_GATEWAY_MT7688) += gardena-smart-gateway-mt7688.dtb
 dtb-$(CONFIG_BOARD_LINKIT_SMART_7688) += linkit-smart-7688.dtb
arch/mips/dts/mediatek,mt7621-nand-rfb.dts new file +52 -0

52 lines not on this page · raw message

arch/mips/dts/mediatek,mt7621-rfb.dts new file +68 -0

68 lines not on this page · raw message

arch/mips/mach-mtmips/mt7621/Kconfig +20 -0
index 6948bee31b..add1f4154b 100644
@@ -7,6 +7,26 @@ config DEBUG_UART_BOARD_INIT
 choice
 	prompt "Board select"
 
+config BOARD_MT7621_RFB
+	bool "MediaTek MT7621 RFB (SPI-NOR)"
+	help
+	  The reference design of MT7621A (WS3010) booting from SPI-NOR flash.
+	  The board can be configured with DDR2 (64MiB~256MiB) or DDR3
+	  (128MiB~512MiB). The board has 16 MiB SPI-NOR flash, built-in MT7530
+	  GbE switch, 1 UART, 1 USB 2.0 host, 1 USB 3.0 host, 1 SDXC, 3 PCIe
+	  sockets, 1 RGMII to external GbE PHY, 2 audio jacks (in/out),
+	  JTAG pins and expansion GPIO pins.
+
+config BOARD_MT7621_NAND_RFB
+	bool "MediaTek MT7621 RFB (NAND)"
+	help
+	  The reference design of MT7621A (WS3010) booting from NAND flash.
+	  The board can be configured with DDR2 (64MiB~256MiB) or DDR3
+	  (128MiB~512MiB). The board has 128 MiB parallel NAND flash, built-in
+	  MT7530 GbE switch, 1 UART, 1 USB 2.0 host, 1 USB 3.0 host, 3 PCIe
+	  sockets, 1 RGMII to external GbE PHY, 2 audio jacks (in/out),
+	  JTAG pins and expansion GPIO pins.
+
 endchoice
 
 config SYS_CONFIG_NAME
board/mediatek/mt7621/MAINTAINERS new file +9 -0
new file mode 100644
index 0000000000..add653b931
@@ -0,0 +1,9 @@
+MT7621_RFB BOARD
+M:	Weijie Gao <[email protected]>
+S:	Maintained
+F:	board/mediatek/mt7621
+F:	configs/mt7621_rfb_ramboot_defconfig
+F:	configs/mt7621_nand_rfb_ramboot_defconfig
+F:	arch/mips/dts/mediatek,mt7621-rfb.dts
+F:	arch/mips/dts/mediatek,mt7621-nand-rfb.dts
+F:	include/configs/mt7621-rfb.h
board/mediatek/mt7621/Makefile new file +3 -0
new file mode 100644
index 0000000000..db129c5aba
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y += board.o
board/mediatek/mt7621/board.c new file +6 -0
new file mode 100644
index 0000000000..119b8fc9e5
@@ -0,0 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
configs/mt7621_nand_rfb_ramboot_defconfig new file +72 -0

72 lines not on this page · raw message

configs/mt7621_rfb_ramboot_defconfig new file +75 -0

75 lines not on this page · raw message

include/configs/mt7621-rfb.h new file +18 -0
new file mode 100644
index 0000000000..2287cb1103
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#ifndef __CONFIG_MT7621_RFB_H
+#define __CONFIG_MT7621_RFB_H
+
+#include "mt7621.h"
+
+/* Network */
+#define CONFIG_IPADDR			192.168.1.1
+#define CONFIG_SERVERIP			192.168.1.2
+#define CONFIG_NETMASK			255.255.255.0
+
+#endif /* __CONFIG_MT7621_RFB_H */
Signature · 1 line
2.17.1
author
#9 lore raw

PATCH v2 4/14 reset: mtmips: add reset controller support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch adds reset controller bits definition header file for MediaTek MT7621 SoC

---
v2 changes: none

---
 include/dt-bindings/reset/mt7621-reset.h | 38 ++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 include/dt-bindings/reset/mt7621-reset.h
include/dt-bindings/reset/mt7621-reset.h new file +38 -0
new file mode 100644
index 0000000000..e129c531fc
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 MediaTek Inc. All rights reserved.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_MT7621_RESET_H_
+#define _DT_BINDINGS_MT7621_RESET_H_
+
+#define RST_PPE			31
+#define RST_SDXC		30
+#define RST_CRYPTO		29
+#define RST_AUX_STCK		28
+#define RST_PCIE2		26
+#define RST_PCIE1		25
+#define RST_PCIE0		24
+#define RST_GMAC		23
+#define RST_UART3		21
+#define RST_UART2		20
+#define RST_UART1		19
+#define RST_SPI			18
+#define RST_I2S			17
+#define RST_I2C			16
+#define RST_NFI			15
+#define RST_GDMA		14
+#define RST_PIO			13
+#define RST_PCM			11
+#define RST_MC			10
+#define RST_INTC		9
+#define RST_TIMER		8
+#define RST_SPDIFTX		7
+#define RST_FE			6
+#define RST_HSDMA		5
+#define RST_MCM			2
+#define RST_SYS			0
+
+#endif /* _DT_BINDINGS_MT7621_RESET_H_ */
Signature · 1 line
2.17.1
author
#3 lore raw

PATCH v2 3/14 clk: mtmips: add clock driver for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch adds a clock driver for MediaTek MT7621 SoC.
This driver provides clock gate control as well as getting clock frequency for CPU/SYS/XTAL and some peripherals.

---
v2 changes: none

---
 drivers/clk/mtmips/Makefile            |   1 +
 drivers/clk/mtmips/clk-mt7621.c        | 260 +++++++++++++++++++++++++
 include/dt-bindings/clock/mt7621-clk.h |  42 ++++
 3 files changed, 303 insertions(+)
 create mode 100644 drivers/clk/mtmips/clk-mt7621.c
 create mode 100644 include/dt-bindings/clock/mt7621-clk.h
drivers/clk/mtmips/Makefile +1 -0
index 732e7f2545..ee8b5afe87 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
 
 obj-$(CONFIG_SOC_MT7620) += clk-mt7620.o
+obj-$(CONFIG_SOC_MT7621) += clk-mt7621.o
 obj-$(CONFIG_SOC_MT7628) += clk-mt7628.o
drivers/clk/mtmips/clk-mt7621.c new file +260 -0

260 lines not on this page · raw message

include/dt-bindings/clock/mt7621-clk.h new file +42 -0

42 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#10 lore raw

PATCH v2 5/14 pinctrl: mtmips: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch adds pinctrl support for MediaTek MT7621 SoC. The MT7621 SoC supports pinconf, but it is not the same as mt7628.

---
v2 changes: none

---
 drivers/pinctrl/mtmips/Kconfig                |   9 +
 drivers/pinctrl/mtmips/Makefile               |   1 +
 drivers/pinctrl/mtmips/pinctrl-mt7621.c       | 307 ++++++++++++++++++
 .../pinctrl/mtmips/pinctrl-mtmips-common.c    |   4 +-
 .../pinctrl/mtmips/pinctrl-mtmips-common.h    |  12 +
 5 files changed, 331 insertions(+), 2 deletions(-)
 create mode 100644 drivers/pinctrl/mtmips/pinctrl-mt7621.c
drivers/pinctrl/mtmips/Kconfig +9 -0
index 844d5b743f..456f3ea25d 100644
@@ -12,6 +12,15 @@ config PINCTRL_MT7620
 	  The driver is controlled by a device tree node which contains
 	  the pin mux functions for each available pin groups.
 
+config PINCTRL_MT7621
+	bool "MediaTek MT7621 pin control driver"
+	select PINCTRL_MTMIPS
+	depends on SOC_MT7621 && PINCTRL_GENERIC
+	help
+	  Support pin multiplexing control on MediaTek MT7621.
+	  The driver is controlled by a device tree node which contains
+	  the pin mux functions for each available pin groups.
+
 config PINCTRL_MT7628
 	bool "MediaTek MT7628 pin control driver"
 	select PINCTRL_MTMIPS
drivers/pinctrl/mtmips/Makefile +1 -0
index ba945a89a7..8fece4f5fa 100644
@@ -5,4 +5,5 @@ obj-$(CONFIG_PINCTRL_MTMIPS) += pinctrl-mtmips-common.o
 
 # SoC Drivers
 obj-$(CONFIG_PINCTRL_MT7620) += pinctrl-mt7620.o
+obj-$(CONFIG_PINCTRL_MT7621) += pinctrl-mt7621.o
 obj-$(CONFIG_PINCTRL_MT7628) += pinctrl-mt7628.o
drivers/pinctrl/mtmips/pinctrl-mt7621.c new file +307 -0

307 lines not on this page · raw message

drivers/pinctrl/mtmips/pinctrl-mtmips-common.c +2 -2
index e361916eb2..869b781068 100644
@@ -13,8 +13,8 @@
 
 #include "pinctrl-mtmips-common.h"
 
-static void mtmips_pinctrl_reg_set(struct mtmips_pinctrl_priv *priv,
-				   u32 reg, u32 shift, u32 mask, u32 value)
+void mtmips_pinctrl_reg_set(struct mtmips_pinctrl_priv *priv,
+			    u32 reg, u32 shift, u32 mask, u32 value)
 {
 	u32 val;
 
drivers/pinctrl/mtmips/pinctrl-mtmips-common.h +12 -0
index b51d8f009c..1f1023ef42 100644
@@ -22,6 +22,10 @@ struct mtmips_pmx_group {
 	u32 shift;
 	char mask;
 
+	int pconf_avail;
+	u32 pconf_reg;
+	u32 pconf_shift;
+
 	int nfuncs;
 	const struct mtmips_pmx_func *funcs;
 };
@@ -42,6 +46,14 @@ struct mtmips_pinctrl_priv {
 	{ .name = (_name), .reg = (_reg), .shift = (_shift), .mask = (_mask), \
 	  .funcs = (_funcs), .nfuncs = ARRAY_SIZE(_funcs) }
 
+#define GRP_PCONF(_name, _funcs, _reg, _shift, _mask, _pconf_reg, _pconf_shift) \
+	{ .name = (_name), .reg = (_reg), .shift = (_shift), .mask = (_mask), \
+	  .funcs = (_funcs), .nfuncs = ARRAY_SIZE(_funcs), .pconf_avail = 1, \
+	  .pconf_reg = (_pconf_reg), .pconf_shift = (_pconf_shift) }
+
+void mtmips_pinctrl_reg_set(struct mtmips_pinctrl_priv *priv,
+			    u32 reg, u32 shift, u32 mask, u32 value);
+
 int mtmips_get_functions_count(struct udevice *dev);
 const char *mtmips_get_function_name(struct udevice *dev,
 				     unsigned int selector);
Signature · 1 line
2.17.1
author
#12 lore raw

PATCH v2 7/14 usb: xhci-mtk: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch makes xhci-mtk driver available for MediaTek MT7621 SoC

---
v2 changes: none

---
 drivers/usb/host/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/Kconfig +1 -1
index ccecb5a3b0..f2c060e692 100644
@@ -34,7 +34,7 @@ config USB_XHCI_DWC3_OF_SIMPLE
 
 config USB_XHCI_MTK
 	bool "Support for MediaTek on-chip xHCI USB controller"
-	depends on ARCH_MEDIATEK
+	depends on ARCH_MEDIATEK || SOC_MT7621
 	help
 	  Enables support for the on-chip xHCI controller on MediaTek SoCs.
 
Signature · 1 line
2.17.1
author
#13 lore raw

PATCH v2 8/14 phy: mtk-tphy: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch makes mtk-tphy driver available for MediaTek MT7621 SoC

---
v2 changes: none

---
 drivers/phy/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/phy/Kconfig +1 -1
index 4767d215f3..6ab99d2643 100644
@@ -266,7 +266,7 @@ config MT76X8_USB_PHY
 config PHY_MTK_TPHY
 	bool "MediaTek T-PHY Driver"
 	depends on PHY
-	depends on ARCH_MEDIATEK
+	depends on ARCH_MEDIATEK || SOC_MT7621
 	help
 	  MediaTek T-PHY driver supports usb2.0, usb3.0 ports, PCIe and
 	  SATA, and meanwhile supports two version T-PHY which have
Signature · 1 line
2.17.1
author
#14 lore raw

PATCH v2 9/14 spi: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch makes mt7621_spi driver available for MediaTek MT7621 SoC

---
v2 changes: none

---
 drivers/spi/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/Kconfig +1 -1
index d07e9a28af..a43e652231 100644
@@ -219,7 +219,7 @@ config MT7620_SPI
 
 config MT7621_SPI
 	bool "MediaTek MT7621 SPI driver"
-	depends on SOC_MT7628
+	depends on SOC_MT7621 || SOC_MT7628
 	help
 	  Enable the MT7621 SPI driver. This driver can be used to access
 	  the SPI NOR flash on platforms embedding this Ralink / MediaTek
Signature · 1 line
2.17.1
author
#11 lore raw

PATCH v2 6/14 nand: raw: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch adds NAND flash controller driver for MediaTek MT7621 SoC. The NAND flash controller of MT7621 supports only SLC NAND flashes. It supports 4~12 bits correction with maximum 4KB page size.

---
v2 changes: none

---
 drivers/mtd/nand/raw/Kconfig       |   11 +
 drivers/mtd/nand/raw/Makefile      |    1 +
 drivers/mtd/nand/raw/mt7621_nand.c | 1189 ++++++++++++++++++++++++++++
 3 files changed, 1201 insertions(+)
 create mode 100644 drivers/mtd/nand/raw/mt7621_nand.c
drivers/mtd/nand/raw/Kconfig +11 -0
index cb0c0a1581..fe87c521d7 100644
@@ -475,6 +475,17 @@ config ROCKCHIP_NAND
 	    NFC v800: RK3308, RV1108
 	    NFC v900: PX30, RK3326
 
+config NAND_MT7621
+	bool "Support for MediaTek MT7621 NAND flash controller"
+	depends on SOC_MT7621
+	select SYS_NAND_SELF_INIT
+	imply CMD_NAND
+	help
+	  This enables NAND driver for the NAND flash controller on MediaTek
+	  MT7621 platform.
+	  The controller supports 4~12 bits correction per 512 bytes with a
+	  maximum 4KB page size.
+
 comment "Generic NAND options"
 
 config SYS_NAND_BLOCK_SIZE
drivers/mtd/nand/raw/Makefile +1 -0
index 6ec3581d20..6d6721a3be 100644
@@ -72,6 +72,7 @@ obj-$(CONFIG_NAND_ZYNQ) += zynq_nand.o
 obj-$(CONFIG_NAND_STM32_FMC2) += stm32_fmc2_nand.o
 obj-$(CONFIG_CORTINA_NAND) += cortina_nand.o
 obj-$(CONFIG_ROCKCHIP_NAND) += rockchip_nfc.o
+obj-$(CONFIG_NAND_MT7621) += mt7621_nand.o
 
 else  # minimal SPL drivers
 
drivers/mtd/nand/raw/mt7621_nand.c new file +1189 -0

1,189 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#15 lore raw

PATCH v2 10/14 gpio: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch makes mt7621_gpio driver available for MediaTek MT7621 SoC

---
v2 changes: none

---
 drivers/gpio/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/Kconfig +1 -1
index 40abc33772..8c49ca3f50 100644
@@ -501,7 +501,7 @@ config MT7620_GPIO
 
 config MT7621_GPIO
 	bool "MediaTek MT7621 GPIO driver"
-	depends on DM_GPIO && SOC_MT7628
+	depends on DM_GPIO && (SOC_MT7621 || SOC_MT7628)
 	default y
 	help
 	  Say yes here to support MediaTek MT7621 compatible GPIOs.
Signature · 1 line
2.17.1
author
#16 lore raw

PATCH v2 11/14 watchdog: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch makes mt7621_wdt driver available for MediaTek MT7621 SoC

---
v2 changes: none

---
 drivers/watchdog/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/watchdog/Kconfig +1 -1
index d306054a8c..cf383de973 100644
@@ -173,7 +173,7 @@ config WDT_MT7620
 
 config WDT_MT7621
 	bool "MediaTek MT7621 watchdog timer support"
-	depends on WDT && SOC_MT7628
+	depends on WDT && (SOC_MT7621 || SOC_MT7628)
 	help
 	  Select this to enable Ralink / Mediatek watchdog timer,
 	  which can be found on some MediaTek chips.
Signature · 1 line
2.17.1
author
#17 lore raw

PATCH v2 12/14 mmc: mediatek: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch adds SDXC support for MediaTek MT7621 SoC

---
v2 changes: none

---
 drivers/mmc/mtk-sd.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/mmc/mtk-sd.c +13 -0
index 8599f095bc..1199052a89 100644
@@ -1746,6 +1746,18 @@ static const struct msdc_compatible mt7620_compat = {
 	.default_pad_dly = true,
 };
 
+static const struct msdc_compatible mt7621_compat = {
+	.clk_div_bits = 8,
+	.pad_tune0 = false,
+	.async_fifo = true,
+	.data_tune = true,
+	.busy_check = false,
+	.stop_clk_fix = false,
+	.enhance_rx = false,
+	.builtin_pad_ctrl = true,
+	.default_pad_dly = true,
+};
+
 static const struct msdc_compatible mt7622_compat = {
 	.clk_div_bits = 12,
 	.pad_tune0 = true,
@@ -1794,6 +1806,7 @@ static const struct msdc_compatible mt8183_compat = {
 
 static const struct udevice_id msdc_ids[] = {
 	{ .compatible = "mediatek,mt7620-mmc", .data = (ulong)&mt7620_compat },
+	{ .compatible = "mediatek,mt7621-mmc", .data = (ulong)&mt7621_compat },
 	{ .compatible = "mediatek,mt7622-mmc", .data = (ulong)&mt7622_compat },
 	{ .compatible = "mediatek,mt7623-mmc", .data = (ulong)&mt7623_compat },
 	{ .compatible = "mediatek,mt8512-mmc", .data = (ulong)&mt8512_compat },
Signature · 1 line
2.17.1
author
#19 lore raw

PATCH v2 13/14 net: mediatek: add support for MediaTek MT7621 SoC

In reply to Weijie Gao

This patch adds GMAC support for MediaTek MT7621 SoC. MT7621 has the same GMAC/Switch configuration as MT7623.

---
v2 changes: none

---
 drivers/net/mtk_eth.c | 27 +++++++++++++++++++++------
 drivers/net/mtk_eth.h |  8 ++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
drivers/net/mtk_eth.c +21 -6
index 26f02847a2..3b42c99c2a 100644
@@ -145,7 +145,8 @@ enum mtk_switch {
 enum mtk_soc {
 	SOC_MT7623,
 	SOC_MT7629,
-	SOC_MT7622
+	SOC_MT7622,
+	SOC_MT7621
 };
 
 struct mtk_eth_priv {
@@ -669,12 +670,18 @@ static int mt7530_pad_clk_setup(struct mtk_eth_priv *priv, int mode)
 static int mt7530_setup(struct mtk_eth_priv *priv)
 {
 	u16 phy_addr, phy_val;
-	u32 val;
+	u32 val, txdrv;
 	int i;
 
-	/* Select 250MHz clk for RGMII mode */
-	mtk_ethsys_rmw(priv, ETHSYS_CLKCFG0_REG,
-		       ETHSYS_TRGMII_CLK_SEL362_5, 0);
+	if (priv->soc != SOC_MT7621) {
+		/* Select 250MHz clk for RGMII mode */
+		mtk_ethsys_rmw(priv, ETHSYS_CLKCFG0_REG,
+			       ETHSYS_TRGMII_CLK_SEL362_5, 0);
+
+		txdrv = 8;
+	} else {
+		txdrv = 4;
+	}
 
 	/* Modify HWTRAP first to allow direct access to internal PHYs */
 	mt753x_reg_read(priv, HWTRAP_REG, &val);
@@ -732,7 +739,8 @@ static int mt7530_setup(struct mtk_eth_priv *priv)
 	/* Lower Tx Driving for TRGMII path */
 	for (i = 0 ; i < NUM_TRGMII_CTRL ; i++)
 		mt753x_reg_write(priv, MT7530_TRGMII_TD_ODT(i),
-				 (8 << TD_DM_DRVP_S) | (8 << TD_DM_DRVN_S));
+				 (txdrv << TD_DM_DRVP_S) |
+				 (txdrv << TD_DM_DRVN_S));
 
 	for (i = 0 ; i < NUM_TRGMII_CTRL; i++)
 		mt753x_reg_rmw(priv, MT7530_TRGMII_RD(i), RD_TAP_M, 16);
@@ -1437,6 +1445,12 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
 		return -ENODEV;
 	}
 
+	if (priv->soc == SOC_MT7621) {
+		/* ioremap is needed for MIPS platform */
+		priv->ethsys_base =
+			ioremap_nocache((phys_addr_t)priv->ethsys_base, 0x100);
+	}
+
 	/* Reset controllers */
 	ret = reset_get_by_name(dev, "fe", &priv->rst_fe);
 	if (ret) {
@@ -1542,6 +1556,7 @@ static const struct udevice_id mtk_eth_ids[] = {
 	{ .compatible = "mediatek,mt7629-eth", .data = SOC_MT7629 },
 	{ .compatible = "mediatek,mt7623-eth", .data = SOC_MT7623 },
 	{ .compatible = "mediatek,mt7622-eth", .data = SOC_MT7622 },
+	{ .compatible = "mediatek,mt7621-eth", .data = SOC_MT7621 },
 	{}
 };
 
drivers/net/mtk_eth.h +8 -0
index 057ecfaabf..4a8c66c671 100644
@@ -412,4 +412,12 @@
 #define PHY_POWER_SAVING_M		0x300
 #define PHY_POWER_SAVING_TX		0x0
 
+#ifndef CONFIG_SYS_NONCACHED_MEMORY
+/*
+ * noncached_alloc is provided only for ARM. Add a prototype here for other
+ * platforms to suppress compilation warning.
+ */
+phys_addr_t noncached_alloc(size_t size, size_t align);
+#endif
+
 #endif /* _MTK_ETH_H_ */
Signature · 1 line
2.17.1
author
#22 lore raw

PATCH v2 14/14 MAINTAINERS: update maintainer for MediaTek MIPS platform

In reply to Weijie Gao

Update maintainer for MediaTek MIPS platform

---
v2 changes: none

---
 MAINTAINERS | 5 +++++
 1 file changed, 5 insertions(+)
MAINTAINERS +5 -0
index 5069f18806..7d65856743 100644
@@ -855,15 +855,20 @@ R:	GSS_MTK_Uboot_upstream <[email protected]>
 S:	Maintained
 F:	arch/mips/mach-mtmips/
 F:	arch/mips/dts/mt7620.dtsi
+F:	arch/mips/dts/mt7621.dtsi
 F:	arch/mips/dts/mt7620-u-boot.dtsi
 F:	include/configs/mt7620.h
+F:	include/configs/mt7621.h
 F:	include/dt-bindings/clock/mt7620-clk.h
+F:	include/dt-bindings/clock/mt7621-clk.h
 F:	include/dt-bindings/clock/mt7628-clk.h
 F:	include/dt-bindings/reset/mt7620-reset.h
+F:	include/dt-bindings/reset/mt7621-reset.h
 F:	include/dt-bindings/reset/mt7628-reset.h
 F:	drivers/clk/mtmips/
 F:	drivers/pinctrl/mtmips/
 F:	drivers/gpio/mt7620_gpio.c
+F:	drivers/mtd/nand/raw/mt7621_nand.c
 F:	drivers/net/mt7620-eth.c
 F:	drivers/phy/mt7620-usb-phy.c
 F:	drivers/reset/reset-mtmips.c
Signature · 1 line
2.17.1
#20 lore raw

Re: [PATCH v2 13/14] net: mediatek: add support for MediaTek MT7621 SoC

In reply to Weijie Gao
Quoted 60 lines · Weijie Gao

This patch adds GMAC support for MediaTek MT7621 SoC. MT7621 has the same GMAC/Switch configuration as MT7623.

---
v2 changes: none

---
 drivers/net/mtk_eth.c | 27 +++++++++++++++++++++------
 drivers/net/mtk_eth.h |  8 ++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
drivers/net/mtk_eth.c +14 -6
index 26f02847a2..3b42c99c2a 100644
@@ -145,7 +145,8 @@ enum mtk_switch {
 enum mtk_soc {
        SOC_MT7623,
        SOC_MT7629,
-       SOC_MT7622
+       SOC_MT7622,
+       SOC_MT7621
 };
 
 struct mtk_eth_priv {
@@ -669,12 +670,18 @@ static int mt7530_pad_clk_setup(struct mtk_eth_priv *priv, int mode)
 static int mt7530_setup(struct mtk_eth_priv *priv)
 {
        u16 phy_addr, phy_val;
-       u32 val;
+       u32 val, txdrv;
        int i;
 
-       /* Select 250MHz clk for RGMII mode */
-       mtk_ethsys_rmw(priv, ETHSYS_CLKCFG0_REG,
-                      ETHSYS_TRGMII_CLK_SEL362_5, 0);
+       if (priv->soc != SOC_MT7621) {
+               /* Select 250MHz clk for RGMII mode */
+               mtk_ethsys_rmw(priv, ETHSYS_CLKCFG0_REG,
+                              ETHSYS_TRGMII_CLK_SEL362_5, 0);
+
+               txdrv = 8;
+       } else {
+               txdrv = 4;
+       }
 
        /* Modify HWTRAP first to allow direct access to internal PHYs */
        mt753x_reg_read(priv, HWTRAP_REG, &val);
@@ -732,7 +739,8 @@ static int mt7530_setup(struct mtk_eth_priv *priv)
        /* Lower Tx Driving for TRGMII path */
        for (i = 0 ; i < NUM_TRGMII_CTRL ; i++)
                mt753x_reg_write(priv, MT7530_TRGMII_TD_ODT(i),
-                                (8 << TD_DM_DRVP_S) | (8 << TD_DM_DRVN_S));
+                                (txdrv << TD_DM_DRVP_S) |
+                                (txdrv << TD_DM_DRVN_S));
 
        for (i = 0 ; i < NUM_TRGMII_CTRL; i++)
                mt753x_reg_rmw(priv, MT7530_TRGMII_RD(i), RD_TAP_M, 16);

drivers/net/mtk_eth.c static int mtk_eth_of_to_plat(struct udevice *dev) · line 1449

Quoted 5 lines
drivers/net/mtk_eth.c +2 -0
@@ -1437,6 +1445,12 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
                return -ENODEV;
        }
 
+       if (priv->soc == SOC_MT7621) {
+               /* ioremap is needed for MIPS platform */

For MIPS ? you need to io map for every platform, some platform just works without it.

Quoted 20 lines
drivers/net/mtk_eth.c +5 -0
+               priv->ethsys_base =
+                       ioremap_nocache((phys_addr_t)priv->ethsys_base, 0x100);
+       }
+
        /* Reset controllers */
        ret = reset_get_by_name(dev, "fe", &priv->rst_fe);
        if (ret) {
@@ -1542,6 +1556,7 @@ static const struct udevice_id mtk_eth_ids[] = {
        { .compatible = "mediatek,mt7629-eth", .data = SOC_MT7629 },
        { .compatible = "mediatek,mt7623-eth", .data = SOC_MT7623 },
        { .compatible = "mediatek,mt7622-eth", .data = SOC_MT7622 },
+       { .compatible = "mediatek,mt7621-eth", .data = SOC_MT7621 },
        {}
 };
 
drivers/net/mtk_eth.h +0 -0
index 057ecfaabf..4a8c66c671 100644

drivers/net/mtk_eth.h line 420

Quoted 9 lines
drivers/net/mtk_eth.h +6 -0
@@ -412,4 +412,12 @@
 #define PHY_POWER_SAVING_M             0x300
 #define PHY_POWER_SAVING_TX            0x0
 
+#ifndef CONFIG_SYS_NONCACHED_MEMORY
+/*
+ * noncached_alloc is provided only for ARM. Add a prototype here for other
+ * platforms to suppress compilation warning.
+ */
+phys_addr_t noncached_alloc(size_t size, size_t align);

That's not the place for that. I assume that it fails on MIPS, please create a patch for MIPS arch.

Quoted 6 lines
drivers/net/mtk_eth.h +2 -1
+#endif
+
 #endif /* _MTK_ETH_H_ */
--

2.17.1

author
#21 lore raw

Re: [PATCH v2 13/14] net: mediatek: add support for MediaTek MT7621 SoC

Quoted 71 lines · Ramon Fried
Quoted 69 lines · Weijie Gao

This patch adds GMAC support for MediaTek MT7621 SoC. MT7621 has the same GMAC/Switch configuration as MT7623.

---
v2 changes: none

---
 drivers/net/mtk_eth.c | 27 +++++++++++++++++++++------
 drivers/net/mtk_eth.h |  8 ++++++++
 2 files changed, 29 insertions(+), 6 deletions(-)
drivers/net/mtk_eth.c +12 -5
index 26f02847a2..3b42c99c2a 100644
@@ -145,7 +145,8 @@ enum mtk_switch {
 enum mtk_soc {
        SOC_MT7623,
        SOC_MT7629,
-       SOC_MT7622
+       SOC_MT7622,
+       SOC_MT7621
 };
 
 struct mtk_eth_priv {
@@ -669,12 +670,18 @@ static int mt7530_pad_clk_setup(struct
 mtk_eth_priv *priv, int mode)
 static int mt7530_setup(struct mtk_eth_priv *priv)
 {
        u16 phy_addr, phy_val;
-       u32 val;
+       u32 val, txdrv;
        int i;
 
-       /* Select 250MHz clk for RGMII mode */
-       mtk_ethsys_rmw(priv, ETHSYS_CLKCFG0_REG,
-                      ETHSYS_TRGMII_CLK_SEL362_5, 0);
+       if (priv->soc != SOC_MT7621) {
+               /* Select 250MHz clk for RGMII mode */
+               mtk_ethsys_rmw(priv, ETHSYS_CLKCFG0_REG,
+                              ETHSYS_TRGMII_CLK_SEL362_5, 0);
+
+               txdrv = 8;
+       } else {
+               txdrv = 4;
+       }
 
        /* Modify HWTRAP first to allow direct access to internal

PHYs */

        mt753x_reg_read(priv, HWTRAP_REG, &val);
drivers/net/mtk_eth.c +2 -1
@@ -732,7 +739,8 @@ static int mt7530_setup(struct mtk_eth_priv
 *priv)
        /* Lower Tx Driving for TRGMII path */
        for (i = 0 ; i < NUM_TRGMII_CTRL ; i++)
                mt753x_reg_write(priv, MT7530_TRGMII_TD_ODT(i),
-                                (8 << TD_DM_DRVP_S) | (8 <<
 TD_DM_DRVN_S));
+                                (txdrv << TD_DM_DRVP_S) |
+                                (txdrv << TD_DM_DRVN_S));
 
        for (i = 0 ; i < NUM_TRGMII_CTRL; i++)
                mt753x_reg_rmw(priv, MT7530_TRGMII_RD(i), RD_TAP_M,

16);

drivers/net/mtk_eth.c +0 -0
@@ -1437,6 +1445,12 @@ static int mtk_eth_of_to_plat(struct udevice
 *dev)
                return -ENODEV;
        }
 
Quoted 5 lines

drivers/net/mtk_eth.c static int mtk_eth_of_to_plat(struct udevice *dev) · line 1449

Quoted 2 lines
drivers/net/mtk_eth.c +2 -0
+       if (priv->soc == SOC_MT7621) {
+               /* ioremap is needed for MIPS platform */

For MIPS ? you need to io map for every platform, some platform just works without it.

That's my mistake. The map_sysmem called by regmap_get_range is a dummy function for both arm and mips. But for arm the virtual address in u-boot is identical to the physical address and I didn't notice that.

I'll make ioremap unconditional.

Quoted 29 lines
Quoted 29 lines
drivers/net/mtk_eth.c +4 -0
+               priv->ethsys_base =
+                       ioremap_nocache((phys_addr_t)priv-
 >ethsys_base, 0x100);
+       }
+
        /* Reset controllers */
        ret = reset_get_by_name(dev, "fe", &priv->rst_fe);
        if (ret) {
drivers/net/mtk_eth.c +0 -0
@@ -1542,6 +1556,7 @@ static const struct udevice_id mtk_eth_ids[]
 = {
        { .compatible = "mediatek,mt7629-eth", .data = SOC_MT7629
 },
        { .compatible = "mediatek,mt7623-eth", .data = SOC_MT7623
 },
        { .compatible = "mediatek,mt7622-eth", .data = SOC_MT7622

},
+ { .compatible = "mediatek,mt7621-eth", .data = SOC_MT7621
},

        {}

};

drivers/net/mtk_eth.h +0 -0
index 057ecfaabf..4a8c66c671 100644
@@ -412,4 +412,12 @@
 #define PHY_POWER_SAVING_M             0x300
 #define PHY_POWER_SAVING_TX            0x0
 
Quoted 11 lines
Quoted 7 lines
drivers/net/mtk_eth.h +3 -0
+#ifndef CONFIG_SYS_NONCACHED_MEMORY
+/*
+ * noncached_alloc is provided only for ARM. Add a prototype here

for other
+ * platforms to suppress compilation warning.
+ */
+phys_addr_t noncached_alloc(size_t size, size_t align);

That's not the place for that. I assume that it fails on MIPS, please create a patch for MIPS arch.

OK. I'll create patches for MIPS

Quoted 6 lines
Quoted 6 lines
drivers/net/mtk_eth.h +2 -1
+#endif
+
 #endif /* _MTK_ETH_H_ */
--

2.17.1

Reviewed-by on v2 12/14
#18 lore raw

Re: [PATCH v2 12/14] mmc: mediatek: add support for MediaTek MT7621 SoC

In reply to Weijie Gao
Quoted 3 lines · Weijie Gao

This patch adds SDXC support for MediaTek MT7621 SoC

Best Regards,
Jaehoon Chung

Quoted 38 lines

---
v2 changes: none

---
 drivers/mmc/mtk-sd.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/mmc/mtk-sd.c +13 -0
index 8599f095bc..1199052a89 100644
@@ -1746,6 +1746,18 @@ static const struct msdc_compatible mt7620_compat = {
 	.default_pad_dly = true,
 };
 
+static const struct msdc_compatible mt7621_compat = {
+	.clk_div_bits = 8,
+	.pad_tune0 = false,
+	.async_fifo = true,
+	.data_tune = true,
+	.busy_check = false,
+	.stop_clk_fix = false,
+	.enhance_rx = false,
+	.builtin_pad_ctrl = true,
+	.default_pad_dly = true,
+};
+
 static const struct msdc_compatible mt7622_compat = {
 	.clk_div_bits = 12,
 	.pad_tune0 = true,
@@ -1794,6 +1806,7 @@ static const struct msdc_compatible mt8183_compat = {
 
 static const struct udevice_id msdc_ids[] = {
 	{ .compatible = "mediatek,mt7620-mmc", .data = (ulong)&mt7620_compat },
+	{ .compatible = "mediatek,mt7621-mmc", .data = (ulong)&mt7621_compat },
 	{ .compatible = "mediatek,mt7622-mmc", .data = (ulong)&mt7622_compat },
 	{ .compatible = "mediatek,mt7623-mmc", .data = (ulong)&mt7623_compat },
 	{ .compatible = "mediatek,mt8512-mmc", .data = (ulong)&mt8512_compat },
#4 lore raw

Re: [PATCH v2 03/14] clk: mtmips: add clock driver for MediaTek MT7621 SoC

In reply to Weijie Gao
Quoted 45 lines · Weijie Gao

This patch adds a clock driver for MediaTek MT7621 SoC.
This driver provides clock gate control as well as getting clock frequency for CPU/SYS/XTAL and some peripherals.

---
v2 changes: none

---
  drivers/clk/mtmips/Makefile            |   1 +
  drivers/clk/mtmips/clk-mt7621.c        | 260 +++++++++++++++++++++++++
  include/dt-bindings/clock/mt7621-clk.h |  42 ++++
  3 files changed, 303 insertions(+)

create mode 100644 drivers/clk/mtmips/clk-mt7621.c create mode 100644 include/dt-bindings/clock/mt7621-clk.h

drivers/clk/mtmips/Makefile +1 -0
index 732e7f2545..ee8b5afe87 100644
@@ -1,4 +1,5 @@
  # SPDX-License-Identifier: GPL-2.0
 
  obj-$(CONFIG_SOC_MT7620) += clk-mt7620.o
+obj-$(CONFIG_SOC_MT7621) += clk-mt7621.o
  obj-$(CONFIG_SOC_MT7628) += clk-mt7628.o
drivers/clk/mtmips/clk-mt7621.c new file +14 -0
new file mode 100644
index 0000000000..3799d1806a
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <dm/device_compat.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <dt-bindings/clock/mt7621-clk.h>

drivers/clk/mtmips/clk-mt7621.c line 24

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+#include <linux/bitops.h>
+#include <linux/io.h>
+
+#define SYSC_MAP_SIZE			0x100
+#define MEMC_MAP_SIZE			0x1000
+
+/* SYSC */
+#define SYSCFG0_REG			0x10
+#define XTAL_MODE_SEL_S			6
+#define XTAL_MODE_SEL_M			0x1c0

Please use genmask to define this:

#define XTAL_MODE_SEL_M GENMASK(8, 6)

and SEL_S is unnecessary, see commentary below.

Quoted 23 lines
drivers/clk/mtmips/clk-mt7621.c new file +23 -0
+
+#define CLKCFG0_REG			0x2c
+#define CPU_CLK_SEL_S			30
+#define CPU_CLK_SEL_M			0xc0000000
+#define PERI_CLK_SEL			0x10
+
+#define CLKCFG1_REG			0x30
+
+#define CUR_CLK_STS_REG			0x44
+#define CUR_CPU_FDIV_S			8
+#define CUR_CPU_FDIV_M			0x1f00
+#define CUR_CPU_FFRAC_S			0
+#define CUR_CPU_FFRAC_M			0x1f
+
+/* MEMC */
+#define MEMPLL1_REG			0x0604
+#define RG_MEPL_DIV2_SEL_S		1
+#define RG_MEPL_DIV2_SEL_M		0x06
+
+#define MEMPLL6_REG			0x0618
+#define MEMPLL18_REG			0x0648
+#define RG_MEPL_PREDIV_S		12
+#define RG_MEPL_PREDIV_M		0x3000

drivers/clk/mtmips/clk-mt7621.c line 57

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+#define RG_MEPL_FBDIV_S			4
+#define RG_MEPL_FBDIV_M			0x7f0
+
+/* Clock sources */
+#define CLK_SRC_CPU			-1
+#define CLK_SRC_CPU_D2			-2
+#define CLK_SRC_DDR			-3
+#define CLK_SRC_SYS			-4
+#define CLK_SRC_XTAL			-5
+#define CLK_SRC_PERI			-6

Please use an enum. And why are these negative?

Quoted 43 lines
drivers/clk/mtmips/clk-mt7621.c new file +43 -0
+/* EPLL clock */
+#define EPLL_CLK			50000000
+
+struct mt7621_clk_priv {
+	void __iomem *sysc_base;
+	void __iomem *memc_base;
+	int cpu_clk;
+	int ddr_clk;
+	int sys_clk;
+	int xtal_clk;
+};
+
+static const int mt7621_clks[] = {
+	[CLK_SYS] = CLK_SRC_SYS,
+	[CLK_DDR] = CLK_SRC_DDR,
+	[CLK_CPU] = CLK_SRC_CPU,
+	[CLK_XTAL] = CLK_SRC_XTAL,
+	[CLK_MIPS_CNT] = CLK_SRC_CPU_D2,
+	[CLK_UART3] = CLK_SRC_PERI,
+	[CLK_UART2] = CLK_SRC_PERI,
+	[CLK_UART1] = CLK_SRC_PERI,
+	[CLK_SPI] = CLK_SRC_SYS,
+	[CLK_I2C] = CLK_SRC_PERI,
+	[CLK_TIMER] = CLK_SRC_PERI,
+};
+
+static ulong mt7621_clk_get_rate(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+	u32 val;
+
+	if (clk->id >= ARRAY_SIZE(mt7621_clks))
+		return 0;
+
+	switch (mt7621_clks[clk->id]) {
+	case CLK_SRC_CPU:
+		return priv->cpu_clk;
+	case CLK_SRC_CPU_D2:
+		return priv->cpu_clk / 2;
+	case CLK_SRC_DDR:
+		return priv->ddr_clk;
+	case CLK_SRC_SYS:
+		return priv->sys_clk;

drivers/clk/mtmips/clk-mt7621.c line 111

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+	case CLK_SRC_XTAL:
+		return priv->xtal_clk;
+	case CLK_SRC_PERI:
+		val = readl(priv->sysc_base + CLKCFG0_REG);
+		if (val & PERI_CLK_SEL)
+			return priv->xtal_clk;
+		else
+			return EPLL_CLK;
+	default:
+		return 0;

-ENOSYS

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 8 lines
drivers/clk/mtmips/clk-mt7621.c new file +8 -0
+	}
+}
+
+static int mt7621_clk_enable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)

Please compare with a symbol.

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 1 line
drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		return -1;

-ENOSYS

Quoted 25 lines
drivers/clk/mtmips/clk-mt7621.c new file +25 -0
+
+	setbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk->id));
+
+	return 0;
+}
+
+static int mt7621_clk_disable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)
+		return -1;
+
+	clrbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk->id));
+
+	return 0;
+}
+
+const struct clk_ops mt7621_clk_ops = {
+	.enable = mt7621_clk_enable,
+	.disable = mt7621_clk_disable,
+	.get_rate = mt7621_clk_get_rate,
+};
+
+static void mt7621_get_clocks(struct mt7621_clk_priv *priv)

drivers/clk/mtmips/clk-mt7621.c line 155

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+{
+	u32 bs, xtal_sel, clkcfg0, cur_clk, mempll, dividx, fb;
+	u32 xtal_clk, xtal_div, ffiv, ffrac, cpu_clk, ddr_clk;
+	static const u32 xtal_div_tbl[] = {0, 1, 2, 2};
+
+	bs = readl(priv->sysc_base + SYSCFG0_REG);
+	clkcfg0 = readl(priv->sysc_base + CLKCFG0_REG);
+	cur_clk = readl(priv->sysc_base + CUR_CLK_STS_REG);
+
+	xtal_sel = (bs & XTAL_MODE_SEL_M) >> XTAL_MODE_SEL_S;

xtal_sel = FIELD_GET(XTAL_MODE_SEL_M, bs);

drivers/clk/mtmips/clk-mt7621.c line 164

Quoted 9 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+
+	if (xtal_sel <= 2)
+		xtal_clk = 20 * 1000 * 1000;
+	else if (xtal_sel <= 5)
+		xtal_clk = 40 * 1000 * 1000;
+	else
+		xtal_clk = 25 * 1000 * 1000;
+
+	switch ((clkcfg0 & CPU_CLK_SEL_M) >> CPU_CLK_SEL_S) {

ditto

drivers/clk/mtmips/clk-mt7621.c line 171

Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +7 -0
+	case 0:
+		cpu_clk = 500 * 1000 * 1000;
+		break;
+	case 1:
+		mempll = readl(priv->memc_base + MEMPLL18_REG);
+		dividx = (mempll & RG_MEPL_PREDIV_M) >> RG_MEPL_PREDIV_S;
+		fb = (mempll & RG_MEPL_FBDIV_M) >> RG_MEPL_FBDIV_S;

ditto

drivers/clk/mtmips/clk-mt7621.c line 180

Quoted 9 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+		xtal_div = 1 << xtal_div_tbl[dividx];
+		cpu_clk = (fb + 1) * xtal_clk / xtal_div;
+		break;
+	default:
+		cpu_clk = xtal_clk;
+	}
+
+	ffiv = (cur_clk & CUR_CPU_FDIV_M) >> CUR_CPU_FDIV_S;
+	ffrac = (cur_clk & CUR_CPU_FFRAC_M) >> CUR_CPU_FFRAC_S;

ditto

drivers/clk/mtmips/clk-mt7621.c line 185

Quoted 5 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	cpu_clk = cpu_clk / ffiv * ffrac;
+
+	mempll = readl(priv->memc_base + MEMPLL6_REG);
+	dividx = (mempll & RG_MEPL_PREDIV_M) >> RG_MEPL_PREDIV_S;
+	fb = (mempll & RG_MEPL_FBDIV_M) >> RG_MEPL_FBDIV_S;

ditto

drivers/clk/mtmips/clk-mt7621.c line 190

Quoted 5 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	xtal_div = 1 << xtal_div_tbl[dividx];
+	ddr_clk = fb * xtal_clk / xtal_div;
+
+	bs = readl(priv->memc_base + MEMPLL1_REG);
+	if (((bs & RG_MEPL_DIV2_SEL_M) >> RG_MEPL_DIV2_SEL_S) == 0)

ditto

and you can just use

	if (!cond)

drivers/clk/mtmips/clk-mt7621.c line 196

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+		ddr_clk *= 2;
+
+	priv->cpu_clk = cpu_clk;
+	priv->sys_clk = cpu_clk / 4;
+	priv->ddr_clk = ddr_clk;
+	priv->xtal_clk = xtal_clk;

Please implement the above logic in get_rate(). For example:

static ulong do_mt7621_clk_get_rate()

{
	...
	switch (clk->id) {
		case CLK_SYS:
			cpu_clk = do_mt7621_clk_get_rate(priv, CLK_SYS);
			return IS_ERROR_VALUE(cpu_clk) ? cpu_clk : cpu_clk / 4;
		...
	}
}

static ulong mt7621_clk_get_rate()

{
	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);

	return do_mt7621_clk_get_rate(priv, clk->id);
}
Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +7 -0
+}
+
+static int mt7621_clk_probe(struct udevice *dev)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(dev);
+	struct ofnode_phandle_args args;
+	struct regmap *regmap;

drivers/clk/mtmips/clk-mt7621.c line 213

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+	void __iomem *base;
+	int ret;
+
+	/* get corresponding sysc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,sysc", NULL, 0, 0,
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);

According to the Linux binding for this node, it is supposed to live under the syscon already. So you can do

	syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));

and skip the phandle.

drivers/clk/mtmips/clk-mt7621.c line 219

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find sysc\n");

dev_dbg (see doc/develop/driver-model/design.rst)

drivers/clk/mtmips/clk-mt7621.c line 226

Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +7 -0
+		return -ENODEV;
+	}
+
+	priv->sysc_base = ioremap_nocache((phys_addr_t)base, SYSC_MAP_SIZE);
+
+	/* get corresponding memc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,memc", NULL, 0, 0,

should be "ralink,memctl".

drivers/clk/mtmips/clk-mt7621.c line 215

Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +7 -0
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);

These two steps can be compined with syscon_regmap_lookup_by_phandle.

drivers/clk/mtmips/clk-mt7621.c line 237

Quoted 3 lines
drivers/clk/mtmips/clk-mt7621.c new file +3 -0
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find memc\n");

dev_dbg

Quoted 35 lines
drivers/clk/mtmips/clk-mt7621.c new file +23 -0
+		return -ENODEV;
+	}
+
+	priv->memc_base = ioremap_nocache((phys_addr_t)base, MEMC_MAP_SIZE);
+
+	mt7621_get_clocks(priv);
+
+	return 0;
+}
+
+static const struct udevice_id mt7621_clk_ids[] = {
+	{ .compatible = "mediatek,mt7621-clk" },
+	{ }
+};
+
+U_BOOT_DRIVER(mt7621_clk) = {
+	.name = "mt7621-clk",
+	.id = UCLASS_CLK,
+	.of_match = mt7621_clk_ids,
+	.probe = mt7621_clk_probe,
+	.priv_auto = sizeof(struct mt7621_clk_priv),
+	.ops = &mt7621_clk_ops,
+};
include/dt-bindings/clock/mt7621-clk.h new file +6 -0
new file mode 100644
index 0000000000..b24aef351c
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 MediaTek Inc. All rights reserved.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */

include/dt-bindings/clock/mt7621-clk.h line 16

Quoted 10 lines
include/dt-bindings/clock/mt7621-clk.h new file +10 -0
+
+#ifndef _DT_BINDINGS_MT7621_CLK_H_
+#define _DT_BINDINGS_MT7621_CLK_H_
+
+/* Base clocks */
+#define CLK_MIPS_CNT			36
+#define CLK_SYS				35
+#define CLK_DDR				34
+#define CLK_CPU				33
+#define CLK_XTAL			32

Why is there a gap?

Quoted 15 lines
include/dt-bindings/clock/mt7621-clk.h new file +15 -0
+/* Peripheral clocks */
+#define CLK_SDXC			30
+#define CLK_CRYPTO			29
+#define CLK_PCIE2			26
+#define CLK_PCIE1			25
+#define CLK_PCIE0			24
+#define CLK_GMAC			23
+#define CLK_UART3			21
+#define CLK_UART2			20
+#define CLK_UART1			19
+#define CLK_SPI				18
+#define CLK_I2S				17
+#define CLK_I2C				16
+#define CLK_NFI				15
+#define CLK_GDMA			14

include/dt-bindings/clock/mt7621-clk.h line 42

Quoted 10 lines
include/dt-bindings/clock/mt7621-clk.h new file +10 -0
+#define CLK_PIO				13
+#define CLK_PCM				11
+#define CLK_MC				10
+#define CLK_INTC			9
+#define CLK_TIMER			8
+#define CLK_SPDIFTX			7
+#define CLK_FE				6
+#define CLK_HSDMA			5
+
+#endif /* _DT_BINDINGS_MT7621_CLK_H_ */

This file looks very different from include/dt-bindings/clock/mt7621-clk.h in Linux. In particular, it is backwards, the IDs are different (HSDMA is 8 in Linux but 5 here), some of the IDs are named differently (SP_DIVTX vs SPDIFTX), and there is no MT7621 prefix. Can you comment on these? Are they deliberate? Note that in general, numerical IDs should be kept the same between Linux and U-Boot so we can use the same device tree. If you need to map between logical clock ID and a position in a register, I suggest something like

struct {
	u8 gate_bit;
} clocks {
	[CLK_HSDMA] = { .gate_bit = 5 },
};

--Sean

author
#5 lore raw

Re: [PATCH v2 03/14] clk: mtmips: add clock driver for MediaTek MT7621 SoC

Quoted 94 lines · Sean Anderson
Quoted 49 lines · Weijie Gao

This patch adds a clock driver for MediaTek MT7621 SoC. This driver provides clock gate control as well as getting clock frequency
for CPU/SYS/XTAL and some peripherals.

---
v2 changes: none

---
  drivers/clk/mtmips/Makefile            |   1 +
  drivers/clk/mtmips/clk-mt7621.c        | 260
+++++++++++++++++++++++++
  include/dt-bindings/clock/mt7621-clk.h |  42 ++++
  3 files changed, 303 insertions(+)

create mode 100644 drivers/clk/mtmips/clk-mt7621.c create mode 100644 include/dt-bindings/clock/mt7621-clk.h

drivers/clk/mtmips/Makefile +1 -0
index 732e7f2545..ee8b5afe87 100644
@@ -1,4 +1,5 @@
  # SPDX-License-Identifier: GPL-2.0
 
  obj-$(CONFIG_SOC_MT7620) += clk-mt7620.o
+obj-$(CONFIG_SOC_MT7621) += clk-mt7621.o
  obj-$(CONFIG_SOC_MT7628) += clk-mt7628.o
drivers/clk/mtmips/clk-mt7621.c new file +14 -0
new file mode 100644
index 0000000000..3799d1806a
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <dm/device_compat.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <dt-bindings/clock/mt7621-clk.h>

drivers/clk/mtmips/clk-mt7621.c line 24

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+#include <linux/bitops.h>
+#include <linux/io.h>
+
+#define SYSC_MAP_SIZE			0x100
+#define MEMC_MAP_SIZE			0x1000
+
+/* SYSC */
+#define SYSCFG0_REG			0x10
+#define XTAL_MODE_SEL_S			6
+#define XTAL_MODE_SEL_M			0x1c0

Please use genmask to define this:

#define XTAL_MODE_SEL_M GENMASK(8, 6)

and SEL_S is unnecessary, see commentary below.

Quoted 27 lines
drivers/clk/mtmips/clk-mt7621.c new file +27 -0
+
+#define CLKCFG0_REG			0x2c
+#define CPU_CLK_SEL_S			30
+#define CPU_CLK_SEL_M			0xc0000000
+#define PERI_CLK_SEL			0x10
+
+#define CLKCFG1_REG			0x30
+
+#define CUR_CLK_STS_REG			0x44
+#define CUR_CPU_FDIV_S			8
+#define CUR_CPU_FDIV_M			0x1f00
+#define CUR_CPU_FFRAC_S			0
+#define CUR_CPU_FFRAC_M			0x1f
+
+/* MEMC */
+#define MEMPLL1_REG			0x0604
+#define RG_MEPL_DIV2_SEL_S		1
+#define RG_MEPL_DIV2_SEL_M		0x06
+
+#define MEMPLL6_REG			0x0618
+#define MEMPLL18_REG			0x0648
+#define RG_MEPL_PREDIV_S		12
+#define RG_MEPL_PREDIV_M		0x3000
+#define RG_MEPL_FBDIV_S			4
+#define RG_MEPL_FBDIV_M			0x7f0
+
+/* Clock sources */
Quoted 8 lines

drivers/clk/mtmips/clk-mt7621.c line 57

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+#define CLK_SRC_CPU			-1
+#define CLK_SRC_CPU_D2			-2
+#define CLK_SRC_DDR			-3
+#define CLK_SRC_SYS			-4
+#define CLK_SRC_XTAL			-5
+#define CLK_SRC_PERI			-6

Please use an enum. And why are these negative?

I'll rewrite this

Quoted 57 lines
Quoted 44 lines
drivers/clk/mtmips/clk-mt7621.c new file +43 -0
+/* EPLL clock */
+#define EPLL_CLK			50000000
+
+struct mt7621_clk_priv {
+	void __iomem *sysc_base;
+	void __iomem *memc_base;
+	int cpu_clk;
+	int ddr_clk;
+	int sys_clk;
+	int xtal_clk;
+};
+
+static const int mt7621_clks[] = {
+	[CLK_SYS] = CLK_SRC_SYS,
+	[CLK_DDR] = CLK_SRC_DDR,
+	[CLK_CPU] = CLK_SRC_CPU,
+	[CLK_XTAL] = CLK_SRC_XTAL,
+	[CLK_MIPS_CNT] = CLK_SRC_CPU_D2,
+	[CLK_UART3] = CLK_SRC_PERI,
+	[CLK_UART2] = CLK_SRC_PERI,
+	[CLK_UART1] = CLK_SRC_PERI,
+	[CLK_SPI] = CLK_SRC_SYS,
+	[CLK_I2C] = CLK_SRC_PERI,
+	[CLK_TIMER] = CLK_SRC_PERI,
+};
+
+static ulong mt7621_clk_get_rate(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+	u32 val;
+
+	if (clk->id >= ARRAY_SIZE(mt7621_clks))
+		return 0;
+
+	switch (mt7621_clks[clk->id]) {
+	case CLK_SRC_CPU:
+		return priv->cpu_clk;
+	case CLK_SRC_CPU_D2:
+		return priv->cpu_clk / 2;
+	case CLK_SRC_DDR:
+		return priv->ddr_clk;
+	case CLK_SRC_SYS:
+		return priv->sys_clk;

drivers/clk/mtmips/clk-mt7621.c line 111

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+	case CLK_SRC_XTAL:
+		return priv->xtal_clk;
+	case CLK_SRC_PERI:
+		val = readl(priv->sysc_base + CLKCFG0_REG);
+		if (val & PERI_CLK_SEL)
+			return priv->xtal_clk;
+		else
+			return EPLL_CLK;
+	default:
+		return 0;

-ENOSYS

Quoted 10 lines

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 8 lines
drivers/clk/mtmips/clk-mt7621.c new file +8 -0
+	}
+}
+
+static int mt7621_clk_enable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)

Please compare with a symbol.

OK. actually the clock gate register is 32-bit, and 31 is the MSB.

Quoted 34 lines

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 2 lines
drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		return -1;

-ENOSYS

Quoted 29 lines
drivers/clk/mtmips/clk-mt7621.c new file +29 -0
+
+	setbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk->id));
+
+	return 0;
+}
+
+static int mt7621_clk_disable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)
+		return -1;
+
+	clrbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk->id));
+
+	return 0;
+}
+
+const struct clk_ops mt7621_clk_ops = {
+	.enable = mt7621_clk_enable,
+	.disable = mt7621_clk_disable,
+	.get_rate = mt7621_clk_get_rate,
+};
+
+static void mt7621_get_clocks(struct mt7621_clk_priv *priv)
+{
+	u32 bs, xtal_sel, clkcfg0, cur_clk, mempll, dividx, fb;
+	u32 xtal_clk, xtal_div, ffiv, ffrac, cpu_clk, ddr_clk;
+	static const u32 xtal_div_tbl[] = {0, 1, 2, 2};
Quoted 8 lines

drivers/clk/mtmips/clk-mt7621.c line 155

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+
+	bs = readl(priv->sysc_base + SYSCFG0_REG);
+	clkcfg0 = readl(priv->sysc_base + CLKCFG0_REG);
+	cur_clk = readl(priv->sysc_base + CUR_CLK_STS_REG);
+
+	xtal_sel = (bs & XTAL_MODE_SEL_M) >> XTAL_MODE_SEL_S;

xtal_sel = FIELD_GET(XTAL_MODE_SEL_M, bs);

got it.

Quoted 80 lines

drivers/clk/mtmips/clk-mt7621.c line 164

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+
+	if (xtal_sel <= 2)
+		xtal_clk = 20 * 1000 * 1000;
+	else if (xtal_sel <= 5)
+		xtal_clk = 40 * 1000 * 1000;
+	else
+		xtal_clk = 25 * 1000 * 1000;
+
+	switch ((clkcfg0 & CPU_CLK_SEL_M) >> CPU_CLK_SEL_S) {

ditto

Quoted 9 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+	case 0:
+		cpu_clk = 500 * 1000 * 1000;
+		break;
+	case 1:
+		mempll = readl(priv->memc_base + MEMPLL18_REG);
+		dividx = (mempll & RG_MEPL_PREDIV_M) >>

RG_MEPL_PREDIV_S;

drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		fb = (mempll & RG_MEPL_FBDIV_M) >>

RG_MEPL_FBDIV_S;

ditto

drivers/clk/mtmips/clk-mt7621.c line 180

Quoted 9 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+		xtal_div = 1 << xtal_div_tbl[dividx];
+		cpu_clk = (fb + 1) * xtal_clk / xtal_div;
+		break;
+	default:
+		cpu_clk = xtal_clk;
+	}
+
+	ffiv = (cur_clk & CUR_CPU_FDIV_M) >> CUR_CPU_FDIV_S;
+	ffrac = (cur_clk & CUR_CPU_FFRAC_M) >> CUR_CPU_FFRAC_S;

ditto

drivers/clk/mtmips/clk-mt7621.c line 185

Quoted 5 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	cpu_clk = cpu_clk / ffiv * ffrac;
+
+	mempll = readl(priv->memc_base + MEMPLL6_REG);
+	dividx = (mempll & RG_MEPL_PREDIV_M) >> RG_MEPL_PREDIV_S;
+	fb = (mempll & RG_MEPL_FBDIV_M) >> RG_MEPL_FBDIV_S;

ditto

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	xtal_div = 1 << xtal_div_tbl[dividx];
+	ddr_clk = fb * xtal_clk / xtal_div;
+
+	bs = readl(priv->memc_base + MEMPLL1_REG);
+	if (((bs & RG_MEPL_DIV2_SEL_M) >> RG_MEPL_DIV2_SEL_S) ==

0)

ditto

and you can just use

	if (!cond)

drivers/clk/mtmips/clk-mt7621.c line 196

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+		ddr_clk *= 2;
+
+	priv->cpu_clk = cpu_clk;
+	priv->sys_clk = cpu_clk / 4;
+	priv->ddr_clk = ddr_clk;
+	priv->xtal_clk = xtal_clk;

Please implement the above logic in get_rate(). For example:

static ulong do_mt7621_clk_get_rate()

{
	...
	switch (clk->id) {
		case CLK_SYS:
			cpu_clk = do_mt7621_clk_get_rate(priv,
CLK_SYS);
			return IS_ERROR_VALUE(cpu_clk) ? cpu_clk :
cpu_clk / 4;
		...
	}
}
Quoted 6 lines

static ulong mt7621_clk_get_rate()

{
	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);

	return do_mt7621_clk_get_rate(priv, clk->id);
}

ok

Quoted 23 lines
Quoted 14 lines
drivers/clk/mtmips/clk-mt7621.c new file +12 -0
+}
+
+static int mt7621_clk_probe(struct udevice *dev)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(dev);
+	struct ofnode_phandle_args args;
+	struct regmap *regmap;
+	void __iomem *base;
+	int ret;
+
+	/* get corresponding sysc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,sysc",

NULL, 0, 0,

drivers/clk/mtmips/clk-mt7621.c line 213

Quoted 5 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);

According to the Linux binding for this node, it is supposed to live under the syscon already. So you can do

Quoted 3 lines
	syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));

and skip the phandle.

I'll try this

Quoted 9 lines

drivers/clk/mtmips/clk-mt7621.c line 219

Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find sysc\n");

dev_dbg (see doc/develop/driver-model/design.rst)

ok

Quoted 12 lines
Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +4 -0
+		return -ENODEV;
+	}
+
+	priv->sysc_base = ioremap_nocache((phys_addr_t)base,

SYSC_MAP_SIZE);

drivers/clk/mtmips/clk-mt7621.c new file +3 -0
+
+	/* get corresponding memc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,memc",

NULL, 0, 0,

should be "ralink,memctl".

ok

Quoted 58 lines

drivers/clk/mtmips/clk-mt7621.c line 215

Quoted 8 lines
drivers/clk/mtmips/clk-mt7621.c new file +7 -0
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);

These two steps can be compined with syscon_regmap_lookup_by_phandle.

drivers/clk/mtmips/clk-mt7621.c line 237

Quoted 3 lines
drivers/clk/mtmips/clk-mt7621.c new file +3 -0
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find memc\n");

dev_dbg

Quoted 41 lines
drivers/clk/mtmips/clk-mt7621.c new file +4 -0
+		return -ENODEV;
+	}
+
+	priv->memc_base = ioremap_nocache((phys_addr_t)base,

MEMC_MAP_SIZE);

drivers/clk/mtmips/clk-mt7621.c new file +19 -0
+
+	mt7621_get_clocks(priv);
+
+	return 0;
+}
+
+static const struct udevice_id mt7621_clk_ids[] = {
+	{ .compatible = "mediatek,mt7621-clk" },
+	{ }
+};
+
+U_BOOT_DRIVER(mt7621_clk) = {
+	.name = "mt7621-clk",
+	.id = UCLASS_CLK,
+	.of_match = mt7621_clk_ids,
+	.probe = mt7621_clk_probe,
+	.priv_auto = sizeof(struct mt7621_clk_priv),
+	.ops = &mt7621_clk_ops,
+};
include/dt- renamed from include/dt-bindings/clock/mt7621-clk.h +0 -0

bindings/clock/mt7621-clk.h
new file mode 100644
index 0000000000..b24aef351c

include/dt-bindings/clock/mt7621-clk.h new file +10 -0
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 MediaTek Inc. All rights reserved.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_MT7621_CLK_H_
+#define _DT_BINDINGS_MT7621_CLK_H_
+
Quoted 8 lines

include/dt-bindings/clock/mt7621-clk.h line 16

Quoted 6 lines
include/dt-bindings/clock/mt7621-clk.h new file +6 -0
+/* Base clocks */
+#define CLK_MIPS_CNT			36
+#define CLK_SYS				35
+#define CLK_DDR				34
+#define CLK_CPU				33
+#define CLK_XTAL			32

Why is there a gap?

0~31 values are bits in clock gate register, and bit 31 is unused. values above 31 represent clock sources not defined in the gate register.

Quoted 22 lines
Quoted 22 lines
include/dt-bindings/clock/mt7621-clk.h new file +21 -0
+/* Peripheral clocks */
+#define CLK_SDXC			30
+#define CLK_CRYPTO			29
+#define CLK_PCIE2			26
+#define CLK_PCIE1			25
+#define CLK_PCIE0			24
+#define CLK_GMAC			23
+#define CLK_UART3			21
+#define CLK_UART2			20
+#define CLK_UART1			19
+#define CLK_SPI				18
+#define CLK_I2S				17
+#define CLK_I2C				16
+#define CLK_NFI				15
+#define CLK_GDMA			14
+#define CLK_PIO				13
+#define CLK_PCM				11
+#define CLK_MC				10
+#define CLK_INTC			9
+#define CLK_TIMER			8
+#define CLK_SPDIFTX			7
Quoted 8 lines

include/dt-bindings/clock/mt7621-clk.h line 42

Quoted 4 lines
include/dt-bindings/clock/mt7621-clk.h new file +4 -0
+#define CLK_FE				6
+#define CLK_HSDMA			5
+
+#endif /* _DT_BINDINGS_MT7621_CLK_H_ */

This file looks very different from include/dt-bindings/clock/mt7621-clk.h in Linux. In particular, it is backwards, the IDs are different (HSDMA is 8 in Linux but 5 here),

5 directly represents the bit in clock gate register, which means a mapping must be done for the include/dt-bindings/clock/mt7621-clk.h (i.e. subtract by 3) in kernel.

btw, the file in kernel is not submitted by mediatek.

Quoted 4 lines

some
of the IDs are named differently (SP_DIVTX vs SPDIFTX), and there is no
MT7621 prefix. Can you comment on these? Are they deliberate?

The name SPDIFTX comes from the MT7621 programming guide of mediatek. Adding MT7621 seems better.

Quoted 6 lines

Note that
in general, numerical IDs should be kept the same between Linux and U-Boot so we can use the same device tree. If you need to map between logical clock ID and a position in a register, I suggest something like

Quoted 6 lines
struct {
	u8 gate_bit;
} clocks {
	[CLK_HSDMA] = { .gate_bit = 5 },
};

This is a driver dedicated for u-boot, and actually only the SYS clock is used. I believe using correct gate bit number is clearer.

Quoted 1 line

--Sean

#6 lore raw

Re: [PATCH v2 03/14] clk: mtmips: add clock driver for MediaTek MT7621 SoC

Hi Weijie,

(sorry for the delayed response)

Quoted 174 lines · Weijie Gao
Quoted 94 lines · Sean Anderson
Quoted 49 lines · Weijie Gao

This patch adds a clock driver for MediaTek MT7621 SoC. This driver provides clock gate control as well as getting clock frequency
for CPU/SYS/XTAL and some peripherals.

---
v2 changes: none

---
   drivers/clk/mtmips/Makefile            |   1 +
   drivers/clk/mtmips/clk-mt7621.c        | 260
+++++++++++++++++++++++++
   include/dt-bindings/clock/mt7621-clk.h |  42 ++++
   3 files changed, 303 insertions(+)

create mode 100644 drivers/clk/mtmips/clk-mt7621.c create mode 100644 include/dt-bindings/clock/mt7621-clk.h

drivers/clk/mtmips/Makefile +1 -0
index 732e7f2545..ee8b5afe87 100644
@@ -1,4 +1,5 @@
   # SPDX-License-Identifier: GPL-2.0
 
   obj-$(CONFIG_SOC_MT7620) += clk-mt7620.o
+obj-$(CONFIG_SOC_MT7621) += clk-mt7621.o
   obj-$(CONFIG_SOC_MT7628) += clk-mt7628.o
drivers/clk/mtmips/clk-mt7621.c new file +14 -0
new file mode 100644
index 0000000000..3799d1806a
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <dm/device_compat.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <dt-bindings/clock/mt7621-clk.h>

drivers/clk/mtmips/clk-mt7621.c line 24

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+#include <linux/bitops.h>
+#include <linux/io.h>
+
+#define SYSC_MAP_SIZE			0x100
+#define MEMC_MAP_SIZE			0x1000
+
+/* SYSC */
+#define SYSCFG0_REG			0x10
+#define XTAL_MODE_SEL_S			6
+#define XTAL_MODE_SEL_M			0x1c0

Please use genmask to define this:

#define XTAL_MODE_SEL_M GENMASK(8, 6)

and SEL_S is unnecessary, see commentary below.

Quoted 27 lines
drivers/clk/mtmips/clk-mt7621.c new file +27 -0
+
+#define CLKCFG0_REG			0x2c
+#define CPU_CLK_SEL_S			30
+#define CPU_CLK_SEL_M			0xc0000000
+#define PERI_CLK_SEL			0x10
+
+#define CLKCFG1_REG			0x30
+
+#define CUR_CLK_STS_REG			0x44
+#define CUR_CPU_FDIV_S			8
+#define CUR_CPU_FDIV_M			0x1f00
+#define CUR_CPU_FFRAC_S			0
+#define CUR_CPU_FFRAC_M			0x1f
+
+/* MEMC */
+#define MEMPLL1_REG			0x0604
+#define RG_MEPL_DIV2_SEL_S		1
+#define RG_MEPL_DIV2_SEL_M		0x06
+
+#define MEMPLL6_REG			0x0618
+#define MEMPLL18_REG			0x0648
+#define RG_MEPL_PREDIV_S		12
+#define RG_MEPL_PREDIV_M		0x3000
+#define RG_MEPL_FBDIV_S			4
+#define RG_MEPL_FBDIV_M			0x7f0
+
+/* Clock sources */
Quoted 8 lines

drivers/clk/mtmips/clk-mt7621.c line 57

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+#define CLK_SRC_CPU			-1
+#define CLK_SRC_CPU_D2			-2
+#define CLK_SRC_DDR			-3
+#define CLK_SRC_SYS			-4
+#define CLK_SRC_XTAL			-5
+#define CLK_SRC_PERI			-6

Please use an enum. And why are these negative?

I'll rewrite this

Quoted 57 lines
Quoted 44 lines
drivers/clk/mtmips/clk-mt7621.c new file +43 -0
+/* EPLL clock */
+#define EPLL_CLK			50000000
+
+struct mt7621_clk_priv {
+	void __iomem *sysc_base;
+	void __iomem *memc_base;
+	int cpu_clk;
+	int ddr_clk;
+	int sys_clk;
+	int xtal_clk;
+};
+
+static const int mt7621_clks[] = {
+	[CLK_SYS] = CLK_SRC_SYS,
+	[CLK_DDR] = CLK_SRC_DDR,
+	[CLK_CPU] = CLK_SRC_CPU,
+	[CLK_XTAL] = CLK_SRC_XTAL,
+	[CLK_MIPS_CNT] = CLK_SRC_CPU_D2,
+	[CLK_UART3] = CLK_SRC_PERI,
+	[CLK_UART2] = CLK_SRC_PERI,
+	[CLK_UART1] = CLK_SRC_PERI,
+	[CLK_SPI] = CLK_SRC_SYS,
+	[CLK_I2C] = CLK_SRC_PERI,
+	[CLK_TIMER] = CLK_SRC_PERI,
+};
+
+static ulong mt7621_clk_get_rate(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+	u32 val;
+
+	if (clk->id >= ARRAY_SIZE(mt7621_clks))
+		return 0;
+
+	switch (mt7621_clks[clk->id]) {
+	case CLK_SRC_CPU:
+		return priv->cpu_clk;
+	case CLK_SRC_CPU_D2:
+		return priv->cpu_clk / 2;
+	case CLK_SRC_DDR:
+		return priv->ddr_clk;
+	case CLK_SRC_SYS:
+		return priv->sys_clk;

drivers/clk/mtmips/clk-mt7621.c line 111

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+	case CLK_SRC_XTAL:
+		return priv->xtal_clk;
+	case CLK_SRC_PERI:
+		val = readl(priv->sysc_base + CLKCFG0_REG);
+		if (val & PERI_CLK_SEL)
+			return priv->xtal_clk;
+		else
+			return EPLL_CLK;
+	default:
+		return 0;

-ENOSYS

Quoted 10 lines

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 8 lines
drivers/clk/mtmips/clk-mt7621.c new file +8 -0
+	}
+}
+
+static int mt7621_clk_enable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)

Please compare with a symbol.

Quoted 1 line

OK. actually the clock gate register is 32-bit, and 31 is the MSB.

see below

Quoted 257 lines
Quoted 34 lines

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 2 lines
drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		return -1;

-ENOSYS

Quoted 29 lines
drivers/clk/mtmips/clk-mt7621.c new file +29 -0
+
+	setbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk->id));
+
+	return 0;
+}
+
+static int mt7621_clk_disable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)
+		return -1;
+
+	clrbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk->id));
+
+	return 0;
+}
+
+const struct clk_ops mt7621_clk_ops = {
+	.enable = mt7621_clk_enable,
+	.disable = mt7621_clk_disable,
+	.get_rate = mt7621_clk_get_rate,
+};
+
+static void mt7621_get_clocks(struct mt7621_clk_priv *priv)
+{
+	u32 bs, xtal_sel, clkcfg0, cur_clk, mempll, dividx, fb;
+	u32 xtal_clk, xtal_div, ffiv, ffrac, cpu_clk, ddr_clk;
+	static const u32 xtal_div_tbl[] = {0, 1, 2, 2};
Quoted 8 lines

drivers/clk/mtmips/clk-mt7621.c line 155

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+
+	bs = readl(priv->sysc_base + SYSCFG0_REG);
+	clkcfg0 = readl(priv->sysc_base + CLKCFG0_REG);
+	cur_clk = readl(priv->sysc_base + CUR_CLK_STS_REG);
+
+	xtal_sel = (bs & XTAL_MODE_SEL_M) >> XTAL_MODE_SEL_S;

xtal_sel = FIELD_GET(XTAL_MODE_SEL_M, bs);

got it.

Quoted 80 lines

drivers/clk/mtmips/clk-mt7621.c line 164

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+
+	if (xtal_sel <= 2)
+		xtal_clk = 20 * 1000 * 1000;
+	else if (xtal_sel <= 5)
+		xtal_clk = 40 * 1000 * 1000;
+	else
+		xtal_clk = 25 * 1000 * 1000;
+
+	switch ((clkcfg0 & CPU_CLK_SEL_M) >> CPU_CLK_SEL_S) {

ditto

Quoted 9 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+	case 0:
+		cpu_clk = 500 * 1000 * 1000;
+		break;
+	case 1:
+		mempll = readl(priv->memc_base + MEMPLL18_REG);
+		dividx = (mempll & RG_MEPL_PREDIV_M) >>

RG_MEPL_PREDIV_S;

drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		fb = (mempll & RG_MEPL_FBDIV_M) >>

RG_MEPL_FBDIV_S;

ditto

drivers/clk/mtmips/clk-mt7621.c line 180

Quoted 9 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+		xtal_div = 1 << xtal_div_tbl[dividx];
+		cpu_clk = (fb + 1) * xtal_clk / xtal_div;
+		break;
+	default:
+		cpu_clk = xtal_clk;
+	}
+
+	ffiv = (cur_clk & CUR_CPU_FDIV_M) >> CUR_CPU_FDIV_S;
+	ffrac = (cur_clk & CUR_CPU_FFRAC_M) >> CUR_CPU_FFRAC_S;

ditto

drivers/clk/mtmips/clk-mt7621.c line 185

Quoted 5 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	cpu_clk = cpu_clk / ffiv * ffrac;
+
+	mempll = readl(priv->memc_base + MEMPLL6_REG);
+	dividx = (mempll & RG_MEPL_PREDIV_M) >> RG_MEPL_PREDIV_S;
+	fb = (mempll & RG_MEPL_FBDIV_M) >> RG_MEPL_FBDIV_S;

ditto

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	xtal_div = 1 << xtal_div_tbl[dividx];
+	ddr_clk = fb * xtal_clk / xtal_div;
+
+	bs = readl(priv->memc_base + MEMPLL1_REG);
+	if (((bs & RG_MEPL_DIV2_SEL_M) >> RG_MEPL_DIV2_SEL_S) ==

0)

ditto

and you can just use

	if (!cond)

drivers/clk/mtmips/clk-mt7621.c line 196

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+		ddr_clk *= 2;
+
+	priv->cpu_clk = cpu_clk;
+	priv->sys_clk = cpu_clk / 4;
+	priv->ddr_clk = ddr_clk;
+	priv->xtal_clk = xtal_clk;

Please implement the above logic in get_rate(). For example:

static ulong do_mt7621_clk_get_rate()

{
	...
	switch (clk->id) {
		case CLK_SYS:
			cpu_clk = do_mt7621_clk_get_rate(priv,
CLK_SYS);
			return IS_ERROR_VALUE(cpu_clk) ? cpu_clk :
cpu_clk / 4;
		...
	}
}
Quoted 6 lines

static ulong mt7621_clk_get_rate()

{
	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);

	return do_mt7621_clk_get_rate(priv, clk->id);
}

ok

Quoted 23 lines
Quoted 14 lines
drivers/clk/mtmips/clk-mt7621.c new file +12 -0
+}
+
+static int mt7621_clk_probe(struct udevice *dev)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(dev);
+	struct ofnode_phandle_args args;
+	struct regmap *regmap;
+	void __iomem *base;
+	int ret;
+
+	/* get corresponding sysc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,sysc",

NULL, 0, 0,

drivers/clk/mtmips/clk-mt7621.c line 213

Quoted 5 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);

According to the Linux binding for this node, it is supposed to live under the syscon already. So you can do

Quoted 3 lines
	syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));

and skip the phandle.

I'll try this

Quoted 9 lines

drivers/clk/mtmips/clk-mt7621.c line 219

Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find sysc\n");

dev_dbg (see doc/develop/driver-model/design.rst)

ok

Quoted 12 lines
Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +4 -0
+		return -ENODEV;
+	}
+
+	priv->sysc_base = ioremap_nocache((phys_addr_t)base,

SYSC_MAP_SIZE);

drivers/clk/mtmips/clk-mt7621.c new file +3 -0
+
+	/* get corresponding memc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,memc",

NULL, 0, 0,

should be "ralink,memctl".

ok

Quoted 58 lines

drivers/clk/mtmips/clk-mt7621.c line 215

Quoted 8 lines
drivers/clk/mtmips/clk-mt7621.c new file +7 -0
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);

These two steps can be compined with syscon_regmap_lookup_by_phandle.

drivers/clk/mtmips/clk-mt7621.c line 237

Quoted 3 lines
drivers/clk/mtmips/clk-mt7621.c new file +3 -0
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find memc\n");

dev_dbg

Quoted 41 lines
drivers/clk/mtmips/clk-mt7621.c new file +4 -0
+		return -ENODEV;
+	}
+
+	priv->memc_base = ioremap_nocache((phys_addr_t)base,

MEMC_MAP_SIZE);

drivers/clk/mtmips/clk-mt7621.c new file +19 -0
+
+	mt7621_get_clocks(priv);
+
+	return 0;
+}
+
+static const struct udevice_id mt7621_clk_ids[] = {
+	{ .compatible = "mediatek,mt7621-clk" },
+	{ }
+};
+
+U_BOOT_DRIVER(mt7621_clk) = {
+	.name = "mt7621-clk",
+	.id = UCLASS_CLK,
+	.of_match = mt7621_clk_ids,
+	.probe = mt7621_clk_probe,
+	.priv_auto = sizeof(struct mt7621_clk_priv),
+	.ops = &mt7621_clk_ops,
+};
include/dt- renamed from include/dt-bindings/clock/mt7621-clk.h +0 -0

bindings/clock/mt7621-clk.h
new file mode 100644
index 0000000000..b24aef351c

include/dt-bindings/clock/mt7621-clk.h new file +10 -0
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 MediaTek Inc. All rights reserved.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_MT7621_CLK_H_
+#define _DT_BINDINGS_MT7621_CLK_H_
+
Quoted 8 lines

include/dt-bindings/clock/mt7621-clk.h line 16

Quoted 6 lines
include/dt-bindings/clock/mt7621-clk.h new file +6 -0
+/* Base clocks */
+#define CLK_MIPS_CNT			36
+#define CLK_SYS				35
+#define CLK_DDR				34
+#define CLK_CPU				33
+#define CLK_XTAL			32

Why is there a gap?

Quoted 3 lines

0~31 values are bits in clock gate register, and bit 31 is unused. values above 31 represent clock sources not defined in the gate register.

OK, but above your check is for clock IDs less than 31. So shouldn't it be something like

	if (clk->id > CLK_SDXC)
		return -EINVAL;
Quoted 31 lines
Quoted 22 lines
Quoted 22 lines
include/dt-bindings/clock/mt7621-clk.h new file +21 -0
+/* Peripheral clocks */
+#define CLK_SDXC			30
+#define CLK_CRYPTO			29
+#define CLK_PCIE2			26
+#define CLK_PCIE1			25
+#define CLK_PCIE0			24
+#define CLK_GMAC			23
+#define CLK_UART3			21
+#define CLK_UART2			20
+#define CLK_UART1			19
+#define CLK_SPI				18
+#define CLK_I2S				17
+#define CLK_I2C				16
+#define CLK_NFI				15
+#define CLK_GDMA			14
+#define CLK_PIO				13
+#define CLK_PCM				11
+#define CLK_MC				10
+#define CLK_INTC			9
+#define CLK_TIMER			8
+#define CLK_SPDIFTX			7
Quoted 8 lines

include/dt-bindings/clock/mt7621-clk.h line 42

Quoted 4 lines
include/dt-bindings/clock/mt7621-clk.h new file +4 -0
+#define CLK_FE				6
+#define CLK_HSDMA			5
+
+#endif /* _DT_BINDINGS_MT7621_CLK_H_ */

This file looks very different from include/dt-bindings/clock/mt7621-clk.h in Linux. In particular, it is backwards, the IDs are different (HSDMA is 8 in Linux but 5 here),

Quoted 5 lines

5 directly represents the bit in clock gate register, which means a mapping must be done for the include/dt-bindings/clock/mt7621-clk.h (i.e. subtract by 3) in kernel.

btw, the file in kernel is not submitted by mediatek.

I think aligning the defines with the names in the datasheet is a good idea. Can you send a patch to Linux to update the names of the defines?

Quoted 20 lines
Quoted 4 lines

some
of the IDs are named differently (SP_DIVTX vs SPDIFTX), and there is no
MT7621 prefix. Can you comment on these? Are they deliberate?

The name SPDIFTX comes from the MT7621 programming guide of mediatek. Adding MT7621 seems better.

Quoted 6 lines

Note that
in general, numerical IDs should be kept the same between Linux and U-Boot so we can use the same device tree. If you need to map between logical clock ID and a position in a register, I suggest something like

Quoted 6 lines
struct {
	u8 gate_bit;
} clocks {
	[CLK_HSDMA] = { .gate_bit = 5 },
};
Quoted 2 lines

This is a driver dedicated for u-boot, and actually only the SYS clock is used. I believe using correct gate bit number is clearer.

It is fine to implement only the necessary functionality, but it should be done in a way which is easy to extend in the future, and which won't cause us compatibility problems.

Generally, I would like to preserve both source and binary compatibility with Linux where possible. I am not sure whether they are hard requirements, so I made a post regarding that question [1]. For now, addressing my above comments will be fine.

--Sean

[1] https://lore.kernel.org/u-boot/[email protected]/T/#u

author
#7 lore raw

Re: [PATCH v2 03/14] clk: mtmips: add clock driver for MediaTek MT7621 SoC

Quoted 541 lines · Sean Anderson

Hi Weijie,

(sorry for the delayed response)

Quoted 175 lines · Weijie Gao
Quoted 95 lines · Sean Anderson
Quoted 50 lines · Weijie Gao

This patch adds a clock driver for MediaTek MT7621 SoC. This driver provides clock gate control as well as getting clock
frequency
for CPU/SYS/XTAL and some peripherals.

---
v2 changes: none

---
   drivers/clk/mtmips/Makefile            |   1 +
   drivers/clk/mtmips/clk-mt7621.c        | 260
+++++++++++++++++++++++++
   include/dt-bindings/clock/mt7621-clk.h |  42 ++++
   3 files changed, 303 insertions(+)

create mode 100644 drivers/clk/mtmips/clk-mt7621.c create mode 100644 include/dt-bindings/clock/mt7621-clk.h

drivers/clk/mtmips/Makefile +1 -0
index 732e7f2545..ee8b5afe87 100644
@@ -1,4 +1,5 @@
   # SPDX-License-Identifier: GPL-2.0
 
   obj-$(CONFIG_SOC_MT7620) += clk-mt7620.o
+obj-$(CONFIG_SOC_MT7621) += clk-mt7621.o
   obj-$(CONFIG_SOC_MT7628) += clk-mt7628.o
drivers/clk/mtmips/clk-mt7621.c new file +14 -0
new file mode 100644
index 0000000000..3799d1806a
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2021 MediaTek Inc. All Rights Reserved.
+ *
+ * Author: Weijie Gao <[email protected]>
+ */
+
+#include <common.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <dm/device_compat.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <dt-bindings/clock/mt7621-clk.h>

drivers/clk/mtmips/clk-mt7621.c line 24

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+#include <linux/bitops.h>
+#include <linux/io.h>
+
+#define SYSC_MAP_SIZE			0x100
+#define MEMC_MAP_SIZE			0x1000
+
+/* SYSC */
+#define SYSCFG0_REG			0x10
+#define XTAL_MODE_SEL_S			6
+#define XTAL_MODE_SEL_M			0x1c0

Please use genmask to define this:

#define XTAL_MODE_SEL_M GENMASK(8, 6)

and SEL_S is unnecessary, see commentary below.

Quoted 27 lines
drivers/clk/mtmips/clk-mt7621.c new file +27 -0
+
+#define CLKCFG0_REG			0x2c
+#define CPU_CLK_SEL_S			30
+#define CPU_CLK_SEL_M			0xc0000000
+#define PERI_CLK_SEL			0x10
+
+#define CLKCFG1_REG			0x30
+
+#define CUR_CLK_STS_REG			0x44
+#define CUR_CPU_FDIV_S			8
+#define CUR_CPU_FDIV_M			0x1f00
+#define CUR_CPU_FFRAC_S			0
+#define CUR_CPU_FFRAC_M			0x1f
+
+/* MEMC */
+#define MEMPLL1_REG			0x0604
+#define RG_MEPL_DIV2_SEL_S		1
+#define RG_MEPL_DIV2_SEL_M		0x06
+
+#define MEMPLL6_REG			0x0618
+#define MEMPLL18_REG			0x0648
+#define RG_MEPL_PREDIV_S		12
+#define RG_MEPL_PREDIV_M		0x3000
+#define RG_MEPL_FBDIV_S			4
+#define RG_MEPL_FBDIV_M			0x7f0
+
+/* Clock sources */
Quoted 8 lines

drivers/clk/mtmips/clk-mt7621.c line 57

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+#define CLK_SRC_CPU			-1
+#define CLK_SRC_CPU_D2			-2
+#define CLK_SRC_DDR			-3
+#define CLK_SRC_SYS			-4
+#define CLK_SRC_XTAL			-5
+#define CLK_SRC_PERI			-6

Please use an enum. And why are these negative?

I'll rewrite this

Quoted 57 lines
Quoted 44 lines
drivers/clk/mtmips/clk-mt7621.c new file +43 -0
+/* EPLL clock */
+#define EPLL_CLK			50000000
+
+struct mt7621_clk_priv {
+	void __iomem *sysc_base;
+	void __iomem *memc_base;
+	int cpu_clk;
+	int ddr_clk;
+	int sys_clk;
+	int xtal_clk;
+};
+
+static const int mt7621_clks[] = {
+	[CLK_SYS] = CLK_SRC_SYS,
+	[CLK_DDR] = CLK_SRC_DDR,
+	[CLK_CPU] = CLK_SRC_CPU,
+	[CLK_XTAL] = CLK_SRC_XTAL,
+	[CLK_MIPS_CNT] = CLK_SRC_CPU_D2,
+	[CLK_UART3] = CLK_SRC_PERI,
+	[CLK_UART2] = CLK_SRC_PERI,
+	[CLK_UART1] = CLK_SRC_PERI,
+	[CLK_SPI] = CLK_SRC_SYS,
+	[CLK_I2C] = CLK_SRC_PERI,
+	[CLK_TIMER] = CLK_SRC_PERI,
+};
+
+static ulong mt7621_clk_get_rate(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+	u32 val;
+
+	if (clk->id >= ARRAY_SIZE(mt7621_clks))
+		return 0;
+
+	switch (mt7621_clks[clk->id]) {
+	case CLK_SRC_CPU:
+		return priv->cpu_clk;
+	case CLK_SRC_CPU_D2:
+		return priv->cpu_clk / 2;
+	case CLK_SRC_DDR:
+		return priv->ddr_clk;
+	case CLK_SRC_SYS:
+		return priv->sys_clk;

drivers/clk/mtmips/clk-mt7621.c line 111

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +10 -0
+	case CLK_SRC_XTAL:
+		return priv->xtal_clk;
+	case CLK_SRC_PERI:
+		val = readl(priv->sysc_base + CLKCFG0_REG);
+		if (val & PERI_CLK_SEL)
+			return priv->xtal_clk;
+		else
+			return EPLL_CLK;
+	default:
+		return 0;

-ENOSYS

Quoted 10 lines

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 8 lines
drivers/clk/mtmips/clk-mt7621.c new file +8 -0
+	}
+}
+
+static int mt7621_clk_enable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)

Please compare with a symbol.

Quoted 1 line

OK. actually the clock gate register is 32-bit, and 31 is the MSB.

see below

Quoted 267 lines
Quoted 37 lines

drivers/clk/mtmips/clk-mt7621.c line 119

Quoted 2 lines
drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		return -1;

-ENOSYS

Quoted 32 lines
drivers/clk/mtmips/clk-mt7621.c new file +2 -0
+
+	setbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk-
Quoted 1 line

id));

drivers/clk/mtmips/clk-mt7621.c new file +12 -0
+
+	return 0;
+}
+
+static int mt7621_clk_disable(struct clk *clk)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (clk->id > 31)
+		return -1;
+
+	clrbits_32(priv->sysc_base + CLKCFG1_REG, BIT(clk-
Quoted 1 line

id));

drivers/clk/mtmips/clk-mt7621.c new file +13 -0
+
+	return 0;
+}
+
+const struct clk_ops mt7621_clk_ops = {
+	.enable = mt7621_clk_enable,
+	.disable = mt7621_clk_disable,
+	.get_rate = mt7621_clk_get_rate,
+};
+
+static void mt7621_get_clocks(struct mt7621_clk_priv *priv)
+{
+	u32 bs, xtal_sel, clkcfg0, cur_clk, mempll, dividx,

fb;

drivers/clk/mtmips/clk-mt7621.c new file +2 -0
+	u32 xtal_clk, xtal_div, ffiv, ffrac, cpu_clk, ddr_clk;
+	static const u32 xtal_div_tbl[] = {0, 1, 2, 2};
Quoted 8 lines

drivers/clk/mtmips/clk-mt7621.c line 155

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+
+	bs = readl(priv->sysc_base + SYSCFG0_REG);
+	clkcfg0 = readl(priv->sysc_base + CLKCFG0_REG);
+	cur_clk = readl(priv->sysc_base + CUR_CLK_STS_REG);
+
+	xtal_sel = (bs & XTAL_MODE_SEL_M) >> XTAL_MODE_SEL_S;

xtal_sel = FIELD_GET(XTAL_MODE_SEL_M, bs);

got it.

Quoted 84 lines

drivers/clk/mtmips/clk-mt7621.c line 164

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+
+	if (xtal_sel <= 2)
+		xtal_clk = 20 * 1000 * 1000;
+	else if (xtal_sel <= 5)
+		xtal_clk = 40 * 1000 * 1000;
+	else
+		xtal_clk = 25 * 1000 * 1000;
+
+	switch ((clkcfg0 & CPU_CLK_SEL_M) >> CPU_CLK_SEL_S) {

ditto

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	case 0:
+		cpu_clk = 500 * 1000 * 1000;
+		break;
+	case 1:
+		mempll = readl(priv->memc_base +

MEMPLL18_REG);

drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		dividx = (mempll & RG_MEPL_PREDIV_M) >>

RG_MEPL_PREDIV_S;

drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+		fb = (mempll & RG_MEPL_FBDIV_M) >>

RG_MEPL_FBDIV_S;

ditto

Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +9 -0
+		xtal_div = 1 << xtal_div_tbl[dividx];
+		cpu_clk = (fb + 1) * xtal_clk / xtal_div;
+		break;
+	default:
+		cpu_clk = xtal_clk;
+	}
+
+	ffiv = (cur_clk & CUR_CPU_FDIV_M) >> CUR_CPU_FDIV_S;
+	ffrac = (cur_clk & CUR_CPU_FFRAC_M) >>

CUR_CPU_FFRAC_S;

ditto

drivers/clk/mtmips/clk-mt7621.c

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +4 -0
+	cpu_clk = cpu_clk / ffiv * ffrac;
+
+	mempll = readl(priv->memc_base + MEMPLL6_REG);
+	dividx = (mempll & RG_MEPL_PREDIV_M) >>

RG_MEPL_PREDIV_S;

drivers/clk/mtmips/clk-mt7621.c new file +1 -0
+	fb = (mempll & RG_MEPL_FBDIV_M) >> RG_MEPL_FBDIV_S;

ditto

Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+	xtal_div = 1 << xtal_div_tbl[dividx];
+	ddr_clk = fb * xtal_clk / xtal_div;
+
+	bs = readl(priv->memc_base + MEMPLL1_REG);
+	if (((bs & RG_MEPL_DIV2_SEL_M) >> RG_MEPL_DIV2_SEL_S)

==
0)

ditto

and you can just use

	if (!cond)

drivers/clk/mtmips/clk-mt7621.c line 196

Quoted 6 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+		ddr_clk *= 2;
+
+	priv->cpu_clk = cpu_clk;
+	priv->sys_clk = cpu_clk / 4;
+	priv->ddr_clk = ddr_clk;
+	priv->xtal_clk = xtal_clk;

Please implement the above logic in get_rate(). For example:

static ulong do_mt7621_clk_get_rate()

{
	...
	switch (clk->id) {
		case CLK_SYS:
			cpu_clk = do_mt7621_clk_get_rate(priv,
CLK_SYS);
			return IS_ERROR_VALUE(cpu_clk) ? cpu_clk :
cpu_clk / 4;
		...
	}
}
Quoted 6 lines

static ulong mt7621_clk_get_rate()

{
	struct mt7621_clk_priv *priv = dev_get_priv(clk->dev);

	return do_mt7621_clk_get_rate(priv, clk->id);
}

ok

Quoted 24 lines
Quoted 14 lines
drivers/clk/mtmips/clk-mt7621.c new file +12 -0
+}
+
+static int mt7621_clk_probe(struct udevice *dev)
+{
+	struct mt7621_clk_priv *priv = dev_get_priv(dev);
+	struct ofnode_phandle_args args;
+	struct regmap *regmap;
+	void __iomem *base;
+	int ret;
+
+	/* get corresponding sysc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,sysc",

NULL, 0, 0,

drivers/clk/mtmips/clk-mt7621.c line 213

Quoted 5 lines
drivers/clk/mtmips/clk-mt7621.c new file +5 -0
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);

According to the Linux binding for this node, it is supposed to live
under the syscon already. So you can do

Quoted 3 lines
	syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));

and skip the phandle.

I'll try this

Quoted 9 lines

drivers/clk/mtmips/clk-mt7621.c line 219

Quoted 7 lines
drivers/clk/mtmips/clk-mt7621.c new file +6 -0
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);
+
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find sysc\n");

dev_dbg (see doc/develop/driver-model/design.rst)

ok

Quoted 12 lines
Quoted 10 lines
drivers/clk/mtmips/clk-mt7621.c new file +4 -0
+		return -ENODEV;
+	}
+
+	priv->sysc_base = ioremap_nocache((phys_addr_t)base,

SYSC_MAP_SIZE);

drivers/clk/mtmips/clk-mt7621.c new file +3 -0
+
+	/* get corresponding memc phandle */
+	ret = dev_read_phandle_with_args(dev, "mediatek,memc",

NULL, 0, 0,

should be "ralink,memctl".

ok

Quoted 60 lines

drivers/clk/mtmips/clk-mt7621.c line 215

Quoted 8 lines
drivers/clk/mtmips/clk-mt7621.c new file +7 -0
+					 &args);
+	if (ret)
+		return ret;
+
+	regmap = syscon_node_to_regmap(args.node);
+	if (IS_ERR(regmap))
+		return PTR_ERR(regmap);

These two steps can be compined with
syscon_regmap_lookup_by_phandle.

drivers/clk/mtmips/clk-mt7621.c line 237

Quoted 3 lines
drivers/clk/mtmips/clk-mt7621.c new file +3 -0
+	base = regmap_get_range(regmap, 0);
+	if (!base) {
+		dev_err(dev, "Unable to find memc\n");

dev_dbg

Quoted 42 lines
drivers/clk/mtmips/clk-mt7621.c new file +4 -0
+		return -ENODEV;
+	}
+
+	priv->memc_base = ioremap_nocache((phys_addr_t)base,

MEMC_MAP_SIZE);

drivers/clk/mtmips/clk-mt7621.c new file +19 -0
+
+	mt7621_get_clocks(priv);
+
+	return 0;
+}
+
+static const struct udevice_id mt7621_clk_ids[] = {
+	{ .compatible = "mediatek,mt7621-clk" },
+	{ }
+};
+
+U_BOOT_DRIVER(mt7621_clk) = {
+	.name = "mt7621-clk",
+	.id = UCLASS_CLK,
+	.of_match = mt7621_clk_ids,
+	.probe = mt7621_clk_probe,
+	.priv_auto = sizeof(struct mt7621_clk_priv),
+	.ops = &mt7621_clk_ops,
+};
include/dt- renamed from include/dt-bindings/clock/mt7621-clk.h +0 -0

bindings/clock/mt7621-clk.h
new file mode 100644
index 0000000000..b24aef351c

include/dt-bindings/clock/mt7621-clk.h new file +10 -0
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2021 MediaTek Inc. All rights reserved.
+ *
+ * Author:  Weijie Gao <[email protected]>
+ */
+
+#ifndef _DT_BINDINGS_MT7621_CLK_H_
+#define _DT_BINDINGS_MT7621_CLK_H_
+
Quoted 8 lines

include/dt-bindings/clock/mt7621-clk.h line 16

Quoted 6 lines
include/dt-bindings/clock/mt7621-clk.h new file +6 -0
+/* Base clocks */
+#define CLK_MIPS_CNT			36
+#define CLK_SYS				35
+#define CLK_DDR				34
+#define CLK_CPU				33
+#define CLK_XTAL			32

Why is there a gap?

Quoted 3 lines

0~31 values are bits in clock gate register, and bit 31 is unused. values above 31 represent clock sources not defined in the gate register.

OK, but above your check is for clock IDs less than 31. So shouldn't it
be something like

	if (clk->id > CLK_SDXC)
		return -EINVAL;
Quoted 33 lines
Quoted 24 lines
Quoted 24 lines
include/dt-bindings/clock/mt7621-clk.h new file +23 -0
+/* Peripheral clocks */
+#define CLK_SDXC			30
+#define CLK_CRYPTO			29
+#define CLK_PCIE2			26
+#define CLK_PCIE1			25
+#define CLK_PCIE0			24
+#define CLK_GMAC			23
+#define CLK_UART3			21
+#define CLK_UART2			20
+#define CLK_UART1			19
+#define CLK_SPI				18
+#define CLK_I2S				17
+#define CLK_I2C				16
+#define CLK_NFI				15
+#define CLK_GDMA			14
+#define CLK_PIO				13
+#define CLK_PCM				11
+#define CLK_MC				10
+#define CLK_INTC			9
+#define CLK_TIMER			8
+#define CLK_SPDIFTX			7
+#define CLK_FE				6
+#define CLK_HSDMA			5
Quoted 8 lines

include/dt-bindings/clock/mt7621-clk.h line 42

Quoted 2 lines
include/dt-bindings/clock/mt7621-clk.h new file +2 -0
+
+#endif /* _DT_BINDINGS_MT7621_CLK_H_ */

This file looks very different from include/dt-bindings/clock/mt7621-clk.h in Linux. In particular, it is
backwards, the IDs are different (HSDMA is 8 in Linux but 5 here),

Quoted 5 lines

5 directly represents the bit in clock gate register, which means a mapping must be done for the include/dt-bindings/clock/mt7621-clk.h (i.e. subtract by 3) in kernel.

btw, the file in kernel is not submitted by mediatek.

I think aligning the defines with the names in the datasheet is a good
idea. Can you send a patch to Linux to update the names of the defines?

Quoted 25 lines
Quoted 5 lines

some
of the IDs are named differently (SP_DIVTX vs SPDIFTX), and there is
no
MT7621 prefix. Can you comment on these? Are they deliberate?

The name SPDIFTX comes from the MT7621 programming guide of mediatek.
Adding MT7621 seems better.

Quoted 9 lines

Note that
in general, numerical IDs should be kept the same between Linux and
U-Boot so we can use the same device tree. If you need to map between
logical clock ID and a position in a register, I suggest something
like

Quoted 6 lines
struct {
	u8 gate_bit;
} clocks {
	[CLK_HSDMA] = { .gate_bit = 5 },
};
Quoted 3 lines

This is a driver dedicated for u-boot, and actually only the SYS clock
is used. I believe using correct gate bit number is clearer.

It is fine to implement only the necessary functionality, but it should
be done in a way which is easy to extend in the future, and which won't
cause us compatibility problems.

Quoted 5 lines

Generally, I would like to preserve both source and binary compatibility
with Linux where possible. I am not sure whether they are hard requirements, so I made a post regarding that question [1]. For now, addressing my above comments will be fine.

I agreed.
But now I decide to write a simple driver which provides only the bus clock. It seems that I don't have much time for rewrite the full clock driver at present.

Quoted 5 lines

--Sean

[1] https://lore.kernel.org/u-boot/c670a4cc-b234-03d4-adfb-e6a8560c2d
[email protected]/T/#u

#8 lore raw

Re: [PATCH v2 03/14] clk: mtmips: add clock driver for MediaTek MT7621 SoC

Quoted 14 lines · Weijie Gao
Quoted 11 lines · Sean Anderson

It is fine to implement only the necessary functionality, but it should
be done in a way which is easy to extend in the future, and which won't
cause us compatibility problems.

Generally, I would like to preserve both source and binary compatibility
with Linux where possible. I am not sure whether they are hard requirements, so I made a post regarding that question [1]. For now, addressing my above comments will be fine.

Quoted 4 lines

I agreed.
But now I decide to write a simple driver which provides only the bus clock. It seems that I don't have much time for rewrite the full clock driver at present.

Well, all you have to do is something like

switch (clk->id) {
case MT7621_CLK_TIMER:

    mask = CLKCFG1_TIMER;
    break;

/* etc */
}

or use an array if you like that style better.

--Sean