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) 2017-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_m3n_v10.h" |
| 14 | |
Marek Vasut | ce56e46 | 2019-06-14 02:21:54 +0200 | [diff] [blame] | 15 | #define RCAR_QOS_VERSION "rev.0.09" |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 16 | |
Marek Vasut | ce56e46 | 2019-06-14 02:21:54 +0200 | [diff] [blame] | 17 | #define REF_ARS_ARBSTOPCYCLE_M3N \ |
| 18 | (((SL_INIT_SSLOTCLK_M3N) - 5U) << 16U) |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 19 | |
Marek Vasut | ce56e46 | 2019-06-14 02:21:54 +0200 | [diff] [blame] | 20 | #define QOSWT_TIME_BANK0 20000000U /* unit:ns */ |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 21 | |
Marek Vasut | ce56e46 | 2019-06-14 02:21:54 +0200 | [diff] [blame] | 22 | #define QOSWT_WTEN_ENABLE 0x1U |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 23 | |
Marek Vasut | ce56e46 | 2019-06-14 02:21:54 +0200 | [diff] [blame] | 24 | #define OSWT_WTREF_SLOT0_EN_REQ1_SLOT 3U |
| 25 | #define OSWT_WTREF_SLOT0_EN_REQ2_SLOT 9U |
| 26 | #define QOSWT_WTREF_SLOT0_EN \ |
| 27 | ((0x1U << OSWT_WTREF_SLOT0_EN_REQ1_SLOT) | \ |
| 28 | (0x1U << OSWT_WTREF_SLOT0_EN_REQ2_SLOT)) |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 29 | #define QOSWT_WTREF_SLOT1_EN QOSWT_WTREF_SLOT0_EN |
| 30 | |
Marek Vasut | ce56e46 | 2019-06-14 02:21:54 +0200 | [diff] [blame] | 31 | #define QOSWT_WTSET0_REQ_SSLOT0 5U |
| 32 | #define WT_BASE_SUB_SLOT_NUM0 12U |
| 33 | #define QOSWT_WTSET0_PERIOD0_M3N \ |
| 34 | ((QOSWT_TIME_BANK0 / QOSWT_WTSET0_CYCLE_M3N) - 1U) |
| 35 | #define QOSWT_WTSET0_SSLOT0 (QOSWT_WTSET0_REQ_SSLOT0 - 1U) |
| 36 | #define QOSWT_WTSET0_SLOTSLOT0 (WT_BASE_SUB_SLOT_NUM0 - 1U) |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 37 | |
| 38 | #define QOSWT_WTSET1_PERIOD1_M3N QOSWT_WTSET0_PERIOD0_M3N |
Marek Vasut | ce56e46 | 2019-06-14 02:21:54 +0200 | [diff] [blame] | 39 | #define QOSWT_WTSET1_SSLOT1 QOSWT_WTSET0_SSLOT0 |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 40 | #define QOSWT_WTSET1_SLOTSLOT1 QOSWT_WTSET0_SLOTSLOT0 |
| 41 | |
| 42 | #if RCAR_QOS_TYPE == RCAR_QOS_TYPE_DEFAULT |
| 43 | |
| 44 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 45 | #include "qos_init_m3n_v10_mstat195.h" |
| 46 | #else |
| 47 | #include "qos_init_m3n_v10_mstat390.h" |
| 48 | #endif |
| 49 | |
| 50 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 51 | |
| 52 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 53 | #include "qos_init_m3n_v10_qoswt195.h" |
| 54 | #else |
| 55 | #include "qos_init_m3n_v10_qoswt390.h" |
| 56 | #endif |
| 57 | |
| 58 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 59 | #endif |
| 60 | |
| 61 | static void dbsc_setting(void) |
| 62 | { |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 63 | /* Register write enable */ |
| 64 | io_write_32(DBSC_DBSYSCNT0, 0x00001234U); |
| 65 | |
| 66 | /* BUFCAM settings */ |
Marek Vasut | 07d506e | 2019-06-14 01:58:27 +0200 | [diff] [blame] | 67 | io_write_32(DBSC_DBCAM0CNF1, 0x00043218); |
| 68 | io_write_32(DBSC_DBCAM0CNF2, 0x000000F4); |
| 69 | io_write_32(DBSC_DBSCHCNT0, 0x000F0037); |
| 70 | io_write_32(DBSC_DBSCHSZ0, 0x00000001); |
| 71 | io_write_32(DBSC_DBSCHRW0, 0x22421111); |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 72 | |
Marek Vasut | ccbf81f | 2019-06-14 01:58:56 +0200 | [diff] [blame] | 73 | /* DDR3 */ |
| 74 | io_write_32(DBSC_SCFCTST2, 0x012F1123); |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 75 | |
| 76 | /* QoS Settings */ |
| 77 | io_write_32(DBSC_DBSCHQOS00, 0x00000F00); |
| 78 | io_write_32(DBSC_DBSCHQOS01, 0x00000B00); |
| 79 | io_write_32(DBSC_DBSCHQOS02, 0x00000000); |
| 80 | io_write_32(DBSC_DBSCHQOS03, 0x00000000); |
| 81 | io_write_32(DBSC_DBSCHQOS40, 0x00000300); |
| 82 | io_write_32(DBSC_DBSCHQOS41, 0x000002F0); |
| 83 | io_write_32(DBSC_DBSCHQOS42, 0x00000200); |
| 84 | io_write_32(DBSC_DBSCHQOS43, 0x00000100); |
| 85 | io_write_32(DBSC_DBSCHQOS90, 0x00000100); |
| 86 | io_write_32(DBSC_DBSCHQOS91, 0x000000F0); |
| 87 | io_write_32(DBSC_DBSCHQOS92, 0x000000A0); |
| 88 | io_write_32(DBSC_DBSCHQOS93, 0x00000040); |
| 89 | io_write_32(DBSC_DBSCHQOS130, 0x00000100); |
| 90 | io_write_32(DBSC_DBSCHQOS131, 0x000000F0); |
| 91 | io_write_32(DBSC_DBSCHQOS132, 0x000000A0); |
| 92 | io_write_32(DBSC_DBSCHQOS133, 0x00000040); |
| 93 | io_write_32(DBSC_DBSCHQOS140, 0x000000C0); |
| 94 | io_write_32(DBSC_DBSCHQOS141, 0x000000B0); |
| 95 | io_write_32(DBSC_DBSCHQOS142, 0x00000080); |
| 96 | io_write_32(DBSC_DBSCHQOS143, 0x00000040); |
| 97 | io_write_32(DBSC_DBSCHQOS150, 0x00000040); |
| 98 | io_write_32(DBSC_DBSCHQOS151, 0x00000030); |
| 99 | io_write_32(DBSC_DBSCHQOS152, 0x00000020); |
| 100 | io_write_32(DBSC_DBSCHQOS153, 0x00000010); |
| 101 | |
| 102 | /* Register write protect */ |
| 103 | io_write_32(DBSC_DBSYSCNT0, 0x00000000U); |
| 104 | } |
| 105 | |
| 106 | void qos_init_m3n_v10(void) |
| 107 | { |
| 108 | dbsc_setting(); |
| 109 | |
| 110 | /* DRAM Split Address mapping */ |
| 111 | #if RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_4CH |
| 112 | #if RCAR_LSI == RCAR_M3N |
| 113 | #error "Don't set DRAM Split 4ch(M3N)" |
| 114 | #else |
| 115 | ERROR("DRAM Split 4ch not supported.(M3N)"); |
| 116 | panic(); |
| 117 | #endif |
| 118 | #elif (RCAR_DRAM_SPLIT == RCAR_DRAM_SPLIT_2CH) |
| 119 | #if RCAR_LSI == RCAR_M3N |
| 120 | #error "Don't set DRAM Split 2ch(M3N)" |
| 121 | #else |
| 122 | ERROR("DRAM Split 2ch not supported.(M3N)"); |
| 123 | panic(); |
| 124 | #endif |
| 125 | #else |
| 126 | NOTICE("BL2: DRAM Split is OFF\n"); |
| 127 | #endif |
| 128 | |
| 129 | #if !(RCAR_QOS_TYPE == RCAR_QOS_NONE) |
| 130 | #if RCAR_QOS_TYPE == RCAR_QOS_TYPE_DEFAULT |
| 131 | NOTICE("BL2: QoS is default setting(%s)\n", RCAR_QOS_VERSION); |
| 132 | #endif |
| 133 | |
| 134 | #if RCAR_REF_INT == RCAR_REF_DEFAULT |
| 135 | NOTICE("BL2: DRAM refresh interval 1.95 usec\n"); |
| 136 | #else |
| 137 | NOTICE("BL2: DRAM refresh interval 3.9 usec\n"); |
| 138 | #endif |
| 139 | |
| 140 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 141 | NOTICE("BL2: Periodic Write DQ Training\n"); |
| 142 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 143 | |
| 144 | io_write_32(QOSCTRL_RAS, 0x00000028U); |
| 145 | io_write_64(QOSCTRL_DANN, 0x0402000002020201UL); |
| 146 | io_write_32(QOSCTRL_DANT, 0x00100804U); |
| 147 | io_write_32(QOSCTRL_FSS, 0x0000000AU); |
| 148 | io_write_32(QOSCTRL_INSFC, 0x06330001U); |
| 149 | io_write_32(QOSCTRL_EARLYR, 0x00000001U); |
| 150 | io_write_32(QOSCTRL_RACNT0, 0x00010003U); |
| 151 | |
| 152 | io_write_32(QOSCTRL_SL_INIT, |
| 153 | SL_INIT_REFFSSLOT | SL_INIT_SLOTSSLOT | |
| 154 | SL_INIT_SSLOTCLK_M3N); |
| 155 | io_write_32(QOSCTRL_REF_ARS, REF_ARS_ARBSTOPCYCLE_M3N); |
| 156 | |
Marek Vasut | 7e0ac9e | 2019-06-14 01:57:30 +0200 | [diff] [blame] | 157 | uint32_t i; |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 158 | |
Marek Vasut | 7e0ac9e | 2019-06-14 01:57:30 +0200 | [diff] [blame] | 159 | for (i = 0U; i < ARRAY_SIZE(mstat_fix); i++) { |
| 160 | io_write_64(QOSBW_FIX_QOS_BANK0 + i * 8, mstat_fix[i]); |
| 161 | io_write_64(QOSBW_FIX_QOS_BANK1 + i * 8, mstat_fix[i]); |
| 162 | } |
| 163 | for (i = 0U; i < ARRAY_SIZE(mstat_be); i++) { |
| 164 | io_write_64(QOSBW_BE_QOS_BANK0 + i * 8, mstat_be[i]); |
| 165 | io_write_64(QOSBW_BE_QOS_BANK1 + i * 8, mstat_be[i]); |
| 166 | } |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 167 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
Marek Vasut | 7e0ac9e | 2019-06-14 01:57:30 +0200 | [diff] [blame] | 168 | for (i = 0U; i < ARRAY_SIZE(qoswt_fix); i++) { |
| 169 | io_write_64(QOSWT_FIX_WTQOS_BANK0 + i * 8, |
| 170 | qoswt_fix[i]); |
| 171 | io_write_64(QOSWT_FIX_WTQOS_BANK1 + i * 8, |
| 172 | qoswt_fix[i]); |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 173 | } |
Marek Vasut | 7e0ac9e | 2019-06-14 01:57:30 +0200 | [diff] [blame] | 174 | for (i = 0U; i < ARRAY_SIZE(qoswt_be); i++) { |
| 175 | io_write_64(QOSWT_BE_WTQOS_BANK0 + i * 8, qoswt_be[i]); |
| 176 | io_write_64(QOSWT_BE_WTQOS_BANK1 + i * 8, qoswt_be[i]); |
| 177 | } |
| 178 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 179 | |
Jorge Ramirez-Ortiz | 47503d2 | 2018-09-23 09:36:52 +0200 | [diff] [blame] | 180 | /* RT bus Leaf setting */ |
| 181 | io_write_32(RT_ACT0, 0x00000000U); |
| 182 | io_write_32(RT_ACT1, 0x00000000U); |
| 183 | |
| 184 | /* CCI bus Leaf setting */ |
| 185 | io_write_32(CPU_ACT0, 0x00000003U); |
| 186 | io_write_32(CPU_ACT1, 0x00000003U); |
| 187 | |
| 188 | io_write_32(QOSCTRL_RAEN, 0x00000001U); |
| 189 | |
| 190 | #if RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE |
| 191 | /* re-write training setting */ |
| 192 | io_write_32(QOSWT_WTREF, |
| 193 | ((QOSWT_WTREF_SLOT1_EN << 16) | QOSWT_WTREF_SLOT0_EN)); |
| 194 | io_write_32(QOSWT_WTSET0, |
| 195 | ((QOSWT_WTSET0_PERIOD0_M3N << 16) | |
| 196 | (QOSWT_WTSET0_SSLOT0 << 8) | QOSWT_WTSET0_SLOTSLOT0)); |
| 197 | io_write_32(QOSWT_WTSET1, |
| 198 | ((QOSWT_WTSET1_PERIOD1_M3N << 16) | |
| 199 | (QOSWT_WTSET1_SSLOT1 << 8) | QOSWT_WTSET1_SLOTSLOT1)); |
| 200 | |
| 201 | io_write_32(QOSWT_WTEN, QOSWT_WTEN_ENABLE); |
| 202 | #endif /* RCAR_REWT_TRAINING != RCAR_REWT_TRAINING_DISABLE */ |
| 203 | |
| 204 | io_write_32(QOSCTRL_STATQC, 0x00000001U); |
| 205 | #else |
| 206 | NOTICE("BL2: QoS is None\n"); |
| 207 | |
| 208 | io_write_32(QOSCTRL_RAEN, 0x00000001U); |
| 209 | #endif /* !(RCAR_QOS_TYPE == RCAR_QOS_NONE) */ |
| 210 | } |