Commit 44c54c4e authored by Heiner Kallweit's avatar Heiner Kallweit Committed by Wolfram Sang

i2c: i801: Improve status polling

Polling uses the same timeout as irq mode: 400 * 500us = 200ms = HZ / 5.
So let's use the adapter->timeout value also for polling. This has the
advantage that userspace can control the timeout value for polling as
well. In addition change the code to make it better readable.
Last but not least remove the timeout debug messages. Calls to both
functions are followed by a call to i801_check_post() that will print
an error message in case of timeout.
Signed-off-by: default avatarHeiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: default avatarJean Delvare <jdelvare@suse.de>
Tested-by: default avatarJean Delvare <jdelvare@suse.de>
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent e11654ec
...@@ -156,9 +156,6 @@ ...@@ -156,9 +156,6 @@
#define SMBAUXCTL_CRC BIT(0) #define SMBAUXCTL_CRC BIT(0)
#define SMBAUXCTL_E32B BIT(1) #define SMBAUXCTL_E32B BIT(1)
/* Other settings */
#define MAX_RETRIES 400
/* I801 command constants */ /* I801 command constants */
#define I801_QUICK 0x00 #define I801_QUICK 0x00
#define I801_BYTE 0x04 #define I801_BYTE 0x04
...@@ -447,42 +444,35 @@ static int i801_check_post(struct i801_priv *priv, int status) ...@@ -447,42 +444,35 @@ static int i801_check_post(struct i801_priv *priv, int status)
/* Wait for BUSY being cleared and either INTR or an error flag being set */ /* Wait for BUSY being cleared and either INTR or an error flag being set */
static int i801_wait_intr(struct i801_priv *priv) static int i801_wait_intr(struct i801_priv *priv)
{ {
int timeout = 0; unsigned long timeout = jiffies + priv->adapter.timeout;
int status; int status, busy;
/* We will always wait for a fraction of a second! */
do { do {
usleep_range(250, 500); usleep_range(250, 500);
status = inb_p(SMBHSTSTS(priv)); status = inb_p(SMBHSTSTS(priv));
} while (((status & SMBHSTSTS_HOST_BUSY) || busy = status & SMBHSTSTS_HOST_BUSY;
!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR))) && status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR;
(timeout++ < MAX_RETRIES)); if (!busy && status)
return status;
} while (time_is_after_eq_jiffies(timeout));
if (timeout > MAX_RETRIES) {
dev_dbg(&priv->pci_dev->dev, "INTR Timeout!\n");
return -ETIMEDOUT; return -ETIMEDOUT;
}
return status & (STATUS_ERROR_FLAGS | SMBHSTSTS_INTR);
} }
/* Wait for either BYTE_DONE or an error flag being set */ /* Wait for either BYTE_DONE or an error flag being set */
static int i801_wait_byte_done(struct i801_priv *priv) static int i801_wait_byte_done(struct i801_priv *priv)
{ {
int timeout = 0; unsigned long timeout = jiffies + priv->adapter.timeout;
int status; int status;
/* We will always wait for a fraction of a second! */
do { do {
usleep_range(250, 500); usleep_range(250, 500);
status = inb_p(SMBHSTSTS(priv)); status = inb_p(SMBHSTSTS(priv));
} while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) && if (status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE))
(timeout++ < MAX_RETRIES)); return status & STATUS_ERROR_FLAGS;
} while (time_is_after_eq_jiffies(timeout));
if (timeout > MAX_RETRIES) {
dev_dbg(&priv->pci_dev->dev, "BYTE_DONE Timeout!\n");
return -ETIMEDOUT; return -ETIMEDOUT;
}
return status & STATUS_ERROR_FLAGS;
} }
static int i801_transaction(struct i801_priv *priv, int xact) static int i801_transaction(struct i801_priv *priv, int xact)
......
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