bc6cae005323fb2a82e2adcefea4c6ecdd8ad729
[coreboot.git] / src / mainboard / lippert / hurricane-lx / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  * Copyright (C) 2010 LiPPERT Embedded Computers GmbH
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 /* Based on romstage.c from the SpaceRunner-LX mainboard. */
23
24 #include <stdlib.h>
25 #include <stdint.h>
26 #include <device/pci_def.h>
27 #include <arch/io.h>
28 #include <device/pnp_def.h>
29 #include <arch/hlt.h>
30 #include <console/console.h>
31 #include "cpu/x86/bist.h"
32 #include "cpu/x86/msr.h"
33 #include <cpu/amd/lxdef.h>
34 #include <cpu/amd/geode_post_code.h>
35 #include "southbridge/amd/cs5536/cs5536.h"
36 #include <spd.h>
37
38 #include "southbridge/amd/cs5536/cs5536_early_smbus.c"
39 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
40 #include "superio/ite/it8712f/it8712f_early_serial.c"
41
42 /* Bit0 enables Spread Spectrum. */
43 #define SMC_CONFIG      0x01
44
45 #define ManualConf 1            /* No automatic strapped PLL config */
46 #define PLLMSRhi 0x0000049C     /* Manual settings for the PLL */
47 #define PLLMSRlo 0x00DE6001
48
49 static inline int spd_read_byte(unsigned int device, unsigned int address)
50 {
51         if (device != DIMM0)
52                 return 0xFF;    /* No DIMM1, don't even try. */
53
54         return smbus_read_byte(device, address);
55 }
56
57 #if !CONFIG_BOARD_OLD_REVISION
58 /* Send config data to System Management Controller via SMB. */
59 static int smc_send_config(unsigned char config_data)
60 {
61         if (smbus_check_stop_condition(SMBUS_IO_BASE))
62                 return 1;
63         if (smbus_start_condition(SMBUS_IO_BASE))
64                 return 2;
65         if (smbus_send_slave_address(SMBUS_IO_BASE, 0x50)) // SMC address
66                 return 3;
67         if (smbus_send_command(SMBUS_IO_BASE, 0x28)) // set config data
68                 return 4;
69         if (smbus_send_command(SMBUS_IO_BASE, 0x01)) // data length
70                 return 5;
71         if (smbus_send_command(SMBUS_IO_BASE, config_data))
72                 return 6;
73         smbus_stop_condition(SMBUS_IO_BASE);
74         return 0;
75 }
76 #endif
77
78 #include "northbridge/amd/lx/raminit.h"
79 #include "northbridge/amd/lx/pll_reset.c"
80 #include "northbridge/amd/lx/raminit.c"
81 #include "lib/generic_sdram.c"
82 #include "cpu/amd/model_lx/cpureginit.c"
83 #include "cpu/amd/model_lx/syspreinit.c"
84 #include "cpu/amd/model_lx/msrinit.c"
85
86 static const u16 sio_init_table[] = { // hi=data, lo=index
87         0x0707,         // select LDN 7 (GPIO, SPI, watchdog, ...)
88         0x042C,         // disable ATXPG; VIN6 enabled, FAN4/5 disabled, VIN7,VIN3 enabled
89         0x1423,         // don't delay PoWeROK1/2
90         0x9072,         // watchdog triggers PWROK, counts seconds
91 #if !CONFIG_USE_WATCHDOG_ON_BOOT
92         0x0073, 0x0074, // disarm watchdog by changing 56 s timeout to 0
93 #endif
94         0xBF25, 0x172A, 0xF326, // select GPIO function for most pins
95         0xBF27, 0xFF28, 0x2D29, // (GP36=FAN_CTL3 (PWM), GP23,22,16,15=SPI, GP13=PWROK1)
96         0x66B8, 0x0CB9, // enable pullups on SPI, RS485_EN
97         0x07C0,         // enable Simple-I/O for GP12-10= RS485_EN2,1, WD_ACTIVE
98         0x06C8,         // config GP12,11 as output, GP10 as input
99         0x2DF5,         // map Hw Monitor Thermal Output to GP55
100 #if CONFIG_BOARD_OLD_REVISION
101         0x1F2A, 0xC072, // switch GP13 to GPIO, WDT output from PWROK to KRST
102 #endif
103 };
104
105 /* Early mainboard specific GPIO setup. */
106 static void mb_gpio_init(void)
107 {
108         int i;
109
110         /* Init Super I/O WDT, GPIOs. Done early, WDT init may trigger reset! */
111         it8712f_enter_conf();
112         for (i = 0; i < ARRAY_SIZE(sio_init_table); i++) {
113                 u16 val = sio_init_table[i];
114                 outb((u8)val, SIO_INDEX);
115                 outb(val >> 8, SIO_DATA);
116         }
117         it8712f_exit_conf();
118 }
119
120 void main(unsigned long bist)
121 {
122         post_code(0x01);
123
124         static const struct mem_controller memctrl[] = {
125                 {.channel0 = {(0xa << 3) | 0, (0xa << 3) | 1}}
126         };
127
128         SystemPreInit();
129         msr_init();
130
131         cs5536_early_setup();
132
133         /*
134          * Note: Must do this AFTER the early_setup! It is counting on some
135          * early MSR setup for CS5536.
136          */
137         it8712f_enable_serial(0, CONFIG_TTYS0_BASE); // Does not use its 1st parameter
138         mb_gpio_init();
139         uart_init();
140         console_init();
141
142         /* Halt if there was a built in self test failure */
143         report_bist_failure(bist);
144
145         pll_reset(ManualConf);
146
147         cpuRegInit(0, DIMM0, DIMM1, DRAM_TERMINATED);
148
149 #if !CONFIG_BOARD_OLD_REVISION
150         int err;
151         /* bit0 = Spread Spectrum */
152         if ((err = smc_send_config(SMC_CONFIG))) {
153                 print_err("ERROR ");
154                 print_err_char('0'+err);
155                 print_err(" sending config data to SMC\n");
156         }
157 #endif
158
159         sdram_initialize(1, memctrl);
160
161         /* Check memory. */
162         /* ram_check(0, 640 * 1024); */
163
164         /* Memory is setup. Return to cache_as_ram.inc and continue to boot. */
165         return;
166 }