Remove pc80/serial.c includes in ROMCC boards and include
[coreboot.git] / src / mainboard / amd / rumba / romstage.c
1 #include <stdint.h>
2 #include <device/pci_def.h>
3 #include <arch/io.h>
4 #include <device/pnp_def.h>
5 #include <arch/romcc_io.h>
6 #include <arch/hlt.h>
7 #include <console/console.h>
8 #include "lib/ramtest.c"
9 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
10 #include "cpu/x86/bist.h"
11 #include "cpu/x86/msr.h"
12 #include <cpu/amd/gx2def.h>
13
14 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
15
16 #include "southbridge/amd/cs5536/cs5536_early_smbus.c"
17 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
18
19 static inline int spd_read_byte(unsigned device, unsigned address)
20 {
21         return smbus_read_byte(device, address);
22 }
23
24 #include "northbridge/amd/gx2/raminit.h"
25
26 static inline unsigned int fls(unsigned int x)
27 {
28         int r;
29
30         __asm__("bsfl %1,%0\n\t"
31                 "jnz 1f\n\t"
32                 "movl $32,%0\n"
33                 "1:" : "=r" (r) : "g" (x));
34         return r;
35 }
36
37 static void sdram_set_spd_registers(const struct mem_controller *ctrl)
38 {
39         /* Total size of DIMM = 2^row address (byte 3) * 2^col address (byte 4) *
40          *                      component Banks (byte 17) * module banks, side (byte 5) *
41          *                      width in bits (byte 6,7)
42          *                    = Density per side (byte 31) * number of sides (byte 5) */
43         /* 1. Initialize GLMC registers base on SPD values, do one DIMM for now */
44         msr_t msr;
45         unsigned char module_banks, val;
46
47         msr = rdmsr(MC_CF07_DATA);
48
49         /* get module banks (sides) per dimm, SPD byte 5 */
50         module_banks = spd_read_byte(0xA0, 5);
51         if (module_banks < 1 || module_banks > 2)
52                 print_err("Module banks per dimm\n");
53         module_banks >>= 1;
54         msr.hi &= ~(1 << CF07_UPPER_D0_MB_SHIFT);
55         msr.hi |= (module_banks << CF07_UPPER_D0_MB_SHIFT);
56
57         /* get component banks per module bank, SPD byte 17 */
58         val = spd_read_byte(0xA0, 17);
59         if (val < 2 || val > 4)
60                 print_err("Component banks per module bank\n");
61         val >>= 2;
62         msr.hi &= ~(0x1 << CF07_UPPER_D0_CB_SHIFT);
63         msr.hi |=  (val << CF07_UPPER_D0_CB_SHIFT);
64
65         /* get the module bank density, SPD byte 31  */
66         val = spd_read_byte(0xA0, 31);
67         val = fls(val);
68         val <<= module_banks;
69         msr.hi &= ~(0xf << CF07_UPPER_D0_SZ_SHIFT);
70         msr.hi |=  (val << CF07_UPPER_D0_SZ_SHIFT);
71
72         /* page size = 2^col address */
73         val = spd_read_byte(0xA0, 4);
74         val -= 7;
75         msr.hi &= ~(0x7 << CF07_UPPER_D0_PSZ_SHIFT);
76         msr.hi |=  (val << CF07_UPPER_D0_PSZ_SHIFT);
77
78         print_debug("computed msr.hi ");
79         print_debug_hex32(msr.hi);
80         print_debug("\n");
81
82         msr.lo = 0x00003000;
83         wrmsr(MC_CF07_DATA, msr);
84
85         msr = rdmsr(0x20000019);
86         msr.hi = 0x18000108;
87         msr.lo = 0x696332a3;
88         wrmsr(0x20000019, msr);
89
90 }
91
92 #include "northbridge/amd/gx2/raminit.c"
93 #include "lib/generic_sdram.c"
94
95 #define PLLMSRhi 0x00001490
96 #define PLLMSRlo 0x02000030
97 #define PLLMSRlo1 ((0xde << 16) | (1 << 26) | (1 << 24))
98 #define PLLMSRlo2 ((1<<14) |(1<<13) | (1<<0))
99 #include "northbridge/amd/gx2/pll_reset.c"
100 #include "cpu/amd/model_gx2/cpureginit.c"
101 #include "cpu/amd/model_gx2/syspreinit.c"
102 static void msr_init(void)
103 {
104         /* total physical memory */
105         __builtin_wrmsr(0x1808,  0x10f3bf00, 0x22fffc02);
106
107         /* traditional memory 0kB-512kB, 512kB-1MB */
108         __builtin_wrmsr(0x10000020, 0xfff80, 0x20000000);
109         __builtin_wrmsr(0x10000021, 0x80fffe0, 0x20000000);
110
111         __builtin_wrmsr(0x40000020, 0xfff80, 0x20000000);
112         __builtin_wrmsr(0x40000021, 0x80fffe0, 0x20000000);
113
114         /* put code in northbridge[init].c here */
115 }
116
117 static void main(unsigned long bist)
118 {
119         static const struct mem_controller memctrl [] = {
120                 {.channel0 = {(0xa<<3)|0, (0xa<<3)|1}}
121         };
122
123         SystemPreInit();
124
125
126         w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
127         uart_init();
128         console_init();
129
130         cs5536_early_setup();
131
132         pll_reset();
133
134         cpuRegInit();
135         print_err("done cpuRegInit\n");
136
137         sdram_initialize(1, memctrl);
138
139         msr_init();
140
141         /* Check all of memory */
142         //ram_check(0x00000000, 640*1024);
143 }
144