Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2015 Damien Zammit <damien@zamaudio.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of |
| 9 | * the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <stdint.h> |
| 18 | #include <arch/io.h> |
| 19 | #include <arch/cpu.h> |
| 20 | #include <console/console.h> |
| 21 | #include <commonlib/helpers.h> |
| 22 | #include <delay.h> |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 23 | #include <pc80/mc146818rtc.h> |
| 24 | /* This northbridge can also occur with ICH10 */ |
| 25 | #if IS_ENABLED(CONFIG_SOUTHBRIDGE_INTEL_I82801GX) |
| 26 | #include <southbridge/intel/i82801gx/i82801gx.h> |
| 27 | #endif |
Martin Roth | cbe3892 | 2016-01-05 19:40:41 -0700 | [diff] [blame] | 28 | #include "iomap.h" |
| 29 | #include "x4x.h" |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 30 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 31 | #define ME_UMA_SIZEMB 0 |
| 32 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 33 | static inline void barrier(void) |
| 34 | { |
| 35 | asm volatile("mfence":::); |
| 36 | } |
| 37 | |
| 38 | static u32 fsb2mhz(u32 speed) |
| 39 | { |
| 40 | return (speed * 267) + 800; |
| 41 | } |
| 42 | |
| 43 | static u32 ddr2mhz(u32 speed) |
| 44 | { |
| 45 | static const u16 mhz[] = { 0, 0, 667, 800, 1067, 1333 }; |
| 46 | |
| 47 | if (speed >= ARRAY_SIZE(mhz)) |
| 48 | return 0; |
| 49 | |
| 50 | return mhz[speed]; |
| 51 | } |
| 52 | |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 53 | /* Find MSB bitfield location using bit scan reverse instruction */ |
| 54 | static u8 msbpos(u32 val) |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 55 | { |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 56 | u32 pos; |
| 57 | |
| 58 | if (val == 0) { |
| 59 | printk(BIOS_WARNING, "WARNING: Input to BSR is zero\n"); |
| 60 | return 0; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 61 | } |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 62 | |
| 63 | asm ("bsrl %1, %0" |
| 64 | :"=r"(pos) |
| 65 | :"r"(val) |
| 66 | ); |
| 67 | |
| 68 | return (u8)(pos & 0xff); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void sdram_detect_smallest_params2(struct sysinfo *s) |
| 72 | { |
| 73 | u16 mult[6] = { |
| 74 | 5000, // 400 |
| 75 | 3750, // 533 |
| 76 | 3000, // 667 |
| 77 | 2500, // 800 |
| 78 | 1875, // 1066 |
| 79 | 1500, // 1333 |
| 80 | }; |
| 81 | |
| 82 | u8 i; |
| 83 | u32 tmp; |
| 84 | u32 maxtras = 0; |
| 85 | u32 maxtrp = 0; |
| 86 | u32 maxtrcd = 0; |
| 87 | u32 maxtwr = 0; |
| 88 | u32 maxtrfc = 0; |
| 89 | u32 maxtwtr = 0; |
| 90 | u32 maxtrrd = 0; |
| 91 | u32 maxtrtp = 0; |
| 92 | |
| 93 | FOR_EACH_POPULATED_DIMM(s->dimms, i) { |
| 94 | maxtras = MAX(maxtras, s->dimms[i].spd_data[30] * 1000); |
| 95 | maxtrp = MAX(maxtrp, (s->dimms[i].spd_data[27] * 1000) >> 2); |
| 96 | maxtrcd = MAX(maxtrcd, (s->dimms[i].spd_data[29] * 1000) >> 2); |
| 97 | maxtwr = MAX(maxtwr, (s->dimms[i].spd_data[36] * 1000) >> 2); |
| 98 | maxtrfc = MAX(maxtrfc, s->dimms[i].spd_data[42] * 1000 + |
| 99 | (s->dimms[i].spd_data[40] & 0xf)); |
| 100 | maxtwtr = MAX(maxtwtr, (s->dimms[i].spd_data[37] * 1000) >> 2); |
| 101 | maxtrrd = MAX(maxtrrd, (s->dimms[i].spd_data[28] * 1000) >> 2); |
| 102 | maxtrtp = MAX(maxtrtp, (s->dimms[i].spd_data[38] * 1000) >> 2); |
| 103 | } |
| 104 | for (i = 9; i < 24; i++) { |
| 105 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 106 | if (tmp >= maxtras) { |
| 107 | s->selected_timings.tRAS = i; |
| 108 | break; |
| 109 | } |
| 110 | } |
| 111 | for (i = 3; i < 10; i++) { |
| 112 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 113 | if (tmp >= maxtrp) { |
| 114 | s->selected_timings.tRP = i; |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | for (i = 3; i < 10; i++) { |
| 119 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 120 | if (tmp >= maxtrcd) { |
| 121 | s->selected_timings.tRCD = i; |
| 122 | break; |
| 123 | } |
| 124 | } |
| 125 | for (i = 3; i < 15; i++) { |
| 126 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 127 | if (tmp >= maxtwr) { |
| 128 | s->selected_timings.tWR = i; |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | for (i = 15; i < 78; i++) { |
| 133 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 134 | if (tmp >= maxtrfc) { |
| 135 | s->selected_timings.tRFC = ((i + 16) & 0xfe) - 15; |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | for (i = 4; i < 15; i++) { |
| 140 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 141 | if (tmp >= maxtwtr) { |
| 142 | s->selected_timings.tWTR = i; |
| 143 | break; |
| 144 | } |
| 145 | } |
| 146 | for (i = 2; i < 15; i++) { |
| 147 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 148 | if (tmp >= maxtrrd) { |
| 149 | s->selected_timings.tRRD = i; |
| 150 | break; |
| 151 | } |
| 152 | } |
| 153 | for (i = 4; i < 15; i++) { |
| 154 | tmp = mult[s->selected_timings.mem_clk] * i; |
| 155 | if (tmp >= maxtrtp) { |
| 156 | s->selected_timings.tRTP = i; |
| 157 | break; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | s->selected_timings.fsb_clk = s->max_fsb; |
| 162 | |
| 163 | printk(BIOS_DEBUG, "Selected timings:\n"); |
| 164 | printk(BIOS_DEBUG, "\tFSB: %dMHz\n", fsb2mhz(s->selected_timings.fsb_clk)); |
| 165 | printk(BIOS_DEBUG, "\tDDR: %dMHz\n", ddr2mhz(s->selected_timings.mem_clk)); |
| 166 | |
| 167 | printk(BIOS_DEBUG, "\tCAS: %d\n", s->selected_timings.CAS); |
| 168 | printk(BIOS_DEBUG, "\ttRAS: %d\n", s->selected_timings.tRAS); |
| 169 | printk(BIOS_DEBUG, "\ttRP: %d\n", s->selected_timings.tRP); |
| 170 | printk(BIOS_DEBUG, "\ttRCD: %d\n", s->selected_timings.tRCD); |
| 171 | printk(BIOS_DEBUG, "\ttWR: %d\n", s->selected_timings.tWR); |
| 172 | printk(BIOS_DEBUG, "\ttRFC: %d\n", s->selected_timings.tRFC); |
| 173 | printk(BIOS_DEBUG, "\ttWTR: %d\n", s->selected_timings.tWTR); |
| 174 | printk(BIOS_DEBUG, "\ttRRD: %d\n", s->selected_timings.tRRD); |
| 175 | printk(BIOS_DEBUG, "\ttRTP: %d\n", s->selected_timings.tRTP); |
| 176 | } |
| 177 | |
| 178 | static void clkcross_ddr2(struct sysinfo *s) |
| 179 | { |
| 180 | u8 i, j; |
| 181 | MCHBAR16(0xc1c) = MCHBAR16(0xc1c) | (1 << 15); |
| 182 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 183 | static const u32 clkxtab[6][3][13] = { |
Arthur Heymans | 8a3514d | 2016-10-27 23:56:08 +0200 | [diff] [blame] | 184 | /* MEMCLK 400 N/A */ |
| 185 | {{}, {}, {} }, |
| 186 | /* MEMCLK 533 N/A */ |
| 187 | {{}, {}, {} }, |
| 188 | /* MEMCLK 667 |
| 189 | * FSB 800 */ |
| 190 | {{0x1f1f1f1f, 0x1a07070b, 0x00000000, 0x10000000, |
| 191 | 0x20010208, 0x04080000, 0x10010002, 0x00000000, |
| 192 | 0x00000000, 0x02000000, 0x04000100, 0x08000000, |
| 193 | 0x10200204}, |
| 194 | /* FSB 1067 */ |
| 195 | {0x6d5b1f1f, 0x0f0f0f0f, 0x00000000, 0x20000000, |
| 196 | 0x80020410, 0x02040008, 0x10000100, 0x00000000, |
| 197 | 0x00000000, 0x04000000, 0x08000102, 0x20000000, |
| 198 | 0x40010208}, |
| 199 | /* FSB 1333 */ |
| 200 | {0x05050303, 0xffffffff, 0xffff0000, 0x00000000, |
| 201 | 0x08020000, 0x00000000, 0x00020001, 0x00000000, |
| 202 | 0x00000000, 0x00000000, 0x08010204, 0x00000000, |
| 203 | 0x04010000} }, |
| 204 | /* MEMCLK 800 |
| 205 | * FSB 800 */ |
| 206 | {{0xffffffff, 0x05030305, 0x0000ffff, 0x0000000, |
| 207 | 0x08010204, 0x00000000, 0x08010204, 0x0000000, |
| 208 | 0x00000000, 0x00000000, 0x00020001, 0x0000000, |
| 209 | 0x04080102}, |
| 210 | /* FSB 1067 */ |
| 211 | {0x07070707, 0x06030303, 0x00000000, 0x00000000, |
| 212 | 0x08010200, 0x00000000, 0x04000102, 0x00000000, |
| 213 | 0x00000000, 0x00000000, 0x00020001, 0x00000000, |
| 214 | 0x02040801}, |
| 215 | /* FSB 1333 */ |
| 216 | {0x0d0b0707, 0x3e1f1f2f, 0x01010000, 0x00000000, |
| 217 | 0x10020400, 0x02000000, 0x00040100, 0x00000000, |
| 218 | 0x00000000, 0x04080000, 0x00100102, 0x00000000, |
| 219 | 0x08100200} }, |
| 220 | /* MEMCLK 1067 */ |
| 221 | {{}, |
| 222 | /* FSB 1067 */ |
| 223 | {0xffffffff, 0x05030305, 0x0000ffff, 0x00000000, |
| 224 | 0x04080102, 0x00000000, 0x08010204, 0x00000000, |
| 225 | 0x00000000, 0x00000000, 0x00020001, 0x00000000, |
| 226 | 0x02040801}, |
| 227 | /* FSB 1333 */ |
| 228 | {0x0f0f0f0f, 0x5b1f1f6d, 0x00000000, 0x00000000, |
| 229 | 0x08010204, 0x04000000, 0x00080102, 0x00000000, |
| 230 | 0x00000000, 0x02000408, 0x00100001, 0x00000000, |
| 231 | 0x04080102} }, |
| 232 | /* MEMCLK 1333 */ |
| 233 | {{}, {}, |
| 234 | /* FSB 1333 */ |
| 235 | {0xffffffff, 0x05030305, 0x0000ffff, 0x00000000, |
| 236 | 0x04080102, 0x00000000, 0x04080102, 0x00000000, |
| 237 | 0x00000000, 0x00000000, 0x00000000, 0x00000000, |
| 238 | 0x02040801} } |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | i = (u8)s->selected_timings.mem_clk; |
| 242 | j = (u8)s->selected_timings.fsb_clk; |
| 243 | |
| 244 | MCHBAR32(0xc04) = clkxtab[i][j][0]; |
| 245 | MCHBAR32(0xc50) = clkxtab[i][j][1]; |
| 246 | MCHBAR32(0xc54) = clkxtab[i][j][2]; |
| 247 | MCHBAR8(0xc08) = MCHBAR8(0xc08) | (1 << 7); |
| 248 | MCHBAR32(0x6d8) = clkxtab[i][j][3]; |
| 249 | MCHBAR32(0x6e0) = clkxtab[i][j][3]; |
| 250 | MCHBAR32(0x6dc) = clkxtab[i][j][4]; |
| 251 | MCHBAR32(0x6e4) = clkxtab[i][j][4]; |
| 252 | MCHBAR32(0x6e8) = clkxtab[i][j][5]; |
| 253 | MCHBAR32(0x6f0) = clkxtab[i][j][5]; |
| 254 | MCHBAR32(0x6ec) = clkxtab[i][j][6]; |
| 255 | MCHBAR32(0x6f4) = clkxtab[i][j][6]; |
| 256 | MCHBAR32(0x6f8) = clkxtab[i][j][7]; |
| 257 | MCHBAR32(0x6fc) = clkxtab[i][j][8]; |
| 258 | MCHBAR32(0x708) = clkxtab[i][j][11]; |
| 259 | MCHBAR32(0x70c) = clkxtab[i][j][12]; |
| 260 | } |
| 261 | |
| 262 | static void checkreset_ddr2(struct sysinfo *s) |
| 263 | { |
| 264 | u8 pmcon2; |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 265 | u32 pmsts; |
| 266 | |
| 267 | if (s->boot_path >= 1) { |
| 268 | pmsts = MCHBAR32(PMSTS_MCHBAR); |
| 269 | if (!(pmsts & 1)) |
| 270 | printk(BIOS_DEBUG, |
| 271 | "Channel 0 possibly not in self refresh\n"); |
| 272 | if (!(pmsts & 2)) |
| 273 | printk(BIOS_DEBUG, |
| 274 | "Channel 1 possibly not in self refresh\n"); |
| 275 | } |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 276 | |
| 277 | pmcon2 = pci_read_config8(PCI_DEV(0, 0x1f, 0), 0xa2); |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 278 | |
| 279 | if (pmcon2 & 0x80) { |
| 280 | pmcon2 &= ~0x80; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 281 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, pmcon2); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 282 | |
| 283 | /* do magic 0xf0 thing. */ |
| 284 | u8 reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf0); |
| 285 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf0, reg8 & ~(1 << 2)); |
| 286 | reg8 = pci_read_config8(PCI_DEV(0, 0, 0), 0xf0); |
| 287 | pci_write_config8(PCI_DEV(0, 0, 0), 0xf0, reg8 | (1 << 2)); |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 288 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 289 | printk(BIOS_DEBUG, "Reset...\n"); |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 290 | outb(0x6, 0xcf9); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 291 | asm ("hlt"); |
| 292 | } |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 293 | pmcon2 |= 0x80; |
| 294 | pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, pmcon2); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void setioclk_ddr2(struct sysinfo *s) |
| 298 | { |
| 299 | MCHBAR32(0x1bc) = 0x08060402; |
| 300 | MCHBAR16(0x1c0) = MCHBAR16(0x1c0) | 0x200; |
| 301 | MCHBAR16(0x1c0) = MCHBAR16(0x1c0) | 0x100; |
| 302 | MCHBAR16(0x1c0) = MCHBAR16(0x1c0) | 0x20; |
| 303 | MCHBAR16(0x1c0) = MCHBAR16(0x1c0) & ~1; |
| 304 | switch (s->selected_timings.mem_clk) { |
| 305 | default: |
| 306 | case MEM_CLOCK_800MHz: |
| 307 | case MEM_CLOCK_1066MHz: |
| 308 | MCHBAR8(0x5d9) = (MCHBAR8(0x5d9) & ~0x2) | 0x2; |
| 309 | MCHBAR8(0x9d9) = (MCHBAR8(0x9d9) & ~0x2) | 0x2; |
| 310 | MCHBAR8(0x189) = (MCHBAR8(0x189) & ~0xf0) | 0xc0; |
| 311 | MCHBAR8(0x189) = (MCHBAR8(0x189) & ~0xf0) | 0xe0; |
| 312 | MCHBAR8(0x189) = (MCHBAR8(0x189) & ~0xf0) | 0xa0; |
| 313 | break; |
| 314 | case MEM_CLOCK_667MHz: |
| 315 | case MEM_CLOCK_1333MHz: |
| 316 | MCHBAR8(0x5d9) = MCHBAR8(0x5d9) & ~0x2; |
| 317 | MCHBAR8(0x9d9) = MCHBAR8(0x9d9) & ~0x2; |
| 318 | MCHBAR8(0x189) = (MCHBAR8(0x189) & ~0xf0) | 0x40; |
| 319 | break; |
| 320 | } |
| 321 | MCHBAR32(0x594) = MCHBAR32(0x594) | (1 << 31); |
| 322 | MCHBAR32(0x994) = MCHBAR32(0x994) | (1 << 31); |
| 323 | } |
| 324 | |
| 325 | static void launch_ddr2(struct sysinfo *s) |
| 326 | { |
| 327 | u8 i; |
| 328 | u32 launch1 = 0x58001117; |
| 329 | u32 launch2 = 0; |
| 330 | u32 launch3 = 0; |
| 331 | |
| 332 | if (s->selected_timings.CAS == 5) { |
| 333 | launch2 = 0x00220201; |
Damien Zammit | 7c2e539 | 2016-07-24 03:28:42 +1000 | [diff] [blame] | 334 | } else if (s->selected_timings.CAS == 6) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 335 | launch2 = 0x00230302; |
| 336 | } else { |
Damien Zammit | 7c2e539 | 2016-07-24 03:28:42 +1000 | [diff] [blame] | 337 | die("Unsupported CAS\n"); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
| 341 | MCHBAR32(0x400*i + 0x220) = launch1; |
| 342 | MCHBAR32(0x400*i + 0x224) = launch2; |
| 343 | MCHBAR32(0x400*i + 0x21c) = launch3; |
| 344 | MCHBAR32(0x400*i + 0x248) = MCHBAR32(0x400*i + 0x248) | (1 << 23); |
| 345 | } |
| 346 | |
| 347 | MCHBAR32(0x2c0) = (MCHBAR32(0x2c0) & ~0x58000000) | 0x48000000; |
| 348 | MCHBAR32(0x2c0) = MCHBAR32(0x2c0) | 0x1e0; |
| 349 | MCHBAR32(0x2c4) = (MCHBAR32(0x2c4) & ~0xf) | 0xc; |
| 350 | } |
| 351 | |
| 352 | static void clkset0(u8 ch, u8 setting[5]) |
| 353 | { |
| 354 | MCHBAR16(0x400*ch + 0x5a0) = (MCHBAR16(0x400*ch + 0x5a0) & ~0xc440) | |
| 355 | (setting[4] << 14) | |
| 356 | (setting[3] << 6) | |
| 357 | (setting[2] << 10); |
| 358 | MCHBAR8(0x400*ch + 0x581) = (MCHBAR8(0x400*ch + 0x581) & ~0x70) | |
| 359 | (setting[1] << 4); |
| 360 | MCHBAR8(0x400*ch + 0x581) = (MCHBAR8(0x400*ch + 0x581) & ~0xf) | |
| 361 | setting[0]; |
| 362 | } |
| 363 | |
| 364 | static void clkset1(u8 ch, u8 setting[5]) |
| 365 | { |
| 366 | MCHBAR32(0x400*ch + 0x5a0) = (MCHBAR32(0x400*ch + 0x5a0) & ~0x30880) | |
| 367 | (setting[4] << 16) | |
| 368 | (setting[3] << 7) | |
| 369 | (setting[2] << 11); |
| 370 | MCHBAR8(0x400*ch + 0x582) = (MCHBAR8(0x400*ch + 0x582) & ~0x70) | |
| 371 | (setting[1] << 4); |
| 372 | MCHBAR8(0x400*ch + 0x582) = (MCHBAR8(0x400*ch + 0x582) & ~0xf) | |
| 373 | setting[0]; |
| 374 | } |
| 375 | |
| 376 | static void ctrlset0(u8 ch, u8 setting[5]) |
| 377 | { |
| 378 | MCHBAR32(0x400*ch + 0x59c) = (MCHBAR32(0x400*ch + 0x59c) & ~0x3300000) | |
| 379 | (setting[4] << 24) | |
| 380 | (setting[3] << 20) | |
| 381 | (setting[2] << 21); |
| 382 | MCHBAR8(0x400*ch + 0x584) = (MCHBAR8(0x400*ch + 0x584) & ~0x70) | |
| 383 | (setting[1] << 4); |
| 384 | MCHBAR8(0x400*ch + 0x584) = (MCHBAR8(0x400*ch + 0x584) & ~0xf) | |
| 385 | setting[0]; |
| 386 | } |
| 387 | |
| 388 | static void ctrlset1(u8 ch, u8 setting[5]) |
| 389 | { |
| 390 | MCHBAR32(0x400*ch + 0x59c) = (MCHBAR32(0x400*ch + 0x59c) & ~0x18c00000) | |
| 391 | (setting[4] << 27) | |
| 392 | (setting[3] << 22) | |
| 393 | (setting[2] << 23); |
| 394 | MCHBAR8(0x400*ch + 0x585) = (MCHBAR8(0x400*ch + 0x585) & ~0x70) | |
| 395 | (setting[1] << 4); |
| 396 | MCHBAR8(0x400*ch + 0x585) = (MCHBAR8(0x400*ch + 0x585) & ~0xf) | |
| 397 | setting[0]; |
| 398 | } |
| 399 | |
| 400 | static void ctrlset2(u8 ch, u8 setting[5]) |
| 401 | { |
| 402 | MCHBAR32(0x400*ch + 0x598) = (MCHBAR32(0x400*ch + 0x598) & ~0x18c00000) | |
| 403 | (setting[4] << 14) | |
| 404 | (setting[3] << 12) | |
| 405 | (setting[2] << 13); |
| 406 | MCHBAR8(0x400*ch + 0x586) = (MCHBAR8(0x400*ch + 0x586) & ~0x70) | |
| 407 | (setting[1] << 4); |
| 408 | MCHBAR8(0x400*ch + 0x586) = (MCHBAR8(0x400*ch + 0x586) & ~0xf) | |
| 409 | setting[0]; |
| 410 | } |
| 411 | |
| 412 | static void ctrlset3(u8 ch, u8 setting[5]) |
| 413 | { |
| 414 | MCHBAR32(0x400*ch + 0x598) = (MCHBAR32(0x400*ch + 0x598) & ~0x18c00000) | |
| 415 | (setting[4] << 10) | |
| 416 | (setting[3] << 8) | |
| 417 | (setting[2] << 9); |
| 418 | MCHBAR8(0x400*ch + 0x587) = (MCHBAR8(0x400*ch + 0x587) & ~0x70) | |
| 419 | (setting[1] << 4); |
| 420 | MCHBAR8(0x400*ch + 0x587) = (MCHBAR8(0x400*ch + 0x587) & ~0xf) | |
| 421 | setting[0]; |
| 422 | } |
| 423 | |
| 424 | static void cmdset(u8 ch, u8 setting[5]) |
| 425 | { |
| 426 | MCHBAR8(0x400*ch + 0x598) = (MCHBAR8(0x400*ch + 0x598) & ~0x30) | |
| 427 | (setting[4] << 4); |
| 428 | MCHBAR8(0x400*ch + 0x594) = (MCHBAR8(0x400*ch + 0x594) & ~0x60) | |
| 429 | (setting[3] << 5) | |
| 430 | (setting[2] << 6); |
| 431 | MCHBAR8(0x400*ch + 0x580) = (MCHBAR8(0x400*ch + 0x580) & ~0x70) | |
| 432 | (setting[1] << 4); |
| 433 | MCHBAR8(0x400*ch + 0x580) = (MCHBAR8(0x400*ch + 0x580) & ~0xf) | |
| 434 | setting[0]; |
| 435 | } |
| 436 | |
| 437 | static void dqsset(u8 ch, u8 lane, u8 setting[5]) |
| 438 | { |
| 439 | MCHBAR32(0x400*ch + 0x5fc) = MCHBAR32(0x400*ch + 0x5fc) & ~(2 << (lane*4)); |
| 440 | |
| 441 | MCHBAR32(0x400*ch + 0x5b4) = (MCHBAR32(0x400*ch + 0x5b4) & ~(0x201 << lane)) | |
| 442 | (setting[2] << (9 + lane)) | |
| 443 | (setting[3] << lane); |
| 444 | MCHBAR32(0x400*ch + 0x5b8) = (MCHBAR32(0x400*ch + 0x5b8) & ~(0x201 << lane)) | |
| 445 | (setting[2] << (9 + lane)) | |
| 446 | (setting[3] << lane); |
| 447 | MCHBAR32(0x400*ch + 0x5bc) = (MCHBAR32(0x400*ch + 0x5bc) & ~(0x201 << lane)) | |
| 448 | (setting[2] << (9 + lane)) | |
| 449 | (setting[3] << lane); |
| 450 | MCHBAR32(0x400*ch + 0x5c0) = (MCHBAR32(0x400*ch + 0x5c0) & ~(0x201 << lane)) | |
| 451 | (setting[2] << (9 + lane)) | |
| 452 | (setting[3] << lane); |
| 453 | |
| 454 | MCHBAR32(0x400*ch + 0x5c8) = (MCHBAR32(0x400*ch + 0x5c8) & ~(0x3 << (16+lane*2))) | |
| 455 | (setting[4] << (16+lane*2)); |
| 456 | MCHBAR32(0x400*ch + 0x5cc) = (MCHBAR32(0x400*ch + 0x5cc) & ~(0x3 << (16+lane*2))) | |
| 457 | (setting[4] << (16+lane*2)); |
| 458 | MCHBAR32(0x400*ch + 0x5d0) = (MCHBAR32(0x400*ch + 0x5d0) & ~(0x3 << (16+lane*2))) | |
| 459 | (setting[4] << (16+lane*2)); |
| 460 | MCHBAR32(0x400*ch + 0x5d4) = (MCHBAR32(0x400*ch + 0x5d4) & ~(0x3 << (16+lane*2))) | |
| 461 | (setting[4] << (16+lane*2)); |
| 462 | |
| 463 | MCHBAR8(0x400*ch + 0x520 + lane*4) = (MCHBAR8(0x400*ch + 0x520 + lane*4) & ~0x70) | |
| 464 | (setting[1] << 4); |
| 465 | MCHBAR8(0x400*ch + 0x520 + lane*4) = (MCHBAR8(0x400*ch + 0x520 + lane*4) & ~0xf) | |
| 466 | setting[0]; |
| 467 | MCHBAR8(0x400*ch + 0x521 + lane*4) = (MCHBAR8(0x400*ch + 0x521 + lane*4) & ~0x70) | |
| 468 | (setting[1] << 4); |
| 469 | MCHBAR8(0x400*ch + 0x521 + lane*4) = (MCHBAR8(0x400*ch + 0x521 + lane*4) & ~0xf) | |
| 470 | setting[0]; |
| 471 | MCHBAR8(0x400*ch + 0x522 + lane*4) = (MCHBAR8(0x400*ch + 0x522 + lane*4) & ~0x70) | |
| 472 | (setting[1] << 4); |
| 473 | MCHBAR8(0x400*ch + 0x522 + lane*4) = (MCHBAR8(0x400*ch + 0x522 + lane*4) & ~0xf) | |
| 474 | setting[0]; |
| 475 | MCHBAR8(0x400*ch + 0x523 + lane*4) = (MCHBAR8(0x400*ch + 0x523 + lane*4) & ~0x70) | |
| 476 | (setting[1] << 4); |
| 477 | MCHBAR8(0x400*ch + 0x523 + lane*4) = (MCHBAR8(0x400*ch + 0x523 + lane*4) & ~0xf) | |
| 478 | setting[0]; |
| 479 | } |
| 480 | |
| 481 | static void dqset(u8 ch, u8 lane, u8 setting[5]) |
| 482 | { |
| 483 | MCHBAR32(0x400*ch + 0x5fc) = MCHBAR32(0x400*ch + 0x5fc) & ~(1 << (lane*4)); |
| 484 | |
| 485 | MCHBAR32(0x400*ch + 0x5a4) = (MCHBAR32(0x400*ch + 0x5a4) & ~(0x201 << lane)) | |
| 486 | (setting[2] << (9+lane)) | |
| 487 | (setting[3] << lane); |
| 488 | MCHBAR32(0x400*ch + 0x5a8) = (MCHBAR32(0x400*ch + 0x5a8) & ~(0x201 << lane)) | |
| 489 | (setting[2] << (9+lane)) | |
| 490 | (setting[3] << lane); |
| 491 | MCHBAR32(0x400*ch + 0x5ac) = (MCHBAR32(0x400*ch + 0x5ac) & ~(0x201 << lane)) | |
| 492 | (setting[2] << (9+lane)) | |
| 493 | (setting[3] << lane); |
| 494 | MCHBAR32(0x400*ch + 0x5b0) = (MCHBAR32(0x400*ch + 0x5b0) & ~(0x201 << lane)) | |
| 495 | (setting[2] << (9+lane)) | |
| 496 | (setting[3] << lane); |
| 497 | |
| 498 | MCHBAR32(0x400*ch + 0x5c8) = (MCHBAR32(0x400*ch + 0x5c8) & ~(0x3 << (lane*2))) | |
| 499 | (setting[4] << (2*lane)); |
| 500 | MCHBAR32(0x400*ch + 0x5cc) = (MCHBAR32(0x400*ch + 0x5cc) & ~(0x3 << (lane*2))) | |
| 501 | (setting[4] << (2*lane)); |
| 502 | MCHBAR32(0x400*ch + 0x5d0) = (MCHBAR32(0x400*ch + 0x5d0) & ~(0x3 << (lane*2))) | |
| 503 | (setting[4] << (2*lane)); |
| 504 | MCHBAR32(0x400*ch + 0x5d4) = (MCHBAR32(0x400*ch + 0x5d4) & ~(0x3 << (lane*2))) | |
| 505 | (setting[4] << (2*lane)); |
| 506 | |
| 507 | MCHBAR8(0x400*ch + 0x500 + lane*4) = (MCHBAR8(0x400*ch + 0x500 + lane*4) & ~0x70) | |
| 508 | (setting[1] << 4); |
| 509 | MCHBAR8(0x400*ch + 0x500 + lane*4) = (MCHBAR8(0x400*ch + 0x500 + lane*4) & ~0xf) | |
| 510 | setting[0]; |
| 511 | MCHBAR8(0x400*ch + 0x501 + lane*4) = (MCHBAR8(0x400*ch + 0x501 + lane*4) & ~0x70) | |
| 512 | (setting[1] << 4); |
| 513 | MCHBAR8(0x400*ch + 0x501 + lane*4) = (MCHBAR8(0x400*ch + 0x501 + lane*4) & ~0xf) | |
| 514 | setting[0]; |
| 515 | MCHBAR8(0x400*ch + 0x502 + lane*4) = (MCHBAR8(0x400*ch + 0x502 + lane*4) & ~0x70) | |
| 516 | (setting[1] << 4); |
| 517 | MCHBAR8(0x400*ch + 0x502 + lane*4) = (MCHBAR8(0x400*ch + 0x502 + lane*4) & ~0xf) | |
| 518 | setting[0]; |
| 519 | MCHBAR8(0x400*ch + 0x503 + lane*4) = (MCHBAR8(0x400*ch + 0x503 + lane*4) & ~0x70) | |
| 520 | (setting[1] << 4); |
| 521 | MCHBAR8(0x400*ch + 0x503 + lane*4) = (MCHBAR8(0x400*ch + 0x503 + lane*4) & ~0xf) | |
| 522 | setting[0]; |
| 523 | } |
| 524 | |
| 525 | static void timings_ddr2(struct sysinfo *s) |
| 526 | { |
| 527 | u8 i; |
| 528 | u8 twl, ta1, ta2, ta3, ta4; |
| 529 | u8 reg8; |
| 530 | u8 flag1 = 0; |
| 531 | u8 flag2 = 0; |
| 532 | u16 reg16; |
| 533 | u32 reg32; |
| 534 | u16 ddr, fsb; |
| 535 | u8 trpmod = 0; |
| 536 | u8 bankmod = 1; |
| 537 | u8 pagemod = 0; |
Arthur Heymans | eee4f6b | 2017-01-03 00:49:45 +0100 | [diff] [blame] | 538 | u8 adjusted_cas; |
| 539 | |
| 540 | adjusted_cas = s->selected_timings.CAS - 3; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 541 | |
| 542 | u16 fsb2ps[3] = { |
| 543 | 5000, // 800 |
| 544 | 3750, // 1067 |
| 545 | 3000 // 1333 |
| 546 | }; |
| 547 | |
| 548 | u16 ddr2ps[6] = { |
| 549 | 5000, // 400 |
| 550 | 3750, // 533 |
| 551 | 3000, // 667 |
| 552 | 2500, // 800 |
| 553 | 1875, // 1067 |
| 554 | 1500 // 1333 |
| 555 | }; |
| 556 | |
| 557 | u16 lut1[6] = { |
| 558 | 0, |
| 559 | 0, |
| 560 | 2600, |
| 561 | 3120, |
| 562 | 4171, |
| 563 | 5200 |
| 564 | }; |
| 565 | |
| 566 | ta1 = 6; |
| 567 | ta2 = 6; |
| 568 | ta3 = 5; |
| 569 | ta4 = 8; |
| 570 | |
| 571 | twl = s->selected_timings.CAS - 1; |
| 572 | |
| 573 | FOR_EACH_POPULATED_DIMM(s->dimms, i) { |
| 574 | if (s->dimms[i].banks == 1) { // 8 banks |
| 575 | trpmod = 1; |
| 576 | bankmod = 0; |
| 577 | } |
| 578 | if (s->dimms[i].page_size == 2048) { |
| 579 | pagemod = 1; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
Arthur Heymans | eee4f6b | 2017-01-03 00:49:45 +0100 | [diff] [blame] | 584 | MCHBAR8(0x400*i + 0x26f) = MCHBAR8(0x400*i + 0x26f) | 0x3; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 585 | MCHBAR8(0x400*i + 0x228) = (MCHBAR8(0x400*i + 0x228) & ~0x7) | 0x2; |
Arthur Heymans | eee4f6b | 2017-01-03 00:49:45 +0100 | [diff] [blame] | 586 | MCHBAR8(0x400*i + 0x240) = (MCHBAR8(0x400*i + 0x240) & ~0xf0) |
| 587 | | (0 << 4); /* tWL - x ?? */ |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 588 | MCHBAR8(0x400*i + 0x240) = (MCHBAR8(0x400*i + 0x240) & ~0xf) | |
Arthur Heymans | eee4f6b | 2017-01-03 00:49:45 +0100 | [diff] [blame] | 589 | adjusted_cas; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 590 | MCHBAR16(0x400*i + 0x265) = (MCHBAR16(0x400*i + 0x265) & ~0x3f00) | |
Arthur Heymans | eee4f6b | 2017-01-03 00:49:45 +0100 | [diff] [blame] | 591 | ((adjusted_cas + 9) << 8); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 592 | |
| 593 | reg16 = (s->selected_timings.tRAS << 11) | |
| 594 | ((twl + 4 + s->selected_timings.tWR) << 6) | |
| 595 | ((2 + MAX(s->selected_timings.tRTP, 2)) << 2) | 1; |
| 596 | MCHBAR16(0x400*i + 0x250) = reg16; |
| 597 | |
| 598 | reg32 = (bankmod << 21) | |
| 599 | (s->selected_timings.tRRD << 17) | |
| 600 | (s->selected_timings.tRP << 13) | |
| 601 | ((s->selected_timings.tRP + trpmod) << 9) | |
| 602 | s->selected_timings.tRFC; |
| 603 | reg8 = (MCHBAR8(0x400*i + 0x26f) >> 1) & 1; |
| 604 | if (bankmod) { |
| 605 | switch (s->selected_timings.mem_clk) { |
| 606 | default: |
| 607 | case MEM_CLOCK_667MHz: |
| 608 | if (reg8) { |
| 609 | if (pagemod) { |
| 610 | reg32 |= 16 << 22; |
| 611 | } else { |
| 612 | reg32 |= 12 << 22; |
| 613 | } |
| 614 | } else { |
| 615 | if (pagemod) { |
| 616 | reg32 |= 18 << 22; |
| 617 | } else { |
| 618 | reg32 |= 14 << 22; |
| 619 | } |
| 620 | } |
| 621 | break; |
| 622 | case MEM_CLOCK_800MHz: |
| 623 | if (reg8) { |
| 624 | if (pagemod) { |
| 625 | reg32 |= 18 << 22; |
| 626 | } else { |
| 627 | reg32 |= 14 << 22; |
| 628 | } |
| 629 | } else { |
| 630 | if (pagemod) { |
| 631 | reg32 |= 20 << 22; |
| 632 | } else { |
| 633 | reg32 |= 16 << 22; |
| 634 | } |
| 635 | } |
| 636 | break; |
| 637 | } |
| 638 | } |
| 639 | MCHBAR32(0x400*i + 0x252) = reg32; |
| 640 | |
| 641 | MCHBAR16(0x400*i + 0x256) = (s->selected_timings.tRCD << 12) | |
| 642 | (0x4 << 8) | (ta2 << 4) | ta4; |
| 643 | |
| 644 | MCHBAR32(0x400*i + 0x258) = (s->selected_timings.tRCD << 17) | |
| 645 | ((twl + 4 + s->selected_timings.tWTR) << 12) | |
| 646 | (ta3 << 8) | (4 << 4) | ta1; |
| 647 | |
| 648 | MCHBAR16(0x400*i + 0x25b) = ((s->selected_timings.tRP + trpmod) << 9) | |
| 649 | s->selected_timings.tRFC; |
| 650 | |
| 651 | MCHBAR16(0x400*i + 0x260) = (MCHBAR16(0x400*i + 0x260) & ~0x3fe) | (100 << 1); |
| 652 | MCHBAR8(0x400*i + 0x264) = 0xff; |
| 653 | MCHBAR8(0x400*i + 0x25d) = (MCHBAR8(0x400*i + 0x25d) & ~0x3f) | |
| 654 | s->selected_timings.tRAS; |
| 655 | MCHBAR16(0x400*i + 0x244) = 0x2310; |
| 656 | |
| 657 | switch (s->selected_timings.mem_clk) { |
| 658 | case MEM_CLOCK_667MHz: |
| 659 | reg8 = 0; |
| 660 | break; |
| 661 | default: |
| 662 | reg8 = 1; |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | MCHBAR8(0x400*i + 0x246) = (MCHBAR8(0x400*i + 0x246) & ~0x1f) | |
| 667 | (reg8 << 2) | 1; |
| 668 | |
| 669 | fsb = fsb2ps[s->selected_timings.fsb_clk]; |
| 670 | ddr = ddr2ps[s->selected_timings.mem_clk]; |
Arthur Heymans | eee4f6b | 2017-01-03 00:49:45 +0100 | [diff] [blame] | 671 | reg32 = (u32)((adjusted_cas + 7 + reg8) * ddr); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 672 | reg32 = (u32)((reg32 / fsb) << 8); |
| 673 | reg32 |= 0x0e000000; |
| 674 | if ((fsb2mhz(s->selected_timings.fsb_clk) / |
| 675 | ddr2mhz(s->selected_timings.mem_clk)) > 2) { |
| 676 | reg32 |= 1 << 24; |
| 677 | } |
| 678 | MCHBAR32(0x400*i + 0x248) = (MCHBAR32(0x400*i + 0x248) & ~0x0f001f00) | |
| 679 | reg32; |
| 680 | |
| 681 | if (twl > 2) { |
| 682 | flag1 = 1; |
| 683 | } |
| 684 | if (s->selected_timings.mem_clk >= MEM_CLOCK_800MHz) { |
| 685 | flag2 = 1; |
| 686 | } |
| 687 | reg16 = (u8)(twl - 1 - flag1 - flag2); |
| 688 | reg16 |= reg16 << 4; |
| 689 | if (s->selected_timings.mem_clk == MEM_CLOCK_1333MHz) { |
| 690 | if (reg16) { |
| 691 | reg16--; |
| 692 | } |
| 693 | } |
| 694 | reg16 |= flag1 << 8; |
| 695 | reg16 |= flag2 << 9; |
| 696 | MCHBAR16(0x400*i + 0x24d) = (MCHBAR16(0x400*i + 0x24d) & ~0x1ff) | reg16; |
| 697 | MCHBAR16(0x400*i + 0x25e) = 0x15a5; |
| 698 | MCHBAR32(0x400*i + 0x265) = MCHBAR32(0x400*i + 0x265) & ~0x1f; |
| 699 | MCHBAR32(0x400*i + 0x269) = (MCHBAR32(0x400*i + 0x269) & ~0x000fffff) | |
| 700 | (0x3f << 14) | lut1[s->selected_timings.mem_clk]; |
| 701 | MCHBAR8(0x400*i + 0x274) = MCHBAR8(0x400*i + 0x274) | 1; |
| 702 | MCHBAR8(0x400*i + 0x24c) = MCHBAR8(0x400*i + 0x24c) & ~0x3; |
| 703 | |
| 704 | reg16 = 0; |
| 705 | switch (s->selected_timings.mem_clk) { |
| 706 | default: |
| 707 | case MEM_CLOCK_667MHz: |
| 708 | reg16 = 0x99; |
| 709 | break; |
| 710 | case MEM_CLOCK_800MHz: |
| 711 | if (s->selected_timings.CAS == 5) { |
| 712 | reg16 = 0x19a; |
| 713 | } else if (s->selected_timings.CAS == 6) { |
| 714 | reg16 = 0x9a; |
| 715 | } |
| 716 | break; |
| 717 | } |
| 718 | reg16 &= 0x7; |
| 719 | reg16 += twl + 9; |
| 720 | reg16 <<= 10; |
| 721 | MCHBAR16(0x400*i + 0x24d) = (MCHBAR16(0x400*i + 0x24d) & ~0x7c00) | reg16; |
| 722 | MCHBAR8(0x400*i + 0x267) = (MCHBAR8(0x400*i + 0x267) & ~0x3f) | 0x13; |
| 723 | MCHBAR8(0x400*i + 0x268) = (MCHBAR8(0x400*i + 0x268) & ~0xff) | 0x4a; |
| 724 | |
| 725 | reg16 = (MCHBAR16(0x400*i + 0x269) & 0xc000) >> 2; |
| 726 | reg16 += 2 << 12; |
| 727 | reg16 |= (0x15 << 6) | 0x1f; |
| 728 | MCHBAR16(0x400*i + 0x26d) = (MCHBAR16(0x400*i + 0x26d) & ~0x7fff) | reg16; |
| 729 | |
| 730 | reg32 = (1 << 25) | (6 << 27); |
| 731 | MCHBAR32(0x400*i + 0x269) = (MCHBAR32(0x400*i + 0x269) & ~0xfa300000) | reg32; |
| 732 | MCHBAR8(0x400*i + 0x271) = MCHBAR8(0x400*i + 0x271) & ~0x80; |
| 733 | MCHBAR8(0x400*i + 0x274) = MCHBAR8(0x400*i + 0x274) & ~0x6; |
| 734 | } // END EACH POPULATED CHANNEL |
| 735 | |
| 736 | reg16 = 0x1f << 5; |
| 737 | reg16 |= 0xe << 10; |
| 738 | MCHBAR16(0x125) = (MCHBAR16(0x125) & ~0x3fe0) | reg16; |
| 739 | MCHBAR16(0x127) = (MCHBAR16(0x127) & ~0x7ff) | 0x540; |
| 740 | MCHBAR8(0x129) = MCHBAR8(0x129) | 0x1f; |
| 741 | MCHBAR8(0x12c) = MCHBAR8(0x12c) | 0xa0; |
| 742 | MCHBAR32(0x241) = (MCHBAR32(0x241) & ~0x1ffff) | 0x11; |
| 743 | MCHBAR32(0x641) = (MCHBAR32(0x641) & ~0x1ffff) | 0x11; |
| 744 | MCHBAR8(0x246) = MCHBAR8(0x246) & ~0x10; |
| 745 | MCHBAR8(0x646) = MCHBAR8(0x646) & ~0x10; |
| 746 | MCHBAR32(0x120) = (2 << 29) | (1 << 28) | (1 << 23) | 0xd7f5f; |
| 747 | reg8 = (u8)((MCHBAR32(0x252) & 0x1e000) >> 13); |
| 748 | MCHBAR8(0x12d) = (MCHBAR8(0x12d) & ~0xf0) | (reg8 << 4); |
Arthur Heymans | eee4f6b | 2017-01-03 00:49:45 +0100 | [diff] [blame] | 749 | reg8 = (u8)((MCHBAR32(0x258) & 0x1e0000) >> 17); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 750 | MCHBAR8(0x12d) = (MCHBAR8(0x12d) & ~0xf) | reg8; |
| 751 | MCHBAR8(0x12f) = 0x4c; |
| 752 | reg32 = (1 << 31) | (0x80 << 14) | (1 << 13) | (0xa << 9); |
| 753 | MCHBAR32(0x6c0) = (MCHBAR32(0x6c0) & ~0xffffff00) | reg32; |
| 754 | MCHBAR8(0x6c4) = (MCHBAR8(0x6c4) & ~0x7) | 0x2; |
| 755 | } |
| 756 | |
| 757 | static void dll_ddr2(struct sysinfo *s) |
| 758 | { |
| 759 | u8 i, j, r, reg8, clk, async; |
| 760 | u16 reg16 = 0; |
| 761 | u32 reg32 = 0; |
| 762 | u8 lane; |
| 763 | |
| 764 | MCHBAR16(0x180) = (MCHBAR16(0x180) & ~0x7e06) | 0xc04; |
| 765 | MCHBAR16(0x182) = (MCHBAR16(0x182) & ~0x3ff) | 0xc8; |
| 766 | MCHBAR16(0x18a) = (MCHBAR16(0x18a) & ~0x1f1f) | 0x0f0f; |
| 767 | MCHBAR16(0x1b4) = (MCHBAR16(0x1b4) & ~0x8020) | 0x100; |
| 768 | MCHBAR8(0x194) = (MCHBAR8(0x194) & ~0x77) | 0x33; |
| 769 | switch (s->selected_timings.mem_clk) { |
| 770 | default: |
| 771 | case MEM_CLOCK_667MHz: |
| 772 | reg16 = (0xa << 9) | 0xa; |
| 773 | break; |
| 774 | case MEM_CLOCK_800MHz: |
| 775 | reg16 = (0x9 << 9) | 0x9; |
| 776 | break; |
| 777 | } |
| 778 | MCHBAR16(0x19c) = (MCHBAR16(0x19c) & ~0x1e0f) | reg16; |
| 779 | MCHBAR16(0x19c) = (MCHBAR16(0x19c) & ~0x2030) | 0x2010; |
| 780 | udelay(1); |
| 781 | MCHBAR16(0x198) = MCHBAR16(0x198) & ~0x100; |
| 782 | |
| 783 | MCHBAR16(0x1c8) = (MCHBAR16(0x1c8) & ~0x1f) | 0xd; |
| 784 | |
| 785 | udelay(1); |
| 786 | MCHBAR8(0x190) = MCHBAR8(0x190) & ~1; |
| 787 | udelay(1); // 533ns |
| 788 | MCHBAR32(0x198) = MCHBAR32(0x198) & ~0x11554000; |
| 789 | udelay(1); |
| 790 | MCHBAR32(0x198) = MCHBAR32(0x198) & ~0x1455; |
| 791 | udelay(1); |
| 792 | MCHBAR8(0x583) = MCHBAR8(0x583) & ~0x1c; |
| 793 | MCHBAR8(0x983) = MCHBAR8(0x983) & ~0x1c; |
| 794 | udelay(1); // 533ns |
| 795 | MCHBAR8(0x583) = MCHBAR8(0x583) & ~0x3; |
| 796 | MCHBAR8(0x983) = MCHBAR8(0x983) & ~0x3; |
| 797 | udelay(1); // 533ns |
| 798 | |
| 799 | // ME related |
| 800 | MCHBAR32(0x1a0) = (MCHBAR32(0x1a0) & ~0x7ffffff) | 0x551803; |
| 801 | |
| 802 | MCHBAR16(0x1b4) = MCHBAR16(0x1b4) & ~0x800; |
| 803 | MCHBAR8(0x1a8) = MCHBAR8(0x1a8) | 0xf0; |
| 804 | |
| 805 | FOR_EACH_CHANNEL(i) { |
| 806 | reg16 = 0; |
| 807 | MCHBAR16(0x400*i + 0x59c) = MCHBAR16(0x400*i + 0x59c) & ~0x3000; |
| 808 | |
| 809 | reg32 = 0; |
| 810 | FOR_EACH_RANK_IN_CHANNEL(r) if (!RANK_IS_POPULATED(s->dimms, i, r)) { |
| 811 | reg32 |= 0x111 << r; |
| 812 | } |
| 813 | MCHBAR32(0x400*i + 0x59c) = (MCHBAR32(0x400*i + 0x59c) & ~0xfff) | reg32; |
| 814 | MCHBAR8(0x400*i + 0x594) = MCHBAR8(0x400*i + 0x594) & ~1; |
| 815 | |
| 816 | if (!CHANNEL_IS_POPULATED(s->dimms, i)) { |
| 817 | printk(BIOS_DEBUG, "No dimms in channel %d\n", i); |
| 818 | reg8 = 0x3f; |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 819 | } else if (ONLY_DIMMA_IS_POPULATED(s->dimms, i)) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 820 | printk(BIOS_DEBUG, "DimmA populated only in channel %d\n", i); |
| 821 | reg8 = 0x38; |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 822 | } else if (ONLY_DIMMB_IS_POPULATED(s->dimms, i)) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 823 | printk(BIOS_DEBUG, "DimmB populated only in channel %d\n", i); |
| 824 | reg8 = 0x7; |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 825 | } else if (BOTH_DIMMS_ARE_POPULATED(s->dimms, i)) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 826 | printk(BIOS_DEBUG, "Both dimms populated in channel %d\n", i); |
| 827 | reg8 = 0; |
| 828 | } else { |
| 829 | die("Unhandled case\n"); |
| 830 | } |
| 831 | |
Martin Roth | 128c104 | 2016-11-18 09:29:03 -0700 | [diff] [blame] | 832 | //reg8 = 0x00; // FIXME don't switch on all clocks anyway |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 833 | |
| 834 | MCHBAR32(0x400*i + 0x5a0) = (MCHBAR32(0x400*i + 0x5a0) & ~0x3f000000) | |
| 835 | ((u32)(reg8 << 24)); |
| 836 | } // END EACH CHANNEL |
| 837 | |
| 838 | MCHBAR8(0x1a8) = MCHBAR8(0x1a8) | 1; |
| 839 | MCHBAR8(0x1a8) = MCHBAR8(0x1a8) & ~0x4; |
| 840 | |
| 841 | // Update DLL timing |
| 842 | MCHBAR8(0x1a4) = MCHBAR8(0x1a4) & ~0x80; |
| 843 | MCHBAR8(0x1a4) = MCHBAR8(0x1a4) | 0x40; |
| 844 | MCHBAR16(0x5f0) = (MCHBAR16(0x5f0) & ~0x400) | 0x400; |
| 845 | |
| 846 | u8 dll_setting_667[23][5] = { |
| 847 | // tap pi db delay |
| 848 | {13, 0, 1,0, 0}, |
| 849 | {4, 1, 0,0, 0}, |
| 850 | {13, 0, 1,0, 0}, |
| 851 | {4, 5, 0,0, 0}, |
| 852 | {4, 1, 0,0, 0}, |
| 853 | {4, 1, 0,0, 0}, |
| 854 | {4, 1, 0,0, 0}, |
| 855 | {1, 5, 1,1, 1}, |
| 856 | {1, 6, 1,1, 1}, |
| 857 | {2, 0, 1,1, 1}, |
| 858 | {2, 1, 1,1, 1}, |
| 859 | {2, 1, 1,1, 1}, |
| 860 | {14, 6, 1,0, 0}, |
| 861 | {14, 3, 1,0, 0}, |
| 862 | {14, 0, 1,0, 0}, |
| 863 | {9, 0, 0,0, 1}, |
| 864 | {9, 1, 0,0, 1}, |
| 865 | {9, 2, 0,0, 1}, |
| 866 | {9, 2, 0,0, 1}, |
| 867 | {9, 1, 0,0, 1}, |
| 868 | {6, 4, 0,0, 1}, |
| 869 | {6, 2, 0,0, 1}, |
| 870 | {5, 4, 0,0, 1} |
| 871 | }; |
| 872 | |
| 873 | u8 dll_setting_800[23][5] = { |
| 874 | // tap pi db delay |
| 875 | {11, 5, 1,0, 0}, |
| 876 | {0, 5, 1,1, 0}, |
| 877 | {11, 5, 1,0, 0}, |
| 878 | {1, 4, 1,1, 0}, |
| 879 | {0, 5, 1,1, 0}, |
| 880 | {0, 5, 1,1, 0}, |
| 881 | {0, 5, 1,1, 0}, |
| 882 | {2, 5, 1,1, 1}, |
| 883 | {2, 6, 1,1, 1}, |
| 884 | {3, 0, 1,1, 1}, |
| 885 | {3, 0, 1,1, 1}, |
| 886 | {3, 3, 1,1, 1}, |
| 887 | {2, 0, 1,1, 1}, |
| 888 | {1, 3, 1,1, 1}, |
| 889 | {0, 3, 1,1, 1}, |
| 890 | {9, 3, 0,0, 1}, |
| 891 | {9, 4, 0,0, 1}, |
| 892 | {9, 5, 0,0, 1}, |
| 893 | {9, 6, 0,0, 1}, |
| 894 | {10, 0, 0,0, 1}, |
| 895 | {8, 1, 0,0, 1}, |
| 896 | {7, 5, 0,0, 1}, |
| 897 | {6, 2, 0,0, 1} |
| 898 | }; |
| 899 | |
| 900 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
| 901 | MCHBAR16(0x400*i + 0x5f0) = (MCHBAR16(0x400*i + 0x5f0) & ~0x3fc) | 0x3fc; |
| 902 | MCHBAR32(0x400*i + 0x5fc) = MCHBAR32(0x400*i + 0x5fc) & ~0xcccccccc; |
| 903 | MCHBAR8(0x400*i + 0x5d9) = (MCHBAR8(0x400*i + 0x5d9) & ~0xf0) | 0x70; |
| 904 | MCHBAR16(0x400*i + 0x590) = (MCHBAR16(0x400*i + 0x590) & ~0xffff) | 0x5555; |
| 905 | } |
| 906 | |
| 907 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
| 908 | if (s->selected_timings.mem_clk == MEM_CLOCK_667MHz) { |
| 909 | clkset0(i, &dll_setting_667[CLKSET0][0]); |
| 910 | clkset1(i, &dll_setting_667[CLKSET1][0]); |
| 911 | ctrlset0(i, &dll_setting_667[CTRL0][0]); |
| 912 | ctrlset1(i, &dll_setting_667[CTRL1][0]); |
| 913 | ctrlset2(i, &dll_setting_667[CTRL2][0]); |
| 914 | ctrlset3(i, &dll_setting_667[CTRL3][0]); |
| 915 | cmdset(i, &dll_setting_667[CMD][0]); |
| 916 | } else { |
| 917 | clkset0(i, &dll_setting_800[CLKSET0][0]); |
| 918 | clkset1(i, &dll_setting_800[CLKSET1][0]); |
| 919 | ctrlset0(i, &dll_setting_800[CTRL0][0]); |
| 920 | ctrlset1(i, &dll_setting_800[CTRL1][0]); |
| 921 | ctrlset2(i, &dll_setting_800[CTRL2][0]); |
| 922 | ctrlset3(i, &dll_setting_800[CTRL3][0]); |
| 923 | cmdset(i, &dll_setting_800[CMD][0]); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | // XXX if not async mode |
| 928 | MCHBAR16(0x180) = MCHBAR16(0x180) & ~0x8200; |
| 929 | MCHBAR8(0x180) = MCHBAR8(0x180) | 0x4; |
| 930 | j = 0; |
| 931 | for (i = 0; i < 16; i++) { |
| 932 | MCHBAR8(0x1c8) = (MCHBAR8(0x1c8) & ~0x1f) | i; |
| 933 | MCHBAR8(0x180) = MCHBAR8(0x180) | 0x10; |
| 934 | while (MCHBAR8(0x180) & 0x10); |
| 935 | if (MCHBAR32(0x184) == 0xffffffff) { |
| 936 | j++; |
| 937 | if (j >= 2) |
| 938 | break; |
| 939 | |
| 940 | if (s->selected_timings.mem_clk == MEM_CLOCK_667MHz) { |
| 941 | j = 2; |
| 942 | break; |
| 943 | } |
| 944 | } else { |
| 945 | j = 0; |
| 946 | } |
| 947 | } |
| 948 | if (i == 1 || ((i == 0) && s->selected_timings.mem_clk == MEM_CLOCK_667MHz)) { |
| 949 | j = 0; |
| 950 | i++; |
| 951 | for (; i < 16; i++) { |
| 952 | MCHBAR8(0x1c8) = (MCHBAR8(0x1c8) & ~0x1f) | i; |
| 953 | MCHBAR8(0x180) = MCHBAR8(0x180) | 0x4; |
| 954 | while (MCHBAR8(0x180) & 0x10); |
| 955 | if (MCHBAR32(0x184) == 0) { |
| 956 | i++; |
| 957 | break; |
| 958 | } |
| 959 | } |
| 960 | for (; i < 16; i++) { |
| 961 | MCHBAR8(0x1c8) = (MCHBAR8(0x1c8) & ~0x1f) | i; |
| 962 | MCHBAR8(0x180) = MCHBAR8(0x180) | 0x10; |
| 963 | while (MCHBAR8(0x180) & 0x10); |
| 964 | if (MCHBAR32(0x184) == 0xffffffff) { |
| 965 | j++; |
| 966 | if (j >= 2) |
| 967 | break; |
| 968 | } else { |
| 969 | j = 0; |
| 970 | } |
| 971 | } |
| 972 | if (j < 2) { |
| 973 | MCHBAR8(0x1c8) = MCHBAR8(0x1c8) & ~0x1f; |
| 974 | MCHBAR8(0x180) = MCHBAR8(0x180) | 0x10; |
| 975 | while (MCHBAR8(0x180) & 0x10); |
| 976 | j = 2; |
| 977 | } |
| 978 | } |
| 979 | |
| 980 | if (j < 2) { |
| 981 | MCHBAR8(0x1c8) = MCHBAR8(0x1c8) & ~0x1f; |
| 982 | async = 1; |
| 983 | } |
| 984 | |
| 985 | clk = 0x1a; |
| 986 | if (async != 1) { |
| 987 | reg8 = MCHBAR8(0x188) & 0x1e; |
| 988 | if (s->selected_timings.mem_clk == MEM_CLOCK_667MHz && |
| 989 | s->selected_timings.fsb_clk == FSB_CLOCK_800MHz) { |
| 990 | clk = 0x10; |
| 991 | } else if (s->selected_timings.mem_clk == MEM_CLOCK_800MHz) { |
| 992 | clk = 0x10; |
| 993 | } else { |
| 994 | clk = 0x1a; |
| 995 | } |
| 996 | } |
| 997 | MCHBAR8(0x180) = MCHBAR8(0x180) & ~0x80; |
| 998 | |
| 999 | if ((s->selected_timings.fsb_clk == FSB_CLOCK_800MHz) && |
| 1000 | (s->selected_timings.mem_clk == MEM_CLOCK_667MHz)) { |
| 1001 | i = MCHBAR8(0x180) & 0xf; |
| 1002 | i = (i + 10) % 14; |
| 1003 | MCHBAR8(0x1c8) = (MCHBAR8(0x1c8) & ~0x1f) | i; |
| 1004 | MCHBAR8(0x180) = MCHBAR8(0x180) | 0x10; |
Elyes HAOUAS | 12df950 | 2016-08-23 21:29:48 +0200 | [diff] [blame] | 1005 | while (MCHBAR8(0x180) & 0x10); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | reg8 = MCHBAR8(0x188) & ~1; |
| 1009 | MCHBAR8(0x188) = reg8; |
| 1010 | reg8 &= ~0x3e; |
| 1011 | reg8 |= clk; |
| 1012 | MCHBAR8(0x188) = reg8; |
| 1013 | reg8 |= 1; |
| 1014 | MCHBAR8(0x188) = reg8; |
| 1015 | |
| 1016 | if (s->selected_timings.mem_clk == MEM_CLOCK_1333MHz) { |
| 1017 | MCHBAR8(0x18c) = MCHBAR8(0x18c) | 1; |
| 1018 | } |
| 1019 | |
| 1020 | // Program DQ/DQS dll settings |
| 1021 | reg32 = 0; |
| 1022 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
| 1023 | for (lane = 0; lane < 8; lane++) { |
| 1024 | if (s->selected_timings.mem_clk == MEM_CLOCK_667MHz) { |
| 1025 | reg32 = 0x06db7777; |
| 1026 | } else if (s->selected_timings.mem_clk == MEM_CLOCK_800MHz) { |
| 1027 | reg32 = 0x00007777; |
| 1028 | } |
| 1029 | MCHBAR32(0x400*i + 0x540 + lane*4) = |
| 1030 | (MCHBAR32(0x400*i + 0x540 + lane*4) & 0x0fffffff) | |
| 1031 | reg32; |
| 1032 | } |
| 1033 | } |
| 1034 | |
| 1035 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
| 1036 | if (s->selected_timings.mem_clk == MEM_CLOCK_667MHz) { |
| 1037 | for (lane = 0; lane < 8; lane++) { |
| 1038 | dqsset(i, lane, &dll_setting_667[DQS1+lane][0]); |
| 1039 | } |
| 1040 | for (lane = 0; lane < 8; lane++) { |
| 1041 | dqset(i, lane, &dll_setting_667[DQ1+lane][0]); |
| 1042 | } |
| 1043 | } else { |
| 1044 | for (lane = 0; lane < 8; lane++) { |
| 1045 | dqsset(i, lane, &dll_setting_800[DQS1+lane][0]); |
| 1046 | } |
| 1047 | for (lane = 0; lane < 8; lane++) { |
| 1048 | dqset(i, lane, &dll_setting_800[DQ1+lane][0]); |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | static void rcomp_ddr2(struct sysinfo *s) |
| 1055 | { |
| 1056 | u8 i, j, k; |
| 1057 | u32 x32a[8] = { 0x04040404, 0x06050505, 0x09090807, 0x0D0C0B0A, 0x04040404, 0x08070605, 0x0C0B0A09, 0x100F0E0D }; |
| 1058 | u16 x378[6] = { 0, 0xAAAA, 0x7777, 0x7777, 0x7777, 0x7777 }; |
| 1059 | u32 x382[6] = { 0, 0x02020202, 0x02020202, 0x02020202, 0x04030303, 0x04030303 }; |
| 1060 | u32 x386[6] = { 0, 0x03020202, 0x03020202, 0x03020202, 0x05040404, 0x05040404 }; |
| 1061 | u32 x38a[6] = { 0, 0x04040303, 0x04040303, 0x04040303, 0x07070605, 0x07070605 }; |
| 1062 | u32 x38e[6] = { 0, 0x06060505, 0x06060505, 0x06060505, 0x09090808, 0x09090808 }; |
| 1063 | u32 x392[6] = { 0, 0x02020202, 0x02020202, 0x02020202, 0x03030202, 0x03030202 }; |
| 1064 | u32 x396[6] = { 0, 0x03030202, 0x03030202, 0x03030202, 0x05040303, 0x05040303 }; |
| 1065 | u32 x39a[6] = { 0, 0x04040403, 0x04040403, 0x04040403, 0x07070605, 0x07070605 }; |
| 1066 | u32 x39e[6] = { 0, 0x06060505, 0x06060505, 0x06060505, 0x08080808, 0x08080808 }; |
| 1067 | u16 addr[6] = { 0x31c, 0x374, 0x3a2, 0x3d0, 0x3fe, 0x42c }; |
| 1068 | u8 bit[6] = { 0, 0, 1, 1, 0, 0 }; |
| 1069 | |
| 1070 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
| 1071 | for (j = 0; j < 6; j++) { |
| 1072 | if (j == 0) { |
| 1073 | MCHBAR32(0x400*i + addr[j]) = |
| 1074 | (MCHBAR32(0x400*i + addr[j]) & ~0xff000) | 0xaa000; |
| 1075 | MCHBAR16(0x400*i + 0x320) = (MCHBAR16(0x400*i + 0x320) & ~0xffff) | 0x6666; |
| 1076 | for (k = 0; k < 8; k++) { |
| 1077 | MCHBAR32(0x400*i + addr[j] + 0xe + (k << 2)) = |
| 1078 | (MCHBAR32(0x400*i + addr[j] + 0xe + (k << 2)) & ~0x3f3f3f3f) | x32a[k]; |
| 1079 | MCHBAR32(0x400*i + addr[j] + 0x2e + (k << 2)) = |
| 1080 | (MCHBAR32(0x400*i + addr[j] + 0x2e + (k << 2)) & ~0x3f3f3f3f) | x32a[k]; |
| 1081 | } |
| 1082 | } else { |
| 1083 | MCHBAR16(0x400*i + addr[j]) = (MCHBAR16(0x400*i + addr[j]) & ~0xf000) | 0xa000; |
| 1084 | MCHBAR16(0x400*i + addr[j] + 4) = (MCHBAR16(0x400*i + addr[j] + 4) & ~0xffff) | |
| 1085 | x378[j]; |
| 1086 | MCHBAR32(0x400*i + addr[j] + 0xe) = |
| 1087 | (MCHBAR32(0x400*i + addr[j] + 0xe) & ~0x3f3f3f3f) | x382[j]; |
| 1088 | MCHBAR32(0x400*i + addr[j] + 0x12) = |
| 1089 | (MCHBAR32(0x400*i + addr[j] + 0x12) & ~0x3f3f3f3f) | x386[j]; |
| 1090 | MCHBAR32(0x400*i + addr[j] + 0x16) = |
| 1091 | (MCHBAR32(0x400*i + addr[j] + 0x16) & ~0x3f3f3f3f) | x38a[j]; |
| 1092 | MCHBAR32(0x400*i + addr[j] + 0x1a) = |
| 1093 | (MCHBAR32(0x400*i + addr[j] + 0x1a) & ~0x3f3f3f3f) | x38e[j]; |
| 1094 | MCHBAR32(0x400*i + addr[j] + 0x1e) = |
| 1095 | (MCHBAR32(0x400*i + addr[j] + 0x1e) & ~0x3f3f3f3f) | x392[j]; |
| 1096 | MCHBAR32(0x400*i + addr[j] + 0x22) = |
| 1097 | (MCHBAR32(0x400*i + addr[j] + 0x22) & ~0x3f3f3f3f) | x396[j]; |
| 1098 | MCHBAR32(0x400*i + addr[j] + 0x26) = |
| 1099 | (MCHBAR32(0x400*i + addr[j] + 0x26) & ~0x3f3f3f3f) | x39a[j]; |
| 1100 | MCHBAR32(0x400*i + addr[j] + 0x2a) = |
| 1101 | (MCHBAR32(0x400*i + addr[j] + 0x2a) & ~0x3f3f3f3f) | x39e[j]; |
| 1102 | } |
| 1103 | MCHBAR8(0x400*i + addr[j]) = (MCHBAR8(0x400*i + addr[j]) & ~1) | bit[j]; |
| 1104 | } |
| 1105 | MCHBAR8(0x400*i + 0x45a) = (MCHBAR8(0x400*i + 0x45a) & ~0x3f) | 0x12; |
| 1106 | MCHBAR8(0x400*i + 0x45e) = (MCHBAR8(0x400*i + 0x45e) & ~0x3f) | 0x12; |
| 1107 | MCHBAR8(0x400*i + 0x462) = (MCHBAR8(0x400*i + 0x462) & ~0x3f) | 0x12; |
| 1108 | MCHBAR8(0x400*i + 0x466) = (MCHBAR8(0x400*i + 0x466) & ~0x3f) | 0x12; |
| 1109 | } // END EACH POPULATED CHANNEL |
| 1110 | |
| 1111 | MCHBAR32(0x134) = (MCHBAR32(0x134) & ~0x63c00) | 0x63c00; |
| 1112 | MCHBAR16(0x174) = (MCHBAR16(0x174) & ~0x63ff) | 0x63ff; |
| 1113 | MCHBAR16(0x178) = 0x0135; |
| 1114 | MCHBAR32(0x130) = (MCHBAR32(0x130) & ~0x7bdffe0) | 0x7a9ffa0; |
| 1115 | |
| 1116 | if (!CHANNEL_IS_POPULATED(s->dimms, 0)) { |
| 1117 | MCHBAR32(0x130) = MCHBAR32(0x130) & ~(1 << 27); |
| 1118 | } |
| 1119 | if (!CHANNEL_IS_POPULATED(s->dimms, 1)) { |
| 1120 | MCHBAR32(0x130) = MCHBAR32(0x130) & ~(1 << 28); |
| 1121 | } |
| 1122 | |
| 1123 | MCHBAR8(0x130) = MCHBAR8(0x130) | 1; |
| 1124 | } |
| 1125 | |
| 1126 | static void odt_ddr2(struct sysinfo *s) |
| 1127 | { |
| 1128 | u8 i; |
| 1129 | u16 odt[16][2] = { |
| 1130 | { 0x0000,0x0000 }, // NC_NC |
| 1131 | { 0x0000,0x0001 }, // x8SS_NC |
| 1132 | { 0x0000,0x0011 }, // x8DS_NC |
| 1133 | { 0x0000,0x0001 }, // x16SS_NC |
| 1134 | { 0x0004,0x0000 }, // NC_x8SS |
| 1135 | { 0x0101,0x0404 }, // x8SS_x8SS |
| 1136 | { 0x0101,0x4444 }, // x8DS_x8SS |
| 1137 | { 0x0101,0x0404 }, // x16SS_x8SS |
| 1138 | { 0x0044,0x0000 }, // NC_x8DS |
| 1139 | { 0x1111,0x0404 }, // x8SS_x8DS |
| 1140 | { 0x1111,0x4444 }, // x8DS_x8DS |
| 1141 | { 0x1111,0x0404 }, // x16SS_x8DS |
| 1142 | { 0x0004,0x0000 }, // NC_x16SS |
| 1143 | { 0x0101,0x0404 }, // x8SS_x16SS |
| 1144 | { 0x0101,0x4444 }, // x8DS_x16SS |
| 1145 | { 0x0101,0x0404 }, // x16SS_x16SS |
| 1146 | }; |
| 1147 | |
| 1148 | FOR_EACH_POPULATED_CHANNEL(s->dimms, i) { |
| 1149 | MCHBAR16(0x400*i + 0x298) = odt[s->dimm_config[i]][1]; |
| 1150 | MCHBAR16(0x400*i + 0x294) = odt[s->dimm_config[i]][0]; |
| 1151 | MCHBAR16(0x400*i + 0x29c) = (MCHBAR16(0x400*i + 0x29c) & ~0xfff) | 0x66b; |
| 1152 | MCHBAR32(0x400*i + 0x260) = (MCHBAR32(0x400*i + 0x260) & ~0x70e3c00) | 0x3063c00; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | static void dojedec_ddr2(u8 r, u8 ch, u8 cmd, u16 val) |
| 1157 | { |
| 1158 | u32 addr = (ch << 29) | (r*0x08000000); |
| 1159 | volatile u32 rubbish; |
| 1160 | |
| 1161 | MCHBAR8(0x271) = (MCHBAR8(0x271) & ~0x3e) | cmd; |
| 1162 | MCHBAR8(0x671) = (MCHBAR8(0x671) & ~0x3e) | cmd; |
| 1163 | rubbish = read32((void*)((val<<3) | addr)); |
| 1164 | udelay(10); |
| 1165 | MCHBAR8(0x271) = (MCHBAR8(0x271) & ~0x3e) | NORMALOP_CMD; |
| 1166 | MCHBAR8(0x671) = (MCHBAR8(0x671) & ~0x3e) | NORMALOP_CMD; |
| 1167 | } |
| 1168 | |
| 1169 | static void jedec_ddr2(struct sysinfo *s) |
| 1170 | { |
| 1171 | u8 i; |
| 1172 | u16 mrsval, ch, r, v; |
| 1173 | |
| 1174 | u8 odt[16][4] = { |
| 1175 | {0x00, 0x00, 0x00, 0x00}, |
| 1176 | {0x01, 0x00, 0x00, 0x00}, |
| 1177 | {0x01, 0x01, 0x00, 0x00}, |
| 1178 | {0x01, 0x00, 0x00, 0x00}, |
| 1179 | {0x00, 0x00, 0x01, 0x00}, |
| 1180 | {0x11, 0x00, 0x11, 0x00}, |
| 1181 | {0x11, 0x11, 0x11, 0x00}, |
| 1182 | {0x11, 0x00, 0x11, 0x00}, |
| 1183 | {0x00, 0x00, 0x01, 0x01}, |
| 1184 | {0x11, 0x00, 0x11, 0x11}, |
| 1185 | {0x11, 0x11, 0x11, 0x11}, |
| 1186 | {0x11, 0x00, 0x11, 0x11}, |
| 1187 | {0x00, 0x00, 0x01, 0x00}, |
| 1188 | {0x11, 0x00, 0x11, 0x00}, |
| 1189 | {0x11, 0x11, 0x11, 0x00}, |
| 1190 | {0x11, 0x00, 0x11, 0x00} |
| 1191 | }; |
| 1192 | |
| 1193 | u16 jedec[12][2] = { |
| 1194 | {NOP_CMD, 0x0}, |
| 1195 | {PRECHARGE_CMD, 0x0}, |
| 1196 | {EMRS2_CMD, 0x0}, |
| 1197 | {EMRS3_CMD, 0x0}, |
| 1198 | {EMRS1_CMD, 0x0}, |
| 1199 | {MRS_CMD, 0x100}, // DLL Reset |
| 1200 | {PRECHARGE_CMD, 0x0}, |
| 1201 | {CBR_CMD, 0x0}, |
| 1202 | {CBR_CMD, 0x0}, |
| 1203 | {MRS_CMD, 0x0}, // DLL out of reset |
| 1204 | {EMRS1_CMD, 0x380}, // OCD calib default |
| 1205 | {EMRS1_CMD, 0x0} |
| 1206 | }; |
| 1207 | |
| 1208 | mrsval = (s->selected_timings.CAS << 4) | ((s->selected_timings.tWR - 1) << 9) | 0xb; |
| 1209 | |
| 1210 | printk(BIOS_DEBUG, "MRS...\n"); |
| 1211 | |
| 1212 | udelay(200); |
| 1213 | |
| 1214 | FOR_EACH_POPULATED_RANK(s->dimms, ch, r) { |
| 1215 | printk(BIOS_DEBUG, "CH%d: Found Rank %d\n", ch, r); |
| 1216 | for (i = 0; i < 12; i++) { |
| 1217 | v = jedec[i][1]; |
| 1218 | switch (jedec[i][0]) { |
| 1219 | case EMRS1_CMD: |
| 1220 | v |= (odt[s->dimm_config[ch]][r] << 2); |
| 1221 | break; |
| 1222 | case MRS_CMD: |
| 1223 | v |= mrsval; |
| 1224 | break; |
| 1225 | default: |
| 1226 | break; |
| 1227 | } |
| 1228 | dojedec_ddr2(r + ch*4, ch, jedec[i][0], v); |
| 1229 | udelay(1); |
| 1230 | //printk(BIOS_DEBUG, "Jedec step %d\n", i); |
| 1231 | } |
| 1232 | } |
| 1233 | printk(BIOS_DEBUG, "MRS done\n"); |
| 1234 | } |
| 1235 | |
| 1236 | static u8 sampledqs(u16 mchloc, u32 addr, u8 hilow, u8 repeat) |
| 1237 | { |
| 1238 | u8 dqsmatch = 1; |
| 1239 | volatile u32 strobe; |
| 1240 | |
| 1241 | while (repeat-- > 0) { |
| 1242 | MCHBAR8(0x5d8) = MCHBAR8(0x5d8) & ~0x2; |
| 1243 | udelay(2); |
| 1244 | MCHBAR8(0x5d8) = MCHBAR8(0x5d8) | 0x2; |
| 1245 | udelay(2); |
| 1246 | MCHBAR8(0x9d8) = MCHBAR8(0x9d8) & ~0x2; |
| 1247 | udelay(2); |
| 1248 | MCHBAR8(0x9d8) = MCHBAR8(0x9d8) | 0x2; |
| 1249 | udelay(2); |
| 1250 | barrier(); |
| 1251 | strobe = read32((u32 *)addr); |
| 1252 | barrier(); |
| 1253 | if (((MCHBAR32(mchloc) & 0x40) >> 6) != hilow) { |
| 1254 | dqsmatch = 0; |
| 1255 | } |
| 1256 | } |
| 1257 | return dqsmatch; |
| 1258 | } |
| 1259 | |
| 1260 | static void rcven_ddr2(struct sysinfo *s) |
| 1261 | { |
| 1262 | u8 i, reg8, ch, lane; |
| 1263 | u32 addr; |
| 1264 | u8 tap = 0; |
| 1265 | u8 savecc, savemedium, savetap, coarsecommon, medium; |
| 1266 | u8 lanecoarse[8] = {0}; |
| 1267 | u8 mincoarse = 0xff; |
| 1268 | u8 pitap[2][8]; |
| 1269 | u16 coarsectrl[2]; |
| 1270 | u16 coarsedelay[2]; |
| 1271 | u16 mediumphase[2]; |
| 1272 | u16 readdelay[2]; |
| 1273 | u16 mchbar; |
| 1274 | MCHBAR8(0x5d8) = MCHBAR8(0x5d8) & ~0xc; |
| 1275 | MCHBAR8(0x9d8) = MCHBAR8(0x9d8) & ~0xc; |
| 1276 | MCHBAR8(0x5dc) = MCHBAR8(0x5dc) & ~0x80; |
| 1277 | |
| 1278 | FOR_EACH_POPULATED_CHANNEL(s->dimms, ch) { |
| 1279 | addr = (ch << 29); |
| 1280 | for (i = 0; !RANK_IS_POPULATED(s->dimms, ch, i); i++) { |
| 1281 | addr += 128*1024*1024; |
| 1282 | } |
| 1283 | for (lane = 0; lane < 8; lane++) { |
| 1284 | printk(BIOS_DEBUG, "Channel %d, Lane %d addr=0x%08x\n", ch, lane, addr); |
| 1285 | coarsecommon = (s->selected_timings.CAS - 1); |
| 1286 | switch (lane) { |
| 1287 | case 0: case 1: medium = 0; break; |
| 1288 | case 2: case 3: medium = 1; break; |
| 1289 | case 4: case 5: medium = 2; break; |
| 1290 | case 6: case 7: medium = 3; break; |
| 1291 | default: medium = 0; break; |
| 1292 | } |
| 1293 | mchbar = 0x400*ch + 0x561 + (lane << 2); |
| 1294 | tap = 0; |
| 1295 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & ~0xf0000) | |
| 1296 | (coarsecommon << 16); |
| 1297 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & ~(3 << (lane*2))) | |
| 1298 | (medium << (lane*2)); |
| 1299 | MCHBAR8(0x400*ch + 0x560 + lane*4) = MCHBAR8(0x400*ch + 0x560 + lane*4) & ~0xf; |
| 1300 | MCHBAR8(0x400*ch + 0x560 + lane*4) = MCHBAR8(0x400*ch + 0x560 + lane*4) & ~0x70; |
| 1301 | savecc = coarsecommon; |
| 1302 | savemedium = medium; |
| 1303 | savetap = 0; |
| 1304 | |
| 1305 | MCHBAR16(0x400*ch + 0x588) = (MCHBAR16(0x400*ch + 0x588) & ~(3 << (lane*2))) | |
| 1306 | (1 << (lane*2)); |
| 1307 | |
| 1308 | printk(BIOS_DEBUG, "rcven 0.1 coarse=%d\n", coarsecommon); |
| 1309 | while (sampledqs(mchbar, addr, 1, 1) == 1) { |
| 1310 | if (medium < 3) { |
| 1311 | medium++; |
| 1312 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1313 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1314 | } else { |
| 1315 | medium = 0; |
| 1316 | coarsecommon++; |
| 1317 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & |
| 1318 | ~0xf0000) | (coarsecommon << 16); |
| 1319 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1320 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1321 | } |
| 1322 | if (coarsecommon > 16) { |
| 1323 | die("Coarse > 16: DQS tuning failed, halt\n"); |
| 1324 | break; |
| 1325 | } |
| 1326 | } |
| 1327 | printk(BIOS_DEBUG, " GOT IT (high -> low transition) coarse=%d medium=%d\n", coarsecommon, medium); |
| 1328 | |
| 1329 | savemedium = medium; |
| 1330 | savecc = coarsecommon; |
| 1331 | if (medium < 3) { |
| 1332 | medium++; |
| 1333 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1334 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1335 | } else { |
| 1336 | medium = 0; |
| 1337 | coarsecommon++; |
| 1338 | |
| 1339 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & ~0xf0000) | |
| 1340 | (coarsecommon << 16); |
| 1341 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & ~(3 << (lane*2))) | |
| 1342 | (medium << (lane*2)); |
| 1343 | } |
| 1344 | |
| 1345 | printk(BIOS_DEBUG, "rcven 0.2\n"); |
| 1346 | while (sampledqs(mchbar, addr, 0, 1) == 1) { |
| 1347 | savemedium = medium; |
| 1348 | savecc = coarsecommon; |
| 1349 | if (medium < 3) { |
| 1350 | medium++; |
| 1351 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1352 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1353 | } else { |
| 1354 | medium = 0; |
| 1355 | coarsecommon++; |
| 1356 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & |
| 1357 | ~0xf0000) | (coarsecommon << 16); |
| 1358 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1359 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1360 | } |
| 1361 | if (coarsecommon > 16) { |
| 1362 | die("Coarse DQS tuning 2 failed, halt\n"); |
| 1363 | break; |
| 1364 | } |
| 1365 | } |
| 1366 | printk(BIOS_DEBUG, " GOT IT (low -> high transition) coarse=%d medium=%d\n", coarsecommon, medium); |
| 1367 | |
| 1368 | |
| 1369 | coarsecommon = savecc; |
| 1370 | medium = savemedium; |
| 1371 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & |
| 1372 | ~0xf0000) | (coarsecommon << 16); |
| 1373 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1374 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1375 | |
| 1376 | printk(BIOS_DEBUG, "rcven 0.3\n"); |
| 1377 | tap = 0; |
| 1378 | while (sampledqs(mchbar, addr, 1, 1) == 0) { |
| 1379 | savetap = tap; |
| 1380 | tap++; |
| 1381 | if (tap > 14) { |
| 1382 | break; |
| 1383 | } |
| 1384 | MCHBAR8(0x400*ch + 0x560 + (lane*4)) = |
| 1385 | (MCHBAR8(0x400*ch + 0x560 + (lane*4)) & ~0xf) | tap; |
| 1386 | } |
| 1387 | |
| 1388 | tap = savetap; |
| 1389 | MCHBAR8(0x400*ch + 0x560 + (lane*4)) = |
| 1390 | (MCHBAR8(0x400*ch + 0x560 + (lane*4)) & ~0xf) | tap; |
| 1391 | MCHBAR8(0x400*ch + 0x560 + (lane*4)) = |
| 1392 | (MCHBAR8(0x400*ch + 0x560 + (lane*4)) & ~0x70) | 0x30; |
| 1393 | if (medium < 3) { |
| 1394 | medium++; |
| 1395 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1396 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1397 | } else { |
| 1398 | medium = 0; |
| 1399 | coarsecommon++; |
| 1400 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & |
| 1401 | ~0xf0000) | (coarsecommon << 16); |
| 1402 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1403 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1404 | } |
| 1405 | if (sampledqs(mchbar, addr, 1, 1) == 0) { |
| 1406 | die("Not at DQS high, doh\n"); |
| 1407 | } |
| 1408 | |
| 1409 | printk(BIOS_DEBUG, "rcven 0.4\n"); |
| 1410 | while (sampledqs(mchbar, addr, 1, 1) == 1) { |
| 1411 | coarsecommon--; |
| 1412 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & |
| 1413 | ~0xf0000) | (coarsecommon << 16); |
| 1414 | if (coarsecommon == 0) { |
| 1415 | die("Couldn't find DQS-high 0 indicator, halt\n"); |
| 1416 | break; |
| 1417 | } |
| 1418 | } |
| 1419 | printk(BIOS_DEBUG, " GOT IT (high -> low transition) coarse=%d medium=%d\n", coarsecommon, medium); |
| 1420 | |
| 1421 | printk(BIOS_DEBUG, "rcven 0.5\n"); |
| 1422 | while (sampledqs(mchbar, addr, 0, 1) == 1) { |
| 1423 | savemedium = medium; |
| 1424 | savecc = coarsecommon; |
| 1425 | if (medium < 3) { |
| 1426 | medium++; |
| 1427 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1428 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1429 | } else { |
| 1430 | medium = 0; |
| 1431 | coarsecommon++; |
| 1432 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & |
| 1433 | ~0xf0000) | (coarsecommon << 16); |
| 1434 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1435 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1436 | } |
| 1437 | if (coarsecommon > 16) { |
| 1438 | die("Coarse DQS tuning 5 failed, halt\n"); |
| 1439 | break; |
| 1440 | } |
| 1441 | } |
| 1442 | printk(BIOS_DEBUG, " GOT IT (low -> high transition) coarse=%d medium=%d\n", coarsecommon, medium); |
| 1443 | |
| 1444 | printk(BIOS_DEBUG, "rcven 0.6\n"); |
| 1445 | coarsecommon = savecc; |
| 1446 | medium = savemedium; |
| 1447 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & |
| 1448 | ~0xf0000) | (coarsecommon << 16); |
| 1449 | MCHBAR16(0x400*ch + 0x58c) = (MCHBAR16(0x400*ch + 0x58c) & |
| 1450 | ~(3 << (lane*2))) | (medium << (lane*2)); |
| 1451 | while (sampledqs(mchbar, addr, 1, 1) == 0) { |
| 1452 | savetap = tap; |
| 1453 | tap++; |
| 1454 | if (tap > 14) { |
| 1455 | break; |
| 1456 | } |
| 1457 | MCHBAR8(0x400*ch + 0x560 + lane*4) = |
| 1458 | (MCHBAR8(0x400*ch + 0x560 + lane*4) & ~0xf) | tap; |
| 1459 | } |
| 1460 | tap = savetap; |
| 1461 | MCHBAR8(0x400*ch + 0x560 + lane*4) = |
| 1462 | (MCHBAR8(0x400*ch + 0x560 + lane*4) & ~0xf) | tap; |
| 1463 | MCHBAR8(0x400*ch + 0x560 + lane*4) = |
| 1464 | (MCHBAR8(0x400*ch + 0x560 + lane*4) & ~0x70) | 0x70; |
| 1465 | |
| 1466 | pitap[ch][lane] = 0x70 | tap; |
| 1467 | |
| 1468 | MCHBAR16(0x400*ch + 0x588) = MCHBAR16(0x400*ch + 0x588) & ~(3 << (lane*2)); |
| 1469 | lanecoarse[lane] = coarsecommon; |
| 1470 | printk(BIOS_DEBUG, "rcven 0.7\n"); |
| 1471 | } // END EACH LANE |
| 1472 | |
| 1473 | // Find minimum coarse value |
| 1474 | for (lane = 0; lane < 8; lane++) { |
| 1475 | if (mincoarse > lanecoarse[lane]) { |
| 1476 | mincoarse = lanecoarse[lane]; |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | printk(BIOS_DEBUG, "Found min coarse value = %d\n", mincoarse); |
| 1481 | |
| 1482 | for (lane = 0; lane < 8; lane++) { |
| 1483 | reg8 = (lanecoarse[lane] == 0) ? 0 : lanecoarse[lane] - mincoarse; |
| 1484 | MCHBAR16(0x400*ch + 0x5fa) = (MCHBAR16(0x400*ch + 0x5fa) & ~(3 << (lane*2))) | |
| 1485 | (reg8 << (lane*2)); |
| 1486 | } |
| 1487 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & ~0xf0000) | (mincoarse << 16); |
| 1488 | coarsectrl[ch] = mincoarse; |
| 1489 | coarsedelay[ch] = MCHBAR16(0x400*ch + 0x5fa); |
| 1490 | mediumphase[ch] = MCHBAR16(0x400*ch + 0x58c); |
| 1491 | readdelay[ch] = MCHBAR16(0x400*ch + 0x588); |
| 1492 | } // END EACH POPULATED CHANNEL |
| 1493 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1494 | FOR_EACH_CHANNEL(ch) { |
| 1495 | for (lane = 0; lane < 8; lane++) { |
| 1496 | MCHBAR8(0x400*ch + 0x560 + (lane*4)) = |
| 1497 | (MCHBAR8(0x400*ch + 0x560 + (lane*4)) & ~0xf) | pitap[ch][lane]; |
| 1498 | } |
| 1499 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & ~0xf0000) | |
| 1500 | (coarsectrl[ch] << 16); |
| 1501 | MCHBAR16(0x400*ch + 0x5fa) = coarsedelay[ch]; |
| 1502 | MCHBAR16(0x400*ch + 0x58c) = mediumphase[ch]; |
| 1503 | } |
| 1504 | printk(BIOS_DEBUG, "End rcven\n"); |
| 1505 | } |
| 1506 | |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1507 | static void sdram_save_receive_enable(void) |
| 1508 | { |
| 1509 | int i = 0; |
| 1510 | u16 reg16; |
| 1511 | u8 values[18]; |
| 1512 | u8 lane, ch; |
| 1513 | |
| 1514 | FOR_EACH_CHANNEL(ch) { |
| 1515 | lane = 0; |
| 1516 | while (lane < 8) { |
| 1517 | values[i] = (MCHBAR8(0x400*ch + 0x560 + lane++ * 4) & 0xf); |
| 1518 | values[i++] |= (MCHBAR8(0x400*ch + 0x560 + lane++ * 4) & 0xf) << 4; |
| 1519 | } |
| 1520 | values[i++] = (MCHBAR32(0x400*ch + 0x248) >> 16) & 0xf; |
| 1521 | reg16 = MCHBAR16(0x400*ch + 0x5fa); |
| 1522 | values[i++] = reg16 & 0xff; |
| 1523 | values[i++] = (reg16 >> 8) & 0xff; |
| 1524 | reg16 = MCHBAR16(0x400*ch + 0x58c); |
| 1525 | values[i++] = reg16 & 0xff; |
| 1526 | values[i++] = (reg16 >> 8) & 0xff; |
| 1527 | } |
| 1528 | |
| 1529 | for (i = 0; i < ARRAY_SIZE(values); i++) |
| 1530 | cmos_write(values[i], 128 + i); |
| 1531 | } |
| 1532 | |
| 1533 | static void sdram_recover_receive_enable(void) |
| 1534 | { |
| 1535 | u8 i; |
| 1536 | u32 reg32; |
| 1537 | u16 reg16; |
| 1538 | u8 values[18]; |
| 1539 | u8 ch, lane; |
| 1540 | |
| 1541 | for (i = 0; i < ARRAY_SIZE(values); i++) |
| 1542 | values[i] = cmos_read(128 + i); |
| 1543 | |
| 1544 | i = 0; |
| 1545 | FOR_EACH_CHANNEL(ch) { |
| 1546 | lane = 0; |
| 1547 | while (lane < 8) { |
| 1548 | MCHBAR8(0x400*ch + 0x560 + lane++ * 4) = 0x70 | |
| 1549 | (values[i] & 0xf); |
| 1550 | MCHBAR8(0x400*ch + 0x560 + lane++ * 4) = 0x70 | |
| 1551 | ((values[i++] >> 4) & 0xf); |
| 1552 | } |
| 1553 | reg32 = (MCHBAR32(0x400*ch + 0x248) & ~0xf0000) |
| 1554 | | ((values[i++] & 0xf) << 16); |
| 1555 | MCHBAR32(0x400*ch + 0x248) = reg32; |
| 1556 | reg16 = values[i++]; |
| 1557 | reg16 |= values[i++] << 8; |
| 1558 | MCHBAR16(0x400*ch + 0x5fa) = reg16; |
| 1559 | reg16 = values[i++]; |
| 1560 | reg16 |= values[i++] << 8; |
| 1561 | MCHBAR16(0x400*ch + 0x58c) = reg16; |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | static void sdram_program_receive_enable(struct sysinfo *s) |
| 1566 | { |
| 1567 | /* enable upper CMOS */ |
| 1568 | RCBA32(0x3400) = (1 << 2); |
| 1569 | |
| 1570 | /* Program Receive Enable Timings */ |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 1571 | if ((s->boot_path == BOOT_PATH_WARM_RESET) |
| 1572 | || (s->boot_path == BOOT_PATH_RESUME)) { |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1573 | sdram_recover_receive_enable(); |
| 1574 | } else { |
| 1575 | rcven_ddr2(s); |
| 1576 | sdram_save_receive_enable(); |
| 1577 | } |
| 1578 | } |
| 1579 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1580 | static void dradrb_ddr2(struct sysinfo *s) |
| 1581 | { |
| 1582 | u8 map, i, ch, r, rankpop0, rankpop1; |
| 1583 | u32 c0dra = 0; |
| 1584 | u32 c1dra = 0; |
| 1585 | u32 c0drb = 0; |
| 1586 | u32 c1drb = 0; |
| 1587 | u32 dra; |
| 1588 | u32 dra0; |
| 1589 | u32 dra1; |
| 1590 | u16 totalmemorymb; |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1591 | u32 size, offset; |
| 1592 | u32 size0, size1; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1593 | u8 dratab[2][2][2][4] = { |
| 1594 | { |
| 1595 | { |
| 1596 | {0xff, 0xff, 0xff, 0xff}, |
| 1597 | {0xff, 0x00, 0x02, 0xff} |
| 1598 | }, |
| 1599 | { |
| 1600 | {0xff, 0x01, 0xff, 0xff}, |
| 1601 | {0xff, 0x03, 0xff, 0xff} |
| 1602 | } |
| 1603 | }, |
| 1604 | { |
| 1605 | { |
| 1606 | {0xff, 0xff, 0xff, 0xff}, |
| 1607 | {0xff, 0x04, 0x06, 0x08} |
| 1608 | }, |
| 1609 | { |
| 1610 | {0xff, 0xff, 0xff, 0xff}, |
| 1611 | {0x05, 0x07, 0x09, 0xff} |
| 1612 | } |
| 1613 | } |
| 1614 | }; |
| 1615 | |
| 1616 | u8 drbtab[10] = {0x04, 0x02, 0x08, 0x04, 0x08, 0x04, 0x10, 0x08, 0x20, 0x10}; |
| 1617 | |
| 1618 | // DRA |
| 1619 | rankpop0 = 0; |
| 1620 | rankpop1 = 0; |
| 1621 | FOR_EACH_POPULATED_RANK(s->dimms, ch, r) { |
Damien Zammit | 68e1dcf | 2016-06-03 15:39:30 +1000 | [diff] [blame] | 1622 | if (((s->dimms[ch<<1].card_type != RAW_CARD_UNPOPULATED) && ((r) < s->dimms[ch<<1].ranks))) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1623 | i = ch << 1; |
| 1624 | } else { |
| 1625 | i = (ch << 1) + 1; |
| 1626 | } |
| 1627 | dra = dratab[s->dimms[i].banks] |
| 1628 | [s->dimms[i].width] |
| 1629 | [s->dimms[i].cols-9] |
| 1630 | [s->dimms[i].rows-12]; |
| 1631 | if (s->dimms[i].banks == 1) { |
| 1632 | dra |= 0x80; |
| 1633 | } |
| 1634 | if (ch == 0) { |
| 1635 | c0dra |= dra << (r*8); |
| 1636 | rankpop0 |= 1 << r; |
| 1637 | } else { |
| 1638 | c1dra |= dra << (r*8); |
| 1639 | rankpop1 |= 1 << r; |
| 1640 | } |
| 1641 | } |
| 1642 | MCHBAR32(0x208) = c0dra; |
| 1643 | MCHBAR32(0x608) = c1dra; |
| 1644 | |
| 1645 | MCHBAR8(0x262) = (MCHBAR8(0x262) & ~0xf0) | ((rankpop0 << 4) & 0xf0); |
| 1646 | MCHBAR8(0x662) = (MCHBAR8(0x662) & ~0xf0) | ((rankpop1 << 4) & 0xf0); |
| 1647 | |
| 1648 | if (ONLY_DIMMA_IS_POPULATED(s->dimms, 0) || ONLY_DIMMB_IS_POPULATED(s->dimms, 0)) { |
| 1649 | MCHBAR8(0x260) = MCHBAR8(0x260) | 1; |
| 1650 | } |
| 1651 | if (ONLY_DIMMA_IS_POPULATED(s->dimms, 1) || ONLY_DIMMB_IS_POPULATED(s->dimms, 1)) { |
| 1652 | MCHBAR8(0x660) = MCHBAR8(0x660) | 1; |
| 1653 | } |
| 1654 | |
| 1655 | // DRB |
| 1656 | FOR_EACH_POPULATED_RANK(s->dimms, ch, r) { |
Damien Zammit | 68e1dcf | 2016-06-03 15:39:30 +1000 | [diff] [blame] | 1657 | if (((s->dimms[ch<<1].card_type != RAW_CARD_UNPOPULATED) && ((r) < s->dimms[ch<<1].ranks))) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1658 | i = ch << 1; |
| 1659 | } else { |
| 1660 | i = (ch << 1) + 1; |
| 1661 | } |
| 1662 | if (ch == 0) { |
| 1663 | dra0 = (c0dra >> (8*r)) & 0x7f; |
| 1664 | c0drb = (u16)(c0drb + drbtab[dra0]); |
| 1665 | s->dimms[i].rank_capacity_mb = drbtab[dra0] << 6; |
| 1666 | MCHBAR16(0x200 + 2*r) = c0drb; |
| 1667 | } else { |
| 1668 | dra1 = (c1dra >> (8*r)) & 0x7f; |
| 1669 | c1drb = (u16)(c1drb + drbtab[dra1]); |
| 1670 | s->dimms[i].rank_capacity_mb = drbtab[dra1] << 6; |
| 1671 | MCHBAR16(0x600 + 2*r) = c1drb; |
| 1672 | } |
| 1673 | } |
| 1674 | |
| 1675 | s->channel_capacity[0] = c0drb << 6; |
| 1676 | s->channel_capacity[1] = c1drb << 6; |
| 1677 | totalmemorymb = s->channel_capacity[0] + s->channel_capacity[1]; |
| 1678 | printk(BIOS_DEBUG, "Total memory: %d + %d = %dMiB\n", |
| 1679 | s->channel_capacity[0], s->channel_capacity[1], totalmemorymb); |
| 1680 | |
| 1681 | rankpop1 >>= 4; |
| 1682 | if (rankpop1) { |
| 1683 | MCHBAR16(0x600 + 2*msbpos(rankpop1)) = c0drb + c1drb; |
| 1684 | MCHBAR16(0x602 + 2*msbpos(rankpop1)) = c0drb + c1drb; |
| 1685 | MCHBAR16(0x604 + 2*msbpos(rankpop1)) = c0drb + c1drb; |
| 1686 | MCHBAR16(0x606 + 2*msbpos(rankpop1)) = c0drb + c1drb; |
| 1687 | } |
| 1688 | |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1689 | /* Populated channel sizes in MiB */ |
| 1690 | size0 = s->channel_capacity[0]; |
| 1691 | size1 = s->channel_capacity[1]; |
| 1692 | |
| 1693 | MCHBAR8(0x111) = MCHBAR8(0x111) & ~0x2; |
| 1694 | MCHBAR8(0x111) = MCHBAR8(0x111) | (1 << 4); |
| 1695 | |
| 1696 | /* Set ME UMA size in MiB */ |
| 1697 | MCHBAR16(0x100) = ME_UMA_SIZEMB; |
| 1698 | |
| 1699 | /* Set ME UMA Present bit */ |
| 1700 | MCHBAR32(0x111) = MCHBAR32(0x111) | 1; |
| 1701 | |
| 1702 | size = MIN(size0 - ME_UMA_SIZEMB, size1) * 2; |
| 1703 | |
| 1704 | MCHBAR16(0x104) = size; |
| 1705 | MCHBAR16(0x102) = size0 + size1 - size; |
| 1706 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1707 | map = 0; |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1708 | if (size0 == 0) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1709 | map = 0; |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1710 | } else if (size1 == 0) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1711 | map |= 0x20; |
| 1712 | } else { |
| 1713 | map |= 0x40; |
| 1714 | } |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1715 | if (size == 0) { |
| 1716 | map |= 0x18; |
| 1717 | } |
| 1718 | |
| 1719 | if (size0 - ME_UMA_SIZEMB >= size1) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1720 | map |= 0x4; |
| 1721 | } |
| 1722 | MCHBAR8(0x110) = map; |
| 1723 | MCHBAR16(0x10e) = 0; |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1724 | |
| 1725 | if (size1 != 0) { |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1726 | offset = 0; |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1727 | } else if ((size0 > size1) && ((map & 0x7) == 0x4)) { |
| 1728 | offset = size/2 + (size0 + size1 - size); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1729 | } else { |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1730 | offset = size/2 + ME_UMA_SIZEMB; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1731 | } |
| 1732 | MCHBAR16(0x108) = offset; |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1733 | MCHBAR16(0x10a) = size/2; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | static void mmap_ddr2(struct sysinfo *s) |
| 1737 | { |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 1738 | bool reclaim; |
| 1739 | u32 gfxsize, gttsize, tsegsize, mmiosize, tom, tolud, touud; |
| 1740 | u32 gfxbase, gttbase, tsegbase, reclaimbase, reclaimlimit; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1741 | u16 ggc; |
Arthur Heymans | 27f94ee | 2016-06-18 21:08:58 +0200 | [diff] [blame] | 1742 | u16 ggc2uma[] = { 0, 1, 4, 8, 16, 32, 48, 64, 128, 256, 96, |
| 1743 | 160, 224, 352 }; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1744 | u8 ggc2gtt[] = { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4}; |
| 1745 | |
| 1746 | ggc = pci_read_config16(PCI_DEV(0,0,0), 0x52); |
| 1747 | gfxsize = ggc2uma[(ggc & 0xf0) >> 4]; |
| 1748 | gttsize = ggc2gtt[(ggc & 0xf00) >> 8]; |
| 1749 | tsegsize = 1; // 1MB TSEG |
Damien Zammit | 523e90f | 2016-09-05 02:32:40 +1000 | [diff] [blame] | 1750 | mmiosize = 0x800; // 2GB MMIO |
Damien Zammit | 9fb08f5 | 2016-01-22 18:56:23 +1100 | [diff] [blame] | 1751 | tom = s->channel_capacity[0] + s->channel_capacity[1] - ME_UMA_SIZEMB; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1752 | tolud = MIN(0x1000 - mmiosize, tom); |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 1753 | |
| 1754 | reclaim = false; |
| 1755 | if ((tom - tolud) > 0x40) |
| 1756 | reclaim = true; |
| 1757 | |
| 1758 | if (reclaim) { |
| 1759 | tolud = tolud & ~0x3f; |
| 1760 | tom = tom & ~0x3f; |
| 1761 | reclaimbase = MAX(0x1000, tom); |
| 1762 | reclaimlimit = reclaimbase + (MIN(0x1000, tom) - tolud) - 0x40; |
| 1763 | } |
| 1764 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1765 | touud = tom; |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 1766 | if (reclaim) |
| 1767 | touud = reclaimlimit + 0x40; |
| 1768 | |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1769 | gfxbase = tolud - gfxsize; |
| 1770 | gttbase = gfxbase - gttsize; |
| 1771 | tsegbase = gttbase - tsegsize; |
| 1772 | |
| 1773 | pci_write_config16(PCI_DEV(0,0,0), 0xb0, tolud << 4); |
| 1774 | pci_write_config16(PCI_DEV(0,0,0), 0xa0, tom >> 6); |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 1775 | if (reclaim) { |
| 1776 | pci_write_config16(PCI_DEV(0,0,0), 0x98, |
| 1777 | (u16)(reclaimbase >> 6)); |
| 1778 | pci_write_config16(PCI_DEV(0,0,0), 0x9a, |
| 1779 | (u16)(reclaimlimit >> 6)); |
| 1780 | } |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1781 | pci_write_config16(PCI_DEV(0,0,0), 0xa2, touud); |
| 1782 | pci_write_config32(PCI_DEV(0,0,0), 0xa4, gfxbase << 20); |
| 1783 | pci_write_config32(PCI_DEV(0,0,0), 0xa8, gttbase << 20); |
| 1784 | pci_write_config32(PCI_DEV(0,0,0), 0xac, tsegbase << 20); |
| 1785 | } |
| 1786 | |
| 1787 | static void enhanced_ddr2(struct sysinfo *s) |
| 1788 | { |
| 1789 | u8 ch, reg8; |
| 1790 | |
| 1791 | MCHBAR32(0xfb0) = 0x1000d024; |
| 1792 | MCHBAR32(0xfb4) = 0xc842; |
| 1793 | MCHBAR32(0xfbc) = 0xf; |
| 1794 | MCHBAR32(0xfc4) = 0xfe22244; |
| 1795 | MCHBAR8(0x12f) = 0x5c; |
| 1796 | MCHBAR8(0xfb0) = (MCHBAR8(0xfb0) & ~1) | 1; |
| 1797 | MCHBAR8(0x12f) = MCHBAR8(0x12f) | 0x2; |
| 1798 | MCHBAR8(0x6c0) = (MCHBAR8(0x6c0) & ~0xf0) | 0xa0; |
| 1799 | MCHBAR32(0xfa8) = 0x30d400; |
| 1800 | |
| 1801 | FOR_EACH_POPULATED_CHANNEL(s->dimms, ch) { |
| 1802 | MCHBAR8(0x400*ch + 0x26c) = MCHBAR8(0x400*ch + 0x26c) | 1; |
| 1803 | MCHBAR32(0x400*ch + 0x278) = 0x88141881; |
| 1804 | MCHBAR16(0x400*ch + 0x27c) = 0x0041; |
| 1805 | MCHBAR8(0x400*ch + 0x292) = 0xf2; |
| 1806 | MCHBAR16(0x400*ch + 0x272) = MCHBAR16(0x400*ch + 0x272) | 0x100; |
| 1807 | MCHBAR8(0x400*ch + 0x243) = (MCHBAR8(0x400*ch + 0x243) & ~0x2) | 1; |
| 1808 | MCHBAR32(0x400*ch + 0x288) = 0x8040200; |
| 1809 | MCHBAR32(0x400*ch + 0x28c) = 0xff402010; |
| 1810 | MCHBAR32(0x400*ch + 0x290) = 0x4f2091c; |
| 1811 | } |
| 1812 | |
| 1813 | reg8 = pci_read_config8(PCI_DEV(0,0,0), 0xf0); |
| 1814 | pci_write_config8(PCI_DEV(0,0,0), 0xf0, reg8 | 1); |
| 1815 | MCHBAR32(0xfa0) = (MCHBAR32(0xfa0) & ~0x20002) | 0x2; |
| 1816 | MCHBAR32(0xfa4) = (MCHBAR32(0xfa4) & ~0x219100c3) | 0x219100c2; |
| 1817 | MCHBAR32(0x2c) = 0x44a53; |
| 1818 | MCHBAR32(0x30) = 0x1f5a86; |
| 1819 | MCHBAR32(0x34) = 0x1902810; |
| 1820 | MCHBAR32(0x38) = 0xf7000000; |
| 1821 | MCHBAR32(0x3c) = 0x23014410; |
| 1822 | MCHBAR32(0x40) = (MCHBAR32(0x40) & ~0x8f038000) | 0x8f038000; |
| 1823 | MCHBAR32(0x20) = 0x33001; |
| 1824 | pci_write_config8(PCI_DEV(0,0,0), 0xf0, reg8 & ~1); |
| 1825 | } |
| 1826 | |
| 1827 | static void power_ddr2(struct sysinfo *s) |
| 1828 | { |
| 1829 | u32 reg1, reg2, reg3, reg4, clkgate, x592; |
| 1830 | u8 lane, ch; |
| 1831 | u8 twl = 0; |
| 1832 | u16 x264, x23c; |
| 1833 | |
| 1834 | twl = s->selected_timings.CAS - 1; |
| 1835 | x264 = 0x78; |
| 1836 | switch (s->selected_timings.mem_clk) { |
| 1837 | default: |
| 1838 | case MEM_CLOCK_667MHz: |
| 1839 | reg1 = 0x99; |
| 1840 | reg2 = 0x1048a9; |
| 1841 | clkgate = 0x230000; |
| 1842 | x23c = 0x7a89; |
| 1843 | break; |
| 1844 | case MEM_CLOCK_800MHz: |
| 1845 | if (s->selected_timings.CAS == 5) { |
| 1846 | reg1 = 0x19a; |
| 1847 | reg2 = 0x1048aa; |
| 1848 | } else { |
| 1849 | reg1 = 0x9a; |
| 1850 | reg2 = 0x2158aa; |
| 1851 | x264 = 0x89; |
| 1852 | } |
| 1853 | clkgate = 0x280000; |
| 1854 | x23c = 0x7b89; |
| 1855 | break; |
| 1856 | } |
| 1857 | reg3 = 0x232; |
| 1858 | reg4 = 0x2864; |
| 1859 | |
| 1860 | if (CHANNEL_IS_POPULATED(s->dimms, 0) && CHANNEL_IS_POPULATED(s->dimms, 1)) { |
| 1861 | MCHBAR32(0x14) = 0x0010461f; |
| 1862 | } else { |
| 1863 | MCHBAR32(0x14) = 0x0010691f; |
| 1864 | } |
| 1865 | MCHBAR32(0x18) = 0xdf6437f7; |
| 1866 | MCHBAR32(0x1c) = 0x0; |
| 1867 | MCHBAR32(0x24) = (MCHBAR32(0x24) & ~0xe0000000) | 0x30000000; |
| 1868 | MCHBAR32(0x44) = (MCHBAR32(0x44) & ~0x1fef0000) | 0x6b0000; |
| 1869 | MCHBAR16(0x115) = (u16) reg1; |
| 1870 | MCHBAR32(0x117) = (MCHBAR32(0x117) & ~0xffffff) | reg2; |
| 1871 | MCHBAR8(0x124) = 0x7; |
| 1872 | MCHBAR16(0x12a) = (MCHBAR16(0x12a) & 0) | 0x80; |
| 1873 | MCHBAR8(0x12c) = (MCHBAR8(0x12c) & 0) | 0xa0; |
| 1874 | MCHBAR16(0x174) = MCHBAR16(0x174) & ~(1 << 15); |
| 1875 | MCHBAR16(0x188) = (MCHBAR16(0x188) & ~0x1f00) | 0x1f00; |
| 1876 | MCHBAR8(0x18c) = MCHBAR8(0x18c) & ~0x8; |
| 1877 | MCHBAR8(0x192) = (MCHBAR8(0x192) & ~1) | 1; |
| 1878 | MCHBAR8(0x193) = (MCHBAR8(0x193) & ~0xf) | 0xf; |
| 1879 | MCHBAR16(0x1b4) = (MCHBAR16(0x1b4) & ~0x480) | 0x80; |
| 1880 | MCHBAR16(0x210) = (MCHBAR16(0x210) & ~0x1fff) | 0x3f; // | clockgatingiii |
| 1881 | MCHBAR32(0x6d1) = (MCHBAR32(0x6d1) & ~0xff03ff) | 0x100 | clkgate; |
| 1882 | MCHBAR8(0x212) = (MCHBAR8(0x212) & ~0x7f) | 0x7f; |
| 1883 | MCHBAR32(0x2c0) = (MCHBAR32(0x2c0) & ~0xffff0) | 0xcc5f0; |
| 1884 | MCHBAR8(0x2c4) = (MCHBAR8(0x2c4) & ~0x70) | 0x70; |
| 1885 | MCHBAR32(0x2d1) = (MCHBAR32(0x2d1) & ~0xffffff) | 0xff2831; // | clockgatingi |
| 1886 | MCHBAR32(0x2d4) = 0x40453600; |
| 1887 | MCHBAR32(0x300) = 0xc0b0a08; |
| 1888 | MCHBAR32(0x304) = 0x6040201; |
| 1889 | MCHBAR32(0x30c) = (MCHBAR32(0x30c) & ~0x43c0f) | 0x41405; |
| 1890 | MCHBAR16(0x610) = 0x232; |
| 1891 | MCHBAR16(0x612) = 0x2864; |
| 1892 | MCHBAR32(0x62c) = (MCHBAR32(0x62c) & ~0xc000000) | 0x4000000; |
| 1893 | MCHBAR32(0xae4) = 0; |
| 1894 | MCHBAR32(0xc00) = (MCHBAR32(0xc00) & ~0xf0000) | 0x10000; |
| 1895 | MCHBAR32(0xf00) = 0x393a3b3c; |
| 1896 | MCHBAR32(0xf04) = 0x3d3e3f40; |
| 1897 | MCHBAR32(0xf08) = 0x393a3b3c; |
| 1898 | MCHBAR32(0xf0c) = 0x3d3e3f40; |
| 1899 | MCHBAR32(0xf18) = MCHBAR32(0xf18) & ~0xfff00001; |
| 1900 | MCHBAR32(0xf48) = 0xfff0ffe0; |
| 1901 | MCHBAR32(0xf4c) = 0xffc0ff00; |
| 1902 | MCHBAR32(0xf50) = 0xfc00f000; |
| 1903 | MCHBAR32(0xf54) = 0xc0008000; |
| 1904 | MCHBAR32(0xf6c) = (MCHBAR32(0xf6c) & ~0xffff0000) | 0xffff0000; |
| 1905 | MCHBAR32(0xfac) = MCHBAR32(0xfac) & ~0x80000000; |
| 1906 | MCHBAR32(0xfb8) = MCHBAR32(0xfb8) & ~0xff000000; |
| 1907 | MCHBAR32(0xfbc) = (MCHBAR32(0xfbc) & ~0x7f800) | 0xf000; |
| 1908 | MCHBAR32(0x1104) = 0x3003232; |
| 1909 | MCHBAR32(0x1108) = 0x74; |
| 1910 | if (s->selected_timings.fsb_clk == FSB_CLOCK_800MHz) { |
| 1911 | MCHBAR32(0x110c) = 0xaa; |
| 1912 | } else { |
| 1913 | MCHBAR32(0x110c) = 0x100; |
| 1914 | } |
| 1915 | MCHBAR32(0x1110) = 0x10810350 & ~0x78; |
| 1916 | MCHBAR32(0x1114) = 0; |
| 1917 | if (s->selected_timings.mem_clk == MEM_CLOCK_667MHz) { |
| 1918 | twl = 5; |
| 1919 | } else { |
| 1920 | twl = 6; |
| 1921 | } |
| 1922 | x592 = 0xff; |
| 1923 | if (pci_read_config8(PCI_DEV(0,0,0), 0x8) < 3) { |
| 1924 | x592 = ~0x4; |
| 1925 | } |
| 1926 | FOR_EACH_POPULATED_CHANNEL(s->dimms, ch) { |
| 1927 | MCHBAR8(0x400*ch + 0x239) = twl + 15; |
| 1928 | MCHBAR16(0x400*ch + 0x23c) = x23c; |
| 1929 | MCHBAR32(0x400*ch + 0x248) = (MCHBAR32(0x400*ch + 0x248) & ~0x706033) | 0x406033; |
| 1930 | MCHBAR32(0x400*ch + 0x260) = (MCHBAR32(0x400*ch + 0x260) & ~(1 << 16)) | (1 << 16); |
| 1931 | MCHBAR8(0x400*ch + 0x264) = x264; |
| 1932 | MCHBAR8(0x400*ch + 0x592) = (MCHBAR8(0x400*ch + 0x592) & ~0x3f) | (0x3c & x592); |
| 1933 | MCHBAR8(0x400*ch + 0x593) = (MCHBAR8(0x400*ch + 0x593) & ~0x1f) | 0x1e; |
| 1934 | } |
| 1935 | |
| 1936 | for (lane = 0; lane < 8; lane++) { |
| 1937 | MCHBAR8(0x561 + (lane << 2)) = MCHBAR8(0x561 + (lane << 2)) & ~(1 << 3); |
| 1938 | } |
| 1939 | } |
| 1940 | |
| 1941 | void raminit_ddr2(struct sysinfo *s) |
| 1942 | { |
| 1943 | u8 ch; |
| 1944 | u8 r, bank; |
| 1945 | u32 reg32; |
| 1946 | |
| 1947 | // Select timings based on SPD info |
| 1948 | sdram_detect_smallest_params2(s); |
| 1949 | |
| 1950 | // Reset if required |
| 1951 | checkreset_ddr2(s); |
| 1952 | |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1953 | if (s->boot_path != BOOT_PATH_WARM_RESET) { |
| 1954 | // Clear self refresh |
| 1955 | MCHBAR32(PMSTS_MCHBAR) = MCHBAR32(PMSTS_MCHBAR) |
| 1956 | | PMSTS_BOTH_SELFREFRESH; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1957 | |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1958 | // Clear host clk gate reg |
| 1959 | MCHBAR32(0x1c) = MCHBAR32(0x1c) | 0xffffffff; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1960 | |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1961 | // Select DDR2 |
| 1962 | MCHBAR8(0x1a8) = MCHBAR8(0x1a8) & ~0x4; |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1963 | |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1964 | // Set freq |
| 1965 | MCHBAR32(0xc00) = (MCHBAR32(0xc00) & ~0x70) | |
| 1966 | (s->selected_timings.mem_clk << 4) | (1 << 10); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1967 | |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1968 | // Overwrite freq if chipset rejects it |
| 1969 | s->selected_timings.mem_clk = (MCHBAR8(0xc00) & 0x70) >> 4; |
| 1970 | if (s->selected_timings.mem_clk > (s->max_fsb + 3)) |
| 1971 | die("Error: DDR is faster than FSB, halt\n"); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | udelay(250000); |
| 1975 | |
| 1976 | // Program clock crossing |
| 1977 | clkcross_ddr2(s); |
| 1978 | printk(BIOS_DEBUG, "Done clk crossing\n"); |
| 1979 | |
| 1980 | // DDR2 IO |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1981 | if (s->boot_path != BOOT_PATH_WARM_RESET) { |
| 1982 | setioclk_ddr2(s); |
| 1983 | printk(BIOS_DEBUG, "Done I/O clk\n"); |
| 1984 | } |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 1985 | |
| 1986 | // Grant to launch |
| 1987 | launch_ddr2(s); |
| 1988 | printk(BIOS_DEBUG, "Done launch\n"); |
| 1989 | |
| 1990 | // Program DDR2 timings |
| 1991 | timings_ddr2(s); |
| 1992 | printk(BIOS_DEBUG, "Done timings\n"); |
| 1993 | |
| 1994 | // Program DLL |
| 1995 | dll_ddr2(s); |
| 1996 | |
| 1997 | // RCOMP |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 1998 | if (s->boot_path != BOOT_PATH_WARM_RESET) { |
| 1999 | rcomp_ddr2(s); |
| 2000 | printk(BIOS_DEBUG, "RCOMP\n"); |
| 2001 | } |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 2002 | |
| 2003 | // ODT |
| 2004 | odt_ddr2(s); |
| 2005 | printk(BIOS_DEBUG, "Done ODT\n"); |
| 2006 | |
| 2007 | // RCOMP update |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 2008 | if (s->boot_path != BOOT_PATH_WARM_RESET) { |
| 2009 | while ((MCHBAR8(0x130) & 1) != 0) |
| 2010 | ; |
| 2011 | printk(BIOS_DEBUG, "Done RCOMP update\n"); |
| 2012 | } |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 2013 | |
| 2014 | // Set defaults |
| 2015 | MCHBAR32(0x260) = (MCHBAR32(0x260) & ~1) | 0xf00000; |
| 2016 | MCHBAR32(0x660) = (MCHBAR32(0x660) & ~1) | 0xf00000; |
| 2017 | MCHBAR32(0x208) = 0x01010101; |
| 2018 | MCHBAR32(0x608) = 0x01010101; |
| 2019 | MCHBAR32(0x200) = 0x00040002; |
| 2020 | MCHBAR32(0x204) = 0x00080006; |
| 2021 | MCHBAR32(0x600) = 0x00040002; |
| 2022 | MCHBAR32(0x604) = 0x00100006; |
| 2023 | MCHBAR8(0x111) = MCHBAR8(0x111) | 0x2; |
| 2024 | MCHBAR32(0x104) = 0; |
| 2025 | MCHBAR16(0x102) = 0x400; |
| 2026 | MCHBAR8(0x100) = (2 << 5) | (3 << 3); |
| 2027 | MCHBAR16(0x10e) = 0; |
| 2028 | MCHBAR32(0x108) = 0; |
| 2029 | pci_write_config16(PCI_DEV(0,0,0), 0xb0, 0x4000); |
| 2030 | pci_write_config16(PCI_DEV(0,0,0), 0xa0, 0x0010); |
| 2031 | pci_write_config16(PCI_DEV(0,0,0), 0xa2, 0x0400); |
| 2032 | pci_write_config32(PCI_DEV(0,0,0), 0xa4, 0x40000000); |
| 2033 | pci_write_config32(PCI_DEV(0,0,0), 0xa8, 0x40000000); |
| 2034 | pci_write_config32(PCI_DEV(0,0,0), 0xac, 0x40000000); |
| 2035 | |
| 2036 | // IOBUFACT |
| 2037 | if (CHANNEL_IS_POPULATED(s->dimms, 0)) { |
| 2038 | MCHBAR8(0x5dd) = (MCHBAR8(0x5dd) & ~0x3f) | 0x3f; |
| 2039 | MCHBAR8(0x5d8) = MCHBAR8(0x5d8) | 0x7; |
| 2040 | } |
| 2041 | if (CHANNEL_IS_POPULATED(s->dimms, 1)) { |
| 2042 | if (pci_read_config8(PCI_DEV(0,0,0), 0x8) < 2) { |
| 2043 | MCHBAR8(0x5dd) = (MCHBAR8(0x5dd) & ~0x3f) | 0x3f; |
| 2044 | MCHBAR8(0x5d8) = MCHBAR8(0x5d8) | 1; |
| 2045 | } |
| 2046 | MCHBAR8(0x9dd) = (MCHBAR8(0x9dd) & ~0x3f) | 0x3f; |
| 2047 | MCHBAR8(0x9d8) = MCHBAR8(0x9d8) | 0x7; |
| 2048 | } |
| 2049 | |
| 2050 | // Pre jedec |
| 2051 | MCHBAR8(0x40) = MCHBAR8(0x40) | 0x2; |
| 2052 | FOR_EACH_POPULATED_CHANNEL(s->dimms, ch) { |
| 2053 | MCHBAR32(0x400*ch + 0x260) = MCHBAR32(0x400*ch + 0x260) | (1 << 27); |
| 2054 | } |
| 2055 | MCHBAR16(0x212) = (MCHBAR16(0x212) & ~0xf000) | 0xf000; |
| 2056 | MCHBAR16(0x212) = (MCHBAR16(0x212) & ~0xf00) | 0xf00; |
| 2057 | printk(BIOS_DEBUG, "Done pre-jedec\n"); |
| 2058 | |
| 2059 | // JEDEC reset |
Arthur Heymans | ef7e98a | 2016-12-30 21:07:18 +0100 | [diff] [blame] | 2060 | if (s->boot_path != BOOT_PATH_RESUME) |
| 2061 | jedec_ddr2(s); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 2062 | |
| 2063 | printk(BIOS_DEBUG, "Done jedec steps\n"); |
| 2064 | |
| 2065 | // After JEDEC reset |
| 2066 | MCHBAR8(0x40) = MCHBAR8(0x40) & ~0x2; |
| 2067 | FOR_EACH_POPULATED_CHANNEL(s->dimms, ch) { |
| 2068 | if (s->selected_timings.mem_clk == MEM_CLOCK_667MHz) { |
| 2069 | reg32 = (2 << 18) | (3 << 13) | (5 << 8); |
| 2070 | } else { |
| 2071 | reg32 = (2 << 18) | (3 << 13) | (4 << 8); |
| 2072 | } |
| 2073 | MCHBAR32(0x400*ch + 0x274) = (MCHBAR32(0x400*ch + 0x274) & ~0xfff00) | reg32; |
| 2074 | MCHBAR8(0x400*ch + 0x274) = MCHBAR8(0x400*ch + 0x274) & ~0x80; |
| 2075 | MCHBAR8(0x400*ch + 0x26c) = MCHBAR8(0x400*ch + 0x26c) | 1; |
| 2076 | MCHBAR32(0x400*ch + 0x278) = 0x88141881; |
| 2077 | MCHBAR16(0x400*ch + 0x27c) = 0x41; |
| 2078 | MCHBAR8(0x400*ch + 0x292) = 0xf2; |
| 2079 | MCHBAR8(0x400*ch + 0x271) = (MCHBAR8(0x400*ch + 0x271) & ~0xe) | 0xe; |
| 2080 | } |
| 2081 | MCHBAR8(0x2c4) = MCHBAR8(0x2c4) | 0x8; |
| 2082 | MCHBAR8(0x2c3) = MCHBAR8(0x2c3) | 0x40; |
| 2083 | MCHBAR8(0x2c4) = MCHBAR8(0x2c4) | 0x4; |
| 2084 | |
| 2085 | printk(BIOS_DEBUG, "Done post-jedec\n"); |
| 2086 | |
| 2087 | // Set DDR2 init complete |
| 2088 | FOR_EACH_POPULATED_CHANNEL(s->dimms, ch) { |
| 2089 | MCHBAR32(0x400*ch + 0x268) = (MCHBAR32(0x400*ch + 0x268) & ~0xc0000000) | 0xc0000000; |
| 2090 | } |
| 2091 | |
| 2092 | // Receive enable |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 2093 | sdram_program_receive_enable(s); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 2094 | printk(BIOS_DEBUG, "Done rcven\n"); |
| 2095 | |
| 2096 | // Finish rcven |
| 2097 | FOR_EACH_CHANNEL(ch) { |
| 2098 | MCHBAR8(0x400*ch + 0x5d8) = MCHBAR8(0x400*ch + 0x5d8) & ~0xe; |
| 2099 | MCHBAR8(0x400*ch + 0x5d8) = MCHBAR8(0x400*ch + 0x5d8) | 0x2; |
| 2100 | MCHBAR8(0x400*ch + 0x5d8) = MCHBAR8(0x400*ch + 0x5d8) | 0x4; |
| 2101 | MCHBAR8(0x400*ch + 0x5d8) = MCHBAR8(0x400*ch + 0x5d8) | 0x8; |
| 2102 | } |
| 2103 | MCHBAR8(0x5dc) = MCHBAR8(0x5dc) | 0x80; |
| 2104 | MCHBAR8(0x5dc) = MCHBAR8(0x5dc) & ~0x80; |
| 2105 | MCHBAR8(0x5dc) = MCHBAR8(0x5dc) | 0x80; |
| 2106 | |
| 2107 | // Dummy writes / reads |
Arthur Heymans | 97e13d8 | 2016-11-30 18:40:38 +0100 | [diff] [blame] | 2108 | if (s->boot_path == BOOT_PATH_NORMAL) { |
| 2109 | volatile u32 data; |
| 2110 | FOR_EACH_POPULATED_RANK(s->dimms, ch, r) { |
| 2111 | for (bank = 0; bank < 4; bank++) { |
| 2112 | reg32 = (ch << 29) | (r*0x8000000) | |
| 2113 | (bank << 12); |
| 2114 | write32((u32 *)reg32, 0xffffffff); |
| 2115 | data = read32((u32 *)reg32); |
| 2116 | printk(BIOS_DEBUG, "Wrote ones,"); |
| 2117 | printk(BIOS_DEBUG, " Read: [0x%08x]=0x%08x\n", |
| 2118 | reg32, data); |
| 2119 | write32((u32 *)reg32, 0x00000000); |
| 2120 | data = read32((u32 *)reg32); |
| 2121 | printk(BIOS_DEBUG, "Wrote zeros,"); |
| 2122 | printk(BIOS_DEBUG, " Read: [0x%08x]=0x%08x\n", |
| 2123 | reg32, data); |
| 2124 | } |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 2125 | } |
| 2126 | } |
| 2127 | printk(BIOS_DEBUG, "Done dummy reads\n"); |
| 2128 | |
| 2129 | // XXX tRD |
| 2130 | |
| 2131 | // XXX Write training |
| 2132 | |
| 2133 | // XXX Read training |
| 2134 | |
| 2135 | // DRADRB |
| 2136 | dradrb_ddr2(s); |
| 2137 | printk(BIOS_DEBUG, "Done DRADRB\n"); |
| 2138 | |
| 2139 | // Memory map |
| 2140 | mmap_ddr2(s); |
| 2141 | printk(BIOS_DEBUG, "Done memory map\n"); |
| 2142 | |
| 2143 | // Enhanced mode |
| 2144 | enhanced_ddr2(s); |
| 2145 | printk(BIOS_DEBUG, "Done enhanced mode\n"); |
| 2146 | |
| 2147 | // Periodic RCOMP |
| 2148 | MCHBAR16(0x160) = (MCHBAR16(0x160) & ~0xfff) | 0x999; |
| 2149 | MCHBAR16(0x1b4) = MCHBAR16(0x1b4) | 0x3000; |
| 2150 | MCHBAR8(0x130) = MCHBAR8(0x130) | 0x82; |
| 2151 | printk(BIOS_DEBUG, "Done PRCOMP\n"); |
| 2152 | |
| 2153 | // Power settings |
| 2154 | power_ddr2(s); |
| 2155 | printk(BIOS_DEBUG, "Done power settings\n"); |
| 2156 | |
| 2157 | // ME related |
Damien Zammit | d63115d | 2016-01-22 19:11:44 +1100 | [diff] [blame] | 2158 | if (RANK_IS_POPULATED(s->dimms, 0, 0) |
| 2159 | || RANK_IS_POPULATED(s->dimms, 1, 0)) { |
| 2160 | MCHBAR8(0xa2f) = MCHBAR8(0xa2f) | (1 << 0); |
| 2161 | } |
| 2162 | if (RANK_IS_POPULATED(s->dimms, 0, 1) |
| 2163 | || RANK_IS_POPULATED(s->dimms, 1, 1)) { |
| 2164 | MCHBAR8(0xa2f) = MCHBAR8(0xa2f) | (1 << 1); |
| 2165 | } |
| 2166 | MCHBAR32(0xa30) = MCHBAR32(0xa30) | (1 << 26); |
Damien Zammit | 4b513a6 | 2015-08-20 00:37:05 +1000 | [diff] [blame] | 2167 | |
| 2168 | printk(BIOS_DEBUG, "Done ddr2\n"); |
| 2169 | } |