blob: ce0a6ac2687a92cfe39cc5c4ae6000e4516ce4e5 [file] [log] [blame]
Rudolf Marek133647a2010-04-05 19:47:34 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
5 * Copyright (C) 2010 Rudolf Marek <r.marek@assembler.cz>
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; version 2 of 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
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Rudolf Marek133647a2010-04-05 19:47:34 +000019 */
20
Rudolf Marek133647a2010-04-05 19:47:34 +000021#define RC0 (6<<8)
22#define RC1 (7<<8)
23
Rudolf Marek133647a2010-04-05 19:47:34 +000024#define SMBUS_HUB 0x71
25
26#include <stdint.h>
27#include <string.h>
28#include <device/pci_def.h>
29#include <arch/io.h>
30#include <device/pnp_def.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000031#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000032#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000033#include <console/console.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000034#include <cpu/amd/model_fxx_rev.h>
35#include "northbridge/amd/amdk8/raminit.h"
Rudolf Marek133647a2010-04-05 19:47:34 +000036#include "lib/delay.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000037#include <spd.h>
Kyösti Mälkkic66f1cb2013-08-12 16:09:00 +030038#include "cpu/x86/lapic.h"
Rudolf Marek133647a2010-04-05 19:47:34 +000039#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghanffe460d2014-04-27 22:51:40 +100040#include <superio/winbond/common/winbond.h>
41#include <superio/winbond/w83627dhg/w83627dhg.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000042#include "cpu/x86/bist.h"
Rudolf Marek133647a2010-04-05 19:47:34 +000043#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000044#include "southbridge/amd/rs780/early_setup.c"
efdesign9800c8c4a2011-07-20 12:37:58 -060045#include "southbridge/amd/sb700/sb700.h"
46#include "southbridge/amd/sb700/smbus.h"
stepan836ae292010-12-08 05:42:47 +000047#include "northbridge/amd/amdk8/debug.c" /* After sb700/early_setup.c! */
Rudolf Marek133647a2010-04-05 19:47:34 +000048
49#define SERIAL_DEV PNP_DEV(0x2e, W83627DHG_SP1)
Uwe Hermann3a4ed152010-12-05 22:36:14 +000050#define GPIO2345_DEV PNP_DEV(0x2e, W83627DHG_GPIO2345_V)
Rudolf Marek133647a2010-04-05 19:47:34 +000051
Uwe Hermann7b997052010-11-21 22:47:22 +000052static void memreset(int controllers, const struct mem_controller *ctrl) { }
53static void activate_spd_rom(const struct mem_controller *ctrl) { }
Rudolf Marek133647a2010-04-05 19:47:34 +000054
Rudolf Marek133647a2010-04-05 19:47:34 +000055static inline int spd_read_byte(u32 device, u32 address)
56{
efdesign9800c8c4a2011-07-20 12:37:58 -060057 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
Rudolf Marek133647a2010-04-05 19:47:34 +000058}
59
60#include "northbridge/amd/amdk8/amdk8.h"
61#include "northbridge/amd/amdk8/incoherent_ht.c"
62#include "northbridge/amd/amdk8/raminit.c"
63#include "northbridge/amd/amdk8/coherent_ht.c"
64#include "lib/generic_sdram.c"
65#include "resourcemap.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000066#include "cpu/amd/dualcore/dualcore.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000067#include "cpu/amd/model_fxx/init_cpus.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000068#include "cpu/amd/model_fxx/fidvid.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000069#include "northbridge/amd/amdk8/early_ht.c"
70
Stefan Reinauer56a684a2010-04-07 15:40:26 +000071static void sio_init(void)
Rudolf Marek133647a2010-04-05 19:47:34 +000072{
73 u8 reg;
74
75 pnp_enter_ext_func_mode(GPIO2345_DEV);
76 pnp_set_logical_device(GPIO2345_DEV);
77
Rudolf Marekaa55f372011-01-16 16:23:51 +000078 /* Pin 119 ~ 120 is GP21, GP20 */
Rudolf Marek133647a2010-04-05 19:47:34 +000079 reg = pnp_read_config(GPIO2345_DEV, 0x29);
80 pnp_write_config(GPIO2345_DEV, 0x29, (reg | 2));
81
Rudolf Marek9c9ae3a2010-11-30 21:21:33 +000082 /* Turn on the Power LED ("Suspend LED" in Super I/O) */
83 reg = pnp_read_config(GPIO2345_DEV, 0xf3);
84 pnp_write_config(GPIO2345_DEV, 0xf3, (reg | 0x40));
85
Rudolf Marek133647a2010-04-05 19:47:34 +000086 /* todo document this */
87 pnp_write_config(GPIO2345_DEV, 0x2c, 0x1);
88 pnp_write_config(GPIO2345_DEV, 0x2d, 0x1);
89
Rudolf Marekaa55f372011-01-16 16:23:51 +000090 /* GPO20 - sideport voltage 1 = 1.82 0 = 1.92
91 GPI21 - unknown input (NC?)
92 GPI22 - unknown input (NC?)
93 GPO23 - mgpuV bit0
Rudolf Mareka1125232011-01-16 17:15:36 +000094 GP24-27 - PS/2 mouse/keyb (only keyb is connected use flip interface for mouse)
Rudolf Marekaa55f372011-01-16 16:23:51 +000095 */
Rudolf Marek133647a2010-04-05 19:47:34 +000096 pnp_write_config(GPIO2345_DEV, 0x30, 0x07); /* Enable GPIO 2,3,4. */
97 pnp_write_config(GPIO2345_DEV, 0xe3, 0xf6); /* dir of GPIO2 11110110*/
98 pnp_write_config(GPIO2345_DEV, 0xe4, 0x0e); /* data */
99 pnp_write_config(GPIO2345_DEV, 0xe5, 0x00); /* No inversion */
100
efdesign9800c8c4a2011-07-20 12:37:58 -0600101 /* GPIO30 - unknown output, set to 0
Rudolf Marekaa55f372011-01-16 16:23:51 +0000102 GPI31 - unknown input NC?
103 GPI32 - unknown input NC?
104 GPIO33 - unknown output, set to 0.
105 GPI34 - unknown input NC?
106 GPO35 - loadline control 1 = enabled (2 phase clock) 0 = disabled 4 phase clock
107 GPIO36 - input = HT voltage 1.30V output (low) = HT voltage 1.35V
108 GP37 - unknown input NC? */
109
Rudolf Marek133647a2010-04-05 19:47:34 +0000110 pnp_write_config(GPIO2345_DEV, 0xf0, 0xd6); /* dir of GPIO3 11010110*/
111 pnp_write_config(GPIO2345_DEV, 0xf1, 0x96); /* data */
112 pnp_write_config(GPIO2345_DEV, 0xf2, 0x00); /* No inversion */
113
Rudolf Marekaa55f372011-01-16 16:23:51 +0000114 /* GPO40 - mgpuV bit2
115 GPO41 - mgpuV bit1
116 GPO42 - IRTX
117 GPO43 - IRRX
118 GPIO44 - memory voltage bit2 (input/outputlow)
119 GPIO45 - memory voltage bit1 (2.60 (000) - 2.95 (111))
120 GPIO46 - memory voltage bit0
121 GPIO47 - unknown input? */
122
Rudolf Marek133647a2010-04-05 19:47:34 +0000123 pnp_write_config(GPIO2345_DEV, 0xf4, 0xd0); /* dir of GPIO4 11010000 */
124 pnp_write_config(GPIO2345_DEV, 0xf5, 0x83); /* data */
125 pnp_write_config(GPIO2345_DEV, 0xf6, 0x00); /* No inversion */
126
127 pnp_write_config(GPIO2345_DEV, 0xf7, 0x00); /* MFC */
128 pnp_write_config(GPIO2345_DEV, 0xf8, 0x00); /* MFC */
129 pnp_write_config(GPIO2345_DEV, 0xfe, 0x07); /* trig type */
130 pnp_exit_ext_func_mode(GPIO2345_DEV);
131}
132
133void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
134{
Rudolf Marekf41752c2010-11-30 20:18:53 +0000135 static const u16 spd_addr[] = { DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
Rudolf Marek133647a2010-04-05 19:47:34 +0000136 int needs_reset = 0;
137 u32 bsp_apicid = 0;
138 msr_t msr;
139 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +0100140 struct sys_info *sysinfo = &sysinfo_car;
Rudolf Marek133647a2010-04-05 19:47:34 +0000141
142 if (!cpu_init_detectedx && boot_cpu()) {
143 /* Nothing special needs to be done to find bus 0 */
144 /* Allow the HT devices to be found */
145 enumerate_ht_chain();
Zheng Baoc3422232011-03-28 03:33:10 +0000146 /* sb7xx_51xx_lpc_port80(); */
147 sb7xx_51xx_pci_port80();
Rudolf Marek133647a2010-04-05 19:47:34 +0000148 }
149
Uwe Hermann7b997052010-11-21 22:47:22 +0000150 if (bist == 0)
Rudolf Marek133647a2010-04-05 19:47:34 +0000151 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Rudolf Marek133647a2010-04-05 19:47:34 +0000152
153 enable_rs780_dev8();
Zheng Baoc3422232011-03-28 03:33:10 +0000154 sb7xx_51xx_lpc_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000155
156 sio_init();
Edward O'Callaghanffe460d2014-04-27 22:51:40 +1000157 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Uwe Hermannb015d022010-09-24 18:18:20 +0000158
Rudolf Marek133647a2010-04-05 19:47:34 +0000159 console_init();
160
161 /* Halt if there was a built in self test failure */
162 report_bist_failure(bist);
163 printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
164
165 setup_939a785gmh_resource_map();
166
167 setup_coherent_ht_domain();
168
Patrick Georgie1667822012-05-05 15:29:32 +0200169#if CONFIG_LOGICAL_CPUS
Rudolf Marek133647a2010-04-05 19:47:34 +0000170 /* It is said that we should start core1 after all core0 launched */
171 wait_all_core0_started();
172 start_other_cores();
173#endif
174 wait_all_aps_started(bsp_apicid);
175
176 ht_setup_chains_x(sysinfo);
177
178 /* run _early_setup before soft-reset. */
179 rs780_early_setup();
Zheng Baoc3422232011-03-28 03:33:10 +0000180 sb7xx_51xx_early_setup();
Rudolf Marek133647a2010-04-05 19:47:34 +0000181
182 /* Check to see if processor is capable of changing FIDVID */
183 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
184 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000185 if ((cpuid1.edx & 0x6) == 0x6) {
Rudolf Marek133647a2010-04-05 19:47:34 +0000186 /* Read FIDVID_STATUS */
187 msr=rdmsr(0xc0010042);
188 printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
189
190 enable_fid_change();
191 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
192 init_fidvid_bsp(bsp_apicid);
193
194 /* show final fid and vid */
195 msr=rdmsr(0xc0010042);
196 printk(BIOS_DEBUG, "end msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
Rudolf Marek133647a2010-04-05 19:47:34 +0000197 } else {
198 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
199 }
200
201 needs_reset = optimize_link_coherent_ht();
202 needs_reset |= optimize_link_incoherent_ht(sysinfo);
203 rs780_htinit();
204 printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
205
206 if (needs_reset) {
207 print_info("ht reset -\n");
208 soft_reset();
209 }
210
211 allow_all_aps_stop(bsp_apicid);
212
213 /* It's the time to set ctrl now; */
214 printk(BIOS_DEBUG, "sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
215 sysinfo->nodes, sysinfo->ctrl, spd_addr);
216 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
217 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
218
219 rs780_before_pci_init();
Zheng Baoc3422232011-03-28 03:33:10 +0000220 sb7xx_51xx_before_pci_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000221
222 post_cache_as_ram();
223}