cff36d23fba7e6354956bab9f8e37a1bb2829bfc
[coreboot.git] / src / mainboard / rca / rm4100 / auto.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
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 #define ASSEMBLY 1
22
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <device/pci_def.h>
26 #include <arch/io.h>
27 #include <device/pnp_def.h>
28 #include <arch/romcc_io.h>
29 #include <arch/hlt.h>
30 #include "pc80/serial.c"
31 #include "pc80/udelay_io.c"
32 #include "arch/i386/lib/console.c"
33 #include "ram/ramtest.c"
34 #include "superio/smsc/smscsuperio/smscsuperio_early_serial.c"
35 #include "northbridge/intel/i82830/raminit.h"
36 #include "southbridge/intel/i82801xx/i82801xx.h"
37 #include "cpu/x86/mtrr/earlymtrr.c"
38 #include "cpu/x86/bist.h"
39 #include "spd_table.h"
40 #include "gpio.c"
41
42 #define SERIAL_DEV PNP_DEV(0x2e, SMSCSUPERIO_SP1)
43
44 #include "southbridge/intel/i82801xx/i82801xx_early_smbus.c"
45
46 /**
47  * The onboard 128MB PC133 memory does not have a SPD EEPROM so the
48  * values have to be set manually, the SO-DIMM socket is located in
49  * socket0 (0x50), and the onboard memory is located in socket1 (0x51).
50  */
51 static inline int spd_read_byte(unsigned device, unsigned address)
52 {
53         int i;
54
55         if (device == 0x50) {
56                 return smbus_read_byte(device, address);
57         } else if (device == 0x51) {
58                 for (i = 0; i < ARRAY_SIZE(spd_table); i++) {
59                         if (spd_table[i].address == address)
60                                 return spd_table[i].data;
61                 }
62                 return 0xFF; /* Return 0xFF when address is not found. */
63         } else {
64                 return 0xFF; /* Return 0xFF on any failures. */
65         }
66 }
67
68 #include "northbridge/intel/i82830/raminit.c"
69 #include "sdram/generic_sdram.c"
70
71 /**
72  * We have to disable the TCO Timer system reboot feature
73  * or we get several reboots through out the boot processes.
74  */
75 static void disable_tco_timer(void)
76 {
77         device_t dev;
78         u8 reg8;
79
80         /* Set the LPC device statically. */
81         dev = PCI_DEV(0x0, 0x1f, 0x0);
82
83         /* Disable the TCO Timer system reboot feature. */
84         reg8 = pci_read_config8(dev, 0xd4);
85         reg8 |= (1 << 1);
86         pci_write_config8(dev, 0xd4, reg8);
87 }
88
89 /**
90  * The AC'97 Audio Controller I/O space registers are read only by default
91  * so we need to enable them by setting register 0x41 to 0x01.
92  */
93 static void ac97_io_enable(void)
94 {
95         device_t dev;
96
97         /* Set the ac97 audio device staticly. */
98         dev = PCI_DEV(0x0, 0x1f, 0x5);
99
100         /* Enable access to the IO space. */
101         pci_write_config8(dev, 0x41, 0x01);
102 }
103
104 static void main(unsigned long bist)
105 {
106         static const struct mem_controller memctrl[] = {
107                 {
108                         .d0 = PCI_DEV(0, 0, 0),
109                         .channel0 = {0x50, 0x51},
110                 }
111         };
112
113         if (bist == 0)
114                 early_mtrr_init();
115
116         enable_smbus();
117
118         smscsuperio_enable_serial(SERIAL_DEV, TTYS0_BASE);
119         mb_gpio_init();
120         uart_init();
121         console_init();
122
123         /* Halt if there was a built in self test failure. */
124         report_bist_failure(bist);
125
126         sdram_set_registers(memctrl);
127         sdram_set_spd_registers(memctrl);
128         sdram_enable(0, memctrl);
129
130         /* Check RAM. */
131         /* ram_check(0, 640 * 1024); */
132         /* ram_check(130048 * 1024, 131072 * 1024); */
133
134         disable_tco_timer();
135         ac97_io_enable();
136 }