blob: 46f4adbd976136e4168af90707a15bd288833632 [file] [log] [blame]
Angel Pons2dfba372020-04-03 01:21:55 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Dave Frodinc43bce52014-12-03 08:22:46 -07002
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02003#include <AGESA.h>
Dave Frodinc43bce52014-12-03 08:22:46 -07004#include <northbridge/amd/agesa/BiosCallOuts.h>
Kyösti Mälkki74e854c2017-03-05 14:21:39 +02005#include <northbridge/amd/agesa/state_machine.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02006#include <FchPlatform.h>
Dave Frodinc43bce52014-12-03 08:22:46 -07007
Elyes HAOUAS28b38cd2019-03-18 11:30:08 +01008#include "imc.h"
9
Dave Frodinc43bce52014-12-03 08:22:46 -070010const BIOS_CALLOUT_STRUCT BiosCallouts[] =
11{
Dave Frodinc43bce52014-12-03 08:22:46 -070012 {AGESA_DO_RESET, agesa_Reset },
Dave Frodind6aa7cf2014-11-21 14:57:03 -070013 {AGESA_READ_SPD, agesa_ReadSpd_from_cbfs },
Dave Frodinc43bce52014-12-03 08:22:46 -070014 {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 },
Dave Frodinc43bce52014-12-03 08:22:46 -070019 {AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage }
20};
21const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
22
23/**
Dave Frodind6aa7cf2014-11-21 14:57:03 -070024 * ALC272 Verb Table
Dave Frodinc43bce52014-12-03 08:22:46 -070025 */
Dave Frodind6aa7cf2014-11-21 14:57:03 -070026const CODEC_ENTRY Alc272_VerbTbl[] = {
Dave Frodinc43bce52014-12-03 08:22:46 -070027 {0x11, 0x411111F0}, // - SPDIF_OUT2
28 {0x12, 0x411111F0}, // - DMIC_1/2
29 {0x13, 0x411111F0}, // - DMIC_3/4
30 {0x14, 0x411111F0}, // Port D - LOUT1
Dave Frodind6aa7cf2014-11-21 14:57:03 -070031 {0x15, 0x01011050}, // Port A - LOUT2 Explorer 2x DAC
Dave Frodinc43bce52014-12-03 08:22:46 -070032 {0x16, 0x411111F0}, //
33 {0x17, 0x411111F0}, // Port H - MONO
Dave Frodind6aa7cf2014-11-21 14:57:03 -070034 {0x18, 0x01a11840}, // Port B - MIC1
Dave Frodinc43bce52014-12-03 08:22:46 -070035 {0x19, 0x411111F0}, // Port F - MIC2
Dave Frodind6aa7cf2014-11-21 14:57:03 -070036 {0x1a, 0x01811030}, // Port C - LINE1
37 {0x1b, 0x01811020}, // Port E - LINE2 Explorer 2x ADC
Dave Frodinc43bce52014-12-03 08:22:46 -070038 {0x1d, 0x40130605}, // - PCBEEP
Dave Frodind6aa7cf2014-11-21 14:57:03 -070039 {0x1e, 0x411111F0}, // - SPDIF_OUT1
40 {0x21, 0x01211010}, // Port I - HPOUT
Dave Frodinc43bce52014-12-03 08:22:46 -070041 {0xff, 0xffffffff}
42};
43
Dave Frodind6aa7cf2014-11-21 14:57:03 -070044static const CODEC_TBL_LIST CodecTableList[] =
Dave Frodinc43bce52014-12-03 08:22:46 -070045{
Dave Frodind6aa7cf2014-11-21 14:57:03 -070046 {0x10ec0272, (CODEC_ENTRY*)&Alc272_VerbTbl[0]},
Dave Frodinc43bce52014-12-03 08:22:46 -070047 {(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
Elyes HAOUAS2cbfadd2020-01-28 18:11:14 +010082/* Hardware Monitor Fan Control
Dave Frodinc43bce52014-12-03 08:22:46 -070083 * 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.
Dave Frodinc43bce52014-12-03 08:22:46 -070087 */
88static 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();
Dave Frodinc43bce52014-12-03 08:22:46 -070093
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 */
Dave Frodinc43bce52014-12-03 08:22:46 -070097
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 */
Dave Frodinc43bce52014-12-03 08:22:46 -0700101
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600102 LibAmdMemFill(&(FchParams->Imc.EcStruct), 0, sizeof(FCH_EC), FchParams->StdHeader);
Dave Frodinc43bce52014-12-03 08:22:46 -0700103
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;
Dave Frodinc43bce52014-12-03 08:22:46 -0700115
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 = 50; /*AC0 threshold in Celsius */
120 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg3 = 45; /*AC1 threshold in Celsius */
121 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg4 = 40; /*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;
Dave Frodinc43bce52014-12-03 08:22:46 -0700129
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 = 100; /* AL0 percentage */
134 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg3 = 99; /* AL1 percentage */
135 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg4 = 98; /* 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 */
Dave Frodinc43bce52014-12-03 08:22:46 -0700141
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600142 FchParams->Imc.EcStruct.IMCFUNSupportBitMap = 0x111;//BIT0 | BIT4 |BIT8;
Dave Frodinc43bce52014-12-03 08:22:46 -0700143
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 }
Dave Frodinc43bce52014-12-03 08:22:46 -0700155}
156
Kyösti Mälkki74e854c2017-03-05 14:21:39 +0200157void board_FCH_InitReset(struct sysinfo *cb_NA, FCH_RESET_DATA_BLOCK *FchParams_reset)
Dave Frodinc43bce52014-12-03 08:22:46 -0700158{
Kyösti Mälkki74e854c2017-03-05 14:21:39 +0200159}
Dave Frodinc43bce52014-12-03 08:22:46 -0700160
Kyösti Mälkki74e854c2017-03-05 14:21:39 +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 *)(&CodecTableList[0]);
Dave Frodinc43bce52014-12-03 08:22:46 -0700165
Kyösti Mälkki74e854c2017-03-05 14:21:39 +0200166 FchParams_env->Imc.ImcEnable = FALSE;
167 FchParams_env->Hwm.HwMonitorEnable = FALSE;
168 FchParams_env->Hwm.HwmFchtsiAutoPoll = FALSE;/* 1 enable, 0 disable TSI Auto Polling */
Dave Frodinc43bce52014-12-03 08:22:46 -0700169
Kyösti Mälkki74e854c2017-03-05 14:21:39 +0200170 /* Fan Control */
171 oem_fan_control(FchParams_env);
Dave Frodinc43bce52014-12-03 08:22:46 -0700172}