Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 Advanced Micro Devices, Inc. |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 5 | * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC |
| 6 | * Copyright (C) 2014 Kyösti Mälkki <kyosti.malkki@gmail.com> |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 7 | * |
| 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. |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | #include <string.h> |
| 20 | #include <device/pci_def.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <arch/acpi.h> |
| 23 | #include <arch/io.h> |
| 24 | #include <arch/stages.h> |
| 25 | #include <device/pnp_def.h> |
| 26 | #include <arch/cpu.h> |
| 27 | #include <cpu/x86/lapic.h> |
| 28 | #include <console/console.h> |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 29 | #include <commonlib/loglevel.h> |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 30 | #include <cpu/x86/mtrr.h> |
| 31 | #include <cpu/amd/car.h> |
| 32 | #include <northbridge/amd/agesa/agesawrapper.h> |
Kyösti Mälkki | d610c58 | 2017-03-05 06:28:18 +0200 | [diff] [blame^] | 33 | #include <northbridge/amd/agesa/agesa_helper.h> |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 34 | #include <southbridge/amd/cimx/cimx_util.h> |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 35 | #include <cpu/x86/bist.h> |
| 36 | #include <cpu/x86/cache.h> |
| 37 | #include <sb_cimx.h> |
| 38 | #include "SBPLATFORM.h" |
| 39 | #include "cbmem.h" |
| 40 | #include <cpu/amd/mtrr.h> |
| 41 | #include <cpu/amd/agesa/s3_resume.h> |
Kyösti Mälkki | 8c190f3 | 2014-11-14 16:20:22 +0200 | [diff] [blame] | 42 | #include <superio/nuvoton/common/nuvoton.h> |
| 43 | #include <superio/nuvoton/nct5104d/nct5104d.h> |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 44 | #include "gpio_ftns.h" |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 45 | |
Kyösti Mälkki | 8c190f3 | 2014-11-14 16:20:22 +0200 | [diff] [blame] | 46 | #define SIO_PORT 0x2e |
| 47 | #define SERIAL_DEV PNP_DEV(SIO_PORT, NCT5104D_SP1) |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 48 | |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 49 | static void early_lpc_init(void); |
| 50 | |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 51 | void cache_as_ram_main(unsigned long bist, unsigned long cpu_init_detectedx) |
| 52 | { |
| 53 | u32 val; |
| 54 | |
Kyösti Mälkki | 59e0334 | 2016-11-20 11:03:13 +0200 | [diff] [blame] | 55 | /* Must come first to enable PCI MMCONF. */ |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 56 | amd_initmmio(); |
| 57 | |
| 58 | if (!cpu_init_detectedx && boot_cpu()) { |
| 59 | post_code(0x30); |
| 60 | sb_Poweron_Init(); |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 61 | early_lpc_init(); |
| 62 | |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 63 | |
| 64 | post_code(0x31); |
Kyösti Mälkki | 8c190f3 | 2014-11-14 16:20:22 +0200 | [diff] [blame] | 65 | nuvoton_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE); |
Kyösti Mälkki | f09e6d4 | 2015-01-10 12:13:23 +0200 | [diff] [blame] | 66 | console_init(); |
| 67 | } |
| 68 | |
| 69 | /* Halt if there was a built in self test failure */ |
| 70 | post_code(0x34); |
| 71 | report_bist_failure(bist); |
| 72 | |
| 73 | /* Load MPB */ |
| 74 | val = cpuid_eax(1); |
| 75 | printk(BIOS_DEBUG, "BSP Family_Model: %08x\n", val); |
| 76 | printk(BIOS_DEBUG, "cpu_init_detectedx = %08lx\n", cpu_init_detectedx); |
| 77 | |
| 78 | post_code(0x37); |
| 79 | agesawrapper_amdinitreset(); |
| 80 | |
| 81 | post_code(0x39); |
| 82 | agesawrapper_amdinitearly(); |
| 83 | |
| 84 | int s3resume = acpi_is_wakeup_s3(); |
| 85 | if (!s3resume) { |
| 86 | post_code(0x40); |
| 87 | agesawrapper_amdinitpost(); |
| 88 | |
| 89 | post_code(0x42); |
| 90 | agesawrapper_amdinitenv(); |
| 91 | amd_initenv(); |
| 92 | |
| 93 | } else { /* S3 detect */ |
| 94 | printk(BIOS_INFO, "S3 detected\n"); |
| 95 | |
| 96 | post_code(0x60); |
| 97 | agesawrapper_amdinitresume(); |
| 98 | |
| 99 | agesawrapper_amds3laterestore(); |
| 100 | |
| 101 | post_code(0x61); |
| 102 | prepare_for_resume(); |
| 103 | } |
| 104 | |
| 105 | post_code(0x50); |
| 106 | copy_and_run(); |
| 107 | printk(BIOS_ERR, "Error: copy_and_run() returned!\n"); |
| 108 | |
| 109 | post_code(0x54); /* Should never see this post code. */ |
| 110 | } |
Kyösti Mälkki | 7809356 | 2014-11-11 17:22:23 +0200 | [diff] [blame] | 111 | |
| 112 | static void early_lpc_init(void) |
| 113 | { |
| 114 | u32 mmio_base; |
| 115 | |
| 116 | /* PC Engines requires system boot when power is applied. This feature is |
| 117 | * controlled in PM_REG 5Bh register. "Always Power On" works by writing a |
| 118 | * value of 05h. |
| 119 | */ |
| 120 | u8 bdata = pm_ioread(SB_PMIOA_REG5B); |
| 121 | bdata &= 0xf8; //clear bits 0-2 |
| 122 | bdata |= 0x05; //set bits 0,2 |
| 123 | pm_iowrite(SB_PMIOA_REG5B, bdata); |
| 124 | |
| 125 | /* Multi-function pins switch to GPIO0-35, these pins are shared with PCI pins */ |
| 126 | bdata = pm_ioread(SB_PMIOA_REGEA); |
| 127 | bdata &= 0xfe; //clear bit 0 |
| 128 | bdata |= 0x01; //set bit 0 |
| 129 | pm_iowrite(SB_PMIOA_REGEA, bdata); |
| 130 | |
| 131 | //configure required GPIOs |
| 132 | mmio_base = find_gpio_base(); |
| 133 | configure_gpio(mmio_base, GPIO_10, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_HIGH); |
| 134 | configure_gpio(mmio_base, GPIO_11, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_HIGH); |
| 135 | configure_gpio(mmio_base, GPIO_15, GPIO_FTN_1, GPIO_INPUT); |
| 136 | configure_gpio(mmio_base, GPIO_16, GPIO_FTN_1, GPIO_INPUT); |
| 137 | configure_gpio(mmio_base, GPIO_17, GPIO_FTN_1, GPIO_INPUT); |
| 138 | configure_gpio(mmio_base, GPIO_18, GPIO_FTN_1, GPIO_INPUT); |
| 139 | configure_gpio(mmio_base, GPIO_187, GPIO_FTN_1, GPIO_INPUT); |
| 140 | configure_gpio(mmio_base, GPIO_189, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_LOW); |
| 141 | configure_gpio(mmio_base, GPIO_190, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_LOW); |
| 142 | configure_gpio(mmio_base, GPIO_191, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_LOW); |
| 143 | } |