54 #include <linux/module.h>
55 #include <linux/pci.h>
56 #include <linux/kernel.h>
57 #include <linux/stddef.h>
60 #include <linux/i2c.h>
67 #define SMBHSTSTS (0 + ali1535_smba)
68 #define SMBHSTTYP (1 + ali1535_smba)
69 #define SMBHSTPORT (2 + ali1535_smba)
70 #define SMBHSTCMD (7 + ali1535_smba)
71 #define SMBHSTADD (3 + ali1535_smba)
72 #define SMBHSTDAT0 (4 + ali1535_smba)
73 #define SMBHSTDAT1 (5 + ali1535_smba)
74 #define SMBBLKDAT (6 + ali1535_smba)
81 #define SMBHSTCFG 0x0F0
85 #define MAX_TIMEOUT 500
86 #define ALI1535_SMB_IOSIZE 32
88 #define ALI1535_SMB_DEFAULTBASE 0x8040
91 #define ALI1535_LOCK 0x06
94 #define ALI1535_QUICK 0x00
95 #define ALI1535_BYTE 0x10
96 #define ALI1535_BYTE_DATA 0x20
97 #define ALI1535_WORD_DATA 0x30
98 #define ALI1535_BLOCK_DATA 0x40
99 #define ALI1535_I2C_READ 0x60
101 #define ALI1535_DEV10B_EN 0x80
103 #define ALI1535_T_OUT 0x08
104 #define ALI1535_A_HIGH_BIT9 0x08
107 #define ALI1535_KILL 0x04
108 #define ALI1535_A_HIGH_BIT8 0x04
112 #define ALI1535_D_HI_MASK 0x03
117 #define ALI1535_STS_IDLE 0x04
118 #define ALI1535_STS_BUSY 0x08
119 #define ALI1535_STS_DONE 0x10
120 #define ALI1535_STS_DEV 0x20
121 #define ALI1535_STS_BUSERR 0x40
122 #define ALI1535_STS_FAIL 0x80
123 #define ALI1535_STS_ERR 0xE0
125 #define ALI1535_BLOCK_CLR 0x04
128 #define ALI1535_RD_ADDR 0x01
132 #define ALI1535_SMBIO_EN 0x04
135 static unsigned long ali1535_smba;
136 static unsigned short ali1535_offset;
155 dev_err(&dev->
dev,
"ALI1535_smb can't enable device\n");
160 pci_read_config_word(dev,
SMBBA, &ali1535_offset);
161 dev_dbg(&dev->
dev,
"ALI1535_smb is at offset 0x%04x\n", ali1535_offset);
163 if (ali1535_offset == 0) {
165 "ALI1535_smb region uninitialized - upgrade BIOS?\n");
173 ali1535_smba = ali1535_offset;
176 ali1535_driver.name);
181 ali1535_driver.name)) {
182 dev_err(&dev->
dev,
"ALI1535_smb region 0x%lx already in use!\n",
189 pci_read_config_byte(dev,
SMBCFG, &temp);
191 dev_err(&dev->
dev,
"SMB device not enabled - upgrade BIOS?\n");
197 pci_read_config_byte(dev,
SMBHSTCFG, &temp);
198 if ((temp & 1) == 0) {
199 dev_err(&dev->
dev,
"SMBus controller not enabled - upgrade BIOS?\n");
205 pci_write_config_byte(dev,
SMBCLK, 0x20);
214 pci_read_config_byte(dev,
SMBREV, &temp);
216 dev_dbg(&dev->
dev,
"ALI1535_smba = 0x%lx\n", ali1535_smba);
226 static int ali1535_transaction(
struct i2c_adapter *adap)
232 dev_dbg(&adap->
dev,
"Transaction (pre): STS=%02x, TYP=%02x, "
233 "CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
263 "Resetting entire SMB Bus to clear busy condition (%02x)\n",
280 "SMBus reset failed! (0x%02x) - controller or "
281 "device on bus is probably hung\n", temp);
309 dev_dbg(&adap->
dev,
"Error: Failed bus transaction\n");
319 "Error: no response or bus collision ADD=%02x\n",
332 dev_err(&adap->
dev,
"Error: command never completed\n");
335 dev_dbg(&adap->
dev,
"Transaction (post): STS=%02x, TYP=%02x, "
336 "CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
341 if (!(temp & ALI1535_STS_DONE)) {
367 (timeout <
MAX_TIMEOUT) && !(temp & ALI1535_STS_IDLE);
373 dev_warn(&adap->
dev,
"Idle wait Timeout! STS=0x%02x\n", temp);
380 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
386 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
394 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
403 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
414 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
420 len = data->
block[0];
423 data->
block[0] = len;
427 data->
block[0] = len;
432 for (i = 1; i <= len; i++)
437 dev_warn(&adap->
dev,
"Unsupported transaction %d\n", size);
442 result = ali1535_transaction(adap);
465 data->
block[0] = len;
468 for (i = 1; i <= data->
block[0]; i++) {
470 dev_dbg(&adap->
dev,
"Blk: len=%d, i=%d, data=%02x\n",
471 len, i, data->
block[i]);
488 .smbus_xfer = ali1535_access,
489 .functionality = ali1535_func,
495 .algo = &smbus_algorithm,
507 if (ali1535_setup(dev)) {
509 "ALI1535 not detected, module not inserted.\n");
514 ali1535_adapter.
dev.parent = &dev->
dev;
517 "SMBus ALI1535 adapter at %04x", ali1535_offset);
528 .name =
"ali1535_smbus",
529 .id_table = ali1535_ids,
530 .probe = ali1535_probe,