Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 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_h3_v30.h" |
| 14 | |
Marek Vasut | 48cc693 | 2018-12-12 16:35:00 +0100 | [diff] [blame^] | 15 | |
| 16 | #define RCAR_QOS_VERSION "rev.0.10" |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 17 | |
| 18 | #define QOSCTRL_FSS (QOS_BASE1 + 0x0048U) |
| 19 | |
| 20 | #define QOSWT_TIME_BANK0 (20000000U) /* unit:ns */ |
| 21 | |
| 22 | #define QOSWT_WTEN_ENABLE (0x1U) |
| 23 | |
| 24 | #define QOSCTRL_REF_ARS_ARBSTOPCYCLE_H3_30 (SL_INIT_SSLOTCLK_H3_30 - 0x5U) |
| 25 | |
| 26 | #define OSWT_WTREF_SLOT0_EN_REQ1_SLOT (3U) |
| 27 | #define OSWT_WTREF_SLOT0_EN_REQ2_SLOT (9U) |
| 28 | #define QOSWT_WTREF_SLOT0_EN ((0x1U << OSWT_WTREF_SLOT0_EN_REQ1_SLOT) | (0x1U << OSWT_WTREF_SLOT0_EN_REQ2_SLOT)) |
| 29 | #define QOSWT_WTREF_SLOT1_EN ((0x1U << OSWT_WTREF_SLOT0_EN_REQ1_SLOT) | (0x1U << OSWT_WTREF_SLOT0_EN_REQ2_SLOT)) |
| 30 | |
| 31 | #define QOSWT_WTSET0_REQ_SSLOT0 (5U) |
| 32 | #define WT_BASE_SUB_SLOT_NUM0 (12U) |
| 33 | #define QOSWT_WTSET0_PERIOD0_H3_30 ((QOSWT_TIME_BANK0/QOSWT_WTSET0_CYCLE_H3_30)-1U) |
| 34 | #define QOSWT_WTSET0_SSLOT0 (QOSWT_WTSET0_REQ_SSLOT0 -1U) |
| 35 | #define QOSWT_WTSET0_SLOTSLOT0 (WT_BASE_SUB_SLOT_NUM0 -1U) |
| 36 | |
| 37 | #define QOSWT_WTSET1_PERIOD1_H3_30 (QOSWT_WTSET0_PERIOD0_H3_30) |
| 38 | #define QOSWT_WTSET1_SSLOT1 (QOSWT_WTSET0_SSLOT0) |
| 39 | #define QOSWT_WTSET1_SLOTSLOT1 (QOSWT_WTSET0_SLOTSLOT0) |
| 40 | |
| 41 | #if RCAR_QOS_TYPE == RCAR_QOS_TYPE_DEFAULT |
| 42 | |
| 43 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 44 | #include "qos_init_h3_v30_mstat195.h" |
| 45 | #else |
| 46 | #include "qos_init_h3_v30_mstat390.h" |
| 47 | #endif |
| 48 | |
| 49 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 50 | |
| 51 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 52 | #include "qos_init_h3_v30_qoswt195.h" |
| 53 | #else |
| 54 | #include "qos_init_h3_v30_qoswt390.h" |
| 55 | #endif |
| 56 | |
| 57 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 58 | |
| 59 | #endif |
| 60 | |
| 61 | static void dbsc_setting(void) |
| 62 | { |
| 63 | uint32_t md = 0; |
| 64 | |
| 65 | /* Register write enable */ |
| 66 | io_write_32(DBSC_DBSYSCNT0, 0x00001234U); |
| 67 | |
| 68 | /* BUFCAM settings */ |
| 69 | io_write_32(DBSC_DBCAM0CNF1, 0x00043218U); /* dbcam0cnf1 */ |
| 70 | io_write_32(DBSC_DBCAM0CNF2, 0x000000F4U); /* dbcam0cnf2 */ |
| 71 | io_write_32(DBSC_DBCAM0CNF3, 0x00000000U); /* dbcam0cnf3 */ |
| 72 | io_write_32(DBSC_DBSCHCNT0, 0x000F0037U); /* dbschcnt0 */ |
| 73 | io_write_32(DBSC_DBSCHSZ0, 0x00000001U); /* dbschsz0 */ |
| 74 | io_write_32(DBSC_DBSCHRW0, 0x22421111U); /* dbschrw0 */ |
| 75 | |
| 76 | md = (*((volatile uint32_t *)RST_MODEMR) & 0x000A0000) >> 17; |
| 77 | |
| 78 | switch (md) { |
| 79 | case 0x0: |
| 80 | /* DDR3200 */ |
| 81 | io_write_32(DBSC_SCFCTST2, 0x012F1123U); |
| 82 | break; |
| 83 | case 0x1: /* MD19=0,MD17=1 : LPDDR4-3000, 4GByte(1GByte x4) */ |
| 84 | /* DDR2800 */ |
| 85 | io_write_32(DBSC_SCFCTST2, 0x012F1123U); |
| 86 | break; |
| 87 | case 0x4: /* MD19=1,MD17=0 : LPDDR4-2400, 4GByte(1GByte x4) */ |
| 88 | /* DDR2400 */ |
| 89 | io_write_32(DBSC_SCFCTST2, 0x012F1123U); |
| 90 | break; |
| 91 | default: /* MD19=1,MD17=1 : LPDDR4-1600, 4GByte(1GByte x4) */ |
| 92 | /* DDR1600 */ |
| 93 | io_write_32(DBSC_SCFCTST2, 0x012F1123U); |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | /* QoS Settings */ |
| 98 | io_write_32(DBSC_DBSCHQOS00, 0x00000F00U); |
| 99 | io_write_32(DBSC_DBSCHQOS01, 0x00000B00U); |
| 100 | io_write_32(DBSC_DBSCHQOS02, 0x00000000U); |
| 101 | io_write_32(DBSC_DBSCHQOS03, 0x00000000U); |
| 102 | io_write_32(DBSC_DBSCHQOS40, 0x00000300U); |
| 103 | io_write_32(DBSC_DBSCHQOS41, 0x000002F0U); |
| 104 | io_write_32(DBSC_DBSCHQOS42, 0x00000200U); |
| 105 | io_write_32(DBSC_DBSCHQOS43, 0x00000100U); |
| 106 | io_write_32(DBSC_DBSCHQOS90, 0x00000100U); |
| 107 | io_write_32(DBSC_DBSCHQOS91, 0x000000F0U); |
| 108 | io_write_32(DBSC_DBSCHQOS92, 0x000000A0U); |
| 109 | io_write_32(DBSC_DBSCHQOS93, 0x00000040U); |
| 110 | io_write_32(DBSC_DBSCHQOS120, 0x00000040U); |
| 111 | io_write_32(DBSC_DBSCHQOS121, 0x00000030U); |
| 112 | io_write_32(DBSC_DBSCHQOS122, 0x00000020U); |
| 113 | io_write_32(DBSC_DBSCHQOS123, 0x00000010U); |
| 114 | io_write_32(DBSC_DBSCHQOS130, 0x00000100U); |
| 115 | io_write_32(DBSC_DBSCHQOS131, 0x000000F0U); |
| 116 | io_write_32(DBSC_DBSCHQOS132, 0x000000A0U); |
| 117 | io_write_32(DBSC_DBSCHQOS133, 0x00000040U); |
| 118 | io_write_32(DBSC_DBSCHQOS140, 0x000000C0U); |
| 119 | io_write_32(DBSC_DBSCHQOS141, 0x000000B0U); |
| 120 | io_write_32(DBSC_DBSCHQOS142, 0x00000080U); |
| 121 | io_write_32(DBSC_DBSCHQOS143, 0x00000040U); |
| 122 | io_write_32(DBSC_DBSCHQOS150, 0x00000040U); |
| 123 | io_write_32(DBSC_DBSCHQOS151, 0x00000030U); |
| 124 | io_write_32(DBSC_DBSCHQOS152, 0x00000020U); |
| 125 | io_write_32(DBSC_DBSCHQOS153, 0x00000010U); |
| 126 | |
| 127 | /* Register write protect */ |
| 128 | io_write_32(DBSC_DBSYSCNT0, 0x00000000U); |
| 129 | } |
| 130 | |
| 131 | void qos_init_h3_v30(void) |
| 132 | { |
| 133 | unsigned int split_area; |
| 134 | dbsc_setting(); |
| 135 | |
| 136 | #if RCAR_DRAM_LPDDR4_MEMCONF == 0 /* 1GB */ |
| 137 | split_area = 0x1BU; |
| 138 | #else /* default 2GB */ |
| 139 | split_area = 0x1CU; |
| 140 | #endif |
| 141 | |
| 142 | /* DRAM Split Address mapping */ |
| 143 | #if (RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_4CH) || \ |
| 144 | (RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_AUTO) |
| 145 | NOTICE("BL2: DRAM Split is 4ch(DDR %x)\n", (int)qos_init_ddr_phyvalid); |
| 146 | |
| 147 | io_write_32(AXI_ADSPLCR0, ADSPLCR0_ADRMODE_DEFAULT |
| 148 | | ADSPLCR0_SPLITSEL(0xFFU) |
| 149 | | ADSPLCR0_AREA(split_area) |
| 150 | | ADSPLCR0_SWP); |
| 151 | io_write_32(AXI_ADSPLCR1, 0x00000000U); |
| 152 | io_write_32(AXI_ADSPLCR2, 0x00001054U); |
| 153 | io_write_32(AXI_ADSPLCR3, 0x00000000U); |
| 154 | #elif RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_2CH |
| 155 | NOTICE("BL2: DRAM Split is 2ch(DDR %x)\n", (int)qos_init_ddr_phyvalid); |
| 156 | |
| 157 | io_write_32(AXI_ADSPLCR0, ADSPLCR0_AREA(split_area)); |
| 158 | io_write_32(AXI_ADSPLCR1, ADSPLCR0_ADRMODE_DEFAULT |
| 159 | | ADSPLCR0_SPLITSEL(0xFFU) |
| 160 | | ADSPLCR0_AREA(split_area) |
| 161 | | ADSPLCR0_SWP); |
| 162 | io_write_32(AXI_ADSPLCR2, 0x00001004U); |
| 163 | io_write_32(AXI_ADSPLCR3, 0x00000000U); |
| 164 | #else |
| 165 | io_write_32(AXI_ADSPLCR0, ADSPLCR0_AREA(split_area)); |
| 166 | NOTICE("BL2: DRAM Split is OFF(DDR %x)\n", (int)qos_init_ddr_phyvalid); |
| 167 | #endif |
| 168 | |
| 169 | #if !(RCAR_QOS_TYPE == RCAR_QOS_NONE) |
| 170 | #if RCAR_QOS_TYPE == RCAR_QOS_TYPE_DEFAULT |
| 171 | NOTICE("BL2: QoS is default setting(%s)\n", RCAR_QOS_VERSION); |
| 172 | #endif |
| 173 | |
| 174 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 175 | NOTICE("BL2: DRAM refresh interval 1.95 usec\n"); |
| 176 | #else |
| 177 | NOTICE("BL2: DRAM refresh interval 3.9 usec\n"); |
| 178 | #endif |
| 179 | |
| 180 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 181 | NOTICE("BL2: Periodic Write DQ Training\n"); |
| 182 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 183 | |
| 184 | io_write_32(QOSCTRL_RAS, 0x00000044U); |
| 185 | io_write_64(QOSCTRL_DANN, 0x0404010002020201UL); |
| 186 | io_write_32(QOSCTRL_DANT, 0x0020100AU); |
| 187 | io_write_32(QOSCTRL_FSS, 0x0000000AU); |
| 188 | io_write_32(QOSCTRL_INSFC, 0x06330001U); |
| 189 | io_write_32(QOSCTRL_RACNT0, 0x00010003U); |
| 190 | |
| 191 | /* GPU Boost Mode */ |
| 192 | io_write_32(QOSCTRL_STATGEN0, 0x00000001U); |
| 193 | |
| 194 | io_write_32(QOSCTRL_SL_INIT, |
| 195 | SL_INIT_REFFSSLOT | SL_INIT_SLOTSSLOT | |
| 196 | SL_INIT_SSLOTCLK_H3_30); |
| 197 | io_write_32(QOSCTRL_REF_ARS, |
| 198 | ((QOSCTRL_REF_ARS_ARBSTOPCYCLE_H3_30 << 16))); |
| 199 | |
| 200 | { |
| 201 | uint32_t i; |
| 202 | |
| 203 | for (i = 0U; i < ARRAY_SIZE(mstat_fix); i++) { |
| 204 | io_write_64(QOSBW_FIX_QOS_BANK0 + i * 8, mstat_fix[i]); |
| 205 | io_write_64(QOSBW_FIX_QOS_BANK1 + i * 8, mstat_fix[i]); |
| 206 | } |
| 207 | for (i = 0U; i < ARRAY_SIZE(mstat_be); i++) { |
| 208 | io_write_64(QOSBW_BE_QOS_BANK0 + i * 8, mstat_be[i]); |
| 209 | io_write_64(QOSBW_BE_QOS_BANK1 + i * 8, mstat_be[i]); |
| 210 | } |
| 211 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 212 | for (i = 0U; i < ARRAY_SIZE(qoswt_fix); i++) { |
| 213 | io_write_64(QOSWT_FIX_WTQOS_BANK0 + i * 8, |
| 214 | qoswt_fix[i]); |
| 215 | io_write_64(QOSWT_FIX_WTQOS_BANK1 + i * 8, |
| 216 | qoswt_fix[i]); |
| 217 | } |
| 218 | for (i = 0U; i < ARRAY_SIZE(qoswt_be); i++) { |
| 219 | io_write_64(QOSWT_BE_WTQOS_BANK0 + i * 8, qoswt_be[i]); |
| 220 | io_write_64(QOSWT_BE_WTQOS_BANK1 + i * 8, qoswt_be[i]); |
| 221 | } |
| 222 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 223 | } |
| 224 | |
| 225 | /* AXI setting */ |
| 226 | io_write_32(AXI_MMCR, 0x00010008U); |
| 227 | io_write_32(AXI_TR3CR, 0x00010000U); |
| 228 | io_write_32(AXI_TR4CR, 0x00010000U); |
| 229 | |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 230 | /* RT bus Leaf setting */ |
| 231 | io_write_32(RT_ACT0, 0x00000000U); |
| 232 | io_write_32(RT_ACT1, 0x00000000U); |
| 233 | |
| 234 | /* CCI bus Leaf setting */ |
| 235 | io_write_32(CPU_ACT0, 0x00000003U); |
| 236 | io_write_32(CPU_ACT1, 0x00000003U); |
| 237 | io_write_32(CPU_ACT2, 0x00000003U); |
| 238 | io_write_32(CPU_ACT3, 0x00000003U); |
| 239 | |
| 240 | io_write_32(QOSCTRL_RAEN, 0x00000001U); |
| 241 | |
| 242 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 243 | /* re-write training setting */ |
| 244 | io_write_32(QOSWT_WTREF, |
| 245 | ((QOSWT_WTREF_SLOT1_EN << 16) | QOSWT_WTREF_SLOT0_EN)); |
| 246 | io_write_32(QOSWT_WTSET0, |
| 247 | ((QOSWT_WTSET0_PERIOD0_H3_30 << 16) | |
| 248 | (QOSWT_WTSET0_SSLOT0 << 8) | QOSWT_WTSET0_SLOTSLOT0)); |
| 249 | io_write_32(QOSWT_WTSET1, |
| 250 | ((QOSWT_WTSET1_PERIOD1_H3_30 << 16) | |
| 251 | (QOSWT_WTSET1_SSLOT1 << 8) | QOSWT_WTSET1_SLOTSLOT1)); |
| 252 | |
| 253 | io_write_32(QOSWT_WTEN, QOSWT_WTEN_ENABLE); |
| 254 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 255 | |
| 256 | io_write_32(QOSCTRL_STATQC, 0x00000001U); |
| 257 | #else |
| 258 | NOTICE("BL2: QoS is None\n"); |
| 259 | |
| 260 | io_write_32(QOSCTRL_RAEN, 0x00000001U); |
| 261 | #endif /* !(RCAR_QOS_TYPE == RCAR_QOS_NONE) */ |
| 262 | } |