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 | |
| 6 | #ifndef _DDR3_INIT_H |
| 7 | #define _DDR3_INIT_H |
| 8 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 9 | #include "ddr_ml_wrapper.h" |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 10 | #include "mv_ddr_plat.h" |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 11 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 12 | #include "ddr3_logging_def.h" |
| 13 | #include "ddr3_training_hw_algo.h" |
| 14 | #include "ddr3_training_ip.h" |
| 15 | #include "ddr3_training_ip_centralization.h" |
| 16 | #include "ddr3_training_ip_engine.h" |
| 17 | #include "ddr3_training_ip_flow.h" |
| 18 | #include "ddr3_training_ip_pbs.h" |
| 19 | #include "ddr3_training_ip_prv_if.h" |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 20 | #include "ddr3_training_leveling.h" |
| 21 | #include "xor.h" |
| 22 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 23 | /* For checking function return values */ |
| 24 | #define CHECK_STATUS(orig_func) \ |
| 25 | { \ |
| 26 | int status; \ |
| 27 | status = orig_func; \ |
| 28 | if (MV_OK != status) \ |
| 29 | return status; \ |
| 30 | } |
| 31 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 32 | #define SUB_VERSION 0 |
| 33 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 34 | enum log_level { |
| 35 | MV_LOG_LEVEL_0, |
| 36 | MV_LOG_LEVEL_1, |
| 37 | MV_LOG_LEVEL_2, |
| 38 | MV_LOG_LEVEL_3 |
| 39 | }; |
| 40 | |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 41 | /* TODO: consider to move to misl phy driver */ |
| 42 | #define MISL_PHY_DRV_P_OFFS 0x7 |
| 43 | #define MISL_PHY_DRV_N_OFFS 0x0 |
| 44 | #define MISL_PHY_ODT_P_OFFS 0x6 |
| 45 | #define MISL_PHY_ODT_N_OFFS 0x0 |
| 46 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 47 | /* Globals */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 48 | extern u8 debug_training, debug_calibration, debug_ddr4_centralization, |
| 49 | debug_tap_tuning, debug_dm_tuning; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 50 | extern u8 is_reg_dump; |
| 51 | extern u8 generic_init_controller; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 52 | /* list of allowed frequency listed in order of enum mv_ddr_freq */ |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 53 | extern u32 is_pll_old; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 54 | extern struct pattern_info pattern_table[]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 55 | extern u8 debug_centralization, debug_training_ip, debug_training_bist, |
| 56 | debug_pbs, debug_training_static, debug_leveling; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 57 | extern struct hws_tip_config_func_db config_func_info[]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 58 | extern u8 twr_mask_table[]; |
| 59 | extern u8 cl_mask_table[]; |
| 60 | extern u8 cwl_mask_table[]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 61 | extern u32 speed_bin_table_t_rc[]; |
| 62 | extern u32 speed_bin_table_t_rcd_t_rp[]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 63 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 64 | extern u32 vref_init_val; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 65 | extern u32 g_zpri_data; |
| 66 | extern u32 g_znri_data; |
| 67 | extern u32 g_zpri_ctrl; |
| 68 | extern u32 g_znri_ctrl; |
| 69 | extern u32 g_zpodt_data; |
| 70 | extern u32 g_znodt_data; |
| 71 | extern u32 g_zpodt_ctrl; |
| 72 | extern u32 g_znodt_ctrl; |
| 73 | extern u32 g_dic; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 74 | extern u32 g_odt_config; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 75 | extern u32 g_rtt_nom; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 76 | extern u32 g_rtt_wr; |
| 77 | extern u32 g_rtt_park; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 78 | |
| 79 | extern u8 debug_training_access; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 80 | extern u32 first_active_if; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 81 | extern u32 delay_enable, ck_delay, ca_delay; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 82 | extern u32 mask_tune_func; |
| 83 | extern u32 rl_version; |
| 84 | extern int rl_mid_freq_wa; |
| 85 | extern u8 calibration_update_control; /* 2 external only, 1 is internal only */ |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 86 | extern enum mv_ddr_freq medium_freq; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 87 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 88 | extern enum hws_result training_result[MAX_STAGE_LIMIT][MAX_INTERFACE_NUM]; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 89 | extern enum mv_ddr_freq low_freq; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 90 | extern enum auto_tune_stage training_stage; |
| 91 | extern u32 is_pll_before_init; |
| 92 | extern u32 is_adll_calib_before_init; |
| 93 | extern u32 is_dfs_in_init; |
| 94 | extern int wl_debug_delay; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 95 | extern u32 silicon_delay[MAX_DEVICE_NUM]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 96 | extern u32 start_pattern, end_pattern; |
| 97 | extern u32 phy_reg0_val; |
| 98 | extern u32 phy_reg1_val; |
| 99 | extern u32 phy_reg2_val; |
| 100 | extern u32 phy_reg3_val; |
| 101 | extern enum hws_pattern sweep_pattern; |
| 102 | extern enum hws_pattern pbs_pattern; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 103 | extern u32 g_znri_data; |
| 104 | extern u32 g_zpri_data; |
| 105 | extern u32 g_znri_ctrl; |
| 106 | extern u32 g_zpri_ctrl; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 107 | extern u32 finger_test, p_finger_start, p_finger_end, n_finger_start, |
| 108 | n_finger_end, p_finger_step, n_finger_step; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 109 | extern u32 mode_2t; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 110 | extern u32 xsb_validate_type; |
| 111 | extern u32 xsb_validation_base_address; |
| 112 | extern u32 odt_additional; |
| 113 | extern u32 debug_mode; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 114 | extern u32 debug_dunit; |
| 115 | extern u32 clamp_tbl[]; |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 116 | extern u32 freq_mask[MAX_DEVICE_NUM][MV_DDR_FREQ_LAST]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 117 | |
| 118 | extern u32 maxt_poll_tries; |
| 119 | extern u32 is_bist_reset_bit; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 120 | |
| 121 | extern u8 vref_window_size[MAX_INTERFACE_NUM][MAX_BUS_NUM]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 122 | extern u32 effective_cs; |
| 123 | extern int ddr3_tip_centr_skip_min_win_check; |
| 124 | extern u32 *dq_map_table; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 125 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 126 | extern u8 debug_training_hw_alg; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 127 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 128 | extern u32 start_xsb_offset; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 129 | extern u32 odt_config; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 130 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 131 | extern u16 mask_results_dq_reg_map[]; |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 132 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 133 | extern u32 target_freq; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 134 | extern u32 dfs_low_freq; |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 135 | |
| 136 | extern u32 nominal_avs; |
| 137 | extern u32 extension_avs; |
| 138 | |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 139 | #if defined(CONFIG_DDR4) |
| 140 | /* if 1, SSTL & POD have same Vref and workaround is required */ |
| 141 | extern u8 vref_calibration_wa; |
| 142 | #endif /* CONFIG_DDR4 */ |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 143 | |
| 144 | /* Prototypes */ |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 145 | int ddr3_init(void); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 146 | int ddr3_tip_enable_init_sequence(u32 dev_num); |
| 147 | |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 148 | int ddr3_hws_hw_training(enum hws_algo_type algo_mode); |
| 149 | int mv_ddr_early_init(void); |
| 150 | int mv_ddr_early_init2(void); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 151 | int ddr3_silicon_post_init(void); |
| 152 | int ddr3_post_run_alg(void); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 153 | void ddr3_new_tip_ecc_scrub(void); |
| 154 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 155 | int ddr3_tip_reg_write(u32 dev_num, u32 reg_addr, u32 data); |
| 156 | int ddr3_tip_reg_read(u32 dev_num, u32 reg_addr, u32 *data, u32 reg_mask); |
| 157 | int ddr3_silicon_get_ddr_target_freq(u32 *ddr_freq); |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 158 | #if defined(CONFIG_DDR4) |
| 159 | int mv_ddr4_mode_regs_init(u8 dev_num); |
| 160 | int mv_ddr4_sdram_config(u32 dev_num); |
| 161 | int mv_ddr4_phy_config(u32 dev_num); |
| 162 | int mv_ddr4_calibration_adjust(u32 dev_num, u8 vref_en, u8 pod_only); |
| 163 | int mv_ddr4_training_main_flow(u32 dev_num); |
| 164 | #endif /* CONFIG_DDR4 */ |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 165 | |
| 166 | int print_adll(u32 dev_num, u32 adll[MAX_INTERFACE_NUM * MAX_BUS_NUM]); |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 167 | int print_ph(u32 dev_num, u32 adll[MAX_INTERFACE_NUM * MAX_BUS_NUM]); |
| 168 | int read_phase_value(u32 dev_num, u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM], |
| 169 | int reg_addr, u32 mask); |
| 170 | int write_leveling_value(u32 dev_num, u32 pup_values[MAX_INTERFACE_NUM * MAX_BUS_NUM], |
| 171 | u32 pup_ph_values[MAX_INTERFACE_NUM * MAX_BUS_NUM], int reg_addr); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 172 | int ddr3_tip_restore_dunit_regs(u32 dev_num); |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 173 | void print_topology(struct mv_ddr_topology_map *tm); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 174 | |
| 175 | u32 mv_board_id_get(void); |
| 176 | |
| 177 | int ddr3_load_topology_map(void); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 178 | void ddr3_hws_set_log_level(enum ddr_lib_debug_block block, u8 level); |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 179 | void mv_ddr_user_log_level_set(enum ddr_lib_debug_block block); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 180 | int ddr3_tip_tune_training_params(u32 dev_num, |
| 181 | struct tune_train_params *params); |
| 182 | void get_target_freq(u32 freq_mode, u32 *ddr_freq, u32 *hclk_ps); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 183 | void ddr3_fast_path_static_cs_size_config(u32 cs_ena); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 184 | u32 mv_board_id_index_get(u32 board_id); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 185 | void ddr3_set_log_level(u32 n_log_level); |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 186 | |
| 187 | int hws_ddr3_cs_base_adr_calc(u32 if_id, u32 cs, u32 *cs_base_addr); |
| 188 | |
| 189 | int ddr3_tip_print_pbs_result(u32 dev_num, u32 cs_num, enum pbs_dir pbs_mode); |
| 190 | int ddr3_tip_clean_pbs_result(u32 dev_num, enum pbs_dir pbs_mode); |
Chris Packham | 1a07d21 | 2018-05-10 13:28:29 +1200 | [diff] [blame] | 191 | void mv_ddr_mc_config(void); |
| 192 | int mv_ddr_mc_init(void); |
| 193 | void mv_ddr_set_calib_controller(void); |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 194 | /* TODO: consider to move to misl phy driver */ |
| 195 | unsigned int mv_ddr_misl_phy_drv_data_p_get(void); |
| 196 | unsigned int mv_ddr_misl_phy_drv_data_n_get(void); |
| 197 | unsigned int mv_ddr_misl_phy_drv_ctrl_p_get(void); |
| 198 | unsigned int mv_ddr_misl_phy_drv_ctrl_n_get(void); |
| 199 | unsigned int mv_ddr_misl_phy_odt_p_get(void); |
| 200 | unsigned int mv_ddr_misl_phy_odt_n_get(void); |
Tony Dinh | e2c524b | 2023-01-18 19:03:04 -0800 | [diff] [blame] | 201 | #if defined(CONFIG_DDR4) |
| 202 | void refresh(void); |
| 203 | #endif |
Chris Packham | 4bf81db | 2018-12-03 14:26:49 +1300 | [diff] [blame] | 204 | |
Stefan Roese | 5ffceb8 | 2015-03-26 15:36:56 +0100 | [diff] [blame] | 205 | #endif /* _DDR3_INIT_H */ |