11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds piix4.c - Part of lm_sensors, Linux kernel modules for hardware 31da177e4SLinus Torvalds monitoring 41da177e4SLinus Torvalds Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and 51da177e4SLinus Torvalds Philip Edelbrock <phil@netroedge.com> 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds This program is free software; you can redistribute it and/or modify 81da177e4SLinus Torvalds it under the terms of the GNU General Public License as published by 91da177e4SLinus Torvalds the Free Software Foundation; either version 2 of the License, or 101da177e4SLinus Torvalds (at your option) any later version. 111da177e4SLinus Torvalds 121da177e4SLinus Torvalds This program is distributed in the hope that it will be useful, 131da177e4SLinus Torvalds but WITHOUT ANY WARRANTY; without even the implied warranty of 141da177e4SLinus Torvalds MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 151da177e4SLinus Torvalds GNU General Public License for more details. 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds You should have received a copy of the GNU General Public License 181da177e4SLinus Torvalds along with this program; if not, write to the Free Software 191da177e4SLinus Torvalds Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 201da177e4SLinus Torvalds */ 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds /* 231da177e4SLinus Torvalds Supports: 241da177e4SLinus Torvalds Intel PIIX4, 440MX 251da177e4SLinus Torvalds Serverworks OSB4, CSB5, CSB6 261da177e4SLinus Torvalds SMSC Victory66 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds Note: we assume there can only be one device, with one SMBus interface. 291da177e4SLinus Torvalds */ 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #include <linux/module.h> 321da177e4SLinus Torvalds #include <linux/moduleparam.h> 331da177e4SLinus Torvalds #include <linux/pci.h> 341da177e4SLinus Torvalds #include <linux/kernel.h> 351da177e4SLinus Torvalds #include <linux/delay.h> 361da177e4SLinus Torvalds #include <linux/stddef.h> 371da177e4SLinus Torvalds #include <linux/sched.h> 381da177e4SLinus Torvalds #include <linux/ioport.h> 391da177e4SLinus Torvalds #include <linux/i2c.h> 401da177e4SLinus Torvalds #include <linux/init.h> 411da177e4SLinus Torvalds #include <linux/apm_bios.h> 421da177e4SLinus Torvalds #include <linux/dmi.h> 431da177e4SLinus Torvalds #include <asm/io.h> 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds 461da177e4SLinus Torvalds struct sd { 471da177e4SLinus Torvalds const unsigned short mfr; 481da177e4SLinus Torvalds const unsigned short dev; 491da177e4SLinus Torvalds const unsigned char fn; 501da177e4SLinus Torvalds const char *name; 511da177e4SLinus Torvalds }; 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* PIIX4 SMBus address offsets */ 541da177e4SLinus Torvalds #define SMBHSTSTS (0 + piix4_smba) 551da177e4SLinus Torvalds #define SMBHSLVSTS (1 + piix4_smba) 561da177e4SLinus Torvalds #define SMBHSTCNT (2 + piix4_smba) 571da177e4SLinus Torvalds #define SMBHSTCMD (3 + piix4_smba) 581da177e4SLinus Torvalds #define SMBHSTADD (4 + piix4_smba) 591da177e4SLinus Torvalds #define SMBHSTDAT0 (5 + piix4_smba) 601da177e4SLinus Torvalds #define SMBHSTDAT1 (6 + piix4_smba) 611da177e4SLinus Torvalds #define SMBBLKDAT (7 + piix4_smba) 621da177e4SLinus Torvalds #define SMBSLVCNT (8 + piix4_smba) 631da177e4SLinus Torvalds #define SMBSHDWCMD (9 + piix4_smba) 641da177e4SLinus Torvalds #define SMBSLVEVT (0xA + piix4_smba) 651da177e4SLinus Torvalds #define SMBSLVDAT (0xC + piix4_smba) 661da177e4SLinus Torvalds 671da177e4SLinus Torvalds /* count for request_region */ 681da177e4SLinus Torvalds #define SMBIOSIZE 8 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds /* PCI Address Constants */ 711da177e4SLinus Torvalds #define SMBBA 0x090 721da177e4SLinus Torvalds #define SMBHSTCFG 0x0D2 731da177e4SLinus Torvalds #define SMBSLVC 0x0D3 741da177e4SLinus Torvalds #define SMBSHDW1 0x0D4 751da177e4SLinus Torvalds #define SMBSHDW2 0x0D5 761da177e4SLinus Torvalds #define SMBREV 0x0D6 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* Other settings */ 791da177e4SLinus Torvalds #define MAX_TIMEOUT 500 801da177e4SLinus Torvalds #define ENABLE_INT9 0 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds /* PIIX4 constants */ 831da177e4SLinus Torvalds #define PIIX4_QUICK 0x00 841da177e4SLinus Torvalds #define PIIX4_BYTE 0x04 851da177e4SLinus Torvalds #define PIIX4_BYTE_DATA 0x08 861da177e4SLinus Torvalds #define PIIX4_WORD_DATA 0x0C 871da177e4SLinus Torvalds #define PIIX4_BLOCK_DATA 0x14 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds /* insmod parameters */ 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds /* If force is set to anything different from 0, we forcibly enable the 921da177e4SLinus Torvalds PIIX4. DANGEROUS! */ 93*60507095SJean Delvare static int force; 941da177e4SLinus Torvalds module_param (force, int, 0); 951da177e4SLinus Torvalds MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!"); 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds /* If force_addr is set to anything different from 0, we forcibly enable 981da177e4SLinus Torvalds the PIIX4 at the given address. VERY DANGEROUS! */ 99*60507095SJean Delvare static int force_addr; 1001da177e4SLinus Torvalds module_param (force_addr, int, 0); 1011da177e4SLinus Torvalds MODULE_PARM_DESC(force_addr, 1021da177e4SLinus Torvalds "Forcibly enable the PIIX4 at the given address. " 1031da177e4SLinus Torvalds "EXTREMELY DANGEROUS!"); 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds /* If fix_hstcfg is set to anything different from 0, we reset one of the 1061da177e4SLinus Torvalds registers to be a valid value. */ 107*60507095SJean Delvare static int fix_hstcfg; 1081da177e4SLinus Torvalds module_param (fix_hstcfg, int, 0); 1091da177e4SLinus Torvalds MODULE_PARM_DESC(fix_hstcfg, 1101da177e4SLinus Torvalds "Fix config register. Needed on some boards (Force CPCI735)."); 1111da177e4SLinus Torvalds 1121da177e4SLinus Torvalds static int piix4_transaction(void); 1131da177e4SLinus Torvalds 114*60507095SJean Delvare static unsigned short piix4_smba; 1151da177e4SLinus Torvalds static struct i2c_adapter piix4_adapter; 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds static struct dmi_system_id __devinitdata piix4_dmi_table[] = { 1181da177e4SLinus Torvalds { 1191da177e4SLinus Torvalds .ident = "IBM", 1201da177e4SLinus Torvalds .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, 1211da177e4SLinus Torvalds }, 1221da177e4SLinus Torvalds { }, 1231da177e4SLinus Torvalds }; 1241da177e4SLinus Torvalds 1251da177e4SLinus Torvalds static int __devinit piix4_setup(struct pci_dev *PIIX4_dev, 1261da177e4SLinus Torvalds const struct pci_device_id *id) 1271da177e4SLinus Torvalds { 1281da177e4SLinus Torvalds unsigned char temp; 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds /* match up the function */ 1311da177e4SLinus Torvalds if (PCI_FUNC(PIIX4_dev->devfn) != id->driver_data) 1321da177e4SLinus Torvalds return -ENODEV; 1331da177e4SLinus Torvalds 1341da177e4SLinus Torvalds dev_info(&PIIX4_dev->dev, "Found %s device\n", pci_name(PIIX4_dev)); 1351da177e4SLinus Torvalds 1361da177e4SLinus Torvalds /* Don't access SMBus on IBM systems which get corrupted eeproms */ 1371da177e4SLinus Torvalds if (dmi_check_system(piix4_dmi_table) && 1381da177e4SLinus Torvalds PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) { 1391da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, "IBM Laptop detected; this module " 1401da177e4SLinus Torvalds "may corrupt your serial eeprom! Refusing to load " 1411da177e4SLinus Torvalds "module!\n"); 1421da177e4SLinus Torvalds return -EPERM; 1431da177e4SLinus Torvalds } 1441da177e4SLinus Torvalds 1451da177e4SLinus Torvalds /* Determine the address of the SMBus areas */ 1461da177e4SLinus Torvalds if (force_addr) { 1471da177e4SLinus Torvalds piix4_smba = force_addr & 0xfff0; 1481da177e4SLinus Torvalds force = 0; 1491da177e4SLinus Torvalds } else { 1501da177e4SLinus Torvalds pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba); 1511da177e4SLinus Torvalds piix4_smba &= 0xfff0; 1521da177e4SLinus Torvalds if(piix4_smba == 0) { 1531da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, "SMB base address " 1541da177e4SLinus Torvalds "uninitialized - upgrade BIOS or use " 1551da177e4SLinus Torvalds "force_addr=0xaddr\n"); 1561da177e4SLinus Torvalds return -ENODEV; 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds } 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds if (!request_region(piix4_smba, SMBIOSIZE, "piix4-smbus")) { 1611da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n", 1621da177e4SLinus Torvalds piix4_smba); 1631da177e4SLinus Torvalds return -ENODEV; 1641da177e4SLinus Torvalds } 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds /* Some BIOS will set up the chipset incorrectly and leave a register 1691da177e4SLinus Torvalds in an undefined state (causing I2C to act very strangely). */ 1701da177e4SLinus Torvalds if (temp & 0x02) { 1711da177e4SLinus Torvalds if (fix_hstcfg) { 1721da177e4SLinus Torvalds dev_info(&PIIX4_dev->dev, "Working around buggy BIOS " 1731da177e4SLinus Torvalds "(I2C)\n"); 1741da177e4SLinus Torvalds temp &= 0xfd; 1751da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp); 1761da177e4SLinus Torvalds } else { 1771da177e4SLinus Torvalds dev_info(&PIIX4_dev->dev, "Unusual config register " 1781da177e4SLinus Torvalds "value\n"); 1791da177e4SLinus Torvalds dev_info(&PIIX4_dev->dev, "Try using fix_hstcfg=1 if " 1801da177e4SLinus Torvalds "you experience problems\n"); 1811da177e4SLinus Torvalds } 1821da177e4SLinus Torvalds } 1831da177e4SLinus Torvalds 1841da177e4SLinus Torvalds /* If force_addr is set, we program the new address here. Just to make 1851da177e4SLinus Torvalds sure, we disable the PIIX4 first. */ 1861da177e4SLinus Torvalds if (force_addr) { 1871da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe); 1881da177e4SLinus Torvalds pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba); 1891da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01); 1901da177e4SLinus Torvalds dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to " 1911da177e4SLinus Torvalds "new address %04x!\n", piix4_smba); 1921da177e4SLinus Torvalds } else if ((temp & 1) == 0) { 1931da177e4SLinus Torvalds if (force) { 1941da177e4SLinus Torvalds /* This should never need to be done, but has been 1951da177e4SLinus Torvalds * noted that many Dell machines have the SMBus 1961da177e4SLinus Torvalds * interface on the PIIX4 disabled!? NOTE: This assumes 1971da177e4SLinus Torvalds * I/O space and other allocations WERE done by the 1981da177e4SLinus Torvalds * Bios! Don't complain if your hardware does weird 1991da177e4SLinus Torvalds * things after enabling this. :') Check for Bios 2001da177e4SLinus Torvalds * updates before resorting to this. 2011da177e4SLinus Torvalds */ 2021da177e4SLinus Torvalds pci_write_config_byte(PIIX4_dev, SMBHSTCFG, 2031da177e4SLinus Torvalds temp | 1); 2041da177e4SLinus Torvalds dev_printk(KERN_NOTICE, &PIIX4_dev->dev, 2051da177e4SLinus Torvalds "WARNING: SMBus interface has been " 2061da177e4SLinus Torvalds "FORCEFULLY ENABLED!\n"); 2071da177e4SLinus Torvalds } else { 2081da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, 2091da177e4SLinus Torvalds "Host SMBus controller not enabled!\n"); 2101da177e4SLinus Torvalds release_region(piix4_smba, SMBIOSIZE); 2111da177e4SLinus Torvalds piix4_smba = 0; 2121da177e4SLinus Torvalds return -ENODEV; 2131da177e4SLinus Torvalds } 2141da177e4SLinus Torvalds } 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds if ((temp & 0x0E) == 8) 2171da177e4SLinus Torvalds dev_dbg(&PIIX4_dev->dev, "Using Interrupt 9 for SMBus.\n"); 2181da177e4SLinus Torvalds else if ((temp & 0x0E) == 0) 2191da177e4SLinus Torvalds dev_dbg(&PIIX4_dev->dev, "Using Interrupt SMI# for SMBus.\n"); 2201da177e4SLinus Torvalds else 2211da177e4SLinus Torvalds dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration " 2221da177e4SLinus Torvalds "(or code out of date)!\n"); 2231da177e4SLinus Torvalds 2241da177e4SLinus Torvalds pci_read_config_byte(PIIX4_dev, SMBREV, &temp); 2251da177e4SLinus Torvalds dev_dbg(&PIIX4_dev->dev, "SMBREV = 0x%X\n", temp); 2261da177e4SLinus Torvalds dev_dbg(&PIIX4_dev->dev, "SMBA = 0x%X\n", piix4_smba); 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds return 0; 2291da177e4SLinus Torvalds } 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds /* Another internally used function */ 2321da177e4SLinus Torvalds static int piix4_transaction(void) 2331da177e4SLinus Torvalds { 2341da177e4SLinus Torvalds int temp; 2351da177e4SLinus Torvalds int result = 0; 2361da177e4SLinus Torvalds int timeout = 0; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds dev_dbg(&piix4_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, " 2391da177e4SLinus Torvalds "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 2401da177e4SLinus Torvalds inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 2411da177e4SLinus Torvalds inb_p(SMBHSTDAT1)); 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds /* Make sure the SMBus host is ready to start transmitting */ 2441da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 2451da177e4SLinus Torvalds dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). " 2461da177e4SLinus Torvalds "Resetting...\n", temp); 2471da177e4SLinus Torvalds outb_p(temp, SMBHSTSTS); 2481da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 2491da177e4SLinus Torvalds dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp); 2501da177e4SLinus Torvalds return -1; 2511da177e4SLinus Torvalds } else { 2521da177e4SLinus Torvalds dev_dbg(&piix4_adapter.dev, "Successfull!\n"); 2531da177e4SLinus Torvalds } 2541da177e4SLinus Torvalds } 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds /* start the transaction by setting bit 6 */ 2571da177e4SLinus Torvalds outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ 2601da177e4SLinus Torvalds do { 2611da177e4SLinus Torvalds msleep(1); 2621da177e4SLinus Torvalds temp = inb_p(SMBHSTSTS); 2631da177e4SLinus Torvalds } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds /* If the SMBus is still busy, we give up */ 2661da177e4SLinus Torvalds if (timeout >= MAX_TIMEOUT) { 2671da177e4SLinus Torvalds dev_err(&piix4_adapter.dev, "SMBus Timeout!\n"); 2681da177e4SLinus Torvalds result = -1; 2691da177e4SLinus Torvalds } 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds if (temp & 0x10) { 2721da177e4SLinus Torvalds result = -1; 2731da177e4SLinus Torvalds dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n"); 2741da177e4SLinus Torvalds } 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds if (temp & 0x08) { 2771da177e4SLinus Torvalds result = -1; 2781da177e4SLinus Torvalds dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be " 2791da177e4SLinus Torvalds "locked until next hard reset. (sorry!)\n"); 2801da177e4SLinus Torvalds /* Clock stops and slave is stuck in mid-transmission */ 2811da177e4SLinus Torvalds } 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds if (temp & 0x04) { 2841da177e4SLinus Torvalds result = -1; 2851da177e4SLinus Torvalds dev_dbg(&piix4_adapter.dev, "Error: no response!\n"); 2861da177e4SLinus Torvalds } 2871da177e4SLinus Torvalds 2881da177e4SLinus Torvalds if (inb_p(SMBHSTSTS) != 0x00) 2891da177e4SLinus Torvalds outb_p(inb(SMBHSTSTS), SMBHSTSTS); 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 2921da177e4SLinus Torvalds dev_err(&piix4_adapter.dev, "Failed reset at end of " 2931da177e4SLinus Torvalds "transaction (%02x)\n", temp); 2941da177e4SLinus Torvalds } 2951da177e4SLinus Torvalds dev_dbg(&piix4_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, " 2961da177e4SLinus Torvalds "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 2971da177e4SLinus Torvalds inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 2981da177e4SLinus Torvalds inb_p(SMBHSTDAT1)); 2991da177e4SLinus Torvalds return result; 3001da177e4SLinus Torvalds } 3011da177e4SLinus Torvalds 3021da177e4SLinus Torvalds /* Return -1 on error. */ 3031da177e4SLinus Torvalds static s32 piix4_access(struct i2c_adapter * adap, u16 addr, 3041da177e4SLinus Torvalds unsigned short flags, char read_write, 3051da177e4SLinus Torvalds u8 command, int size, union i2c_smbus_data * data) 3061da177e4SLinus Torvalds { 3071da177e4SLinus Torvalds int i, len; 3081da177e4SLinus Torvalds 3091da177e4SLinus Torvalds switch (size) { 3101da177e4SLinus Torvalds case I2C_SMBUS_PROC_CALL: 3111da177e4SLinus Torvalds dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 3121da177e4SLinus Torvalds return -1; 3131da177e4SLinus Torvalds case I2C_SMBUS_QUICK: 3141da177e4SLinus Torvalds outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 3151da177e4SLinus Torvalds SMBHSTADD); 3161da177e4SLinus Torvalds size = PIIX4_QUICK; 3171da177e4SLinus Torvalds break; 3181da177e4SLinus Torvalds case I2C_SMBUS_BYTE: 3191da177e4SLinus Torvalds outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 3201da177e4SLinus Torvalds SMBHSTADD); 3211da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) 3221da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 3231da177e4SLinus Torvalds size = PIIX4_BYTE; 3241da177e4SLinus Torvalds break; 3251da177e4SLinus Torvalds case I2C_SMBUS_BYTE_DATA: 3261da177e4SLinus Torvalds outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 3271da177e4SLinus Torvalds SMBHSTADD); 3281da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 3291da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) 3301da177e4SLinus Torvalds outb_p(data->byte, SMBHSTDAT0); 3311da177e4SLinus Torvalds size = PIIX4_BYTE_DATA; 3321da177e4SLinus Torvalds break; 3331da177e4SLinus Torvalds case I2C_SMBUS_WORD_DATA: 3341da177e4SLinus Torvalds outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 3351da177e4SLinus Torvalds SMBHSTADD); 3361da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 3371da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) { 3381da177e4SLinus Torvalds outb_p(data->word & 0xff, SMBHSTDAT0); 3391da177e4SLinus Torvalds outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); 3401da177e4SLinus Torvalds } 3411da177e4SLinus Torvalds size = PIIX4_WORD_DATA; 3421da177e4SLinus Torvalds break; 3431da177e4SLinus Torvalds case I2C_SMBUS_BLOCK_DATA: 3441da177e4SLinus Torvalds outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 3451da177e4SLinus Torvalds SMBHSTADD); 3461da177e4SLinus Torvalds outb_p(command, SMBHSTCMD); 3471da177e4SLinus Torvalds if (read_write == I2C_SMBUS_WRITE) { 3481da177e4SLinus Torvalds len = data->block[0]; 3491da177e4SLinus Torvalds if (len < 0) 3501da177e4SLinus Torvalds len = 0; 3511da177e4SLinus Torvalds if (len > 32) 3521da177e4SLinus Torvalds len = 32; 3531da177e4SLinus Torvalds outb_p(len, SMBHSTDAT0); 3541da177e4SLinus Torvalds i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 3551da177e4SLinus Torvalds for (i = 1; i <= len; i++) 3561da177e4SLinus Torvalds outb_p(data->block[i], SMBBLKDAT); 3571da177e4SLinus Torvalds } 3581da177e4SLinus Torvalds size = PIIX4_BLOCK_DATA; 3591da177e4SLinus Torvalds break; 3601da177e4SLinus Torvalds } 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds if (piix4_transaction()) /* Error in transaction */ 3651da177e4SLinus Torvalds return -1; 3661da177e4SLinus Torvalds 3671da177e4SLinus Torvalds if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) 3681da177e4SLinus Torvalds return 0; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvalds switch (size) { 3721da177e4SLinus Torvalds case PIIX4_BYTE: /* Where is the result put? I assume here it is in 3731da177e4SLinus Torvalds SMBHSTDAT0 but it might just as well be in the 3741da177e4SLinus Torvalds SMBHSTCMD. No clue in the docs */ 3751da177e4SLinus Torvalds 3761da177e4SLinus Torvalds data->byte = inb_p(SMBHSTDAT0); 3771da177e4SLinus Torvalds break; 3781da177e4SLinus Torvalds case PIIX4_BYTE_DATA: 3791da177e4SLinus Torvalds data->byte = inb_p(SMBHSTDAT0); 3801da177e4SLinus Torvalds break; 3811da177e4SLinus Torvalds case PIIX4_WORD_DATA: 3821da177e4SLinus Torvalds data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 3831da177e4SLinus Torvalds break; 3841da177e4SLinus Torvalds case PIIX4_BLOCK_DATA: 3851da177e4SLinus Torvalds data->block[0] = inb_p(SMBHSTDAT0); 3861da177e4SLinus Torvalds i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 3871da177e4SLinus Torvalds for (i = 1; i <= data->block[0]; i++) 3881da177e4SLinus Torvalds data->block[i] = inb_p(SMBBLKDAT); 3891da177e4SLinus Torvalds break; 3901da177e4SLinus Torvalds } 3911da177e4SLinus Torvalds return 0; 3921da177e4SLinus Torvalds } 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvalds static u32 piix4_func(struct i2c_adapter *adapter) 3951da177e4SLinus Torvalds { 3961da177e4SLinus Torvalds return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 3971da177e4SLinus Torvalds I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 3981da177e4SLinus Torvalds I2C_FUNC_SMBUS_BLOCK_DATA; 3991da177e4SLinus Torvalds } 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvalds static struct i2c_algorithm smbus_algorithm = { 4021da177e4SLinus Torvalds .smbus_xfer = piix4_access, 4031da177e4SLinus Torvalds .functionality = piix4_func, 4041da177e4SLinus Torvalds }; 4051da177e4SLinus Torvalds 4061da177e4SLinus Torvalds static struct i2c_adapter piix4_adapter = { 4071da177e4SLinus Torvalds .owner = THIS_MODULE, 4081da177e4SLinus Torvalds .class = I2C_CLASS_HWMON, 4091da177e4SLinus Torvalds .algo = &smbus_algorithm, 4101da177e4SLinus Torvalds .name = "unset", 4111da177e4SLinus Torvalds }; 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvalds static struct pci_device_id piix4_ids[] = { 4141da177e4SLinus Torvalds { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3), 4151da177e4SLinus Torvalds .driver_data = 3 }, 4161da177e4SLinus Torvalds { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4), 4171da177e4SLinus Torvalds .driver_data = 0 }, 4181da177e4SLinus Torvalds { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5), 4191da177e4SLinus Torvalds .driver_data = 0 }, 4201da177e4SLinus Torvalds { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB6), 4211da177e4SLinus Torvalds .driver_data = 0 }, 4221da177e4SLinus Torvalds { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3), 4231da177e4SLinus Torvalds .driver_data = 3 }, 4241da177e4SLinus Torvalds { PCI_DEVICE(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_3), 4251da177e4SLinus Torvalds .driver_data = 0 }, 4261da177e4SLinus Torvalds { 0, } 4271da177e4SLinus Torvalds }; 4281da177e4SLinus Torvalds 4291da177e4SLinus Torvalds MODULE_DEVICE_TABLE (pci, piix4_ids); 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvalds static int __devinit piix4_probe(struct pci_dev *dev, 4321da177e4SLinus Torvalds const struct pci_device_id *id) 4331da177e4SLinus Torvalds { 4341da177e4SLinus Torvalds int retval; 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvalds retval = piix4_setup(dev, id); 4371da177e4SLinus Torvalds if (retval) 4381da177e4SLinus Torvalds return retval; 4391da177e4SLinus Torvalds 4401da177e4SLinus Torvalds /* set up the driverfs linkage to our parent device */ 4411da177e4SLinus Torvalds piix4_adapter.dev.parent = &dev->dev; 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds snprintf(piix4_adapter.name, I2C_NAME_SIZE, 4441da177e4SLinus Torvalds "SMBus PIIX4 adapter at %04x", piix4_smba); 4451da177e4SLinus Torvalds 4461da177e4SLinus Torvalds if ((retval = i2c_add_adapter(&piix4_adapter))) { 4471da177e4SLinus Torvalds dev_err(&dev->dev, "Couldn't register adapter!\n"); 4481da177e4SLinus Torvalds release_region(piix4_smba, SMBIOSIZE); 4491da177e4SLinus Torvalds piix4_smba = 0; 4501da177e4SLinus Torvalds } 4511da177e4SLinus Torvalds 4521da177e4SLinus Torvalds return retval; 4531da177e4SLinus Torvalds } 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds static void __devexit piix4_remove(struct pci_dev *dev) 4561da177e4SLinus Torvalds { 4571da177e4SLinus Torvalds if (piix4_smba) { 4581da177e4SLinus Torvalds i2c_del_adapter(&piix4_adapter); 4591da177e4SLinus Torvalds release_region(piix4_smba, SMBIOSIZE); 4601da177e4SLinus Torvalds piix4_smba = 0; 4611da177e4SLinus Torvalds } 4621da177e4SLinus Torvalds } 4631da177e4SLinus Torvalds 4641da177e4SLinus Torvalds static struct pci_driver piix4_driver = { 4651da177e4SLinus Torvalds .name = "piix4_smbus", 4661da177e4SLinus Torvalds .id_table = piix4_ids, 4671da177e4SLinus Torvalds .probe = piix4_probe, 4681da177e4SLinus Torvalds .remove = __devexit_p(piix4_remove), 4691da177e4SLinus Torvalds }; 4701da177e4SLinus Torvalds 4711da177e4SLinus Torvalds static int __init i2c_piix4_init(void) 4721da177e4SLinus Torvalds { 4731da177e4SLinus Torvalds return pci_register_driver(&piix4_driver); 4741da177e4SLinus Torvalds } 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvalds static void __exit i2c_piix4_exit(void) 4771da177e4SLinus Torvalds { 4781da177e4SLinus Torvalds pci_unregister_driver(&piix4_driver); 4791da177e4SLinus Torvalds } 4801da177e4SLinus Torvalds 4811da177e4SLinus Torvalds MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and " 4821da177e4SLinus Torvalds "Philip Edelbrock <phil@netroedge.com>"); 4831da177e4SLinus Torvalds MODULE_DESCRIPTION("PIIX4 SMBus driver"); 4841da177e4SLinus Torvalds MODULE_LICENSE("GPL"); 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds module_init(i2c_piix4_init); 4871da177e4SLinus Torvalds module_exit(i2c_piix4_exit); 488