0b198c863e3f5d6b1d7aec4e04ae63ee56450447
[coreboot.git] / src / vendorcode / amd / cimx / sb800 / ECfanc.c
1 /*\r
2  *****************************************************************************\r
3  *\r
4  * This file is part of the coreboot project.\r
5  *\r
6  * Copyright (C) 2010 Advanced Micro Devices, Inc.\r
7  *\r
8  * This program is free software; you can redistribute it and/or modify\r
9  * it under the terms of the GNU General Public License as published by\r
10  * the Free Software Foundation; version 2 of the License.\r
11  *\r
12  * This program is distributed in the hope that it will be useful,\r
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15  * GNU General Public License for more details.\r
16  *\r
17  * You should have received a copy of the GNU General Public License\r
18  * along with this program; if not, write to the Free Software\r
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA\r
20  * ***************************************************************************\r
21  *\r
22  */\r
23 \r
24 \r
25 #include "SBPLATFORM.h"\r
26 #include "ECfan.h"\r
27 /**\r
28  * Table for Function Number\r
29  *\r
30  *\r
31  *\r
32  *\r
33  */\r
34 UINT8 FunctionNumber[] =\r
35 {\r
36   Fun_81,\r
37   Fun_83,\r
38   Fun_85,\r
39   Fun_89,\r
40 };\r
41 \r
42 /**\r
43  * Table for Max Thermal Zone\r
44  *\r
45  *\r
46  *\r
47  *\r
48  */\r
49 UINT8 MaxZone[] =\r
50 {\r
51   4,\r
52   4,\r
53   4,\r
54   4,\r
55 };\r
56 \r
57 /**\r
58  * Table for Max Register\r
59  *\r
60  *\r
61  *\r
62  *\r
63  */\r
64 UINT8 MaxRegister[] =\r
65 {\r
66   MSG_REG9,\r
67   MSG_REGB,\r
68   MSG_REG9,\r
69   MSG_REGA,\r
70 };\r
71 \r
72 /*-------------------------------------------------------------------------------\r
73 ;Procedure:  IsZoneFuncEnable\r
74 ;\r
75 ;Description:  This routine will check every zone support function with BitMap from user define\r
76 ;\r
77 ;\r
78 ;Exit:  None\r
79 ;\r
80 ;Modified:  None\r
81 ;\r
82 ;-----------------------------------------------------------------------------\r
83 */\r
84 BOOLEAN\r
85 IsZoneFuncEnable (\r
86   UINT16 Flag,\r
87   UINT8  func,\r
88   UINT8  Zone\r
89 )\r
90 {\r
91   return (BOOLEAN)(((Flag >> (func *4)) & 0xF) & ((UINT8        )1 << Zone));\r
92 }\r
93 \r
94 /*-------------------------------------------------------------------------------\r
95 ;Procedure:  sbECfancontrolservice\r
96 ;\r
97 ;Description:  This routine service EC fan policy\r
98 ;\r
99 ;\r
100 ;Exit:  None\r
101 ;\r
102 ;Modified:  None\r
103 ;\r
104 ;-----------------------------------------------------------------------------\r
105 */\r
106 VOID\r
107 sbECfancontrolservice (\r
108   IN     AMDSBCFG* pConfig\r
109   )\r
110 {\r
111   UINT8 ZoneNum;\r
112   UINT8 FunNum;\r
113   UINT8 RegNum;\r
114   UINT8 * CurPoint;\r
115   UINT8 FunIndex;\r
116   BOOLEAN IsSendEcMsg;\r
117 \r
118   CurPoint = &pConfig->Pecstruct.MSGFun81zone0MSGREG0 + MaxZone[0] * (MaxRegister[0] - MSG_REG0 + 1);\r
119   for ( FunIndex = 1; FunIndex <= 3; FunIndex++ ) {\r
120     FunNum = FunctionNumber[FunIndex];\r
121     for ( ZoneNum = 0; ZoneNum < MaxZone[FunIndex]; ZoneNum++ ) {\r
122       IsSendEcMsg = IsZoneFuncEnable (pConfig->Pecstruct.IMCFUNSupportBitMap, FunIndex, ZoneNum);\r
123       for ( RegNum = MSG_REG0; RegNum <= MaxRegister[FunIndex]; RegNum++ ) {\r
124         if (IsSendEcMsg) {\r
125           WriteECmsg (RegNum, AccWidthUint8, CurPoint); //\r
126         }\r
127         CurPoint += 1;\r
128       }\r
129       if (IsSendEcMsg) {\r
130         WriteECmsg (MSG_SYS_TO_IMC, AccWidthUint8, &FunNum); // function number\r
131         WaitForEcLDN9MailboxCmdAck ();\r
132       }\r
133     }\r
134   }\r
135   CurPoint = &pConfig->Pecstruct.MSGFun81zone0MSGREG0;\r
136   for ( FunIndex = 0; FunIndex <= 0; FunIndex++ ) {\r
137     FunNum = FunctionNumber[FunIndex];\r
138     for ( ZoneNum = 0; ZoneNum < MaxZone[FunIndex]; ZoneNum++ ) {\r
139       IsSendEcMsg = IsZoneFuncEnable (pConfig->Pecstruct.IMCFUNSupportBitMap, FunIndex, ZoneNum);\r
140       for ( RegNum = MSG_REG0; RegNum <= MaxRegister[FunIndex]; RegNum++ ) {\r
141         if (IsSendEcMsg) {\r
142           WriteECmsg (RegNum, AccWidthUint8, CurPoint); //\r
143         }\r
144         CurPoint += 1;\r
145       }\r
146       if (IsSendEcMsg) {\r
147         WriteECmsg (MSG_SYS_TO_IMC, AccWidthUint8, &FunNum); // function number\r
148         WaitForEcLDN9MailboxCmdAck ();\r
149       }\r
150     }\r
151   }\r
152 }\r
153 \r
154 /*-------------------------------------------------------------------------------\r
155 ;Procedure:  SBIMCFanInitializeS3\r
156 ;\r
157 ;Description:  This routine initialize IMC fan when S3 resume\r
158 ;\r
159 ;\r
160 ;Exit:  None\r
161 ;\r
162 ;Modified:  None\r
163 ;\r
164 ;-----------------------------------------------------------------------------\r
165 */\r
166 VOID\r
167 SBIMCFanInitializeS3 (VOID)\r
168 {\r
169     UINT8 dbPortStatus,Value80,Value82,Value83,Value84;\r
170 \r
171     getChipSysMode (&dbPortStatus);\r
172     if ((dbPortStatus & ChipSysEcEnable) != 0) {\r
173         Value80 = 0x98;\r
174         Value82 = 0x00;\r
175         Value83 = 0x02;\r
176         Value84 = 0x00;\r
177 \r
178         // Clear MSG_REG0 to receive acknowledge byte\r
179         WriteECmsg (MSG_REG0, AccWidthUint8, &Value82);\r
180         \r
181         // Set MSG_REG1\r
182         //   0x02 -  Notify IMC that the system is waken from any sleep state\r
183         WriteECmsg (MSG_REG1, AccWidthUint8, &Value83);\r
184         \r
185         // Set timeout counter value to 00 which disables watchdog timer\r
186         WriteECmsg (MSG_REG2, AccWidthUint8, &Value84);\r
187         \r
188         // Write mailbox function number to kick off the command\r
189         //   0x98 -  IMC System Sleep and Wake Services        \r
190         WriteECmsg (MSG_SYS_TO_IMC, AccWidthUint8, &Value80);\r
191         \r
192         // Read acknowledge byte to make sure function is executed properly\r
193         WaitForEcLDN9MailboxCmdAck ();\r
194     }\r
195 }\r