1 From e0c82f36ad5180d9582d353407ff1bf34a2734bb Mon Sep 17 00:00:00 2001
2 From: Weijie Gao <weijie.gao@mediatek.com>
3 Date: Fri, 20 May 2022 11:22:21 +0800
4 Subject: [PATCH 05/25] mips: mtmips: add support for MediaTek MT7621 SoC
6 This patch adds support for MediaTek MT7621 SoC.
7 All files are dedicated for u-boot.
9 The default build target is u-boot-mt7621.bin.
11 The specification of this chip:
12 https://www.mediatek.com/products/homenetworking/mt7621
14 Reviewed-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
15 Signed-off-by: Weijie Gao <weijie.gao@mediatek.com>
17 arch/mips/dts/mt7621-u-boot.dtsi | 111 ++++++
18 arch/mips/dts/mt7621.dtsi | 349 +++++++++++++++++++
19 arch/mips/mach-mtmips/Kconfig | 49 ++-
20 arch/mips/mach-mtmips/Makefile | 4 +
21 arch/mips/mach-mtmips/cpu.c | 2 +-
22 arch/mips/mach-mtmips/mt7621/Kconfig | 95 +++++
23 arch/mips/mach-mtmips/mt7621/Makefile | 14 +
24 arch/mips/mach-mtmips/mt7621/init.c | 246 +++++++++++++
25 arch/mips/mach-mtmips/mt7621/mt7621.h | 229 ++++++++++++
26 arch/mips/mach-mtmips/mt7621/serial.c | 23 ++
27 arch/mips/mach-mtmips/mt7621/spl/Makefile | 9 +
28 arch/mips/mach-mtmips/mt7621/spl/cps.c | 153 ++++++++
29 arch/mips/mach-mtmips/mt7621/spl/dram.c | 153 ++++++++
30 arch/mips/mach-mtmips/mt7621/spl/dram.h | 39 +++
31 arch/mips/mach-mtmips/mt7621/spl/launch.c | 100 ++++++
32 arch/mips/mach-mtmips/mt7621/spl/launch.h | 52 +++
33 arch/mips/mach-mtmips/mt7621/spl/launch_ll.S | 339 ++++++++++++++++++
34 arch/mips/mach-mtmips/mt7621/spl/serial.c | 24 ++
35 arch/mips/mach-mtmips/mt7621/spl/spl.c | 95 +++++
36 arch/mips/mach-mtmips/mt7621/spl/start.S | 226 ++++++++++++
37 arch/mips/mach-mtmips/mt7621/sram_init.S | 22 ++
38 arch/mips/mach-mtmips/mt7621/tpl/Makefile | 4 +
39 arch/mips/mach-mtmips/mt7621/tpl/start.S | 161 +++++++++
40 arch/mips/mach-mtmips/mt7621/tpl/tpl.c | 144 ++++++++
41 include/configs/mt7621.h | 65 ++++
42 25 files changed, 2702 insertions(+), 6 deletions(-)
43 create mode 100644 arch/mips/dts/mt7621-u-boot.dtsi
44 create mode 100644 arch/mips/dts/mt7621.dtsi
45 create mode 100644 arch/mips/mach-mtmips/mt7621/Kconfig
46 create mode 100644 arch/mips/mach-mtmips/mt7621/Makefile
47 create mode 100644 arch/mips/mach-mtmips/mt7621/init.c
48 create mode 100644 arch/mips/mach-mtmips/mt7621/mt7621.h
49 create mode 100644 arch/mips/mach-mtmips/mt7621/serial.c
50 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/Makefile
51 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/cps.c
52 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/dram.c
53 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/dram.h
54 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/launch.c
55 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/launch.h
56 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/launch_ll.S
57 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/serial.c
58 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/spl.c
59 create mode 100644 arch/mips/mach-mtmips/mt7621/spl/start.S
60 create mode 100644 arch/mips/mach-mtmips/mt7621/sram_init.S
61 create mode 100644 arch/mips/mach-mtmips/mt7621/tpl/Makefile
62 create mode 100644 arch/mips/mach-mtmips/mt7621/tpl/start.S
63 create mode 100644 arch/mips/mach-mtmips/mt7621/tpl/tpl.c
64 create mode 100644 include/configs/mt7621.h
67 +++ b/arch/mips/dts/mt7621-u-boot.dtsi
69 +// SPDX-License-Identifier: GPL-2.0
71 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
73 + * Author: Weijie Gao <weijie.gao@mediatek.com>
76 +#include <linux/stringify.h>
85 + u-boot,dm-pre-reloc;
89 + u-boot,dm-pre-reloc;
93 + u-boot,dm-pre-reloc;
97 + u-boot,dm-pre-reloc;
101 + u-boot,dm-pre-reloc;
105 + u-boot,dm-pre-reloc;
109 + u-boot,dm-pre-reloc;
113 + u-boot,dm-pre-reloc;
120 + filename = "u-boot-spl-ddr.bin";
125 + filename = "u-boot-spl.bin";
129 + filename = "mt7621_stage_sram.bin";
135 + filename = "u-boot-spl-ddr.img";
138 +#ifdef CONFIG_MT7621_BOOT_FROM_NAND
139 + args = "-T", "mtk_image", "-n", "mt7621=1",
140 + "-a", __stringify(CONFIG_SPL_TEXT_BASE),
141 + "-e", __stringify(CONFIG_SPL_TEXT_BASE);
143 + args = "-A", "mips", "-T", "standalone", "-O", "u-boot",
144 + "-C", "none", "-n", "MT7621 U-Boot SPL",
145 + "-a", __stringify(CONFIG_SPL_TEXT_BASE),
146 + "-e", __stringify(CONFIG_SPL_TEXT_BASE);
150 + filename = "u-boot-spl-ddr.bin";
156 + filename = "u-boot-mt7621.bin";
159 +#ifndef CONFIG_MT7621_BOOT_FROM_NAND
162 + filename = "u-boot-tpl.bin";
167 +#ifdef CONFIG_MT7621_BOOT_FROM_NAND
168 + align-end = <0x1000>;
170 + filename = "u-boot-spl-ddr.img";
175 + filename = "u-boot-lzma.img";
181 +++ b/arch/mips/dts/mt7621.dtsi
183 +// SPDX-License-Identifier: GPL-2.0
185 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
187 + * Author: Weijie Gao <weijie.gao@mediatek.com>
190 +#include <dt-bindings/clock/mt7621-clk.h>
191 +#include <dt-bindings/reset/mt7621-reset.h>
192 +#include <dt-bindings/phy/phy.h>
195 + #address-cells = <1>;
197 + compatible = "mediatek,mt7621-soc";
200 + #address-cells = <1>;
204 + device_type = "cpu";
205 + compatible = "mips,mips1004Kc";
210 + device_type = "cpu";
211 + compatible = "mips,mips1004Kc";
217 + compatible = "fixed-clock";
219 + clock-frequency = <48000000>;
221 + #clock-cells = <0>;
225 + compatible = "fixed-clock";
227 + clock-frequency = <50000000>;
229 + #clock-cells = <0>;
232 + sysc: sysctrl@1e000000 {
233 + compatible = "mediatek,mt7621-sysc", "syscon";
234 + reg = <0x1e000000 0x100>;
236 + clkctrl: clock-controller@1e000030 {
237 + compatible = "mediatek,mt7621-clk";
238 + mediatek,memc = <&memc>;
240 + #clock-cells = <1>;
244 + rstctrl: reset-controller@1e000034 {
245 + compatible = "mediatek,mtmips-reset";
246 + reg = <0x1e000034 0x4>;
247 + #reset-cells = <1>;
250 + reboot: resetctl-reboot {
251 + compatible = "resetctl-reboot";
253 + resets = <&rstctrl RST_SYS>;
254 + reset-names = "sysreset";
257 + memc: memctrl@1e005000 {
258 + compatible = "mediatek,mt7621-memc", "syscon";
259 + reg = <0x1e005000 0x1000>;
262 + pinctrl: pinctrl@1e000060 {
263 + compatible = "mediatek,mt7621-pinctrl";
264 + reg = <0x1e000048 0x30>;
266 + pinctrl-names = "default";
267 + pinctrl-0 = <&state_default>;
269 + state_default: pin_state {
272 + uart1_pins: uart1_pins {
277 + uart2_pins: uart2_pins {
282 + uart3_pins: uart3_pins {
287 + sdxc_pins: sdxc_pins {
292 + spi_pins: spi_pins {
297 + eth_pins: eth_pins {
305 + function = "rgmii";
309 + groups = "esw int";
310 + function = "esw int";
315 + drive-strength = <2>;
320 + watchdog: watchdog@1e000100 {
321 + compatible = "mediatek,mt7621-wdt";
322 + reg = <0x1e000100 0x40>;
324 + resets = <&rstctrl RST_TIMER>;
325 + reset-names = "wdt";
327 + status = "disabled";
330 + gpio: gpio@1e000600 {
331 + #address-cells = <1>;
334 + compatible = "mtk,mt7621-gpio";
335 + reg = <0x1e000600 0x100>;
337 + resets = <&rstctrl RST_PIO>;
338 + reset-names = "pio";
342 + compatible = "mtk,mt7621-gpio-bank";
349 + compatible = "mtk,mt7621-gpio-bank";
356 + compatible = "mtk,mt7621-gpio-bank";
362 + spi: spi@1e000b00 {
363 + compatible = "ralink,mt7621-spi";
364 + reg = <0x1e000b00 0x40>;
366 + status = "disabled";
368 + pinctrl-names = "default";
369 + pinctrl-0 = <&spi_pins>;
371 + resets = <&rstctrl RST_SPI>;
372 + reset-names = "spi";
374 + clocks = <&clkctrl MT7621_CLK_SPI>;
376 + #address-cells = <1>;
380 + uart0: uart1@1e000c00 {
381 + compatible = "mediatek,hsuart", "ns16550a";
382 + reg = <0x1e000c00 0x100>;
384 + pinctrl-names = "default";
385 + pinctrl-0 = <&uart1_pins>;
387 + clocks = <&clkctrl MT7621_CLK_UART1>;
389 + resets = <&rstctrl RST_UART1>;
394 + uart1: uart2@1e000d00 {
395 + compatible = "mediatek,hsuart", "ns16550a";
396 + reg = <0x1e000d00 0x100>;
398 + pinctrl-names = "default";
399 + pinctrl-0 = <&uart2_pins>;
401 + clocks = <&clkctrl MT7621_CLK_UART2>;
403 + resets = <&rstctrl RST_UART2>;
407 + status = "disabled";
410 + uart2: uart3@1e000e00 {
411 + compatible = "mediatek,hsuart", "ns16550a";
412 + reg = <0x1e000e00 0x100>;
414 + pinctrl-names = "default";
415 + pinctrl-0 = <&uart3_pins>;
417 + clocks = <&clkctrl MT7621_CLK_UART3>;
419 + resets = <&rstctrl RST_UART3>;
423 + status = "disabled";
426 + eth: eth@1e100000 {
427 + compatible = "mediatek,mt7621-eth";
428 + reg = <0x1e100000 0x20000>;
429 + mediatek,ethsys = <&sysc>;
431 + pinctrl-names = "default";
432 + pinctrl-0 = <ð_pins>;
434 + resets = <&rstctrl RST_FE>, <&rstctrl RST_GMAC>, <&rstctrl RST_MCM>;
435 + reset-names = "fe", "gmac", "mcm";
437 + clocks = <&clkctrl MT7621_CLK_GDMA>,
438 + <&clkctrl MT7621_CLK_ETH>;
439 + clock-names = "gmac", "fe";
441 + #address-cells = <1>;
444 + mediatek,gmac-id = <0>;
445 + phy-mode = "rgmii";
446 + mediatek,switch = "mt7530";
455 + mmc: mmc@1e130000 {
456 + compatible = "mediatek,mt7621-mmc";
457 + reg = <0x1e130000 0x4000>;
459 + status = "disabled";
465 + pinctrl-names = "default";
466 + pinctrl-0 = <&sdxc_pins>;
468 + clocks = <&clk50m>, <&clkctrl MT7621_CLK_SHXC>;
469 + clock-names = "source", "hclk";
471 + resets = <&rstctrl RST_SDXC>;
474 + ssusb: usb@1e1c0000 {
475 + compatible = "mediatek,mt7621-xhci", "mediatek,mtk-xhci";
476 + reg = <0x1e1c0000 0x1000>, <0x1e1d0700 0x100>;
477 + reg-names = "mac", "ippc";
479 + clocks = <&clk48m>, <&clk48m>;
480 + clock-names = "sys_ck", "ref_ck";
482 + phys = <&u2port0 PHY_TYPE_USB2>,
483 + <&u3port0 PHY_TYPE_USB3>,
484 + <&u2port1 PHY_TYPE_USB2>;
486 + status = "disabled";
489 + u3phy: usb-phy@1e1d0000 {
490 + compatible = "mediatek,mt7621-u3phy",
491 + "mediatek,generic-tphy-v1";
492 + reg = <0x1e1d0000 0x700>;
493 + #address-cells = <1>;
496 + status = "disabled";
498 + u2port0: usb-phy@1e1d0800 {
499 + reg = <0x1e1d0800 0x0100>;
501 + clocks = <&clk48m>;
502 + clock-names = "ref";
505 + u3port0: usb-phy@1e1d0900 {
506 + reg = <0x1e1d0900 0x0100>;
510 + u2port1: usb-phy@1e1d1000 {
511 + reg = <0x1e1d1000 0x0100>;
513 + clocks = <&clk48m>;
514 + clock-names = "ref";
518 + i2c: i2c@1e000900 {
519 + compatible = "i2c-gpio";
521 + status = "disabled";
523 + i2c-gpio,delay-us = <3>;
525 + gpios = <&gpio0 3 1>, /* PIN3 as SDA */
526 + <&gpio0 4 1>; /* PIN4 as CLK */
528 + #address-cells = <1>;
532 --- a/arch/mips/mach-mtmips/Kconfig
533 +++ b/arch/mips/mach-mtmips/Kconfig
534 @@ -9,6 +9,7 @@ config SYS_MALLOC_F_LEN
537 default "mt7620" if SOC_MT7620
538 + default "mt7621" if SOC_MT7621
539 default "mt7628" if SOC_MT7628
541 config SYS_DCACHE_SIZE
542 @@ -18,25 +19,45 @@ config SYS_DCACHE_LINE_SIZE
545 config SYS_ICACHE_SIZE
547 + default 65536 if SOC_MT7620 || SOC_MT7628
548 + default 32768 if SOC_MT7621
550 config SYS_ICACHE_LINE_SIZE
553 +config SYS_SCACHE_LINE_SIZE
554 + default 32 if SOC_MT7621
557 - default 0x9c000000 if !SPL
558 - default 0x80200000 if SPL
559 + default 0x9c000000 if !SPL && !SOC_MT7621
560 + default 0x80200000 if SPL || SOC_MT7621
564 + default 0x9c000000 if !SOC_MT7621
565 + default 0x80100000 if SOC_MT7621
567 +config SPL_SIZE_LIMIT
568 + default 0x30000 if SOC_MT7621
570 +config TPL_TEXT_BASE
571 + default 0xbfc00000 if SOC_MT7621
574 + default 4096 if SOC_MT7621
577 default "u-boot-lzma.img" if SPL_LZMA
580 - default "u-boot-with-spl.bin" if SPL
581 + default "u-boot-with-spl.bin" if SPL && !SOC_MT7621
582 + default "u-boot-lzma.img" if SOC_MT7621
587 + default 256 if SOC_MT7620 || SOC_MT7628
588 + default 512 if SOC_MT7621
591 prompt "MediaTek MIPS SoC select"
593 @@ -55,6 +76,23 @@ config SOC_MT7620
595 This supports MediaTek MT7620.
600 + select MIPS_L2_CACHE
601 + select SYS_CACHE_SHIFT_5
602 + select SYS_MIPS_CACHE_INIT_RAM_LOAD
603 + select PINCTRL_MT7621
609 + select SPL_LOADER_SUPPORT if SPL
610 + select SPL_INIT_STACK_WITHOUT_MALLOC_F if SPL
612 + This supports MediaTek MT7621.
616 select SYS_CACHE_SHIFT_5
617 @@ -80,6 +118,7 @@ config SOC_MT7628
620 source "arch/mips/mach-mtmips/mt7620/Kconfig"
621 +source "arch/mips/mach-mtmips/mt7621/Kconfig"
622 source "arch/mips/mach-mtmips/mt7628/Kconfig"
625 --- a/arch/mips/mach-mtmips/Makefile
626 +++ b/arch/mips/mach-mtmips/Makefile
628 # SPDX-License-Identifier: GPL-2.0+
632 +ifneq ($(CONFIG_SOC_MT7621),y)
635 obj-$(CONFIG_SPL_BUILD) += spl.o
638 obj-$(CONFIG_SOC_MT7620) += mt7620/
639 +obj-$(CONFIG_SOC_MT7621) += mt7621/
640 obj-$(CONFIG_SOC_MT7628) += mt7628/
641 --- a/arch/mips/mach-mtmips/cpu.c
642 +++ b/arch/mips/mach-mtmips/cpu.c
643 @@ -16,7 +16,7 @@ DECLARE_GLOBAL_DATA_PTR;
647 - gd->ram_size = get_ram_size((void *)KSEG1, SZ_256M);
648 + gd->ram_size = get_ram_size((void *)KSEG1, CONFIG_MAX_MEM_SIZE << 20);
653 +++ b/arch/mips/mach-mtmips/mt7621/Kconfig
658 +menu "CPU & DDR configuration"
660 +config MT7621_CPU_FREQ
661 + int "CPU Frequency (MHz)"
666 + prompt "DRAM Frequency"
667 + default MT7621_DRAM_FREQ_1200
669 +config MT7621_DRAM_FREQ_400
672 +config MT7621_DRAM_FREQ_800
675 +config MT7621_DRAM_FREQ_1066
678 +config MT7621_DRAM_FREQ_1200
684 + prompt "DDR2 timing parameters"
685 + default MT7621_DRAM_DDR2_1024M
687 +config MT7621_DRAM_DDR2_512M
690 +config MT7621_DRAM_DDR2_1024M
693 +config MT7621_DRAM_DDR2_512M_W9751G6KB_A02_1066MHZ
694 + bool "W9751G6KB_A02 @ 1066MHz (64MB)"
696 +config MT7621_DRAM_DDR2_1024M_W971GG6KB25_800MHZ
697 + bool "W971GG6KB25 @ 800MHz (128MB)"
699 +config MT7621_DRAM_DDR2_1024M_W971GG6KB18_1066MHZ
700 + bool "W971GG6KB18 @ 1066MHz (128MB)"
705 + prompt "DDR3 timing parameters"
706 + default MT7621_DRAM_DDR3_2048M
708 +config MT7621_DRAM_DDR3_1024M
711 +config MT7621_DRAM_DDR3_1024M_KGD
712 + bool "128MB KGD (MT7621DA)"
714 +config MT7621_DRAM_DDR3_2048M
717 +config MT7621_DRAM_DDR3_4096M
724 +config DEBUG_UART_BOARD_INIT
727 +config MT7621_BOOT_FROM_NAND
728 + bool "Boot from NAND"
730 + Select this if u-boot will boot from NAND flash. When booting from
731 + NAND, SPL will be loaded by bootrom directly and no TPL is needed.
734 + prompt "Board select"
738 +config SYS_CONFIG_NAME
739 + string "Board configuration name"
740 + default "mt7621" if BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
743 + string "Board name"
744 + default "mt7621" if BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
747 + default "mediatek" if BOARD_MT7621_RFB || BOARD_MT7621_NAND_RFB
751 +++ b/arch/mips/mach-mtmips/mt7621/Makefile
753 +# SPDX-License-Identifier: GPL-2.0
758 +ifeq ($(CONFIG_SPL_BUILD),y)
759 +ifeq ($(CONFIG_TPL_BUILD),y)
765 +obj-y += sram_init.o
768 +++ b/arch/mips/mach-mtmips/mt7621/init.c
770 +// SPDX-License-Identifier: GPL-2.0
772 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
774 + * Author: Weijie Gao <weijie.gao@mediatek.com>
779 +#include <dm/uclass.h>
780 +#include <dt-bindings/clock/mt7621-clk.h>
781 +#include <asm/global_data.h>
782 +#include <linux/io.h>
783 +#include <linux/bitfield.h>
786 +DECLARE_GLOBAL_DATA_PTR;
788 +static const char *const boot_mode[(CHIP_MODE_M >> CHIP_MODE_S) + 1] = {
789 + [1] = "NAND 2K+64",
790 + [2] = "SPI-NOR 3-Byte Addr",
791 + [3] = "SPI-NOR 4-Byte Addr",
792 + [10] = "NAND 2K+128",
793 + [11] = "NAND 4K+128",
794 + [12] = "NAND 4K+256",
797 +int print_cpuinfo(void)
799 + void __iomem *sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
800 + u32 val, ver, eco, pkg, core, dram, chipmode;
801 + u32 cpu_clk, ddr_clk, bus_clk, xtal_clk;
802 + struct udevice *clkdev;
803 + const char *bootdev;
807 + val = readl(sysc + SYSCTL_CHIP_REV_ID_REG);
808 + ver = FIELD_GET(VER_ID_M, val);
809 + eco = FIELD_GET(ECO_ID_M, val);
810 + pkg = FIELD_GET(PKG_ID, val);
811 + core = FIELD_GET(CPU_ID, val);
813 + val = readl(sysc + SYSCTL_SYSCFG0_REG);
814 + dram = FIELD_GET(DRAM_TYPE, val);
815 + chipmode = FIELD_GET(CHIP_MODE_M, val);
817 + bootdev = boot_mode[chipmode];
819 + bootdev = "Unsupported boot mode";
821 + printf("CPU: MediaTek MT7621%c ver %u, eco %u\n",
822 + core ? (pkg ? 'A' : 'N') : 'S', ver, eco);
824 + printf("Boot: DDR%u, %s\n", dram ? 2 : 3, bootdev);
826 + ret = uclass_get_device_by_driver(UCLASS_CLK, DM_DRIVER_GET(mt7621_clk),
833 + clk.id = MT7621_CLK_CPU;
834 + cpu_clk = clk_get_rate(&clk);
836 + clk.id = MT7621_CLK_BUS;
837 + bus_clk = clk_get_rate(&clk);
839 + clk.id = MT7621_CLK_DDR;
840 + ddr_clk = clk_get_rate(&clk);
842 + clk.id = MT7621_CLK_XTAL;
843 + xtal_clk = clk_get_rate(&clk);
845 + /* Set final timer frequency */
847 + gd->arch.timer_freq = cpu_clk / 2;
849 + printf("Clock: CPU: %uMHz, DDR: %uMT/s, Bus: %uMHz, XTAL: %uMHz\n",
850 + cpu_clk / 1000000, ddr_clk / 500000, bus_clk / 1000000,
851 + xtal_clk / 1000000);
856 +unsigned long get_xtal_mhz(void)
858 + void __iomem *sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
861 + bs = readl(sysc + SYSCTL_SYSCFG0_REG);
862 + xtal_sel = FIELD_GET(XTAL_MODE_SEL_M, bs);
866 + else if (xtal_sel <= 5)
872 +static void xhci_config_40mhz(void __iomem *usbh)
874 + writel(FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_M, 0x20) |
875 + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_M, 0x20) |
876 + FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MODE_M, 2) |
877 + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MODE_M, 2) | 0x10,
878 + usbh + SSUSB_MAC_CK_CTRL_REG);
880 + writel(FIELD_PREP(SSUSB_PLL_PREDIV_PE1D_M, 2) |
881 + FIELD_PREP(SSUSB_PLL_PREDIV_U3_M, 1) |
882 + FIELD_PREP(SSUSB_PLL_FBKDI_M, 4),
883 + usbh + DA_SSUSB_U3PHYA_10_REG);
885 + writel(FIELD_PREP(SSUSB_PLL_FBKDIV_PE2H_M, 0x18) |
886 + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1D_M, 0x18) |
887 + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1H_M, 0x18) |
888 + FIELD_PREP(SSUSB_PLL_FBKDIV_U3_M, 0x1e),
889 + usbh + DA_SSUSB_PLL_FBKDIV_REG);
891 + writel(FIELD_PREP(SSUSB_PLL_PCW_NCPO_U3_M, 0x1e400000),
892 + usbh + DA_SSUSB_PLL_PCW_NCPO_REG);
894 + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE1H_M, 0x25) |
895 + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_U3_M, 0x73),
896 + usbh + DA_SSUSB_PLL_SSC_DELTA1_REG);
898 + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA_U3_M, 0x71) |
899 + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE2D_M, 0x4a),
900 + usbh + DA_SSUSB_U3PHYA_21_REG);
902 + writel(FIELD_PREP(SSUSB_PLL_SSC_PRD_M, 0x140),
903 + usbh + SSUSB_U3PHYA_9_REG);
905 + writel(FIELD_PREP(SSUSB_SYSPLL_PCW_NCPO_M, 0x11c00000),
906 + usbh + SSUSB_U3PHYA_3_REG);
908 + writel(FIELD_PREP(SSUSB_PCIE_CLKDRV_AMP_M, 4) |
909 + FIELD_PREP(SSUSB_SYSPLL_FBSEL_M, 1) |
910 + FIELD_PREP(SSUSB_SYSPLL_PREDIV_M, 1),
911 + usbh + SSUSB_U3PHYA_1_REG);
913 + writel(FIELD_PREP(SSUSB_SYSPLL_FBDIV_M, 0x12) |
914 + SSUSB_SYSPLL_VCO_DIV_SEL | SSUSB_SYSPLL_FPEN |
915 + SSUSB_SYSPLL_MONCK_EN | SSUSB_SYSPLL_VOD_EN,
916 + usbh + SSUSB_U3PHYA_2_REG);
918 + writel(SSUSB_EQ_CURSEL | FIELD_PREP(SSUSB_RX_DAC_MUX_M, 8) |
919 + FIELD_PREP(SSUSB_PCIE_SIGDET_VTH_M, 1) |
920 + FIELD_PREP(SSUSB_PCIE_SIGDET_LPF_M, 1),
921 + usbh + SSUSB_U3PHYA_11_REG);
923 + writel(FIELD_PREP(SSUSB_RING_OSC_CNTEND_M, 0x1ff) |
924 + FIELD_PREP(SSUSB_XTAL_OSC_CNTEND_M, 0x7f) |
925 + SSUSB_RING_BYPASS_DET,
926 + usbh + SSUSB_B2_ROSC_0_REG);
928 + writel(FIELD_PREP(SSUSB_RING_OSC_FRC_RECAL_M, 3) |
929 + SSUSB_RING_OSC_FRC_SEL,
930 + usbh + SSUSB_B2_ROSC_1_REG);
933 +static void xhci_config_25mhz(void __iomem *usbh)
935 + writel(FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_M, 0x20) |
936 + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_M, 0x20) |
937 + FIELD_PREP(SSUSB_MAC3_SYS_CK_GATE_MODE_M, 2) |
938 + FIELD_PREP(SSUSB_MAC2_SYS_CK_GATE_MODE_M, 2) | 0x10,
939 + usbh + SSUSB_MAC_CK_CTRL_REG);
941 + writel(FIELD_PREP(SSUSB_PLL_PREDIV_PE1D_M, 2) |
942 + FIELD_PREP(SSUSB_PLL_FBKDI_M, 4),
943 + usbh + DA_SSUSB_U3PHYA_10_REG);
945 + writel(FIELD_PREP(SSUSB_PLL_FBKDIV_PE2H_M, 0x18) |
946 + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1D_M, 0x18) |
947 + FIELD_PREP(SSUSB_PLL_FBKDIV_PE1H_M, 0x18) |
948 + FIELD_PREP(SSUSB_PLL_FBKDIV_U3_M, 0x19),
949 + usbh + DA_SSUSB_PLL_FBKDIV_REG);
951 + writel(FIELD_PREP(SSUSB_PLL_PCW_NCPO_U3_M, 0x18000000),
952 + usbh + DA_SSUSB_PLL_PCW_NCPO_REG);
954 + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE1H_M, 0x25) |
955 + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_U3_M, 0x4a),
956 + usbh + DA_SSUSB_PLL_SSC_DELTA1_REG);
958 + writel(FIELD_PREP(SSUSB_PLL_SSC_DELTA_U3_M, 0x48) |
959 + FIELD_PREP(SSUSB_PLL_SSC_DELTA1_PE2D_M, 0x4a),
960 + usbh + DA_SSUSB_U3PHYA_21_REG);
962 + writel(FIELD_PREP(SSUSB_PLL_SSC_PRD_M, 0x190),
963 + usbh + SSUSB_U3PHYA_9_REG);
965 + writel(FIELD_PREP(SSUSB_SYSPLL_PCW_NCPO_M, 0xe000000),
966 + usbh + SSUSB_U3PHYA_3_REG);
968 + writel(FIELD_PREP(SSUSB_PCIE_CLKDRV_AMP_M, 4) |
969 + FIELD_PREP(SSUSB_SYSPLL_FBSEL_M, 1),
970 + usbh + SSUSB_U3PHYA_1_REG);
972 + writel(FIELD_PREP(SSUSB_SYSPLL_FBDIV_M, 0xf) |
973 + SSUSB_SYSPLL_VCO_DIV_SEL | SSUSB_SYSPLL_FPEN |
974 + SSUSB_SYSPLL_MONCK_EN | SSUSB_SYSPLL_VOD_EN,
975 + usbh + SSUSB_U3PHYA_2_REG);
977 + writel(SSUSB_EQ_CURSEL | FIELD_PREP(SSUSB_RX_DAC_MUX_M, 8) |
978 + FIELD_PREP(SSUSB_PCIE_SIGDET_VTH_M, 1) |
979 + FIELD_PREP(SSUSB_PCIE_SIGDET_LPF_M, 1),
980 + usbh + SSUSB_U3PHYA_11_REG);
982 + writel(FIELD_PREP(SSUSB_RING_OSC_CNTEND_M, 0x1ff) |
983 + FIELD_PREP(SSUSB_XTAL_OSC_CNTEND_M, 0x7f) |
984 + SSUSB_RING_BYPASS_DET,
985 + usbh + SSUSB_B2_ROSC_0_REG);
987 + writel(FIELD_PREP(SSUSB_RING_OSC_FRC_RECAL_M, 3) |
988 + SSUSB_RING_OSC_FRC_SEL,
989 + usbh + SSUSB_B2_ROSC_1_REG);
992 +void lowlevel_init(void)
994 + void __iomem *usbh = ioremap_nocache(SSUSB_BASE, SSUSB_SIZE);
995 + u32 xtal = get_xtal_mhz();
997 + /* Setup USB xHCI */
999 + xhci_config_40mhz(usbh);
1000 + else if (xtal == 25)
1001 + xhci_config_25mhz(usbh);
1004 +ulong notrace get_tbclk(void)
1006 + return gd->arch.timer_freq;
1009 +void _machine_restart(void)
1011 + void __iomem *sysc = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
1014 + writel(SYS_RST, sysc + SYSCTL_RSTCTL_REG);
1017 +++ b/arch/mips/mach-mtmips/mt7621/mt7621.h
1019 +/* SPDX-License-Identifier: GPL-2.0 */
1021 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1023 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1029 +#define SYSCTL_BASE 0x1e000000
1030 +#define SYSCTL_SIZE 0x100
1031 +#define TIMER_BASE 0x1e000100
1032 +#define TIMER_SIZE 0x100
1033 +#define RBUS_BASE 0x1e000400
1034 +#define RBUS_SIZE 0x100
1035 +#define GPIO_BASE 0x1e000600
1036 +#define GPIO_SIZE 0x100
1037 +#define DMA_CFG_ARB_BASE 0x1e000800
1038 +#define DMA_CFG_ARB_SIZE 0x100
1039 +#define SPI_BASE 0x1e000b00
1040 +#define SPI_SIZE 0x100
1041 +#define UART1_BASE 0x1e000c00
1042 +#define UART1_SIZE 0x100
1043 +#define UART2_BASE 0x1e000d00
1044 +#define UART2_SIZE 0x100
1045 +#define UART3_BASE 0x1e000e00
1046 +#define UART3_SIZE 0x100
1047 +#define NFI_BASE 0x1e003000
1048 +#define NFI_SIZE 0x800
1049 +#define NFI_ECC_BASE 0x1e003800
1050 +#define NFI_ECC_SIZE 0x800
1051 +#define DRAMC_BASE 0x1e005000
1052 +#define DRAMC_SIZE 0x1000
1053 +#define FE_BASE 0x1e100000
1054 +#define FE_SIZE 0xe000
1055 +#define GMAC_BASE 0x1e110000
1056 +#define GMAC_SIZE 0x8000
1057 +#define SSUSB_BASE 0x1e1c0000
1058 +#define SSUSB_SIZE 0x40000
1060 + /* GIC Base Address */
1061 +#define MIPS_GIC_BASE 0x1fbc0000
1063 + /* CPC Base Address */
1064 +#define MIPS_CPC_BASE 0x1fbf0000
1066 + /* Flash Memory-mapped Base Address */
1067 +#define FLASH_MMAP_BASE 0x1fc00000
1068 +#define TPL_INFO_OFFSET 0x40
1069 +#define TPL_INFO_MAGIC 0x31323637 /* Magic "7621" */
1072 +#define FE_SRAM_BASE1 0x8000
1073 +#define FE_SRAM_BASE2 0xa000
1076 +#define SYSCTL_CHIP_REV_ID_REG 0x0c
1077 +#define CPU_ID 0x20000
1078 +#define PKG_ID 0x10000
1080 +#define VER_ID_M 0xf00
1082 +#define ECO_ID_M 0x0f
1084 +#define SYSCTL_SYSCFG0_REG 0x10
1085 +#define XTAL_MODE_SEL_S 6
1086 +#define XTAL_MODE_SEL_M 0x1c0
1087 +#define DRAM_TYPE 0x10
1088 +#define CHIP_MODE_S 0
1089 +#define CHIP_MODE_M 0x0f
1091 +#define BOOT_SRAM_BASE_REG 0x20
1093 +#define SYSCTL_CLKCFG0_REG 0x2c
1094 +#define CPU_CLK_SEL_S 30
1095 +#define CPU_CLK_SEL_M 0xc0000000
1096 +#define MPLL_CFG_SEL_S 23
1097 +#define MPLL_CFG_SEL_M 0x800000
1099 +#define SYSCTL_RSTCTL_REG 0x34
1100 +#define MCM_RST 0x04
1101 +#define SYS_RST 0x01
1103 +#define SYSCTL_CUR_CLK_STS_REG 0x44
1104 +#define CUR_CPU_FDIV_S 8
1105 +#define CUR_CPU_FDIV_M 0x1f00
1106 +#define CUR_CPU_FFRAC_S 0
1107 +#define CUR_CPU_FFRAC_M 0x1f
1109 +#define SYSCTL_GPIOMODE_REG 0x60
1110 +#define UART2_MODE_S 5
1111 +#define UART2_MODE_M 0x60
1112 +#define UART3_MODE_S 3
1113 +#define UART3_MODE_M 0x18
1114 +#define UART1_MODE 0x02
1117 +#define RBUS_DYN_CFG0_REG 0x0010
1118 +#define CPU_FDIV_S 8
1119 +#define CPU_FDIV_M 0x1f00
1120 +#define CPU_FFRAC_S 0
1121 +#define CPU_FFRAC_M 0x1f
1123 +/* DMA_CFG_ARB_BASE */
1124 +#define DMA_ROUTE_REG 0x000c
1127 +#define SPI_SPACE_REG 0x003c
1128 +#define FS_SLAVE_SEL_S 12
1129 +#define FS_SLAVE_SEL_M 0x70000
1130 +#define FS_CLK_SEL_S 0
1131 +#define FS_CLK_SEL_M 0xfff
1134 +#define FE_RST_GLO_REG 0x0004
1135 +#define FE_PSE_RAM 0x04
1136 +#define FE_PSE_MEM_EN 0x02
1137 +#define FE_PSE_RESET 0x01
1140 +#define SSUSB_MAC_CK_CTRL_REG 0x10784
1141 +#define SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_S 16
1142 +#define SSUSB_MAC3_SYS_CK_GATE_MASK_TIME_M 0xff0000
1143 +#define SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_S 8
1144 +#define SSUSB_MAC2_SYS_CK_GATE_MASK_TIME_M 0xff00
1145 +#define SSUSB_MAC3_SYS_CK_GATE_MODE_S 2
1146 +#define SSUSB_MAC3_SYS_CK_GATE_MODE_M 0x0c
1147 +#define SSUSB_MAC2_SYS_CK_GATE_MODE_S 0
1148 +#define SSUSB_MAC2_SYS_CK_GATE_MODE_M 0x03
1150 +#define SSUSB_B2_ROSC_0_REG 0x10a40
1151 +#define SSUSB_RING_OSC_CNTEND_S 23
1152 +#define SSUSB_RING_OSC_CNTEND_M 0xff800000
1153 +#define SSUSB_XTAL_OSC_CNTEND_S 16
1154 +#define SSUSB_XTAL_OSC_CNTEND_M 0x7f0000
1155 +#define SSUSB_RING_BYPASS_DET 0x01
1157 +#define SSUSB_B2_ROSC_1_REG 0x10a44
1158 +#define SSUSB_RING_OSC_FRC_RECAL_S 17
1159 +#define SSUSB_RING_OSC_FRC_RECAL_M 0x60000
1160 +#define SSUSB_RING_OSC_FRC_SEL 0x01
1162 +#define SSUSB_U3PHYA_1_REG 0x10b04
1163 +#define SSUSB_PCIE_CLKDRV_AMP_S 27
1164 +#define SSUSB_PCIE_CLKDRV_AMP_M 0x38000000
1165 +#define SSUSB_SYSPLL_FBSEL_S 2
1166 +#define SSUSB_SYSPLL_FBSEL_M 0x0c
1167 +#define SSUSB_SYSPLL_PREDIV_S 0
1168 +#define SSUSB_SYSPLL_PREDIV_M 0x03
1170 +#define SSUSB_U3PHYA_2_REG 0x10b08
1171 +#define SSUSB_SYSPLL_FBDIV_S 24
1172 +#define SSUSB_SYSPLL_FBDIV_M 0x7f000000
1173 +#define SSUSB_SYSPLL_VCO_DIV_SEL 0x200000
1174 +#define SSUSB_SYSPLL_FPEN 0x2000
1175 +#define SSUSB_SYSPLL_MONCK_EN 0x1000
1176 +#define SSUSB_SYSPLL_VOD_EN 0x200
1178 +#define SSUSB_U3PHYA_3_REG 0x10b10
1179 +#define SSUSB_SYSPLL_PCW_NCPO_S 1
1180 +#define SSUSB_SYSPLL_PCW_NCPO_M 0xfffffffe
1182 +#define SSUSB_U3PHYA_9_REG 0x10b24
1183 +#define SSUSB_PLL_SSC_PRD_S 0
1184 +#define SSUSB_PLL_SSC_PRD_M 0xffff
1186 +#define SSUSB_U3PHYA_11_REG 0x10b2c
1187 +#define SSUSB_EQ_CURSEL 0x1000000
1188 +#define SSUSB_RX_DAC_MUX_S 19
1189 +#define SSUSB_RX_DAC_MUX_M 0xf80000
1190 +#define SSUSB_PCIE_SIGDET_VTH_S 5
1191 +#define SSUSB_PCIE_SIGDET_VTH_M 0x60
1192 +#define SSUSB_PCIE_SIGDET_LPF_S 3
1193 +#define SSUSB_PCIE_SIGDET_LPF_M 0x18
1195 +#define DA_SSUSB_PLL_FBKDIV_REG 0x10c1c
1196 +#define SSUSB_PLL_FBKDIV_PE2H_S 24
1197 +#define SSUSB_PLL_FBKDIV_PE2H_M 0x7f000000
1198 +#define SSUSB_PLL_FBKDIV_PE1D_S 16
1199 +#define SSUSB_PLL_FBKDIV_PE1D_M 0x7f0000
1200 +#define SSUSB_PLL_FBKDIV_PE1H_S 8
1201 +#define SSUSB_PLL_FBKDIV_PE1H_M 0x7f00
1202 +#define SSUSB_PLL_FBKDIV_U3_S 0
1203 +#define SSUSB_PLL_FBKDIV_U3_M 0x7f
1205 +#define DA_SSUSB_U3PHYA_10_REG 0x10c20
1206 +#define SSUSB_PLL_PREDIV_PE1D_S 18
1207 +#define SSUSB_PLL_PREDIV_PE1D_M 0xc0000
1208 +#define SSUSB_PLL_PREDIV_U3_S 8
1209 +#define SSUSB_PLL_PREDIV_U3_M 0x300
1210 +#define SSUSB_PLL_FBKDI_S 0
1211 +#define SSUSB_PLL_FBKDI_M 0x07
1213 +#define DA_SSUSB_PLL_PCW_NCPO_REG 0x10c24
1214 +#define SSUSB_PLL_PCW_NCPO_U3_S 0
1215 +#define SSUSB_PLL_PCW_NCPO_U3_M 0x7fffffff
1217 +#define DA_SSUSB_PLL_SSC_DELTA1_REG 0x10c38
1218 +#define SSUSB_PLL_SSC_DELTA1_PE1H_S 16
1219 +#define SSUSB_PLL_SSC_DELTA1_PE1H_M 0xffff0000
1220 +#define SSUSB_PLL_SSC_DELTA1_U3_S 0
1221 +#define SSUSB_PLL_SSC_DELTA1_U3_M 0xffff
1223 +#define DA_SSUSB_U3PHYA_21_REG 0x10c40
1224 +#define SSUSB_PLL_SSC_DELTA_U3_S 16
1225 +#define SSUSB_PLL_SSC_DELTA_U3_M 0xffff0000
1226 +#define SSUSB_PLL_SSC_DELTA1_PE2D_S 0
1227 +#define SSUSB_PLL_SSC_DELTA1_PE2D_M 0xffff
1229 +/* MT7621 specific CM values */
1231 +/* GCR_REGx_BASE */
1232 +#define GCR_REG0_BASE_VALUE 0x1c000000
1233 +#define GCR_REG1_BASE_VALUE 0x60000000
1234 +#define GCR_REG2_BASE_VALUE 0x1c000000
1235 +#define GCR_REG3_BASE_VALUE 0x1c000000
1237 +/* GCR_REGx_MASK */
1238 +#define GCR_REG0_MASK_VALUE 0x0000fc00 /* 64M Bus */
1239 +#define GCR_REG1_MASK_VALUE 0x0000f000 /* 256M PCI Mem */
1240 +#define GCR_REG2_MASK_VALUE 0x0000fc00 /* unused */
1241 +#define GCR_REG3_MASK_VALUE 0x0000fc00 /* unused */
1243 +#ifndef __ASSEMBLY__
1244 +unsigned long get_xtal_mhz(void);
1247 +#endif /* _MT7621_H_ */
1249 +++ b/arch/mips/mach-mtmips/mt7621/serial.c
1251 +// SPDX-License-Identifier: GPL-2.0
1253 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1255 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1258 +#include <asm/io.h>
1259 +#include <asm/addrspace.h>
1260 +#include "mt7621.h"
1262 +void board_debug_uart_init(void)
1264 + void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
1266 +#if CONFIG_DEBUG_UART_BASE == 0xbe000c00 /* KSEG1ADDR(UART1_BASE) */
1267 + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART1_MODE);
1268 +#elif CONFIG_DEBUG_UART_BASE == 0xbe000d00 /* KSEG1ADDR(UART2_BASE) */
1269 + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART2_MODE_M);
1270 +#elif CONFIG_DEBUG_UART_BASE == 0xbe000e00 /* KSEG1ADDR(UART3_BASE) */
1271 + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART3_MODE_M);
1275 +++ b/arch/mips/mach-mtmips/mt7621/spl/Makefile
1285 +obj-y += launch_ll.o
1287 +++ b/arch/mips/mach-mtmips/mt7621/spl/cps.c
1289 +// SPDX-License-Identifier: GPL-2.0
1291 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1293 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1296 +#include <asm/io.h>
1297 +#include <asm/addrspace.h>
1298 +#include <asm/mipsregs.h>
1299 +#include <asm/cm.h>
1300 +#include <linux/bitfield.h>
1301 +#include "../mt7621.h"
1303 +/* GIC Shared Register Bases */
1304 +#define GIC_SH_POL_BASE 0x100
1305 +#define GIC_SH_TRIG_BASE 0x180
1306 +#define GIC_SH_RMASK_BASE 0x300
1307 +#define GIC_SH_SMASK_BASE 0x380
1308 +#define GIC_SH_MASK_BASE 0x400
1309 +#define GIC_SH_PEND_BASE 0x480
1310 +#define GIC_SH_MAP_PIN_BASE 0x500
1311 +#define GIC_SH_MAP_VPE_BASE 0x2000
1313 +/* GIC Registers */
1314 +#define GIC_SH_POL31_0 (GIC_SH_POL_BASE + 0x00)
1315 +#define GIC_SH_POL63_32 (GIC_SH_POL_BASE + 0x04)
1317 +#define GIC_SH_TRIG31_0 (GIC_SH_TRIG_BASE + 0x00)
1318 +#define GIC_SH_TRIG63_32 (GIC_SH_TRIG_BASE + 0x04)
1320 +#define GIC_SH_RMASK31_0 (GIC_SH_RMASK_BASE + 0x00)
1321 +#define GIC_SH_RMASK63_32 (GIC_SH_RMASK_BASE + 0x04)
1323 +#define GIC_SH_SMASK31_0 (GIC_SH_SMASK_BASE + 0x00)
1324 +#define GIC_SH_SMASK63_32 (GIC_SH_SMASK_BASE + 0x04)
1326 +#define GIC_SH_MAP_PIN(n) (GIC_SH_MAP_PIN_BASE + (n) * 4)
1328 +#define GIC_SH_MAP_VPE(n, v) (GIC_SH_MAP_VPE_BASE + (n) * 0x20 + ((v) / 32) * 4)
1329 +#define GIC_SH_MAP_VPE31_0(n) GIC_SH_MAP_VPE(n, 0)
1331 +/* GIC_SH_MAP_PIN fields */
1332 +#define GIC_MAP_TO_PIN BIT(31)
1333 +#define GIC_MAP_TO_NMI BIT(30)
1334 +#define GIC_MAP GENMASK(5, 0)
1335 +#define GIC_MAP_SHIFT 0
1337 +static void cm_init(void __iomem *cm_base)
1339 + u32 gcrcfg, num_cores;
1341 + gcrcfg = readl(cm_base + GCR_CONFIG);
1342 + num_cores = FIELD_GET(GCR_CONFIG_PCORES, gcrcfg) + 1;
1344 + writel((1 << num_cores) - 1, cm_base + GCR_ACCESS);
1346 + writel(GCR_REG0_BASE_VALUE, cm_base + GCR_REG0_BASE);
1347 + writel(GCR_REG1_BASE_VALUE, cm_base + GCR_REG1_BASE);
1348 + writel(GCR_REG2_BASE_VALUE, cm_base + GCR_REG2_BASE);
1349 + writel(GCR_REG3_BASE_VALUE, cm_base + GCR_REG3_BASE);
1351 + clrsetbits_32(cm_base + GCR_REG0_MASK,
1352 + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
1353 + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG0_MASK_VALUE) |
1354 + GCR_REGn_MASK_CMTGT_IOCU0);
1356 + clrsetbits_32(cm_base + GCR_REG1_MASK,
1357 + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
1358 + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG1_MASK_VALUE) |
1359 + GCR_REGn_MASK_CMTGT_IOCU0);
1361 + clrsetbits_32(cm_base + GCR_REG2_MASK,
1362 + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
1363 + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG2_MASK_VALUE) |
1364 + GCR_REGn_MASK_CMTGT_IOCU0);
1366 + clrsetbits_32(cm_base + GCR_REG3_MASK,
1367 + GCR_REGn_MASK_ADDRMASK | GCR_REGn_MASK_CMTGT,
1368 + FIELD_PREP(GCR_REGn_MASK_ADDRMASK, GCR_REG3_MASK_VALUE) |
1369 + GCR_REGn_MASK_CMTGT_IOCU0);
1371 + clrbits_32(cm_base + GCR_BASE, CM_DEFAULT_TARGET_MASK);
1372 + setbits_32(cm_base + GCR_CONTROL, GCR_CONTROL_SYNCCTL);
1375 +static void gic_init(void)
1377 + void __iomem *gic_base = (void *)KSEG1ADDR(MIPS_GIC_BASE);
1380 + /* Interrupt 0..5: Level Trigger, Active High */
1381 + writel(0, gic_base + GIC_SH_TRIG31_0);
1382 + writel(0x3f, gic_base + GIC_SH_RMASK31_0);
1383 + writel(0x3f, gic_base + GIC_SH_POL31_0);
1384 + writel(0x3f, gic_base + GIC_SH_SMASK31_0);
1386 + /* Interrupt 56..63: Edge Trigger, Rising Edge */
1387 + /* Hardcoded to set up the last 8 external interrupts for IPI. */
1388 + writel(0xff000000, gic_base + GIC_SH_TRIG63_32);
1389 + writel(0xff000000, gic_base + GIC_SH_RMASK63_32);
1390 + writel(0xff000000, gic_base + GIC_SH_POL63_32);
1391 + writel(0xff000000, gic_base + GIC_SH_SMASK63_32);
1393 + /* Map interrupt source to particular hardware interrupt pin */
1394 + /* source {0,1,2,3,4,5} -> pin {0,0,4,3,0,5} */
1395 + writel(GIC_MAP_TO_PIN | 0, gic_base + GIC_SH_MAP_PIN(0));
1396 + writel(GIC_MAP_TO_PIN | 0, gic_base + GIC_SH_MAP_PIN(1));
1397 + writel(GIC_MAP_TO_PIN | 4, gic_base + GIC_SH_MAP_PIN(2));
1398 + writel(GIC_MAP_TO_PIN | 3, gic_base + GIC_SH_MAP_PIN(3));
1399 + writel(GIC_MAP_TO_PIN | 0, gic_base + GIC_SH_MAP_PIN(4));
1400 + writel(GIC_MAP_TO_PIN | 5, gic_base + GIC_SH_MAP_PIN(5));
1402 + /* source 56~59 -> pin 1, 60~63 -> pin 2 */
1403 + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(56));
1404 + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(57));
1405 + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(58));
1406 + writel(GIC_MAP_TO_PIN | 1, gic_base + GIC_SH_MAP_PIN(59));
1407 + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(60));
1408 + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(61));
1409 + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(62));
1410 + writel(GIC_MAP_TO_PIN | 2, gic_base + GIC_SH_MAP_PIN(63));
1412 + /* Interrupt map to VPE (bit mask) */
1413 + for (i = 0; i < 32; i++)
1414 + writel(BIT(0), gic_base + GIC_SH_MAP_VPE31_0(i));
1417 + * Direct GIC_int 56..63 to vpe 0..3
1418 + * MIPS Linux convention that last 16 interrupts implemented be set
1419 + * aside for IPI signaling.
1420 + * The actual interrupts are tied low and software sends interrupts
1421 + * via GIC_SH_WEDGE writes.
1423 + for (i = 0; i < 4; i++) {
1424 + writel(BIT(i), gic_base + GIC_SH_MAP_VPE31_0(i + 56));
1425 + writel(BIT(i), gic_base + GIC_SH_MAP_VPE31_0(i + 60));
1429 +void mt7621_cps_init(void)
1431 + void __iomem *cm_base = (void *)KSEG1ADDR(CONFIG_MIPS_CM_BASE);
1434 + writel(MIPS_GIC_BASE | GCR_GIC_EN, cm_base + GCR_GIC_BASE);
1437 + writel(MIPS_CPC_BASE | GCR_CPC_EN, cm_base + GCR_CPC_BASE);
1443 +++ b/arch/mips/mach-mtmips/mt7621/spl/dram.c
1445 +// SPDX-License-Identifier: GPL-2.0
1447 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1449 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1452 +#include <vsprintf.h>
1453 +#include <asm/io.h>
1454 +#include <asm/sections.h>
1455 +#include <asm/byteorder.h>
1456 +#include <asm/addrspace.h>
1457 +#include <linux/string.h>
1458 +#include "../mt7621.h"
1461 +static const u32 ddr2_act[DDR_PARAM_SIZE] = {
1462 +#if defined(CONFIG_MT7621_DRAM_DDR2_512M)
1463 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x22174441,
1464 + 0x00000000, 0xF0748661, 0x40001273, 0x9F0A0481,
1465 + 0x0304692F, 0x15602842, 0x00008888, 0x88888888,
1466 + 0x00000000, 0x00000000, 0x00000000, 0x07100000,
1467 + 0x00001B63, 0x00002000, 0x00004000, 0x00006000,
1468 + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1469 +#elif defined(CONFIG_MT7621_DRAM_DDR2_512M_W9751G6KB_A02_1066MHZ)
1470 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x33484584,
1471 + 0x00000000, 0xF07486A1, 0x50001273, 0x9F010481,
1472 + 0x0304693F, 0x15602842, 0x00008888, 0x88888888,
1473 + 0x00000000, 0x00000000, 0x00000010, 0x07100000,
1474 + 0x00001F73, 0x00002000, 0x00004000, 0x00006000,
1475 + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1476 +#elif defined(CONFIG_MT7621_DRAM_DDR2_1024M_W971GG6KB25_800MHZ)
1477 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x22174430,
1478 + 0x01000000, 0xF0748661, 0x40001273, 0x9F0F0481,
1479 + 0x0304692F, 0x15602842, 0x00008888, 0x88888888,
1480 + 0x00000000, 0x00000000, 0x00000000, 0x07100000,
1481 + 0x00001B63, 0x00002000, 0x00004000, 0x00006000,
1482 + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1483 +#elif defined(CONFIG_MT7621_DRAM_DDR2_1024M_W971GG6KB18_1066MHZ)
1484 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x33484584,
1485 + 0x01000000, 0xF07486A1, 0x50001273, 0x9F070481,
1486 + 0x0304693F, 0x15602842, 0x00008888, 0x88888888,
1487 + 0x00000000, 0x00000000, 0x00000010, 0x07100000,
1488 + 0x00001F73, 0x00002000, 0x00004000, 0x00006000,
1489 + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1490 +#else /* CONFIG_MT7621_DRAM_DDR2_1024M */
1491 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x22174441,
1492 + 0x01000000, 0xF0748661, 0x40001273, 0x9F0F0481,
1493 + 0x0304692F, 0x15602842, 0x00008888, 0x88888888,
1494 + 0x00000000, 0x00000000, 0x00000000, 0x07100000,
1495 + 0x00001B63, 0x00002000, 0x00004000, 0x00006000,
1496 + 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1500 +static const u32 ddr3_act[DDR_PARAM_SIZE] = {
1501 +#if defined(CONFIG_MT7621_DRAM_DDR3_1024M)
1502 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x44694683,
1503 + 0x01000000, 0xF07486A1, 0xC287221D, 0x9F060481,
1504 + 0x03046948, 0x15602842, 0x00008888, 0x88888888,
1505 + 0x00000000, 0x00000000, 0x00000210, 0x07100000,
1506 + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
1507 + 0x0C000000, 0x07070000, 0x00000000, 0x00000000,
1508 +#elif defined(CONFIG_MT7621_DRAM_DDR3_4096M)
1509 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x44694683,
1510 + 0x01000000, 0xF07486A1, 0xC287221D, 0x9F0F0481,
1511 + 0x03046948, 0x15602842, 0x00008888, 0x88888888,
1512 + 0x00000000, 0x00000000, 0x00000240, 0x07100000,
1513 + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
1514 + 0x0C000000, 0x07070000, 0x00000000, 0x00000000,
1515 +#elif defined(CONFIG_MT7621_DRAM_DDR3_1024M_KGD)
1516 + 0xFF00FF00, 0xFF00FF00, 0x00000007, 0x44694683,
1517 + 0x01000000, 0xF07406A1, 0xC287221D, 0x9F060481,
1518 + 0x03046923, 0x152f2842, 0x00008888, 0x88888888,
1519 + 0x00000000, 0x00000000, 0x00000210, 0x07100000,
1520 + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
1521 + 0x0C000000, 0x07070000, 0x000C0000, 0x00000000,
1522 +#else /* CONFIG_MT7621_DRAM_DDR3_2048M */
1523 + 0xAA00AA00, 0xAA00AA00, 0x00000007, 0x44694673,
1524 + 0x01000000, 0xF07486A1, 0xC287221D, 0x9F050481,
1525 + 0x03046948, 0x15602842, 0x00008888, 0x88888888,
1526 + 0x00000000, 0x00000000, 0x00000220, 0x07100000,
1527 + 0x00001B61, 0x00002040, 0x00004010, 0x00006000,
1528 + 0x0C000000, 0x07070000, 0x00000000, 0x00000000,
1532 +#if defined(CONFIG_MT7621_DRAM_FREQ_400)
1533 +#define DDR_FREQ_PARAM 0x41000000
1534 +#elif defined(CONFIG_MT7621_DRAM_FREQ_1066)
1535 +#define DDR_FREQ_PARAM 0x21000000
1536 +#elif defined(CONFIG_MT7621_DRAM_FREQ_1200)
1537 +#define DDR_FREQ_PARAM 0x11000000
1538 +#else /* CONFIG_MT7621_DRAM_FREQ_800 */
1539 +#define DDR_FREQ_PARAM 0x31000000
1542 +#define RG_MEPL_FBDIV_S 4
1543 +#define RG_MEPL_FBDIV_M 0x7f
1545 +static inline void word_copy(u32 *dest, const u32 *src, u32 count)
1549 + for (i = 0; i < count; i++)
1553 +static u32 calc_cpu_pll_val(void)
1555 + u32 div, baseval, fb;
1557 + div = get_xtal_mhz();
1561 + baseval = 0xc0005802;
1563 + baseval = 0xc0004802;
1566 + fb = CONFIG_MT7621_CPU_FREQ / div - 1;
1567 + if (fb > RG_MEPL_FBDIV_M)
1568 + fb = RG_MEPL_FBDIV_M;
1570 + return baseval | (fb << RG_MEPL_FBDIV_S);
1573 +void prepare_stage_bin(void)
1577 + const struct stage_header *stock_stage_bin =
1578 + (const struct stage_header *)__image_copy_end;
1580 + struct stage_header *new_stage_bin =
1581 + (struct stage_header *)STAGE_LOAD_ADDR;
1583 + if (be32_to_cpu(stock_stage_bin->ep) != STAGE_LOAD_ADDR)
1584 + panic("Invalid DDR stage binary blob\n");
1586 + stage_size = be32_to_cpu(stock_stage_bin->stage_size);
1588 + word_copy((u32 *)new_stage_bin, (const u32 *)stock_stage_bin,
1589 + (stage_size + sizeof(u32) - 1) / sizeof(u32));
1591 + word_copy(new_stage_bin->ddr2_act, ddr2_act, DDR_PARAM_SIZE);
1592 + word_copy(new_stage_bin->ddr3_act, ddr3_act, DDR_PARAM_SIZE);
1594 + new_stage_bin->cpu_pll_cfg = calc_cpu_pll_val();
1595 + new_stage_bin->ddr_pll_cfg = DDR_FREQ_PARAM;
1596 + new_stage_bin->baudrate = CONFIG_BAUDRATE;
1599 +++ b/arch/mips/mach-mtmips/mt7621/spl/dram.h
1601 +/* SPDX-License-Identifier: GPL-2.0 */
1603 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1605 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1608 +#ifndef _MT7621_DRAM_H_
1609 +#define _MT7621_DRAM_H_
1611 +#define STAGE_LOAD_ADDR 0xBE108800
1613 +#ifndef __ASSEMBLY__
1614 +#include <linux/types.h>
1616 +#define DDR_PARAM_SIZE 24
1618 +struct stage_header {
1629 + char build_tag[32];
1630 + u32 ddr3_act[DDR_PARAM_SIZE];
1632 + u32 ddr2_act[DDR_PARAM_SIZE];
1639 +#endif /* _MT7621_DRAM_H_ */
1641 +++ b/arch/mips/mach-mtmips/mt7621/spl/launch.c
1643 +// SPDX-License-Identifier: GPL-2.0
1645 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1647 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1650 +#include <asm/io.h>
1651 +#include <asm/cm.h>
1652 +#include <asm/sections.h>
1653 +#include <asm/addrspace.h>
1654 +#include <asm/mipsmtregs.h>
1655 +#include <linux/sizes.h>
1657 +#include <cpu_func.h>
1658 +#include "launch.h"
1659 +#include "../mt7621.h"
1661 +/* Cluster Power Controller (CPC) offsets */
1662 +#define CPC_CL_OTHER 0x2010
1663 +#define CPC_CO_CMD 0x4000
1665 +/* CPC_CL_OTHER fields */
1666 +#define CPC_CL_OTHER_CORENUM_SHIFT 16
1667 +#define CPC_CL_OTHER_CORENUM GENMASK(23, 16)
1672 +#define NUM_CORES 2
1674 +#define WAIT_CPUS_TIMEOUT 4000
1676 +static void copy_launch_wait_code(void)
1678 + memset((void *)KSEG1, 0, SZ_4K);
1680 + memcpy((void *)KSEG1ADDR(LAUNCH_WAITCODE),
1681 + &launch_wait_code_start,
1682 + &launch_wait_code_end - &launch_wait_code_start);
1684 + invalidate_dcache_range(KSEG0, SZ_4K);
1687 +static void bootup_secondary_core(void)
1689 + void __iomem *cpcbase = (void __iomem *)KSEG1ADDR(MIPS_CPC_BASE);
1692 + for (i = 1; i < NUM_CORES; i++) {
1693 + writel(i << CPC_CL_OTHER_CORENUM_SHIFT, cpcbase + CPC_CL_OTHER);
1694 + writel(PWR_UP, cpcbase + CPC_CO_CMD);
1698 +void secondary_cpu_init(void)
1700 + void __iomem *sysc = (void __iomem *)KSEG1ADDR(SYSCTL_BASE);
1701 + u32 i, dual_core = 0, cpuready = 1, cpumask = 0x03;
1703 + struct cpulaunch_t *c;
1705 + /* Copy LAUNCH wait code used by other VPEs */
1706 + copy_launch_wait_code();
1708 + dual_core = readl(sysc + SYSCTL_CHIP_REV_ID_REG) & CPU_ID;
1711 + /* Bootup secondary core for MT7621A */
1714 + /* Make BootROM/TPL redirect Core1's bootup flow to our entry point */
1715 + writel((uintptr_t)&_start, sysc + BOOT_SRAM_BASE_REG);
1717 + bootup_secondary_core();
1720 + /* Join the coherent domain */
1721 + join_coherent_domain(dual_core ? 2 : 1);
1723 + /* Bootup Core0/VPE1 */
1726 + /* Wait for all CPU ready */
1727 + wait_tick = get_timer(0) + WAIT_CPUS_TIMEOUT;
1729 + while (time_before(get_timer(0), wait_tick)) {
1730 + /* CPU0 is obviously ready */
1731 + for (i = 1; i < NUM_CPUS; i++) {
1732 + c = (struct cpulaunch_t *)(KSEG0ADDR(CPULAUNCH) +
1733 + (i << LOG2CPULAUNCH));
1735 + if (c->flags & LAUNCH_FREADY)
1736 + cpuready |= BIT(i);
1739 + if ((cpuready & cpumask) == cpumask)
1744 +++ b/arch/mips/mach-mtmips/mt7621/spl/launch.h
1746 +/* SPDX-License-Identifier: GPL-2.0 */
1748 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1750 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1756 +#ifndef __ASSEMBLY__
1758 +struct cpulaunch_t {
1763 + unsigned long _pad[3]; /* pad to cache line size to avoid thrashing */
1764 + unsigned long flags;
1767 +extern char launch_wait_code_start;
1768 +extern char launch_wait_code_end;
1770 +void join_coherent_domain(int ncores);
1771 +void boot_vpe1(void);
1775 +#define LAUNCH_PC 0
1776 +#define LAUNCH_GP 4
1777 +#define LAUNCH_SP 8
1778 +#define LAUNCH_A0 12
1779 +#define LAUNCH_FLAGS 28
1783 +#define LOG2CPULAUNCH 5
1785 +#define LAUNCH_FREADY 1
1786 +#define LAUNCH_FGO 2
1787 +#define LAUNCH_FGONE 4
1789 +#define LAUNCH_WAITCODE 0x00000d00
1790 +#define SCRLAUNCH 0x00000e00
1791 +#define CPULAUNCH 0x00000f00
1792 +#define NCPULAUNCH 8
1794 +/* Polling period in count cycles for secondary CPU's */
1795 +#define LAUNCHPERIOD 10000
1797 +#endif /* _LAUNCH_H_ */
1799 +++ b/arch/mips/mach-mtmips/mt7621/spl/launch_ll.S
1801 +/* SPDX-License-Identifier: GPL-2.0 */
1803 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
1805 + * Author: Weijie Gao <weijie.gao@mediatek.com>
1808 +#include <asm/cm.h>
1809 +#include <asm/asm.h>
1810 +#include <asm/regdef.h>
1811 +#include <asm/cacheops.h>
1812 +#include <asm/mipsregs.h>
1813 +#include <asm/addrspace.h>
1814 +#include <asm/mipsmtregs.h>
1815 +#include "launch.h"
1817 + .macro cache_loop curr, end, line_sz, op
1818 +10: cache \op, 0(\curr)
1819 + PTR_ADDU \curr, \curr, \line_sz
1820 + bne \curr, \end, 10b
1826 + * Join the coherent domain
1827 + * a0 = number of cores
1829 +LEAF(join_coherent_domain)
1831 + * Enable coherence and allow interventions from all other cores.
1832 + * (Write access enabled via GCR_ACCESS by core 0.)
1838 + li t0, KSEG1ADDR(CONFIG_MIPS_CM_BASE)
1839 + sw t1, GCR_Cx_COHERENCE(t0)
1844 +_next_coherent_core:
1845 + sll t1, t2, GCR_Cx_OTHER_CORENUM_SHIFT
1846 + sw t1, GCR_Cx_OTHER(t0)
1848 +_busy_wait_coherent_core:
1849 + lw t1, GCR_CO_COHERENCE(t0)
1850 + beqz t1, _busy_wait_coherent_core
1853 + bne t2, a0, _next_coherent_core
1856 + END(join_coherent_domain)
1859 + * All VPEs other than VPE0 will go here.
1861 +LEAF(launch_vpe_entry)
1862 + mfc0 t0, CP0_EBASE
1863 + and t0, t0, MIPS_EBASE_CPUNUM
1865 + /* per-VPE cpulaunch_t */
1866 + li a0, KSEG0ADDR(CPULAUNCH)
1867 + sll t1, t0, LOG2CPULAUNCH
1870 + /* Set CPU online flag */
1871 + li t0, LAUNCH_FREADY
1872 + sw t0, LAUNCH_FLAGS(a0)
1874 + /* Enable count interrupt in mask, but do not enable interrupts */
1875 + mfc0 t0, CP0_STATUS
1876 + ori t0, STATUSF_IP7
1877 + mtc0 t0, CP0_STATUS
1879 + /* VPEs executing in wait code do not need a stack */
1880 + li t9, KSEG0ADDR(LAUNCH_WAITCODE)
1882 + END(launch_vpe_entry)
1885 + * This function will not be executed in place.
1886 + * It will be copied into memory, and VPEs other than VPE0 will be
1887 + * started to run into this in-memory function.
1889 +LEAF(launch_wait_code)
1890 + .globl launch_wait_code_start
1891 +launch_wait_code_start:
1896 + /* Poll CPU go flag */
1897 + mtc0 zero, CP0_COUNT
1898 + li t1, LAUNCHPERIOD
1899 + mtc0 t1, CP0_COMPARE
1902 + /* Software wait */
1903 + mfc0 t2, CP0_COUNT
1905 + bltz t2, time_wait
1907 + /* Check the launch flag */
1908 + lw t3, LAUNCH_FLAGS(t0)
1909 + and t3, LAUNCH_FGO
1910 + beqz t3, start_poll
1912 + /* Reset the counter and interrupts to give naive clients a chance */
1913 + mfc0 t1, CP0_STATUS
1914 + ins t1, zero, STATUSB_IP7, 1
1915 + mtc0 t1, CP0_STATUS
1917 + mfc0 t1, CP0_COUNT
1919 + mtc0 t1, CP0_COMPARE
1921 + /* Jump to kernel */
1922 + lw t9, LAUNCH_PC(t0)
1923 + lw gp, LAUNCH_GP(t0)
1924 + lw sp, LAUNCH_SP(t0)
1925 + lw a0, LAUNCH_A0(t0)
1929 + ori t3, LAUNCH_FGONE
1930 + sw t3, LAUNCH_FLAGS(t0)
1934 + .globl launch_wait_code_end
1935 +launch_wait_code_end:
1936 + END(launch_wait_code)
1939 + * Core1 will go here.
1941 +LEAF(launch_core_entry)
1942 + /* Disable caches */
1943 + bal mips_cache_disable
1945 + /* Initialize L1 cache only */
1946 + li a0, CONFIG_SYS_ICACHE_SIZE
1947 + li a1, CONFIG_SYS_ICACHE_LINE_SIZE
1948 + li a2, CONFIG_SYS_DCACHE_SIZE
1949 + li a3, CONFIG_SYS_DCACHE_LINE_SIZE
1951 + mtc0 zero, CP0_TAGLO
1952 + mtc0 zero, CP0_TAGLO, 2
1956 + * Initialize the I-cache first,
1960 + /* clear tag to invalidate */
1961 + cache_loop t0, t1, a1, INDEX_STORE_TAG_I
1962 +#ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
1963 + /* fill once, so data field parity is correct */
1965 + cache_loop t0, t1, a1, FILL
1966 + /* invalidate again - prudent but not strictly necessary */
1968 + cache_loop t0, t1, a1, INDEX_STORE_TAG_I
1972 + * then initialize D-cache.
1975 + PTR_ADDU t1, t0, a2
1976 + /* clear all tags */
1977 + cache_loop t0, t1, a3, INDEX_STORE_TAG_D
1978 +#ifdef CONFIG_SYS_MIPS_CACHE_INIT_RAM_LOAD
1979 + /* load from each line (in cached space) */
1981 +2: LONG_L zero, 0(t0)
1984 + /* clear all tags */
1986 + cache_loop t0, t1, a3, INDEX_STORE_TAG_D
1989 + /* Set Cache Mode */
1990 + mfc0 t0, CP0_CONFIG
1991 + li t1, CONF_CM_CACHABLE_COW
1993 + mtc0 t0, CP0_CONFIG
1995 + /* Join the coherent domain */
1997 + bal join_coherent_domain
1999 + /* Bootup Core0/VPE1 */
2002 + b launch_vpe_entry
2003 + END(launch_core_entry)
2007 + * This subroutine must be executed from VPE0 with VPECONF0[MVP] already set.
2010 + mfc0 t0, CP0_MVPCONF0
2012 + /* a0 = number of TCs - 1 */
2013 + ext a0, t0, MVPCONF0_PTC_SHIFT, 8
2014 + beqz a0, _vpe1_init_done
2016 + /* a1 = number of VPEs - 1 */
2017 + ext a1, t0, MVPCONF0_PVPE_SHIFT, 4
2018 + beqz a1, _vpe1_init_done
2020 + /* a2 = current TC No. */
2023 + /* Enter VPE Configuration State */
2024 + mfc0 t0, CP0_MVPCONTROL
2025 + or t0, MVPCONTROL_VPC
2026 + mtc0 t0, CP0_MVPCONTROL
2030 + /* Set the TC number to be used on MTTR and MFTR instructions */
2031 + mfc0 t0, CP0_VPECONTROL
2033 + mtc0 t0, CP0_VPECONTROL
2036 + /* TC0 is already bound */
2037 + beqz a2, _next_vpe
2039 + /* Halt current TC */
2041 + mttc0 t0, CP0_TCHALT
2044 + /* If there is spare TC, bind it to the last VPE (VPE[a1]) */
2046 + bnez t1, _vpe_bind_tc
2049 + /* Set Exclusive TC for active TC */
2050 + mftc0 t0, CP0_VPECONF0
2051 + ins t0, a2, VPECONF0_XTC_SHIFT, 8
2052 + mttc0 t0, CP0_VPECONF0
2056 + /* Bind TC to a VPE */
2057 + mftc0 t0, CP0_TCBIND
2058 + ins t0, t1, TCBIND_CURVPE_SHIFT, 4
2059 + mttc0 t0, CP0_TCBIND
2062 + * Set up CP0_TCSTATUS register:
2063 + * Disable Coprocessor Usable bits
2064 + * Disable MDMX/DSP ASE
2066 + * not dynamically allocatable
2069 + * interrupt exempt
2072 + li t0, TCSTATUS_IXMT
2073 + mttc0 t0, CP0_TCSTATUS
2077 + bnez t1, _done_vpe # No more VPEs
2079 + /* Disable TC multi-threading */
2080 + mftc0 t0, CP0_VPECONTROL
2081 + ins t0, zero, VPECONTROL_TE_SHIFT, 1
2082 + mttc0 t0, CP0_VPECONTROL
2084 + /* Skip following configuration for TC0 */
2085 + beqz a2, _done_vpe
2087 + /* Deactivate VPE, set Master VPE */
2088 + mftc0 t0, CP0_VPECONF0
2089 + ins t0, zero, VPECONF0_VPA_SHIFT, 1
2090 + or t0, VPECONF0_MVP
2091 + mttc0 t0, CP0_VPECONF0
2093 + mfc0 t0, CP0_STATUS
2094 + mttc0 t0, CP0_STATUS
2096 + mttc0 zero, CP0_EPC
2097 + mttc0 zero, CP0_CAUSE
2099 + mfc0 t0, CP0_CONFIG
2100 + mttc0 t0, CP0_CONFIG
2103 + * VPE1 of each core can execute cached as its L1 I$ has already
2104 + * been initialized.
2105 + * and the L2$ has been initialized or "disabled" via CCA override.
2108 + mttc0 t0, CP0_TCRESTART
2110 + /* Unset Interrupt Exempt, set Activate Thread */
2111 + mftc0 t0, CP0_TCSTATUS
2112 + ins t0, zero, TCSTATUS_IXMT_SHIFT, 1
2113 + ori t0, TCSTATUS_A
2114 + mttc0 t0, CP0_TCSTATUS
2117 + mttc0 zero, CP0_TCHALT
2119 + /* Activate VPE */
2120 + mftc0 t0, CP0_VPECONF0
2121 + ori t0, VPECONF0_VPA
2122 + mttc0 t0, CP0_VPECONF0
2129 + mfc0 t0, CP0_MVPCONTROL
2130 + /* Enable all activated VPE to execute */
2131 + ori t0, MVPCONTROL_EVP
2132 + /* Exit VPE Configuration State */
2133 + ins t0, zero, MVPCONTROL_VPC_SHIFT, 1
2134 + mtc0 t0, CP0_MVPCONTROL
2141 +++ b/arch/mips/mach-mtmips/mt7621/spl/serial.c
2143 +// SPDX-License-Identifier: GPL-2.0
2145 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
2147 + * Author: Weijie Gao <weijie.gao@mediatek.com>
2150 +#include <asm/io.h>
2151 +#include "../mt7621.h"
2153 +void mtmips_spl_serial_init(void)
2155 +#ifdef CONFIG_SPL_SERIAL
2156 + void __iomem *base = ioremap_nocache(SYSCTL_BASE, SYSCTL_SIZE);
2158 +#if CONFIG_CONS_INDEX == 1
2159 + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART1_MODE);
2160 +#elif CONFIG_CONS_INDEX == 2
2161 + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART2_MODE_M);
2162 +#elif CONFIG_CONS_INDEX == 3
2163 + clrbits_32(base + SYSCTL_GPIOMODE_REG, UART3_MODE_M);
2164 +#endif /* CONFIG_CONS_INDEX */
2165 +#endif /* CONFIG_SPL_SERIAL */
2168 +++ b/arch/mips/mach-mtmips/mt7621/spl/spl.c
2170 +// SPDX-License-Identifier: GPL-2.0
2172 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
2174 + * Author: Weijie Gao <weijie.gao@mediatek.com>
2180 +#include <vsprintf.h>
2181 +#include <malloc.h>
2182 +#include <asm/io.h>
2183 +#include <asm/sections.h>
2184 +#include <asm/addrspace.h>
2185 +#include <asm/byteorder.h>
2186 +#include <asm/global_data.h>
2187 +#include <linux/sizes.h>
2188 +#include <mach/serial.h>
2189 +#include "../mt7621.h"
2192 +DECLARE_GLOBAL_DATA_PTR;
2199 +void set_timer_freq_simple(void)
2201 + u32 div = get_xtal_mhz();
2203 + /* Round down cpu freq */
2204 + gd->arch.timer_freq = rounddown(CONFIG_MT7621_CPU_FREQ, div) * 500000;
2207 +void __noreturn board_init_f(ulong dummy)
2211 +#ifdef CONFIG_SPL_SERIAL
2213 + * mtmips_spl_serial_init() is useful if debug uart is enabled,
2214 + * or DM based serial is not enabled.
2216 + mtmips_spl_serial_init();
2217 + preloader_console_init();
2220 + board_init_r(NULL, 0);
2223 +void board_boot_order(u32 *spl_boot_list)
2225 +#ifdef CONFIG_MT7621_BOOT_FROM_NAND
2226 + spl_boot_list[0] = BOOT_DEVICE_NAND;
2228 + spl_boot_list[0] = BOOT_DEVICE_NOR;
2232 +unsigned long spl_nor_get_uboot_base(void)
2234 + const struct tpl_info *tpli;
2235 + const image_header_t *hdr;
2238 + addr = FLASH_MMAP_BASE + TPL_INFO_OFFSET;
2239 + tpli = (const struct tpl_info *)KSEG1ADDR(addr);
2241 + if (tpli->magic == TPL_INFO_MAGIC) {
2242 + addr = FLASH_MMAP_BASE + tpli->size;
2243 + hdr = (const image_header_t *)KSEG1ADDR(addr);
2245 + if (image_get_magic(hdr) == IH_MAGIC) {
2246 + addr += sizeof(*hdr) + image_get_size(hdr);
2247 + return KSEG1ADDR(addr);
2251 + panic("Unable to locate SPL payload\n");
2255 +uint32_t spl_nand_get_uboot_raw_page(void)
2257 + const struct stage_header *sh = (const struct stage_header *)&_start;
2260 + addr = image_get_header_size() + be32_to_cpu(sh->stage_size);
2261 + addr = ALIGN(addr, SZ_4K);
2266 +++ b/arch/mips/mach-mtmips/mt7621/spl/start.S
2268 +/* SPDX-License-Identifier: GPL-2.0 */
2270 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
2272 + * Author: Weijie Gao <weijie.gao@mediatek.com>
2275 +#include <asm-offsets.h>
2276 +#include <config.h>
2277 +#include <asm/asm.h>
2278 +#include <asm/regdef.h>
2279 +#include <asm/mipsregs.h>
2280 +#include <asm/cacheops.h>
2281 +#include <asm/addrspace.h>
2282 +#include <asm/mipsmtregs.h>
2283 +#include <asm/cm.h>
2284 +#include "../mt7621.h"
2287 +#ifndef CONFIG_SYS_INIT_SP_ADDR
2288 +#define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_SDRAM_BASE + \
2289 + CONFIG_SYS_INIT_SP_OFFSET)
2292 +#define SP_ADDR_TEMP 0xbe10dff0
2294 + .macro init_wr sel
2295 + MTC0 zero, CP0_WATCHLO,\sel
2296 + mtc0 t1, CP0_WATCHHI,\sel
2299 + .macro setup_stack_gd
2301 + PTR_LI t1, CONFIG_SYS_INIT_SP_ADDR
2302 + and sp, t1, t0 # force 16 byte alignment
2304 + sp, sp, GD_SIZE # reserve space for gd
2305 + and sp, sp, t0 # force 16 byte alignment
2306 + move k0, sp # save gd pointer
2307 +#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
2308 + !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
2309 + li t2, CONFIG_VAL(SYS_MALLOC_F_LEN)
2311 + sp, sp, t2 # reserve space for early malloc
2312 + and sp, sp, t0 # force 16 byte alignment
2320 + PTR_ADDIU t0, PTRSIZE
2324 +#if CONFIG_VAL(SYS_MALLOC_F_LEN) && \
2325 + !CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
2326 + PTR_S sp, GD_MALLOC_BASE(k0) # gd->malloc_base offset
2334 + mtc0 zero, CP0_COUNT
2336 + /* Stage header required by BootROM */
2338 + .word 0 # ep, filled by mkimage
2339 + .word 0 # stage_size, filled by mkimage
2340 + .word 0 # has_stage2
2342 + .word 0 # next_size
2343 + .word 0 # next_offset
2346 + /* Init CP0 Status */
2347 + mfc0 t0, CP0_STATUS
2349 + or t0, ST0_BEV | ST0_ERL
2350 + mtc0 t0, CP0_STATUS
2353 + /* Clear Watch Status bits and disable watch exceptions */
2354 + li t1, 0x7 # Clear I, R and W conditions
2360 + /* Clear WP, IV and SW interrupts */
2361 + mtc0 zero, CP0_CAUSE
2363 + /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
2364 + mtc0 zero, CP0_COMPARE
2366 + /* VPE1 goes to wait code directly */
2367 + mfc0 t0, CP0_TCBIND
2368 + andi t0, TCBIND_CURVPE
2369 + bnez t0, launch_vpe_entry
2372 + /* Core1 goes to specific launch entry */
2373 + PTR_LI t0, KSEG1ADDR(CONFIG_MIPS_CM_BASE)
2374 + lw t1, GCR_Cx_ID(t0)
2375 + bnez t1, launch_core_entry
2378 + /* MT7530 reset */
2379 + li t0, KSEG1ADDR(SYSCTL_BASE)
2380 + lw t1, SYSCTL_RSTCTL_REG(t0)
2382 + sw t1, SYSCTL_RSTCTL_REG(t0)
2384 + /* Disable DMA route for PSE SRAM set by BootROM */
2385 + PTR_LI t0, KSEG1ADDR(DMA_CFG_ARB_BASE)
2386 + sw zero, DMA_ROUTE_REG(t0)
2388 + /* Set CPU clock to 500MHz (Required if boot from NAND) */
2389 + li t0, KSEG1ADDR(SYSCTL_BASE)
2390 + lw t1, SYSCTL_CLKCFG0_REG(t0)
2391 + ins t1, zero, 30, 2 # CPU_CLK_SEL
2392 + sw t1, SYSCTL_CLKCFG0_REG(t0)
2394 + /* Set CPU clock divider to 1/1 */
2395 + li t0, KSEG1ADDR(RBUS_BASE)
2397 + sw t1, RBUS_DYN_CFG0_REG(t0)
2399 + /* (Re-)initialize the SRAM */
2400 + bal mips_sram_init
2403 + /* Set up temporary stack */
2404 + li sp, SP_ADDR_TEMP
2406 + /* Setup full CPS */
2410 + bal mt7621_cps_init
2413 + /* Prepare for CPU/DDR initialization binary blob */
2414 + bal prepare_stage_bin
2417 + /* Call CPU/DDR initialization binary blob */
2418 + li t9, STAGE_LOAD_ADDR
2422 + /* Switch CPU PLL source */
2423 + li t0, KSEG1ADDR(SYSCTL_BASE)
2424 + lw t1, SYSCTL_CLKCFG0_REG(t0)
2426 + ins t1, t2, CPU_CLK_SEL_S, 2
2427 + sw t1, SYSCTL_CLKCFG0_REG(t0)
2430 + * Currently SPL is running on locked L2 cache (on KSEG0).
2431 + * To reset the entire cache, we have to writeback SPL to DRAM first.
2432 + * Cache flush won't work here. Use memcpy instead.
2435 + la a0, __text_start
2437 + la a2, __image_copy_end
2440 + ins a0, a3, 29, 3 # convert to KSEG1
2445 + /* Disable caches */
2446 + bal mips_cache_disable
2449 + /* Reset caches */
2450 + bal mips_cache_reset
2453 + /* Disable SRAM */
2454 + li t0, KSEG1ADDR(FE_BASE)
2455 + li t1, FE_PSE_RESET
2456 + sw t1, FE_RST_GLO_REG(t0)
2458 + /* Clear the .bss section */
2459 + la a0, __bss_start
2466 + /* Set up initial stack and global data */
2469 +#if CONFIG_IS_ENABLED(INIT_STACK_WITHOUT_MALLOC_F)
2470 + /* Set malloc base */
2471 + li t0, (CONFIG_SYS_INIT_SP_ADDR + 15) & (~15)
2472 + PTR_S t0, GD_MALLOC_BASE(k0) # gd->malloc_base offset
2475 +#if defined(CONFIG_DEBUG_UART) && defined(CONFIG_SPL_SERIAL)
2476 + /* Earliest point to set up debug uart */
2477 + bal debug_uart_init
2482 + bal set_timer_freq_simple
2485 + /* Bootup secondary CPUs */
2486 + bal secondary_cpu_init
2489 + move a0, zero # a0 <-- boot_flags = 0
2495 +++ b/arch/mips/mach-mtmips/mt7621/sram_init.S
2497 +/* SPDX-License-Identifier: GPL-2.0 */
2499 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
2501 + * Author: Weijie Gao <weijie.gao@mediatek.com>
2504 +#include <asm/addrspace.h>
2505 +#include <asm/asm.h>
2506 +#include <asm/regdef.h>
2507 +#include "mt7621.h"
2509 +LEAF(mips_sram_init)
2510 + li t0, KSEG1ADDR(FE_BASE)
2511 + li t1, FE_PSE_RESET
2512 + sw t1, FE_RST_GLO_REG(t0)
2514 + li t1, (FE_PSE_RAM | FE_PSE_MEM_EN)
2515 + sw t1, FE_RST_GLO_REG(t0)
2518 + END(mips_sram_init)
2520 +++ b/arch/mips/mach-mtmips/mt7621/tpl/Makefile
2527 +++ b/arch/mips/mach-mtmips/mt7621/tpl/start.S
2529 +/* SPDX-License-Identifier: GPL-2.0 */
2531 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
2533 + * Author: Weijie Gao <weijie.gao@mediatek.com>
2536 +#include <asm-offsets.h>
2537 +#include <config.h>
2538 +#include <asm/asm.h>
2539 +#include <asm/regdef.h>
2540 +#include <asm/addrspace.h>
2541 +#include <asm/mipsregs.h>
2542 +#include <asm/cm.h>
2543 +#include "../mt7621.h"
2545 +#define SP_ADDR_TEMP 0xbe10dff0
2549 + .macro init_wr sel
2550 + MTC0 zero, CP0_WATCHLO,\sel
2551 + mtc0 t1, CP0_WATCHHI,\sel
2554 + .macro uhi_mips_exception
2555 + move k0, t9 # preserve t9 in k0
2556 + move k1, a0 # preserve a0 in k1
2557 + li t9, 15 # UHI exception operation
2558 + li a0, 0 # Use hard register context
2559 + sdbbp 1 # Invoke UHI operation
2564 + mtc0 zero, CP0_COUNT
2567 + * Store TPL size here.
2568 + * This will be used by SPL to locate u-boot payload.
2570 + .org TPL_INFO_OFFSET
2571 + .word TPL_INFO_MAGIC
2572 + .word __image_copy_len
2574 + /* Exception vector */
2576 + /* TLB refill, 32 bit task */
2577 + uhi_mips_exception
2580 + /* XTLB refill, 64 bit task */
2581 + uhi_mips_exception
2584 + /* Cache error exception */
2585 + uhi_mips_exception
2588 + /* General exception */
2589 + uhi_mips_exception
2592 + /* Catch interrupt exceptions */
2593 + uhi_mips_exception
2596 + /* EJTAG debug exception */
2603 + /* Set KSEG0 to Uncached */
2604 + mfc0 t0, CP0_CONFIG
2605 + ins t0, zero, 0, 3
2606 + ori t0, t0, CONF_CM_UNCACHED
2607 + mtc0 t0, CP0_CONFIG
2610 + /* Check for CPU number */
2611 + mfc0 t0, CP0_EBASE
2612 + and t0, t0, MIPS_EBASE_CPUNUM
2616 + /* Secondary core goes to specified SPL entry address */
2617 + li t0, KSEG1ADDR(SYSCTL_BASE)
2618 + lw t0, BOOT_SRAM_BASE_REG(t0)
2622 + /* Init CP0 Status */
2623 +1: mfc0 t0, CP0_STATUS
2625 + or t0, ST0_BEV | ST0_ERL
2626 + mtc0 t0, CP0_STATUS
2629 + /* Clear Watch Status bits and disable watch exceptions */
2630 + li t1, 0x7 # Clear I, R and W conditions
2636 + /* Clear WP, IV and SW interrupts */
2637 + mtc0 zero, CP0_CAUSE
2639 + /* Clear timer interrupt (CP0_COUNT cleared on branch to 'reset') */
2640 + mtc0 zero, CP0_COMPARE
2642 + /* Setup basic CPS */
2646 + li t0, KSEG1ADDR(CONFIG_MIPS_CM_BASE)
2647 + li t1, GCR_REG0_BASE_VALUE
2648 + sw t1, GCR_REG0_BASE(t0)
2650 + li t1, ((GCR_REG0_MASK_VALUE << GCR_REGn_MASK_ADDRMASK_SHIFT) | \
2651 + GCR_REGn_MASK_CMTGT_IOCU0)
2652 + sw t1, GCR_REG0_MASK(t0)
2654 + lw t1, GCR_BASE(t0)
2655 + ins t1, zero, 0, 2 # CM_DEFAULT_TARGET
2656 + sw t1, GCR_BASE(t0)
2658 + lw t1, GCR_CONTROL(t0)
2659 + li t2, GCR_CONTROL_SYNCCTL
2661 + sw t1, GCR_CONTROL(t0)
2663 + /* Increase SPI frequency */
2664 + li t0, KSEG1ADDR(SPI_BASE)
2666 + sw t1, SPI_SPACE_REG(t0)
2668 + /* Set CPU clock to 500MHz */
2669 + li t0, KSEG1ADDR(SYSCTL_BASE)
2670 + lw t1, SYSCTL_CLKCFG0_REG(t0)
2671 + ins t1, zero, 30, 2 # CPU_CLK_SEL
2672 + sw t1, SYSCTL_CLKCFG0_REG(t0)
2674 + /* Set CPU clock divider to 1/1 */
2675 + li t0, KSEG1ADDR(RBUS_BASE)
2677 + sw t1, RBUS_DYN_CFG0_REG(t0)
2679 + /* Initialize the SRAM */
2680 + bal mips_sram_init
2683 + /* Set up initial stack */
2684 + li sp, SP_ADDR_TEMP
2691 +++ b/arch/mips/mach-mtmips/mt7621/tpl/tpl.c
2693 +// SPDX-License-Identifier: GPL-2.0
2695 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
2697 + * Author: Weijie Gao <weijie.gao@mediatek.com>
2701 +#include <asm/system.h>
2702 +#include <asm/sections.h>
2703 +#include <asm/cacheops.h>
2704 +#include <asm/mipsregs.h>
2705 +#include <asm/cm.h>
2707 +#define INDEX_STORE_DATA_SD 0x0f
2709 +typedef void __noreturn (*image_entry_noargs_t)(void);
2712 + * Lock L2 cache and fill data
2713 + * Assume that data is 4-byte aligned and start_addr/size is 32-byte aligned
2715 +static void fill_lock_l2cache(uintptr_t dataptr, ulong start_addr, ulong size)
2717 + ulong slsize = CONFIG_SYS_DCACHE_LINE_SIZE;
2718 + ulong end_addr = start_addr + size;
2719 + const u32 *data = (u32 *)dataptr;
2723 + /* Clear WSC & SPR bit in ErrCtl */
2724 + val = read_c0_ecc();
2725 + val &= 0xcfffffff;
2726 + write_c0_ecc(val);
2727 + execution_hazard_barrier();
2729 + for (addr = start_addr; addr < end_addr; addr += slsize) {
2730 + /* Set STagLo to lock cache line */
2731 + write_c0_staglo((addr & 0x1ffff800) | 0xa0);
2732 + mips_cache(INDEX_STORE_TAG_SD, (void *)addr);
2735 + for (i = 0; i < slsize; i += 8) {
2737 + __write_32bit_c0_register($28, 5, val); /* sdtaglo */
2739 + __write_32bit_c0_register($29, 5, val); /* sdtaghi */
2740 + mips_cache(INDEX_STORE_DATA_SD, (void *)(addr + i));
2747 +/* A simple function to initialize MT7621's cache */
2748 +static void mt7621_cache_init(void)
2750 + void __iomem *cm_base = (void *)KSEG1ADDR(CONFIG_MIPS_CM_BASE);
2751 + ulong lsize = CONFIG_SYS_DCACHE_LINE_SIZE;
2755 + /* Enable CCA override. Set to uncached */
2756 + val = readl(cm_base + GCR_BASE);
2757 + val &= ~CCA_DEFAULT_OVR_MASK;
2758 + val |= CCA_DEFAULT_OVREN | (2 << CCA_DEFAULT_OVR_SHIFT);
2759 + writel(val, cm_base + GCR_BASE);
2761 + /* Initialize L1 I-Cache */
2762 + write_c0_taglo(0);
2763 + write_c0_taghi(0);
2765 + for (addr = 0; addr < CONFIG_SYS_ICACHE_SIZE; addr += lsize)
2766 + mips_cache(INDEX_STORE_TAG_I, (void *)addr);
2768 + /* Initialize L1 D-Cache */
2769 + write_c0_dtaglo(0);
2770 + __write_32bit_c0_register($29, 2, 0); /* dtaghi */
2772 + for (addr = 0; addr < CONFIG_SYS_DCACHE_SIZE; addr += lsize)
2773 + mips_cache(INDEX_STORE_TAG_D, (void *)addr);
2775 + /* Initialize L2 Cache */
2776 + write_c0_staglo(0);
2777 + __write_32bit_c0_register($29, 4, 0); /* staghi */
2779 + for (addr = 0; addr < (256 << 10); addr += lsize)
2780 + mips_cache(INDEX_STORE_TAG_SD, (void *)addr);
2782 + /* Dsiable CCA override */
2783 + val = readl(cm_base + GCR_BASE);
2784 + val &= ~(CCA_DEFAULT_OVR_MASK | CCA_DEFAULT_OVREN);
2785 + writel(val, cm_base + GCR_BASE);
2787 + /* Set KSEG0 to non-coherent cached (important!) */
2788 + val = read_c0_config();
2789 + val &= ~CONF_CM_CMASK;
2790 + val |= CONF_CM_CACHABLE_NONCOHERENT;
2791 + write_c0_config(val);
2792 + execution_hazard_barrier();
2794 + /* Again, invalidate L1 D-Cache */
2795 + for (addr = 0; addr < CONFIG_SYS_DCACHE_SIZE; addr += lsize)
2796 + mips_cache(INDEX_WRITEBACK_INV_D, (void *)addr);
2798 + /* Invalidate L1 I-Cache */
2799 + for (addr = 0; addr < CONFIG_SYS_ICACHE_SIZE; addr += lsize)
2800 + mips_cache(INDEX_INVALIDATE_I, (void *)addr);
2802 + /* Disable L2 cache bypass */
2803 + val = read_c0_config2();
2804 + val &= ~MIPS_CONF_IMPL;
2805 + write_c0_config2(val);
2806 + execution_hazard_barrier();
2809 +void __noreturn tpl_main(void)
2811 + const image_header_t *hdr = (const image_header_t *)__image_copy_end;
2812 + image_entry_noargs_t image_entry;
2813 + u32 loadaddr, size;
2816 + /* Initialize the cache first */
2817 + mt7621_cache_init();
2819 + if (image_get_magic(hdr) != IH_MAGIC)
2822 + loadaddr = image_get_load(hdr);
2823 + size = image_get_size(hdr);
2824 + image_entry = (image_entry_noargs_t)image_get_ep(hdr);
2826 + /* Load TPL image to L2 cache */
2827 + data = (uintptr_t)__image_copy_end + sizeof(struct image_header);
2828 + fill_lock_l2cache(data, loadaddr, size);
2838 +++ b/include/configs/mt7621.h
2840 +/* SPDX-License-Identifier: GPL-2.0 */
2842 + * Copyright (C) 2022 MediaTek Inc. All rights reserved.
2844 + * Author: Weijie Gao <weijie.gao@mediatek.com>
2847 +#ifndef __CONFIG_MT7621_H
2848 +#define __CONFIG_MT7621_H
2850 +#define CONFIG_SYS_MIPS_TIMER_FREQ 440000000
2852 +#define CONFIG_SYS_BOOTPARAMS_LEN 0x20000
2854 +#define CONFIG_SYS_SDRAM_BASE 0x80000000
2856 +#define CONFIG_VERY_BIG_RAM
2857 +#define CONFIG_MAX_MEM_MAPPED 0x1c000000
2859 +#define CONFIG_SYS_INIT_SP_OFFSET 0x800000
2861 +#define CONFIG_SYS_BOOTM_LEN 0x2000000
2863 +#define CONFIG_SYS_MAXARGS 16
2864 +#define CONFIG_SYS_CBSIZE 1024
2866 +#define CONFIG_SYS_NONCACHED_MEMORY 0x100000
2869 +#define MMC_SUPPORTS_TUNING
2872 +#define CONFIG_SYS_MAX_NAND_DEVICE 1
2875 +#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_SERIAL)
2876 +#define CONFIG_SYS_NS16550_MEM32
2877 +#define CONFIG_SYS_NS16550_CLK 50000000
2878 +#define CONFIG_SYS_NS16550_REG_SIZE -4
2879 +#define CONFIG_SYS_NS16550_COM1 0xbe000c00
2882 +/* Serial common */
2883 +#define CONFIG_SYS_BAUDRATE_TABLE { 9600, 19200, 38400, 57600, 115200, \
2884 + 230400, 460800, 921600 }
2887 +#define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE
2889 +#ifdef CONFIG_TPL_BUILD
2890 +#define CONFIG_SPL_START_S_PATH "arch/mips/mach-mtmips/mt7621/tpl"
2891 +/* .bss will not be used by TPL */
2892 +#define CONFIG_SPL_BSS_START_ADDR 0x80000000
2893 +#define CONFIG_SPL_BSS_MAX_SIZE 0
2895 +#define CONFIG_SPL_START_S_PATH "arch/mips/mach-mtmips/mt7621/spl"
2896 +#define CONFIG_SPL_BSS_START_ADDR 0x80140000
2897 +#define CONFIG_SPL_BSS_MAX_SIZE 0x80000
2898 +#define CONFIG_SPL_MAX_SIZE 0x30000
2902 +#define CONFIG_SYS_UBOOT_BASE 0
2904 +#endif /* __CONFIG_MT7621_H */