2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-03-26 14:36:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) Marvell International Ltd. and its affiliates
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ddr3_init.h"
|
2018-05-10 01:28:29 +00:00
|
|
|
#include "mv_ddr_common.h"
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2023-01-19 03:03:04 +00:00
|
|
|
#if defined(CONFIG_DDR4)
|
|
|
|
static char *ddr_type = "DDR4";
|
|
|
|
#else /* CONFIG_DDR4 */
|
2015-03-26 14:36:56 +00:00
|
|
|
static char *ddr_type = "DDR3";
|
2023-01-19 03:03:04 +00:00
|
|
|
#endif /* CONFIG_DDR4 */
|
2015-03-26 14:36:56 +00:00
|
|
|
|
|
|
|
/*
|
2018-05-10 01:28:29 +00:00
|
|
|
* generic_init_controller controls D-unit configuration:
|
|
|
|
* '1' - dynamic D-unit configuration,
|
2015-03-26 14:36:56 +00:00
|
|
|
*/
|
|
|
|
u8 generic_init_controller = 1;
|
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
static int mv_ddr_training_params_set(u8 dev_num);
|
2015-03-26 14:36:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Name: ddr3_init - Main DDR3 Init function
|
|
|
|
* Desc: This routine initialize the DDR3 MC and runs HW training.
|
|
|
|
* Args: None.
|
|
|
|
* Notes:
|
|
|
|
* Returns: None.
|
|
|
|
*/
|
|
|
|
int ddr3_init(void)
|
|
|
|
{
|
|
|
|
int status;
|
2018-05-10 01:28:29 +00:00
|
|
|
int is_manual_cal_done;
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
/* Print mv_ddr version */
|
|
|
|
mv_ddr_ver_print();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
mv_ddr_pre_training_fixup();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
/* SoC/Board special initializations */
|
|
|
|
mv_ddr_pre_training_soc_config(ddr_type);
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
/* Set log level for training library */
|
|
|
|
mv_ddr_user_log_level_set(DEBUG_BLOCK_ALL);
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
mv_ddr_early_init();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-12-03 01:26:49 +00:00
|
|
|
if (mv_ddr_topology_map_update()) {
|
2018-05-10 01:28:29 +00:00
|
|
|
printf("mv_ddr: failed to update topology\n");
|
|
|
|
return MV_FAIL;
|
2015-03-26 14:36:56 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
if (mv_ddr_early_init2() != MV_OK)
|
|
|
|
return MV_FAIL;
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
/* Set training algorithm's parameters */
|
|
|
|
status = mv_ddr_training_params_set(0);
|
|
|
|
if (MV_OK != status)
|
|
|
|
return status;
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
mv_ddr_mc_config();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
is_manual_cal_done = mv_ddr_manual_cal_do();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
mv_ddr_mc_init();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
if (!is_manual_cal_done) {
|
2023-01-19 03:03:04 +00:00
|
|
|
#if defined(CONFIG_DDR4)
|
|
|
|
status = mv_ddr4_calibration_adjust(0, 1, 0);
|
|
|
|
if (status != MV_OK) {
|
|
|
|
printf("%s: failed (0x%x)\n", __func__, status);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
#endif
|
2018-05-10 01:28:29 +00:00
|
|
|
}
|
2015-03-26 14:36:56 +00:00
|
|
|
|
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
status = ddr3_silicon_post_init();
|
|
|
|
if (MV_OK != status) {
|
|
|
|
printf("DDR3 Post Init - FAILED 0x%x\n", status);
|
|
|
|
return status;
|
2015-03-26 14:36:56 +00:00
|
|
|
}
|
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
/* PHY initialization (Training) */
|
|
|
|
status = hws_ddr3_tip_run_alg(0, ALGO_TYPE_DYNAMIC);
|
|
|
|
if (MV_OK != status) {
|
|
|
|
printf("%s Training Sequence - FAILED\n", ddr_type);
|
|
|
|
return status;
|
|
|
|
}
|
2015-03-26 14:36:56 +00:00
|
|
|
|
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
/* Post MC/PHY initializations */
|
|
|
|
mv_ddr_post_training_soc_config(ddr_type);
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
mv_ddr_post_training_fixup();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-12-03 01:26:49 +00:00
|
|
|
if (mv_ddr_is_ecc_ena())
|
|
|
|
mv_ddr_mem_scrubbing();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
printf("mv_ddr: completed successfully\n");
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2018-05-10 01:28:29 +00:00
|
|
|
return MV_OK;
|
2015-03-26 14:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-05-10 01:28:29 +00:00
|
|
|
* Name: mv_ddr_training_params_set
|
2015-03-26 14:36:56 +00:00
|
|
|
* Desc:
|
|
|
|
* Args:
|
2018-05-10 01:28:29 +00:00
|
|
|
* Notes: sets internal training params
|
2015-03-26 14:36:56 +00:00
|
|
|
* Returns:
|
|
|
|
*/
|
2018-05-10 01:28:29 +00:00
|
|
|
static int mv_ddr_training_params_set(u8 dev_num)
|
2015-03-26 14:36:56 +00:00
|
|
|
{
|
|
|
|
struct tune_train_params params;
|
2021-02-19 16:11:17 +00:00
|
|
|
struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get();
|
2015-03-26 14:36:56 +00:00
|
|
|
int status;
|
2018-05-10 01:28:29 +00:00
|
|
|
u32 cs_num;
|
2020-01-29 23:50:44 +00:00
|
|
|
int ck_delay;
|
2018-05-10 01:28:29 +00:00
|
|
|
|
2018-12-03 01:26:49 +00:00
|
|
|
cs_num = mv_ddr_cs_num_get();
|
2020-01-29 23:50:44 +00:00
|
|
|
ck_delay = mv_ddr_ck_delay_get();
|
2015-03-26 14:36:56 +00:00
|
|
|
|
|
|
|
/* NOTE: do not remove any field initilization */
|
|
|
|
params.ck_delay = TUNE_TRAINING_PARAMS_CK_DELAY;
|
|
|
|
params.phy_reg3_val = TUNE_TRAINING_PARAMS_PHYREG3VAL;
|
2018-05-10 01:28:29 +00:00
|
|
|
params.g_zpri_data = TUNE_TRAINING_PARAMS_PRI_DATA;
|
|
|
|
params.g_znri_data = TUNE_TRAINING_PARAMS_NRI_DATA;
|
|
|
|
params.g_zpri_ctrl = TUNE_TRAINING_PARAMS_PRI_CTRL;
|
|
|
|
params.g_znri_ctrl = TUNE_TRAINING_PARAMS_NRI_CTRL;
|
|
|
|
params.g_znodt_data = TUNE_TRAINING_PARAMS_N_ODT_DATA;
|
|
|
|
params.g_zpodt_ctrl = TUNE_TRAINING_PARAMS_P_ODT_CTRL;
|
|
|
|
params.g_znodt_ctrl = TUNE_TRAINING_PARAMS_N_ODT_CTRL;
|
|
|
|
|
2023-01-19 03:03:04 +00:00
|
|
|
#if defined(CONFIG_DDR4)
|
|
|
|
params.g_zpodt_data = TUNE_TRAINING_PARAMS_P_ODT_DATA_DDR4;
|
|
|
|
params.g_odt_config = TUNE_TRAINING_PARAMS_ODT_CONFIG_DDR4;
|
|
|
|
params.g_rtt_nom = TUNE_TRAINING_PARAMS_RTT_NOM_DDR4;
|
|
|
|
params.g_dic = TUNE_TRAINING_PARAMS_DIC_DDR4;
|
|
|
|
if (cs_num == 1) {
|
|
|
|
params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_1CS;
|
|
|
|
params.g_rtt_park = TUNE_TRAINING_PARAMS_RTT_PARK_1CS;
|
|
|
|
} else {
|
|
|
|
params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_2CS;
|
|
|
|
params.g_rtt_park = TUNE_TRAINING_PARAMS_RTT_PARK_2CS;
|
|
|
|
}
|
|
|
|
#else /* CONFIG_DDR4 */
|
2018-05-10 01:28:29 +00:00
|
|
|
params.g_zpodt_data = TUNE_TRAINING_PARAMS_P_ODT_DATA;
|
|
|
|
params.g_dic = TUNE_TRAINING_PARAMS_DIC;
|
|
|
|
params.g_rtt_nom = TUNE_TRAINING_PARAMS_RTT_NOM;
|
|
|
|
if (cs_num == 1) {
|
|
|
|
params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_1CS;
|
|
|
|
params.g_odt_config = TUNE_TRAINING_PARAMS_ODT_CONFIG_1CS;
|
|
|
|
} else {
|
|
|
|
params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_2CS;
|
|
|
|
params.g_odt_config = TUNE_TRAINING_PARAMS_ODT_CONFIG_2CS;
|
|
|
|
}
|
2023-01-19 03:03:04 +00:00
|
|
|
#endif /* CONFIG_DDR4 */
|
2015-03-26 14:36:56 +00:00
|
|
|
|
2020-01-29 23:50:44 +00:00
|
|
|
if (ck_delay > 0)
|
|
|
|
params.ck_delay = ck_delay;
|
|
|
|
|
2021-02-19 16:11:17 +00:00
|
|
|
/* Use platform specific override ODT value */
|
|
|
|
if (tm->odt_config)
|
|
|
|
params.g_odt_config = tm->odt_config;
|
|
|
|
|
2015-03-26 14:36:56 +00:00
|
|
|
status = ddr3_tip_tune_training_params(dev_num, ¶ms);
|
|
|
|
if (MV_OK != status) {
|
|
|
|
printf("%s Training Sequence - FAILED\n", ddr_type);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return MV_OK;
|
|
|
|
}
|