reset.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * (C) Copyright 2012 Stephen Warren
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0
  8. */
  9. #include <common.h>
  10. #include <asm/io.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. __efi_runtime_data struct bcm2835_wdog_regs *wdog_regs =
  21. (struct bcm2835_wdog_regs *)BCM2835_WDOG_PHYSADDR;
  22. void __efi_runtime reset_cpu(ulong addr)
  23. {
  24. uint32_t rstc;
  25. rstc = readl(&wdog_regs->rstc);
  26. rstc &= ~BCM2835_WDOG_RSTC_WRCFG_MASK;
  27. rstc |= BCM2835_WDOG_RSTC_WRCFG_FULL_RESET;
  28. writel(BCM2835_WDOG_PASSWORD | RESET_TIMEOUT, &wdog_regs->wdog);
  29. writel(BCM2835_WDOG_PASSWORD | rstc, &wdog_regs->rstc);
  30. }
  31. #ifdef CONFIG_EFI_LOADER
  32. void __efi_runtime EFIAPI efi_reset_system(
  33. enum efi_reset_type reset_type,
  34. efi_status_t reset_status,
  35. unsigned long data_size, void *reset_data)
  36. {
  37. u32 val;
  38. switch (reset_type) {
  39. case EFI_RESET_COLD:
  40. case EFI_RESET_WARM:
  41. reset_cpu(0);
  42. break;
  43. case EFI_RESET_SHUTDOWN:
  44. /*
  45. * We set the watchdog hard reset bit here to distinguish this reset
  46. * from the normal (full) reset. bootcode.bin will not reboot after a
  47. * hard reset.
  48. */
  49. val = readl(&wdog_regs->rsts);
  50. val |= BCM2835_WDOG_PASSWORD;
  51. val |= BCM2835_WDOG_RSTS_RASPBERRYPI_HALT;
  52. writel(val, &wdog_regs->rsts);
  53. reset_cpu(0);
  54. break;
  55. }
  56. while (1) { }
  57. }
  58. void efi_reset_system_init(void)
  59. {
  60. efi_add_runtime_mmio(&wdog_regs, sizeof(*wdog_regs));
  61. }
  62. #endif