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