Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Mike Loptien | 573a1d6 | 2013-03-18 11:19:26 -0600 | [diff] [blame] | 3 | |
| 4 | /* SMBUS Support */ |
| 5 | Mutex (SBX0, 0x00) |
| 6 | OperationRegion (SMB0, SystemIO, 0xB00, 0x0C) |
| 7 | Field (SMB0, ByteAcc, NoLock, Preserve) { |
Paul Menzel | 7b1a8a7 | 2015-06-14 11:55:27 +0200 | [diff] [blame] | 8 | HSTS, 8, /* SMBUS status */ |
Mike Loptien | 573a1d6 | 2013-03-18 11:19:26 -0600 | [diff] [blame] | 9 | SSTS, 8, /* SMBUS slave status */ |
| 10 | HCNT, 8, /* SMBUS control */ |
| 11 | HCMD, 8, /* SMBUS host cmd */ |
| 12 | HADD, 8, /* SMBUS address */ |
| 13 | DAT0, 8, /* SMBUS data0 */ |
| 14 | DAT1, 8, /* SMBUS data1 */ |
| 15 | BLKD, 8, /* SMBUS block data */ |
| 16 | SCNT, 8, /* SMBUS slave control */ |
Paul Menzel | 4159a80 | 2013-07-14 00:24:31 +0200 | [diff] [blame] | 17 | SCMD, 8, /* SMBUS shadow cmd */ |
Mike Loptien | 573a1d6 | 2013-03-18 11:19:26 -0600 | [diff] [blame] | 18 | SEVT, 8, /* SMBUS slave event */ |
Paul Menzel | 7b1a8a7 | 2015-06-14 11:55:27 +0200 | [diff] [blame] | 19 | SDAT, 8 /* SMBUS slave data */ |
Mike Loptien | 573a1d6 | 2013-03-18 11:19:26 -0600 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | Method (WCLR, 0, NotSerialized) { /* clear SMBUS status register */ |
| 23 | Store (0x1E, HSTS) |
| 24 | Store (0xFA, Local0) |
| 25 | While (LAnd (LNotEqual (And (HSTS, 0x1E), Zero), LGreater (Local0, Zero))) { |
| 26 | Stall (0x64) |
| 27 | Decrement (Local0) |
| 28 | } |
| 29 | |
| 30 | Return (Local0) |
| 31 | } |
| 32 | |
| 33 | Method (SWTC, 1, NotSerialized) { |
| 34 | Store (Arg0, Local0) |
| 35 | Store (0x07, Local2) |
| 36 | Store (One, Local1) |
| 37 | While (LEqual (Local1, One)) { |
| 38 | Store (And (HSTS, 0x1E), Local3) |
| 39 | If (LNotEqual (Local3, Zero)) { /* read sucess */ |
| 40 | If (LEqual (Local3, 0x02)) { |
| 41 | Store (Zero, Local2) |
| 42 | } |
| 43 | |
| 44 | Store (Zero, Local1) |
| 45 | } |
| 46 | Else { |
| 47 | If (LLess (Local0, 0x0A)) { /* read failure */ |
| 48 | Store (0x10, Local2) |
| 49 | Store (Zero, Local1) |
| 50 | } |
| 51 | Else { |
| 52 | Sleep (0x0A) /* 10 ms, try again */ |
| 53 | Subtract (Local0, 0x0A, Local0) |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | Return (Local2) |
| 59 | } |
| 60 | |
| 61 | Method (SMBR, 3, NotSerialized) { |
| 62 | Store (0x07, Local0) |
| 63 | If (LEqual (Acquire (SBX0, 0xFFFF), Zero)) { |
| 64 | Store (WCLR (), Local0) /* clear SMBUS status register before read data */ |
| 65 | If (LEqual (Local0, Zero)) { |
| 66 | Release (SBX0) |
| 67 | Return (0x0) |
| 68 | } |
| 69 | |
| 70 | Store (0x1F, HSTS) |
| 71 | Store (Or (ShiftLeft (Arg1, One), One), HADD) |
| 72 | Store (Arg2, HCMD) |
| 73 | If (LEqual (Arg0, 0x07)) { |
| 74 | Store (0x48, HCNT) /* read byte */ |
| 75 | } |
| 76 | |
| 77 | Store (SWTC (0x03E8), Local1) /* 1000 ms */ |
| 78 | If (LEqual (Local1, Zero)) { |
| 79 | If (LEqual (Arg0, 0x07)) { |
| 80 | Store (DAT0, Local0) |
| 81 | } |
| 82 | } |
| 83 | Else { |
| 84 | Store (Local1, Local0) |
| 85 | } |
| 86 | |
| 87 | Release (SBX0) |
| 88 | } |
| 89 | |
| 90 | /* DBGO("the value of SMBusData0 register ") */ |
| 91 | /* DBGO(Arg2) */ |
| 92 | /* DBGO(" is ") */ |
| 93 | /* DBGO(Local0) */ |
| 94 | /* DBGO("\n") */ |
| 95 | |
| 96 | Return (Local0) |
| 97 | } |