344e0eed84e3092dc259dc0b77d62e2c3ce3cd88
[coreboot.git] / src / mainboard / lippert / spacerunner-lx / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  * Copyright (C) 2008 LiPPERT Embedded Computers GmbH
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 /* Based on romstage.c from AMD's DB800 and DBM690T mainboards. */
23
24 #include <stdlib.h>
25 #include <stdint.h>
26 #include <spd.h>
27 #include <device/pci_def.h>
28 #include <arch/io.h>
29 #include <device/pnp_def.h>
30 #include <arch/hlt.h>
31 #include "pc80/serial.c"
32 #include "console/console.c"
33 #include "lib/ramtest.c"
34 #include "cpu/x86/bist.h"
35 #include "cpu/x86/msr.h"
36 #include <cpu/amd/lxdef.h>
37 #include <cpu/amd/geode_post_code.h>
38 #include "southbridge/amd/cs5536/cs5536.h"
39
40 #define POST_CODE(x) outb(x, 0x80)
41
42 #include "southbridge/amd/cs5536/cs5536_early_smbus.c"
43 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
44 #include "superio/ite/it8712f/it8712f_early_serial.c"
45
46 /* Bit0 enables Spread Spectrum, bit1 makes on-board SSD act as IDE slave. */
47 #define SMC_CONFIG 0x01
48
49 #define ManualConf 1            /* No automatic strapped PLL config */
50 #define PLLMSRhi 0x0000059C     /* Manual settings for the PLL */
51 #define PLLMSRlo 0x00DE6001
52 #define DIMM0 0xA0
53 #define DIMM1 0xA2
54
55 static const unsigned char spdbytes[] = {       // 4x Promos V58C2512164SA-J5I
56         0xFF, 0xFF,                             // only values used by Geode-LX raminit.c are set
57         [SPD_MEMORY_TYPE]               = SPD_MEMORY_TYPE_SDRAM_DDR,    // (Fundamental) memory type
58         [SPD_NUM_ROWS]                  = 0x0D, // Number of row address bits [13]
59         [SPD_NUM_COLUMNS]               = 0x0A, // Number of column address bits [10]
60         [SPD_NUM_DIMM_BANKS]            = 1,    // Number of module rows (banks)
61         0xFF, 0xFF, 0xFF,
62         [SPD_MIN_CYCLE_TIME_AT_CAS_MAX] = 0x50, // SDRAM cycle time (highest CAS latency), RAS access time (tRAC) [5.0 ns in BCD]
63         0xFF, 0xFF,
64         [SPD_REFRESH]                   = 0x82, // Refresh rate/type [Self Refresh, 7.8 us]
65         [SPD_PRIMARY_SDRAM_WIDTH]       = 64,   // SDRAM width (primary SDRAM) [64 bits]
66         0xFF, 0xFF, 0xFF,
67         [SPD_NUM_BANKS_PER_SDRAM]       = 4,    // SDRAM device attributes, number of banks on SDRAM device
68         [SPD_ACCEPTABLE_CAS_LATENCIES]  = 0x1C, // SDRAM device attributes, CAS latency [3, 2.5, 2]
69         0xFF, 0xFF,
70         [SPD_MODULE_ATTRIBUTES]         = 0x20, // SDRAM module attributes [differential clk]
71         [SPD_DEVICE_ATTRIBUTES_GENERAL] = 0x40, // SDRAM device attributes, general [Concurrent AP]
72         [SPD_SDRAM_CYCLE_TIME_2ND]      = 0x60, // SDRAM cycle time (2nd highest CAS latency) [6.0 ns in BCD]
73         0xFF,
74         [SPD_SDRAM_CYCLE_TIME_3RD]      = 0x75, // SDRAM cycle time (3rd highest CAS latency) [7.5 ns in BCD]
75         0xFF,
76         [SPD_tRP]                       = 60,   // Min. row precharge time [15 ns in units of 0.25 ns]
77         [SPD_tRRD]                      = 40,   // Min. row active to row active [10 ns in units of 0.25 ns]
78         [SPD_tRCD]                      = 60,   // Min. RAS to CAS delay [15 ns in units of 0.25 ns]
79         [SPD_tRAS]                      = 40,   // Min. RAS pulse width = active to precharge delay [40 ns]
80         [SPD_BANK_DENSITY]              = 0x40, // Density of each row on module [256 MB]
81         0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
82         [SPD_tRFC]                      = 70    // SDRAM Device Minimum Auto Refresh to Active/Auto Refresh [70 ns]
83 };
84
85 static inline int spd_read_byte(unsigned int device, unsigned int address)
86 {
87         if (device != DIMM0)
88                 return 0xFF;    /* No DIMM1, don't even try. */
89
90 #if CONFIG_DEBUG
91         if (address >= sizeof(spdbytes) || spdbytes[address] == 0xFF) {
92                 print_err("ERROR: spd_read_byte(DIMM0, 0x");
93                 print_err_hex8(address);
94                 print_err(") returns 0xff\n");
95         }
96 #endif
97
98         /* Fake SPD ROM value */
99         return (address < sizeof(spdbytes)) ? spdbytes[address] : 0xFF;
100 }
101
102 /* Send config data to System Management Controller via SMB. */
103 static int smc_send_config(unsigned char config_data)
104 {
105         if (smbus_check_stop_condition(SMBUS_IO_BASE))
106                 return 1;
107         if (smbus_start_condition(SMBUS_IO_BASE))
108                 return 2;
109         if (smbus_send_slave_address(SMBUS_IO_BASE, 0x50)) // SMC address
110                 return 3;
111         if (smbus_send_command(SMBUS_IO_BASE, 0x28)) // set config data
112                 return 4;
113         if (smbus_send_command(SMBUS_IO_BASE, 0x01)) // data length
114                 return 5;
115         if (smbus_send_command(SMBUS_IO_BASE, config_data))
116                 return 6;
117         smbus_stop_condition(SMBUS_IO_BASE);
118         return 0;
119 }
120
121 #include "northbridge/amd/lx/raminit.h"
122 #include "northbridge/amd/lx/pll_reset.c"
123 #include "northbridge/amd/lx/raminit.c"
124 #include "lib/generic_sdram.c"
125 #include "cpu/amd/model_lx/cpureginit.c"
126 #include "cpu/amd/model_lx/syspreinit.c"
127
128 static void msr_init(void)
129 {
130         msr_t msr;
131
132         /* Setup access to the cache for under 1MB. */
133         msr.hi = 0x24fffc02;
134         msr.lo = 0x1000A000;    /* 0-A0000 write back */
135         wrmsr(CPU_RCONF_DEFAULT, msr);
136
137         msr.hi = 0x0;           /* Write back */
138         msr.lo = 0x0;
139         wrmsr(CPU_RCONF_A0_BF, msr);
140         wrmsr(CPU_RCONF_C0_DF, msr);
141         wrmsr(CPU_RCONF_E0_FF, msr);
142
143         /* Setup access to the cache for under 640K. Note MC not setup yet. */
144         msr.hi = 0x20000000;
145         msr.lo = 0xfff80;
146         wrmsr(MSR_GLIU0 + 0x20, msr);
147
148         msr.hi = 0x20000000;
149         msr.lo = 0x80fffe0;
150         wrmsr(MSR_GLIU0 + 0x21, msr);
151
152         msr.hi = 0x20000000;
153         msr.lo = 0xfff80;
154         wrmsr(MSR_GLIU1 + 0x20, msr);
155
156         msr.hi = 0x20000000;
157         msr.lo = 0x80fffe0;
158         wrmsr(MSR_GLIU1 + 0x21, msr);
159 }
160
161 static const u16 sio_init_table[] = { // hi=data, lo=index
162         0x0707,         // select LDN 7 (GPIO, SPI, watchdog, ...)
163         0x1E2C,         // disable ATXPowerGood
164         0x0423,         // don't delay POWerOK1/2
165         0x9072,         // watchdog triggers POWOK, counts seconds
166 #if !CONFIG_USE_WATCHDOG_ON_BOOT
167         0x0073, 0x0074, // disable watchdog by setting timeout to 0
168 #endif
169         0xBF25, 0x172A, 0xF326, // select GPIO function for most pins
170         0xFF27, 0xDF28, 0x2729, // (GP45=SUSB, GP23,22,16,15=SPI, GP13=PWROK1)
171         0x072C,         // VIN6=enabled?, FAN4/5 disabled, VIN7=internal, VIN3=internal
172         0x66B8, 0x0CB9, // enable pullups
173         0x07C0,         // enable Simple-I/O for GP12-10= RS485_EN2,1, LIVE_LED
174         0x07C8,         // config GP12-10 as output
175         0x2DF5,         // map Hw Monitor Thermal Output to GP55
176         0x08F8,         // map GP LED Blinking 1 to GP10=LIVE_LED (deactivate Simple I/O to use)
177 };
178
179 /* Early mainboard specific GPIO setup. */
180 static void mb_gpio_init(void)
181 {
182         int i;
183
184         /* Init Super I/O WDT, GPIOs. Done early, WDT init may trigger reset! */
185         it8712f_enter_conf();
186         for (i = 0; i < ARRAY_SIZE(sio_init_table); i++) {
187                 u16 val = sio_init_table[i];
188                 outb((u8)val, SIO_INDEX);
189                 outb(val >> 8, SIO_DATA);
190         }
191         it8712f_exit_conf();
192 }
193
194 void cache_as_ram_main(void)
195 {
196         int err;
197         POST_CODE(0x01);
198
199         static const struct mem_controller memctrl[] = {
200                 {.channel0 = {(0xa << 3) | 0, (0xa << 3) | 1}}
201         };
202
203         SystemPreInit();
204         msr_init();
205
206         cs5536_early_setup();
207
208         /*
209          * Note: Must do this AFTER the early_setup! It is counting on some
210          * early MSR setup for CS5536.
211          */
212         it8712f_enable_serial(0, CONFIG_TTYS0_BASE); // Does not use its 1st parameter
213         mb_gpio_init();
214         uart_init();
215         console_init();
216
217         pll_reset(ManualConf);
218
219         cpuRegInit();
220
221         /* bit1 = on-board IDE is slave, bit0 = Spread Spectrum */
222         if ((err = smc_send_config(SMC_CONFIG))) {
223                 print_err("ERROR ");
224                 print_err_char('0'+err);
225                 print_err(" sending config data to SMC\n");
226         }
227
228         sdram_initialize(1, memctrl);
229
230         /* Check memory. */
231         /* ram_check(0, 640 * 1024); */
232
233         /* Memory is setup. Return to cache_as_ram.inc and continue to boot. */
234         return;
235 }
236