Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -320,7 +320,7 @@ static int try_address(struct i2c_adapter *i2c_adap,
		       unsigned char addr, int retries)
{
	struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
	int i, ret = -1;
	int i, ret = 0;

	for (i = 0; i <= retries; i++) {
		ret = i2c_outb(i2c_adap, addr);
@@ -508,7 +508,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
			addr ^= 1;
		ret = try_address(i2c_adap, addr, retries);
		if ((ret != 1) && !nak_ok)
			return -EREMOTEIO;
			return -ENXIO;
	}

	return 0;
+10 −12
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
			dev_err(&adap->dev,
				"SMBus reset failed! (0x%02x) - controller or "
				"device on bus is probably hung\n", temp);
			return -1;
			return -EBUSY;
		}
	} else {
		/* check and clear done bit */
@@ -281,12 +281,12 @@ static int ali1535_transaction(struct i2c_adapter *adap)

	/* If the SMBus is still busy, we give up */
	if (timeout >= MAX_TIMEOUT) {
		result = -1;
		result = -ETIMEDOUT;
		dev_err(&adap->dev, "SMBus Timeout!\n");
	}

	if (temp & ALI1535_STS_FAIL) {
		result = -1;
		result = -EIO;
		dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
	}

@@ -295,7 +295,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
	 * do a printk.  This means that bus collisions go unreported.
	 */
	if (temp & ALI1535_STS_BUSERR) {
		result = -1;
		result = -ENXIO;
		dev_dbg(&adap->dev,
			"Error: no response or bus collision ADD=%02x\n",
			inb_p(SMBHSTADD));
@@ -303,13 +303,13 @@ static int ali1535_transaction(struct i2c_adapter *adap)

	/* haven't ever seen this */
	if (temp & ALI1535_STS_DEV) {
		result = -1;
		result = -EIO;
		dev_err(&adap->dev, "Error: device error\n");
	}

	/* check to see if the "command complete" indication is set */
	if (!(temp & ALI1535_STS_DONE)) {
		result = -1;
		result = -ETIMEDOUT;
		dev_err(&adap->dev, "Error: command never completed\n");
	}

@@ -332,7 +332,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
	return result;
}

/* Return -1 on error. */
/* Return negative errno on error. */
static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
			  unsigned short flags, char read_write, u8 command,
			  int size, union i2c_smbus_data *data)
@@ -359,7 +359,7 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
	switch (size) {
	case I2C_SMBUS_PROC_CALL:
		dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
		result = -1;
		result = -EOPNOTSUPP;
		goto EXIT;
	case I2C_SMBUS_QUICK:
		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
@@ -420,11 +420,9 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
		break;
	}

	if (ali1535_transaction(adap)) {
		/* Error in transaction */
		result = -1;
	result = ali1535_transaction(adap);
	if (result)
		goto EXIT;
	}

	if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) {
		result = 0;
+17 −6
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
{
	u32 data;
	int timeout;
	int status = -EIO;

	dev_dbg(&a->dev, "Transaction (pre): STS=%02x, CNTL1=%02x, "
		"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)
		/* Issue 'kill' to host controller */
		outb_p(HST_CNTL2_KILL,SMB_HST_CNTL2);
		data = inb_p(SMB_HST_STS);
		status = -ETIMEDOUT;
 	}

	/* device error - no response, ignore the autodetection case */
	if ((data & HST_STS_DEVERR) && (size != HST_CNTL2_QUICK)) {
	if (data & HST_STS_DEVERR) {
		if (size != HST_CNTL2_QUICK)
			dev_err(&a->dev, "Device error!\n");
		status = -ENXIO;
	}

	/* bus collision */
	if (data & HST_STS_BUSERR) {
		dev_err(&a->dev, "Bus collision!\n");
@@ -122,13 +125,14 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
		outb_p(0x0,SMB_HST_CNTL2);
	}

	return -1;
	return status;
}

static int ali1563_block_start(struct i2c_adapter * a)
{
	u32 data;
	int timeout;
	int status = -EIO;

	dev_dbg(&a->dev, "Block (pre): STS=%02x, CNTL1=%02x, "
		"CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
@@ -164,13 +168,20 @@ static int ali1563_block_start(struct i2c_adapter * a)

	if (timeout && !(data & HST_STS_BAD))
		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",
		timeout ? "Timeout " : "",
		timeout ? "" : "Timeout ",
		data & HST_STS_FAIL ? "Transaction Failed " : "",
		data & HST_STS_BUSERR ? "No response or Bus Collision " : "",
		data & HST_STS_DEVERR ? "Device Error " : "",
		!(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)
+10 −9
Original line number Diff line number Diff line
@@ -282,7 +282,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
			dev_err(&adap->dev, "SMBus reset failed! (0x%02x) - "
				"controller or device on bus is probably hung\n",
				temp);
			return -1;
			return -EBUSY;
		}
	} else {
		/* check and clear done bit */
@@ -304,12 +304,12 @@ static int ali15x3_transaction(struct i2c_adapter *adap)

	/* If the SMBus is still busy, we give up */
	if (timeout >= MAX_TIMEOUT) {
		result = -1;
		result = -ETIMEDOUT;
		dev_err(&adap->dev, "SMBus Timeout!\n");
	}

	if (temp & ALI15X3_STS_TERM) {
		result = -1;
		result = -EIO;
		dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
	}

@@ -320,7 +320,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
	  This means that bus collisions go unreported.
	*/
	if (temp & ALI15X3_STS_COLL) {
		result = -1;
		result = -ENXIO;
		dev_dbg(&adap->dev,
			"Error: no response or bus collision ADD=%02x\n",
			inb_p(SMBHSTADD));
@@ -328,7 +328,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)

	/* haven't ever seen this */
	if (temp & ALI15X3_STS_DEV) {
		result = -1;
		result = -EIO;
		dev_err(&adap->dev, "Error: device error\n");
	}
	dev_dbg(&adap->dev, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, "
@@ -338,7 +338,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
	return result;
}

/* Return -1 on error. */
/* Return negative errno on error. */
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)
@@ -364,7 +364,7 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
	switch (size) {
	case I2C_SMBUS_PROC_CALL:
		dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
		return -1;
		return -EOPNOTSUPP;
	case I2C_SMBUS_QUICK:
		outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
		       SMBHSTADD);
@@ -421,8 +421,9 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,

	outb_p(size, SMBHSTCNT);	/* output command */

	if (ali15x3_transaction(adap))	/* Error in transaction */
		return -1;
	temp = ali15x3_transaction(adap);
	if (temp)
		return temp;

	if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK))
		return 0;
+2 −2
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr,
	/* We exclude the multiplexed addresses */
	if (addr == 0x4c || (addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30
	 || addr == 0x18)
		return -1;
		return -ENXIO;

	mutex_lock(&amd756_lock);

@@ -86,7 +86,7 @@ static inline s32 amd756_access_channel(struct i2c_adapter * adap, u16 addr,

	/* We exclude the non-multiplexed addresses */
	if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
		return -1;
		return -ENXIO;

	mutex_lock(&amd756_lock);

Loading