blob: 6a7353608bf5ad1677503d7d465d55d0f7415c2c [file] [log] [blame]
Richard Smithcb8eab42006-07-24 04:25:47 +00001/*
Stefan Reinauer7e61e452008-01-18 10:35:56 +00002 * This file is part of the coreboot project.
Uwe Hermann1a9c8922007-04-01 17:24:03 +00003 *
Uwe Hermann1683cef2008-11-27 00:47:07 +00004 * Copyright (C) 2007-2008 Uwe Hermann <uwe@hermann-uwe.de>
Uwe Hermann1a9c8922007-04-01 17:24:03 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Richard Smithcb8eab42006-07-24 04:25:47 +000019 */
20
Uwe Hermann1a9c8922007-04-01 17:24:03 +000021#include <spd.h>
22#include <sdram_mode.h>
23#include <delay.h>
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +000024#include <stdlib.h>
Uwe Hermann1a9c8922007-04-01 17:24:03 +000025#include "i440bx.h"
Richard Smithcb8eab42006-07-24 04:25:47 +000026
Uwe Hermann1a9c8922007-04-01 17:24:03 +000027/*-----------------------------------------------------------------------------
28Macros and definitions.
29-----------------------------------------------------------------------------*/
Richard Smithcb8eab42006-07-24 04:25:47 +000030
Uwe Hermann1a9c8922007-04-01 17:24:03 +000031/* Debugging macros. */
Uwe Hermann01ce6012010-03-05 10:03:50 +000032#if CONFIG_DEBUG_RAM_SETUP
Uwe Hermann1a9c8922007-04-01 17:24:03 +000033#define PRINT_DEBUG(x) print_debug(x)
34#define PRINT_DEBUG_HEX8(x) print_debug_hex8(x)
35#define PRINT_DEBUG_HEX16(x) print_debug_hex16(x)
36#define PRINT_DEBUG_HEX32(x) print_debug_hex32(x)
37#define DUMPNORTH() dump_pci_device(PCI_DEV(0, 0, 0))
Richard Smithcb8eab42006-07-24 04:25:47 +000038#else
Uwe Hermann941a6f02007-04-30 23:27:27 +000039#define PRINT_DEBUG(x)
Uwe Hermann1a9c8922007-04-01 17:24:03 +000040#define PRINT_DEBUG_HEX8(x)
41#define PRINT_DEBUG_HEX16(x)
42#define PRINT_DEBUG_HEX32(x)
43#define DUMPNORTH()
Richard Smithcb8eab42006-07-24 04:25:47 +000044#endif
45
Uwe Hermann1683cef2008-11-27 00:47:07 +000046#define NB PCI_DEV(0, 0, 0)
47
Uwe Hermann1a9c8922007-04-01 17:24:03 +000048/* SDRAMC[7:5] - SDRAM Mode Select (SMS). */
49#define RAM_COMMAND_NORMAL 0x0
50#define RAM_COMMAND_NOP 0x1
51#define RAM_COMMAND_PRECHARGE 0x2
52#define RAM_COMMAND_MRS 0x3
53#define RAM_COMMAND_CBR 0x4
Richard Smithcb8eab42006-07-24 04:25:47 +000054
Uwe Hermann1a9c8922007-04-01 17:24:03 +000055/* Map the JEDEC SPD refresh rates (array index) to 440BX refresh rates as
56 * defined in DRAMC[2:0].
57 *
58 * [0] == Normal 15.625 us -> 15.6 us
59 * [1] == Reduced(.25X) 3.9 us -> 7.8 ns
60 * [2] == Reduced(.5X) 7.8 us -> 7.8 us
61 * [3] == Extended(2x) 31.3 us -> 31.2 us
62 * [4] == Extended(4x) 62.5 us -> 62.4 us
63 * [5] == Extended(8x) 125 us -> 124.8 us
64 */
65static const uint32_t refresh_rate_map[] = {
66 1, 5, 5, 2, 3, 4
67};
Richard Smithcb8eab42006-07-24 04:25:47 +000068
Uwe Hermann1a9c8922007-04-01 17:24:03 +000069/* Table format: register, bitmask, value. */
70static const long register_values[] = {
71 /* NBXCFG - NBX Configuration Register
Uwe Hermannf5a6fd22007-05-27 23:31:31 +000072 * 0x50 - 0x53
Uwe Hermann1a9c8922007-04-01 17:24:03 +000073 *
74 * [31:24] SDRAM Row Without ECC
75 * 0 = ECC components are populated in this row
76 * 1 = ECC components are not populated in this row
77 * [23:19] Reserved
78 * [18:18] Host Bus Fast Data Ready Enable (HBFDRE)
79 * Assertion of DRAM data on host bus occurs...
80 * 0 = ...one clock after sampling snoop results (default)
81 * 1 = ...on the same clock the snoop result is being sampled
82 * (this mode is faster by one clock cycle)
83 * [17:17] ECC - EDO static Drive mode
84 * 0 = Normal mode (default)
85 * 1 = ECC signals are always driven
86 * [16:16] IDSEL_REDIRECT
87 * 0 = IDSEL1 is allocated to this bridge (default)
88 * 1 = IDSEL7 is allocated to this bridge
89 * [15:15] WSC# Handshake Disable
90 * 1 = Uni-processor mode
91 * 0 = Dual-processor mode with external IOAPIC (default)
92 * [14:14] Intel Reserved
93 * [13:12] Host/DRAM Frequency
94 * 00 = 100 MHz
95 * 01 = Reserved
96 * 10 = 66 MHz
97 * 11 = Reserved
98 * [11:11] AGP to PCI Access Enable
99 * 1 = Enable
100 * 0 = Disable
101 * [10:10] PCI Agent to Aperture Access Disable
102 * 1 = Disable
103 * 0 = Enable (default)
104 * [09:09] Aperture Access Global Enable
105 * 1 = Enable
106 * 0 = Disable
107 * [08:07] DRAM Data Integrity Mode (DDIM)
108 * 00 = Non-ECC
109 * 01 = EC-only
110 * 10 = ECC Mode
111 * 11 = ECC Mode with hardware scrubbing enabled
112 * [06:06] ECC Diagnostic Mode Enable (EDME)
113 * 1 = Enable
114 * 0 = Normal operation mode (default)
115 * [05:05] MDA Present (MDAP)
116 * Works in conjunction with the VGA_EN bit.
117 * VGA_EN MDAP
118 * 0 x All VGA cycles are sent to PCI
119 * 1 0 All VGA cycles are sent to AGP
120 * 1 1 All VGA cycles are sent to AGP, except for
121 * cycles in the MDA range.
122 * [04:04] Reserved
123 * [03:03] USWC Write Post During I/O Bridge Access Enable (UWPIO)
124 * 1 = Enable
125 * 0 = Disable
126 * [02:02] In-Order Queue Depth (IOQD)
127 * 1 = In-order queue = maximum
128 * 0 = A7# is sampled asserted (i.e., 0)
129 * [01:00] Reserved
Richard Smithcb8eab42006-07-24 04:25:47 +0000130 */
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000131 // TODO
Uwe Hermannbc3594732007-06-07 22:16:30 +0000132 NBXCFG + 0, 0x00, 0x0c,
133 // NBXCFG + 1, 0x00, 0xa0,
134 NBXCFG + 1, 0x00, 0x80,
135 NBXCFG + 2, 0x00, 0x00,
136 NBXCFG + 3, 0x00, 0xff,
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000137
138 /* DRAMC - DRAM Control Register
139 * 0x57
140 *
141 * [7:6] Reserved
142 * [5:5] Module Mode Configuration (MMCONFIG)
143 * TODO
144 * [4:3] DRAM Type (DT)
145 * 00 = EDO
146 * 01 = SDRAM
147 * 10 = Registered SDRAM
148 * 11 = Reserved
149 * Note: EDO, SDRAM and Registered SDRAM cannot be mixed.
150 * [2:0] DRAM Refresh Rate (DRR)
151 * 000 = Refresh disabled
152 * 001 = 15.6 us
153 * 010 = 31.2 us
154 * 011 = 62.4 us
155 * 100 = 124.8 us
156 * 101 = 249.6 us
157 * 110 = Reserved
158 * 111 = Reserved
Richard Smithcb8eab42006-07-24 04:25:47 +0000159 */
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000160 /* Choose SDRAM (not registered), and disable refresh for now. */
Uwe Hermannbc3594732007-06-07 22:16:30 +0000161 DRAMC, 0x00, 0x08,
Richard Smithcb8eab42006-07-24 04:25:47 +0000162
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000163 /*
164 * PAM[6:0] - Programmable Attribute Map Registers
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000165 * 0x59 - 0x5f
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000166 *
167 * 0x59 [3:0] Reserved
168 * 0x59 [5:4] 0xF0000 - 0xFFFFF BIOS area
169 * 0x5a [1:0] 0xC0000 - 0xC3FFF ISA add-on BIOS
170 * 0x5a [5:4] 0xC4000 - 0xC7FFF ISA add-on BIOS
171 * 0x5b [1:0] 0xC8000 - 0xCBFFF ISA add-on BIOS
172 * 0x5b [5:4] 0xCC000 - 0xCFFFF ISA add-on BIOS
173 * 0x5c [1:0] 0xD0000 - 0xD3FFF ISA add-on BIOS
174 * 0x5c [5:4] 0xD4000 - 0xD7FFF ISA add-on BIOS
175 * 0x5d [1:0] 0xD8000 - 0xDBFFF ISA add-on BIOS
176 * 0x5d [5:4] 0xDC000 - 0xDFFFF ISA add-on BIOS
177 * 0x5e [1:0] 0xE0000 - 0xE3FFF BIOS entension
178 * 0x5e [5:4] 0xE4000 - 0xE7FFF BIOS entension
179 * 0x5f [1:0] 0xE8000 - 0xEBFFF BIOS entension
180 * 0x5f [5:4] 0xEC000 - 0xEFFFF BIOS entension
181 *
182 * Bit assignment:
183 * 00 = DRAM Disabled (all access goes to memory mapped I/O space)
184 * 01 = Read Only (Reads to DRAM, writes to memory mapped I/O space)
185 * 10 = Write Only (Writes to DRAM, reads to memory mapped I/O space)
186 * 11 = Read/Write (all access goes to DRAM)
187 */
188 // TODO
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000189 PAM0, 0x00, 0x00,
190 PAM1, 0x00, 0x00,
191 PAM2, 0x00, 0x00,
192 PAM3, 0x00, 0x00,
193 PAM4, 0x00, 0x00,
194 PAM5, 0x00, 0x00,
195 PAM6, 0x00, 0x00,
Richard Smithcb8eab42006-07-24 04:25:47 +0000196
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000197 /* DRB[0:7] - DRAM Row Boundary Registers
198 * 0x60 - 0x67
199 *
200 * An array of 8 byte registers, which hold the ending memory address
201 * assigned to each pair of DIMMs, in 8MB granularity.
202 *
203 * 0x60 DRB0 = Total memory in row0 (in 8 MB)
204 * 0x61 DRB1 = Total memory in row0+1 (in 8 MB)
205 * 0x62 DRB2 = Total memory in row0+1+2 (in 8 MB)
206 * 0x63 DRB3 = Total memory in row0+1+2+3 (in 8 MB)
207 * 0x64 DRB4 = Total memory in row0+1+2+3+4 (in 8 MB)
208 * 0x65 DRB5 = Total memory in row0+1+2+3+4+5 (in 8 MB)
209 * 0x66 DRB6 = Total memory in row0+1+2+3+4+5+6 (in 8 MB)
210 * 0x67 DRB7 = Total memory in row0+1+2+3+4+5+6+7 (in 8 MB)
211 */
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000212 /* Set the DRBs to zero for now, this will be fixed later. */
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000213 DRB0, 0x00, 0x00,
214 DRB1, 0x00, 0x00,
215 DRB2, 0x00, 0x00,
216 DRB3, 0x00, 0x00,
217 DRB4, 0x00, 0x00,
218 DRB5, 0x00, 0x00,
219 DRB6, 0x00, 0x00,
220 DRB7, 0x00, 0x00,
221
222 /* FDHC - Fixed DRAM Hole Control Register
223 * 0x68
224 *
225 * Controls two fixed DRAM holes: 512 KB - 640 KB and 15 MB - 16 MB.
226 *
227 * [7:6] Hole Enable (HEN)
228 * 00 = None
229 * 01 = 512 KB - 640 KB (128 KB)
230 * 10 = 15 MB - 16 MB (1 MB)
231 * 11 = Reserved
232 * [5:0] Reserved
233 */
234 /* No memory holes. */
235 FDHC, 0x00, 0x00,
236
237 /* RPS - SDRAM Row Page Size Register
238 * 0x74 - 0x75
239 *
240 * Sets the row page size for SDRAM. For EDO memory, the page
241 * size is fixed at 2 KB.
242 *
243 * [15:0] Page Size (PS)
244 * TODO
245 */
246 // TODO
Uwe Hermannbc3594732007-06-07 22:16:30 +0000247 RPS + 0, 0x00, 0x00,
248 RPS + 1, 0x00, 0x00,
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000249
250 /* SDRAMC - SDRAM Control Register
Uwe Hermann7ea18cf2007-05-04 00:51:17 +0000251 * 0x76 - 0x77
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000252 *
253 * [15:10] Reserved
254 * [09:08] Idle/Pipeline DRAM Leadoff Timing (IPDLT)
255 * 00 = Illegal
256 * 01 = Add a clock delay to the lead-off clock count
257 * 10 = Illegal
258 * 11 = Illegal
259 * [07:05] SDRAM Mode Select (SMS)
260 * 000 = Normal SDRAM Operation (default)
261 * 001 = NOP Command Enable
262 * 010 = All Banks Precharge Enable
263 * 011 = Mode Register Set Enable
264 * 100 = CBR Enable
265 * 101 = Reserved
266 * 110 = Reserved
267 * 111 = Reserved
268 * [04:04] SDRAMPWR
269 * 0 = 3 DIMM configuration
270 * 1 = 4 DIMM configuration
271 * [03:03] Leadoff Command Timing (LCT)
272 * 0 = 4 CS# Clock
273 * 1 = 3 CS# Clock
274 * [02:02] CAS# Latency (CL)
275 * 0 = 3 DCLK CAS# latency
276 * 1 = 2 DCLK CAS# latency
277 * [01:01] SDRAM RAS# to CAS# Delay (SRCD)
278 * 0 = 3 clocks between a row activate and a read or write cmd.
279 * 1 = 2 clocks between a row activate and a read or write cmd.
280 * [00:00] SDRAM RAS# Precharge (SRP)
281 * 0 = 3 clocks of RAS# precharge
282 * 1 = 2 clocks of RAS# precharge
283 */
Uwe Hermannbc3594732007-06-07 22:16:30 +0000284 SDRAMC + 0, 0x00, 0x00,
Mats Erik Andersson45db3662008-09-30 04:52:29 +0000285 SDRAMC + 1, 0x00, 0x00,
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000286
287 /* PGPOL - Paging Policy Register
288 * 0x78 - 0x79
289 *
290 * [15:08] Banks per Row (BPR)
291 * TODO
292 * 0 = 2 banks
293 * 1 = 4 banks
294 * [07:05] Reserved
295 * [04:04] Intel Reserved
296 * [03:00] DRAM Idle Timer (DIT)
297 * 0000 = 0 clocks
298 * 0001 = 2 clocks
299 * 0010 = 4 clocks
300 * 0011 = 8 clocks
301 * 0100 = 10 clocks
302 * 0101 = 12 clocks
303 * 0110 = 16 clocks
304 * 0111 = 32 clocks
305 * 1xxx = Infinite (pages are not closed for idle condition)
306 */
307 // TODO
Uwe Hermannbc3594732007-06-07 22:16:30 +0000308 PGPOL + 0, 0x00, 0x00,
309 PGPOL + 1, 0x00, 0xff,
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000310
311 /* PMCR - Power Management Control Register
312 * 0x7a
313 *
314 * [07:07] Power Down SDRAM Enable (PDSE)
315 * 1 = Enable
316 * 0 = Disable
317 * [06:06] ACPI Control Register Enable (SCRE)
318 * 1 = Enable
319 * 0 = Disable (default)
320 * [05:05] Suspend Refresh Type (SRT)
321 * 1 = Self refresh mode
322 * 0 = CBR fresh mode
323 * [04:04] Normal Refresh Enable (NREF_EN)
324 * 1 = Enable
325 * 0 = Disable
326 * [03:03] Quick Start Mode (QSTART)
327 * 1 = Quick start mode for the processor is enabled
328 * [02:02] Gated Clock Enable (GCLKEN)
329 * 1 = Enable
330 * 0 = Disable
331 * [01:01] AGP Disable (AGP_DIS)
332 * 1 = Disable
333 * 0 = Enable
334 * [00:00] CPU reset without PCIRST enable (CRst_En)
335 * 1 = Enable
336 * 0 = Disable
337 */
338 /* Enable normal refresh and the gated clock. */
339 // TODO: Only do this later?
340 // PMCR, 0x00, 0x14,
341 // PMCR, 0x00, 0x10,
342 PMCR, 0x00, 0x00,
343};
344
345/*-----------------------------------------------------------------------------
346SDRAM configuration functions.
347-----------------------------------------------------------------------------*/
348
349/**
350 * Send the specified RAM command to all DIMMs.
351 *
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000352 * @param command The RAM command to send to the DIMM(s).
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000353 */
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000354static void do_ram_command(u32 command)
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000355{
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000356 int i, caslatency;
357 u8 dimm_start, dimm_end;
358 u16 reg16;
359 u32 addr, addr_offset;
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000360
361 /* Configure the RAM command. */
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000362 reg16 = pci_read_config16(NB, SDRAMC);
363 reg16 &= 0xff1f; /* Clear bits 7-5. */
364 reg16 |= (u16) (command << 5); /* Write command into bits 7-5. */
365 pci_write_config16(NB, SDRAMC, reg16);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000366
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000367 /*
368 * RAM_COMMAND_NORMAL affects only the memory controller and
369 * doesn't need to be "sent" to the DIMMs.
370 */
371 if (command == RAM_COMMAND_NORMAL)
372 return;
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000373
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000374 /* Send the RAM command to each row of memory. */
375 dimm_start = 0;
376 for (i = 0; i < (DIMM_SOCKETS * 2); i++) {
377 addr_offset = 0;
378 caslatency = 3; /* TODO: Dynamically get CAS latency later. */
379 if (command == RAM_COMMAND_MRS) {
380 /*
381 * MAA[12:11,9:0] must be inverted when sent to DIMM
382 * 2 or 3 (no inversion if sent to DIMM 0 or 1).
383 */
384 if ((i >= 0 && i <= 3) && caslatency == 3)
385 addr_offset = 0x1d0;
386 if ((i >= 4 && i <= 7) && caslatency == 3)
387 addr_offset = 0x1e28;
388 if ((i >= 0 && i <= 3) && caslatency == 2)
389 addr_offset = 0x150;
390 if ((i >= 4 && i <= 7) && caslatency == 2)
391 addr_offset = 0x1ea8;
392 }
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000393
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000394 dimm_end = pci_read_config8(NB, DRB + i);
395
396 addr = (dimm_start * 8 * 1024 * 1024) + addr_offset;
397 if (dimm_end > dimm_start) {
398#if 0
399 PRINT_DEBUG(" Sending RAM command 0x");
400 PRINT_DEBUG_HEX16(reg16);
401 PRINT_DEBUG(" to 0x");
402 PRINT_DEBUG_HEX32(addr);
403 PRINT_DEBUG("\r\n");
404#endif
405
406 read32(addr);
407 }
408
409 /* Set the start of the next DIMM. */
410 dimm_start = dimm_end;
411 }
Richard Smithcb8eab42006-07-24 04:25:47 +0000412}
413
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000414/*-----------------------------------------------------------------------------
415DIMM-independant configuration functions.
416-----------------------------------------------------------------------------*/
Richard Smithcb8eab42006-07-24 04:25:47 +0000417
Uwe Hermann1683cef2008-11-27 00:47:07 +0000418static void spd_enable_refresh(void)
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000419{
420 int i, value;
421 uint8_t reg;
422
Uwe Hermann1683cef2008-11-27 00:47:07 +0000423 reg = pci_read_config8(NB, DRAMC);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000424
425 for (i = 0; i < DIMM_SOCKETS; i++) {
Uwe Hermann1683cef2008-11-27 00:47:07 +0000426 value = spd_read_byte(DIMM_SPD_BASE + i, SPD_REFRESH);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000427 if (value < 0)
428 continue;
429 reg = (reg & 0xf8) | refresh_rate_map[(value & 0x7f)];
430
431 PRINT_DEBUG(" Enabling refresh (DRAMC = 0x");
432 PRINT_DEBUG_HEX8(reg);
433 PRINT_DEBUG(") for DIMM ");
434 PRINT_DEBUG_HEX8(i);
435 PRINT_DEBUG("\r\n");
436 }
437
Uwe Hermann1683cef2008-11-27 00:47:07 +0000438 pci_write_config8(NB, DRAMC, reg);
Richard Smithcb8eab42006-07-24 04:25:47 +0000439}
440
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000441/*-----------------------------------------------------------------------------
442Public interface.
443-----------------------------------------------------------------------------*/
444
Uwe Hermann1683cef2008-11-27 00:47:07 +0000445static void sdram_set_registers(void)
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000446{
447 int i, max;
Uwe Hermannbc3594732007-06-07 22:16:30 +0000448 uint8_t reg;
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000449
450 PRINT_DEBUG("Northbridge prior to SDRAM init:\r\n");
451 DUMPNORTH();
452
Carl-Daniel Hailfinger2ee67792008-10-01 12:52:52 +0000453 max = ARRAY_SIZE(register_values);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000454
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000455 /* Set registers as specified in the register_values[] array. */
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000456 for (i = 0; i < max; i += 3) {
Uwe Hermann1683cef2008-11-27 00:47:07 +0000457 reg = pci_read_config8(NB, register_values[i]);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000458 reg &= register_values[i + 1];
459 reg |= register_values[i + 2] & ~(register_values[i + 1]);
Uwe Hermann1683cef2008-11-27 00:47:07 +0000460 pci_write_config8(NB, register_values[i], reg);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000461
462 PRINT_DEBUG(" Set register 0x");
Uwe Hermannbc3594732007-06-07 22:16:30 +0000463 PRINT_DEBUG_HEX8(register_values[i]);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000464 PRINT_DEBUG(" to 0x");
Uwe Hermannbc3594732007-06-07 22:16:30 +0000465 PRINT_DEBUG_HEX8(reg);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000466 PRINT_DEBUG("\r\n");
467 }
468}
469
Uwe Hermann1683cef2008-11-27 00:47:07 +0000470static void sdram_set_spd_registers(void)
Richard Smithcb8eab42006-07-24 04:25:47 +0000471{
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000472 /* TODO: Don't hardcode the values here, get info via SPD. */
473
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000474 /* Map all legacy regions to RAM (read/write). This is required if
475 * you want to use the RAM area from 768 KB - 1 MB. If the PAM
476 * registers are not set here appropriately, the RAM in that region
477 * will not be accessible, thus a RAM check of it will also fail.
478 */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000479 pci_write_config8(NB, PAM0, 0x30);
480 pci_write_config8(NB, PAM1, 0x33);
481 pci_write_config8(NB, PAM2, 0x33);
482 pci_write_config8(NB, PAM3, 0x33);
483 pci_write_config8(NB, PAM4, 0x33);
484 pci_write_config8(NB, PAM5, 0x33);
485 pci_write_config8(NB, PAM6, 0x33);
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000486
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000487 /* TODO: Set DRB0-DRB7. */
Uwe Hermannf5a6fd22007-05-27 23:31:31 +0000488 /* Currently this is hardcoded to one 64 MB DIMM in slot 0. */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000489 pci_write_config8(NB, DRB0, 0x08);
490 pci_write_config8(NB, DRB1, 0x08);
491 pci_write_config8(NB, DRB2, 0x08);
492 pci_write_config8(NB, DRB3, 0x08);
493 pci_write_config8(NB, DRB4, 0x08);
494 pci_write_config8(NB, DRB5, 0x08);
495 pci_write_config8(NB, DRB6, 0x08);
496 pci_write_config8(NB, DRB7, 0x08);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000497
498 /* TODO: Set DRAMC. Don't enable refresh for now. */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000499 pci_write_config8(NB, DRAMC, 0x08);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000500
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000501 /* TODO: Set RPS. Needs to be fixed for multiple DIMM support. */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000502 pci_write_config16(NB, RPS, 0x0001);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000503
504 /* TODO: Set SDRAMC. */
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000505 pci_write_config16(NB, SDRAMC, 0x0010); /* SDRAMPWR=1: 4 DIMM config */
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000506
507 /* TODO: Set PGPOL. */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000508 // pci_write_config16(NB, PGPOL, 0x0107);
509 pci_write_config16(NB, PGPOL, 0x0123);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000510
511 /* TODO: Set NBXCFG. */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000512 // pci_write_config32(NB, NBXCFG, 0x0100220c); // FIXME?
513 pci_write_config32(NB, NBXCFG, 0xff00800c);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000514
515 /* TODO: Set PMCR? */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000516 // pci_write_config8(NB, PMCR, 0x14);
517 pci_write_config8(NB, PMCR, 0x10);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000518
519 /* TODO? */
Uwe Hermann1683cef2008-11-27 00:47:07 +0000520 pci_write_config8(NB, PCI_LATENCY_TIMER, 0x40);
521 pci_write_config8(NB, DRAMT, 0x03);
522 pci_write_config8(NB, MBSC, 0x03);
523 pci_write_config8(NB, SCRR, 0x38);
Richard Smithcb8eab42006-07-24 04:25:47 +0000524}
525
Uwe Hermann1683cef2008-11-27 00:47:07 +0000526static void sdram_enable(void)
Richard Smithcb8eab42006-07-24 04:25:47 +0000527{
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000528 int i;
Richard Smithcb8eab42006-07-24 04:25:47 +0000529
Uwe Hermann861f9642007-05-28 14:37:06 +0000530 /* 0. Wait until power/voltages and clocks are stable (200us). */
531 udelay(200);
Richard Smithcb8eab42006-07-24 04:25:47 +0000532
Uwe Hermann861f9642007-05-28 14:37:06 +0000533 /* 1. Apply NOP. Wait 200 clock cycles (200us should do). */
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000534 PRINT_DEBUG("RAM Enable 1: Apply NOP\r\n");
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000535 do_ram_command(RAM_COMMAND_NOP);
Uwe Hermann861f9642007-05-28 14:37:06 +0000536 udelay(200);
Richard Smithcb8eab42006-07-24 04:25:47 +0000537
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000538 /* 2. Precharge all. Wait tRP. */
539 PRINT_DEBUG("RAM Enable 2: Precharge all\r\n");
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000540 do_ram_command(RAM_COMMAND_PRECHARGE);
Uwe Hermann861f9642007-05-28 14:37:06 +0000541 udelay(1);
Richard Smithcb8eab42006-07-24 04:25:47 +0000542
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000543 /* 3. Perform 8 refresh cycles. Wait tRC each time. */
544 PRINT_DEBUG("RAM Enable 3: CBR\r\n");
545 for (i = 0; i < 8; i++) {
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000546 do_ram_command(RAM_COMMAND_CBR);
Uwe Hermann861f9642007-05-28 14:37:06 +0000547 udelay(1);
Richard Smithcb8eab42006-07-24 04:25:47 +0000548 }
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000549
550 /* 4. Mode register set. Wait two memory cycles. */
551 PRINT_DEBUG("RAM Enable 4: Mode register set\r\n");
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000552 do_ram_command(RAM_COMMAND_MRS);
Uwe Hermann861f9642007-05-28 14:37:06 +0000553 udelay(2);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000554
555 /* 5. Normal operation. */
556 PRINT_DEBUG("RAM Enable 5: Normal operation\r\n");
Uwe Hermann8b643cea2008-12-09 16:36:12 +0000557 do_ram_command(RAM_COMMAND_NORMAL);
Uwe Hermann861f9642007-05-28 14:37:06 +0000558 udelay(1);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000559
560 /* 6. Finally enable refresh. */
561 PRINT_DEBUG("RAM Enable 6: Enable refresh\r\n");
Uwe Hermann1683cef2008-11-27 00:47:07 +0000562 // pci_write_config8(NB, PMCR, 0x10);
563 spd_enable_refresh();
Uwe Hermann861f9642007-05-28 14:37:06 +0000564 udelay(1);
Uwe Hermann1a9c8922007-04-01 17:24:03 +0000565
566 PRINT_DEBUG("Northbridge following SDRAM init:\r\n");
567 DUMPNORTH();
Richard Smithcb8eab42006-07-24 04:25:47 +0000568}