On Mon, Nov 27, 2006 at 09:05:12AM +0100, Segher Boessenkool wrote:
> Okay...  So, is this your DIMM?
> 
> 100MHz SDRAM, 64MB, in last (4th) slot.

Yep. There are only 3 slots on the board, but the SPD dump says it's the
last one (number 3, i.e., the 4th), too.


> You did forget a few registers though -- the three bytes
> at offset 0xca, and the 16 bytes at offset 0xe0.

Yeah, I previously ignored those as the code from v1 didn't set them
AFAIK. I set them now, though.
http://tracker.linuxbios.org/trac/LinuxBIOS/browser/trunk/LinuxBIOSv1/src/northbridge/intel/440bx/raminit.inc


> Be careful
> to set the enable bit (bit 7 in 0xe7) last.

Yep. As the last step in sdram_set_registers() or as the last step
in RAM init in general?


> Also, you probably didn't program the MRS on the memory.

Yes, I'm quite sure I messed that up. In general, in do_ram_command() I
have to set DRAMC bits 7-5 to the respective command and then read32() from
some memory location for the change to "take effect", right?
If so, which memory location is that? Does it depend on some input data?

I still don't really understand this part of the RAM init, so the code
might be very, very wrong...


> You should do that with the register at 0x76.  The correct
> sequence is:
> 
> - precharge all banks, wait tRP
> - refresh, wait tRC (do this step 8 times)
> - write to MRS, wait 2 memory cycles

I think I got this part right mostly.


> To figure out what host addresses you should use to get
> onto the DRAM address pins A13..A0, look at the tables in
> chapter 4.3.  I think shifting to the left by 15 bits would
> work in your case, so accessing address 0x1d0000.  This
> should be done per DIMM rank, but you only have one anyway :-)

Hm, so just read32(0x1d0000) and that's it? I tried that but it failed.
(but there are a ton of other errors I might still have in the code)

Attached is my stripped-down raminit.c which does the bare minimum
hardcoding of the values and nothing more. It doesn't work, and
after quite a lot of testing I can't seem to find the problem(s).

Shifting by 15 causes a hang in ram_check() so I tried 23 (looking at
the v1 code). Again, I don't know what I'm doing here ;-)

Btw, I'm now running ram_check(0x1000, 0x4000000); which should check
all of the 64MB of RAM, right?


Thanks, Uwe.
-- 
http://www.hermann-uwe.de  | http://www.holsham-traders.de
http://www.crazy-hacks.org | http://www.unmaintained-free-software.org
#include <spd.h>
#include <sdram_mode.h>
#include "i440bx.h"


/*-----------------------------------------------------------------------------
Definitions.
-----------------------------------------------------------------------------*/

/* Uncomment this to enable local debugging messages. */
#define DEBUG_RAM_CONFIG 1

/* Debugging macros. */
#if defined(DEBUG_RAM_CONFIG)
#define RAM_DEBUG_MESSAGE(x)  print_debug(x)
#define RAM_DEBUG_HEX32(x)    print_debug_hex32(x)
#define RAM_DEBUG_HEX8(x)     print_debug_hex8(x)
#define DUMPNORTH()           dump_pci_device(PCI_DEV(0, 0, 0))
#else
#define RAM_DEBUG_MESSAGE(x)
#define RAM_DEBUG_HEX32(x)
#define RAM_DEBUG_HEX8(x)
#define DUMPNORTH()
#endif

/* SDRAMC[7:5] - SDRAM Mode Select (SMS). */
#define RAM_COMMAND_NORMAL    0x0
#define RAM_COMMAND_NOP       0x1
#define RAM_COMMAND_PRECHARGE 0x2
#define RAM_COMMAND_MRS       0x3
#define RAM_COMMAND_CBR       0x4

/* Map the JEDEC SPD refresh rates (array index) to 440BX refresh rates as
 * defined in DRAMC[2:0].
 *
 * [0] == Normal        15.625 us ->  15.6 us
 * [1] == Reduced(.25X)    3.9 us ->   7.8 ns
 * [2] == Reduced(.5X)     7.8 us ->   7.8 us
 * [3] == Extended(2x)    31.3 us ->  31.2 us
 * [4] == Extended(4x)    62.5 us ->  62.4 us
 * [5] == Extended(8x)     125 us -> 124.8 us
 */
static const uint32_t refresh_rate_map[] = {
	1, 5, 5, 2, 3, 4
};


/*-----------------------------------------------------------------------------
Delay functions.
-----------------------------------------------------------------------------*/

#define SLOW_DOWN_IO inb(0x80);

static void do_delay(void)
{
	int i;
	for (i = 0; i < 16; i++) {
		SLOW_DOWN_IO
	}
}

#define DO_DELAY do_delay();
#define EXTRA_DELAY DO_DELAY


/*-----------------------------------------------------------------------------
SDRAM configuration functions.
-----------------------------------------------------------------------------*/

static void do_ram_command(const struct mem_controller *ctrl,
			   uint32_t command, uint16_t jedec_mode_bits)
{
	int i;
	uint16_t reg;

	/* Configure the RAM command. */
	reg = pci_read_config16(ctrl->d0, SDRAMC);
	reg &= 0xff1f; /* Clear bits 7-5. */
	reg |= (uint16_t)(command << 5);
	pci_write_config16(ctrl->d0, SDRAMC, reg);

	/* RAM_COMMAND_NORMAL affects only the memory controller and
	   doesn't need to be "sent" to the DIMMs. */
	/* if (command == RAM_COMMAND_NORMAL) return; */

	RAM_DEBUG_MESSAGE("    Sending RAM command to ");
	RAM_DEBUG_HEX32(reg << 23);
	RAM_DEBUG_MESSAGE("\r\n");

	read32(reg << 23);
}


/*-----------------------------------------------------------------------------
DIMM-independant configuration functions.
-----------------------------------------------------------------------------*/

static void spd_enable_refresh(const struct mem_controller *ctrl)
{
	uint8_t reg;
	int i, value;

	reg = pci_read_config8(ctrl->d0, DRAMC);

	for (i = 0; i < MAX_DIMM_SOCKETS_PER_CHANNEL; i++) {
		value = spd_read_byte(ctrl->channel0[i], SPD_REFRESH);
		if (value < 0) continue;

		reg = (reg & 0xf8) | refresh_rate_map[(value & 0x7f)];
	}

	pci_write_config8(ctrl->d0, DRAMC, reg);
}


/*-----------------------------------------------------------------------------
Public interface.
-----------------------------------------------------------------------------*/

static void sdram_set_registers(const struct mem_controller *ctrl)
{
	RAM_DEBUG_MESSAGE("Northbridge prior to SDRAM init:\r\n");
	DUMPNORTH();

	pci_write_config8(ctrl->d0, PAM0, 0x10);
	pci_write_config8(ctrl->d0, PAM1, 0x11);
	pci_write_config8(ctrl->d0, PAM2, 0x01);
	pci_write_config8(ctrl->d0, PAM3, 0x00);
	pci_write_config8(ctrl->d0, PAM4, 0x00);
	pci_write_config8(ctrl->d0, PAM5, 0x00);
	pci_write_config8(ctrl->d0, PAM6, 0x00);

	pci_write_config8(ctrl->d0, 0x13, 0xd8);
	pci_write_config8(ctrl->d0, 0x92, 0x00);

	pci_write_config8(ctrl->d0, 0x0d, 0x40);
	pci_write_config8(ctrl->d0, 0x13, 0xd8);

	pci_write_config8(ctrl->d0, DRAMT, 0x00);
	pci_write_config8(ctrl->d0, 0x6d, 0x2a);
	pci_write_config8(ctrl->d0, 0x70, 0x20);
	pci_write_config8(ctrl->d0, SMRAM, 0x0a);
	pci_write_config8(ctrl->d0, 0x80, 0x02);

	pci_write_config8(ctrl->d0, 0x90, 0x98);
	pci_write_config8(ctrl->d0, 0x91, 0xcc);
	pci_write_config8(ctrl->d0, 0xb0, 0x80);
	pci_write_config8(ctrl->d0, 0xb1, 0x20);
	pci_write_config8(ctrl->d0, 0xb4, 0x30);
	pci_write_config8(ctrl->d0, 0xba, 0xc3);
	pci_write_config8(ctrl->d0, 0xbb, 0x03);
	pci_write_config8(ctrl->d0, 0xbc, 0x20);
	pci_write_config8(ctrl->d0, 0xbd, 0x10);
	pci_write_config8(ctrl->d0, 0xc4, 0xff);
	pci_write_config8(ctrl->d0, 0xc5, 0xfc);
	pci_write_config8(ctrl->d0, 0xc6, 0xff);
	pci_write_config8(ctrl->d0, 0xc7, 0xff);
	pci_write_config8(ctrl->d0, 0xc8, 0x18);
	pci_write_config8(ctrl->d0, 0xc9, 0x0c);
	pci_write_config8(ctrl->d0, 0xca, 0xff);
	pci_write_config8(ctrl->d0, 0xcb, 0xff);
	pci_write_config8(ctrl->d0, 0xcc, 0x61);
	pci_write_config8(ctrl->d0, 0xe0, 0x4c);
	pci_write_config8(ctrl->d0, 0xe1, 0xad);
	pci_write_config8(ctrl->d0, 0xe2, 0xff);
	pci_write_config8(ctrl->d0, 0xe3, 0xbb);
	pci_write_config8(ctrl->d0, 0xe4, 0x8a);
	pci_write_config8(ctrl->d0, 0xe5, 0x3e);
	pci_write_config8(ctrl->d0, 0xe6, 0x00);
	/* pci_write_config8(ctrl->d0, 0xe7, 0x80); */
	pci_write_config8(ctrl->d0, 0xe8, 0x2c);
	pci_write_config8(ctrl->d0, 0xe9, 0xd3);
	pci_write_config8(ctrl->d0, 0xea, 0xf7);
	pci_write_config8(ctrl->d0, 0xeb, 0xcf);
	pci_write_config8(ctrl->d0, 0xec, 0x9d);
	pci_write_config8(ctrl->d0, 0xed, 0x3e);
	pci_write_config8(ctrl->d0, 0xee, 0x00);
	pci_write_config8(ctrl->d0, 0xef, 0x00);
	pci_write_config8(ctrl->d0, 0xf0, 0x40);
	pci_write_config8(ctrl->d0, 0xf1, 0x01);
	pci_write_config8(ctrl->d0, 0xf7, 0x60);

	/* Now set bit 7 of 0xe7 (must come last). */
	pci_write_config8(ctrl->d0, 0xe7, 0x80);
}

static void sdram_set_spd_registers(const struct mem_controller *ctrl) 
{
	pci_write_config8(ctrl->d0, DRB0, 0x00);
	pci_write_config8(ctrl->d0, DRB1, 0x00);
	pci_write_config8(ctrl->d0, DRB2, 0x00);
	pci_write_config8(ctrl->d0, DRB3, 0x00);
	pci_write_config8(ctrl->d0, DRB4, 0x00);
	pci_write_config8(ctrl->d0, DRB5, 0x00);
	pci_write_config8(ctrl->d0, DRB6, 0x08);
	pci_write_config8(ctrl->d0, DRB7, 0x08);

	/* Don't enable refresh for now. */
	pci_write_config8(ctrl->d0, DRAMC, 0x08);

	pci_write_config16(ctrl->d0, RPS, 0x1000);
	pci_write_config16(ctrl->d0, SDRAMC, 0x0110);
	pci_write_config16(ctrl->d0, PGPOL, 0xff23);
	pci_write_config32(ctrl->d0, NBXCFG, 0xff008a0c);
	pci_write_config8(ctrl->d0, PMCR, 0x10);
}

static void sdram_enable(int controllers, const struct mem_controller *ctrl)
{
	/* 1. & 2. Power up and start clocks. */
	RAM_DEBUG_MESSAGE("Ram Enable 1: Power up\r\n");
	RAM_DEBUG_MESSAGE("Ram Enable 2: Start clocks\r\n");

	/* A 200us delay is needed. */
	DO_DELAY
	EXTRA_DELAY

	/* 3. Apply NOP. */
	RAM_DEBUG_MESSAGE("Ram Enable 3: Apply NOP\r\n");
	do_ram_command(ctrl, RAM_COMMAND_NOP, 0);
	EXTRA_DELAY

	/* 4. Precharge all. */
	RAM_DEBUG_MESSAGE("Ram Enable 4: Precharge all\r\n");
	do_ram_command(ctrl, RAM_COMMAND_PRECHARGE, 0);
	EXTRA_DELAY
	
	/* 5. Issue EMRS to enable DLL. */
	/* TODO: Not needed on 440BX? */
	
	/* 6. Reset DLL. */
	/* TODO: Not needed on 440BX? */

	/* DO_DELAY */
	/* EXTRA_DELAY */
	/* TODO: Not needed on 440BX? */
	
	/* 7. Precharge all. */
	/* TODO: Not needed on 440BX? */
	
	/* 8. Now we need 2 AUTO REFRESH / CBR cycles to be performed. */
	RAM_DEBUG_MESSAGE("Ram Enable 8: CBR\r\n");
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY
	/* And for good luck 6 more CBRs. */
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY
	do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
	EXTRA_DELAY

	/* 9. Mode register set. */
	RAM_DEBUG_MESSAGE("Ram Enable 9: Mode register set\r\n");
	/* do_ram_command(ctrl, RAM_COMMAND_MRS, 0); */
	pci_write_config16(ctrl->d0, SDRAMC, 0x3a);
	RAM_DEBUG_MESSAGE("    Sending RAM command to (0x3a << 23)\r\n");
	read32(0x3a << 23);
	EXTRA_DELAY

	/* 10. DDR Receive FIFO RE-Sync. */
	/* TODO: Not needed on 440BX? */
	
	/* 11. Normal operation. */
	RAM_DEBUG_MESSAGE("Ram Enable 11: Normal operation\r\n");
	do_ram_command(ctrl, RAM_COMMAND_NORMAL, 0);
	EXTRA_DELAY

	/* Finally enable refresh. */
	spd_enable_refresh(ctrl);
	EXTRA_DELAY

	RAM_DEBUG_MESSAGE("Northbridge following SDRAM init:\r\n");
	DUMPNORTH();
}

Attachment: signature.asc
Description: Digital signature

-- 
linuxbios mailing list
[email protected]
http://www.openbios.org/mailman/listinfo/linuxbios

Reply via email to