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