Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 3 | * |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007-2008 Uwe Hermann <uwe@hermann-uwe.de> |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 5 | * Copyright (C) 2010 Keith Hui <buurin@gmail.com> |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 22 | #include <spd.h> |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 23 | #include <delay.h> |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 25 | #include "i440bx.h" |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 26 | #include "raminit.h" |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 27 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 28 | /*----------------------------------------------------------------------------- |
| 29 | Macros and definitions. |
| 30 | -----------------------------------------------------------------------------*/ |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 31 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 32 | /* Debugging macros. */ |
Uwe Hermann | 01ce601 | 2010-03-05 10:03:50 +0000 | [diff] [blame] | 33 | #if CONFIG_DEBUG_RAM_SETUP |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 34 | #define PRINT_DEBUG(x) print_debug(x) |
| 35 | #define PRINT_DEBUG_HEX8(x) print_debug_hex8(x) |
| 36 | #define PRINT_DEBUG_HEX16(x) print_debug_hex16(x) |
| 37 | #define PRINT_DEBUG_HEX32(x) print_debug_hex32(x) |
Stefan Reinauer | 3ac400e | 2010-03-30 22:12:59 +0000 | [diff] [blame] | 38 | // no dump_pci_device in src/northbridge/intel/i440bx |
| 39 | // #define DUMPNORTH() dump_pci_device(PCI_DEV(0, 0, 0)) |
| 40 | #define DUMPNORTH() |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 41 | #else |
Uwe Hermann | 941a6f0 | 2007-04-30 23:27:27 +0000 | [diff] [blame] | 42 | #define PRINT_DEBUG(x) |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 43 | #define PRINT_DEBUG_HEX8(x) |
| 44 | #define PRINT_DEBUG_HEX16(x) |
| 45 | #define PRINT_DEBUG_HEX32(x) |
| 46 | #define DUMPNORTH() |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 47 | #endif |
| 48 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 49 | #define NB PCI_DEV(0, 0, 0) |
| 50 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 51 | /* SDRAMC[7:5] - SDRAM Mode Select (SMS). */ |
| 52 | #define RAM_COMMAND_NORMAL 0x0 |
| 53 | #define RAM_COMMAND_NOP 0x1 |
| 54 | #define RAM_COMMAND_PRECHARGE 0x2 |
| 55 | #define RAM_COMMAND_MRS 0x3 |
| 56 | #define RAM_COMMAND_CBR 0x4 |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 57 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 58 | /* Map the JEDEC SPD refresh rates (array index) to 440BX refresh rates as |
| 59 | * defined in DRAMC[2:0]. |
| 60 | * |
| 61 | * [0] == Normal 15.625 us -> 15.6 us |
| 62 | * [1] == Reduced(.25X) 3.9 us -> 7.8 ns |
| 63 | * [2] == Reduced(.5X) 7.8 us -> 7.8 us |
| 64 | * [3] == Extended(2x) 31.3 us -> 31.2 us |
| 65 | * [4] == Extended(4x) 62.5 us -> 62.4 us |
| 66 | * [5] == Extended(8x) 125 us -> 124.8 us |
| 67 | */ |
| 68 | static const uint32_t refresh_rate_map[] = { |
| 69 | 1, 5, 5, 2, 3, 4 |
| 70 | }; |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 71 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 72 | /* Table format: register, bitmask, value. */ |
| 73 | static const long register_values[] = { |
| 74 | /* NBXCFG - NBX Configuration Register |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 75 | * 0x50 - 0x53 |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 76 | * |
| 77 | * [31:24] SDRAM Row Without ECC |
| 78 | * 0 = ECC components are populated in this row |
| 79 | * 1 = ECC components are not populated in this row |
| 80 | * [23:19] Reserved |
| 81 | * [18:18] Host Bus Fast Data Ready Enable (HBFDRE) |
| 82 | * Assertion of DRAM data on host bus occurs... |
| 83 | * 0 = ...one clock after sampling snoop results (default) |
| 84 | * 1 = ...on the same clock the snoop result is being sampled |
| 85 | * (this mode is faster by one clock cycle) |
| 86 | * [17:17] ECC - EDO static Drive mode |
| 87 | * 0 = Normal mode (default) |
| 88 | * 1 = ECC signals are always driven |
| 89 | * [16:16] IDSEL_REDIRECT |
| 90 | * 0 = IDSEL1 is allocated to this bridge (default) |
| 91 | * 1 = IDSEL7 is allocated to this bridge |
| 92 | * [15:15] WSC# Handshake Disable |
| 93 | * 1 = Uni-processor mode |
| 94 | * 0 = Dual-processor mode with external IOAPIC (default) |
| 95 | * [14:14] Intel Reserved |
| 96 | * [13:12] Host/DRAM Frequency |
| 97 | * 00 = 100 MHz |
| 98 | * 01 = Reserved |
| 99 | * 10 = 66 MHz |
| 100 | * 11 = Reserved |
| 101 | * [11:11] AGP to PCI Access Enable |
| 102 | * 1 = Enable |
| 103 | * 0 = Disable |
| 104 | * [10:10] PCI Agent to Aperture Access Disable |
| 105 | * 1 = Disable |
| 106 | * 0 = Enable (default) |
| 107 | * [09:09] Aperture Access Global Enable |
| 108 | * 1 = Enable |
| 109 | * 0 = Disable |
| 110 | * [08:07] DRAM Data Integrity Mode (DDIM) |
| 111 | * 00 = Non-ECC |
| 112 | * 01 = EC-only |
| 113 | * 10 = ECC Mode |
| 114 | * 11 = ECC Mode with hardware scrubbing enabled |
| 115 | * [06:06] ECC Diagnostic Mode Enable (EDME) |
| 116 | * 1 = Enable |
| 117 | * 0 = Normal operation mode (default) |
| 118 | * [05:05] MDA Present (MDAP) |
| 119 | * Works in conjunction with the VGA_EN bit. |
| 120 | * VGA_EN MDAP |
| 121 | * 0 x All VGA cycles are sent to PCI |
| 122 | * 1 0 All VGA cycles are sent to AGP |
| 123 | * 1 1 All VGA cycles are sent to AGP, except for |
| 124 | * cycles in the MDA range. |
| 125 | * [04:04] Reserved |
| 126 | * [03:03] USWC Write Post During I/O Bridge Access Enable (UWPIO) |
| 127 | * 1 = Enable |
| 128 | * 0 = Disable |
| 129 | * [02:02] In-Order Queue Depth (IOQD) |
| 130 | * 1 = In-order queue = maximum |
| 131 | * 0 = A7# is sampled asserted (i.e., 0) |
| 132 | * [01:00] Reserved |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 133 | */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 134 | // TODO |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 135 | NBXCFG + 0, 0x00, 0x0c, |
| 136 | // NBXCFG + 1, 0x00, 0xa0, |
| 137 | NBXCFG + 1, 0x00, 0x80, |
| 138 | NBXCFG + 2, 0x00, 0x00, |
| 139 | NBXCFG + 3, 0x00, 0xff, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 140 | |
| 141 | /* DRAMC - DRAM Control Register |
| 142 | * 0x57 |
| 143 | * |
| 144 | * [7:6] Reserved |
| 145 | * [5:5] Module Mode Configuration (MMCONFIG) |
| 146 | * TODO |
| 147 | * [4:3] DRAM Type (DT) |
| 148 | * 00 = EDO |
| 149 | * 01 = SDRAM |
| 150 | * 10 = Registered SDRAM |
| 151 | * 11 = Reserved |
| 152 | * Note: EDO, SDRAM and Registered SDRAM cannot be mixed. |
| 153 | * [2:0] DRAM Refresh Rate (DRR) |
| 154 | * 000 = Refresh disabled |
| 155 | * 001 = 15.6 us |
| 156 | * 010 = 31.2 us |
| 157 | * 011 = 62.4 us |
| 158 | * 100 = 124.8 us |
| 159 | * 101 = 249.6 us |
| 160 | * 110 = Reserved |
| 161 | * 111 = Reserved |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 162 | */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 163 | /* Choose SDRAM (not registered), and disable refresh for now. */ |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 164 | DRAMC, 0x00, 0x08, |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 165 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 166 | /* |
| 167 | * PAM[6:0] - Programmable Attribute Map Registers |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 168 | * 0x59 - 0x5f |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 169 | * |
| 170 | * 0x59 [3:0] Reserved |
| 171 | * 0x59 [5:4] 0xF0000 - 0xFFFFF BIOS area |
| 172 | * 0x5a [1:0] 0xC0000 - 0xC3FFF ISA add-on BIOS |
| 173 | * 0x5a [5:4] 0xC4000 - 0xC7FFF ISA add-on BIOS |
| 174 | * 0x5b [1:0] 0xC8000 - 0xCBFFF ISA add-on BIOS |
| 175 | * 0x5b [5:4] 0xCC000 - 0xCFFFF ISA add-on BIOS |
| 176 | * 0x5c [1:0] 0xD0000 - 0xD3FFF ISA add-on BIOS |
| 177 | * 0x5c [5:4] 0xD4000 - 0xD7FFF ISA add-on BIOS |
| 178 | * 0x5d [1:0] 0xD8000 - 0xDBFFF ISA add-on BIOS |
| 179 | * 0x5d [5:4] 0xDC000 - 0xDFFFF ISA add-on BIOS |
| 180 | * 0x5e [1:0] 0xE0000 - 0xE3FFF BIOS entension |
| 181 | * 0x5e [5:4] 0xE4000 - 0xE7FFF BIOS entension |
| 182 | * 0x5f [1:0] 0xE8000 - 0xEBFFF BIOS entension |
| 183 | * 0x5f [5:4] 0xEC000 - 0xEFFFF BIOS entension |
| 184 | * |
| 185 | * Bit assignment: |
| 186 | * 00 = DRAM Disabled (all access goes to memory mapped I/O space) |
| 187 | * 01 = Read Only (Reads to DRAM, writes to memory mapped I/O space) |
| 188 | * 10 = Write Only (Writes to DRAM, reads to memory mapped I/O space) |
| 189 | * 11 = Read/Write (all access goes to DRAM) |
| 190 | */ |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * Map all legacy regions to RAM (read/write). This is required if |
| 194 | * you want to use the RAM area from 768 KB - 1 MB. If the PAM |
| 195 | * registers are not set here appropriately, the RAM in that region |
| 196 | * will not be accessible, thus a RAM check of it will also fail. |
| 197 | * |
| 198 | * TODO: This was set in sdram_set_spd_registers(). |
| 199 | * Test if it still works when set here. |
| 200 | */ |
| 201 | PAM0, 0x00, 0x30, |
| 202 | PAM1, 0x00, 0x33, |
| 203 | PAM2, 0x00, 0x33, |
| 204 | PAM3, 0x00, 0x33, |
| 205 | PAM4, 0x00, 0x33, |
| 206 | PAM5, 0x00, 0x33, |
| 207 | PAM6, 0x00, 0x33, |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 208 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 209 | /* DRB[0:7] - DRAM Row Boundary Registers |
| 210 | * 0x60 - 0x67 |
| 211 | * |
| 212 | * An array of 8 byte registers, which hold the ending memory address |
| 213 | * assigned to each pair of DIMMs, in 8MB granularity. |
| 214 | * |
| 215 | * 0x60 DRB0 = Total memory in row0 (in 8 MB) |
| 216 | * 0x61 DRB1 = Total memory in row0+1 (in 8 MB) |
| 217 | * 0x62 DRB2 = Total memory in row0+1+2 (in 8 MB) |
| 218 | * 0x63 DRB3 = Total memory in row0+1+2+3 (in 8 MB) |
| 219 | * 0x64 DRB4 = Total memory in row0+1+2+3+4 (in 8 MB) |
| 220 | * 0x65 DRB5 = Total memory in row0+1+2+3+4+5 (in 8 MB) |
| 221 | * 0x66 DRB6 = Total memory in row0+1+2+3+4+5+6 (in 8 MB) |
| 222 | * 0x67 DRB7 = Total memory in row0+1+2+3+4+5+6+7 (in 8 MB) |
| 223 | */ |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 224 | /* Set the DRBs to zero for now, this will be fixed later. */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 225 | DRB0, 0x00, 0x00, |
| 226 | DRB1, 0x00, 0x00, |
| 227 | DRB2, 0x00, 0x00, |
| 228 | DRB3, 0x00, 0x00, |
| 229 | DRB4, 0x00, 0x00, |
| 230 | DRB5, 0x00, 0x00, |
| 231 | DRB6, 0x00, 0x00, |
| 232 | DRB7, 0x00, 0x00, |
| 233 | |
| 234 | /* FDHC - Fixed DRAM Hole Control Register |
| 235 | * 0x68 |
| 236 | * |
| 237 | * Controls two fixed DRAM holes: 512 KB - 640 KB and 15 MB - 16 MB. |
| 238 | * |
| 239 | * [7:6] Hole Enable (HEN) |
| 240 | * 00 = None |
| 241 | * 01 = 512 KB - 640 KB (128 KB) |
| 242 | * 10 = 15 MB - 16 MB (1 MB) |
| 243 | * 11 = Reserved |
| 244 | * [5:0] Reserved |
| 245 | */ |
| 246 | /* No memory holes. */ |
| 247 | FDHC, 0x00, 0x00, |
| 248 | |
| 249 | /* RPS - SDRAM Row Page Size Register |
| 250 | * 0x74 - 0x75 |
| 251 | * |
| 252 | * Sets the row page size for SDRAM. For EDO memory, the page |
| 253 | * size is fixed at 2 KB. |
| 254 | * |
| 255 | * [15:0] Page Size (PS) |
| 256 | * TODO |
| 257 | */ |
| 258 | // TODO |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 259 | RPS + 0, 0x00, 0x00, |
| 260 | RPS + 1, 0x00, 0x00, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 261 | |
| 262 | /* SDRAMC - SDRAM Control Register |
Uwe Hermann | 7ea18cf | 2007-05-04 00:51:17 +0000 | [diff] [blame] | 263 | * 0x76 - 0x77 |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 264 | * |
| 265 | * [15:10] Reserved |
| 266 | * [09:08] Idle/Pipeline DRAM Leadoff Timing (IPDLT) |
| 267 | * 00 = Illegal |
| 268 | * 01 = Add a clock delay to the lead-off clock count |
| 269 | * 10 = Illegal |
| 270 | * 11 = Illegal |
| 271 | * [07:05] SDRAM Mode Select (SMS) |
| 272 | * 000 = Normal SDRAM Operation (default) |
| 273 | * 001 = NOP Command Enable |
| 274 | * 010 = All Banks Precharge Enable |
| 275 | * 011 = Mode Register Set Enable |
| 276 | * 100 = CBR Enable |
| 277 | * 101 = Reserved |
| 278 | * 110 = Reserved |
| 279 | * 111 = Reserved |
| 280 | * [04:04] SDRAMPWR |
| 281 | * 0 = 3 DIMM configuration |
| 282 | * 1 = 4 DIMM configuration |
| 283 | * [03:03] Leadoff Command Timing (LCT) |
| 284 | * 0 = 4 CS# Clock |
| 285 | * 1 = 3 CS# Clock |
| 286 | * [02:02] CAS# Latency (CL) |
| 287 | * 0 = 3 DCLK CAS# latency |
| 288 | * 1 = 2 DCLK CAS# latency |
| 289 | * [01:01] SDRAM RAS# to CAS# Delay (SRCD) |
| 290 | * 0 = 3 clocks between a row activate and a read or write cmd. |
| 291 | * 1 = 2 clocks between a row activate and a read or write cmd. |
| 292 | * [00:00] SDRAM RAS# Precharge (SRP) |
| 293 | * 0 = 3 clocks of RAS# precharge |
| 294 | * 1 = 2 clocks of RAS# precharge |
| 295 | */ |
Keith Hui | 9c1e1f0 | 2010-03-13 20:16:48 +0000 | [diff] [blame] | 296 | #if CONFIG_SDRAMPWR_4DIMM |
| 297 | SDRAMC + 0, 0x00, 0x10, /* The board has 4 DIMM slots. */ |
| 298 | #else |
| 299 | SDRAMC + 0, 0x00, 0x00, /* The board has 3 DIMM slots.*/ |
| 300 | #endif |
Mats Erik Andersson | 45db366 | 2008-09-30 04:52:29 +0000 | [diff] [blame] | 301 | SDRAMC + 1, 0x00, 0x00, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 302 | |
| 303 | /* PGPOL - Paging Policy Register |
| 304 | * 0x78 - 0x79 |
| 305 | * |
| 306 | * [15:08] Banks per Row (BPR) |
| 307 | * TODO |
| 308 | * 0 = 2 banks |
| 309 | * 1 = 4 banks |
| 310 | * [07:05] Reserved |
| 311 | * [04:04] Intel Reserved |
| 312 | * [03:00] DRAM Idle Timer (DIT) |
| 313 | * 0000 = 0 clocks |
| 314 | * 0001 = 2 clocks |
| 315 | * 0010 = 4 clocks |
| 316 | * 0011 = 8 clocks |
| 317 | * 0100 = 10 clocks |
| 318 | * 0101 = 12 clocks |
| 319 | * 0110 = 16 clocks |
| 320 | * 0111 = 32 clocks |
| 321 | * 1xxx = Infinite (pages are not closed for idle condition) |
| 322 | */ |
| 323 | // TODO |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 324 | PGPOL + 0, 0x00, 0x00, |
| 325 | PGPOL + 1, 0x00, 0xff, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 326 | |
| 327 | /* PMCR - Power Management Control Register |
| 328 | * 0x7a |
| 329 | * |
| 330 | * [07:07] Power Down SDRAM Enable (PDSE) |
| 331 | * 1 = Enable |
| 332 | * 0 = Disable |
| 333 | * [06:06] ACPI Control Register Enable (SCRE) |
| 334 | * 1 = Enable |
| 335 | * 0 = Disable (default) |
| 336 | * [05:05] Suspend Refresh Type (SRT) |
| 337 | * 1 = Self refresh mode |
| 338 | * 0 = CBR fresh mode |
| 339 | * [04:04] Normal Refresh Enable (NREF_EN) |
| 340 | * 1 = Enable |
| 341 | * 0 = Disable |
| 342 | * [03:03] Quick Start Mode (QSTART) |
| 343 | * 1 = Quick start mode for the processor is enabled |
| 344 | * [02:02] Gated Clock Enable (GCLKEN) |
| 345 | * 1 = Enable |
| 346 | * 0 = Disable |
| 347 | * [01:01] AGP Disable (AGP_DIS) |
| 348 | * 1 = Disable |
| 349 | * 0 = Enable |
| 350 | * [00:00] CPU reset without PCIRST enable (CRst_En) |
| 351 | * 1 = Enable |
| 352 | * 0 = Disable |
| 353 | */ |
| 354 | /* Enable normal refresh and the gated clock. */ |
| 355 | // TODO: Only do this later? |
| 356 | // PMCR, 0x00, 0x14, |
| 357 | // PMCR, 0x00, 0x10, |
| 358 | PMCR, 0x00, 0x00, |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 359 | |
| 360 | /* Enable SCRR.SRRAEN and let BX choose the SRR. */ |
| 361 | SCRR + 1, 0x00, 0x10, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 362 | }; |
| 363 | |
| 364 | /*----------------------------------------------------------------------------- |
| 365 | SDRAM configuration functions. |
| 366 | -----------------------------------------------------------------------------*/ |
| 367 | |
| 368 | /** |
| 369 | * Send the specified RAM command to all DIMMs. |
| 370 | * |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 371 | * @param command The RAM command to send to the DIMM(s). |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 372 | */ |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 373 | static void do_ram_command(u32 command) |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 374 | { |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 375 | int i, caslatency; |
| 376 | u8 dimm_start, dimm_end; |
| 377 | u16 reg16; |
| 378 | u32 addr, addr_offset; |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 379 | |
| 380 | /* Configure the RAM command. */ |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 381 | reg16 = pci_read_config16(NB, SDRAMC); |
| 382 | reg16 &= 0xff1f; /* Clear bits 7-5. */ |
| 383 | reg16 |= (u16) (command << 5); /* Write command into bits 7-5. */ |
| 384 | pci_write_config16(NB, SDRAMC, reg16); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 385 | |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 386 | /* |
| 387 | * RAM_COMMAND_NORMAL affects only the memory controller and |
| 388 | * doesn't need to be "sent" to the DIMMs. |
| 389 | */ |
| 390 | if (command == RAM_COMMAND_NORMAL) |
| 391 | return; |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 392 | |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 393 | /* Send the RAM command to each row of memory. */ |
| 394 | dimm_start = 0; |
| 395 | for (i = 0; i < (DIMM_SOCKETS * 2); i++) { |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 396 | addr_offset = 0; |
| 397 | caslatency = 3; /* TODO: Dynamically get CAS latency later. */ |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 398 | if (command == RAM_COMMAND_MRS) { |
| 399 | /* |
| 400 | * MAA[12:11,9:0] must be inverted when sent to DIMM |
| 401 | * 2 or 3 (no inversion if sent to DIMM 0 or 1). |
| 402 | */ |
| 403 | if ((i >= 0 && i <= 3) && caslatency == 3) |
| 404 | addr_offset = 0x1d0; |
| 405 | if ((i >= 4 && i <= 7) && caslatency == 3) |
| 406 | addr_offset = 0x1e28; |
| 407 | if ((i >= 0 && i <= 3) && caslatency == 2) |
| 408 | addr_offset = 0x150; |
| 409 | if ((i >= 4 && i <= 7) && caslatency == 2) |
| 410 | addr_offset = 0x1ea8; |
| 411 | } |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 412 | |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 413 | dimm_end = pci_read_config8(NB, DRB + i); |
| 414 | |
| 415 | addr = (dimm_start * 8 * 1024 * 1024) + addr_offset; |
| 416 | if (dimm_end > dimm_start) { |
| 417 | #if 0 |
| 418 | PRINT_DEBUG(" Sending RAM command 0x"); |
| 419 | PRINT_DEBUG_HEX16(reg16); |
| 420 | PRINT_DEBUG(" to 0x"); |
| 421 | PRINT_DEBUG_HEX32(addr); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 422 | PRINT_DEBUG("\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 423 | #endif |
| 424 | |
| 425 | read32(addr); |
| 426 | } |
| 427 | |
| 428 | /* Set the start of the next DIMM. */ |
| 429 | dimm_start = dimm_end; |
| 430 | } |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 433 | static void set_dram_buffer_strength(void) |
| 434 | { |
Keith Hui | b48ba66 | 2010-03-17 02:15:07 +0000 | [diff] [blame] | 435 | /* To give some breathing room for romcc, |
| 436 | * mbsc0 doubles as drb |
| 437 | * mbsc1 doubles as drb1 |
| 438 | * mbfs0 doubles as i and reg |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 439 | */ |
Keith Hui | b48ba66 | 2010-03-17 02:15:07 +0000 | [diff] [blame] | 440 | uint8_t mbsc0,mbsc1,mbsc3,mbsc4,mbfs0,mbfs2,fsb; |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 441 | |
Keith Hui | b48ba66 | 2010-03-17 02:15:07 +0000 | [diff] [blame] | 442 | /* Tally how many rows between rows 0-3 and rows 4-7 are populated. |
| 443 | * This determines how to program MBFS and MBSC. |
| 444 | */ |
| 445 | uint8_t dimm03 = 0; |
| 446 | uint8_t dimm47 = 0; |
| 447 | |
| 448 | mbsc0 = 0; |
| 449 | for (mbfs0 = DRB0; mbfs0 <= DRB7; mbfs0++) { |
| 450 | mbsc1 = pci_read_config8(NB, mbfs0); |
| 451 | if (mbsc0 != mbsc1) { |
| 452 | if (mbfs0 <= DRB3) { |
| 453 | dimm03++; |
| 454 | } else { |
| 455 | dimm47++; |
| 456 | } |
| 457 | mbsc0 = mbsc1; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /* Algorithm bitmap for programming MBSC[39:0] and MBFS[23:0] |
| 462 | * |
| 463 | * 440BX datasheet says buffer frequency is independent from bus frequency |
| 464 | * and mismatch both ways are possible. This is how it is programmed |
| 465 | * in ASUS P2B-LS. |
| 466 | * |
| 467 | * There are four main conditions to check when programming DRAM buffer |
| 468 | * frequency and strength: |
| 469 | * |
| 470 | * a: >2 rows populated across DIMM0,1 |
| 471 | * b: >2 rows populated across DIMM2,3 |
| 472 | * c: >4 rows populated across all DIMM slots |
| 473 | * and either one of: |
| 474 | * 1: NBXCFG[13] strapped as 100MHz, or |
| 475 | * 6: NBXCFG[13] strapped as 66MHz |
| 476 | * |
| 477 | * CKE0/FENA ----------------------------------------------------------+ |
| 478 | * CKE1/GCKE -------------------[ MBFS ]------------------------+| |
| 479 | * DQMA/CASA[764320]# ----------[ 0 = 66MHz ]-----------------------+|| |
| 480 | * DQMB1/CASB1# ----------------[ 1 = 100MHz ]----------------------+||| |
| 481 | * DQMB5/CASB5# ---------------------------------------------------+|||| |
| 482 | * DQMA1/CASA1# --------------------------------------------------+||||| |
| 483 | * DQMA5/CASA5# -------------------------------------------------+|||||| |
| 484 | * CSA0-5#,CSB0-5# ----------------------------------------++++++||||||| |
| 485 | * CSA6#/CKE2# -------------------------------------------+||||||||||||| |
| 486 | * CSB6#/CKE4# ------------------------------------------+|||||||||||||| |
| 487 | * CSA7#/CKE3# -----------------------------------------+||||||||||||||| |
| 488 | * CSB7#/CKE5# ----------------------------------------+|||||||||||||||| |
| 489 | * MECC[7:0] #2/#1 (100MHz) -------------------------++||||||||||||||||| |
| 490 | * MD[63:0] #2/#1 (100MHz) ------------------------++||||||||||||||||||| |
| 491 | * MAB[12:11,9:0]#,MAB[13,10],WEB#,SRASB#,SCASB# -+||||||||||||||||||||| |
| 492 | * MAA[13:0],WEA#,SRASA#,SCASA# -----------------+|||||||||||||||||||||| |
| 493 | * Reserved ------------------------------------+||||||||||||||||||||||| |
| 494 | * |||||||||||||||||||||||| |
| 495 | * 3 32 21 10 0 * 2 21 10 0 |
| 496 | * 9876543210987654321098765432109876543210 * 321098765432109876543210 |
| 497 | * a 10------------------------1010---------- * -1---------------11----- a |
| 498 | *!a 11------------------------1111---------- * -0---------------00----- !a |
| 499 | * b --10--------------------------1010------ * --1----------------11--- b |
| 500 | *!b --11--------------------------1111------ * --0----------------00--- !b |
| 501 | * c ----------------------------------1100-- * ----------------------1- c |
| 502 | *!c ----------------------------------1011-- * ----------------------0- !c |
| 503 | * 1 ----1010101000000000000000------------00 * ---11111111111111----1-0 1 |
| 504 | * 6 ----000000000000000000000010101010----00 * ---1111111111111100000-0 6 |
| 505 | * | | | | | | | | | | ||||||| | | | | | | |
| 506 | * | | | | | | | | | | ||||||| | | | | | +- CKE0/FENA |
| 507 | * | | | | | | | | | | ||||||| | | | | +--- CKE1/GCKE |
| 508 | * | | | | | | | | | | ||||||| | | | +----- DQMA/CASA[764320]# |
| 509 | * | | | | | | | | | | ||||||| | | +------- DQMB1/CASB1# |
| 510 | * | | | | | | | | | | ||||||| | +--------- DQMB5/CASB5# |
| 511 | * | | | | | | | | | | ||||||| +----------- DQMA1/CASA1# |
| 512 | * | | | | | | | | | | ||||||+------------- DQMA5/CASA5# |
| 513 | * | | | | | | | | | | ++++++-------------- CSA0-5#,CSB0-5# [ 0=1x;1=2x ] |
| 514 | * | | | | | | | | | +--------------------- CSA6#/CKE2# |
| 515 | * | | | | | | | | +---[ MBSC ]------ CSB6#/CKE4# |
| 516 | * | | | | | | | +-----[ 00 = 1x ]------ CSA7#/CKE3# |
| 517 | * | | | | | | +-------[ 01 invalid ]------ CSB7#/CKE5# |
| 518 | * | | | | | +---------[ 10 = 2x ]------ MECC[7:0] #1 (2x) |
| 519 | * | | | | +-----------[ 11 = 3x ]------ MECC[7:0] #2 (2x) |
| 520 | * | | | +--------------------------------- MD[63:0] #1 (2x) |
| 521 | * | | +----------------------------------- MD[63:0] #2 (2x) |
| 522 | * | +------------------------------------- MAB[12:11,9:0]#,MAB[13,10],WEB#,SRASB#,SCASB# |
| 523 | * +--------------------------------------- MAA[13:0],WEA#,SRASA#,SCASA# |
| 524 | * MBSC[47:40] and MBFS[23] are reserved. |
| 525 | * |
| 526 | * This algorithm is checked against P2B-LS factory BIOS. It has 4 DIMM slots. |
| 527 | * Therefore it assumes a board with 4 slots, and will need testing |
| 528 | * on boards with 3 DIMM slots. |
| 529 | */ |
| 530 | |
| 531 | mbsc0 = 0x80; |
| 532 | mbsc1 = 0x2a; |
| 533 | mbfs2 = 0x1f; |
| 534 | if (pci_read_config8(NB, NBXCFG + 1) & 0x30) { |
| 535 | fsb = 66; |
| 536 | mbsc3 = 0x00; |
| 537 | mbsc4 = 0x00; |
| 538 | mbfs0 = 0x80; |
| 539 | } else { |
| 540 | fsb = 100; |
| 541 | mbsc3 = 0xa0; |
| 542 | mbsc4 = 0x0a; |
| 543 | mbfs0 = 0x84; |
| 544 | } |
| 545 | |
| 546 | if (dimm03 > 2) { |
| 547 | mbsc4 = mbsc4 | 0x80; |
| 548 | mbsc1 = mbsc1 | 0x28; |
| 549 | mbfs2 = mbfs2 | 0x40; |
| 550 | mbfs0 = mbfs0 | 0x60; |
| 551 | } else { |
| 552 | mbsc4 = mbsc4 | 0xc0; |
| 553 | if (fsb == 100) { |
| 554 | mbsc1 = mbsc1 | 0x3c; |
| 555 | } |
| 556 | } |
| 557 | if (dimm47 > 2) { |
| 558 | mbsc4 = mbsc4 | 0x20; |
| 559 | mbsc1 = mbsc1 | 0x02; |
| 560 | mbsc0 = mbsc0 | 0x80; |
| 561 | mbfs2 = mbfs2 | 0x20; |
| 562 | mbfs0 = mbfs0 | 0x18; |
| 563 | } else { |
| 564 | mbsc4 = mbsc4 | 0x30; |
| 565 | if (fsb == 100) { |
| 566 | mbsc1 = mbsc1 | 0x03; |
| 567 | mbsc0 = mbsc0 | 0xc0; |
| 568 | } |
| 569 | } |
| 570 | if ((dimm03 + dimm47) > 4) { |
| 571 | mbsc0 = mbsc0 | 0x30; |
| 572 | mbfs0 = mbfs0 | 0x02; |
| 573 | } else { |
| 574 | mbsc0 = mbsc0 | 0x2c; |
| 575 | } |
| 576 | |
| 577 | pci_write_config8(NB, MBSC + 0, mbsc0); |
| 578 | pci_write_config8(NB, MBSC + 1, mbsc1); |
| 579 | pci_write_config8(NB, MBSC + 2, 0x00); |
| 580 | pci_write_config8(NB, MBSC + 3, mbsc3); |
| 581 | pci_write_config8(NB, MBSC + 4, mbsc4); |
| 582 | pci_write_config8(NB, MBFS + 0, mbfs0); |
| 583 | pci_write_config8(NB, MBFS + 1, 0xff); |
| 584 | pci_write_config8(NB, MBFS + 2, mbfs2); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 587 | /*----------------------------------------------------------------------------- |
| 588 | DIMM-independant configuration functions. |
| 589 | -----------------------------------------------------------------------------*/ |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 590 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 591 | static void spd_enable_refresh(void) |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 592 | { |
| 593 | int i, value; |
| 594 | uint8_t reg; |
| 595 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 596 | reg = pci_read_config8(NB, DRAMC); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 597 | |
| 598 | for (i = 0; i < DIMM_SOCKETS; i++) { |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 599 | value = spd_read_byte(DIMM_SPD_BASE + i, SPD_REFRESH); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 600 | if (value < 0) |
| 601 | continue; |
| 602 | reg = (reg & 0xf8) | refresh_rate_map[(value & 0x7f)]; |
| 603 | |
| 604 | PRINT_DEBUG(" Enabling refresh (DRAMC = 0x"); |
| 605 | PRINT_DEBUG_HEX8(reg); |
| 606 | PRINT_DEBUG(") for DIMM "); |
| 607 | PRINT_DEBUG_HEX8(i); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 608 | PRINT_DEBUG("\n"); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 611 | pci_write_config8(NB, DRAMC, reg); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 612 | } |
| 613 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 614 | /*----------------------------------------------------------------------------- |
| 615 | Public interface. |
| 616 | -----------------------------------------------------------------------------*/ |
| 617 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 618 | static void sdram_set_registers(void) |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 619 | { |
| 620 | int i, max; |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 621 | uint8_t reg; |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 622 | |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 623 | PRINT_DEBUG("Northbridge prior to SDRAM init:\n"); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 624 | DUMPNORTH(); |
| 625 | |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 626 | max = ARRAY_SIZE(register_values); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 627 | |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 628 | /* Set registers as specified in the register_values[] array. */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 629 | for (i = 0; i < max; i += 3) { |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 630 | reg = pci_read_config8(NB, register_values[i]); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 631 | reg &= register_values[i + 1]; |
| 632 | reg |= register_values[i + 2] & ~(register_values[i + 1]); |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 633 | pci_write_config8(NB, register_values[i], reg); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 634 | #if 0 |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 635 | PRINT_DEBUG(" Set register 0x"); |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 636 | PRINT_DEBUG_HEX8(register_values[i]); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 637 | PRINT_DEBUG(" to 0x"); |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 638 | PRINT_DEBUG_HEX8(reg); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 639 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 640 | #endif |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 644 | struct dimm_size { |
| 645 | unsigned long side1; |
| 646 | unsigned long side2; |
| 647 | }; |
| 648 | |
| 649 | static struct dimm_size spd_get_dimm_size(unsigned int device) |
| 650 | { |
| 651 | struct dimm_size sz; |
| 652 | int i, module_density, dimm_banks; |
| 653 | sz.side1 = 0; |
| 654 | module_density = spd_read_byte(device, SPD_DENSITY_OF_EACH_ROW_ON_MODULE); |
| 655 | dimm_banks = spd_read_byte(device, SPD_NUM_DIMM_BANKS); |
| 656 | |
| 657 | /* Find the size of side1. */ |
| 658 | /* Find the larger value. The larger value is always side1. */ |
| 659 | for (i = 512; i >= 0; i >>= 1) { |
| 660 | if ((module_density & i) == i) { |
| 661 | sz.side1 = i; |
| 662 | break; |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | /* Set to 0 in case it's single sided. */ |
| 667 | sz.side2 = 0; |
| 668 | |
| 669 | /* Test if it's a dual-sided DIMM. */ |
| 670 | if (dimm_banks > 1) { |
| 671 | /* Test if there's a second value. If so it's asymmetrical. */ |
| 672 | if (module_density != i) { |
| 673 | /* |
| 674 | * Find second value, picking up where we left off. |
| 675 | * i >>= 1 done initially to make sure we don't get |
| 676 | * the same value again. |
| 677 | */ |
| 678 | for (i >>= 1; i >= 0; i >>= 1) { |
| 679 | if (module_density == (sz.side1 | i)) { |
| 680 | sz.side2 = i; |
| 681 | break; |
| 682 | } |
| 683 | } |
| 684 | /* If not, it's symmetrical. */ |
| 685 | } else { |
| 686 | sz.side2 = sz.side1; |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | /* |
| 691 | * SPD byte 31 is the memory size divided by 4 so we |
| 692 | * need to muliply by 4 to get the total size. |
| 693 | */ |
| 694 | sz.side1 *= 4; |
| 695 | sz.side2 *= 4; |
| 696 | |
| 697 | return sz; |
| 698 | } |
| 699 | /* |
| 700 | * Sets DRAM attributes one DIMM at a time, based on SPD data. |
| 701 | * Northbridge settings that are set: NBXCFG[31:24], DRB0-DRB7, RPS, DRAMC. |
| 702 | */ |
| 703 | static void set_dram_row_attributes(void) |
| 704 | { |
| 705 | int i, dra, drb, col, width, value, rps, edosd, ecc, nbxecc; |
| 706 | u8 bpr; /* Top 8 bits of PGPOL */ |
| 707 | |
| 708 | edosd = 0; |
| 709 | rps = 0; |
| 710 | drb = 0; |
| 711 | bpr = 0; |
| 712 | nbxecc = 0xff; |
| 713 | |
| 714 | for (i = 0; i < DIMM_SOCKETS; i++) { |
| 715 | unsigned int device; |
| 716 | device = DIMM_SPD_BASE + i; |
| 717 | bpr >>= 2; |
| 718 | |
| 719 | /* First check if a DIMM is actually present. */ |
| 720 | value = spd_read_byte(device, SPD_MEMORY_TYPE); |
| 721 | /* This is 440BX! We do EDO too! */ |
| 722 | if (value == SPD_MEMORY_TYPE_EDO |
| 723 | || value == SPD_MEMORY_TYPE_SDRAM) { |
| 724 | |
| 725 | PRINT_DEBUG("Found "); |
| 726 | if (value == SPD_MEMORY_TYPE_EDO) { |
| 727 | edosd |= 0x02; |
| 728 | } else if (value == SPD_MEMORY_TYPE_SDRAM) { |
| 729 | edosd |= 0x04; |
| 730 | } |
| 731 | PRINT_DEBUG("DIMM in slot "); |
| 732 | PRINT_DEBUG_HEX8(i); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 733 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 734 | |
| 735 | if (edosd == 0x06) { |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 736 | print_err("Mixing EDO/SDRAM unsupported!\n"); |
| 737 | die("HALT\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | /* "DRA" is our RPS for the two rows on this DIMM. */ |
| 741 | dra = 0; |
| 742 | |
| 743 | /* Columns */ |
| 744 | col = spd_read_byte(device, SPD_NUM_COLUMNS); |
| 745 | |
| 746 | /* |
| 747 | * Is this an ECC DIMM? Actually will be a 2 if so. |
| 748 | * TODO: Other register than NBXCFG also needs this |
| 749 | * ECC information. |
| 750 | */ |
| 751 | ecc = spd_read_byte(device, SPD_DIMM_CONFIG_TYPE); |
| 752 | |
| 753 | /* Data width */ |
| 754 | width = spd_read_byte(device, SPD_MODULE_DATA_WIDTH_LSB); |
| 755 | |
| 756 | /* Exclude error checking data width from page size calculations */ |
| 757 | if (ecc) { |
| 758 | value = spd_read_byte(device, |
| 759 | SPD_ERROR_CHECKING_SDRAM_WIDTH); |
| 760 | width -= value; |
| 761 | /* ### ECC */ |
| 762 | /* Clear top 2 bits to help set up NBXCFG. */ |
| 763 | ecc &= 0x3f; |
| 764 | } else { |
| 765 | /* Without ECC, top 2 bits should be 11. */ |
| 766 | ecc |= 0xc0; |
| 767 | } |
| 768 | |
| 769 | /* Calculate page size in bits. */ |
| 770 | value = ((1 << col) * width); |
| 771 | |
| 772 | /* Convert to KB. */ |
| 773 | dra = (value >> 13); |
| 774 | |
| 775 | /* Number of banks of DIMM (single or double sided). */ |
| 776 | value = spd_read_byte(device, SPD_NUM_DIMM_BANKS); |
| 777 | |
| 778 | /* Once we have dra, col is done and can be reused. |
| 779 | * So it's reused for number of banks. |
| 780 | */ |
| 781 | col = spd_read_byte(device, SPD_NUM_BANKS_PER_SDRAM); |
| 782 | |
| 783 | if (value == 1) { |
| 784 | /* |
| 785 | * Second bank of 1-bank DIMMs "doesn't have |
| 786 | * ECC" - or anything. |
| 787 | */ |
| 788 | ecc |= 0x80; |
| 789 | if (dra == 2) { |
| 790 | dra = 0x0; /* 2KB */ |
| 791 | } else if (dra == 4) { |
| 792 | dra = 0x1; /* 4KB */ |
| 793 | } else if (dra == 8) { |
| 794 | dra = 0x2; /* 8KB */ |
| 795 | } else { |
| 796 | dra = -1; |
| 797 | } |
| 798 | /* |
| 799 | * Sets a flag in PGPOL[BPR] if this DIMM has |
| 800 | * 4 banks per row. |
| 801 | */ |
| 802 | if (col == 4) |
| 803 | bpr |= 0x40; |
| 804 | } else if (value == 2) { |
| 805 | if (dra == 2) { |
| 806 | dra = 0x0; /* 2KB */ |
| 807 | } else if (dra == 4) { |
| 808 | dra = 0x05; /* 4KB */ |
| 809 | } else if (dra == 8) { |
| 810 | dra = 0x0a; /* 8KB */ |
| 811 | } else { |
| 812 | dra = -1; |
| 813 | } |
| 814 | /* Ditto */ |
| 815 | if (col == 4) |
| 816 | bpr |= 0xc0; |
| 817 | } else { |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 818 | print_err("# of banks of DIMM unsupported!\n"); |
| 819 | die("HALT\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 820 | } |
| 821 | if (dra == -1) { |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 822 | print_err("Page size not supported\n"); |
| 823 | die("HALT\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | /* |
| 827 | * 440BX supports asymmetrical dual-sided DIMMs, |
| 828 | * but can't handle DIMMs smaller than 8MB per |
| 829 | * side or larger than 128MB per side. |
| 830 | */ |
| 831 | struct dimm_size sz = spd_get_dimm_size(device); |
| 832 | if ((sz.side1 < 8)) { |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 833 | print_err("DIMMs smaller than 8MB per side\n" |
| 834 | "are not supported on this NB.\n"); |
| 835 | die("HALT\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 836 | } |
| 837 | if ((sz.side1 > 128)) { |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 838 | print_err("DIMMs > 128MB per side\n" |
| 839 | "are not supported on this NB\n"); |
| 840 | die("HALT\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* Divide size by 8 to set up the DRB registers. */ |
| 844 | drb += (sz.side1 / 8); |
| 845 | |
| 846 | /* |
| 847 | * Build the DRB for the next row in MSB so it gets |
| 848 | * placed in DRB[n+1] where it belongs when written |
| 849 | * as a 16-bit word. |
| 850 | */ |
| 851 | drb &= 0xff; |
| 852 | drb |= (drb + (sz.side2 / 8)) << 8; |
| 853 | } else { |
| 854 | #if 0 |
| 855 | PRINT_DEBUG("No DIMM found in slot "); |
| 856 | PRINT_DEBUG_HEX8(i); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 857 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 858 | #endif |
| 859 | |
| 860 | /* If there's no DIMM in the slot, set dra to 0x00. */ |
| 861 | dra = 0x00; |
| 862 | ecc = 0xc0; |
| 863 | /* Still have to propagate DRB over. */ |
| 864 | drb &= 0xff; |
| 865 | drb |= (drb << 8); |
| 866 | } |
| 867 | |
| 868 | pci_write_config16(NB, DRB + (2 * i), drb); |
| 869 | #if 0 |
| 870 | PRINT_DEBUG("DRB has been set to 0x"); |
| 871 | PRINT_DEBUG_HEX16(drb); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 872 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 873 | #endif |
| 874 | |
| 875 | /* Brings the upper DRB back down to be base for |
| 876 | * DRB calculations for the next two rows. |
| 877 | */ |
| 878 | drb >>= 8; |
| 879 | |
| 880 | rps |= (dra & 0x0f) << (i * 4); |
| 881 | nbxecc = (nbxecc >> 2) | (ecc & 0xc0); |
| 882 | } |
| 883 | |
| 884 | /* Set paging policy register. */ |
| 885 | pci_write_config8(NB, PGPOL + 1, bpr); |
| 886 | PRINT_DEBUG("PGPOL[BPR] has been set to 0x"); |
| 887 | PRINT_DEBUG_HEX8(bpr); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 888 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 889 | |
| 890 | /* Set DRAM row page size register. */ |
| 891 | pci_write_config16(NB, RPS, rps); |
| 892 | PRINT_DEBUG("RPS has been set to 0x"); |
| 893 | PRINT_DEBUG_HEX16(rps); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 894 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 895 | |
| 896 | /* ### ECC */ |
| 897 | pci_write_config8(NB, NBXCFG + 3, nbxecc); |
| 898 | PRINT_DEBUG("NBXECC[31:24] has been set to 0x"); |
| 899 | PRINT_DEBUG_HEX8(nbxecc); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 900 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 901 | |
| 902 | /* Set DRAMC[4:3] to proper memory type (EDO/SDRAM). |
| 903 | * TODO: Registered SDRAM support. |
| 904 | */ |
| 905 | edosd &= 0x07; |
| 906 | if (edosd & 0x02) { |
| 907 | edosd |= 0x00; |
| 908 | } else if (edosd & 0x04) { |
| 909 | edosd |= 0x08; |
| 910 | } |
| 911 | edosd &= 0x18; |
| 912 | |
| 913 | /* edosd is now in the form needed for DRAMC[4:3]. */ |
| 914 | value = pci_read_config8(NB, DRAMC) & 0xe7; |
| 915 | value |= edosd; |
| 916 | pci_write_config8(NB, DRAMC, value); |
| 917 | PRINT_DEBUG("DRAMC has been set to 0x"); |
| 918 | PRINT_DEBUG_HEX8(value); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 919 | PRINT_DEBUG("\n"); |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 922 | static void sdram_set_spd_registers(void) |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 923 | { |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 924 | /* Setup DRAM row boundary registers and other attributes. */ |
| 925 | set_dram_row_attributes(); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 926 | |
| 927 | /* TODO: Set SDRAMC. */ |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 928 | pci_write_config16(NB, SDRAMC, 0x0010); /* SDRAMPWR=1: 4 DIMM config */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 929 | |
Keith Hui | 59356ca | 2010-03-06 18:16:25 +0000 | [diff] [blame] | 930 | /* TODO */ |
| 931 | set_dram_buffer_strength(); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 932 | |
| 933 | /* TODO: Set PMCR? */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 934 | // pci_write_config8(NB, PMCR, 0x14); |
| 935 | pci_write_config8(NB, PMCR, 0x10); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 936 | |
| 937 | /* TODO? */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 938 | pci_write_config8(NB, DRAMT, 0x03); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 939 | } |
| 940 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 941 | static void sdram_enable(void) |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 942 | { |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 943 | int i; |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 944 | |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 945 | /* 0. Wait until power/voltages and clocks are stable (200us). */ |
| 946 | udelay(200); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 947 | |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 948 | /* 1. Apply NOP. Wait 200 clock cycles (200us should do). */ |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 949 | PRINT_DEBUG("RAM Enable 1: Apply NOP\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 950 | do_ram_command(RAM_COMMAND_NOP); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 951 | udelay(200); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 952 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 953 | /* 2. Precharge all. Wait tRP. */ |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 954 | PRINT_DEBUG("RAM Enable 2: Precharge all\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 955 | do_ram_command(RAM_COMMAND_PRECHARGE); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 956 | udelay(1); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 957 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 958 | /* 3. Perform 8 refresh cycles. Wait tRC each time. */ |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 959 | PRINT_DEBUG("RAM Enable 3: CBR\n"); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 960 | for (i = 0; i < 8; i++) { |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 961 | do_ram_command(RAM_COMMAND_CBR); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 962 | udelay(1); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 963 | } |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 964 | |
| 965 | /* 4. Mode register set. Wait two memory cycles. */ |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 966 | PRINT_DEBUG("RAM Enable 4: Mode register set\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 967 | do_ram_command(RAM_COMMAND_MRS); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 968 | udelay(2); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 969 | |
| 970 | /* 5. Normal operation. */ |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 971 | PRINT_DEBUG("RAM Enable 5: Normal operation\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame] | 972 | do_ram_command(RAM_COMMAND_NORMAL); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 973 | udelay(1); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 974 | |
| 975 | /* 6. Finally enable refresh. */ |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 976 | PRINT_DEBUG("RAM Enable 6: Enable refresh\n"); |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 977 | // pci_write_config8(NB, PMCR, 0x10); |
| 978 | spd_enable_refresh(); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 979 | udelay(1); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 980 | |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 981 | PRINT_DEBUG("Northbridge following SDRAM init:\n"); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 982 | DUMPNORTH(); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 983 | } |