blob: 95b8e41840f93cd08ce3560d3522ba9a679bc2ca [file] [log] [blame]
zbao323a9232012-07-19 16:39:01 +08001/*
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.
zbao323a9232012-07-19 16:39:01 +080014 */
15
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020016#include <AGESA.h>
Kyösti Mälkki26f297e2014-05-26 11:27:54 +030017#include <northbridge/amd/agesa/BiosCallOuts.h>
Kyösti Mälkki46379c72017-03-04 07:50:38 +020018#include <northbridge/amd/agesa/state_machine.h>
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +020019#include <FchPlatform.h>
20#include <cbfs.h>
WANG Siyuand5813532013-12-02 10:48:26 +080021#include "imc.h"
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030022#include <stdlib.h>
zbao323a9232012-07-19 16:39:01 +080023
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030024const BIOS_CALLOUT_STRUCT BiosCallouts[] =
zbao323a9232012-07-19 16:39:01 +080025{
Kyösti Mälkki83cc3b02014-05-04 23:13:08 +030026 {AGESA_DO_RESET, agesa_Reset },
Kyösti Mälkkic5cc9f22014-10-17 22:33:22 +030027 {AGESA_READ_SPD, agesa_ReadSpd },
Kyösti Mälkki83cc3b02014-05-04 23:13:08 +030028 {AGESA_READ_SPD_RECOVERY, agesa_NoopUnsupported },
29 {AGESA_RUNFUNC_ONAP, agesa_RunFuncOnAp },
30 {AGESA_GET_IDS_INIT_DATA, agesa_EmptyIdsInitData },
31 {AGESA_HOOKBEFORE_DQS_TRAINING, agesa_NoopSuccess },
32 {AGESA_HOOKBEFORE_EXIT_SELF_REF, agesa_NoopSuccess },
Kyösti Mälkkicb989f22014-05-04 23:13:08 +030033 {AGESA_GNB_GFX_GET_VBIOS_IMAGE, agesa_GfxGetVbiosImage }
zbao323a9232012-07-19 16:39:01 +080034};
Kyösti Mälkki6025efa2014-05-05 13:20:56 +030035const int BiosCalloutsLen = ARRAY_SIZE(BiosCallouts);
zbao323a9232012-07-19 16:39:01 +080036
zbao323a9232012-07-19 16:39:01 +080037/**
38 * AMD Parmer Platform ALC272 Verb Table
39 */
Paul Menzel3a145712013-05-04 18:21:17 +020040static const CODEC_ENTRY Parmer_Alc272_VerbTbl[] = {
zbao323a9232012-07-19 16:39:01 +080041 {0x11, 0x411111F0},
42 {0x12, 0x411111F0},
43 {0x13, 0x411111F0},
44 {0x14, 0x411111F0},
45 {0x15, 0x411111F0},
46 {0x16, 0x411111F0},
47 {0x17, 0x411111F0},
zbaodcc17ae2012-07-24 19:03:03 +080048 {0x18, 0x01a19840},
zbao323a9232012-07-19 16:39:01 +080049 {0x19, 0x411111F0},
zbaodcc17ae2012-07-24 19:03:03 +080050 {0x1a, 0x01813030},
zbao323a9232012-07-19 16:39:01 +080051 {0x1b, 0x411111F0},
zbaodcc17ae2012-07-24 19:03:03 +080052 {0x1d, 0x40130605},
53 {0x1e, 0x01441120},
54 {0x21, 0x01211010},
zbao323a9232012-07-19 16:39:01 +080055 {0xff, 0xffffffff}
56};
57
Paul Menzel1ae7d472013-05-04 18:41:54 +020058static const CODEC_TBL_LIST CodecTableList[] =
zbao323a9232012-07-19 16:39:01 +080059{
zbaodcc17ae2012-07-24 19:03:03 +080060 {0x10ec0272, (CODEC_ENTRY*)&Parmer_Alc272_VerbTbl[0]},
zbao323a9232012-07-19 16:39:01 +080061 {(UINT32)0x0FFFFFFFF, (CODEC_ENTRY*)0x0FFFFFFFFUL}
62};
63
64#define FAN_INPUT_INTERNAL_DIODE 0
65#define FAN_INPUT_TEMP0 1
66#define FAN_INPUT_TEMP1 2
67#define FAN_INPUT_TEMP2 3
68#define FAN_INPUT_TEMP3 4
69#define FAN_INPUT_TEMP0_FILTER 5
70#define FAN_INPUT_ZERO 6
71#define FAN_INPUT_DISABLED 7
72
73#define FAN_AUTOMODE (1 << 0)
74#define FAN_LINEARMODE (1 << 1)
75#define FAN_STEPMODE ~(1 << 1)
76#define FAN_POLARITY_HIGH (1 << 2)
77#define FAN_POLARITY_LOW ~(1 << 2)
78
79/* Normally, 4-wire fan runs at 25KHz and 3-wire fan runs at 100Hz */
80#define FREQ_28KHZ 0x0
81#define FREQ_25KHZ 0x1
82#define FREQ_23KHZ 0x2
83#define FREQ_21KHZ 0x3
84#define FREQ_29KHZ 0x4
85#define FREQ_18KHZ 0x5
86#define FREQ_100HZ 0xF7
87#define FREQ_87HZ 0xF8
88#define FREQ_58HZ 0xF9
89#define FREQ_44HZ 0xFA
90#define FREQ_35HZ 0xFB
91#define FREQ_29HZ 0xFC
92#define FREQ_22HZ 0xFD
93#define FREQ_14HZ 0xFE
94#define FREQ_11HZ 0xFF
95
96/* Parmer Hardware Monitor Fan Control
97 * Hardware limitation:
98 * HWM failed to read the input temperture vi I2C,
99 * if other software switch the I2C switch by mistake or intention.
100 * We recommend to using IMC to control Fans, instead of HWM.
101 */
102static void oem_fan_control(FCH_DATA_BLOCK *FchParams)
103{
zbao323a9232012-07-19 16:39:01 +0800104 /* Enable IMC fan control. the recommand way */
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600105 if (IS_ENABLED(CONFIG_HUDSON_IMC_FWM)) {
106 imc_reg_init();
WANG Siyuand5813532013-12-02 10:48:26 +0800107
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600108 /* HwMonitorEnable = TRUE && HwmFchtsiAutoOpll ==FALSE to call FchECfancontrolservice */
109 FchParams->Hwm.HwMonitorEnable = TRUE;
110 FchParams->Hwm.HwmFchtsiAutoPoll = FALSE;/* 0 disable, 1 enable TSI Auto Polling */
WANG Siyuand5813532013-12-02 10:48:26 +0800111
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600112 FchParams->Imc.ImcEnable = TRUE;
113 FchParams->Hwm.HwmControl = 1; /* 1 IMC, 0 HWM */
Elyes HAOUASa342f392018-10-17 10:56:26 +0200114 FchParams->Imc.ImcEnableOverWrite = 1; /* 2 disable IMC, 1 enable IMC, 0 following hw strap setting */
zbao323a9232012-07-19 16:39:01 +0800115
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600116 LibAmdMemFill(&(FchParams->Imc.EcStruct), 0, sizeof(FCH_EC), FchParams->StdHeader);
zbao323a9232012-07-19 16:39:01 +0800117
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600118 /* Thermal Zone Parameter */
119 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg0 = 0x00;
120 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg1 = 0x00; /* Zone */
121 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg2 = 0x3d; //BIT0 | BIT2 | BIT5;
122 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg3 = 0x0e;//6 | BIT3;
123 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg4 = 0x00;
124 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg5 = 0x54;
125 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg6 = 0x98; /* SMBUS Address for SMBUS based temperature sensor such as SB-TSI and ADM1032 */
126 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg7 = 0x02;
127 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg8 = 0x01; /* PWM steping rate in unit of PWM level percentage */
128 FchParams->Imc.EcStruct.MsgFun81Zone0MsgReg9 = 0x00;
zbao323a9232012-07-19 16:39:01 +0800129
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600130 /* IMC Fan Policy temperature thresholds */
131 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg0 = 0x00;
132 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg1 = 0x00; /* Zone */
133 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg2 = 0x46;///80; /*AC0 threshold in Celsius */
134 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg3 = 0x3c; /*AC1 threshold in Celsius */
135 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg4 = 0x32; /*AC2 threshold in Celsius */
136 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg5 = 0xff; /*AC3 threshold in Celsius, 0xFF is not define */
137 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg6 = 0xff; /*AC4 threshold in Celsius, 0xFF is not define */
138 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg7 = 0xff; /*AC5 threshold in Celsius, 0xFF is not define */
139 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg8 = 0xff; /*AC6 threshold in Celsius, 0xFF is not define */
140 FchParams->Imc.EcStruct.MsgFun83Zone0MsgReg9 = 0xff; /*AC7 lowest threshold in Celsius, 0xFF is not define */
141 FchParams->Imc.EcStruct.MsgFun83Zone0MsgRegA = 0x4b; /*critical threshold* in Celsius, 0xFF is not define */
142 FchParams->Imc.EcStruct.MsgFun83Zone0MsgRegB = 0x00;
zbao323a9232012-07-19 16:39:01 +0800143
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600144 /* IMC Fan Policy PWM Settings */
145 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg0 = 0x00;
146 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg1 = 0x00; /* Zone */
147 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg2 = 0x5a; /* AL0 percentage */
148 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg3 = 0x46; /* AL1 percentage */
149 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg4 = 0x28; /* AL2 percentage */
150 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg5 = 0xff; /* AL3 percentage */
151 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg6 = 0xff; /* AL4 percentage */
152 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg7 = 0xff; /* AL5 percentage */
153 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg8 = 0xff; /* AL6 percentage */
154 FchParams->Imc.EcStruct.MsgFun85Zone0MsgReg9 = 0xff; /* AL7 percentage */
zbao323a9232012-07-19 16:39:01 +0800155
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600156 FchParams->Imc.EcStruct.IMCFUNSupportBitMap = 0x111;//BIT0 | BIT4 |BIT8;
zbao323a9232012-07-19 16:39:01 +0800157
Marshall Dawson6dd620b2017-08-16 18:04:06 -0600158 /* NOTE:
159 * FchInitLateHwm will overwrite the EcStruct with EcDefaultMassege,
160 * AGESA put EcDefaultMassege as global data in ROM, so we can't overwride it.
161 * so we remove it from AGESA code. Please Seee FchInitLateHwm.
162 */
163 } else {
164 /* HWM fan control, the way not recommand */
165 FchParams->Imc.ImcEnable = FALSE;
166 FchParams->Hwm.HwMonitorEnable = TRUE;
167 FchParams->Hwm.HwmFchtsiAutoPoll = TRUE;/* 1 enable, 0 disable TSI Auto Polling */
168 }
zbao323a9232012-07-19 16:39:01 +0800169}
170
Kyösti Mälkki46379c72017-03-04 07:50:38 +0200171void board_FCH_InitReset(struct sysinfo *cb_NA, FCH_RESET_DATA_BLOCK *FchParams_reset)
zbao323a9232012-07-19 16:39:01 +0800172{
Kyösti Mälkki46379c72017-03-04 07:50:38 +0200173 FchParams_reset->LegacyFree = IS_ENABLED(CONFIG_HUDSON_LEGACY_FREE);
174}
zbao323a9232012-07-19 16:39:01 +0800175
Kyösti Mälkki46379c72017-03-04 07:50:38 +0200176void board_FCH_InitEnv(struct sysinfo *cb_NA, FCH_DATA_BLOCK *FchParams_env)
177{
178 /* Azalia Controller OEM Codec Table Pointer */
179 FchParams_env->Azalia.AzaliaOemCodecTablePtr = (CODEC_TBL_LIST *)(&CodecTableList[0]);
zbao323a9232012-07-19 16:39:01 +0800180
Kyösti Mälkki46379c72017-03-04 07:50:38 +0200181 oem_fan_control(FchParams_env);
zbao323a9232012-07-19 16:39:01 +0800182}