Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Stephen Warren |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/io.h> |
Matthias Brugger | 2c68dee | 2019-11-19 16:01:03 +0100 | [diff] [blame^] | 11 | #include <asm/arch/base.h> |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 12 | #include <asm/arch/wdog.h> |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 13 | #include <efi_loader.h> |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 14 | |
| 15 | #define RESET_TIMEOUT 10 |
| 16 | |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 17 | /* |
| 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. |
| 21 | */ |
| 22 | #define BCM2835_WDOG_RSTS_RASPBERRYPI_HALT 0x555 |
| 23 | |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 24 | /* max ticks timeout */ |
| 25 | #define BCM2835_WDOG_MAX_TIMEOUT 0x000fffff |
| 26 | |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 27 | void hw_watchdog_disable(void) {} |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 28 | |
Matthias Brugger | 2c68dee | 2019-11-19 16:01:03 +0100 | [diff] [blame^] | 29 | __efi_runtime_data struct bcm2835_wdog_regs *wdog_regs; |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 30 | |
Matthias Brugger | 2c68dee | 2019-11-19 16:01:03 +0100 | [diff] [blame^] | 31 | static void __efi_runtime |
| 32 | __reset_cpu(struct bcm2835_wdog_regs *wdog_regs, ulong ticks) |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 33 | { |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 34 | uint32_t rstc, timeout; |
| 35 | |
| 36 | if (ticks == 0) { |
| 37 | hw_watchdog_disable(); |
| 38 | timeout = RESET_TIMEOUT; |
| 39 | } else |
| 40 | timeout = ticks & BCM2835_WDOG_MAX_TIMEOUT; |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 41 | |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 42 | rstc = readl(&wdog_regs->rstc); |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 43 | rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK; |
| 44 | rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET; |
| 45 | |
Paolo Pisati | 6213c55 | 2017-02-10 17:28:05 +0100 | [diff] [blame] | 46 | writel(BCM2835_WDOG_PASSWORD | timeout, &wdog_regs->wdog); |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 47 | writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc); |
| 48 | } |
| 49 | |
Matthias Brugger | 2c68dee | 2019-11-19 16:01:03 +0100 | [diff] [blame^] | 50 | void reset_cpu(ulong ticks) |
| 51 | { |
| 52 | struct bcm2835_wdog_regs *regs = |
| 53 | (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR; |
| 54 | |
| 55 | __reset_cpu(regs, 0); |
| 56 | } |
| 57 | |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 58 | #ifdef CONFIG_EFI_LOADER |
| 59 | |
| 60 | void __efi_runtime EFIAPI efi_reset_system( |
| 61 | enum efi_reset_type reset_type, |
| 62 | efi_status_t reset_status, |
| 63 | unsigned long data_size, void *reset_data) |
| 64 | { |
| 65 | u32 val; |
| 66 | |
Alexander Graf | b7eefe4 | 2018-06-10 21:51:02 +0200 | [diff] [blame] | 67 | if (reset_type == EFI_RESET_COLD || |
| 68 | reset_type == EFI_RESET_WARM || |
| 69 | reset_type == EFI_RESET_PLATFORM_SPECIFIC) { |
Matthias Brugger | 2c68dee | 2019-11-19 16:01:03 +0100 | [diff] [blame^] | 70 | __reset_cpu(wdog_regs, 0); |
Alexander Graf | b7eefe4 | 2018-06-10 21:51:02 +0200 | [diff] [blame] | 71 | } else if (reset_type == EFI_RESET_SHUTDOWN) { |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 72 | /* |
| 73 | * We set the watchdog hard reset bit here to distinguish this reset |
| 74 | * from the normal (full) reset. bootcode.bin will not reboot after a |
| 75 | * hard reset. |
| 76 | */ |
| 77 | val = readl(&wdog_regs->rsts); |
| 78 | val |= BCM2835_WDOG_PASSWORD; |
| 79 | val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT; |
| 80 | writel(val, &wdog_regs->rsts); |
Matthias Brugger | 2c68dee | 2019-11-19 16:01:03 +0100 | [diff] [blame^] | 81 | __reset_cpu(wdog_regs, 0); |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | while (1) { } |
| 85 | } |
| 86 | |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 87 | efi_status_t efi_reset_system_init(void) |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 88 | { |
Matthias Brugger | 2c68dee | 2019-11-19 16:01:03 +0100 | [diff] [blame^] | 89 | wdog_regs = (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR; |
Heinrich Schuchardt | 099b3b7 | 2018-03-03 15:28:59 +0100 | [diff] [blame] | 90 | return efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs)); |
Stephen Warren | 45b8ae6 | 2012-08-05 16:07:21 +0000 | [diff] [blame] | 91 | } |
Alexander Graf | 3fce534 | 2016-11-02 10:36:18 +0100 | [diff] [blame] | 92 | |
| 93 | #endif |