blob: 93a3a5b5a9f244e93b5e8b18523a8e9728cbab6e [file] [log] [blame]
Yinghai Lu70093f72004-07-01 03:55:03 +00001/* This was originally for the e7500, modified for e7501
Stefan Reinauer14e22772010-04-27 06:56:47 +00002 * The primary differences are that 7501 apparently can
Yinghai Lu70093f72004-07-01 03:55:03 +00003 * support single channel RAM (i haven't tested),
4 * CAS1.5 is no longer supported, The ECC scrubber
5 * now supports a mode to zero RAM and init ECC in one step
Stefan Reinauer14e22772010-04-27 06:56:47 +00006 * and the undocumented registers at 0x80 require new
Yinghai Lu70093f72004-07-01 03:55:03 +00007 * (undocumented) values determined by guesswork and
8 * comparison w/ OEM BIOS values.
9 * Steven James 02/06/2003
10 */
11
12/* converted to C 6/2004 yhlu */
13
Steven J. Magnania4baa162005-09-26 13:54:32 +000014#include <assert.h>
Julius Werner7a8a4ab2015-05-22 16:26:40 -070015#include <lib.h>
Steven J. Magnania4baa162005-09-26 13:54:32 +000016#include <spd.h>
17#include <sdram_mode.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000018#include <stdlib.h>
Steven J. Magnania4baa162005-09-26 13:54:32 +000019#include "e7501.h"
Yinghai Lu70093f72004-07-01 03:55:03 +000020
Uwe Hermannb69cb5a2010-10-26 22:46:43 +000021/*-----------------------------------------------------------------------------
22Definitions:
23-----------------------------------------------------------------------------*/
24
Stefan Reinauer14e22772010-04-27 06:56:47 +000025// Uncomment this to enable run-time checking of DIMM parameters
Steven J. Magnania4baa162005-09-26 13:54:32 +000026// for dual-channel operation
27// Unfortunately the code seems to chew up several K of space.
28//#define VALIDATE_DIMM_COMPATIBILITY
Yinghai Lu70093f72004-07-01 03:55:03 +000029
Uwe Hermann01ce6012010-03-05 10:03:50 +000030#if CONFIG_DEBUG_RAM_SETUP
Stefan Reinauer65b72ab2015-01-05 12:59:54 -080031#define RAM_DEBUG_MESSAGE(x) printk(BIOS_DEBUG, x)
32#define RAM_DEBUG_HEX32(x) printk(BIOS_DEBUG, "%08x", x)
33#define RAM_DEBUG_HEX8(x) printk(BIOS_DEBUG, "%02x", x)
Stefan Reinauer23836e22010-04-15 12:39:29 +000034#define DUMPNORTH() dump_pci_device(PCI_DEV(0, 0, 0))
Steven J. Magnania4baa162005-09-26 13:54:32 +000035#else
36#define RAM_DEBUG_MESSAGE(x)
37#define RAM_DEBUG_HEX32(x)
38#define RAM_DEBUG_HEX8(x)
39#define DUMPNORTH()
Yinghai Lu70093f72004-07-01 03:55:03 +000040#endif
41
Steven J. Magnania4baa162005-09-26 13:54:32 +000042#define E7501_SDRAM_MODE (SDRAM_BURST_INTERLEAVED | SDRAM_BURST_4)
Stefan Reinauer23836e22010-04-15 12:39:29 +000043#define SPD_ERROR "Error reading SPD info\n"
Yinghai Lu70093f72004-07-01 03:55:03 +000044
Steven J. Magnania4baa162005-09-26 13:54:32 +000045// NOTE: This used to be 0x100000.
Stefan Reinauer23836e22010-04-15 12:39:29 +000046// That doesn't work on systems where A20M# is asserted, because
47// attempts to access 0x1000NN end up accessing 0x0000NN.
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -080048#define RCOMP_MMIO ((u8 *)0x200000)
Yinghai Lu70093f72004-07-01 03:55:03 +000049
Steven J. Magnania4baa162005-09-26 13:54:32 +000050struct dimm_size {
Stefan Reinauer23836e22010-04-15 12:39:29 +000051 unsigned long side1;
52 unsigned long side2;
Steven J. Magnania4baa162005-09-26 13:54:32 +000053};
Yinghai Lu70093f72004-07-01 03:55:03 +000054
Stefan Reinauer23836e22010-04-15 12:39:29 +000055static const uint32_t refresh_frequency[] = {
Stefan Reinauer14e22772010-04-27 06:56:47 +000056 /* Relative frequency (array value) of each E7501 Refresh Mode Select
Steven J. Magnania4baa162005-09-26 13:54:32 +000057 * (RMS) value (array index)
58 * 0 == least frequent refresh (longest interval between refreshes)
Stefan Reinauer14e22772010-04-27 06:56:47 +000059 * [0] disabled -> 0
Steven J. Magnania4baa162005-09-26 13:54:32 +000060 * [1] 15.6 usec -> 2
61 * [2] 7.8 usec -> 3
62 * [3] 64 usec -> 1
63 * [4] reserved -> 0
64 * [5] reserved -> 0
65 * [6] reserved -> 0
66 * [7] 64 clocks -> 4
67 */
Stefan Reinauer23836e22010-04-15 12:39:29 +000068 0, 2, 3, 1, 0, 0, 0, 4
69};
Steven J. Magnania4baa162005-09-26 13:54:32 +000070
71static const uint32_t refresh_rate_map[] = {
Stefan Reinauer14e22772010-04-27 06:56:47 +000072 /* Map the JEDEC spd refresh rates (array index) to E7501 Refresh Mode
Steven J. Magnania4baa162005-09-26 13:54:32 +000073 * Select values (array value)
74 * These are all the rates defined by JESD21-C Appendix D, Rev. 1.0
Stefan Reinauer14e22772010-04-27 06:56:47 +000075 * The E7501 supports only 15.6 us (1), 7.8 us (2), 64 us (3), and
Steven J. Magnania4baa162005-09-26 13:54:32 +000076 * 64 clock (481 ns) (7) refresh.
77 * [0] == 15.625 us -> 15.6 us
Stefan Reinauer23836e22010-04-15 12:39:29 +000078 * [1] == 3.9 us -> 481 ns
Steven J. Magnania4baa162005-09-26 13:54:32 +000079 * [2] == 7.8 us -> 7.8 us
80 * [3] == 31.3 us -> 15.6 us
81 * [4] == 62.5 us -> 15.6 us
82 * [5] == 125 us -> 64 us
83 */
84 1, 7, 2, 1, 1, 3
85};
Yinghai Lu70093f72004-07-01 03:55:03 +000086
Stefan Reinauer23836e22010-04-15 12:39:29 +000087#define MAX_SPD_REFRESH_RATE ((sizeof(refresh_rate_map) / sizeof(uint32_t)) - 1)
Yinghai Lu70093f72004-07-01 03:55:03 +000088
Steven J. Magnania4baa162005-09-26 13:54:32 +000089// SPD parameters that must match for dual-channel operation
90static const uint8_t dual_channel_parameters[] = {
Stefan Reinauer23836e22010-04-15 12:39:29 +000091 SPD_MEMORY_TYPE,
92 SPD_MODULE_VOLTAGE,
93 SPD_NUM_COLUMNS,
94 SPD_NUM_ROWS,
95 SPD_NUM_DIMM_BANKS,
96 SPD_PRIMARY_SDRAM_WIDTH,
Uwe Hermann998a57c2006-11-22 11:41:32 +000097 SPD_NUM_BANKS_PER_SDRAM
Steven J. Magnania4baa162005-09-26 13:54:32 +000098};
Yinghai Lu70093f72004-07-01 03:55:03 +000099
100 /*
Stefan Reinauer23836e22010-04-15 12:39:29 +0000101 * Table: constant_register_values
Yinghai Lu70093f72004-07-01 03:55:03 +0000102 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000103static const long constant_register_values[] = {
Yinghai Lu70093f72004-07-01 03:55:03 +0000104 /* SVID - Subsystem Vendor Identification Register
105 * 0x2c - 0x2d
106 * [15:00] Subsytem Vendor ID (Indicates system board vendor)
107 */
108 /* SID - Subsystem Identification Register
109 * 0x2e - 0x2f
110 * [15:00] Subsystem ID
111 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000112 // Not everyone wants to be Super Micro Computer, Inc.
113 // The mainboard should set this if desired.
Stefan Reinauer14e22772010-04-27 06:56:47 +0000114 // 0x2c, 0, (0x15d9 << 0) | (0x3580 << 16),
Yinghai Lu70093f72004-07-01 03:55:03 +0000115
116 /* Undocumented
Steven J. Magnania4baa162005-09-26 13:54:32 +0000117 * (DRAM Read Timing Control, if similar to 855PM?)
118 * 0x80 - 0x81
Yinghai Lu70093f72004-07-01 03:55:03 +0000119 * This register has something to do with CAS latencies,
120 * possibily this is the real chipset control.
121 * At 0x00 CAS latency 1.5 works.
122 * At 0x06 CAS latency 2.5 works.
123 * At 0x01 CAS latency 2.0 works.
124 */
125 /* This is still undocumented in e7501, but with different values
126 * CAS 2.0 values taken from Intel BIOS settings, others are a guess
127 * and may be terribly wrong. Old values preserved as comments until I
128 * figure this out for sure.
Stefan Reinauer14e22772010-04-27 06:56:47 +0000129 * e7501 docs claim that CAS1.5 is unsupported, so it may or may not
Yinghai Lu70093f72004-07-01 03:55:03 +0000130 * work at all.
131 * Steven James 02/06/2003
132 */
Stefan Reinauer14e22772010-04-27 06:56:47 +0000133 /* NOTE: values now configured in configure_e7501_cas_latency() based
Steven J. Magnania4baa162005-09-26 13:54:32 +0000134 * on SPD info and total number of DIMMs (per Intel)
135 */
Yinghai Lu70093f72004-07-01 03:55:03 +0000136
137 /* FDHC - Fixed DRAM Hole Control
138 * 0x58
139 * [7:7] Hole_Enable
140 * 0 == No memory Hole
141 * 1 == Memory Hole from 15MB to 16MB
142 * [6:0] Reserved
143 *
144 * PAM - Programmable Attribute Map
145 * 0x59 [1:0] Reserved
146 * 0x59 [5:4] 0xF0000 - 0xFFFFF
147 * 0x5A [1:0] 0xC0000 - 0xC3FFF
148 * 0x5A [5:4] 0xC4000 - 0xC7FFF
149 * 0x5B [1:0] 0xC8000 - 0xCBFFF
150 * 0x5B [5:4] 0xCC000 - 0xCFFFF
151 * 0x5C [1:0] 0xD0000 - 0xD3FFF
152 * 0x5C [5:4] 0xD4000 - 0xD7FFF
153 * 0x5D [1:0] 0xD8000 - 0xDBFFF
154 * 0x5D [5:4] 0xDC000 - 0xDFFFF
155 * 0x5E [1:0] 0xE0000 - 0xE3FFF
156 * 0x5E [5:4] 0xE4000 - 0xE7FFF
157 * 0x5F [1:0] 0xE8000 - 0xEBFFF
158 * 0x5F [5:4] 0xEC000 - 0xEFFFF
159 * 00 == DRAM Disabled (All Access go to memory mapped I/O space)
160 * 01 == Read Only (Reads to DRAM, Writes to memory mapped I/O space)
161 * 10 == Write Only (Writes to DRAM, Reads to memory mapped I/O space)
162 * 11 == Normal (All Access go to DRAM)
163 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000164
165 // Map all legacy ranges to DRAM
Yinghai Lu70093f72004-07-01 03:55:03 +0000166 0x58, 0xcccccf7f, (0x00 << 0) | (0x30 << 8) | (0x33 << 16) | (0x33 << 24),
167 0x5C, 0xcccccccc, (0x33 << 0) | (0x33 << 8) | (0x33 << 16) | (0x33 << 24),
168
169 /* DRB - DRAM Row Boundary Registers
170 * 0x60 - 0x6F
171 * An array of 8 byte registers, which hold the ending
Stefan Reinauer14e22772010-04-27 06:56:47 +0000172 * memory address assigned to each pair of DIMMS, in 64MB
173 * granularity.
Yinghai Lu70093f72004-07-01 03:55:03 +0000174 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000175 // Conservatively say each row has 64MB of ram, we will fix this up later
176 // NOTE: These defaults allow us to prime all of the DIMMs on the board
Stefan Reinauer23836e22010-04-15 12:39:29 +0000177 // without jumping through 36-bit adddressing hoops, even if the
178 // total memory is > 4 GB. Changing these values may break do_ram_command()!
Yinghai Lu70093f72004-07-01 03:55:03 +0000179 0x60, 0x00000000, (0x01 << 0) | (0x02 << 8) | (0x03 << 16) | (0x04 << 24),
180 0x64, 0x00000000, (0x05 << 0) | (0x06 << 8) | (0x07 << 16) | (0x08 << 24),
Yinghai Lu70093f72004-07-01 03:55:03 +0000181
Stefan Reinauer14e22772010-04-27 06:56:47 +0000182 /* DRA - DRAM Row Attribute Register
Yinghai Lu70093f72004-07-01 03:55:03 +0000183 * 0x70 Row 0,1
184 * 0x71 Row 2,3
Stefan Reinauer23836e22010-04-15 12:39:29 +0000185 * 0x72 Row 4,5
Yinghai Lu70093f72004-07-01 03:55:03 +0000186 * 0x73 Row 6,7
187 * [7:7] Device width for Odd numbered rows
188 * 0 == 8 bits wide x8
189 * 1 == 4 bits wide x4
190 * [6:4] Row Attributes for Odd numbered rows
Steven J. Magnania4baa162005-09-26 13:54:32 +0000191 * 010 == 8KB (for dual-channel)
192 * 011 == 16KB (for dual-channel)
193 * 100 == 32KB (for dual-channel)
194 * 101 == 64KB (for dual-channel)
Yinghai Lu70093f72004-07-01 03:55:03 +0000195 * Others == Reserved
196 * [3:3] Device width for Even numbered rows
197 * 0 == 8 bits wide x8
198 * 1 == 4 bits wide x4
199 * [2:0] Row Attributes for Even numbered rows
Steven J. Magnania4baa162005-09-26 13:54:32 +0000200 * 010 == 8KB (for dual-channel)
201 * 011 == 16KB (for dual-channel)
202 * 100 == 32KB (for dual-channel)
Yinghai Lu70093f72004-07-01 03:55:03 +0000203 * 101 == 64KB (This page size appears broken)
204 * Others == Reserved
205 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000206 // NOTE: overridden by configure_e7501_row_attributes(), later
Steven J. Magnania4baa162005-09-26 13:54:32 +0000207 0x70, 0x00000000, 0,
Yinghai Lu70093f72004-07-01 03:55:03 +0000208
Steven J. Magnania4baa162005-09-26 13:54:32 +0000209 /* DRT - DRAM Timing Register
Yinghai Lu70093f72004-07-01 03:55:03 +0000210 * 0x78
211 * [31:30] Reserved
212 * [29:29] Back to Back Write-Read Turn Around
213 * 0 == 3 clocks between WR-RD commands
214 * 1 == 2 clocks between WR-RD commands
215 * [28:28] Back to Back Read-Write Turn Around
216 * 0 == 5 clocks between RD-WR commands
217 * 1 == 4 clocks between RD-WR commands
218 * [27:27] Back to Back Read Turn Around
219 * 0 == 4 clocks between RD commands
220 * 1 == 3 clocks between RD commands
221 * [26:24] Read Delay (tRD)
222 * 000 == 7 clocks
223 * 001 == 6 clocks
224 * 010 == 5 clocks
225 * Others == Reserved
226 * [23:19] Reserved
227 * [18:16] DRAM idle timer
Stefan Reinauer23836e22010-04-15 12:39:29 +0000228 * 000 == infinite
229 * 011 == 16 dram clocks
230 * 001 == 0 clocks
Yinghai Lu70093f72004-07-01 03:55:03 +0000231 * [15:11] Reserved
232 * [10:09] Active to Precharge (tRAS)
233 * 00 == 7 clocks
234 * 01 == 6 clocks
235 * 10 == 5 clocks
236 * 11 == Reserved
237 * [08:06] Reserved
238 * [05:04] Cas Latency (tCL)
239 * 00 == 2.5 Clocks
240 * 01 == 2.0 Clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +0000241 * 10 == Reserved (was 1.5 Clocks for E7500)
Yinghai Lu70093f72004-07-01 03:55:03 +0000242 * 11 == Reserved
243 * [03:03] Write Ras# to Cas# Delay (tRCD)
244 * 0 == 3 DRAM Clocks
245 * 1 == 2 DRAM Clocks
Stefan Reinauer23836e22010-04-15 12:39:29 +0000246 * [02:01] Read RAS# to CAS# Delay (tRCD)
247 * 00 == reserved
248 * 01 == reserved
Yinghai Lu70093f72004-07-01 03:55:03 +0000249 * 10 == 3 DRAM Clocks
250 * 11 == 2 DRAM Clocks
251 * [00:00] DRAM RAS# to Precharge (tRP)
252 * 0 == 3 DRAM Clocks
253 * 1 == 2 DRAM Clocks
254 */
Yinghai Lu70093f72004-07-01 03:55:03 +0000255
Stefan Reinauer23836e22010-04-15 12:39:29 +0000256 // Some earlier settings:
Yinghai Lu70093f72004-07-01 03:55:03 +0000257 /* Most aggressive settings possible */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000258// 0x78, 0xc0fff8c4, (1<<29)|(1<<28)|(1<<27)|(2<<24)|(2<<9)|CAS_LATENCY|(1<<3)|(1<<1)|(1<<0),
259// 0x78, 0xc0f8f8c0, (1<<29)|(1<<28)|(1<<27)|(1<<24)|(1<<16)|(2<<9)|CAS_LATENCY|(1<<3)|(3<<1)|(1<<0),
260// 0x78, 0xc0f8f9c0, (1<<29)|(1<<28)|(1<<27)|(1<<24)|(1<<16)|(2<<9)|CAS_LATENCY|(1<<3)|(3<<1)|(1<<0),
Steven J. Magnania4baa162005-09-26 13:54:32 +0000261
262 // The only things we need to set here are DRAM idle timer, Back-to-Back Read Turnaround, and
263 // Back-to-Back Write-Read Turnaround. All others are configured based on SPD.
Stefan Reinauer23836e22010-04-15 12:39:29 +0000264 0x78, 0xD7F8FFFF, (1 << 29) | (1 << 27) | (1 << 16),
Yinghai Lu70093f72004-07-01 03:55:03 +0000265
266 /* FIXME why was I attempting to set a reserved bit? */
267 /* 0x0100040f */
268
269 /* DRC - DRAM Contoller Mode Register
270 * 0x7c
271 * [31:30] Reserved
272 * [29:29] Initialization Complete
273 * 0 == Not Complete
274 * 1 == Complete
275 * [28:23] Reserved
Stefan Reinauer23836e22010-04-15 12:39:29 +0000276 * [22:22] Channels
277 * 0 == Single channel
278 * 1 == Dual Channel
Yinghai Lu70093f72004-07-01 03:55:03 +0000279 * [21:20] DRAM Data Integrity Mode
280 * 00 == Disabled, no ECC
281 * 01 == Reserved
282 * 10 == Error checking, using chip-kill, with correction
283 * 11 == Reserved
Steven J. Magnania4baa162005-09-26 13:54:32 +0000284 * [19:18] DRB Granularity (Read-Only)
285 * 00 == 32 MB quantities (single channel mode)
Stefan Reinauer23836e22010-04-15 12:39:29 +0000286 * 01 == 64 MB quantities (dual-channel mode)
287 * 10 == Reserved
288 * 11 == Reserved
289 * [17:17] (Intel Undocumented) should always be set to 1 (SJM: comment inconsistent with current setting, below)
Yinghai Lu70093f72004-07-01 03:55:03 +0000290 * [16:16] Command Per Clock - Address/Control Assertion Rule (CPC)
291 * 0 == 2n Rule
292 * 1 == 1n rule
293 * [15:11] Reserved
294 * [10:08] Refresh mode select
295 * 000 == Refresh disabled
296 * 001 == Refresh interval 15.6 usec
297 * 010 == Refresh interval 7.8 usec
298 * 011 == Refresh interval 64 usec
299 * 111 == Refresh every 64 clocks (fast refresh)
300 * [07:07] Reserved
301 * [06:04] Mode Select (SMS)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000302 * 000 == Reserved (was Self Refresh Mode in E7500)
Yinghai Lu70093f72004-07-01 03:55:03 +0000303 * 001 == NOP Command
304 * 010 == All Banks Precharge
305 * 011 == Mode Register Set
Stefan Reinauer23836e22010-04-15 12:39:29 +0000306 * 100 == Extended Mode Register Set
Yinghai Lu70093f72004-07-01 03:55:03 +0000307 * 101 == Reserved
308 * 110 == CBR Refresh
309 * 111 == Normal Operation
310 * [03:00] Reserved
311 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000312// .long 0x7c, 0xffcefcff, (1<<22)|(2 << 20)|(1 << 16)| (0 << 8),
313// .long 0x7c, 0xff8cfcff, (1<<22)|(2 << 20)|(1 << 17)|(1 << 16)| (0 << 8),
314// .long 0x7c, 0xff80fcff, (1<<22)|(2 << 20)|(1 << 18)|(1 << 17)|(1 << 16)| (0 << 8),
Yinghai Lu70093f72004-07-01 03:55:03 +0000315
Stefan Reinauer14e22772010-04-27 06:56:47 +0000316 // Default to dual-channel mode, ECC, 1-clock address/cmd hold
Steven J. Magnania4baa162005-09-26 13:54:32 +0000317 // NOTE: configure_e7501_dram_controller_mode() configures further
Stefan Reinauer23836e22010-04-15 12:39:29 +0000318 0x7c, 0xff8ef8ff, (1 << 22) | (2 << 20) | (1 << 16) | (0 << 8),
Yinghai Lu70093f72004-07-01 03:55:03 +0000319
Steven J. Magnania4baa162005-09-26 13:54:32 +0000320 /* Another Intel undocumented register
321 * 0x88 - 0x8B
Stefan Reinauer23836e22010-04-15 12:39:29 +0000322 * [31:31] Purpose unknown
323 * [26:26] Master DLL Reset?
324 * 0 == Normal operation?
325 * 1 == Reset?
326 * [07:07] Periodic memory recalibration?
327 * 0 == Disabled?
328 * 1 == Enabled?
329 * [04:04] Receive FIFO RE-Sync?
330 * 0 == Normal operation?
331 * 1 == Reset?
Steven J. Magnania4baa162005-09-26 13:54:32 +0000332 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000333 // NOTE: Some factory BIOSs don't do this.
334 // Doesn't seem to matter either way.
Steven J. Magnania4baa162005-09-26 13:54:32 +0000335 0x88, 0xffffff00, 0x80,
Yinghai Lu70093f72004-07-01 03:55:03 +0000336
337 /* CLOCK_DIS - CK/CK# Disable Register
338 * 0x8C
Steven J. Magnania4baa162005-09-26 13:54:32 +0000339 * [7:7] DDR Frequency
Stefan Reinauer23836e22010-04-15 12:39:29 +0000340 * 0 == 100 MHz (200 MHz data rate)
341 * 1 == 133 MHz (266 MHz data rate)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000342 * [6:4] Reserved
Yinghai Lu70093f72004-07-01 03:55:03 +0000343 * [3:3] CK3
344 * 0 == Enable
345 * 1 == Disable
346 * [2:2] CK2
347 * 0 == Enable
348 * 1 == Disable
349 * [1:1] CK1
350 * 0 == Enable
351 * 1 == Disable
352 * [0:0] CK0
353 * 0 == Enable
354 * 1 == Disable
355 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000356 // NOTE: Disable all clocks initially; turn ones we need back on
Stefan Reinauer23836e22010-04-15 12:39:29 +0000357 // in enable_e7501_clocks()
Yinghai Lu70093f72004-07-01 03:55:03 +0000358 0x8C, 0xfffffff0, 0xf,
359
360 /* TOLM - Top of Low Memory Register
361 * 0xC4 - 0xC5
362 * [15:11] Top of low memory (TOLM)
363 * The address below 4GB that should be treated as RAM,
364 * on a 128MB granularity.
365 * [10:00] Reserved
366 */
367 /* REMAPBASE - Remap Base Address Regsiter
368 * 0xC6 - 0xC7
369 * [15:10] Reserved
370 * [09:00] Remap Base Address [35:26] 64M aligned
371 * Bits [25:0] are assumed to be 0.
372 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000373
374 // NOTE: TOLM overridden by configure_e7501_ram_addresses()
Yinghai Lu70093f72004-07-01 03:55:03 +0000375 0xc4, 0xfc0007ff, (0x2000 << 0) | (0x3ff << 16),
Steven J. Magnania4baa162005-09-26 13:54:32 +0000376
Yinghai Lu70093f72004-07-01 03:55:03 +0000377 /* REMAPLIMIT - Remap Limit Address Register
378 * 0xC8 - 0xC9
379 * [15:10] Reserved
380 * [09:00] Remap Limit Address [35:26] 64M aligned
Steven J. Magnania4baa162005-09-26 13:54:32 +0000381 * When remaplimit < remapbase the remap window is disabled.
Yinghai Lu70093f72004-07-01 03:55:03 +0000382 */
383 0xc8, 0xfffffc00, 0,
384
385 /* DVNP - Device Not Present Register
386 * 0xE0 - 0xE1
387 * [15:05] Reserved
Stefan Reinauer23836e22010-04-15 12:39:29 +0000388 * [04:04] Device 4 Function 1 Present
Yinghai Lu70093f72004-07-01 03:55:03 +0000389 * 0 == Present
390 * 1 == Absent
Stefan Reinauer23836e22010-04-15 12:39:29 +0000391 * [03:03] Device 3 Function 1 Present
Yinghai Lu70093f72004-07-01 03:55:03 +0000392 * 0 == Present
393 * 1 == Absent
Stefan Reinauer23836e22010-04-15 12:39:29 +0000394 * [02:02] Device 2 Function 1 Present
Yinghai Lu70093f72004-07-01 03:55:03 +0000395 * 0 == Present
396 * 1 == Absent
Stefan Reinauer23836e22010-04-15 12:39:29 +0000397 * [01:01] Reserved
398 * [00:00] Device 0 Function 1 Present
Yinghai Lu70093f72004-07-01 03:55:03 +0000399 * 0 == Present
400 * 1 == Absent
401 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000402
403 // Enable D0:D1, disable D2:F1, D3:F1, D4:F1
Stefan Reinauer23836e22010-04-15 12:39:29 +0000404 0xe0, 0xffffffe2, (1 << 4) | (1 << 3) | (1 << 2) | (0 << 0),
Steven J. Magnania4baa162005-09-26 13:54:32 +0000405
406 // Undocumented
Yinghai Lu70093f72004-07-01 03:55:03 +0000407 0xd8, 0xffff9fff, 0x00000000,
Steven J. Magnania4baa162005-09-26 13:54:32 +0000408
409 // Undocumented - this is pure conjecture based on similarity to 855PM
410 /* MCHTST - MCH Test Register
411 * 0xF4 - 0xF7
412 * [31:31] Purpose unknown
413 * [30:30] Purpose unknown
414 * [29:23] Unknown - not used?
Stefan Reinauer23836e22010-04-15 12:39:29 +0000415 * [22:22] System Memory MMR Enable
Steven J. Magnania4baa162005-09-26 13:54:32 +0000416 * 0 == Disable: mem space and BAR at 0x14 are not accessible
417 * 1 == Enable: mem space and BAR at 0x14 are accessible
418 * [21:20] Purpose unknown
Stefan Reinauer23836e22010-04-15 12:39:29 +0000419 * [19:02] Unknown - not used?
420 * [01:01] D6EN (Device #6 enable)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000421 * 0 == Disable
422 * 1 == Enable
Stefan Reinauer23836e22010-04-15 12:39:29 +0000423 * [00:00] Unknown - not used?
Steven J. Magnania4baa162005-09-26 13:54:32 +0000424 */
425
Yinghai Lu70093f72004-07-01 03:55:03 +0000426 0xf4, 0x3f8ffffd, 0x40300002,
Steven J. Magnania4baa162005-09-26 13:54:32 +0000427
428#ifdef SUSPICIOUS_LOOKING_CODE
Stefan Reinauer14e22772010-04-27 06:56:47 +0000429 // SJM: Undocumented.
Stefan Reinauer23836e22010-04-15 12:39:29 +0000430 // This will access D2:F0:0x50, is this correct??
Steven J. Magnania4baa162005-09-26 13:54:32 +0000431 0x1050, 0xffffffcf, 0x00000030,
432#endif
Yinghai Lu70093f72004-07-01 03:55:03 +0000433};
434
Steven J. Magnania4baa162005-09-26 13:54:32 +0000435 /* DDR RECOMP tables */
Yinghai Lu70093f72004-07-01 03:55:03 +0000436
Steven J. Magnania4baa162005-09-26 13:54:32 +0000437// Slew table for 1x drive?
438static const uint32_t maybe_1x_slew_table[] = {
Yinghai Lu70093f72004-07-01 03:55:03 +0000439 0x44332211, 0xc9776655, 0xffffffff, 0xffffffff,
440 0x22111111, 0x55444332, 0xfffca876, 0xffffffff,
441};
Steven J. Magnania4baa162005-09-26 13:54:32 +0000442
443// Slew table for 2x drive?
444static const uint32_t maybe_2x_slew_table[] = {
Yinghai Lu70093f72004-07-01 03:55:03 +0000445 0x00000000, 0x76543210, 0xffffeca8, 0xffffffff,
446 0x21000000, 0xa8765432, 0xffffffec, 0xffffffff,
447};
Steven J. Magnania4baa162005-09-26 13:54:32 +0000448
449// Pull Up / Pull Down offset table, if analogous to IXP2800?
450static const uint32_t maybe_pull_updown_offset_table[] = {
Yinghai Lu70093f72004-07-01 03:55:03 +0000451 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff,
452 0x88888888, 0x88888888, 0x88888888, 0x88888888,
453};
454
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000455/*-----------------------------------------------------------------------------
456Delay functions:
457-----------------------------------------------------------------------------*/
458
Stefan Reinauer23836e22010-04-15 12:39:29 +0000459#define SLOW_DOWN_IO inb(0x80)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000460//#define SLOW_DOWN_IO udelay(40);
Yinghai Lu70093f72004-07-01 03:55:03 +0000461
Stefan Reinauer23836e22010-04-15 12:39:29 +0000462 /* Estimate that SLOW_DOWN_IO takes about 50&76us */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000463 /* delay for 200us */
arch import user (historical)6ca76362005-07-06 17:17:25 +0000464
465#if 1
466static void do_delay(void)
467{
Steven J. Magnania4baa162005-09-26 13:54:32 +0000468 int i;
Stefan Reinauer23836e22010-04-15 12:39:29 +0000469 for (i = 0; i < 16; i++) {
470 SLOW_DOWN_IO;
471 }
arch import user (historical)6ca76362005-07-06 17:17:25 +0000472}
Stefan Reinauer23836e22010-04-15 12:39:29 +0000473
474#define DO_DELAY do_delay()
arch import user (historical)6ca76362005-07-06 17:17:25 +0000475#else
476#define DO_DELAY \
Stefan Reinauer23836e22010-04-15 12:39:29 +0000477 udelay(200)
478#endif
arch import user (historical)6ca76362005-07-06 17:17:25 +0000479
480#define EXTRA_DELAY DO_DELAY
481
Steven J. Magnania4baa162005-09-26 13:54:32 +0000482static void die_on_spd_error(int spd_return_value)
483{
484 if (spd_return_value < 0)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000485 die("Error reading SPD info\n");
Yinghai Lu70093f72004-07-01 03:55:03 +0000486}
487
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000488/*-----------------------------------------------------------------------------
489Serial presence detect (SPD) functions:
490-----------------------------------------------------------------------------*/
491
492/**
493 * Calculate the page size for each physical bank of the DIMM:
494 * log2(page size) = (# columns) + log2(data width)
495 *
496 * NOTE: Page size is the total number of data bits in a row.
497 *
498 * @param dimm_socket_address SMBus address of DIMM socket to interrogate.
499 * @return log2(page size) for each side of the DIMM.
500 */
501static struct dimm_size sdram_spd_get_page_size(uint16_t dimm_socket_address)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000502{
503 uint16_t module_data_width;
Yinghai Lu70093f72004-07-01 03:55:03 +0000504 int value;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000505 struct dimm_size pgsz;
Yinghai Lu70093f72004-07-01 03:55:03 +0000506
507 pgsz.side1 = 0;
Stefan Reinauer23836e22010-04-15 12:39:29 +0000508 pgsz.side2 = 0;
509
Steven J. Magnania4baa162005-09-26 13:54:32 +0000510 // Side 1
Stefan Reinauer23836e22010-04-15 12:39:29 +0000511 value = spd_read_byte(dimm_socket_address, SPD_NUM_COLUMNS);
512 if (value < 0)
513 goto hw_err;
514 pgsz.side1 = value & 0xf; // # columns in bank 1
515
Yinghai Lu70093f72004-07-01 03:55:03 +0000516 /* Get the module data width and convert it to a power of two */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000517 value =
518 spd_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_MSB);
519 if (value < 0)
520 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000521 module_data_width = (value & 0xff) << 8;
Yinghai Lu70093f72004-07-01 03:55:03 +0000522
Stefan Reinauer23836e22010-04-15 12:39:29 +0000523 value =
524 spd_read_byte(dimm_socket_address, SPD_MODULE_DATA_WIDTH_LSB);
525 if (value < 0)
526 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000527 module_data_width |= (value & 0xff);
Yinghai Lu70093f72004-07-01 03:55:03 +0000528
Steven J. Magnania4baa162005-09-26 13:54:32 +0000529 pgsz.side1 += log2(module_data_width);
Yinghai Lu70093f72004-07-01 03:55:03 +0000530
531 /* side two */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000532 value = spd_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS);
Stefan Reinauer23836e22010-04-15 12:39:29 +0000533 if (value < 0)
534 goto hw_err;
535 if (value > 2)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000536 die("Bad SPD value\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +0000537 if (value == 2) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000538
Stefan Reinauer23836e22010-04-15 12:39:29 +0000539 pgsz.side2 = pgsz.side1; // Assume symmetric banks until we know differently
540 value =
541 spd_read_byte(dimm_socket_address, SPD_NUM_COLUMNS);
542 if (value < 0)
543 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000544 if ((value & 0xf0) != 0) {
545 // Asymmetric banks
Stefan Reinauer23836e22010-04-15 12:39:29 +0000546 pgsz.side2 -= value & 0xf; /* Subtract out columns on side 1 */
547 pgsz.side2 += (value >> 4) & 0xf; /* Add in columns on side 2 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000548 }
549 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000550
Stefan Reinauer23836e22010-04-15 12:39:29 +0000551 return pgsz;
Yinghai Lu70093f72004-07-01 03:55:03 +0000552
Stefan Reinauer23836e22010-04-15 12:39:29 +0000553 hw_err:
Steven J. Magnania4baa162005-09-26 13:54:32 +0000554 die(SPD_ERROR);
Stefan Reinauer23836e22010-04-15 12:39:29 +0000555 return pgsz; // Never reached
Yinghai Lu70093f72004-07-01 03:55:03 +0000556}
Yinghai Lu70093f72004-07-01 03:55:03 +0000557
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000558/**
559 * Read the width in bits of each DIMM side's DRAMs via SPD (i.e. 4, 8, 16).
560 *
561 * @param dimm_socket_address SMBus address of DIMM socket to interrogate.
562 * @return Width in bits of each DIMM side's DRAMs.
563 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000564static struct dimm_size sdram_spd_get_width(uint16_t dimm_socket_address)
Yinghai Lu70093f72004-07-01 03:55:03 +0000565{
Steven J. Magnania4baa162005-09-26 13:54:32 +0000566 int value;
567 struct dimm_size width;
Stefan Reinauer23836e22010-04-15 12:39:29 +0000568
Steven J. Magnania4baa162005-09-26 13:54:32 +0000569 width.side1 = 0;
570 width.side2 = 0;
Yinghai Lu70093f72004-07-01 03:55:03 +0000571
Stefan Reinauer23836e22010-04-15 12:39:29 +0000572 value =
573 spd_read_byte(dimm_socket_address, SPD_PRIMARY_SDRAM_WIDTH);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000574 die_on_spd_error(value);
Stefan Reinauer23836e22010-04-15 12:39:29 +0000575
576 width.side1 = value & 0x7f; // Mask off bank 2 flag
Steven J. Magnania4baa162005-09-26 13:54:32 +0000577
578 if (value & 0x80) {
579 width.side2 = width.side1 << 1; // Bank 2 exists and is double-width
580 } else {
581 // If bank 2 exists, it's the same width as bank 1
Stefan Reinauer23836e22010-04-15 12:39:29 +0000582 value =
583 spd_read_byte(dimm_socket_address, SPD_NUM_DIMM_BANKS);
584 die_on_spd_error(value);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000585
586#ifdef ROMCC_IF_BUG_FIXED
587 if (value == 2)
588 width.side2 = width.side1;
589#else
590 switch (value) {
591 case 2:
592 width.side2 = width.side1;
593 break;
594
595 default:
596 break;
597 }
598#endif
599 }
600
601 return width;
602}
Stefan Reinauer23836e22010-04-15 12:39:29 +0000603
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000604/**
605 * Calculate the log base 2 size in bits of both DIMM sides.
606 *
607 * log2(# bits) = (# columns) + log2(data width) +
608 * (# rows) + log2(banks per SDRAM)
609 *
610 * Note that it might be easier to use SPD byte 31 here, it has the DIMM size
611 * as a multiple of 4MB. The way we do it now we can size both sides of an
612 * asymmetric DIMM.
613 *
614 * @param dimm_socket_address SMBus address of DIMM socket to interrogate.
615 * @return log2(number of bits) for each side of the DIMM.
616 */
Steven J. Magnania4baa162005-09-26 13:54:32 +0000617static struct dimm_size spd_get_dimm_size(unsigned dimm_socket_address)
618{
Stefan Reinauer23836e22010-04-15 12:39:29 +0000619 int value;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000620
621 // Start with log2(page size)
Stefan Reinauer23836e22010-04-15 12:39:29 +0000622 struct dimm_size sz = sdram_spd_get_page_size(dimm_socket_address);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000623
624 if (sz.side1 > 0) {
625
626 value = spd_read_byte(dimm_socket_address, SPD_NUM_ROWS);
627 die_on_spd_error(value);
628
Stefan Reinauer23836e22010-04-15 12:39:29 +0000629 sz.side1 += value & 0xf;
Yinghai Lu70093f72004-07-01 03:55:03 +0000630
Steven J. Magnania4baa162005-09-26 13:54:32 +0000631 if (sz.side2 > 0) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000632
Steven J. Magnania4baa162005-09-26 13:54:32 +0000633 // Double-sided DIMM
634 if (value & 0xF0)
Stefan Reinauer23836e22010-04-15 12:39:29 +0000635 sz.side2 += value >> 4; // Asymmetric
Steven J. Magnania4baa162005-09-26 13:54:32 +0000636 else
Stefan Reinauer23836e22010-04-15 12:39:29 +0000637 sz.side2 += value; // Symmetric
Steven J. Magnania4baa162005-09-26 13:54:32 +0000638 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000639
Stefan Reinauer23836e22010-04-15 12:39:29 +0000640 value =
641 spd_read_byte(dimm_socket_address,
642 SPD_NUM_BANKS_PER_SDRAM);
643 die_on_spd_error(value);
Yinghai Lu70093f72004-07-01 03:55:03 +0000644
Steven J. Magnania4baa162005-09-26 13:54:32 +0000645 value = log2(value);
Stefan Reinauer23836e22010-04-15 12:39:29 +0000646 sz.side1 += value;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000647 if (sz.side2 > 0)
Stefan Reinauer23836e22010-04-15 12:39:29 +0000648 sz.side2 += value;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000649 }
Yinghai Lu70093f72004-07-01 03:55:03 +0000650
Steven J. Magnania4baa162005-09-26 13:54:32 +0000651 return sz;
Yinghai Lu70093f72004-07-01 03:55:03 +0000652}
653
Stefan Reinauer23836e22010-04-15 12:39:29 +0000654#ifdef VALIDATE_DIMM_COMPATIBILITY
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000655
656/**
657 * Determine whether two DIMMs have the same value for an SPD parameter.
658 *
659 * @param spd_byte_number The SPD byte number to compare in both DIMMs.
660 * @param dimm0_address SMBus address of the 1st DIMM socket to interrogate.
661 * @param dimm1_address SMBus address of the 2nd DIMM socket to interrogate.
662 * @return 1 if both DIMM sockets report the same value for the specified
663 * SPD parameter, 0 if the values differed or an error occurred.
664 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000665static uint8_t are_spd_values_equal(uint8_t spd_byte_number,
666 uint16_t dimm0_address,
667 uint16_t dimm1_address)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000668{
669 uint8_t bEqual = 0;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000670 int dimm0_value = spd_read_byte(dimm0_address, spd_byte_number);
671 int dimm1_value = spd_read_byte(dimm1_address, spd_byte_number);
Yinghai Lu70093f72004-07-01 03:55:03 +0000672
Stefan Reinauer23836e22010-04-15 12:39:29 +0000673 if ((dimm0_value >= 0) && (dimm1_value >= 0)
674 && (dimm0_value == dimm1_value))
Steven J. Magnania4baa162005-09-26 13:54:32 +0000675 bEqual = 1;
Yinghai Lu70093f72004-07-01 03:55:03 +0000676
Steven J. Magnania4baa162005-09-26 13:54:32 +0000677 return bEqual;
678}
Stefan Reinauer23836e22010-04-15 12:39:29 +0000679#endif
Yinghai Lu70093f72004-07-01 03:55:03 +0000680
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000681/**
682 * Scan for compatible DIMMs.
683 *
684 * The code in this module only supports dual-channel operation, so we test
685 * that compatible DIMMs are paired.
686 *
687 * @param ctrl PCI addresses of memory controller functions, and SMBus
688 * addresses of DIMM slots on the mainboard.
689 * @return A bitmask indicating which of the possible sockets for each channel
690 * was found to contain a compatible DIMM.
691 * Bit 0 corresponds to the closest socket for channel 0
692 * Bit 1 to the next socket for channel 0
693 * ...
694 * Bit MAX_DIMM_SOCKETS_PER_CHANNEL-1 to the last socket for channel 0
695 * Bit MAX_DIMM_SOCKETS_PER_CHANNEL is the closest socket for channel 1
696 * ...
697 * Bit 2*MAX_DIMM_SOCKETS_PER_CHANNEL-1 is the last socket for channel 1
698 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000699static uint8_t spd_get_supported_dimms(const struct mem_controller *ctrl)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000700{
701 int i;
702 uint8_t dimm_mask = 0;
Yinghai Lu70093f72004-07-01 03:55:03 +0000703
Steven J. Magnania4baa162005-09-26 13:54:32 +0000704 // Have to increase size of dimm_mask if this assertion is violated
705 ASSERT(MAX_DIMM_SOCKETS_PER_CHANNEL <= 4);
Yinghai Lu70093f72004-07-01 03:55:03 +0000706
Steven J. Magnania4baa162005-09-26 13:54:32 +0000707 // Find DIMMs we can support on channel 0.
708 // Then see if the corresponding channel 1 DIMM has the same parameters,
709 // since we only support dual-channel.
Yinghai Lu70093f72004-07-01 03:55:03 +0000710
Stefan Reinauer23836e22010-04-15 12:39:29 +0000711 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
Steven J. Magnania4baa162005-09-26 13:54:32 +0000712
Stefan Reinauer23836e22010-04-15 12:39:29 +0000713 uint16_t channel0_dimm = ctrl->channel0[i];
Steven J. Magnania4baa162005-09-26 13:54:32 +0000714 uint16_t channel1_dimm = ctrl->channel1[i];
715 uint8_t bDualChannel = 1;
Stefan Reinauer23836e22010-04-15 12:39:29 +0000716#ifdef VALIDATE_DIMM_COMPATIBILITY
717 struct dimm_size page_size;
718 struct dimm_size sdram_width;
719#endif
Steven J. Magnania4baa162005-09-26 13:54:32 +0000720 int spd_value;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000721
722 if (channel0_dimm == 0)
Stefan Reinauer23836e22010-04-15 12:39:29 +0000723 continue; // No such socket on this mainboard
Steven J. Magnania4baa162005-09-26 13:54:32 +0000724
Stefan Reinauer23836e22010-04-15 12:39:29 +0000725 if (spd_read_byte(channel0_dimm, SPD_MEMORY_TYPE) !=
726 SPD_MEMORY_TYPE_SDRAM_DDR)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000727 continue;
728
729#ifdef VALIDATE_DIMM_COMPATIBILITY
Stefan Reinauer23836e22010-04-15 12:39:29 +0000730 if (spd_read_byte(channel0_dimm, SPD_MODULE_VOLTAGE) !=
731 SPD_VOLTAGE_SSTL2)
732 continue; // Unsupported voltage
Steven J. Magnania4baa162005-09-26 13:54:32 +0000733
734 // E7501 does not support unregistered DIMMs
Stefan Reinauer23836e22010-04-15 12:39:29 +0000735 spd_value =
736 spd_read_byte(channel0_dimm, SPD_MODULE_ATTRIBUTES);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000737 if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0))
738 continue;
Stefan Reinauer23836e22010-04-15 12:39:29 +0000739
740 // Must support burst = 4 for dual-channel operation on E7501
Steven J. Magnania4baa162005-09-26 13:54:32 +0000741 // NOTE: for single-channel, burst = 8 is required
Stefan Reinauer23836e22010-04-15 12:39:29 +0000742 spd_value =
743 spd_read_byte(channel0_dimm,
744 SPD_SUPPORTED_BURST_LENGTHS);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000745 if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0))
746 continue;
747
Stefan Reinauer23836e22010-04-15 12:39:29 +0000748 page_size = sdram_spd_get_page_size(channel0_dimm);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000749 sdram_width = sdram_spd_get_width(channel0_dimm);
750
751 // Validate DIMM page size
752 // The E7501 only supports page sizes of 4, 8, 16, or 32 KB per channel
753 // NOTE: 4 KB = 32 Kb = 2^15
Stefan Reinauer23836e22010-04-15 12:39:29 +0000754 // 32 KB = 262 Kb = 2^18
Steven J. Magnania4baa162005-09-26 13:54:32 +0000755
756 if ((page_size.side1 < 15) || (page_size.side1 > 18))
757 continue;
758
759 // If DIMM is double-sided, verify side2 page size
Stefan Reinauer23836e22010-04-15 12:39:29 +0000760 if (page_size.side2 != 0) {
761 if ((page_size.side2 < 15)
762 || (page_size.side2 > 18))
Steven J. Magnania4baa162005-09-26 13:54:32 +0000763 continue;
764 }
Steven J. Magnania4baa162005-09-26 13:54:32 +0000765 // Validate SDRAM width
766 // The E7501 only supports x4 and x8 devices
767
768 if ((sdram_width.side1 != 4) && (sdram_width.side1 != 8))
769 continue;
770
771 // If DIMM is double-sided, verify side2 width
Stefan Reinauer23836e22010-04-15 12:39:29 +0000772 if (sdram_width.side2 != 0) {
773 if ((sdram_width.side2 != 4)
774 && (sdram_width.side2 != 8))
Steven J. Magnania4baa162005-09-26 13:54:32 +0000775 continue;
776 }
Stefan Reinauer23836e22010-04-15 12:39:29 +0000777#endif
Steven J. Magnania4baa162005-09-26 13:54:32 +0000778 // Channel 0 DIMM looks compatible.
779 // Now see if it is paired with the proper DIMM on channel 1.
780
Stefan Reinauer23836e22010-04-15 12:39:29 +0000781 ASSERT(channel1_dimm != 0); // No such socket on this mainboard??
Steven J. Magnania4baa162005-09-26 13:54:32 +0000782
783 // NOTE: unpopulated DIMMs cause read to fail
Stefan Reinauer23836e22010-04-15 12:39:29 +0000784 spd_value =
785 spd_read_byte(channel1_dimm, SPD_MODULE_ATTRIBUTES);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000786 if (!(spd_value & MODULE_REGISTERED) || (spd_value < 0)) {
Stefan Reinauer23836e22010-04-15 12:39:29 +0000787
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800788 printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +0000789 continue;
790 }
Steven J. Magnania4baa162005-09-26 13:54:32 +0000791#ifdef VALIDATE_DIMM_COMPATIBILITY
Stefan Reinauer23836e22010-04-15 12:39:29 +0000792 spd_value =
793 spd_read_byte(channel1_dimm,
794 SPD_SUPPORTED_BURST_LENGTHS);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000795 if (!(spd_value & SPD_BURST_LENGTH_4) || (spd_value < 0))
796 continue;
Yinghai Lu70093f72004-07-01 03:55:03 +0000797
Stefan Reinauer23836e22010-04-15 12:39:29 +0000798 int j;
799 for (j = 0; j < sizeof(dual_channel_parameters); ++j) {
800 if (!are_spd_values_equal
801 (dual_channel_parameters[j], channel0_dimm,
802 channel1_dimm)) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000803
Steven J. Magnania4baa162005-09-26 13:54:32 +0000804 bDualChannel = 0;
805 break;
Yinghai Lu70093f72004-07-01 03:55:03 +0000806 }
807 }
arch import user (historical)6ca76362005-07-06 17:17:25 +0000808#endif
Yinghai Lu70093f72004-07-01 03:55:03 +0000809
Steven J. Magnania4baa162005-09-26 13:54:32 +0000810 // Code around ROMCC bug in optimization of "if" statements
811#ifdef ROMCC_IF_BUG_FIXED
812 if (bDualChannel) {
813 // Made it through all the checks, this DIMM pair is usable
Stefan Reinauer23836e22010-04-15 12:39:29 +0000814 dimm_mask |= ((1 << i) | (1 << (MAX_DIMM_SOCKETS_PER_CHANNEL + i)));
815 } else
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800816 printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +0000817#else
818 switch (bDualChannel) {
819 case 0:
Stefan Reinauer65b72ab2015-01-05 12:59:54 -0800820 printk(BIOS_DEBUG, "Skipping un-matched DIMMs - only dual-channel operation supported\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +0000821 break;
Stefan Reinauer23836e22010-04-15 12:39:29 +0000822
Steven J. Magnania4baa162005-09-26 13:54:32 +0000823 default:
824 // Made it through all the checks, this DIMM pair is usable
Stefan Reinauer23836e22010-04-15 12:39:29 +0000825 dimm_mask |= (1 << i) | (1 << (MAX_DIMM_SOCKETS_PER_CHANNEL + i));
Steven J. Magnania4baa162005-09-26 13:54:32 +0000826 break;
Yinghai Lu70093f72004-07-01 03:55:03 +0000827 }
Stefan Reinauer23836e22010-04-15 12:39:29 +0000828#endif
Yinghai Lu70093f72004-07-01 03:55:03 +0000829 }
830
Yinghai Lu70093f72004-07-01 03:55:03 +0000831 return dimm_mask;
Yinghai Lu70093f72004-07-01 03:55:03 +0000832}
Steven J. Magnania4baa162005-09-26 13:54:32 +0000833
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000834/*-----------------------------------------------------------------------------
835SDRAM configuration functions:
836-----------------------------------------------------------------------------*/
Steven J. Magnania4baa162005-09-26 13:54:32 +0000837
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000838/**
839 * Send the specified command to all DIMMs.
840 *
841 * @param command Specifies the command to be sent to the DIMMs.
842 * @param jedec_mode_bits For the MRS & EMRS commands, bits 0-12 contain the
843 * register value in JEDEC format.
844 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000845static void do_ram_command(uint8_t command, uint16_t jedec_mode_bits)
Yinghai Lu70093f72004-07-01 03:55:03 +0000846{
Stefan Reinauer23836e22010-04-15 12:39:29 +0000847 int i;
Steven J. Magnania4baa162005-09-26 13:54:32 +0000848 uint32_t dram_controller_mode;
849 uint8_t dimm_start_64M_multiple = 0;
850 uint16_t e7501_mode_bits = jedec_mode_bits;
Yinghai Lu70093f72004-07-01 03:55:03 +0000851
Steven J. Magnania4baa162005-09-26 13:54:32 +0000852 // Configure the RAM command
Stefan Reinauer23836e22010-04-15 12:39:29 +0000853 dram_controller_mode = pci_read_config32(PCI_DEV(0, 0, 0), DRC);
854 dram_controller_mode &= 0xFFFFFF8F;
855 dram_controller_mode |= command;
856 pci_write_config32(PCI_DEV(0, 0, 0), DRC, dram_controller_mode);
Yinghai Lu70093f72004-07-01 03:55:03 +0000857
Stefan Reinauer14e22772010-04-27 06:56:47 +0000858 // RAM_COMMAND_NORMAL is an exception.
Steven J. Magnania4baa162005-09-26 13:54:32 +0000859 // It affects only the memory controller and does not need to be "sent" to the DIMMs.
Yinghai Lu70093f72004-07-01 03:55:03 +0000860
Steven J. Magnania4baa162005-09-26 13:54:32 +0000861 if (command != RAM_COMMAND_NORMAL) {
862
863 // Send the command to all DIMMs by accessing a memory location within each
864 // NOTE: for mode select commands, some of the location address bits
Stefan Reinauer23836e22010-04-15 12:39:29 +0000865 // are part of the command
Steven J. Magnania4baa162005-09-26 13:54:32 +0000866
867 // Map JEDEC mode bits to E7501
868 if (command == RAM_COMMAND_MRS) {
869 // Host address lines [15:5] map to DIMM address lines [12:11, 9:1]
870 // The E7501 hard-sets DIMM address lines 10 & 0 to zero
871
872 ASSERT(!(jedec_mode_bits & 0x0401));
873
Stefan Reinauer23836e22010-04-15 12:39:29 +0000874 e7501_mode_bits = ((jedec_mode_bits & 0x1800) << (15 - 12)) | // JEDEC bits 11-12 move to bits 14-15
875 ((jedec_mode_bits & 0x03FE) << (13 - 9)); // JEDEC bits 1-9 move to bits 5-13
Steven J. Magnania4baa162005-09-26 13:54:32 +0000876
877 } else if (command == RAM_COMMAND_EMRS) {
878 // Host address lines [15:3] map to DIMM address lines [12:0]
879 e7501_mode_bits = jedec_mode_bits <<= 3;
880 } else
881 ASSERT(jedec_mode_bits == 0);
Yinghai Lu70093f72004-07-01 03:55:03 +0000882
Steven J. Magnania4baa162005-09-26 13:54:32 +0000883 dimm_start_64M_multiple = 0;
Yinghai Lu70093f72004-07-01 03:55:03 +0000884
Steven J. Magnania4baa162005-09-26 13:54:32 +0000885 for (i = 0; i < (MAX_NUM_CHANNELS * MAX_DIMM_SOCKETS_PER_CHANNEL); ++i) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000886
Stefan Reinauer23836e22010-04-15 12:39:29 +0000887 uint8_t dimm_end_64M_multiple =
888 pci_read_config8(PCI_DEV(0, 0, 0), DRB_ROW_0 + i);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000889 if (dimm_end_64M_multiple > dimm_start_64M_multiple) {
Yinghai Lu70093f72004-07-01 03:55:03 +0000890
Steven J. Magnania4baa162005-09-26 13:54:32 +0000891 // This code assumes DRAM row boundaries are all set below 4 GB
892 // NOTE: 0x40 * 64 MB == 4 GB
893 ASSERT(dimm_start_64M_multiple < 0x40);
Yinghai Lu70093f72004-07-01 03:55:03 +0000894
Stefan Reinauer14e22772010-04-27 06:56:47 +0000895 // NOTE: 2^26 == 64 MB
Yinghai Lu70093f72004-07-01 03:55:03 +0000896
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -0800897 u8 *dimm_start_address = (u8 *)
898 (dimm_start_64M_multiple << 26);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000899
900 RAM_DEBUG_MESSAGE(" Sending RAM command to 0x");
901 RAM_DEBUG_HEX32(dimm_start_address + e7501_mode_bits);
Stefan Reinauer64ed2b72010-03-31 14:47:43 +0000902 RAM_DEBUG_MESSAGE("\n");
Stefan Reinauer23836e22010-04-15 12:39:29 +0000903
Steven J. Magnania4baa162005-09-26 13:54:32 +0000904 read32(dimm_start_address + e7501_mode_bits);
905
906 // Set the start of the next DIMM
Stefan Reinauer23836e22010-04-15 12:39:29 +0000907 dimm_start_64M_multiple =
908 dimm_end_64M_multiple;
Yinghai Lu70093f72004-07-01 03:55:03 +0000909 }
910 }
Steven J. Magnania4baa162005-09-26 13:54:32 +0000911 }
912}
Yinghai Lu70093f72004-07-01 03:55:03 +0000913
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000914/**
915 * Set the mode register of all DIMMs.
916 *
917 * The proper CAS# latency setting is added to the mode bits specified
918 * by the caller.
919 *
920 * @param jedec_mode_bits For the MRS & EMRS commands, bits 0-12 contain the
921 * register value in JEDEC format.
922 */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +0000923static void set_ram_mode(uint16_t jedec_mode_bits)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000924{
925 ASSERT(!(jedec_mode_bits & SDRAM_CAS_MASK));
926
Stefan Reinauer23836e22010-04-15 12:39:29 +0000927 uint32_t dram_cas_latency =
928 pci_read_config32(PCI_DEV(0, 0, 0), DRT) & DRT_CAS_MASK;
929
Steven J. Magnania4baa162005-09-26 13:54:32 +0000930 switch (dram_cas_latency) {
931 case DRT_CAS_2_5:
932 jedec_mode_bits |= SDRAM_CAS_2_5;
933 break;
934
935 case DRT_CAS_2_0:
936 jedec_mode_bits |= SDRAM_CAS_2_0;
937 break;
938
939 default:
940 BUG();
941 break;
942 }
943
Stefan Reinauera8aa1b12010-02-24 13:09:09 +0000944 do_ram_command(RAM_COMMAND_MRS, jedec_mode_bits);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000945}
946
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000947/*-----------------------------------------------------------------------------
948DIMM-independant configuration functions:
949-----------------------------------------------------------------------------*/
Steven J. Magnania4baa162005-09-26 13:54:32 +0000950
Uwe Hermannb69cb5a2010-10-26 22:46:43 +0000951/**
952 * Configure the E7501's DRAM Row Boundary (DRB) registers for the memory
953 * present in the specified DIMM.
954 *
955 * @param dimm_log2_num_bits Specifies log2(number of bits) for each side of
956 * the DIMM.
957 * @param total_dram_64M_multiple Total DRAM in the system (as a multiple of
958 * 64 MB) for DIMMs < dimm_index.
959 * @param dimm_index Which DIMM pair is being processed
960 * (0..MAX_DIMM_SOCKETS_PER_CHANNEL).
961 * @return New multiple of 64 MB total DRAM in the system.
962 */
Stefan Reinauer23836e22010-04-15 12:39:29 +0000963static uint8_t configure_dimm_row_boundaries(struct dimm_size dimm_log2_num_bits, uint8_t total_dram_64M_multiple, unsigned dimm_index)
Steven J. Magnania4baa162005-09-26 13:54:32 +0000964{
965 int i;
966
967 ASSERT(dimm_index < MAX_DIMM_SOCKETS_PER_CHANNEL);
968
969 // DIMM sides must be at least 32 MB
970 ASSERT(dimm_log2_num_bits.side1 >= 28);
Stefan Reinauer23836e22010-04-15 12:39:29 +0000971 ASSERT((dimm_log2_num_bits.side2 == 0)
972 || (dimm_log2_num_bits.side2 >= 28));
Steven J. Magnania4baa162005-09-26 13:54:32 +0000973
Stefan Reinauer14e22772010-04-27 06:56:47 +0000974 // In dual-channel mode, we are called only once for each pair of DIMMs.
Steven J. Magnania4baa162005-09-26 13:54:32 +0000975 // Each time we process twice the capacity of a single DIMM.
976
977 // Convert single DIMM capacity to paired DIMM capacity
978 // (multiply by two ==> add 1 to log2)
979 dimm_log2_num_bits.side1++;
980 if (dimm_log2_num_bits.side2 > 0)
981 dimm_log2_num_bits.side2++;
Stefan Reinauer23836e22010-04-15 12:39:29 +0000982
Steven J. Magnania4baa162005-09-26 13:54:32 +0000983 // Add the capacity of side 1 this DIMM pair (as a multiple of 64 MB)
984 // to the total capacity of the system
985 // NOTE: 64 MB == 512 Mb, and log2(512 Mb) == 29
986
987 total_dram_64M_multiple += (1 << (dimm_log2_num_bits.side1 - 29));
988
989 // Configure the boundary address for the row on side 1
Stefan Reinauer23836e22010-04-15 12:39:29 +0000990 pci_write_config8(PCI_DEV(0, 0, 0), DRB_ROW_0 + (dimm_index << 1),
991 total_dram_64M_multiple);
Steven J. Magnania4baa162005-09-26 13:54:32 +0000992
Stefan Reinauer14e22772010-04-27 06:56:47 +0000993 // If the DIMMs are double-sided, add the capacity of side 2 this DIMM pair
Steven J. Magnania4baa162005-09-26 13:54:32 +0000994 // (as a multiple of 64 MB) to the total capacity of the system
Stefan Reinauer23836e22010-04-15 12:39:29 +0000995 if (dimm_log2_num_bits.side2 >= 29)
996 total_dram_64M_multiple +=
997 (1 << (dimm_log2_num_bits.side2 - 29));
998
Steven J. Magnania4baa162005-09-26 13:54:32 +0000999 // Configure the boundary address for the row (if any) on side 2
Stefan Reinauer23836e22010-04-15 12:39:29 +00001000 pci_write_config8(PCI_DEV(0, 0, 0), DRB_ROW_1 + (dimm_index << 1),
1001 total_dram_64M_multiple);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001002
1003 // Update boundaries for rows subsequent to these.
1004 // These settings will be overridden by a subsequent call if a populated physical slot exists
Stefan Reinauer23836e22010-04-15 12:39:29 +00001005
1006 for (i = dimm_index + 1; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
1007 pci_write_config8(PCI_DEV(0, 0, 0), DRB_ROW_0 + (i << 1),
1008 total_dram_64M_multiple);
1009 pci_write_config8(PCI_DEV(0, 0, 0), DRB_ROW_1 + (i << 1),
1010 total_dram_64M_multiple);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001011 }
Stefan Reinauer23836e22010-04-15 12:39:29 +00001012
1013 return total_dram_64M_multiple;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001014}
1015
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001016/**
1017 * Set the E7501's DRAM row boundary addresses & its Top Of Low Memory (TOLM).
1018 *
1019 * If necessary, set up a remap window so we don't waste DRAM that ordinarily
1020 * would lie behind addresses reserved for memory-mapped I/O.
1021 *
1022 * @param ctrl PCI addresses of memory controller functions, and SMBus
1023 * addresses of DIMM slots on the mainboard.
1024 * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms().
1025 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001026static void configure_e7501_ram_addresses(const struct mem_controller
1027 *ctrl, uint8_t dimm_mask)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001028{
1029 int i;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001030 uint8_t total_dram_64M_multiple = 0;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001031
1032 // Configure the E7501's DRAM row boundaries
1033 // Start by zeroing out the temporary initial configuration
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001034 pci_write_config32(PCI_DEV(0, 0, 0), DRB_ROW_0, 0);
1035 pci_write_config32(PCI_DEV(0, 0, 0), DRB_ROW_4, 0);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001036
Stefan Reinauer23836e22010-04-15 12:39:29 +00001037 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
Steven J. Magnania4baa162005-09-26 13:54:32 +00001038
Stefan Reinauer23836e22010-04-15 12:39:29 +00001039 uint16_t dimm_socket_address = ctrl->channel0[i];
Steven J. Magnania4baa162005-09-26 13:54:32 +00001040 struct dimm_size sz;
1041
Stefan Reinauer23836e22010-04-15 12:39:29 +00001042 if (!(dimm_mask & (1 << i)))
1043 continue; // This DIMM not present
Steven J. Magnania4baa162005-09-26 13:54:32 +00001044
Stefan Reinauer23836e22010-04-15 12:39:29 +00001045 sz = spd_get_dimm_size(dimm_socket_address);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001046
Stefan Reinauer23836e22010-04-15 12:39:29 +00001047 RAM_DEBUG_MESSAGE("dimm size =");
Stefan Reinauer3c0bfaf2010-12-27 11:34:57 +00001048 RAM_DEBUG_HEX32((u32)sz.side1);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001049 RAM_DEBUG_MESSAGE(" ");
Stefan Reinauer3c0bfaf2010-12-27 11:34:57 +00001050 RAM_DEBUG_HEX32((u32)sz.side2);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001051 RAM_DEBUG_MESSAGE("\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +00001052
1053 if (sz.side1 == 0)
Stefan Reinauer64ed2b72010-03-31 14:47:43 +00001054 die("Bad SPD value\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +00001055
Stefan Reinauer23836e22010-04-15 12:39:29 +00001056 total_dram_64M_multiple =
1057 configure_dimm_row_boundaries(sz, total_dram_64M_multiple, i);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001058 }
1059
1060 // Configure the Top Of Low Memory (TOLM) in the E7501
1061 // This address must be a multiple of 128 MB that is less than 4 GB.
1062 // NOTE: 16-bit wide TOLM register stores only the highest 5 bits of a 32-bit address
Stefan Reinauer23836e22010-04-15 12:39:29 +00001063 // in the highest 5 bits.
Steven J. Magnania4baa162005-09-26 13:54:32 +00001064
1065 // We set TOLM to the smaller of 0xC0000000 (3 GB) or the total DRAM in the system.
1066 // This reserves addresses from 0xC0000000 - 0xFFFFFFFF for non-DRAM purposes
1067 // such as flash and memory-mapped I/O.
1068
1069 // If there is more than 3 GB of DRAM, we define a remap window which
1070 // makes the DRAM "behind" the reserved region available above the top of physical
1071 // memory.
1072
1073 // NOTE: 0xC0000000 / (64 MB) == 0x30
1074
Stefan Reinauer23836e22010-04-15 12:39:29 +00001075 if (total_dram_64M_multiple <= 0x30) {
Steven J. Magnania4baa162005-09-26 13:54:32 +00001076
1077 // <= 3 GB total RAM
1078
1079 /* I should really adjust all of this in C after I have resources
Stefan Reinauer23836e22010-04-15 12:39:29 +00001080 * to all of the pci devices.
1081 */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001082
1083 // Round up to 128MB granularity
1084 // SJM: Is "missing" 64 MB of memory a potential issue? Should this round down?
1085
Stefan Reinauer23836e22010-04-15 12:39:29 +00001086 uint8_t total_dram_128M_multiple =
1087 (total_dram_64M_multiple + 1) >> 1;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001088
1089 // Convert to high 16 bits of address
Stefan Reinauer23836e22010-04-15 12:39:29 +00001090 uint16_t top_of_low_memory =
1091 total_dram_128M_multiple << 11;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001092
Stefan Reinauer23836e22010-04-15 12:39:29 +00001093 pci_write_config16(PCI_DEV(0, 0, 0), TOLM,
1094 top_of_low_memory);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001095
1096 } else {
1097
1098 // > 3 GB total RAM
1099
1100 // Set defaults for > 4 GB DRAM, i.e. remap a 1 GB (= 0x10 * 64 MB) range of memory
Stefan Reinauer23836e22010-04-15 12:39:29 +00001101 uint16_t remap_base = total_dram_64M_multiple; // A[25:0] == 0
Steven J. Magnania4baa162005-09-26 13:54:32 +00001102 uint16_t remap_limit = total_dram_64M_multiple + 0x10 - 1; // A[25:0] == 0xF
1103
1104 // Put TOLM at 3 GB
1105
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001106 pci_write_config16(PCI_DEV(0, 0, 0), TOLM, 0xc000);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001107
1108 // Define a remap window to make the RAM that would appear from 3 GB - 4 GB
1109 // visible just beyond 4 GB or the end of physical memory, whichever is larger
1110 // NOTE: 16-bit wide REMAP registers store only the highest 10 bits of a 36-bit address,
Stefan Reinauer23836e22010-04-15 12:39:29 +00001111 // (i.e. a multiple of 64 MB) in the lowest 10 bits.
Steven J. Magnania4baa162005-09-26 13:54:32 +00001112 // NOTE: 0x100000000 / (64 MB) == 0x40
1113
Stefan Reinauer23836e22010-04-15 12:39:29 +00001114 if (total_dram_64M_multiple < 0x40) {
1115 remap_base = 0x40; // 0x100000000
1116 remap_limit =
1117 0x40 + (total_dram_64M_multiple - 0x30) - 1;
Yinghai Lu70093f72004-07-01 03:55:03 +00001118 }
1119
Stefan Reinauer23836e22010-04-15 12:39:29 +00001120 pci_write_config16(PCI_DEV(0, 0, 0), REMAPBASE,
1121 remap_base);
1122 pci_write_config16(PCI_DEV(0, 0, 0), REMAPLIMIT,
1123 remap_limit);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001124 }
1125}
1126
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001127/**
1128 * If we're configured to use ECC, initialize the SDRAM and clear the E7501's
1129 * ECC error flags.
1130 */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001131static void initialize_ecc(void)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001132{
1133 uint32_t dram_controller_mode;
1134
1135 /* Test to see if ECC support is enabled */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001136 dram_controller_mode = pci_read_config32(PCI_DEV(0, 0, 0), DRC);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001137 dram_controller_mode >>= 20;
1138 dram_controller_mode &= 3;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001139 if (dram_controller_mode == 2) {
1140
Steven J. Magnania4baa162005-09-26 13:54:32 +00001141 uint8_t byte;
1142
Stefan Reinauer64ed2b72010-03-31 14:47:43 +00001143 RAM_DEBUG_MESSAGE("Initializing ECC state...\n");
Stefan Reinauer23836e22010-04-15 12:39:29 +00001144 /* Initialize ECC bits , use ECC zero mode (new to 7501) */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001145 pci_write_config8(PCI_DEV(0, 0, 0), MCHCFGNS, 0x06);
1146 pci_write_config8(PCI_DEV(0, 0, 0), MCHCFGNS, 0x07);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001147
1148 // Wait for scrub cycle to complete
1149 do {
Stefan Reinauer23836e22010-04-15 12:39:29 +00001150 byte =
1151 pci_read_config8(PCI_DEV(0, 0, 0), MCHCFGNS);
1152 } while ((byte & 0x08) == 0);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001153
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001154 pci_write_config8(PCI_DEV(0, 0, 0), MCHCFGNS, byte & 0xfc);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001155 RAM_DEBUG_MESSAGE("ECC state initialized.\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +00001156
1157 /* Clear the ECC error bits */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001158 pci_write_config8(PCI_DEV(0, 0, 1), DRAM_FERR, 0x03);
1159 pci_write_config8(PCI_DEV(0, 0, 1), DRAM_NERR, 0x03);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001160
1161 // Clear DRAM Interface error bits (write-one-clear)
Stefan Reinauer23836e22010-04-15 12:39:29 +00001162 pci_write_config32(PCI_DEV(0, 0, 1), FERR_GLOBAL, 1 << 18);
1163 pci_write_config32(PCI_DEV(0, 0, 1), NERR_GLOBAL, 1 << 18);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001164
1165 // Start normal ECC scrub
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001166 pci_write_config8(PCI_DEV(0, 0, 0), MCHCFGNS, 5);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001167 }
Stefan Reinauer23836e22010-04-15 12:39:29 +00001168
Steven J. Magnania4baa162005-09-26 13:54:32 +00001169}
1170
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001171/**
1172 * Program the DRAM Timing register (DRT) of the E7501 (except for CAS#
1173 * latency, which is assumed to have been programmed already), based on the
1174 * parameters of the various installed DIMMs.
1175 *
1176 * @param ctrl PCI addresses of memory controller functions, and SMBus
1177 * addresses of DIMM slots on the mainboard.
1178 * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms().
1179 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001180static void configure_e7501_dram_timing(const struct mem_controller *ctrl,
1181 uint8_t dimm_mask)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001182{
1183 int i;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001184 uint32_t dram_timing;
1185 int value;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001186 uint8_t slowest_row_precharge = 0;
1187 uint8_t slowest_ras_cas_delay = 0;
1188 uint8_t slowest_active_to_precharge_delay = 0;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001189 uint32_t current_cas_latency =
1190 pci_read_config32(PCI_DEV(0, 0, 0), DRT) & DRT_CAS_MASK;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001191
1192 // CAS# latency must be programmed beforehand
Stefan Reinauer23836e22010-04-15 12:39:29 +00001193 ASSERT((current_cas_latency == DRT_CAS_2_0)
1194 || (current_cas_latency == DRT_CAS_2_5));
Steven J. Magnania4baa162005-09-26 13:54:32 +00001195
1196 // Each timing parameter is determined by the slowest DIMM
1197
1198 for (i = 0; i < MAX_DIMM_SOCKETS; i++) {
Stefan Reinauer23836e22010-04-15 12:39:29 +00001199 uint16_t dimm_socket_address;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001200
Steven J. Magnania4baa162005-09-26 13:54:32 +00001201 if (!(dimm_mask & (1 << i)))
Stefan Reinauer23836e22010-04-15 12:39:29 +00001202 continue; // This DIMM not present
Steven J. Magnania4baa162005-09-26 13:54:32 +00001203
1204 if (i < MAX_DIMM_SOCKETS_PER_CHANNEL)
1205 dimm_socket_address = ctrl->channel0[i];
1206 else
Stefan Reinauer23836e22010-04-15 12:39:29 +00001207 dimm_socket_address =
1208 ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL];
Steven J. Magnania4baa162005-09-26 13:54:32 +00001209
Stefan Reinauer23836e22010-04-15 12:39:29 +00001210 value =
1211 spd_read_byte(dimm_socket_address,
1212 SPD_MIN_ROW_PRECHARGE_TIME);
1213 if (value < 0)
1214 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001215 if (value > slowest_row_precharge)
1216 slowest_row_precharge = value;
1217
Stefan Reinauer23836e22010-04-15 12:39:29 +00001218 value =
1219 spd_read_byte(dimm_socket_address,
1220 SPD_MIN_RAS_TO_CAS_DELAY);
1221 if (value < 0)
1222 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001223 if (value > slowest_ras_cas_delay)
1224 slowest_ras_cas_delay = value;
1225
Stefan Reinauer23836e22010-04-15 12:39:29 +00001226 value =
1227 spd_read_byte(dimm_socket_address,
1228 SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY);
1229 if (value < 0)
1230 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001231 if (value > slowest_active_to_precharge_delay)
1232 slowest_active_to_precharge_delay = value;
1233 }
1234
1235 // NOTE for timing parameters:
Stefan Reinauer23836e22010-04-15 12:39:29 +00001236 // At 133 MHz, 1 clock == 7.52 ns
Steven J. Magnania4baa162005-09-26 13:54:32 +00001237
Stefan Reinauer23836e22010-04-15 12:39:29 +00001238 /* Read the initial state */
1239 dram_timing = pci_read_config32(PCI_DEV(0, 0, 0), DRT);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001240
1241 /* Trp */
1242
1243 // E7501 supports only 2 or 3 clocks for tRP
Stefan Reinauer23836e22010-04-15 12:39:29 +00001244 if (slowest_row_precharge > ((22 << 2) | (2 << 0)))
1245 die("unsupported DIMM tRP"); // > 22.5 ns: 4 or more clocks
1246 else if (slowest_row_precharge > (15 << 2))
Stefan Reinauer14e22772010-04-27 06:56:47 +00001247 dram_timing &= ~(1 << 0); // > 15.0 ns: 3 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001248 else
Stefan Reinauer23836e22010-04-15 12:39:29 +00001249 dram_timing |= (1 << 0); // <= 15.0 ns: 2 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001250
1251 /* Trcd */
1252
1253 // E7501 supports only 2 or 3 clocks for tRCD
1254 // Use the same value for both read & write
Stefan Reinauer23836e22010-04-15 12:39:29 +00001255 dram_timing &= ~((1 << 3) | (3 << 1));
1256 if (slowest_ras_cas_delay > ((22 << 2) | (2 << 0)))
1257 die("unsupported DIMM tRCD"); // > 22.5 ns: 4 or more clocks
1258 else if (slowest_ras_cas_delay > (15 << 2))
Stefan Reinauer14e22772010-04-27 06:56:47 +00001259 dram_timing |= (2 << 1); // > 15.0 ns: 3 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001260 else
Stefan Reinauer23836e22010-04-15 12:39:29 +00001261 dram_timing |= ((1 << 3) | (3 << 1)); // <= 15.0 ns: 2 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001262
1263 /* Tras */
1264
1265 // E7501 supports only 5, 6, or 7 clocks for tRAS
1266 // 5 clocks ~= 37.6 ns, 6 clocks ~= 45.1 ns, 7 clocks ~= 52.6 ns
Stefan Reinauer23836e22010-04-15 12:39:29 +00001267 dram_timing &= ~(3 << 9);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001268
1269 if (slowest_active_to_precharge_delay > 52)
Stefan Reinauer23836e22010-04-15 12:39:29 +00001270 die("unsupported DIMM tRAS"); // > 52 ns: 8 or more clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001271 else if (slowest_active_to_precharge_delay > 45)
Stefan Reinauer14e22772010-04-27 06:56:47 +00001272 dram_timing |= (0 << 9); // 46-52 ns: 7 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001273 else if (slowest_active_to_precharge_delay > 37)
Stefan Reinauer23836e22010-04-15 12:39:29 +00001274 dram_timing |= (1 << 9); // 38-45 ns: 6 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001275 else
Stefan Reinauer23836e22010-04-15 12:39:29 +00001276 dram_timing |= (2 << 9); // < 38 ns: 5 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001277
Stefan Reinauer23836e22010-04-15 12:39:29 +00001278 /* Trd */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001279
Elyes HAOUAS0f92f632014-07-27 19:37:31 +02001280 /* Set to a 7 clock read delay. This is for 133MHz
Stefan Reinauer23836e22010-04-15 12:39:29 +00001281 * with a CAS latency of 2.5 if 2.0 a 6 clock
1282 * delay is good */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001283
Stefan Reinauer23836e22010-04-15 12:39:29 +00001284 dram_timing &= ~(7 << 24); // 7 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001285 if (current_cas_latency == DRT_CAS_2_0)
Stefan Reinauer23836e22010-04-15 12:39:29 +00001286 dram_timing |= (1 << 24); // 6 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001287
1288 /*
1289 * Back to Back Read-Write Turn Around
1290 */
1291 /* Set to a 5 clock back to back read to write turn around.
1292 * 4 is a good delay if the CAS latency is 2.0 */
1293
Stefan Reinauer23836e22010-04-15 12:39:29 +00001294 dram_timing &= ~(1 << 28); // 5 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001295 if (current_cas_latency == DRT_CAS_2_0)
Stefan Reinauer23836e22010-04-15 12:39:29 +00001296 dram_timing |= (1 << 28); // 4 clocks
Steven J. Magnania4baa162005-09-26 13:54:32 +00001297
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001298 pci_write_config32(PCI_DEV(0, 0, 0), DRT, dram_timing);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001299
1300 return;
1301
Stefan Reinauer23836e22010-04-15 12:39:29 +00001302 hw_err:
Steven J. Magnania4baa162005-09-26 13:54:32 +00001303 die(SPD_ERROR);
1304}
1305
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001306/**
1307 * Determine the shortest CAS# latency that the E7501 and all DIMMs have in
1308 * common, and program the E7501 to use it.
1309 *
1310 * @param ctrl PCI addresses of memory controller functions, and SMBus
1311 * addresses of DIMM slots on the mainboard.
1312 * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms().
1313 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001314static void configure_e7501_cas_latency(const struct mem_controller *ctrl,
1315 uint8_t dimm_mask)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001316{
1317 int i;
1318 int value;
1319 uint32_t dram_timing;
1320 uint16_t maybe_dram_read_timing;
1321 uint32_t dword;
1322
1323 // CAS# latency bitmasks in SPD_ACCEPTABLE_CAS_LATENCIES format
1324 // NOTE: E7501 supports only 2.0 and 2.5
Stefan Reinauer23836e22010-04-15 12:39:29 +00001325 uint32_t system_compatible_cas_latencies =
1326 SPD_CAS_LATENCY_2_0 | SPD_CAS_LATENCY_2_5;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001327 uint32_t current_cas_latency;
1328 uint32_t dimm_compatible_cas_latencies;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001329
Steven J. Magnania4baa162005-09-26 13:54:32 +00001330 for (i = 0; i < MAX_DIMM_SOCKETS; i++) {
1331
Stefan Reinauer23836e22010-04-15 12:39:29 +00001332 uint16_t dimm_socket_address;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001333
1334 if (!(dimm_mask & (1 << i)))
Stefan Reinauer23836e22010-04-15 12:39:29 +00001335 continue; // This DIMM not usable
Steven J. Magnania4baa162005-09-26 13:54:32 +00001336
1337 if (i < MAX_DIMM_SOCKETS_PER_CHANNEL)
1338 dimm_socket_address = ctrl->channel0[i];
1339 else
Stefan Reinauer23836e22010-04-15 12:39:29 +00001340 dimm_socket_address =
1341 ctrl->channel1[i - MAX_DIMM_SOCKETS_PER_CHANNEL];
Steven J. Magnania4baa162005-09-26 13:54:32 +00001342
Stefan Reinauer23836e22010-04-15 12:39:29 +00001343 value =
1344 spd_read_byte(dimm_socket_address,
1345 SPD_ACCEPTABLE_CAS_LATENCIES);
1346 if (value < 0)
1347 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001348
Stefan Reinauer23836e22010-04-15 12:39:29 +00001349 dimm_compatible_cas_latencies = value & 0x7f; // Start with all supported by DIMM
1350 current_cas_latency = 1 << log2(dimm_compatible_cas_latencies); // Max supported by DIMM
Steven J. Magnania4baa162005-09-26 13:54:32 +00001351
1352 // Can we support the highest CAS# latency?
1353
Stefan Reinauer23836e22010-04-15 12:39:29 +00001354 value =
1355 spd_read_byte(dimm_socket_address,
1356 SPD_MIN_CYCLE_TIME_AT_CAS_MAX);
1357 if (value < 0)
1358 goto hw_err;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001359
1360 // NOTE: At 133 MHz, 1 clock == 7.52 ns
1361 if (value > 0x75) {
1362 // Our bus is too fast for this CAS# latency
1363 // Remove it from the bitmask of those supported by the DIMM that are compatible
1364 dimm_compatible_cas_latencies &= ~current_cas_latency;
1365 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001366 // Can we support the next-highest CAS# latency (max - 0.5)?
1367
1368 current_cas_latency >>= 1;
1369 if (current_cas_latency != 0) {
Stefan Reinauer23836e22010-04-15 12:39:29 +00001370 value =
1371 spd_read_byte(dimm_socket_address,
1372 SPD_SDRAM_CYCLE_TIME_2ND);
1373 if (value < 0)
1374 goto hw_err;
1375 if (value > 0x75)
1376 dimm_compatible_cas_latencies &=
1377 ~current_cas_latency;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001378 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001379 // Can we support the next-highest CAS# latency (max - 1.0)?
1380 current_cas_latency >>= 1;
1381 if (current_cas_latency != 0) {
Stefan Reinauer23836e22010-04-15 12:39:29 +00001382 value =
1383 spd_read_byte(dimm_socket_address,
1384 SPD_SDRAM_CYCLE_TIME_3RD);
1385 if (value < 0)
1386 goto hw_err;
1387 if (value > 0x75)
1388 dimm_compatible_cas_latencies &=
1389 ~current_cas_latency;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001390 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001391 // Restrict the system to CAS# latencies compatible with this DIMM
Stefan Reinauer23836e22010-04-15 12:39:29 +00001392 system_compatible_cas_latencies &=
1393 dimm_compatible_cas_latencies;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001394
Stefan Reinauer23836e22010-04-15 12:39:29 +00001395 /* go to the next DIMM */
Yinghai Lu70093f72004-07-01 03:55:03 +00001396 }
1397
1398 /* After all of the arduous calculation setup with the fastest
1399 * cas latency I can use.
1400 */
Yinghai Lu70093f72004-07-01 03:55:03 +00001401
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001402 dram_timing = pci_read_config32(PCI_DEV(0, 0, 0), DRT);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001403 dram_timing &= ~(DRT_CAS_MASK);
1404
Stefan Reinauer23836e22010-04-15 12:39:29 +00001405 maybe_dram_read_timing =
1406 pci_read_config16(PCI_DEV(0, 0, 0), MAYBE_DRDCTL);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001407 maybe_dram_read_timing &= 0xF00C;
1408
1409 if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_0) {
1410 dram_timing |= DRT_CAS_2_0;
1411 maybe_dram_read_timing |= 0xBB1;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001412 } else if (system_compatible_cas_latencies & SPD_CAS_LATENCY_2_5) {
Steven J. Magnania4baa162005-09-26 13:54:32 +00001413
Stefan Reinauer23836e22010-04-15 12:39:29 +00001414 uint32_t dram_row_attributes =
1415 pci_read_config32(PCI_DEV(0, 0, 0), DRA);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001416
1417 dram_timing |= DRT_CAS_2_5;
1418
1419 // At CAS# 2.5, DRAM Read Timing (if that's what it its) appears to need a slightly
1420 // different value if all DIMM slots are populated
1421
Stefan Reinauer23836e22010-04-15 12:39:29 +00001422 if ((dram_row_attributes & 0xff)
1423 && (dram_row_attributes & 0xff00)
1424 && (dram_row_attributes & 0xff0000)
1425 && (dram_row_attributes & 0xff000000)) {
Steven J. Magnania4baa162005-09-26 13:54:32 +00001426
1427 // All slots populated
1428 maybe_dram_read_timing |= 0x0882;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001429 } else {
Steven J. Magnania4baa162005-09-26 13:54:32 +00001430 // Some unpopulated slots
1431 maybe_dram_read_timing |= 0x0662;
1432 }
Stefan Reinauer23836e22010-04-15 12:39:29 +00001433 } else
Stefan Reinauer64ed2b72010-03-31 14:47:43 +00001434 die("No CAS# latencies compatible with all DIMMs!!\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +00001435
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001436 pci_write_config32(PCI_DEV(0, 0, 0), DRT, dram_timing);
Yinghai Lu70093f72004-07-01 03:55:03 +00001437
1438 /* set master DLL reset */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001439 dword = pci_read_config32(PCI_DEV(0, 0, 0), 0x88);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001440 dword |= (1 << 26);
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001441 pci_write_config32(PCI_DEV(0, 0, 0), 0x88, dword);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001442
Steven J. Magnania4baa162005-09-26 13:54:32 +00001443 dword &= 0x0c0007ff; /* patch try register 88 is undocumented tnz */
Yinghai Lu70093f72004-07-01 03:55:03 +00001444 dword |= 0xd2109800;
1445
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001446 pci_write_config32(PCI_DEV(0, 0, 0), 0x88, dword);
Yinghai Lu70093f72004-07-01 03:55:03 +00001447
Stefan Reinauer23836e22010-04-15 12:39:29 +00001448 pci_write_config16(PCI_DEV(0, 0, 0), MAYBE_DRDCTL,
1449 maybe_dram_read_timing);
1450
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001451 dword = pci_read_config32(PCI_DEV(0, 0, 0), 0x88); /* reset master DLL reset */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001452 dword &= ~(1 << 26);
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001453 pci_write_config32(PCI_DEV(0, 0, 0), 0x88, dword);
Yinghai Lu70093f72004-07-01 03:55:03 +00001454
Steven J. Magnania4baa162005-09-26 13:54:32 +00001455 return;
Yinghai Lu70093f72004-07-01 03:55:03 +00001456
Stefan Reinauer23836e22010-04-15 12:39:29 +00001457 hw_err:
Steven J. Magnania4baa162005-09-26 13:54:32 +00001458 die(SPD_ERROR);
Yinghai Lu70093f72004-07-01 03:55:03 +00001459}
1460
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001461/**
1462 * Configure the refresh interval so that we refresh no more often than
1463 * required by the "most needy" DIMM. Also disable ECC if any of the DIMMs
1464 * don't support it.
1465 *
1466 * @param ctrl PCI addresses of memory controller functions, and SMBus
1467 * addresses of DIMM slots on the mainboard.
1468 * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms().
1469 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001470static void configure_e7501_dram_controller_mode(const struct
1471 mem_controller *ctrl,
1472 uint8_t dimm_mask)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001473{
Stefan Reinauer23836e22010-04-15 12:39:29 +00001474 int i;
Yinghai Lu70093f72004-07-01 03:55:03 +00001475
Steven J. Magnania4baa162005-09-26 13:54:32 +00001476 // Initial settings
Stefan Reinauer23836e22010-04-15 12:39:29 +00001477 uint32_t controller_mode =
1478 pci_read_config32(PCI_DEV(0, 0, 0), DRC);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001479 uint32_t system_refresh_mode = (controller_mode >> 8) & 7;
Yinghai Lu70093f72004-07-01 03:55:03 +00001480
Steven J. Magnania4baa162005-09-26 13:54:32 +00001481 // Code below assumes that most aggressive settings are in
1482 // force when we are called, either via E7501 reset defaults
1483 // or by sdram_set_registers():
Stefan Reinauer23836e22010-04-15 12:39:29 +00001484 // - ECC enabled
1485 // - No refresh
Steven J. Magnania4baa162005-09-26 13:54:32 +00001486
Stefan Reinauer23836e22010-04-15 12:39:29 +00001487 ASSERT((controller_mode & (3 << 20)) == (2 << 20)); // ECC
1488 ASSERT(!(controller_mode & (7 << 8))); // Refresh
Steven J. Magnania4baa162005-09-26 13:54:32 +00001489
Stefan Reinauer23836e22010-04-15 12:39:29 +00001490 /* Walk through _all_ dimms and find the least-common denominator for:
1491 * - ECC support
1492 * - refresh rates
1493 */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001494
1495 for (i = 0; i < MAX_DIMM_SOCKETS; i++) {
1496
1497 uint32_t dimm_refresh_mode;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001498 int value;
1499 uint16_t dimm_socket_address;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001500
Yinghai Lu70093f72004-07-01 03:55:03 +00001501 if (!(dimm_mask & (1 << i))) {
Stefan Reinauer23836e22010-04-15 12:39:29 +00001502 continue; // This DIMM not usable
1503 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001504
1505 if (i < MAX_DIMM_SOCKETS_PER_CHANNEL)
1506 dimm_socket_address = ctrl->channel0[i];
1507 else
Stefan Reinauer23836e22010-04-15 12:39:29 +00001508 dimm_socket_address =
1509 ctrl->channel1[i -
1510 MAX_DIMM_SOCKETS_PER_CHANNEL];
Steven J. Magnania4baa162005-09-26 13:54:32 +00001511
1512 // Disable ECC mode if any one of the DIMMs does not support ECC
1513 // SJM: Should we just die here? E7501 datasheet says non-ECC DIMMs aren't supported.
1514
Stefan Reinauer23836e22010-04-15 12:39:29 +00001515 value =
1516 spd_read_byte(dimm_socket_address,
1517 SPD_DIMM_CONFIG_TYPE);
1518 die_on_spd_error(value);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001519 if (value != ERROR_SCHEME_ECC) {
1520 controller_mode &= ~(3 << 20);
Yinghai Lu70093f72004-07-01 03:55:03 +00001521 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001522
1523 value = spd_read_byte(dimm_socket_address, SPD_REFRESH);
1524 die_on_spd_error(value);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001525 value &= 0x7f; // Mask off self-refresh bit
1526 if (value > MAX_SPD_REFRESH_RATE) {
Stefan Reinauer65b72ab2015-01-05 12:59:54 -08001527 printk(BIOS_ERR, "unsupported refresh rate\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +00001528 continue;
Yinghai Lu70093f72004-07-01 03:55:03 +00001529 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001530 // Get the appropriate E7501 refresh mode for this DIMM
1531 dimm_refresh_mode = refresh_rate_map[value];
1532 if (dimm_refresh_mode > 7) {
Stefan Reinauer65b72ab2015-01-05 12:59:54 -08001533 printk(BIOS_ERR, "unsupported refresh rate\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +00001534 continue;
Yinghai Lu70093f72004-07-01 03:55:03 +00001535 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001536 // If this DIMM requires more frequent refresh than others,
1537 // update the system setting
Stefan Reinauer23836e22010-04-15 12:39:29 +00001538 if (refresh_frequency[dimm_refresh_mode] >
1539 refresh_frequency[system_refresh_mode])
Steven J. Magnania4baa162005-09-26 13:54:32 +00001540 system_refresh_mode = dimm_refresh_mode;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001541
Steven J. Magnania4baa162005-09-26 13:54:32 +00001542#ifdef SUSPICIOUS_LOOKING_CODE
1543// SJM NOTE: This code doesn't look right. SPD values are an order of magnitude smaller
Stefan Reinauer23836e22010-04-15 12:39:29 +00001544// than the clock period of the memory controller. Also, no other northbridge
1545// looks at SPD_CMD_SIGNAL_INPUT_HOLD_TIME.
Steven J. Magnania4baa162005-09-26 13:54:32 +00001546
1547 // Switch to 2 clocks for address/command if required by any one of the DIMMs
1548 // NOTE: At 133 MHz, 1 clock == 7.52 ns
Stefan Reinauer23836e22010-04-15 12:39:29 +00001549 value =
1550 spd_read_byte(dimm_socket_address,
1551 SPD_CMD_SIGNAL_INPUT_HOLD_TIME);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001552 die_on_spd_error(value);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001553 if (value >= 0xa0) { /* At 133MHz this constant should be 0x75 */
1554 controller_mode &= ~(1 << 16); /* Use two clock cyles instead of one */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001555 }
Yinghai Lu70093f72004-07-01 03:55:03 +00001556#endif
Stefan Reinauer23836e22010-04-15 12:39:29 +00001557
1558 /* go to the next DIMM */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001559 }
Yinghai Lu70093f72004-07-01 03:55:03 +00001560
Steven J. Magnania4baa162005-09-26 13:54:32 +00001561 controller_mode |= (system_refresh_mode << 8);
Yinghai Lu70093f72004-07-01 03:55:03 +00001562
Steven J. Magnania4baa162005-09-26 13:54:32 +00001563 // Configure the E7501
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001564 pci_write_config32(PCI_DEV(0, 0, 0), DRC, controller_mode);
Yinghai Lu70093f72004-07-01 03:55:03 +00001565}
Yinghai Lu70093f72004-07-01 03:55:03 +00001566
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001567/**
1568 * Configure the E7501's DRAM Row Attributes (DRA) registers based on DIMM
1569 * parameters read via SPD. This tells the controller the width of the SDRAM
1570 * chips on each DIMM side (x4 or x8) and the page size of each DIMM side
1571 * (4, 8, 16, or 32 KB).
1572 *
1573 * @param ctrl PCI addresses of memory controller functions, and SMBus
1574 * addresses of DIMM slots on the mainboard.
1575 * @param dimm_mask Bitmask of populated DIMMs, spd_get_supported_dimms().
1576 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001577static void configure_e7501_row_attributes(const struct mem_controller
1578 *ctrl, uint8_t dimm_mask)
Yinghai Lu70093f72004-07-01 03:55:03 +00001579{
1580 int i;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001581 uint32_t row_attributes = 0;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001582
Stefan Reinauer23836e22010-04-15 12:39:29 +00001583 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
1584
1585 uint16_t dimm_socket_address = ctrl->channel0[i];
1586 struct dimm_size page_size;
1587 struct dimm_size sdram_width;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001588
1589 if (!(dimm_mask & (1 << i)))
Stefan Reinauer23836e22010-04-15 12:39:29 +00001590 continue; // This DIMM not usable
Steven J. Magnania4baa162005-09-26 13:54:32 +00001591
1592 // Get the relevant parameters via SPD
Stefan Reinauer23836e22010-04-15 12:39:29 +00001593 page_size = sdram_spd_get_page_size(dimm_socket_address);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001594 sdram_width = sdram_spd_get_width(dimm_socket_address);
1595
1596 // Update the DRAM Row Attributes.
1597 // Page size is encoded as log2(page size in bits) - log2(8 Kb)
1598 // NOTE: 8 Kb = 2^13
Stefan Reinauer23836e22010-04-15 12:39:29 +00001599 row_attributes |= (page_size.side1 - 13) << (i << 3); // Side 1 of each DIMM is an EVEN row
Steven J. Magnania4baa162005-09-26 13:54:32 +00001600
1601 if (sdram_width.side2 > 0)
Stefan Reinauer23836e22010-04-15 12:39:29 +00001602 row_attributes |= (page_size.side2 - 13) << ((i << 3) + 4); // Side 2 is ODD
Steven J. Magnania4baa162005-09-26 13:54:32 +00001603
1604 // Set x4 flags if appropriate
1605 if (sdram_width.side1 == 4) {
Stefan Reinauer23836e22010-04-15 12:39:29 +00001606 row_attributes |= 0x08 << (i << 3);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001607 }
1608
1609 if (sdram_width.side2 == 4) {
Stefan Reinauer23836e22010-04-15 12:39:29 +00001610 row_attributes |= 0x08 << ((i << 3) + 4);
1611 }
1612
1613 /* go to the next DIMM */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001614 }
1615
1616 /* Write the new row attributes register */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001617 pci_write_config32(PCI_DEV(0, 0, 0), DRA, row_attributes);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001618}
1619
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001620/*
1621 * Enable clock signals for populated DIMM sockets and disable them for
1622 * unpopulated sockets (to reduce EMI).
1623 *
1624 * @param dimm_mask Bitmask of populated DIMMs, see spd_get_supported_dimms().
1625 */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001626static void enable_e7501_clocks(uint8_t dimm_mask)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001627{
1628 int i;
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001629 uint8_t clock_disable = pci_read_config8(PCI_DEV(0, 0, 0), CKDIS);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001630
1631 for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
1632
Stefan Reinauer23836e22010-04-15 12:39:29 +00001633 uint8_t socket_mask = 1 << i;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001634
1635 if (dimm_mask & socket_mask)
1636 clock_disable &= ~socket_mask; // DIMM present, enable clock
1637 else
1638 clock_disable |= socket_mask; // DIMM absent, disable clock
1639 }
Stefan Reinauer23836e22010-04-15 12:39:29 +00001640
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001641 pci_write_config8(PCI_DEV(0, 0, 0), CKDIS, clock_disable);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001642}
1643
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001644/* DIMM-dedependent configuration functions */
Steven J. Magnania4baa162005-09-26 13:54:32 +00001645
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001646/**
1647 * DDR Receive FIFO RE-Sync (?)
1648 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001649static void RAM_RESET_DDR_PTR(void)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001650{
1651 uint8_t byte;
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001652 byte = pci_read_config8(PCI_DEV(0, 0, 0), 0x88);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001653 byte |= (1 << 4);
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001654 pci_write_config8(PCI_DEV(0, 0, 0), 0x88, byte);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001655
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001656 byte = pci_read_config8(PCI_DEV(0, 0, 0), 0x88);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001657 byte &= ~(1 << 4);
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001658 pci_write_config8(PCI_DEV(0, 0, 0), 0x88, byte);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001659}
1660
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001661/**
1662 * Set E7501 registers that are either independent of DIMM specifics, or
1663 * establish default settings that will be overridden when we learn the
1664 * specifics.
1665 *
1666 * This sets PCI configuration registers to known good values based on the
1667 * table 'constant_register_values', which are a triple of configuration
1668 * register offset, mask, and bits to set.
1669 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001670static void ram_set_d0f0_regs(void)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001671{
1672 int i;
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +00001673 int num_values = ARRAY_SIZE(constant_register_values);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001674
Stefan Reinauer23836e22010-04-15 12:39:29 +00001675 ASSERT((num_values % 3) == 0); // Bad table?
Steven J. Magnania4baa162005-09-26 13:54:32 +00001676
Stefan Reinauer23836e22010-04-15 12:39:29 +00001677 for (i = 0; i < num_values; i += 3) {
Steven J. Magnania4baa162005-09-26 13:54:32 +00001678
1679 uint32_t register_offset = constant_register_values[i];
Stefan Reinauer23836e22010-04-15 12:39:29 +00001680 uint32_t bits_to_mask = constant_register_values[i + 1];
1681 uint32_t bits_to_set = constant_register_values[i + 2];
Steven J. Magnania4baa162005-09-26 13:54:32 +00001682 uint32_t register_value;
1683
1684 // It's theoretically possible to set values for something other than D0:F0,
1685 // but it's not typically done here
1686 ASSERT(!(register_offset & 0xFFFFFF00));
1687
1688 // bits_to_mask and bits_to_set should not reference the same bits
1689 // Again, not strictly an error, but flagged as a potential bug
1690 ASSERT((bits_to_mask & bits_to_set) == 0);
1691
Stefan Reinauer23836e22010-04-15 12:39:29 +00001692 register_value =
1693 pci_read_config32(PCI_DEV(0, 0, 0), register_offset);
1694 register_value &= bits_to_mask;
1695 register_value |= bits_to_set;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001696
Stefan Reinauer23836e22010-04-15 12:39:29 +00001697 pci_write_config32(PCI_DEV(0, 0, 0), register_offset,
1698 register_value);
1699 }
Steven J. Magnania4baa162005-09-26 13:54:32 +00001700}
1701
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001702/**
1703 * Copy 64 bytes from one location to another.
1704 *
1705 * @param src_addr TODO
1706 * @param dst_addr TODO
1707 */
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -08001708static void write_8dwords(const uint32_t *src_addr, u8 *dst_addr)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001709{
1710 int i;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001711 for (i = 0; i < 8; i++) {
Steven J. Magnania4baa162005-09-26 13:54:32 +00001712 write32(dst_addr, *src_addr);
1713 src_addr++;
1714 dst_addr += sizeof(uint32_t);
1715 }
1716}
1717
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001718/**
1719 * Set the E7501's (undocumented) RCOMP registers.
1720 *
1721 * Per the 855PM datasheet and IXP2800 HW Initialization Reference Manual,
1722 * RCOMP registers appear to affect drive strength, pullup/pulldown offset,
1723 * and slew rate of various signal groups.
1724 *
1725 * Comments below are conjecture based on apparent similarity between the
1726 * E7501 and these two chips.
1727 */
Stefan Reinauer23836e22010-04-15 12:39:29 +00001728static void ram_set_rcomp_regs(void)
Steven J. Magnania4baa162005-09-26 13:54:32 +00001729{
1730 uint32_t dword;
1731 uint8_t maybe_strength_control;
1732
Stefan Reinauer64ed2b72010-03-31 14:47:43 +00001733 RAM_DEBUG_MESSAGE("Setting RCOMP registers.\n");
Steven J. Magnania4baa162005-09-26 13:54:32 +00001734
Stefan Reinauer23836e22010-04-15 12:39:29 +00001735 /*enable access to the rcomp bar */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001736 dword = pci_read_config32(PCI_DEV(0, 0, 0), MAYBE_MCHTST);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001737 dword |= (1 << 22);
1738 pci_write_config32(PCI_DEV(0, 0, 0), MAYBE_MCHTST, dword);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001739
1740 // Set the RCOMP MMIO base address
Kevin Paul Herbertbde6d302014-12-24 18:43:20 -08001741 pci_write_config32(PCI_DEV(0, 0, 0), MAYBE_SMRBASE,
1742 (uintptr_t)RCOMP_MMIO);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001743
1744 // Block RCOMP updates while we configure the registers
1745 dword = read32(RCOMP_MMIO + MAYBE_SMRCTL);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001746 dword |= (1 << 9);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001747 write32(RCOMP_MMIO + MAYBE_SMRCTL, dword);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001748
1749 /* Begin to write the RCOMP registers */
1750
1751 // Set CMD and DQ/DQS strength to 2x (?)
1752 maybe_strength_control = read8(RCOMP_MMIO + MAYBE_DQCMDSTR) & 0x88;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001753 maybe_strength_control |= 0x44;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001754 write8(RCOMP_MMIO + MAYBE_DQCMDSTR, maybe_strength_control);
1755
1756 write_8dwords(maybe_2x_slew_table, RCOMP_MMIO + 0x80);
1757 write16(RCOMP_MMIO + 0x42, 0);
1758
1759 write_8dwords(maybe_1x_slew_table, RCOMP_MMIO + 0x60);
1760
1761 // NOTE: some factory BIOS set 0x9088 here. Seems to work either way.
1762 write16(RCOMP_MMIO + 0x40, 0);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001763
1764 // Set RCVEnOut# strength to 2x (?)
1765 maybe_strength_control = read8(RCOMP_MMIO + MAYBE_RCVENSTR) & 0xF8;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001766 maybe_strength_control |= 4;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001767 write8(RCOMP_MMIO + MAYBE_RCVENSTR, maybe_strength_control);
1768
1769 write_8dwords(maybe_2x_slew_table, RCOMP_MMIO + 0x1c0);
1770 write16(RCOMP_MMIO + 0x50, 0);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001771
Steven J. Magnania4baa162005-09-26 13:54:32 +00001772 // Set CS# strength for x4 SDRAM to 2x (?)
1773 maybe_strength_control = read8(RCOMP_MMIO + MAYBE_CSBSTR) & 0xF8;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001774 maybe_strength_control |= 4;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001775 write8(RCOMP_MMIO + MAYBE_CSBSTR, maybe_strength_control);
1776
1777 write_8dwords(maybe_2x_slew_table, RCOMP_MMIO + 0x140);
1778 write16(RCOMP_MMIO + 0x48, 0);
1779
1780 // Set CKE strength for x4 SDRAM to 2x (?)
1781 maybe_strength_control = read8(RCOMP_MMIO + MAYBE_CKESTR) & 0xF8;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001782 maybe_strength_control |= 4;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001783 write8(RCOMP_MMIO + MAYBE_CKESTR, maybe_strength_control);
1784
1785 write_8dwords(maybe_2x_slew_table, RCOMP_MMIO + 0xa0);
1786 write16(RCOMP_MMIO + 0x44, 0);
1787
1788 // Set CK strength for x4 SDRAM to 1x (?)
1789 maybe_strength_control = read8(RCOMP_MMIO + MAYBE_CKSTR) & 0xF8;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001790 maybe_strength_control |= 1;
Steven J. Magnania4baa162005-09-26 13:54:32 +00001791 write8(RCOMP_MMIO + MAYBE_CKSTR, maybe_strength_control);
1792
1793 write_8dwords(maybe_pull_updown_offset_table, RCOMP_MMIO + 0x180);
1794 write16(RCOMP_MMIO + 0x4c, 0);
1795
1796 write8(RCOMP_MMIO + 0x2c, 0xff);
1797
Steven J. Magnania4baa162005-09-26 13:54:32 +00001798 // Set the digital filter length to 8 (?)
1799 dword = read32(RCOMP_MMIO + MAYBE_SMRCTL);
1800
1801 // NOTE: Some factory BIOS don't do this.
Stefan Reinauer23836e22010-04-15 12:39:29 +00001802 // Doesn't seem to matter either way.
Steven J. Magnania4baa162005-09-26 13:54:32 +00001803 dword &= ~2;
1804
1805 dword |= 1;
1806 write32(RCOMP_MMIO + MAYBE_SMRCTL, dword);
1807
1808 /* Wait 40 usec */
1809 SLOW_DOWN_IO;
Stefan Reinauer23836e22010-04-15 12:39:29 +00001810
Steven J. Magnania4baa162005-09-26 13:54:32 +00001811 /* unblock updates */
1812 dword = read32(RCOMP_MMIO + MAYBE_SMRCTL);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001813 dword &= ~(1 << 9);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001814 write32(RCOMP_MMIO + MAYBE_SMRCTL, dword);
1815
1816 // Force a RCOMP measurement cycle?
Stefan Reinauer23836e22010-04-15 12:39:29 +00001817 dword |= (1 << 8);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001818 write32(RCOMP_MMIO + MAYBE_SMRCTL, dword);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001819 dword &= ~(1 << 8);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001820 write32(RCOMP_MMIO + MAYBE_SMRCTL, dword);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001821
Steven J. Magnania4baa162005-09-26 13:54:32 +00001822 /* Wait 40 usec */
1823 SLOW_DOWN_IO;
1824
1825 /*disable access to the rcomp bar */
Stefan Reinauera8aa1b12010-02-24 13:09:09 +00001826 dword = pci_read_config32(PCI_DEV(0, 0, 0), MAYBE_MCHTST);
Stefan Reinauer23836e22010-04-15 12:39:29 +00001827 dword &= ~(1 << 22);
1828 pci_write_config32(PCI_DEV(0, 0, 0), MAYBE_MCHTST, dword);
Steven J. Magnania4baa162005-09-26 13:54:32 +00001829
1830}
1831
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001832/*-----------------------------------------------------------------------------
1833Public interface:
1834-----------------------------------------------------------------------------*/
Steven J. Magnania4baa162005-09-26 13:54:32 +00001835
Uwe Hermannb69cb5a2010-10-26 22:46:43 +00001836/**
1837 * Go through the JEDEC initialization sequence for all DIMMs, then enable
1838 * refresh and initialize ECC and memory to zero. Upon exit, SDRAM is up
1839 * and running.
1840 *
1841 * @param controllers Not used.
1842 * @param ctrl PCI addresses of memory controller functions, and SMBus
1843 * addresses of DIMM slots on the mainboard.