blob: 151d882557054e17e9675bb6e4a777d82bf77dab [file] [log] [blame]
Frank Vibrans2b4c8312011-02-14 18:30:54 +00001/*
2 *****************************************************************************
3 *
4 * Copyright (c) 2011, Advanced Micro Devices, Inc.
5 * All rights reserved.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +10006 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +00007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100014 * * Neither the name of Advanced Micro Devices, Inc. nor the names of
15 * its contributors may be used to endorse or promote products derived
Frank Vibrans2b4c8312011-02-14 18:30:54 +000016 * from this software without specific prior written permission.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100017 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Edward O'Callaghanef5981b2014-07-06 19:20:52 +100028 *
Frank Vibrans2b4c8312011-02-14 18:30:54 +000029 * ***************************************************************************
30 *
31 */
32
33
34#include "SBPLATFORM.h"
35#include "ECfan.h"
36/**
37 * Table for Function Number
38 *
39 *
40 *
41 *
42 */
Elyes HAOUASad1456f2019-06-22 09:52:12 +020043static const UINT8 FunctionNumber[] =
Frank Vibrans2b4c8312011-02-14 18:30:54 +000044{
45 Fun_81,
46 Fun_83,
47 Fun_85,
48 Fun_89,
49};
50
51/**
52 * Table for Max Thermal Zone
53 *
54 *
55 *
56 *
57 */
Elyes HAOUASad1456f2019-06-22 09:52:12 +020058static const UINT8 MaxZone[] =
Frank Vibrans2b4c8312011-02-14 18:30:54 +000059{
60 4,
61 4,
62 4,
63 4,
64};
65
66/**
67 * Table for Max Register
68 *
69 *
70 *
71 *
72 */
Elyes HAOUASad1456f2019-06-22 09:52:12 +020073static const UINT8 MaxRegister[] =
Frank Vibrans2b4c8312011-02-14 18:30:54 +000074{
75 MSG_REG9,
76 MSG_REGB,
77 MSG_REG9,
78 MSG_REGA,
79};
80
81/*-------------------------------------------------------------------------------
82;Procedure: IsZoneFuncEnable
83;
84;Description: This routine will check every zone support function with BitMap from user define
85;
86;
87;Exit: None
88;
89;Modified: None
90;
91;-----------------------------------------------------------------------------
92*/
93BOOLEAN
94IsZoneFuncEnable (
95 UINT16 Flag,
96 UINT8 func,
97 UINT8 Zone
98)
99{
100 return (BOOLEAN)(((Flag >> (func *4)) & 0xF) & ((UINT8 )1 << Zone));
101}
102
103/*-------------------------------------------------------------------------------
104;Procedure: sbECfancontrolservice
105;
106;Description: This routine service EC fan policy
107;
108;
109;Exit: None
110;
111;Modified: None
112;
113;-----------------------------------------------------------------------------
114*/
115VOID
116sbECfancontrolservice (
117 IN AMDSBCFG* pConfig
118 )
119{
120 UINT8 ZoneNum;
121 UINT8 FunNum;
122 UINT8 RegNum;
123 UINT8 * CurPoint;
124 UINT8 FunIndex;
125 BOOLEAN IsSendEcMsg;
126
127 CurPoint = &pConfig->Pecstruct.MSGFun81zone0MSGREG0 + MaxZone[0] * (MaxRegister[0] - MSG_REG0 + 1);
128 for ( FunIndex = 1; FunIndex <= 3; FunIndex++ ) {
129 FunNum = FunctionNumber[FunIndex];
130 for ( ZoneNum = 0; ZoneNum < MaxZone[FunIndex]; ZoneNum++ ) {
131 IsSendEcMsg = IsZoneFuncEnable (pConfig->Pecstruct.IMCFUNSupportBitMap, FunIndex, ZoneNum);
132 for ( RegNum = MSG_REG0; RegNum <= MaxRegister[FunIndex]; RegNum++ ) {
133 if (IsSendEcMsg) {
134 WriteECmsg (RegNum, AccWidthUint8, CurPoint); //
135 }
136 CurPoint += 1;
137 }
138 if (IsSendEcMsg) {
139 WriteECmsg (MSG_SYS_TO_IMC, AccWidthUint8, &FunNum); // function number
140 WaitForEcLDN9MailboxCmdAck ();
141 }
142 }
143 }
144 CurPoint = &pConfig->Pecstruct.MSGFun81zone0MSGREG0;
145 for ( FunIndex = 0; FunIndex <= 0; FunIndex++ ) {
146 FunNum = FunctionNumber[FunIndex];
147 for ( ZoneNum = 0; ZoneNum < MaxZone[FunIndex]; ZoneNum++ ) {
148 IsSendEcMsg = IsZoneFuncEnable (pConfig->Pecstruct.IMCFUNSupportBitMap, FunIndex, ZoneNum);
149 for ( RegNum = MSG_REG0; RegNum <= MaxRegister[FunIndex]; RegNum++ ) {
150 if (IsSendEcMsg) {
151 WriteECmsg (RegNum, AccWidthUint8, CurPoint); //
152 }
153 CurPoint += 1;
154 }
155 if (IsSendEcMsg) {
156 WriteECmsg (MSG_SYS_TO_IMC, AccWidthUint8, &FunNum); // function number
157 WaitForEcLDN9MailboxCmdAck ();
158 }
159 }
160 }
161}
162
163/*-------------------------------------------------------------------------------
164;Procedure: SBIMCFanInitializeS3
165;
166;Description: This routine initialize IMC fan when S3 resume
167;
168;
169;Exit: None
170;
171;Modified: None
172;
173;-----------------------------------------------------------------------------
174*/
175VOID
176SBIMCFanInitializeS3 (VOID)
177{
178 UINT8 dbPortStatus,Value80,Value82,Value83,Value84;
179
180 getChipSysMode (&dbPortStatus);
181 if ((dbPortStatus & ChipSysEcEnable) != 0) {
182 Value80 = 0x98;
183 Value82 = 0x00;
184 Value83 = 0x02;
185 Value84 = 0x00;
186
187 // Clear MSG_REG0 to receive acknowledge byte
188 WriteECmsg (MSG_REG0, AccWidthUint8, &Value82);
Edward O'Callaghanef5981b2014-07-06 19:20:52 +1000189
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000190 // Set MSG_REG1
191 // 0x02 - Notify IMC that the system is waken from any sleep state
192 WriteECmsg (MSG_REG1, AccWidthUint8, &Value83);
Edward O'Callaghanef5981b2014-07-06 19:20:52 +1000193
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000194 // Set timeout counter value to 00 which disables watchdog timer
195 WriteECmsg (MSG_REG2, AccWidthUint8, &Value84);
Edward O'Callaghanef5981b2014-07-06 19:20:52 +1000196
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000197 // Write mailbox function number to kick off the command
Edward O'Callaghanef5981b2014-07-06 19:20:52 +1000198 // 0x98 - IMC System Sleep and Wake Services
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000199 WriteECmsg (MSG_SYS_TO_IMC, AccWidthUint8, &Value80);
Edward O'Callaghanef5981b2014-07-06 19:20:52 +1000200
Frank Vibrans2b4c8312011-02-14 18:30:54 +0000201 // Read acknowledge byte to make sure function is executed properly
202 WaitForEcLDN9MailboxCmdAck ();
203 }
204}