11 #include <linux/module.h>
12 #include <linux/pci.h>
13 #include <linux/kernel.h>
14 #include <linux/stddef.h>
17 #include <linux/i2c.h>
20 #include <linux/slab.h>
40 #define AMD_PCI_MISC 0x48
42 #define AMD_PCI_MISC_SCI 0x04
43 #define AMD_PCI_MISC_INT 0x02
44 #define AMD_PCI_MISC_SPEEDUP 0x01
50 #define AMD_EC_DATA 0x00
51 #define AMD_EC_SC 0x04
52 #define AMD_EC_CMD 0x04
53 #define AMD_EC_ICR 0x08
55 #define AMD_EC_SC_SMI 0x04
56 #define AMD_EC_SC_SCI 0x02
57 #define AMD_EC_SC_BURST 0x01
58 #define AMD_EC_SC_CMD 0x08
59 #define AMD_EC_SC_IBF 0x02
60 #define AMD_EC_SC_OBF 0x01
62 #define AMD_EC_CMD_RD 0x80
63 #define AMD_EC_CMD_WR 0x81
64 #define AMD_EC_CMD_BE 0x82
65 #define AMD_EC_CMD_BD 0x83
66 #define AMD_EC_CMD_QR 0x84
72 static int amd_ec_wait_write(
struct amd_smbus *smbus)
81 "Timeout while waiting for IBF to clear\n");
88 static int amd_ec_wait_read(
struct amd_smbus *smbus)
97 "Timeout while waiting for OBF to set\n");
109 status = amd_ec_wait_write(smbus);
114 status = amd_ec_wait_write(smbus);
119 status = amd_ec_wait_read(smbus);
127 static int amd_ec_write(
struct amd_smbus *smbus,
unsigned char address,
132 status = amd_ec_wait_write(smbus);
137 status = amd_ec_wait_write(smbus);
142 status = amd_ec_wait_write(smbus);
154 #define AMD_SMB_PRTCL 0x00
155 #define AMD_SMB_STS 0x01
156 #define AMD_SMB_ADDR 0x02
157 #define AMD_SMB_CMD 0x03
158 #define AMD_SMB_DATA 0x04
159 #define AMD_SMB_BCNT 0x24
160 #define AMD_SMB_ALRM_A 0x25
161 #define AMD_SMB_ALRM_D 0x26
163 #define AMD_SMB_STS_DONE 0x80
164 #define AMD_SMB_STS_ALRM 0x40
165 #define AMD_SMB_STS_RES 0x20
166 #define AMD_SMB_STS_STATUS 0x1f
168 #define AMD_SMB_STATUS_OK 0x00
169 #define AMD_SMB_STATUS_FAIL 0x07
170 #define AMD_SMB_STATUS_DNAK 0x10
171 #define AMD_SMB_STATUS_DERR 0x11
172 #define AMD_SMB_STATUS_CMD_DENY 0x12
173 #define AMD_SMB_STATUS_UNKNOWN 0x13
174 #define AMD_SMB_STATUS_ACC_DENY 0x17
175 #define AMD_SMB_STATUS_TIMEOUT 0x18
176 #define AMD_SMB_STATUS_NOTSUP 0x19
177 #define AMD_SMB_STATUS_BUSY 0x1A
178 #define AMD_SMB_STATUS_PEC 0x1F
180 #define AMD_SMB_PRTCL_WRITE 0x00
181 #define AMD_SMB_PRTCL_READ 0x01
182 #define AMD_SMB_PRTCL_QUICK 0x02
183 #define AMD_SMB_PRTCL_BYTE 0x04
184 #define AMD_SMB_PRTCL_BYTE_DATA 0x06
185 #define AMD_SMB_PRTCL_WORD_DATA 0x08
186 #define AMD_SMB_PRTCL_BLOCK_DATA 0x0a
187 #define AMD_SMB_PRTCL_PROC_CALL 0x0c
188 #define AMD_SMB_PRTCL_BLOCK_PROC_CALL 0x0d
189 #define AMD_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
190 #define AMD_SMB_PRTCL_PEC 0x80
222 status = amd_ec_write(smbus,
AMD_SMB_CMD, command);
235 status = amd_ec_write(smbus,
AMD_SMB_CMD, command);
252 status = amd_ec_write(smbus,
AMD_SMB_CMD, command);
261 for (i = 0; i < len; i++) {
275 status = amd_ec_write(smbus,
AMD_SMB_CMD, command);
282 for (i = 0; i < len; i++) {
293 status = amd_ec_write(smbus,
AMD_SMB_CMD, command);
311 status = amd_ec_write(smbus,
AMD_SMB_CMD, command);
317 for (i = 0; i < len; i++) {
328 dev_warn(&adap->
dev,
"Unsupported transaction %d\n", size);
339 status = amd_ec_read(smbus,
AMD_SMB_STS, temp + 0);
345 status = amd_ec_read(smbus,
AMD_SMB_STS, temp + 0);
350 if (~temp[0] & AMD_SMB_STS_DONE) {
352 status = amd_ec_read(smbus,
AMD_SMB_STS, temp + 0);
376 status = amd_ec_read(smbus,
AMD_SMB_DATA + 1, temp + 1);
379 data->
word = (temp[1] << 8) | temp[0];
389 for (i = 0; i < len; i++) {
391 data->
block + i + 1);
395 data->
block[0] = len;
413 .smbus_xfer = amd8111_access,
414 .functionality = amd8111_func,
455 "SMBus2 AMD8111 adapter at %04x", smbus->
base);
457 smbus->
adapter.algo = &smbus_algorithm;
458 smbus->
adapter.algo_data = smbus;
466 goto out_release_region;
468 pci_set_drvdata(dev, smbus);
480 struct amd_smbus *smbus = pci_get_drvdata(dev);
488 .name =
"amd8111_smbus2",
489 .id_table = amd8111_ids,
490 .probe = amd8111_probe,