2 * (C) Copyright 2012 Stephen Warren
4 * See file CREDITS for list of people who contributed to this
7 * SPDX-License-Identifier: GPL-2.0
12 #include <asm/arch/wdog.h>
13 #include <efi_loader.h>
15 #define RESET_TIMEOUT 10
18 * The Raspberry Pi firmware uses the RSTS register to know which partiton
19 * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
20 * Partiton 63 is a special partition used by the firmware to indicate halt.
22 #define BCM2835_WDOG_RSTS_RASPBERRYPI_HALT 0x555
24 /* max ticks timeout */
25 #define BCM2835_WDOG_MAX_TIMEOUT 0x000fffff
27 #ifdef CONFIG_BCM2835_WDT
28 extern void hw_watchdog_disable(void);
30 void hw_watchdog_disable(void) {}
33 __efi_runtime_data struct bcm2835_wdog_regs *wdog_regs =
34 (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
36 void __efi_runtime reset_cpu(ulong ticks)
38 uint32_t rstc, timeout;
41 hw_watchdog_disable();
42 timeout = RESET_TIMEOUT;
44 timeout = ticks & BCM2835_WDOG_MAX_TIMEOUT;
46 rstc = readl(&wdog_regs->rstc);
47 rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK;
48 rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET;
50 writel(BCM2835_WDOG_PASSWORD | timeout, &wdog_regs->wdog);
51 writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc);
54 #ifdef CONFIG_EFI_LOADER
56 void __efi_runtime EFIAPI efi_reset_system(
57 enum efi_reset_type reset_type,
58 efi_status_t reset_status,
59 unsigned long data_size, void *reset_data)
68 case EFI_RESET_SHUTDOWN:
70 * We set the watchdog hard reset bit here to distinguish this reset
71 * from the normal (full) reset. bootcode.bin will not reboot after a
74 val = readl(&wdog_regs->rsts);
75 val |= BCM2835_WDOG_PASSWORD;
76 val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT;
77 writel(val, &wdog_regs->rsts);
85 void efi_reset_system_init(void)
87 efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs));