Angel Pons | 6e5aabd | 2020-03-23 23:44:42 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 2 | |
| 3 | #ifndef RAMINIT_COMMON_H |
| 4 | #define RAMINIT_COMMON_H |
| 5 | |
Felix Held | 380c6b2 | 2020-01-26 05:06:38 +0100 | [diff] [blame] | 6 | #include <stdint.h> |
| 7 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 8 | #define BASEFREQ 133 |
| 9 | #define tDLLK 512 |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 10 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 11 | #define IS_SANDY_CPU(x) ((x & 0xffff0) == 0x206a0) |
| 12 | #define IS_SANDY_CPU_C(x) ((x & 0xf) == 4) |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 13 | #define IS_SANDY_CPU_D0(x) ((x & 0xf) == 5) |
| 14 | #define IS_SANDY_CPU_D1(x) ((x & 0xf) == 6) |
| 15 | #define IS_SANDY_CPU_D2(x) ((x & 0xf) == 7) |
| 16 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 17 | #define IS_IVY_CPU(x) ((x & 0xffff0) == 0x306a0) |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 18 | #define IS_IVY_CPU_C(x) ((x & 0xf) == 4) |
| 19 | #define IS_IVY_CPU_K(x) ((x & 0xf) == 5) |
| 20 | #define IS_IVY_CPU_D(x) ((x & 0xf) == 6) |
| 21 | #define IS_IVY_CPU_E(x) ((x & 0xf) >= 8) |
| 22 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 23 | #define NUM_CHANNELS 2 |
| 24 | #define NUM_SLOTRANKS 4 |
| 25 | #define NUM_SLOTS 2 |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 26 | #define NUM_LANES 9 |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 27 | |
Angel Pons | 3abd206 | 2020-05-03 00:25:02 +0200 | [diff] [blame] | 28 | /* IOSAV_n_SP_CMD_CTRL DRAM commands */ |
Angel Pons | 6aa7cca | 2020-05-02 19:38:34 +0200 | [diff] [blame] | 29 | #define IOSAV_MRS (0xf000) |
| 30 | #define IOSAV_PRE (0xf002) |
| 31 | #define IOSAV_ZQCS (0xf003) |
| 32 | #define IOSAV_ACT (0xf006) |
| 33 | #define IOSAV_RD (0xf105) |
| 34 | #define IOSAV_NOP_ALT (0xf107) |
| 35 | #define IOSAV_WR (0xf201) |
| 36 | #define IOSAV_NOP (0xf207) |
Angel Pons | 69e1714 | 2020-03-23 12:26:29 +0100 | [diff] [blame] | 37 | |
Angel Pons | 3abd206 | 2020-05-03 00:25:02 +0200 | [diff] [blame] | 38 | /* IOSAV_n_SUBSEQ_CTRL data direction */ |
| 39 | #define SSQ_NA 0 /* Non-data */ |
| 40 | #define SSQ_RD 1 /* Read */ |
| 41 | #define SSQ_WR 2 /* Write */ |
| 42 | #define SSQ_RW 3 /* Read and write */ |
| 43 | |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 44 | struct iosav_ssq { |
| 45 | /* IOSAV_n_SP_CMD_CTRL */ |
| 46 | union { |
| 47 | struct { |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 48 | u32 command : 16; /* [15.. 0] */ |
| 49 | u32 ranksel_ap : 2; /* [17..16] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 50 | u32 : 14; |
| 51 | }; |
| 52 | u32 raw; |
| 53 | } sp_cmd_ctrl; |
| 54 | |
| 55 | /* IOSAV_n_SUBSEQ_CTRL */ |
| 56 | union { |
| 57 | struct { |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 58 | u32 cmd_executions : 9; /* [ 8.. 0] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 59 | u32 : 1; |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 60 | u32 cmd_delay_gap : 5; /* [14..10] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 61 | u32 : 1; |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 62 | u32 post_ssq_wait : 9; /* [24..16] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 63 | u32 : 1; |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 64 | u32 data_direction : 2; /* [27..26] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 65 | u32 : 4; |
| 66 | }; |
| 67 | u32 raw; |
| 68 | } subseq_ctrl; |
| 69 | |
| 70 | /* IOSAV_n_SP_CMD_ADDR */ |
| 71 | union { |
| 72 | struct { |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 73 | u32 address : 16; /* [15.. 0] */ |
| 74 | u32 rowbits : 3; /* [18..16] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 75 | u32 : 1; |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 76 | u32 bank : 3; /* [22..20] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 77 | u32 : 1; |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 78 | u32 rank : 2; /* [25..24] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 79 | u32 : 6; |
| 80 | }; |
| 81 | u32 raw; |
| 82 | } sp_cmd_addr; |
| 83 | |
| 84 | /* IOSAV_n_ADDR_UPDATE */ |
| 85 | union { |
| 86 | struct { |
Angel Pons | 19c5cd2 | 2020-08-10 14:27:23 +0200 | [diff] [blame] | 87 | u32 inc_addr_1 : 1; /* [ 0.. 0] */ |
| 88 | u32 inc_addr_8 : 1; /* [ 1.. 1] */ |
| 89 | u32 inc_bank : 1; /* [ 2.. 2] */ |
| 90 | u32 inc_rank : 2; /* [ 4.. 3] */ |
| 91 | u32 addr_wrap : 5; /* [ 9.. 5] */ |
| 92 | u32 lfsr_upd : 2; /* [11..10] */ |
| 93 | u32 upd_rate : 4; /* [15..12] */ |
| 94 | u32 lfsr_xors : 2; /* [17..16] */ |
Angel Pons | d5b780c | 2020-05-02 21:48:46 +0200 | [diff] [blame] | 95 | u32 : 14; |
| 96 | }; |
| 97 | u32 raw; |
| 98 | } addr_update; |
| 99 | }; |
| 100 | |
Angel Pons | 9fcc110 | 2020-11-19 22:23:13 +0100 | [diff] [blame] | 101 | union gdcr_rx_reg { |
| 102 | struct { |
| 103 | u32 rcven_pi_code : 6; /* [ 5.. 0] */ |
| 104 | u32 : 2; |
| 105 | u32 rx_dqs_p_pi_code : 7; /* [14.. 8] */ |
| 106 | u32 : 1; |
| 107 | u32 rcven_logic_delay : 3; /* [18..16] */ |
| 108 | u32 : 1; |
| 109 | u32 rx_dqs_n_pi_code : 7; /* [26..20] */ |
| 110 | u32 : 5; |
| 111 | }; |
| 112 | u32 raw; |
| 113 | }; |
| 114 | |
| 115 | union gdcr_tx_reg { |
| 116 | struct { |
| 117 | u32 tx_dq_pi_code : 6; /* [ 5.. 0] */ |
| 118 | u32 : 2; |
| 119 | u32 tx_dqs_pi_code : 6; /* [13.. 8] */ |
| 120 | u32 : 1; |
| 121 | u32 tx_dqs_logic_delay : 3; /* [17..15] */ |
| 122 | u32 : 1; |
| 123 | u32 tx_dq_logic_delay : 1; /* [19..19] */ |
| 124 | u32 : 12; |
| 125 | }; |
| 126 | u32 raw; |
| 127 | }; |
| 128 | |
Angel Pons | 737f111 | 2020-11-13 14:07:30 +0100 | [diff] [blame] | 129 | union gdcr_cmd_pi_coding_reg { |
| 130 | struct { |
| 131 | u32 cmd_pi_code : 6; /* [ 5.. 0] */ |
| 132 | u32 ctl_pi_code_d0 : 6; /* [11.. 6] */ |
| 133 | u32 cmd_logic_delay : 1; /* [12..12] */ |
| 134 | u32 cmd_phase_delay : 1; /* [13..13] */ |
| 135 | u32 cmd_xover_enable : 1; /* [14..14] */ |
| 136 | u32 ctl_logic_delay_d0 : 1; /* [15..15] */ |
| 137 | u32 ctl_phase_delay_d0 : 1; /* [16..16] */ |
| 138 | u32 ctl_xover_enable_d0 : 1; /* [17..17] */ |
| 139 | u32 ctl_pi_code_d1 : 6; /* [23..18] */ |
| 140 | u32 ctl_logic_delay_d1 : 1; /* [24..24] */ |
| 141 | u32 ctl_phase_delay_d1 : 1; /* [25..25] */ |
| 142 | u32 ctl_xover_enable_d1 : 1; /* [26..26] */ |
| 143 | u32 : 5; |
| 144 | }; |
| 145 | u32 raw; |
| 146 | }; |
| 147 | |
Angel Pons | 58b609b | 2020-11-13 14:35:29 +0100 | [diff] [blame] | 148 | union gdcr_training_mod_reg { |
| 149 | struct { |
| 150 | u32 receive_enable_mode : 1; /* [ 0.. 0] */ |
| 151 | u32 write_leveling_mode : 1; /* [ 1.. 1] */ |
| 152 | u32 training_rank_sel : 2; /* [ 3.. 2] */ |
| 153 | u32 enable_dqs_wl : 4; /* [ 7.. 4] */ |
| 154 | u32 dqs_logic_delay_wl : 1; /* [ 8.. 8] */ |
| 155 | u32 dq_dqs_training_res : 1; /* [ 9.. 9] */ |
| 156 | u32 : 4; |
| 157 | u32 delay_dq : 1; /* [14..14] */ |
| 158 | u32 odt_always_on : 1; /* [15..15] */ |
| 159 | u32 : 4; |
| 160 | u32 force_drive_enable : 1; /* [20..20] */ |
| 161 | u32 dft_tx_pi_clk_view : 1; /* [21..21] */ |
| 162 | u32 dft_tx_pi_clk_swap : 1; /* [22..22] */ |
| 163 | u32 early_odt_en : 1; /* [23..23] */ |
| 164 | u32 vref_gen_ctl : 6; /* [29..24] */ |
| 165 | u32 ext_vref_sel : 1; /* [30..30] */ |
| 166 | u32 tx_fifo_always_on : 1; /* [31..31] */ |
| 167 | }; |
| 168 | u32 raw; |
| 169 | }; |
| 170 | |
Angel Pons | 4f86d63 | 2020-11-19 17:18:46 +0100 | [diff] [blame] | 171 | union comp_ofst_1_reg { |
| 172 | struct { |
| 173 | u32 dq_odt_down : 3; /* [ 2.. 0] */ |
| 174 | u32 dq_odt_up : 3; /* [ 5.. 3] */ |
| 175 | u32 clk_odt_down : 3; /* [ 8.. 6] */ |
| 176 | u32 clk_odt_up : 3; /* [11.. 9] */ |
| 177 | u32 dq_drv_down : 3; /* [14..12] */ |
| 178 | u32 dq_drv_up : 3; /* [17..15] */ |
| 179 | u32 clk_drv_down : 3; /* [20..18] */ |
| 180 | u32 clk_drv_up : 3; /* [23..21] */ |
| 181 | u32 ctl_drv_down : 3; /* [26..24] */ |
| 182 | u32 ctl_drv_up : 3; /* [29..27] */ |
| 183 | u32 : 2; |
| 184 | }; |
| 185 | u32 raw; |
| 186 | }; |
| 187 | |
Angel Pons | 7a61274 | 2020-11-12 13:34:03 +0100 | [diff] [blame] | 188 | union tc_dbp_reg { |
| 189 | struct { |
| 190 | u32 tRCD : 4; /* [ 3.. 0] */ |
| 191 | u32 tRP : 4; /* [ 7.. 4] */ |
| 192 | u32 tAA : 4; /* [11.. 8] */ |
| 193 | u32 tCWL : 4; /* [15..12] */ |
| 194 | u32 tRAS : 8; /* [23..16] */ |
| 195 | u32 : 8; |
| 196 | }; |
| 197 | u32 raw; |
| 198 | }; |
| 199 | |
| 200 | union tc_rap_reg { |
| 201 | struct { |
| 202 | u32 tRRD : 4; /* [ 3.. 0] */ |
| 203 | u32 tRTP : 4; /* [ 7.. 4] */ |
| 204 | u32 tCKE : 4; /* [11.. 8] */ |
| 205 | u32 tWTR : 4; /* [15..12] */ |
| 206 | u32 tFAW : 8; /* [23..16] */ |
| 207 | u32 tWR : 5; /* [28..24] */ |
| 208 | u32 dis_3st : 1; /* [29..29] */ |
| 209 | u32 tCMD : 2; /* [31..30] */ |
| 210 | }; |
| 211 | u32 raw; |
| 212 | }; |
| 213 | |
| 214 | union tc_rwp_reg { |
| 215 | struct { |
| 216 | u32 tRRDR : 3; /* [ 2.. 0] */ |
| 217 | u32 : 1; |
| 218 | u32 tRRDD : 3; /* [ 6.. 4] */ |
| 219 | u32 : 1; |
| 220 | u32 tWWDR : 3; /* [10.. 8] */ |
| 221 | u32 : 1; |
| 222 | u32 tWWDD : 3; /* [14..12] */ |
| 223 | u32 : 1; |
| 224 | u32 tRWDRDD : 3; /* [18..16] */ |
| 225 | u32 : 1; |
| 226 | u32 tWRDRDD : 3; /* [22..20] */ |
| 227 | u32 : 1; |
| 228 | u32 tRWSR : 3; /* [26..24] */ |
| 229 | u32 dec_wrd : 1; /* [27..27] */ |
| 230 | u32 : 4; |
| 231 | }; |
| 232 | u32 raw; |
| 233 | }; |
| 234 | |
| 235 | union tc_othp_reg { |
| 236 | struct { |
| 237 | u32 tXPDLL : 5; /* [ 4.. 0] */ |
| 238 | u32 tXP : 3; /* [ 7.. 5] */ |
| 239 | u32 tAONPD : 4; /* [11.. 8] */ |
| 240 | u32 tCPDED : 2; /* [13..12] */ |
| 241 | u32 tPRPDEN : 2; /* [15..14] */ |
| 242 | u32 odt_delay_d0 : 2; /* [17..16] */ |
| 243 | u32 odt_delay_d1 : 2; /* [19..18] */ |
| 244 | u32 : 12; |
| 245 | }; |
| 246 | u32 raw; |
| 247 | }; |
| 248 | |
| 249 | union tc_dtp_reg { |
| 250 | struct { |
| 251 | u32 : 12; |
| 252 | u32 overclock_tXP : 1; /* [12..12] */ |
| 253 | u32 overclock_tXPDLL : 1; /* [13..13] */ |
| 254 | u32 : 18; |
| 255 | }; |
| 256 | u32 raw; |
| 257 | }; |
| 258 | |
| 259 | union tc_rfp_reg { |
| 260 | struct { |
| 261 | u32 oref_ri : 8; /* [ 7.. 0] */ |
| 262 | u32 refresh_high_wm : 4; /* [11.. 8] */ |
| 263 | u32 refresh_panic_wm : 4; /* [15..12] */ |
| 264 | u32 refresh_2x_control : 2; /* [17..16] */ |
| 265 | u32 : 14; |
| 266 | }; |
| 267 | u32 raw; |
| 268 | }; |
| 269 | |
| 270 | union tc_rftp_reg { |
| 271 | struct { |
| 272 | u32 tREFI : 16; /* [15.. 0] */ |
| 273 | u32 tRFC : 9; /* [24..16] */ |
| 274 | u32 tREFIx9 : 7; /* [31..25] */ |
| 275 | }; |
| 276 | u32 raw; |
| 277 | }; |
| 278 | |
| 279 | union tc_srftp_reg { |
| 280 | struct { |
| 281 | u32 tXSDLL : 12; /* [11.. 0] */ |
| 282 | u32 tXS_offset : 4; /* [15..12] */ |
| 283 | u32 tZQOPER : 10; /* [25..16] */ |
| 284 | u32 : 2; |
| 285 | u32 tMOD : 4; /* [31..28] */ |
| 286 | }; |
| 287 | u32 raw; |
| 288 | }; |
| 289 | |
Angel Pons | ffd5015 | 2020-11-12 11:03:10 +0100 | [diff] [blame] | 290 | typedef struct ramctr_timing_st ramctr_timing; |
| 291 | |
Angel Pons | 8f0757e | 2020-11-11 23:03:36 +0100 | [diff] [blame] | 292 | void iosav_write_sequence(const int ch, const struct iosav_ssq *seq, const unsigned int length); |
Angel Pons | 1c505f8 | 2020-11-11 20:55:35 +0100 | [diff] [blame] | 293 | void iosav_run_queue(const int ch, const u8 loops, const u8 as_timer); |
| 294 | void iosav_run_once(const int ch); |
| 295 | void wait_for_iosav(int channel); |
| 296 | |
Angel Pons | ffd5015 | 2020-11-12 11:03:10 +0100 | [diff] [blame] | 297 | void iosav_write_zqcs_sequence(int channel, int slotrank, u32 gap, u32 post, u32 wrap); |
| 298 | void iosav_write_prea_sequence(int channel, int slotrank, u32 post, u32 wrap); |
| 299 | void iosav_write_read_mpr_sequence( |
| 300 | int channel, int slotrank, u32 tMOD, u32 loops, u32 gap, u32 loops2, u32 post2); |
Angel Pons | 801a5cb | 2020-11-15 15:48:29 +0100 | [diff] [blame] | 301 | void iosav_write_prea_act_read_sequence(ramctr_timing *ctrl, int channel, int slotrank); |
Angel Pons | 9426721 | 2020-11-14 16:49:29 +0100 | [diff] [blame] | 302 | void iosav_write_jedec_write_leveling_sequence( |
| 303 | ramctr_timing *ctrl, int channel, int slotrank, int bank, u32 mr1reg); |
Angel Pons | ffd5015 | 2020-11-12 11:03:10 +0100 | [diff] [blame] | 304 | void iosav_write_misc_write_sequence(ramctr_timing *ctrl, int channel, int slotrank, |
| 305 | u32 gap0, u32 loops0, u32 gap1, u32 loops2, u32 wrap2); |
| 306 | void iosav_write_command_training_sequence( |
| 307 | ramctr_timing *ctrl, int channel, int slotrank, unsigned int address); |
| 308 | void iosav_write_data_write_sequence(ramctr_timing *ctrl, int channel, int slotrank); |
| 309 | void iosav_write_aggressive_write_read_sequence(ramctr_timing *ctrl, int channel, int slotrank); |
| 310 | void iosav_write_memory_test_sequence(ramctr_timing *ctrl, int channel, int slotrank); |
| 311 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 312 | /* FIXME: Vendor BIOS uses 64 but our algorithms are less |
| 313 | performant and even 1 seems to be enough in practice. */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 314 | #define NUM_PATTERNS 4 |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 315 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 316 | /* |
| 317 | * WARNING: Do not forget to increase MRC_CACHE_VERSION when the saved data is changed! |
| 318 | */ |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 319 | #define MRC_CACHE_VERSION 5 |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 320 | |
Angel Pons | 09fc4b9 | 2020-11-19 12:02:07 +0100 | [diff] [blame] | 321 | enum pdwm_mode { |
| 322 | PDM_NONE = 0, |
| 323 | PDM_APD = 1, |
| 324 | PDM_PPD = 2, |
| 325 | PDM_APD_PPD = 3, |
| 326 | PDM_DLL_OFF = 6, |
| 327 | PDM_APD_DLL_OFF = 7, |
| 328 | }; |
| 329 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 330 | typedef struct odtmap_st { |
| 331 | u16 rttwr; |
| 332 | u16 rttnom; |
| 333 | } odtmap; |
| 334 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 335 | /* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 336 | typedef struct dimm_info_st { |
| 337 | dimm_attr dimm[NUM_CHANNELS][NUM_SLOTS]; |
| 338 | } dimm_info; |
| 339 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 340 | /* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 341 | struct ram_rank_timings { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 342 | /* ROUNDT_LAT register: One byte per slotrank */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 343 | u8 roundtrip_latency; |
| 344 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 345 | /* IO_LATENCY register: One nibble per slotrank */ |
Felix Held | ef4fe3e | 2019-12-31 14:15:05 +0100 | [diff] [blame] | 346 | u8 io_latency; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 347 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 348 | /* Phase interpolator coding for command and control */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 349 | int pi_coding; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 350 | |
| 351 | struct ram_lane_timings { |
Angel Pons | c8ac2cc | 2020-11-19 22:50:54 +0100 | [diff] [blame] | 352 | /* GDCR RX timings */ |
| 353 | u16 rcven; |
| 354 | u8 rx_dqs_p; |
| 355 | u8 rx_dqs_n; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 356 | |
Angel Pons | c8ac2cc | 2020-11-19 22:50:54 +0100 | [diff] [blame] | 357 | /* GDCR TX timings */ |
| 358 | int tx_dq; |
| 359 | u16 tx_dqs; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 360 | } lanes[NUM_LANES]; |
| 361 | }; |
| 362 | |
Angel Pons | 5c1baf5 | 2020-03-22 12:23:35 +0100 | [diff] [blame] | 363 | /* WARNING: Do not forget to increase MRC_CACHE_VERSION when this struct is changed! */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 364 | typedef struct ramctr_timing_st { |
| 365 | u16 spd_crc[NUM_CHANNELS][NUM_SLOTS]; |
Angel Pons | 80037f7 | 2020-03-21 13:12:37 +0100 | [diff] [blame] | 366 | |
| 367 | /* CPUID value */ |
| 368 | u32 cpu; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 369 | |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 370 | /* DDR base_freq = 100 Mhz / 133 Mhz */ |
| 371 | u8 base_freq; |
| 372 | |
Angel Pons | 48409b8 | 2020-03-23 22:19:29 +0100 | [diff] [blame] | 373 | /* Frequency index */ |
| 374 | u32 FRQ; |
| 375 | |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 376 | u16 cas_supported; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 377 | /* Latencies are in units of ns, scaled by x256 */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 378 | u32 tCK; |
| 379 | u32 tAA; |
| 380 | u32 tWR; |
| 381 | u32 tRCD; |
| 382 | u32 tRRD; |
| 383 | u32 tRP; |
| 384 | u32 tRAS; |
| 385 | u32 tRFC; |
| 386 | u32 tWTR; |
| 387 | u32 tRTP; |
| 388 | u32 tFAW; |
Dan Elkouby | dabebc3 | 2018-04-13 18:47:10 +0300 | [diff] [blame] | 389 | u32 tCWL; |
| 390 | u32 tCMD; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 391 | /* Latencies in terms of clock cycles |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 392 | They are saved separately as they are needed for DRAM MRS commands */ |
| 393 | u8 CAS; /* CAS read latency */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 394 | u8 CWL; /* CAS write latency */ |
| 395 | |
| 396 | u32 tREFI; |
| 397 | u32 tMOD; |
| 398 | u32 tXSOffset; |
| 399 | u32 tWLO; |
| 400 | u32 tCKE; |
| 401 | u32 tXPDLL; |
| 402 | u32 tXP; |
| 403 | u32 tAONPD; |
| 404 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 405 | /* Bits [0..11] of PM_DLL_CONFIG: Master DLL wakeup delay timer */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 406 | u16 mdll_wake_delay; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 407 | |
| 408 | u8 rankmap[NUM_CHANNELS]; |
| 409 | int ref_card_offset[NUM_CHANNELS]; |
| 410 | u32 mad_dimm[NUM_CHANNELS]; |
| 411 | int channel_size_mb[NUM_CHANNELS]; |
| 412 | u32 cmd_stretch[NUM_CHANNELS]; |
| 413 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 414 | int pi_code_offset; |
| 415 | int pi_coding_threshold; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 416 | |
Patrick Rudolph | 05d4bf7e | 2017-10-28 16:36:09 +0200 | [diff] [blame] | 417 | bool ecc_supported; |
| 418 | bool ecc_forced; |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 419 | bool ecc_enabled; |
| 420 | int lanes; /* active lanes: 8 or 9 */ |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 421 | int edge_offset[3]; |
Angel Pons | c8ac2cc | 2020-11-19 22:50:54 +0100 | [diff] [blame] | 422 | int tx_dq_offset[3]; |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 423 | |
| 424 | int extended_temperature_range; |
| 425 | int auto_self_refresh; |
| 426 | |
| 427 | int rank_mirror[NUM_CHANNELS][NUM_SLOTRANKS]; |
| 428 | |
| 429 | struct ram_rank_timings timings[NUM_CHANNELS][NUM_SLOTRANKS]; |
| 430 | |
| 431 | dimm_info info; |
| 432 | } ramctr_timing; |
| 433 | |
Felix Held | 87ddea2 | 2020-01-26 04:55:27 +0100 | [diff] [blame] | 434 | #define SOUTHBRIDGE PCI_DEV(0, 0x1f, 0) |
| 435 | |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 436 | #define FOR_ALL_LANES for (lane = 0; lane < ctrl->lanes; lane++) |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 437 | #define FOR_ALL_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) |
| 438 | #define FOR_ALL_POPULATED_RANKS for (slotrank = 0; slotrank < NUM_SLOTRANKS; slotrank++) if (ctrl->rankmap[channel] & (1 << slotrank)) |
| 439 | #define FOR_ALL_POPULATED_CHANNELS for (channel = 0; channel < NUM_CHANNELS; channel++) if (ctrl->rankmap[channel]) |
| 440 | #define MAX_EDGE_TIMING 71 |
Angel Pons | c8ac2cc | 2020-11-19 22:50:54 +0100 | [diff] [blame] | 441 | #define MAX_TX_DQ 127 |
| 442 | #define MAX_TX_DQS 511 |
| 443 | #define MAX_RCVEN 127 |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 444 | #define MAX_CAS 18 |
| 445 | #define MIN_CAS 4 |
| 446 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 447 | #define MAKE_ERR ((channel << 16) | (slotrank << 8) | 1) |
| 448 | #define GET_ERR_CHANNEL(x) (x >> 16) |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 449 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 450 | void dram_mrscommands(ramctr_timing *ctrl); |
| 451 | void program_timings(ramctr_timing *ctrl, int channel); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 452 | void dram_find_common_params(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 453 | void dram_xover(ramctr_timing *ctrl); |
| 454 | void dram_timing_regs(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 455 | void dram_dimm_mapping(ramctr_timing *ctrl); |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 456 | void dram_dimm_set_mapping(ramctr_timing *ctrl, int training); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 457 | void dram_zones(ramctr_timing *ctrl, int training); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 458 | void dram_memorymap(ramctr_timing *ctrl, int me_uma_size); |
| 459 | void dram_jedecreset(ramctr_timing *ctrl); |
Angel Pons | 7f5a97c | 2020-11-13 16:58:46 +0100 | [diff] [blame] | 460 | int receive_enable_calibration(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 461 | int write_training(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 462 | int command_training(ramctr_timing *ctrl); |
Angel Pons | 4c79f93 | 2020-11-14 01:26:52 +0100 | [diff] [blame] | 463 | int read_mpr_training(ramctr_timing *ctrl); |
Angel Pons | 08f749d | 2020-11-17 16:50:56 +0100 | [diff] [blame] | 464 | int aggressive_read_training(ramctr_timing *ctrl); |
Angel Pons | 2a7d752 | 2020-11-19 12:49:07 +0100 | [diff] [blame] | 465 | int aggressive_write_training(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 466 | void normalize_training(ramctr_timing *ctrl); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 467 | int channel_test(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 468 | void set_scrambling_seed(ramctr_timing *ctrl); |
Angel Pons | 89ae6b8 | 2020-03-21 13:23:32 +0100 | [diff] [blame] | 469 | void set_wmm_behavior(const u32 cpu); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 470 | void prepare_training(ramctr_timing *ctrl); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 471 | void set_read_write_timings(ramctr_timing *ctrl); |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 472 | void set_normal_operation(ramctr_timing *ctrl); |
| 473 | void final_registers(ramctr_timing *ctrl); |
| 474 | void restore_timings(ramctr_timing *ctrl); |
Angel Pons | efbed26 | 2020-03-23 23:18:03 +0100 | [diff] [blame] | 475 | int try_init_dram_ddr3(ramctr_timing *ctrl, int fast_boot, int s3resume, int me_uma_size); |
Patrick Rudolph | fd5fa2a | 2016-11-11 18:22:33 +0100 | [diff] [blame] | 476 | |
Patrick Rudolph | dd66287 | 2017-10-28 18:20:11 +0200 | [diff] [blame] | 477 | void channel_scrub(ramctr_timing *ctrl); |
Patrick Rudolph | 05d4bf7e | 2017-10-28 16:36:09 +0200 | [diff] [blame] | 478 | bool get_host_ecc_cap(void); |
| 479 | bool get_host_ecc_forced(void); |
| 480 | |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 481 | #endif |