reset.c 2.3 KB

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