45 #include <linux/module.h>
47 #include <linux/pci.h>
48 #include <linux/kernel.h>
49 #include <linux/stddef.h>
51 #include <linux/i2c.h>
56 static struct pci_dev *vt596_pdev;
63 static unsigned short vt596_smba;
64 #define SMBHSTSTS (vt596_smba + 0)
65 #define SMBHSTCNT (vt596_smba + 2)
66 #define SMBHSTCMD (vt596_smba + 3)
67 #define SMBHSTADD (vt596_smba + 4)
68 #define SMBHSTDAT0 (vt596_smba + 5)
69 #define SMBHSTDAT1 (vt596_smba + 6)
70 #define SMBBLKDAT (vt596_smba + 7)
80 #define MAX_TIMEOUT 500
83 #define VT596_QUICK 0x00
84 #define VT596_BYTE 0x04
85 #define VT596_BYTE_DATA 0x08
86 #define VT596_WORD_DATA 0x0C
87 #define VT596_PROC_CALL 0x10
88 #define VT596_BLOCK_DATA 0x14
89 #define VT596_I2C_BLOCK_DATA 0x34
100 static u16 force_addr;
103 "Forcibly enable the SMBus at the given address. "
104 "EXTREMELY DANGEROUS!");
110 #define FEATURE_I2CBLOCK (1<<0)
111 static unsigned int vt596_features;
114 static void vt596_dump_regs(
const char *
msg,
u8 size)
116 dev_dbg(&vt596_adapter.dev,
"%s: STS=%02x CNT=%02x CMD=%02x ADD=%02x "
125 dev_dbg(&vt596_adapter.dev,
"BLK=");
129 dev_dbg(&vt596_adapter.dev,
" ");
136 static inline void vt596_dump_regs(
const char *
msg,
u8 size) { }
140 static int vt596_transaction(
u8 size)
146 vt596_dump_regs(
"Transaction (pre)", size);
150 dev_dbg(&vt596_adapter.dev,
"SMBus busy (0x%02x). "
151 "Resetting...\n", temp);
155 dev_err(&vt596_adapter.dev,
"SMBus reset failed! "
168 }
while ((temp & 0x01) && (++timeout <
MAX_TIMEOUT));
173 dev_err(&vt596_adapter.dev,
"SMBus timeout!\n");
178 dev_err(&vt596_adapter.dev,
"Transaction failed (0x%02x)\n",
184 dev_err(&vt596_adapter.dev,
"SMBus collision!\n");
189 dev_dbg(&vt596_adapter.dev,
"No response\n");
196 vt596_dump_regs(
"Transaction (post)", size);
240 goto exit_unsupported;
252 for (i = 1; i <= len; i++)
259 goto exit_unsupported;
264 status = vt596_transaction(size);
289 for (i = 1; i <= data->
block[0]; i++)
296 dev_warn(&vt596_adapter.dev,
"Unsupported transaction %d\n",
307 if (vt596_features & FEATURE_I2CBLOCK)
313 .smbus_xfer = vt596_access,
314 .functionality = vt596_func,
320 .algo = &smbus_algorithm,
331 vt596_smba = force_addr & 0xfff0;
336 if ((pci_read_config_word(pdev, id->
driver_data, &vt596_smba)) ||
337 !(vt596_smba & 0x0001)) {
340 !pci_read_config_word(pdev,
SMBBA2, &vt596_smba) &&
341 (vt596_smba & 0x0001)) {
346 "SMBus I/O Base address\n");
351 vt596_smba &= 0xfff0;
352 if (vt596_smba == 0) {
354 "uninitialized - upgrade BIOS or use "
355 "force_addr=0xaddr\n");
365 dev_err(&pdev->
dev,
"SMBus region 0x%x already in use!\n",
370 pci_read_config_byte(pdev,
SMBHSTCFG, &temp);
374 pci_write_config_byte(pdev,
SMBHSTCFG, temp & 0xfe);
375 pci_write_config_word(pdev, id->
driver_data, vt596_smba);
376 pci_write_config_byte(pdev,
SMBHSTCFG, temp | 0x01);
377 dev_warn(&pdev->
dev,
"WARNING: SMBus interface set to new "
378 "address 0x%04x!\n", vt596_smba);
379 }
else if (!(temp & 0x01)) {
387 pci_write_config_byte(pdev,
SMBHSTCFG, temp | 0x01);
390 dev_err(&pdev->
dev,
"SMBUS: Error: Host SMBus "
391 "controller not enabled! - upgrade BIOS or "
398 dev_dbg(&pdev->
dev,
"VT596_smba = 0x%X\n", vt596_smba);
422 vt596_adapter.
dev.parent = &pdev->
dev;
424 "SMBus Via Pro adapter at %04x", vt596_smba);
482 .name =
"vt596_smbus",
483 .id_table = vt596_ids,
484 .probe = vt596_probe,
487 static int __init i2c_vt596_init(
void)
489 return pci_register_driver(&vt596_driver);
493 static void __exit i2c_vt596_exit(
void)
496 if (vt596_pdev !=
NULL) {