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