blob: d97f2b0a6a220d19ba0dd84fab967cd35cc740aa [file] [log] [blame]
Angel Pons5c596802020-04-03 01:21:01 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Siyuan Wang80cf7d52013-07-09 17:42:43 +08002
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02003#include <AGESA.h>
Kyösti Mälkki26f297e2014-05-26 11:27:54 +03004#include <northbridge/amd/agesa/BiosCallOuts.h>
Kyösti Mälkki6dcd4bc2017-03-04 07:33:19 +02005#include <northbridge/amd/agesa/state_machine.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02006#include <FchPlatform.h>
Siyuan Wang80cf7d52013-07-09 17:42:43 +08007
Elyes HAOUAS28b38cd2019-03-18 11:30:08 +01008#include "imc.h"
9
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030010const BIOS_CALLOUT_STRUCT BiosCallouts[] =
Siyuan Wang80cf7d52013-07-09 17:42:43 +080011{
Kyösti Mälkki83cc3b02014-05-04 23:13:08 +030012 {AGESA_DO_RESET, agesa_Reset },
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030013 {AGESA_READ_SPD, agesa_ReadSpd },
Kyösti Mälkki83cc3b02014-05-04 23:13:08 +030014 {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
15 {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
16 {AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
17 {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess },
18 {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess },
Kyösti Mälkkicb989f22014-05-04 23:13:08 +030019 {AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage }
Siyuan Wang80cf7d52013-07-09 17:42:43 +080020};
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030021const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
Siyuan Wang80cf7d52013-07-09 17:42:43 +080022
23/**
24 * AMD Olivehill Platform ALC272 Verb Table
25 */
26static const CODEC_ENTRY Olivehill_Alc272_VerbTbl[] = {
27 {0x11, 0x411111F0}, // - SPDIF_OUT2
28 {0x12, 0x411111F0}, // - DMIC_1/2
29 {0x13, 0x411111F0}, // - DMIC_3/4
30 {0x14, 0x411111F0}, // Port D - LOUT1
31 {0x15, 0x411111F0}, // Port A - LOUT2
32 {0x16, 0x411111F0}, //
33 {0x17, 0x411111F0}, // Port H - MONO
34 {0x18, 0x01a19840}, // Port B - MIC1
35 {0x19, 0x411111F0}, // Port F - MIC2
36 {0x1a, 0x01813030}, // Port C - LINE1
37 {0x1b, 0x411111F0}, // Port E - LINE2
38 {0x1d, 0x40130605}, // - PCBEEP
39 {0x1e, 0x01441120}, // - SPDIF_OUT1
40 {0x21, 0x01214010}, // Port I - HPOUT
41 {0xff, 0xffffffff}
42};
43
44static const CODEC_TBL_LIST OlivehillCodecTableList[] =
45{
46 {0x10ec0272, (CODEC_ENTRY*)&Olivehill_Alc272_VerbTbl[0]},
47 {(UINT32)0x0FFFFFFFF, (CODEC_ENTRY*)0x0FFFFFFFFUL}
48};
49
50#define FAN_INPUT_INTERNAL_DIODE 0
51#define FAN_INPUT_TEMP0 1
52#define FAN_INPUT_TEMP1 2
53#define FAN_INPUT_TEMP2 3
54#define FAN_INPUT_TEMP3 4
55#define FAN_INPUT_TEMP0_FILTER 5
56#define FAN_INPUT_ZERO 6
57#define FAN_INPUT_DISABLED 7
58
59#define FAN_AUTOMODE (1 << 0)
60#define FAN_LINEARMODE (1 << 1)
61#define FAN_STEPMODE ~(1 << 1)
62#define FAN_POLARITY_HIGH (1 << 2)
63#define FAN_POLARITY_LOW ~(1 << 2)
64
65/* Normally, 4-wire fan runs at 25KHz and 3-wire fan runs at 100Hz */
66#define FREQ_28KHZ 0x0
67#define FREQ_25KHZ 0x1
68#define FREQ_23KHZ 0x2
69#define FREQ_21KHZ 0x3
70#define FREQ_29KHZ 0x4
71#define FREQ_18KHZ 0x5
72#define FREQ_100HZ 0xF7
73#define FREQ_87HZ 0xF8
74#define FREQ_58HZ 0xF9
75#define FREQ_44HZ 0xFA
76#define FREQ_35HZ 0xFB
77#define FREQ_29HZ 0xFC
78#define FREQ_22HZ 0xFD
79#define FREQ_14HZ 0xFE
80#define FREQ_11HZ 0xFF
81
82/* Olivehill Hardware Monitor Fan Control
83 * Hardware limitation:
Elyes HAOUAS2cbfadd2020-01-28 18:11:14 +010084 * HWM failed to read the input temperature via I2C,
85 * if other software switches the I2C switch by mistake or intention.
86 * We recommend using IMC to control Fans, instead of HWM.
Siyuan Wang80cf7d52013-07-09 17:42:43 +080087 */
Siyuan Wang80cf7d52013-07-09 17:42:43 +080088static void oem_fan_control(FCH_DATA_BLOCK *FchParams)
89{
Elyes HAOUAS2cbfadd2020-01-28 18:11:14 +010090 /* Enable IMC fan control, the recommended way */
Julius Wernercd49cce2019-03-05 16:53:33 -080091 if (CONFIG(HUDSON_IMC_FWM)) {
Marshall Dawson6dd620b2017-08-16 18:04:06 -060092 imc_reg_init();
WANG Siyuan62a3f6f2013-12-02 10:39:44 +080093
Marshall Dawson6dd620b2017-08-16 18:04:06 -060094 /* HwMonitorEnable = TRUE && HwmFchtsiAutoOpll ==FALSE to call FchECfancontrolservice */
95 FchParams->Hwm.HwMonitorEnable = TRUE;
96 FchParams->Hwm.HwmFchtsiAutoPoll = FALSE;/* 0 disable, 1 enable TSI Auto Polling */
WANG Siyuan62a3f6f2013-12-02 10:39:44 +080097
Marshall Dawson6dd620b2017-08-16 18:04:06 -060098 FchParams->Imc.ImcEnable = TRUE;
99 FchParams->Hwm.HwmControl = 1; /* 1 IMC, 0 HWM */
Elyes HAOUASa342f392018-10-17 10:56:26 +0200100 FchParams->Imc.ImcEnableOverWrite = 1; /* 2 disable IMC, 1 enable IMC, 0 following hw strap setting */
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800101
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600102 LibAmdMemFill(&(FchParams->Imc.EcStruct), 0, sizeof(FCH_EC), FchParams->StdHeader);
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800103
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600104 /* Thermal Zone Parameter */
105 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg0 = 0x00;
106 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg1 = 0x00; /* Zone */
107 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg2 = 0x3d; //BIT0 | BIT2 | BIT5;
108 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg3 = 0x4e;//6 | BIT3;
109 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg4 = 0x00;
110 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg5 = 0x04;
111 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg6 = 0x9a; /* SMBUS Address for SMBUS based temperature sensor such as SB-TSI and ADM1032 */
112 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg7 = 0x01;
Elyes HAOUAS73be5f72019-12-05 17:18:15 +0100113 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg8 = 0x01; /* PWM stepping rate in unit of PWM level percentage */
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600114 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg9 = 0x00;
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800115
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600116 /* IMC Fan Policy temperature thresholds */
117 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg0 = 0x00;
118 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg1 = 0x00; /* Zone */
119 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg2 = 0x46;///80; /*AC0 threshold in Celsius */
120 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg3 = 0x3c; /*AC1 threshold in Celsius */
121 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg4 = 0x32; /*AC2 threshold in Celsius */
122 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg5 = 0xff; /*AC3 threshold in Celsius, 0xFF is not define */
123 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg6 = 0xff; /*AC4 threshold in Celsius, 0xFF is not define */
124 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg7 = 0xff; /*AC5 threshold in Celsius, 0xFF is not define */
125 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg8 = 0xff; /*AC6 threshold in Celsius, 0xFF is not define */
126 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg9 = 0xff; /*AC7 lowest threshold in Celsius, 0xFF is not define */
127 FchParams->Imc.EcStruct.MsgFun83Zone0MsgRegA = 0x4b; /*critical threshold* in Celsius, 0xFF is not define */
128 FchParams->Imc.EcStruct.MsgFun83Zone0MsgRegB = 0x00;
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800129
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600130 /* IMC Fan Policy PWM Settings */
131 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg0 = 0x00;
132 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg1 = 0x00; /* Zone */
133 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg2 = 0x5a; /* AL0 percentage */
134 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg3 = 0x46; /* AL1 percentage */
135 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg4 = 0x28; /* AL2 percentage */
136 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg5 = 0xff; /* AL3 percentage */
137 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg6 = 0xff; /* AL4 percentage */
138 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg7 = 0xff; /* AL5 percentage */
139 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg8 = 0xff; /* AL6 percentage */
140 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg9 = 0xff; /* AL7 percentage */
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800141
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600142 FchParams->Imc.EcStruct.IMCFUNSupportBitMap = 0x111;//BIT0 | BIT4 |BIT8;
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800143
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600144 /* NOTE:
Elyes HAOUAS2cbfadd2020-01-28 18:11:14 +0100145 * FchInitLateHwm will overwrite the EcStruct with EcDefaultMessage,
146 * AGESA puts EcDefaultMessage as global data in ROM, so we can't overwrite it.
147 * So we remove it from AGESA code. Please See FchInitLateHwm.
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600148 */
149 } else {
Elyes HAOUAS2cbfadd2020-01-28 18:11:14 +0100150 /* HWM fan control, the way not recommended */
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600151 FchParams->Imc.ImcEnable = FALSE;
152 FchParams->Hwm.HwMonitorEnable = TRUE;
153 FchParams->Hwm.HwmFchtsiAutoPoll = TRUE;/* 1 enable, 0 disable TSI Auto Polling */
154 }
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800155}
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800156
Kyösti Mälkki6dcd4bc2017-03-04 07:33:19 +0200157void board_FCH_InitReset(struct sysinfo *cb_NA, FCH_RESET_DATA_BLOCK *FchParams_reset)
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800158{
Kyösti Mälkki6dcd4bc2017-03-04 07:33:19 +0200159}
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800160
Kyösti Mälkki6dcd4bc2017-03-04 07:33:19 +0200161void board_FCH_InitEnv(struct sysinfo *cb_NA, FCH_DATA_BLOCK *FchParams_env)
162{
163 /* Azalia Controller OEM Codec Table Pointer */
164 FchParams_env->Azalia.AzaliaOemCodecTablePtr = (CODEC_TBL_LIST *)(&OlivehillCodecTableList[0]);
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800165
Kyösti Mälkki6dcd4bc2017-03-04 07:33:19 +0200166 /* Fan Control */
167 oem_fan_control(FchParams_env);
Siyuan Wang80cf7d52013-07-09 17:42:43 +0800168}