blob: a0ca50d0a7c0b9808000338d193a0df2ac1f177d [file] [log] [blame]
Konstantin Porotchkin486f8682018-06-07 18:31:14 +03001/*
2 * Copyright (C) 2018 Marvell International Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 * https://spdx.org/licenses
6 */
7
8#include <ap_setup.h>
9#include <cache_llc.h>
10#include <debug.h>
11#include <marvell_plat_priv.h>
Marcin Wojtasfd1718a2018-03-21 09:59:59 +010012#include <plat_marvell.h>
Konstantin Porotchkin486f8682018-06-07 18:31:14 +030013#include <runtime_svc.h>
14#include <smcc.h>
15#include "comphy/phy-comphy-cp110.h"
16
17/* #define DEBUG_COMPHY */
18#ifdef DEBUG_COMPHY
19#define debug(format...) NOTICE(format)
20#else
21#define debug(format, arg...)
22#endif
23
24/* Comphy related FID's */
25#define MV_SIP_COMPHY_POWER_ON 0x82000001
26#define MV_SIP_COMPHY_POWER_OFF 0x82000002
27#define MV_SIP_COMPHY_PLL_LOCK 0x82000003
28#define MV_SIP_COMPHY_XFI_TRAIN 0x82000004
29#define MV_SIP_COMPHY_DIG_RESET 0x82000005
30
31/* Miscellaneous FID's' */
32#define MV_SIP_DRAM_SIZE 0x82000010
33#define MV_SIP_LLC_ENABLE 0x82000011
Marcin Wojtasfd1718a2018-03-21 09:59:59 +010034#define MV_SIP_PMU_IRQ_ENABLE 0x82000012
35#define MV_SIP_PMU_IRQ_DISABLE 0x82000013
Konstantin Porotchkin486f8682018-06-07 18:31:14 +030036
37#define MAX_LANE_NR 6
38#define MVEBU_COMPHY_OFFSET 0x441000
39#define MVEBU_SD_OFFSET 0x120000
40
41/* This macro is used to identify COMPHY related calls from SMC function ID */
42#define is_comphy_fid(fid) \
43 ((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_DIG_RESET)
44
45
46uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid,
47 u_register_t x1,
48 u_register_t x2,
49 u_register_t x3,
50 u_register_t x4,
51 void *cookie,
52 void *handle,
53 u_register_t flags)
54{
55 u_register_t ret;
56 int i;
57
58 debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n",
59 __func__, smc_fid, x1, x2, x3);
60 if (is_comphy_fid(smc_fid)) {
61
62 /* some systems passes SD phys address instead of COMPHY phys
63 * address - convert it
64 */
65 if (x1 & MVEBU_SD_OFFSET)
66 x1 = (x1 & ~0xffffff) + MVEBU_COMPHY_OFFSET;
67
68 if ((x1 & 0xffffff) != MVEBU_COMPHY_OFFSET) {
69 ERROR("%s: Wrong smc (0x%x) address: %lx\n",
70 __func__, smc_fid, x1);
71 SMC_RET1(handle, SMC_UNK);
72 }
73
74 if (x2 >= MAX_LANE_NR) {
75 ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n",
76 __func__, smc_fid, x2);
77 SMC_RET1(handle, SMC_UNK);
78 }
79 }
80
81 switch (smc_fid) {
82
83 /* Comphy related FID's */
84 case MV_SIP_COMPHY_POWER_ON:
85 /* x1: comphy_base, x2: comphy_index, x3: comphy_mode */
86 ret = mvebu_cp110_comphy_power_on(x1, x2, x3);
87 SMC_RET1(handle, ret);
88 case MV_SIP_COMPHY_POWER_OFF:
89 /* x1: comphy_base, x2: comphy_index */
90 ret = mvebu_cp110_comphy_power_off(x1, x2);
91 SMC_RET1(handle, ret);
92 case MV_SIP_COMPHY_PLL_LOCK:
93 /* x1: comphy_base, x2: comphy_index */
94 ret = mvebu_cp110_comphy_is_pll_locked(x1, x2);
95 SMC_RET1(handle, ret);
96 case MV_SIP_COMPHY_XFI_TRAIN:
97 /* x1: comphy_base, x2: comphy_index */
98 ret = mvebu_cp110_comphy_xfi_rx_training(x1, x2);
99 SMC_RET1(handle, ret);
100 case MV_SIP_COMPHY_DIG_RESET:
101 /* x1: comphy_base, x2: comphy_index, x3: mode, x4: command */
102 ret = mvebu_cp110_comphy_digital_reset(x1, x2, x3, x4);
103 SMC_RET1(handle, ret);
104
105 /* Miscellaneous FID's' */
106 case MV_SIP_DRAM_SIZE:
107 /* x1: ap_base_addr */
108 ret = mvebu_get_dram_size(x1);
109 SMC_RET1(handle, ret);
110 case MV_SIP_LLC_ENABLE:
111 for (i = 0; i < ap_get_count(); i++)
112 llc_runtime_enable(i);
113
114 SMC_RET1(handle, 0);
Marcin Wojtasfd1718a2018-03-21 09:59:59 +0100115#ifdef MVEBU_PMU_IRQ_WA
116 case MV_SIP_PMU_IRQ_ENABLE:
117 mvebu_pmu_interrupt_enable();
118 SMC_RET1(handle, 0);
119 case MV_SIP_PMU_IRQ_DISABLE:
120 mvebu_pmu_interrupt_disable();
121 SMC_RET1(handle, 0);
122#endif
Konstantin Porotchkin486f8682018-06-07 18:31:14 +0300123
124 default:
125 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
126 SMC_RET1(handle, SMC_UNK);
127 }
128}
129
130/* Define a runtime service descriptor for fast SMC calls */
131DECLARE_RT_SVC(
132 marvell_sip_svc,
133 OEN_SIP_START,
134 OEN_SIP_END,
135 SMC_TYPE_FAST,
136 NULL,
137 mrvl_sip_smc_handler
138);