[PATCH linux dev-4.13 3/3] i2c: fsi: Use usleep instead of schedule calls
Eddie James
eajames at linux.vnet.ibm.com
Wed May 30 05:16:38 AEST 2018
Simplify the FSI I2C driver by calling usleep_range while waiting for
data to be made available instead of scheduling a timeout. The schedule
overhead isn't worth it for what should be a short time.
Signed-off-by: Eddie James <eajames at linux.vnet.ibm.com>
---
drivers/i2c/busses/i2c-fsi.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c
index adc2e38..52a662c 100644
--- a/drivers/i2c/busses/i2c-fsi.c
+++ b/drivers/i2c/busses/i2c-fsi.c
@@ -20,7 +20,6 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
-#include <linux/sched.h>
#define FSI_ENGID_I2C 0x7
@@ -135,7 +134,8 @@
#define I2C_PORT_BUSY_RESET 0x80000000
-#define I2C_LOCAL_WAIT_TIMEOUT 2 /* jiffies */
+#define I2C_LOCAL_SLEEP_MAX_US 500
+#define I2C_LOCAL_SLEEP_MIN_US 50
/* choose timeout length from legacy driver; it's well tested */
#define I2C_ABORT_TIMEOUT msecs_to_jiffies(100)
@@ -490,10 +490,7 @@ static int fsi_i2c_abort(struct fsi_i2c_port *port, u32 status)
if (status & I2C_STAT_CMD_COMP)
return 0;
- set_current_state(TASK_INTERRUPTIBLE);
- if (schedule_timeout(I2C_LOCAL_WAIT_TIMEOUT) > 0)
- return -EINTR;
-
+ usleep_range(I2C_LOCAL_SLEEP_MIN_US, I2C_LOCAL_SLEEP_MAX_US);
} while (time_after(start + I2C_ABORT_TIMEOUT, jiffies));
return -ETIME;
@@ -556,7 +553,7 @@ static int fsi_i2c_wait(struct fsi_i2c_port *port, struct i2c_msg *msg,
unsigned long timeout)
{
u32 status = 0;
- int rc, rc_abort;
+ int rc;
unsigned long start = jiffies;
do {
@@ -578,21 +575,10 @@ static int fsi_i2c_wait(struct fsi_i2c_port *port, struct i2c_msg *msg,
continue;
}
- set_current_state(TASK_INTERRUPTIBLE);
- if (schedule_timeout(I2C_LOCAL_WAIT_TIMEOUT) > 0) {
- rc = -EINTR;
- goto abort;
- }
+ usleep_range(I2C_LOCAL_SLEEP_MIN_US, I2C_LOCAL_SLEEP_MAX_US);
} while (time_after(start + timeout, jiffies));
- rc = -ETIME;
-
-abort:
- rc_abort = fsi_i2c_abort(port, status);
- if (rc_abort)
- return rc_abort;
-
- return rc;
+ return -ETIME;
}
static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
--
1.8.3.1
More information about the openbmc
mailing list