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