Commit f289aa67 authored by Linus Torvalds's avatar Linus Torvalds

Merge bk://kernel.bkbits.net/gregkh/linux/i2c-2.5

into home.transmeta.com:/home/torvalds/v2.5/linux
parents 76c25284 0b4a5d51
......@@ -76,6 +76,24 @@ config I2C_I801
in the lm_sensors package, which you can download at
http://www.lm-sensors.nu
config I2C_ISA
tristate " ISA Bus support"
depends on I2C && I2C_PROC && ISA && EXPERIMENTAL
help
If you say yes to this option, support will be included for i2c
interfaces that are on the ISA bus.
This can also be built as a module which can be inserted and removed
while the kernel is running. If you want to compile it as a module,
say M here and read <file:Documentation/modules.txt>.
The module will be called i2c-isa.
You will also need the latest user-space utilties: you can find them
in the lm_sensors package, which you can download at
http://www.lm-sensors.nu
config I2C_PIIX4
tristate " Intel PIIX4"
depends on I2C && I2C_PROC && PCI && EXPERIMENTAL
......
......@@ -6,4 +6,5 @@ obj-$(CONFIG_I2C_ALI15X3) += i2c-ali15x3.o
obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o
obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
obj-$(CONFIG_I2C_I801) += i2c-i801.o
obj-$(CONFIG_I2C_ISA) += i2c-isa.o
obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o
......@@ -60,6 +60,8 @@
/* Note: we assume there can only be one ALI15X3, with one SMBus interface */
/* #define DEBUG 1 */
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/kernel.h>
......@@ -129,55 +131,52 @@ MODULE_PARM(force_addr, "i");
MODULE_PARM_DESC(force_addr,
"Initialize the base address of the i2c controller");
static void ali15x3_do_pause(unsigned int amount);
static int ali15x3_transaction(void);
static unsigned short ali15x3_smba = 0;
int ali15x3_setup(struct pci_dev *ALI15X3_dev)
static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
{
u16 a;
unsigned char temp;
/* Check the following things:
/* Check the following things:
- SMB I/O address is initialized
- Device is enabled
- We can use the addresses
*/
*/
/* Unlock the register.
/* Unlock the register.
The data sheet says that the address registers are read-only
if the lock bits are 1, but in fact the address registers
are zero unless you clear the lock bits.
*/
*/
pci_read_config_byte(ALI15X3_dev, SMBATPC, &temp);
if (temp & ALI15X3_LOCK) {
temp &= ~ALI15X3_LOCK;
pci_write_config_byte(ALI15X3_dev, SMBATPC, temp);
}
/* Determine the address of the SMBus area */
/* Determine the address of the SMBus area */
pci_read_config_word(ALI15X3_dev, SMBBA, &ali15x3_smba);
ali15x3_smba &= (0xffff & ~(ALI15X3_SMB_IOSIZE - 1));
if (ali15x3_smba == 0 && force_addr == 0) {
printk
("i2c-ali15x3.o: ALI15X3_smb region uninitialized - upgrade BIOS or use force_addr=0xaddr\n");
dev_err(&ALI15X3_dev->dev, "ALI15X3_smb region uninitialized "
"- upgrade BIOS or use force_addr=0xaddr\n");
return -ENODEV;
}
if(force_addr)
ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1);
if (check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) {
printk
("i2c-ali15x3.o: ALI15X3_smb region 0x%x already in use!\n",
if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb")) {
dev_err(&ALI15X3_dev->dev,
"ALI15X3_smb region 0x%x already in use!\n",
ali15x3_smba);
return -ENODEV;
}
if(force_addr) {
printk("i2c-ali15x3.o: forcing ISA address 0x%04X\n", ali15x3_smba);
dev_info(&ALI15X3_dev->dev, "forcing ISA address 0x%04X\n",
ali15x3_smba);
if (PCIBIOS_SUCCESSFUL !=
pci_write_config_word(ALI15X3_dev, SMBBA, ali15x3_smba))
return -ENODEV;
......@@ -186,68 +185,60 @@ int ali15x3_setup(struct pci_dev *ALI15X3_dev)
return -ENODEV;
if ((a & ~(ALI15X3_SMB_IOSIZE - 1)) != ali15x3_smba) {
/* make sure it works */
printk("i2c-ali15x3.o: force address failed - not supported?\n");
dev_err(&ALI15X3_dev->dev,
"force address failed - not supported?\n");
return -ENODEV;
}
}
/* check if whole device is enabled */
/* check if whole device is enabled */
pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp);
if ((temp & 1) == 0) {
printk("i2c-ali15x3: enabling SMBus device\n");
dev_info(&ALI15X3_dev->dev, "enabling SMBus device\n");
pci_write_config_byte(ALI15X3_dev, SMBCOM, temp | 0x01);
}
/* Is SMB Host controller enabled? */
/* Is SMB Host controller enabled? */
pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp);
if ((temp & 1) == 0) {
printk("i2c-ali15x3: enabling SMBus controller\n");
dev_info(&ALI15X3_dev->dev, "enabling SMBus controller\n");
pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 0x01);
}
/* set SMB clock to 74KHz as recommended in data sheet */
/* set SMB clock to 74KHz as recommended in data sheet */
pci_write_config_byte(ALI15X3_dev, SMBCLK, 0x20);
/* Everything is happy, let's grab the memory and set things up. */
request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb");
#ifdef DEBUG
/*
/*
The interrupt routing for SMB is set up in register 0x77 in the
1533 ISA Bridge device, NOT in the 7101 device.
Don't bother with finding the 1533 device and reading the register.
if ((....... & 0x0F) == 1)
printk("i2c-ali15x3.o: ALI15X3 using Interrupt 9 for SMBus.\n");
*/
dev_dbg(&ALI15X3_dev->dev, "ALI15X3 using Interrupt 9 for SMBus.\n");
*/
pci_read_config_byte(ALI15X3_dev, SMBREV, &temp);
printk("i2c-ali15x3.o: SMBREV = 0x%X\n", temp);
printk("i2c-ali15x3.o: ALI15X3_smba = 0x%X\n", ali15x3_smba);
#endif /* DEBUG */
dev_dbg(&ALI15X3_dev->dev, "SMBREV = 0x%X\n", temp);
dev_dbg(&ALI15X3_dev->dev, "iALI15X3_smba = 0x%X\n", ali15x3_smba);
return 0;
}
/* Internally used pause function */
void ali15x3_do_pause(unsigned int amount)
static void ali15x3_do_pause(unsigned int amount)
{
current->state = TASK_INTERRUPTIBLE;
schedule_timeout(amount);
}
/* Another internally used function */
int ali15x3_transaction(void)
static int ali15x3_transaction(struct i2c_adapter *adap)
{
int temp;
int result = 0;
int timeout = 0;
#ifdef DEBUG
printk
("i2c-ali15x3.o: Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, "
"DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBHSTDAT1));
#endif
dev_dbg(&adap->dev, "Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, "
"ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS),
inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
/* get status */
temp = inb_p(SMBHSTSTS);
......@@ -255,43 +246,32 @@ int ali15x3_transaction(void)
/* Make sure the SMBus host is ready to start transmitting */
/* Check the busy bit first */
if (temp & ALI15X3_STS_BUSY) {
/*
If the host controller is still busy, it may have timed out in the previous transaction,
resulting in a "SMBus Timeout" printk.
/*
If the host controller is still busy, it may have timed out in the
previous transaction, resulting in a "SMBus Timeout" Dev.
I've tried the following to reset a stuck busy bit.
1. Reset the controller with an ABORT command.
(this doesn't seem to clear the controller if an external device is hung)
2. Reset the controller and the other SMBus devices with a T_OUT command.
(this clears the host busy bit if an external device is hung,
but it comes back upon a new access to a device)
(this doesn't seem to clear the controller if an external
device is hung)
2. Reset the controller and the other SMBus devices with a
T_OUT command. (this clears the host busy bit if an
external device is hung, but it comes back upon a new access
to a device)
3. Disable and reenable the controller in SMBHSTCFG
Worst case, nothing seems to work except power reset.
*/
/* Abort - reset the host controller */
/*
#ifdef DEBUG
printk("i2c-ali15x3.o: Resetting host controller to clear busy condition\n",temp);
#endif
outb_p(ALI15X3_ABORT, SMBHSTCNT);
temp = inb_p(SMBHSTSTS);
if (temp & ALI15X3_STS_BUSY) {
*/
/*
*/
/* Abort - reset the host controller */
/*
Try resetting entire SMB bus, including other devices -
This may not work either - it clears the BUSY bit but
then the BUSY bit may come back on when you try and use the chip again.
If that's the case you are stuck.
*/
printk
("i2c-ali15x3.o: Resetting entire SMB Bus to clear busy condition (%02x)\n",
temp);
*/
dev_info(&adap->dev, "Resetting entire SMB Bus to "
"clear busy condition (%02x)\n", temp);
outb_p(ALI15X3_T_OUT, SMBHSTCNT);
temp = inb_p(SMBHSTSTS);
}
/*
}
*/
/* now check the error bits and the busy bit */
if (temp & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) {
......@@ -302,8 +282,8 @@ int ali15x3_transaction(void)
/* this is probably going to be correctable only by a power reset
as one of the bits now appears to be stuck */
/* This may be a bus or device with electrical problems. */
printk
("i2c-ali15x3.o: SMBus reset failed! (0x%02x) - controller or device on bus is probably hung\n",
dev_err(&adap->dev, "SMBus reset failed! (0x%02x) - "
"controller or device on bus is probably hung\n",
temp);
return -1;
}
......@@ -328,48 +308,41 @@ int ali15x3_transaction(void)
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
result = -1;
printk("i2c-ali15x3.o: SMBus Timeout!\n");
dev_err(&adap->dev, "SMBus Timeout!\n");
}
if (temp & ALI15X3_STS_TERM) {
result = -1;
#ifdef DEBUG
printk("i2c-ali15x3.o: Error: Failed bus transaction\n");
#endif
dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
}
/*
Unfortunately the ALI SMB controller maps "no response" and "bus collision"
into a single bit. No reponse is the usual case so don't
/*
Unfortunately the ALI SMB controller maps "no response" and "bus
collision" into a single bit. No reponse is the usual case so don't
do a printk.
This means that bus collisions go unreported.
*/
*/
if (temp & ALI15X3_STS_COLL) {
result = -1;
#ifdef DEBUG
printk
("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n",
dev_dbg(&adap->dev,
"Error: no response or bus collision ADD=%02x\n",
inb_p(SMBHSTADD));
#endif
}
/* haven't ever seen this */
/* haven't ever seen this */
if (temp & ALI15X3_STS_DEV) {
result = -1;
printk("i2c-ali15x3.o: Error: device error\n");
dev_err(&adap->dev, "Error: device error\n");
}
#ifdef DEBUG
printk
("i2c-ali15x3.o: Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, "
"DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBHSTDAT1));
#endif
dev_dbg(&adap->dev, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, "
"ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS),
inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
return result;
}
/* Return -1 on error. */
s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command,
int size, union i2c_smbus_data * data)
{
......@@ -377,9 +350,9 @@ s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
int temp;
int timeout;
/* clear all the bits (clear-on-write) */
/* clear all the bits (clear-on-write) */
outb_p(0xFF, SMBHSTSTS);
/* make sure SMBus is idle */
/* make sure SMBus is idle */
temp = inb_p(SMBHSTSTS);
for (timeout = 0;
(timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE);
......@@ -388,14 +361,12 @@ s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
temp = inb_p(SMBHSTSTS);
}
if (timeout >= MAX_TIMEOUT) {
printk("i2c-ali15x3.o: Idle wait Timeout! STS=0x%02x\n",
temp);
dev_err(&adap->dev, "Idle wait Timeout! STS=0x%02x\n", temp);
}
switch (size) {
case I2C_SMBUS_PROC_CALL:
printk
("i2c-ali15x3.o: I2C_SMBUS_PROC_CALL not supported!\n");
dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
return -1;
case I2C_SMBUS_QUICK:
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
......@@ -442,7 +413,8 @@ s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
data->block[0] = len;
}
outb_p(len, SMBHSTDAT0);
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */
/* Reset SMBBLKDAT */
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT);
for (i = 1; i <= len; i++)
outb_p(data->block[i], SMBBLKDAT);
}
......@@ -452,7 +424,7 @@ s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
outb_p(size, SMBHSTCNT); /* output command */
if (ali15x3_transaction()) /* Error in transaction */
if (ali15x3_transaction(adap)) /* Error in transaction */
return -1;
if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK))
......@@ -474,22 +446,19 @@ s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
if (len > 32)
len = 32;
data->block[0] = len;
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */
/* Reset SMBBLKDAT */
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT);
for (i = 1; i <= data->block[0]; i++) {
data->block[i] = inb_p(SMBBLKDAT);
#ifdef DEBUG
printk
("i2c-ali15x3.o: Blk: len=%d, i=%d, data=%02x\n",
dev_dbg(&adap->dev, "Blk: len=%d, i=%d, data=%02x\n",
len, i, data->block[i]);
#endif /* DEBUG */
}
break;
}
return 0;
}
u32 ali15x3_func(struct i2c_adapter *adapter)
static u32 ali15x3_func(struct i2c_adapter *adapter)
{
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
......@@ -510,8 +479,6 @@ static struct i2c_adapter ali15x3_adapter = {
.algo = &smbus_algorithm,
};
static struct pci_device_id ali15x3_ids[] __devinitdata = {
{
.vendor = PCI_VENDOR_ID_AL,
......@@ -525,9 +492,8 @@ static struct pci_device_id ali15x3_ids[] __devinitdata = {
static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
if (ali15x3_setup(dev)) {
printk
("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n");
dev_err(&dev->dev,
"ALI15X3 not detected, module not inserted.\n");
return -ENODEV;
}
......@@ -557,17 +523,15 @@ static int __init i2c_ali15x3_init(void)
return pci_module_init(&ali15x3_driver);
}
static void __exit i2c_ali15x3_exit(void)
{
pci_unregister_driver(&ali15x3_driver);
release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE);
}
MODULE_AUTHOR
("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker <mdsxyz123@yahoo.com>");
MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl>, "
"Philip Edelbrock <phil@netroedge.com>, "
"and Mark D. Studebaker <mdsxyz123@yahoo.com>");
MODULE_DESCRIPTION("ALI15X3 SMBus driver");
MODULE_LICENSE("GPL");
......
......@@ -35,6 +35,8 @@
Note: we assume there can only be one device, with one SMBus interface.
*/
/* #define DEBUG 1 */
#include <linux/version.h>
#include <linux/module.h>
#include <linux/pci.h>
......@@ -46,8 +48,6 @@
#include <linux/init.h>
#include <asm/io.h>
#define DRV_NAME "i2c-amd756"
/* AMD756 SMBus address offsets */
#define SMB_ADDR_OFFSET 0xE0
#define SMB_IOSIZE 16
......@@ -117,20 +117,20 @@ static void amd756_do_pause(unsigned int amount)
#define GE_ABORT (1 << 5)
static int amd756_transaction(void)
static int amd756_transaction(struct i2c_adapter *adap)
{
int temp;
int result = 0;
int timeout = 0;
pr_debug(DRV_NAME
": Transaction (pre): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n",
inw_p(SMB_GLOBAL_STATUS), inw_p(SMB_GLOBAL_ENABLE),
inw_p(SMB_HOST_ADDRESS), inb_p(SMB_HOST_DATA));
dev_dbg(&adap->dev, ": Transaction (pre): GS=%04x, GE=%04x, ADD=%04x, "
"DAT=%04x\n", inw_p(SMB_GLOBAL_STATUS),
inw_p(SMB_GLOBAL_ENABLE), inw_p(SMB_HOST_ADDRESS),
inb_p(SMB_HOST_DATA));
/* Make sure the SMBus host is ready to start transmitting */
if ((temp = inw_p(SMB_GLOBAL_STATUS)) & (GS_HST_STS | GS_SMB_STS)) {
pr_debug(DRV_NAME ": SMBus busy (%04x). Waiting... \n", temp);
dev_dbg(&adap->dev, ": SMBus busy (%04x). Waiting... \n", temp);
do {
amd756_do_pause(1);
temp = inw_p(SMB_GLOBAL_STATUS);
......@@ -138,7 +138,7 @@ static int amd756_transaction(void)
(timeout++ < MAX_TIMEOUT));
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
pr_debug(DRV_NAME ": Busy wait timeout (%04x)\n", temp);
dev_dbg(&adap->dev, ": Busy wait timeout (%04x)\n", temp);
goto abort;
}
timeout = 0;
......@@ -155,46 +155,46 @@ static int amd756_transaction(void)
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
pr_debug(DRV_NAME ": Completion timeout!\n");
dev_dbg(&adap->dev, ": Completion timeout!\n");
goto abort;
}
if (temp & GS_PRERR_STS) {
result = -1;
pr_debug(DRV_NAME ": SMBus Protocol error (no response)!\n");
dev_dbg(&adap->dev, ": SMBus Protocol error (no response)!\n");
}
if (temp & GS_COL_STS) {
result = -1;
printk(KERN_WARNING DRV_NAME " SMBus collision!\n");
dev_warn(&adap->dev, " SMBus collision!\n");
}
if (temp & GS_TO_STS) {
result = -1;
pr_debug(DRV_NAME ": SMBus protocol timeout!\n");
dev_dbg(&adap->dev, ": SMBus protocol timeout!\n");
}
if (temp & GS_HCYC_STS)
pr_debug(DRV_NAME " SMBus protocol success!\n");
dev_dbg(&adap->dev, " SMBus protocol success!\n");
outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS);
#ifdef DEBUG
if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_CLEAR_STS) != 0x00) {
pr_debug(DRV_NAME
dev_dbg(&adap->dev,
": Failed reset at end of transaction (%04x)\n", temp);
}
#endif
pr_debug(DRV_NAME
dev_dbg(&adap->dev,
": Transaction (post): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n",
inw_p(SMB_GLOBAL_STATUS), inw_p(SMB_GLOBAL_ENABLE),
inw_p(SMB_HOST_ADDRESS), inb_p(SMB_HOST_DATA));
#endif
return result;
abort:
printk(KERN_WARNING DRV_NAME ": Sending abort.\n");
dev_warn(&adap->dev, ": Sending abort.\n");
outw_p(inw(SMB_GLOBAL_ENABLE) | GE_ABORT, SMB_GLOBAL_ENABLE);
amd756_do_pause(100);
outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS);
......@@ -211,7 +211,7 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
/** TODO: Should I supporte the 10-bit transfers? */
switch (size) {
case I2C_SMBUS_PROC_CALL:
pr_debug(DRV_NAME ": I2C_SMBUS_PROC_CALL not supported!\n");
dev_dbg(&adap->dev, ": I2C_SMBUS_PROC_CALL not supported!\n");
/* TODO: Well... It is supported, I'm just not sure what to do here... */
return -1;
case I2C_SMBUS_QUICK:
......@@ -266,7 +266,7 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
/* How about enabling interrupts... */
outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE);
if (amd756_transaction()) /* Error in transaction */
if (amd756_transaction(adap)) /* Error in transaction */
return -1;
if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK))
......@@ -334,7 +334,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
u8 temp;
if (amd756_ioport) {
printk(KERN_ERR DRV_NAME ": Only one device supported. "
dev_err(&pdev->dev, ": Only one device supported. "
"(you have a strange motherboard, btw..)\n");
return -ENODEV;
}
......@@ -351,7 +351,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
pci_read_config_byte(pdev, SMBGCFG, &temp);
if ((temp & 128) == 0) {
printk(KERN_ERR DRV_NAME
dev_err(&pdev->dev,
": Error: SMBus controller I/O not enabled!\n");
return -ENODEV;
}
......@@ -364,16 +364,14 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
}
if (!request_region(amd756_ioport, SMB_IOSIZE, "amd756-smbus")) {
printk(KERN_ERR DRV_NAME
": SMB region 0x%x already in use!\n", amd756_ioport);
dev_err(&pdev->dev, ": SMB region 0x%x already in use!\n",
amd756_ioport);
return -ENODEV;
}
#ifdef DEBUG
pci_read_config_byte(pdev, SMBREV, &temp);
printk(KERN_DEBUG DRV_NAME ": SMBREV = 0x%X\n", temp);
printk(KERN_DEBUG DRV_NAME ": AMD756_smba = 0x%X\n", amd756_ioport);
#endif
dev_dbg(&pdev->dev, ": SMBREV = 0x%X\n", temp);
dev_dbg(&pdev->dev, ": AMD756_smba = 0x%X\n", amd756_ioport);
/* set up the driverfs linkage to our parent device */
amd756_adapter.dev.parent = &pdev->dev;
......@@ -383,7 +381,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
error = i2c_add_adapter(&amd756_adapter);
if (error) {
printk(KERN_ERR DRV_NAME
dev_err(&pdev->dev,
": Adapter registration failed, module not inserted.\n");
goto out_err;
}
......
......@@ -74,7 +74,7 @@ unsigned int amd_ec_wait_write(struct amd_smbus *smbus)
udelay(1);
if (!timeout) {
printk(KERN_WARNING "i2c-amd8111.c: Timeout while waiting for IBF to clear\n");
dev_warn(&smbus->dev->dev, "Timeout while waiting for IBF to clear\n");
return -1;
}
......@@ -89,7 +89,7 @@ unsigned int amd_ec_wait_read(struct amd_smbus *smbus)
udelay(1);
if (!timeout) {
printk(KERN_WARNING "i2c-amd8111.c: Timeout while waiting for OBF to set\n");
dev_warn(&smbus->dev->dev, "Timeout while waiting for OBF to set\n");
return -1;
}
......@@ -256,11 +256,11 @@ s32 amd8111_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
case I2C_SMBUS_BLOCK_DATA_PEC:
case I2C_SMBUS_PROC_CALL_PEC:
case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
printk(KERN_WARNING "i2c-amd8111.c: Unexpected software PEC transaction %d\n.", size);
dev_warn(&adap->dev, "Unexpected software PEC transaction %d\n.", size);
return -1;
default:
printk(KERN_WARNING "i2c-amd8111.c: Unsupported transaction %d\n", size);
dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
return -1;
}
......@@ -392,7 +392,7 @@ static void __devexit amd8111_remove(struct pci_dev *dev)
}
static struct pci_driver amd8111_driver = {
.name = "amd8111 smbus",
.name = "amd8111 smbus 2",
.id_table = amd8111_ids,
.probe = amd8111_probe,
.remove = __devexit_p(amd8111_remove),
......
......@@ -49,27 +49,10 @@
#include <linux/i2c.h>
#include <asm/io.h>
MODULE_LICENSE("GPL");
#ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC
#define HAVE_PEC
#endif
#ifndef PCI_DEVICE_ID_INTEL_82801CA_SMBUS
#define PCI_DEVICE_ID_INTEL_82801CA_SMBUS 0x2483
#endif
#ifndef PCI_DEVICE_ID_INTEL_82801DB_SMBUS
#define PCI_DEVICE_ID_INTEL_82801DB_SMBUS 0x24C3
#endif
static int supported[] = {PCI_DEVICE_ID_INTEL_82801AA_3,
PCI_DEVICE_ID_INTEL_82801AB_3,
PCI_DEVICE_ID_INTEL_82801BA_2,
PCI_DEVICE_ID_INTEL_82801CA_SMBUS,
PCI_DEVICE_ID_INTEL_82801DB_SMBUS,
0 };
/* I801 SMBus address offsets */
#define SMBHSTSTS (0 + i801_smba)
#define SMBHSTCNT (2 + i801_smba)
......@@ -119,10 +102,6 @@ MODULE_PARM_DESC(force_addr,
"Forcibly enable the I801 at the given address. "
"EXTREMELY DANGEROUS!");
static void i801_do_pause(unsigned int amount);
static int i801_transaction(void);
static int i801_block_transaction(union i2c_smbus_data *data,
......@@ -135,7 +114,6 @@ static int isich4;
static int i801_setup(struct pci_dev *dev)
{
int error_return = 0;
int *num = supported;
unsigned char temp;
/* Note: we keep on searching until we have found 'function 3' */
......@@ -143,101 +121,90 @@ static int i801_setup(struct pci_dev *dev)
return -ENODEV;
I801_dev = dev;
isich4 = *num == PCI_DEVICE_ID_INTEL_82801DB_SMBUS;
if (dev->device == PCI_DEVICE_ID_INTEL_82801DB_3)
isich4 = 1;
else
isich4 = 0;
/* Determine the address of the SMBus areas */
/* Determine the address of the SMBus areas */
if (force_addr) {
i801_smba = force_addr & 0xfff0;
} else {
pci_read_config_word(I801_dev, SMBBA, &i801_smba);
i801_smba &= 0xfff0;
if(i801_smba == 0) {
printk(KERN_ERR "i2c-i801.o: SMB base address uninitialized - upgrade BIOS or use force_addr=0xaddr\n");
dev_err(&dev->dev, "SMB base address uninitialized"
"- upgrade BIOS or use force_addr=0xaddr\n");
return -ENODEV;
}
}
if (check_region(i801_smba, (isich4 ? 16 : 8))) {
printk
(KERN_ERR "i2c-i801.o: I801_smb region 0x%x already in use!\n",
if (!request_region(i801_smba, (isich4 ? 16 : 8), "i801-smbus")) {
dev_err(&dev->dev, "I801_smb region 0x%x already in use!\n",
i801_smba);
error_return = -ENODEV;
error_return = -EBUSY;
goto END;
}
pci_read_config_byte(I801_dev, SMBHSTCFG, &temp);
temp &= ~SMBHSTCFG_I2C_EN; /* SMBus timing */
pci_write_config_byte(I801_dev, SMBHSTCFG, temp);
/* If force_addr is set, we program the new address here. Just to make
/* If force_addr is set, we program the new address here. Just to make
sure, we disable the device first. */
if (force_addr) {
pci_write_config_byte(I801_dev, SMBHSTCFG, temp & 0xfe);
pci_write_config_word(I801_dev, SMBBA, i801_smba);
pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 0x01);
printk
(KERN_WARNING "i2c-i801.o: WARNING: I801 SMBus interface set to new "
"address %04x!\n", i801_smba);
dev_warn(&dev->dev, "WARNING: I801 SMBus interface set to "
"new address %04x!\n", i801_smba);
} else if ((temp & 1) == 0) {
pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 1);
printk(KERN_WARNING "i2c-i801.o: enabling SMBus device\n");
dev_warn(&dev->dev, "enabling SMBus device\n");
}
request_region(i801_smba, (isich4 ? 16 : 8), "i801-smbus");
#ifdef DEBUG
if (temp & 0x02)
printk
(KERN_DEBUG "i2c-i801.o: I801 using Interrupt SMI# for SMBus.\n");
dev_dbg(&dev->dev, "I801 using Interrupt SMI# for SMBus.\n");
else
printk
(KERN_DEBUG "i2c-i801.o: I801 using PCI Interrupt for SMBus.\n");
dev_dbg(&dev->dev, "I801 using PCI Interrupt for SMBus.\n");
pci_read_config_byte(I801_dev, SMBREV, &temp);
printk(KERN_DEBUG "i2c-i801.o: SMBREV = 0x%X\n", temp);
printk(KERN_DEBUG "i2c-i801.o: I801_smba = 0x%X\n", i801_smba);
#endif /* DEBUG */
dev_dbg(&dev->dev, "SMBREV = 0x%X\n", temp);
dev_dbg(&dev->dev, "I801_smba = 0x%X\n", i801_smba);
END:
END:
return error_return;
}
void i801_do_pause(unsigned int amount)
static void i801_do_pause(unsigned int amount)
{
current->state = TASK_INTERRUPTIBLE;
schedule_timeout(amount);
}
int i801_transaction(void)
static int i801_transaction(void)
{
int temp;
int result = 0;
int timeout = 0;
#ifdef DEBUG
printk
(KERN_DEBUG "i2c-i801.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, "
"DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD),
inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
#endif
dev_dbg(&I801_dev->dev, "Transaction (pre): CNT=%02x, CMD=%02x,"
"ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBHSTDAT1));
/* Make sure the SMBus host is ready to start transmitting */
/* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: SMBus busy (%02x). Resetting... \n",
dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting... \n",
temp);
#endif
outb_p(temp, SMBHSTSTS);
if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: Failed! (%02x)\n", temp);
#endif
dev_dbg(&I801_dev->dev, "Failed! (%02x)\n", temp);
return -1;
} else {
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: Successfull!\n");
#endif
dev_dbg(&I801_dev->dev, "Successfull!\n");
}
}
......@@ -251,55 +218,43 @@ int i801_transaction(void)
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: SMBus Timeout!\n");
dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
result = -1;
#endif
}
if (temp & 0x10) {
result = -1;
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: Error: Failed bus transaction\n");
#endif
dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n");
}
if (temp & 0x08) {
result = -1;
printk
(KERN_ERR "i2c-i801.o: Bus collision! SMBus may be locked until next hard\n"
"reset. (sorry!)\n");
dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked "
"until next hard reset. (sorry!)\n");
/* Clock stops and slave is stuck in mid-transmission */
}
if (temp & 0x04) {
result = -1;
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: Error: no response!\n");
#endif
dev_dbg(&I801_dev->dev, "Error: no response!\n");
}
if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00)
outb_p(inb(SMBHSTSTS), SMBHSTSTS);
if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
#ifdef DEBUG
printk
(KERN_DEBUG "i2c-i801.o: Failed reset at end of transaction (%02x)\n",
temp);
#endif
dev_dbg(&I801_dev->dev, "Failed reset at end of transaction"
"(%02x)\n", temp);
}
#ifdef DEBUG
printk
(KERN_DEBUG "i2c-i801.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, "
"DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD),
inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
#endif
dev_dbg(&I801_dev->dev, "Transaction (post): CNT=%02x, CMD=%02x, "
"ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBHSTDAT1));
return result;
}
/* All-inclusive block transaction function */
int i801_block_transaction(union i2c_smbus_data *data, char read_write,
static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
int command)
{
int i, len;
......@@ -316,8 +271,8 @@ int i801_block_transaction(union i2c_smbus_data *data, char read_write,
pci_write_config_byte(I801_dev, SMBHSTCFG,
hostc | SMBHSTCFG_I2C_EN);
} else {
printk("i2c-i801.o: "
"I2C_SMBUS_I2C_BLOCK_READ not supported!\n");
dev_err(&I801_dev->dev,
"I2C_SMBUS_I2C_BLOCK_READ not DB!\n");
return -1;
}
}
......@@ -343,19 +298,12 @@ int i801_block_transaction(union i2c_smbus_data *data, char read_write,
smbcmd = I801_BLOCK_LAST;
else
smbcmd = I801_BLOCK_DATA;
#if 0 /* now using HW PEC */
if(isich4 && command == I2C_SMBUS_BLOCK_DATA_PEC)
smbcmd |= I801_PEC_EN;
#endif
outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT);
#ifdef DEBUG
printk
(KERN_DEBUG "i2c-i801.o: Block (pre %d): CNT=%02x, CMD=%02x, ADD=%02x, "
"DAT0=%02x, BLKDAT=%02x\n", i, inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBBLKDAT));
#endif
dev_dbg(&I801_dev->dev, "Block (pre %d): CNT=%02x, CMD=%02x, "
"ADD=%02x, DAT0=%02x, BLKDAT=%02x\n", i,
inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT));
/* Make sure the SMBus host is ready to start transmitting */
temp = inb_p(SMBHSTSTS);
......@@ -369,34 +317,24 @@ int i801_block_transaction(union i2c_smbus_data *data, char read_write,
errmask=0x1e;
}
if (temp & errmask) {
#ifdef DEBUG
printk
(KERN_DEBUG "i2c-i801.o: SMBus busy (%02x). Resetting... \n",
temp);
#endif
dev_dbg(&I801_dev->dev, "SMBus busy (%02x). "
"Resetting... \n", temp);
outb_p(temp, SMBHSTSTS);
if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
printk
(KERN_ERR "i2c-i801.o: Reset failed! (%02x)\n",
temp);
dev_err(&I801_dev->dev,
"Reset failed! (%02x)\n", temp);
result = -1;
goto END;
}
if (i != 1) {
result = -1; /* if die in middle of block transaction, fail */
/* if die in middle of block transaction, fail */
result = -1;
goto END;
}
}
if (i == 1) {
#if 0 /* #ifdef HAVE_PEC (now using HW PEC) */
if(isich4 && command == I2C_SMBUS_BLOCK_DATA_PEC) {
if(read_write == I2C_SMBUS_WRITE)
outb_p(data->block[len + 1], SMBPEC);
}
#endif
if (i == 1)
outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT);
}
/* We will always wait for a fraction of a second! */
timeout = 0;
......@@ -410,25 +348,19 @@ int i801_block_transaction(union i2c_smbus_data *data, char read_write,
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
result = -1;
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: SMBus Timeout!\n");
#endif
dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
}
if (temp & 0x10) {
result = -1;
#ifdef DEBUG
printk
(KERN_DEBUG "i2c-i801.o: Error: Failed bus transaction\n");
#endif
dev_dbg(&I801_dev->dev,
"Error: Failed bus transaction\n");
} else if (temp & 0x08) {
result = -1;
printk(KERN_ERR "i2c-i801.o: Bus collision!\n");
dev_err(&I801_dev->dev, "Bus collision!\n");
} else if (temp & 0x04) {
result = -1;
#ifdef DEBUG
printk(KERN_DEBUG "i2c-i801.o: Error: no response!\n");
#endif
dev_dbg(&I801_dev->dev, "Error: no response!\n");
}
if (i == 1 && read_write == I2C_SMBUS_READ) {
......@@ -448,18 +380,15 @@ int i801_block_transaction(union i2c_smbus_data *data, char read_write,
if ((temp & 0x9e) != 0x00)
outb_p(temp, SMBHSTSTS); /* signals SMBBLKDAT ready */
#ifdef DEBUG
if ((temp = (0x1e & inb_p(SMBHSTSTS))) != 0x00) {
printk
(KERN_DEBUG "i2c-i801.o: Bad status (%02x) at end of transaction\n",
dev_dbg(&I801_dev->dev,
"Bad status (%02x) at end of transaction\n",
temp);
}
printk
(KERN_DEBUG "i2c-i801.o: Block (post %d): CNT=%02x, CMD=%02x, ADD=%02x, "
"DAT0=%02x, BLKDAT=%02x\n", i, inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBBLKDAT));
#endif
dev_dbg(&I801_dev->dev, "Block (post %d): CNT=%02x, CMD=%02x, "
"ADD=%02x, DAT0=%02x, BLKDAT=%02x\n", i,
inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
inb_p(SMBHSTDAT0), inb_p(SMBBLKDAT));
if (result < 0)
goto END;
......@@ -476,13 +405,8 @@ int i801_block_transaction(union i2c_smbus_data *data, char read_write,
&& (timeout++ < MAX_TIMEOUT));
if (timeout >= MAX_TIMEOUT) {
printk(KERN_DEBUG "i2c-i801.o: PEC Timeout!\n");
}
#if 0 /* now using HW PEC */
if(read_write == I2C_SMBUS_READ) {
data->block[len + 1] = inb_p(SMBPEC);
dev_dbg(&I801_dev->dev, "PEC Timeout!\n");
}
#endif
outb_p(temp, SMBHSTSTS);
}
#endif
......@@ -496,9 +420,9 @@ int i801_block_transaction(union i2c_smbus_data *data, char read_write,
}
/* Return -1 on error. */
s32 i801_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
char read_write, u8 command, int size,
union i2c_smbus_data * data)
static s32 i801_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command,
int size, union i2c_smbus_data * data)
{
int hwpec = 0;
int block = 0;
......@@ -554,7 +478,7 @@ s32 i801_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
break;
case I2C_SMBUS_PROC_CALL:
default:
printk(KERN_ERR "i2c-i801.o: Unsupported transaction %d\n", size);
dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size);
return -1;
}
......@@ -600,7 +524,7 @@ s32 i801_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
}
u32 i801_func(struct i2c_adapter *adapter)
static u32 i801_func(struct i2c_adapter *adapter)
{
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
......@@ -627,8 +551,6 @@ static struct i2c_adapter i801_adapter = {
.algo = &smbus_algorithm,
};
static struct pci_device_id i801_ids[] __devinitdata = {
{
.vendor = PCI_VENDOR_ID_INTEL,
......@@ -650,13 +572,13 @@ static struct pci_device_id i801_ids[] __devinitdata = {
},
{
.vendor = PCI_VENDOR_ID_INTEL,
.device = PCI_DEVICE_ID_INTEL_82801CA_SMBUS,
.device = PCI_DEVICE_ID_INTEL_82801CA_3,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
},
{
.vendor = PCI_VENDOR_ID_INTEL,
.device = PCI_DEVICE_ID_INTEL_82801DB_SMBUS,
.device = PCI_DEVICE_ID_INTEL_82801DB_3,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
},
......@@ -667,8 +589,8 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
{
if (i801_setup(dev)) {
printk
(KERN_WARNING "i2c-i801.o: I801 not detected, module not inserted.\n");
dev_warn(&dev->dev,
"I801 not detected, module not inserted.\n");
return -ENODEV;
}
......@@ -694,22 +616,21 @@ static struct pci_driver i801_driver = {
static int __init i2c_i801_init(void)
{
printk(KERN_INFO "i2c-i801.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
printk(KERN_INFO "i2c-i801 version %s (%s)\n", I2C_VERSION, I2C_DATE);
return pci_module_init(&i801_driver);
}
static void __exit i2c_i801_exit(void)
{
pci_unregister_driver(&i801_driver);
release_region(i801_smba, (isich4 ? 16 : 8));
}
MODULE_AUTHOR
("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker <mdsxyz123@yahoo.com>");
MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl>, "
"Philip Edelbrock <phil@netroedge.com>, "
"and Mark D. Studebaker <mdsxyz123@yahoo.com>");
MODULE_DESCRIPTION("I801 SMBus driver");
MODULE_LICENSE("GPL");
module_init(i2c_i801_init);
module_exit(i2c_i801_exit);
/*
i2c-isa.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* This implements an i2c algorithm/adapter for ISA bus. Not that this is
on first sight very useful; almost no functionality is preserved.
Except that it makes writing drivers for chips which can be on both
the SMBus and the ISA bus very much easier. See lm78.c for an example
of this. */
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/i2c.h>
/* This is the actual algorithm we define */
static struct i2c_algorithm isa_algorithm = {
.name = "ISA bus algorithm",
.id = I2C_ALGO_ISA,
};
/* There can only be one... */
static struct i2c_adapter isa_adapter = {
.owner = THIS_MODULE,
.name = "ISA main adapter",
.id = I2C_ALGO_ISA | I2C_HW_ISA,
.algo = &isa_algorithm,
};
static int __init i2c_isa_init(void)
{
return i2c_add_adapter(&isa_adapter);
}
static void __exit i2c_isa_exit(void)
{
i2c_del_adapter(&isa_adapter);
}
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
MODULE_DESCRIPTION("ISA bus access through i2c");
MODULE_LICENSE("GPL");
module_init(i2c_isa_init);
module_exit(i2c_isa_exit);
......@@ -28,6 +28,8 @@
Note: we assume there can only be one device, with one SMBus interface.
*/
/* #define DEBUG 1 */
#include <linux/module.h>
#include <linux/config.h>
#include <linux/pci.h>
......@@ -102,6 +104,7 @@ static int piix4_transaction(void);
static unsigned short piix4_smba = 0;
static struct i2c_adapter piix4_adapter;
/*
* Get DMI information.
......@@ -125,18 +128,17 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id
if (PCI_FUNC(PIIX4_dev->devfn) != id->driver_data)
return -ENODEV;
printk(KERN_INFO "i2c-piix4.o: Found %s device\n", PIIX4_dev->dev.name);
dev_info(&PIIX4_dev->dev, "Found %s device\n", PIIX4_dev->dev.name);
if(ibm_dmi_probe()) {
printk
(KERN_ERR "i2c-piix4.o: IBM Laptop detected; this module may corrupt\n");
printk
(KERN_ERR " your serial eeprom! Refusing to load module!\n");
dev_err(&PIIX4_dev->dev, "IBM Laptop detected; this module "
"may corrupt your serial eeprom! Refusing to load "
"module!\n");
error_return = -EPERM;
goto END;
}
/* Determine the address of the SMBus areas */
/* Determine the address of the SMBus areas */
if (force_addr) {
piix4_smba = force_addr & 0xfff0;
force = 0;
......@@ -144,75 +146,68 @@ static int piix4_setup(struct pci_dev *PIIX4_dev, const struct pci_device_id *id
pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba);
piix4_smba &= 0xfff0;
if(piix4_smba == 0) {
printk(KERN_ERR "i2c-piix4.o: SMB base address uninitialized - upgrade BIOS or use force_addr=0xaddr\n");
dev_err(&PIIX4_dev->dev, "SMB base address "
"uninitialized - upgrade BIOS or use "
"force_addr=0xaddr\n");
return -ENODEV;
}
}
if (check_region(piix4_smba, 8)) {
printk
(KERN_ERR "i2c-piix4.o: SMB region 0x%x already in use!\n",
if (!request_region(piix4_smba, 8, "piix4-smbus")) {
dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n",
piix4_smba);
error_return = -ENODEV;
goto END;
}
pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
/* If force_addr is set, we program the new address here. Just to make
/* If force_addr is set, we program the new address here. Just to make
sure, we disable the PIIX4 first. */
if (force_addr) {
pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe);
pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba);
pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01);
printk
(KERN_INFO "i2c-piix4.o: WARNING: SMBus interface set to new "
"address %04x!\n", piix4_smba);
dev_info(&PIIX4_dev->dev, "WARNING: SMBus interface set to "
"new address %04x!\n", piix4_smba);
} else if ((temp & 1) == 0) {
if (force) {
/* This should never need to be done, but has been noted that
many Dell machines have the SMBus interface on the PIIX4
disabled!? NOTE: This assumes I/O space and other allocations WERE
done by the Bios! Don't complain if your hardware does weird
things after enabling this. :') Check for Bios updates before
resorting to this. */
/* This should never need to be done, but has been
* noted that many Dell machines have the SMBus
* interface on the PIIX4 disabled!? NOTE: This assumes
* I/O space and other allocations WERE done by the
* Bios! Don't complain if your hardware does weird
* things after enabling this. :') Check for Bios
* updates before resorting to this.
*/
pci_write_config_byte(PIIX4_dev, SMBHSTCFG,
temp | 1);
printk
(KERN_NOTICE "i2c-piix4.o: WARNING: SMBus interface has been FORCEFULLY "
"ENABLED!\n");
dev_printk(KERN_NOTICE, &PIIX4_dev->dev,
"WARNING: SMBus interface has been "
"FORCEFULLY ENABLED!\n");
} else {
printk
(KERN_ERR "i2c-piix4.o: Host SMBus controller not enabled!\n");
dev_err(&PIIX4_dev->dev,
"Host SMBus controller not enabled!\n");
error_return = -ENODEV;
goto END;
}
}
/* Everything is happy, let's grab the memory and set things up. */
request_region(piix4_smba, 8, "piix4-smbus");
#ifdef DEBUG
if ((temp & 0x0E) == 8)
printk
(KERN_DEBUG "i2c-piix4.o: Using Interrupt 9 for SMBus.\n");
dev_dbg(&PIIX4_dev->dev, "Using Interrupt 9 for SMBus.\n");
else if ((temp & 0x0E) == 0)
printk
(KERN_DEBUG "i2c-piix4.o: Using Interrupt SMI# for SMBus.\n");
dev_dbg(&PIIX4_dev->dev, "Using Interrupt SMI# for SMBus.\n");
else
printk
(KERN_ERR "i2c-piix4.o: Illegal Interrupt configuration (or code out "
"of date)!\n");
dev_err(&PIIX4_dev->dev, "Illegal Interrupt configuration "
"(or code out of date)!\n");
pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
printk(KERN_DEBUG "i2c-piix4.o: SMBREV = 0x%X\n", temp);
printk(KERN_DEBUG "i2c-piix4.o: SMBA = 0x%X\n", piix4_smba);
#endif /* DEBUG */
dev_dbg(&PIIX4_dev->dev, "SMBREV = 0x%X\n", temp);
dev_dbg(&PIIX4_dev->dev, "SMBA = 0x%X\n", piix4_smba);
END:
END:
return error_return;
}
/* Internally used pause function */
static void piix4_do_pause(unsigned int amount)
{
......@@ -227,29 +222,21 @@ static int piix4_transaction(void)
int result = 0;
int timeout = 0;
#ifdef DEBUG
printk
(KERN_DEBUG "i2c-piix4.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, "
"DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD),
inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
#endif
dev_dbg(&piix4_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
"ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBHSTDAT1));
/* Make sure the SMBus host is ready to start transmitting */
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
#ifdef DEBUG
printk(KERN_DEBUG "i2c-piix4.o: SMBus busy (%02x). Resetting... \n",
temp);
#endif
dev_dbg(&piix4_adapter.dev, "SMBus busy (%02x). "
"Resetting... \n", temp);
outb_p(temp, SMBHSTSTS);
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
#ifdef DEBUG
printk(KERN_ERR "i2c-piix4.o: Failed! (%02x)\n", temp);
#endif
dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp);
return -1;
} else {
#ifdef DEBUG
printk(KERN_DEBUG "i2c-piix4.o: Successfull!\n");
#endif
dev_dbg(&piix4_adapter.dev, "Successfull!\n");
}
}
......@@ -262,50 +249,40 @@ static int piix4_transaction(void)
temp = inb_p(SMBHSTSTS);
} while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
#ifdef DEBUG
/* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) {
printk(KERN_ERR "i2c-piix4.o: SMBus Timeout!\n");
dev_err(&piix4_adapter.dev, "SMBus Timeout!\n");
result = -1;
}
#endif
if (temp & 0x10) {
result = -1;
#ifdef DEBUG
printk(KERN_ERR "i2c-piix4.o: Error: Failed bus transaction\n");
#endif
dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n");
}
if (temp & 0x08) {
result = -1;
printk
(KERN_ERR "i2c-piix4.o: Bus collision! SMBus may be locked until next hard\n"
"reset. (sorry!)\n");
dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be "
"locked until next hard reset. (sorry!)\n");
/* Clock stops and slave is stuck in mid-transmission */
}
if (temp & 0x04) {
result = -1;
#ifdef DEBUG
printk(KERN_ERR "i2c-piix4.o: Error: no response!\n");
#endif
dev_err(&piix4_adapter.dev, "Error: no response!\n");
}
if (inb_p(SMBHSTSTS) != 0x00)
outb_p(inb(SMBHSTSTS), SMBHSTSTS);
#ifdef DEBUG
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
printk
(KERN_ERR "i2c-piix4.o: Failed reset at end of transaction (%02x)\n",
temp);
dev_err(&piix4_adapter.dev, "Failed reset at end of "
"transaction (%02x)\n", temp);
}
printk
(KERN_DEBUG "i2c-piix4.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, "
"DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD),
inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1));
#endif
dev_dbg(&piix4_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, "
"ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
inb_p(SMBHSTDAT1));
return result;
}
......@@ -318,8 +295,7 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
switch (size) {
case I2C_SMBUS_PROC_CALL:
printk
(KERN_ERR "i2c-piix4.o: I2C_SMBUS_PROC_CALL not supported!\n");
dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
return -1;
case I2C_SMBUS_QUICK:
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
......@@ -402,7 +378,6 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
return 0;
}
static u32 piix4_func(struct i2c_adapter *adapter)
{
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
......@@ -424,8 +399,6 @@ static struct i2c_adapter piix4_adapter = {
.algo = &smbus_algorithm,
};
static struct pci_device_id piix4_ids[] __devinitdata = {
{
.vendor = PCI_VENDOR_ID_INTEL,
......@@ -499,7 +472,7 @@ static struct pci_driver piix4_driver = {
static int __init i2c_piix4_init(void)
{
printk("i2c-piix4.o version %s (%s)\n", I2C_VERSION, I2C_DATE);
printk(KERN_INFO "i2c-piix4 version %s (%s)\n", I2C_VERSION, I2C_DATE);
return pci_module_init(&piix4_driver);
}
......@@ -510,8 +483,6 @@ static void __exit i2c_piix4_exit(void)
release_region(piix4_smba, 8);
}
MODULE_AUTHOR
("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
MODULE_DESCRIPTION("PIIX4 SMBus driver");
......
......@@ -93,9 +93,9 @@ SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1
/* Initial values */
/* Note: Eventhough I left the low and high limits named os and hyst,
/* Note: Even though I left the low and high limits named os and hyst,
they don't quite work like a thermostat the way the LM75 does. I.e.,
a lower temp than THYST actuall triggers an alarm instead of
a lower temp than THYST actually triggers an alarm instead of
clearing it. Weird, ey? --Phil */
#define adm1021_INIT_TOS 60
#define adm1021_INIT_THYST 20
......
......@@ -25,7 +25,7 @@
#include <linux/i2c-proc.h>
#define LM75_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */
#define LM75_SYSCTL_TEMP 1200 /* Degrees Celsius * 10 */
/* Addresses to scan */
static unsigned short normal_i2c[] = { SENSORS_I2C_END };
......
......@@ -152,7 +152,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
/* load own address in S0, effective address is (own << 1) */
i2c_outb(adap, get_own(adap));
/* check it's realy writen */
/* check it's really written */
if ((temp = i2c_inb(adap)) != get_own(adap)) {
DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S0 (0x%02x).\n", temp));
return -ENXIO;
......@@ -168,7 +168,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
/* load clock register S2 */
i2c_outb(adap, get_clock(adap));
/* check it's realy writen, the only 5 lowest bits does matter */
/* check it's really written, the only 5 lowest bits does matter */
if (((temp = i2c_inb(adap)) & 0x1f) != get_clock(adap)) {
DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't set S2 (0x%02x).\n", temp));
return -ENXIO;
......@@ -177,7 +177,7 @@ static int pcf_init_8584 (struct i2c_algo_pcf_data *adap)
/* Enable serial interface, idle, S0 selected */
set_pcf(adap, 1, I2C_PCF_IDLE);
/* check to see PCF is realy idled and we can access status register */
/* check to see PCF is really idled and we can access status register */
if ((temp = get_pcf(adap, 1)) != (I2C_PCF_PIN | I2C_PCF_BB)) {
DEB2(printk(KERN_ERR "i2c-algo-pcf.o: PCF detection failed -- can't select S1` (0x%02x).\n", temp));
return -ENXIO;
......
......@@ -53,6 +53,16 @@ static void i2cproc_remove(int bus);
#endif /* CONFIG_PROC_FS */
int i2c_device_probe(struct device *dev)
{
return -ENODEV;
}
int i2c_device_remove(struct device *dev)
{
return 0;
}
/* ---------------------------------------------------
* registering functions
* ---------------------------------------------------
......@@ -205,6 +215,16 @@ int i2c_add_driver(struct i2c_driver *driver)
DEB(printk(KERN_DEBUG "i2c-core.o: driver %s registered.\n",driver->name));
/* add the driver to the list of i2c drivers in the driver core */
driver->driver.name = driver->name;
driver->driver.bus = &i2c_bus_type;
driver->driver.probe = i2c_device_probe;
driver->driver.remove = i2c_device_remove;
res = driver_register(&driver->driver);
if (res)
goto out_unlock;
/* now look for instances of driver on our adapters
*/
if (driver->flags& (I2C_DF_NOTIFY|I2C_DF_DUMMY)) {
......@@ -236,6 +256,8 @@ int i2c_del_driver(struct i2c_driver *driver)
goto out_unlock;
}
driver_unregister(&driver->driver);
/* Have a look at each adapter, if clients of this driver are still
* attached. If so, detach them to be able to kill the driver
* afterwards.
......
......@@ -270,7 +270,7 @@ static int i2c_sysctl_chips(ctl_table * table, int *name, int nlen,
}
/* This funcion reads or writes a 'real' value (encoded by the combination
/* This function reads or writes a 'real' value (encoded by the combination
of an integer and a magnitude, the last is the power of ten the value
should be divided with) to a /proc/sys directory. To use this function,
you must (before registering the ctl_table) set the extra2 field to the
......
......@@ -143,7 +143,10 @@ struct i2c_driver {
* with the device.
*/
int (*command)(struct i2c_client *client,unsigned int cmd, void *arg);
struct device_driver driver;
};
#define to_i2c_driver(d) container_of(d, struct i2c_driver, driver)
extern struct bus_type i2c_bus_type;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment