mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-28 20:58:22 +00:00
`indent -kr -i8' on all kernel sources
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@707 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
83d5845df5
commit
6a2c82b491
29 files changed
+10217
-9155
No files matched your search
+332
-301
@@ -86,7 +86,7 @@
|
||||
#define SMBBLKDAT (6 + ali15x3_smba)
|
||||
|
||||
/* PCI Address Constants */
|
||||
#define SMBCOM 0x004
|
||||
#define SMBCOM 0x004
|
||||
#define SMBBA 0x014
|
||||
#define SMBATPC 0x05B /* used to unlock xxxBA registers */
|
||||
#define SMBHSTCFG 0x0E0
|
||||
@@ -118,9 +118,9 @@
|
||||
#define ALI15X3_BLOCK_CLR 0x80
|
||||
|
||||
/* ALI15X3 status register bits */
|
||||
#define ALI15X3_STS_IDLE 0x04
|
||||
#define ALI15X3_STS_BUSY 0x08
|
||||
#define ALI15X3_STS_DONE 0x10
|
||||
#define ALI15X3_STS_IDLE 0x04
|
||||
#define ALI15X3_STS_BUSY 0x08
|
||||
#define ALI15X3_STS_DONE 0x10
|
||||
#define ALI15X3_STS_DEV 0x20 /* device error */
|
||||
#define ALI15X3_STS_COLL 0x40 /* collision or no response */
|
||||
#define ALI15X3_STS_TERM 0x80 /* terminated by abort */
|
||||
@@ -132,13 +132,14 @@ static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_ali15x3_init(void);
|
||||
int __init i2c_ali15x3_init(void);
|
||||
static int __init ali15x3_cleanup(void);
|
||||
static int ali15x3_setup(void);
|
||||
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);
|
||||
static void ali15x3_do_pause( unsigned int amount );
|
||||
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);
|
||||
static void ali15x3_do_pause(unsigned int amount);
|
||||
static int ali15x3_transaction(void);
|
||||
static void ali15x3_inc(struct i2c_adapter *adapter);
|
||||
static void ali15x3_dec(struct i2c_adapter *adapter);
|
||||
@@ -147,28 +148,28 @@ static u32 ali15x3_func(struct i2c_adapter *adapter);
|
||||
#ifdef MODULE
|
||||
extern int init_module(void);
|
||||
extern int cleanup_module(void);
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
|
||||
static struct i2c_algorithm smbus_algorithm = {
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ ali15x3_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ ali15x3_func,
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ ali15x3_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ ali15x3_func,
|
||||
};
|
||||
|
||||
static struct i2c_adapter ali15x3_adapter = {
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
ali15x3_inc,
|
||||
ali15x3_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
ali15x3_inc,
|
||||
ali15x3_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int __initdata ali15x3_initialized;
|
||||
@@ -181,27 +182,27 @@ static unsigned short ali15x3_smba = 0;
|
||||
defined to make the transition easier. */
|
||||
int ali15x3_setup(void)
|
||||
{
|
||||
int error_return=0;
|
||||
unsigned char temp;
|
||||
int error_return = 0;
|
||||
unsigned char temp;
|
||||
|
||||
struct pci_dev *ALI15X3_dev;
|
||||
struct pci_dev *ALI15X3_dev;
|
||||
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-ali15x3.o: Error: No PCI-bus found!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-ali15x3.o: Error: No PCI-bus found!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Look for the ALI15X3, M7101 device */
|
||||
ALI15X3_dev = NULL;
|
||||
ALI15X3_dev = pci_find_device(PCI_VENDOR_ID_AL,
|
||||
PCI_DEVICE_ID_AL_M7101, ALI15X3_dev);
|
||||
if(ALI15X3_dev == NULL) {
|
||||
printk("i2c-ali15x3.o: Error: Can't detect ali15x3!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* Look for the ALI15X3, M7101 device */
|
||||
ALI15X3_dev = NULL;
|
||||
ALI15X3_dev = pci_find_device(PCI_VENDOR_ID_AL,
|
||||
PCI_DEVICE_ID_AL_M7101, ALI15X3_dev);
|
||||
if (ALI15X3_dev == NULL) {
|
||||
printk("i2c-ali15x3.o: Error: Can't detect ali15x3!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Check the following things:
|
||||
- SMB I/O address is initialized
|
||||
@@ -214,66 +215,71 @@ int ali15x3_setup(void)
|
||||
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);
|
||||
}
|
||||
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 */
|
||||
pci_read_config_word(ALI15X3_dev, SMBBA,&ali15x3_smba);
|
||||
ali15x3_smba &= (0xffff & ~ (ALI15X3_SMB_IOSIZE - 1));
|
||||
if(ali15x3_smba == 0) {
|
||||
printk("i2c-ali15x3.o: ALI15X3_smb region uninitialized - upgrade BIOS?\n");
|
||||
error_return=-ENODEV;
|
||||
}
|
||||
pci_read_config_word(ALI15X3_dev, SMBBA, &ali15x3_smba);
|
||||
ali15x3_smba &= (0xffff & ~(ALI15X3_SMB_IOSIZE - 1));
|
||||
if (ali15x3_smba == 0) {
|
||||
printk
|
||||
("i2c-ali15x3.o: ALI15X3_smb region uninitialized - upgrade BIOS?\n");
|
||||
error_return = -ENODEV;
|
||||
}
|
||||
|
||||
if(error_return == -ENODEV)
|
||||
goto END;
|
||||
if (error_return == -ENODEV)
|
||||
goto END;
|
||||
|
||||
if (check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) {
|
||||
printk("i2c-ali15x3.o: ALI15X3_smb region 0x%x already in use!\n", ali15x3_smba);
|
||||
error_return=-ENODEV;
|
||||
}
|
||||
if (check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) {
|
||||
printk
|
||||
("i2c-ali15x3.o: ALI15X3_smb region 0x%x already in use!\n",
|
||||
ali15x3_smba);
|
||||
error_return = -ENODEV;
|
||||
}
|
||||
|
||||
if(error_return == -ENODEV)
|
||||
goto END;
|
||||
if (error_return == -ENODEV)
|
||||
goto END;
|
||||
|
||||
/* check if whole device is enabled */
|
||||
pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp);
|
||||
if ((temp & 1) == 0) {
|
||||
printk("SMBUS: Error: SMB device not enabled - upgrade BIOS?\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp);
|
||||
if ((temp & 1) == 0) {
|
||||
printk
|
||||
("SMBUS: Error: SMB device not enabled - upgrade BIOS?\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Is SMB Host controller enabled? */
|
||||
pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp);
|
||||
pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp);
|
||||
#ifdef FORCE_ALI15X3_ENABLE
|
||||
/* This should never need to be done.
|
||||
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. */
|
||||
if ((temp & 1) == 0) {
|
||||
pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 1);
|
||||
printk("i2c-ali15x3.o: WARNING: ALI15X3 SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!!\n");
|
||||
}
|
||||
#else /* FORCE_ALI15X3_ENABLE */
|
||||
if ((temp & 1) == 0) {
|
||||
printk("SMBUS: Error: Host SMBus controller not enabled - upgrade BIOS?\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
#endif /* FORCE_ALI15X3_ENABLE */
|
||||
if ((temp & 1) == 0) {
|
||||
pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 1);
|
||||
printk
|
||||
("i2c-ali15x3.o: WARNING: ALI15X3 SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!!\n");
|
||||
}
|
||||
#else /* FORCE_ALI15X3_ENABLE */
|
||||
if ((temp & 1) == 0) {
|
||||
printk
|
||||
("SMBUS: Error: Host SMBus controller not enabled - upgrade BIOS?\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
#endif /* FORCE_ALI15X3_ENABLE */
|
||||
|
||||
/* set SMB clock to 74KHz as recommended in data sheet */
|
||||
pci_write_config_byte(ALI15X3_dev, SMBCLK, 0x20);
|
||||
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");
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb");
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
@@ -283,43 +289,44 @@ int ali15x3_setup(void)
|
||||
if ((....... & 0x0F) == 1)
|
||||
printk("i2c-ali15x3.o: 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 */
|
||||
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 */
|
||||
|
||||
END:
|
||||
return error_return;
|
||||
END:
|
||||
return error_return;
|
||||
}
|
||||
|
||||
|
||||
/* Internally used pause function */
|
||||
void ali15x3_do_pause( unsigned int amount )
|
||||
void ali15x3_do_pause(unsigned int amount)
|
||||
{
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
}
|
||||
|
||||
/* Another internally used function */
|
||||
int ali15x3_transaction(void)
|
||||
int ali15x3_transaction(void)
|
||||
{
|
||||
int temp;
|
||||
int result=0;
|
||||
int timeout=0;
|
||||
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));
|
||||
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
|
||||
|
||||
/* get status */
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
/* get status */
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
/* Check the busy bit first */
|
||||
if (temp & ALI15X3_STS_BUSY) {
|
||||
/* 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.
|
||||
@@ -341,61 +348,67 @@ int ali15x3_transaction(void)
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
if (temp & ALI15X3_STS_BUSY) {
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
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);
|
||||
outb_p(ALI15X3_T_OUT, SMBHSTCNT);
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
}
|
||||
printk
|
||||
("i2c-ali15x3.o: 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)) {
|
||||
/* do a clear-on-write */
|
||||
outb_p(0xFF, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) {
|
||||
/* 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",temp);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* check and clear done bit */
|
||||
if (temp & ALI15X3_STS_DONE) {
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
}
|
||||
}
|
||||
/* now check the error bits and the busy bit */
|
||||
if (temp & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) {
|
||||
/* do a clear-on-write */
|
||||
outb_p(0xFF, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) &
|
||||
(ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) {
|
||||
/* 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",
|
||||
temp);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* check and clear done bit */
|
||||
if (temp & ALI15X3_STS_DONE) {
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
}
|
||||
}
|
||||
|
||||
/* start the transaction by writing anything to the start register */
|
||||
outb_p(0xFF, SMBHSTSTART);
|
||||
/* start the transaction by writing anything to the start register */
|
||||
outb_p(0xFF, SMBHSTSTART);
|
||||
|
||||
/* We will always wait for a fraction of a second! */
|
||||
timeout = 0;
|
||||
do {
|
||||
ali15x3_do_pause(1);
|
||||
temp=inb_p(SMBHSTSTS);
|
||||
} while ((!(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE))) && (timeout++ < MAX_TIMEOUT));
|
||||
/* We will always wait for a fraction of a second! */
|
||||
timeout = 0;
|
||||
do {
|
||||
ali15x3_do_pause(1);
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
} while ((!(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE)))
|
||||
&& (timeout++ < MAX_TIMEOUT));
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
result = -1;
|
||||
printk("i2c-ali15x3.o: SMBus Timeout!\n");
|
||||
}
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
result = -1;
|
||||
printk("i2c-ali15x3.o: SMBus Timeout!\n");
|
||||
}
|
||||
|
||||
if (temp & ALI15X3_STS_TERM) {
|
||||
result = -1;
|
||||
if (temp & ALI15X3_STS_TERM) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-ali15x3.o: Error: Failed bus transaction\n");
|
||||
printk("i2c-ali15x3.o: Error: Failed bus transaction\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Unfortunately the ALI SMB controller maps "no response" and "bus collision"
|
||||
@@ -403,136 +416,148 @@ int ali15x3_transaction(void)
|
||||
do a printk.
|
||||
This means that bus collisions go unreported.
|
||||
*/
|
||||
if (temp & ALI15X3_STS_COLL) {
|
||||
result = -1;
|
||||
if (temp & ALI15X3_STS_COLL) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n", inb_p(SMBHSTADD));
|
||||
printk
|
||||
("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n",
|
||||
inb_p(SMBHSTADD));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/* haven't ever seen this */
|
||||
if (temp & ALI15X3_STS_DEV) {
|
||||
result = -1;
|
||||
printk("i2c-ali15x3.o: Error: device error\n");
|
||||
}
|
||||
|
||||
if (temp & ALI15X3_STS_DEV) {
|
||||
result = -1;
|
||||
printk("i2c-ali15x3.o: 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));
|
||||
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
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return -1 on error. See smbus.h for more information */
|
||||
s32 ali15x3_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
|
||||
char read_write, u8 command, int size,
|
||||
union i2c_smbus_data * data)
|
||||
s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
|
||||
unsigned short flags, char read_write, u8 command,
|
||||
int size, union i2c_smbus_data * data)
|
||||
{
|
||||
int i,len;
|
||||
int temp;
|
||||
int timeout;
|
||||
int i, len;
|
||||
int temp;
|
||||
int timeout;
|
||||
|
||||
/* clear all the bits (clear-on-write) */
|
||||
outb_p(0xFF, SMBHSTSTS);
|
||||
outb_p(0xFF, SMBHSTSTS);
|
||||
/* make sure SMBus is idle */
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
for(timeout = 0; (timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE); timeout++)
|
||||
{
|
||||
ali15x3_do_pause(1);
|
||||
temp=inb_p(SMBHSTSTS);
|
||||
}
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
printk("i2c-ali15x3.o: Idle wait Timeout! STS=0x%02x\n", temp);
|
||||
}
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
for (timeout = 0;
|
||||
(timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE);
|
||||
timeout++) {
|
||||
ali15x3_do_pause(1);
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
}
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
printk("i2c-ali15x3.o: 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");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
size = ALI15X3_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = ALI15X3_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte,SMBHSTDAT0);
|
||||
size = ALI15X3_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff,SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1);
|
||||
}
|
||||
size = ALI15X3_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0) {
|
||||
len = 0;
|
||||
data->block[0] = len;
|
||||
}
|
||||
if (len > 32) {
|
||||
len = 32;
|
||||
data->block[0] = len;
|
||||
}
|
||||
outb_p(len,SMBHSTDAT0);
|
||||
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i++)
|
||||
outb_p(data->block[i],SMBBLKDAT);
|
||||
}
|
||||
size = ALI15X3_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
switch (size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk
|
||||
("i2c-ali15x3.o: I2C_SMBUS_PROC_CALL not supported!\n");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
size = ALI15X3_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = ALI15X3_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte, SMBHSTDAT0);
|
||||
size = ALI15X3_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff, SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
|
||||
}
|
||||
size = ALI15X3_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0) {
|
||||
len = 0;
|
||||
data->block[0] = len;
|
||||
}
|
||||
if (len > 32) {
|
||||
len = 32;
|
||||
data->block[0] = len;
|
||||
}
|
||||
outb_p(len, SMBHSTDAT0);
|
||||
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i++)
|
||||
outb_p(data->block[i], SMBBLKDAT);
|
||||
}
|
||||
size = ALI15X3_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
outb_p(size, SMBHSTCNT); /* output command */
|
||||
outb_p(size, SMBHSTCNT); /* output command */
|
||||
|
||||
if (ali15x3_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK))
|
||||
return 0;
|
||||
|
||||
if (ali15x3_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
switch(size) {
|
||||
case ALI15X3_BYTE: /* Result put in SMBHSTDAT0 */
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case ALI15X3_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case ALI15X3_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
case ALI15X3_BLOCK_DATA:
|
||||
len = inb_p(SMBHSTDAT0);
|
||||
if(len > 32)
|
||||
len = 32;
|
||||
data->block[0] = len;
|
||||
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= data->block[0]; i++) {
|
||||
data->block[i] = inb_p(SMBBLKDAT);
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK))
|
||||
return 0;
|
||||
|
||||
|
||||
switch (size) {
|
||||
case ALI15X3_BYTE: /* Result put in SMBHSTDAT0 */
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case ALI15X3_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case ALI15X3_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
case ALI15X3_BLOCK_DATA:
|
||||
len = inb_p(SMBHSTDAT0);
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
data->block[0] = len;
|
||||
outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
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", len, i, data->block[i]);
|
||||
#endif DEBUG
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
printk
|
||||
("i2c-ali15x3.o: Blk: len=%d, i=%d, data=%02x\n",
|
||||
len, i, data->block[i]);
|
||||
#endif /* DEBUG */
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ali15x3_inc(struct i2c_adapter *adapter)
|
||||
@@ -549,72 +574,78 @@ void ali15x3_dec(struct i2c_adapter *adapter)
|
||||
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 |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
}
|
||||
|
||||
int __init i2c_ali15x3_init(void)
|
||||
{
|
||||
int res;
|
||||
printk("ali15x3.o version %s (%s)\n",LM_VERSION,LM_DATE);
|
||||
int res;
|
||||
printk("ali15x3.o version %s (%s)\n", LM_VERSION, LM_DATE);
|
||||
#ifdef DEBUG
|
||||
/* PE- It might be good to make this a permanent part of the code! */
|
||||
if (ali15x3_initialized) {
|
||||
printk("i2c-ali15x3.o: Oops, ali15x3_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (ali15x3_initialized) {
|
||||
printk
|
||||
("i2c-ali15x3.o: Oops, ali15x3_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
#endif
|
||||
ali15x3_initialized = 0;
|
||||
if ((res = ali15x3_setup())) {
|
||||
printk("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n");
|
||||
ali15x3_cleanup();
|
||||
return res;
|
||||
}
|
||||
ali15x3_initialized ++;
|
||||
sprintf(ali15x3_adapter.name,"SMBus ALI15X3 adapter at %04x",ali15x3_smba);
|
||||
if ((res = i2c_add_adapter(&ali15x3_adapter))) {
|
||||
printk("i2c-ali15x3.o: Adapter registration failed, module not inserted.\n");
|
||||
ali15x3_cleanup();
|
||||
return res;
|
||||
}
|
||||
ali15x3_initialized++;
|
||||
printk("i2c-ali15x3.o: ALI15X3 SMBus Controller detected and initialized\n");
|
||||
return 0;
|
||||
ali15x3_initialized = 0;
|
||||
if ((res = ali15x3_setup())) {
|
||||
printk
|
||||
("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n");
|
||||
ali15x3_cleanup();
|
||||
return res;
|
||||
}
|
||||
ali15x3_initialized++;
|
||||
sprintf(ali15x3_adapter.name, "SMBus ALI15X3 adapter at %04x",
|
||||
ali15x3_smba);
|
||||
if ((res = i2c_add_adapter(&ali15x3_adapter))) {
|
||||
printk
|
||||
("i2c-ali15x3.o: Adapter registration failed, module not inserted.\n");
|
||||
ali15x3_cleanup();
|
||||
return res;
|
||||
}
|
||||
ali15x3_initialized++;
|
||||
printk
|
||||
("i2c-ali15x3.o: ALI15X3 SMBus Controller detected and initialized\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init ali15x3_cleanup(void)
|
||||
{
|
||||
int res;
|
||||
if (ali15x3_initialized >= 2)
|
||||
{
|
||||
if ((res = i2c_del_adapter(&ali15x3_adapter))) {
|
||||
printk("i2c-ali15x3.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
ali15x3_initialized--;
|
||||
}
|
||||
if (ali15x3_initialized >= 1) {
|
||||
release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE);
|
||||
ali15x3_initialized--;
|
||||
}
|
||||
return 0;
|
||||
int res;
|
||||
if (ali15x3_initialized >= 2) {
|
||||
if ((res = i2c_del_adapter(&ali15x3_adapter))) {
|
||||
printk
|
||||
("i2c-ali15x3.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
ali15x3_initialized--;
|
||||
}
|
||||
if (ali15x3_initialized >= 1) {
|
||||
release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE);
|
||||
ali15x3_initialized--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_NO_SYMBOLS;
|
||||
|
||||
#ifdef MODULE
|
||||
|
||||
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");
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_ali15x3_init();
|
||||
return i2c_ali15x3_init();
|
||||
}
|
||||
|
||||
int cleanup_module(void)
|
||||
{
|
||||
return ali15x3_cleanup();
|
||||
return ali15x3_cleanup();
|
||||
}
|
||||
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
+285
-263
@@ -54,10 +54,10 @@
|
||||
/* PCI Address Constants */
|
||||
|
||||
/* address of I/O space */
|
||||
#define SMBBA 0x058 /* mh */
|
||||
#define SMBBA 0x058 /* mh */
|
||||
|
||||
/* general configuration */
|
||||
#define SMBGCFG 0x041 /* mh */
|
||||
#define SMBGCFG 0x041 /* mh */
|
||||
|
||||
/* silicon revision code */
|
||||
#define SMBREV 0x008
|
||||
@@ -80,13 +80,13 @@ static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_amd756_init(void);
|
||||
int __init i2c_amd756_init(void);
|
||||
static int __init amd756_cleanup(void);
|
||||
static int amd756_setup(void);
|
||||
static s32 amd756_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data);
|
||||
static void amd756_do_pause( unsigned int amount );
|
||||
static s32 amd756_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data *data);
|
||||
static void amd756_do_pause(unsigned int amount);
|
||||
static int amd756_transaction(void);
|
||||
static void amd756_inc(struct i2c_adapter *adapter);
|
||||
static void amd756_dec(struct i2c_adapter *adapter);
|
||||
@@ -95,28 +95,28 @@ static u32 amd756_func(struct i2c_adapter *adapter);
|
||||
#ifdef MODULE
|
||||
extern int init_module(void);
|
||||
extern int cleanup_module(void);
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
|
||||
static struct i2c_algorithm smbus_algorithm = {
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ amd756_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ amd756_func,
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ amd756_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ amd756_func,
|
||||
};
|
||||
|
||||
static struct i2c_adapter amd756_adapter = {
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD756,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
amd756_inc,
|
||||
amd756_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD756,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
amd756_inc,
|
||||
amd756_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int __initdata amd756_initialized;
|
||||
@@ -131,72 +131,77 @@ static unsigned short amd756_smba = 0;
|
||||
defined to make the transition easier. */
|
||||
int amd756_setup(void)
|
||||
{
|
||||
int error_return=0;
|
||||
unsigned char temp;
|
||||
int error_return = 0;
|
||||
unsigned char temp;
|
||||
|
||||
struct pci_dev *AMD756_dev;
|
||||
struct pci_dev *AMD756_dev;
|
||||
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-amd756.o: Error: No PCI-bus found!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-amd756.o: Error: No PCI-bus found!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Look for the AMD756, function 3 */
|
||||
/* Note: we keep on searching until we have found 'function 3' */
|
||||
AMD756_dev = NULL;
|
||||
do
|
||||
AMD756_dev = pci_find_device(PCI_VENDOR_ID_AMD,
|
||||
PCI_DEVICE_ID_AMD_756, AMD756_dev);
|
||||
while (AMD756_dev && (PCI_FUNC(AMD756_dev->devfn) != 3));
|
||||
if(AMD756_dev == NULL) {
|
||||
printk("i2c-amd756.o: Error: Can't detect AMD756, function 3!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* Look for the AMD756, function 3 */
|
||||
/* Note: we keep on searching until we have found 'function 3' */
|
||||
AMD756_dev = NULL;
|
||||
do
|
||||
AMD756_dev = pci_find_device(PCI_VENDOR_ID_AMD,
|
||||
PCI_DEVICE_ID_AMD_756,
|
||||
AMD756_dev);
|
||||
while (AMD756_dev && (PCI_FUNC(AMD756_dev->devfn) != 3));
|
||||
if (AMD756_dev == NULL) {
|
||||
printk
|
||||
("i2c-amd756.o: Error: Can't detect AMD756, function 3!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Determine the address of the SMBus areas */
|
||||
|
||||
/* Technically it is a dword but... */
|
||||
pci_read_config_word(AMD756_dev, SMBBA, &amd756_smba);
|
||||
amd756_smba &= 0xfff0;
|
||||
/* Technically it is a dword but... */
|
||||
pci_read_config_word(AMD756_dev, SMBBA, &amd756_smba);
|
||||
amd756_smba &= 0xfff0;
|
||||
|
||||
if (check_region(amd756_smba, 8)) {
|
||||
printk("i2c-amd756.o: AMD756_smb region 0x%x already in use!\n", amd756_smba);
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
if (check_region(amd756_smba, 8)) {
|
||||
printk
|
||||
("i2c-amd756.o: AMD756_smb region 0x%x already in use!\n",
|
||||
amd756_smba);
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pci_read_config_byte(AMD756_dev, SMBGCFG, &temp);
|
||||
pci_read_config_byte(AMD756_dev, SMBGCFG, &temp);
|
||||
|
||||
if ((temp & 128) == 0) {
|
||||
printk("SMBUS: Error: Host SMBus controller I/O not enabled!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
if ((temp & 128) == 0) {
|
||||
printk
|
||||
("SMBUS: Error: Host SMBus controller I/O not enabled!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(amd756_smba, 8, "amd756-smbus");
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(amd756_smba, 8, "amd756-smbus");
|
||||
|
||||
#ifdef DEBUG
|
||||
/*
|
||||
if ((temp & 0x0E) == 8)
|
||||
printk("i2c-amd756.o: AMD756 using Interrupt 9 for SMBus.\n");
|
||||
else if ((temp & 0x0E) == 0)
|
||||
printk("i2c-amd756.o: AMD756 using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk("i2c-amd756.o: AMD756: Illegal Interrupt configuration (or code out "
|
||||
"of date)!\n");
|
||||
*/
|
||||
/*
|
||||
if ((temp & 0x0E) == 8)
|
||||
printk("i2c-amd756.o: AMD756 using Interrupt 9 for SMBus.\n");
|
||||
else if ((temp & 0x0E) == 0)
|
||||
printk("i2c-amd756.o: AMD756 using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk("i2c-amd756.o: AMD756: Illegal Interrupt configuration (or code out "
|
||||
"of date)!\n");
|
||||
*/
|
||||
|
||||
pci_read_config_byte(AMD756_dev, SMBREV, &temp);
|
||||
printk("i2c-amd756.o: SMBREV = 0x%X\n",temp);
|
||||
printk("i2c-amd756.o: AMD756_smba = 0x%X\n",amd756_smba);
|
||||
#endif /* DEBUG */
|
||||
pci_read_config_byte(AMD756_dev, SMBREV, &temp);
|
||||
printk("i2c-amd756.o: SMBREV = 0x%X\n", temp);
|
||||
printk("i2c-amd756.o: AMD756_smba = 0x%X\n", amd756_smba);
|
||||
#endif /* DEBUG */
|
||||
|
||||
END:
|
||||
return error_return;
|
||||
END:
|
||||
return error_return;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -206,13 +211,13 @@ END:
|
||||
*/
|
||||
|
||||
/* Internally used pause function */
|
||||
void amd756_do_pause( unsigned int amount )
|
||||
void amd756_do_pause(unsigned int amount)
|
||||
{
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
}
|
||||
|
||||
#define GS_ABRT_STS (1 << 0)
|
||||
#define GS_ABRT_STS (1 << 0)
|
||||
#define GS_COL_STS (1 << 1)
|
||||
#define GS_PRERR_STS (1 << 2)
|
||||
#define GS_HST_STS (1 << 3)
|
||||
@@ -222,186 +227,200 @@ void amd756_do_pause( unsigned int amount )
|
||||
#define GS_CLEAR_STS (GS_ABRT_STS | GS_COL_STS | GS_PRERR_STS | \
|
||||
GS_HCYC_STS | GS_TO_STS )
|
||||
|
||||
#define GE_CYC_TYPE_MASK (7)
|
||||
#define GE_HOST_STC (1 << 3)
|
||||
|
||||
#define GE_CYC_TYPE_MASK (7)
|
||||
#define GE_HOST_STC (1 << 3)
|
||||
|
||||
/* Another internally used function */
|
||||
int amd756_transaction(void)
|
||||
int amd756_transaction(void)
|
||||
{
|
||||
int temp;
|
||||
int result=0;
|
||||
int timeout=0;
|
||||
int temp;
|
||||
int result = 0;
|
||||
int timeout = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: 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));
|
||||
printk
|
||||
("i2c-amd756.o: 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));
|
||||
#endif
|
||||
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
/* TODO: What about SM_BSY? */
|
||||
if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) != 0x00) {
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
/* TODO: What about SM_BSY? */
|
||||
if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: SMBus busy (%04x). Resetting (NOT)... \n",temp);
|
||||
printk
|
||||
("i2c-amd756.o: SMBus busy (%04x). Resetting (NOT)... \n",
|
||||
temp);
|
||||
#endif
|
||||
/* TODO: How to reset the AMD?
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
*/
|
||||
if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) != 0x00) {
|
||||
/* TODO: How to reset the AMD?
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
*/
|
||||
if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) !=
|
||||
0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: Failed! (%04x)\n",temp);
|
||||
printk("i2c-amd756.o: Failed! (%04x)\n", temp);
|
||||
#endif
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: Successfull!\n");
|
||||
printk("i2c-amd756.o: Successfull!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* start the transaction by setting bit 6 */
|
||||
outw_p(inw(SMB_GLOBAL_ENABLE) | GE_HOST_STC, SMB_GLOBAL_ENABLE);
|
||||
/* start the transaction by setting bit 6 */
|
||||
outw_p(inw(SMB_GLOBAL_ENABLE) | GE_HOST_STC, SMB_GLOBAL_ENABLE);
|
||||
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
amd756_do_pause(1);
|
||||
temp=inw_p(SMB_GLOBAL_STATUS);
|
||||
} while ((temp & GS_HST_STS) && (timeout++ < MAX_TIMEOUT));
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
amd756_do_pause(1);
|
||||
temp = inw_p(SMB_GLOBAL_STATUS);
|
||||
} while ((temp & GS_HST_STS) && (timeout++ < MAX_TIMEOUT));
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: SMBus explicit timeout!\n");
|
||||
result = -1;
|
||||
printk("i2c-amd756.o: SMBus explicit timeout!\n");
|
||||
result = -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & GS_PRERR_STS) {
|
||||
result = -1;
|
||||
if (temp & GS_PRERR_STS) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: SMBus Protocol error!\n");
|
||||
printk("i2c-amd756.o: SMBus Protocol error!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & GS_COL_STS) {
|
||||
result = -1;
|
||||
printk("i2c-amd756.o: SMBus collision!\n");
|
||||
/* TODO: Clear Collision Status with a 1 */
|
||||
}
|
||||
if (temp & GS_COL_STS) {
|
||||
result = -1;
|
||||
printk("i2c-amd756.o: SMBus collision!\n");
|
||||
/* TODO: Clear Collision Status with a 1 */
|
||||
}
|
||||
|
||||
if (temp & GS_TO_STS) {
|
||||
result = -1;
|
||||
if (temp & GS_TO_STS) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: SMBus protocol timeout!\n");
|
||||
printk("i2c-amd756.o: SMBus protocol timeout!\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if (temp & GS_HCYC_STS) {
|
||||
printk("i2c-amd756.o: SMBus protocol success!\n");
|
||||
}
|
||||
if (temp & GS_HCYC_STS) {
|
||||
printk("i2c-amd756.o: SMBus protocol success!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
outw_p (GS_CLEAR_STS, SMB_GLOBAL_STATUS);
|
||||
outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS);
|
||||
|
||||
if (((temp = inw_p (SMB_GLOBAL_STATUS)) & GS_CLEAR_STS) != 0x00) {
|
||||
if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_CLEAR_STS) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: Failed reset at end of transaction (%04x)\n",temp);
|
||||
printk
|
||||
("i2c-amd756.o: Failed reset at end of transaction (%04x)\n",
|
||||
temp);
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printk("i2c-amd756.o: 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));
|
||||
printk
|
||||
("i2c-amd756.o: 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;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return -1 on error. See smbus.h for more information */
|
||||
s32 amd756_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
s32 amd756_access(struct i2c_adapter * adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
{
|
||||
int i,len;
|
||||
|
||||
int i, len;
|
||||
|
||||
/** TODO: Should I supporte the 10-bit transfers? */
|
||||
switch(size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk("i2c-amd756.o: 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:
|
||||
outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS);
|
||||
size = AMD756_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS);
|
||||
/* TODO: Why only during write? */
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p (command, SMB_HOST_COMMAND);
|
||||
size = AMD756_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS);
|
||||
outb_p (command, SMB_HOST_COMMAND);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outw_p(data->byte, SMB_HOST_DATA);
|
||||
size = AMD756_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS);
|
||||
outb_p (command, SMB_HOST_COMMAND);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outw_p (data->word, SMB_HOST_DATA); /* TODO: endian???? */
|
||||
size = AMD756_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS);
|
||||
outb_p (command, SMB_HOST_COMMAND);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outw_p (len, SMB_HOST_DATA);
|
||||
/* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i ++)
|
||||
outb_p (data->block[i], SMB_HOST_BLOCK_DATA);
|
||||
}
|
||||
size = AMD756_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
switch (size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk
|
||||
("i2c-amd756.o: 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:
|
||||
outw_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMB_HOST_ADDRESS);
|
||||
size = AMD756_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outw_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMB_HOST_ADDRESS);
|
||||
/* TODO: Why only during write? */
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMB_HOST_COMMAND);
|
||||
size = AMD756_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outw_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMB_HOST_ADDRESS);
|
||||
outb_p(command, SMB_HOST_COMMAND);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outw_p(data->byte, SMB_HOST_DATA);
|
||||
size = AMD756_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outw_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMB_HOST_ADDRESS);
|
||||
outb_p(command, SMB_HOST_COMMAND);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outw_p(data->word, SMB_HOST_DATA); /* TODO: endian???? */
|
||||
size = AMD756_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outw_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMB_HOST_ADDRESS);
|
||||
outb_p(command, SMB_HOST_COMMAND);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outw_p(len, SMB_HOST_DATA);
|
||||
/* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i++)
|
||||
outb_p(data->block[i],
|
||||
SMB_HOST_BLOCK_DATA);
|
||||
}
|
||||
size = AMD756_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
/* How about enabling interrupts... */
|
||||
outw_p (size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE);
|
||||
/* How about enabling interrupts... */
|
||||
outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE);
|
||||
|
||||
if (amd756_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK))
|
||||
return 0;
|
||||
|
||||
if (amd756_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
switch(size) {
|
||||
case AMD756_BYTE:
|
||||
data->byte = inw_p (SMB_HOST_DATA);
|
||||
break;
|
||||
case AMD756_BYTE_DATA:
|
||||
data->byte = inw_p (SMB_HOST_DATA);
|
||||
break;
|
||||
case AMD756_WORD_DATA:
|
||||
data->word = inw_p (SMB_HOST_DATA); /* TODO: endian???? */
|
||||
break;
|
||||
case AMD756_BLOCK_DATA:
|
||||
data->block[0] = inw_p (SMB_HOST_DATA & 63);
|
||||
/* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */
|
||||
for (i = 1; i <= data->block[0]; i++)
|
||||
data->block[i] = inb_p (SMB_HOST_BLOCK_DATA);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK))
|
||||
return 0;
|
||||
|
||||
|
||||
switch (size) {
|
||||
case AMD756_BYTE:
|
||||
data->byte = inw_p(SMB_HOST_DATA);
|
||||
break;
|
||||
case AMD756_BYTE_DATA:
|
||||
data->byte = inw_p(SMB_HOST_DATA);
|
||||
break;
|
||||
case AMD756_WORD_DATA:
|
||||
data->word = inw_p(SMB_HOST_DATA); /* TODO: endian???? */
|
||||
break;
|
||||
case AMD756_BLOCK_DATA:
|
||||
data->block[0] = inw_p(SMB_HOST_DATA & 63);
|
||||
/* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */
|
||||
for (i = 1; i <= data->block[0]; i++)
|
||||
data->block[i] = inb_p(SMB_HOST_BLOCK_DATA);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void amd756_inc(struct i2c_adapter *adapter)
|
||||
@@ -417,56 +436,60 @@ void amd756_dec(struct i2c_adapter *adapter)
|
||||
|
||||
u32 amd756_func(struct i2c_adapter *adapter)
|
||||
{
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL;
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL;
|
||||
}
|
||||
|
||||
int __init i2c_amd756_init(void)
|
||||
{
|
||||
int res;
|
||||
printk("amd756.o version %s (%s)\n",LM_VERSION,LM_DATE);
|
||||
int res;
|
||||
printk("amd756.o version %s (%s)\n", LM_VERSION, LM_DATE);
|
||||
#ifdef DEBUG
|
||||
/* PE- It might be good to make this a permanent part of the code! */
|
||||
if (amd756_initialized) {
|
||||
printk("i2c-amd756.o: Oops, amd756_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (amd756_initialized) {
|
||||
printk
|
||||
("i2c-amd756.o: Oops, amd756_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
#endif
|
||||
amd756_initialized = 0;
|
||||
if ((res = amd756_setup())) {
|
||||
printk("i2c-amd756.o: AMD756 not detected, module not inserted.\n");
|
||||
amd756_cleanup();
|
||||
return res;
|
||||
}
|
||||
amd756_initialized ++;
|
||||
sprintf(amd756_adapter.name,"SMBus AMD756 adapter at %04x",amd756_smba);
|
||||
if ((res = i2c_add_adapter(&amd756_adapter))) {
|
||||
printk("i2c-amd756.o: Adapter registration failed, module not inserted.\n");
|
||||
amd756_cleanup();
|
||||
return res;
|
||||
}
|
||||
amd756_initialized++;
|
||||
printk("i2c-amd756.o: AMD756 bus detected and initialized\n");
|
||||
return 0;
|
||||
amd756_initialized = 0;
|
||||
if ((res = amd756_setup())) {
|
||||
printk
|
||||
("i2c-amd756.o: AMD756 not detected, module not inserted.\n");
|
||||
amd756_cleanup();
|
||||
return res;
|
||||
}
|
||||
amd756_initialized++;
|
||||
sprintf(amd756_adapter.name, "SMBus AMD756 adapter at %04x",
|
||||
amd756_smba);
|
||||
if ((res = i2c_add_adapter(&amd756_adapter))) {
|
||||
printk
|
||||
("i2c-amd756.o: Adapter registration failed, module not inserted.\n");
|
||||
amd756_cleanup();
|
||||
return res;
|
||||
}
|
||||
amd756_initialized++;
|
||||
printk("i2c-amd756.o: AMD756 bus detected and initialized\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init amd756_cleanup(void)
|
||||
{
|
||||
int res;
|
||||
if (amd756_initialized >= 2)
|
||||
{
|
||||
if ((res = i2c_del_adapter(&amd756_adapter))) {
|
||||
printk("i2c-amd756.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
amd756_initialized--;
|
||||
}
|
||||
if (amd756_initialized >= 1) {
|
||||
release_region(amd756_smba, 8);
|
||||
amd756_initialized--;
|
||||
}
|
||||
return 0;
|
||||
int res;
|
||||
if (amd756_initialized >= 2) {
|
||||
if ((res = i2c_del_adapter(&amd756_adapter))) {
|
||||
printk
|
||||
("i2c-amd756.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
amd756_initialized--;
|
||||
}
|
||||
if (amd756_initialized >= 1) {
|
||||
release_region(amd756_smba, 8);
|
||||
amd756_initialized--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_NO_SYMBOLS;
|
||||
@@ -478,13 +501,12 @@ MODULE_DESCRIPTION("AMD756 SMBus driver");
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_amd756_init();
|
||||
return i2c_amd756_init();
|
||||
}
|
||||
|
||||
int cleanup_module(void)
|
||||
{
|
||||
return amd756_cleanup();
|
||||
return amd756_cleanup();
|
||||
}
|
||||
|
||||
#endif /* MODULE */
|
||||
|
||||
#endif /* MODULE */
|
||||
+29
-29
@@ -57,37 +57,37 @@ static unsigned long hydra_base;
|
||||
|
||||
static inline void pdregw(u32 val)
|
||||
{
|
||||
writel(val, hydra_base+HYDRA_CACHE_PD);
|
||||
writel(val, hydra_base + HYDRA_CACHE_PD);
|
||||
}
|
||||
|
||||
static inline u32 pdregr(void)
|
||||
{
|
||||
u32 val = readl(hydra_base+HYDRA_CACHE_PD);
|
||||
u32 val = readl(hydra_base + HYDRA_CACHE_PD);
|
||||
return val;
|
||||
}
|
||||
|
||||
static void bit_hydra_setscl(void *data, int state)
|
||||
{
|
||||
u32 val = pdregr();
|
||||
if (state)
|
||||
val &= ~ HYDRA_SCLK_OE;
|
||||
else {
|
||||
val &= ~HYDRA_SCLK;
|
||||
val |= HYDRA_SCLK_OE;
|
||||
}
|
||||
pdregw(val);
|
||||
u32 val = pdregr();
|
||||
if (state)
|
||||
val &= ~HYDRA_SCLK_OE;
|
||||
else {
|
||||
val &= ~HYDRA_SCLK;
|
||||
val |= HYDRA_SCLK_OE;
|
||||
}
|
||||
pdregw(val);
|
||||
}
|
||||
|
||||
static void bit_hydra_setsda(void *data, int state)
|
||||
{
|
||||
u32 val = pdregr();
|
||||
if (state)
|
||||
val &= ~ HYDRA_SDAT_OE;
|
||||
else {
|
||||
val &= ~HYDRA_SDAT;
|
||||
val |= HYDRA_SDAT_OE;
|
||||
}
|
||||
pdregw(val);
|
||||
u32 val = pdregr();
|
||||
if (state)
|
||||
val &= ~HYDRA_SDAT_OE;
|
||||
else {
|
||||
val &= ~HYDRA_SDAT;
|
||||
val |= HYDRA_SDAT_OE;
|
||||
}
|
||||
pdregw(val);
|
||||
}
|
||||
|
||||
static int bit_hydra_getscl(void *data)
|
||||
@@ -118,7 +118,7 @@ struct i2c_algo_bit_data bit_hydra_data = {
|
||||
bit_hydra_setscl,
|
||||
bit_hydra_getsda,
|
||||
bit_hydra_getscl,
|
||||
5, 5, 100, /*waits, timeout */
|
||||
5, 5, 100, /*waits, timeout */
|
||||
};
|
||||
|
||||
struct i2c_adapter bit_hydra_ops = {
|
||||
@@ -140,20 +140,19 @@ static int find_hydra(void)
|
||||
|
||||
if (!pci_present())
|
||||
return -ENODEV;
|
||||
|
||||
|
||||
dev = pci_find_device(VENDOR, DEVICE, NULL);
|
||||
if (!dev) {
|
||||
printk("Hydra not found\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13)
|
||||
base_addr = dev->resource[0].start;
|
||||
#else
|
||||
base_addr = dev->base_address[0];
|
||||
#endif
|
||||
hydra_base = (unsigned long)ioremap(base_addr, 0x100);
|
||||
hydra_base = (unsigned long) ioremap(base_addr, 0x100);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -163,21 +162,22 @@ static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_hydra_init(void)
|
||||
int __init i2c_hydra_init(void)
|
||||
{
|
||||
if (find_hydra() < 0) {
|
||||
printk("Error while reading PCI configuration\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
pdregw(0); /* clear SCLK_OE and SDAT_OE */
|
||||
pdregw(0); /* clear SCLK_OE and SDAT_OE */
|
||||
|
||||
if (i2c_bit_add_bus(&bit_hydra_ops) == 0) {
|
||||
printk("Hydra i2c: Module succesfully loaded\n");
|
||||
return 0;
|
||||
} else {
|
||||
iounmap((void *)hydra_base);
|
||||
printk("Hydra i2c: Algo-bit error, couldn't register bus\n");
|
||||
iounmap((void *) hydra_base);
|
||||
printk
|
||||
("Hydra i2c: Algo-bit error, couldn't register bus\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
@@ -188,17 +188,17 @@ EXPORT_NO_SYMBOLS;
|
||||
MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
|
||||
MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O");
|
||||
|
||||
int init_module(void)
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_hydra_init();
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
void cleanup_module(void)
|
||||
{
|
||||
i2c_bit_del_bus(&bit_hydra_ops);
|
||||
if (hydra_base) {
|
||||
pdregw(0); /* clear SCLK_OE and SDAT_OE */
|
||||
iounmap((void *)hydra_base);
|
||||
iounmap((void *) hydra_base);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+398
-361
@@ -23,7 +23,7 @@
|
||||
This driver supports the Intel 82801AA and 82801AB
|
||||
I/O Controller Hubs (ICH). They are similar to the PIIX4 and are part
|
||||
of Intel's '810' chipset. See the doc/busses/i2c-i801 file for details.
|
||||
*/
|
||||
*/
|
||||
|
||||
/* Note: we assume there can only be one I801, with one SMBus interface */
|
||||
|
||||
@@ -79,24 +79,26 @@
|
||||
/* If force is set to anything different from 0, we forcibly enable the
|
||||
I801. DANGEROUS! */
|
||||
static int force = 0;
|
||||
MODULE_PARM(force,"i");
|
||||
MODULE_PARM_DESC(force,"Forcibly enable the I801. DANGEROUS!");
|
||||
MODULE_PARM(force, "i");
|
||||
MODULE_PARM_DESC(force, "Forcibly enable the I801. DANGEROUS!");
|
||||
|
||||
/* If force_addr is set to anything different from 0, we forcibly enable
|
||||
the I801 at the given address. VERY DANGEROUS! */
|
||||
static int force_addr = 0;
|
||||
MODULE_PARM(force_addr,"i");
|
||||
MODULE_PARM_DESC(force_addr,"Forcibly enable the I801 at the given address. "
|
||||
"EXTREMELY DANGEROUS!");
|
||||
MODULE_PARM(force_addr, "i");
|
||||
MODULE_PARM_DESC(force_addr,
|
||||
"Forcibly enable the I801 at the given address. "
|
||||
"EXTREMELY DANGEROUS!");
|
||||
|
||||
static int __init i801_cleanup(void);
|
||||
static int i801_setup(void);
|
||||
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);
|
||||
static void i801_do_pause( unsigned int amount );
|
||||
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);
|
||||
static void i801_do_pause(unsigned int amount);
|
||||
static int i801_transaction(void);
|
||||
static 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);
|
||||
static void i801_inc(struct i2c_adapter *adapter);
|
||||
static void i801_dec(struct i2c_adapter *adapter);
|
||||
static u32 i801_func(struct i2c_adapter *adapter);
|
||||
@@ -104,28 +106,28 @@ static u32 i801_func(struct i2c_adapter *adapter);
|
||||
#ifdef MODULE
|
||||
extern int init_module(void);
|
||||
extern int cleanup_module(void);
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
|
||||
static struct i2c_algorithm smbus_algorithm = {
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ i801_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ i801_func,
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ i801_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ i801_func,
|
||||
};
|
||||
|
||||
static struct i2c_adapter i801_adapter = {
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
i801_inc,
|
||||
i801_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
i801_inc,
|
||||
i801_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int __initdata i801_initialized;
|
||||
@@ -138,393 +140,424 @@ static unsigned short i801_smba = 0;
|
||||
defined to make the transition easier. */
|
||||
int i801_setup(void)
|
||||
{
|
||||
int error_return=0;
|
||||
unsigned char temp;
|
||||
int error_return = 0;
|
||||
unsigned char temp;
|
||||
|
||||
struct pci_dev *I801_dev;
|
||||
struct pci_dev *I801_dev;
|
||||
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-i801.o: Error: No PCI-bus found!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-i801.o: Error: No PCI-bus found!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Look for the I801, function 3 */
|
||||
/* Have to check for both the 82801AA and 82801AB */
|
||||
/* Note: we keep on searching until we have found 'function 3' */
|
||||
I801_dev = NULL;
|
||||
do
|
||||
I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
|
||||
PCI_DEVICE_ID_INTEL_82801AA_3, I801_dev);
|
||||
while(I801_dev && (PCI_FUNC(I801_dev->devfn) != 3));
|
||||
if(I801_dev == NULL) {
|
||||
do
|
||||
I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
|
||||
PCI_DEVICE_ID_INTEL_82801AB_3, I801_dev);
|
||||
while(I801_dev && (PCI_FUNC(I801_dev->devfn) != 3));
|
||||
}
|
||||
if(I801_dev == NULL) {
|
||||
printk("i2c-i801.o: Error: Can't detect I801, function 3!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* Look for the I801, function 3 */
|
||||
/* Have to check for both the 82801AA and 82801AB */
|
||||
/* Note: we keep on searching until we have found 'function 3' */
|
||||
I801_dev = NULL;
|
||||
do
|
||||
I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
|
||||
PCI_DEVICE_ID_INTEL_82801AA_3,
|
||||
I801_dev);
|
||||
while (I801_dev && (PCI_FUNC(I801_dev->devfn) != 3));
|
||||
if (I801_dev == NULL) {
|
||||
do
|
||||
I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
|
||||
PCI_DEVICE_ID_INTEL_82801AB_3,
|
||||
I801_dev);
|
||||
while (I801_dev && (PCI_FUNC(I801_dev->devfn) != 3));
|
||||
}
|
||||
if (I801_dev == NULL) {
|
||||
printk
|
||||
("i2c-i801.o: Error: Can't detect I801, function 3!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Determine the address of the SMBus areas */
|
||||
if (force_addr) {
|
||||
i801_smba = force_addr & 0xfff0;
|
||||
force = 0;
|
||||
} else {
|
||||
pci_read_config_word(I801_dev, SMBBA,&i801_smba);
|
||||
i801_smba &= 0xfff0;
|
||||
}
|
||||
if (force_addr) {
|
||||
i801_smba = force_addr & 0xfff0;
|
||||
force = 0;
|
||||
} else {
|
||||
pci_read_config_word(I801_dev, SMBBA, &i801_smba);
|
||||
i801_smba &= 0xfff0;
|
||||
}
|
||||
|
||||
if (check_region(i801_smba, 8)) {
|
||||
printk("i2c-i801.o: I801_smb region 0x%x already in use!\n", i801_smba);
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
if (check_region(i801_smba, 8)) {
|
||||
printk
|
||||
("i2c-i801.o: I801_smb region 0x%x already in use!\n",
|
||||
i801_smba);
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pci_read_config_byte(I801_dev, SMBHSTCFG, &temp);
|
||||
pci_read_config_byte(I801_dev, SMBHSTCFG, &temp);
|
||||
/* If force_addr is set, we program the new address here. Just to make
|
||||
sure, we disable the I801 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("i2c-i801.o: WARNING: I801 SMBus interface set to new "
|
||||
"address %04x!\n",i801_smba);
|
||||
} else if ((temp & 1) == 0) {
|
||||
if (force) {
|
||||
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
|
||||
("i2c-i801.o: WARNING: I801 SMBus interface set to new "
|
||||
"address %04x!\n", i801_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. */
|
||||
pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 1);
|
||||
printk("i2c-i801.o: WARNING: I801 SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!\n");
|
||||
} else {
|
||||
printk("SMBUS: Error: Host SMBus controller not enabled!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
pci_write_config_byte(I801_dev, SMBHSTCFG,
|
||||
temp | 1);
|
||||
printk
|
||||
("i2c-i801.o: WARNING: I801 SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!\n");
|
||||
} else {
|
||||
printk
|
||||
("SMBUS: Error: Host SMBus controller not enabled!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
/* note: we assumed that the BIOS picked SMBus or I2C Bus timing
|
||||
appropriately (bit 2 in SMBHSTCFG) */
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(i801_smba, 8, "i801-smbus");
|
||||
/* note: we assumed that the BIOS picked SMBus or I2C Bus timing
|
||||
appropriately (bit 2 in SMBHSTCFG) */
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(i801_smba, 8, "i801-smbus");
|
||||
|
||||
#ifdef DEBUG
|
||||
if (temp & 0x02)
|
||||
printk("i2c-i801.o: I801 using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk("i2c-i801.o: I801 using PCI Interrupt for SMBus.\n");
|
||||
if (temp & 0x02)
|
||||
printk
|
||||
("i2c-i801.o: I801 using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk
|
||||
("i2c-i801.o: I801 using PCI Interrupt for SMBus.\n");
|
||||
|
||||
pci_read_config_byte(I801_dev, SMBREV, &temp);
|
||||
printk("i2c-i801.o: SMBREV = 0x%X\n",temp);
|
||||
printk("i2c-i801.o: I801_smba = 0x%X\n",i801_smba);
|
||||
#endif /* DEBUG */
|
||||
pci_read_config_byte(I801_dev, SMBREV, &temp);
|
||||
printk("i2c-i801.o: SMBREV = 0x%X\n", temp);
|
||||
printk("i2c-i801.o: I801_smba = 0x%X\n", i801_smba);
|
||||
#endif /* DEBUG */
|
||||
|
||||
END:
|
||||
return error_return;
|
||||
END:
|
||||
return error_return;
|
||||
}
|
||||
|
||||
|
||||
/* Internally used pause function */
|
||||
void i801_do_pause( unsigned int amount )
|
||||
void i801_do_pause(unsigned int amount)
|
||||
{
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
}
|
||||
|
||||
/* Another internally used function */
|
||||
int i801_transaction(void)
|
||||
int i801_transaction(void)
|
||||
{
|
||||
int temp;
|
||||
int result=0;
|
||||
int timeout=0;
|
||||
int temp;
|
||||
int result = 0;
|
||||
int timeout = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
printk("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));
|
||||
printk
|
||||
("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
|
||||
|
||||
/* 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) {
|
||||
/* 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("i2c-i801.o: SMBus busy (%02x). Resetting... \n",temp);
|
||||
printk("i2c-i801.o: SMBus busy (%02x). Resetting... \n",
|
||||
temp);
|
||||
#endif
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Failed! (%02x)\n",temp);
|
||||
printk("i2c-i801.o: Failed! (%02x)\n", temp);
|
||||
#endif
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Successfull!\n");
|
||||
printk("i2c-i801.o: Successfull!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
i801_do_pause(1);
|
||||
temp=inb_p(SMBHSTSTS);
|
||||
} while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
i801_do_pause(1);
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
} while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: SMBus Timeout!\n");
|
||||
result = -1;
|
||||
printk("i2c-i801.o: SMBus Timeout!\n");
|
||||
result = -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Error: Failed bus transaction\n");
|
||||
printk("i2c-i801.o: Error: Failed bus transaction\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk("i2c-i801.o: Bus collision! SMBus may be locked until next hard
|
||||
reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk
|
||||
("i2c-i801.o: Bus collision! SMBus may be locked until next hard\n"
|
||||
"reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
|
||||
if (temp & 0x04) {
|
||||
result = -1;
|
||||
if (temp & 0x04) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Error: no response!\n");
|
||||
printk("i2c-i801.o: Error: no response!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00)
|
||||
outb_p( inb(SMBHSTSTS), SMBHSTSTS);
|
||||
if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00)
|
||||
outb_p(inb(SMBHSTSTS), SMBHSTSTS);
|
||||
|
||||
if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
|
||||
if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Failed reset at end of transaction (%02x)\n",temp);
|
||||
printk
|
||||
("i2c-i801.o: Failed reset at end of transaction (%02x)\n",
|
||||
temp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printk("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));
|
||||
printk
|
||||
("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
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* All-inclusive block transaction function */
|
||||
int i801_block_transaction(union i2c_smbus_data *data, char read_write)
|
||||
{
|
||||
int i, len;
|
||||
int smbcmd;
|
||||
int temp;
|
||||
int result=0;
|
||||
int timeout=0;
|
||||
int i, len;
|
||||
int smbcmd;
|
||||
int temp;
|
||||
int result = 0;
|
||||
int timeout = 0;
|
||||
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 1)
|
||||
len = 1;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outb_p(len,SMBHSTDAT0);
|
||||
outb_p(data->block[1],SMBBLKDAT);
|
||||
} else {
|
||||
len = 32; /* max for reads */
|
||||
}
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 1)
|
||||
len = 1;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outb_p(len, SMBHSTDAT0);
|
||||
outb_p(data->block[1], SMBBLKDAT);
|
||||
} else {
|
||||
len = 32; /* max for reads */
|
||||
}
|
||||
|
||||
for(i = 1; i <= len; i++)
|
||||
{
|
||||
if(i == len && read_write == I2C_SMBUS_READ)
|
||||
smbcmd = I801_BLOCK_LAST;
|
||||
else
|
||||
smbcmd = I801_BLOCK_DATA;
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->block[i],SMBBLKDAT);
|
||||
outb_p((smbcmd & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
for (i = 1; i <= len; i++) {
|
||||
if (i == len && read_write == I2C_SMBUS_READ)
|
||||
smbcmd = I801_BLOCK_LAST;
|
||||
else
|
||||
smbcmd = I801_BLOCK_DATA;
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->block[i], SMBBLKDAT);
|
||||
outb_p((smbcmd & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
|
||||
#ifdef DEBUG
|
||||
printk("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));
|
||||
printk
|
||||
("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
|
||||
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
/* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
|
||||
/* 0x9e = Byte_Done, Failed, Bus_Err, Dev_Err, Intr */
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
if (((i == 1) && ((temp & 0x1f) != 0x00)) ||
|
||||
((i != 1) && ((temp & 0x9e) != 0x00)))
|
||||
{
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
/* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
|
||||
/* 0x9e = Byte_Done, Failed, Bus_Err, Dev_Err, Intr */
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
if (((i == 1) && ((temp & 0x1f) != 0x00)) ||
|
||||
((i != 1) && ((temp & 0x9e) != 0x00))) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: SMBus busy (%02x). Resetting... \n",temp);
|
||||
printk
|
||||
("i2c-i801.o: SMBus busy (%02x). Resetting... \n",
|
||||
temp);
|
||||
#endif
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if (((temp = inb_p(SMBHSTSTS)) & 0x9f) != 0x00)
|
||||
{
|
||||
printk("i2c-i801.o: Reset failed! (%02x)\n",temp);
|
||||
return -1;
|
||||
}
|
||||
if(i != 1)
|
||||
return -1; /* if die in middle of block transaction, fail */
|
||||
}
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if (((temp = inb_p(SMBHSTSTS)) & 0x9f) != 0x00) {
|
||||
printk
|
||||
("i2c-i801.o: Reset failed! (%02x)\n",
|
||||
temp);
|
||||
return -1;
|
||||
}
|
||||
if (i != 1)
|
||||
return -1; /* if die in middle of block transaction, fail */
|
||||
}
|
||||
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
i801_do_pause(1);
|
||||
temp=inb_p(SMBHSTSTS);
|
||||
} while ((((i >= len) && (temp & 0x01)) || ((i < len) && (temp & 0x80)))
|
||||
&& (timeout++ < MAX_TIMEOUT));
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
i801_do_pause(1);
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
}
|
||||
while (
|
||||
(((i >= len) && (temp & 0x01))
|
||||
|| ((i < len) && (temp & 0x80)))
|
||||
&& (timeout++ < MAX_TIMEOUT));
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
result = -1;
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: SMBus Timeout!\n");
|
||||
printk("i2c-i801.o: SMBus Timeout!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Error: Failed bus transaction\n");
|
||||
printk
|
||||
("i2c-i801.o: Error: Failed bus transaction\n");
|
||||
#endif
|
||||
} else if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk("i2c-i801.o: Bus collision! SMBus may be locked until next hard"
|
||||
" reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
} else if (temp & 0x04) {
|
||||
result = -1;
|
||||
} else if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk
|
||||
("i2c-i801.o: Bus collision! SMBus may be locked until next hard"
|
||||
" reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
} else if (temp & 0x04) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Error: no response!\n");
|
||||
printk("i2c-i801.o: Error: no response!\n");
|
||||
#endif
|
||||
} else if (temp & 0x80) {
|
||||
result = -1;
|
||||
} else if (temp & 0x80) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Error: Failed in middle of block!\n");
|
||||
printk
|
||||
("i2c-i801.o: Error: Failed in middle of block!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if ((temp & 0x9f) != 0x00)
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if ((temp & 0x9f) != 0x00)
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
|
||||
if ((temp = (0x9f & inb_p(SMBHSTSTS))) != 0x00) {
|
||||
if ((temp = (0x9f & inb_p(SMBHSTSTS))) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-i801.o: Failed reset at end of transaction (%02x)\n",temp);
|
||||
printk
|
||||
("i2c-i801.o: Failed reset at end of transaction (%02x)\n",
|
||||
temp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printk("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));
|
||||
printk
|
||||
("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
|
||||
|
||||
if (i == 1 && read_write == I2C_SMBUS_READ) {
|
||||
len = inb_p(SMBHSTDAT0);
|
||||
if (len < 1)
|
||||
len = 1;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
data->block[0] = len;
|
||||
}
|
||||
if (read_write == I2C_SMBUS_READ)
|
||||
data->block[i] = inb_p(SMBBLKDAT);
|
||||
if (i == 1 && read_write == I2C_SMBUS_READ) {
|
||||
len = inb_p(SMBHSTDAT0);
|
||||
if (len < 1)
|
||||
len = 1;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
data->block[0] = len;
|
||||
}
|
||||
if (read_write == I2C_SMBUS_READ)
|
||||
data->block[i] = inb_p(SMBBLKDAT);
|
||||
|
||||
if(result < 0)
|
||||
return(result);
|
||||
}
|
||||
return(0);
|
||||
if (result < 0)
|
||||
return (result);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Return -1 on error. See smbus.h for more information */
|
||||
s32 i801_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
|
||||
char read_write, u8 command, int size,
|
||||
union i2c_smbus_data * data)
|
||||
s32 i801_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
|
||||
char read_write, u8 command, int size,
|
||||
union i2c_smbus_data * data)
|
||||
{
|
||||
|
||||
switch(size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk("i2c-i801.o: I2C_SMBUS_PROC_CALL not supported!\n");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
size = I801_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = I801_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte,SMBHSTDAT0);
|
||||
size = I801_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff,SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1);
|
||||
}
|
||||
size = I801_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
/* Block transactions are very different from piix4 block
|
||||
and from the other i801 transactions. Handle in the
|
||||
i801_block_transaction() routine. */
|
||||
return(i801_block_transaction(data, read_write));
|
||||
}
|
||||
switch (size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk("i2c-i801.o: I2C_SMBUS_PROC_CALL not supported!\n");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
size = I801_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = I801_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte, SMBHSTDAT0);
|
||||
size = I801_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff, SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
|
||||
}
|
||||
size = I801_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
/* Block transactions are very different from piix4 block
|
||||
and from the other i801 transactions. Handle in the
|
||||
i801_block_transaction() routine. */
|
||||
return (i801_block_transaction(data, read_write));
|
||||
}
|
||||
|
||||
/* 'size' is really the transaction type */
|
||||
outb_p((size & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
/* 'size' is really the transaction type */
|
||||
outb_p((size & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
|
||||
if (i801_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == I801_QUICK))
|
||||
return 0;
|
||||
|
||||
if (i801_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
switch(size) {
|
||||
case I801_BYTE: /* Result put in SMBHSTDAT0 */
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case I801_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case I801_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == I801_QUICK))
|
||||
return 0;
|
||||
|
||||
|
||||
switch (size) {
|
||||
case I801_BYTE: /* Result put in SMBHSTDAT0 */
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case I801_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case I801_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void i801_inc(struct i2c_adapter *adapter)
|
||||
@@ -539,74 +572,78 @@ void i801_dec(struct i2c_adapter *adapter)
|
||||
|
||||
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 |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
}
|
||||
|
||||
int __init i2c_i801_init(void)
|
||||
{
|
||||
int res;
|
||||
printk("i801.o version %s (%s)\n",LM_VERSION,LM_DATE);
|
||||
int res;
|
||||
printk("i801.o version %s (%s)\n", LM_VERSION, LM_DATE);
|
||||
#ifdef DEBUG
|
||||
/* PE- It might be good to make this a permanent part of the code! */
|
||||
if (i801_initialized) {
|
||||
printk("i2c-i801.o: Oops, i801_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (i801_initialized) {
|
||||
printk
|
||||
("i2c-i801.o: Oops, i801_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
#endif
|
||||
i801_initialized = 0;
|
||||
if ((res = i801_setup())) {
|
||||
printk("i2c-i801.o: I801 not detected, module not inserted.\n");
|
||||
i801_cleanup();
|
||||
return res;
|
||||
}
|
||||
i801_initialized ++;
|
||||
sprintf(i801_adapter.name,"SMBus I801 adapter at %04x",i801_smba);
|
||||
if ((res = i2c_add_adapter(&i801_adapter))) {
|
||||
printk("i2c-i801.o: Adapter registration failed, module not inserted.\n");
|
||||
i801_cleanup();
|
||||
return res;
|
||||
}
|
||||
i801_initialized++;
|
||||
printk("i2c-i801.o: I801 bus detected and initialized\n");
|
||||
return 0;
|
||||
i801_initialized = 0;
|
||||
if ((res = i801_setup())) {
|
||||
printk
|
||||
("i2c-i801.o: I801 not detected, module not inserted.\n");
|
||||
i801_cleanup();
|
||||
return res;
|
||||
}
|
||||
i801_initialized++;
|
||||
sprintf(i801_adapter.name, "SMBus I801 adapter at %04x",
|
||||
i801_smba);
|
||||
if ((res = i2c_add_adapter(&i801_adapter))) {
|
||||
printk
|
||||
("i2c-i801.o: Adapter registration failed, module not inserted.\n");
|
||||
i801_cleanup();
|
||||
return res;
|
||||
}
|
||||
i801_initialized++;
|
||||
printk("i2c-i801.o: I801 bus detected and initialized\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init i801_cleanup(void)
|
||||
{
|
||||
int res;
|
||||
if (i801_initialized >= 2)
|
||||
{
|
||||
if ((res = i2c_del_adapter(&i801_adapter))) {
|
||||
printk("i2c-i801.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
i801_initialized--;
|
||||
}
|
||||
if (i801_initialized >= 1) {
|
||||
release_region(i801_smba, 8);
|
||||
i801_initialized--;
|
||||
}
|
||||
return 0;
|
||||
int res;
|
||||
if (i801_initialized >= 2) {
|
||||
if ((res = i2c_del_adapter(&i801_adapter))) {
|
||||
printk
|
||||
("i2c-i801.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
i801_initialized--;
|
||||
}
|
||||
if (i801_initialized >= 1) {
|
||||
release_region(i801_smba, 8);
|
||||
i801_initialized--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_NO_SYMBOLS;
|
||||
|
||||
#ifdef MODULE
|
||||
|
||||
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");
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_i801_init();
|
||||
return i2c_i801_init();
|
||||
}
|
||||
|
||||
int cleanup_module(void)
|
||||
{
|
||||
return i801_cleanup();
|
||||
return i801_cleanup();
|
||||
}
|
||||
|
||||
#endif /* MODULE */
|
||||
|
||||
#endif /* MODULE */
|
||||
+55
-55
@@ -36,8 +36,8 @@
|
||||
#include "version.h"
|
||||
#include "i2c-isa.h"
|
||||
|
||||
static void isa_inc_use (struct i2c_adapter *adapter);
|
||||
static void isa_dec_use (struct i2c_adapter *adapter);
|
||||
static void isa_inc_use(struct i2c_adapter *adapter);
|
||||
static void isa_dec_use(struct i2c_adapter *adapter);
|
||||
static u32 isa_func(struct i2c_adapter *adapter);
|
||||
|
||||
#ifdef MODULE
|
||||
@@ -45,95 +45,96 @@ static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_isa_init(void);
|
||||
int __init i2c_isa_init(void);
|
||||
static int __init isa_cleanup(void);
|
||||
|
||||
#ifdef MODULE
|
||||
extern int init_module(void);
|
||||
extern int cleanup_module(void);
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
|
||||
/* This is the actual algorithm we define */
|
||||
static struct i2c_algorithm isa_algorithm = {
|
||||
/* name */ "ISA bus algorithm",
|
||||
/* id */ I2C_ALGO_ISA,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ NULL,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ &isa_func,
|
||||
/* name */ "ISA bus algorithm",
|
||||
/* id */ I2C_ALGO_ISA,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ NULL,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ &isa_func,
|
||||
};
|
||||
|
||||
/* There can only be one... */
|
||||
static struct i2c_adapter isa_adapter = {
|
||||
/* name */ "ISA main adapter",
|
||||
/* id */ I2C_ALGO_ISA | I2C_HW_ISA,
|
||||
/* algorithm */ &isa_algorithm,
|
||||
/* algo_data */ NULL,
|
||||
/* inc_use */ &isa_inc_use,
|
||||
/* dec_use */ &isa_dec_use,
|
||||
/* data */ NULL,
|
||||
/* Other fields not initialized */
|
||||
/* name */ "ISA main adapter",
|
||||
/* id */ I2C_ALGO_ISA | I2C_HW_ISA,
|
||||
/* algorithm */ &isa_algorithm,
|
||||
/* algo_data */ NULL,
|
||||
/* inc_use */ &isa_inc_use,
|
||||
/* dec_use */ &isa_dec_use,
|
||||
/* data */ NULL,
|
||||
/* Other fields not initialized */
|
||||
};
|
||||
|
||||
/* Used in isa_init/cleanup */
|
||||
static int __initdata isa_initialized;
|
||||
|
||||
void isa_inc_use (struct i2c_adapter *adapter)
|
||||
void isa_inc_use(struct i2c_adapter *adapter)
|
||||
{
|
||||
#ifdef MODULE
|
||||
MOD_INC_USE_COUNT;
|
||||
MOD_INC_USE_COUNT;
|
||||
#endif
|
||||
}
|
||||
|
||||
void isa_dec_use (struct i2c_adapter *adapter)
|
||||
void isa_dec_use(struct i2c_adapter *adapter)
|
||||
{
|
||||
#ifdef MODULE
|
||||
MOD_DEC_USE_COUNT;
|
||||
MOD_DEC_USE_COUNT;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We can't do a thing... */
|
||||
static u32 isa_func(struct i2c_adapter *adapter)
|
||||
{
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init i2c_isa_init(void)
|
||||
{
|
||||
int res;
|
||||
printk("i2c-isa.o version %s (%s)\n",LM_VERSION,LM_DATE);
|
||||
int res;
|
||||
printk("i2c-isa.o version %s (%s)\n", LM_VERSION, LM_DATE);
|
||||
#ifdef DEBUG
|
||||
if (isa_initialized) {
|
||||
printk("i2c-isa.o: Oops, isa_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (isa_initialized) {
|
||||
printk
|
||||
("i2c-isa.o: Oops, isa_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
#endif
|
||||
isa_initialized = 0;
|
||||
if ((res = i2c_add_adapter(&isa_adapter))) {
|
||||
printk("i2c-isa.o: Adapter registration failed, "
|
||||
"module i2c-isa.o is not inserted\n.");
|
||||
isa_cleanup();
|
||||
return res;
|
||||
}
|
||||
isa_initialized++;
|
||||
printk("i2c-isa.o: ISA bus access for i2c modules initialized.\n");
|
||||
return 0;
|
||||
isa_initialized = 0;
|
||||
if ((res = i2c_add_adapter(&isa_adapter))) {
|
||||
printk("i2c-isa.o: Adapter registration failed, "
|
||||
"module i2c-isa.o is not inserted\n.");
|
||||
isa_cleanup();
|
||||
return res;
|
||||
}
|
||||
isa_initialized++;
|
||||
printk("i2c-isa.o: ISA bus access for i2c modules initialized.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init isa_cleanup(void)
|
||||
{
|
||||
int res;
|
||||
if (isa_initialized >= 1)
|
||||
{
|
||||
if ((res = i2c_del_adapter(&isa_adapter))) {
|
||||
printk("i2c-isa.o: Adapter deregistration failed, module not removed.\n");
|
||||
return res;
|
||||
} else
|
||||
isa_initialized--;
|
||||
}
|
||||
return 0;
|
||||
int res;
|
||||
if (isa_initialized >= 1) {
|
||||
if ((res = i2c_del_adapter(&isa_adapter))) {
|
||||
printk
|
||||
("i2c-isa.o: Adapter deregistration failed, module not removed.\n");
|
||||
return res;
|
||||
} else
|
||||
isa_initialized--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_NO_SYMBOLS;
|
||||
@@ -145,13 +146,12 @@ MODULE_DESCRIPTION("ISA bus access through i2c");
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_isa_init();
|
||||
return i2c_isa_init();
|
||||
}
|
||||
|
||||
int cleanup_module(void)
|
||||
{
|
||||
return isa_cleanup();
|
||||
return isa_cleanup();
|
||||
}
|
||||
|
||||
#endif /* MODULE */
|
||||
|
||||
#endif /* MODULE */
|
||||
+300
-274
@@ -72,28 +72,29 @@
|
||||
/* If force is set to anything different from 0, we forcibly enable the
|
||||
PIIX4. DANGEROUS! */
|
||||
static int force = 0;
|
||||
MODULE_PARM(force,"i");
|
||||
MODULE_PARM_DESC(force,"Forcibly enable the PIIX4. DANGEROUS!");
|
||||
MODULE_PARM(force, "i");
|
||||
MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!");
|
||||
|
||||
/* If force_addr is set to anything different from 0, we forcibly enable
|
||||
the PIIX4 at the given address. VERY DANGEROUS! */
|
||||
static int force_addr = 0;
|
||||
MODULE_PARM(force_addr,"i");
|
||||
MODULE_PARM_DESC(force_addr,"Forcibly enable the PIIX4 at the given address. "
|
||||
"EXTREMELY DANGEROUS!");
|
||||
MODULE_PARM(force_addr, "i");
|
||||
MODULE_PARM_DESC(force_addr,
|
||||
"Forcibly enable the PIIX4 at the given address. "
|
||||
"EXTREMELY DANGEROUS!");
|
||||
|
||||
#ifdef MODULE
|
||||
static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_piix4_init(void);
|
||||
int __init i2c_piix4_init(void);
|
||||
static int __init piix4_cleanup(void);
|
||||
static int piix4_setup(void);
|
||||
static s32 piix4_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data);
|
||||
static void piix4_do_pause( unsigned int amount );
|
||||
static s32 piix4_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data *data);
|
||||
static void piix4_do_pause(unsigned int amount);
|
||||
static int piix4_transaction(void);
|
||||
static void piix4_inc(struct i2c_adapter *adapter);
|
||||
static void piix4_dec(struct i2c_adapter *adapter);
|
||||
@@ -102,28 +103,28 @@ static u32 piix4_func(struct i2c_adapter *adapter);
|
||||
#ifdef MODULE
|
||||
extern int init_module(void);
|
||||
extern int cleanup_module(void);
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
|
||||
static struct i2c_algorithm smbus_algorithm = {
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ piix4_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ piix4_func,
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ piix4_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ piix4_func,
|
||||
};
|
||||
|
||||
static struct i2c_adapter piix4_adapter = {
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_PIIX4,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
piix4_inc,
|
||||
piix4_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_PIIX4,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
piix4_inc,
|
||||
piix4_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int __initdata piix4_initialized;
|
||||
@@ -136,275 +137,296 @@ static unsigned short piix4_smba = 0;
|
||||
defined to make the transition easier. */
|
||||
int piix4_setup(void)
|
||||
{
|
||||
int error_return=0;
|
||||
unsigned char temp;
|
||||
int error_return = 0;
|
||||
unsigned char temp;
|
||||
|
||||
struct pci_dev *PIIX4_dev;
|
||||
struct pci_dev *PIIX4_dev;
|
||||
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-piix4.o: Error: No PCI-bus found!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-piix4.o: Error: No PCI-bus found!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Look for the PIIX4, function 3 */
|
||||
/* Note: we keep on searching until we have found 'function 3' */
|
||||
PIIX4_dev = NULL;
|
||||
do
|
||||
PIIX4_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
|
||||
PCI_DEVICE_ID_INTEL_82371AB_3, PIIX4_dev);
|
||||
while(PIIX4_dev && (PCI_FUNC(PIIX4_dev->devfn) != 3));
|
||||
if(PIIX4_dev == NULL) {
|
||||
printk("i2c-piix4.o: Error: Can't detect PIIX4, function 3!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* Look for the PIIX4, function 3 */
|
||||
/* Note: we keep on searching until we have found 'function 3' */
|
||||
PIIX4_dev = NULL;
|
||||
do
|
||||
PIIX4_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
|
||||
PCI_DEVICE_ID_INTEL_82371AB_3,
|
||||
PIIX4_dev);
|
||||
while (PIIX4_dev && (PCI_FUNC(PIIX4_dev->devfn) != 3));
|
||||
if (PIIX4_dev == NULL) {
|
||||
printk
|
||||
("i2c-piix4.o: Error: Can't detect PIIX4, function 3!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Determine the address of the SMBus areas */
|
||||
if (force_addr) {
|
||||
piix4_smba = force_addr & 0xfff0;
|
||||
force = 0;
|
||||
} else {
|
||||
if (force_addr) {
|
||||
piix4_smba = force_addr & 0xfff0;
|
||||
force = 0;
|
||||
} else {
|
||||
|
||||
pci_read_config_word(PIIX4_dev, SMBBA,&piix4_smba);
|
||||
piix4_smba &= 0xfff0;
|
||||
}
|
||||
pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba);
|
||||
piix4_smba &= 0xfff0;
|
||||
}
|
||||
|
||||
if (check_region(piix4_smba, 8)) {
|
||||
printk("i2c-piix4.o: PIIX4_smb region 0x%x already in use!\n", piix4_smba);
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
if (check_region(piix4_smba, 8)) {
|
||||
printk
|
||||
("i2c-piix4.o: PIIX4_smb region 0x%x already in use!\n",
|
||||
piix4_smba);
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
|
||||
pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
|
||||
/* 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("i2c-piix4.o: WARNING: PIIX4 SMBus interface set to new "
|
||||
"address %04x!\n",piix4_smba);
|
||||
} else if ((temp & 1) == 0) {
|
||||
if (force) {
|
||||
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
|
||||
("i2c-piix4.o: WARNING: PIIX4 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. */
|
||||
pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 1);
|
||||
printk("i2c-piix4.o: WARNING: PIIX4 SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!\n");
|
||||
} else {
|
||||
printk("SMBUS: Error: Host SMBus controller not enabled!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
pci_write_config_byte(PIIX4_dev, SMBHSTCFG,
|
||||
temp | 1);
|
||||
printk
|
||||
("i2c-piix4.o: WARNING: PIIX4 SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!\n");
|
||||
} else {
|
||||
printk
|
||||
("SMBUS: Error: 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");
|
||||
/* 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("i2c-piix4.o: PIIX4 using Interrupt 9 for SMBus.\n");
|
||||
else if ((temp & 0x0E) == 0)
|
||||
printk("i2c-piix4.o: PIIX4 using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk("i2c-piix4.o: PIIX4: Illegal Interrupt configuration (or code out "
|
||||
"of date)!\n");
|
||||
if ((temp & 0x0E) == 8)
|
||||
printk
|
||||
("i2c-piix4.o: PIIX4 using Interrupt 9 for SMBus.\n");
|
||||
else if ((temp & 0x0E) == 0)
|
||||
printk
|
||||
("i2c-piix4.o: PIIX4 using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk
|
||||
("i2c-piix4.o: PIIX4: Illegal Interrupt configuration (or code out "
|
||||
"of date)!\n");
|
||||
|
||||
pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
|
||||
printk("i2c-piix4.o: SMBREV = 0x%X\n",temp);
|
||||
printk("i2c-piix4.o: PIIX4_smba = 0x%X\n",piix4_smba);
|
||||
#endif /* DEBUG */
|
||||
pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
|
||||
printk("i2c-piix4.o: SMBREV = 0x%X\n", temp);
|
||||
printk("i2c-piix4.o: PIIX4_smba = 0x%X\n", piix4_smba);
|
||||
#endif /* DEBUG */
|
||||
|
||||
END:
|
||||
return error_return;
|
||||
END:
|
||||
return error_return;
|
||||
}
|
||||
|
||||
|
||||
/* Internally used pause function */
|
||||
void piix4_do_pause( unsigned int amount )
|
||||
void piix4_do_pause(unsigned int amount)
|
||||
{
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
}
|
||||
|
||||
/* Another internally used function */
|
||||
int piix4_transaction(void)
|
||||
int piix4_transaction(void)
|
||||
{
|
||||
int temp;
|
||||
int result=0;
|
||||
int timeout=0;
|
||||
int temp;
|
||||
int result = 0;
|
||||
int timeout = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
printk("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));
|
||||
printk
|
||||
("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
|
||||
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-piix4.o: SMBus busy (%02x). Resetting... \n",temp);
|
||||
printk("i2c-piix4.o: SMBus busy (%02x). Resetting... \n",
|
||||
temp);
|
||||
#endif
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-piix4.o: Failed! (%02x)\n",temp);
|
||||
printk("i2c-piix4.o: Failed! (%02x)\n", temp);
|
||||
#endif
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-piix4.o: Successfull!\n");
|
||||
printk("i2c-piix4.o: Successfull!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
|
||||
/* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
|
||||
do {
|
||||
piix4_do_pause(1);
|
||||
temp=inb_p(SMBHSTSTS);
|
||||
} while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
|
||||
/* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
|
||||
do {
|
||||
piix4_do_pause(1);
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
} while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-piix4.o: SMBus Timeout!\n");
|
||||
result = -1;
|
||||
printk("i2c-piix4.o: SMBus Timeout!\n");
|
||||
result = -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-piix4.o: Error: Failed bus transaction\n");
|
||||
printk("i2c-piix4.o: Error: Failed bus transaction\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk("i2c-piix4.o: Bus collision! SMBus may be locked until next hard
|
||||
reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk
|
||||
("i2c-piix4.o: Bus collision! SMBus may be locked until next hard\n"
|
||||
"reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
|
||||
if (temp & 0x04) {
|
||||
result = -1;
|
||||
if (temp & 0x04) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-piix4.o: Error: no response!\n");
|
||||
printk("i2c-piix4.o: Error: no response!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (inb_p(SMBHSTSTS) != 0x00)
|
||||
outb_p( inb(SMBHSTSTS), SMBHSTSTS);
|
||||
if (inb_p(SMBHSTSTS) != 0x00)
|
||||
outb_p(inb(SMBHSTSTS), SMBHSTSTS);
|
||||
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-piix4.o: Failed reset at end of transaction (%02x)\n",temp);
|
||||
printk
|
||||
("i2c-piix4.o: Failed reset at end of transaction (%02x)\n",
|
||||
temp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printk("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));
|
||||
printk
|
||||
("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
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return -1 on error. See smbus.h for more information */
|
||||
s32 piix4_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
s32 piix4_access(struct i2c_adapter * adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
{
|
||||
int i,len;
|
||||
int i, len;
|
||||
|
||||
switch(size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk("i2c-piix4.o: I2C_SMBUS_PROC_CALL not supported!\n");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
size = PIIX4_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = PIIX4_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte,SMBHSTDAT0);
|
||||
size = PIIX4_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff,SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1);
|
||||
}
|
||||
size = PIIX4_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outb_p(len,SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i ++)
|
||||
outb_p(data->block[i],SMBBLKDAT);
|
||||
}
|
||||
size = PIIX4_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
switch (size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk
|
||||
("i2c-piix4.o: I2C_SMBUS_PROC_CALL not supported!\n");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
size = PIIX4_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = PIIX4_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte, SMBHSTDAT0);
|
||||
size = PIIX4_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff, SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
|
||||
}
|
||||
size = PIIX4_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outb_p(len, SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i++)
|
||||
outb_p(data->block[i], SMBBLKDAT);
|
||||
}
|
||||
size = PIIX4_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
|
||||
if (piix4_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
|
||||
return 0;
|
||||
|
||||
if (piix4_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
switch(size) {
|
||||
case PIIX4_BYTE: /* Where is the result put? I assume here it is in
|
||||
SMBHSTDAT0 but it might just as well be in the
|
||||
SMBHSTCMD. No clue in the docs */
|
||||
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case PIIX4_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case PIIX4_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
case PIIX4_BLOCK_DATA:
|
||||
data->block[0] = inb_p(SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= data->block[0]; i++)
|
||||
data->block[i] = inb_p(SMBBLKDAT);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
|
||||
return 0;
|
||||
|
||||
|
||||
switch (size) {
|
||||
case PIIX4_BYTE: /* Where is the result put? I assume here it is in
|
||||
SMBHSTDAT0 but it might just as well be in the
|
||||
SMBHSTCMD. No clue in the docs */
|
||||
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case PIIX4_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case PIIX4_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
case PIIX4_BLOCK_DATA:
|
||||
data->block[0] = inb_p(SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= data->block[0]; i++)
|
||||
data->block[i] = inb_p(SMBBLKDAT);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void piix4_inc(struct i2c_adapter *adapter)
|
||||
@@ -420,74 +442,78 @@ void piix4_dec(struct i2c_adapter *adapter)
|
||||
|
||||
u32 piix4_func(struct i2c_adapter *adapter)
|
||||
{
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
}
|
||||
|
||||
int __init i2c_piix4_init(void)
|
||||
{
|
||||
int res;
|
||||
printk("piix4.o version %s (%s)\n",LM_VERSION,LM_DATE);
|
||||
int res;
|
||||
printk("piix4.o version %s (%s)\n", LM_VERSION, LM_DATE);
|
||||
#ifdef DEBUG
|
||||
/* PE- It might be good to make this a permanent part of the code! */
|
||||
if (piix4_initialized) {
|
||||
printk("i2c-piix4.o: Oops, piix4_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (piix4_initialized) {
|
||||
printk
|
||||
("i2c-piix4.o: Oops, piix4_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
#endif
|
||||
piix4_initialized = 0;
|
||||
if ((res = piix4_setup())) {
|
||||
printk("i2c-piix4.o: PIIX4 not detected, module not inserted.\n");
|
||||
piix4_cleanup();
|
||||
return res;
|
||||
}
|
||||
piix4_initialized ++;
|
||||
sprintf(piix4_adapter.name,"SMBus PIIX4 adapter at %04x",piix4_smba);
|
||||
if ((res = i2c_add_adapter(&piix4_adapter))) {
|
||||
printk("i2c-piix4.o: Adapter registration failed, module not inserted.\n");
|
||||
piix4_cleanup();
|
||||
return res;
|
||||
}
|
||||
piix4_initialized++;
|
||||
printk("i2c-piix4.o: PIIX4 bus detected and initialized\n");
|
||||
return 0;
|
||||
piix4_initialized = 0;
|
||||
if ((res = piix4_setup())) {
|
||||
printk
|
||||
("i2c-piix4.o: PIIX4 not detected, module not inserted.\n");
|
||||
piix4_cleanup();
|
||||
return res;
|
||||
}
|
||||
piix4_initialized++;
|
||||
sprintf(piix4_adapter.name, "SMBus PIIX4 adapter at %04x",
|
||||
piix4_smba);
|
||||
if ((res = i2c_add_adapter(&piix4_adapter))) {
|
||||
printk
|
||||
("i2c-piix4.o: Adapter registration failed, module not inserted.\n");
|
||||
piix4_cleanup();
|
||||
return res;
|
||||
}
|
||||
piix4_initialized++;
|
||||
printk("i2c-piix4.o: PIIX4 bus detected and initialized\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init piix4_cleanup(void)
|
||||
{
|
||||
int res;
|
||||
if (piix4_initialized >= 2)
|
||||
{
|
||||
if ((res = i2c_del_adapter(&piix4_adapter))) {
|
||||
printk("i2c-piix4.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
piix4_initialized--;
|
||||
}
|
||||
if (piix4_initialized >= 1) {
|
||||
release_region(piix4_smba, 8);
|
||||
piix4_initialized--;
|
||||
}
|
||||
return 0;
|
||||
int res;
|
||||
if (piix4_initialized >= 2) {
|
||||
if ((res = i2c_del_adapter(&piix4_adapter))) {
|
||||
printk
|
||||
("i2c-piix4.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
piix4_initialized--;
|
||||
}
|
||||
if (piix4_initialized >= 1) {
|
||||
release_region(piix4_smba, 8);
|
||||
piix4_initialized--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_NO_SYMBOLS;
|
||||
|
||||
#ifdef MODULE
|
||||
|
||||
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
|
||||
MODULE_AUTHOR
|
||||
("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
|
||||
MODULE_DESCRIPTION("PIIX4 SMBus driver");
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_piix4_init();
|
||||
return i2c_piix4_init();
|
||||
}
|
||||
|
||||
int cleanup_module(void)
|
||||
{
|
||||
return piix4_cleanup();
|
||||
return piix4_cleanup();
|
||||
}
|
||||
|
||||
#endif /* MODULE */
|
||||
|
||||
#endif /* MODULE */
|
||||
+238
-209
@@ -77,13 +77,14 @@ static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_sis5595_init(void);
|
||||
int __init i2c_sis5595_init(void);
|
||||
static int __init sis5595_cleanup(void);
|
||||
static int sis5595_setup(void);
|
||||
static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data);
|
||||
static void sis5595_do_pause( unsigned int amount );
|
||||
static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size,
|
||||
union i2c_smbus_data *data);
|
||||
static void sis5595_do_pause(unsigned int amount);
|
||||
static int sis5595_transaction(void);
|
||||
static void sis5595_inc(struct i2c_adapter *adapter);
|
||||
static void sis5595_dec(struct i2c_adapter *adapter);
|
||||
@@ -92,28 +93,28 @@ static u32 sis5595_func(struct i2c_adapter *adapter);
|
||||
#ifdef MODULE
|
||||
extern int init_module(void);
|
||||
extern int cleanup_module(void);
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
|
||||
static struct i2c_algorithm smbus_algorithm = {
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ sis5595_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ sis5595_func,
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ sis5595_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ sis5595_func,
|
||||
};
|
||||
|
||||
static struct i2c_adapter sis5595_adapter = {
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_SIS5595,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
sis5595_inc,
|
||||
sis5595_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_SIS5595,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
sis5595_inc,
|
||||
sis5595_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int __initdata sis5595_initialized;
|
||||
@@ -121,14 +122,14 @@ static unsigned short sis5595_base = 0;
|
||||
|
||||
static u8 sis5595_read(u8 reg)
|
||||
{
|
||||
outb(reg,sis5595_base+SMB_INDEX);
|
||||
return inb(sis5595_base+SMB_DAT);
|
||||
outb(reg, sis5595_base + SMB_INDEX);
|
||||
return inb(sis5595_base + SMB_DAT);
|
||||
}
|
||||
|
||||
static void sis5595_write(u8 reg, u8 data)
|
||||
{
|
||||
outb(reg,sis5595_base+SMB_INDEX);
|
||||
outb(data,sis5595_base+SMB_DAT);
|
||||
outb(reg, sis5595_base + SMB_INDEX);
|
||||
outb(data, sis5595_base + SMB_DAT);
|
||||
}
|
||||
|
||||
|
||||
@@ -138,192 +139,217 @@ static void sis5595_write(u8 reg, u8 data)
|
||||
defined to make the transition easier. */
|
||||
int sis5595_setup(void)
|
||||
{
|
||||
int error_return=0;
|
||||
int error_return = 0;
|
||||
|
||||
struct pci_dev *SIS5595_dev;
|
||||
struct pci_dev *SIS5595_dev;
|
||||
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-sis5595.o: Error: No PCI-bus found!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-sis5595.o: Error: No PCI-bus found!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Look for the SIS5595, function 3 */
|
||||
SIS5595_dev = NULL;
|
||||
if (!(SIS5595_dev = pci_find_device(PCI_VENDOR_ID_SI,
|
||||
PCI_DEVICE_ID_SI_503, SIS5595_dev))) {
|
||||
printk("i2c-sis5595.o: Error: Can't detect SIS5595!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* Look for the SIS5595, function 3 */
|
||||
SIS5595_dev = NULL;
|
||||
if (!(SIS5595_dev = pci_find_device(PCI_VENDOR_ID_SI,
|
||||
PCI_DEVICE_ID_SI_503,
|
||||
SIS5595_dev))) {
|
||||
printk("i2c-sis5595.o: Error: Can't detect SIS5595!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Determine the address of the SMBus areas */
|
||||
pci_read_config_word(SIS5595_dev, ACPI_BASE,&sis5595_base);
|
||||
pci_read_config_word(SIS5595_dev, ACPI_BASE, &sis5595_base);
|
||||
#ifdef DEBUG
|
||||
printk("ACPI Base address: %04x\n",sis5595_base);
|
||||
printk("ACPI Base address: %04x\n", sis5595_base);
|
||||
#endif
|
||||
/* NB: We grab just the two SMBus registers here, but this may still
|
||||
* interfere with ACPI :-( */
|
||||
if (check_region(sis5595_base + SMB_INDEX, 2)) {
|
||||
printk("i2c-sis5595.o: SMBus registers 0x%4x-0x%4x already in use!\n",
|
||||
sis5595_base + SMB_INDEX,sis5595_base + SMB_INDEX+1);
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* NB: We grab just the two SMBus registers here, but this may still
|
||||
* interfere with ACPI :-( */
|
||||
if (check_region(sis5595_base + SMB_INDEX, 2)) {
|
||||
printk
|
||||
("i2c-sis5595.o: SMBus registers 0x%4x-0x%4x already in use!\n",
|
||||
sis5595_base + SMB_INDEX,
|
||||
sis5595_base + SMB_INDEX + 1);
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(sis5595_base + SMB_INDEX, 2, "sis5595-smbus");
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(sis5595_base + SMB_INDEX, 2, "sis5595-smbus");
|
||||
|
||||
END:
|
||||
return error_return;
|
||||
END:
|
||||
return error_return;
|
||||
}
|
||||
|
||||
|
||||
/* Internally used pause function */
|
||||
void sis5595_do_pause( unsigned int amount )
|
||||
void sis5595_do_pause(unsigned int amount)
|
||||
{
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
}
|
||||
|
||||
/* Another internally used function */
|
||||
int sis5595_transaction(void)
|
||||
int sis5595_transaction(void)
|
||||
{
|
||||
int temp;
|
||||
int result=0;
|
||||
int timeout=0;
|
||||
int temp;
|
||||
int result = 0;
|
||||
int timeout = 0;
|
||||
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8))
|
||||
!= 0x00) {
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
if (
|
||||
(temp =
|
||||
sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) !=
|
||||
0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-sis5595.o: SMBus busy (%04x). Resetting... \n",temp);
|
||||
printk("i2c-sis5595.o: SMBus busy (%04x). Resetting... \n",
|
||||
temp);
|
||||
#endif
|
||||
sis5595_write(SMB_STS_LO,temp & 0xff);
|
||||
sis5595_write(SMB_STS_HI,temp >> 8);
|
||||
if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8))
|
||||
!= 0x00) {
|
||||
sis5595_write(SMB_STS_LO, temp & 0xff);
|
||||
sis5595_write(SMB_STS_HI, temp >> 8);
|
||||
if (
|
||||
(temp =
|
||||
sis5595_read(SMB_STS_LO) +
|
||||
(sis5595_read(SMB_STS_HI) << 8)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-sis5595.o: Failed! (%02x)\n",temp);
|
||||
printk("i2c-sis5595.o: Failed! (%02x)\n", temp);
|
||||
#endif
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-sis5595.o: Successfull!\n");
|
||||
printk("i2c-sis5595.o: Successfull!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* start the transaction by setting bit 4 */
|
||||
sis5595_write(SMB_CTL_LO,sis5595_read(SMB_CTL_LO)|0x10);
|
||||
/* start the transaction by setting bit 4 */
|
||||
sis5595_write(SMB_CTL_LO, sis5595_read(SMB_CTL_LO) | 0x10);
|
||||
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
sis5595_do_pause(1);
|
||||
temp=sis5595_read(SMB_STS_LO);
|
||||
} while (!(temp & 0x40) && (timeout++ < MAX_TIMEOUT));
|
||||
/* We will always wait for a fraction of a second! */
|
||||
do {
|
||||
sis5595_do_pause(1);
|
||||
temp = sis5595_read(SMB_STS_LO);
|
||||
} while (!(temp & 0x40) && (timeout++ < MAX_TIMEOUT));
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-sis5595.o: SMBus Timeout!\n");
|
||||
printk("i2c-sis5595.o: SMBus Timeout!\n");
|
||||
#endif
|
||||
result = -1;
|
||||
}
|
||||
result = -1;
|
||||
}
|
||||
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-sis5595.o: Error: Failed bus transaction\n");
|
||||
printk("i2c-sis5595.o: Error: Failed bus transaction\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x20) {
|
||||
result = -1;
|
||||
printk("i2c-sis5595.o: Bus collision! SMBus may be locked until next hard
|
||||
reset (or not...)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
if (temp & 0x20) {
|
||||
result = -1;
|
||||
printk
|
||||
("i2c-sis5595.o: Bus collision! SMBus may be locked until next hard\n"
|
||||
"reset (or not...)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
|
||||
if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8))
|
||||
!= 0x00) {
|
||||
sis5595_write(SMB_STS_LO,temp & 0xff);
|
||||
sis5595_write(SMB_STS_HI,temp >> 8);
|
||||
}
|
||||
if (
|
||||
(temp =
|
||||
sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) !=
|
||||
0x00) {
|
||||
sis5595_write(SMB_STS_LO, temp & 0xff);
|
||||
sis5595_write(SMB_STS_HI, temp >> 8);
|
||||
}
|
||||
|
||||
if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8))
|
||||
!= 0x00) {
|
||||
if (
|
||||
(temp =
|
||||
sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) !=
|
||||
0x00) {
|
||||
|
||||
#ifdef DEBUG
|
||||
printk("i2c-sis5595.o: Failed reset at end of transaction (%02x)\n",temp);
|
||||
printk
|
||||
("i2c-sis5595.o: Failed reset at end of transaction (%02x)\n",
|
||||
temp);
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return -1 on error. See smbus.h for more information */
|
||||
s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
s32 sis5595_access(struct i2c_adapter * adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
{
|
||||
switch(size) {
|
||||
case I2C_SMBUS_QUICK:
|
||||
sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
size = SIS5595_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
sis5595_write(SMB_CMD,command);
|
||||
size = SIS5595_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
sis5595_write(SMB_CMD,command);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
sis5595_write(SMB_BYTE,data->byte);
|
||||
size = SIS5595_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
sis5595_write(SMB_CMD,command);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
sis5595_write(SMB_BYTE,data->word & 0xff);
|
||||
sis5595_write(SMB_BYTE+1,(data->word & 0xff00) >> 8);
|
||||
}
|
||||
size = (size==I2C_SMBUS_PROC_CALL)?SIS5595_PROC_CALL:SIS5595_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
printk("sis5595.o: Block data not yet implemented!\n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
switch (size) {
|
||||
case I2C_SMBUS_QUICK:
|
||||
sis5595_write(SMB_ADDR,
|
||||
((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
size = SIS5595_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
sis5595_write(SMB_ADDR,
|
||||
((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
sis5595_write(SMB_CMD, command);
|
||||
size = SIS5595_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
sis5595_write(SMB_ADDR,
|
||||
((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
sis5595_write(SMB_CMD, command);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
sis5595_write(SMB_BYTE, data->byte);
|
||||
size = SIS5595_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
sis5595_write(SMB_ADDR,
|
||||
((addr & 0x7f) << 1) | (read_write & 0x01));
|
||||
sis5595_write(SMB_CMD, command);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
sis5595_write(SMB_BYTE, data->word & 0xff);
|
||||
sis5595_write(SMB_BYTE + 1,
|
||||
(data->word & 0xff00) >> 8);
|
||||
}
|
||||
size =
|
||||
(size ==
|
||||
I2C_SMBUS_PROC_CALL) ? SIS5595_PROC_CALL :
|
||||
SIS5595_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
printk("sis5595.o: Block data not yet implemented!\n");
|
||||
return -1;
|
||||
break;
|
||||
}
|
||||
|
||||
sis5595_write(SMB_CTL_LO,((size & 0x0E)));
|
||||
sis5595_write(SMB_CTL_LO, ((size & 0x0E)));
|
||||
|
||||
if (sis5595_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
if ((size != SIS5595_PROC_CALL) &&
|
||||
((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK)))
|
||||
return 0;
|
||||
|
||||
if (sis5595_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
switch(size) {
|
||||
case SIS5595_BYTE: /* Where is the result put? I assume here it is in
|
||||
SMB_DATA but it might just as well be in the
|
||||
SMB_CMD. No clue in the docs */
|
||||
case SIS5595_BYTE_DATA:
|
||||
data->byte = sis5595_read(SMB_BYTE);
|
||||
break;
|
||||
case SIS5595_WORD_DATA:
|
||||
case SIS5595_PROC_CALL:
|
||||
data->word = sis5595_read(SMB_BYTE) + (sis5595_read(SMB_BYTE+1) << 8);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
if ((size != SIS5595_PROC_CALL) &&
|
||||
((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK)))
|
||||
return 0;
|
||||
|
||||
|
||||
switch (size) {
|
||||
case SIS5595_BYTE: /* Where is the result put? I assume here it is in
|
||||
SMB_DATA but it might just as well be in the
|
||||
SMB_CMD. No clue in the docs */
|
||||
case SIS5595_BYTE_DATA:
|
||||
data->byte = sis5595_read(SMB_BYTE);
|
||||
break;
|
||||
case SIS5595_WORD_DATA:
|
||||
case SIS5595_PROC_CALL:
|
||||
data->word =
|
||||
sis5595_read(SMB_BYTE) +
|
||||
(sis5595_read(SMB_BYTE + 1) << 8);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sis5595_inc(struct i2c_adapter *adapter)
|
||||
@@ -339,56 +365,60 @@ void sis5595_dec(struct i2c_adapter *adapter)
|
||||
|
||||
u32 sis5595_func(struct i2c_adapter *adapter)
|
||||
{
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_PROC_CALL;
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_PROC_CALL;
|
||||
}
|
||||
|
||||
int __init i2c_sis5595_init(void)
|
||||
{
|
||||
int res;
|
||||
printk("sis5595.o version %s (%s)\n",LM_VERSION,LM_DATE);
|
||||
int res;
|
||||
printk("sis5595.o version %s (%s)\n", LM_VERSION, LM_DATE);
|
||||
#ifdef DEBUG
|
||||
/* PE- It might be good to make this a permanent part of the code! */
|
||||
if (sis5595_initialized) {
|
||||
printk("i2c-sis5595.o: Oops, sis5595_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (sis5595_initialized) {
|
||||
printk
|
||||
("i2c-sis5595.o: Oops, sis5595_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
#endif
|
||||
sis5595_initialized = 0;
|
||||
if ((res = sis5595_setup())) {
|
||||
printk("i2c-sis5595.o: SIS5595 not detected, module not inserted.\n");
|
||||
sis5595_cleanup();
|
||||
return res;
|
||||
}
|
||||
sis5595_initialized ++;
|
||||
sprintf(sis5595_adapter.name,"SMBus SIS5595 adapter at %04x",sis5595_base + SMB_INDEX);
|
||||
if ((res = i2c_add_adapter(&sis5595_adapter))) {
|
||||
printk("i2c-sis5595.o: Adapter registration failed, module not inserted.\n");
|
||||
sis5595_cleanup();
|
||||
return res;
|
||||
}
|
||||
sis5595_initialized++;
|
||||
printk("i2c-sis5595.o: SIS5595 bus detected and initialized\n");
|
||||
return 0;
|
||||
sis5595_initialized = 0;
|
||||
if ((res = sis5595_setup())) {
|
||||
printk
|
||||
("i2c-sis5595.o: SIS5595 not detected, module not inserted.\n");
|
||||
sis5595_cleanup();
|
||||
return res;
|
||||
}
|
||||
sis5595_initialized++;
|
||||
sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x",
|
||||
sis5595_base + SMB_INDEX);
|
||||
if ((res = i2c_add_adapter(&sis5595_adapter))) {
|
||||
printk
|
||||
("i2c-sis5595.o: Adapter registration failed, module not inserted.\n");
|
||||
sis5595_cleanup();
|
||||
return res;
|
||||
}
|
||||
sis5595_initialized++;
|
||||
printk("i2c-sis5595.o: SIS5595 bus detected and initialized\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init sis5595_cleanup(void)
|
||||
{
|
||||
int res;
|
||||
if (sis5595_initialized >= 2)
|
||||
{
|
||||
if ((res = i2c_del_adapter(&sis5595_adapter))) {
|
||||
printk("i2c-sis5595.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
sis5595_initialized--;
|
||||
}
|
||||
if (sis5595_initialized >= 1) {
|
||||
release_region(sis5595_base + SMB_INDEX, 2);
|
||||
sis5595_initialized--;
|
||||
}
|
||||
return 0;
|
||||
int res;
|
||||
if (sis5595_initialized >= 2) {
|
||||
if ((res = i2c_del_adapter(&sis5595_adapter))) {
|
||||
printk
|
||||
("i2c-sis5595.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
sis5595_initialized--;
|
||||
}
|
||||
if (sis5595_initialized >= 1) {
|
||||
release_region(sis5595_base + SMB_INDEX, 2);
|
||||
sis5595_initialized--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_NO_SYMBOLS;
|
||||
@@ -400,13 +430,12 @@ MODULE_DESCRIPTION("SIS5595 SMBus driver");
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_sis5595_init();
|
||||
return i2c_sis5595_init();
|
||||
}
|
||||
|
||||
int cleanup_module(void)
|
||||
{
|
||||
return sis5595_cleanup();
|
||||
return sis5595_cleanup();
|
||||
}
|
||||
|
||||
#endif /* MODULE */
|
||||
|
||||
#endif /* MODULE */
|
||||
+47
-42
@@ -40,14 +40,14 @@
|
||||
|
||||
/* Power management registers */
|
||||
|
||||
#define PM_CFG_REVID 0x08 /* silicon revision code */
|
||||
#define PM_CFG_REVID 0x08 /* silicon revision code */
|
||||
#define PM_CFG_IOBASE0 0x20
|
||||
#define PM_CFG_IOBASE1 0x48
|
||||
|
||||
#define I2C_DIR (pm_io_base+0x40)
|
||||
#define I2C_OUT (pm_io_base+0x42)
|
||||
#define I2C_IN (pm_io_base+0x44)
|
||||
#define I2C_SCL 0x02 /* clock bit in DIR/OUT/IN register */
|
||||
#define I2C_SCL 0x02 /* clock bit in DIR/OUT/IN register */
|
||||
#define I2C_SDA 0x04
|
||||
|
||||
/* io-region reservation */
|
||||
@@ -55,9 +55,9 @@
|
||||
#define IOTEXT "via-i2c"
|
||||
|
||||
/* ----- global defines ----------------------------------------------- */
|
||||
#define DEB(x) x /* silicon revision, io addresses */
|
||||
#define DEB2(x) x /* line status */
|
||||
#define DEBE(x) /* */
|
||||
#define DEB(x) x /* silicon revision, io addresses */
|
||||
#define DEB2(x) x /* line status */
|
||||
#define DEBE(x) /* */
|
||||
|
||||
/* ----- local functions ---------------------------------------------- */
|
||||
|
||||
@@ -65,22 +65,24 @@ static u16 pm_io_base;
|
||||
|
||||
static void bit_via_setscl(void *data, int state)
|
||||
{
|
||||
outb(state ? inb(I2C_OUT)|I2C_SCL : inb(I2C_OUT)&~I2C_SCL, I2C_OUT);
|
||||
outb(state ? inb(I2C_OUT) | I2C_SCL : inb(I2C_OUT) & ~I2C_SCL,
|
||||
I2C_OUT);
|
||||
}
|
||||
|
||||
static void bit_via_setsda(void *data, int state)
|
||||
{
|
||||
outb(state ? inb(I2C_OUT)|I2C_SDA : inb(I2C_OUT)&~I2C_SDA, I2C_OUT);
|
||||
outb(state ? inb(I2C_OUT) | I2C_SDA : inb(I2C_OUT) & ~I2C_SDA,
|
||||
I2C_OUT);
|
||||
}
|
||||
|
||||
static int bit_via_getscl(void *data)
|
||||
{
|
||||
return (0 != (inb(I2C_IN) & I2C_SCL) );
|
||||
return (0 != (inb(I2C_IN) & I2C_SCL));
|
||||
}
|
||||
|
||||
static int bit_via_getsda(void *data)
|
||||
{
|
||||
return (0 != (inb(I2C_IN) & I2C_SDA) );
|
||||
return (0 != (inb(I2C_IN) & I2C_SDA));
|
||||
}
|
||||
|
||||
static void bit_via_inc(struct i2c_adapter *adapter)
|
||||
@@ -101,7 +103,7 @@ static struct i2c_algo_bit_data bit_data = {
|
||||
bit_via_setscl,
|
||||
bit_via_getsda,
|
||||
bit_via_getscl,
|
||||
5, 5, 100, /*waits, timeout */
|
||||
5, 5, 100, /*waits, timeout */
|
||||
};
|
||||
|
||||
static struct i2c_adapter bit_via_ops = {
|
||||
@@ -122,38 +124,40 @@ static int find_via(void)
|
||||
struct pci_dev *s_bridge;
|
||||
u16 base;
|
||||
u8 rev;
|
||||
|
||||
if (! pci_present())
|
||||
|
||||
if (!pci_present())
|
||||
return -ENODEV;
|
||||
|
||||
|
||||
s_bridge = pci_find_device(VENDOR, DEVICE, NULL);
|
||||
|
||||
if (! s_bridge) {
|
||||
|
||||
if (!s_bridge) {
|
||||
printk("vt82c586b not found\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if ( PCIBIOS_SUCCESSFUL !=
|
||||
pci_read_config_byte(s_bridge, PM_CFG_REVID, &rev))
|
||||
if (PCIBIOS_SUCCESSFUL !=
|
||||
pci_read_config_byte(s_bridge, PM_CFG_REVID, &rev))
|
||||
return -ENODEV;
|
||||
|
||||
switch(rev)
|
||||
{
|
||||
case 0x00: base = PM_CFG_IOBASE0;
|
||||
break;
|
||||
case 0x01:
|
||||
case 0x10: base = PM_CFG_IOBASE1;
|
||||
break;
|
||||
|
||||
default : base = PM_CFG_IOBASE1;
|
||||
/* later revision */
|
||||
}
|
||||
switch (rev) {
|
||||
case 0x00:
|
||||
base = PM_CFG_IOBASE0;
|
||||
break;
|
||||
case 0x01:
|
||||
case 0x10:
|
||||
base = PM_CFG_IOBASE1;
|
||||
break;
|
||||
|
||||
if ( PCIBIOS_SUCCESSFUL !=
|
||||
pci_read_config_word(s_bridge, base, &pm_io_base))
|
||||
return -ENODEV;
|
||||
|
||||
pm_io_base &= (0xff<<8);
|
||||
default:
|
||||
base = PM_CFG_IOBASE1;
|
||||
/* later revision */
|
||||
}
|
||||
|
||||
if (PCIBIOS_SUCCESSFUL !=
|
||||
pci_read_config_word(s_bridge, base, &pm_io_base))
|
||||
return -ENODEV;
|
||||
|
||||
pm_io_base &= (0xff << 8);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -162,30 +166,31 @@ static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_via_init(void)
|
||||
int __init i2c_via_init(void)
|
||||
{
|
||||
if (find_via() < 0) {
|
||||
printk("Error while reading PCI configuration\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if ( check_region(I2C_DIR, IOSPACE) < 0) {
|
||||
if (check_region(I2C_DIR, IOSPACE) < 0) {
|
||||
printk("IO 0x%x-0x%x already in use\n",
|
||||
I2C_DIR, I2C_DIR+IOSPACE);
|
||||
I2C_DIR, I2C_DIR + IOSPACE);
|
||||
return -EBUSY;
|
||||
} else {
|
||||
request_region(I2C_DIR, IOSPACE, IOTEXT);
|
||||
outb(inb(I2C_DIR) | I2C_SDA | I2C_SCL, I2C_DIR);
|
||||
outb(inb(I2C_OUT) | I2C_SDA | I2C_SCL, I2C_OUT);
|
||||
outb(inb(I2C_OUT) | I2C_SDA | I2C_SCL, I2C_OUT);
|
||||
}
|
||||
|
||||
|
||||
if (i2c_bit_add_bus(&bit_via_ops) == 0) {
|
||||
printk("i2c-via.o: Module succesfully loaded\n");
|
||||
return 0;
|
||||
} else {
|
||||
outb(inb(I2C_DIR)&~(I2C_SDA|I2C_SCL), I2C_DIR);
|
||||
outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR);
|
||||
release_region(I2C_DIR, IOSPACE);
|
||||
printk("i2c-via.o: Algo-bit error, couldn't register bus\n");
|
||||
printk
|
||||
("i2c-via.o: Algo-bit error, couldn't register bus\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
}
|
||||
@@ -196,12 +201,12 @@ EXPORT_NO_SYMBOLS;
|
||||
MODULE_AUTHOR("Kyösti Mälkki <kmalkki@cc.hut.fi>");
|
||||
MODULE_DESCRIPTION("i2c for Via vt82c586b southbridge");
|
||||
|
||||
int init_module(void)
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_via_init();
|
||||
}
|
||||
|
||||
void cleanup_module(void)
|
||||
void cleanup_module(void)
|
||||
{
|
||||
i2c_bit_del_bus(&bit_via_ops);
|
||||
release_region(I2C_DIR, IOSPACE);
|
||||
|
||||
+311
-284
@@ -88,28 +88,29 @@ static unsigned short smb_cf_hstcfg;
|
||||
/* If force is set to anything different from 0, we forcibly enable the
|
||||
VT596. DANGEROUS! */
|
||||
static int force = 0;
|
||||
MODULE_PARM(force,"i");
|
||||
MODULE_PARM_DESC(force,"Forcibly enable the VT82C596 SMBus. DANGEROUS!");
|
||||
MODULE_PARM(force, "i");
|
||||
MODULE_PARM_DESC(force, "Forcibly enable the VT82C596 SMBus. DANGEROUS!");
|
||||
|
||||
/* If force_addr is set to anything different from 0, we forcibly enable
|
||||
the VT596 at the given address. VERY DANGEROUS! */
|
||||
static int force_addr = 0;
|
||||
MODULE_PARM(force_addr,"i");
|
||||
MODULE_PARM_DESC(force_addr,"Forcibly enable the VT82C596 SMBus at the given address. "
|
||||
"EXTREMELY DANGEROUS!");
|
||||
MODULE_PARM(force_addr, "i");
|
||||
MODULE_PARM_DESC(force_addr,
|
||||
"Forcibly enable the VT82C596 SMBus at the given address. "
|
||||
"EXTREMELY DANGEROUS!");
|
||||
|
||||
#ifdef MODULE
|
||||
static
|
||||
#else
|
||||
extern
|
||||
#endif
|
||||
int __init i2c_vt596_init(void);
|
||||
int __init i2c_vt596_init(void);
|
||||
static int __init vt596_cleanup(void);
|
||||
static int vt596_setup(void);
|
||||
static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags,char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data);
|
||||
static void vt596_do_pause( unsigned int amount );
|
||||
static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
|
||||
unsigned short flags, char read_write,
|
||||
u8 command, int size, union i2c_smbus_data *data);
|
||||
static void vt596_do_pause(unsigned int amount);
|
||||
static int vt596_transaction(void);
|
||||
static void vt596_inc(struct i2c_adapter *adapter);
|
||||
static void vt596_dec(struct i2c_adapter *adapter);
|
||||
@@ -118,28 +119,28 @@ static u32 vt596_func(struct i2c_adapter *adapter);
|
||||
#ifdef MODULE
|
||||
extern int init_module(void);
|
||||
extern int cleanup_module(void);
|
||||
#endif /* MODULE */
|
||||
#endif /* MODULE */
|
||||
|
||||
static struct i2c_algorithm smbus_algorithm = {
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ vt596_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ vt596_func,
|
||||
/* name */ "Non-I2C SMBus adapter",
|
||||
/* id */ I2C_ALGO_SMBUS,
|
||||
/* master_xfer */ NULL,
|
||||
/* smbus_access */ vt596_access,
|
||||
/* slave_send */ NULL,
|
||||
/* slave_rcv */ NULL,
|
||||
/* algo_control */ NULL,
|
||||
/* functionality */ vt596_func,
|
||||
};
|
||||
|
||||
static struct i2c_adapter vt596_adapter = {
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_VIA2,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
vt596_inc,
|
||||
vt596_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
"unset",
|
||||
I2C_ALGO_SMBUS | I2C_HW_SMBUS_VIA2,
|
||||
&smbus_algorithm,
|
||||
NULL,
|
||||
vt596_inc,
|
||||
vt596_dec,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static int __initdata vt596_initialized;
|
||||
@@ -152,286 +153,308 @@ static unsigned short vt596_smba = 0;
|
||||
defined to make the transition easier. */
|
||||
int vt596_setup(void)
|
||||
{
|
||||
int error_return=0;
|
||||
unsigned char temp;
|
||||
int error_return = 0;
|
||||
unsigned char temp;
|
||||
|
||||
struct pci_dev *VT596_dev;
|
||||
struct pci_dev *VT596_dev;
|
||||
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-viapro.o: Error: No PCI-bus found!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
/* First check whether we can access PCI at all */
|
||||
if (pci_present() == 0) {
|
||||
printk("i2c-viapro.o: Error: No PCI-bus found!\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Look for the VT596 function 3 _or_ VT686 function 4 */
|
||||
VT596_dev = NULL;
|
||||
VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA,
|
||||
PCI_DEVICE_ID_VIA_82C596_3, VT596_dev);
|
||||
if (VT596_dev == NULL)
|
||||
VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA,
|
||||
PCI_DEVICE_ID_VIA_82C686_4, VT596_dev);
|
||||
/* Look for the VT596 function 3 _or_ VT686 function 4 */
|
||||
VT596_dev = NULL;
|
||||
VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA,
|
||||
PCI_DEVICE_ID_VIA_82C596_3, VT596_dev);
|
||||
if (VT596_dev == NULL)
|
||||
VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA,
|
||||
PCI_DEVICE_ID_VIA_82C686_4,
|
||||
VT596_dev);
|
||||
|
||||
if (VT596_dev == NULL) {
|
||||
printk("i2c-viapro.o: Error: Can't detect vt82c596 or vt82c686");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
if (VT596_dev == NULL) {
|
||||
printk
|
||||
("i2c-viapro.o: Error: Can't detect vt82c596 or vt82c686");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Determine the configuration space registers for the SMBus areas */
|
||||
if ((! pci_read_config_word(VT596_dev, SMBBA1, &vt596_smba)) && (vt596_smba & 0x1)) {
|
||||
smb_cf_base = SMBBA1;
|
||||
smb_cf_hstcfg = 0xD2;
|
||||
} else if ((! pci_read_config_word(VT596_dev, SMBBA2, &vt596_smba)) && (vt596_smba & 0x1)) {
|
||||
smb_cf_base = SMBBA2;
|
||||
smb_cf_hstcfg = 0x84;
|
||||
} else {
|
||||
printk("i2c-viapro.o: Cannot configure SMBus I/O Base address\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
if ((!pci_read_config_word(VT596_dev, SMBBA1, &vt596_smba))
|
||||
&& (vt596_smba & 0x1)) {
|
||||
smb_cf_base = SMBBA1;
|
||||
smb_cf_hstcfg = 0xD2;
|
||||
} else if ((!pci_read_config_word(VT596_dev, SMBBA2, &vt596_smba))
|
||||
&& (vt596_smba & 0x1)) {
|
||||
smb_cf_base = SMBBA2;
|
||||
smb_cf_hstcfg = 0x84;
|
||||
} else {
|
||||
printk
|
||||
("i2c-viapro.o: Cannot configure SMBus I/O Base address\n");
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
/* Determine the address of the SMBus areas */
|
||||
if (force_addr) {
|
||||
vt596_smba = force_addr & 0xfff0;
|
||||
force = 0;
|
||||
} else {
|
||||
vt596_smba &= 0xfff0;
|
||||
}
|
||||
if (force_addr) {
|
||||
vt596_smba = force_addr & 0xfff0;
|
||||
force = 0;
|
||||
} else {
|
||||
vt596_smba &= 0xfff0;
|
||||
}
|
||||
|
||||
if (check_region(vt596_smba, 8)) {
|
||||
printk("i2c-viapro.o: vt82c596_smb region 0x%x already in use!\n", vt596_smba);
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
if (check_region(vt596_smba, 8)) {
|
||||
printk
|
||||
("i2c-viapro.o: vt82c596_smb region 0x%x already in use!\n",
|
||||
vt596_smba);
|
||||
error_return = -ENODEV;
|
||||
goto END;
|
||||
}
|
||||
|
||||
pci_read_config_byte(VT596_dev, SMBHSTCFG, &temp);
|
||||
pci_read_config_byte(VT596_dev, SMBHSTCFG, &temp);
|
||||
/* If force_addr is set, we program the new address here. Just to make
|
||||
sure, we disable the VT596 first. */
|
||||
if (force_addr) {
|
||||
pci_write_config_byte(VT596_dev, SMBHSTCFG, temp & 0xfe);
|
||||
pci_write_config_word(VT596_dev, SMBBA,vt596_smba);
|
||||
pci_write_config_byte(VT596_dev, SMBHSTCFG, temp | 0x01);
|
||||
printk("i2c-viapro.o: WARNING: VT596 SMBus interface set to new "
|
||||
"address %04x!\n",vt596_smba);
|
||||
} else if ((temp & 1) == 0) {
|
||||
if (force) {
|
||||
if (force_addr) {
|
||||
pci_write_config_byte(VT596_dev, SMBHSTCFG, temp & 0xfe);
|
||||
pci_write_config_word(VT596_dev, SMBBA, vt596_smba);
|
||||
pci_write_config_byte(VT596_dev, SMBHSTCFG, temp | 0x01);
|
||||
printk
|
||||
("i2c-viapro.o: WARNING: VT596 SMBus interface set to new "
|
||||
"address %04x!\n", vt596_smba);
|
||||
} else if ((temp & 1) == 0) {
|
||||
if (force) {
|
||||
/* 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(VT596_dev, SMBHSTCFG, temp | 1);
|
||||
printk("i2c-viapro.o: WARNING: SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!\n");
|
||||
} else {
|
||||
printk("SMBUS: Error: Host SMBus controller not enabled!\n");
|
||||
error_return=-ENODEV;
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
pci_write_config_byte(VT596_dev, SMBHSTCFG,
|
||||
temp | 1);
|
||||
printk
|
||||
("i2c-viapro.o: WARNING: SMBus interface has been FORCEFULLY "
|
||||
"ENABLED!\n");
|
||||
} else {
|
||||
printk
|
||||
("SMBUS: Error: 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(vt596_smba, 8, "via2-smbus");
|
||||
/* Everything is happy, let's grab the memory and set things up. */
|
||||
request_region(vt596_smba, 8, "via2-smbus");
|
||||
|
||||
#ifdef DEBUG
|
||||
if ((temp & 0x0E) == 8)
|
||||
printk("i2c-viapro.o: using Interrupt 9 for SMBus.\n");
|
||||
else if ((temp & 0x0E) == 0)
|
||||
printk("i2c-viapro.o: using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk("i2c-viapro.o: Illegal Interrupt configuration (or code out "
|
||||
"of date)!\n");
|
||||
if ((temp & 0x0E) == 8)
|
||||
printk("i2c-viapro.o: using Interrupt 9 for SMBus.\n");
|
||||
else if ((temp & 0x0E) == 0)
|
||||
printk("i2c-viapro.o: using Interrupt SMI# for SMBus.\n");
|
||||
else
|
||||
printk
|
||||
("i2c-viapro.o: Illegal Interrupt configuration (or code out "
|
||||
"of date)!\n");
|
||||
|
||||
pci_read_config_byte(VT596_dev, SMBREV, &temp);
|
||||
printk("i2c-viapro.o: SMBREV = 0x%X\n",temp);
|
||||
printk("i2c-viapro.o: VT596_smba = 0x%X\n",vt596_smba);
|
||||
#endif /* DEBUG */
|
||||
pci_read_config_byte(VT596_dev, SMBREV, &temp);
|
||||
printk("i2c-viapro.o: SMBREV = 0x%X\n", temp);
|
||||
printk("i2c-viapro.o: VT596_smba = 0x%X\n", vt596_smba);
|
||||
#endif /* DEBUG */
|
||||
|
||||
END:
|
||||
return error_return;
|
||||
END:
|
||||
return error_return;
|
||||
}
|
||||
|
||||
|
||||
/* Internally used pause function */
|
||||
void vt596_do_pause( unsigned int amount )
|
||||
void vt596_do_pause(unsigned int amount)
|
||||
{
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
current->state = TASK_INTERRUPTIBLE;
|
||||
schedule_timeout(amount);
|
||||
}
|
||||
|
||||
/* Another internally used function */
|
||||
int vt596_transaction(void)
|
||||
int vt596_transaction(void)
|
||||
{
|
||||
int temp;
|
||||
int result=0;
|
||||
int timeout=0;
|
||||
int temp;
|
||||
int result = 0;
|
||||
int timeout = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.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));
|
||||
printk
|
||||
("i2c-viapro.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
|
||||
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
/* Make sure the SMBus host is ready to start transmitting */
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.o: SMBus busy (%02x). Resetting... \n",temp);
|
||||
printk("i2c-viapro.o: SMBus busy (%02x). Resetting... \n",
|
||||
temp);
|
||||
#endif
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
outb_p(temp, SMBHSTSTS);
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.o: Failed! (%02x)\n",temp);
|
||||
printk("i2c-viapro.o: Failed! (%02x)\n", temp);
|
||||
#endif
|
||||
return -1;
|
||||
} else {
|
||||
return -1;
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.o: Successfull!\n");
|
||||
printk("i2c-viapro.o: Successfull!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
/* start the transaction by setting bit 6 */
|
||||
outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
|
||||
|
||||
/* We will always wait for a fraction of a second!
|
||||
I don't know if VIA needs this, Intel did */
|
||||
do {
|
||||
vt596_do_pause(1);
|
||||
temp=inb_p(SMBHSTSTS);
|
||||
} while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
|
||||
/* We will always wait for a fraction of a second!
|
||||
I don't know if VIA needs this, Intel did */
|
||||
do {
|
||||
vt596_do_pause(1);
|
||||
temp = inb_p(SMBHSTSTS);
|
||||
} while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
|
||||
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
/* If the SMBus is still busy, we give up */
|
||||
if (timeout >= MAX_TIMEOUT) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.o: SMBus Timeout!\n");
|
||||
result = -1;
|
||||
printk("i2c-viapro.o: SMBus Timeout!\n");
|
||||
result = -1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
if (temp & 0x10) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.o: Error: Failed bus transaction\n");
|
||||
printk("i2c-viapro.o: Error: Failed bus transaction\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk("i2c-viapro.o: Bus collision! SMBus may be locked until next hard
|
||||
reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
if (temp & 0x08) {
|
||||
result = -1;
|
||||
printk
|
||||
("i2c-viapro.o: Bus collision! SMBus may be locked until next hard\n"
|
||||
"reset. (sorry!)\n");
|
||||
/* Clock stops and slave is stuck in mid-transmission */
|
||||
}
|
||||
|
||||
if (temp & 0x04) {
|
||||
result = -1;
|
||||
if (temp & 0x04) {
|
||||
result = -1;
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.o: Error: no response!\n");
|
||||
printk("i2c-viapro.o: Error: no response!\n");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (inb_p(SMBHSTSTS) != 0x00)
|
||||
outb_p( inb(SMBHSTSTS), SMBHSTSTS);
|
||||
if (inb_p(SMBHSTSTS) != 0x00)
|
||||
outb_p(inb(SMBHSTSTS), SMBHSTSTS);
|
||||
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.o: Failed reset at end of transaction (%02x)\n",temp);
|
||||
printk
|
||||
("i2c-viapro.o: Failed reset at end of transaction (%02x)\n",
|
||||
temp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printk("i2c-viapro.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));
|
||||
printk
|
||||
("i2c-viapro.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
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Return -1 on error. See smbus.h for more information */
|
||||
s32 vt596_access(struct i2c_adapter *adap, u16 addr, unsigned short flags,
|
||||
char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
s32 vt596_access(struct i2c_adapter * adap, u16 addr, unsigned short flags,
|
||||
char read_write,
|
||||
u8 command, int size, union i2c_smbus_data * data)
|
||||
{
|
||||
int i,len;
|
||||
int i, len;
|
||||
|
||||
switch(size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk("i2c-viapro.o: I2C_SMBUS_PROC_CALL not supported!\n");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
size = VT596_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = VT596_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte,SMBHSTDAT0);
|
||||
size = VT596_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff,SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1);
|
||||
}
|
||||
size = VT596_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outb_p(len,SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i ++)
|
||||
outb_p(data->block[i],SMBBLKDAT);
|
||||
}
|
||||
size = VT596_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
switch (size) {
|
||||
case I2C_SMBUS_PROC_CALL:
|
||||
printk
|
||||
("i2c-viapro.o: I2C_SMBUS_PROC_CALL not supported!\n");
|
||||
return -1;
|
||||
case I2C_SMBUS_QUICK:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
size = VT596_QUICK;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(command, SMBHSTCMD);
|
||||
size = VT596_BYTE;
|
||||
break;
|
||||
case I2C_SMBUS_BYTE_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE)
|
||||
outb_p(data->byte, SMBHSTDAT0);
|
||||
size = VT596_BYTE_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_WORD_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
outb_p(data->word & 0xff, SMBHSTDAT0);
|
||||
outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
|
||||
}
|
||||
size = VT596_WORD_DATA;
|
||||
break;
|
||||
case I2C_SMBUS_BLOCK_DATA:
|
||||
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
|
||||
SMBHSTADD);
|
||||
outb_p(command, SMBHSTCMD);
|
||||
if (read_write == I2C_SMBUS_WRITE) {
|
||||
len = data->block[0];
|
||||
if (len < 0)
|
||||
len = 0;
|
||||
if (len > 32)
|
||||
len = 32;
|
||||
outb_p(len, SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= len; i++)
|
||||
outb_p(data->block[i], SMBBLKDAT);
|
||||
}
|
||||
size = VT596_BLOCK_DATA;
|
||||
break;
|
||||
}
|
||||
|
||||
outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
|
||||
|
||||
if (vt596_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK))
|
||||
return 0;
|
||||
|
||||
if (vt596_transaction()) /* Error in transaction */
|
||||
return -1;
|
||||
|
||||
switch(size) {
|
||||
case VT596_BYTE: /* Where is the result put? I assume here it is in
|
||||
SMBHSTDAT0 but it might just as well be in the
|
||||
SMBHSTCMD. No clue in the docs */
|
||||
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case VT596_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case VT596_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
case VT596_BLOCK_DATA:
|
||||
data->block[0] = inb_p(SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= data->block[0]; i++)
|
||||
data->block[i] = inb_p(SMBBLKDAT);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK))
|
||||
return 0;
|
||||
|
||||
|
||||
switch (size) {
|
||||
case VT596_BYTE: /* Where is the result put? I assume here it is in
|
||||
SMBHSTDAT0 but it might just as well be in the
|
||||
SMBHSTCMD. No clue in the docs */
|
||||
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case VT596_BYTE_DATA:
|
||||
data->byte = inb_p(SMBHSTDAT0);
|
||||
break;
|
||||
case VT596_WORD_DATA:
|
||||
data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
|
||||
break;
|
||||
case VT596_BLOCK_DATA:
|
||||
data->block[0] = inb_p(SMBHSTDAT0);
|
||||
i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
|
||||
for (i = 1; i <= data->block[0]; i++)
|
||||
data->block[i] = inb_p(SMBBLKDAT);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vt596_inc(struct i2c_adapter *adapter)
|
||||
@@ -448,74 +471,78 @@ void vt596_dec(struct i2c_adapter *adapter)
|
||||
u32 vt596_func(struct i2c_adapter *adapter)
|
||||
{
|
||||
return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
|
||||
I2C_FUNC_SMBUS_BLOCK_DATA;
|
||||
}
|
||||
|
||||
int __init i2c_vt596_init(void)
|
||||
{
|
||||
int res;
|
||||
printk("via2.o version %s (%s)\n",LM_VERSION,LM_DATE);
|
||||
int res;
|
||||
printk("via2.o version %s (%s)\n", LM_VERSION, LM_DATE);
|
||||
#ifdef DEBUG
|
||||
/* PE- It might be good to make this a permanent part of the code! */
|
||||
if (vt596_initialized) {
|
||||
printk("i2c-viapro.o: Oops, vt596_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
if (vt596_initialized) {
|
||||
printk
|
||||
("i2c-viapro.o: Oops, vt596_init called a second time!\n");
|
||||
return -EBUSY;
|
||||
}
|
||||
#endif
|
||||
vt596_initialized = 0;
|
||||
if ((res = vt596_setup())) {
|
||||
printk("i2c-viapro.o: vt82c596 not detected, module not inserted.\n");
|
||||
vt596_cleanup();
|
||||
return res;
|
||||
}
|
||||
vt596_initialized ++;
|
||||
sprintf(vt596_adapter.name,"SMBus vt82c596 adapter at %04x",vt596_smba);
|
||||
if ((res = i2c_add_adapter(&vt596_adapter))) {
|
||||
printk("i2c-viapro.o: Adapter registration failed, module not inserted.\n");
|
||||
vt596_cleanup();
|
||||
return res;
|
||||
}
|
||||
vt596_initialized++;
|
||||
printk("i2c-viapro.o: vt82c596 bus detected and initialized\n");
|
||||
return 0;
|
||||
vt596_initialized = 0;
|
||||
if ((res = vt596_setup())) {
|
||||
printk
|
||||
("i2c-viapro.o: vt82c596 not detected, module not inserted.\n");
|
||||
vt596_cleanup();
|
||||
return res;
|
||||
}
|
||||
vt596_initialized++;
|
||||
sprintf(vt596_adapter.name, "SMBus vt82c596 adapter at %04x",
|
||||
vt596_smba);
|
||||
if ((res = i2c_add_adapter(&vt596_adapter))) {
|
||||
printk
|
||||
("i2c-viapro.o: Adapter registration failed, module not inserted.\n");
|
||||
vt596_cleanup();
|
||||
return res;
|
||||
}
|
||||
vt596_initialized++;
|
||||
printk("i2c-viapro.o: vt82c596 bus detected and initialized\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __init vt596_cleanup(void)
|
||||
{
|
||||
int res;
|
||||
if (vt596_initialized >= 2)
|
||||
{
|
||||
if ((res = i2c_del_adapter(&vt596_adapter))) {
|
||||
printk("i2c-viapro.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
vt596_initialized--;
|
||||
}
|
||||
if (vt596_initialized >= 1) {
|
||||
release_region(vt596_smba, 8);
|
||||
vt596_initialized--;
|
||||
}
|
||||
return 0;
|
||||
int res;
|
||||
if (vt596_initialized >= 2) {
|
||||
if ((res = i2c_del_adapter(&vt596_adapter))) {
|
||||
printk
|
||||
("i2c-viapro.o: i2c_del_adapter failed, module not removed\n");
|
||||
return res;
|
||||
} else
|
||||
vt596_initialized--;
|
||||
}
|
||||
if (vt596_initialized >= 1) {
|
||||
release_region(vt596_smba, 8);
|
||||
vt596_initialized--;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
EXPORT_NO_SYMBOLS;
|
||||
|
||||
#ifdef MODULE
|
||||
|
||||
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
|
||||
MODULE_AUTHOR
|
||||
("Frodo Looijaard <frodol@dds.nl> and Philip Edelbrock <phil@netroedge.com>");
|
||||
MODULE_DESCRIPTION("vt82c596 SMBus driver");
|
||||
|
||||
|
||||
int init_module(void)
|
||||
{
|
||||
return i2c_vt596_init();
|
||||
return i2c_vt596_init();
|
||||
}
|
||||
|
||||
int cleanup_module(void)
|
||||
{
|
||||
return vt596_cleanup();
|
||||
return vt596_cleanup();
|
||||
}
|
||||
|
||||
#endif /* MODULE */
|
||||
|
||||
#endif /* MODULE */
|
||||
+630
-506
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user