Make ASUS P3B-F RAM init actually work by enabling SPD access.
[coreboot.git] / src / mainboard / asus / p3b-f / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Uwe Hermann <uwe@hermann-uwe.de>
5  *
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
19  */
20
21 #include <stdint.h>
22 #include <device/pci_def.h>
23 #include <arch/io.h>
24 #include <device/pnp_def.h>
25 #include <arch/romcc_io.h>
26 #include <arch/hlt.h>
27 #include <stdlib.h>
28 #include <console/console.h>
29 #include "lib/ramtest.c"
30 #include "southbridge/intel/i82371eb/i82371eb_enable_rom.c"
31 #include "southbridge/intel/i82371eb/i82371eb_early_smbus.c"
32 #include "southbridge/intel/i82371eb/i82371eb_early_pm.c"
33 #include "northbridge/intel/i440bx/raminit.h"
34 #include "lib/debug.c"
35 #include "pc80/udelay_io.c"
36 #include "lib/delay.c"
37 #include "cpu/x86/mtrr/earlymtrr.c"
38 #include "cpu/x86/bist.h"
39 /* FIXME: The ASUS P3B-F has a Winbond W83977EF, actually. */
40 #include "superio/winbond/w83977tf/w83977tf_early_serial.c"
41
42 /* FIXME: The ASUS P3B-F has a Winbond W83977EF, actually. */
43 #define SERIAL_DEV PNP_DEV(0x3f0, W83977TF_SP1)
44
45 static inline int spd_read_byte(unsigned int device, unsigned int address)
46 {
47         return smbus_read_byte(device, address);
48 }
49
50 #include "northbridge/intel/i440bx/raminit.c"
51 #include "northbridge/intel/i440bx/debug.c"
52
53 /*
54  * ASUS P3B-F specific SPD enable magic.
55  *
56  * Setting the byte at offset 0x37 in the PM I/O space to 0x6f will make the
57  * board DIMMs accessible at SMBus/SPD offsets 0x50-0x53. Per default the SPD
58  * offsets 0x50-0x53 are _not_ readable (all SPD reads will return 0xff) which
59  * will make RAM init fail.
60  *
61  * Tested values for PM I/O offset 0x37:
62  * 0x67: 11 00 111: Only SMBus/I2C offsets 0x48/0x49/0x2d accessible
63  * 0x6f: 11 01 111: Only SMBus/I2C offsets 0x50-0x53 (SPD) accessible
64  * 0x77: 11 10 111: Only SMBus/I2C offset 0x69 accessible
65  *
66  * PM I/O space offset 0x37 is GPOREG[31:24], i.e. it controls the GPIOs
67  * 24-30 of the PIIX4E (bit 31 is reserved). Thus, GPIOs 27 and 28
68  * control which SMBus/I2C offsets can be accessed.
69  */
70 static void enable_spd(void)
71 {
72         outb(0x6f, PM_IO_BASE + 0x37);
73 }
74
75 /*
76  * Disable SPD access after RAM init to allow access to SMBus/I2C offsets
77  * 0x48/0x49/0x2d, which is required e.g. by lm-sensors.
78  */
79 static void disable_spd(void)
80 {
81         outb(0x67, PM_IO_BASE + 0x37);
82 }
83
84 static void main(unsigned long bist)
85 {
86         if (bist == 0)
87                 early_mtrr_init();
88
89         /* FIXME: The ASUS P3B-F has a Winbond W83977EF, actually. */
90         w83977tf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
91         uart_init();
92         console_init();
93         report_bist_failure(bist);
94
95         /* Enable access to the full ROM chip, needed very early by CBFS. */
96         i82371eb_enable_rom(PCI_DEV(0, 4, 0)); /* ISA bridge is 00:04.0. */
97
98         enable_smbus();
99         enable_pm();
100
101         enable_spd();
102
103         /* dump_spd_registers(); */
104         sdram_set_registers();
105         sdram_set_spd_registers();
106         sdram_enable();
107         /* ram_check(0, 640 * 1024); */
108
109         disable_spd();
110 }
111