blob: df211059b9d692b19f964fa0ff4c7bfd9212ffed [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>
12#include <lib/smccc.h>
13
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030014#include <marvell_plat_priv.h>
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +010015#include <plat_marvell.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030017#include "comphy/phy-comphy-cp110.h"
18
19/* #define DEBUG_COMPHY */
20#ifdef DEBUG_COMPHY
21#define debug(format...) NOTICE(format)
22#else
23#define debug(format, arg...)
24#endif
25
26/* Comphy related FID's */
27#define MV_SIP_COMPHY_POWER_ON 0x82000001
28#define MV_SIP_COMPHY_POWER_OFF 0x82000002
29#define MV_SIP_COMPHY_PLL_LOCK 0x82000003
30#define MV_SIP_COMPHY_XFI_TRAIN 0x82000004
31#define MV_SIP_COMPHY_DIG_RESET 0x82000005
32
33/* Miscellaneous FID's' */
34#define MV_SIP_DRAM_SIZE 0x82000010
35#define MV_SIP_LLC_ENABLE 0x82000011
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +010036#define MV_SIP_PMU_IRQ_ENABLE 0x82000012
37#define MV_SIP_PMU_IRQ_DISABLE 0x82000013
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030038
39#define MAX_LANE_NR 6
40#define MVEBU_COMPHY_OFFSET 0x441000
41#define MVEBU_SD_OFFSET 0x120000
42
43/* This macro is used to identify COMPHY related calls from SMC function ID */
44#define is_comphy_fid(fid) \
45 ((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_DIG_RESET)
46
47
48uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid,
49 u_register_t x1,
50 u_register_t x2,
51 u_register_t x3,
52 u_register_t x4,
53 void *cookie,
54 void *handle,
55 u_register_t flags)
56{
57 u_register_t ret;
58 int i;
59
60 debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n",
61 __func__, smc_fid, x1, x2, x3);
62 if (is_comphy_fid(smc_fid)) {
63
64 /* some systems passes SD phys address instead of COMPHY phys
65 * address - convert it
66 */
67 if (x1 & MVEBU_SD_OFFSET)
68 x1 = (x1 & ~0xffffff) + MVEBU_COMPHY_OFFSET;
69
70 if ((x1 & 0xffffff) != MVEBU_COMPHY_OFFSET) {
71 ERROR("%s: Wrong smc (0x%x) address: %lx\n",
72 __func__, smc_fid, x1);
73 SMC_RET1(handle, SMC_UNK);
74 }
75
76 if (x2 >= MAX_LANE_NR) {
77 ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n",
78 __func__, smc_fid, x2);
79 SMC_RET1(handle, SMC_UNK);
80 }
81 }
82
83 switch (smc_fid) {
84
85 /* Comphy related FID's */
86 case MV_SIP_COMPHY_POWER_ON:
87 /* x1: comphy_base, x2: comphy_index, x3: comphy_mode */
88 ret = mvebu_cp110_comphy_power_on(x1, x2, x3);
89 SMC_RET1(handle, ret);
90 case MV_SIP_COMPHY_POWER_OFF:
91 /* x1: comphy_base, x2: comphy_index */
Igal Libermanbd51efd2018-11-15 16:13:11 +020092 ret = mvebu_cp110_comphy_power_off(x1, x2, x3);
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +030093 SMC_RET1(handle, ret);
94 case MV_SIP_COMPHY_PLL_LOCK:
95 /* x1: comphy_base, x2: comphy_index */
96 ret = mvebu_cp110_comphy_is_pll_locked(x1, x2);
97 SMC_RET1(handle, ret);
98 case MV_SIP_COMPHY_XFI_TRAIN:
99 /* x1: comphy_base, x2: comphy_index */
100 ret = mvebu_cp110_comphy_xfi_rx_training(x1, x2);
101 SMC_RET1(handle, ret);
102 case MV_SIP_COMPHY_DIG_RESET:
103 /* x1: comphy_base, x2: comphy_index, x3: mode, x4: command */
104 ret = mvebu_cp110_comphy_digital_reset(x1, x2, x3, x4);
105 SMC_RET1(handle, ret);
106
107 /* Miscellaneous FID's' */
108 case MV_SIP_DRAM_SIZE:
109 /* x1: ap_base_addr */
110 ret = mvebu_get_dram_size(x1);
111 SMC_RET1(handle, ret);
112 case MV_SIP_LLC_ENABLE:
113 for (i = 0; i < ap_get_count(); i++)
114 llc_runtime_enable(i);
115
116 SMC_RET1(handle, 0);
Marcin Wojtas0c60c2f2018-03-21 09:59:59 +0100117#ifdef MVEBU_PMU_IRQ_WA
118 case MV_SIP_PMU_IRQ_ENABLE:
119 mvebu_pmu_interrupt_enable();
120 SMC_RET1(handle, 0);
121 case MV_SIP_PMU_IRQ_DISABLE:
122 mvebu_pmu_interrupt_disable();
123 SMC_RET1(handle, 0);
124#endif
Konstantin Porotchkinf69ec582018-06-07 18:31:14 +0300125
126 default:
127 ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
128 SMC_RET1(handle, SMC_UNK);
129 }
130}
131
132/* Define a runtime service descriptor for fast SMC calls */
133DECLARE_RT_SVC(
134 marvell_sip_svc,
135 OEN_SIP_START,
136 OEN_SIP_END,
137 SMC_TYPE_FAST,
138 NULL,
139 mrvl_sip_smc_handler
140);