xref: /rk3399_ARM-atf/plat/allwinner/common/sunxi_pm.c (revision 58032586f88980c03969e47bcc9a84b5abc788e2)
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 static void __dead2 sunxi_system_off(void)
22 {
23 	ERROR("PSCI: Full shutdown not implemented, halting\n");
24 	wfi();
25 	panic();
26 }
27 
28 static void __dead2 sunxi_system_reset(void)
29 {
30 	/* Reset the whole system when the watchdog times out */
31 	mmio_write_32(SUNXI_WDOG0_CFG_REG, 1);
32 	/* Enable the watchdog with the shortest timeout (0.5 seconds) */
33 	mmio_write_32(SUNXI_WDOG0_MODE_REG, (0 << 4) | 1);
34 	/* Wait for twice the watchdog timeout before panicking */
35 	mdelay(1000);
36 
37 	ERROR("PSCI: System reset failed\n");
38 	wfi();
39 	panic();
40 }
41 
42 static plat_psci_ops_t sunxi_psci_ops = {
43 	.system_off			= sunxi_system_off,
44 	.system_reset			= sunxi_system_reset,
45 };
46 
47 int plat_setup_psci_ops(uintptr_t sec_entrypoint,
48 			const plat_psci_ops_t **psci_ops)
49 {
50 	assert(psci_ops);
51 
52 	*psci_ops = &sunxi_psci_ops;
53 
54 	return 0;
55 }
56