Remove multiple mmconf settings and just use kconfig setting.
[coreboot.git] / src / vendorcode / amd / cimx / sb800 / ECfanLIB.c
1 /**
2  * @file
3  *
4  * Southbridge EC IO access common routine
5  *
6  */
7 /*
8  *****************************************************************************
9  *
10  * Copyright (c) 2011, Advanced Micro Devices, Inc.
11  * All rights reserved.
12  * 
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions are met:
15  *     * Redistributions of source code must retain the above copyright
16  *       notice, this list of conditions and the following disclaimer.
17  *     * Redistributions in binary form must reproduce the above copyright
18  *       notice, this list of conditions and the following disclaimer in the
19  *       documentation and/or other materials provided with the distribution.
20  *     * Neither the name of Advanced Micro Devices, Inc. nor the names of 
21  *       its contributors may be used to endorse or promote products derived 
22  *       from this software without specific prior written permission.
23  * 
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL ADVANCED MICRO DEVICES, INC. BE LIABLE FOR ANY
28  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  * 
35  * ***************************************************************************
36  *
37  */
38
39 #include "SBPLATFORM.h"
40 #include "ECfan.h"
41
42 VOID
43 ReadECmsg (
44   IN       UINT8 Address,
45   IN       UINT8 OpFlag,
46      OUT   VOID* Value
47   )
48 {
49  UINT8 i;
50
51   OpFlag = OpFlag & 0x7f;
52   if (OpFlag == 0x02) OpFlag = 0x03;
53   for (i = 0; i <= OpFlag; i++) {
54     WriteIO(MailBoxPort, AccWidthUint8, &Address);  // EC_LDN9_MAILBOX_BASE_ADDRESS
55     Address++;
56     ReadIO(MailBoxPort + 1, AccWidthUint8, (UINT8 *)Value+i);   // EC_LDN9_MAILBOX_BASE_ADDRESS
57   }
58 }
59
60
61 VOID
62 WriteECmsg (
63   IN       UINT8 Address,
64   IN       UINT8 OpFlag,
65   IN       VOID* Value
66   )
67 {
68  UINT8 i;
69
70   OpFlag = OpFlag & 0x7f;
71   if (OpFlag == 0x02) OpFlag = 0x03;
72   for (i = 0; i <= OpFlag; i++) {
73     WriteIO(MailBoxPort, AccWidthUint8, &Address);  // EC_LDN9_MAILBOX_BASE_ADDRESS
74     Address++;
75     WriteIO(MailBoxPort + 1, AccWidthUint8, (UINT8 *)Value+i);   // EC_LDN9_MAILBOX_BASE_ADDRESS
76   }
77 }
78
79 VOID
80 WaitForEcLDN9MailboxCmdAck (
81   VOID
82   )
83 {
84   UINT8 Msgdata;
85   UINT16 Delaytime;
86   Msgdata = 0;
87   for (Delaytime = 0; Delaytime <= 500; Delaytime++) {
88     ReadECmsg (MSG_REG0, AccWidthUint8, &Msgdata);
89     if ( Msgdata == 0xfa) {
90       break;
91     }
92     SbStall (1000); // Wait for 1ms
93   }
94 }
95
96