Skip to contentSkip to conversation

i2c: designware: return proper fault codes

PATCH Applied Dmitry Guzman 3 participants 3 messages Nov 3 – Nov 8

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c: designware: return proper fault codes

I2C documentation Documentation/i2c/fault-codes.rst defines fault codes for different negative results in I2C transmittion. Previously, i2c-designware driver didn't implement them properly - it returned EREMOTEIO on NACK either on address or data phase instead of ENXIO and EIO respectively, and EINVAL instead of EOPNOTSUPP if a message cannot be sent due to controller hardware limitations.

To comply with the documentation, return the proper fault codes for different conditions, namely:

- EOPNOTSUPP if the controller cannot transfer the message sequence requested (for example, target address change without STOP condition)
- ENXIO if target address is not acknowledged
- EIO on other faults detected by controller (for example, NACK on data)

---
This patch was previously submitted as a part of a patchset that introduces detailed fault reporting feature in i2c-nomadik and i2c-designware drivers and i2c-core.

This patch does not depend on remaining patches in that set, so I submit it separately.

Link to the patch set that it was submitted in:

https://lore.kernel.org/r/[email protected]

---
 drivers/i2c/busses/i2c-designware-common.c | 8 ++++++--
 drivers/i2c/busses/i2c-designware-core.h   | 3 +--
 drivers/i2c/busses/i2c-designware-master.c | 2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)
drivers/i2c/busses/i2c-designware-common.c +6 -2
index a1eca6cd4b75..e934bcbe7660 100644
@@ -776,11 +776,15 @@ int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev)
 	unsigned long abort_source = dev->abort_source;
 	int i;
 
-	if (abort_source & DW_IC_TX_ABRT_NOACK) {
+	if (abort_source & (DW_IC_TX_ABRT_ADDR_NOACK | DW_IC_TX_ABRT_TXDATA_NOACK)) {
 		for_each_set_bit(i, &abort_source, ARRAY_SIZE(abort_sources))
 			dev_dbg(dev->dev,
 				"%s: %s\n", __func__, abort_sources[i]);
-		return -EREMOTEIO;
+
+		if (abort_source & DW_IC_TX_ABRT_TXDATA_NOACK)
+			return -EIO;
+		else
+			return -ENXIO;
 	}
 
 	for_each_set_bit(i, &abort_source, ARRAY_SIZE(abort_sources))
drivers/i2c/busses/i2c-designware-core.h +1 -2
index 2c929a6e8da2..025311c8662c 100644
@@ -112,10 +112,9 @@
 #define DW_IC_RX_ABRT_SLAVE_ARBLOST		BIT(ABRT_SLAVE_ARBLOST)
 #define DW_IC_RX_ABRT_SLAVE_FLUSH_TXFIFO	BIT(ABRT_SLAVE_FLUSH_TXFIFO)
 
-#define DW_IC_TX_ABRT_NOACK			(DW_IC_TX_ABRT_7B_ADDR_NOACK | \
+#define DW_IC_TX_ABRT_ADDR_NOACK		(DW_IC_TX_ABRT_7B_ADDR_NOACK | \
 						 DW_IC_TX_ABRT_10ADDR1_NOACK | \
 						 DW_IC_TX_ABRT_10ADDR2_NOACK | \
-						 DW_IC_TX_ABRT_TXDATA_NOACK | \
 						 DW_IC_TX_ABRT_GCALL_NOACK)
 
 struct clk;
drivers/i2c/busses/i2c-designware-master.c +1 -1
index 7e1d9a2e7733..a469a52b2f8f 100644
@@ -915,7 +915,7 @@ i2c_dw_xfer_common(struct dw_i2c_dev *dev, struct i2c_msg msgs[], int num)
 		 */
 		for (cnt = 1; ; cnt++) {
 			if (!i2c_dw_msg_is_valid(dev, msgs_part, cnt - 1)) {
-				ret = -EINVAL;
+				ret = -EOPNOTSUPP;
 				break;
 			}
 

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261025-i2c-designware-fixes-35d79db08689

Best regards,

Signature · 1 line
Dmitry Guzman <[email protected]>
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dmitry Guzman

I2C documentation Documentation/i2c/fault-codes.rst defines fault codes for different negative results in I2C transmittion. Previously, i2c-designware driver didn't implement them properly - it returned EREMOTEIO on NACK either on address or data phase instead of ENXIO and EIO respectively, and EINVAL instead of EOPNOTSUPP if a message cannot be sent due to controller hardware limitations.

To comply with the documentation, return the proper fault codes for different conditions, namely:

Quoted 6 lines

- EOPNOTSUPP if the controller cannot transfer the message sequence requested (for example, target address change without STOP condition)
- ENXIO if target address is not acknowledged
- EIO on other faults detected by controller (for example, NACK on data)

Reviewed-by on v1 1/1 Applied
#2 lore raw
In reply to Dmitry Guzman
Quoted 10 lines · Dmitry Guzman

I2C documentation Documentation/i2c/fault-codes.rst defines fault codes for different negative results in I2C transmittion. Previously, i2c-designware driver didn't implement them properly - it returned EREMOTEIO on NACK either on address or data phase instead of ENXIO and EIO respectively, and EINVAL instead of EOPNOTSUPP if a message cannot be sent due to controller hardware limitations.

To comply with the documentation, return the proper fault codes for different conditions, namely:

Quoted 7 lines

- EOPNOTSUPP if the controller cannot transfer the message sequence requested (for example, target address change without STOP condition)
- ENXIO if target address is not acknowledged
- EIO on other faults detected by controller (for example, NACK on data)

Cool, thanks for making error codes more consistent.

Applied to for-andi.