Angel Pons | 2dfba37 | 2020-04-03 01:21:55 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 2 | |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 3 | #include <AGESA.h> |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 4 | #include <northbridge/amd/agesa/BiosCallOuts.h> |
Kyösti Mälkki | 74e854c | 2017-03-05 14:21:39 +0200 | [diff] [blame] | 5 | #include <northbridge/amd/agesa/state_machine.h> |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 6 | #include <FchPlatform.h> |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 7 | |
Elyes HAOUAS | 28b38cd | 2019-03-18 11:30:08 +0100 | [diff] [blame] | 8 | #include "imc.h" |
| 9 | |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 10 | const BIOS_CALLOUT_STRUCT BiosCallouts[] = |
| 11 | { |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 12 | {AGESA_DO_RESET, agesa_Reset }, |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 13 | {AGESA_READ_SPD, agesa_ReadSpd_from_cbfs }, |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 14 | {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 Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 19 | {AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage } |
| 20 | }; |
| 21 | const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts); |
| 22 | |
| 23 | /** |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 24 | * ALC272 Verb Table |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 25 | */ |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 26 | const CODEC_ENTRY Alc272_VerbTbl[] = { |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 27 | {0x11, 0x411111F0}, // - SPDIF_OUT2 |
| 28 | {0x12, 0x411111F0}, // - DMIC_1/2 |
| 29 | {0x13, 0x411111F0}, // - DMIC_3/4 |
| 30 | {0x14, 0x411111F0}, // Port D - LOUT1 |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 31 | {0x15, 0x01011050}, // Port A - LOUT2 Explorer 2x DAC |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 32 | {0x16, 0x411111F0}, // |
| 33 | {0x17, 0x411111F0}, // Port H - MONO |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 34 | {0x18, 0x01a11840}, // Port B - MIC1 |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 35 | {0x19, 0x411111F0}, // Port F - MIC2 |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 36 | {0x1a, 0x01811030}, // Port C - LINE1 |
| 37 | {0x1b, 0x01811020}, // Port E - LINE2 Explorer 2x ADC |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 38 | {0x1d, 0x40130605}, // - PCBEEP |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 39 | {0x1e, 0x411111F0}, // - SPDIF_OUT1 |
| 40 | {0x21, 0x01211010}, // Port I - HPOUT |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 41 | {0xff, 0xffffffff} |
| 42 | }; |
| 43 | |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 44 | static const CODEC_TBL_LIST CodecTableList[] = |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 45 | { |
Dave Frodin | d6aa7cf | 2014-11-21 14:57:03 -0700 | [diff] [blame] | 46 | {0x10ec0272, (CODEC_ENTRY*)&Alc272_VerbTbl[0]}, |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 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 | |
Elyes HAOUAS | 2cbfadd | 2020-01-28 18:11:14 +0100 | [diff] [blame] | 82 | /* Hardware Monitor Fan Control |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 83 | * Hardware limitation: |
Elyes HAOUAS | 2cbfadd | 2020-01-28 18:11:14 +0100 | [diff] [blame] | 84 | * 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 Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 87 | */ |
| 88 | static void oem_fan_control(FCH_DATA_BLOCK *FchParams) |
| 89 | { |
Elyes HAOUAS | 2cbfadd | 2020-01-28 18:11:14 +0100 | [diff] [blame] | 90 | /* Enable IMC fan control, the recommended way */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 91 | if (CONFIG(HUDSON_IMC_FWM)) { |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 92 | imc_reg_init(); |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 93 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 94 | /* 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 Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 97 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 98 | FchParams->Imc.ImcEnable = TRUE; |
| 99 | FchParams->Hwm.HwmControl = 1; /* 1 IMC, 0 HWM */ |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 100 | FchParams->Imc.ImcEnableOverWrite = 1; /* 2 disable IMC, 1 enable IMC, 0 following hw strap setting */ |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 101 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 102 | LibAmdMemFill(&(FchParams->Imc.EcStruct), 0, sizeof(FCH_EC), FchParams->StdHeader); |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 103 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 104 | /* 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 HAOUAS | 73be5f7 | 2019-12-05 17:18:15 +0100 | [diff] [blame] | 113 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg8 = 0x01; /* PWM stepping rate in unit of PWM level percentage */ |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 114 | FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg9 = 0x00; |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 115 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 116 | /* 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 Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 129 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 130 | /* 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 Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 141 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 142 | FchParams->Imc.EcStruct.IMCFUNSupportBitMap = 0x111;//BIT0 | BIT4 |BIT8; |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 143 | |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 144 | /* NOTE: |
Elyes HAOUAS | 2cbfadd | 2020-01-28 18:11:14 +0100 | [diff] [blame] | 145 | * 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 Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 148 | */ |
| 149 | } else { |
Elyes HAOUAS | 2cbfadd | 2020-01-28 18:11:14 +0100 | [diff] [blame] | 150 | /* HWM fan control, the way not recommended */ |
Marshall Dawson | 6dd620b | 2017-08-16 18:04:06 -0600 | [diff] [blame] | 151 | FchParams->Imc.ImcEnable = FALSE; |
| 152 | FchParams->Hwm.HwMonitorEnable = TRUE; |
| 153 | FchParams->Hwm.HwmFchtsiAutoPoll = TRUE;/* 1 enable, 0 disable TSI Auto Polling */ |
| 154 | } |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Kyösti Mälkki | 74e854c | 2017-03-05 14:21:39 +0200 | [diff] [blame] | 157 | void board_FCH_InitReset(struct sysinfo *cb_NA, FCH_RESET_DATA_BLOCK *FchParams_reset) |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 158 | { |
Kyösti Mälkki | 74e854c | 2017-03-05 14:21:39 +0200 | [diff] [blame] | 159 | } |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 160 | |
Kyösti Mälkki | 74e854c | 2017-03-05 14:21:39 +0200 | [diff] [blame] | 161 | void 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 Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 165 | |
Kyösti Mälkki | 74e854c | 2017-03-05 14:21:39 +0200 | [diff] [blame] | 166 | 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 Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 169 | |
Kyösti Mälkki | 74e854c | 2017-03-05 14:21:39 +0200 | [diff] [blame] | 170 | /* Fan Control */ |
| 171 | oem_fan_control(FchParams_env); |
Dave Frodin | c43bce5 | 2014-12-03 08:22:46 -0700 | [diff] [blame] | 172 | } |