Commit 97140342 authored by David Brownell's avatar David Brownell Committed by Jean Delvare

i2c: Bus drivers return -Errno not -1

Tighten error paths used by various i2c adapters (mostly x86) so
they return real fault/errno codes instead of a "-1" (which is
most often interpreted as "-EPERM").  Build tested, with eyeball
review.

One minor initial goal is to have adapters consistently return
the code "-ENXIO" when addressing a device doesn't get an ACK
response, at least in the probe paths where they are already
good at stifling related logspam.
Signed-off-by: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
parent 6ea438ec
...@@ -320,7 +320,7 @@ static int try_address(struct i2c_adapter *i2c_adap, ...@@ -320,7 +320,7 @@ static int try_address(struct i2c_adapter *i2c_adap,
unsigned char addr, int retries) unsigned char addr, int retries)
{ {
struct i2c_algo_bit_data *adap = i2c_adap->algo_data; struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
int i, ret = -1; int i, ret = 0;
for (i = 0; i <= retries; i++) { for (i = 0; i <= retries; i++) {
ret = i2c_outb(i2c_adap, addr); ret = i2c_outb(i2c_adap, addr);
...@@ -508,7 +508,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg) ...@@ -508,7 +508,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
addr ^= 1; addr ^= 1;
ret = try_address(i2c_adap, addr, retries); ret = try_address(i2c_adap, addr, retries);
if ((ret != 1) && !nak_ok) if ((ret != 1) && !nak_ok)
return -EREMOTEIO; return -ENXIO;
} }
return 0; return 0;
......
...@@ -259,7 +259,7 @@ static int ali1535_transaction(struct i2c_adapter *adap) ...@@ -259,7 +259,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
dev_err(&adap->dev, dev_err(&adap->dev,
"SMBus reset failed! (0x%02x) - controller or " "SMBus reset failed! (0x%02x) - controller or "
"device on bus is probably hung\n", temp); "device on bus is probably hung\n", temp);
return -1; return -EBUSY;
} }
} else { } else {
/* check and clear done bit */ /* check and clear done bit */
...@@ -281,12 +281,12 @@ static int ali1535_transaction(struct i2c_adapter *adap) ...@@ -281,12 +281,12 @@ static int ali1535_transaction(struct i2c_adapter *adap)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
result = -1; result = -ETIMEDOUT;
dev_err(&adap->dev, "SMBus Timeout!\n"); dev_err(&adap->dev, "SMBus Timeout!\n");
} }
if (temp & ALI1535_STS_FAIL) { if (temp & ALI1535_STS_FAIL) {
result = -1; result = -EIO;
dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
} }
...@@ -295,7 +295,7 @@ static int ali1535_transaction(struct i2c_adapter *adap) ...@@ -295,7 +295,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
* do a printk. This means that bus collisions go unreported. * do a printk. This means that bus collisions go unreported.
*/ */
if (temp & ALI1535_STS_BUSERR) { if (temp & ALI1535_STS_BUSERR) {
result = -1; result = -ENXIO;
dev_dbg(&adap->dev, dev_dbg(&adap->dev,
"Error: no response or bus collision ADD=%02x\n", "Error: no response or bus collision ADD=%02x\n",
inb_p(SMBHSTADD)); inb_p(SMBHSTADD));
...@@ -303,13 +303,13 @@ static int ali1535_transaction(struct i2c_adapter *adap) ...@@ -303,13 +303,13 @@ static int ali1535_transaction(struct i2c_adapter *adap)
/* haven't ever seen this */ /* haven't ever seen this */
if (temp & ALI1535_STS_DEV) { if (temp & ALI1535_STS_DEV) {
result = -1; result = -EIO;
dev_err(&adap->dev, "Error: device error\n"); dev_err(&adap->dev, "Error: device error\n");
} }
/* check to see if the "command complete" indication is set */ /* check to see if the "command complete" indication is set */
if (!(temp & ALI1535_STS_DONE)) { if (!(temp & ALI1535_STS_DONE)) {
result = -1; result = -ETIMEDOUT;
dev_err(&adap->dev, "Error: command never completed\n"); dev_err(&adap->dev, "Error: command never completed\n");
} }
...@@ -332,7 +332,7 @@ static int ali1535_transaction(struct i2c_adapter *adap) ...@@ -332,7 +332,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
return result; return result;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write, u8 command, unsigned short flags, char read_write, u8 command,
int size, union i2c_smbus_data *data) int size, union i2c_smbus_data *data)
...@@ -359,7 +359,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, ...@@ -359,7 +359,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
switch (size) { switch (size) {
case I2C_SMBUS_PROC_CALL: case I2C_SMBUS_PROC_CALL:
dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
result = -1; result = -EOPNOTSUPP;
goto EXIT; goto EXIT;
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
...@@ -420,11 +420,9 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, ...@@ -420,11 +420,9 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
break; break;
} }
if (ali1535_transaction(adap)) { result = ali1535_transaction(adap);
/* Error in transaction */ if (result)
result = -1;
goto EXIT; goto EXIT;
}
if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) { if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) {
result = 0; result = 0;
......
...@@ -67,6 +67,7 @@ static int ali1563_transaction(struct i2c_adapter * a, int size) ...@@ -67,6 +67,7 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
{ {
u32 data; u32 data;
int timeout; int timeout;
int status = -EIO;
dev_dbg(&a->dev, "Transaction (pre): STS=%02x, CNTL1=%02x, " dev_dbg(&a->dev, "Transaction (pre): STS=%02x, CNTL1=%02x, "
"CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
...@@ -103,13 +104,15 @@ static int ali1563_transaction(struct i2c_adapter * a, int size) ...@@ -103,13 +104,15 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
/* Issue 'kill' to host controller */ /* Issue 'kill' to host controller */
outb_p(HST_CNTL2_KILL,SMB_HST_CNTL2); outb_p(HST_CNTL2_KILL,SMB_HST_CNTL2);
data = inb_p(SMB_HST_STS); data = inb_p(SMB_HST_STS);
status = -ETIMEDOUT;
} }
/* device error - no response, ignore the autodetection case */ /* device error - no response, ignore the autodetection case */
if ((data & HST_STS_DEVERR) && (size != HST_CNTL2_QUICK)) { if (data & HST_STS_DEVERR) {
dev_err(&a->dev, "Device error!\n"); if (size != HST_CNTL2_QUICK)
dev_err(&a->dev, "Device error!\n");
status = -ENXIO;
} }
/* bus collision */ /* bus collision */
if (data & HST_STS_BUSERR) { if (data & HST_STS_BUSERR) {
dev_err(&a->dev, "Bus collision!\n"); dev_err(&a->dev, "Bus collision!\n");
...@@ -122,13 +125,14 @@ static int ali1563_transaction(struct i2c_adapter * a, int size) ...@@ -122,13 +125,14 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
outb_p(0x0,SMB_HST_CNTL2); outb_p(0x0,SMB_HST_CNTL2);
} }
return -1; return status;
} }
static int ali1563_block_start(struct i2c_adapter * a) static int ali1563_block_start(struct i2c_adapter * a)
{ {
u32 data; u32 data;
int timeout; int timeout;
int status = -EIO;
dev_dbg(&a->dev, "Block (pre): STS=%02x, CNTL1=%02x, " dev_dbg(&a->dev, "Block (pre): STS=%02x, CNTL1=%02x, "
"CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
...@@ -164,13 +168,20 @@ static int ali1563_block_start(struct i2c_adapter * a) ...@@ -164,13 +168,20 @@ static int ali1563_block_start(struct i2c_adapter * a)
if (timeout && !(data & HST_STS_BAD)) if (timeout && !(data & HST_STS_BAD))
return 0; return 0;
if (timeout == 0)
status = -ETIMEDOUT;
if (data & HST_STS_DEVERR)
status = -ENXIO;
dev_err(&a->dev, "SMBus Error: %s%s%s%s%s\n", dev_err(&a->dev, "SMBus Error: %s%s%s%s%s\n",
timeout ? "Timeout " : "", timeout ? "" : "Timeout ",
data & HST_STS_FAIL ? "Transaction Failed " : "", data & HST_STS_FAIL ? "Transaction Failed " : "",
data & HST_STS_BUSERR ? "No response or Bus Collision " : "", data & HST_STS_BUSERR ? "No response or Bus Collision " : "",
data & HST_STS_DEVERR ? "Device Error " : "", data & HST_STS_DEVERR ? "Device Error " : "",
!(data & HST_STS_DONE) ? "Transaction Never Finished " : ""); !(data & HST_STS_DONE) ? "Transaction Never Finished " : "");
return -1; return status;
} }
static int ali1563_block(struct i2c_adapter * a, union i2c_smbus_data * data, u8 rw) static int ali1563_block(struct i2c_adapter * a, union i2c_smbus_data * data, u8 rw)
......
...@@ -282,7 +282,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap) ...@@ -282,7 +282,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
dev_err(&adap->dev, "SMBus reset failed! (0x%02x) - " dev_err(&adap->dev, "SMBus reset failed! (0x%02x) - "
"controller or device on bus is probably hung\n", "controller or device on bus is probably hung\n",
temp); temp);
return -1; return -EBUSY;
} }
} else { } else {
/* check and clear done bit */ /* check and clear done bit */
...@@ -304,12 +304,12 @@ static int ali15x3_transaction(struct i2c_adapter *adap) ...@@ -304,12 +304,12 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
result = -1; result = -ETIMEDOUT;
dev_err(&adap->dev, "SMBus Timeout!\n"); dev_err(&adap->dev, "SMBus Timeout!\n");
} }
if (temp & ALI15X3_STS_TERM) { if (temp & ALI15X3_STS_TERM) {
result = -1; result = -EIO;
dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
} }
...@@ -320,7 +320,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap) ...@@ -320,7 +320,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
This means that bus collisions go unreported. This means that bus collisions go unreported.
*/ */
if (temp & ALI15X3_STS_COLL) { if (temp & ALI15X3_STS_COLL) {
result = -1; result = -ENXIO;
dev_dbg(&adap->dev, dev_dbg(&adap->dev,
"Error: no response or bus collision ADD=%02x\n", "Error: no response or bus collision ADD=%02x\n",
inb_p(SMBHSTADD)); inb_p(SMBHSTADD));
...@@ -328,7 +328,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap) ...@@ -328,7 +328,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
/* haven't ever seen this */ /* haven't ever seen this */
if (temp & ALI15X3_STS_DEV) { if (temp & ALI15X3_STS_DEV) {
result = -1; result = -EIO;
dev_err(&adap->dev, "Error: device error\n"); dev_err(&adap->dev, "Error: device error\n");
} }
dev_dbg(&adap->dev, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, " dev_dbg(&adap->dev, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, "
...@@ -338,7 +338,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap) ...@@ -338,7 +338,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
return result; return result;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr, static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, unsigned short flags, char read_write, u8 command,
int size, union i2c_smbus_data * data) int size, union i2c_smbus_data * data)
...@@ -364,7 +364,7 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr, ...@@ -364,7 +364,7 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
switch (size) { switch (size) {
case I2C_SMBUS_PROC_CALL: case I2C_SMBUS_PROC_CALL:
dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
return -1; return -EOPNOTSUPP;
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
SMBHSTADD); SMBHSTADD);
...@@ -421,8 +421,9 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr, ...@@ -421,8 +421,9 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
outb_p(size, SMBHSTCNT); /* output command */ outb_p(size, SMBHSTCNT); /* output command */
if (ali15x3_transaction(adap)) /* Error in transaction */ temp = ali15x3_transaction(adap);
return -1; if (temp)
return temp;
if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK)) if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK))
return 0; return 0;
......
...@@ -58,7 +58,7 @@ static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr, ...@@ -58,7 +58,7 @@ static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr,
/* We exclude the multiplexed addresses */ /* We exclude the multiplexed addresses */
if (addr == 0x4c || (addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30 if (addr == 0x4c || (addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30
|| addr == 0x18) || addr == 0x18)
return -1; return -ENXIO;
mutex_lock(&amd756_lock); mutex_lock(&amd756_lock);
...@@ -86,7 +86,7 @@ static inline s32 amd756_access_channel(struct i2c_adapter * adap, u16 addr, ...@@ -86,7 +86,7 @@ static inline s32 amd756_access_channel(struct i2c_adapter * adap, u16 addr,
/* We exclude the non-multiplexed addresses */ /* We exclude the non-multiplexed addresses */
if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30) if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
return -1; return -ENXIO;
mutex_lock(&amd756_lock); mutex_lock(&amd756_lock);
......
...@@ -151,17 +151,17 @@ static int amd756_transaction(struct i2c_adapter *adap) ...@@ -151,17 +151,17 @@ static int amd756_transaction(struct i2c_adapter *adap)
} }
if (temp & GS_PRERR_STS) { if (temp & GS_PRERR_STS) {
result = -1; result = -ENXIO;
dev_dbg(&adap->dev, "SMBus Protocol error (no response)!\n"); dev_dbg(&adap->dev, "SMBus Protocol error (no response)!\n");
} }
if (temp & GS_COL_STS) { if (temp & GS_COL_STS) {
result = -1; result = -EIO;
dev_warn(&adap->dev, "SMBus collision!\n"); dev_warn(&adap->dev, "SMBus collision!\n");
} }
if (temp & GS_TO_STS) { if (temp & GS_TO_STS) {
result = -1; result = -ETIMEDOUT;
dev_dbg(&adap->dev, "SMBus protocol timeout!\n"); dev_dbg(&adap->dev, "SMBus protocol timeout!\n");
} }
...@@ -189,22 +189,23 @@ static int amd756_transaction(struct i2c_adapter *adap) ...@@ -189,22 +189,23 @@ static int amd756_transaction(struct i2c_adapter *adap)
outw_p(inw(SMB_GLOBAL_ENABLE) | GE_ABORT, SMB_GLOBAL_ENABLE); outw_p(inw(SMB_GLOBAL_ENABLE) | GE_ABORT, SMB_GLOBAL_ENABLE);
msleep(100); msleep(100);
outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS); outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS);
return -1; return -EIO;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 amd756_access(struct i2c_adapter * adap, u16 addr, static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data * data) u8 command, int size, union i2c_smbus_data * data)
{ {
int i, len; int i, len;
int status;
/** TODO: Should I supporte the 10-bit transfers? */ /** TODO: Should I supporte the 10-bit transfers? */
switch (size) { switch (size) {
case I2C_SMBUS_PROC_CALL: case I2C_SMBUS_PROC_CALL:
dev_dbg(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); dev_dbg(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
/* TODO: Well... It is supported, I'm just not sure what to do here... */ /* TODO: Well... It is supported, I'm just not sure what to do here... */
return -1; return -EOPNOTSUPP;
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), outw_p(((addr & 0x7f) << 1) | (read_write & 0x01),
SMB_HOST_ADDRESS); SMB_HOST_ADDRESS);
...@@ -256,8 +257,9 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr, ...@@ -256,8 +257,9 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
/* How about enabling interrupts... */ /* How about enabling interrupts... */
outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE); outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE);
if (amd756_transaction(adap)) /* Error in transaction */ status = amd756_transaction(adap);
return -1; if (status)
return status;
if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK)) if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK))
return 0; return 0;
......
...@@ -77,7 +77,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus) ...@@ -77,7 +77,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus)
if (!timeout) { if (!timeout) {
dev_warn(&smbus->dev->dev, dev_warn(&smbus->dev->dev,
"Timeout while waiting for IBF to clear\n"); "Timeout while waiting for IBF to clear\n");
return -1; return -ETIMEDOUT;
} }
return 0; return 0;
...@@ -93,7 +93,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) ...@@ -93,7 +93,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus)
if (!timeout) { if (!timeout) {
dev_warn(&smbus->dev->dev, dev_warn(&smbus->dev->dev,
"Timeout while waiting for OBF to set\n"); "Timeout while waiting for OBF to set\n");
return -1; return -ETIMEDOUT;
} }
return 0; return 0;
...@@ -102,16 +102,21 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus) ...@@ -102,16 +102,21 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus)
static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address,
unsigned char *data) unsigned char *data)
{ {
if (amd_ec_wait_write(smbus)) int status;
return -1;
status = amd_ec_wait_write(smbus);
if (status)
return status;
outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD); outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD);
if (amd_ec_wait_write(smbus)) status = amd_ec_wait_write(smbus);
return -1; if (status)
return status;
outb(address, smbus->base + AMD_EC_DATA); outb(address, smbus->base + AMD_EC_DATA);
if (amd_ec_wait_read(smbus)) status = amd_ec_wait_read(smbus);
return -1; if (status)
return status;
*data = inb(smbus->base + AMD_EC_DATA); *data = inb(smbus->base + AMD_EC_DATA);
return 0; return 0;
...@@ -120,16 +125,21 @@ static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, ...@@ -120,16 +125,21 @@ static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address,
static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address, static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address,
unsigned char data) unsigned char data)
{ {
if (amd_ec_wait_write(smbus)) int status;
return -1;
status = amd_ec_wait_write(smbus);
if (status)
return status;
outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD); outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD);
if (amd_ec_wait_write(smbus)) status = amd_ec_wait_write(smbus);
return -1; if (status)
return status;
outb(address, smbus->base + AMD_EC_DATA); outb(address, smbus->base + AMD_EC_DATA);
if (amd_ec_wait_write(smbus)) status = amd_ec_wait_write(smbus);
return -1; if (status)
return status;
outb(data, smbus->base + AMD_EC_DATA); outb(data, smbus->base + AMD_EC_DATA);
return 0; return 0;
...@@ -267,12 +277,17 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, ...@@ -267,12 +277,17 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr,
default: default:
dev_warn(&adap->dev, "Unsupported transaction %d\n", size); dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
return -1; return -EOPNOTSUPP;
} }
amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1);
amd_ec_write(smbus, AMD_SMB_PRTCL, protocol); amd_ec_write(smbus, AMD_SMB_PRTCL, protocol);
/* FIXME this discards status from ec_read(); so temp[0] will
* hold stack garbage ... the rest of this routine will act
* nonsensically. Ignored ec_write() status might explain
* some such failures...
*/
amd_ec_read(smbus, AMD_SMB_STS, temp + 0); amd_ec_read(smbus, AMD_SMB_STS, temp + 0);
if (~temp[0] & AMD_SMB_STS_DONE) { if (~temp[0] & AMD_SMB_STS_DONE) {
...@@ -286,7 +301,7 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, ...@@ -286,7 +301,7 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr,
} }
if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS)) if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS))
return -1; return -EIO;
if (read_write == I2C_SMBUS_WRITE) if (read_write == I2C_SMBUS_WRITE)
return 0; return 0;
......
...@@ -151,7 +151,7 @@ static int i801_transaction(int xact) ...@@ -151,7 +151,7 @@ static int i801_transaction(int xact)
outb_p(temp, SMBHSTSTS); outb_p(temp, SMBHSTSTS);
if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) {
dev_dbg(&I801_dev->dev, "Failed! (%02x)\n", temp); dev_dbg(&I801_dev->dev, "Failed! (%02x)\n", temp);
return -1; return -EBUSY;
} else { } else {
dev_dbg(&I801_dev->dev, "Successful!\n"); dev_dbg(&I801_dev->dev, "Successful!\n");
} }
...@@ -170,7 +170,7 @@ static int i801_transaction(int xact) ...@@ -170,7 +170,7 @@ static int i801_transaction(int xact)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
result = -1; result = -ETIMEDOUT;
/* try to stop the current command */ /* try to stop the current command */
dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); dev_dbg(&I801_dev->dev, "Terminating the current operation\n");
outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT);
...@@ -179,19 +179,19 @@ static int i801_transaction(int xact) ...@@ -179,19 +179,19 @@ static int i801_transaction(int xact)
} }
if (temp & SMBHSTSTS_FAILED) { if (temp & SMBHSTSTS_FAILED) {
result = -1; result = -EIO;
dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n"); dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n");
} }
if (temp & SMBHSTSTS_BUS_ERR) { if (temp & SMBHSTSTS_BUS_ERR) {
result = -1; result = -EIO;
dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked " dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked "
"until next hard reset. (sorry!)\n"); "until next hard reset. (sorry!)\n");
/* Clock stops and slave is stuck in mid-transmission */ /* Clock stops and slave is stuck in mid-transmission */
} }
if (temp & SMBHSTSTS_DEV_ERR) { if (temp & SMBHSTSTS_DEV_ERR) {
result = -1; result = -ENXIO;
dev_dbg(&I801_dev->dev, "Error: no response!\n"); dev_dbg(&I801_dev->dev, "Error: no response!\n");
} }
...@@ -231,6 +231,7 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data, ...@@ -231,6 +231,7 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data,
char read_write, int hwpec) char read_write, int hwpec)
{ {
int i, len; int i, len;
int status;
inb_p(SMBHSTCNT); /* reset the data buffer index */ inb_p(SMBHSTCNT); /* reset the data buffer index */
...@@ -242,14 +243,15 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data, ...@@ -242,14 +243,15 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data,
outb_p(data->block[i+1], SMBBLKDAT); outb_p(data->block[i+1], SMBBLKDAT);
} }
if (i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 |
I801_PEC_EN * hwpec)) I801_PEC_EN * hwpec);
return -1; if (status)
return status;
if (read_write == I2C_SMBUS_READ) { if (read_write == I2C_SMBUS_READ) {
len = inb_p(SMBHSTDAT0); len = inb_p(SMBHSTDAT0);
if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
return -1; return -EPROTO;
data->block[0] = len; data->block[0] = len;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
...@@ -314,11 +316,11 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, ...@@ -314,11 +316,11 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) { if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
dev_err(&I801_dev->dev, dev_err(&I801_dev->dev,
"Reset failed! (%02x)\n", temp); "Reset failed! (%02x)\n", temp);
return -1; return -EBUSY;
} }
if (i != 1) if (i != 1)
/* if die in middle of block transaction, fail */ /* if die in middle of block transaction, fail */
return -1; return -EIO;
} }
if (i == 1) if (i == 1)
...@@ -342,19 +344,19 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, ...@@ -342,19 +344,19 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
msleep(1); msleep(1);
outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL),
SMBHSTCNT); SMBHSTCNT);
result = -1; result = -ETIMEDOUT;
dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
} }
if (temp & SMBHSTSTS_FAILED) { if (temp & SMBHSTSTS_FAILED) {
result = -1; result = -EIO;
dev_dbg(&I801_dev->dev, dev_dbg(&I801_dev->dev,
"Error: Failed bus transaction\n"); "Error: Failed bus transaction\n");
} else if (temp & SMBHSTSTS_BUS_ERR) { } else if (temp & SMBHSTSTS_BUS_ERR) {
result = -1; result = -EIO;
dev_err(&I801_dev->dev, "Bus collision!\n"); dev_err(&I801_dev->dev, "Bus collision!\n");
} else if (temp & SMBHSTSTS_DEV_ERR) { } else if (temp & SMBHSTSTS_DEV_ERR) {
result = -1; result = -ENXIO;
dev_dbg(&I801_dev->dev, "Error: no response!\n"); dev_dbg(&I801_dev->dev, "Error: no response!\n");
} }
...@@ -362,7 +364,7 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data, ...@@ -362,7 +364,7 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
&& command != I2C_SMBUS_I2C_BLOCK_DATA) { && command != I2C_SMBUS_I2C_BLOCK_DATA) {
len = inb_p(SMBHSTDAT0); len = inb_p(SMBHSTDAT0);
if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
return -1; return -EPROTO;
data->block[0] = len; data->block[0] = len;
} }
...@@ -394,7 +396,7 @@ static int i801_set_block_buffer_mode(void) ...@@ -394,7 +396,7 @@ static int i801_set_block_buffer_mode(void)
{ {
outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL);
if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0)
return -1; return -EIO;
return 0; return 0;
} }
...@@ -414,7 +416,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write, ...@@ -414,7 +416,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
} else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) {
dev_err(&I801_dev->dev, dev_err(&I801_dev->dev,
"I2C block read is unsupported!\n"); "I2C block read is unsupported!\n");
return -1; return -EOPNOTSUPP;
} }
} }
...@@ -449,7 +451,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write, ...@@ -449,7 +451,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
return result; return result;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 i801_access(struct i2c_adapter * adap, u16 addr, static s32 i801_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, u8 command, unsigned short flags, char read_write, u8 command,
int size, union i2c_smbus_data * data) int size, union i2c_smbus_data * data)
...@@ -514,7 +516,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr, ...@@ -514,7 +516,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
case I2C_SMBUS_PROC_CALL: case I2C_SMBUS_PROC_CALL:
default: default:
dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size);
return -1; return -EOPNOTSUPP;
} }
if (hwpec) /* enable/disable hardware PEC */ if (hwpec) /* enable/disable hardware PEC */
...@@ -537,7 +539,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr, ...@@ -537,7 +539,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
if(block) if(block)
return ret; return ret;
if(ret) if(ret)
return -1; return ret;
if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
return 0; return 0;
......
...@@ -172,16 +172,16 @@ static int nforce2_check_status(struct i2c_adapter *adap) ...@@ -172,16 +172,16 @@ static int nforce2_check_status(struct i2c_adapter *adap)
dev_dbg(&adap->dev, "SMBus Timeout!\n"); dev_dbg(&adap->dev, "SMBus Timeout!\n");
if (smbus->can_abort) if (smbus->can_abort)
nforce2_abort(adap); nforce2_abort(adap);
return -1; return -ETIMEDOUT;
} }
if (!(temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) { if (!(temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) {
dev_dbg(&adap->dev, "Transaction failed (0x%02x)!\n", temp); dev_dbg(&adap->dev, "Transaction failed (0x%02x)!\n", temp);
return -1; return -EIO;
} }
return 0; return 0;
} }
/* Return -1 on error */ /* Return negative errno on error */
static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data * data) u8 command, int size, union i2c_smbus_data * data)
...@@ -189,7 +189,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, ...@@ -189,7 +189,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
struct nforce2_smbus *smbus = adap->algo_data; struct nforce2_smbus *smbus = adap->algo_data;
unsigned char protocol, pec; unsigned char protocol, pec;
u8 len; u8 len;
int i; int i, status;
protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ :
NVIDIA_SMB_PRTCL_WRITE; NVIDIA_SMB_PRTCL_WRITE;
...@@ -233,7 +233,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, ...@@ -233,7 +233,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
"Transaction failed " "Transaction failed "
"(requested block size: %d)\n", "(requested block size: %d)\n",
len); len);
return -1; return -EINVAL;
} }
outb_p(len, NVIDIA_SMB_BCNT); outb_p(len, NVIDIA_SMB_BCNT);
for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
...@@ -245,14 +245,15 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, ...@@ -245,14 +245,15 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
default: default:
dev_err(&adap->dev, "Unsupported transaction %d\n", size); dev_err(&adap->dev, "Unsupported transaction %d\n", size);
return -1; return -EOPNOTSUPP;
} }
outb_p((addr & 0x7f) << 1, NVIDIA_SMB_ADDR); outb_p((addr & 0x7f) << 1, NVIDIA_SMB_ADDR);
outb_p(protocol, NVIDIA_SMB_PRTCL); outb_p(protocol, NVIDIA_SMB_PRTCL);
if (nforce2_check_status(adap)) status = nforce2_check_status(adap);
return -1; if (status)
return status;
if (read_write == I2C_SMBUS_WRITE) if (read_write == I2C_SMBUS_WRITE)
return 0; return 0;
...@@ -274,7 +275,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, ...@@ -274,7 +275,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
dev_err(&adap->dev, "Transaction failed " dev_err(&adap->dev, "Transaction failed "
"(received block size: 0x%02x)\n", "(received block size: 0x%02x)\n",
len); len);
return -1; return -EPROTO;
} }
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i); data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i);
...@@ -335,7 +336,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar, ...@@ -335,7 +336,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
!= PCIBIOS_SUCCESSFUL) { != PCIBIOS_SUCCESSFUL) {
dev_err(&dev->dev, "Error reading PCI config for %s\n", dev_err(&dev->dev, "Error reading PCI config for %s\n",
name); name);
return -1; return -EIO;
} }
smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK; smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK;
...@@ -345,7 +346,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar, ...@@ -345,7 +346,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) { if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) {
dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n", dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n",
smbus->base, smbus->base+smbus->size-1, name); smbus->base, smbus->base+smbus->size-1, name);
return -1; return -EBUSY;
} }
smbus->adapter.owner = THIS_MODULE; smbus->adapter.owner = THIS_MODULE;
smbus->adapter.id = I2C_HW_SMBUS_NFORCE2; smbus->adapter.id = I2C_HW_SMBUS_NFORCE2;
...@@ -360,7 +361,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar, ...@@ -360,7 +361,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
if (error) { if (error) {
dev_err(&smbus->adapter.dev, "Failed to register adapter.\n"); dev_err(&smbus->adapter.dev, "Failed to register adapter.\n");
release_region(smbus->base, smbus->size); release_region(smbus->base, smbus->size);
return -1; return error;
} }
dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", smbus->base); dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", smbus->base);
return 0; return 0;
......
...@@ -253,7 +253,7 @@ static int piix4_transaction(void) ...@@ -253,7 +253,7 @@ static int piix4_transaction(void)
outb_p(temp, SMBHSTSTS); outb_p(temp, SMBHSTSTS);
if ((temp = inb_p(SMBHSTSTS)) != 0x00) { if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp); dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp);
return -1; return -EBUSY;
} else { } else {
dev_dbg(&piix4_adapter.dev, "Successful!\n"); dev_dbg(&piix4_adapter.dev, "Successful!\n");
} }
...@@ -275,23 +275,23 @@ static int piix4_transaction(void) ...@@ -275,23 +275,23 @@ static int piix4_transaction(void)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
dev_err(&piix4_adapter.dev, "SMBus Timeout!\n"); dev_err(&piix4_adapter.dev, "SMBus Timeout!\n");
result = -1; result = -ETIMEDOUT;
} }
if (temp & 0x10) { if (temp & 0x10) {
result = -1; result = -EIO;
dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n"); dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n");
} }
if (temp & 0x08) { if (temp & 0x08) {
result = -1; result = -EIO;
dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be " dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be "
"locked until next hard reset. (sorry!)\n"); "locked until next hard reset. (sorry!)\n");
/* Clock stops and slave is stuck in mid-transmission */ /* Clock stops and slave is stuck in mid-transmission */
} }
if (temp & 0x04) { if (temp & 0x04) {
result = -1; result = -ENXIO;
dev_dbg(&piix4_adapter.dev, "Error: no response!\n"); dev_dbg(&piix4_adapter.dev, "Error: no response!\n");
} }
...@@ -309,17 +309,18 @@ static int piix4_transaction(void) ...@@ -309,17 +309,18 @@ static int piix4_transaction(void)
return result; return result;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 piix4_access(struct i2c_adapter * adap, u16 addr, static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data * data) u8 command, int size, union i2c_smbus_data * data)
{ {
int i, len; int i, len;
int status;
switch (size) { switch (size) {
case I2C_SMBUS_PROC_CALL: case I2C_SMBUS_PROC_CALL:
dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
return -1; return -EOPNOTSUPP;
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
SMBHSTADD); SMBHSTADD);
...@@ -371,8 +372,9 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr, ...@@ -371,8 +372,9 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
if (piix4_transaction()) /* Error in transaction */ status = piix4_transaction();
return -1; if (status)
return status;
if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
return 0; return 0;
......
...@@ -236,7 +236,7 @@ static int sis5595_transaction(struct i2c_adapter *adap) ...@@ -236,7 +236,7 @@ static int sis5595_transaction(struct i2c_adapter *adap)
sis5595_write(SMB_STS_HI, temp >> 8); 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) {
dev_dbg(&adap->dev, "Failed! (%02x)\n", temp); dev_dbg(&adap->dev, "Failed! (%02x)\n", temp);
return -1; return -EBUSY;
} else { } else {
dev_dbg(&adap->dev, "Successful!\n"); dev_dbg(&adap->dev, "Successful!\n");
} }
...@@ -254,19 +254,19 @@ static int sis5595_transaction(struct i2c_adapter *adap) ...@@ -254,19 +254,19 @@ static int sis5595_transaction(struct i2c_adapter *adap)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
dev_dbg(&adap->dev, "SMBus Timeout!\n"); dev_dbg(&adap->dev, "SMBus Timeout!\n");
result = -1; result = -ETIMEDOUT;
} }
if (temp & 0x10) { if (temp & 0x10) {
dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
result = -1; result = -ENXIO;
} }
if (temp & 0x20) { if (temp & 0x20) {
dev_err(&adap->dev, "Bus collision! SMBus may be locked until " dev_err(&adap->dev, "Bus collision! SMBus may be locked until "
"next hard reset (or not...)\n"); "next hard reset (or not...)\n");
/* Clock stops and slave is stuck in mid-transmission */ /* Clock stops and slave is stuck in mid-transmission */
result = -1; result = -EIO;
} }
temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8); temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8);
...@@ -282,11 +282,13 @@ static int sis5595_transaction(struct i2c_adapter *adap) ...@@ -282,11 +282,13 @@ static int sis5595_transaction(struct i2c_adapter *adap)
return result; return result;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 sis5595_access(struct i2c_adapter *adap, u16 addr, static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write, unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data *data) u8 command, int size, union i2c_smbus_data *data)
{ {
int status;
switch (size) { switch (size) {
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
sis5595_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); sis5595_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01));
...@@ -318,13 +320,14 @@ static s32 sis5595_access(struct i2c_adapter *adap, u16 addr, ...@@ -318,13 +320,14 @@ static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
break; break;
default: default:
dev_warn(&adap->dev, "Unsupported transaction %d\n", size); dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
return -1; return -EOPNOTSUPP;
} }
sis5595_write(SMB_CTL_LO, ((size & 0x0E))); sis5595_write(SMB_CTL_LO, ((size & 0x0E)));
if (sis5595_transaction(adap)) status = sis5595_transaction(adap);
return -1; if (status)
return status;
if ((size != SIS5595_PROC_CALL) && if ((size != SIS5595_PROC_CALL) &&
((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK))) ((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK)))
......
...@@ -134,7 +134,7 @@ static int sis630_transaction_start(struct i2c_adapter *adap, int size, u8 *oldc ...@@ -134,7 +134,7 @@ static int sis630_transaction_start(struct i2c_adapter *adap, int size, u8 *oldc
if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) { if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) {
dev_dbg(&adap->dev, "Failed! (%02x)\n", temp); dev_dbg(&adap->dev, "Failed! (%02x)\n", temp);
return -1; return -EBUSY;
} else { } else {
dev_dbg(&adap->dev, "Successful!\n"); dev_dbg(&adap->dev, "Successful!\n");
} }
...@@ -177,17 +177,17 @@ static int sis630_transaction_wait(struct i2c_adapter *adap, int size) ...@@ -177,17 +177,17 @@ static int sis630_transaction_wait(struct i2c_adapter *adap, int size)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
dev_dbg(&adap->dev, "SMBus Timeout!\n"); dev_dbg(&adap->dev, "SMBus Timeout!\n");
result = -1; result = -ETIMEDOUT;
} }
if (temp & 0x02) { if (temp & 0x02) {
dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
result = -1; result = -ENXIO;
} }
if (temp & 0x04) { if (temp & 0x04) {
dev_err(&adap->dev, "Bus collision!\n"); dev_err(&adap->dev, "Bus collision!\n");
result = -1; result = -EIO;
/* /*
TBD: Datasheet say: TBD: Datasheet say:
the software should clear this bit and restart SMBUS operation. the software should clear this bit and restart SMBUS operation.
...@@ -250,8 +250,10 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat ...@@ -250,8 +250,10 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
if (i==8 || (len<8 && i==len)) { if (i==8 || (len<8 && i==len)) {
dev_dbg(&adap->dev, "start trans len=%d i=%d\n",len ,i); dev_dbg(&adap->dev, "start trans len=%d i=%d\n",len ,i);
/* first transaction */ /* first transaction */
if (sis630_transaction_start(adap, SIS630_BLOCK_DATA, &oldclock)) rc = sis630_transaction_start(adap,
return -1; SIS630_BLOCK_DATA, &oldclock);
if (rc)
return rc;
} }
else if ((i-1)%8 == 7 || i==len) { else if ((i-1)%8 == 7 || i==len) {
dev_dbg(&adap->dev, "trans_wait len=%d i=%d\n",len,i); dev_dbg(&adap->dev, "trans_wait len=%d i=%d\n",len,i);
...@@ -264,9 +266,10 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat ...@@ -264,9 +266,10 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
*/ */
sis630_write(SMB_STS,0x10); sis630_write(SMB_STS,0x10);
} }
if (sis630_transaction_wait(adap, SIS630_BLOCK_DATA)) { rc = sis630_transaction_wait(adap,
SIS630_BLOCK_DATA);
if (rc) {
dev_dbg(&adap->dev, "trans_wait failed\n"); dev_dbg(&adap->dev, "trans_wait failed\n");
rc = -1;
break; break;
} }
} }
...@@ -275,13 +278,14 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat ...@@ -275,13 +278,14 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
else { else {
/* read request */ /* read request */
data->block[0] = len = 0; data->block[0] = len = 0;
if (sis630_transaction_start(adap, SIS630_BLOCK_DATA, &oldclock)) { rc = sis630_transaction_start(adap,
return -1; SIS630_BLOCK_DATA, &oldclock);
} if (rc)
return rc;
do { do {
if (sis630_transaction_wait(adap, SIS630_BLOCK_DATA)) { rc = sis630_transaction_wait(adap, SIS630_BLOCK_DATA);
if (rc) {
dev_dbg(&adap->dev, "trans_wait failed\n"); dev_dbg(&adap->dev, "trans_wait failed\n");
rc = -1;
break; break;
} }
/* if this first transaction then read byte count */ /* if this first transaction then read byte count */
...@@ -311,11 +315,13 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat ...@@ -311,11 +315,13 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
return rc; return rc;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 sis630_access(struct i2c_adapter *adap, u16 addr, static s32 sis630_access(struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write, unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data *data) u8 command, int size, union i2c_smbus_data *data)
{ {
int status;
switch (size) { switch (size) {
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01));
...@@ -350,13 +356,13 @@ static s32 sis630_access(struct i2c_adapter *adap, u16 addr, ...@@ -350,13 +356,13 @@ static s32 sis630_access(struct i2c_adapter *adap, u16 addr,
size = SIS630_BLOCK_DATA; size = SIS630_BLOCK_DATA;
return sis630_block_data(adap, data, read_write); return sis630_block_data(adap, data, read_write);
default: default:
printk("Unsupported I2C size\n"); printk("Unsupported SMBus operation\n");
return -1; return -EOPNOTSUPP;
break;
} }
if (sis630_transaction(adap, size)) status = sis630_transaction(adap, size);
return -1; if (status)
return status;
if ((size != SIS630_PCALL) && if ((size != SIS630_PCALL) &&
((read_write == I2C_SMBUS_WRITE) || (size == SIS630_QUICK))) { ((read_write == I2C_SMBUS_WRITE) || (size == SIS630_QUICK))) {
...@@ -373,8 +379,7 @@ static s32 sis630_access(struct i2c_adapter *adap, u16 addr, ...@@ -373,8 +379,7 @@ static s32 sis630_access(struct i2c_adapter *adap, u16 addr,
data->word = sis630_read(SMB_BYTE) + (sis630_read(SMB_BYTE + 1) << 8); data->word = sis630_read(SMB_BYTE) + (sis630_read(SMB_BYTE + 1) << 8);
break; break;
default: default:
return -1; return -EOPNOTSUPP;
break;
} }
return 0; return 0;
......
...@@ -111,7 +111,7 @@ static int sis96x_transaction(int size) ...@@ -111,7 +111,7 @@ static int sis96x_transaction(int size)
/* check it again */ /* check it again */
if (((temp = sis96x_read(SMB_CNT)) & 0x03) != 0x00) { if (((temp = sis96x_read(SMB_CNT)) & 0x03) != 0x00) {
dev_dbg(&sis96x_adapter.dev, "Failed (0x%02x)\n", temp); dev_dbg(&sis96x_adapter.dev, "Failed (0x%02x)\n", temp);
return -1; return -EBUSY;
} else { } else {
dev_dbg(&sis96x_adapter.dev, "Successful\n"); dev_dbg(&sis96x_adapter.dev, "Successful\n");
} }
...@@ -136,19 +136,19 @@ static int sis96x_transaction(int size) ...@@ -136,19 +136,19 @@ static int sis96x_transaction(int size)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
dev_dbg(&sis96x_adapter.dev, "SMBus Timeout! (0x%02x)\n", temp); dev_dbg(&sis96x_adapter.dev, "SMBus Timeout! (0x%02x)\n", temp);
result = -1; result = -ETIMEDOUT;
} }
/* device error - probably missing ACK */ /* device error - probably missing ACK */
if (temp & 0x02) { if (temp & 0x02) {
dev_dbg(&sis96x_adapter.dev, "Failed bus transaction!\n"); dev_dbg(&sis96x_adapter.dev, "Failed bus transaction!\n");
result = -1; result = -ENXIO;
} }
/* bus collision */ /* bus collision */
if (temp & 0x04) { if (temp & 0x04) {
dev_dbg(&sis96x_adapter.dev, "Bus collision!\n"); dev_dbg(&sis96x_adapter.dev, "Bus collision!\n");
result = -1; result = -EIO;
} }
/* Finish up by resetting the bus */ /* Finish up by resetting the bus */
...@@ -161,11 +161,12 @@ static int sis96x_transaction(int size) ...@@ -161,11 +161,12 @@ static int sis96x_transaction(int size)
return result; return result;
} }
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 sis96x_access(struct i2c_adapter * adap, u16 addr, static s32 sis96x_access(struct i2c_adapter * adap, u16 addr,
unsigned short flags, char read_write, unsigned short flags, char read_write,
u8 command, int size, union i2c_smbus_data * data) u8 command, int size, union i2c_smbus_data * data)
{ {
int status;
switch (size) { switch (size) {
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
...@@ -203,17 +204,17 @@ static s32 sis96x_access(struct i2c_adapter * adap, u16 addr, ...@@ -203,17 +204,17 @@ static s32 sis96x_access(struct i2c_adapter * adap, u16 addr,
case I2C_SMBUS_BLOCK_DATA: case I2C_SMBUS_BLOCK_DATA:
/* TO DO: */ /* TO DO: */
dev_info(&adap->dev, "SMBus block not implemented!\n"); dev_info(&adap->dev, "SMBus block not implemented!\n");
return -1; return -EOPNOTSUPP;
break; break;
default: default:
dev_info(&adap->dev, "Unsupported I2C size\n"); dev_info(&adap->dev, "Unsupported SMBus operation\n");
return -1; return -EOPNOTSUPP;
break;
} }
if (sis96x_transaction(size)) status = sis96x_transaction(size);
return -1; if (status)
return status;
if ((size != SIS96x_PROC_CALL) && if ((size != SIS96x_PROC_CALL) &&
((read_write == I2C_SMBUS_WRITE) || (size == SIS96x_QUICK))) ((read_write == I2C_SMBUS_WRITE) || (size == SIS96x_QUICK)))
......
...@@ -43,7 +43,7 @@ struct stub_chip { ...@@ -43,7 +43,7 @@ struct stub_chip {
static struct stub_chip *stub_chips; static struct stub_chip *stub_chips;
/* Return -1 on error. */ /* Return negative errno on error. */
static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
char read_write, u8 command, int size, union i2c_smbus_data * data) char read_write, u8 command, int size, union i2c_smbus_data * data)
{ {
...@@ -120,7 +120,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, ...@@ -120,7 +120,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
default: default:
dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n");
ret = -1; ret = -EOPNOTSUPP;
break; break;
} /* switch (size) */ } /* switch (size) */
......
...@@ -152,7 +152,7 @@ static int vt596_transaction(u8 size) ...@@ -152,7 +152,7 @@ static int vt596_transaction(u8 size)
if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
dev_err(&vt596_adapter.dev, "SMBus reset failed! " dev_err(&vt596_adapter.dev, "SMBus reset failed! "
"(0x%02x)\n", temp); "(0x%02x)\n", temp);
return -1; return -EBUSY;
} }
} }
...@@ -167,24 +167,24 @@ static int vt596_transaction(u8 size) ...@@ -167,24 +167,24 @@ static int vt596_transaction(u8 size)
/* If the SMBus is still busy, we give up */ /* If the SMBus is still busy, we give up */
if (timeout >= MAX_TIMEOUT) { if (timeout >= MAX_TIMEOUT) {
result = -1; result = -ETIMEDOUT;
dev_err(&vt596_adapter.dev, "SMBus timeout!\n"); dev_err(&vt596_adapter.dev, "SMBus timeout!\n");
} }
if (temp & 0x10) { if (temp & 0x10) {
result = -1; result = -EIO;
dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n", dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n",
size); size);
} }
if (temp & 0x08) { if (temp & 0x08) {
result = -1; result = -EIO;
dev_err(&vt596_adapter.dev, "SMBus collision!\n"); dev_err(&vt596_adapter.dev, "SMBus collision!\n");
} }
if (temp & 0x04) { if (temp & 0x04) {
int read = inb_p(SMBHSTADD) & 0x01; int read = inb_p(SMBHSTADD) & 0x01;
result = -1; result = -ENXIO;
/* The quick and receive byte commands are used to probe /* The quick and receive byte commands are used to probe
for chips, so errors are expected, and we don't want for chips, so errors are expected, and we don't want
to frighten the user. */ to frighten the user. */
...@@ -202,12 +202,13 @@ static int vt596_transaction(u8 size) ...@@ -202,12 +202,13 @@ static int vt596_transaction(u8 size)
return result; return result;
} }
/* Return -1 on error, 0 on success */ /* Return negative errno on error, 0 on success */
static s32 vt596_access(struct i2c_adapter *adap, u16 addr, static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
unsigned short flags, char read_write, u8 command, unsigned short flags, char read_write, u8 command,
int size, union i2c_smbus_data *data) int size, union i2c_smbus_data *data)
{ {
int i; int i;
int status;
switch (size) { switch (size) {
case I2C_SMBUS_QUICK: case I2C_SMBUS_QUICK:
...@@ -258,8 +259,9 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, ...@@ -258,8 +259,9 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD); outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD);
if (vt596_transaction(size)) /* Error in transaction */ status = vt596_transaction(size);
return -1; if (status)
return status;
if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK))
return 0; return 0;
...@@ -287,7 +289,7 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr, ...@@ -287,7 +289,7 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
exit_unsupported: exit_unsupported:
dev_warn(&vt596_adapter.dev, "Unsupported command invoked! (0x%02x)\n", dev_warn(&vt596_adapter.dev, "Unsupported command invoked! (0x%02x)\n",
size); size);
return -1; return -EOPNOTSUPP;
} }
static u32 vt596_func(struct i2c_adapter *adapter) static u32 vt596_func(struct i2c_adapter *adapter)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment