Add support for Intel Panther Point PCH
[coreboot.git] / src / southbridge / intel / bd82x6x / acpi / smbus.asl
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2009 coresystems GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; version 2 of
9  * the License.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19  * MA 02110-1301 USA
20  */
21
22 // Intel SMBus Controller 0:1f.3
23
24 Device (SBUS)
25 {
26         Name (_ADR, 0x001f0003)
27
28 #ifdef ENABLE_SMBUS_METHODS
29         OperationRegion (SMBP, PCI_Config, 0x00, 0x100)
30         Field(SMBP, DWordAcc, NoLock, Preserve)
31         {
32                 Offset(0x40),
33                 ,       2,
34                 I2CE,   1
35         }
36
37         OperationRegion (SMBI, SystemIO, SMBUS_IO_BASE, 0x20)
38         Field (SMBI, ByteAcc, NoLock, Preserve)
39         {
40                 HSTS,   8,      // Host Status
41                 ,       8,
42                 HCNT,   8,      // Host Control
43                 HCMD,   8,      // Host Command
44                 TXSA,   8,      // Transmit Slave Address
45                 DAT0,   8,      // Host Data 0
46                 DAT1,   8,      // Host Data 1
47                 HBDB,   8,      // Host Block Data Byte
48                 PECK,   8,      // Packet Error Check
49                 RXSA,   8,      // Receive Slave Address
50                 RXDA,   16,     // Receive Slave Data
51                 AUXS,   8,      // Auxiliary Status
52                 AUXC,   8,      // Auxiliary Control
53                 SLPC,   8,      // SMLink Pin Control
54                 SBPC,   8,      // SMBus Pin Control
55                 SSTS,   8,      // Slave Status
56                 SCMD,   8,      // Slave Command
57                 NADR,   8,      // Notify Device Address
58                 NDLB,   8,      // Notify Data Low Byte
59                 NDLH,   8,      // Notify Data High Byte
60         }
61
62         // Kill all SMBus communication
63         Method (KILL, 0, Serialized)
64         {
65                 Or (HCNT, 0x02, HCNT)   // Send Kill
66                 Or (HSTS, 0xff, HSTS)   // Clean Status
67         }
68
69         // Check if last operation completed
70         // return       Failure = 0, Success = 1
71         Method (CMPL, 0, Serialized)
72         {
73                 Store (4000, Local0)            // Timeout 200ms in 50us steps
74                 While (Local0) {
75                         If (And(HSTS, 0x02)) {  // Completion Status?
76                                 Return (1)      // Operation Completed
77                         } Else {
78                                 Stall (50)
79                                 Decrement (Local0)
80                                 If (LEqual(Local0, 0)) {
81                                         KILL()
82                                 }
83                         }
84                 }
85
86                 Return (0)              //  Failure
87         }
88
89
90         // Wait for SMBus to become ready
91         Method (SRDY, 0, Serialized)
92         {
93                 Store (200, Local0)     // Timeout 200ms
94                 While (Local0) {
95                         If (And(HSTS, 0x40)) {          // IN_USE?
96                                 Sleep(1)                // Wait 1ms
97                                 Decrement(Local0)       // timeout--
98                                 If (LEqual(Local0, 0)) {
99                                         Return (1)
100                                 }
101                         } Else {
102                                 Store (0, Local0)       // We're ready
103                         }
104                 }
105
106                 Store (4000, Local0)    // Timeout 200ms (50us * 4000)
107                 While (Local0) {
108                         If (And (HSTS, 0x01)) {         // Host Busy?
109                                 Stall(50)               // Wait 50us
110                                 Decrement(Local0)       // timeout--
111                                 If (LEqual(Local0, 0)) {
112                                         KILL()
113                                 }
114                         } Else {
115                                 Return (0)              // Success
116                         }
117                 }
118
119                 Return (1)              // Failure
120         }
121
122         // SMBus Send Byte
123         // Arg0:        Address
124         // Arg1:        Data
125         // Return:      1 = Success, 0=Failure
126
127         Method (SSXB, 2, Serialized)
128         {
129
130                 // Is the SMBus Controller Ready?
131                 If (SRDY()) {
132                         Return (0)
133                 }
134
135                 // Send Byte
136                 Store (0, I2CE)         // SMBus Enable
137                 Store (0xbf, HSTS)
138                 Store (Arg0, TXSA)      // Write Address
139                 Store (Arg1, HCMD)      // Write Data
140
141                 Store (0x48, HCNT)      // Start + Byte Data Protocol
142
143                 If (CMPL()) {
144                         Or (HSTS, 0xff, HSTS)   // Clean up
145                         Return (1)              // Success
146                 }
147
148                 Return (0)
149         }
150
151
152         // SMBus Receive Byte
153         // Arg0:        Address
154         // Return:      0xffff = Failure, Data (8bit) = Success
155
156         Method (SRXB, 2, Serialized)
157         {
158
159                 // Is the SMBus Controller Ready?
160                 If (SRDY()) {
161                         Return (0xffff)
162                 }
163
164                 // Receive Byte
165                 Store (0, I2CE)         // SMBus Enable
166                 Store (0xbf, HSTS)
167                 Store (Or (Arg0, 1), TXSA)      // Write Address
168
169                 Store (0x44, HCNT)      // Start
170
171                 If (CMPL()) {
172                         Or (HSTS, 0xff, HSTS)   // Clean up
173                         Return (DAT0)           // Success
174                 }
175
176                 Return (0xffff)
177         }
178
179
180         // SMBus Write Byte
181         // Arg0:        Address
182         // Arg1:        Command
183         // Arg2:        Data
184         // Return:      1 = Success, 0=Failure
185
186         Method (SWRB, 3, Serialized)
187         {
188
189                 // Is the SMBus Controller Ready?
190                 If (SRDY()) {
191                         Return (0)
192                 }
193
194                 // Send Byte
195                 Store (0, I2CE)         // SMBus Enable
196                 Store (0xbf, HSTS)
197                 Store (Arg0, TXSA)      // Write Address
198                 Store (Arg1, HCMD)      // Write Command
199                 Store (Arg2, DAT0)      // Write Data
200
201                 Store (0x48, HCNT)      // Start + Byte Protocol
202
203                 If (CMPL()) {
204                         Or (HSTS, 0xff, HSTS)   // Clean up
205                         Return (1)              // Success
206                 }
207
208                 Return (0)
209         }
210
211
212         // SMBus Read Byte
213         // Arg0:        Address
214         // Arg1:        Command
215         // Return:      0xffff = Failure, Data (8bit) = Success
216
217         Method (SRDB, 2, Serialized)
218         {
219
220                 // Is the SMBus Controller Ready?
221                 If (SRDY()) {
222                         Return (0xffff)
223                 }
224
225                 // Receive Byte
226                 Store (0, I2CE)                 // SMBus Enable
227                 Store (0xbf, HSTS)
228                 Store (Or (Arg0, 1), TXSA)      // Write Address
229                 Store (Arg1, HCMD)              // Command
230
231                 Store (0x48, HCNT)              // Start
232
233                 If (CMPL()) {
234                         Or (HSTS, 0xff, HSTS)   // Clean up
235                         Return (DAT0)           // Success
236                 }
237
238                 Return (0xffff)
239         }
240 #endif
241 }
242