sunxi_native_pm.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2017-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch_helpers.h>
  7. #include <common/debug.h>
  8. #include <drivers/arm/gicv2.h>
  9. #include <drivers/delay_timer.h>
  10. #include <lib/mmio.h>
  11. #include <lib/psci/psci.h>
  12. #include <sunxi_mmap.h>
  13. #include <sunxi_private.h>
  14. #define SUNXI_WDOG0_CTRL_REG (SUNXI_R_WDOG_BASE + 0x0010)
  15. #define SUNXI_WDOG0_CFG_REG (SUNXI_R_WDOG_BASE + 0x0014)
  16. #define SUNXI_WDOG0_MODE_REG (SUNXI_R_WDOG_BASE + 0x0018)
  17. static int sunxi_pwr_domain_on(u_register_t mpidr)
  18. {
  19. sunxi_cpu_on(mpidr);
  20. return PSCI_E_SUCCESS;
  21. }
  22. static void sunxi_pwr_domain_off(const psci_power_state_t *target_state)
  23. {
  24. gicv2_cpuif_disable();
  25. sunxi_cpu_power_off_self();
  26. }
  27. static void sunxi_pwr_domain_on_finish(const psci_power_state_t *target_state)
  28. {
  29. gicv2_pcpu_distif_init();
  30. gicv2_cpuif_enable();
  31. }
  32. static void __dead2 sunxi_system_off(void)
  33. {
  34. gicv2_cpuif_disable();
  35. /* Attempt to power down the board (may not return) */
  36. sunxi_power_down();
  37. /* Turn off all CPUs */
  38. sunxi_cpu_power_off_others();
  39. sunxi_cpu_power_off_self();
  40. psci_power_down_wfi();
  41. }
  42. static void __dead2 sunxi_system_reset(void)
  43. {
  44. gicv2_cpuif_disable();
  45. /* Reset the whole system when the watchdog times out */
  46. mmio_write_32(SUNXI_WDOG0_CFG_REG, 1);
  47. /* Enable the watchdog with the shortest timeout (0.5 seconds) */
  48. mmio_write_32(SUNXI_WDOG0_MODE_REG, (0 << 4) | 1);
  49. /* Wait for twice the watchdog timeout before panicking */
  50. mdelay(1000);
  51. ERROR("PSCI: System reset failed\n");
  52. panic();
  53. }
  54. static const plat_psci_ops_t sunxi_native_psci_ops = {
  55. .pwr_domain_on = sunxi_pwr_domain_on,
  56. .pwr_domain_off = sunxi_pwr_domain_off,
  57. .pwr_domain_on_finish = sunxi_pwr_domain_on_finish,
  58. .system_off = sunxi_system_off,
  59. .system_reset = sunxi_system_reset,
  60. .validate_ns_entrypoint = sunxi_validate_ns_entrypoint,
  61. };
  62. void sunxi_set_native_psci_ops(const plat_psci_ops_t **psci_ops)
  63. {
  64. *psci_ops = &sunxi_native_psci_ops;
  65. }