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> |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (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 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 21 | #include <spd.h> |
| 22 | #include <sdram_mode.h> |
| 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" |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 26 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 27 | /*----------------------------------------------------------------------------- |
| 28 | Macros and definitions. |
| 29 | -----------------------------------------------------------------------------*/ |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 30 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 31 | /* Uncomment this to enable debugging output. */ |
| 32 | #define DEBUG_RAM_SETUP 1 |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 33 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 34 | /* Debugging macros. */ |
| 35 | #if defined(DEBUG_RAM_SETUP) |
| 36 | #define PRINT_DEBUG(x) print_debug(x) |
| 37 | #define PRINT_DEBUG_HEX8(x) print_debug_hex8(x) |
| 38 | #define PRINT_DEBUG_HEX16(x) print_debug_hex16(x) |
| 39 | #define PRINT_DEBUG_HEX32(x) print_debug_hex32(x) |
| 40 | #define DUMPNORTH() dump_pci_device(PCI_DEV(0, 0, 0)) |
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 | */ |
| 191 | // TODO |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 192 | PAM0, 0x00, 0x00, |
| 193 | PAM1, 0x00, 0x00, |
| 194 | PAM2, 0x00, 0x00, |
| 195 | PAM3, 0x00, 0x00, |
| 196 | PAM4, 0x00, 0x00, |
| 197 | PAM5, 0x00, 0x00, |
| 198 | PAM6, 0x00, 0x00, |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 199 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 200 | /* DRB[0:7] - DRAM Row Boundary Registers |
| 201 | * 0x60 - 0x67 |
| 202 | * |
| 203 | * An array of 8 byte registers, which hold the ending memory address |
| 204 | * assigned to each pair of DIMMs, in 8MB granularity. |
| 205 | * |
| 206 | * 0x60 DRB0 = Total memory in row0 (in 8 MB) |
| 207 | * 0x61 DRB1 = Total memory in row0+1 (in 8 MB) |
| 208 | * 0x62 DRB2 = Total memory in row0+1+2 (in 8 MB) |
| 209 | * 0x63 DRB3 = Total memory in row0+1+2+3 (in 8 MB) |
| 210 | * 0x64 DRB4 = Total memory in row0+1+2+3+4 (in 8 MB) |
| 211 | * 0x65 DRB5 = Total memory in row0+1+2+3+4+5 (in 8 MB) |
| 212 | * 0x66 DRB6 = Total memory in row0+1+2+3+4+5+6 (in 8 MB) |
| 213 | * 0x67 DRB7 = Total memory in row0+1+2+3+4+5+6+7 (in 8 MB) |
| 214 | */ |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 215 | /* Set the DRBs to zero for now, this will be fixed later. */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 216 | DRB0, 0x00, 0x00, |
| 217 | DRB1, 0x00, 0x00, |
| 218 | DRB2, 0x00, 0x00, |
| 219 | DRB3, 0x00, 0x00, |
| 220 | DRB4, 0x00, 0x00, |
| 221 | DRB5, 0x00, 0x00, |
| 222 | DRB6, 0x00, 0x00, |
| 223 | DRB7, 0x00, 0x00, |
| 224 | |
| 225 | /* FDHC - Fixed DRAM Hole Control Register |
| 226 | * 0x68 |
| 227 | * |
| 228 | * Controls two fixed DRAM holes: 512 KB - 640 KB and 15 MB - 16 MB. |
| 229 | * |
| 230 | * [7:6] Hole Enable (HEN) |
| 231 | * 00 = None |
| 232 | * 01 = 512 KB - 640 KB (128 KB) |
| 233 | * 10 = 15 MB - 16 MB (1 MB) |
| 234 | * 11 = Reserved |
| 235 | * [5:0] Reserved |
| 236 | */ |
| 237 | /* No memory holes. */ |
| 238 | FDHC, 0x00, 0x00, |
| 239 | |
| 240 | /* RPS - SDRAM Row Page Size Register |
| 241 | * 0x74 - 0x75 |
| 242 | * |
| 243 | * Sets the row page size for SDRAM. For EDO memory, the page |
| 244 | * size is fixed at 2 KB. |
| 245 | * |
| 246 | * [15:0] Page Size (PS) |
| 247 | * TODO |
| 248 | */ |
| 249 | // TODO |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 250 | RPS + 0, 0x00, 0x00, |
| 251 | RPS + 1, 0x00, 0x00, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 252 | |
| 253 | /* SDRAMC - SDRAM Control Register |
Uwe Hermann | 7ea18cf | 2007-05-04 00:51:17 +0000 | [diff] [blame] | 254 | * 0x76 - 0x77 |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 255 | * |
| 256 | * [15:10] Reserved |
| 257 | * [09:08] Idle/Pipeline DRAM Leadoff Timing (IPDLT) |
| 258 | * 00 = Illegal |
| 259 | * 01 = Add a clock delay to the lead-off clock count |
| 260 | * 10 = Illegal |
| 261 | * 11 = Illegal |
| 262 | * [07:05] SDRAM Mode Select (SMS) |
| 263 | * 000 = Normal SDRAM Operation (default) |
| 264 | * 001 = NOP Command Enable |
| 265 | * 010 = All Banks Precharge Enable |
| 266 | * 011 = Mode Register Set Enable |
| 267 | * 100 = CBR Enable |
| 268 | * 101 = Reserved |
| 269 | * 110 = Reserved |
| 270 | * 111 = Reserved |
| 271 | * [04:04] SDRAMPWR |
| 272 | * 0 = 3 DIMM configuration |
| 273 | * 1 = 4 DIMM configuration |
| 274 | * [03:03] Leadoff Command Timing (LCT) |
| 275 | * 0 = 4 CS# Clock |
| 276 | * 1 = 3 CS# Clock |
| 277 | * [02:02] CAS# Latency (CL) |
| 278 | * 0 = 3 DCLK CAS# latency |
| 279 | * 1 = 2 DCLK CAS# latency |
| 280 | * [01:01] SDRAM RAS# to CAS# Delay (SRCD) |
| 281 | * 0 = 3 clocks between a row activate and a read or write cmd. |
| 282 | * 1 = 2 clocks between a row activate and a read or write cmd. |
| 283 | * [00:00] SDRAM RAS# Precharge (SRP) |
| 284 | * 0 = 3 clocks of RAS# precharge |
| 285 | * 1 = 2 clocks of RAS# precharge |
| 286 | */ |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 287 | SDRAMC + 0, 0x00, 0x00, |
Mats Erik Andersson | 45db366 | 2008-09-30 04:52:29 +0000 | [diff] [blame] | 288 | SDRAMC + 1, 0x00, 0x00, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 289 | |
| 290 | /* PGPOL - Paging Policy Register |
| 291 | * 0x78 - 0x79 |
| 292 | * |
| 293 | * [15:08] Banks per Row (BPR) |
| 294 | * TODO |
| 295 | * 0 = 2 banks |
| 296 | * 1 = 4 banks |
| 297 | * [07:05] Reserved |
| 298 | * [04:04] Intel Reserved |
| 299 | * [03:00] DRAM Idle Timer (DIT) |
| 300 | * 0000 = 0 clocks |
| 301 | * 0001 = 2 clocks |
| 302 | * 0010 = 4 clocks |
| 303 | * 0011 = 8 clocks |
| 304 | * 0100 = 10 clocks |
| 305 | * 0101 = 12 clocks |
| 306 | * 0110 = 16 clocks |
| 307 | * 0111 = 32 clocks |
| 308 | * 1xxx = Infinite (pages are not closed for idle condition) |
| 309 | */ |
| 310 | // TODO |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 311 | PGPOL + 0, 0x00, 0x00, |
| 312 | PGPOL + 1, 0x00, 0xff, |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 313 | |
| 314 | /* PMCR - Power Management Control Register |
| 315 | * 0x7a |
| 316 | * |
| 317 | * [07:07] Power Down SDRAM Enable (PDSE) |
| 318 | * 1 = Enable |
| 319 | * 0 = Disable |
| 320 | * [06:06] ACPI Control Register Enable (SCRE) |
| 321 | * 1 = Enable |
| 322 | * 0 = Disable (default) |
| 323 | * [05:05] Suspend Refresh Type (SRT) |
| 324 | * 1 = Self refresh mode |
| 325 | * 0 = CBR fresh mode |
| 326 | * [04:04] Normal Refresh Enable (NREF_EN) |
| 327 | * 1 = Enable |
| 328 | * 0 = Disable |
| 329 | * [03:03] Quick Start Mode (QSTART) |
| 330 | * 1 = Quick start mode for the processor is enabled |
| 331 | * [02:02] Gated Clock Enable (GCLKEN) |
| 332 | * 1 = Enable |
| 333 | * 0 = Disable |
| 334 | * [01:01] AGP Disable (AGP_DIS) |
| 335 | * 1 = Disable |
| 336 | * 0 = Enable |
| 337 | * [00:00] CPU reset without PCIRST enable (CRst_En) |
| 338 | * 1 = Enable |
| 339 | * 0 = Disable |
| 340 | */ |
| 341 | /* Enable normal refresh and the gated clock. */ |
| 342 | // TODO: Only do this later? |
| 343 | // PMCR, 0x00, 0x14, |
| 344 | // PMCR, 0x00, 0x10, |
| 345 | PMCR, 0x00, 0x00, |
| 346 | }; |
| 347 | |
| 348 | /*----------------------------------------------------------------------------- |
| 349 | SDRAM configuration functions. |
| 350 | -----------------------------------------------------------------------------*/ |
| 351 | |
| 352 | /** |
| 353 | * Send the specified RAM command to all DIMMs. |
| 354 | * |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 355 | * @param command The RAM command to send to the DIMM(s). |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 356 | */ |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 357 | static void do_ram_command(u32 command) |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 358 | { |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 359 | int i, caslatency; |
| 360 | u8 dimm_start, dimm_end; |
| 361 | u16 reg16; |
| 362 | u32 addr, addr_offset; |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 363 | |
| 364 | /* Configure the RAM command. */ |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 365 | reg16 = pci_read_config16(NB, SDRAMC); |
| 366 | reg16 &= 0xff1f; /* Clear bits 7-5. */ |
| 367 | reg16 |= (u16) (command << 5); /* Write command into bits 7-5. */ |
| 368 | pci_write_config16(NB, SDRAMC, reg16); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 369 | |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 370 | /* |
| 371 | * RAM_COMMAND_NORMAL affects only the memory controller and |
| 372 | * doesn't need to be "sent" to the DIMMs. |
| 373 | */ |
| 374 | if (command == RAM_COMMAND_NORMAL) |
| 375 | return; |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 376 | |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 377 | /* Send the RAM command to each row of memory. */ |
| 378 | dimm_start = 0; |
| 379 | for (i = 0; i < (DIMM_SOCKETS * 2); i++) { |
| 380 | addr_offset = 0; |
| 381 | caslatency = 3; /* TODO: Dynamically get CAS latency later. */ |
| 382 | if (command == RAM_COMMAND_MRS) { |
| 383 | /* |
| 384 | * MAA[12:11,9:0] must be inverted when sent to DIMM |
| 385 | * 2 or 3 (no inversion if sent to DIMM 0 or 1). |
| 386 | */ |
| 387 | if ((i >= 0 && i <= 3) && caslatency == 3) |
| 388 | addr_offset = 0x1d0; |
| 389 | if ((i >= 4 && i <= 7) && caslatency == 3) |
| 390 | addr_offset = 0x1e28; |
| 391 | if ((i >= 0 && i <= 3) && caslatency == 2) |
| 392 | addr_offset = 0x150; |
| 393 | if ((i >= 4 && i <= 7) && caslatency == 2) |
| 394 | addr_offset = 0x1ea8; |
| 395 | } |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 396 | |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 397 | dimm_end = pci_read_config8(NB, DRB + i); |
| 398 | |
| 399 | addr = (dimm_start * 8 * 1024 * 1024) + addr_offset; |
| 400 | if (dimm_end > dimm_start) { |
| 401 | #if 0 |
| 402 | PRINT_DEBUG(" Sending RAM command 0x"); |
| 403 | PRINT_DEBUG_HEX16(reg16); |
| 404 | PRINT_DEBUG(" to 0x"); |
| 405 | PRINT_DEBUG_HEX32(addr); |
| 406 | PRINT_DEBUG("\r\n"); |
| 407 | #endif |
| 408 | |
| 409 | read32(addr); |
| 410 | } |
| 411 | |
| 412 | /* Set the start of the next DIMM. */ |
| 413 | dimm_start = dimm_end; |
| 414 | } |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 417 | /*----------------------------------------------------------------------------- |
| 418 | DIMM-independant configuration functions. |
| 419 | -----------------------------------------------------------------------------*/ |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 420 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 421 | static void spd_enable_refresh(void) |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 422 | { |
| 423 | int i, value; |
| 424 | uint8_t reg; |
| 425 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 426 | reg = pci_read_config8(NB, DRAMC); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 427 | |
| 428 | for (i = 0; i < DIMM_SOCKETS; i++) { |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 429 | value = spd_read_byte(DIMM_SPD_BASE + i, SPD_REFRESH); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 430 | if (value < 0) |
| 431 | continue; |
| 432 | reg = (reg & 0xf8) | refresh_rate_map[(value & 0x7f)]; |
| 433 | |
| 434 | PRINT_DEBUG(" Enabling refresh (DRAMC = 0x"); |
| 435 | PRINT_DEBUG_HEX8(reg); |
| 436 | PRINT_DEBUG(") for DIMM "); |
| 437 | PRINT_DEBUG_HEX8(i); |
| 438 | PRINT_DEBUG("\r\n"); |
| 439 | } |
| 440 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 441 | pci_write_config8(NB, DRAMC, reg); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 444 | /*----------------------------------------------------------------------------- |
| 445 | Public interface. |
| 446 | -----------------------------------------------------------------------------*/ |
| 447 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 448 | static void sdram_set_registers(void) |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 449 | { |
| 450 | int i, max; |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 451 | uint8_t reg; |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 452 | |
| 453 | PRINT_DEBUG("Northbridge prior to SDRAM init:\r\n"); |
| 454 | DUMPNORTH(); |
| 455 | |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 456 | max = ARRAY_SIZE(register_values); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 457 | |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 458 | /* Set registers as specified in the register_values[] array. */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 459 | for (i = 0; i < max; i += 3) { |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 460 | reg = pci_read_config8(NB, register_values[i]); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 461 | reg &= register_values[i + 1]; |
| 462 | reg |= register_values[i + 2] & ~(register_values[i + 1]); |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 463 | pci_write_config8(NB, register_values[i], reg); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 464 | |
| 465 | PRINT_DEBUG(" Set register 0x"); |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 466 | PRINT_DEBUG_HEX8(register_values[i]); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 467 | PRINT_DEBUG(" to 0x"); |
Uwe Hermann | bc359473 | 2007-06-07 22:16:30 +0000 | [diff] [blame] | 468 | PRINT_DEBUG_HEX8(reg); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 469 | PRINT_DEBUG("\r\n"); |
| 470 | } |
| 471 | } |
| 472 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 473 | static void sdram_set_spd_registers(void) |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 474 | { |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 475 | /* TODO: Don't hardcode the values here, get info via SPD. */ |
| 476 | |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 477 | /* Map all legacy regions to RAM (read/write). This is required if |
| 478 | * you want to use the RAM area from 768 KB - 1 MB. If the PAM |
| 479 | * registers are not set here appropriately, the RAM in that region |
| 480 | * will not be accessible, thus a RAM check of it will also fail. |
| 481 | */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 482 | pci_write_config8(NB, PAM0, 0x30); |
| 483 | pci_write_config8(NB, PAM1, 0x33); |
| 484 | pci_write_config8(NB, PAM2, 0x33); |
| 485 | pci_write_config8(NB, PAM3, 0x33); |
| 486 | pci_write_config8(NB, PAM4, 0x33); |
| 487 | pci_write_config8(NB, PAM5, 0x33); |
| 488 | pci_write_config8(NB, PAM6, 0x33); |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 489 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 490 | /* TODO: Set DRB0-DRB7. */ |
Uwe Hermann | f5a6fd2 | 2007-05-27 23:31:31 +0000 | [diff] [blame] | 491 | /* Currently this is hardcoded to one 64 MB DIMM in slot 0. */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 492 | pci_write_config8(NB, DRB0, 0x08); |
| 493 | pci_write_config8(NB, DRB1, 0x08); |
| 494 | pci_write_config8(NB, DRB2, 0x08); |
| 495 | pci_write_config8(NB, DRB3, 0x08); |
| 496 | pci_write_config8(NB, DRB4, 0x08); |
| 497 | pci_write_config8(NB, DRB5, 0x08); |
| 498 | pci_write_config8(NB, DRB6, 0x08); |
| 499 | pci_write_config8(NB, DRB7, 0x08); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 500 | |
| 501 | /* TODO: Set DRAMC. Don't enable refresh for now. */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 502 | pci_write_config8(NB, DRAMC, 0x08); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 503 | |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 504 | /* TODO: Set RPS. Needs to be fixed for multiple DIMM support. */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 505 | pci_write_config16(NB, RPS, 0x0001); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 506 | |
| 507 | /* TODO: Set SDRAMC. */ |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 508 | pci_write_config16(NB, SDRAMC, 0x0010); /* SDRAMPWR=1: 4 DIMM config */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 509 | |
| 510 | /* TODO: Set PGPOL. */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 511 | // pci_write_config16(NB, PGPOL, 0x0107); |
| 512 | pci_write_config16(NB, PGPOL, 0x0123); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 513 | |
| 514 | /* TODO: Set NBXCFG. */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 515 | // pci_write_config32(NB, NBXCFG, 0x0100220c); // FIXME? |
| 516 | pci_write_config32(NB, NBXCFG, 0xff00800c); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 517 | |
| 518 | /* TODO: Set PMCR? */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 519 | // pci_write_config8(NB, PMCR, 0x14); |
| 520 | pci_write_config8(NB, PMCR, 0x10); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 521 | |
| 522 | /* TODO? */ |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 523 | pci_write_config8(NB, PCI_LATENCY_TIMER, 0x40); |
| 524 | pci_write_config8(NB, DRAMT, 0x03); |
| 525 | pci_write_config8(NB, MBSC, 0x03); |
| 526 | pci_write_config8(NB, SCRR, 0x38); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 529 | static void sdram_enable(void) |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 530 | { |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 531 | int i; |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 532 | |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 533 | /* 0. Wait until power/voltages and clocks are stable (200us). */ |
| 534 | udelay(200); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 535 | |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 536 | /* 1. Apply NOP. Wait 200 clock cycles (200us should do). */ |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 537 | PRINT_DEBUG("RAM Enable 1: Apply NOP\r\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 538 | do_ram_command(RAM_COMMAND_NOP); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 539 | udelay(200); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 540 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 541 | /* 2. Precharge all. Wait tRP. */ |
| 542 | PRINT_DEBUG("RAM Enable 2: Precharge all\r\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 543 | do_ram_command(RAM_COMMAND_PRECHARGE); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 544 | udelay(1); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 545 | |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 546 | /* 3. Perform 8 refresh cycles. Wait tRC each time. */ |
| 547 | PRINT_DEBUG("RAM Enable 3: CBR\r\n"); |
| 548 | for (i = 0; i < 8; i++) { |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 549 | do_ram_command(RAM_COMMAND_CBR); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 550 | udelay(1); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 551 | } |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 552 | |
| 553 | /* 4. Mode register set. Wait two memory cycles. */ |
| 554 | PRINT_DEBUG("RAM Enable 4: Mode register set\r\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 555 | do_ram_command(RAM_COMMAND_MRS); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 556 | udelay(2); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 557 | |
| 558 | /* 5. Normal operation. */ |
| 559 | PRINT_DEBUG("RAM Enable 5: Normal operation\r\n"); |
Uwe Hermann | 8b643cea | 2008-12-09 16:36:12 +0000 | [diff] [blame^] | 560 | do_ram_command(RAM_COMMAND_NORMAL); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 561 | udelay(1); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 562 | |
| 563 | /* 6. Finally enable refresh. */ |
| 564 | PRINT_DEBUG("RAM Enable 6: Enable refresh\r\n"); |
Uwe Hermann | 1683cef | 2008-11-27 00:47:07 +0000 | [diff] [blame] | 565 | // pci_write_config8(NB, PMCR, 0x10); |
| 566 | spd_enable_refresh(); |
Uwe Hermann | 861f964 | 2007-05-28 14:37:06 +0000 | [diff] [blame] | 567 | udelay(1); |
Uwe Hermann | 1a9c892 | 2007-04-01 17:24:03 +0000 | [diff] [blame] | 568 | |
| 569 | PRINT_DEBUG("Northbridge following SDRAM init:\r\n"); |
| 570 | DUMPNORTH(); |
Richard Smith | cb8eab4 | 2006-07-24 04:25:47 +0000 | [diff] [blame] | 571 | } |