Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 Marvell International Ltd. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * https://spdx.org/licenses |
| 6 | */ |
| 7 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | #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 Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 14 | #include <marvell_plat_priv.h> |
Marcin Wojtas | 0c60c2f | 2018-03-21 09:59:59 +0100 | [diff] [blame] | 15 | #include <plat_marvell.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 17 | #include "comphy/phy-comphy-cp110.h" |
Grzegorz Jaszczyk | 0988f38 | 2019-04-04 17:16:39 +0200 | [diff] [blame] | 18 | #include <stdbool.h> |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 19 | |
| 20 | /* #define DEBUG_COMPHY */ |
| 21 | #ifdef DEBUG_COMPHY |
| 22 | #define debug(format...) NOTICE(format) |
| 23 | #else |
| 24 | #define debug(format, arg...) |
| 25 | #endif |
| 26 | |
| 27 | /* Comphy related FID's */ |
| 28 | #define MV_SIP_COMPHY_POWER_ON 0x82000001 |
| 29 | #define MV_SIP_COMPHY_POWER_OFF 0x82000002 |
| 30 | #define MV_SIP_COMPHY_PLL_LOCK 0x82000003 |
| 31 | #define MV_SIP_COMPHY_XFI_TRAIN 0x82000004 |
| 32 | #define MV_SIP_COMPHY_DIG_RESET 0x82000005 |
| 33 | |
| 34 | /* Miscellaneous FID's' */ |
| 35 | #define MV_SIP_DRAM_SIZE 0x82000010 |
| 36 | #define MV_SIP_LLC_ENABLE 0x82000011 |
Marcin Wojtas | 0c60c2f | 2018-03-21 09:59:59 +0100 | [diff] [blame] | 37 | #define MV_SIP_PMU_IRQ_ENABLE 0x82000012 |
| 38 | #define MV_SIP_PMU_IRQ_DISABLE 0x82000013 |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 39 | |
| 40 | #define MAX_LANE_NR 6 |
| 41 | #define MVEBU_COMPHY_OFFSET 0x441000 |
Grzegorz Jaszczyk | 0988f38 | 2019-04-04 17:16:39 +0200 | [diff] [blame] | 42 | #define MVEBU_CP_BASE_MASK (~0xffffff) |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 43 | |
| 44 | /* This macro is used to identify COMPHY related calls from SMC function ID */ |
| 45 | #define is_comphy_fid(fid) \ |
| 46 | ((fid) >= MV_SIP_COMPHY_POWER_ON && (fid) <= MV_SIP_COMPHY_DIG_RESET) |
| 47 | |
Grzegorz Jaszczyk | 0988f38 | 2019-04-04 17:16:39 +0200 | [diff] [blame] | 48 | _Bool is_cp_range_valid(u_register_t *addr) |
| 49 | { |
| 50 | int cp_nr; |
| 51 | |
| 52 | *addr &= MVEBU_CP_BASE_MASK; |
| 53 | for (cp_nr = 0; cp_nr < CP_NUM; cp_nr++) { |
| 54 | if (*addr == MVEBU_CP_REGS_BASE(cp_nr)) |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | return false; |
| 59 | } |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 60 | |
| 61 | uintptr_t mrvl_sip_smc_handler(uint32_t smc_fid, |
| 62 | u_register_t x1, |
| 63 | u_register_t x2, |
| 64 | u_register_t x3, |
| 65 | u_register_t x4, |
| 66 | void *cookie, |
| 67 | void *handle, |
| 68 | u_register_t flags) |
| 69 | { |
| 70 | u_register_t ret; |
| 71 | int i; |
| 72 | |
| 73 | debug("%s: got SMC (0x%x) x1 0x%lx, x2 0x%lx, x3 0x%lx\n", |
| 74 | __func__, smc_fid, x1, x2, x3); |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 75 | |
Grzegorz Jaszczyk | 0988f38 | 2019-04-04 17:16:39 +0200 | [diff] [blame] | 76 | if (is_comphy_fid(smc_fid)) { |
| 77 | /* validate address passed via x1 */ |
| 78 | if (!is_cp_range_valid(&x1)) { |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 79 | ERROR("%s: Wrong smc (0x%x) address: %lx\n", |
| 80 | __func__, smc_fid, x1); |
| 81 | SMC_RET1(handle, SMC_UNK); |
| 82 | } |
| 83 | |
Grzegorz Jaszczyk | 0988f38 | 2019-04-04 17:16:39 +0200 | [diff] [blame] | 84 | x1 += MVEBU_COMPHY_OFFSET; |
| 85 | |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 86 | if (x2 >= MAX_LANE_NR) { |
| 87 | ERROR("%s: Wrong smc (0x%x) lane nr: %lx\n", |
| 88 | __func__, smc_fid, x2); |
| 89 | SMC_RET1(handle, SMC_UNK); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | switch (smc_fid) { |
| 94 | |
| 95 | /* Comphy related FID's */ |
| 96 | case MV_SIP_COMPHY_POWER_ON: |
| 97 | /* x1: comphy_base, x2: comphy_index, x3: comphy_mode */ |
| 98 | ret = mvebu_cp110_comphy_power_on(x1, x2, x3); |
| 99 | SMC_RET1(handle, ret); |
| 100 | case MV_SIP_COMPHY_POWER_OFF: |
| 101 | /* x1: comphy_base, x2: comphy_index */ |
Igal Liberman | bd51efd | 2018-11-15 16:13:11 +0200 | [diff] [blame] | 102 | ret = mvebu_cp110_comphy_power_off(x1, x2, x3); |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 103 | SMC_RET1(handle, ret); |
| 104 | case MV_SIP_COMPHY_PLL_LOCK: |
| 105 | /* x1: comphy_base, x2: comphy_index */ |
| 106 | ret = mvebu_cp110_comphy_is_pll_locked(x1, x2); |
| 107 | SMC_RET1(handle, ret); |
| 108 | case MV_SIP_COMPHY_XFI_TRAIN: |
| 109 | /* x1: comphy_base, x2: comphy_index */ |
| 110 | ret = mvebu_cp110_comphy_xfi_rx_training(x1, x2); |
| 111 | SMC_RET1(handle, ret); |
| 112 | case MV_SIP_COMPHY_DIG_RESET: |
| 113 | /* x1: comphy_base, x2: comphy_index, x3: mode, x4: command */ |
| 114 | ret = mvebu_cp110_comphy_digital_reset(x1, x2, x3, x4); |
| 115 | SMC_RET1(handle, ret); |
| 116 | |
| 117 | /* Miscellaneous FID's' */ |
| 118 | case MV_SIP_DRAM_SIZE: |
Grzegorz Jaszczyk | 5339f6f | 2019-04-04 17:20:05 +0200 | [diff] [blame] | 119 | ret = mvebu_get_dram_size(MVEBU_REGS_BASE); |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 120 | SMC_RET1(handle, ret); |
| 121 | case MV_SIP_LLC_ENABLE: |
| 122 | for (i = 0; i < ap_get_count(); i++) |
| 123 | llc_runtime_enable(i); |
| 124 | |
| 125 | SMC_RET1(handle, 0); |
Marcin Wojtas | 0c60c2f | 2018-03-21 09:59:59 +0100 | [diff] [blame] | 126 | #ifdef MVEBU_PMU_IRQ_WA |
| 127 | case MV_SIP_PMU_IRQ_ENABLE: |
| 128 | mvebu_pmu_interrupt_enable(); |
| 129 | SMC_RET1(handle, 0); |
| 130 | case MV_SIP_PMU_IRQ_DISABLE: |
| 131 | mvebu_pmu_interrupt_disable(); |
| 132 | SMC_RET1(handle, 0); |
| 133 | #endif |
Konstantin Porotchkin | f69ec58 | 2018-06-07 18:31:14 +0300 | [diff] [blame] | 134 | |
| 135 | default: |
| 136 | ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid); |
| 137 | SMC_RET1(handle, SMC_UNK); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /* Define a runtime service descriptor for fast SMC calls */ |
| 142 | DECLARE_RT_SVC( |
| 143 | marvell_sip_svc, |
| 144 | OEN_SIP_START, |
| 145 | OEN_SIP_END, |
| 146 | SMC_TYPE_FAST, |
| 147 | NULL, |
| 148 | mrvl_sip_smc_handler |
| 149 | ); |