diff mbox series

[v2] i2c: i801: Don't clear status flags twice in interrupt mode

Message ID 0995f70a-7d5f-b616-0fe0-0b2b7c16bda0@gmail.com
State New
Headers show
Series [v2] i2c: i801: Don't clear status flags twice in interrupt mode | expand

Commit Message

Heiner Kallweit Dec. 3, 2021, 9:53 p.m. UTC
In interrupt mode we clear the status flags twice, in the interrupt
handler and in i801_check_post(). Remove clearing the status flags
from i801_check_post() and let i801_wait_intr() clear them in
polling mode. Another benefit is that now only checks for error
conditions are left in i801_check_post(), thus better matching the
function name.

Note: There's a comment in i801_check_post() that i801_wait_intr()
clears the error status bits. Actually this hasn't been true until
this change.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
v2:
- clear status flags also in i801_wait_byte_done()
- remove outdated comment at i801_check_post()
---
 drivers/i2c/busses/i2c-i801.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 930c6edbe..60fdb2fec 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -372,11 +372,6 @@  static int i801_check_pre(struct i801_priv *priv)
 	return 0;
 }
 
-/*
- * Convert the status register to an error code, and clear it.
- * Note that status only contains the bits we want to clear, not the
- * actual register value.
- */
 static int i801_check_post(struct i801_priv *priv, int status)
 {
 	int result = 0;
@@ -440,9 +435,6 @@  static int i801_check_post(struct i801_priv *priv, int status)
 		dev_dbg(&priv->pci_dev->dev, "Lost arbitration\n");
 	}
 
-	/* Clear status flags except BYTE_DONE, to be cleared by caller */
-	outb_p(status, SMBHSTSTS(priv));
-
 	return result;
 }
 
@@ -457,8 +449,10 @@  static int i801_wait_intr(struct i801_priv *priv)
 		status = inb_p(SMBHSTSTS(priv));
 		busy = status & SMBHSTSTS_HOST_BUSY;
 		status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR;
-		if (!busy && status)
+		if (!busy && status) {
+			outb_p(status, SMBHSTSTS(priv));
 			return status;
+		}
 	} while (time_is_after_eq_jiffies(timeout));
 
 	return -ETIMEDOUT;
@@ -473,8 +467,13 @@  static int i801_wait_byte_done(struct i801_priv *priv)
 	do {
 		usleep_range(250, 500);
 		status = inb_p(SMBHSTSTS(priv));
-		if (status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE))
-			return status & STATUS_ERROR_FLAGS;
+		status &= STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE;
+		if (status & STATUS_ERROR_FLAGS) {
+			outb_p(status, SMBHSTSTS(priv));
+			return status;
+		} else if (status & SMBHSTSTS_BYTE_DONE) {
+			return 0;
+		}
 	} while (time_is_after_eq_jiffies(timeout));
 
 	return -ETIMEDOUT;