Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 1 | /* |
| 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 Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Kyösti Mälkki | f21c2ac | 2014-10-19 09:35:18 +0300 | [diff] [blame] | 17 | #include <northbridge/amd/agesa/agesawrapper.h> |
Idwer Vollering | fa02e16 | 2014-03-29 13:13:10 +0100 | [diff] [blame] | 18 | |
Kyösti Mälkki | 207880c | 2013-12-10 09:03:17 +0200 | [diff] [blame] | 19 | #include <arch/acpi.h> |
Idwer Vollering | fa02e16 | 2014-03-29 13:13:10 +0100 | [diff] [blame] | 20 | #include <arch/cpu.h> |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 21 | #include <arch/io.h> |
| 22 | #include <arch/stages.h> |
Idwer Vollering | fa02e16 | 2014-03-29 13:13:10 +0100 | [diff] [blame] | 23 | #include <cbmem.h> |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 24 | #include <console/console.h> |
Idwer Vollering | fa02e16 | 2014-03-29 13:13:10 +0100 | [diff] [blame] | 25 | #include <cpu/amd/agesa/s3_resume.h> |
Edward O'Callaghan | bf9d122 | 2014-10-29 09:26:00 +1100 | [diff] [blame] | 26 | #include <cpu/amd/car.h> |
Idwer Vollering | fa02e16 | 2014-03-29 13:13:10 +0100 | [diff] [blame] | 27 | #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'Callaghan | f292002 | 2014-04-27 00:41:50 +1000 | [diff] [blame] | 36 | #include <superio/ite/common/ite.h> |
Rudolf Marek | 80b627e | 2014-05-13 16:36:56 +0200 | [diff] [blame] | 37 | #include <superio/ite/it8728f/it8728f.h> |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 38 | |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 39 | #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 Marek | 80b627e | 2014-05-13 16:36:56 +0200 | [diff] [blame] | 44 | #define SERIAL_DEV PNP_DEV(0x2e, IT8728F_SP1) |
| 45 | #define GPIO_DEV PNP_DEV(0x2e, IT8728F_GPIO) |
Edward O'Callaghan | f292002 | 2014-04-27 00:41:50 +1000 | [diff] [blame] | 46 | |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 47 | static 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 | |
| 61 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
| 62 | { |
| 63 | u32 val; |
| 64 | u8 byte; |
| 65 | device_t dev; |
Idwer Vollering | a09dad0 | 2014-03-11 15:43:35 +0000 | [diff] [blame] | 66 | |
| 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älkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 74 | amd_initmmio(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 75 | |
| 76 | if (!cpu_init_detectedx && boot_cpu()) { |
| 77 | |
Rudolf Marek | 80b627e | 2014-05-13 16:36:56 +0200 | [diff] [blame] | 78 | /* enable SIO LPC decode */ |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 79 | 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 Marek | 80b627e | 2014-05-13 16:36:56 +0200 | [diff] [blame] | 84 | /* enable serial decode */ |
| 85 | byte = pci_read_config8(dev, 0x44); |
| 86 | byte |= (1 << 6); /* 0x3f8 */ |
| 87 | pci_write_config8(dev, 0x44, byte); |
| 88 | |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 89 | 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 Marek | 80b627e | 2014-05-13 16:36:56 +0200 | [diff] [blame] | 97 | ite_kill_watchdog(GPIO_DEV); |
Edward O'Callaghan | f292002 | 2014-04-27 00:41:50 +1000 | [diff] [blame] | 98 | ite_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Rudolf Marek | 80b627e | 2014-05-13 16:36:56 +0200 | [diff] [blame] | 99 | ite_enable_3vsbsw(GPIO_DEV); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 100 | 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 Menzel | b2cddd4 | 2013-05-05 12:09:16 +0200 | [diff] [blame] | 111 | /* default is byte = 0x0, so no need to set it in this case */ |
| 112 | if (byte) |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 113 | 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 HAOUAS | aedcc10 | 2014-07-21 08:07:19 +0200 | [diff] [blame] | 122 | printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val); |
| 123 | printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 124 | |
| 125 | post_code(0x37); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 126 | agesawrapper_amdinitreset(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 127 | post_code(0x39); |
| 128 | |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 129 | agesawrapper_amdinitearly(); |
Kyösti Mälkki | 78c5d58 | 2015-01-09 23:48:47 +0200 | [diff] [blame] | 130 | int s3resume = acpi_is_wakeup_s3(); |
Kyösti Mälkki | e1b468e | 2014-06-18 09:10:53 +0300 | [diff] [blame] | 131 | if (!s3resume) { |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 132 | post_code(0x40); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 133 | agesawrapper_amdinitpost(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 134 | post_code(0x41); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 135 | agesawrapper_amdinitenv(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 136 | disable_cache_as_ram(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 137 | } else { /* S3 detect */ |
| 138 | printk(BIOS_INFO, "S3 detected\n"); |
| 139 | |
| 140 | post_code(0x60); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 141 | agesawrapper_amdinitresume(); |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 142 | amd_initcpuio(); |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 143 | agesawrapper_amds3laterestore(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 144 | |
| 145 | post_code(0x61); |
Kyösti Mälkki | 23b4f0c | 2014-06-18 09:55:26 +0300 | [diff] [blame] | 146 | prepare_for_resume(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 147 | } |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 148 | |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 149 | post_code(0x50); |
Stefan Reinauer | 648d166 | 2013-05-06 18:05:39 -0700 | [diff] [blame] | 150 | copy_and_run(); |
Rudolf Marek | c8eab2c | 2013-03-20 21:43:50 +0100 | [diff] [blame] | 151 | |
| 152 | post_code(0x54); /* Should never see this post code. */ |
| 153 | } |