reset.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * (C) Copyright 2012 Stephen Warren
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. */
  8. #include <common.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/base.h>
  11. #include <asm/arch/wdog.h>
  12. #include <efi_loader.h>
  13. #define RESET_TIMEOUT 10
  14. /*
  15. * The Raspberry Pi firmware uses the RSTS register to know which partiton
  16. * to boot from. The partiton value is spread into bits 0, 2, 4, 6, 8, 10.
  17. * Partiton 63 is a special partition used by the firmware to indicate halt.
  18. */
  19. #define BCM2835_WDOG_RSTS_RASPBERRYPI_HALT 0x555
  20. /* max ticks timeout */
  21. #define BCM2835_WDOG_MAX_TIMEOUT 0x000fffff
  22. void hw_watchdog_disable(void) {}
  23. __efi_runtime_data struct bcm2835_wdog_regs *wdog_regs;
  24. static void __efi_runtime
  25. __reset_cpu(struct bcm2835_wdog_regs *wdog_regs, ulong ticks)
  26. {
  27. uint32_t rstc, timeout;
  28. if (ticks == 0) {
  29. hw_watchdog_disable();
  30. timeout = RESET_TIMEOUT;
  31. } else
  32. timeout = ticks & BCM2835_WDOG_MAX_TIMEOUT;
  33. rstc = readl(&wdog_regs->rstc);
  34. rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK;
  35. rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET;
  36. writel(BCM2835_WDOG_PASSWORD | timeout, &wdog_regs->wdog);
  37. writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc);
  38. }
  39. void reset_cpu(ulong ticks)
  40. {
  41. struct bcm2835_wdog_regs *regs =
  42. (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
  43. __reset_cpu(regs, 0);
  44. }
  45. #ifdef CONFIG_EFI_LOADER
  46. void __efi_runtime EFIAPI efi_reset_system(
  47. enum efi_reset_type reset_type,
  48. efi_status_t reset_status,
  49. unsigned long data_size, void *reset_data)
  50. {
  51. u32 val;
  52. if (reset_type == EFI_RESET_COLD ||
  53. reset_type == EFI_RESET_WARM ||
  54. reset_type == EFI_RESET_PLATFORM_SPECIFIC) {
  55. __reset_cpu(wdog_regs, 0);
  56. } else if (reset_type == EFI_RESET_SHUTDOWN) {
  57. /*
  58. * We set the watchdog hard reset bit here to distinguish this reset
  59. * from the normal (full) reset. bootcode.bin will not reboot after a
  60. * hard reset.
  61. */
  62. val = readl(&wdog_regs->rsts);
  63. val |= BCM2835_WDOG_PASSWORD;
  64. val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT;
  65. writel(val, &wdog_regs->rsts);
  66. __reset_cpu(wdog_regs, 0);
  67. }
  68. while (1) { }
  69. }
  70. efi_status_t efi_reset_system_init(void)
  71. {
  72. wdog_regs = (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
  73. return efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs));
  74. }
  75. #endif