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