blob: 49281b905aa01d09a88770d7f827ce52998780c2 [file] [log] [blame]
Piotr Króldcd2f172016-05-27 12:04:13 +02001/*
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
16#include <stdint.h>
17#include <string.h>
18#include <device/pci_def.h>
Piotr Króldcd2f172016-05-27 12:04:13 +020019#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Michał Żygowskieaba5102018-10-24 16:57:47 +020021#include <device/pnp.h>
Piotr Króldcd2f172016-05-27 12:04:13 +020022#include <arch/cpu.h>
23#include <cpu/x86/lapic.h>
24#include <console/console.h>
25#include <commonlib/loglevel.h>
Michał Żygowski57760e32017-10-17 09:04:58 +020026#include <timestamp.h>
Piotr Króldcd2f172016-05-27 12:04:13 +020027#include <cpu/amd/car.h>
Kyösti Mälkkibebd7662017-04-13 15:25:43 +030028#include <northbridge/amd/agesa/state_machine.h>
Piotr Króldcd2f172016-05-27 12:04:13 +020029#include <northbridge/amd/pi/agesawrapper.h>
30#include <northbridge/amd/pi/agesawrapper_call.h>
31#include <cpu/x86/bist.h>
Piotr Króldcd2f172016-05-27 12:04:13 +020032#include <southbridge/amd/pi/hudson/hudson.h>
Michał Żygowskieaba5102018-10-24 16:57:47 +020033#include <superio/nuvoton/common/nuvoton.h>
34#include <superio/nuvoton/nct5104d/nct5104d.h>
Piotr Króldcd2f172016-05-27 12:04:13 +020035#include <Fch/Fch.h>
Philipp Deppenwieseca39df82017-03-01 02:37:36 +010036
Piotr Króldcd2f172016-05-27 12:04:13 +020037#include "gpio_ftns.h"
38
Michał Żygowskieaba5102018-10-24 16:57:47 +020039#define SIO_PORT 0x2e
40#define SERIAL1_DEV PNP_DEV(SIO_PORT, NCT5104D_SP1)
41#define SERIAL2_DEV PNP_DEV(SIO_PORT, NCT5104D_SP2)
42
Piotr Króldcd2f172016-05-27 12:04:13 +020043static void early_lpc_init(void);
44
45void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
46{
47 u32 val;
48
49 /*
50 * In Hudson RRG, PMIOxD2[5:4] is "Drive strength control for
51 * LpcClk[1:0]". This following register setting has been
52 * replicated in every reference design since Parmer, so it is
53 * believed to be required even though it is not documented in
54 * the SoC BKDGs. Without this setting, there is no serial
55 * output.
56 */
57 outb(0xD2, 0xcd6);
58 outb(0x00, 0xcd7);
59
Piotr Króldcd2f172016-05-27 12:04:13 +020060 hudson_lpc_port80();
61
62 if (!cpu_init_detectedx && boot_cpu()) {
Michał Żygowskieaba5102018-10-24 16:57:47 +020063 pci_devfn_t dev;
64 u32 data;
65
Michał Żygowski57760e32017-10-17 09:04:58 +020066 timestamp_init(timestamp_get());
67 timestamp_add_now(TS_START_ROMSTAGE);
68
Piotr Króldcd2f172016-05-27 12:04:13 +020069 post_code(0x30);
70 early_lpc_init();
71
72 hudson_clk_output_48Mhz();
73 post_code(0x31);
Michał Żygowskieaba5102018-10-24 16:57:47 +020074
75 dev = PCI_DEV(0, 0x14, 3);
76 data = pci_read_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE);
77 /* enable 0x2e/0x4e IO decoding before configuring SuperIO */
78 pci_write_config32(dev, LPC_IO_OR_MEM_DECODE_ENABLE, data | 3);
79
80 /* COM2 on apu5 is reserved so only COM1 should be supported */
81 if ((CONFIG_UART_FOR_CONSOLE == 1) &&
82 !IS_ENABLED(CONFIG_BOARD_PCENGINES_APU5))
83 nuvoton_enable_serial(SERIAL2_DEV, CONFIG_TTYS0_BASE);
84 else if (CONFIG_UART_FOR_CONSOLE == 0)
85 nuvoton_enable_serial(SERIAL1_DEV, CONFIG_TTYS0_BASE);
86
Piotr Króldcd2f172016-05-27 12:04:13 +020087 console_init();
88 }
89
90 /* Halt if there was a built in self test failure */
91 post_code(0x34);
92 report_bist_failure(bist);
93
94 /* Load MPB */
95 val = cpuid_eax(1);
Elyes HAOUASe3e3f4f2018-06-29 21:41:41 +020096 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
97 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
Piotr Króldcd2f172016-05-27 12:04:13 +020098
99 post_code(0x37);
100 AGESAWRAPPER(amdinitreset);
101
102 post_code(0x38);
103 printk(BIOS_DEBUG, "Got past avalon_early_setup\n");
104
105 post_code(0x39);
106 AGESAWRAPPER(amdinitearly);
Piotr Króldcd2f172016-05-27 12:04:13 +0200107
Krystian Hebelfba03202018-12-21 18:19:14 +0100108 /* Disable SVI2 controller to wait for command completion */
109 val = pci_read_config32(PCI_DEV(0, 0x18, 5), 0x12C);
110 if (val & (1 << 30)) {
111 printk(BIOS_DEBUG, "SVI2 Wait completion disabled\n");
112 } else {
113 printk(BIOS_DEBUG, "Disabling SVI2 Wait completion\n");
114 val |= (1 << 30);
115 pci_write_config32(PCI_DEV(0, 0x18, 5), 0x12C, val);
116 }
117
Michał Żygowski57760e32017-10-17 09:04:58 +0200118 timestamp_add_now(TS_BEFORE_INITRAM);
119
Kyösti Mälkki1b183aa2017-02-26 10:11:21 +0200120 post_code(0x40);
121 AGESAWRAPPER(amdinitpost);
Michał Żygowski57760e32017-10-17 09:04:58 +0200122
123 /* FIXME: Detect if TSC frequency changed during raminit? */
124 timestamp_rescale_table(1, 4);
125
126 timestamp_add_now(TS_AFTER_INITRAM);
Kyösti Mälkkibebd7662017-04-13 15:25:43 +0300127}
Piotr Króldcd2f172016-05-27 12:04:13 +0200128
Kyösti Mälkkibebd7662017-04-13 15:25:43 +0300129void agesa_postcar(struct sysinfo *cb)
130{
Kyösti Mälkki1b183aa2017-02-26 10:11:21 +0200131 //PspMboxBiosCmdDramInfo();
132 post_code(0x41);
133 AGESAWRAPPER(amdinitenv);
Piotr Króldcd2f172016-05-27 12:04:13 +0200134
Piotr Króldcd2f172016-05-27 12:04:13 +0200135 outb(0xEA, 0xCD6);
136 outb(0x1, 0xcd7);
Piotr Króldcd2f172016-05-27 12:04:13 +0200137}
138
Piotr Króldcd2f172016-05-27 12:04:13 +0200139static void early_lpc_init(void)
140{
141 u32 setting = 0x0;
142
143 //
144 // Configure output disabled, value low, pull up/down disabled
145 //
Michał Żygowskia4432f42018-07-27 15:59:51 +0200146 if (IS_ENABLED(CONFIG_BOARD_PCENGINES_APU5)) {
147 configure_gpio(IOMUX_GPIO_22, Function0, GPIO_22, setting);
148 }
149
Kamil Wcislo70b92452017-10-12 11:55:16 +0200150 if (IS_ENABLED(CONFIG_BOARD_PCENGINES_APU2) ||
Piotr Król83b4fb92017-11-29 16:34:44 +0100151 IS_ENABLED(CONFIG_BOARD_PCENGINES_APU3) ||
152 IS_ENABLED(CONFIG_BOARD_PCENGINES_APU4)) {
Michał Żygowskia4432f42018-07-27 15:59:51 +0200153 configure_gpio(IOMUX_GPIO_32, Function0, GPIO_32, setting);
Kamil Wcislo70b92452017-10-12 11:55:16 +0200154 }
155
Michał Żygowskia4432f42018-07-27 15:59:51 +0200156 configure_gpio(IOMUX_GPIO_49, Function2, GPIO_49, setting);
157 configure_gpio(IOMUX_GPIO_50, Function2, GPIO_50, setting);
158 configure_gpio(IOMUX_GPIO_71, Function0, GPIO_71, setting);
159
Piotr Króldcd2f172016-05-27 12:04:13 +0200160 //
161 // Configure output enabled, value low, pull up/down disabled
162 //
Michał Żygowskia4432f42018-07-27 15:59:51 +0200163 setting = GPIO_OUTPUT_ENABLE;
Piotr Król83b4fb92017-11-29 16:34:44 +0100164 if (IS_ENABLED(CONFIG_BOARD_PCENGINES_APU3) ||
165 IS_ENABLED(CONFIG_BOARD_PCENGINES_APU4)) {
Michał Żygowskia4432f42018-07-27 15:59:51 +0200166 configure_gpio(IOMUX_GPIO_33, Function0, GPIO_33, setting);
Kamil Wcislo70b92452017-10-12 11:55:16 +0200167 }
168
Michał Żygowskia4432f42018-07-27 15:59:51 +0200169 configure_gpio(IOMUX_GPIO_57, Function1, GPIO_57, setting);
170 configure_gpio(IOMUX_GPIO_58, Function1, GPIO_58, setting);
171 configure_gpio(IOMUX_GPIO_59, Function3, GPIO_59, setting);
172
Piotr Króldcd2f172016-05-27 12:04:13 +0200173 //
174 // Configure output enabled, value high, pull up/down disabled
175 //
Michał Żygowskia4432f42018-07-27 15:59:51 +0200176 setting = GPIO_OUTPUT_ENABLE | GPIO_OUTPUT_VALUE;
177
Kamil Wcislo70b92452017-10-12 11:55:16 +0200178 if (IS_ENABLED(CONFIG_BOARD_PCENGINES_APU5)) {
Michał Żygowskia4432f42018-07-27 15:59:51 +0200179 configure_gpio(IOMUX_GPIO_32, Function0, GPIO_32, setting);
180 configure_gpio(IOMUX_GPIO_33, Function0, GPIO_33, setting);
Kamil Wcislo70b92452017-10-12 11:55:16 +0200181 }
182
Michał Żygowskia4432f42018-07-27 15:59:51 +0200183 configure_gpio(IOMUX_GPIO_51, Function2, GPIO_51, setting);
184 configure_gpio(IOMUX_GPIO_55, Function3, GPIO_55, setting);
185 configure_gpio(IOMUX_GPIO_64, Function2, GPIO_64, setting);
186 configure_gpio(IOMUX_GPIO_68, Function0, GPIO_68, setting);
Piotr Króldcd2f172016-05-27 12:04:13 +0200187}