ee101b944f4200b51d483332c465538f0ec4de9f
[coreboot.git] / src / mainboard / pcengines / alix1c / 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 <spd.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 <console/console.h>
28 #include "lib/ramtest.c"
29 #include "cpu/x86/bist.h"
30 #include "cpu/x86/msr.h"
31 #include <cpu/amd/lxdef.h>
32 #include <cpu/amd/geode_post_code.h>
33 #include "southbridge/amd/cs5536/cs5536.h"
34
35 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
36
37 /* The ALIX1.C has no SMBus; the setup is hard-wired. */
38 static void cs5536_enable_smbus(void)
39 {
40 }
41
42 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
43 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
44
45 /* The part is a Hynix hy5du121622ctp-d43.
46  *
47  * HY 5D U 12 16 2 2 C <blank> T <blank> P D43
48  * Hynix
49  * DDR SDRAM (5D)
50  * VDD 2.5 VDDQ 2.5 (U)
51  * 512M 8K REFRESH (12)
52  * x16 (16)
53  * 4banks (2)
54  * SSTL_2 (2)
55  * 4th GEN die (C)
56  * Normal Power Consumption (<blank> )
57  * TSOP (T)
58  * Single Die (<blank>)
59  * Lead Free (P)
60  * DDR400 3-3-3 (D43)
61  */
62 /* SPD array */
63 static const u8 spdbytes[] = {
64         [SPD_ACCEPTABLE_CAS_LATENCIES] = 0x10,
65         [SPD_BANK_DENSITY] = 0x40,
66         [SPD_DEVICE_ATTRIBUTES_GENERAL] = 0xff,
67         [SPD_MEMORY_TYPE] = 7,
68         [SPD_MIN_CYCLE_TIME_AT_CAS_MAX] = 10, /* A guess for the tRAC value */
69         [SPD_MODULE_ATTRIBUTES] = 0xff, /* FIXME later when we figure out. */
70         [SPD_NUM_BANKS_PER_SDRAM] = 4,
71         [SPD_PRIMARY_SDRAM_WIDTH] = 8,
72         [SPD_NUM_DIMM_BANKS] = 1, /* ALIX1.C is 1 bank. */
73         [SPD_NUM_COLUMNS] = 0xa,
74         [SPD_NUM_ROWS] = 3,
75         [SPD_REFRESH] = 0x3a,
76         [SPD_SDRAM_CYCLE_TIME_2ND] = 60,
77         [SPD_SDRAM_CYCLE_TIME_3RD] = 75,
78         [SPD_tRAS] = 40,
79         [SPD_tRCD] = 15,
80         [SPD_tRFC] = 70,
81         [SPD_tRP] = 15,
82         [SPD_tRRD] = 10,
83 };
84
85 static u8 spd_read_byte(u8 device, u8 address)
86 {
87         print_debug("spd_read_byte dev ");
88         print_debug_hex8(device);
89
90         if (device != (0x50 << 1)) {
91                 print_debug(" returns 0xff\n");
92                 return 0xff;
93         }
94
95         print_debug(" addr ");
96         print_debug_hex8(address);
97         print_debug(" returns ");
98         print_debug_hex8(spdbytes[address]);
99         print_debug("\n");
100
101         return spdbytes[address];
102 }
103
104 #define ManualConf      0               /* Do automatic strapped PLL config */
105 #define PLLMSRhi        0x00001490      /* Manual settings for the PLL */
106 #define PLLMSRlo        0x02000030
107
108 #define DIMM0           0xa0
109 #define DIMM1           0xa2
110
111 #include "northbridge/amd/lx/raminit.h"
112 #include "northbridge/amd/lx/pll_reset.c"
113 #include "northbridge/amd/lx/raminit.c"
114 #include "lib/generic_sdram.c"
115 #include "cpu/amd/model_lx/cpureginit.c"
116 #include "cpu/amd/model_lx/syspreinit.c"
117 #include "cpu/amd/model_lx/msrinit.c"
118
119 /** Early mainboard specific GPIO setup. */
120 static void mb_gpio_init(void)
121 {
122 }
123
124 void main(unsigned long bist)
125 {
126         static const struct mem_controller memctrl[] = {
127                 {.channel0 = {0x50}},
128         };
129
130         post_code(0x01);
131
132         SystemPreInit();
133         msr_init();
134
135         cs5536_early_setup();
136
137         /* NOTE: Must do this AFTER cs5536_early_setup()!
138          * It is counting on some early MSR setup for the CS5536.
139          */
140         cs5536_disable_internal_uart();
141         w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
142         mb_gpio_init();
143         uart_init();
144         console_init();
145
146         /* Halt if there was a built in self test failure */
147         report_bist_failure(bist);
148
149         pll_reset(ManualConf);
150
151         cpuRegInit();
152
153         sdram_initialize(1, memctrl);
154
155         /* Check memory */
156         /* Enable this only if you are having questions. */
157         /* ram_check(0, 640 * 1024); */
158
159         /* Switch from Cache as RAM to real RAM.
160          *
161          * There are two ways we could think about this.
162          *
163          * 1. If we are using the romstage.inc ROMCC way, the stack is
164          * going to be re-setup in the code following this code.  Just
165          * wbinvd the stack to clear the cache tags.  We don't care
166          * where the stack used to be.
167          *
168          * 2. This file is built as a normal .c -> .o and linked in
169          * etc.  The stack might be used to return etc.  That means we
170          * care about what is in the stack.  If we are smart we set
171          * the CAR stack to the same location as the rest of
172          * coreboot. If that is the case we can just do a wbinvd.
173          * The stack will be written into real RAM that is now setup
174          * and we continue like nothing happened.  If the stack is
175          * located somewhere other than where LB would like it, you
176          * need to write some code to do a copy from cache to RAM
177          *
178          * We use method 1 on Norwich and on this board too.
179          */
180         post_code(0x02);
181         print_err("POST 02\n");
182         __asm__("wbinvd\n");
183         print_err("Past wbinvd\n");
184
185         /* We are finding the return does not work on this board. Explicitly
186          * call the label that is after the call to us. This is gross, but
187          * sometimes at this level it is the only way out.
188          */
189         void done_cache_as_ram_main(void);
190         done_cache_as_ram_main();
191 }
192