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