1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Stefan Roese <sr@denx.de>
12 #include <linux/sizes.h>
17 #ifdef CONFIG_BOOT_ROM
18 int mach_cpu_init(void)
28 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, SZ_256M);
33 int print_cpuinfo(void)
35 static const char * const boot_str[] = { "PLL (3-Byte SPI Addr)",
36 "PLL (4-Byte SPI Addr)",
37 "XTAL (3-Byte SPI Addr)",
38 "XTAL (4-Byte SPI Addr)" };
39 const void *blob = gd->fdt_blob;
40 void __iomem *sysc_base;
41 char buf[STR_LEN + 1];
48 /* Get system controller base address */
49 node = fdt_node_offset_by_compatible(blob, -1, "ralink,mt7620a-sysc");
51 return -FDT_ERR_NOTFOUND;
53 base = fdtdec_get_addr_size_auto_noparent(blob, node, "reg",
55 if (base == FDT_ADDR_T_NONE)
58 sysc_base = ioremap_nocache(base, size);
60 str = (char *)sysc_base + MT76XX_CHIPID_OFFS;
61 snprintf(buf, STR_LEN + 1, "%s", str);
62 val = readl(sysc_base + MT76XX_CHIP_REV_ID_OFFS);
63 printf("CPU: %-*s Rev %ld.%ld - ", STR_LEN, buf,
64 (val & GENMASK(11, 8)) >> 8, val & GENMASK(3, 0));
66 val = (readl(sysc_base + MT76XX_SYSCFG0_OFFS) & GENMASK(3, 1)) >> 1;
67 printf("Boot from %s\n", boot_str[val]);
72 #ifdef CONFIG_WATCHDOG
73 static struct udevice *watchdog_dev __attribute__((section(".data"))) = NULL;
75 /* Called by macro WATCHDOG_RESET */
76 void watchdog_reset(void)
78 static ulong next_reset;
86 /* Do not reset the watchdog too often */
87 if (now > next_reset) {
88 next_reset = now + 1000; /* reset every 1000ms */
89 wdt_reset(watchdog_dev);
94 int arch_misc_init(void)
97 * It has been noticed, that sometimes the d-cache is not in a
98 * "clean-state" when U-Boot is running on MT7688. This was
99 * detected when using the ethernet driver (which uses d-cache)
100 * and a TFTP command does not complete. Flushing the complete
101 * d-cache (again?) here seems to fix this issue.
103 flush_dcache_range(gd->bd->bi_memstart,
104 gd->bd->bi_memstart + gd->ram_size - 1);
106 #ifdef CONFIG_WATCHDOG
108 if (uclass_get_device_by_seq(UCLASS_WDT, 0, &watchdog_dev)) {
109 debug("Watchdog: Not found by seq!\n");
110 if (uclass_get_device(UCLASS_WDT, 0, &watchdog_dev)) {
111 puts("Watchdog: Not found!\n");
116 wdt_start(watchdog_dev, 60000, 0); /* 60 seconds */
117 printf("Watchdog: Started\n");