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