blob: 3d1458bed1a19d1fd60ab6ad44c0f4be440ac2bb [file] [log] [blame]
WANG Siyuanf77f7342013-08-13 17:09:51 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <stdint.h>
21#include <string.h>
22#include <device/pci_def.h>
23#include <device/pci_ids.h>
Kyösti Mälkki207880c2013-12-10 09:03:17 +020024#include <arch/acpi.h>
WANG Siyuanf77f7342013-08-13 17:09:51 +080025#include <arch/io.h>
26#include <arch/stages.h>
27#include <device/pnp_def.h>
28#include <arch/cpu.h>
29#include <cpu/x86/lapic.h>
30#include <console/console.h>
31#include <console/loglevel.h>
Edward O'Callaghanbf9d1222014-10-29 09:26:00 +110032#include <cpu/amd/car.h>
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030033#include <northbridge/amd/agesa/agesawrapper.h>
WANG Siyuanf77f7342013-08-13 17:09:51 +080034#include "cpu/x86/bist.h"
35#include "cpu/x86/lapic.h"
36#include "southbridge/amd/agesa/hudson/hudson.h"
37#include "cpu/amd/agesa/s3_resume.h"
WANG Siyuanf77f7342013-08-13 17:09:51 +080038#include "cbmem.h"
Edward O'Callaghan92da2062014-05-13 23:52:30 +100039#include <superio/winbond/common/winbond.h>
40#include <superio/winbond/w83627uhg/w83627uhg.h>
WANG Siyuanf77f7342013-08-13 17:09:51 +080041
42#define SERIAL_DEV PNP_DEV(0x2e, W83627UHG_SP1)
43
WANG Siyuanf77f7342013-08-13 17:09:51 +080044
45void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
46{
47 u32 val, t32;
48 u32 *addr32;
WANG Siyuanf77f7342013-08-13 17:09:51 +080049
50 /* In Hudson RRG, PMIOxD2[5:4] is "Drive strength control for
51 * LpcClk[1:0]". To be consistent with Parmer, setting to 4mA
52 * even though the register is not documented in the Kabini BKDG.
53 * Otherwise the serial output is bad code.
54 */
55 //outb(0xD2, 0xcd6);
56 //outb(0x00, 0xcd7);
57
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +030058 agesawrapper_amdinitmmio();
WANG Siyuanf77f7342013-08-13 17:09:51 +080059
Kyösti Mälkki88ff8b52014-11-21 17:40:37 +020060 /* Set LPC decode enables. */
61 pci_devfn_t dev = PCI_DEV(0, 0x14, 3);
62 pci_write_config32(dev, 0x44, 0xff03ffd5);
63
WANG Siyuanf77f7342013-08-13 17:09:51 +080064 hudson_lpc_port80();
65
66 /* Enable the AcpiMmio space */
67 outb(0x24, 0xcd6);
68 outb(0x1, 0xcd7);
69
70 /* Set auxiliary output clock frequency on OSCOUT1 pin to be 48MHz */
71 addr32 = (u32 *)0xfed80e28;
72 t32 = *addr32;
73 t32 &= 0xfff8ffff;
74 *addr32 = t32;
75
76 /* Enable Auxiliary Clock1, disable FCH 14 MHz OscClk */
77 addr32 = (u32 *)0xfed80e40;
78 t32 = *addr32;
79 t32 &= 0xffffbffb;
80 *addr32 = t32;
81
82 if (!cpu_init_detectedx && boot_cpu()) {
83 post_code(0x30);
84 post_code(0x31);
85
Edward O'Callaghan92da2062014-05-13 23:52:30 +100086 /* w83627uhg has a default clk of 48MHz, p.9 of data-sheet */
87 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
WANG Siyuanf77f7342013-08-13 17:09:51 +080088
89 console_init();
90 }
91
92 /* Halt if there was a built in self test failure */
93 post_code(0x34);
94 report_bist_failure(bist);
95
96 /* Load MPB */
97 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +020098 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
99 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
WANG Siyuanf77f7342013-08-13 17:09:51 +0800100
101 /* On Larne, after LpcClkDrvSth is set, it needs some time to be stable, because of the buffer ICS551M */
102 int i;
103 for(i = 0; i < 200000; i++)
104 val = inb(0xcd6);
105
106 post_code(0x37);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300107 agesawrapper_amdinitreset();
WANG Siyuanf77f7342013-08-13 17:09:51 +0800108 post_code(0x38);
109 printk(BIOS_DEBUG, "Got past yangtze_early_setup\n");
110
111 post_code(0x39);
112
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300113 agesawrapper_amdinitearly();
Kyösti Mälkkie1b468e2014-06-18 09:10:53 +0300114 int s3resume = acpi_is_wakeup_early() && acpi_s3_resume_allowed();
115 if (!s3resume) {
WANG Siyuanf77f7342013-08-13 17:09:51 +0800116 post_code(0x40);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300117 agesawrapper_amdinitpost();
WANG Siyuanf77f7342013-08-13 17:09:51 +0800118 post_code(0x41);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300119 agesawrapper_amdinitenv();
WANG Siyuanf77f7342013-08-13 17:09:51 +0800120 /* TODO: Disable cache is not ok. */
121 disable_cache_as_ram();
WANG Siyuanf77f7342013-08-13 17:09:51 +0800122 } else { /* S3 detect */
123 printk(BIOS_INFO, "S3 detected\n");
124
125 post_code(0x60);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300126 agesawrapper_amdinitresume();
WANG Siyuanf77f7342013-08-13 17:09:51 +0800127
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300128 agesawrapper_amdinitcpuio();
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300129 agesawrapper_amds3laterestore();
WANG Siyuanf77f7342013-08-13 17:09:51 +0800130
131 post_code(0x61);
Kyösti Mälkki23b4f0c2014-06-18 09:55:26 +0300132 prepare_for_resume();
WANG Siyuanf77f7342013-08-13 17:09:51 +0800133 }
WANG Siyuanf77f7342013-08-13 17:09:51 +0800134
135 outb(0xEA, 0xCD6);
136 outb(0x1, 0xcd7);
WANG Siyuanf77f7342013-08-13 17:09:51 +0800137
138 post_code(0x50);
139 copy_and_run();
140
141 post_code(0x54); /* Should never see this post code. */
142}