Debian Codegraph @

src/vendorcode/mediatek/mt8192/dramc/dramc_pi_main.c

raw symbols SCIP
1 /* SPDX-License-Identifier: BSD-3-Clause */
2
3 #include "dramc_top.h"
4
5 #include "dramc_actiming.h"
6 #include "dramc_common.h"
7 #include "dramc_dv_init.h"
8 #include "dramc_int_global.h"
9 #include <emi.h>
10 #include "x_hal_io.h"
11 #include "sv_c_data_traffic.h"
12 #include "dramc_pi_api.h"
13 #include <soc/dramc_param.h>
14 #include <soc/emi.h>
15 #include <types.h>
16
17 DRAMC_CTX_T dram_ctx_chb;
18
19 #if (FOR_DV_SIMULATION_USED == 1)
20 U8 gu1BroadcastIsLP4 = TRUE;
21 #endif
22
23 bool gAndroid_DVFS_en = TRUE;
24 bool gUpdateHighestFreq = FALSE;
25
26 #define DV_SIMULATION_BYTEMODE 0
27 #define DV_SIMULATION_LP5_TRAINING_MODE1 1
28 #define DV_SIMULATION_LP5_CBT_PHASH_R 1
29
30 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
31 SAVE_TIME_FOR_CALIBRATION_T SavetimeData;
32 #endif
33
34 U8 gHQA_Test_Freq_Vcore_Level = 0; // 0: only 1 freq , others are multi freq 1: low vcore 2: high vcore
35
36 #define ENABLE_DRAM_SINGLE_FREQ_SELECT 0xFF // 0xFF=all freq by gFreqTbl. The 0x"X" != 0xFF for single freq by gFreqTbl index, ex: 0x3 for DDR3733
37
38 DRAM_DFS_FREQUENCY_TABLE_T gFreqTbl[DRAM_DFS_SHUFFLE_MAX] = {
39 {LP4_DDR3200 /*0*/, DIV8_MODE, SRAM_SHU1, DUTY_LAST_K, VREF_CALI_OFF, CLOSE_LOOP_MODE}, // highest freq of term group (3733) must k first.
40 {LP4_DDR4266 /*1*/, DIV8_MODE, SRAM_SHU0, DUTY_NEED_K, VREF_CALI_ON, CLOSE_LOOP_MODE}, // highest freq of term group (3733) must k first.
41 {LP4_DDR800 /*2*/, DIV4_MODE, SRAM_SHU6, DUTY_DEFAULT, VREF_CALI_OFF, SEMI_OPEN_LOOP_MODE}, //Darren: DDR1600 for MRW (DramcModeRegInit_LP4 and CBT)
42 {LP4_DDR1866 /*3*/, DIV8_MODE, SRAM_SHU3, DUTY_LAST_K, VREF_CALI_OFF, CLOSE_LOOP_MODE}, // highest freq of unterm group (2400) must k first.
43 {LP4_DDR1200 /*4*/, DIV8_MODE, SRAM_SHU5, DUTY_LAST_K, VREF_CALI_OFF, CLOSE_LOOP_MODE}, // highest freq of unterm group (2400) must k first.
44 {LP4_DDR2400 /*5*/, DIV8_MODE, SRAM_SHU2, DUTY_NEED_K, VREF_CALI_ON, CLOSE_LOOP_MODE}, // highest freq of unterm group (2400) must k first.
45 {LP4_DDR1600 /*6*/, DIV8_MODE, SRAM_SHU4, DUTY_DEFAULT, VREF_CALI_ON, CLOSE_LOOP_MODE}, //Darren: DDR1600 for MRW (DramcModeRegInit_LP4 and CBT)
46 };
47
48
49 DRAMC_CTX_T DramCtx_LPDDR4 =
50 {
51 CHANNEL_SINGLE, // Channel number
52 CHANNEL_A, // DRAM_CHANNEL
53 RANK_DUAL, //DRAM_RANK_NUMBER_T
54 RANK_0, //DRAM_RANK_T
55
56 #ifdef MTK_FIXDDR1600_SUPPORT
57 LP4_DDR1600,
58 #else
59 #if __FLASH_TOOL_DA__
60 LP4_DDR1600,
61 #else
62 #if (DV_SIMULATION_LP4 == 1)
63 LP4_DDR1600,
64 #else
65 LP5_DDR3200,
66 #endif
67 #endif
68 #endif
69 DRAM_DFS_SHUFFLE_1,
70 #if DV_SIMULATION_LP4
71 TYPE_LPDDR4X, // DRAM_DRAM_TYPE_T
72 #else
73 TYPE_LPDDR5,
74 #endif
75 FSP_0 , //// DRAM Fast switch point type, only for LP4, useless in LP3
76 ODT_OFF,
77 {CBT_NORMAL_MODE, CBT_NORMAL_MODE}, // bring up LP4X rank0 & rank1 use normal mode
78 #if ENABLE_READ_DBI
79 {DBI_OFF,DBI_ON}, //read DBI
80 #else
81 {DBI_OFF,DBI_OFF}, //read DBI
82 #endif
83 #if ENABLE_WRITE_DBI
84 {DBI_OFF,DBI_ON}, // write DBI
85 #else
86 {DBI_OFF,DBI_OFF}, // write DBI
87 #endif
88 DATA_WIDTH_16BIT, // DRAM_DATA_WIDTH_T
89 DEFAULT_TEST2_1_CAL, // test2_1;
90 DEFAULT_TEST2_2_CAL, // test2_2;
91 #if ENABLE_K_WITH_WORST_SI_UI_SHIFT
92 TEST_WORST_SI_PATTERN, // test_pattern;
93 #else
94 TEST_XTALK_PATTERN,
95 #endif
96 #if (DV_SIMULATION_LP4 == 1)
97 800, // frequency
98 800, // freqGroup
99 #else
100 1600,
101 1600,
102 #endif
103 0x88, //vendor_id initial value
104 REVISION_ID_MAGIC,
105 0xff, //density
106 {0,0},
107 0, // u2num_dlycell_perT;
108 270, // u2DelayCellTimex100;
109
110 #if PRINT_CALIBRATION_SUMMARY
111 //aru4CalResultFlag[CHANNEL_NUM][RANK_MAX]
112 {{0,}},
113 //aru4CalExecuteFlag[CHANNEL_NUM][RANK_MAX]
114 {{0,}},
115 1,
116 0,
117 #endif
118 {0}, //BOOL arfgWriteLevelingInitShif;
119 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
120 FALSE, //femmc_Ready
121 0,
122 0,
123 0,
124 &SavetimeData,
125 #endif
126 &gFreqTbl[DRAM_DFS_SHUFFLE_MAX-1], // default is DDR1600 1:8 mode
127 DRAM_DFS_REG_SHU0,
128 TRAINING_MODE2,
129 CBT_PHASE_RISING,
130 0, //new CBT pattern
131 PHYPLL_MODE,
132 DBI_OFF,
133 FSP_MAX,
134 PINMUX_EMCP,
135 {DISABLE,DISABLE}, // disable 10GB
136 0,
137 };
138
139
140
141 #if defined(DDR_INIT_TIME_PROFILING) || (__ETT__ && SUPPORT_SAVE_TIME_FOR_CALIBRATION)
142 DRAMC_CTX_T gTimeProfilingDramCtx;
143 U8 gtime_profiling_flag = 0;
144 #endif
145
146 void vSetVcoreByFreq(DRAMC_CTX_T *p)
147 {
148 #if 1//def MTK_PMIC_MT6359
149 #if (FOR_DV_SIMULATION_USED==0 && SW_CHANGE_FOR_SIMULATION==0)
150 #if __FLASH_TOOL_DA__
151 dramc_set_vcore_voltage(725000);
152 #else
153 unsigned int vio18, vcore, vdram, vddq, vmddr;
154
155 vio18 = vcore = vdram = vddq = vmddr = 0;
156 (void)vio18;
157
158 #if __ETT__
159 hqa_set_voltage_by_freq(p, &vio18, &vcore, &vdram, &vddq, &vmddr);
160 #elif 0//defined(VCORE_BIN)
161 switch (vGet_Current_ShuLevel(p)) {
162 case SRAM_SHU0: //4266
163 #ifdef VOLTAGE_SEL
164 vcore = vcore_voltage_select(KSHU0);
165 if (!vcore)
166 #endif
167 vcore = get_vcore_uv_table(0);
168 break;
169 case SRAM_SHU1: //3200
170 #ifdef VOLTAGE_SEL
171 vcore = vcore_voltage_select(KSHU1);
172 if (!vcore)
173 #endif
174 vcore = (get_vcore_uv_table(0) + get_vcore_uv_table(1)) >> 1;
175 break;
176 case SRAM_SHU2: //2400
177 case SRAM_SHU3: //1866
178 #ifdef VOLTAGE_SEL
179 vcore = vcore_voltage_select(KSHU2);
180 if (!vcore)
181 #endif
182 vcore = (get_vcore_uv_table(0) + get_vcore_uv_table(2)) >> 1;
183 break;
184 case SRAM_SHU4: //1600
185 case SRAM_SHU5: //1200
186 case SRAM_SHU6: //800
187 #ifdef VOLTAGE_SEL
188 vcore = vcore_voltage_select(KSHU4);
189 if (!vcore)
190 #endif
191 vcore = (get_vcore_uv_table(0) + get_vcore_uv_table(3)) >> 1;
192 break;
193 }
194 #else
195 switch (vGet_Current_ShuLevel(p)) {
196 case SRAM_SHU0: // 4266
197 #ifdef VOLTAGE_SEL
198 vcore = vcore_voltage_select(KSHU0);
199 #else
200 vcore = SEL_PREFIX_VCORE(LP4, KSHU0);
201 #endif
202 break;
203 case SRAM_SHU1: // 3200
204 #ifdef VOLTAGE_SEL
205 vcore = vcore_voltage_select(KSHU1);
206 #else
207 vcore = SEL_PREFIX_VCORE(LP4, KSHU1);
208 #endif
209 break;
210 case SRAM_SHU2: // 2400
211 case SRAM_SHU3: //1866
212 #ifdef VOLTAGE_SEL
213 vcore = vcore_voltage_select(KSHU2);
214 #else
215 vcore = SEL_PREFIX_VCORE(LP4, KSHU2);
216 #endif
217 break;
218 case SRAM_SHU4: //1600
219 case SRAM_SHU5: //1200
220 case SRAM_SHU6: //800
221 #ifdef VOLTAGE_SEL
222 vcore = vcore_voltage_select(KSHU4);
223 #else
224 vcore = SEL_PREFIX_VCORE(LP4, KSHU4);
225 #endif
226 break;
227 default:
228 return;
229 }
230 #endif
231
232 if (vcore)
233 dramc_set_vcore_voltage(vcore);
234
235 #if defined(DRAM_HQA)
236 vio18 = SEL_VIO18;
237 if (vio18)
238 dramc_set_vio18_voltage(vio18);
239
240 vdram = SEL_PREFIX_VDRAM(LP4);
241 if (vdram)
242 dramc_set_vdram_voltage(p->dram_type, vdram);
243
244 vddq = SEL_PREFIX_VDDQ;
245 if (vddq)
246 dramc_set_vddq_voltage(p->dram_type, vddq);
247
248 vmddr = SEL_PREFIX_VMDDR;
249 if (vmddr)
250 dramc_set_vmddr_voltage(vmddr);
251 #endif
252
253 #ifdef FOR_HQA_REPORT_USED
254 switch (vGet_Current_ShuLevel(p)) {
255 case SRAM_SHU0: //3733
256 case SRAM_SHU1: //3200
257 case SRAM_SHU2: //2400
258 case SRAM_SHU3: //1866
259 case SRAM_SHU4: //1600
260 case SRAM_SHU5: //1200
261 case SRAM_SHU6: //800
262 gHQA_Test_Freq_Vcore_Level = 0; //only 1 freq
263 break;
264 default:
265 print("[HQA] undefined shuffle level for Vcore (SHU%d)\r\n", vGet_Current_ShuLevel(p));
266 #if __ETT__
267 while(1);
268 #endif
269 break;
270 }
271 #endif
272
273 #ifndef DDR_INIT_TIME_PROFILING
274 print("Read voltage for %d, %d\n", p->frequency, vGet_Current_ShuLevel(p));
275 print("Vio18 = %d\n", dramc_get_vio18_voltage());
276 print("Vcore = %d\n", dramc_get_vcore_voltage());
277 print("Vdram = %d\n", dramc_get_vdram_voltage(p->dram_type));
278 print("Vddq = %d\n", dramc_get_vddq_voltage(p->dram_type));
279 print("Vmddr = %d\n", dramc_get_vmddr_voltage());
280 #endif
281 #endif
282 #endif
283 #endif
284 }
285
286 U32 vGetVoltage(DRAMC_CTX_T *p, U32 get_voltage_type)
287 {
288 #if (defined(DRAM_HQA) || __ETT__) && (FOR_DV_SIMULATION_USED == 0)
289 if (get_voltage_type==0)
290 return dramc_get_vcore_voltage();
291
292 if (get_voltage_type==1)
293 return dramc_get_vdram_voltage(p->dram_type);
294
295 if (get_voltage_type==2)
296 return dramc_get_vddq_voltage(p->dram_type);
297
298 if (get_voltage_type==3)
299 return dramc_get_vio18_voltage();
300 if (get_voltage_type==4)
301 return dramc_get_vmddr_voltage();
302
303 #endif
304
305 return 0;
306 }
307
308 #ifdef FOR_HQA_TEST_USED
309 VCORE_DELAYCELL_T gVcoreDelayCellTable[49]={ {500000, 512},
310 {506250, 496},
311 {512500, 482},
312 {518750, 469},
313 {525000, 457},
314 {531250, 445},
315 {537500, 434},
316 {543750, 423},
317 {550000, 412},
318 {556250, 402},
319 {562500, 393},
320 {568750, 384},
321 {575000, 377},
322 {581250, 369},
323 {587500, 362},
324 {593750, 355},
325 {600000, 348},
326 {606250, 341},
327 {612500, 335},
328 {618750, 328},
329 {625000, 322},
330 {631250, 317},
331 {637500, 312},
332 {643750, 307},
333 {650000, 302},
334 {656250, 297},
335 {662500, 292},
336 {668750, 288},
337 {675000, 284},
338 {681250, 280},
339 {687500, 276},
340 {693750, 272},
341 {700000, 269},
342 {706250, 265},
343 {712500, 262},
344 {718750, 258},
345 {725000, 255},
346 {731250, 252},
347 {737500, 249},
348 {743750, 246},
349 {750000, 243},
350 {756250, 241},
351 {762500, 238},
352 {768750, 236},
353 {775000, 233},
354 {781250, 231},
355 {787500, 229},
356 {793750, 227},
357 {800000, 225},
358 //{825000, 718},
359 //{831250, 717},
360 //{837500, 715},
361 //{843750, 713},
362 //{850000, 708},
363 //{856250, 705},
364 //{862500, 702},
365 //{868750, 700},
366 //{875000, 698}
367 };
368
369 void GetVcoreDelayCellTimeFromTable(DRAMC_CTX_T *p)
370 {
371 U32 channel_i, i;
372 U32 get_vcore = 0;
373 U16 u2gdelay_cell_ps = 0;
374 U8 u1delay_cell_cnt = 0;
375 VCORE_DELAYCELL_T *pVcoreDelayCellTable;
376
377 #if (defined(DRAM_HQA) || __ETT__) && (FOR_DV_SIMULATION_USED == 0)
378 #if 1//__Petrus_TO_BE_PORTING__
379 get_vcore = dramc_get_vcore_voltage();
380 #endif
381 #endif
382
383 pVcoreDelayCellTable = (VCORE_DELAYCELL_T *)gVcoreDelayCellTable;
384 u1delay_cell_cnt = sizeof(gVcoreDelayCellTable)/sizeof(gVcoreDelayCellTable[0]);
385
386 for(i=0; i<u1delay_cell_cnt; i++)
387 {
388 if (get_vcore >= pVcoreDelayCellTable[i].u2Vcore)
389 {
390 u2gdelay_cell_ps = pVcoreDelayCellTable[i].u2DelayCell;
391 }
392 }
393
394 msg("[GetVcoreDelayCellTimeFromTable(%d)] VCore=%d(x100), DelayCell=%d(x100)\n", u1delay_cell_cnt, get_vcore, u2gdelay_cell_ps);
395
396 for(channel_i=CHANNEL_A; channel_i < p->support_channel_num; channel_i++)
397 {
398 u2gdelay_cell_ps_all[get_shuffleIndex_by_Freq(p)][channel_i] = u2gdelay_cell_ps;
399 u4gVcore[get_shuffleIndex_by_Freq(p)] = get_vcore/1000;
400 }
401 }
402 #endif
403
404 ///TODO: wait for porting +++
405 #ifdef FIRST_BRING_UP
406 void Test_Broadcast_Feature(DRAMC_CTX_T *p)
407 {
408 U32 u4RegBackupAddress[] =
409 {
410 (DRAMC_REG_SHURK_SELPH_DQ2),
411 (DRAMC_REG_SHURK_SELPH_DQ2 + SHIFT_TO_CHB_ADDR),
412
413 (DDRPHY_REG_SHU_RK_B0_DQ0),
414 (DDRPHY_REG_SHU_RK_B0_DQ0 + SHIFT_TO_CHB_ADDR),
415 };
416 U32 read_value;
417 U32 backup_broadcast;
418
419 backup_broadcast = GetDramcBroadcast();
420
421 DramcBroadcastOnOff(DRAMC_BROADCAST_OFF);
422
423 DramcBackupRegisters(p, u4RegBackupAddress, sizeof(u4RegBackupAddress) / sizeof(U32));
424
425 DramcBroadcastOnOff(DRAMC_BROADCAST_ON);
426
427 vIO32Write4B(DRAMC_REG_SHURK_SELPH_DQ2, 0xA55A00FF);
428 vIO32Write4B(DDRPHY_REG_SHU_RK_B0_DQ0, 0xA55A00FF);
429
430 read_value = u4IO32Read4B(DRAMC_REG_SHURK_SELPH_DQ2 + SHIFT_TO_CHB_ADDR);
431 if (read_value != 0xA55A00FF)
432 {
433 err("Check Erro! Broad Cast CHA RG to CHB Fail!!\n");
434 while (1);
435 }
436
437 read_value = u4IO32Read4B(DDRPHY_REG_SHU_RK_B0_DQ0 + SHIFT_TO_CHB_ADDR);
438 if (read_value != 0xA55A00FF)
439 {
440 err("Check Erro! Broad Cast CHA RG to CHB Fail!!\n");
441 while (1);
442 }
443
444 DramcBroadcastOnOff(DRAMC_BROADCAST_OFF);
445
446 DramcRestoreRegisters(p, u4RegBackupAddress, sizeof(u4RegBackupAddress) / sizeof(U32));
447
448 DramcBroadcastOnOff(backup_broadcast);
449 }
450 #endif
451
452 #ifdef ENABLE_MIOCK_JMETER
453 U8 gPRE_MIOCK_JMETER_HQA_USED_flag=0;
454
455 static void Set_PRE_MIOCK_JMETER_HQA_USED_flag(U8 value)
456 {
457 gPRE_MIOCK_JMETER_HQA_USED_flag = value;
458 }
459
460 void Get_RX_DelayCell(DRAMC_CTX_T *p)
461 {
462 #if defined(FOR_HQA_REPORT_USED) && (FOR_DV_SIMULATION_USED==0) && (SW_CHANGE_FOR_SIMULATION==0)
463 if (gHQALOG_RX_delay_cell_ps_075V == 0)
464 {
465 #if __ETT__
466 msg("RX delay cell calibration (%d):\n", hqa_vmddr_class);
467
468 switch (hqa_vmddr_class)
469 {
470 case 1:
471 dramc_set_vcore_voltage(_SEL_PREFIX(VMDDR, HV, LP4));
472 break;
473 case 2:
474 dramc_set_vcore_voltage(_SEL_PREFIX(VMDDR, NV, LP4));
475 break;
476 case 3:
477 dramc_set_vcore_voltage(_SEL_PREFIX(VMDDR, LV, LP4));
478 break;
479 }
480 #else
481 // set vcore to RX used 0.75V
482 dramc_set_vcore_voltage(SEL_PREFIX_VMDDR); //set vmddr voltage to vcore to K RX delay cell
483 #endif
484
485 DramcMiockJmeter(p);
486
487 gHQALOG_RX_delay_cell_ps_075V = u2gdelay_cell_ps;
488
489 // set vocre back
490 vSetVcoreByFreq(p);
491 }
492 #endif
493 }
494
495 void PRE_MIOCK_JMETER_HQA_USED(DRAMC_CTX_T *p)
496 {
497 U32 backup_freq_sel, backup_channel;
498 U32 channel_idx;
499
500 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
501 if(p->femmc_Ready==1)
502 {
503 for(channel_idx=CHANNEL_A; channel_idx<p->support_channel_num; channel_idx++)
504 {
505 //for (shuffleIdx = DRAM_DFS_SHUFFLE_1; shuffleIdx < DRAM_DFS_SHUFFLE_MAX; shuffleIdx++)
506 {
507 u2g_num_dlycell_perT_all[p->shu_type][channel_idx] = p->pSavetimeData->u2num_dlycell_perT;
508 u2gdelay_cell_ps_all[p->shu_type][channel_idx] = p->pSavetimeData->u2DelayCellTimex100;
509 }
510 }
511
512 p->u2num_dlycell_perT = p->pSavetimeData->u2num_dlycell_perT;
513 p->u2DelayCellTimex100 = p->pSavetimeData->u2DelayCellTimex100;
514 return;
515 }
516 #endif
517
518
519 backup_freq_sel = vGet_PLL_FreqSel(p);
520 backup_channel = p->channel;
521
522 msg3("[JMETER_HQA]\n");
523 Set_PRE_MIOCK_JMETER_HQA_USED_flag(1);
524
525 vSetPHY2ChannelMapping(p, CHANNEL_A);
526
527 DramcMiockJmeterHQA(p);
528
529 vSetPHY2ChannelMapping(p, backup_channel);
530
531 Set_PRE_MIOCK_JMETER_HQA_USED_flag(0);
532
533 vSet_PLL_FreqSel(p, backup_freq_sel);
534 }
535 #endif
536
537
538 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
539 #if !EMMC_READY
540 u32 g_dram_save_time_init_done[DRAM_DFS_SHUFFLE_MAX] = {0};
541 SAVE_TIME_FOR_CALIBRATION_T SaveTimeDataByShuffle[DRAM_DFS_SHUFFLE_MAX];
542 #endif
543 static DRAM_STATUS_T DramcSave_Time_For_Cal_End(DRAMC_CTX_T *p)
544 {
545 if (!u1IsLP4Family(p->dram_type))
546 return DRAM_FAIL;
547
548 if (p->femmc_Ready == 0)
549 {
550 #if EMMC_READY
551 write_offline_dram_calibration_data(p->shu_type, p->pSavetimeData);
552 msg("[FAST_K] Save calibration result to emmc\n");
553 #else
554 g_dram_save_time_init_done[p->shu_type] = 1;
555 memcpy(&(SaveTimeDataByShuffle[p->shu_type]), p->pSavetimeData, sizeof(SAVE_TIME_FOR_CALIBRATION_T));
556 msg("[FAST_K] Save calibration result to SW memory\n");
557 #endif
558 }
559 else
560 {
561 msg("[FAST_K] Bypass saving calibration result to emmc\n");
562 }
563
564 return DRAM_OK;
565 }
566
567 static DRAM_STATUS_T DramcSave_Time_For_Cal_Init(DRAMC_CTX_T *p)
568 {
569 if (!u1IsLP4Family(p->dram_type))
570 return DRAM_FAIL;
571
572 if (doe_get_config("fullk"))
573 return DRAM_FAIL;
574
575 // Parepare fask k data
576 #if EMMC_READY
577 // scy: only need to read emmc one time for each boot-up
578 //if (g_dram_save_time_init_done == 1)
579 // return DRAM_OK;
580 //else
581 // g_dram_save_time_init_done = 1;
582 if (read_offline_dram_calibration_data(p->shu_type, p->pSavetimeData) < 0)
583 {
584 p->femmc_Ready = 0;
585 memset(p->pSavetimeData, 0, sizeof(SAVE_TIME_FOR_CALIBRATION_T));
586 }
587 else
588 {
589 p->femmc_Ready = 1;
590 }
591
592 #else //EMMC is not avaliable, load off-line data
593
594 if (g_dram_save_time_init_done[p->shu_type] == 0)
595 {
596 p->femmc_Ready = 0;
597 memset(p->pSavetimeData, 0, sizeof(SAVE_TIME_FOR_CALIBRATION_T));
598 }
599 else
600 {
601 memcpy(p->pSavetimeData, &(SaveTimeDataByShuffle[p->shu_type]), sizeof(SAVE_TIME_FOR_CALIBRATION_T));
602 p->femmc_Ready = 1;
603 }
604 #endif
605
606 if (p->femmc_Ready == 1)
607 {
608 if (p->frequency < 1600)
609 { // freq < 1600, TX and RX tracking are disable. Therefore, bypass calibration.
610 p->Bypass_RDDQC = 1;
611 p->Bypass_RXWINDOW = 1;
612 p->Bypass_TXWINDOW = 1;
613 }
614 else
615 {
616 p->Bypass_RDDQC = 1;
617 p->Bypass_RXWINDOW = !ENABLE_RX_TRACKING;
618 p->Bypass_TXWINDOW = 0;
619 }
620
621 #if RUNTIME_SHMOO_RELEATED_FUNCTION
622 p->Bypass_RDDQC = 1;
623 p->Bypass_RXWINDOW = 1;
624 p->Bypass_TXWINDOW = 1;
625 #endif
626 }
627
628 #if EMMC_READY
629 msg("[FAST_K] DramcSave_Time_For_Cal_Init SHU%d, femmc_Ready=%d\n", p->shu_type, p->femmc_Ready);
630 #else
631 msg("[FAST_K] DramcSave_Time_For_Cal_Init SHU%d, Init_done=%d, femmc_Ready=%d\n", p->shu_type, g_dram_save_time_init_done[p->shu_type], p->femmc_Ready);
632 #endif
633 msg("[FAST_K] Bypass_RDDQC %d, Bypass_RXWINDOW=%d, Bypass_TXWINDOW=%d\n", p->Bypass_RDDQC, p->Bypass_RXWINDOW, p->Bypass_TXWINDOW);
634
635 return DRAM_OK;
636 }
637 #endif
638
639 #if ENABLE_RANK_NUMBER_AUTO_DETECTION
640 static void DramRankNumberDetection(DRAMC_CTX_T *p)
641 {
642 U8 u1RankBak;
643
644 u1RankBak = u1GetRank(p); // backup current rank setting
645
646 vSetPHY2ChannelMapping(p, CHANNEL_A); // when switching channel, must update PHY to Channel Mapping
647 vSetRank(p, RANK_1);
648
649 if (DramcWriteLeveling(p, AUTOK_ON, PI_BASED) == DRAM_OK)
650 {
651 p->support_rank_num = RANK_DUAL;
652 vIO32WriteFldAlign(DRAMC_REG_SA_RESERVE, 0, SA_RESERVE_SINGLE_RANK); //keep support_rank_num to reserved rg
653 }
654 else
655 {
656 p->support_rank_num = RANK_SINGLE;
657 vIO32WriteFldAlign(DRAMC_REG_SA_RESERVE, 1, SA_RESERVE_SINGLE_RANK); //keep support_rank_num to reserved rg
658 }
659 msg("[RankNumberDetection] %d\n", p->support_rank_num);
660
661 vSetRank(p, u1RankBak); // restore rank setting
662 }
663 #endif
664
665 static void UpdateGlobal10GBEnVariables(DRAMC_CTX_T *p)
666 {
667 p->u110GBEn[RANK_0] = (get_row_width_by_emi(RANK_0) >= 18) ? ENABLE : DISABLE;
668 p->u110GBEn[RANK_1] = (get_row_width_by_emi(RANK_1) >= 18) ? ENABLE : DISABLE;
669 //msg("[10GBEn] RANK0=%d, RANK1=%d\n", p->u110GBEn[RANK_0], p->u110GBEn[RANK_1]);
670 }
671
672 void vCalibration_Flow_For_MDL(DRAMC_CTX_T *p)
673 {
674 U8 u1RankMax;
675 S8 s1RankIdx;
676
677 #if GATING_ADJUST_TXDLY_FOR_TRACKING
678 DramcRxdqsGatingPreProcess(p);
679 #endif
680
681 if (p->support_rank_num == RANK_DUAL)
682 u1RankMax = RANK_MAX;
683 else
684 u1RankMax = RANK_1;
685
686 for (s1RankIdx = RANK_0; s1RankIdx < u1RankMax; s1RankIdx++)
687 {
688 vSetRank(p, s1RankIdx);
689
690 vAutoRefreshSwitch(p, ENABLE); //when doing gating, RX and TX calibration, auto refresh should be enable
691 dramc_rx_dqs_gating_cal(p, AUTOK_OFF, 0);
692 DramcRxWindowPerbitCal(p, PATTERN_RDDQC, NULL, AUTOK_OFF);
693
694 #if MRW_CHECK_ONLY
695 mcSHOW_MRW_MSG("\n==[MR Dump] %s==\n", __func__);
696 #endif
697 vAutoRefreshSwitch(p, DISABLE); //After gating, Rx and Tx calibration, auto refresh should be disable
698 }
699
700 vSetRank(p, RANK_0); // Set p's rank back to 0 (Avoids unexpected auto-rank offset calculation in u4RegBaseAddrTraslate())
701
702 #if GATING_ADJUST_TXDLY_FOR_TRACKING
703 DramcRxdqsGatingPostProcess(p);
704 #endif
705 }
706
707 static int GetDramInforAfterCalByMRR(DRAMC_CTX_T *p, DRAM_INFO_BY_MRR_T *DramInfo)
708 {
709 U8 u1RankIdx, u1DieNumber = 0;
710 U16 u2Density;
711 U16 u2MR7;
712 U16 u2MR8 = 0;
713 U64 u8Size = 0, u8Size_backup = 0;
714
715 if (p->revision_id != REVISION_ID_MAGIC)
716 return 0;
717
718 vSetPHY2ChannelMapping(p, CHANNEL_A);
719
720 // Read MR5 for Vendor ID
721 DramcModeRegReadByRank(p, RANK_0, 5, &(p->vendor_id));// for byte mode, don't show value of another die.
722 p->vendor_id &= 0xFF;
723 msg("[GetDramInforAfterCalByMRR] Vendor %x.\n", p->vendor_id);
724 // Read MR6 for Revision ID
725 DramcModeRegReadByRank(p, RANK_0, 6, &(p->revision_id));// for byte mode, don't show value of another die.
726 msg("[GetDramInforAfterCalByMRR] Revision %x.\n", p->revision_id);
727 // Read MR6 for Revision ID2
728 DramcModeRegReadByRank(p, RANK_0, 7, &u2MR7);// for byte mode, don't show value of another die.
729 msg("[GetDramInforAfterCalByMRR] Revision 2 %x.\n", u2MR7);
730 #if (!__ETT__) && (FOR_DV_SIMULATION_USED==0)
731 set_dram_mr(5, p->vendor_id);
732 set_dram_mr(6, p->revision_id);
733 set_dram_mr(7, u2MR7);
734 #endif
735 if (DramInfo != NULL)
736 {
737 DramInfo->u2MR5VendorID = p->vendor_id;
738 DramInfo->u2MR6RevisionID = p->revision_id;
739
740 for (u1RankIdx = 0; u1RankIdx < RANK_MAX; u1RankIdx++)
741 DramInfo->u8MR8RankSize[u1RankIdx] = 0;
742 }
743
744 // Read MR8 for dram density
745 for (u1RankIdx = 0; u1RankIdx < (p->support_rank_num); u1RankIdx++)
746 {
747 #if 0//PRINT_CALIBRATION_SUMMARY
748 if ((p->aru4CalExecuteFlag[u1ChannelIdx][u1RankIdx] != 0) && \
749 (p->aru4CalResultFlag[u1ChannelIdx][u1RankIdx] == 0))
750 #endif
751 {
752 DramcModeRegReadByRank(p, u1RankIdx, 0, &(gu2MR0_Value[u1RankIdx]));
753 msg("MR0 0x%x\n", gu2MR0_Value[u1RankIdx]);
754
755 DramcModeRegReadByRank(p, u1RankIdx, 8, &u2Density);
756 msg("MR8 0x%x\n", u2Density);
757 u2MR8 |= (u2Density & 0xFF) << (u1RankIdx * 8);
758
759 u1DieNumber = 1;
760 if (((u2Density >> 6) & 0x3) == 1) //OP[7:6] =0, x16 (normal mode)
761 u1DieNumber = 2;
762
763 u2Density = (u2Density >> 2) & 0xf;
764
765 switch (u2Density)
766 {
767 ///TODO: Darren, please check the value of u8Size.
768 case 0x0:
769 u8Size = 0x20000000; //4Gb = 512MB
770 //msg("[EMI]DRAM density = 4Gb\n");
771 break;
772 case 0x1:
773 u8Size = 0x30000000; //6Gb = 768MB
774 //msg("[EMI]DRAM density = 6Gb\n");
775 break;
776 case 0x2:
777 u8Size = 0x40000000; //8Gb = 1GB = 2^30 bytes = 0x40000000 bytes
778 //msg("[EMI]DRAM density = 8Gb\n");
779 break;
780 case 0x3:
781 u8Size = 0x60000000; //12Gb = 1.5GB = 3^30 bytes = 0x60000000 bytes
782 //msg("[EMI]DRAM density = 12Gb\n");
783 break;
784 case 0x4:
785 u8Size = 0x80000000; //16Gb = 2GB = 4^30 bytes = 0x80000000 bytes
786 //msg("[EMI]DRAM density = 16Gb\n");
787 break;
788 case 0x5:
789 u8Size = 0xc0000000; //24Gb = 3GB = 6^30 bytes = 0xc0000000 bytes
790 //msg("[EMI]DRAM density = 24Gb\n");
791 break;
792 case 0x6:
793 u8Size = 0x100000000L; //32Gb = 4GB = 8^30 bytes = 0x10000000 bytes
794 //msg("[EMI]DRAM density = 32Gb\n");
795 break;
796 default:
797 u8Size = 0; //reserved
798 }
799
800 if (u8Size_backup < u8Size) // find max dram size for vDramcACTimingOptimize
801 {
802 u8Size_backup = u8Size;
803 p->density = u2Density;
804 }
805
806 p->ranksize[u1RankIdx] = u8Size * u1DieNumber; //dram rank size = density * DieNumber
807
808 if (DramInfo != NULL)
809 {
810 DramInfo->u8MR8RankSize[u1RankIdx] = p->ranksize[u1RankIdx];
811 }
812 }
813 // 1GB = 2^30 bytes
814 // u8Size * (2^3) / (2^30) ==>Gb
815 msg("RK%d, DieNum %d, Density %dGb, RKsize %dGb.\n\n", u1RankIdx, u1DieNumber, (U32)(u8Size >> 27), (U32)(p->ranksize[u1RankIdx] >> 27));
816 }
817 #if (!__ETT__) && (FOR_DV_SIMULATION_USED==0)
818 set_dram_mr(8, u2MR8);
819 #endif
820 return 0;
821 }
822
823 static void vCalibration_Flow_LP4(DRAMC_CTX_T *p)
824 {
825 U8 u1RankMax;
826 S8 s1RankIdx;
827 //DRAM_STATUS_T VrefStatus;
828
829 #ifdef DDR_INIT_TIME_PROFILING
830 U32 CPU_Cycle;
831 TimeProfileBegin();
832 #endif
833
834 #if __Petrus_TO_BE_PORTING__
835 #if ENABLE_PHY_RX_INPUT_OFFSET // skip when bring up
836 ///TODO: no shuffle, only need to do once under highest freq.
837 if(p->frequency == u2DFSGetHighestFreq(p))
838 DramcRXInputBufferOffsetCal(p);
839
840 #ifdef DDR_INIT_TIME_PROFILING
841 CPU_Cycle=TimeProfileEnd();
842 time_msg("\tRX input cal takes %d us\n", CPU_Cycle);
843 TimeProfileBegin();
844 #endif
845 #endif
846 #endif
847
848
849 #if GATING_ADJUST_TXDLY_FOR_TRACKING
850 DramcRxdqsGatingPreProcess(p);
851 #endif
852
853 if (p->support_rank_num==RANK_DUAL)
854 u1RankMax = RANK_MAX;
855 else
856 u1RankMax = RANK_1;
857
858 //vAutoRefreshSwitch(p, DISABLE); //auto refresh is set as disable in LP4_DramcSetting, so don't need to disable again
859 vAutoRefreshSwitch(p, DISABLE);
860
861 #if 1//(SIMUILATION_CBT == 1)
862 for(s1RankIdx=RANK_0; s1RankIdx<u1RankMax; s1RankIdx++)
863 {
864 vSetRank(p, s1RankIdx);
865 #if PINMUX_AUTO_TEST_PER_BIT_CA
866 CheckCAPinMux(p);
867 #endif
868
869 CmdBusTrainingLP45(p, AUTOK_OFF);
870
871 #if ENABLE_EYESCAN_GRAPH
872 print_EYESCAN_LOG_message(p, 0); //draw CBT eyescan
873 #endif
874
875 #ifdef DDR_INIT_TIME_PROFILING
876 CPU_Cycle=TimeProfileEnd();
877 time_msg("\tRank %d CBT takes %d us\n", s1RankIdx, CPU_Cycle);
878 TimeProfileBegin();
879 #endif
880 }
881 vSetRank(p, RANK_0);
882
883 #if __Petrus_TO_BE_PORTING__
884 No_Parking_On_CLRPLL(p);
885 #endif
886
887 // The patch must to do after cbt training
888 ShuffleDfsToFSP1(p);
889 #endif
890
891 #if 0//(SIMULATION_WRITE_LEVELING == 1)
892 for(s1RankIdx=RANK_0; s1RankIdx<u1RankMax; s1RankIdx++)
893 {
894 vSetRank(p, s1RankIdx);
895
896 vAutoRefreshSwitch(p, DISABLE); //When doing WriteLeveling, should make sure that auto refresh is disable
897
898 #if (!WCK_LEVELING_FM_WORKAROUND)
899 if (u1IsLP4Family(p->dram_type))
900 #endif
901 {
902 if (!(u1IsLP4Div4DDR800(p) && (p->rank == RANK_1))) // skip for DDR800 rank1
903 {
904 msg("\n----->DramcWriteLeveling(PI) begin...\n");
905
906 DramcWriteLeveling(p, AUTOK_OFF, PI_BASED);
907
908 msg("DramcWriteLeveling(PI) end<-----\n\n");
909 }
910 }
911
912 #ifdef DDR_INIT_TIME_PROFILING
913 CPU_Cycle=TimeProfileEnd();
914 time_msg("\tRank %d Write leveling takes %d us\n", s1RankIdx, CPU_Cycle);
915 TimeProfileBegin();
916 #endif
917 }
918 vSetRank(p, RANK_0);
919
920 #if ENABLE_WDQS_MODE_2 // <=DDR1600 reduce PI change code time
921 if (!(u1IsLP4Div4DDR800(p)) && (p->frequency <= 800) && (p->support_rank_num == RANK_DUAL)) // skip DDR800semi, for DDR1200/DDR1600 only
922 WriteLevelingPosCal(p, PI_BASED);
923 #elif ENABLE_TX_WDQS // for WDQS mode 1 to avoid dual rank PI code incorrect
924 if (!(u1IsLP4Div4DDR800(p)) && (p->support_rank_num == RANK_DUAL))
925 WriteLevelingPosCal(p, PI_BASED);
926 #endif
927 #endif /* (SIMULATION_WRITE_LEVELING == 1) */
928
929 for(s1RankIdx=RANK_0; s1RankIdx<u1RankMax; s1RankIdx++)
930 {
931 vSetRank(p, s1RankIdx);
932
933 #if 1//(SIMULATION_WRITE_LEVELING == 1)
934 vAutoRefreshSwitch(p, DISABLE); //When doing WriteLeveling, should make sure that auto refresh is disable
935
936 #if (!WCK_LEVELING_FM_WORKAROUND)
937 if (u1IsLP4Family(p->dram_type))
938 #endif
939 {
940 if (!(u1IsLP4Div4DDR800(p) && (p->rank == RANK_1))) // skip for DDR800 rank1
941 {
942 msg("\n----->DramcWriteLeveling(PI) begin...\n");
943
944 DramcWriteLeveling(p, AUTOK_ON, PI_BASED);
945
946 msg("DramcWriteLeveling(PI) end<-----\n\n");
947 }
948 #ifdef DDR_INIT_TIME_PROFILING
949 CPU_Cycle=TimeProfileEnd();
950 time_msg("\tRank %d Write leveling takes %d us\n", s1RankIdx, CPU_Cycle);
951 TimeProfileBegin();
952 #endif
953 }
954 #endif /* (SIMULATION_WRITE_LEVELING == 1) */
955
956 vAutoRefreshSwitch(p, ENABLE); //when doing gating, RX and TX calibration, auto refresh should be enable
957
958 dramc_rx_dqs_gating_cal(p, AUTOK_OFF, 0);
959
960 #ifdef DDR_INIT_TIME_PROFILING
961 CPU_Cycle=TimeProfileEnd();
962 time_msg("\tRank %d Gating takes %d us\n", s1RankIdx, CPU_Cycle);
963 TimeProfileBegin();
964 #endif
965
966 DramcRxWindowPerbitCal(p, PATTERN_RDDQC, NULL, AUTOK_OFF);
967
968 #ifdef DDR_INIT_TIME_PROFILING
969 CPU_Cycle=TimeProfileEnd();
970 time_msg("\tRank %d RX RDDQC takes %d us\n", s1RankIdx, CPU_Cycle);
971 TimeProfileBegin();
972 #endif
973
974 #if MRW_CHECK_ONLY
975 mcSHOW_MRW_MSG("\n==[MR Dump] %s==\n", __func__);
976 #endif
977
978 DramcTxWindowPerbitCal(p, TX_DQ_DQS_MOVE_DQ_DQM, FALSE, AUTOK_OFF);
979
980 if (Get_Vref_Calibration_OnOff(p)==VREF_CALI_ON)
981 {
982 DramcTxWindowPerbitCal(p, TX_DQ_DQS_MOVE_DQ_ONLY, TRUE, AUTOK_OFF);
983 }
984
985 #if PINMUX_AUTO_TEST_PER_BIT_TX
986 CheckTxPinMux(p);
987 #endif
988 DramcTxWindowPerbitCal(p, TX_DQ_DQS_MOVE_DQ_ONLY, FALSE, AUTOK_OFF);
989
990 #if TX_K_DQM_WITH_WDBI
991 if (p->DBI_W_onoff[p->dram_fsp]==DBI_ON)
992 {
993 // K DQM with DBI_ON, and check DQM window spec.
994 //msg("[TX_K_DQM_WITH_WDBI] Step1: K DQM with DBI_ON, and check DQM window spec.\n\n");
995 vSwitchWriteDBISettings(p, DBI_ON);
996 DramcTxWindowPerbitCal((DRAMC_CTX_T *) p, TX_DQ_DQS_MOVE_DQM_ONLY, FALSE, AUTOK_OFF);
997 vSwitchWriteDBISettings(p, DBI_OFF);
998 }
999 #endif
1000
1001 #if ENABLE_EYESCAN_GRAPH
1002 Dramc_K_TX_EyeScan_Log(p);
1003 print_EYESCAN_LOG_message(p, 2); //draw TX eyescan
1004 #endif
1005
1006 #ifdef DDR_INIT_TIME_PROFILING
1007 CPU_Cycle=TimeProfileEnd();
1008 time_msg("\tRank %d TX calibration takes %d us\n", s1RankIdx, CPU_Cycle);
1009 TimeProfileBegin();
1010 #endif
1011
1012 DramcRxdatlatCal(p);
1013
1014 #ifdef DDR_INIT_TIME_PROFILING
1015 CPU_Cycle=TimeProfileEnd();
1016 time_msg("\tRank %d Datlat takes %d us\n", s1RankIdx, CPU_Cycle);
1017 TimeProfileBegin();
1018 #endif
1019
1020 #if PINMUX_AUTO_TEST_PER_BIT_RX
1021 CheckRxPinMux(p);
1022 #endif
1023 DramcRxWindowPerbitCal(p, PATTERN_TEST_ENGINE, NULL /*Set Vref = 0 to test*/, AUTOK_OFF);
1024
1025 #ifdef DDR_INIT_TIME_PROFILING
1026 CPU_Cycle=TimeProfileEnd();
1027 time_msg("\tRank %d RX calibration takes %d us\n", s1RankIdx, CPU_Cycle);
1028 TimeProfileBegin();
1029 #endif
1030 // DramcRxdqsGatingCal(p);
1031
1032 #if ENABLE_EYESCAN_GRAPH
1033 print_EYESCAN_LOG_message(p, 1); //draw RX eyescan
1034 #endif
1035
1036 #if (SIMULATION_RX_DVS == 1)
1037 if (p->frequency >=2133)
1038 DramcRxDVSWindowCal(p);
1039 #endif
1040
1041 #if TX_OE_CALIBATION && !ENABLE_WDQS_MODE_2
1042 if(p->frequency >= 1600)
1043 {
1044 DramcTxOECalibration(p);
1045 }
1046 #endif
1047
1048 vAutoRefreshSwitch(p, DISABLE);
1049
1050 #if ENABLE_TX_TRACKING
1051 DramcDQSOSCSetMR18MR19(p);
1052 DramcDQSOSCMR23(p);
1053 #endif
1054
1055 }
1056
1057 #if __Petrus_TO_BE_PORTING__
1058 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1059 if(p->femmc_Ready==0)
1060 #endif
1061 {
1062 if(p->frequency >= RX_VREF_DUAL_RANK_K_FREQ) // for 3733/4266
1063 {
1064 U8 u1ByteIdx, u1HighFreqRXVref[2];
1065 for(u1ByteIdx =0 ; u1ByteIdx<(p->data_width/DQS_BIT_NUMBER); u1ByteIdx++)
1066 {
1067 u1HighFreqRXVref[u1ByteIdx] = (gFinalRXVrefDQ[p->channel][RANK_0][u1ByteIdx] + gFinalRXVrefDQ[p->channel][RANK_1][u1ByteIdx]) >> 1;
1068 msg("RX Vref Byte%d (u1HighFreqRXVref) = %d = (%d+ %d)>>1\n", u1ByteIdx, u1HighFreqRXVref[u1ByteIdx], gFinalRXVrefDQ[p->channel][RANK_0][u1ByteIdx], gFinalRXVrefDQ[p->channel][RANK_1][u1ByteIdx]);
1069 }
1070
1071 for(s1RankIdx=RANK_0; s1RankIdx < u1RankMax; s1RankIdx++)
1072 {
1073 vSetRank(p, s1RankIdx);
1074 DramcRxWindowPerbitCal((DRAMC_CTX_T *) p, 1, u1HighFreqRXVref);
1075 }
1076 }
1077 }
1078 #endif
1079
1080 vSetRank(p, RANK_0); // Set p's rank back to 0 (Avoids unexpected auto-rank offset calculation in u4RegBaseAddrTraslate())
1081
1082 #if ENABLE_TX_TRACKING
1083 DramcDQSOSCShuSettings(p);
1084 #endif
1085
1086 #if (SIMULATION_GATING && GATING_ADJUST_TXDLY_FOR_TRACKING)
1087 DramcRxdqsGatingPostProcess(p);
1088 #endif
1089
1090 #if TDQSCK_PRECALCULATION_FOR_DVFS
1091 DramcDQSPrecalculation_preset(p);
1092 #endif
1093
1094 #if SIMULATION_RX_DVS
1095 if (p->frequency >=2133)
1096 DramcDramcRxDVSCalPostProcess(p);
1097 #endif
1098
1099 DramcDualRankRxdatlatCal(p);
1100
1101 #if RDSEL_TRACKING_EN
1102 if (p->frequency >= 1866)
1103 RDSELRunTimeTracking_preset(p);
1104 #endif
1105
1106 #if XRTWTW_NEW_CROSS_RK_MODE
1107 if(p->support_rank_num == RANK_DUAL)
1108 {
1109 XRTWTW_SHU_Setting(p);
1110 }
1111 #endif
1112
1113 #if __Petrus_TO_BE_PORTING__
1114 #if LJPLL_FREQ_DEBUG_LOG
1115 DDRPhyFreqMeter();
1116 #endif
1117 #endif
1118
1119 #ifdef DDR_INIT_TIME_PROFILING
1120 CPU_Cycle=TimeProfileEnd();
1121 time_msg("\tMisc takes %d us\n\n", s1RankIdx, CPU_Cycle);
1122 #endif
1123 }
1124
1125 static void vDramCalibrationSingleChannel(DRAMC_CTX_T *p)
1126 {
1127 #if 0//!__ETT__
1128 /*
1129 * Since DRAM calibration will cost much time,
1130 * kick wdt here to prevent watchdog timeout.
1131 */
1132 #if (FOR_DV_SIMULATION_USED == 0 && SW_CHANGE_FOR_SIMULATION == 0)
1133 mtk_wdt_restart();
1134 #endif
1135 #endif
1136
1137 vCalibration_Flow_LP4(p);
1138 }
1139
1140 void vDramCalibrationAllChannel(DRAMC_CTX_T *p)
1141 {
1142 U8 channel_idx, rank_idx;
1143
1144 #ifdef DDR_INIT_TIME_PROFILING
1145 U32 u4low_tick0, u4high_tick0, u4low_tick1, u4high_tick1;
1146 #if __ETT__
1147 u4low_tick0 = GPT_GetTickCount(&u4high_tick0);
1148 #else
1149 u4low_tick0 = get_timer(0);
1150 #endif
1151 #endif
1152
1153 vIO32WriteFldMulti_All(DDRPHY_REG_CA_CMD2, P_Fld(1, CA_CMD2_RG_TX_ARCMD_OE_DIS_CA)
1154 | P_Fld(0, CA_CMD2_RG_TX_ARCA_OE_TIE_SEL_CA)
1155 | P_Fld(0xff, CA_CMD2_RG_TX_ARCA_OE_TIE_EN_CA));
1156 for (channel_idx = CHANNEL_A; channel_idx < p->support_channel_num; channel_idx++)
1157 {
1158 vSetPHY2ChannelMapping(p, channel_idx);// when switching channel, must update PHY to Channel Mapping
1159 vIO32WriteFldMulti(DRAMC_REG_ADDR(DDRPHY_REG_CA_CMD2), P_Fld(0, CA_CMD2_RG_TX_ARCMD_OE_DIS_CA)
1160 | P_Fld(1, CA_CMD2_RG_TX_ARCA_OE_TIE_SEL_CA)
1161 | P_Fld(0xff, CA_CMD2_RG_TX_ARCA_OE_TIE_EN_CA));
1162 vDramCalibrationSingleChannel(p);
1163 }
1164
1165 vSetPHY2ChannelMapping(p, CHANNEL_A);
1166
1167 #if PRINT_CALIBRATION_SUMMARY
1168 vPrintCalibrationResult(p);
1169 #endif
1170
1171 #ifdef FOR_HQA_TEST_USED
1172 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1173 if (p->femmc_Ready == 1)
1174 {
1175 msg("\nCalibration fast K is enable, cannot show HQA measurement information\n");
1176 }
1177 else
1178 #endif
1179 print_HQA_measure_message(p);
1180 #endif
1181
1182 /* Enable/Disable calibrated rank's DBI function accordingly */
1183 #if ENABLE_READ_DBI
1184 //Read DBI ON
1185 vSetRank(p, RANK_0);
1186 vSetPHY2ChannelMapping(p, CHANNEL_A);
1187
1188 DramcReadDBIOnOff(p, p->DBI_R_onoff[p->dram_fsp]);
1189 #endif
1190
1191 #if ENABLE_WRITE_DBI
1192 // Just settle the DBI parameters which would be stored into shuffle space.
1193 if (p->DBI_W_onoff[p->dram_fsp])
1194 {
1195 for (channel_idx = CHANNEL_A; channel_idx < p->support_channel_num; channel_idx++)
1196 {
1197 vSetPHY2ChannelMapping(p, channel_idx);
1198
1199 for (rank_idx = RANK_0; rank_idx < RANK_MAX; rank_idx++)
1200 {
1201 vSetRank(p, rank_idx);
1202 DramcWriteShiftMCKForWriteDBI(p, -1); //Tx DQ/DQM -1 MCK for write DBI ON
1203 }
1204 vSetRank(p, RANK_0);
1205 }
1206 vSetPHY2ChannelMapping(p, CHANNEL_A);
1207
1208 // Improve Write DBI Power
1209 ApplyWriteDBIPowerImprove(p, ENABLE);
1210
1211 #if ENABLE_WRITE_DBI_Protect
1212 ApplyWriteDBIProtect(p, ENABLE);
1213 #endif
1214 }
1215
1216 DramcWriteDBIOnOff(p, p->DBI_W_onoff[p->dram_fsp]);
1217 #endif
1218
1219 #if TX_PICG_NEW_MODE
1220 TXPICGSetting(p);
1221 #endif
1222
1223 #if XRTRTR_NEW_CROSS_RK_MODE
1224 if (p->support_rank_num == RANK_DUAL)
1225 {
1226 XRTRTR_SHU_Setting(p);
1227 }
1228 #endif
1229
1230 #if (ENABLE_TX_TRACKING || TDQSCK_PRECALCULATION_FOR_DVFS)
1231 FreqJumpRatioCalculation(p);
1232 #endif
1233
1234 #ifdef TEMP_SENSOR_ENABLE
1235 DramcHMR4_Presetting(p);
1236 #endif
1237
1238 #if (ENABLE_PER_BANK_REFRESH == 1)
1239 DramcEnablePerBankRefresh(p, ON);
1240 #else
1241 DramcEnablePerBankRefresh(p, OFF);
1242 #endif
1243
1244 #if DRAMC_MODIFIED_REFRESH_MODE
1245 DramcModifiedRefreshMode(p);
1246 #endif
1247
1248 #if DRAMC_CKE_DEBOUNCE
1249 DramcCKEDebounce(p);
1250 #endif
1251
1252 #if ENABLE_TX_TRACKING
1253 U8 backup_channel = p->channel;
1254 U8 channelIdx;
1255
1256 for (channelIdx = CHANNEL_A; channelIdx < p->support_channel_num; channelIdx++)
1257 {
1258 vSetPHY2ChannelMapping(p, channelIdx);
1259 DramcHwDQSOSC(p);
1260 }
1261
1262 vSetPHY2ChannelMapping(p, backup_channel);
1263 msg("TX_TRACKING: ON\n");
1264 #else
1265 msg("TX_TRACKING: OFF\n");
1266 #endif
1267
1268
1269 #if ENABLE_DFS_RUNTIME_MRW
1270 DFSRuntimeMRW_preset(p, vGet_Current_ShuLevel(p));
1271 #endif
1272
1273 #ifdef DDR_INIT_TIME_PROFILING
1274 #if __ETT__
1275 u4low_tick1 = GPT_GetTickCount(&u4high_tick1);
1276 time_msg(" (4) vDramCalibrationAllChannel() take %d ms\n\r", ((u4low_tick1 - u4low_tick0) * 76) / 1000000);
1277 #else
1278 u4low_tick1 = get_timer(u4low_tick0);
1279 time_msg(" (4) vDramCalibrationAllChannel() take %d ms\n\r", u4low_tick1);
1280 #endif
1281 #endif
1282 }
1283
1284 U8 gGet_MDL_Used_Flag = 0;
1285 void Set_MDL_Used_Flag(U8 value)
1286 {
1287 gGet_MDL_Used_Flag = value;
1288 }
1289
1290 U8 Get_MDL_Used_Flag(void)
1291 {
1292 return gGet_MDL_Used_Flag;
1293 }
1294
1295 DRAMC_CTX_T *psCurrDramCtx;
1296 U8 gfirst_init_flag = 0;
1297 int Init_DRAM(DRAM_DRAM_TYPE_T dram_type, DRAM_CBT_MODE_EXTERN_T dram_cbt_mode_extern,
1298 DRAM_INFO_BY_MRR_T *DramInfo, U8 get_mdl_used)
1299 {
1300 #if !SW_CHANGE_FOR_SIMULATION
1301
1302 DRAMC_CTX_T * p;
1303 U8 final_shu;
1304 DRAM_DFS_FREQUENCY_TABLE_T *first_cali_freq_tbl;
1305
1306 #ifdef DDR_INIT_TIME_PROFILING
1307 U32 CPU_Cycle;
1308 TimeProfileBegin();
1309 #endif
1310
1311 psCurrDramCtx = &DramCtx_LPDDR4;
1312
1313 #if defined(DDR_INIT_TIME_PROFILING) || (__ETT__ && SUPPORT_SAVE_TIME_FOR_CALIBRATION)
1314 if (gtime_profiling_flag == 0)
1315 {
1316 memcpy(&gTimeProfilingDramCtx, psCurrDramCtx, sizeof(DRAMC_CTX_T));
1317 gtime_profiling_flag = 1;
1318 }
1319
1320 p = &gTimeProfilingDramCtx;
1321 gfirst_init_flag = 0;
1322
1323 //DramcConfInfraReset(p); //No need when DDR_INIT_TIME_PROFILING_TEST_CNT=1
1324 #else
1325 p = psCurrDramCtx;
1326 #endif
1327
1328 p->new_cbt_mode = 1;
1329
1330 Set_MDL_Used_Flag(get_mdl_used);
1331
1332 p->dram_type = dram_type;
1333
1334 /* Convert DRAM_CBT_MODE_EXTERN_T to DRAM_CBT_MODE_T */
1335 switch ((int)dram_cbt_mode_extern)
1336 {
1337 case CBT_R0_R1_NORMAL:
1338 p->dram_cbt_mode[RANK_0] = CBT_NORMAL_MODE;
1339 p->dram_cbt_mode[RANK_1] = CBT_NORMAL_MODE;
1340 break;
1341 case CBT_R0_R1_BYTE:
1342 p->dram_cbt_mode[RANK_0] = CBT_BYTE_MODE1;
1343 p->dram_cbt_mode[RANK_1] = CBT_BYTE_MODE1;
1344 break;
1345 case CBT_R0_NORMAL_R1_BYTE:
1346 p->dram_cbt_mode[RANK_0] = CBT_NORMAL_MODE;
1347 p->dram_cbt_mode[RANK_1] = CBT_BYTE_MODE1;
1348 break;
1349 case CBT_R0_BYTE_R1_NORMAL:
1350 p->dram_cbt_mode[RANK_0] = CBT_BYTE_MODE1;
1351 p->dram_cbt_mode[RANK_1] = CBT_NORMAL_MODE;
1352 break;
1353 default:
1354 err("Error!");
1355 break;
1356 }
1357 msg2("dram_cbt_mode_extern: %d\n"
1358 "dram_cbt_mode [RK0]: %d, [RK1]: %d\n",
1359 (int)dram_cbt_mode_extern, p->dram_cbt_mode[RANK_0], p->dram_cbt_mode[RANK_1]);
1360
1361 #if ENABLE_APB_MASK_WRITE
1362 U32 u4GPTTickCnt;
1363 TimeProfileBegin();
1364
1365 EnableDramcAPBMaskWrite(p);
1366 DramcRegAPBWriteMask(p);
1367
1368 u4GPTTickCnt = TimeProfileEnd();
1369 time_msg("[DramcRegAPBWriteMask] take %d ms\n", u4GPTTickCnt / 1000);
1370
1371 TestAPBMaskWriteFunc(p);
1372
1373 while (1);
1374 #endif
1375
1376 DramcBroadcastOnOff(DRAMC_BROADCAST_ON); //LP4 broadcast on
1377
1378 if (gfirst_init_flag == 0)
1379 {
1380 MPLLInit();
1381 Global_Option_Init(p);
1382 gfirst_init_flag = 1;
1383 }
1384
1385 #ifdef FIRST_BRING_UP
1386 Test_Broadcast_Feature(p);
1387 #endif
1388
1389 #if (FOR_DV_SIMULATION_USED == 0 && SW_CHANGE_FOR_SIMULATION == 0)
1390 {
1391 U32 backup_broadcast;
1392 backup_broadcast = GetDramcBroadcast();
1393 DramcBroadcastOnOff(DRAMC_BROADCAST_OFF);
1394 mdl_setting(p);
1395 UpdateGlobal10GBEnVariables(p); // @Darren, for 10GB
1396 TA2_Test_Run_Time_HW_Set_Column_Num(p);
1397 DramcBroadcastOnOff(backup_broadcast);
1398 }
1399 #endif
1400
1401 info("\n\n[Bian_co] ETT version 0.0.0.1\n dram_type %d, R0 cbt_mode %d, R1 cbt_mode %d VENDOR=%d\n\n", p->dram_type, p->dram_cbt_mode[RANK_0], p->dram_cbt_mode[RANK_1], p->vendor_id);
1402
1403 #if __Petrus_TO_BE_PORTING__
1404 vDramcInit_PreSettings(p);
1405 #endif
1406
1407 // DramC & PHY init for all channels
1408 //=== First frequency ======
1409 first_cali_freq_tbl = &gFreqTbl[DRAM_DFS_SHUFFLE_MAX-1];
1410
1411 #if defined(DUMP_INIT_RG_LOG_TO_DE)
1412 vSetDFSFreqSelByTable(p, &gFreqTbl[1]); //0:3200 1:4266, 2:800, 3:1866, 4:1200, 5:2400, 6:1600
1413 #else
1414 vSetDFSFreqSelByTable(p, first_cali_freq_tbl);
1415 //vSetDFSFreqSelByTable(p, &gFreqTbl[1]);
1416 #endif
1417 //#if (ENABLE_DRAM_SINGLE_FREQ_SELECT != 0xFF) || defined(FIRST_BRING_UP) || (__FLASH_TOOL_DA__)
1418 if (is_dvfs_enabled())
1419 gAndroid_DVFS_en = TRUE;
1420 else
1421 gAndroid_DVFS_en = FALSE;
1422
1423 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1424 DramcSave_Time_For_Cal_Init(p);
1425 #endif
1426 #ifndef LOOPBACK_TEST
1427 if (p->dram_type == TYPE_LPDDR4X) // LP4/LP4P need confirm
1428 {
1429 // LP4 IMP_LOW_FREQ <= DDR3733, IMP_HIGH_FREQ >= DDR4266
1430 // LP5 IMP_LOW_FREQ <= DDR3733, IMP_HIGH_FREQ >= DDR4266
1431 DramcSwImpedanceCal(p, 1, IMP_LOW_FREQ);
1432 DramcSwImpedanceCal(p, 1, IMP_HIGH_FREQ);
1433 #if ENABLE_SAMSUNG_NT_ODT
1434 DramcSwImpedanceCal(p, 1, IMP_NT_ODTN); // for Samsung NT ODTN
1435 #endif
1436 }
1437 else
1438 {
1439 err("[DramcSwImpedanceCal] Warnning: Need confirm DRAM type for SW IMP Calibration !!!\n");
1440 #if __ETT__
1441 while (1);
1442 #endif
1443 }
1444 #endif
1445
1446 #ifdef DDR_INIT_TIME_PROFILING
1447 CPU_Cycle = TimeProfileEnd();
1448 time_msg("(0)Pre_Init + SwImdepance takes %d ms\n\r", CPU_Cycle / 1000);
1449 #endif
1450
1451 #ifdef DUMP_INIT_RG_LOG_TO_DE
1452 gDUMP_INIT_RG_LOG_TO_DE_RG_log_flag = 1;
1453 mcSHOW_DUMP_INIT_RG_MSG("\n\n//=== DDR\033[1;32m%d\033[m\n",p->frequency<<1);
1454 #endif
1455
1456 //Clk free run
1457 //EnableDramcPhyDCM(p, 0);
1458
1459 DFSInitForCalibration(p);
1460
1461 #ifdef TEST_MODE_MRS
1462 if (global_which_test == 0)
1463 TestModeTestMenu();
1464 #endif
1465
1466
1467 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1468 if (p->femmc_Ready==1)
1469 {
1470 p->support_rank_num = p->pSavetimeData->support_rank_num;
1471 }
1472 #endif
1473
1474 #if (FOR_DV_SIMULATION_USED == 0 && SW_CHANGE_FOR_SIMULATION == 0)
1475 U32 backup_broadcast;
1476 backup_broadcast = GetDramcBroadcast();
1477 DramcBroadcastOnOff(DRAMC_BROADCAST_OFF);
1478 emi_init2();
1479 DramcBroadcastOnOff(backup_broadcast);
1480 #endif
1481
1482 if (Get_MDL_Used_Flag()==GET_MDL_USED)
1483 {
1484 // only K CHA to save time
1485 vSetPHY2ChannelMapping(p, CHANNEL_A);
1486 vCalibration_Flow_For_MDL(p); // currently for LP4
1487 GetDramInforAfterCalByMRR(p, DramInfo);
1488 return 0;
1489 }
1490 else //NORMAL_USED
1491 {
1492 #if (fcFOR_CHIP_ID == fcMargaux) // @Darren, new chip need double confirm
1493 if (p->DRAMPinmux == PINMUX_DSC)
1494 UpdateDFSTbltoDDR3200(p);
1495 #endif
1496 vDramCalibrationAllChannel(p);
1497 GetDramInforAfterCalByMRR(p, DramInfo);
1498 vDramcACTimingOptimize(p);
1499 }
1500
1501 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1502 DramcSave_Time_For_Cal_End(p);
1503 #endif
1504
1505 #if ((!defined(FIRST_BRING_UP)) || (ENABLE_DRAM_SINGLE_FREQ_SELECT != 0xFF)) && (!__FLASH_TOOL_DA__)
1506 DramcSaveToShuffleSRAM(p, DRAM_DFS_SHUFFLE_1, (DRAM_DFS_SHUFFLE_TYPE_T)p->pDFSTable->shuffleIdx);
1507 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1508 DramcSave_Time_For_Cal_End(p);
1509 #endif
1510 LoadShuffleSRAMtoDramc(p, (DRAM_DFS_SHUFFLE_TYPE_T)p->pDFSTable->shuffleIdx, DRAM_DFS_SHUFFLE_2); //Darren: DDR1600 for MRW (DramcModeRegInit_LP4 and CBT)
1511 #if ENABLE_SRAM_DMA_WA
1512 DPHYSRAMShuWAToSHU1(p); //Darren: DDR1600 for MRW (DramcModeRegInit_LP4 and CBT)
1513 #endif
1514
1515 S8 u1ShuIdx;
1516 S8 allCaliShuIdx = 0xFF;
1517
1518 if (CONFIG(MEDIATEK_DRAM_DVFS_LIMIT_FREQ_CNT)) {
1519 if (p->DRAMPinmux == PINMUX_DSC)
1520 allCaliShuIdx = 0x61; // 3200, 2400, 1600
1521 else
1522 allCaliShuIdx = 0x43; // 3200, 4266, 1600
1523 }
1524 dramc_debug("all cali shu idx: 0x%x\n", allCaliShuIdx);
1525
1526 //#if (ENABLE_DRAM_SINGLE_FREQ_SELECT == 0xFF)
1527 if (is_dvfs_enabled()) {
1528 for (u1ShuIdx = DRAM_DFS_SHUFFLE_MAX - 2; u1ShuIdx >= DRAM_DFS_SHUFFLE_1; u1ShuIdx--)
1529 {
1530 #if (fcFOR_CHIP_ID == fcMargaux) && (ENABLE_DRAM_SINGLE_FREQ_SELECT == 0xFF) // @Darren, new chip need double confirm
1531 if ((p->DRAMPinmux == PINMUX_DSC) && (gFreqTbl[u1ShuIdx].shuffleIdx == SRAM_SHU0))
1532 continue;
1533 #endif
1534
1535 // ignore the calibration for shuffle which is not in allCaliShuIdx, just copy first cali shuffle data
1536 if (!(allCaliShuIdx & BIT(u1ShuIdx))) {
1537 // copy first calibration shuffle to this shuffle (if DVFS, need double confirm)
1538 DramcSaveToShuffleSRAM(p, DRAM_DFS_SHUFFLE_1, (DRAM_DFS_SHUFFLE_TYPE_T)gFreqTbl[u1ShuIdx].shuffleIdx);
1539 continue;
1540 }
1541
1542 vSetDFSFreqSelByTable(p, &gFreqTbl[u1ShuIdx]);
1543 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1544 DramcSave_Time_For_Cal_Init(p);
1545 #endif
1546 DFSInitForCalibration(p);
1547 vDramCalibrationAllChannel(p);
1548 vDramcACTimingOptimize(p);
1549
1550 #if RUNTIME_SHMOO_RELEATED_FUNCTION && SUPPORT_SAVE_TIME_FOR_CALIBRATION
1551 if (p->frequency == u2DFSGetHighestFreq(p))
1552 {
1553 DramcRunTimeShmooRG_BackupRestore(p);
1554
1555 RunTime_Shmoo_update_parameters(p);
1556 }
1557 #endif
1558 DramcSaveToShuffleSRAM(p, DRAM_DFS_SHUFFLE_1, (DRAM_DFS_SHUFFLE_TYPE_T)gFreqTbl[u1ShuIdx].shuffleIdx);
1559 #if (fcFOR_CHIP_ID == fcMargaux) && (ENABLE_DRAM_SINGLE_FREQ_SELECT == 0xFF) // @Darren, new chip need double confirm
1560 if ((p->DRAMPinmux == PINMUX_DSC) && (gFreqTbl[u1ShuIdx].shuffleIdx == SRAM_SHU1))
1561 DramcSaveToShuffleSRAM(p, DRAM_DFS_SHUFFLE_1, (DRAM_DFS_SHUFFLE_TYPE_T)gFreqTbl[u1ShuIdx + 1].shuffleIdx); // Copy SRAM_SHU1 to SRAM_SHU0
1562 #endif
1563
1564 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1565 DramcSave_Time_For_Cal_End(p);
1566 #endif
1567 }
1568 }
1569 #endif //((!defined(FIRST_BRING_UP)) || (ENABLE_DRAM_SINGLE_FREQ_SELECT != 0xFF)) && (!__FLASH_TOOL_DA__)
1570
1571 #ifdef DDR_INIT_TIME_PROFILING
1572 TimeProfileBegin();
1573 #endif
1574
1575 vAfterCalibration(p);
1576
1577 #ifdef ENABLE_POST_PACKAGE_REPAIR
1578 PostPackageRepair();
1579 #endif
1580
1581 #if __Petrus_TO_BE_PORTING__
1582
1583 #if 0//TX_OE_CALIBATION, for DMA test
1584 U8 u1ChannelIdx, u1RankIdx;
1585 for (u1ChannelIdx = 0; u1ChannelIdx < (p->support_channel_num); u1ChannelIdx++)
1586 for (u1RankIdx = 0; u1RankIdx < (p->support_rank_num); u1RankIdx++)
1587 {
1588 vSetPHY2ChannelMapping(p, u1ChannelIdx);
1589 vSetRank(p, u1RankIdx);
1590 DramcTxOECalibration(p);
1591 }
1592
1593 vSetPHY2ChannelMapping(p, CHANNEL_A);
1594 vSetRank(p, RANK_0);
1595
1596 U32 u4err_value;
1597 DramcDmaEngine((DRAMC_CTX_T *)p, 0x50000000, 0x60000000, 0xff00, 8, DMA_PREPARE_DATA_ONLY, p->support_channel_num);
1598 u4err_value = DramcDmaEngine((DRAMC_CTX_T *)p, 0x50000000, 0x60000000, 0xff00, 8, DMA_CHECK_DATA_ACCESS_AND_COMPARE, p->support_channel_num);
1599 msg("DramC_TX_OE_Calibration 0x%X\n", u4err_value);
1600 #endif
1601
1602 #if !LCPLL_IC_SCAN
1603 #if (FOR_DV_SIMULATION_USED == 0 && SW_CHANGE_FOR_SIMULATION == 0)
1604 print_DBG_info(p);
1605 Dump_EMIRegisters(p);
1606 #endif
1607 #endif
1608
1609 #if 0
1610 DramcRegDump(p, SRAM_SHU0);
1611 #endif
1612
1613 // ETT_NO_DRAM #endif
1614
1615 #if ETT_NO_DRAM
1616 //NoDramDramcRegDump(p);
1617 NoDramRegFill();
1618 #endif
1619 #endif //#if __Petrus_TO_BE_PORTING__
1620
1621 #if DRAMC_MODEREG_CHECK
1622 DramcModeReg_Check(p);
1623 #endif
1624
1625 #if __FLASH_TOOL_DA__
1626 vPrintPinInfoResult(p);
1627 vGetErrorTypeResult(p);
1628 #endif
1629 #if CPU_RW_TEST_AFTER_K
1630 msg("\n[MEM_TEST] 02: After DFS, before run time config\n");
1631 vDramCPUReadWriteTestAfterCalibration(p);
1632 #endif
1633
1634 #if TA2_RW_TEST_AFTER_K
1635 msg("\n[TA2_TEST]\n");
1636 TA2_Test_Run_Time_HW(p);
1637 #endif
1638
1639 #if __ETT__
1640 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1641 if (!(p->femmc_Ready == 0))
1642 #elif defined(DDR_INIT_TIME_PROFILING)
1643 if (u2TimeProfileCnt == (DDR_INIT_TIME_PROFILING_TEST_CNT - 1)) //last time of loop
1644 #endif
1645 #endif
1646 {
1647 EnableDFSHwModeClk(p);
1648 msg("DFS_SHUFFLE_HW_MODE: ON\n");
1649 if (gAndroid_DVFS_en == TRUE) // shuffle to DDR3733 boot
1650 {
1651 #if defined(SLT)
1652 final_shu = SRAM_SHU1; //DDR3200
1653 #else
1654 final_shu = SRAM_SHU0; //DDR4266
1655 #endif
1656
1657 vSetDFSFreqSelByTable(p, get_FreqTbl_by_shuffleIndex(p, final_shu));
1658 DramcDFSDirectJump_SRAMShuRGMode(p, SRAM_SHU1);
1659 DramcDFSDirectJump_SRAMShuRGMode(p, final_shu);
1660 print("switch to %d Mbps bootup\n", p->frequency * 2);
1661 }
1662
1663
1664 #if __Petrus_TO_BE_PORTING__
1665 #if (DVT_TEST_DUMMY_RD_SIDEBAND_FROM_SPM && defined(DUMMY_READ_FOR_TRACKING))
1666 DramcDummyReadForSPMSideBand(p); // SPM dummy read 1us <-> 4us for DVT only (it must call after TransferPLLToSPMControl)
1667 #endif
1668
1669 EnableDramcTrackingBySPMControl(p);
1670
1671 msg("\n\nSettings after calibration\n\n");
1672 reg_msg("\n\nSettings after calibration\n\n");
1673 #endif
1674
1675 DramcRunTimeConfig(p);
1676 }
1677
1678 #if CPU_RW_TEST_AFTER_K
1679 msg("\n[MEM_TEST] 03: After run time config\n");
1680 vDramCPUReadWriteTestAfterCalibration(p);
1681 #endif
1682
1683 #if TA2_RW_TEST_AFTER_K
1684 msg("\n[TA2_TEST]\n");
1685 TA2_Test_Run_Time_HW(p);
1686 #endif
1687
1688
1689 #if (__ETT__ && CPU_RW_TEST_AFTER_K)
1690 /* 0x46000000 is LK base addr */
1691 //while(1)
1692 {
1693 //if ((s4value = dramc_complex_mem_test (0x46000000, 0x2000)) == 0)
1694 if ((s4value = dramc_complex_mem_test (0x40024000, 0x20000)) == 0)
1695 {
1696 msg("1st complex R/W mem test pass\n");
1697 }
1698 else
1699 {
1700 msg("1st complex R/W mem test fail :-%d\n", -s4value);
1701 #if defined(SLT)
1702 err("[dramc] DRAM_FATAL_ERR_FLAG = 0x80000000\n");
1703 while (1);
1704 #endif
1705 }
1706 }
1707 #endif
1708
1709 #if MRW_CHECK_ONLY
1710 vPrintFinalModeRegisterSetting(p);
1711 #endif
1712
1713 #ifdef DDR_INIT_TIME_PROFILING
1714 CPU_Cycle = TimeProfileEnd();
1715 time_msg(" (5) After calibration takes %d ms\n\r", CPU_Cycle / 1000);
1716 #endif // end of DDR_INIT_TIME_PROFILING
1717
1718 #endif//SW_CHANGE_FOR_SIMULATION
1719 //Low_Power_Scenarios_Test(p);
1720
1721 //vSetDFSFreqSelByTable(p, get_FreqTbl_by_shuffleIndex(p, SRAM_SHU1));
1722 //DramcDFSDirectJump(p, SRAM_SHU1);//Switch to CLRPLL
1723
1724 //ETT_DRM(p);
1725 return 0;
1726 }
1727 ///TODO: wait for porting ---
1728
1729
1730 ///TODO: wait for porting +++
1731 static void DPI_vDramCalibrationSingleChannel(DRAMC_CTX_T *DramConfig, cal_sv_rand_args_t *psra)
1732 {
1733 U8 ii;
1734
1735 ///TODO: wait for porting +++
1736 #if GATING_ADJUST_TXDLY_FOR_TRACKING
1737 DramcRxdqsGatingPreProcess(DramConfig);
1738 #endif
1739 ///TODO: wait for porting ---
1740
1741 vAutoRefreshSwitch(DramConfig, DISABLE);
1742
1743 #if 1//(SIMUILATION_CBT == 1)
1744 for (ii = RANK_0; ii < DramConfig->support_rank_num; ii++)
1745 {
1746 vSetRank(DramConfig, ii);
1747
1748 if (!psra || psra->cbt) {
1749 msg("\n----->DramcCBT begin...\n");
1750 timestamp_show();
1751 #if CBT_O1_PINMUX_WORKAROUND
1752 CmdBusTrainingLP45(DramConfig, AUTOK_OFF); //Cannot use aito-k in A60868
1753 #else
1754 if (psra)
1755 CmdBusTrainingLP45(DramConfig, psra->cbt_autok);
1756 else
1757 CmdBusTrainingLP45(DramConfig, AUTOK_OFF);
1758 #endif
1759 timestamp_show();
1760 msg("DramcCBT end<-----\n\n");
1761 }
1762 #if ENABLE_EYESCAN_GRAPH
1763 msg("CBT EYESCAN start<-----\n\n");
1764 print_EYESCAN_LOG_message(DramConfig, 0); //draw CBT eyescan
1765 msg("CBT EYESCAN end<-----\n\n");
1766 #endif
1767 }
1768
1769 vSetRank(DramConfig, RANK_0);
1770
1771 ///TODO: wait for porting +++
1772 #if __A60868_TO_BE_PORTING__
1773 No_Parking_On_CLRPLL(DramConfig);
1774 #endif // __A60868_TO_BE_PORTING__
1775 ///TODO: wait for porting ---
1776 #endif /* (SIMUILATION_CBT == 1) */
1777
1778 for (ii = RANK_0; ii < DramConfig->support_rank_num; ii++)
1779 {
1780 vSetRank(DramConfig, ii);
1781
1782 vAutoRefreshSwitch(DramConfig, DISABLE); //When doing WriteLeveling, should make sure that auto refresh is disable
1783
1784 #if 1//(SIMULATION_WRITE_LEVELING == 1)
1785 #if (!WCK_LEVELING_FM_WORKAROUND)
1786 if (u1IsLP4Family(DramConfig->dram_type))
1787 #endif
1788 {
1789 if (!(u1IsLP4Div4DDR800(DramConfig) && (DramConfig->rank == RANK_1))) // skip for DDR800 rank1
1790 {
1791 if (!psra || psra->wl) {
1792 msg("\n----->DramcWriteLeveling(PI) begin...\n");
1793 timestamp_show();
1794 if (psra)
1795 {
1796 DramcWriteLeveling(DramConfig, psra->wl_autok, PI_BASED);
1797 }
1798 else
1799 DramcWriteLeveling(DramConfig, AUTOK_OFF, PI_BASED);
1800
1801 timestamp_show();
1802 msg("DramcWriteLeveling(PI) end<-----\n\n");
1803 }
1804 }
1805 }
1806 #endif /* (SIMULATION_WRITE_LEVELING == 1) */
1807
1808 vAutoRefreshSwitch(DramConfig, ENABLE);
1809
1810 #if 1//(SIMULATION_GATING == 1)
1811 if (!psra || psra->gating) {
1812 msg("\n----->DramcGating begin...\n");
1813 timestamp_show();
1814 if (psra)
1815 dramc_rx_dqs_gating_cal(DramConfig, psra->gating_autok, 0);
1816 else
1817 dramc_rx_dqs_gating_cal(DramConfig, AUTOK_OFF, 0);
1818 timestamp_show();
1819 msg("DramcGating end < -----\n\n");
1820 }
1821 #endif
1822
1823 #if 1//(SIMULATION_RX_RDDQC == 1)
1824 if (!psra || psra->rddqc) {
1825 msg("\n----->DramcRxWindowPerbitCal RDDQC begin...\n");
1826 timestamp_show();
1827
1828 #if 0 // Used when testing LP5 RK1 WCK2CK in high efficiency mode and differential mode.
1829 p->rank = 1;
1830 // For test HEFF = 1 / WCKDUAL = 0
1831 vIO32WriteFldAlign(DRAMC_REG_ADDR(DRAMC_REG_SHU_WCKCTRL), 0, SHU_WCKCTRL_WCKDUAL);
1832 vIO32WriteFldMulti(DRAMC_REG_ADDR(DRAMC_REG_SHU_COMMON0),
1833 P_Fld(1, SHU_COMMON0_LP5WCKON) |
1834 P_Fld(1, SHU_COMMON0_LP5HEFF_MODE));
1835 vIO32WriteFldAlign(DRAMC_REG_ADDR(DRAMC_REG_CKECTRL), 0, CKECTRL_CKE2RANK_OPT8);
1836 #endif
1837 DramcRxWindowPerbitCal(DramConfig, PATTERN_RDDQC, NULL, AUTOK_OFF);
1838 timestamp_show();
1839 msg("DramcRxWindowPerbitCal end<-----\n\n");
1840 }
1841 #endif // (SIMULATION_RX_RDDQC == 1)
1842
1843 #if (__LP5_COMBO__ == TRUE)
1844 #if (SIMULATION_DUTY_CYC_MONITOR == 1)
1845 if (is_lp5_family(DramConfig) && DramConfig->frequency >= GetFreqBySel(DramConfig,LP5_DDR4266))
1846 {
1847 if (!psra) {
1848 msg("\n----->DramcDutyCycleMonitor begin...\n");
1849 timestamp_show();
1850 DramcDutyCycleMonitor(DramConfig);
1851 timestamp_show();
1852 msg("DramcDutyCycleMonitor end<-----\n\n");
1853
1854 msg("\n----->DramcWriteLeveling(DLY) begin...\n");
1855 timestamp_show();
1856 DramcWriteLeveling(DramConfig, psra->wl_autok, DLY_BASED);
1857 timestamp_show();
1858 msg("DramcWriteLeveling(DLY)end<-----\n\n");
1859 }
1860 }
1861 #endif /* (SIMULATION_DUTY_CYC_MONITOR == 1) */
1862 #endif // (__LP5_COMBO__ == TRUE)
1863
1864 #if 1//(SIMULATION_TX_PERBIT == 1)
1865 if (!psra || psra->tx_perbit) {
1866 msg("\n----->DramcTxWindowPerbitCal begin...\n");
1867 timestamp_show();
1868 if (psra)
1869 DramcTxWindowPerbitCal(DramConfig, TX_DQ_DQS_MOVE_DQ_DQM,
1870 FALSE, psra->tx_auto_cal);
1871 else
1872 DramcTxWindowPerbitCal(DramConfig, TX_DQ_DQS_MOVE_DQ_DQM,
1873 FALSE, AUTOK_OFF);
1874 if (Get_Vref_Calibration_OnOff(DramConfig) == VREF_CALI_ON) {
1875 if (psra)
1876 DramcTxWindowPerbitCal(DramConfig, TX_DQ_DQS_MOVE_DQ_ONLY,
1877 TRUE, psra->tx_auto_cal);
1878 else
1879 DramcTxWindowPerbitCal(DramConfig, TX_DQ_DQS_MOVE_DQ_ONLY,
1880 TRUE, AUTOK_OFF);
1881 }
1882 if (psra)
1883 DramcTxWindowPerbitCal(DramConfig, TX_DQ_DQS_MOVE_DQ_ONLY,
1884 FALSE, psra->tx_auto_cal);
1885 else
1886 DramcTxWindowPerbitCal(DramConfig, TX_DQ_DQS_MOVE_DQ_ONLY,
1887 FALSE, AUTOK_OFF);
1888 timestamp_show();
1889 msg("DramcTxWindowPerbitCal end<-----\n\n");
1890
1891 #if ENABLE_EYESCAN_GRAPH
1892 msg("\n----->DramcTxEYESCAN begin...\n");
1893 Dramc_K_TX_EyeScan_Log(DramConfig);
1894 print_EYESCAN_LOG_message(DramConfig, 2); //draw TX eyescan
1895 msg("\n----->DramcTxEYESCAN end...\n");
1896 #endif
1897 }
1898 #endif // (SIMULATION_TX_PERBIT == 1)
1899
1900 #if 1//(SIMULATION_DATLAT == 1)
1901 if (1) { // No parameter in correspondence with by now
1902 msg("\n----->DramcRxdatlatCal begin...\n");
1903 timestamp_show();
1904
1905 DramcRxdatlatCal(DramConfig);
1906
1907 timestamp_show();
1908 msg("DramcRxdatlatCal end<-----\n\n");
1909 }
1910 #endif // (SIMULATION_DATLAT == 1)
1911
1912 #if 1//(SIMULATION_RX_PERBIT == 1)
1913 if (!psra || psra->rx_perbit) {
1914 msg("\n----->DramcRxWindowPerbitCal begin...\n");
1915 timestamp_show();
1916 if (psra)
1917 DramcRxWindowPerbitCal(DramConfig, PATTERN_TEST_ENGINE,
1918 NULL /*Set Vref = 0 to test*/, psra->rx_auto_cal);
1919 else
1920 DramcRxWindowPerbitCal(DramConfig, PATTERN_TEST_ENGINE,
1921 NULL /*Set Vref = 0 to test*/, AUTOK_OFF);
1922 timestamp_show();
1923 msg("DramcRxWindowPerbitCal end<-----\n\n");
1924
1925 #if ENABLE_EYESCAN_GRAPH
1926 msg("DramcRxWindowPerbitCal EYESCAN start<-----\n\n");
1927 print_EYESCAN_LOG_message(DramConfig, 1); //draw RX eyescan
1928 msg("DramcRxWindowPerbitCal EYESCAN end<-----\n\n");
1929 #endif
1930 }
1931 #endif // (SIMULATION_RX_PERBIT == 1)
1932
1933 #if (SIMULATION_RX_DVS == 1)
1934 if (DramConfig->frequency >=2133)
1935 DramcRxDVSWindowCal(DramConfig);
1936 #endif
1937
1938 #if TX_OE_CALIBATION
1939 if (DramConfig->frequency >= 1600)
1940 {
1941 DramcTxOECalibration(DramConfig);
1942 }
1943 #endif // TX_OE_CALIBATION
1944
1945 #if ENABLE_TX_TRACKING
1946 #if 0 /* Starting from Vinson, no need to pre-calculate MR23 for different freqs */
1947 if (gu1MR23Done == FALSE)
1948 {
1949 DramcDQSOSCAuto(p);
1950 }
1951 #endif
1952 DramcDQSOSCAuto(DramConfig);
1953 DramcDQSOSCMR23(DramConfig);
1954 DramcDQSOSCSetMR18MR19(DramConfig);
1955 #endif
1956 }
1957
1958 vSetRank(DramConfig, RANK_0);
1959
1960 #if ENABLE_TX_TRACKING
1961 DramcDQSOSCShuSettings(DramConfig);
1962 #endif
1963
1964 ///TODO: wait for porting +++
1965 #if GATING_ADJUST_TXDLY_FOR_TRACKING
1966 DramcRxdqsGatingPostProcess(DramConfig);
1967 #endif
1968
1969 #if TDQSCK_PRECALCULATION_FOR_DVFS
1970 DramcDQSPrecalculation_preset(DramConfig);
1971 #endif
1972
1973 #if SIMULATION_RX_DVS
1974 if (DramConfig->frequency >=2133)
1975 DramcDramcRxDVSCalPostProcess(DramConfig);
1976 #endif
1977
1978 #if XRTWTW_NEW_CROSS_RK_MODE
1979 if (DramConfig->support_rank_num == RANK_DUAL)
1980 {
1981 XRTWTW_SHU_Setting(DramConfig);
1982 }
1983 #endif
1984
1985 #if DV_SIMULATION_DATLAT
1986 DramcDualRankRxdatlatCal(DramConfig);
1987 #endif
1988
1989 #if RDSEL_TRACKING_EN
1990 if (DramConfig->frequency != 400)
1991 RDSELRunTimeTracking_preset(DramConfig);
1992 #endif
1993
1994 ///TODO: wait for porting ---
1995
1996 }
1997
1998 static void DPI_vDramCalibrationAllChannel(DRAMC_CTX_T *DramConfig, cal_sv_rand_args_t *psra)
1999 {
2000 U8 channel_idx, rank_idx;
2001
2002 CKEFixOnOff(DramConfig, CKE_WRITE_TO_ALL_RANK, CKE_FIXOFF, CKE_WRITE_TO_ALL_CHANNEL);
2003 for (channel_idx = CHANNEL_A; channel_idx < DramConfig->support_channel_num; channel_idx++)
2004 {
2005 vSetPHY2ChannelMapping(DramConfig, channel_idx);// when switching channel, must update PHY to Channel Mapping
2006 CKEFixOnOff(DramConfig, CKE_WRITE_TO_ALL_RANK, CKE_FIXON, CKE_WRITE_TO_ONE_CHANNEL);
2007 DPI_vDramCalibrationSingleChannel(DramConfig, psra);
2008 }
2009
2010 vSetPHY2ChannelMapping(DramConfig, CHANNEL_A);
2011
2012 ///TODO: wait for porting +++
2013 #if ENABLE_READ_DBI
2014 DramcReadDBIOnOff(DramConfig, DramConfig->DBI_R_onoff[DramConfig->dram_fsp]);
2015 #endif
2016
2017 #if ENABLE_WRITE_DBI
2018 // Just settle the DBI parameters which would be stored into shuffle space.
2019 if (DramConfig->DBI_W_onoff[DramConfig->dram_fsp])
2020 {
2021 for (channel_idx = CHANNEL_A; channel_idx < DramConfig->support_channel_num; channel_idx++)
2022 {
2023 vSetPHY2ChannelMapping(DramConfig, channel_idx);
2024
2025 for (rank_idx = RANK_0; rank_idx < DramConfig->support_rank_num; rank_idx++)
2026 {
2027 vSetRank(DramConfig, rank_idx);
2028 DramcWriteShiftMCKForWriteDBI(DramConfig, -1); //Tx DQ/DQM -1 MCK for write DBI ON
2029 }
2030 vSetRank(DramConfig, RANK_0);
2031 }
2032 vSetPHY2ChannelMapping(DramConfig, CHANNEL_A);
2033
2034 // Improve Write DBI Power
2035 ApplyWriteDBIPowerImprove(DramConfig, ENABLE);
2036
2037 #if ENABLE_WRITE_DBI_Protect
2038 ApplyWriteDBIProtect(DramConfig, ENABLE);
2039 #endif
2040 }
2041 DramcWriteDBIOnOff(DramConfig, DramConfig->DBI_W_onoff[DramConfig->dram_fsp]);
2042
2043
2044 #endif
2045
2046 #if XRTRTR_NEW_CROSS_RK_MODE
2047 if (DramConfig->support_rank_num == RANK_DUAL)
2048 {
2049 XRTRTR_SHU_Setting(DramConfig);
2050 }
2051 #endif
2052
2053 #if DV_SIMULATION_DFS
2054 #if (ENABLE_TX_TRACKING || TDQSCK_PRECALCULATION_FOR_DVFS)
2055 FreqJumpRatioCalculation(DramConfig);
2056 #endif
2057 #endif
2058
2059 #ifdef TEMP_SENSOR_ENABLE
2060 DramcHMR4_Presetting(DramConfig);
2061 #endif
2062
2063 #if (ENABLE_PER_BANK_REFRESH == 1)
2064 DramcEnablePerBankRefresh(DramConfig, ON);
2065 #else
2066 DramcEnablePerBankRefresh(DramConfig, OFF);
2067 #endif
2068
2069 #if ENABLE_TX_TRACKING
2070 U8 backup_channel = DramConfig->channel;
2071 U8 channelIdx;
2072
2073 for (channelIdx = CHANNEL_A; channelIdx < DramConfig->support_channel_num; channelIdx++)
2074 {
2075 vSetPHY2ChannelMapping(DramConfig, channelIdx);
2076 DramcHwDQSOSC(DramConfig);
2077 }
2078
2079 vSetPHY2ChannelMapping(DramConfig, backup_channel);
2080 msg("TX_TRACKING: ON\n");
2081 #else
2082 msg("TX_TRACKING: OFF\n");
2083 #endif
2084
2085 ///TODO: wait for porting ---
2086
2087 }
2088
2089 ///TODO: wait for porting +++
2090 #if __A60868_TO_BE_PORTING__
2091 void RG_dummy_write(DRAMC_CTX_T *p, U32 pattern)
2092 {
2093 unsigned int ii;
2094 for (ii = 0; ii < 20; ii++)
2095 vIO32WriteFldAlign(DDRPHY_RFU_0X1D4, pattern, RFU_0X1D4_RESERVED_0X1D4);
2096 }
2097
2098 void EnablePLLtoSPMControl(DRAMC_CTX_T *p)
2099 {
2100 vIO32WriteFldAlign_All(DDRPHY_MISC_SPM_CTRL1, 0, MISC_SPM_CTRL1_SPM_DVFS_CONTROL_SEL); // DFS SPM mode for calibration
2101 }
2102 #endif // __A60868_TO_BE_PORTING__
2103 ///TODO: wait for porting ---
2104
2105 void dump_dramc_ctx(DRAMC_CTX_T *p)
2106 {
2107 msg("== DRAMC_CTX_T ==\n");
2108 msg("support_channel_num: %d\n", p->support_channel_num);
2109 msg("channel: %d\n", p->channel);
2110 msg("support_rank_num: %d\n", p->support_rank_num);
2111 msg("rank: %d\n", p->rank);
2112 msg("freq_sel: %d\n", p->freq_sel);
2113 msg("shu_type: %d\n", p->shu_type);
2114 msg("dram_type: %d\n", p->dram_type);
2115 msg("dram_fsp: %d\n", p->dram_fsp);
2116 msg("odt_onoff: %d\n", p->odt_onoff);
2117 msg("dram_cbt_mode: %d, %d\n", (int)p->dram_cbt_mode[0], (int)p->dram_cbt_mode[1]);
2118 msg("DBI_R_onoff: %d, %d\n", (int)p->DBI_R_onoff[0], (int)p->DBI_R_onoff[1]);
2119 msg("DBI_W_onoff: %d, %d\n", (int)p->DBI_W_onoff[0], (int)p->DBI_W_onoff[1]);
2120 msg("data_width: %d\n", p->data_width);
2121 msg("test2_1: 0x%x\n", p->test2_1);
2122 msg("test2_2: 0x%x\n", p->test2_2);
2123 msg("frequency: %d\n", p->frequency);
2124 msg("freqGroup: %d\n", p->freqGroup);
2125 msg("lp5_training_mode: %d\n", p->lp5_training_mode);
2126 msg("lp5_cbt_phase: %d\n", p->lp5_cbt_phase);
2127 msg("new_cbt_mode: %d\n", p->new_cbt_mode);
2128 msg("u1PLLMode: %d\n", p->u1PLLMode);
2129 msg("curDBIState: %d\n", p->curDBIState);
2130 }
2131
2132
2133 void DPI_SW_main_LP4(DRAMC_CTX_T *ExtConfig, cal_sv_rand_args_t *psra)
2134 {
2135 u32 value;
2136 #if DV_SIMULATION_DFS
2137 S8 s1ShuIdx;
2138 #endif
2139
2140 DRAMC_CTX_T *p = &DramCtx_LPDDR4; //default;
2141
2142 p->dram_type = ExtConfig->dram_type;
2143 if(p->dram_type==TYPE_LPDDR5)
2144 {
2145 MEM_TYPE = LPDDR5;
2146 }
2147 else
2148 {
2149 MEM_TYPE = LPDDR4;
2150 }
2151
2152 p->dram_cbt_mode[0] = ExtConfig->dram_cbt_mode[0];
2153 p->dram_cbt_mode[1] = ExtConfig->dram_cbt_mode[1];
2154 p->freq_sel = ExtConfig->freq_sel;
2155 p->frequency = ExtConfig->frequency;
2156 p->freqGroup = ExtConfig->freqGroup;
2157 p->new_cbt_mode = ExtConfig->new_cbt_mode;
2158
2159 #if 0 // for Refs
2160 DRAM_DFS_FREQUENCY_TABLE_T gFreqTbl[DRAM_DFS_SHUFFLE_MAX] = {
2161 {LP4_DDR3200 /*0*/, DIV8_MODE, SRAM_SHU1, DUTY_LAST_K, VREF_CALI_OFF, CLOSE_LOOP_MODE}, // highest freq of term group (3733) must k first.
2162 {LP4_DDR4266 /*1*/, DIV8_MODE, SRAM_SHU0, DUTY_NEED_K, VREF_CALI_ON, CLOSE_LOOP_MODE}, // highest freq of term group (3733) must k first.
2163 {LP4_DDR800 /*2*/, DIV4_MODE, SRAM_SHU6, DUTY_DEFAULT, VREF_CALI_OFF, SEMI_OPEN_LOOP_MODE}, //Darren: DDR1600 for MRW (DramcModeRegInit_LP4 and CBT)
2164 {LP4_DDR1866 /*3*/, DIV8_MODE, SRAM_SHU3, DUTY_LAST_K, VREF_CALI_OFF, CLOSE_LOOP_MODE}, // highest freq of unterm group (2400) must k first.
2165 {LP4_DDR1200 /*4*/, DIV8_MODE, SRAM_SHU5, DUTY_LAST_K, VREF_CALI_OFF, CLOSE_LOOP_MODE}, // highest freq of unterm group (2400) must k first.
2166 {LP4_DDR2400 /*5*/, DIV8_MODE, SRAM_SHU2, DUTY_NEED_K, VREF_CALI_ON, CLOSE_LOOP_MODE}, // highest freq of unterm group (2400) must k first.
2167 {LP4_DDR1600 /*6*/, DIV8_MODE, SRAM_SHU4, DUTY_DEFAULT, VREF_CALI_ON, CLOSE_LOOP_MODE}, //Darren: DDR1600 for MRW (DramcModeRegInit_LP4 and CBT)
2168 };
2169 #endif
2170 if (u1IsLP4Family(p->dram_type))
2171 {
2172 if((ExtConfig->freq_sel==LP4_DDR3733) || (ExtConfig->freq_sel==LP4_DDR4266))
2173 {
2174 p->pDFSTable = &gFreqTbl[1];
2175 }
2176 else if(ExtConfig->freq_sel==LP4_DDR1600)
2177 {
2178 p->pDFSTable = &gFreqTbl[6];
2179 }
2180 else if(ExtConfig->freq_sel==LP4_DDR800)
2181 {
2182 p->pDFSTable = &gFreqTbl[2];
2183 }
2184 /*else if(ExtConfig->freq_sel==LP4_DDR400)
2185 {
2186 p->pDFSTable = &gFreqTbl[2];
2187 }*/
2188 }
2189
2190 enter_function();
2191
2192 if (!psra) {
2193 /*
2194 * for SA's simulation
2195 */
2196 msg("enter SA's simulation flow.\n");
2197 p->support_channel_num = CHANNEL_SINGLE;
2198 p->channel = CHANNEL_A;
2199 p->support_rank_num = RANK_DUAL;
2200 /* DramRank */
2201 p->rank = RANK_0;
2202 /* DRAMC operation clock frequency in MHz */
2203 #if (fcFOR_CHIP_ID == fcA60868)
2204 #if DV_SIMULATION_DFS
2205 p->pDFSTable = &gFreqTbl[DRAM_DFS_SHUFFLE_2];
2206 p->shu_type = DRAM_DFS_SHUFFLE_2;
2207 #endif
2208 #endif
2209 #if 0
2210 /* DRAM type */
2211 #if DV_SIMULATION_LP4
2212 p->dram_type = TYPE_LPDDR4X;
2213 //p->freq_sel = LP4_DDR3200;//DV_SIMULATION_RUN_FREQ_SEL;
2214 //p->frequency = 1600;//DV_SIMULATION_RUN_FREQ;
2215 p->freq_sel = LP4_DDR1600;//DV_SIMULATION_RUN_FREQ_SEL;
2216 p->frequency = 800;//DV_SIMULATION_RUN_FREQ;
2217 #else
2218 p->dram_type = TYPE_LPDDR5;
2219 p->freq_sel = LP5_DDR3200;//DV_SIMULATION_RUN_FREQ_SEL;
2220 p->frequency = 1600;//DV_SIMULATION_RUN_FREQ;
2221 #endif
2222 #endif
2223 /* DRAM Fast switch point type, only for LP4, useless in LP3 */
2224 p->dram_fsp = FSP_0;
2225
2226 #if 0
2227 #if DV_SIMULATION_BYTEMODE
2228 p->dram_cbt_mode[RANK_0] = CBT_BYTE_MODE1;
2229 p->dram_cbt_mode[RANK_1] = CBT_BYTE_MODE1;
2230 #else
2231 p->dram_cbt_mode[RANK_0] = CBT_NORMAL_MODE;
2232 p->dram_cbt_mode[RANK_1] = CBT_NORMAL_MODE;
2233 #endif
2234 #endif
2235 /* IC and DRAM read DBI */
2236 p->DBI_R_onoff[FSP_0] = DBI_OFF; /* only for LP4, uesless in LP3 */
2237 p->DBI_R_onoff[FSP_1] = DBI_OFF; /* only for LP4, uesless in LP3 */
2238 #if ENABLE_READ_DBI
2239 p->DBI_R_onoff[FSP_1] = DBI_ON; /* only for LP4, uesless in LP3 */
2240 #else
2241 p->DBI_R_onoff[FSP_1] = DBI_OFF; /* only for LP4, uesless in LP3 */
2242 #endif
2243 /* IC and DRAM write DBI */
2244 p->DBI_W_onoff[FSP_0] = DBI_OFF; /* only for LP4, uesless in LP3 */
2245 p->DBI_W_onoff[FSP_1] = DBI_OFF; /* only for LP4, uesless in LP3 */
2246 #if ENABLE_WRITE_DBI
2247 p->DBI_W_onoff[FSP_1] = DBI_ON; /* only for LP4, uesless in LP3 */
2248 #else
2249 p->DBI_W_onoff[FSP_1] = DBI_OFF; /* only for LP4, uesless in LP3 */
2250 #endif
2251 /* bus width */
2252 p->data_width = DATA_WIDTH_16BIT;
2253 /* DRAMC internal test engine-2 parameters in calibration */
2254 p->test2_1 = DEFAULT_TEST2_1_CAL;
2255 p->test2_2 = DEFAULT_TEST2_2_CAL;
2256 /* DRAMC test pattern in calibration */
2257 p->test_pattern = TEST_XTALK_PATTERN;
2258 /* u2DelayCellTimex100 */
2259 p->u2DelayCellTimex100 = 250; // @Darren, 2.5ps
2260 p->vendor_id = 0x1;
2261 p->density = 0;
2262 /* p->ranksize = {0,0}; */
2263 p->ShuRGAccessIdx = DRAM_DFS_REG_SHU0;
2264 #if DV_SIMULATION_LP5_TRAINING_MODE1
2265 p->lp5_training_mode = TRAINING_MODE1;
2266 #else
2267 p->lp5_training_mode = TRAINING_MODE2;
2268 #endif
2269
2270 #if DV_SIMULATION_LP5_CBT_PHASH_R
2271 p->lp5_cbt_phase = CBT_PHASE_RISING;
2272 #else
2273 p->lp5_cbt_phase = CBT_PHASE_FALLING;
2274 #endif
2275 } else {
2276 /*
2277 * for DV's regression
2278 */
2279 msg("enter DV's regression flow.\n");
2280 p->support_channel_num = CHANNEL_SINGLE;
2281 p->channel = psra->calibration_channel;
2282 p->support_rank_num = RANK_DUAL;
2283 /* DramRank */
2284 p->rank = psra->calibration_rank;
2285 /* DRAMC operation clock frequency in MHz */
2286 #if (fcFOR_CHIP_ID == fcA60868)
2287 #if DV_SIMULATION_DFS
2288 p->pDFSTable = &gFreqTbl[DRAM_DFS_SHUFFLE_2];
2289 p->shu_type = DRAM_DFS_SHUFFLE_2;
2290 #endif
2291 #endif
2292
2293 /* DRAM type */
2294 //p->dram_type = psra->dram_type;
2295 //p->freq_sel = LP5_DDR4266;//DV_SIMULATION_RUN_FREQ_SEL;
2296 //p->frequency = 2133;//DV_SIMULATION_RUN_FREQ;
2297 //set_type_freq_by_svargs(p, psra);
2298
2299 /* DRAM Fast switch point type, only for LP4, useless in LP3 */
2300 p->dram_fsp = FSP_0;
2301
2302 p->dram_cbt_mode[RANK_0] = psra->rk0_cbt_mode;
2303 p->dram_cbt_mode[RANK_1] = psra->rk1_cbt_mode;
2304
2305 /* IC and DRAM read DBI */
2306 p->DBI_R_onoff[FSP_0] = (psra->mr3_value >> 6) & 0x1; /* only for LP4, uesless in LP3 */
2307 p->DBI_R_onoff[FSP_1] = (psra->mr3_value >> 6) & 0x1; /* only for LP4, uesless in LP3 */
2308 p->DBI_R_onoff[FSP_2] = (psra->mr3_value >> 6) & 0x1;
2309 /* IC and DRAM write DBI */
2310 p->DBI_W_onoff[FSP_0] = (psra->mr3_value >> 7) & 0x1; /* only for LP4, uesless in LP3 */
2311 p->DBI_W_onoff[FSP_1] = (psra->mr3_value >> 7) & 0x1; /* only for LP4, uesless in LP3 */
2312 p->DBI_W_onoff[FSP_2] = (psra->mr3_value >> 7) & 0x1;
2313 /* bus width */
2314 p->data_width = DATA_WIDTH_16BIT;
2315 /* DRAMC internal test engine-2 parameters in calibration */
2316 p->test2_1 = DEFAULT_TEST2_1_CAL;
2317 p->test2_2 = DEFAULT_TEST2_2_CAL;
2318 /* DRAMC test pattern in calibration */
2319 p->test_pattern = TEST_XTALK_PATTERN;
2320 /* u2DelayCellTimex100 */
2321 p->u2DelayCellTimex100 = 0;
2322 p->vendor_id = 0x1;
2323 p->density = 0;
2324 /* p->ranksize = {0,0}; */
2325 p->ShuRGAccessIdx = DRAM_DFS_REG_SHU0;
2326 p->lp5_training_mode = psra->cbt_training_mode;
2327 p->lp5_cbt_phase = psra->cbt_phase;
2328 p->new_cbt_mode = psra->new_cbt_mode;
2329 }
2330
2331 #if QT_GUI_Tool
2332 p->lp5_training_mode = ExtConfig->lp5_training_mode;
2333 #endif
2334
2335 if (psra && is_lp5_family(p)) {
2336 p->dram_fsp = (psra->mr16_value >> 2) & 0x3;
2337 } else if (psra && u1IsLP4Family(p->dram_type)) {
2338 p->dram_fsp = (psra->mr13_value >> 7) & 0x1;
2339 }
2340
2341 // p->dram_type = TYPE_LPDDR5;
2342 // #define __FW_VER__ "WCK leveling with DLY +16! and MRinit for FSP1 -- 777"
2343 #define __FW_VER__ "All struct move done, new RX range -- 444"
2344
2345 if (u1IsLP4Family(p->dram_type)) {
2346 msg("%s enter == LP4 == ...%s\n", __FUNCTION__, __FW_VER__);
2347 } else {
2348 msg("%s enter == LP5 == ...%s\n", __FUNCTION__, __FW_VER__);
2349 }
2350 msg(CHK_INCLUDE_LOCAL_HEADER);
2351
2352 msg("SIMULATION_LP4_ZQ ... %d\n", SIMULATION_LP4_ZQ);
2353 msg("SIMULATION_SW_IMPED ... %d\n", SIMULATION_SW_IMPED);
2354 msg("SIMULATION_MIOCK_JMETER ... %d\n", SIMULATION_MIOCK_JMETER);
2355 msg("SIMULATION_8PHASE ... %d\n", SIMULATION_8PHASE);
2356 msg("SIMULATION_RX_INPUT_BUF ... %d\n", SIMULATION_RX_INPUT_BUF);
2357 msg("SIMUILATION_CBT ... %d\n", SIMUILATION_CBT);
2358 msg("SIMULATION_WRITE_LEVELING ... %d\n", SIMULATION_WRITE_LEVELING);
2359 msg("SIMULATION_DUTY_CYC_MONITOR ... %d\n", SIMULATION_DUTY_CYC_MONITOR);
2360 msg("SIMULATION_GATING ... %d\n", SIMULATION_GATING);
2361 msg("SIMULATION_DATLAT ... %d\n", SIMULATION_DATLAT);
2362 msg("SIMULATION_RX_RDDQC ... %d\n", SIMULATION_RX_RDDQC);
2363 msg("SIMULATION_RX_PERBIT ... %d\n", SIMULATION_RX_PERBIT);
2364 msg("SIMULATION_TX_PERBIT ... %d\n", SIMULATION_TX_PERBIT);
2365 msg("\n\n");
2366
2367 msg("============== CTX before calibration ================\n");
2368 dump_dramc_ctx(p);
2369
2370 DramcBroadcastOnOff(DRAMC_BROADCAST_OFF);
2371
2372 //vIO32Write4B_All2(p, DDRPHY_SHU_RK_CA_CMD1, 0x0FFF);
2373 value = u4Dram_Register_Read(p, DRAMC_REG_DDRCOMMON0);
2374 msg("Get Addr:0x%x, Value:0x%x\n", DRAMC_REG_DDRCOMMON0, value);
2375
2376 value = u4Dram_Register_Read(p, DDRPHY_REG_SHU_RK_CA_CMD1);
2377 msg("Get Addr:0x%x, Value:0x%x\n", DDRPHY_REG_SHU_RK_CA_CMD1, value);
2378
2379 value = u4Dram_Register_Read(p, DDRPHY_REG_MISC_DQO1);
2380 msg("Get Addr:0x%x, Value:0x%x\n", DDRPHY_REG_MISC_DQO1, value);
2381
2382 value = u4Dram_Register_Read(p, DDRPHY_MD32_REG_SSPM_TIMER0_RESET_VAL );
2383 msg("Get Addr:0x%x, Value:0x%x\n", DDRPHY_MD32_REG_SSPM_TIMER0_RESET_VAL, value);
2384
2385 DramcBroadcastOnOff(DRAMC_BROADCAST_ON); //LP4 broadcast on
2386
2387 Global_Option_Init(p);
2388
2389 #if __A60868_TO_BE_PORTING__
2390 vDramcInit_PreSettings(p);
2391
2392 DDRPhyFreqSel(p, p->pDFSTable->freq_sel);
2393
2394 vSetPHY2ChannelMapping(p, p->channel);
2395 #endif // __A60868_TO_BE_PORTING__
2396 ///TODO: wait for porting ---
2397
2398
2399 if (u1IsLP4Family(p->dram_type))
2400 {
2401 vSetDFSFreqSelByTable(p, p->pDFSTable); // for LP4x
2402 }
2403 else ///TODO: Jeremy, modify this when LP5 gFreqtbl ready
2404 {
2405 DDRPhyFreqSel(p, p->freq_sel);
2406 }
2407
2408 #if (SIMULATION_SW_IMPED == 1)
2409 msg("\n----->DramcSwImpedanceCal begin...\n");
2410 timestamp_show();
2411 // LP4 IMP_LOW_FREQ <= DDR3733, IMP_HIGH_FREQ >= DDR4266
2412 // LP5 IMP_LOW_FREQ <= DDR3733, IMP_HIGH_FREQ >= DDR4266
2413 DramcSwImpedanceCal(p, 1, IMP_LOW_FREQ);
2414 DramcSwImpedanceCal(p, 1, IMP_HIGH_FREQ);
2415 timestamp_show();
2416 msg("DramcSwImpedanceCal end<-----\n\n");
2417 #endif /* (SIMULATION_SW_IMPED == 1) */
2418
2419 #if DV_SIMULATION_INIT_C
2420 ///TODO: wait for porting +++
2421 DramcInit(p);
2422
2423 // Before calibration setting
2424 vBeforeCalibration(p);
2425 #if __A60868_TO_BE_PORTING__
2426 #if DV_SIMULATION_BEFORE_K
2427 vApplyConfigBeforeCalibration(p);
2428 //vMR2InitForSimulationTest(p);
2429 #endif
2430
2431 #ifdef DUMP_INIT_RG_LOG_TO_DE
2432 #if 0 //Dump RG to other shuffle for FT used, don't delete
2433 mcSHOW_DUMP_INIT_RG_MSG("\n\n\n\n\n\n===== Save to Shuffle RG ======\n");
2434 DramcSaveToShuffleReg(p, DRAM_DFS_SHUFFLE_1, DRAM_DFS_SHUFFLE_3);
2435 #endif
2436 while (1);
2437 #endif
2438 #endif
2439 #endif // __A60868_TO_BE_PORTING__
2440 ///TODO: wait for porting ---
2441
2442
2443 #if (SIMULATION_MIOCK_JMETER == 1)
2444 msg("\n----->DramcMiockJmeter begin...\n");
2445 timestamp_show();
2446 PRE_MIOCK_JMETER_HQA_USED(p);
2447 timestamp_show();
2448 msg("DramcMiockJmeter end<-----\n\n");
2449 #endif /* (SIMULATION_MIOCK_JMETER == 1) */
2450
2451 #if (SIMULATION_8PHASE == 1)
2452 if(is_lp5_family(p) && (p->frequency >= 2133)) {
2453 msg("\n----->Dramc8PhaseCal begin...\n");
2454 timestamp_show();
2455 Dramc8PhaseCal(p); // it must set before duty calib
2456 timestamp_show();
2457 msg("Dramc8PhaseCal end<-----\n\n");
2458 }
2459 #endif /* (SIMULATION_8PHASE == 1) */
2460
2461 ///TODO: wait for porting +++
2462 #if !DV_SIMULATION_DFS // No calib will use legacy mode init settings
2463 DPI_vDramCalibrationAllChannel(p, psra); // for DDR1600 1:8 mode
2464 #endif
2465
2466 #if DV_SIMULATION_DFS
2467 DramcSaveToShuffleSRAM(p, DRAM_DFS_SHUFFLE_1, p->pDFSTable->shuffleIdx);
2468 LoadShuffleSRAMtoDramc(p, p->pDFSTable->shuffleIdx, DRAM_DFS_SHUFFLE_2); //Darren: DDR1600 for MRW (DramcModeRegInit_LP4 and CBT)
2469 #if ENABLE_SRAM_DMA_WA
2470 DPHYSaveToSRAMShuWA(p, p->pDFSTable->shuffleIdx);
2471 #endif
2472
2473 #if (fcFOR_CHIP_ID == fcA60868)
2474 for (s1ShuIdx = DRAM_DFS_SHUFFLE_MAX - 10; s1ShuIdx >= DRAM_DFS_SHUFFLE_1; s1ShuIdx--)
2475 #else
2476 for (s1ShuIdx = DRAM_DFS_SHUFFLE_MAX - 2; s1ShuIdx >= DRAM_DFS_SHUFFLE_1; s1ShuIdx--)
2477 #endif
2478 {
2479 vSetDFSFreqSelByTable(p, &gFreqTbl[s1ShuIdx]);
2480 DramcInit(p);
2481 // Before calibration setting
2482 vBeforeCalibration(p);
2483
2484 #if DV_SIMULATION_BEFORE_K
2485 vApplyConfigBeforeCalibration(p);
2486 #endif
2487
2488 #if (SIMULATION_8PHASE == 1)
2489 if(is_lp5_family(p) && (p->frequency >= 2133)) {
2490 msg("\n----->Dramc8PhaseCal begin...\n");
2491 timestamp_show();
2492 Dramc8PhaseCal(p); // it must set before duty calib
2493 timestamp_show();
2494 msg("Dramc8PhaseCal end<-----\n\n");
2495 }
2496 #endif /* (SIMULATION_8PHASE == 1) */
2497
2498 #if !DV_SIMULATION_DFS // No calib will use legacy mode init settings
2499 DPI_vDramCalibrationAllChannel(p, psra); // for gDVDFSTbl
2500 #endif
2501 DramcSaveToShuffleSRAM(p, DRAM_DFS_SHUFFLE_1, gFreqTbl[s1ShuIdx].shuffleIdx);
2502 #if ENABLE_SRAM_DMA_WA
2503 DPHYSaveToSRAMShuWA(p, gFreqTbl[s1ShuIdx].shuffleIdx);
2504 #endif
2505 }
2506 #endif
2507 ///TODO: wait for porting ---
2508
2509
2510
2511
2512 ///TODO: wait for porting +++
2513 vAfterCalibration(p);
2514
2515 #if SIMULATION_RUNTIME_CONFIG
2516 DramcRunTimeConfig(p);
2517 #endif
2518
2519 #if __A60868_TO_BE_PORTING__
2520 #if DV_SIMULATION_AFTER_K
2521 vApplyConfigAfterCalibration(p);
2522 #endif
2523
2524 #if DV_SIMULATION_RUN_TIME_MRW
2525 enter_pasr_dpd_config(0, 0xFF);
2526 #endif
2527
2528 #if DV_SIMULATION_RUN_TIME_MRR
2529 DramcModeRegReadByRank(p, RANK_0, 4, &u2val1);
2530 DramcModeRegReadByRank(p, RANK_0, 5, &u2val2);
2531 DramcModeRegReadByRank(p, RANK_0, 8, &u2val3);
2532 msg("[Runtime time MRR] MR4 = 0x%x, MR5 = 0x%x, MR8 = 0x%x\n", u2val1, u2val2, u2val3);
2533 #endif
2534
2535 #if 0//DV_SIMULATION_DFS // NOTE: Don't use DramcDFSDirectJump_SPMMode. it will cause NULL object access.
2536 // high freq -> low freq
2537 for (s1ShuIdx = 0; s1ShuIdx < DV_SIMULATION_DFS_SHU_MAX; s1ShuIdx++)
2538 DramcDFSDirectJump_SRAMShuRGMode(p, gDVDFSTbl[s1ShuIdx].shuffleIdx);
2539 // low freq -> high freq
2540 for (s1ShuIdx = DV_SIMULATION_DFS_SHU_MAX - 1; s1ShuIdx >= DRAM_DFS_SHUFFLE_1; s1ShuIdx--)
2541 DramcDFSDirectJump_SRAMShuRGMode(p, gDVDFSTbl[s1ShuIdx].shuffleIdx);
2542 #endif
2543
2544 #if DV_SIMULATION_SPM_CONTROL
2545 EnablePLLtoSPMControl(p);
2546 #endif
2547
2548 RG_dummy_write(p, 0xAAAAAAAA);
2549 #endif // __A60868_TO_BE_PORTING__
2550 ///TODO: wait for porting ---
2551
2552 //Temp_TA2_Test_After_K(p);
2553
2554 //Ett_Mini_Strss_Test(p);
2555 #if MRW_CHECK_ONLY
2556 vPrintFinalModeRegisterSetting(p);
2557 #endif
2558 #if PRINT_CALIBRATION_SUMMARY
2559 vPrintCalibrationResult(p);
2560 #endif
2561
2562 exit_function();
2563 }
2564
2565 ///TODO: wait for porting +++
2566 #if __A60868_TO_BE_PORTING__
2567 #if SW_CHANGE_FOR_SIMULATION
2568 void main(void)
2569 {
2570
2571 DRAMC_CTX_T DramConfig;
2572 DramConfig.channel = CHANNEL_A;
2573 DramConfig.support_rank_num = RANK_DUAL;
2574 // DramRank
2575 DramConfig.rank = RANK_0;
2576 // DRAM type
2577 DramConfig.dram_type = TYPE_LPDDR4X;
2578 // DRAM Fast switch point type, only for LP4, useless in LP3
2579 DramConfig.dram_fsp = FSP_0;
2580 // DRAM CBT mode, only for LP4, useless in LP3
2581 DramConfig.dram_cbt_mode[RANK_0] = CBT_NORMAL_MODE;
2582 DramConfig.dram_cbt_mode[RANK_1] = CBT_NORMAL_MODE;
2583 // IC and DRAM read DBI
2584 DramConfig.DBI_R_onoff[FSP_0] = DBI_OFF; // only for LP4, uesless in LP3
2585 #if ENABLE_READ_DBI
2586 DramConfig.DBI_R_onoff[FSP_1] = DBI_ON; // only for LP4, uesless in LP3
2587 #else
2588 DramConfig.DBI_R_onoff[FSP_1] = DBI_OFF; // only for LP4, uesless in LP3
2589 #endif
2590 // IC and DRAM write DBI
2591 DramConfig.DBI_W_onoff[FSP_0] = DBI_OFF; // only for LP4, uesless in LP3
2592 #if ENABLE_WRITE_DBI
2593 DramConfig.DBI_W_onoff[FSP_1] = DBI_ON; // only for LP4, uesless in LP3
2594 #else
2595 DramConfig.DBI_W_onoff[FSP_1] = DBI_OFF; // only for LP4, uesless in LP3
2596 #endif
2597 // bus width
2598 DramConfig.data_width = DATA_WIDTH_32BIT;
2599 // DRAMC internal test engine-2 parameters in calibration
2600 DramConfig.test2_1 = DEFAULT_TEST2_1_CAL;
2601 DramConfig.test2_2 = DEFAULT_TEST2_2_CAL;
2602 // DRAMC test pattern in calibration
2603 DramConfig.test_pattern = TEST_XTALK_PATTERN;
2604 // DRAMC operation clock frequency in MHz
2605 DramConfig.frequency = 800;
2606
2607 //DramConfig.enable_rx_scan_vref =DISABLE;
2608 //DramConfig.enable_tx_scan_vref =DISABLE;
2609 //DramConfig.dynamicODT = DISABLE;
2610
2611 MPLLInit();
2612
2613 Global_Option_Init(&DramConfig);
2614
2615 // DramC & PHY init for all channels
2616 DDRPhyFreqSel(&DramConfig, LP4_DDR1600);
2617
2618
2619 #if WRITE_LEVELING_MOVE_DQS_INSTEAD_OF_CLK
2620 memset(DramConfig.arfgWriteLevelingInitShif, FALSE, sizeof(DramConfig.arfgWriteLevelingInitShif));
2621 //>fgWriteLevelingInitShif= FALSE;
2622 #endif
2623
2624 DramcInit(&DramConfig);
2625
2626 vApplyConfigBeforeCalibration(&DramConfig);
2627 vMR2InitForSimulationTest(&DramConfig);
2628
2629 vSetPHY2ChannelMapping(&DramConfig, DramConfig.channel);
2630
2631 #if SIMULATION_SW_IMPED
2632 DramcSwImpedanceCal(&DramConfig, 1, LOW_FREQ); //for DRVN/P and ODTN
2633 //DramcSwImpedanceCal(&DramConfig, 1, HIGH_FREQ); //for DRVN/P and ODTN
2634 #endif
2635
2636
2637 #if SIMULATION_LP4_ZQ
2638 if (DramConfig.dram_type == TYPE_LPDDR4 || DramConfig.dram_type == TYPE_LPDDR4X || DramConfig.dram_type == TYPE_LPDDR4P)
2639 {
2640 DramcZQCalibration(&DramConfig);
2641 }
2642 #endif
2643
2644 #if SIMUILATION_LP4_CBT
2645 CmdBusTrainingLP4(&DramConfig);
2646 #endif
2647
2648 #if SIMULATION_WRITE_LEVELING
2649 DramcWriteLeveling(&DramConfig);
2650 #endif
2651
2652 #if SIMULATION_GATING
2653 // Gating calibration of single rank
2654 DramcRxdqsGatingCal(&DramConfig);
2655
2656 // Gating calibration of both rank
2657 //DualRankDramcRxdqsGatingCal(&DramConfig);
2658 #endif
2659
2660 #if SIMUILATION_LP4_RDDQC
2661 DramcRxWindowPerbitCal(&DramConfig, 0, NULL);
2662 #endif
2663
2664 #if SIMULATION_DATLAT
2665 // RX Datlat calibration of single rank
2666 DramcRxdatlatCal(&DramConfig);
2667
2668 // RX Datlat calibration of two rank
2669 //DramcDualRankRxdatlatCal(&DramConfig);
2670 #endif
2671
2672 #if SIMULATION_RX_PERBIT
2673 DramcRxWindowPerbitCal(&DramConfig, 1, NULL);
2674 #endif
2675
2676 #if SIMULATION_TX_PERBIT
2677 DramcTxWindowPerbitCal(&DramConfig, TX_DQ_DQS_MOVE_DQ_DQM);
2678 DramcTxWindowPerbitCal(&DramConfig, TX_DQ_DQS_MOVE_DQ_ONLY);
2679 #endif
2680
2681 #if ENABLE_READ_DBI
2682 //Read DBI ON
2683 SetDramModeRegForReadDBIOnOff(&DramConfig, DramConfig.dram_fsp, DramConfig.DBI_R_onoff[DramConfig.dram_fsp]);
2684 #endif
2685
2686 #if ENABLE_WRITE_DBI
2687 //Write DBI ON
2688 DramcWriteShiftMCKForWriteDBI(&DramConfig, -1);
2689 SetDramModeRegForWriteDBIOnOff(&DramConfig, DramConfig.dram_fsp, DramConfig.DBI_W_onoff[DramConfig.dram_fsp]);
2690 #endif
2691
2692 #if ENABLE_READ_DBI
2693 DramcReadDBIOnOff(&DramConfig, DramConfig.DBI_R_onoff[DramConfig.dram_fsp]);
2694 #endif
2695
2696 #if ENABLE_WRITE_DBI
2697 DramcWriteDBIOnOff(&DramConfig, DramConfig.DBI_W_onoff[DramConfig.dram_fsp]);
2698 #endif
2699 }
2700 #endif //SW_CHANGE_FOR_SIMULATION
2701 #endif // __A60868_TO_BE_PORTING__
2702 ///TODO: wait for porting ---