Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018, Renesas Electronics Corporation. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdint.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 8 | |
| 9 | #include <common/debug.h> |
| 10 | |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 11 | #include "../qos_common.h" |
| 12 | #include "../qos_reg.h" |
| 13 | #include "qos_init_m3_v11.h" |
| 14 | |
| 15 | #define RCAR_QOS_VERSION "rev.0.17" |
| 16 | |
| 17 | #define QOSWT_TIME_BANK0 (20000000U) /* unit:ns */ |
| 18 | |
| 19 | #define QOSWT_WTEN_ENABLE (0x1U) |
| 20 | |
| 21 | #define QOSCTRL_REF_ARS_ARBSTOPCYCLE_M3_11 (SL_INIT_SSLOTCLK_M3_11 - 0x5U) |
| 22 | |
| 23 | #define OSWT_WTREF_SLOT0_EN_REQ1_SLOT (3U) |
| 24 | #define OSWT_WTREF_SLOT0_EN_REQ2_SLOT (9U) |
| 25 | #define QOSWT_WTREF_SLOT0_EN ((0x1U << OSWT_WTREF_SLOT0_EN_REQ1_SLOT) | (0x1U << OSWT_WTREF_SLOT0_EN_REQ2_SLOT)) |
| 26 | #define QOSWT_WTREF_SLOT1_EN ((0x1U << OSWT_WTREF_SLOT0_EN_REQ1_SLOT) | (0x1U << OSWT_WTREF_SLOT0_EN_REQ2_SLOT)) |
| 27 | |
| 28 | #define QOSWT_WTSET0_REQ_SSLOT0 (5U) |
| 29 | #define WT_BASE_SUB_SLOT_NUM0 (12U) |
| 30 | #define QOSWT_WTSET0_PERIOD0_M3_11 ((QOSWT_TIME_BANK0/QOSWT_WTSET0_CYCLE_M3_11)-1U) |
| 31 | #define QOSWT_WTSET0_SSLOT0 (QOSWT_WTSET0_REQ_SSLOT0 -1U) |
| 32 | #define QOSWT_WTSET0_SLOTSLOT0 (WT_BASE_SUB_SLOT_NUM0 -1U) |
| 33 | |
| 34 | #define QOSWT_WTSET1_PERIOD1_M3_11 ((QOSWT_TIME_BANK0/QOSWT_WTSET0_CYCLE_M3_11)-1U) |
| 35 | #define QOSWT_WTSET1_SSLOT1 (QOSWT_WTSET0_REQ_SSLOT0 -1U) |
| 36 | #define QOSWT_WTSET1_SLOTSLOT1 (WT_BASE_SUB_SLOT_NUM0 -1U) |
| 37 | |
| 38 | #if RCAR_QOS_TYPE == RCAR_QOS_TYPE_DEFAULT |
| 39 | |
| 40 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 41 | #include "qos_init_m3_v11_mstat195.h" |
| 42 | #else |
| 43 | #include "qos_init_m3_v11_mstat390.h" |
| 44 | #endif |
| 45 | |
| 46 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 47 | |
| 48 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 49 | #include "qos_init_m3_v11_qoswt195.h" |
| 50 | #else |
| 51 | #include "qos_init_m3_v11_qoswt390.h" |
| 52 | #endif |
| 53 | |
| 54 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 55 | #endif |
| 56 | |
| 57 | static void dbsc_setting(void) |
| 58 | { |
| 59 | uint32_t md = 0; |
| 60 | |
| 61 | /* BUFCAM settings */ |
| 62 | io_write_32(DBSC_DBCAM0CNF1, 0x00043218); /* dbcam0cnf1 */ |
| 63 | io_write_32(DBSC_DBCAM0CNF2, 0x000000F4); /* dbcam0cnf2 */ |
| 64 | io_write_32(DBSC_DBCAM0CNF3, 0x00000000); /* dbcam0cnf3 */ |
| 65 | io_write_32(DBSC_DBSCHCNT0, 0x000F0037); /* dbschcnt0 */ |
| 66 | io_write_32(DBSC_DBSCHSZ0, 0x00000001); /* dbschsz0 */ |
| 67 | io_write_32(DBSC_DBSCHRW0, 0x22421111); /* dbschrw0 */ |
| 68 | |
| 69 | md = (*((volatile uint32_t *)RST_MODEMR) & 0x000A0000) >> 17; |
| 70 | |
| 71 | switch (md) { |
| 72 | case 0x0: |
| 73 | /* DDR3200 */ |
| 74 | io_write_32(DBSC_SCFCTST2, 0x012F1123); |
| 75 | break; |
| 76 | case 0x1: /* MD19=0,MD17=1 : LPDDR4-3000, 4GByte(1GByte x4) */ |
| 77 | /* DDR2800 */ |
| 78 | io_write_32(DBSC_SCFCTST2, 0x012F1123); |
| 79 | break; |
| 80 | case 0x4: /* MD19=1,MD17=0 : LPDDR4-2400, 4GByte(1GByte x4) */ |
| 81 | /* DDR2400 */ |
| 82 | io_write_32(DBSC_SCFCTST2, 0x012F1123); |
| 83 | break; |
| 84 | default: /* MD19=1,MD17=1 : LPDDR4-1600, 4GByte(1GByte x4) */ |
| 85 | /* DDR1600 */ |
| 86 | io_write_32(DBSC_SCFCTST2, 0x012F1123); |
| 87 | break; |
| 88 | } |
| 89 | |
| 90 | /* QoS Settings */ |
| 91 | io_write_32(DBSC_DBSCHQOS00, 0x00000F00); |
| 92 | io_write_32(DBSC_DBSCHQOS01, 0x00000B00); |
| 93 | io_write_32(DBSC_DBSCHQOS02, 0x00000000); |
| 94 | io_write_32(DBSC_DBSCHQOS03, 0x00000000); |
| 95 | io_write_32(DBSC_DBSCHQOS40, 0x00000300); |
| 96 | io_write_32(DBSC_DBSCHQOS41, 0x000002F0); |
| 97 | io_write_32(DBSC_DBSCHQOS42, 0x00000200); |
| 98 | io_write_32(DBSC_DBSCHQOS43, 0x00000100); |
| 99 | io_write_32(DBSC_DBSCHQOS90, 0x00000100); |
| 100 | io_write_32(DBSC_DBSCHQOS91, 0x000000F0); |
| 101 | io_write_32(DBSC_DBSCHQOS92, 0x000000A0); |
| 102 | io_write_32(DBSC_DBSCHQOS93, 0x00000040); |
| 103 | io_write_32(DBSC_DBSCHQOS120, 0x00000040); |
| 104 | io_write_32(DBSC_DBSCHQOS121, 0x00000030); |
| 105 | io_write_32(DBSC_DBSCHQOS122, 0x00000020); |
| 106 | io_write_32(DBSC_DBSCHQOS123, 0x00000010); |
| 107 | io_write_32(DBSC_DBSCHQOS130, 0x00000100); |
| 108 | io_write_32(DBSC_DBSCHQOS131, 0x000000F0); |
| 109 | io_write_32(DBSC_DBSCHQOS132, 0x000000A0); |
| 110 | io_write_32(DBSC_DBSCHQOS133, 0x00000040); |
| 111 | io_write_32(DBSC_DBSCHQOS140, 0x000000C0); |
| 112 | io_write_32(DBSC_DBSCHQOS141, 0x000000B0); |
| 113 | io_write_32(DBSC_DBSCHQOS142, 0x00000080); |
| 114 | io_write_32(DBSC_DBSCHQOS143, 0x00000040); |
| 115 | io_write_32(DBSC_DBSCHQOS150, 0x00000040); |
| 116 | io_write_32(DBSC_DBSCHQOS151, 0x00000030); |
| 117 | io_write_32(DBSC_DBSCHQOS152, 0x00000020); |
| 118 | io_write_32(DBSC_DBSCHQOS153, 0x00000010); |
| 119 | } |
| 120 | |
| 121 | void qos_init_m3_v11(void) |
| 122 | { |
| 123 | dbsc_setting(); |
| 124 | |
| 125 | /* DRAM Split Address mapping */ |
| 126 | #if RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_4CH |
| 127 | #if RCAR_LSI == RCAR_M3 |
| 128 | #error "Don't set DRAM Split 4ch(M3)" |
| 129 | #else |
| 130 | ERROR("DRAM Split 4ch not supported.(M3)"); |
| 131 | panic(); |
| 132 | #endif |
| 133 | #elif (RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_2CH) || \ |
| 134 | (RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_AUTO) |
| 135 | NOTICE("BL2: DRAM Split is 2ch\n"); |
| 136 | io_write_32(AXI_ADSPLCR0, 0x00000000U); |
| 137 | io_write_32(AXI_ADSPLCR1, ADSPLCR0_ADRMODE_DEFAULT |
| 138 | | ADSPLCR0_SPLITSEL(0xFFU) |
| 139 | | ADSPLCR0_AREA(0x1CU) |
| 140 | | ADSPLCR0_SWP); |
| 141 | io_write_32(AXI_ADSPLCR2, 0x00001004U); |
| 142 | io_write_32(AXI_ADSPLCR3, 0x00000000U); |
| 143 | #else |
| 144 | NOTICE("BL2: DRAM Split is OFF\n"); |
| 145 | #endif |
| 146 | |
| 147 | #if !(RCAR_QOS_TYPE == RCAR_QOS_NONE) |
| 148 | #if RCAR_QOS_TYPE == RCAR_QOS_TYPE_DEFAULT |
| 149 | NOTICE("BL2: QoS is default setting(%s)\n", RCAR_QOS_VERSION); |
| 150 | #endif |
| 151 | |
| 152 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 153 | NOTICE("BL2: DRAM refresh interval 1.95 usec\n"); |
| 154 | #else |
| 155 | NOTICE("BL2: DRAM refresh interval 3.9 usec\n"); |
| 156 | #endif |
| 157 | |
| 158 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 159 | NOTICE("BL2: Periodic Write DQ Training\n"); |
| 160 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 161 | |
| 162 | io_write_32(QOSCTRL_RAS, 0x00000044U); |
| 163 | io_write_64(QOSCTRL_DANN, 0x0404020002020201UL); |
| 164 | io_write_32(QOSCTRL_DANT, 0x0020100AU); |
| 165 | io_write_32(QOSCTRL_INSFC, 0x06330001U); |
| 166 | io_write_32(QOSCTRL_RACNT0, 0x02010003U); /* GPU Boost Mode ON */ |
| 167 | |
| 168 | io_write_32(QOSCTRL_SL_INIT, |
| 169 | SL_INIT_REFFSSLOT | SL_INIT_SLOTSSLOT | |
| 170 | SL_INIT_SSLOTCLK_M3_11); |
| 171 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 172 | io_write_32(QOSCTRL_REF_ARS, |
| 173 | ((QOSCTRL_REF_ARS_ARBSTOPCYCLE_M3_11 << 16))); |
| 174 | #else |
| 175 | io_write_32(QOSCTRL_REF_ARS, 0x00330000U); |
| 176 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 177 | |
| 178 | { |
| 179 | uint32_t i; |
| 180 | |
| 181 | for (i = 0U; i < ARRAY_SIZE(mstat_fix); i++) { |
| 182 | io_write_64(QOSBW_FIX_QOS_BANK0 + i * 8, mstat_fix[i]); |
| 183 | io_write_64(QOSBW_FIX_QOS_BANK1 + i * 8, mstat_fix[i]); |
| 184 | } |
| 185 | for (i = 0U; i < ARRAY_SIZE(mstat_be); i++) { |
| 186 | io_write_64(QOSBW_BE_QOS_BANK0 + i * 8, mstat_be[i]); |
| 187 | io_write_64(QOSBW_BE_QOS_BANK1 + i * 8, mstat_be[i]); |
| 188 | } |
| 189 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 190 | for (i = 0U; i < ARRAY_SIZE(qoswt_fix); i++) { |
| 191 | io_write_64(QOSWT_FIX_WTQOS_BANK0 + i * 8, |
| 192 | qoswt_fix[i]); |
| 193 | io_write_64(QOSWT_FIX_WTQOS_BANK1 + i * 8, |
| 194 | qoswt_fix[i]); |
| 195 | } |
| 196 | for (i = 0U; i < ARRAY_SIZE(qoswt_be); i++) { |
| 197 | io_write_64(QOSWT_BE_WTQOS_BANK0 + i * 8, qoswt_be[i]); |
| 198 | io_write_64(QOSWT_BE_WTQOS_BANK1 + i * 8, qoswt_be[i]); |
| 199 | } |
| 200 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 201 | } |
| 202 | |
| 203 | /* 3DG bus Leaf setting */ |
| 204 | io_write_32(GPU_ACT_GRD, 0x00001234U); |
| 205 | io_write_32(GPU_ACT0, 0x00000000U); |
| 206 | io_write_32(GPU_ACT1, 0x00000000U); |
| 207 | io_write_32(GPU_ACT2, 0x00000000U); |
| 208 | io_write_32(GPU_ACT3, 0x00000000U); |
| 209 | |
| 210 | /* RT bus Leaf setting */ |
| 211 | io_write_32(RT_ACT0, 0x00000000U); |
| 212 | io_write_32(RT_ACT1, 0x00000000U); |
| 213 | |
| 214 | /* CCI bus Leaf setting */ |
| 215 | io_write_32(CPU_ACT0, 0x00000003U); |
| 216 | io_write_32(CPU_ACT1, 0x00000003U); |
| 217 | io_write_32(CPU_ACT2, 0x00000003U); |
| 218 | io_write_32(CPU_ACT3, 0x00000003U); |
| 219 | |
| 220 | io_write_32(QOSCTRL_RAEN, 0x00000001U); |
| 221 | |
| 222 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 223 | /* re-write training setting */ |
| 224 | io_write_32(QOSWT_WTREF, |
| 225 | ((QOSWT_WTREF_SLOT1_EN << 16) | QOSWT_WTREF_SLOT0_EN)); |
| 226 | io_write_32(QOSWT_WTSET0, |
| 227 | ((QOSWT_WTSET0_PERIOD0_M3_11 << 16) | |
| 228 | (QOSWT_WTSET0_SSLOT0 << 8) | QOSWT_WTSET0_SLOTSLOT0)); |
| 229 | io_write_32(QOSWT_WTSET1, |
| 230 | ((QOSWT_WTSET1_PERIOD1_M3_11 << 16) | |
| 231 | (QOSWT_WTSET1_SSLOT1 << 8) | QOSWT_WTSET1_SLOTSLOT1)); |
| 232 | |
| 233 | io_write_32(QOSWT_WTEN, QOSWT_WTEN_ENABLE); |
| 234 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 235 | |
| 236 | io_write_32(QOSCTRL_STATQC, 0x00000001U); |
| 237 | #else |
| 238 | NOTICE("BL2: QoS is None\n"); |
| 239 | |
| 240 | io_write_32(QOSCTRL_RAEN, 0x00000001U); |
| 241 | #endif /* !(RCAR_QOS_TYPE == RCAR_QOS_NONE) */ |
| 242 | } |