blob: 346d7d7bec7d65091dbf2b035557e71d913b62a8 [file] [log] [blame]
Mike Loptien573a1d62013-03-18 11:19:26 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Mike Loptien573a1d62013-03-18 11:19:26 -060018 */
19
20/* SMBUS Support */
21Mutex (SBX0, 0x00)
22OperationRegion (SMB0, SystemIO, 0xB00, 0x0C)
23 Field (SMB0, ByteAcc, NoLock, Preserve) {
Paul Menzel7b1a8a72015-06-14 11:55:27 +020024 HSTS, 8, /* SMBUS status */
Mike Loptien573a1d62013-03-18 11:19:26 -060025 SSTS, 8, /* SMBUS slave status */
26 HCNT, 8, /* SMBUS control */
27 HCMD, 8, /* SMBUS host cmd */
28 HADD, 8, /* SMBUS address */
29 DAT0, 8, /* SMBUS data0 */
30 DAT1, 8, /* SMBUS data1 */
31 BLKD, 8, /* SMBUS block data */
32 SCNT, 8, /* SMBUS slave control */
Paul Menzel4159a802013-07-14 00:24:31 +020033 SCMD, 8, /* SMBUS shadow cmd */
Mike Loptien573a1d62013-03-18 11:19:26 -060034 SEVT, 8, /* SMBUS slave event */
Paul Menzel7b1a8a72015-06-14 11:55:27 +020035 SDAT, 8 /* SMBUS slave data */
Mike Loptien573a1d62013-03-18 11:19:26 -060036}
37
38Method (WCLR, 0, NotSerialized) { /* clear SMBUS status register */
39 Store (0x1E, HSTS)
40 Store (0xFA, Local0)
41 While (LAnd (LNotEqual (And (HSTS, 0x1E), Zero), LGreater (Local0, Zero))) {
42 Stall (0x64)
43 Decrement (Local0)
44 }
45
46 Return (Local0)
47}
48
49Method (SWTC, 1, NotSerialized) {
50 Store (Arg0, Local0)
51 Store (0x07, Local2)
52 Store (One, Local1)
53 While (LEqual (Local1, One)) {
54 Store (And (HSTS, 0x1E), Local3)
55 If (LNotEqual (Local3, Zero)) { /* read sucess */
56 If (LEqual (Local3, 0x02)) {
57 Store (Zero, Local2)
58 }
59
60 Store (Zero, Local1)
61 }
62 Else {
63 If (LLess (Local0, 0x0A)) { /* read failure */
64 Store (0x10, Local2)
65 Store (Zero, Local1)
66 }
67 Else {
68 Sleep (0x0A) /* 10 ms, try again */
69 Subtract (Local0, 0x0A, Local0)
70 }
71 }
72 }
73
74 Return (Local2)
75}
76
77Method (SMBR, 3, NotSerialized) {
78 Store (0x07, Local0)
79 If (LEqual (Acquire (SBX0, 0xFFFF), Zero)) {
80 Store (WCLR (), Local0) /* clear SMBUS status register before read data */
81 If (LEqual (Local0, Zero)) {
82 Release (SBX0)
83 Return (0x0)
84 }
85
86 Store (0x1F, HSTS)
87 Store (Or (ShiftLeft (Arg1, One), One), HADD)
88 Store (Arg2, HCMD)
89 If (LEqual (Arg0, 0x07)) {
90 Store (0x48, HCNT) /* read byte */
91 }
92
93 Store (SWTC (0x03E8), Local1) /* 1000 ms */
94 If (LEqual (Local1, Zero)) {
95 If (LEqual (Arg0, 0x07)) {
96 Store (DAT0, Local0)
97 }
98 }
99 Else {
100 Store (Local1, Local0)
101 }
102
103 Release (SBX0)
104 }
105
106 /* DBGO("the value of SMBusData0 register ") */
107 /* DBGO(Arg2) */
108 /* DBGO(" is ") */
109 /* DBGO(Local0) */
110 /* DBGO("\n") */
111
112 Return (Local0)
113}