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