blob: 16cc02b213578bdd8c8e0660852e58bacdc34ce5 [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#include <stdint.h>
22#include <string.h>
23#include <device/pci_def.h>
24#include <arch/io.h>
25#include <device/pnp_def.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000026#include <cpu/x86/lapic.h>
Edwin Beasanteb50c7d2010-07-06 21:05:04 +000027#include <pc80/mc146818rtc.h>
Patrick Georgi12584e22010-05-08 09:14:51 +000028#include <console/console.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000029#include <cpu/amd/model_fxx_rev.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110030#include <northbridge/amd/amdk8/raminit.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000031#include "lib/delay.c"
Patrick Georgi9bd9a902010-11-20 10:31:00 +000032#include <spd.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110033#include <cpu/x86/lapic.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000034#include "northbridge/amd/amdk8/reset_test.c"
Edward O'Callaghanffe460d2014-04-27 22:51:40 +100035#include <superio/winbond/common/winbond.h>
36#include <superio/winbond/w83627dhg/w83627dhg.h>
Edward O'Callaghan77757c22015-01-04 21:33:39 +110037#include <cpu/x86/bist.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000038#include "northbridge/amd/amdk8/setup_resource_map.c"
stepan836ae292010-12-08 05:42:47 +000039#include "southbridge/amd/rs780/early_setup.c"
Edward O'Callaghan77757c22015-01-04 21:33:39 +110040#include <southbridge/amd/sb700/sb700.h>
41#include <southbridge/amd/sb700/smbus.h>
stepan836ae292010-12-08 05:42:47 +000042#include "northbridge/amd/amdk8/debug.c" /* After sb700/early_setup.c! */
Rudolf Marek133647a2010-04-05 19:47:34 +000043
44#define SERIAL_DEV PNP_DEV(0x2e, W83627DHG_SP1)
Uwe Hermann3a4ed152010-12-05 22:36:14 +000045#define GPIO2345_DEV PNP_DEV(0x2e, W83627DHG_GPIO2345_V)
Rudolf Marek133647a2010-04-05 19:47:34 +000046
Uwe Hermann7b997052010-11-21 22:47:22 +000047static void memreset(int controllers, const struct mem_controller *ctrl) { }
48static void activate_spd_rom(const struct mem_controller *ctrl) { }
Rudolf Marek133647a2010-04-05 19:47:34 +000049
Rudolf Marek133647a2010-04-05 19:47:34 +000050static inline int spd_read_byte(u32 device, u32 address)
51{
efdesign9800c8c4a2011-07-20 12:37:58 -060052 return do_smbus_read_byte(SMBUS_IO_BASE, device, address);
Rudolf Marek133647a2010-04-05 19:47:34 +000053}
54
Edward O'Callaghan77757c22015-01-04 21:33:39 +110055#include <northbridge/amd/amdk8/amdk8.h>
Rudolf Marek133647a2010-04-05 19:47:34 +000056#include "northbridge/amd/amdk8/incoherent_ht.c"
57#include "northbridge/amd/amdk8/raminit.c"
58#include "northbridge/amd/amdk8/coherent_ht.c"
59#include "lib/generic_sdram.c"
60#include "resourcemap.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000061#include "cpu/amd/dualcore/dualcore.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000062#include "cpu/amd/model_fxx/init_cpus.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000063#include "cpu/amd/model_fxx/fidvid.c"
Rudolf Marek133647a2010-04-05 19:47:34 +000064#include "northbridge/amd/amdk8/early_ht.c"
65
Stefan Reinauer56a684a2010-04-07 15:40:26 +000066static void sio_init(void)
Rudolf Marek133647a2010-04-05 19:47:34 +000067{
68 u8 reg;
69
70 pnp_enter_ext_func_mode(GPIO2345_DEV);
71 pnp_set_logical_device(GPIO2345_DEV);
72
Rudolf Marekaa55f372011-01-16 16:23:51 +000073 /* Pin 119 ~ 120 is GP21, GP20 */
Rudolf Marek133647a2010-04-05 19:47:34 +000074 reg = pnp_read_config(GPIO2345_DEV, 0x29);
75 pnp_write_config(GPIO2345_DEV, 0x29, (reg | 2));
76
Rudolf Marek9c9ae3a2010-11-30 21:21:33 +000077 /* Turn on the Power LED ("Suspend LED" in Super I/O) */
78 reg = pnp_read_config(GPIO2345_DEV, 0xf3);
79 pnp_write_config(GPIO2345_DEV, 0xf3, (reg | 0x40));
80
Rudolf Marek133647a2010-04-05 19:47:34 +000081 /* todo document this */
82 pnp_write_config(GPIO2345_DEV, 0x2c, 0x1);
83 pnp_write_config(GPIO2345_DEV, 0x2d, 0x1);
84
Rudolf Marekaa55f372011-01-16 16:23:51 +000085 /* GPO20 - sideport voltage 1 = 1.82 0 = 1.92
86 GPI21 - unknown input (NC?)
87 GPI22 - unknown input (NC?)
88 GPO23 - mgpuV bit0
Rudolf Mareka1125232011-01-16 17:15:36 +000089 GP24-27 - PS/2 mouse/keyb (only keyb is connected use flip interface for mouse)
Rudolf Marekaa55f372011-01-16 16:23:51 +000090 */
Rudolf Marek133647a2010-04-05 19:47:34 +000091 pnp_write_config(GPIO2345_DEV, 0x30, 0x07); /* Enable GPIO 2,3,4. */
92 pnp_write_config(GPIO2345_DEV, 0xe3, 0xf6); /* dir of GPIO2 11110110*/
93 pnp_write_config(GPIO2345_DEV, 0xe4, 0x0e); /* data */
94 pnp_write_config(GPIO2345_DEV, 0xe5, 0x00); /* No inversion */
95
efdesign9800c8c4a2011-07-20 12:37:58 -060096 /* GPIO30 - unknown output, set to 0
Rudolf Marekaa55f372011-01-16 16:23:51 +000097 GPI31 - unknown input NC?
98 GPI32 - unknown input NC?
99 GPIO33 - unknown output, set to 0.
100 GPI34 - unknown input NC?
101 GPO35 - loadline control 1 = enabled (2 phase clock) 0 = disabled 4 phase clock
102 GPIO36 - input = HT voltage 1.30V output (low) = HT voltage 1.35V
103 GP37 - unknown input NC? */
104
Rudolf Marek133647a2010-04-05 19:47:34 +0000105 pnp_write_config(GPIO2345_DEV, 0xf0, 0xd6); /* dir of GPIO3 11010110*/
106 pnp_write_config(GPIO2345_DEV, 0xf1, 0x96); /* data */
107 pnp_write_config(GPIO2345_DEV, 0xf2, 0x00); /* No inversion */
108
Rudolf Marekaa55f372011-01-16 16:23:51 +0000109 /* GPO40 - mgpuV bit2
110 GPO41 - mgpuV bit1
111 GPO42 - IRTX
112 GPO43 - IRRX
113 GPIO44 - memory voltage bit2 (input/outputlow)
114 GPIO45 - memory voltage bit1 (2.60 (000) - 2.95 (111))
115 GPIO46 - memory voltage bit0
116 GPIO47 - unknown input? */
117
Rudolf Marek133647a2010-04-05 19:47:34 +0000118 pnp_write_config(GPIO2345_DEV, 0xf4, 0xd0); /* dir of GPIO4 11010000 */
119 pnp_write_config(GPIO2345_DEV, 0xf5, 0x83); /* data */
120 pnp_write_config(GPIO2345_DEV, 0xf6, 0x00); /* No inversion */
121
122 pnp_write_config(GPIO2345_DEV, 0xf7, 0x00); /* MFC */
123 pnp_write_config(GPIO2345_DEV, 0xf8, 0x00); /* MFC */
124 pnp_write_config(GPIO2345_DEV, 0xfe, 0x07); /* trig type */
125 pnp_exit_ext_func_mode(GPIO2345_DEV);
126}
127
128void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
129{
Rudolf Marekf41752c2010-11-30 20:18:53 +0000130 static const u16 spd_addr[] = { DIMM0, DIMM2, 0, 0, DIMM1, DIMM3, 0, 0, };
Rudolf Marek133647a2010-04-05 19:47:34 +0000131 int needs_reset = 0;
132 u32 bsp_apicid = 0;
133 msr_t msr;
134 struct cpuid_result cpuid1;
Patrick Georgibbc880e2012-11-20 18:20:56 +0100135 struct sys_info *sysinfo = &sysinfo_car;
Rudolf Marek133647a2010-04-05 19:47:34 +0000136
137 if (!cpu_init_detectedx && boot_cpu()) {
138 /* Nothing special needs to be done to find bus 0 */
139 /* Allow the HT devices to be found */
140 enumerate_ht_chain();
Zheng Baoc3422232011-03-28 03:33:10 +0000141 /* sb7xx_51xx_lpc_port80(); */
142 sb7xx_51xx_pci_port80();
Rudolf Marek133647a2010-04-05 19:47:34 +0000143 }
144
Uwe Hermann7b997052010-11-21 22:47:22 +0000145 if (bist == 0)
Rudolf Marek133647a2010-04-05 19:47:34 +0000146 bsp_apicid = init_cpus(cpu_init_detectedx, sysinfo);
Rudolf Marek133647a2010-04-05 19:47:34 +0000147
148 enable_rs780_dev8();
Zheng Baoc3422232011-03-28 03:33:10 +0000149 sb7xx_51xx_lpc_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000150
151 sio_init();
Edward O'Callaghanffe460d2014-04-27 22:51:40 +1000152 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Uwe Hermannb015d022010-09-24 18:18:20 +0000153
Rudolf Marek133647a2010-04-05 19:47:34 +0000154 console_init();
155
156 /* Halt if there was a built in self test failure */
157 report_bist_failure(bist);
158 printk(BIOS_DEBUG, "bsp_apicid=0x%x\n", bsp_apicid);
159
160 setup_939a785gmh_resource_map();
161
162 setup_coherent_ht_domain();
163
Patrick Georgie1667822012-05-05 15:29:32 +0200164#if CONFIG_LOGICAL_CPUS
Rudolf Marek133647a2010-04-05 19:47:34 +0000165 /* It is said that we should start core1 after all core0 launched */
166 wait_all_core0_started();
167 start_other_cores();
168#endif
169 wait_all_aps_started(bsp_apicid);
170
171 ht_setup_chains_x(sysinfo);
172
173 /* run _early_setup before soft-reset. */
174 rs780_early_setup();
Zheng Baoc3422232011-03-28 03:33:10 +0000175 sb7xx_51xx_early_setup();
Rudolf Marek133647a2010-04-05 19:47:34 +0000176
177 /* Check to see if processor is capable of changing FIDVID */
178 /* otherwise it will throw a GP# when reading FIDVID_STATUS */
179 cpuid1 = cpuid(0x80000007);
Uwe Hermann7b997052010-11-21 22:47:22 +0000180 if ((cpuid1.edx & 0x6) == 0x6) {
Rudolf Marek133647a2010-04-05 19:47:34 +0000181 /* Read FIDVID_STATUS */
182 msr=rdmsr(0xc0010042);
183 printk(BIOS_DEBUG, "begin msr fid, vid: hi=0x%x, lo=0x%x\n", msr.hi, msr.lo);
184
185 enable_fid_change();
186 enable_fid_change_on_sb(sysinfo->sbbusn, sysinfo->sbdn);
187 init_fidvid_bsp(bsp_apicid);
188
189 /* show final fid and vid */
190 msr=rdmsr(0xc0010042);
191 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 +0000192 } else {
193 printk(BIOS_DEBUG, "Changing FIDVID not supported\n");
194 }
195
196 needs_reset = optimize_link_coherent_ht();
197 needs_reset |= optimize_link_incoherent_ht(sysinfo);
198 rs780_htinit();
199 printk(BIOS_DEBUG, "needs_reset=0x%x\n", needs_reset);
200
201 if (needs_reset) {
202 print_info("ht reset -\n");
203 soft_reset();
204 }
205
206 allow_all_aps_stop(bsp_apicid);
207
208 /* It's the time to set ctrl now; */
209 printk(BIOS_DEBUG, "sysinfo->nodes: %2x sysinfo->ctrl: %p spd_addr: %p\n",
210 sysinfo->nodes, sysinfo->ctrl, spd_addr);
211 fill_mem_ctrl(sysinfo->nodes, sysinfo->ctrl, spd_addr);
212 sdram_initialize(sysinfo->nodes, sysinfo->ctrl, sysinfo);
213
214 rs780_before_pci_init();
Zheng Baoc3422232011-03-28 03:33:10 +0000215 sb7xx_51xx_before_pci_init();
Rudolf Marek133647a2010-04-05 19:47:34 +0000216
217 post_cache_as_ram();
218}