blob: e8cfee55bb8bf10dc43604d57fd674f03d1e2aff [file] [log] [blame]
Jens Rottmannf31ca162008-11-19 12:19:09 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008 LiPPERT Embedded Computers GmbH
5 * Copyright (C) 2007 Advanced Micro Devices, Inc.
6 *
Jens Rottmannf31ca162008-11-19 12:19:09 +00007 * 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
Stefan Reinauer38f147e2010-02-08 12:20:50 +000022/* Based on romstage.c from AMD's DB800 and DBM690T mainboards. */
Uwe Hermann86c9b882008-11-19 13:42:14 +000023
Jens Rottmannf31ca162008-11-19 12:19:09 +000024#define ASSEMBLY 1
Stefan Reinauer9fe4d792010-01-16 17:53:38 +000025#define __PRE_RAM__
Jens Rottmannf31ca162008-11-19 12:19:09 +000026
27#include <stdlib.h>
28#include <stdint.h>
29#include <device/pci_def.h>
30#include <arch/io.h>
31#include <device/pnp_def.h>
32#include <arch/hlt.h>
33#include "pc80/serial.c"
34#include "arch/i386/lib/console.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000035#include "lib/ramtest.c"
Jens Rottmannf31ca162008-11-19 12:19:09 +000036#include "cpu/x86/bist.h"
37#include "cpu/x86/msr.h"
38#include <cpu/amd/lxdef.h>
39#include <cpu/amd/geode_post_code.h>
40#include "southbridge/amd/cs5536/cs5536.h"
41
42#define POST_CODE(x) outb(x, 0x80)
43
44#include "southbridge/amd/cs5536/cs5536_early_smbus.c"
45#include "southbridge/amd/cs5536/cs5536_early_setup.c"
46#include "superio/ite/it8712f/it8712f_early_serial.c"
47
48#define ManualConf 1 /* No automatic strapped PLL config */
49#define PLLMSRhi 0x0000049C /* Manual settings for the PLL */
50#define PLLMSRlo 0x00DE6001
51#define DIMM0 0xA0
52#define DIMM1 0xA2
53
54static inline int spd_read_byte(unsigned int device, unsigned int address)
55{
Uwe Hermann86c9b882008-11-19 13:42:14 +000056 if (device != DIMM0)
57 return 0xFF; /* No DIMM1, don't even try. */
58
Jens Rottmannf31ca162008-11-19 12:19:09 +000059 return smbus_read_byte(device, address);
60}
61
62#include "northbridge/amd/lx/raminit.h"
63#include "northbridge/amd/lx/pll_reset.c"
64#include "northbridge/amd/lx/raminit.c"
Stefan Reinauerc13093b2009-09-23 18:51:03 +000065#include "lib/generic_sdram.c"
Jens Rottmannf31ca162008-11-19 12:19:09 +000066#include "cpu/amd/model_lx/cpureginit.c"
67#include "cpu/amd/model_lx/syspreinit.c"
68
69static void msr_init(void)
70{
71 msr_t msr;
72
73 /* Setup access to the cache for under 1MB. */
74 msr.hi = 0x24fffc02;
75 msr.lo = 0x1000A000; /* 0-A0000 write back */
76 wrmsr(CPU_RCONF_DEFAULT, msr);
77
78 msr.hi = 0x0; /* Write back */
79 msr.lo = 0x0;
80 wrmsr(CPU_RCONF_A0_BF, msr);
81 wrmsr(CPU_RCONF_C0_DF, msr);
82 wrmsr(CPU_RCONF_E0_FF, msr);
83
84 /* Setup access to the cache for under 640K. Note MC not setup yet. */
85 msr.hi = 0x20000000;
86 msr.lo = 0xfff80;
87 wrmsr(MSR_GLIU0 + 0x20, msr);
88
89 msr.hi = 0x20000000;
90 msr.lo = 0x80fffe0;
91 wrmsr(MSR_GLIU0 + 0x21, msr);
92
93 msr.hi = 0x20000000;
94 msr.lo = 0xfff80;
95 wrmsr(MSR_GLIU1 + 0x20, msr);
96
97 msr.hi = 0x20000000;
98 msr.lo = 0x80fffe0;
99 wrmsr(MSR_GLIU1 + 0x21, msr);
100}
101
102static const u16 sio_init_table[] = { // hi=data, lo=index
103 0x0707, // select LDN 7 (GPIO, SPI, watchdog, ...)
104 0x1E2C, // disable ATXPowerGood - will cause a reboot!
105 0x0423, // don't delay POWerOK1/2
106 0x9072, // watchdog triggers POWOK, counts seconds
Stefan Reinauer08670622009-06-30 15:17:49 +0000107#if !CONFIG_USE_WATCHDOG_ON_BOOT
Jens Rottmannf31ca162008-11-19 12:19:09 +0000108 0x0073, 0x0074, // disable watchdog by setting timeout to 0
109#endif
110 0xBF25, 0x372A, 0xF326, // select GPIO function for most pins
111 0xBF27, 0xFF28, 0x2529, // (GP36=FAN_CTL3, GP13=PWROK1)
112 0x1E2C, // VIN6=enabled?, FAN4/5 enabled, VIN7=internal, VIN3=enabled
113 0x46B8, 0x0CB9, // enable pullups
114 0x36C0, // enable Simple-I/O for GP15,14,12,11= LIVE_LED, WD_ACTIVE, RS485_EN2,1
115 0xFFC3, // enable Simple-I/O for GP47-40 (GPIOs on Supervisory Connector)
116 0x26C8, // config GP15,12,11 as output; GP14 as input
117 0x2DF5, // map Hw Monitor Thermal Output to GP55
118 0x0DF8, // map GP LED Blinking 1 to GP15=LIVE_LED (deactivate Simple-I/O to use)
119};
120
121/* Early mainboard specific GPIO setup. */
122static void mb_gpio_init(void)
123{
124 int i;
125
Uwe Hermann86c9b882008-11-19 13:42:14 +0000126 /* Init Super I/O WDT, GPIOs. Done early, WDT init may trigger reset! */
Jens Rottmannf31ca162008-11-19 12:19:09 +0000127 it8712f_enter_conf();
Uwe Hermann86c9b882008-11-19 13:42:14 +0000128 for (i = 0; i < ARRAY_SIZE(sio_init_table); i++) {
Jens Rottmannf31ca162008-11-19 12:19:09 +0000129 u16 val = sio_init_table[i];
Uwe Hermann86c9b882008-11-19 13:42:14 +0000130 outb((u8)val, SIO_INDEX);
131 outb(val >> 8, SIO_DATA);
Jens Rottmannf31ca162008-11-19 12:19:09 +0000132 }
133 it8712f_exit_conf();
134}
135
136void cache_as_ram_main(void)
137{
138 POST_CODE(0x01);
139
140 static const struct mem_controller memctrl[] = {
141 {.channel0 = {(0xa << 3) | 0, (0xa << 3) | 1}}
142 };
143
144 SystemPreInit();
145 msr_init();
146
147 cs5536_early_setup();
148
Uwe Hermann86c9b882008-11-19 13:42:14 +0000149 /*
150 * Note: must do this AFTER the early_setup! It is counting on some
Jens Rottmannf31ca162008-11-19 12:19:09 +0000151 * early MSR setup for CS5536.
152 */
Stefan Reinauer08670622009-06-30 15:17:49 +0000153 it8712f_enable_serial(0, CONFIG_TTYS0_BASE); // Does not use its 1st parameter
Jens Rottmannf31ca162008-11-19 12:19:09 +0000154 mb_gpio_init();
155 uart_init();
156 console_init();
157
158 pll_reset(ManualConf);
159
160 cpuRegInit();
161
162 sdram_initialize(1, memctrl);
163
164 /* Check memory. */
165 /* ram_check(0x00000000, 640 * 1024); */
166
167 /* Memory is setup. Return to cache_as_ram.inc and continue to boot. */
168 return;
169}