blob: 709dbcd80de2f9bf9ddc61c12350d8c0800af2a3 [file] [log] [blame]
Rudolf Marekc8eab2c2013-03-20 21:43:50 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 * Copyright (C) 2012 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.
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010015 */
16
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030017#include <northbridge/amd/agesa/agesawrapper.h>
Idwer Volleringfa02e162014-03-29 13:13:10 +010018
Kyösti Mälkki207880c2013-12-10 09:03:17 +020019#include <arch/acpi.h>
Idwer Volleringfa02e162014-03-29 13:13:10 +010020#include <arch/cpu.h>
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010021#include <arch/io.h>
22#include <arch/stages.h>
Idwer Volleringfa02e162014-03-29 13:13:10 +010023#include <cbmem.h>
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010024#include <console/console.h>
Idwer Volleringfa02e162014-03-29 13:13:10 +010025#include <cpu/amd/agesa/s3_resume.h>
Edward O'Callaghanbf9d1222014-10-29 09:26:00 +110026#include <cpu/amd/car.h>
Idwer Volleringfa02e162014-03-29 13:13:10 +010027#include <cpu/x86/bist.h>
28#include <cpu/x86/lapic.h>
29#include <device/pci_def.h>
30#include <device/pci_ids.h>
31#include <device/pnp_def.h>
32#include <southbridge/amd/agesa/hudson/hudson.h>
33#include <southbridge/amd/agesa/hudson/smbus.h>
34#include <stdint.h>
35#include <string.h>
Edward O'Callaghanf2920022014-04-27 00:41:50 +100036#include <superio/ite/common/ite.h>
Rudolf Marek80b627e2014-05-13 16:36:56 +020037#include <superio/ite/it8728f/it8728f.h>
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010038
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010039#define MMIO_NON_POSTED_START 0xfed00000
40#define MMIO_NON_POSTED_END 0xfedfffff
41#define SB_MMIO 0xFED80000
42#define SB_MMIO_MISC32(x) *(volatile u32 *)(SB_MMIO + 0xE00 + (x))
43
Rudolf Marek80b627e2014-05-13 16:36:56 +020044#define SERIAL_DEV PNP_DEV(0x2e, IT8728F_SP1)
45#define GPIO_DEV PNP_DEV(0x2e, IT8728F_GPIO)
Edward O'Callaghanf2920022014-04-27 00:41:50 +100046
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010047static void sbxxx_enable_48mhzout(void)
48{
49 /* most likely programming to 48MHz out signal */
50 u32 reg32;
51 reg32 = SB_MMIO_MISC32(0x28);
52 reg32 &= 0xffc7ffff;
53 reg32 |= 0x00100000;
54 SB_MMIO_MISC32(0x28) = reg32;
55
56 reg32 = SB_MMIO_MISC32(0x40);
57 reg32 &= ~0x80u;
58 SB_MMIO_MISC32(0x40) = reg32;
59}
60
61void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx)
62{
63 u32 val;
64 u8 byte;
65 device_t dev;
Idwer Volleringa09dad02014-03-11 15:43:35 +000066
67#if IS_ENABLED(CONFIG_POST_DEVICE_PCI_PCIE)
68 hudson_pci_port80();
69#endif
70#if IS_ENABLED(CONFIG_POST_DEVICE_LPC)
71 hudson_lpc_port80();
72#endif
73
Kyösti Mälkki48518f02014-11-25 14:20:57 +020074 amd_initmmio();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010075
76 if (!cpu_init_detectedx && boot_cpu()) {
77
Rudolf Marek80b627e2014-05-13 16:36:56 +020078 /* enable SIO LPC decode */
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010079 dev = PCI_DEV(0, 0x14, 3);
80 byte = pci_read_config8(dev, 0x48);
81 byte |= 3; /* 2e, 2f */
82 pci_write_config8(dev, 0x48, byte);
83
Rudolf Marek80b627e2014-05-13 16:36:56 +020084 /* enable serial decode */
85 byte = pci_read_config8(dev, 0x44);
86 byte |= (1 << 6); /* 0x3f8 */
87 pci_write_config8(dev, 0x44, byte);
88
Rudolf Marekc8eab2c2013-03-20 21:43:50 +010089 post_code(0x30);
90
91 /* enable SB MMIO space */
92 outb(0x24, 0xcd6);
93 outb(0x1, 0xcd7);
94
95 /* enable SIO clock */
96 sbxxx_enable_48mhzout();
Rudolf Marek80b627e2014-05-13 16:36:56 +020097 ite_kill_watchdog(GPIO_DEV);
Edward O'Callaghanf2920022014-04-27 00:41:50 +100098 ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Rudolf Marek80b627e2014-05-13 16:36:56 +020099 ite_enable_3vsbsw(GPIO_DEV);
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100100 console_init();
101
102 /* turn on secondary smbus at b20 */
103 outb(0x28, 0xcd6);
104 byte = inb(0xcd7);
105 byte |= 1;
106 outb(byte, 0xcd7);
107
108 /* set DDR3 voltage */
109 byte = CONFIG_BOARD_ASUS_F2A85_M_DDR3_VOLT_VAL;
110
Paul Menzelb2cddd42013-05-05 12:09:16 +0200111 /* default is byte = 0x0, so no need to set it in this case */
112 if (byte)
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100113 do_smbus_write_byte(0xb20, 0x15, 0x3, byte);
114 }
115
116 /* Halt if there was a built in self test failure */
117 post_code(0x34);
118 report_bist_failure(bist);
119
120 /* Load MPB */
121 val = cpuid_eax(1);
Elyes HAOUASaedcc102014-07-21 08:07:19 +0200122 printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val);
123 printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx);
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100124
125 post_code(0x37);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300126 agesawrapper_amdinitreset();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100127 post_code(0x39);
128
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300129 agesawrapper_amdinitearly();
Kyösti Mälkki78c5d582015-01-09 23:48:47 +0200130 int s3resume = acpi_is_wakeup_s3();
Kyösti Mälkkie1b468e2014-06-18 09:10:53 +0300131 if (!s3resume) {
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100132 post_code(0x40);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300133 agesawrapper_amdinitpost();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100134 post_code(0x41);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300135 agesawrapper_amdinitenv();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100136 disable_cache_as_ram();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100137 } else { /* S3 detect */
138 printk(BIOS_INFO, "S3 detected\n");
139
140 post_code(0x60);
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300141 agesawrapper_amdinitresume();
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200142 amd_initcpuio();
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300143 agesawrapper_amds3laterestore();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100144
145 post_code(0x61);
Kyösti Mälkki23b4f0c2014-06-18 09:55:26 +0300146 prepare_for_resume();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100147 }
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100148
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100149 post_code(0x50);
Stefan Reinauer648d1662013-05-06 18:05:39 -0700150 copy_and_run();
Rudolf Marekc8eab2c2013-03-20 21:43:50 +0100151
152 post_code(0x54); /* Should never see this post code. */
153}