Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "agesawrapper.h" |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 21 | #include "BiosCallOuts.h" |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 22 | #include "OptionsIds.h" |
Alexandru Gagniuc | 1d87dac | 2014-03-28 14:48:13 -0500 | [diff] [blame] | 23 | |
| 24 | #include <cbfs.h> |
| 25 | #include <southbridge/amd/agesa/hudson/imc.h> |
| 26 | #include <vendorcode/amd/agesa/f15tn/Proc/Fch/FchPlatform.h> |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 27 | |
| 28 | STATIC CONST BIOS_CALLOUT_STRUCT BiosCallouts[] = |
| 29 | { |
| 30 | {AGESA_ALLOCATE_BUFFER, fam15tn_AllocateBuffer }, |
| 31 | {AGESA_DEALLOCATE_BUFFER, fam15tn_DeallocateBuffer }, |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 32 | {AGESA_LOCATE_BUFFER, fam15tn_LocateBuffer }, |
| 33 | {AGESA_READ_SPD, fam15tn_ReadSpd }, |
Kyösti Mälkki | 83cc3b0 | 2014-05-04 23:13:08 +0300 | [diff] [blame^] | 34 | {AGESA_DO_RESET, agesa_Reset }, |
| 35 | {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported }, |
| 36 | {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp }, |
| 37 | {AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData }, |
| 38 | {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess }, |
| 39 | {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess }, |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 40 | {AGESA_FCH_OEM_CALLOUT, Fch_Oem_config }, |
Kyösti Mälkki | cb989f2 | 2014-05-04 23:13:08 +0300 | [diff] [blame] | 41 | {AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage } |
Alexandru Gagniuc | fccfee3 | 2014-03-26 18:51:08 -0500 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | AGESA_STATUS GetBiosCallout (UINT32 Func, UINT32 Data, VOID *ConfigPtr) |
| 45 | { |
| 46 | UINTN i; |
| 47 | AGESA_STATUS CalloutStatus; |
| 48 | UINTN CallOutCount = sizeof (BiosCallouts) / sizeof (BiosCallouts [0]); |
| 49 | |
| 50 | for (i = 0; i < CallOutCount; i++) |
| 51 | { |
| 52 | if (BiosCallouts[i].CalloutName == Func) |
| 53 | break; |
| 54 | } |
| 55 | |
| 56 | if(i >= CallOutCount) |
| 57 | return AGESA_UNSUPPORTED; |
| 58 | |
| 59 | CalloutStatus = BiosCallouts[i].CalloutPtr (Func, Data, ConfigPtr); |
| 60 | |
| 61 | return CalloutStatus; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * AMD Parmer Platform ALC272 Verb Table |
| 66 | */ |
| 67 | static const CODEC_ENTRY Parmer_Alc272_VerbTbl[] = { |
| 68 | {0x11, 0x411111F0}, |
| 69 | {0x12, 0x411111F0}, |
| 70 | {0x13, 0x411111F0}, |
| 71 | {0x14, 0x411111F0}, |
| 72 | {0x15, 0x411111F0}, |
| 73 | {0x16, 0x411111F0}, |
| 74 | {0x17, 0x411111F0}, |
| 75 | {0x18, 0x01a19840}, |
| 76 | {0x19, 0x411111F0}, |
| 77 | {0x1a, 0x01813030}, |
| 78 | {0x1b, 0x411111F0}, |
| 79 | {0x1d, 0x40130605}, |
| 80 | {0x1e, 0x01441120}, |
| 81 | {0x21, 0x01211010}, |
| 82 | {0xff, 0xffffffff} |
| 83 | }; |
| 84 | |
| 85 | static const CODEC_TBL_LIST CodecTableList[] = |
| 86 | { |
| 87 | {0x10ec0272, (CODEC_ENTRY*)&Parmer_Alc272_VerbTbl[0]}, |
| 88 | {(UINT32)0x0FFFFFFFF, (CODEC_ENTRY*)0x0FFFFFFFFUL} |
| 89 | }; |
| 90 | |
| 91 | #define FAN_INPUT_INTERNAL_DIODE 0 |
| 92 | #define FAN_INPUT_TEMP0 1 |
| 93 | #define FAN_INPUT_TEMP1 2 |
| 94 | #define FAN_INPUT_TEMP2 3 |
| 95 | #define FAN_INPUT_TEMP3 4 |
| 96 | #define FAN_INPUT_TEMP0_FILTER 5 |
| 97 | #define FAN_INPUT_ZERO 6 |
| 98 | #define FAN_INPUT_DISABLED 7 |
| 99 | |
| 100 | #define FAN_AUTOMODE (1 << 0) |
| 101 | #define FAN_LINEARMODE (1 << 1) |
| 102 | #define FAN_STEPMODE ~(1 << 1) |
| 103 | #define FAN_POLARITY_HIGH (1 << 2) |
| 104 | #define FAN_POLARITY_LOW ~(1 << 2) |
| 105 | |
| 106 | /* Normally, 4-wire fan runs at 25KHz and 3-wire fan runs at 100Hz */ |
| 107 | #define FREQ_28KHZ 0x0 |
| 108 | #define FREQ_25KHZ 0x1 |
| 109 | #define FREQ_23KHZ 0x2 |
| 110 | #define FREQ_21KHZ 0x3 |
| 111 | #define FREQ_29KHZ 0x4 |
| 112 | #define FREQ_18KHZ 0x5 |
| 113 | #define FREQ_100HZ 0xF7 |
| 114 | #define FREQ_87HZ 0xF8 |
| 115 | #define FREQ_58HZ 0xF9 |
| 116 | #define FREQ_44HZ 0xFA |
| 117 | #define FREQ_35HZ 0xFB |
| 118 | #define FREQ_29HZ 0xFC |
| 119 | #define FREQ_22HZ 0xFD |
| 120 | #define FREQ_14HZ 0xFE |
| 121 | #define FREQ_11HZ 0xFF |
| 122 | |
| 123 | /* Parmer Hardware Monitor Fan Control |
| 124 | * Hardware limitation: |
| 125 | * HWM failed to read the input temperture vi I2C, |
| 126 | * if other software switch the I2C switch by mistake or intention. |
| 127 | * We recommend to using IMC to control Fans, instead of HWM. |
| 128 | */ |
| 129 | static void oem_fan_control(FCH_DATA_BLOCK *FchParams) |
| 130 | { |
| 131 | /* Enable IMC fan control. the recommand way */ |
| 132 | #if IS_ENABLED(CONFIG_HUDSON_IMC_FWM) |
| 133 | |
| 134 | imc_reg_init(); |
| 135 | |
| 136 | /* HwMonitorEnable = TRUE && HwmFchtsiAutoOpll ==FALSE to call FchECfancontrolservice */ |
| 137 | FchParams->Hwm.HwMonitorEnable = TRUE; |
| 138 | FchParams->Hwm.HwmFchtsiAutoPoll = FALSE;/* 0 disable, 1 enable TSI Auto Polling */ |
| 139 | |
| 140 | FchParams->Imc.ImcEnable = TRUE; |
| 141 | FchParams->Hwm.HwmControl = 1; /* 1 IMC, 0 HWM */ |
| 142 | FchParams->Imc.ImcEnableOverWrite = 1; /* 2 disable IMC , 1 enable IMC, 0 following hw strap setting */ |
| 143 | |
| 144 | LibAmdMemFill(&(FchParams->Imc.EcStruct), 0, sizeof(FCH_EC), FchParams->StdHeader); |
| 145 | |
| 146 | /* Thermal Zone Parameter */ |
| 147 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg0 = 0x00; |
| 148 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg1 = 0x00; /* Zone */ |
| 149 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg2 = 0x3d; //BIT0 | BIT2 | BIT5; |
| 150 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg3 = 0x0e;//6 | BIT3; |
| 151 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg4 = 0x00; |
| 152 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg5 = 0x54; |
| 153 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg6 = 0x98; /* SMBUS Address for SMBUS based temperature sensor such as SB-TSI and ADM1032 */ |
| 154 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg7 = 0x02; |
| 155 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg8 = 0x01; /* PWM steping rate in unit of PWM level percentage */ |
| 156 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg9 = 0x00; |
| 157 | |
| 158 | /* IMC Fan Policy temperature thresholds */ |
| 159 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg0 = 0x00; |
| 160 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg1 = 0x00; /* Zone */ |
| 161 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg2 = 0x46;///80; /*AC0 threshold in Celsius */ |
| 162 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg3 = 0x3c; /*AC1 threshold in Celsius */ |
| 163 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg4 = 0x32; /*AC2 threshold in Celsius */ |
| 164 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg5 = 0xff; /*AC3 threshold in Celsius, 0xFF is not define */ |
| 165 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg6 = 0xff; /*AC4 threshold in Celsius, 0xFF is not define */ |
| 166 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg7 = 0xff; /*AC5 threshold in Celsius, 0xFF is not define */ |
| 167 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg8 = 0xff; /*AC6 threshold in Celsius, 0xFF is not define */ |
| 168 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg9 = 0xff; /*AC7 lowest threshold in Celsius, 0xFF is not define */ |
| 169 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgRegA = 0x4b; /*critical threshold* in Celsius, 0xFF is not define */ |
| 170 | FchParams->Imc.EcStruct.MsgFun83Zone0MsgRegB = 0x00; |
| 171 | |
| 172 | /* IMC Fan Policy PWM Settings */ |
| 173 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg0 = 0x00; |
| 174 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg1 = 0x00; /* Zone */ |
| 175 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg2 = 0x5a; /* AL0 percentage */ |
| 176 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg3 = 0x46; /* AL1 percentage */ |
| 177 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg4 = 0x28; /* AL2 percentage */ |
| 178 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg5 = 0xff; /* AL3 percentage */ |
| 179 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg6 = 0xff; /* AL4 percentage */ |
| 180 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg7 = 0xff; /* AL5 percentage */ |
| 181 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg8 = 0xff; /* AL6 percentage */ |
| 182 | FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg9 = 0xff; /* AL7 percentage */ |
| 183 | |
| 184 | FchParams->Imc.EcStruct.IMCFUNSupportBitMap = 0x111;//BIT0 | BIT4 |BIT8; |
| 185 | |
| 186 | /* NOTE: |
| 187 | * FchInitLateHwm will overwrite the EcStruct with EcDefaultMassege, |
| 188 | * AGESA put EcDefaultMassege as global data in ROM, so we can't overwride it. |
| 189 | * so we remove it from AGESA code. Please Seee FchInitLateHwm. |
| 190 | */ |
| 191 | |
| 192 | #else /* HWM fan control, the way not recommand */ |
| 193 | FchParams->Imc.ImcEnable = FALSE; |
| 194 | FchParams->Hwm.HwMonitorEnable = TRUE; |
| 195 | FchParams->Hwm.HwmFchtsiAutoPoll = TRUE;/* 1 enable, 0 disable TSI Auto Polling */ |
| 196 | |
| 197 | #endif /* CONFIG_HUDSON_IMC_FWM */ |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Fch Oem setting callback |
| 202 | * |
| 203 | * Configure platform specific Hudson device, |
| 204 | * such Azalia, SATA, IMC etc. |
| 205 | */ |
| 206 | AGESA_STATUS Fch_Oem_config(UINT32 Func, UINT32 FchData, VOID *ConfigPtr) |
| 207 | { |
| 208 | FCH_RESET_DATA_BLOCK *FchParams = (FCH_RESET_DATA_BLOCK *)FchData; |
| 209 | |
| 210 | if (FchParams->StdHeader->Func == AMD_INIT_RESET) { |
| 211 | FCH_RESET_DATA_BLOCK *FchParams_reset = (FCH_RESET_DATA_BLOCK *) FchData; |
| 212 | printk(BIOS_DEBUG, "Fch OEM config in INIT RESET "); |
| 213 | //FchParams_reset->EcChannel0 = TRUE; /* logical devicd 3 */ |
| 214 | #if CONFIG_HUDSON_LEGACY_FREE |
| 215 | FchParams_reset->LegacyFree = 1; |
| 216 | #endif |
| 217 | } else if (FchParams->StdHeader->Func == AMD_INIT_ENV) { |
| 218 | FCH_DATA_BLOCK *FchParams_env = (FCH_DATA_BLOCK *)FchData; |
| 219 | printk(BIOS_DEBUG, "Fch OEM config in INIT ENV "); |
| 220 | |
| 221 | /* Azalia Controller OEM Codec Table Pointer */ |
| 222 | FchParams_env->Azalia.AzaliaOemCodecTablePtr = (CODEC_TBL_LIST *)(&CodecTableList[0]); |
| 223 | /* Azalia Controller Front Panel OEM Table Pointer */ |
| 224 | |
| 225 | /* Fan Control */ |
| 226 | oem_fan_control(FchParams_env); |
| 227 | |
| 228 | /* XHCI configuration */ |
| 229 | #if CONFIG_HUDSON_XHCI_ENABLE |
| 230 | FchParams_env->Usb.Xhci0Enable = TRUE; |
| 231 | #else |
| 232 | FchParams_env->Usb.Xhci0Enable = FALSE; |
| 233 | #endif |
| 234 | FchParams_env->Usb.Xhci1Enable = FALSE; |
| 235 | |
| 236 | /* sata configuration */ |
| 237 | } |
| 238 | printk(BIOS_DEBUG, "Done\n"); |
| 239 | |
| 240 | return AGESA_SUCCESS; |
| 241 | } |