xref: /arm-trusted-firmware/plat/marvell/armada/a3k/common/a3700_sip_svc.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (C) 2018 Marvell International Ltd.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier:     BSD-3-Clause
5*91f16700Schasinglulu  * https://spdx.org/licenses
6*91f16700Schasinglulu  */
7*91f16700Schasinglulu 
8*91f16700Schasinglulu #include <common/debug.h>
9*91f16700Schasinglulu #include <common/runtime_svc.h>
10*91f16700Schasinglulu #include <lib/smccc.h>
11*91f16700Schasinglulu 
12*91f16700Schasinglulu #include <marvell_plat_priv.h>
13*91f16700Schasinglulu #include <plat_marvell.h>
14*91f16700Schasinglulu 
15*91f16700Schasinglulu #include "comphy/phy-comphy-3700.h"
16*91f16700Schasinglulu 
17*91f16700Schasinglulu /* Comphy related FID's */
18*91f16700Schasinglulu #define MV_SIP_COMPHY_POWER_ON	0x82000001
19*91f16700Schasinglulu #define MV_SIP_COMPHY_POWER_OFF	0x82000002
20*91f16700Schasinglulu #define MV_SIP_COMPHY_PLL_LOCK	0x82000003
21*91f16700Schasinglulu 
22*91f16700Schasinglulu /* Miscellaneous FID's' */
23*91f16700Schasinglulu #define MV_SIP_DRAM_SIZE	0x82000010
24*91f16700Schasinglulu 
25*91f16700Schasinglulu /* This macro is used to identify COMPHY related calls from SMC function ID */
26*91f16700Schasinglulu #define is_comphy_fid(fid)	\
27*91f16700Schasinglulu 	((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_PLL_LOCK)
28*91f16700Schasinglulu 
29*91f16700Schasinglulu uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid,
30*91f16700Schasinglulu 			       u_register_t x1,
31*91f16700Schasinglulu 			       u_register_t x2,
32*91f16700Schasinglulu 			       u_register_t x3,
33*91f16700Schasinglulu 			       u_register_t x4,
34*91f16700Schasinglulu 			       void *cookie,
35*91f16700Schasinglulu 			       void *handle,
36*91f16700Schasinglulu 			       u_register_t flags)
37*91f16700Schasinglulu {
38*91f16700Schasinglulu 	u_register_t ret;
39*91f16700Schasinglulu 
40*91f16700Schasinglulu 	VERBOSE("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx\n",
41*91f16700Schasinglulu 		__func__, smc_fid, x1, x2);
42*91f16700Schasinglulu 	if (is_comphy_fid(smc_fid)) {
43*91f16700Schasinglulu 		if (x1 >= MAX_LANE_NR) {
44*91f16700Schasinglulu 			ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n",
45*91f16700Schasinglulu 			      __func__, smc_fid, x2);
46*91f16700Schasinglulu 			SMC_RET1(handle, SMC_UNK);
47*91f16700Schasinglulu 		}
48*91f16700Schasinglulu 	}
49*91f16700Schasinglulu 
50*91f16700Schasinglulu 	switch (smc_fid) {
51*91f16700Schasinglulu 	/* Comphy related FID's */
52*91f16700Schasinglulu 	case MV_SIP_COMPHY_POWER_ON:
53*91f16700Schasinglulu 		/* x1: comphy_index, x2: comphy_mode */
54*91f16700Schasinglulu 		ret = mvebu_3700_comphy_power_on(x1, x2);
55*91f16700Schasinglulu 		SMC_RET1(handle, ret);
56*91f16700Schasinglulu 	case MV_SIP_COMPHY_POWER_OFF:
57*91f16700Schasinglulu 		/* x1: comphy_index, x2: comphy_mode */
58*91f16700Schasinglulu 		ret = mvebu_3700_comphy_power_off(x1, x2);
59*91f16700Schasinglulu 		SMC_RET1(handle, ret);
60*91f16700Schasinglulu 	case MV_SIP_COMPHY_PLL_LOCK:
61*91f16700Schasinglulu 		/* x1: comphy_index, x2: comphy_mode */
62*91f16700Schasinglulu 		ret = mvebu_3700_comphy_is_pll_locked(x1, x2);
63*91f16700Schasinglulu 		SMC_RET1(handle, ret);
64*91f16700Schasinglulu 	/* Miscellaneous FID's' */
65*91f16700Schasinglulu 	case MV_SIP_DRAM_SIZE:
66*91f16700Schasinglulu 		/* x1:  ap_base_addr */
67*91f16700Schasinglulu 		ret = mvebu_get_dram_size(MVEBU_REGS_BASE);
68*91f16700Schasinglulu 		SMC_RET1(handle, ret);
69*91f16700Schasinglulu 
70*91f16700Schasinglulu 	default:
71*91f16700Schasinglulu 		ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
72*91f16700Schasinglulu 		SMC_RET1(handle, SMC_UNK);
73*91f16700Schasinglulu 	}
74*91f16700Schasinglulu }
75*91f16700Schasinglulu 
76*91f16700Schasinglulu /* Define a runtime service descriptor for fast SMC calls */
77*91f16700Schasinglulu DECLARE_RT_SVC(
78*91f16700Schasinglulu 	marvell_sip_svc,
79*91f16700Schasinglulu 	OEN_SIP_START,
80*91f16700Schasinglulu 	OEN_SIP_END,
81*91f16700Schasinglulu 	SMC_TYPE_FAST,
82*91f16700Schasinglulu 	NULL,
83*91f16700Schasinglulu 	mrvl_sip_smc_handler
84*91f16700Schasinglulu );
85