blob: 64187fb48b4b07fb0384687445fea23565ee8fb9 [file] [log] [blame]
Konstantin Porotchkinf69ec582018-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
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008#include <common/debug.h>
9#include <common/runtime_svc.h>
10#include <drivers/marvell/cache_llc.h>
11#include <drivers/marvell/mochi/ap_setup.h>
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030012#include <drivers/rambus/trng_ip_76.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <lib/smccc.h>
14
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030015#include <marvell_plat_priv.h>
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +010016#include <plat_marvell.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030018#include "comphy/phy-comphy-cp110.h"
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020019#include <stdbool.h>
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030020
21/* #define DEBUG_COMPHY */
22#ifdef DEBUG_COMPHY
23#define debug(format...) NOTICE(format)
24#else
25#define debug(format, arg...)
26#endif
27
28/* Comphy related FID's */
29#define MV_SIP_COMPHY_POWER_ON 0x82000001
30#define MV_SIP_COMPHY_POWER_OFF 0x82000002
31#define MV_SIP_COMPHY_PLL_LOCK 0x82000003
32#define MV_SIP_COMPHY_XFI_TRAIN 0x82000004
33#define MV_SIP_COMPHY_DIG_RESET 0x82000005
34
35/* Miscellaneous FID's' */
36#define MV_SIP_DRAM_SIZE 0x82000010
37#define MV_SIP_LLC_ENABLE 0x82000011
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +010038#define MV_SIP_PMU_IRQ_ENABLE 0x82000012
39#define MV_SIP_PMU_IRQ_DISABLE 0x82000013
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030040
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030041/* TRNG */
42#define MV_SIP_RNG_64 0xC200FF11
43
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030044#define MAX_LANE_NR 6
45#define MVEBU_COMPHY_OFFSET 0x441000
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020046#define MVEBU_CP_BASE_MASK (~0xffffff)
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030047
48/* This macro is used to identify COMPHY related calls from SMC function ID */
49#define is_comphy_fid(fid) \
50 ((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_DIG_RESET)
51
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020052_Bool is_cp_range_valid(u_register_t *addr)
53{
54 int cp_nr;
55
56 *addr &= MVEBU_CP_BASE_MASK;
57 for (cp_nr = 0; cp_nr < CP_NUM; cp_nr++) {
58 if (*addr == MVEBU_CP_REGS_BASE(cp_nr))
59 return true;
60 }
61
62 return false;
63}
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030064
65uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid,
66 u_register_t x1,
67 u_register_t x2,
68 u_register_t x3,
69 u_register_t x4,
70 void *cookie,
71 void *handle,
72 u_register_t flags)
73{
74 u_register_t ret;
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +030075 uint32_t w2[2] = {0, 0};
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030076 int i;
77
78 debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n",
79 __func__, smc_fid, x1, x2, x3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030080
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020081 if (is_comphy_fid(smc_fid)) {
82 /* validate address passed via x1 */
83 if (!is_cp_range_valid(&x1)) {
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030084 ERROR("%s: Wrong smc (0x%x) address: %lx\n",
85 __func__, smc_fid, x1);
86 SMC_RET1(handle, SMC_UNK);
87 }
88
Grzegorz Jaszczyk0988f382019-04-04 17:16:39 +020089 x1 += MVEBU_COMPHY_OFFSET;
90
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030091 if (x2 >= MAX_LANE_NR) {
92 ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n",
93 __func__, smc_fid, x2);
94 SMC_RET1(handle, SMC_UNK);
95 }
96 }
97
98 switch (smc_fid) {
99
100 /* Comphy related FID's */
101 case MV_SIP_COMPHY_POWER_ON:
102 /* x1: comphy_base, x2: comphy_index, x3: comphy_mode */
103 ret = mvebu_cp110_comphy_power_on(x1, x2, x3);
104 SMC_RET1(handle, ret);
105 case MV_SIP_COMPHY_POWER_OFF:
106 /* x1: comphy_base, x2: comphy_index */
Igal Libermanbd51efd2018-11-15 16:13:11 +0200107 ret = mvebu_cp110_comphy_power_off(x1, x2, x3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300108 SMC_RET1(handle, ret);
109 case MV_SIP_COMPHY_PLL_LOCK:
110 /* x1: comphy_base, x2: comphy_index */
111 ret = mvebu_cp110_comphy_is_pll_locked(x1, x2);
112 SMC_RET1(handle, ret);
113 case MV_SIP_COMPHY_XFI_TRAIN:
114 /* x1: comphy_base, x2: comphy_index */
115 ret = mvebu_cp110_comphy_xfi_rx_training(x1, x2);
116 SMC_RET1(handle, ret);
117 case MV_SIP_COMPHY_DIG_RESET:
118 /* x1: comphy_base, x2: comphy_index, x3: mode, x4: command */
119 ret = mvebu_cp110_comphy_digital_reset(x1, x2, x3, x4);
120 SMC_RET1(handle, ret);
121
122 /* Miscellaneous FID's' */
123 case MV_SIP_DRAM_SIZE:
Grzegorz Jaszczyk5339f6f2019-04-04 17:20:05 +0200124 ret = mvebu_get_dram_size(MVEBU_REGS_BASE);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300125 SMC_RET1(handle, ret);
126 case MV_SIP_LLC_ENABLE:
127 for (i = 0; i < ap_get_count(); i++)
128 llc_runtime_enable(i);
129
130 SMC_RET1(handle, 0);
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +0100131#ifdef MVEBU_PMU_IRQ_WA
132 case MV_SIP_PMU_IRQ_ENABLE:
133 mvebu_pmu_interrupt_enable();
134 SMC_RET1(handle, 0);
135 case MV_SIP_PMU_IRQ_DISABLE:
136 mvebu_pmu_interrupt_disable();
137 SMC_RET1(handle, 0);
138#endif
Konstantin Porotchkin7b9e4d42020-07-26 17:49:54 +0300139 case MV_SIP_RNG_64:
140 ret = eip76_rng_get_random((uint8_t *)&w2, 4 * (x1 % 2 + 1));
141 SMC_RET3(handle, ret, w2[0], w2[1]);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300142 default:
143 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
144 SMC_RET1(handle, SMC_UNK);
145 }
146}
147
148/* Define a runtime service descriptor for fast SMC calls */
149DECLARE_RT_SVC(
150 marvell_sip_svc,
151 OEN_SIP_START,
152 OEN_SIP_END,
153 SMC_TYPE_FAST,
154 NULL,
155 mrvl_sip_smc_handler
156);