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