Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) Marvell International Ltd. and its affiliates |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 6 | #include "ddr3_init.h" |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 7 | #include "mv_ddr_common.h" |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 8 | |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 9 | #if defined(CONFIG_DDR4) |
| 10 | static char *ddr_type = "DDR4"; |
| 11 | #else /* CONFIG_DDR4 */ |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 12 | static char *ddr_type = "DDR3"; |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 13 | #endif /* CONFIG_DDR4 */ |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 14 | |
| 15 | /* |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 16 | * generic_init_controller controls D-unit configuration: |
| 17 | * '1' - dynamic D-unit configuration, |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 18 | */ |
| 19 | u8 generic_init_controller = 1; |
| 20 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 21 | static int mv_ddr_training_params_set(u8 dev_num); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 22 | |
| 23 | /* |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 24 | * Name: ddr3_init - Main DDR3 Init function |
| 25 | * Desc: This routine initialize the DDR3 MC and runs HW training. |
| 26 | * Args: None. |
| 27 | * Notes: |
| 28 | * Returns: None. |
| 29 | */ |
| 30 | int ddr3_init(void) |
| 31 | { |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 32 | int status; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 33 | int is_manual_cal_done; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 34 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 35 | /* Print mv_ddr version */ |
| 36 | mv_ddr_ver_print(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 37 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 38 | mv_ddr_pre_training_fixup(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 39 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 40 | /* SoC/Board special initializations */ |
| 41 | mv_ddr_pre_training_soc_config(ddr_type); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 42 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 43 | /* Set log level for training library */ |
| 44 | mv_ddr_user_log_level_set(DEBUG_BLOCK_ALL); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 45 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 46 | mv_ddr_early_init(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 47 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 48 | if (mv_ddr_topology_map_update()) { |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 49 | printf("mv_ddr: failed to update topology\n"); |
| 50 | return MV_FAIL; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 53 | if (mv_ddr_early_init2() != MV_OK) |
| 54 | return MV_FAIL; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 55 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 56 | /* Set training algorithm's parameters */ |
| 57 | status = mv_ddr_training_params_set(0); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 58 | if (MV_OK != status) |
| 59 | return status; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 60 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 61 | mv_ddr_mc_config(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 62 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 63 | is_manual_cal_done = mv_ddr_manual_cal_do(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 64 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 65 | mv_ddr_mc_init(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 66 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 67 | if (!is_manual_cal_done) { |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 68 | #if defined(CONFIG_DDR4) |
| 69 | status = mv_ddr4_calibration_adjust(0, 1, 0); |
| 70 | if (status != MV_OK) { |
| 71 | printf("%s: failed (0x%x)\n", __func__, status); |
| 72 | return status; |
| 73 | } |
| 74 | #endif |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 77 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 78 | status = ddr3_silicon_post_init(); |
| 79 | if (MV_OK != status) { |
| 80 | printf("DDR3 Post Init - FAILED 0x%x\n", status); |
| 81 | return status; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 82 | } |
| 83 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 84 | /* PHY initialization (Training) */ |
| 85 | status = hws_ddr3_tip_run_alg(0, ALGO_TYPE_DYNAMIC); |
| 86 | if (MV_OK != status) { |
| 87 | printf("%s Training Sequence - FAILED\n", ddr_type); |
| 88 | return status; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 89 | } |
| 90 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 91 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 92 | /* Post MC/PHY initializations */ |
| 93 | mv_ddr_post_training_soc_config(ddr_type); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 94 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 95 | mv_ddr_post_training_fixup(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 96 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 97 | if (mv_ddr_is_ecc_ena()) |
| 98 | mv_ddr_mem_scrubbing(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 99 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 100 | printf("mv_ddr: completed successfully\n"); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 101 | |
| 102 | return MV_OK; |
| 103 | } |
| 104 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 105 | /* |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 106 | * Name: mv_ddr_training_params_set |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 107 | * Desc: |
| 108 | * Args: |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 109 | * Notes: sets internal training params |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 110 | * Returns: |
| 111 | */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 112 | static int mv_ddr_training_params_set(u8 dev_num) |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 113 | { |
| 114 | struct tune_train_params params; |
Baruch Siach | 4951d42 | 2021-02-19 17:11:17 +0100 | [diff] [blame] | 115 | struct mv_ddr_topology_map *tm = mv_ddr_topology_map_get(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 116 | int status; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 117 | u32 cs_num; |
Chris Packham | e422adc | 2020-01-30 12:50:44 +1300 | [diff] [blame] | 118 | int ck_delay; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 119 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 120 | cs_num = mv_ddr_cs_num_get(); |
Chris Packham | e422adc | 2020-01-30 12:50:44 +1300 | [diff] [blame] | 121 | ck_delay = mv_ddr_ck_delay_get(); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 122 | |
| 123 | /* NOTE: do not remove any field initilization */ |
| 124 | params.ck_delay = TUNE_TRAINING_PARAMS_CK_DELAY; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 125 | params.phy_reg3_val = TUNE_TRAINING_PARAMS_PHYREG3VAL; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 126 | params.g_zpri_data = TUNE_TRAINING_PARAMS_PRI_DATA; |
| 127 | params.g_znri_data = TUNE_TRAINING_PARAMS_NRI_DATA; |
| 128 | params.g_zpri_ctrl = TUNE_TRAINING_PARAMS_PRI_CTRL; |
| 129 | params.g_znri_ctrl = TUNE_TRAINING_PARAMS_NRI_CTRL; |
| 130 | params.g_znodt_data = TUNE_TRAINING_PARAMS_N_ODT_DATA; |
| 131 | params.g_zpodt_ctrl = TUNE_TRAINING_PARAMS_P_ODT_CTRL; |
| 132 | params.g_znodt_ctrl = TUNE_TRAINING_PARAMS_N_ODT_CTRL; |
| 133 | |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 134 | #if defined(CONFIG_DDR4) |
| 135 | params.g_zpodt_data = TUNE_TRAINING_PARAMS_P_ODT_DATA_DDR4; |
| 136 | params.g_odt_config = TUNE_TRAINING_PARAMS_ODT_CONFIG_DDR4; |
| 137 | params.g_rtt_nom = TUNE_TRAINING_PARAMS_RTT_NOM_DDR4; |
| 138 | params.g_dic = TUNE_TRAINING_PARAMS_DIC_DDR4; |
| 139 | if (cs_num == 1) { |
| 140 | params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_1CS; |
| 141 | params.g_rtt_park = TUNE_TRAINING_PARAMS_RTT_PARK_1CS; |
| 142 | } else { |
| 143 | params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_2CS; |
| 144 | params.g_rtt_park = TUNE_TRAINING_PARAMS_RTT_PARK_2CS; |
| 145 | } |
| 146 | #else /* CONFIG_DDR4 */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 147 | params.g_zpodt_data = TUNE_TRAINING_PARAMS_P_ODT_DATA; |
| 148 | params.g_dic = TUNE_TRAINING_PARAMS_DIC; |
| 149 | params.g_rtt_nom = TUNE_TRAINING_PARAMS_RTT_NOM; |
| 150 | if (cs_num == 1) { |
| 151 | params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_1CS; |
| 152 | params.g_odt_config = TUNE_TRAINING_PARAMS_ODT_CONFIG_1CS; |
| 153 | } else { |
| 154 | params.g_rtt_wr = TUNE_TRAINING_PARAMS_RTT_WR_2CS; |
| 155 | params.g_odt_config = TUNE_TRAINING_PARAMS_ODT_CONFIG_2CS; |
| 156 | } |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 157 | #endif /* CONFIG_DDR4 */ |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 158 | |
Chris Packham | e422adc | 2020-01-30 12:50:44 +1300 | [diff] [blame] | 159 | if (ck_delay > 0) |
| 160 | params.ck_delay = ck_delay; |
| 161 | |
Baruch Siach | 4951d42 | 2021-02-19 17:11:17 +0100 | [diff] [blame] | 162 | /* Use platform specific override ODT value */ |
| 163 | if (tm->odt_config) |
| 164 | params.g_odt_config = tm->odt_config; |
| 165 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 166 | status = ddr3_tip_tune_training_params(dev_num, ¶ms); |
| 167 | if (MV_OK != status) { |
| 168 | printf("%s Training Sequence - FAILED\n", ddr_type); |
| 169 | return status; |
| 170 | } |
| 171 | |
| 172 | return MV_OK; |
| 173 | } |