Angel Pons | 6e5aabd | 2020-03-23 23:44:42 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 3 | |
| 4 | #include <console/console.h> |
| 5 | #include <console/usb.h> |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 6 | #include <delay.h> |
Patrick Rudolph | cab4d3d | 2016-11-24 19:40:23 +0100 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 8 | #include "raminit_native.h" |
| 9 | #include "raminit_common.h" |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 10 | #include "raminit_tables.h" |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 11 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 12 | /* Frequency multiplier */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 13 | static u32 get_FRQ(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 14 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 15 | const u32 FRQ = 256000 / (tCK * base_freq); |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 16 | |
| 17 | if (base_freq == 100) { |
| 18 | if (FRQ > 12) |
| 19 | return 12; |
| 20 | if (FRQ < 7) |
| 21 | return 7; |
| 22 | } else { |
| 23 | if (FRQ > 10) |
| 24 | return 10; |
| 25 | if (FRQ < 3) |
| 26 | return 3; |
| 27 | } |
| 28 | |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 29 | return FRQ; |
| 30 | } |
| 31 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 32 | /* Get REFI based on MC frequency, tREFI = 7.8usec */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 33 | static u32 get_REFI(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 34 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 35 | if (base_freq == 100) |
| 36 | return frq_refi_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 37 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 38 | else |
| 39 | return frq_refi_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 42 | /* Get XSOffset based on MC frequency, tXS-Offset: tXS = tRFC + 10ns */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 43 | static u8 get_XSOffset(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 44 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 45 | if (base_freq == 100) |
| 46 | return frq_xs_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 47 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 48 | else |
| 49 | return frq_xs_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 52 | /* Get MOD based on MC frequency */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 53 | static u8 get_MOD(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 54 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 55 | if (base_freq == 100) |
| 56 | return frq_mod_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 57 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 58 | else |
| 59 | return frq_mod_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 62 | /* Get Write Leveling Output delay based on MC frequency */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 63 | static u8 get_WLO(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 64 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 65 | if (base_freq == 100) |
| 66 | return frq_wlo_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 67 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 68 | else |
| 69 | return frq_wlo_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 72 | /* Get CKE based on MC frequency */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 73 | static u8 get_CKE(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 74 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 75 | if (base_freq == 100) |
| 76 | return frq_cke_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 77 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 78 | else |
| 79 | return frq_cke_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 82 | /* Get XPDLL based on MC frequency */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 83 | static u8 get_XPDLL(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 84 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 85 | if (base_freq == 100) |
| 86 | return frq_xpdll_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 87 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 88 | else |
| 89 | return frq_xpdll_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 92 | /* Get XP based on MC frequency */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 93 | static u8 get_XP(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 94 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 95 | if (base_freq == 100) |
| 96 | return frq_xp_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 97 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 98 | else |
| 99 | return frq_xp_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 102 | /* Get AONPD based on MC frequency */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 103 | static u8 get_AONPD(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 104 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 105 | if (base_freq == 100) |
| 106 | return frq_aonpd_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 107 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 108 | else |
| 109 | return frq_aonpd_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 110 | } |
| 111 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 112 | /* Get COMP2 based on MC frequency */ |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 113 | static u32 get_COMP2(u32 tCK, u8 base_freq) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 114 | { |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 115 | if (base_freq == 100) |
| 116 | return frq_comp2_map[1][get_FRQ(tCK, 100) - 7]; |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 117 | |
Angel Pons | 825332d | 2020-03-21 19:31:53 +0100 | [diff] [blame] | 118 | else |
| 119 | return frq_comp2_map[0][get_FRQ(tCK, 133) - 3]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 122 | static void ivb_normalize_tclk(ramctr_timing *ctrl, bool ref_100mhz_support) |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 123 | { |
| 124 | if (ctrl->tCK <= TCK_1200MHZ) { |
| 125 | ctrl->tCK = TCK_1200MHZ; |
| 126 | ctrl->base_freq = 100; |
| 127 | } else if (ctrl->tCK <= TCK_1100MHZ) { |
| 128 | ctrl->tCK = TCK_1100MHZ; |
| 129 | ctrl->base_freq = 100; |
| 130 | } else if (ctrl->tCK <= TCK_1066MHZ) { |
| 131 | ctrl->tCK = TCK_1066MHZ; |
| 132 | ctrl->base_freq = 133; |
| 133 | } else if (ctrl->tCK <= TCK_1000MHZ) { |
| 134 | ctrl->tCK = TCK_1000MHZ; |
| 135 | ctrl->base_freq = 100; |
| 136 | } else if (ctrl->tCK <= TCK_933MHZ) { |
| 137 | ctrl->tCK = TCK_933MHZ; |
| 138 | ctrl->base_freq = 133; |
| 139 | } else if (ctrl->tCK <= TCK_900MHZ) { |
| 140 | ctrl->tCK = TCK_900MHZ; |
| 141 | ctrl->base_freq = 100; |
| 142 | } else if (ctrl->tCK <= TCK_800MHZ) { |
| 143 | ctrl->tCK = TCK_800MHZ; |
| 144 | ctrl->base_freq = 133; |
| 145 | } else if (ctrl->tCK <= TCK_700MHZ) { |
| 146 | ctrl->tCK = TCK_700MHZ; |
| 147 | ctrl->base_freq = 100; |
| 148 | } else if (ctrl->tCK <= TCK_666MHZ) { |
| 149 | ctrl->tCK = TCK_666MHZ; |
| 150 | ctrl->base_freq = 133; |
| 151 | } else if (ctrl->tCK <= TCK_533MHZ) { |
| 152 | ctrl->tCK = TCK_533MHZ; |
| 153 | ctrl->base_freq = 133; |
| 154 | } else if (ctrl->tCK <= TCK_400MHZ) { |
| 155 | ctrl->tCK = TCK_400MHZ; |
| 156 | ctrl->base_freq = 133; |
| 157 | } else { |
| 158 | ctrl->tCK = 0; |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | if (!ref_100mhz_support && ctrl->base_freq == 100) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 163 | /* Skip unsupported frequency */ |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 164 | ctrl->tCK++; |
| 165 | ivb_normalize_tclk(ctrl, ref_100mhz_support); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | static void find_cas_tck(ramctr_timing *ctrl) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 170 | { |
| 171 | u8 val; |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 172 | u32 reg32; |
| 173 | u8 ref_100mhz_support; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 174 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 175 | /* 100 MHz reference clock supported */ |
| 176 | reg32 = pci_read_config32(HOST_BRIDGE, CAPID0_B); |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 177 | ref_100mhz_support = !!((reg32 >> 21) & 0x7); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 178 | printk(BIOS_DEBUG, "100MHz reference clock support: %s\n", ref_100mhz_support ? "yes" |
| 179 | : "no"); |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 180 | |
| 181 | /* Find CAS latency */ |
| 182 | while (1) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 183 | /* |
| 184 | * Normalising tCK before computing clock could potentially |
| 185 | * result in a lower selected CAS, which is desired. |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 186 | */ |
| 187 | ivb_normalize_tclk(ctrl, ref_100mhz_support); |
| 188 | if (!(ctrl->tCK)) |
| 189 | die("Couldn't find compatible clock / CAS settings\n"); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 190 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 191 | val = DIV_ROUND_UP(ctrl->tAA, ctrl->tCK); |
| 192 | printk(BIOS_DEBUG, "Trying CAS %u, tCK %u.\n", val, ctrl->tCK); |
| 193 | for (; val <= MAX_CAS; val++) |
| 194 | if ((ctrl->cas_supported >> (val - MIN_CAS)) & 1) |
| 195 | break; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 196 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 197 | if (val == (MAX_CAS + 1)) { |
| 198 | ctrl->tCK++; |
| 199 | continue; |
| 200 | } else { |
| 201 | printk(BIOS_DEBUG, "Found compatible clock, CAS pair.\n"); |
| 202 | break; |
| 203 | } |
| 204 | } |
| 205 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 206 | printk(BIOS_DEBUG, "Selected DRAM frequency: %u MHz\n", NS2MHZ_DIV256 / ctrl->tCK); |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 207 | printk(BIOS_DEBUG, "Selected CAS latency : %uT\n", val); |
| 208 | ctrl->CAS = val; |
| 209 | } |
| 210 | |
| 211 | |
| 212 | static void dram_timing(ramctr_timing *ctrl) |
| 213 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 214 | /* |
| 215 | * On Ivy Bridge, the maximum supported DDR3 frequency is 1400MHz (DDR3 2800). |
| 216 | * Cap it at 1200MHz (DDR3 2400), and align it to the closest JEDEC standard frequency. |
| 217 | */ |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 218 | if (ctrl->tCK == TCK_1200MHZ) { |
Patrick Rudolph | cb7d6a1 | 2016-11-25 15:40:49 +0100 | [diff] [blame] | 219 | ctrl->edge_offset[0] = 18; //XXX: guessed |
| 220 | ctrl->edge_offset[1] = 8; |
| 221 | ctrl->edge_offset[2] = 8; |
| 222 | ctrl->timC_offset[0] = 20; //XXX: guessed |
| 223 | ctrl->timC_offset[1] = 8; |
| 224 | ctrl->timC_offset[2] = 8; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 225 | ctrl->pi_coding_threshold = 10; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 226 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 227 | } else if (ctrl->tCK == TCK_1100MHZ) { |
Patrick Rudolph | cb7d6a1 | 2016-11-25 15:40:49 +0100 | [diff] [blame] | 228 | ctrl->edge_offset[0] = 17; //XXX: guessed |
| 229 | ctrl->edge_offset[1] = 7; |
| 230 | ctrl->edge_offset[2] = 7; |
| 231 | ctrl->timC_offset[0] = 19; //XXX: guessed |
| 232 | ctrl->timC_offset[1] = 7; |
| 233 | ctrl->timC_offset[2] = 7; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 234 | ctrl->pi_coding_threshold = 13; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 235 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 236 | } else if (ctrl->tCK == TCK_1066MHZ) { |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 237 | ctrl->edge_offset[0] = 16; |
| 238 | ctrl->edge_offset[1] = 7; |
| 239 | ctrl->edge_offset[2] = 7; |
| 240 | ctrl->timC_offset[0] = 18; |
| 241 | ctrl->timC_offset[1] = 7; |
| 242 | ctrl->timC_offset[2] = 7; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 243 | ctrl->pi_coding_threshold = 13; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 244 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 245 | } else if (ctrl->tCK == TCK_1000MHZ) { |
Patrick Rudolph | cb7d6a1 | 2016-11-25 15:40:49 +0100 | [diff] [blame] | 246 | ctrl->edge_offset[0] = 15; //XXX: guessed |
| 247 | ctrl->edge_offset[1] = 6; |
| 248 | ctrl->edge_offset[2] = 6; |
| 249 | ctrl->timC_offset[0] = 17; //XXX: guessed |
| 250 | ctrl->timC_offset[1] = 6; |
| 251 | ctrl->timC_offset[2] = 6; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 252 | ctrl->pi_coding_threshold = 13; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 253 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 254 | } else if (ctrl->tCK == TCK_933MHZ) { |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 255 | ctrl->edge_offset[0] = 14; |
| 256 | ctrl->edge_offset[1] = 6; |
| 257 | ctrl->edge_offset[2] = 6; |
| 258 | ctrl->timC_offset[0] = 15; |
| 259 | ctrl->timC_offset[1] = 6; |
| 260 | ctrl->timC_offset[2] = 6; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 261 | ctrl->pi_coding_threshold = 15; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 262 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 263 | } else if (ctrl->tCK == TCK_900MHZ) { |
Patrick Rudolph | cb7d6a1 | 2016-11-25 15:40:49 +0100 | [diff] [blame] | 264 | ctrl->edge_offset[0] = 14; //XXX: guessed |
| 265 | ctrl->edge_offset[1] = 6; |
| 266 | ctrl->edge_offset[2] = 6; |
| 267 | ctrl->timC_offset[0] = 15; //XXX: guessed |
| 268 | ctrl->timC_offset[1] = 6; |
| 269 | ctrl->timC_offset[2] = 6; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 270 | ctrl->pi_coding_threshold = 12; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 271 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 272 | } else if (ctrl->tCK == TCK_800MHZ) { |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 273 | ctrl->edge_offset[0] = 13; |
| 274 | ctrl->edge_offset[1] = 5; |
| 275 | ctrl->edge_offset[2] = 5; |
| 276 | ctrl->timC_offset[0] = 14; |
| 277 | ctrl->timC_offset[1] = 5; |
| 278 | ctrl->timC_offset[2] = 5; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 279 | ctrl->pi_coding_threshold = 15; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 280 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 281 | } else if (ctrl->tCK == TCK_700MHZ) { |
Patrick Rudolph | cb7d6a1 | 2016-11-25 15:40:49 +0100 | [diff] [blame] | 282 | ctrl->edge_offset[0] = 13; //XXX: guessed |
| 283 | ctrl->edge_offset[1] = 5; |
| 284 | ctrl->edge_offset[2] = 5; |
| 285 | ctrl->timC_offset[0] = 14; //XXX: guessed |
| 286 | ctrl->timC_offset[1] = 5; |
| 287 | ctrl->timC_offset[2] = 5; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 288 | ctrl->pi_coding_threshold = 16; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 289 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 290 | } else if (ctrl->tCK == TCK_666MHZ) { |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 291 | ctrl->edge_offset[0] = 10; |
| 292 | ctrl->edge_offset[1] = 4; |
| 293 | ctrl->edge_offset[2] = 4; |
| 294 | ctrl->timC_offset[0] = 11; |
| 295 | ctrl->timC_offset[1] = 4; |
| 296 | ctrl->timC_offset[2] = 4; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 297 | ctrl->pi_coding_threshold = 16; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 298 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 299 | } else if (ctrl->tCK == TCK_533MHZ) { |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 300 | ctrl->edge_offset[0] = 8; |
| 301 | ctrl->edge_offset[1] = 3; |
| 302 | ctrl->edge_offset[2] = 3; |
| 303 | ctrl->timC_offset[0] = 9; |
| 304 | ctrl->timC_offset[1] = 3; |
| 305 | ctrl->timC_offset[2] = 3; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 306 | ctrl->pi_coding_threshold = 17; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 307 | |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 308 | } else { /* TCK_400MHZ */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 309 | ctrl->edge_offset[0] = 6; |
| 310 | ctrl->edge_offset[1] = 2; |
| 311 | ctrl->edge_offset[2] = 2; |
| 312 | ctrl->timC_offset[0] = 6; |
| 313 | ctrl->timC_offset[1] = 2; |
| 314 | ctrl->timC_offset[2] = 2; |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 315 | ctrl->pi_coding_threshold = 17; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | /* Initial phase between CLK/CMD pins */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 319 | ctrl->pi_code_offset = (256000 / ctrl->tCK) / 66; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 320 | |
| 321 | /* DLL_CONFIG_MDLL_W_TIMER */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 322 | ctrl->mdll_wake_delay = (128000 / ctrl->tCK) + 3; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 323 | |
Dan Elkouby | dabebc3 | 2018-04-13 18:47:10 +0300 | [diff] [blame] | 324 | if (ctrl->tCWL) |
| 325 | ctrl->CWL = DIV_ROUND_UP(ctrl->tCWL, ctrl->tCK); |
| 326 | else |
| 327 | ctrl->CWL = get_CWL(ctrl->tCK); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 328 | |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 329 | printk(BIOS_DEBUG, "Selected CWL latency : %uT\n", ctrl->CWL); |
| 330 | |
| 331 | /* Find tRCD */ |
Arthur Heymans | 50db9c9 | 2017-03-23 18:53:38 +0100 | [diff] [blame] | 332 | ctrl->tRCD = DIV_ROUND_UP(ctrl->tRCD, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 333 | printk(BIOS_DEBUG, "Selected tRCD : %uT\n", ctrl->tRCD); |
| 334 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 335 | ctrl->tRP = DIV_ROUND_UP(ctrl->tRP, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 336 | printk(BIOS_DEBUG, "Selected tRP : %uT\n", ctrl->tRP); |
| 337 | |
| 338 | /* Find tRAS */ |
Arthur Heymans | 50db9c9 | 2017-03-23 18:53:38 +0100 | [diff] [blame] | 339 | ctrl->tRAS = DIV_ROUND_UP(ctrl->tRAS, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 340 | printk(BIOS_DEBUG, "Selected tRAS : %uT\n", ctrl->tRAS); |
| 341 | |
| 342 | /* Find tWR */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 343 | ctrl->tWR = DIV_ROUND_UP(ctrl->tWR, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 344 | printk(BIOS_DEBUG, "Selected tWR : %uT\n", ctrl->tWR); |
| 345 | |
| 346 | /* Find tFAW */ |
Arthur Heymans | 50db9c9 | 2017-03-23 18:53:38 +0100 | [diff] [blame] | 347 | ctrl->tFAW = DIV_ROUND_UP(ctrl->tFAW, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 348 | printk(BIOS_DEBUG, "Selected tFAW : %uT\n", ctrl->tFAW); |
| 349 | |
| 350 | /* Find tRRD */ |
Arthur Heymans | 50db9c9 | 2017-03-23 18:53:38 +0100 | [diff] [blame] | 351 | ctrl->tRRD = DIV_ROUND_UP(ctrl->tRRD, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 352 | printk(BIOS_DEBUG, "Selected tRRD : %uT\n", ctrl->tRRD); |
| 353 | |
| 354 | /* Find tRTP */ |
Arthur Heymans | 50db9c9 | 2017-03-23 18:53:38 +0100 | [diff] [blame] | 355 | ctrl->tRTP = DIV_ROUND_UP(ctrl->tRTP, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 356 | printk(BIOS_DEBUG, "Selected tRTP : %uT\n", ctrl->tRTP); |
| 357 | |
| 358 | /* Find tWTR */ |
Arthur Heymans | 50db9c9 | 2017-03-23 18:53:38 +0100 | [diff] [blame] | 359 | ctrl->tWTR = DIV_ROUND_UP(ctrl->tWTR, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 360 | printk(BIOS_DEBUG, "Selected tWTR : %uT\n", ctrl->tWTR); |
| 361 | |
| 362 | /* Refresh-to-Active or Refresh-to-Refresh (tRFC) */ |
Arthur Heymans | 50db9c9 | 2017-03-23 18:53:38 +0100 | [diff] [blame] | 363 | ctrl->tRFC = DIV_ROUND_UP(ctrl->tRFC, ctrl->tCK); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 364 | printk(BIOS_DEBUG, "Selected tRFC : %uT\n", ctrl->tRFC); |
| 365 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 366 | ctrl->tREFI = get_REFI(ctrl->tCK, ctrl->base_freq); |
| 367 | ctrl->tMOD = get_MOD(ctrl->tCK, ctrl->base_freq); |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 368 | ctrl->tXSOffset = get_XSOffset(ctrl->tCK, ctrl->base_freq); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 369 | ctrl->tWLO = get_WLO(ctrl->tCK, ctrl->base_freq); |
| 370 | ctrl->tCKE = get_CKE(ctrl->tCK, ctrl->base_freq); |
| 371 | ctrl->tXPDLL = get_XPDLL(ctrl->tCK, ctrl->base_freq); |
| 372 | ctrl->tXP = get_XP(ctrl->tCK, ctrl->base_freq); |
| 373 | ctrl->tAONPD = get_AONPD(ctrl->tCK, ctrl->base_freq); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 374 | } |
| 375 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 376 | static void dram_freq(ramctr_timing *ctrl) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 377 | { |
| 378 | if (ctrl->tCK > TCK_400MHZ) { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 379 | printk(BIOS_ERR, |
| 380 | "DRAM frequency is under lowest supported frequency (400 MHz). " |
| 381 | "Increasing to 400 MHz as last resort"); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 382 | ctrl->tCK = TCK_400MHZ; |
| 383 | } |
Patrick Rudolph | 77eaba3 | 2016-11-11 18:55:54 +0100 | [diff] [blame] | 384 | |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 385 | while (1) { |
| 386 | u8 val2; |
| 387 | u32 reg1 = 0; |
| 388 | |
| 389 | /* Step 1 - Set target PCU frequency */ |
Arthur Heymans | 9ed74b5 | 2017-05-16 19:56:49 +0200 | [diff] [blame] | 390 | find_cas_tck(ctrl); |
Patrick Rudolph | cab4d3d | 2016-11-24 19:40:23 +0100 | [diff] [blame] | 391 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 392 | /* Frequency multiplier */ |
| 393 | const u32 FRQ = get_FRQ(ctrl->tCK, ctrl->base_freq); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 394 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 395 | /* |
| 396 | * The PLL will never lock if the required frequency is already set. |
| 397 | * Exit early to prevent a system hang. |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 398 | */ |
| 399 | reg1 = MCHBAR32(MC_BIOS_DATA); |
| 400 | val2 = (u8) reg1; |
| 401 | if (val2) |
| 402 | return; |
| 403 | |
| 404 | /* Step 2 - Select frequency in the MCU */ |
| 405 | reg1 = FRQ; |
Patrick Rudolph | cab4d3d | 2016-11-24 19:40:23 +0100 | [diff] [blame] | 406 | if (ctrl->base_freq == 100) |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 407 | reg1 |= 0x100; /* Enable 100Mhz REF clock */ |
| 408 | |
| 409 | reg1 |= 0x80000000; /* set running bit */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 410 | MCHBAR32(MC_BIOS_REQ) = reg1; |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 411 | int i = 0; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 412 | printk(BIOS_DEBUG, "PLL busy... "); |
| 413 | while (reg1 & 0x80000000) { |
| 414 | udelay(10); |
| 415 | i++; |
| 416 | reg1 = MCHBAR32(MC_BIOS_REQ); |
| 417 | } |
| 418 | printk(BIOS_DEBUG, "done in %d us\n", i * 10); |
| 419 | |
| 420 | /* Step 3 - Verify lock frequency */ |
| 421 | reg1 = MCHBAR32(MC_BIOS_DATA); |
| 422 | val2 = (u8) reg1; |
| 423 | if (val2 >= FRQ) { |
| 424 | printk(BIOS_DEBUG, "MCU frequency is set at : %d MHz\n", |
| 425 | (1000 << 8) / ctrl->tCK); |
| 426 | return; |
| 427 | } |
| 428 | printk(BIOS_DEBUG, "PLL didn't lock. Retrying at lower frequency\n"); |
| 429 | ctrl->tCK++; |
| 430 | } |
| 431 | } |
| 432 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 433 | static void dram_ioregs(ramctr_timing *ctrl) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 434 | { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 435 | u32 reg; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 436 | |
| 437 | int channel; |
| 438 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 439 | /* IO clock */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 440 | FOR_ALL_CHANNELS { |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 441 | MCHBAR32(GDCRCLKRANKSUSED_ch(channel)) = ctrl->rankmap[channel]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 442 | } |
| 443 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 444 | /* IO command */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 445 | FOR_ALL_CHANNELS { |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 446 | MCHBAR32(GDCRCTLRANKSUSED_ch(channel)) = ctrl->rankmap[channel]; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 447 | } |
| 448 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 449 | /* IO control */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 450 | FOR_ALL_POPULATED_CHANNELS { |
| 451 | program_timings(ctrl, channel); |
| 452 | } |
| 453 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 454 | /* Perform RCOMP */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 455 | printram("RCOMP..."); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 456 | while (!(MCHBAR32(RCOMP_TIMER) & (1 << 16))) |
| 457 | ; |
| 458 | |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 459 | printram("done\n"); |
| 460 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 461 | /* Set COMP2 */ |
| 462 | MCHBAR32(CRCOMPOFST2) = get_COMP2(ctrl->tCK, ctrl->base_freq); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 463 | printram("COMP2 done\n"); |
| 464 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 465 | /* Set COMP1 */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 466 | FOR_ALL_POPULATED_CHANNELS { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 467 | reg = MCHBAR32(CRCOMPOFST1_ch(channel)); |
| 468 | reg = (reg & ~0x00000e00) | (1 << 9); /* ODT */ |
| 469 | reg = (reg & ~0x00e00000) | (1 << 21); /* clk drive up */ |
| 470 | reg = (reg & ~0x38000000) | (1 << 27); /* ctl drive up */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 471 | MCHBAR32(CRCOMPOFST1_ch(channel)) = reg; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 472 | } |
| 473 | printram("COMP1 done\n"); |
| 474 | |
| 475 | printram("FORCE RCOMP and wait 20us..."); |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 476 | MCHBAR32(M_COMP) |= (1 << 8); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 477 | udelay(20); |
| 478 | printram("done\n"); |
| 479 | } |
| 480 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 481 | int try_init_dram_ddr3_ivb(ramctr_timing *ctrl, int fast_boot, int s3_resume, int me_uma_size) |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 482 | { |
| 483 | int err; |
| 484 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 485 | printk(BIOS_DEBUG, "Starting Ivybridge RAM training (%d).\n", fast_boot); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 486 | |
| 487 | if (!fast_boot) { |
| 488 | /* Find fastest common supported parameters */ |
| 489 | dram_find_common_params(ctrl); |
| 490 | |
| 491 | dram_dimm_mapping(ctrl); |
| 492 | } |
| 493 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 494 | /* Set MC frequency */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 495 | dram_freq(ctrl); |
| 496 | |
| 497 | if (!fast_boot) { |
| 498 | /* Calculate timings */ |
| 499 | dram_timing(ctrl); |
| 500 | } |
| 501 | |
| 502 | /* Set version register */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 503 | MCHBAR32(MRC_REVISION) = 0xc04eb002; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 504 | |
| 505 | /* Enable crossover */ |
| 506 | dram_xover(ctrl); |
| 507 | |
| 508 | /* Set timing and refresh registers */ |
| 509 | dram_timing_regs(ctrl); |
| 510 | |
| 511 | /* Power mode preset */ |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 512 | MCHBAR32(PM_THML_STAT) = 0x5500; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 513 | |
Angel Pons | 8852188 | 2020-01-05 20:21:20 +0100 | [diff] [blame] | 514 | /* Set scheduler chicken bits */ |
| 515 | MCHBAR32(SCHED_CBIT) = 0x10100005; |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 516 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 517 | /* Set up watermarks and starvation counter */ |
Angel Pons | 89ae6b8 | 2020-03-21 13:23:32 +0100 | [diff] [blame] | 518 | set_wmm_behavior(ctrl->cpu); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 519 | |
| 520 | /* Clear IO reset bit */ |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 521 | MCHBAR32(MC_INIT_STATE_G) &= ~(1 << 5); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 522 | |
| 523 | /* Set MAD-DIMM registers */ |
| 524 | dram_dimm_set_mapping(ctrl); |
| 525 | printk(BIOS_DEBUG, "Done dimm mapping\n"); |
| 526 | |
| 527 | /* Zone config */ |
| 528 | dram_zones(ctrl, 1); |
| 529 | |
| 530 | /* Set memory map */ |
| 531 | dram_memorymap(ctrl, me_uma_size); |
| 532 | printk(BIOS_DEBUG, "Done memory map\n"); |
| 533 | |
| 534 | /* Set IO registers */ |
| 535 | dram_ioregs(ctrl); |
| 536 | printk(BIOS_DEBUG, "Done io registers\n"); |
| 537 | |
| 538 | udelay(1); |
| 539 | |
| 540 | if (fast_boot) { |
| 541 | restore_timings(ctrl); |
| 542 | } else { |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 543 | /* Do JEDEC DDR3 reset sequence */ |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 544 | dram_jedecreset(ctrl); |
| 545 | printk(BIOS_DEBUG, "Done jedec reset\n"); |
| 546 | |
| 547 | /* MRS commands */ |
| 548 | dram_mrscommands(ctrl); |
| 549 | printk(BIOS_DEBUG, "Done MRS commands\n"); |
| 550 | |
| 551 | /* Prepare for memory training */ |
| 552 | prepare_training(ctrl); |
| 553 | |
| 554 | err = read_training(ctrl); |
| 555 | if (err) |
| 556 | return err; |
| 557 | |
| 558 | err = write_training(ctrl); |
| 559 | if (err) |
| 560 | return err; |
| 561 | |
| 562 | printram("CP5a\n"); |
| 563 | |
| 564 | err = discover_edges(ctrl); |
| 565 | if (err) |
| 566 | return err; |
| 567 | |
| 568 | printram("CP5b\n"); |
| 569 | |
| 570 | err = command_training(ctrl); |
| 571 | if (err) |
| 572 | return err; |
| 573 | |
| 574 | printram("CP5c\n"); |
| 575 | |
| 576 | err = discover_edges_write(ctrl); |
| 577 | if (err) |
| 578 | return err; |
| 579 | |
| 580 | err = discover_timC_write(ctrl); |
| 581 | if (err) |
| 582 | return err; |
| 583 | |
| 584 | normalize_training(ctrl); |
| 585 | } |
| 586 | |
Angel Pons | 7c49cb8 | 2020-03-16 23:17:32 +0100 | [diff] [blame] | 587 | set_read_write_timings(ctrl); |
Patrick Rudolph | 305035c | 2016-11-11 18:38:50 +0100 | [diff] [blame] | 588 | |
| 589 | write_controller_mr(ctrl); |
| 590 | |
| 591 | if (!s3_resume) { |
| 592 | err = channel_test(ctrl); |
| 593 | if (err) |
| 594 | return err; |
| 595 | } |
| 596 | |
| 597 | return 0; |
| 598 | } |