Enable or disable the power button in Kconfig
[coreboot.git] / src / mainboard / wyse / s50 / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2010 Nils Jacobs
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of
9  * the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21
22 #include <stdint.h>
23 #include <device/pci_def.h>
24 #include <arch/io.h>
25 #include <device/pnp_def.h>
26 #include <arch/hlt.h>
27 #include <console/console.h>
28 #include <lib.h>
29 #include "cpu/x86/bist.h"
30 #include "cpu/x86/msr.h"
31 #include <cpu/amd/gx2def.h>
32 #include <cpu/amd/geode_post_code.h>
33
34 #include "southbridge/amd/cs5536/cs5536_early_smbus.c"
35 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
36
37 static inline int spd_read_byte(unsigned device, unsigned address)
38 {
39         return smbus_read_byte(device, address);
40 }
41
42 #include "northbridge/amd/gx2/raminit.h"
43
44         /* This is needed because ROMCC doesn`t now the ctz bitop */
45 static inline unsigned int ctz(unsigned int n)
46 {
47         int zeros;
48
49         n = (n ^ (n - 1)) >> 1;
50         for (zeros = 0; n; zeros++)
51         {
52           n >>= 1;
53         }
54         return zeros;
55 }
56
57 static void sdram_set_spd_registers(const struct mem_controller *ctrl) 
58 {
59         /* Total size of DIMM = 2^row address (byte 3) * 2^col address (byte 4) *
60          *                      component Banks (byte 17) * module banks, side (byte 5) *
61          *                      width in bits (byte 6,7)
62          *                    = Density per side (byte 31) * number of sides (byte 5) */
63         /* 1. Initialize GLMC registers base on SPD values, do one DIMM for now */
64         msr_t msr;
65         unsigned char module_banks, val;
66         uint16_t dimm_size;
67
68         msr = rdmsr(MC_CF07_DATA);
69
70         /* get module banks (sides) per dimm, SPD byte 5 */
71         module_banks = spd_read_byte(0xA0, 5);
72         if (module_banks < 1 || module_banks > 2)
73                 print_err("Module banks per dimm\n");
74         module_banks >>= 1;
75         msr.hi &= ~(1 << CF07_UPPER_D0_MB_SHIFT);
76         msr.hi |= (module_banks << CF07_UPPER_D0_MB_SHIFT);
77
78         /* get component banks per module bank, SPD byte 17 */
79         val = spd_read_byte(0xA0, 17);
80         if (val < 2 || val > 4)
81                 print_err("Component banks per module bank\n");
82         val >>= 2;
83         msr.hi &= ~(0x1 << CF07_UPPER_D0_CB_SHIFT);
84         msr.hi |=  (val << CF07_UPPER_D0_CB_SHIFT);
85
86         dimm_size = spd_read_byte(0xA0, 31);
87         dimm_size |= (dimm_size << 8);  /* align so 1GB(bit0) is bit 8, this is a little weird to get gcc to not optimize this out */
88         dimm_size &= 0x01FC;    /* and off 2GB DIMM size : not supported and the 1GB size we just moved up to bit 8 as well as all the extra on top */
89         /*       Module Density * Module Banks */
90         dimm_size <<= (0 >> CF07_UPPER_D0_MB_SHIFT) & 1;        /* shift to multiply by # DIMM banks */
91         if (dimm_size != 0) {
92         dimm_size = ctz(dimm_size);
93         }
94         if (dimm_size > 7) {    /* 7 is 512MB only support 512MB per DIMM */
95                 print_err("Only support up to 512MB \n");
96                 hlt();
97         }
98         msr.hi |= dimm_size << CF07_UPPER_D0_SZ_SHIFT;
99
100         /* page size = 2^col address */
101         val = spd_read_byte(0xA0, 4);
102         val -= 7;
103         msr.hi &= ~(0x7 << CF07_UPPER_D0_PSZ_SHIFT);
104         msr.hi |=  (val << CF07_UPPER_D0_PSZ_SHIFT);
105
106         print_debug("computed msr.hi ");
107         print_debug_hex32(msr.hi);
108         print_debug("\n");
109
110         msr.lo = 0x00003400;
111         wrmsr(MC_CF07_DATA, msr);
112
113         msr = rdmsr(MC_CF8F_DATA);
114         msr.hi = 0x18000008;
115         msr.lo = 0x296332a3;
116         wrmsr(MC_CF8F_DATA, msr);               
117
118 }
119
120 #include "northbridge/amd/gx2/raminit.c"
121 #include "lib/generic_sdram.c"
122 #include "northbridge/amd/gx2/pll_reset.c"
123 #include "cpu/amd/model_gx2/cpureginit.c"
124 #include "cpu/amd/model_gx2/syspreinit.c"
125 #include "cpu/amd/model_lx/msrinit.c"
126
127 void main(unsigned long bist)
128 {
129         static const struct mem_controller memctrl [] = {
130                 {.channel0 = {(0xa<<3)|0, (0xa<<3)|1}}
131         };
132
133         SystemPreInit();
134
135         cs5536_early_setup();
136         
137         /* cs5536_disable_internal_uart  disable them. Set them up now... */
138         cs5536_setup_onchipuart(1);
139
140         uart_init();
141         console_init();
142
143         /* Halt if there was a built in self test failure */
144         report_bist_failure(bist);
145
146         pll_reset();
147
148         cpuRegInit();
149         print_err("done cpuRegInit\n");
150
151         sdram_initialize(1, memctrl);
152         print_err("ram setup done\n");
153
154         msr_init();
155
156         /* Check all of memory */
157         /*ram_check(0x00000000, 640*1024);*/
158         print_err("ram check done\n");
159 }
160