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