xref: /openbmc/u-boot/arch/arm/mach-bcm283x/reset.c (revision 9d0dc69235e8327dba5536761c768d40c4e514e5)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
2ddf6bd48SMasahiro Yamada /*
3ddf6bd48SMasahiro Yamada  * (C) Copyright 2012 Stephen Warren
4ddf6bd48SMasahiro Yamada  *
5ddf6bd48SMasahiro Yamada  * See file CREDITS for list of people who contributed to this
6ddf6bd48SMasahiro Yamada  * project.
7ddf6bd48SMasahiro Yamada  */
8ddf6bd48SMasahiro Yamada 
9ddf6bd48SMasahiro Yamada #include <common.h>
10ddf6bd48SMasahiro Yamada #include <asm/io.h>
11ddf6bd48SMasahiro Yamada #include <asm/arch/wdog.h>
126b0ee506SAlexander Graf #include <efi_loader.h>
13ddf6bd48SMasahiro Yamada 
14ddf6bd48SMasahiro Yamada #define RESET_TIMEOUT 10
15ddf6bd48SMasahiro Yamada 
166b0ee506SAlexander Graf /*
176b0ee506SAlexander Graf  * The Raspberry Pi firmware uses the RSTS register to know which partiton
186b0ee506SAlexander Graf  * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
196b0ee506SAlexander Graf  * Partiton 63 is a special partition used by the firmware to indicate halt.
206b0ee506SAlexander Graf  */
216b0ee506SAlexander Graf #define BCM2835_WDOG_RSTS_RASPBERRYPI_HALT	0x555
226b0ee506SAlexander Graf 
2345a6d231SPaolo Pisati /* max ticks timeout */
2445a6d231SPaolo Pisati #define BCM2835_WDOG_MAX_TIMEOUT	0x000fffff
2545a6d231SPaolo Pisati 
2645a6d231SPaolo Pisati #ifdef CONFIG_BCM2835_WDT
2745a6d231SPaolo Pisati extern void hw_watchdog_disable(void);
2845a6d231SPaolo Pisati #else
hw_watchdog_disable(void)2945a6d231SPaolo Pisati void hw_watchdog_disable(void) {}
3045a6d231SPaolo Pisati #endif
3145a6d231SPaolo Pisati 
326b0ee506SAlexander Graf __efi_runtime_data struct bcm2835_wdog_regs *wdog_regs =
33ddf6bd48SMasahiro Yamada 	(struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
346b0ee506SAlexander Graf 
reset_cpu(ulong ticks)3545a6d231SPaolo Pisati void __efi_runtime reset_cpu(ulong ticks)
366b0ee506SAlexander Graf {
3745a6d231SPaolo Pisati 	uint32_t rstc, timeout;
3845a6d231SPaolo Pisati 
3945a6d231SPaolo Pisati 	if (ticks == 0) {
4045a6d231SPaolo Pisati 		hw_watchdog_disable();
4145a6d231SPaolo Pisati 		timeout = RESET_TIMEOUT;
4245a6d231SPaolo Pisati 	} else
4345a6d231SPaolo Pisati 		timeout = ticks & BCM2835_WDOG_MAX_TIMEOUT;
44ddf6bd48SMasahiro Yamada 
456b0ee506SAlexander Graf 	rstc = readl(&wdog_regs->rstc);
46ddf6bd48SMasahiro Yamada 	rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK;
47ddf6bd48SMasahiro Yamada 	rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET;
48ddf6bd48SMasahiro Yamada 
4945a6d231SPaolo Pisati 	writel(BCM2835_WDOG_PASSWORD | timeout, &wdog_regs->wdog);
506b0ee506SAlexander Graf 	writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc);
51ddf6bd48SMasahiro Yamada }
526b0ee506SAlexander Graf 
536b0ee506SAlexander Graf #ifdef CONFIG_EFI_LOADER
546b0ee506SAlexander Graf 
efi_reset_system(enum efi_reset_type reset_type,efi_status_t reset_status,unsigned long data_size,void * reset_data)556b0ee506SAlexander Graf void __efi_runtime EFIAPI efi_reset_system(
566b0ee506SAlexander Graf 			enum efi_reset_type reset_type,
576b0ee506SAlexander Graf 			efi_status_t reset_status,
586b0ee506SAlexander Graf 			unsigned long data_size, void *reset_data)
596b0ee506SAlexander Graf {
606b0ee506SAlexander Graf 	u32 val;
616b0ee506SAlexander Graf 
62*e4679489SAlexander Graf 	if (reset_type == EFI_RESET_COLD ||
63*e4679489SAlexander Graf 	    reset_type == EFI_RESET_WARM ||
64*e4679489SAlexander Graf 	    reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
656b0ee506SAlexander Graf 		reset_cpu(0);
66*e4679489SAlexander Graf 	} else if (reset_type == EFI_RESET_SHUTDOWN) {
676b0ee506SAlexander Graf 		/*
686b0ee506SAlexander Graf 		 * We set the watchdog hard reset bit here to distinguish this reset
696b0ee506SAlexander Graf 		 * from the normal (full) reset. bootcode.bin will not reboot after a
706b0ee506SAlexander Graf 		 * hard reset.
716b0ee506SAlexander Graf 		 */
726b0ee506SAlexander Graf 		val = readl(&wdog_regs->rsts);
736b0ee506SAlexander Graf 		val |= BCM2835_WDOG_PASSWORD;
746b0ee506SAlexander Graf 		val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT;
756b0ee506SAlexander Graf 		writel(val, &wdog_regs->rsts);
766b0ee506SAlexander Graf 		reset_cpu(0);
776b0ee506SAlexander Graf 	}
786b0ee506SAlexander Graf 
796b0ee506SAlexander Graf 	while (1) { }
806b0ee506SAlexander Graf }
816b0ee506SAlexander Graf 
efi_reset_system_init(void)8222c793e6SHeinrich Schuchardt efi_status_t efi_reset_system_init(void)
836b0ee506SAlexander Graf {
8422c793e6SHeinrich Schuchardt 	return efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs));
856b0ee506SAlexander Graf }
866b0ee506SAlexander Graf 
876b0ee506SAlexander Graf #endif
88