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