1 /* SPDX-License-Identifier: BSD-3-Clause */
3 //=============================================================================
5 //=============================================================================
7 //#include <ett_common.h>
8 //#include <test_case_controller.h>
11 //#include "ett_cust.h"
12 //#include "emi_setting.h"
14 //#include "dramc_pi_api.h"
18 #include "dramc_common.h"
19 #include "dramc_int_global.h"
24 #if !__FLASH_TOOL_DA__ && !__ETT__
25 #include "custom_emi.h" // fix build error: emi_settings
28 #if (FOR_DV_SIMULATION_USED==0)
29 #include <soc/mt6359p.h>
30 #include <soc/regulator.h>
32 /* now we can use definition MTK_PMIC_MT6359
33 * ==============================================================
34 * PMIC |Power |Dflt. Volt. |Step |Support FPWM |Cmt.
35 * --------------------------------------------------------------
36 * MT6359 |Vcore |0.8v |6.25mV |Yes |
37 * |Vm18 |1.8v |0.1V |No |
38 * --------------------------------------------------------------
39 * MT6360 |Vdram |1.125v |5mV |Yes |(DRAM Vdram)
40 * |Vmddr |0.75v |10mV |No |(AP Vdram)
41 * |Vddq |0.6v |10mV |No |
42 * ==============================================================
44 //#define MTK_PMIC_MT6359
48 #define mt_reg_sync_write(x,y) mt_reg_sync_writel(y,x)
50 #define seclib_get_devinfo_with_index(x) 0
52 #ifdef MTK_PMIC_MT6359
53 #include <regulator/mtk_regulator.h>
57 #include <soc/dramc_param.h>
60 //=============================================================================
62 //=============================================================================
64 //=============================================================================
66 //=============================================================================
67 int emi_setting_index
= -1;
69 #ifdef MTK_PMIC_MT6359
70 static struct mtk_regulator reg_vio18
, reg_vdram
, reg_vcore
, reg_vddq
, reg_vmddr
;
74 static LAST_DRAMC_INFO_T
* last_dramc_info_ptr
;
78 static VOLTAGE_SEL_INFO_T voltage_sel_info_ptr
;
81 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
82 extern u64
get_part_addr(const char *name
);
85 #if defined(SLT) && (!__ETT__)
86 #include <pl_version.h>
87 static u64 part_dram_data_addr_slt
= 0;
88 int read_slt_data(DRAM_SLT_DATA_T
*data
);
89 int write_slt_data(DRAM_SLT_DATA_T
*data
);
90 int clean_slt_data(void);
92 //=============================================================================
93 // External references
94 //=============================================================================
95 extern char* opt_dle_value
;
97 void print_DBG_info(DRAMC_CTX_T
*p
);
99 void mdl_setting(DRAMC_CTX_T
*p
)
101 EMI_SETTINGS
*emi_set
;
103 if(emi_setting_index
== -1)
104 emi_set
= &default_emi_setting
;
105 #if (FOR_DV_SIMULATION_USED==0)
107 emi_set
= &emi_settings
[emi_setting_index
];
112 //The following is MDL settings
113 set_cen_emi_cona(emi_set
->EMI_CONA_VAL
);
114 set_cen_emi_conf(emi_set
->EMI_CONF_VAL
);
115 set_cen_emi_conh(emi_set
->EMI_CONH_VAL
);
117 // CHNA and CHNB uses the same CH0 setting
118 set_chn_emi_cona(emi_set
->CHN0_EMI_CONA_VAL
);
119 //set_chn_emi_conc(0x4);
121 p
->vendor_id
= emi_set
->iLPDDR3_MODE_REG_5
;
124 void print_DBG_info(DRAMC_CTX_T
*p
)
128 int mt_get_dram_type(void)
130 unsigned int dtype
= mt_get_dram_type_from_hw_trap();
132 if (dtype
== TYPE_LPDDR4X
)
133 return DTYPE_LPDDR4X
;
140 #ifdef DDR_RESERVE_MODE
141 extern u32 g_ddr_reserve_enable
;
142 extern u32 g_ddr_reserve_success
;
144 extern void before_Dramc_DDR_Reserved_Mode_setting(void);
146 #define CHAN_DRAMC_NAO_MISC_STATUSA(base) (base + 0x80)
147 #define SREF_STATE (1 << 16)
149 unsigned int is_dramc_exit_slf(void)
153 ret
= *(volatile unsigned *)CHAN_DRAMC_NAO_MISC_STATUSA(Channel_A_DRAMC_NAO_BASE_ADDRESS
);
154 if ((ret
& SREF_STATE
) != 0) {
155 dramc_crit("DRAM CHAN-A is in self-refresh (MISC_STATUSA = 0x%x)\n", ret
);
159 ret
= *(volatile unsigned *)CHAN_DRAMC_NAO_MISC_STATUSA(Channel_B_DRAMC_NAO_BASE_ADDRESS
);
160 if ((ret
& SREF_STATE
) != 0) {
161 dramc_crit("DRAM CHAN-B is in self-refresh (MISC_STATUSA = 0x%x)\n", ret
);
165 dramc_crit("ALL DRAM CHAN is not in self-refresh\n");
171 unsigned int dramc_set_vcore_voltage(unsigned int vcore
)
173 #ifdef MTK_PMIC_MT6359
174 return mtk_regulator_set_voltage(®_vcore
, vcore
, MAX_VCORE
);
176 dramc_debug("%s set vcore to %d\n", __func__
, vcore
);
177 //mt6359p_buck_set_voltage(MT6359P_GPU11, vcore);
179 mainboard_set_regulator_voltage(MTK_REGULATOR_VCORE
, vcore
);
184 unsigned int dramc_get_vcore_voltage(void)
186 #ifdef MTK_PMIC_MT6359
187 return mtk_regulator_get_voltage(®_vcore
);
189 return mainboard_get_regulator_voltage(MTK_REGULATOR_VCORE
);
193 unsigned int dramc_set_vdram_voltage(unsigned int ddr_type
, unsigned int vdram
)
195 #ifdef MTK_PMIC_MT6359
196 mtk_regulator_set_voltage(®_vdram
, vdram
, MAX_VDRAM
);
198 mainboard_set_regulator_voltage(MTK_REGULATOR_VDD2
, vdram
);
202 unsigned int dramc_get_vdram_voltage(unsigned int ddr_type
)
204 #ifdef MTK_PMIC_MT6359
205 return mtk_regulator_get_voltage(®_vdram
);
207 return mainboard_get_regulator_voltage(MTK_REGULATOR_VDD2
);
211 unsigned int dramc_set_vddq_voltage(unsigned int ddr_type
, unsigned int vddq
)
213 #ifdef MTK_PMIC_MT6359
214 mtk_regulator_set_voltage(®_vddq
, vddq
, MAX_VDDQ
);
216 mainboard_set_regulator_voltage(MTK_REGULATOR_VDDQ
, vddq
);
220 unsigned int dramc_get_vddq_voltage(unsigned int ddr_type
)
222 #ifdef MTK_PMIC_MT6359
223 return mtk_regulator_get_voltage(®_vddq
);
225 return mainboard_get_regulator_voltage(MTK_REGULATOR_VDDQ
);
229 unsigned int dramc_set_vmddr_voltage(unsigned int vmddr
)
231 #ifdef MTK_PMIC_MT6359
232 return mtk_regulator_set_voltage(®_vmddr
, vmddr
, MAX_VMDDR
);
234 mainboard_set_regulator_voltage(MTK_REGULATOR_VMDDR
, vmddr
);
238 unsigned int dramc_get_vmddr_voltage(void)
240 #ifdef MTK_PMIC_MT6359
241 return mtk_regulator_get_voltage(®_vmddr
);
243 return mainboard_get_regulator_voltage(MTK_REGULATOR_VMDDR
);
247 unsigned int dramc_set_vio18_voltage(unsigned int vio18
)
249 #ifdef MTK_PMIC_MT6359
250 unsigned int twist
= vio18
% UNIT_VIO18_STEP
/ UNIT_VIO18
;
251 vio18
-= vio18
% UNIT_VIO18_STEP
;
252 pmic_config_interface(PMIC_RG_VM18_VOCAL_ADDR
, twist
, PMIC_RG_VM18_VOCAL_MASK
, PMIC_RG_VM18_VOCAL_SHIFT
);
253 return mtk_regulator_set_voltage(®_vio18
, vio18
, MAX_VIO18
);
255 mainboard_set_regulator_voltage(MTK_REGULATOR_VDD1
, vio18
);
261 unsigned int dramc_get_vio18_voltage(void)
263 #ifdef MTK_PMIC_MT6359
264 unsigned int twist
= 0;
265 pmic_read_interface(PMIC_RG_VM18_VOCAL_ADDR
, &twist
, PMIC_RG_VM18_VOCAL_MASK
, PMIC_RG_VM18_VOCAL_SHIFT
);
266 return mtk_regulator_get_voltage(®_vio18
) + twist
* UNIT_VIO18
;
268 return mainboard_get_regulator_voltage(MTK_REGULATOR_VDD1
);
272 #define GPIO_TRAPPING_REG (0x100056f0)
273 unsigned int is_discrete_lpddr4(void)
275 unsigned int type
, ret
;
277 type
= get_ddr_type();
279 ret
= (type
== DDR_TYPE_DISCRETE
) ? 1 : 0;
280 dramc_debug("%s: %d\n", __func__
, ret
);
285 unsigned int mt_get_dram_type_from_hw_trap(void)
290 void setup_dramc_voltage_by_pmic(void)
295 #ifdef MTK_PMIC_MT6359
298 ret
= mtk_regulator_get("vm18", ®_vio18
);
300 dramc_debug("mtk_regulator_get vio18 fail\n");
302 ret
= mtk_regulator_get("vcore", ®_vcore
);
304 dramc_debug("mtk_regulator_get vcore fail\n");
306 ret
= mtk_regulator_get("VDRAM1", ®_vdram
);
308 printf("mtk_regulator_get vdram fail\n");
310 ret
= mtk_regulator_get("VDRAM2", ®_vddq
);
312 printf("mtk_regulator_get vddq fail\n");
314 ret
= mtk_regulator_get("VMDDR", ®_vmddr
);
316 printf("mtk_regulator_get vmddr fail\n");
318 mtk_regulator_set_mode(®_vcore
, 0x1);
319 mtk_regulator_set_mode(®_vdram
, 0x1);
322 dramc_set_vio18_voltage(vio18_voltage_select());
324 dramc_set_vio18_voltage(SEL_VIO18
);
326 #if defined(VCORE_BIN)
328 vcore
= vcore_voltage_select(KSHU0
);
330 dramc_set_vcore_voltage(vcore
);
333 dramc_set_vcore_voltage(get_vcore_uv_table(0));
336 dramc_set_vcore_voltage(vcore_voltage_select(KSHU0
));
338 dramc_set_vcore_voltage(SEL_PREFIX_VCORE(LP4
, KSHU0
));
342 dramc_set_vdram_voltage(TYPE_LPDDR4
, vdram_voltage_select());
344 dramc_set_vdram_voltage(TYPE_LPDDR4
, SEL_PREFIX_VDRAM(LP4
));
348 dramc_set_vddq_voltage(TYPE_LPDDR4
, vddq_voltage_select());
350 dramc_set_vddq_voltage(TYPE_LPDDR4
, SEL_PREFIX_VDDQ
);
354 dramc_set_vmddr_voltage(vmddr_voltage_select());
356 dramc_set_vmddr_voltage(SEL_PREFIX_VMDDR
);
359 dramc_debug("Vio18 = %d\n", dramc_get_vio18_voltage());
360 dramc_debug("Vcore = %d\n", dramc_get_vcore_voltage());
361 dramc_debug("Vdram = %d\n", dramc_get_vdram_voltage(TYPE_LPDDR4
));
362 dramc_debug("Vddq = %d\n", dramc_get_vddq_voltage(TYPE_LPDDR4
));
363 dramc_debug("Vmddr = %d\n", dramc_get_vmddr_voltage());
367 static void restore_vcore_setting(void)
372 #ifdef MTK_PMIC_MT6359
375 ret
= mtk_regulator_get("vcore", ®_vcore
);
377 printf("mtk_regulator_get vcore fail\n");
379 #if defined(VCORE_BIN)
381 vcore
= vcore_voltage_select(KSHU0
);
382 if ((doe_get_config("dram_fix_3094_0825")) || (doe_get_config("dram_all_3094_0825")) || (doe_get_config("dram_opp0_3733_others_3094_0825")))
383 dramc_set_vcore_voltage(825000);
384 else if (doe_get_config("dram_fix_3094_0725") || (doe_get_config("dram_fix_2400_0725")) || (doe_get_config("dram_fix_1534_0725")) || (doe_get_config("dram_fix_1200_0725")) || (doe_get_config("dram_all_3094_0725")) || (doe_get_config("dram_all_1534_0725")) || (doe_get_config("dram_opp0_3094_others_1534_0725")) || (doe_get_config("dram_opp0_2400_others_1534_0725")))
385 dramc_set_vcore_voltage(725000);
386 else if ((doe_get_config("dram_fix_1200_065")) || (doe_get_config("dram_fix_800_065")))
387 dramc_set_vcore_voltage(650000);
389 dramc_set_vcore_voltage(vcore
);
392 dramc_set_vcore_voltage(get_vcore_uv_table(0));
395 dramc_set_vcore_voltage(vcore_voltage_select(KSHU0
));
397 dramc_set_vcore_voltage(SEL_PREFIX_VCORE(LP4
, KSHU0
));
401 dramc_debug("Vcore = %d\n", dramc_get_vcore_voltage());
405 void switch_dramc_voltage_to_auto_mode(void)
407 #ifdef MTK_PMIC_MT6359
408 mtk_regulator_set_mode(®_vcore
, 0x0);
409 mtk_regulator_set_mode(®_vdram
, 0x0);
414 static int mt_get_mdl_number(void)
416 static int mdl_number
= -1;
418 mdl_number
= get_ddr_geometry();
424 int get_dram_channel_support_nr(void)
429 int get_dram_channel_nr(void)
431 return get_channel_nr_by_emi();
434 int get_dram_rank_nr(void)
440 #ifdef DDR_RESERVE_MODE
441 if(g_ddr_reserve_enable
==1 && g_ddr_reserve_success
==1) {
442 return get_rank_nr_by_emi();
446 index
= mt_get_mdl_number();
447 if (index
< 0 || index
>= num_of_emi_records
)
450 cen_emi_cona
= emi_settings
[index
].EMI_CONA_VAL
;
453 cen_emi_cona
= default_emi_setting
.EMI_CONA_VAL
;
456 if ((cen_emi_cona
& (1 << 17)) != 0 || //for channel 0
457 (cen_emi_cona
& (1 << 16)) != 0 ) //for channel 1
463 int get_dram_mr_cnt(void)
468 int get_dram_freq_cnt(void)
470 return DRAMC_FREQ_CNT
;
473 #if (FOR_DV_SIMULATION_USED==0)
474 #if !__FLASH_TOOL_DA__ && !__ETT__
476 void get_dram_rank_size(u64 dram_rank_size
[])
479 int index
, rank_nr
, i
;
481 #ifdef DDR_RESERVE_MODE
482 if(g_ddr_reserve_enable
==1 && g_ddr_reserve_success
==1)
484 get_rank_size_by_emi(dram_rank_size
);
489 index
= mt_get_mdl_number();
491 if (index
< 0 || index
>= num_of_emi_records
)
496 rank_nr
= get_dram_rank_nr();
498 for(i
= 0; i
< rank_nr
; i
++){
499 dram_rank_size
[i
] = emi_settings
[index
].DRAM_RANK_SIZE
[i
];
500 dramc_debug("%d:dram_rank_size:%llx\n",i
,dram_rank_size
[i
]);
505 get_rank_size_by_emi(dram_rank_size
);
510 void get_dram_freq_step(u32 dram_freq_step
[])
513 unsigned int defined_step
[DRAMC_FREQ_CNT
] = {
514 4266, 3200, 2400, 1866, 1600, 1200, 800};
516 if (is_discrete_lpddr4()) {
517 defined_step
[0] = 3200;
519 for (i
= 0; i
< DRAMC_FREQ_CNT
; i
++) {
520 dram_freq_step
[i
] = defined_step
[i
];
524 void set_dram_mr(unsigned int index
, unsigned short value
)
527 unsigned short value_2rk
;
529 value_2rk
= value
& 0xFF;
530 value_2rk
|= (value_2rk
<< 8);
550 unsigned short get_dram_mr(unsigned int index
)
552 unsigned int value
= 0;
556 value
= last_dramc_info_ptr
->mr5
;
559 value
= last_dramc_info_ptr
->mr6
;
562 value
= last_dramc_info_ptr
->mr7
;
565 value
= last_dramc_info_ptr
->mr8
;
569 return (unsigned short)(value
& 0xFFFF);
571 return (unsigned short)(value
& 0xFFFF);
575 void get_dram_mr_info(struct mr_info_t mr_info
[])
579 unsigned int mr_list
[DRAMC_MR_CNT
] = {5, 6, 7, 8};
581 for (i
= 0; i
< DRAMC_MR_CNT
; i
++) {
582 mr_info
[i
].mr_index
= mr_list
[i
];
583 mr_info
[i
].mr_value
= get_dram_mr(mr_list
[i
]);
588 #endif //#if !__FLASH_TOOL_DA__ && !__ETT__
591 static void freq_table_are_all_3094(void)
593 gFreqTbl
[0].freq_sel
= LP4_DDR3200
;
594 gFreqTbl
[0].divmode
= DIV8_MODE
;
595 gFreqTbl
[0].shuffleIdx
= SRAM_SHU1
;
596 gFreqTbl
[0].duty_calibration_mode
= DUTY_NEED_K
;
597 gFreqTbl
[0].vref_calibartion_enable
= VREF_CALI_ON
;
598 gFreqTbl
[0].ddr_loop_mode
= CLOSE_LOOP_MODE
;
600 gFreqTbl
[1].freq_sel
= LP4_DDR3200
;
601 gFreqTbl
[1].divmode
= DIV8_MODE
;
602 gFreqTbl
[1].shuffleIdx
= SRAM_SHU3
;
603 gFreqTbl
[1].duty_calibration_mode
= DUTY_NEED_K
;
604 gFreqTbl
[1].vref_calibartion_enable
= VREF_CALI_ON
;
605 gFreqTbl
[1].ddr_loop_mode
= CLOSE_LOOP_MODE
;
607 gFreqTbl
[2].freq_sel
= LP4_DDR3200
;
608 gFreqTbl
[2].divmode
= DIV8_MODE
;
609 gFreqTbl
[2].shuffleIdx
= SRAM_SHU2
;
610 gFreqTbl
[2].duty_calibration_mode
= DUTY_NEED_K
;
611 gFreqTbl
[2].vref_calibartion_enable
= VREF_CALI_ON
;
612 gFreqTbl
[2].ddr_loop_mode
= CLOSE_LOOP_MODE
;
614 gFreqTbl
[3].freq_sel
= LP4_DDR3200
;
615 gFreqTbl
[3].divmode
= DIV8_MODE
;
616 gFreqTbl
[3].shuffleIdx
= SRAM_SHU0
;
617 gFreqTbl
[3].duty_calibration_mode
= DUTY_NEED_K
;
618 gFreqTbl
[3].vref_calibartion_enable
= VREF_CALI_ON
;
619 gFreqTbl
[3].ddr_loop_mode
= CLOSE_LOOP_MODE
;
621 gFreqTbl
[4].freq_sel
= LP4_DDR3200
;
622 gFreqTbl
[4].divmode
= DIV8_MODE
;
623 gFreqTbl
[4].shuffleIdx
= SRAM_SHU5
;
624 gFreqTbl
[4].duty_calibration_mode
= DUTY_NEED_K
;
625 gFreqTbl
[4].vref_calibartion_enable
= VREF_CALI_ON
;
626 gFreqTbl
[4].ddr_loop_mode
= CLOSE_LOOP_MODE
;
628 gFreqTbl
[5].freq_sel
= LP4_DDR3200
;
629 gFreqTbl
[5].divmode
= DIV8_MODE
;
630 gFreqTbl
[5].shuffleIdx
= SRAM_SHU4
;
631 gFreqTbl
[5].duty_calibration_mode
= DUTY_NEED_K
;
632 gFreqTbl
[5].vref_calibartion_enable
= VREF_CALI_ON
;
633 gFreqTbl
[5].ddr_loop_mode
= CLOSE_LOOP_MODE
;
635 gFreqTbl
[6].freq_sel
= LP4_DDR3200
;
636 gFreqTbl
[6].divmode
= DIV8_MODE
;
637 gFreqTbl
[6].shuffleIdx
= SRAM_SHU6
;
638 gFreqTbl
[6].duty_calibration_mode
= DUTY_NEED_K
;
639 gFreqTbl
[6].vref_calibartion_enable
= VREF_CALI_ON
;
640 gFreqTbl
[6].ddr_loop_mode
= CLOSE_LOOP_MODE
;
644 static void freq_table_are_all_1534(void)
646 gFreqTbl
[0].freq_sel
= LP4_DDR1600
;
647 gFreqTbl
[0].divmode
= DIV8_MODE
;
648 gFreqTbl
[0].shuffleIdx
= SRAM_SHU1
;
649 gFreqTbl
[0].duty_calibration_mode
= DUTY_DEFAULT
;
650 gFreqTbl
[0].vref_calibartion_enable
= VREF_CALI_ON
;
651 gFreqTbl
[0].ddr_loop_mode
= CLOSE_LOOP_MODE
;
653 gFreqTbl
[1].freq_sel
= LP4_DDR1600
;
654 gFreqTbl
[1].divmode
= DIV8_MODE
;
655 gFreqTbl
[1].shuffleIdx
= SRAM_SHU3
;
656 gFreqTbl
[1].duty_calibration_mode
= DUTY_DEFAULT
;
657 gFreqTbl
[1].vref_calibartion_enable
= VREF_CALI_ON
;
658 gFreqTbl
[1].ddr_loop_mode
= CLOSE_LOOP_MODE
;
660 gFreqTbl
[2].freq_sel
= LP4_DDR1600
;
661 gFreqTbl
[2].divmode
= DIV8_MODE
;
662 gFreqTbl
[2].shuffleIdx
= SRAM_SHU2
;
663 gFreqTbl
[2].duty_calibration_mode
= DUTY_DEFAULT
;
664 gFreqTbl
[2].vref_calibartion_enable
= VREF_CALI_ON
;
665 gFreqTbl
[2].ddr_loop_mode
= CLOSE_LOOP_MODE
;
667 gFreqTbl
[3].freq_sel
= LP4_DDR1600
;
668 gFreqTbl
[3].divmode
= DIV8_MODE
;
669 gFreqTbl
[3].shuffleIdx
= SRAM_SHU0
;
670 gFreqTbl
[3].duty_calibration_mode
= DUTY_DEFAULT
;
671 gFreqTbl
[3].vref_calibartion_enable
= VREF_CALI_ON
;
672 gFreqTbl
[3].ddr_loop_mode
= CLOSE_LOOP_MODE
;
674 gFreqTbl
[4].freq_sel
= LP4_DDR1600
;
675 gFreqTbl
[4].divmode
= DIV8_MODE
;
676 gFreqTbl
[4].shuffleIdx
= SRAM_SHU5
;
677 gFreqTbl
[4].duty_calibration_mode
= DUTY_DEFAULT
;
678 gFreqTbl
[4].vref_calibartion_enable
= VREF_CALI_ON
;
679 gFreqTbl
[4].ddr_loop_mode
= CLOSE_LOOP_MODE
;
681 gFreqTbl
[5].freq_sel
= LP4_DDR1600
;
682 gFreqTbl
[5].divmode
= DIV8_MODE
;
683 gFreqTbl
[5].shuffleIdx
= SRAM_SHU4
;
684 gFreqTbl
[5].duty_calibration_mode
= DUTY_DEFAULT
;
685 gFreqTbl
[5].vref_calibartion_enable
= VREF_CALI_ON
;
686 gFreqTbl
[5].ddr_loop_mode
= CLOSE_LOOP_MODE
;
688 gFreqTbl
[6].freq_sel
= LP4_DDR1600
;
689 gFreqTbl
[6].divmode
= DIV8_MODE
;
690 gFreqTbl
[6].shuffleIdx
= SRAM_SHU6
;
691 gFreqTbl
[6].duty_calibration_mode
= DUTY_DEFAULT
;
692 gFreqTbl
[6].vref_calibartion_enable
= VREF_CALI_ON
;
693 gFreqTbl
[6].ddr_loop_mode
= CLOSE_LOOP_MODE
;
697 static void freq_table_opp0_3733_others_3094(void)
699 gFreqTbl
[0].freq_sel
= LP4_DDR3200
;
700 gFreqTbl
[0].divmode
= DIV8_MODE
;
701 gFreqTbl
[0].shuffleIdx
= SRAM_SHU1
;
702 gFreqTbl
[0].duty_calibration_mode
= DUTY_NEED_K
;
703 gFreqTbl
[0].vref_calibartion_enable
= VREF_CALI_ON
;
704 gFreqTbl
[0].ddr_loop_mode
= CLOSE_LOOP_MODE
;
706 gFreqTbl
[1].freq_sel
= LP4_DDR3200
;
707 gFreqTbl
[1].divmode
= DIV8_MODE
;
708 gFreqTbl
[1].shuffleIdx
= SRAM_SHU3
;
709 gFreqTbl
[1].duty_calibration_mode
= DUTY_NEED_K
;
710 gFreqTbl
[1].vref_calibartion_enable
= VREF_CALI_ON
;
711 gFreqTbl
[1].ddr_loop_mode
= CLOSE_LOOP_MODE
;
713 gFreqTbl
[2].freq_sel
= LP4_DDR3200
;
714 gFreqTbl
[2].divmode
= DIV8_MODE
;
715 gFreqTbl
[2].shuffleIdx
= SRAM_SHU2
;
716 gFreqTbl
[2].duty_calibration_mode
= DUTY_NEED_K
;
717 gFreqTbl
[2].vref_calibartion_enable
= VREF_CALI_ON
;
718 gFreqTbl
[2].ddr_loop_mode
= CLOSE_LOOP_MODE
;
720 gFreqTbl
[3].freq_sel
= LP4_DDR3733
;
721 gFreqTbl
[3].divmode
= DIV8_MODE
;
722 gFreqTbl
[3].shuffleIdx
= SRAM_SHU0
;
723 gFreqTbl
[3].duty_calibration_mode
= DUTY_NEED_K
;
724 gFreqTbl
[3].vref_calibartion_enable
= VREF_CALI_ON
;
725 gFreqTbl
[3].ddr_loop_mode
= CLOSE_LOOP_MODE
;
727 gFreqTbl
[4].freq_sel
= LP4_DDR3200
;
728 gFreqTbl
[4].divmode
= DIV8_MODE
;
729 gFreqTbl
[4].shuffleIdx
= SRAM_SHU5
;
730 gFreqTbl
[4].duty_calibration_mode
= DUTY_NEED_K
;
731 gFreqTbl
[4].vref_calibartion_enable
= VREF_CALI_ON
;
732 gFreqTbl
[4].ddr_loop_mode
= CLOSE_LOOP_MODE
;
734 gFreqTbl
[5].freq_sel
= LP4_DDR3200
;
735 gFreqTbl
[5].divmode
= DIV8_MODE
;
736 gFreqTbl
[5].shuffleIdx
= SRAM_SHU4
;
737 gFreqTbl
[5].duty_calibration_mode
= DUTY_NEED_K
;
738 gFreqTbl
[5].vref_calibartion_enable
= VREF_CALI_ON
;
739 gFreqTbl
[5].ddr_loop_mode
= CLOSE_LOOP_MODE
;
741 gFreqTbl
[6].freq_sel
= LP4_DDR3200
;
742 gFreqTbl
[6].divmode
= DIV8_MODE
;
743 gFreqTbl
[6].shuffleIdx
= SRAM_SHU6
;
744 gFreqTbl
[6].duty_calibration_mode
= DUTY_NEED_K
;
745 gFreqTbl
[6].vref_calibartion_enable
= VREF_CALI_ON
;
746 gFreqTbl
[6].ddr_loop_mode
= CLOSE_LOOP_MODE
;
749 static void freq_table_opp0_3094_others_1534(void)
751 gFreqTbl
[0].freq_sel
= LP4_DDR1600
;
752 gFreqTbl
[0].divmode
= DIV8_MODE
;
753 gFreqTbl
[0].shuffleIdx
= SRAM_SHU1
;
754 gFreqTbl
[0].duty_calibration_mode
= DUTY_DEFAULT
;
755 gFreqTbl
[0].vref_calibartion_enable
= VREF_CALI_ON
;
756 gFreqTbl
[0].ddr_loop_mode
= CLOSE_LOOP_MODE
;
758 gFreqTbl
[1].freq_sel
= LP4_DDR1600
;
759 gFreqTbl
[1].divmode
= DIV8_MODE
;
760 gFreqTbl
[1].shuffleIdx
= SRAM_SHU3
;
761 gFreqTbl
[1].duty_calibration_mode
= DUTY_DEFAULT
;
762 gFreqTbl
[1].vref_calibartion_enable
= VREF_CALI_ON
;
763 gFreqTbl
[1].ddr_loop_mode
= CLOSE_LOOP_MODE
;
765 gFreqTbl
[2].freq_sel
= LP4_DDR1600
;
766 gFreqTbl
[2].divmode
= DIV8_MODE
;
767 gFreqTbl
[2].shuffleIdx
= SRAM_SHU2
;
768 gFreqTbl
[2].duty_calibration_mode
= DUTY_DEFAULT
;
769 gFreqTbl
[2].vref_calibartion_enable
= VREF_CALI_ON
;
770 gFreqTbl
[2].ddr_loop_mode
= CLOSE_LOOP_MODE
;
772 gFreqTbl
[3].freq_sel
= LP4_DDR3200
;
773 gFreqTbl
[3].divmode
= DIV8_MODE
;
774 gFreqTbl
[3].shuffleIdx
= SRAM_SHU0
;
775 gFreqTbl
[3].duty_calibration_mode
= DUTY_NEED_K
;
776 gFreqTbl
[3].vref_calibartion_enable
= VREF_CALI_ON
;
777 gFreqTbl
[3].ddr_loop_mode
= CLOSE_LOOP_MODE
;
779 gFreqTbl
[4].freq_sel
= LP4_DDR1600
;
780 gFreqTbl
[4].divmode
= DIV8_MODE
;
781 gFreqTbl
[4].shuffleIdx
= SRAM_SHU5
;
782 gFreqTbl
[4].duty_calibration_mode
= DUTY_DEFAULT
;
783 gFreqTbl
[4].vref_calibartion_enable
= VREF_CALI_ON
;
784 gFreqTbl
[4].ddr_loop_mode
= CLOSE_LOOP_MODE
;
786 gFreqTbl
[5].freq_sel
= LP4_DDR1600
;
787 gFreqTbl
[5].divmode
= DIV8_MODE
;
788 gFreqTbl
[5].shuffleIdx
= SRAM_SHU4
;
789 gFreqTbl
[5].duty_calibration_mode
= DUTY_DEFAULT
;
790 gFreqTbl
[5].vref_calibartion_enable
= VREF_CALI_ON
;
791 gFreqTbl
[5].ddr_loop_mode
= CLOSE_LOOP_MODE
;
793 gFreqTbl
[6].freq_sel
= LP4_DDR1600
;
794 gFreqTbl
[6].divmode
= DIV8_MODE
;
795 gFreqTbl
[6].shuffleIdx
= SRAM_SHU6
;
796 gFreqTbl
[6].duty_calibration_mode
= DUTY_DEFAULT
;
797 gFreqTbl
[6].vref_calibartion_enable
= VREF_CALI_ON
;
798 gFreqTbl
[6].ddr_loop_mode
= CLOSE_LOOP_MODE
;
801 static void freq_table_opp0_2400_others_1534(void)
803 gFreqTbl
[0].freq_sel
= LP4_DDR1600
;
804 gFreqTbl
[0].divmode
= DIV8_MODE
;
805 gFreqTbl
[0].shuffleIdx
= SRAM_SHU1
;
806 gFreqTbl
[0].duty_calibration_mode
= DUTY_DEFAULT
;
807 gFreqTbl
[0].vref_calibartion_enable
= VREF_CALI_ON
;
808 gFreqTbl
[0].ddr_loop_mode
= CLOSE_LOOP_MODE
;
810 gFreqTbl
[1].freq_sel
= LP4_DDR1600
;
811 gFreqTbl
[1].divmode
= DIV8_MODE
;
812 gFreqTbl
[1].shuffleIdx
= SRAM_SHU3
;
813 gFreqTbl
[1].duty_calibration_mode
= DUTY_DEFAULT
;
814 gFreqTbl
[1].vref_calibartion_enable
= VREF_CALI_ON
;
815 gFreqTbl
[1].ddr_loop_mode
= CLOSE_LOOP_MODE
;
817 gFreqTbl
[2].freq_sel
= LP4_DDR1600
;
818 gFreqTbl
[2].divmode
= DIV8_MODE
;
819 gFreqTbl
[2].shuffleIdx
= SRAM_SHU2
;
820 gFreqTbl
[2].duty_calibration_mode
= DUTY_DEFAULT
;
821 gFreqTbl
[2].vref_calibartion_enable
= VREF_CALI_ON
;
822 gFreqTbl
[2].ddr_loop_mode
= CLOSE_LOOP_MODE
;
824 gFreqTbl
[3].freq_sel
= LP4_DDR2400
;
825 gFreqTbl
[3].divmode
= DIV8_MODE
;
826 gFreqTbl
[3].shuffleIdx
= SRAM_SHU0
;
827 gFreqTbl
[3].duty_calibration_mode
= DUTY_NEED_K
;
828 gFreqTbl
[3].vref_calibartion_enable
= VREF_CALI_ON
;
829 gFreqTbl
[3].ddr_loop_mode
= CLOSE_LOOP_MODE
;
831 gFreqTbl
[4].freq_sel
= LP4_DDR1600
;
832 gFreqTbl
[4].divmode
= DIV8_MODE
;
833 gFreqTbl
[4].shuffleIdx
= SRAM_SHU5
;
834 gFreqTbl
[4].duty_calibration_mode
= DUTY_DEFAULT
;
835 gFreqTbl
[4].vref_calibartion_enable
= VREF_CALI_ON
;
836 gFreqTbl
[4].ddr_loop_mode
= CLOSE_LOOP_MODE
;
838 gFreqTbl
[5].freq_sel
= LP4_DDR1600
;
839 gFreqTbl
[5].divmode
= DIV8_MODE
;
840 gFreqTbl
[5].shuffleIdx
= SRAM_SHU4
;
841 gFreqTbl
[5].duty_calibration_mode
= DUTY_DEFAULT
;
842 gFreqTbl
[5].vref_calibartion_enable
= VREF_CALI_ON
;
843 gFreqTbl
[5].ddr_loop_mode
= CLOSE_LOOP_MODE
;
845 gFreqTbl
[6].freq_sel
= LP4_DDR1600
;
846 gFreqTbl
[6].divmode
= DIV8_MODE
;
847 gFreqTbl
[6].shuffleIdx
= SRAM_SHU6
;
848 gFreqTbl
[6].duty_calibration_mode
= DUTY_DEFAULT
;
849 gFreqTbl
[6].vref_calibartion_enable
= VREF_CALI_ON
;
850 gFreqTbl
[6].ddr_loop_mode
= CLOSE_LOOP_MODE
;
852 #if (CFG_DRAM_LOG_TO_STORAGE)
854 extern u64
get_part_addr(const char *name
);
855 u64 part_dram_data_addr_uart
= 0;
857 static char logbuf
[1024];
862 void update_voltage_select_info(void)
864 voltage_sel_info_ptr
.vcore
= doe_get_config("vcore");
865 voltage_sel_info_ptr
.vdram
= doe_get_config("vdram");
866 voltage_sel_info_ptr
.vddq
= doe_get_config("vddq");
867 voltage_sel_info_ptr
.vmddr
= doe_get_config("vmddr");
868 voltage_sel_info_ptr
.vio18
= doe_get_config("vio18");
870 print("DOE setting: vcore %d, vdram %d, vddq %d, vmddr %d, vio18 %d \n",
871 voltage_sel_info_ptr
.vcore
, voltage_sel_info_ptr
.vdram
,
872 voltage_sel_info_ptr
.vddq
, voltage_sel_info_ptr
.vmddr
,
873 voltage_sel_info_ptr
.vio18
);
876 int vio18_voltage_select()
878 if (voltage_sel_info_ptr
.vio18
== LEVEL_LV
) {
880 } else if (voltage_sel_info_ptr
.vio18
== LEVEL_HV
) {
887 int vmddr_voltage_select()
889 if (voltage_sel_info_ptr
.vmddr
== LEVEL_LV
) {
890 return HQA_VMDDR_LV_LP4
;
891 } else if (voltage_sel_info_ptr
.vmddr
== LEVEL_HV
) {
892 return HQA_VMDDR_HV_LP4
;
894 return HQA_VMDDR_NV_LP4
;
898 int vddq_voltage_select()
900 if (voltage_sel_info_ptr
.vddq
== LEVEL_LV
) {
901 return HQA_VDDQ_LV_LP4
;
902 } else if (voltage_sel_info_ptr
.vddq
== LEVEL_HV
) {
903 return HQA_VDDQ_HV_LP4
;
905 return HQA_VDDQ_NV_LP4
;
909 int vdram_voltage_select(void)
911 if (voltage_sel_info_ptr
.vdram
== LEVEL_LV
) {
912 return HQA_VDRAM_LV_LP4
;
913 } else if (voltage_sel_info_ptr
.vdram
== LEVEL_HV
) {
914 return HQA_VDRAM_HV_LP4
;
916 return HQA_VDRAM_NV_LP4
;
920 int vcore_voltage_select(DRAM_KSHU kshu
)
923 if (voltage_sel_info_ptr
.vcore
== LEVEL_LV
) {
926 ret
= HQA_VCORE_LV_LP4_KSHU0_PL
;
929 ret
= HQA_VCORE_LV_LP4_KSHU1_PL
;
932 ret
= HQA_VCORE_LV_LP4_KSHU2_PL
;
935 ret
= HQA_VCORE_LV_LP4_KSHU3_PL
;
938 ret
= HQA_VCORE_LV_LP4_KSHU4_PL
;
941 ret
= HQA_VCORE_LV_LP4_KSHU5_PL
;
944 ret
= HQA_VCORE_LV_LP4_KSHU6_PL
;
947 } else if (voltage_sel_info_ptr
.vcore
== LEVEL_HV
) {
950 ret
= HQA_VCORE_HV_LP4_KSHU0_PL
;
953 ret
= HQA_VCORE_HV_LP4_KSHU1_PL
;
956 ret
= HQA_VCORE_HV_LP4_KSHU2_PL
;
959 ret
= HQA_VCORE_HV_LP4_KSHU3_PL
;
962 ret
= HQA_VCORE_HV_LP4_KSHU4_PL
;
965 ret
= HQA_VCORE_HV_LP4_KSHU5_PL
;
968 ret
= HQA_VCORE_HV_LP4_KSHU6_PL
;
972 #if defined(VCORE_BIN)
977 ret
= HQA_VCORE_NV_LP4_KSHU0_PL
;
980 ret
= HQA_VCORE_NV_LP4_KSHU1_PL
;
983 ret
= HQA_VCORE_NV_LP4_KSHU2_PL
;
986 ret
= HQA_VCORE_NV_LP4_KSHU3_PL
;
989 ret
= HQA_VCORE_NV_LP4_KSHU4_PL
;
992 ret
= HQA_VCORE_NV_LP4_KSHU5_PL
;
995 ret
= HQA_VCORE_NV_LP4_KSHU6_PL
;
1006 #if (FOR_DV_SIMULATION_USED==0)
1008 void mt_set_emi(struct dramc_param
*dparam
)
1011 /*unsigned int SW_CTRL_VC, HW_CTRL_VC;*/
1012 EMI_SETTINGS
*emi_set
= &emi_settings
[0];
1017 update_voltage_select_info();
1019 #if ENABLE_PINMUX_FOR_RANK_SWAP
1020 EMI_rank_swap_handle();
1023 // set voltage and hw trapping before mdl
1024 setup_dramc_voltage_by_pmic();
1026 if ((doe_get_config("dram_all_3094_0825")) || (doe_get_config("dram_all_3094_0725")))
1027 freq_table_are_all_3094();
1028 else if (doe_get_config("dram_all_1534_0725"))
1029 freq_table_are_all_1534();
1030 else if (doe_get_config("dram_opp0_3733_others_3094_0825"))
1031 freq_table_opp0_3733_others_3094();
1032 else if (doe_get_config("dram_opp0_3094_others_1534_0725"))
1033 freq_table_opp0_3094_others_1534();
1034 else if (doe_get_config("dram_opp0_2400_others_1534_0725"))
1035 freq_table_opp0_2400_others_1534();
1039 index
= mt_get_mdl_number();
1040 dramc_crit("[EMI] MDL number = %d\r\n", index
);
1041 if (index
< 0 || index
>= num_of_emi_records
)
1043 die("[EMI] setting failed 0x%x\r\n", index
);
1047 emi_setting_index
= index
;
1048 emi_set
= &emi_settings
[emi_setting_index
];
1050 dramc_crit("[EMI] Get MDL freq = %d\r\n", emi_set
->DRAMC_ACTIME_UNION
[0]);
1052 dramc_crit("[EMI] ComboMCP not ready, using default setting\n");
1053 emi_setting_index
= -1;
1054 emi_set
= &default_emi_setting
;
1056 segment
= (seclib_get_devinfo_with_index(7) & 0xFF);
1057 if ((segment
== 0x80) || (segment
== 0x01) || (segment
== 0x40) || (segment
== 0x02))
1059 emi_set
->DRAMC_ACTIME_UNION
[0] = 3733;
1061 #ifdef DDR_RESERVE_MODE
1062 if(g_ddr_reserve_enable
==1 && g_ddr_reserve_success
==0)
1063 Before_Init_DRAM_While_Reserve_Mode_fail(emi_set
->type
& 0xF);
1066 #if (CFG_DRAM_LOG_TO_STORAGE)
1068 print("log_start=0x%x part_dram_data_addr_uart=0x%llx \n",log_start
,part_dram_data_addr_uart
);
1071 SLT_Init_DRAM((emi_set
->type
& 0xF), emi_set
->dram_cbt_mode_extern
, NULL
, NORMAL_USED
);
1073 Init_DRAM((emi_set
->type
& 0xF), emi_set
->dram_cbt_mode_extern
, NULL
, NORMAL_USED
);
1075 switch_dramc_voltage_to_auto_mode();
1076 restore_vcore_setting();
1078 #if (CFG_DRAM_LOG_TO_STORAGE)
1080 print("log_start=0x%x part_dram_data_addr_uart=0x%llx \n",log_start
,part_dram_data_addr_uart
);
1084 DRAMC_CTX_T
* p
= psCurrDramCtx
;
1092 #define DRAMC_ADDR_SHIFT_CHN(addr, channel) (addr + (channel * 0x10000))
1094 #if (FOR_DV_SIMULATION_USED==0) // for DV sim build pass
1095 int doe_get_config(const char* feature
)
1097 #if defined(ENABLE_DOE)
1098 char *doe_feature
= dconfig_getenv(feature
);
1099 int doe_result
= atoi(doe_feature
);
1100 dramc_crit("DOE force setting %s=%d\n", feature
, doe_result
);
1108 #if (CFG_DRAM_LOG_TO_STORAGE)
1109 void log_to_storage(const char c
)
1112 blkdev_t
*bootdev
= NULL
;
1113 static u8 logen
= 0;
1115 bootdev
= blkdev_get(CFG_BOOT_DEV
);
1117 if (log_start
&& (!logen
)) {
1120 part_dram_data_addr_uart
= get_part_addr("boot_para") + 0x100000; // addr = 0x1f300000, the first 1MB for debug
1121 memset(&logbuf
, 0, sizeof(logbuf
));
1122 for (clr_count
= 0; clr_count
< 3072 ; clr_count
++) //3M
1123 ret
= blkdev_write(bootdev
, (part_dram_data_addr_uart
+ (1024 * clr_count
)), 1024, (u8
*)&logbuf
, storage_get_part_id(STORAGE_PHYS_PART_USER
));
1127 if (((((char) c
>> 4) & 0x7) > 1) & ((((char) c
>> 4) & 0x7) < 7))
1128 logbuf
[logcount
] = ((char) c
& 0xF0) | (((char) c
>> 2) & 0x03) | (((char) c
<< 2) & 0x0C);
1130 logbuf
[logcount
] = (char) c
;
1131 logcount
= logcount
+ 1;
1133 if (logcount
==1024) {
1135 ret
= blkdev_write(bootdev
, part_dram_data_addr_uart
, 1024, (u8
*)&logbuf
, storage_get_part_id(STORAGE_PHYS_PART_USER
));
1136 part_dram_data_addr_uart
= part_dram_data_addr_uart
+ 1024;
1141 #if SUPPORT_SAVE_TIME_FOR_CALIBRATION
1143 u32 g_dram_storage_api_err_code
;
1146 int read_offline_dram_calibration_data(DRAM_DFS_SHUFFLE_TYPE_T shuffle
, SAVE_TIME_FOR_CALIBRATION_T
*offLine_SaveData
)
1148 struct sdram_params
*params
;
1152 params
= &dramc_params
->dramc_datas
.freq_params
[shuffle
];
1154 dramc_info("read calibration data from shuffle %d(For verify: WL B0:%u, B1: %u)\n",
1155 shuffle
, params
->wr_level
[CHANNEL_A
][RANK_0
][0], params
->wr_level
[CHANNEL_B
][RANK_0
][0]);
1156 /* copy the data stored in storage to the data structure for calibration */
1157 memcpy(offLine_SaveData
, params
, sizeof(*offLine_SaveData
));
1162 int write_offline_dram_calibration_data(DRAM_DFS_SHUFFLE_TYPE_T shuffle
, SAVE_TIME_FOR_CALIBRATION_T
*offLine_SaveData
)
1167 int clean_dram_calibration_data(void)
1176 #if __FLASH_TOOL_DA__
1177 unsigned int get_mr8_by_mrr(U8 channel
, U8 rank
)
1179 DRAMC_CTX_T
*p
= psCurrDramCtx
;
1180 unsigned int mr8_value
;
1182 p
->channel
= channel
;
1184 vIO32WriteFldAlign(DRAMC_REG_ADDR(DRAMC_REG_SWCMD_CTRL0
), rank
, SWCMD_CTRL0_MRRRK
);
1185 vIO32WriteFldAlign(DRAMC_REG_ADDR(DRAMC_REG_SWCMD_CTRL0
), 8, SWCMD_CTRL0_MRSMA
);
1186 vIO32WriteFldAlign(DRAMC_REG_ADDR(DRAMC_REG_SWCMD_EN
), 1, SWCMD_EN_MRREN
);
1187 while (u4IO32ReadFldAlign(DRAMC_REG_ADDR(DRAMC_REG_SPCMDRESP
), SPCMDRESP_MRR_RESPONSE
) ==0)
1189 mr8_value
= u4IO32ReadFldAlign(DRAMC_REG_ADDR(DRAMC_REG_MRR_STATUS
), MRR_STATUS_MRR_REG
);
1190 vIO32WriteFldAlign(DRAMC_REG_ADDR(DRAMC_REG_SWCMD_EN
), 0, SWCMD_EN_MRREN
);
1191 vIO32WriteFldAlign(DRAMC_REG_ADDR(DRAMC_REG_SWCMD_CTRL0
), 0, SWCMD_CTRL0_MRRRK
);
1193 return (mr8_value
& 0xff);