blob: e9b940020ced1f188febc74424d8a5011d228642 [file] [log] [blame]
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
Kyösti Mälkki78093562014-11-11 17:22:23 +02005 * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC
6 * Copyright (C) 2014 Kyösti Mälkki <kyosti.malkki@gmail.com>
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +02007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
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#include <stdint.h>
23#include <string.h>
24#include <device/pci_def.h>
25#include <device/pci_ids.h>
26#include <arch/acpi.h>
27#include <arch/io.h>
28#include <arch/stages.h>
29#include <device/pnp_def.h>
30#include <arch/cpu.h>
31#include <cpu/x86/lapic.h>
32#include <console/console.h>
33#include <console/loglevel.h>
34#include <cpu/x86/mtrr.h>
35#include <cpu/amd/car.h>
36#include <northbridge/amd/agesa/agesawrapper.h>
Kyösti Mälkki78093562014-11-11 17:22:23 +020037#include <southbridge/amd/cimx/cimx_util.h>
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020038#include <cpu/x86/bist.h>
39#include <cpu/x86/cache.h>
40#include <sb_cimx.h>
41#include "SBPLATFORM.h"
42#include "cbmem.h"
43#include <cpu/amd/mtrr.h>
44#include <cpu/amd/agesa/s3_resume.h>
Kyösti Mälkki8c190f32014-11-14 16:20:22 +020045#include <superio/nuvoton/common/nuvoton.h>
46#include <superio/nuvoton/nct5104d/nct5104d.h>
Kyösti Mälkki78093562014-11-11 17:22:23 +020047#include "gpio_ftns.h"
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020048
Kyösti Mälkki8c190f32014-11-14 16:20:22 +020049#define SIO_PORT 0x2e
50#define SERIAL_DEV PNP_DEV(SIO_PORT, NCT5104D_SP1)
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020051
Kyösti Mälkki78093562014-11-11 17:22:23 +020052static void early_lpc_init(void);
53
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020054void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
55{
56 u32 val;
57
58 /*
59 * All cores: allow caching of flash chip code and data
60 * (there are no cache-as-ram reliability concerns with family 14h)
61 */
62 __writemsr (0x20c, (0x0100000000ull - CACHE_ROM_SIZE) | 5);
63 __writemsr (0x20d, (0x1000000000ull - CACHE_ROM_SIZE) | 0x800);
64
65 /* All cores: set pstate 0 (1600 MHz) early to save a few ms of boot time */
66 __writemsr (0xc0010062, 0);
67
68 amd_initmmio();
69
70 if (!cpu_init_detectedx && boot_cpu()) {
71 post_code(0x30);
72 sb_Poweron_Init();
Kyösti Mälkki78093562014-11-11 17:22:23 +020073 early_lpc_init();
74
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020075
76 post_code(0x31);
Kyösti Mälkki8c190f32014-11-14 16:20:22 +020077 nuvoton_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020078 console_init();
79 }
80
81 /* Halt if there was a built in self test failure */
82 post_code(0x34);
83 report_bist_failure(bist);
84
85 /* Load MPB */
86 val = cpuid_eax(1);
87 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
88 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
89
90 post_code(0x37);
91 agesawrapper_amdinitreset();
92
93 post_code(0x39);
94 agesawrapper_amdinitearly();
95
96 int s3resume = acpi_is_wakeup_s3();
97 if (!s3resume) {
98 post_code(0x40);
99 agesawrapper_amdinitpost();
100
101 post_code(0x42);
102 agesawrapper_amdinitenv();
103 amd_initenv();
104
105 } else { /* S3 detect */
106 printk(BIOS_INFO, "S3 detected\n");
107
108 post_code(0x60);
109 agesawrapper_amdinitresume();
110
111 agesawrapper_amds3laterestore();
112
113 post_code(0x61);
114 prepare_for_resume();
115 }
116
117 post_code(0x50);
118 copy_and_run();
119 printk(BIOS_ERR, "Error: copy_and_run() returned!\n");
120
121 post_code(0x54); /* Should never see this post code. */
122}
Kyösti Mälkki78093562014-11-11 17:22:23 +0200123
124static void early_lpc_init(void)
125{
126 u32 mmio_base;
127
128 /* PC Engines requires system boot when power is applied. This feature is
129 * controlled in PM_REG 5Bh register. "Always Power On" works by writing a
130 * value of 05h.
131 */
132 u8 bdata = pm_ioread(SB_PMIOA_REG5B);
133 bdata &= 0xf8; //clear bits 0-2
134 bdata |= 0x05; //set bits 0,2
135 pm_iowrite(SB_PMIOA_REG5B, bdata);
136
137 /* Multi-function pins switch to GPIO0-35, these pins are shared with PCI pins */
138 bdata = pm_ioread(SB_PMIOA_REGEA);
139 bdata &= 0xfe; //clear bit 0
140 bdata |= 0x01; //set bit 0
141 pm_iowrite(SB_PMIOA_REGEA, bdata);
142
143 //configure required GPIOs
144 mmio_base = find_gpio_base();
145 configure_gpio(mmio_base, GPIO_10, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_HIGH);
146 configure_gpio(mmio_base, GPIO_11, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_HIGH);
147 configure_gpio(mmio_base, GPIO_15, GPIO_FTN_1, GPIO_INPUT);
148 configure_gpio(mmio_base, GPIO_16, GPIO_FTN_1, GPIO_INPUT);
149 configure_gpio(mmio_base, GPIO_17, GPIO_FTN_1, GPIO_INPUT);
150 configure_gpio(mmio_base, GPIO_18, GPIO_FTN_1, GPIO_INPUT);
151 configure_gpio(mmio_base, GPIO_187, GPIO_FTN_1, GPIO_INPUT);
152 configure_gpio(mmio_base, GPIO_189, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_LOW);
153 configure_gpio(mmio_base, GPIO_190, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_LOW);
154 configure_gpio(mmio_base, GPIO_191, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_LOW);
155}