Debian Codegraph @

src/soc/mediatek/common/wdt.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <arch/cache.h>
4 #include <delay.h>
5 #include <device/mmio.h>
6 #include <console/console.h>
7 #include <halt.h>
8 #include <soc/wdt.h>
9 #include <vendorcode/google/chromeos/chromeos.h>
10
11 __weak void mtk_wdt_clr_status(void) { /* do nothing */ }
12 __weak void mtk_wdt_set_req(void) { /* do nothing */ }
13 __weak void mtk_wdt_clear_efuse_ecc(void) { /* do nothing */ }
14
15 static inline void mtk_wdt_swreset(void)
16 {
17 /*
18 * We trigger a secondary reset by triggering WDT hardware to send the
19 * signal to EC.
20 * We do not use do_board_reset() to send the signal to EC which is
21 * controlled by software driver.
22 * Before triggering the secondary reset, clean the data cache so the
23 * logs in cbmem console (either in SRAM or DRAM) can be flushed.
24 */
25 printk(BIOS_INFO, "%s() called!\n", __func__);
26
27 dcache_clean_all();
28 write32(&mtk_wdt->wdt_restart, MTK_WDT_RESTART_KEY);
29 setbits32(&mtk_wdt->wdt_mode, MTK_WDT_MODE_EXTEN | MTK_WDT_MODE_KEY);
30 udelay(100);
31 write32(&mtk_wdt->wdt_swrst, MTK_WDT_SWRST_KEY);
32
33 halt();
34 }
35
36 int mtk_wdt_init(void)
37 {
38 uint32_t wdt_sta;
39
40 mtk_wdt_clear_efuse_ecc();
41 mtk_wdt_set_req();
42
43 /* Writing mode register will clear status register */
44 wdt_sta = read32(&mtk_wdt->wdt_status);
45
46 mtk_wdt_clr_status();
47
48 printk(BIOS_INFO, "WDT: Status = %#x\n", wdt_sta);
49
50 printk(BIOS_INFO, "WDT: Last reset was ");
51 if (!wdt_sta) {
52 printk(BIOS_INFO, "cold boot\n");
53 } else {
54 if (wdt_sta & MTK_WDT_STA_HW_RST)
55 printk(BIOS_INFO, "hardware watchdog\n");
56 else if (wdt_sta & MTK_WDT_STA_SW_RST)
57 printk(BIOS_INFO, "normal software reboot\n");
58 else if (wdt_sta & MTK_WDT_STA_SPM_RST)
59 printk(BIOS_INFO, "SPM reboot\n");
60 else
61 printk(BIOS_INFO, "other reset type: %#.8x\n", wdt_sta);
62
63 mark_watchdog_tombstone();
64 mtk_wdt_swreset();
65 }
66
67 /* Config watchdog reboot mode:
68 * Clearing bits:
69 * DUAL_MODE & IRQ: trigger reset instead of irq then reset.
70 * EXT_POL: select watchdog output signal as active low.
71 * ENABLE: disable watchdog on initialization.
72 * Setting bit EXTEN to enable watchdog output.
73 */
74 clrsetbits32(&mtk_wdt->wdt_mode,
75 MTK_WDT_MODE_DUAL_MODE | MTK_WDT_MODE_IRQ |
76 MTK_WDT_MODE_EXT_POL | MTK_WDT_MODE_ENABLE,
77 MTK_WDT_MODE_EXTEN | MTK_WDT_MODE_KEY);
78
79 return wdt_sta;
80 }