Sergej Ivanov | d777c78 | 2015-04-03 18:10:27 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2015 Sergej Ivanov <getinaks@gmail.com> |
| 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. |
Sergej Ivanov | d777c78 | 2015-04-03 18:10:27 +0300 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <device/azalia.h> |
| 18 | #include "AGESA.h" |
| 19 | #include "amdlib.h" |
| 20 | #include <northbridge/amd/agesa/BiosCallOuts.h> |
| 21 | #include "Ids.h" |
| 22 | #include "OptionsIds.h" |
| 23 | #include "heapManager.h" |
| 24 | #include "FchPlatform.h" |
| 25 | #include "cbfs.h" |
| 26 | #include <stdlib.h> |
| 27 | |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 28 | static AGESA_STATUS Fch_Oem_config(UINT32 Func, UINTN FchData, VOID *ConfigPtr); |
Sergej Ivanov | d777c78 | 2015-04-03 18:10:27 +0300 | [diff] [blame] | 29 | |
| 30 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = |
| 31 | { |
| 32 | {AGESA_DO_RESET, agesa_Reset }, |
| 33 | {AGESA_READ_SPD, agesa_ReadSpd }, |
| 34 | {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported }, |
| 35 | {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp }, |
| 36 | {AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData }, |
| 37 | {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess }, |
| 38 | {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess }, |
| 39 | {AGESA_FCH_OEM_CALLOUT, Fch_Oem_config }, |
| 40 | {AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage } |
| 41 | }; |
| 42 | const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts); |
| 43 | |
| 44 | /** |
| 45 | * CODEC Initialization Table for Azalia HD Audio using Realtek ALC662 chip (from linux, running under vendor bios) |
| 46 | */ |
| 47 | const CODEC_ENTRY Alc662_VerbTbl[] = |
| 48 | { |
| 49 | { 0x14, 0x01014410 }, |
| 50 | { 0x15, 0x411111f0 }, |
| 51 | { 0x16, 0x411111f0 }, |
| 52 | { 0x18, 0x01a19c30 }, |
| 53 | { 0x19, 0x02a19c40 }, |
| 54 | { 0x1a, 0x0181343f }, |
| 55 | { 0x1b, 0x02214c20 }, |
| 56 | { 0x1c, 0x411111f0 }, |
| 57 | { 0x1d, 0x4004c601 }, |
| 58 | { 0x1e, 0x411111f0 }, |
| 59 | { 0xff, 0xffffffff } |
| 60 | }; |
| 61 | |
| 62 | |
| 63 | static const CODEC_TBL_LIST CodecTableList[] = |
| 64 | { |
| 65 | {0x10ec0662, (CODEC_ENTRY*)&Alc662_VerbTbl[0]}, |
| 66 | {(UINT32)0x0FFFFFFFF, (CODEC_ENTRY*)0x0FFFFFFFFUL} |
| 67 | }; |
| 68 | |
| 69 | #define FAN_INPUT_INTERNAL_DIODE 0 |
| 70 | #define FAN_INPUT_TEMP0 1 |
| 71 | #define FAN_INPUT_TEMP1 2 |
| 72 | #define FAN_INPUT_TEMP2 3 |
| 73 | #define FAN_INPUT_TEMP3 4 |
| 74 | #define FAN_INPUT_TEMP0_FILTER 5 |
| 75 | #define FAN_INPUT_ZERO 6 |
| 76 | #define FAN_INPUT_DISABLED 7 |
| 77 | |
| 78 | #define FAN_AUTOMODE (1 << 0) |
| 79 | #define FAN_LINEARMODE (1 << 1) |
| 80 | #define FAN_STEPMODE ~(1 << 1) |
| 81 | #define FAN_POLARITY_HIGH (1 << 2) |
| 82 | #define FAN_POLARITY_LOW ~(1 << 2) |
| 83 | |
| 84 | /* Normally, 4-wire fan runs at 25KHz and 3-wire fan runs at 100Hz */ |
| 85 | #define FREQ_28KHZ 0x0 |
| 86 | #define FREQ_25KHZ 0x1 |
| 87 | #define FREQ_23KHZ 0x2 |
| 88 | #define FREQ_21KHZ 0x3 |
| 89 | #define FREQ_29KHZ 0x4 |
| 90 | #define FREQ_18KHZ 0x5 |
| 91 | #define FREQ_100HZ 0xF7 |
| 92 | #define FREQ_87HZ 0xF8 |
| 93 | #define FREQ_58HZ 0xF9 |
| 94 | #define FREQ_44HZ 0xFA |
| 95 | #define FREQ_35HZ 0xFB |
| 96 | #define FREQ_29HZ 0xFC |
| 97 | #define FREQ_22HZ 0xFD |
| 98 | #define FREQ_14HZ 0xFE |
| 99 | #define FREQ_11HZ 0xFF |
| 100 | |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * Fch Oem setting callback |
| 105 | * |
| 106 | * Configure platform specific Hudson device, |
| 107 | * such Azalia, SATA, IMC etc. |
| 108 | */ |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 109 | static AGESA_STATUS Fch_Oem_config(UINT32 Func, UINTN FchData, VOID *ConfigPtr) |
Sergej Ivanov | d777c78 | 2015-04-03 18:10:27 +0300 | [diff] [blame] | 110 | { |
| 111 | AMD_CONFIG_PARAMS *StdHeader = ConfigPtr; |
| 112 | |
| 113 | if (StdHeader->Func == AMD_INIT_RESET) { |
| 114 | FCH_RESET_DATA_BLOCK *FchParams_reset = (FCH_RESET_DATA_BLOCK *)FchData; |
Kyösti Mälkki | bc3cee5 | 2015-05-23 14:19:11 +0300 | [diff] [blame] | 115 | printk(BIOS_DEBUG, "Fch OEM config in INIT RESET "); |
Sergej Ivanov | d777c78 | 2015-04-03 18:10:27 +0300 | [diff] [blame] | 116 | FchParams_reset->FchReset.Xhci0Enable = IS_ENABLED(CONFIG_HUDSON_XHCI_ENABLE); |
| 117 | FchParams_reset->FchReset.Xhci1Enable = FALSE; |
| 118 | FchParams_reset->LegacyFree = IS_ENABLED(CONFIG_HUDSON_LEGACY_FREE); |
| 119 | FchParams_reset->FchReset.SataEnable = 1; |
| 120 | FchParams_reset->FchReset.IdeEnable = 0; |
Sergej Ivanov | cd920bf | 2015-12-01 18:53:54 +0300 | [diff] [blame^] | 121 | FchParams_reset->Mode = 6; |
Sergej Ivanov | d777c78 | 2015-04-03 18:10:27 +0300 | [diff] [blame] | 122 | } else if (StdHeader->Func == AMD_INIT_ENV) { |
| 123 | FCH_DATA_BLOCK *FchParams_env = (FCH_DATA_BLOCK *)FchData; |
Kyösti Mälkki | bc3cee5 | 2015-05-23 14:19:11 +0300 | [diff] [blame] | 124 | printk(BIOS_DEBUG, "Fch OEM config in INIT ENV "); |
Sergej Ivanov | d777c78 | 2015-04-03 18:10:27 +0300 | [diff] [blame] | 125 | |
| 126 | /* Azalia Controller OEM Codec Table Pointer */ |
| 127 | FchParams_env->Azalia.AzaliaOemCodecTablePtr = (CODEC_TBL_LIST*)(&CodecTableList[0]); |
| 128 | /* Azalia Controller Front Panel OEM Table Pointer */ |
| 129 | |
| 130 | FchParams_env->Imc.ImcEnable = FALSE; |
| 131 | FchParams_env->Hwm.HwMonitorEnable = FALSE; |
| 132 | FchParams_env->Hwm.HwmFchtsiAutoPoll = FALSE;/* 1 enable, 0 disable TSI Auto Polling */ |
| 133 | |
| 134 | /* sata configuration */ |
| 135 | printk(BIOS_DEBUG, "Configuring SATA: selected mode = "); |
| 136 | FchParams_env->Sata.SataClass = CONFIG_HUDSON_SATA_MODE; |
| 137 | switch ((SATA_CLASS)CONFIG_HUDSON_SATA_MODE) { // code from olivehillplus (ft3b) - only one place where sata is configured |
| 138 | case SataLegacyIde: |
| 139 | case SataRaid: |
| 140 | case SataAhci: |
| 141 | case SataAhci7804: |
| 142 | FchParams_env->Sata.SataIdeMode = FALSE; |
| 143 | printk(BIOS_DEBUG, "AHCI or RAID or IDE = %x\n", CONFIG_HUDSON_SATA_MODE); |
| 144 | break; |
| 145 | |
| 146 | case SataIde2Ahci: |
| 147 | case SataIde2Ahci7804: |
| 148 | default: /* SataNativeIde */ |
| 149 | FchParams_env->Sata.SataIdeMode = TRUE; |
| 150 | printk(BIOS_DEBUG, "IDE2AHCI = %x\n", CONFIG_HUDSON_SATA_MODE); |
| 151 | break; |
| 152 | } |
| 153 | /* XHCI configuration */ |
| 154 | FchParams_env->Usb.Xhci0Enable = IS_ENABLED(CONFIG_HUDSON_XHCI_ENABLE); |
| 155 | FchParams_env->Usb.Xhci1Enable = FALSE; |
| 156 | } |
| 157 | printk(BIOS_DEBUG, "Done\n"); |
| 158 | |
| 159 | return AGESA_SUCCESS; |
| 160 | } |