aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Hu <hanshu-oc@zhaoxin.com>2023-11-02 10:53:52 +0800
committerWolfram Sang <wsa@kernel.org>2024-01-18 21:10:43 +0100
commit8a22991a48f2602aaab79df1301483d50bc51b2c (patch)
tree75b2e37ee236f565d9f3ec0834c1ef349b2213a3
parent462e9804d2c90bfffb494718b5aae5c374ff3b78 (diff)
downloadlinux-bcache-8a22991a48f2602aaab79df1301483d50bc51b2c.tar.gz
i2c: wmt: Reduce redundant: wait event complete
Put the handling of interrupt events in a function class to reduce code redundancy. Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com> Signed-off-by: Wolfram Sang <wsa@kernel.org>
-rw-r--r--drivers/i2c/busses/i2c-wmt.c20
1 files changed, 6 insertions, 14 deletions
diff --git a/drivers/i2c/busses/i2c-wmt.c b/drivers/i2c/busses/i2c-wmt.c
index d554c637753315..1b31330ba4ebc7 100644
--- a/drivers/i2c/busses/i2c-wmt.c
+++ b/drivers/i2c/busses/i2c-wmt.c
@@ -109,6 +109,12 @@ static int wmt_i2c_wait_bus_not_busy(struct wmt_i2c_dev *i2c_dev)
static int wmt_check_status(struct wmt_i2c_dev *i2c_dev)
{
int ret = 0;
+ unsigned long wait_result;
+
+ wait_result = wait_for_completion_timeout(&i2c_dev->complete,
+ msecs_to_jiffies(500));
+ if (!wait_result)
+ return -ETIMEDOUT;
if (i2c_dev->cmd_status & ISR_NACK_ADDR)
ret = -EIO;
@@ -125,7 +131,6 @@ static int wmt_i2c_write(struct i2c_adapter *adap, struct i2c_msg *pmsg,
struct wmt_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
u16 val, tcr_val;
int ret;
- unsigned long wait_result;
int xfer_len = 0;
if (pmsg->len == 0) {
@@ -167,12 +172,6 @@ static int wmt_i2c_write(struct i2c_adapter *adap, struct i2c_msg *pmsg,
}
while (xfer_len < pmsg->len) {
- wait_result = wait_for_completion_timeout(&i2c_dev->complete,
- msecs_to_jiffies(500));
-
- if (wait_result == 0)
- return -ETIMEDOUT;
-
ret = wmt_check_status(i2c_dev);
if (ret)
return ret;
@@ -210,7 +209,6 @@ static int wmt_i2c_read(struct i2c_adapter *adap, struct i2c_msg *pmsg,
struct wmt_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
u16 val, tcr_val;
int ret;
- unsigned long wait_result;
u32 xfer_len = 0;
val = readw(i2c_dev->base + REG_CR);
@@ -251,12 +249,6 @@ static int wmt_i2c_read(struct i2c_adapter *adap, struct i2c_msg *pmsg,
}
while (xfer_len < pmsg->len) {
- wait_result = wait_for_completion_timeout(&i2c_dev->complete,
- msecs_to_jiffies(500));
-
- if (!wait_result)
- return -ETIMEDOUT;
-
ret = wmt_check_status(i2c_dev);
if (ret)
return ret;