Rex-BC Chen | 9c098e2 | 2021-06-29 09:44:31 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
Ryan Chuang | b0b8dc3 | 2021-05-06 23:48:18 +0800 | [diff] [blame] | 2 | |
| 3 | #ifndef _DRAMC_COMMON_H_ |
| 4 | #define _DRAMC_COMMON_H_ |
| 5 | |
| 6 | |
| 7 | #include <soc/dramc_soc.h> |
| 8 | |
| 9 | #include <delay.h> |
| 10 | #include <device/mmio.h> |
| 11 | #include <stdint.h> |
| 12 | #include <types.h> |
| 13 | #include <reg.h> |
| 14 | #include <soc/dramc_common.h> |
| 15 | #include <timer.h> |
| 16 | #include <print.h> |
| 17 | |
| 18 | #include <string.h> |
| 19 | #include "dramc_register.h" |
| 20 | #include "dramc_pi_api.h" |
| 21 | #include "dramc_int_slt.h" |
| 22 | #include "print.h" |
| 23 | #include "reg.h" |
| 24 | |
| 25 | #if FOR_DV_SIMULATION_USED == 1 |
| 26 | #include "dramc_dv_init.h" |
| 27 | #else |
| 28 | #ifdef __DPM__ |
| 29 | #include "dramc_dpm.h" |
| 30 | #elif __ETT__ |
| 31 | #include "common.h" |
| 32 | #endif |
| 33 | #endif |
| 34 | |
| 35 | #if __ETT__ |
| 36 | #include "dramc_version.h" |
| 37 | #else |
| 38 | #define _VERSION_ "ETT Version 0.0.0.1" |
| 39 | #define _COMMIT_VERSION_ "01234567" |
| 40 | #define _COMMIT_DATE_ "2020-10-10/10:10:10" |
| 41 | #endif |
| 42 | /***********************************************************************/ |
| 43 | /* Public Types */ |
| 44 | /***********************************************************************/ |
| 45 | |
| 46 | /*------------------------------------------------------------*/ |
| 47 | /* macros, defines, typedefs, enums */ |
| 48 | /*------------------------------------------------------------*/ |
| 49 | /************************** Common Macro *********************/ |
| 50 | |
| 51 | |
| 52 | #define dsb() asm volatile("dsb sy" : : : "memory") |
| 53 | #define DRV_Reg32(x) read32((const void *)((u64)(x))) |
| 54 | #define DRV_WriteReg32(x, y) write32((void *)((u64)(x)), (y)) |
| 55 | |
| 56 | #define mcDELAY_US(x) udelay(x) |
| 57 | #define mcDELAY_MS(x) udelay(x*1000) |
| 58 | #define mcDELAY_XUS(x) udelay(x) |
| 59 | #define mcDELAY_XNS(x) udelay(1) |
| 60 | // choose a proper mcDELAY |
| 61 | #if defined(__DPM__) |
| 62 | #define mcDELAY_US(x) timer_busy_wait_us(TIMER3, x) |
| 63 | #define mcDELAY_XUS(x) timer_busy_wait_us(TIMER3, x) |
| 64 | #define mcDELAY_XNS(x) timer_busy_wait_us(TIMER3, 1) |
| 65 | #define mcDELAY_MS(x) timer_busy_wait_ms(TIMER3, x) |
| 66 | #endif |
| 67 | |
| 68 | /**********************************************/ |
| 69 | /* Priority of debug log */ |
| 70 | /*--------------------------------------------*/ |
| 71 | /* mcSHOW_DBG_MSG: High */ |
| 72 | /* mcSHOW_DBG_MSG2: Medium High */ |
| 73 | /* mcSHOW_DBG_MSG3: Medium Low */ |
| 74 | /* mcSHOW_DBG_MSG4: Low */ |
| 75 | /**********************************************/ |
Arthur Heymans | e9d9c1e | 2023-04-19 10:08:36 +0200 | [diff] [blame^] | 76 | |
Ryan Chuang | b0b8dc3 | 2021-05-06 23:48:18 +0800 | [diff] [blame] | 77 | #if __FLASH_TOOL_DA__ |
| 78 | #define printf DBG_MSG |
| 79 | #define print DBG_MSG |
| 80 | #elif defined(RELEASE) |
| 81 | #if !__ETT__ |
| 82 | #undef printf |
| 83 | #define printf |
| 84 | #undef print |
| 85 | #define print |
| 86 | #endif |
| 87 | #endif |
| 88 | |
| 89 | #if FOR_DV_SIMULATION_USED |
| 90 | #define mcSHOW_DBG_MSG(_x_) {printf _x_;} |
| 91 | #define mcSHOW_DBG_MSG2(_x_) {printf _x_;} |
| 92 | #define mcSHOW_DBG_MSG3(_x_) {printf _x_;} |
| 93 | #define mcSHOW_DBG_MSG4(_x_) {printf _x_;} |
| 94 | #define mcSHOW_DBG_MSG5(_x_) |
| 95 | #define mcSHOW_DBG_MSG6(_x_) {printf _x_;} |
| 96 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 97 | #define mcSHOW_TIME_MSG(_x_) |
| 98 | #define mcSHOW_ERR_MSG(_x_) {printf _x_;} |
| 99 | #define mcSHOW_DUMP_INIT_RG_MSG(_x_) {printf _x_;} |
| 100 | #elif __ETT__ |
| 101 | #if QT_GUI_Tool |
| 102 | #if MRW_CHECK_ONLY |
| 103 | #define mcSHOW_DBG_MSG_tmp(...) {printf (__VA_ARGS__); if(fp_A60868){fprintf (fp_A60868,__VA_ARGS__);}} |
| 104 | #define mcSHOW_DBG_MSG_Dump(...) |
| 105 | #define mcSHOW_DBG_MSG(_x_) |
| 106 | #define mcSHOW_DBG_MSG2(_x_) |
| 107 | #define mcSHOW_DBG_MSG3(_x_) |
| 108 | #define mcSHOW_DBG_MSG4(_x_) |
| 109 | #define mcSHOW_DBG_MSG5(_x_) |
| 110 | #define mcSHOW_DBG_MSG6(_x_) |
| 111 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 112 | #define mcSHOW_TIME_MSG(_x_) |
| 113 | #define mcSHOW_ERR_MSG(_x_) |
| 114 | #define mcSHOW_DUMP_INIT_RG_MSG(_x_) |
| 115 | #define mcSHOW_MRW_MSG(_x_) {mcSHOW_DBG_MSG_tmp _x_;} |
| 116 | #else |
| 117 | #define mcSHOW_DBG_MSG_tmp(...) {printf (__VA_ARGS__); if(fp_A60868){fprintf (fp_A60868,__VA_ARGS__);}} |
| 118 | #define mcSHOW_DBG_MSG_Dump(...) {if(fp_A60868_RGDump){fprintf (fp_A60868_RGDump,__VA_ARGS__);}} |
| 119 | #define mcSHOW_DBG_MSG(_x_) {mcSHOW_DBG_MSG_tmp _x_;} |
| 120 | #define mcSHOW_DBG_MSG2(_x_) {mcSHOW_DBG_MSG_tmp _x_;} |
| 121 | #define mcSHOW_DBG_MSG3(_x_) {mcSHOW_DBG_MSG_tmp _x_;} |
| 122 | #define mcSHOW_DBG_MSG4(_x_) {mcSHOW_DBG_MSG_tmp _x_;} |
| 123 | #define mcSHOW_DBG_MSG5(_x_) |
| 124 | #define mcSHOW_DBG_MSG6(_x_) |
| 125 | #define mcSHOW_EYESCAN_MSG(_x_) {mcSHOW_DBG_MSG_tmp _x_;} |
| 126 | #define mcSHOW_TIME_MSG(_x_) |
| 127 | #define mcSHOW_ERR_MSG(_x_) {mcSHOW_DBG_MSG_tmp _x_;} |
| 128 | #define mcSHOW_DUMP_INIT_RG_MSG(_x_) |
| 129 | #endif |
| 130 | #elif (defined(DDR_INIT_TIME_PROFILING)) |
| 131 | #define mcSHOW_DBG_MSG(_x_) |
| 132 | #define mcSHOW_DBG_MSG2(_x_) |
| 133 | #define mcSHOW_DBG_MSG3(_x_) |
| 134 | #define mcSHOW_DBG_MSG4(_x_) |
| 135 | #define mcSHOW_DBG_MSG5(_x_) |
| 136 | #define mcSHOW_DBG_MSG6(_x_) |
| 137 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 138 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 139 | #define mcSHOW_TIME_MSG(_x_) {opt_print _x_;} |
| 140 | #define mcSHOW_ERR_MSG(_x_) |
| 141 | #elif DUMP_ALLSUH_RG |
| 142 | #define mcSHOW_DBG_MSG(_x_) {mcDELAY_US(50);opt_print _x_;} |
| 143 | #define mcSHOW_DBG_MSG2(_x_) {mcDELAY_US(50); opt_print _x_;} |
| 144 | #define mcSHOW_DBG_MSG3(_x_) |
| 145 | #define mcSHOW_DBG_MSG4(_x_) |
| 146 | #define mcSHOW_DBG_MSG5(_x_) |
| 147 | #define mcSHOW_DBG_MSG6(_x_) |
| 148 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 149 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 150 | #define mcSHOW_TIME_MSG(_x_) |
| 151 | #define mcSHOW_ERR_MSG(_x_) {mcDELAY_US(50);opt_print _x_;} |
| 152 | #elif defined(RELEASE) |
| 153 | #define mcSHOW_DBG_MSG(_x_) //{opt_print _x_;} |
| 154 | #define mcSHOW_DBG_MSG2(_x_) |
| 155 | #define mcSHOW_DBG_MSG3(_x_) |
| 156 | #define mcSHOW_DBG_MSG4(_x_) |
| 157 | #define mcSHOW_DBG_MSG5(_x_) |
| 158 | #define mcSHOW_DBG_MSG6(_x_) |
| 159 | #define mcSHOW_JV_LOG_MSG(_x_) {opt_print _x_;} |
| 160 | #define mcSHOW_EYESCAN_MSG(_x_) {opt_print _x_;} //mcSHOW_JV_LOG_MSG(_x_) is for vendor JV |
| 161 | #define mcSHOW_TIME_MSG(_x_) |
| 162 | #define mcSHOW_ERR_MSG(_x_) {opt_print _x_;} |
| 163 | #elif VENDER_JV_LOG |
| 164 | #define mcSHOW_DBG_MSG(_x_) |
| 165 | #define mcSHOW_DBG_MSG2(_x_) |
| 166 | #define mcSHOW_DBG_MSG3(_x_) |
| 167 | #define mcSHOW_DBG_MSG4(_x_) |
| 168 | #define mcSHOW_DBG_MSG5(_x_) |
| 169 | #define mcSHOW_DBG_MSG6(_x_) |
| 170 | #define mcSHOW_JV_LOG_MSG(_x_) {opt_print _x_;} //mcSHOW_JV_LOG_MSG(_x_) is for vendor JV |
| 171 | #define mcSHOW_EYESCAN_MSG(_x_) {opt_print _x_;} //mcSHOW_JV_LOG_MSG(_x_) is for vendor JV |
| 172 | #define mcSHOW_TIME_MSG(_x_) |
| 173 | #define mcSHOW_ERR_MSG(_x_) |
| 174 | #elif SW_CHANGE_FOR_SIMULATION |
| 175 | #define mcSHOW_DBG_MSG(_x_) |
| 176 | #define mcSHOW_DBG_MSG2(_x_) |
| 177 | #define mcSHOW_DBG_MSG3(_x_) |
| 178 | #define mcSHOW_DBG_MSG4(_x_) |
| 179 | #define mcSHOW_DBG_MSG5(_x_) |
| 180 | #define mcSHOW_DBG_MSG6(_x_) |
| 181 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 182 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 183 | #define mcSHOW_TIME_MSG(_x_) |
| 184 | #define mcSHOW_ERR_MSG(_x_) |
| 185 | #elif defined(DUMP_INIT_RG_LOG_TO_DE) |
| 186 | #define mcSHOW_DBG_MSG(_x_) |
| 187 | #define mcSHOW_DBG_MSG2(_x_) |
| 188 | #define mcSHOW_DBG_MSG3(_x_) |
| 189 | #define mcSHOW_DBG_MSG4(_x_) |
| 190 | #define mcSHOW_DBG_MSG5(_x_) |
| 191 | #define mcSHOW_DBG_MSG6(_x_) |
| 192 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 193 | #define mcSHOW_DUMP_INIT_RG_MSG(_x_) {gpt_busy_wait_us(50); print _x_;} |
| 194 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 195 | #define mcSHOW_TIME_MSG(_x_) |
| 196 | #define mcSHOW_ERR_MSG(_x_) |
| 197 | #elif MRW_CHECK_ONLY |
| 198 | #define mcSHOW_DBG_MSG(_x_) |
| 199 | #define mcSHOW_DBG_MSG2(_x_) |
| 200 | #define mcSHOW_DBG_MSG3(_x_) |
| 201 | #define mcSHOW_DBG_MSG4(_x_) |
| 202 | #define mcSHOW_DBG_MSG5(_x_) |
| 203 | #define mcSHOW_DBG_MSG6(_x_) |
| 204 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 205 | #define mcSHOW_MRW_MSG(_x_) {printf _x_;} |
| 206 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 207 | #define mcSHOW_TIME_MSG(_x_) |
| 208 | #define mcSHOW_ERR_MSG(_x_) |
| 209 | #else // ETT real chip |
| 210 | #define mcSHOW_DBG_MSG(_x_) {mcDELAY_US(10); print _x_;} |
| 211 | #define mcSHOW_DBG_MSG2(_x_) {mcDELAY_US(10); print _x_;} |
| 212 | #define mcSHOW_DBG_MSG3(_x_) {mcDELAY_US(10); print _x_;} |
| 213 | #define mcSHOW_DBG_MSG4(_x_) |
| 214 | #define mcSHOW_DBG_MSG5(_x_) |
| 215 | #define mcSHOW_DBG_MSG6(_x_) |
| 216 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 217 | #define mcSHOW_EYESCAN_MSG(_x_) {if (gEye_Scan_color_flag) {mcDELAY_US(200);}; print _x_;} |
| 218 | #define mcSHOW_TIME_MSG(_x_) |
| 219 | #define mcSHOW_ERR_MSG(_x_) {print _x_;} |
| 220 | #endif |
| 221 | #else // preloader |
| 222 | #if defined(DDR_INIT_TIME_PROFILING) |
| 223 | #define mcSHOW_DBG_MSG(_x_) |
| 224 | #define mcSHOW_DBG_MSG2(_x_) |
| 225 | #define mcSHOW_DBG_MSG3(_x_) |
| 226 | #define mcSHOW_DBG_MSG4(_x_) |
| 227 | #define mcSHOW_DBG_MSG5(_x_) |
| 228 | #define mcSHOW_DBG_MSG6(_x_) |
| 229 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 230 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 231 | #define mcSHOW_TIME_MSG(_x_) {print _x_;} |
| 232 | #define mcSHOW_ERR_MSG(_x_) |
| 233 | #elif defined(TARGET_BUILD_VARIANT_ENG) //&& !defined(MTK_EFUSE_WRITER_SUPPORT) && !CFG_TEE_SUPPORT && !MTK_EMMC_SUPPORT |
| 234 | #define mcSHOW_DBG_MSG(_x_) {print _x_;} |
| 235 | #define mcSHOW_DBG_MSG2(_x_) {print _x_;} |
| 236 | #define mcSHOW_DBG_MSG3(_x_) {print _x_;} |
| 237 | #define mcSHOW_DBG_MSG4(_x_) |
| 238 | #define mcSHOW_DBG_MSG5(_x_) |
| 239 | #define mcSHOW_DBG_MSG6(_x_) {print _x_;} |
| 240 | #if (CFG_DRAM_LOG_TO_STORAGE) |
| 241 | #define mcSHOW_EYESCAN_MSG(_x_) {print _x_;} |
| 242 | #define mcSHOW_JV_LOG_MSG(_x_) {print _x_;} |
| 243 | #else |
| 244 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 245 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 246 | #endif |
| 247 | #define mcSHOW_TIME_MSG(_x_) |
| 248 | #define mcSHOW_ERR_MSG(_x_) {print _x_;} |
| 249 | #else |
Arthur Heymans | e9d9c1e | 2023-04-19 10:08:36 +0200 | [diff] [blame^] | 250 | #define mcSHOW_DBG_MSG(_x_) { if (0) { print _x_; } } |
| 251 | #define mcSHOW_DBG_MSG2(_x_) { if (0) { print _x_; } } |
Ryan Chuang | b0b8dc3 | 2021-05-06 23:48:18 +0800 | [diff] [blame] | 252 | #define mcSHOW_DBG_MSG3(_x_) |
Arthur Heymans | e9d9c1e | 2023-04-19 10:08:36 +0200 | [diff] [blame^] | 253 | #define mcSHOW_DBG_MSG4(_x_) { if (0) { print _x_; } } |
Ryan Chuang | b0b8dc3 | 2021-05-06 23:48:18 +0800 | [diff] [blame] | 254 | #define mcSHOW_DBG_MSG5(_x_) |
| 255 | #define mcSHOW_DBG_MSG6(_x_) |
| 256 | #define mcSHOW_JV_LOG_MSG(_x_) |
| 257 | #define mcSHOW_EYESCAN_MSG(_x_) |
| 258 | #define mcSHOW_TIME_MSG(_x_) |
| 259 | #define mcSHOW_ERR_MSG(_x_) {print _x_;} |
| 260 | #endif |
| 261 | #endif |
| 262 | |
| 263 | |
| 264 | |
| 265 | #if QT_GUI_Tool ==1 |
| 266 | #define mcFPRINTF(_x_) fprintf _x_; |
| 267 | #else |
| 268 | #define mcFPRINTF(_x_) |
| 269 | #endif |
| 270 | |
| 271 | #ifndef ARRAY_SIZE |
| 272 | #define ARRAY_SIZE(x) (sizeof (x) / sizeof (x[0])) |
| 273 | #endif |
| 274 | |
| 275 | #define enter_function() \ |
| 276 | ({mcSHOW_DBG_MSG(("enter %s\n", __FUNCTION__));}) |
| 277 | |
| 278 | #define exit_function() \ |
| 279 | ({mcSHOW_DBG_MSG(("exit %s\n", __FUNCTION__));}) |
| 280 | |
| 281 | extern int dump_log; |
| 282 | #endif // _DRAMC_COMMON_H_ |