0312d4a27ccc5afca52ed4af784b1dfd54e971ed
[coreboot.git] / src / mainboard / pcengines / alix2d / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
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 version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <stdint.h>
21 #include <stdlib.h>
22 #include <spd.h>
23 #include <device/pci_def.h>
24 #include <arch/io.h>
25 #include <device/pnp_def.h>
26 #include <arch/romcc_io.h>
27 #include <arch/hlt.h>
28 #include <console/console.h>
29 #include <lib.h>
30 #include "cpu/x86/bist.h"
31 #include "cpu/x86/msr.h"
32 #include <cpu/amd/lxdef.h>
33 #include <cpu/amd/geode_post_code.h>
34 #include "southbridge/amd/cs5536/cs5536.h"
35 #include <spd.h>
36
37 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
38
39 /* The ALIX.2D has no SMBus; the setup is hard-wired. */
40 static void cs5536_enable_smbus(void)
41 {
42 }
43
44 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
45
46 /* The part is a Hynix hy5du121622ctp-d43.
47  *
48  * HY 5D U 12 16 2 2 C <blank> T <blank> P D43
49  * Hynix
50  * DDR SDRAM (5D)
51  * VDD 2.5 VDDQ 2.5 (U)
52  * 512M 8K REFRESH (12)
53  * x16 (16)
54  * 4banks (2)
55  * SSTL_2 (2)
56  * 4th GEN die (C)
57  * Normal Power Consumption (<blank> )
58  * TSOP (T)
59  * Single Die (<blank>)
60  * Lead Free (P)
61  * DDR400 3-3-3 (D43)
62  */
63 /* SPD array */
64 static const u8 spdbytes[] = {
65         [SPD_ACCEPTABLE_CAS_LATENCIES] = 0x10,
66         [SPD_BANK_DENSITY] = 0x40,
67         [SPD_DEVICE_ATTRIBUTES_GENERAL] = 0xff,
68         [SPD_MEMORY_TYPE] = 7,
69         [SPD_MIN_CYCLE_TIME_AT_CAS_MAX] = 10, /* A guess for the tRAC value */
70         [SPD_MODULE_ATTRIBUTES] = 0xff, /* FIXME later when we figure out. */
71         [SPD_NUM_BANKS_PER_SDRAM] = 4,
72         [SPD_PRIMARY_SDRAM_WIDTH] = 8,
73         [SPD_NUM_DIMM_BANKS] = 1, /* ALIX1.C is 1 bank. */
74         [SPD_NUM_COLUMNS] = 0xa,
75         [SPD_NUM_ROWS] = 3,
76         [SPD_REFRESH] = 0x3a,
77         [SPD_SDRAM_CYCLE_TIME_2ND] = 60,
78         [SPD_SDRAM_CYCLE_TIME_3RD] = 75,
79         [SPD_tRAS] = 40,
80         [SPD_tRCD] = 15,
81         [SPD_tRFC] = 70,
82         [SPD_tRP] = 15,
83         [SPD_tRRD] = 10,
84 };
85
86 static u8 spd_read_byte(u8 device, u8 address)
87 {
88         print_debug("spd_read_byte dev ");
89         print_debug_hex8(device);
90
91         if (device != DIMM0) {
92                 print_debug(" returns 0xff\n");
93                 return 0xff;
94         }
95
96         print_debug(" addr ");
97         print_debug_hex8(address);
98         print_debug(" returns ");
99         print_debug_hex8(spdbytes[address]);
100         print_debug("\n");
101
102         return spdbytes[address];
103 }
104
105 #define ManualConf      0               /* Do automatic strapped PLL config */
106 #define PLLMSRhi        0x00001490      /* Manual settings for the PLL */
107 #define PLLMSRlo        0x02000030
108
109 #include "northbridge/amd/lx/raminit.h"
110 #include "northbridge/amd/lx/pll_reset.c"
111 #include "northbridge/amd/lx/raminit.c"
112 #include "lib/generic_sdram.c"
113 #include "cpu/amd/model_lx/cpureginit.c"
114 #include "cpu/amd/model_lx/syspreinit.c"
115 #include "cpu/amd/model_lx/msrinit.c"
116
117 /** Early mainboard specific GPIO setup. */
118 static void mb_gpio_init(void)
119 {
120         /*
121          * Enable LEDs GPIO outputs to light up the leds
122          * This is how the original tinyBIOS sets them after boot.
123          * Info: GPIO_IO_BASE, 0x6100, is only valid before PCI init, so it
124          *       may be used here, but not after PCI Init.
125          * Note: Prior to a certain release, Linux used a hardwired 0x6100 in the
126          *       leds-alix2.c driver. Coreboot dynamically assigns this space,
127          *       so the driver does not work anymore.
128          *       Good workaround: use the newer driver
129          *       Ugly workaround: $ wrmsr 0x5140000C 0xf00100006100
130          *         This resets the GPIO I/O space to 0x6100.
131          *         This may break other things, though.
132      */
133         outl(1 << 6, GPIO_IO_BASE + GPIOL_OUTPUT_ENABLE);
134         outl(1 << 9, GPIO_IO_BASE + GPIOH_OUTPUT_ENABLE);
135         outl(1 << 11, GPIO_IO_BASE + GPIOH_OUTPUT_ENABLE);
136
137         /* outl(1 << 6, GPIO_IO_BASE + GPIOL_OUTPUT_VALUE); */  /* Led 1 enabled  */
138     outl(1 << 9, GPIO_IO_BASE + GPIOH_OUTPUT_VALUE);        /* Led 2 disabled */
139         outl(1 << 11, GPIO_IO_BASE + GPIOH_OUTPUT_VALUE);       /* Led 3 disabled */
140
141
142 }
143
144 void main(unsigned long bist)
145 {
146         static const struct mem_controller memctrl[] = {
147                 {.channel0 = {DIMM0}},
148         };
149
150         post_code(0x01);
151
152         SystemPreInit();
153         msr_init();
154
155         cs5536_early_setup();
156
157         /* NOTE: Must do this AFTER cs5536_early_setup()!
158          * It is counting on some early MSR setup for the CS5536.
159          */
160         cs5536_setup_onchipuart(1);
161         mb_gpio_init();
162         uart_init();
163         console_init();
164
165         /* Halt if there was a built in self test failure */
166         report_bist_failure(bist);
167
168         pll_reset(ManualConf);
169
170         cpuRegInit(0, DIMM0, DIMM1, DRAM_TERMINATED);
171
172         sdram_initialize(1, memctrl);
173
174         /* Check memory */
175         /* Enable this only if you are having questions. */
176         /* ram_check(0, 640 * 1024); */
177
178         /* Switch from Cache as RAM to real RAM.
179          *
180          * There are two ways we could think about this.
181          *
182          * 1. If we are using the romstage.inc ROMCC way, the stack is
183          * going to be re-setup in the code following this code.  Just
184          * wbinvd the stack to clear the cache tags.  We don't care
185          * where the stack used to be.
186          *
187          * 2. This file is built as a normal .c -> .o and linked in
188          * etc.  The stack might be used to return etc.  That means we
189          * care about what is in the stack.  If we are smart we set
190          * the CAR stack to the same location as the rest of
191          * coreboot. If that is the case we can just do a wbinvd.
192          * The stack will be written into real RAM that is now setup
193          * and we continue like nothing happened.  If the stack is
194          * located somewhere other than where LB would like it, you
195          * need to write some code to do a copy from cache to RAM
196          *
197          * We use method 1 on Norwich and on this board too.
198          */
199         post_code(0x02);
200         print_err("POST 02\n");
201         __asm__("wbinvd\n");
202         print_err("Past wbinvd\n");
203
204         /* We are finding the return does not work on this board. Explicitly
205          * call the label that is after the call to us. This is gross, but
206          * sometimes at this level it is the only way out.
207          */
208         void done_cache_as_ram_main(void);
209         done_cache_as_ram_main();
210 }
211