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