2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2012-08-05 16:07:21 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2012 Stephen Warren
|
|
|
|
*
|
|
|
|
* See file CREDITS for list of people who contributed to this
|
|
|
|
* project.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:45:01 +00:00
|
|
|
#include <cpu_func.h>
|
2012-08-05 16:07:21 +00:00
|
|
|
#include <asm/io.h>
|
2019-11-19 15:01:03 +00:00
|
|
|
#include <asm/arch/base.h>
|
2012-08-05 16:07:21 +00:00
|
|
|
#include <asm/arch/wdog.h>
|
2016-11-02 09:36:18 +00:00
|
|
|
#include <efi_loader.h>
|
2012-08-05 16:07:21 +00:00
|
|
|
|
|
|
|
#define RESET_TIMEOUT 10
|
|
|
|
|
2016-11-02 09:36:18 +00:00
|
|
|
/*
|
|
|
|
* The Raspberry Pi firmware uses the RSTS register to know which partiton
|
|
|
|
* to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
|
|
|
|
* Partiton 63 is a special partition used by the firmware to indicate halt.
|
|
|
|
*/
|
|
|
|
#define BCM2835_WDOG_RSTS_RASPBERRYPI_HALT 0x555
|
|
|
|
|
2017-02-10 16:28:05 +00:00
|
|
|
/* max ticks timeout */
|
|
|
|
#define BCM2835_WDOG_MAX_TIMEOUT 0x000fffff
|
|
|
|
|
|
|
|
void hw_watchdog_disable(void) {}
|
|
|
|
|
2019-11-19 15:01:03 +00:00
|
|
|
__efi_runtime_data struct bcm2835_wdog_regs *wdog_regs;
|
2016-11-02 09:36:18 +00:00
|
|
|
|
2019-11-19 15:01:03 +00:00
|
|
|
static void __efi_runtime
|
|
|
|
__reset_cpu(struct bcm2835_wdog_regs *wdog_regs, ulong ticks)
|
2012-08-05 16:07:21 +00:00
|
|
|
{
|
2017-02-10 16:28:05 +00:00
|
|
|
uint32_t rstc, timeout;
|
|
|
|
|
|
|
|
if (ticks == 0) {
|
|
|
|
hw_watchdog_disable();
|
|
|
|
timeout = RESET_TIMEOUT;
|
|
|
|
} else
|
|
|
|
timeout = ticks & BCM2835_WDOG_MAX_TIMEOUT;
|
2012-08-05 16:07:21 +00:00
|
|
|
|
2016-11-02 09:36:18 +00:00
|
|
|
rstc = readl(&wdog_regs->rstc);
|
2012-08-05 16:07:21 +00:00
|
|
|
rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK;
|
|
|
|
rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET;
|
|
|
|
|
2017-02-10 16:28:05 +00:00
|
|
|
writel(BCM2835_WDOG_PASSWORD | timeout, &wdog_regs->wdog);
|
2016-11-02 09:36:18 +00:00
|
|
|
writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc);
|
|
|
|
}
|
|
|
|
|
2020-12-15 15:47:52 +00:00
|
|
|
void reset_cpu(void)
|
2019-11-19 15:01:03 +00:00
|
|
|
{
|
|
|
|
struct bcm2835_wdog_regs *regs =
|
|
|
|
(struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
|
|
|
|
|
|
|
|
__reset_cpu(regs, 0);
|
|
|
|
}
|
|
|
|
|
2016-11-02 09:36:18 +00:00
|
|
|
#ifdef CONFIG_EFI_LOADER
|
|
|
|
|
|
|
|
void __efi_runtime EFIAPI efi_reset_system(
|
|
|
|
enum efi_reset_type reset_type,
|
|
|
|
efi_status_t reset_status,
|
|
|
|
unsigned long data_size, void *reset_data)
|
|
|
|
{
|
|
|
|
u32 val;
|
|
|
|
|
2018-06-10 19:51:02 +00:00
|
|
|
if (reset_type == EFI_RESET_COLD ||
|
|
|
|
reset_type == EFI_RESET_WARM ||
|
|
|
|
reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
|
2019-11-19 15:01:03 +00:00
|
|
|
__reset_cpu(wdog_regs, 0);
|
2018-06-10 19:51:02 +00:00
|
|
|
} else if (reset_type == EFI_RESET_SHUTDOWN) {
|
2016-11-02 09:36:18 +00:00
|
|
|
/*
|
|
|
|
* We set the watchdog hard reset bit here to distinguish this reset
|
|
|
|
* from the normal (full) reset. bootcode.bin will not reboot after a
|
|
|
|
* hard reset.
|
|
|
|
*/
|
|
|
|
val = readl(&wdog_regs->rsts);
|
|
|
|
val |= BCM2835_WDOG_PASSWORD;
|
|
|
|
val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT;
|
|
|
|
writel(val, &wdog_regs->rsts);
|
2019-11-19 15:01:03 +00:00
|
|
|
__reset_cpu(wdog_regs, 0);
|
2016-11-02 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) { }
|
2012-08-05 16:07:21 +00:00
|
|
|
}
|
2016-11-02 09:36:18 +00:00
|
|
|
|
2018-03-03 14:28:59 +00:00
|
|
|
efi_status_t efi_reset_system_init(void)
|
2016-11-02 09:36:18 +00:00
|
|
|
{
|
2019-11-19 15:01:03 +00:00
|
|
|
wdog_regs = (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
|
2018-03-03 14:28:59 +00:00
|
|
|
return efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs));
|
2016-11-02 09:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|