19 #include <linux/module.h>
21 #include <linux/i2c.h>
22 #include <linux/pci.h>
26 #define ALI1563_MAX_TIMEOUT 500
27 #define ALI1563_SMBBA 0x80
28 #define ALI1563_SMB_IOEN 1
29 #define ALI1563_SMB_HOSTEN 2
30 #define ALI1563_SMB_IOSIZE 16
32 #define SMB_HST_STS (ali1563_smba + 0)
33 #define SMB_HST_CNTL1 (ali1563_smba + 1)
34 #define SMB_HST_CNTL2 (ali1563_smba + 2)
35 #define SMB_HST_CMD (ali1563_smba + 3)
36 #define SMB_HST_ADD (ali1563_smba + 4)
37 #define SMB_HST_DAT0 (ali1563_smba + 5)
38 #define SMB_HST_DAT1 (ali1563_smba + 6)
39 #define SMB_BLK_DAT (ali1563_smba + 7)
41 #define HST_STS_BUSY 0x01
42 #define HST_STS_INTR 0x02
43 #define HST_STS_DEVERR 0x04
44 #define HST_STS_BUSERR 0x08
45 #define HST_STS_FAIL 0x10
46 #define HST_STS_DONE 0x80
47 #define HST_STS_BAD 0x1c
50 #define HST_CNTL1_TIMEOUT 0x80
51 #define HST_CNTL1_LAST 0x40
53 #define HST_CNTL2_KILL 0x04
54 #define HST_CNTL2_START 0x40
55 #define HST_CNTL2_QUICK 0x00
56 #define HST_CNTL2_BYTE 0x01
57 #define HST_CNTL2_BYTE_DATA 0x02
58 #define HST_CNTL2_WORD_DATA 0x03
59 #define HST_CNTL2_BLOCK 0x05
62 #define HST_CNTL2_SIZEMASK 0x38
65 static unsigned short ali1563_smba;
73 dev_dbg(&a->
dev,
"Transaction (pre): STS=%02x, CNTL1=%02x, "
74 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
81 dev_err(&a->
dev,
"ali1563: Trying to reset busy device\n");
84 if (data & HST_STS_BAD)
94 dev_dbg(&a->
dev,
"Transaction (post): STS=%02x, CNTL1=%02x, "
95 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
100 if (timeout && !(data & HST_STS_BAD))
104 dev_err(&a->
dev,
"Timeout - Trying to KILL transaction!\n");
125 dev_err(&a->
dev,
"Cleaning fail after KILL!\n");
132 static int ali1563_block_start(
struct i2c_adapter * a)
138 dev_dbg(&a->
dev,
"Block (pre): STS=%02x, CNTL1=%02x, "
139 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
145 if (data & HST_STS_BAD) {
146 dev_warn(&a->
dev,
"ali1563: Trying to reset busy device\n");
149 if (data & HST_STS_BAD)
164 dev_dbg(&a->
dev,
"Block (post): STS=%02x, CNTL1=%02x, "
165 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
170 if (timeout && !(data & HST_STS_BAD))
176 if (data & HST_STS_DEVERR)
180 timeout ?
"" :
"Timeout ",
182 data & HST_STS_BUSERR ?
"No response or Bus Collision " :
"",
183 data & HST_STS_DEVERR ?
"Device Error " :
"",
184 !(data & HST_STS_DONE) ?
"Transaction Never Finished " :
"");
197 len = data->
block[0];
209 for (i = 0; i < len; i++) {
212 if ((error = ali1563_block_start(a)))
215 if ((error = ali1563_block_start(a)))
245 dev_warn(&a->
dev,
"SMBus not idle. HST_STS = %02x\n",reg);
266 dev_warn(&a->
dev,
"Unsupported transaction %d\n", size);
296 error = ali1563_block(a,data,rw);
300 if ((error = ali1563_transaction(a, size)))
339 dev_warn(&dev->
dev,
"ali1563_smba Uninitialized\n");
345 dev_warn(&dev->
dev,
"Host Controller not enabled\n");
349 dev_warn(&dev->
dev,
"I/O space not enabled, trying manually\n");
351 ctrl | ALI1563_SMB_IOEN);
353 if (!(ctrl & ALI1563_SMB_IOEN)) {
354 dev_err(&dev->
dev,
"I/O space still not enabled, "
361 ali1563_pci_driver.name))
365 ali1563_pci_driver.name)) {
366 dev_err(&dev->
dev,
"Could not allocate I/O space at 0x%04x\n",
370 dev_info(&dev->
dev,
"Found ALi1563 SMBus at 0x%04x\n", ali1563_smba);
377 static void ali1563_shutdown(
struct pci_dev *dev)
383 .smbus_xfer = ali1563_access,
384 .functionality = ali1563_func,
390 .algo = &ali1563_algorithm,
398 if ((error = ali1563_setup(dev)))
400 ali1563_adapter.
dev.parent = &dev->
dev;
402 "SMBus ALi 1563 Adapter @ %04x", ali1563_smba);
408 ali1563_shutdown(dev);
410 dev_warn(&dev->
dev,
"ALi1563 SMBus probe failed (%d)\n", error);
417 ali1563_shutdown(dev);
427 static struct pci_driver ali1563_pci_driver = {
428 .name =
"ali1563_smbus",
429 .id_table = ali1563_id_table,
430 .probe = ali1563_probe,