1 /*
2 * Copyright (c) 2020, Allwinner Technology, Inc.
3 * Author: Fan Qinghua <fanqinghua@allwinnertech.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 */
14 #ifndef __SUNXI_SIP_H
15 #define __SUNXI_SIP_H
16
17 #include <linux/arm-smccc.h>
18
19 #define SET_ROOT_WAKEUP_SOURCE(root_irq) (root_irq)
20 #define SET_SEC_WAKEUP_SOURCE(root_irq, secondary_irq) \
21 ((1 << 30) | ((secondary_irq) << 10) | (root_irq))
22 #define SET_THIRD_WAKEUP_SOURCE(root_irq, secondary_irq, third_irq) \
23 ((2 << 30) | ((third_irq) << 20) ((secondary_irq) << 10) | (root_irq))
24 #define SET_WAKEUP_TIME_MS(ms) ((3 << 30) | (ms))
25
26 #ifdef CONFIG_ARM
27 #ifdef CONFIG_ARCH_SUN50I
28 #define ARM_SVC_BASE (0x80000000)
29 #else
30 #define ARM_SVC_BASE \
31 ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32, \
32 ARM_SMCCC_OWNER_OEM, 0)
33 #endif
34 #endif
35
36 #ifdef CONFIG_ARM64
37 #define ARM_SVC_BASE (0xc0000000)
38 #endif
39
40 #define SUNXI_BASE (0x10)
41 #define CLEAR_WAKEUP_SRC_REQ (SUNXI_BASE + 0x15)
42 #define SET_WAKEUP_SRC_REQ (SUNXI_BASE + 0x16)
43 #define SET_DEBUG_DRAM_CRC_PARAS_REQ (SUNXI_BASE + 0x54)
44 #define SUNXI_CRASHDUMP (SUNXI_BASE + 0x85)
45
46 #define CLEAR_WAKEUP_SRC (ARM_SVC_BASE + CLEAR_WAKEUP_SRC_REQ)
47 #define SET_WAKEUP_SRC (ARM_SVC_BASE + SET_WAKEUP_SRC_REQ)
48 #define SET_DEBUG_DRAM_CRC_PARAS (ARM_SVC_BASE + SET_DEBUG_DRAM_CRC_PARAS_REQ)
49 #define ARM_SVC_SUNXI_CRASHDUMP_START (ARM_SVC_BASE + SUNXI_CRASHDUMP)
50
51 #if defined(CONFIG_ARM)
invoke_scp_fn_smc(u32 function_id,u32 arg1,u32 arg2,u32 arg3)52 static inline int invoke_scp_fn_smc(u32 function_id, u32 arg1, u32 arg2, u32 arg3)
53 {
54 struct arm_smccc_res res;
55
56 arm_smccc_smc(function_id, arg1, arg2, arg3, 0, 0, 0, 0, &res);
57 return res.a0;
58 }
59 #elif defined(CONFIG_ARM64)
invoke_scp_fn_smc(u64 function_id,u64 arg1,u64 arg2,u64 arg3)60 static inline int invoke_scp_fn_smc(u64 function_id, u64 arg1, u64 arg2, u64 arg3)
61 {
62 struct arm_smccc_res res;
63
64 arm_smccc_smc(function_id, arg1, arg2, arg3, 0, 0, 0, 0, &res);
65 return res.a0;
66 }
67 #endif
68
69 #endif
70