1 /* 2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch_helpers.h> 8 #include <assert.h> 9 #include <debug.h> 10 #include <delay_timer.h> 11 #include <mmio.h> 12 #include <platform.h> 13 #include <platform_def.h> 14 #include <psci.h> 15 #include <sunxi_mmap.h> 16 17 #define SUNXI_WDOG0_CTRL_REG (SUNXI_WDOG_BASE + 0x0010) 18 #define SUNXI_WDOG0_CFG_REG (SUNXI_WDOG_BASE + 0x0014) 19 #define SUNXI_WDOG0_MODE_REG (SUNXI_WDOG_BASE + 0x0018) 20 21 #include "sunxi_private.h" 22 23 static void __dead2 sunxi_system_off(void) 24 { 25 /* Turn off all secondary CPUs */ 26 sunxi_disable_secondary_cpus(plat_my_core_pos()); 27 28 ERROR("PSCI: Full shutdown not implemented, halting\n"); 29 wfi(); 30 panic(); 31 } 32 33 static void __dead2 sunxi_system_reset(void) 34 { 35 /* Reset the whole system when the watchdog times out */ 36 mmio_write_32(SUNXI_WDOG0_CFG_REG, 1); 37 /* Enable the watchdog with the shortest timeout (0.5 seconds) */ 38 mmio_write_32(SUNXI_WDOG0_MODE_REG, (0 << 4) | 1); 39 /* Wait for twice the watchdog timeout before panicking */ 40 mdelay(1000); 41 42 ERROR("PSCI: System reset failed\n"); 43 wfi(); 44 panic(); 45 } 46 47 static plat_psci_ops_t sunxi_psci_ops = { 48 .system_off = sunxi_system_off, 49 .system_reset = sunxi_system_reset, 50 }; 51 52 int plat_setup_psci_ops(uintptr_t sec_entrypoint, 53 const plat_psci_ops_t **psci_ops) 54 { 55 assert(psci_ops); 56 57 *psci_ops = &sunxi_psci_ops; 58 59 return 0; 60 } 61