blob: 1dc7ce50d1d3f76612a6eddfe632e667b4f39d57 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren45b8ae62012-08-05 16:07:21 +00002/*
3 * (C) Copyright 2012 Stephen Warren
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
Stephen Warren45b8ae62012-08-05 16:07:21 +00007 */
8
Tom Rinidec7ea02024-05-20 13:35:03 -06009#include <config.h>
Simon Glassafb02152019-12-28 10:45:01 -070010#include <cpu_func.h>
Stephen Warren45b8ae62012-08-05 16:07:21 +000011#include <asm/io.h>
Matthias Brugger2c68dee2019-11-19 16:01:03 +010012#include <asm/arch/base.h>
Stephen Warren45b8ae62012-08-05 16:07:21 +000013#include <asm/arch/wdog.h>
Alexander Graf3fce5342016-11-02 10:36:18 +010014#include <efi_loader.h>
Stephen Warren45b8ae62012-08-05 16:07:21 +000015
16#define RESET_TIMEOUT 10
17
Alexander Graf3fce5342016-11-02 10:36:18 +010018/*
19 * The Raspberry Pi firmware uses the RSTS register to know which partiton
20 * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
21 * Partiton 63 is a special partition used by the firmware to indicate halt.
22 */
23#define BCM2835_WDOG_RSTS_RASPBERRYPI_HALT 0x555
24
Paolo Pisati6213c552017-02-10 17:28:05 +010025/* max ticks timeout */
26#define BCM2835_WDOG_MAX_TIMEOUT 0x000fffff
27
Matthias Brugger2c68dee2019-11-19 16:01:03 +010028__efi_runtime_data struct bcm2835_wdog_regs *wdog_regs;
Alexander Graf3fce5342016-11-02 10:36:18 +010029
Matthias Brugger2c68dee2019-11-19 16:01:03 +010030static void __efi_runtime
31__reset_cpu(struct bcm2835_wdog_regs *wdog_regs, ulong ticks)
Stephen Warren45b8ae62012-08-05 16:07:21 +000032{
Paolo Pisati6213c552017-02-10 17:28:05 +010033 uint32_t rstc, timeout;
34
Rasmus Villemoesa7ca1c12024-07-12 11:07:24 +020035 if (ticks == 0)
Paolo Pisati6213c552017-02-10 17:28:05 +010036 timeout = RESET_TIMEOUT;
Rasmus Villemoesa7ca1c12024-07-12 11:07:24 +020037 else
Paolo Pisati6213c552017-02-10 17:28:05 +010038 timeout = ticks & BCM2835_WDOG_MAX_TIMEOUT;
Stephen Warren45b8ae62012-08-05 16:07:21 +000039
Alexander Graf3fce5342016-11-02 10:36:18 +010040 rstc = readl(&wdog_regs->rstc);
Stephen Warren45b8ae62012-08-05 16:07:21 +000041 rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK;
42 rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET;
43
Paolo Pisati6213c552017-02-10 17:28:05 +010044 writel(BCM2835_WDOG_PASSWORD | timeout, &wdog_regs->wdog);
Alexander Graf3fce5342016-11-02 10:36:18 +010045 writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc);
46}
47
Harald Seiler6f14d5f2020-12-15 16:47:52 +010048void reset_cpu(void)
Matthias Brugger2c68dee2019-11-19 16:01:03 +010049{
50 struct bcm2835_wdog_regs *regs =
51 (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
52
53 __reset_cpu(regs, 0);
54}
55
Alexander Graf3fce5342016-11-02 10:36:18 +010056#ifdef CONFIG_EFI_LOADER
57
58void __efi_runtime EFIAPI efi_reset_system(
59 enum efi_reset_type reset_type,
60 efi_status_t reset_status,
61 unsigned long data_size, void *reset_data)
62{
63 u32 val;
64
Alexander Grafb7eefe42018-06-10 21:51:02 +020065 if (reset_type == EFI_RESET_COLD ||
66 reset_type == EFI_RESET_WARM ||
67 reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
Matthias Brugger2c68dee2019-11-19 16:01:03 +010068 __reset_cpu(wdog_regs, 0);
Alexander Grafb7eefe42018-06-10 21:51:02 +020069 } else if (reset_type == EFI_RESET_SHUTDOWN) {
Alexander Graf3fce5342016-11-02 10:36:18 +010070 /*
71 * We set the watchdog hard reset bit here to distinguish this reset
72 * from the normal (full) reset. bootcode.bin will not reboot after a
73 * hard reset.
74 */
75 val = readl(&wdog_regs->rsts);
76 val |= BCM2835_WDOG_PASSWORD;
77 val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT;
78 writel(val, &wdog_regs->rsts);
Matthias Brugger2c68dee2019-11-19 16:01:03 +010079 __reset_cpu(wdog_regs, 0);
Alexander Graf3fce5342016-11-02 10:36:18 +010080 }
81
82 while (1) { }
83}
84
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +010085efi_status_t efi_reset_system_init(void)
Alexander Graf3fce5342016-11-02 10:36:18 +010086{
Matthias Brugger2c68dee2019-11-19 16:01:03 +010087 wdog_regs = (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
Heinrich Schuchardt099b3b72018-03-03 15:28:59 +010088 return efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs));
Stephen Warren45b8ae62012-08-05 16:07:21 +000089}
Alexander Graf3fce5342016-11-02 10:36:18 +010090
91#endif