1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
|
//*************************************************************************
//*************************************************************************
//** **
//** (C)Copyright 1985-2008, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//*************************************************************************
//*************************************************************************
//
//*************************************************************************
// $Header: /Alaska/BIN/IO/Fintek/F81866/F81866 Board/F81866SmartFan.c 1 7/20/11 4:23a Kasalinyi $Revision:
//
// $Date:
//*************************************************************************
// Revision History
// ----------------
//
//*************************************************************************
//<AMI_FHDR_START>
//
// Name: <F81866SmartFan.c>
//
// Description: This is related to individual Smart Fan functions.
//
//<AMI_FHDR_END>
//*************************************************************************
#include <Efi.h>
#include <Token.h>
#include <AmiLib.h>
#include <Setup.h>
#include <AmiDxeLib.h>
#include <Protocol\BootScriptSave.h>
#define HWM_CONFIG_INDEX F81866_HWM_BASE_ADDRESS+5
#define HWM_CONFIG_DATA F81866_HWM_BASE_ADDRESS+6
SETUP_DATA SetupData;
static EFI_EVENT gEvtReadyToBoot = NULL;
static EFI_GUID gEfiBootScriptSaveGuid = EFI_BOOT_SCRIPT_SAVE_GUID;
typedef struct _DXE_SMF_INIT_DATA{
UINT8 Reg8;
UINT8 AndData8;
UINT8 OrData8;
} DXE_SMF_INIT_DATA;
typedef struct _S3_SAVE_DATA{
UINT8 Bank;
UINT8 Reg8;
} S3_SAVE_DATA;
//----------------------------------------------------------------------------------------------
// smart system fan registers need init AfterActivate. !!!AfterActivate
//----------------------------------------------------------------------------------------------
DXE_SMF_INIT_DATA DXE_FAN1_INIT_TABLE[] = {
{0x96, 0xFC, 0x00},
{0xA2, 0xFF, 0x00},
{0xA3, 0xFF, 0x00},
{0xA6, 0xFF, 0x00},
{0xA7, 0xFF, 0x00},
{0xA8, 0xFF, 0x00},
{0xA9, 0XFF, 0x00},
{0xAB, 0xFF, 0x00},
{0xAC, 0xFF, 0x00},
{0xAD, 0xFF, 0x00},
{0xAE, 0xFF, 0x00},
};
DXE_SMF_INIT_DATA DXE_FAN2_INIT_TABLE[] = {
{0x96, 0xF3, 0x00},
{0xB2, 0xFF, 0x00},
{0xB3, 0xFF, 0x00},
{0xB6, 0xFF, 0x00},
{0xB7, 0xFF, 0x00},
{0xB8, 0xFF, 0x00},
{0xB9, 0XFF, 0x00},
{0xBB, 0xFF, 0x00},
{0xBC, 0xFF, 0x00},
{0xBD, 0xFF, 0x00},
{0xBE, 0xFF, 0x00},
};
DXE_SMF_INIT_DATA DXE_FAN3_INIT_TABLE[] = {
{0x96, 0xCF, 0x00},
{0xC2, 0xFF, 0x00},
{0xC3, 0xFF, 0x00},
{0xC6, 0xFF, 0x00},
{0xC7, 0xFF, 0x00},
{0xC8, 0xFF, 0x00},
{0xC9, 0XFF, 0x00},
{0xCB, 0xFF, 0x00},
{0xCC, 0xFF, 0x00},
{0xCD, 0xFF, 0x00},
{0xCE, 0xFF, 0x00},
};
S3_SAVE_DATA HwmS3SaveRegisterTbl[] = {
// ----------------------
//| Bank | Reg8 |
// ----------------------
{0x00,0x94},
{0x00,0x96},
{0x00,0xA2},
{0x00,0xA3},
{0x00,0xA6},
{0x00,0xA7},
{0x00,0xA8},
{0x00,0xA9},
{0x00,0xAB},
{0x00,0xAC},
{0x00,0xAD},
{0x00,0xAE},
{0x00,0xB2},
{0x00,0xB3},
{0x00,0xB6},
{0x00,0xB7},
{0x00,0xB8},
{0x00,0xB9},
{0x00,0xBB},
{0x00,0xBC},
{0x00,0xBD},
{0x00,0xBE},
{0x00,0xC2},
{0x00,0xC3},
{0x00,0xC6},
{0x00,0xC7},
{0x00,0xC8},
{0x00,0xC9},
{0x00,0xCB},
{0x00,0xCC},
{0x00,0xCD},
{0x00,0xCE},
};
//--------------------------------------------------------------------------
// Definition of smart fan functions
//--------------------------------------------------------------------------
VOID F81866SmartFunction (VOID);
static VOID SmartFanFuncStart(VOID);
static VOID F81866_SMF1_INIT(void);
static VOID F81866_SMF2_INIT(void);
static VOID F81866_SMF3_INIT(void);
static void F81866_SMF_WRITE_CFG(DXE_SMF_INIT_DATA DXE_SMF_MODEx_Table);
static EFI_STATUS HwmCallbackReadyToBoot(
IN EFI_EVENT Event,
IN VOID *Context);
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure: F81866SmartFunction
//
// Description: This function initializes the IT8783 in BDS phase
//
// Input:
// IN EFI_HANDLE ImageHandle
// IN EFI_SYSTEM_TABLE SystemTable
//
// Output: Status
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID F81866SmartFunction (VOID)
{
EFI_STATUS Status = EFI_SUCCESS;
UINTN Size = sizeof(SETUP_DATA);
EFI_GUID SetupGuid = SETUP_GUID;
//Get Setup variable
Status=pRS->GetVariable( L"Setup", &SetupGuid, NULL, &Size, &SetupData);
if(Status != EFI_SUCCESS) return;
//Init the smart fan function
if(SetupData.SmartFanEnable)
SmartFanFuncStart();
}
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure: SmartFanFuncStart
//
// Description: This function start to initialize the smart fan function
//
// Input: NULL
//
//
// Output: NULL
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>
static VOID SmartFanFuncStart(VOID)
{
EFI_STATUS Status;
//--------------------------------------------------------------------------
// Before speed control, program neccessary registers if needed.
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Start to program the smart fan mode
//--------------------------------------------------------------------------
F81866_SMF1_INIT();
F81866_SMF2_INIT();
F81866_SMF3_INIT();
//Create event for boot script
Status = CreateReadyToBootEvent(
TPL_NOTIFY,
HwmCallbackReadyToBoot,
NULL,
&gEvtReadyToBoot
);
ASSERT_EFI_ERROR(Status);
}
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure: F81866_SMF1_INIT
//
// Description: This function do smart fan1 config
//
// Input: NULL
//
//
// Output: NULL
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>
void F81866_SMF1_INIT(VOID)
{
UINT8 i, temp;
switch (SetupData.Fan1SmartFanMode) {
case 0:
DXE_FAN1_INIT_TABLE[0].OrData8 = 0x02;//mode
DXE_FAN1_INIT_TABLE[1].OrData8 = (UINT8)(1500000/SetupData.Fan1Mode0FixedSpeed >> 8);//mode
DXE_FAN1_INIT_TABLE[2].OrData8 = (UINT8)(1500000/SetupData.Fan1Mode0FixedSpeed & 0xFF);//mode
break;
case 1:
DXE_FAN1_INIT_TABLE[0].OrData8 = 0x03;//mode
DXE_FAN1_INIT_TABLE[2].OrData8 = (UINT8)SetupData.Fan1Mode1FixedDuty*0xFF/100;//mode
break;
case 2:
DXE_FAN1_INIT_TABLE[0].OrData8 = 0x00;//mode
DXE_FAN1_INIT_TABLE[3].OrData8 = SetupData.Fan1Mode2AutoRpmT1;
DXE_FAN1_INIT_TABLE[4].OrData8 = SetupData.Fan1Mode2AutoRpmT2;
DXE_FAN1_INIT_TABLE[5].OrData8 = SetupData.Fan1Mode2AutoRpmT3;
DXE_FAN1_INIT_TABLE[6].OrData8 = SetupData.Fan1Mode2AutoRpmT4;
DXE_FAN1_INIT_TABLE[7].OrData8 = (UINT8)((100-SetupData.Fan1Mode2AutoRpmF1)*32/60);
DXE_FAN1_INIT_TABLE[8].OrData8 = (UINT8)((100-SetupData.Fan1Mode2AutoRpmF2)*32/60);
DXE_FAN1_INIT_TABLE[9].OrData8 = (UINT8)((100-SetupData.Fan1Mode2AutoRpmF3)*32/60);
DXE_FAN1_INIT_TABLE[10].OrData8 = (UINT8)((100-SetupData.Fan1Mode2AutoRpmF4)*32/60);
break;
case 3:
DXE_FAN1_INIT_TABLE[0].OrData8 = 0x01;//mode
DXE_FAN1_INIT_TABLE[3].OrData8 = SetupData.Fan1Mode3AutoDutyT1;
DXE_FAN1_INIT_TABLE[4].OrData8 = SetupData.Fan1Mode3AutoDutyT2;
DXE_FAN1_INIT_TABLE[5].OrData8 = SetupData.Fan1Mode3AutoDutyT3;
DXE_FAN1_INIT_TABLE[6].OrData8 = SetupData.Fan1Mode3AutoDutyT4;
DXE_FAN1_INIT_TABLE[7].OrData8 = (UINT8)(SetupData.Fan1Mode3AutoDutyF1*0xFF/100);
DXE_FAN1_INIT_TABLE[8].OrData8 = (UINT8)(SetupData.Fan1Mode3AutoDutyF2*0xFF/100);
DXE_FAN1_INIT_TABLE[9].OrData8 = (UINT8)(SetupData.Fan1Mode3AutoDutyF3*0xFF/100);
DXE_FAN1_INIT_TABLE[10].OrData8 = (UINT8)(SetupData.Fan1Mode3AutoDutyF4*0xFF/100);
break;
default:
break;
}
for(i=0; i<( (sizeof(DXE_FAN1_INIT_TABLE))/(sizeof(DXE_SMF_INIT_DATA)) ); i++) {
IoWrite8(HWM_CONFIG_INDEX, DXE_FAN1_INIT_TABLE[i].Reg8 );
if(DXE_FAN1_INIT_TABLE[i].AndData8 == 0xFF) {
temp = DXE_FAN1_INIT_TABLE[i].OrData8;
} else {
temp = IoRead8(HWM_CONFIG_DATA);
temp &= DXE_FAN1_INIT_TABLE[i].AndData8;
temp |= DXE_FAN1_INIT_TABLE[i].OrData8;
}
IoWrite8(HWM_CONFIG_DATA, temp);
}
}
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure: F81866_SMF2_INIT
//
// Description: This function do smart fan2 config
//
// Input: NULL
//
//
// Output: NULL
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>
void F81866_SMF2_INIT(VOID)
{
UINT8 i, temp;
switch (SetupData.Fan2SmartFanMode) {
case 0:
DXE_FAN2_INIT_TABLE[0].OrData8 = 0x02 << 2;//mode
DXE_FAN2_INIT_TABLE[1].OrData8 = (UINT8)(1500000/SetupData.Fan2Mode0FixedSpeed >> 8);//mode
DXE_FAN2_INIT_TABLE[2].OrData8 = (UINT8)(1500000/SetupData.Fan2Mode0FixedSpeed & 0xFF);//mode
break;
case 1:
DXE_FAN2_INIT_TABLE[0].OrData8 = 0x03 << 2;//mode
DXE_FAN2_INIT_TABLE[2].OrData8 = (UINT8)(SetupData.Fan2Mode1FixedDuty*0xFF/100);//mode
break;
case 2:
DXE_FAN2_INIT_TABLE[0].OrData8 = 0x00 << 2;//mode
DXE_FAN2_INIT_TABLE[3].OrData8 = SetupData.Fan2Mode2AutoRpmT1;
DXE_FAN2_INIT_TABLE[4].OrData8 = SetupData.Fan2Mode2AutoRpmT2;
DXE_FAN2_INIT_TABLE[5].OrData8 = SetupData.Fan2Mode2AutoRpmT3;
DXE_FAN2_INIT_TABLE[6].OrData8 = SetupData.Fan2Mode2AutoRpmT4;
DXE_FAN2_INIT_TABLE[7].OrData8 = (UINT8)((100-SetupData.Fan2Mode2AutoRpmF1)*32/60);
DXE_FAN2_INIT_TABLE[8].OrData8 = (UINT8)((100-SetupData.Fan2Mode2AutoRpmF2)*32/60);
DXE_FAN2_INIT_TABLE[9].OrData8 = (UINT8)((100-SetupData.Fan2Mode2AutoRpmF3)*32/60);
DXE_FAN2_INIT_TABLE[10].OrData8 = (UINT8)((100-SetupData.Fan2Mode2AutoRpmF4)*32/60);
break;
case 3:
DXE_FAN2_INIT_TABLE[0].OrData8 = 0x01 << 2;//mode
DXE_FAN2_INIT_TABLE[3].OrData8 = SetupData.Fan2Mode3AutoDutyT1;
DXE_FAN2_INIT_TABLE[4].OrData8 = SetupData.Fan2Mode3AutoDutyT2;
DXE_FAN2_INIT_TABLE[5].OrData8 = SetupData.Fan2Mode3AutoDutyT3;
DXE_FAN2_INIT_TABLE[6].OrData8 = SetupData.Fan2Mode3AutoDutyT4;
DXE_FAN2_INIT_TABLE[7].OrData8 = (UINT8)(SetupData.Fan2Mode3AutoDutyF1*0xFF/100);
DXE_FAN2_INIT_TABLE[8].OrData8 = (UINT8)(SetupData.Fan2Mode3AutoDutyF2*0xFF/100);
DXE_FAN2_INIT_TABLE[9].OrData8 = (UINT8)(SetupData.Fan2Mode3AutoDutyF3*0xFF/100);
DXE_FAN2_INIT_TABLE[10].OrData8 = (UINT8)(SetupData.Fan2Mode3AutoDutyF4*0xFF/100);
break;
default:
break;
}
for(i=0; i<( (sizeof(DXE_FAN2_INIT_TABLE))/(sizeof(DXE_SMF_INIT_DATA)) ); i++) {
IoWrite8(HWM_CONFIG_INDEX, DXE_FAN2_INIT_TABLE[i].Reg8 );
if(DXE_FAN2_INIT_TABLE[i].AndData8 == 0xFF) {
temp = DXE_FAN2_INIT_TABLE[i].OrData8;
} else {
temp = IoRead8(HWM_CONFIG_DATA);
temp &= DXE_FAN2_INIT_TABLE[i].AndData8;
temp |= DXE_FAN2_INIT_TABLE[i].OrData8;
}
IoWrite8(HWM_CONFIG_DATA, temp);
}
}
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure: F81866_SMF3_INIT
//
// Description: This function do smart fan3 config
//
// Input: NULL
//
//
// Output: NULL
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>
void F81866_SMF3_INIT(VOID)
{
UINT8 i, temp;
switch (SetupData.Fan3SmartFanMode) {
case 0:
DXE_FAN3_INIT_TABLE[0].OrData8 = 0x02 << 4;//mode
DXE_FAN3_INIT_TABLE[1].OrData8 = (UINT8)(1500000/SetupData.Fan3Mode0FixedSpeed >> 8);//mode
DXE_FAN3_INIT_TABLE[2].OrData8 = (UINT8)(1500000/SetupData.Fan3Mode0FixedSpeed & 0xFF);//mode
break;
case 1:
DXE_FAN3_INIT_TABLE[0].OrData8 = 0x03 << 4;//mode
DXE_FAN3_INIT_TABLE[2].OrData8 = (UINT8)(SetupData.Fan3Mode1FixedDuty*0xFF/100);//mode
break;
case 2:
DXE_FAN3_INIT_TABLE[0].OrData8 = 0x00 << 4;//mode
DXE_FAN3_INIT_TABLE[3].OrData8 = SetupData.Fan3Mode2AutoRpmT1;
DXE_FAN3_INIT_TABLE[4].OrData8 = SetupData.Fan3Mode2AutoRpmT2;
DXE_FAN3_INIT_TABLE[5].OrData8 = SetupData.Fan3Mode2AutoRpmT3;
DXE_FAN3_INIT_TABLE[6].OrData8 = SetupData.Fan3Mode2AutoRpmT4;
DXE_FAN3_INIT_TABLE[7].OrData8 = (UINT8)((100-SetupData.Fan3Mode2AutoRpmF1)*32/60);
DXE_FAN3_INIT_TABLE[8].OrData8 = (UINT8)((100-SetupData.Fan3Mode2AutoRpmF2)*32/60);
DXE_FAN3_INIT_TABLE[9].OrData8 = (UINT8)((100-SetupData.Fan3Mode2AutoRpmF3)*32/60);
DXE_FAN3_INIT_TABLE[10].OrData8 = (UINT8)((100-SetupData.Fan3Mode2AutoRpmF4)*32/60);
break;
case 3:
DXE_FAN3_INIT_TABLE[0].OrData8 = 0x01 << 4;//mode
DXE_FAN3_INIT_TABLE[3].OrData8 = SetupData.Fan3Mode3AutoDutyT1;
DXE_FAN3_INIT_TABLE[4].OrData8 = SetupData.Fan3Mode3AutoDutyT2;
DXE_FAN3_INIT_TABLE[5].OrData8 = SetupData.Fan3Mode3AutoDutyT3;
DXE_FAN3_INIT_TABLE[6].OrData8 = SetupData.Fan3Mode3AutoDutyT4;
DXE_FAN3_INIT_TABLE[7].OrData8 = (UINT8)(SetupData.Fan3Mode3AutoDutyF1*0xFF/100);
DXE_FAN3_INIT_TABLE[8].OrData8 = (UINT8)(SetupData.Fan3Mode3AutoDutyF2*0xFF/100);
DXE_FAN3_INIT_TABLE[9].OrData8 = (UINT8)(SetupData.Fan3Mode3AutoDutyF3*0xFF/100);
DXE_FAN3_INIT_TABLE[10].OrData8 = (UINT8)(SetupData.Fan3Mode3AutoDutyF4*0xFF/100);
break;
default:
break;
}
for(i=0; i<( (sizeof(DXE_FAN3_INIT_TABLE))/(sizeof(DXE_SMF_INIT_DATA)) ); i++) {
IoWrite8(HWM_CONFIG_INDEX, DXE_FAN3_INIT_TABLE[i].Reg8 );
if(DXE_FAN3_INIT_TABLE[i].AndData8 == 0xFF) {
temp = DXE_FAN3_INIT_TABLE[i].OrData8;
} else {
temp = IoRead8(HWM_CONFIG_DATA);
temp &= DXE_FAN3_INIT_TABLE[i].AndData8;
temp |= DXE_FAN3_INIT_TABLE[i].OrData8;
}
IoWrite8(HWM_CONFIG_DATA, temp);
}
}
//<AMI_PHDR_START>
//---------------------------------------------------------------------------
// Procedure: HwmCallbackReadyToBoot
//
// Description: This function save registers for S3
//
// Input: NULL
//
//
// Output: NULL
//
//---------------------------------------------------------------------------
//<AMI_PHDR_END>
static EFI_STATUS HwmCallbackReadyToBoot(
IN EFI_EVENT Event,
IN VOID *Context)
{
EFI_BOOT_SCRIPT_SAVE_PROTOCOL *bss;
EFI_STATUS Status;
UINT8 bank_reg,bank,r,v,i;
Status = pBS->LocateProtocol(&gEfiBootScriptSaveGuid,NULL,&bss);
if(EFI_ERROR(Status)) return Status;
// record the register from table into boot script
for (i=0; i < ((sizeof(HwmS3SaveRegisterTbl))/(sizeof(S3_SAVE_DATA))); i++) {
bank = HwmS3SaveRegisterTbl[i].Bank;
bank_reg = 0x4e;
r = HwmS3SaveRegisterTbl[i].Reg8;
//select bank
IoWrite8(HWM_CONFIG_INDEX, bank_reg);
IoWrite8(HWM_CONFIG_DATA, bank);
//select register to read actual data
IoWrite8(HWM_CONFIG_INDEX, r);
v = IoRead8(HWM_CONFIG_DATA);
//save to s3 bootscrip table
BOOT_SCRIPT_S3_IO_WRITE_MACRO(bss,EfiBootScriptWidthUint8,HWM_CONFIG_INDEX, 1, &bank_reg);
BOOT_SCRIPT_S3_IO_WRITE_MACRO(bss,EfiBootScriptWidthUint8,HWM_CONFIG_DATA, 1, &bank);
BOOT_SCRIPT_S3_IO_WRITE_MACRO(bss,EfiBootScriptWidthUint8,HWM_CONFIG_INDEX, 1, &r);
BOOT_SCRIPT_S3_IO_WRITE_MACRO(bss,EfiBootScriptWidthUint8,HWM_CONFIG_DATA, 1, &v);
}
return Status;
}
//*************************************************************************
//*************************************************************************
//** **
//** (C)Copyright 1985-2008, American Megatrends, Inc. **
//** **
//** All Rights Reserved. **
//** **
//** 5555 Oakbrook Parkway, Suite 200, Norcross, GA 30093 **
//** **
//** Phone: (770)-246-8600 **
//** **
//*************************************************************************
//*************************************************************************
|