Skip to content

Commit 8a22991

Browse files
Hans Huwsakernel
authored andcommitted
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 <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 462e980 commit 8a22991

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

drivers/i2c/busses/i2c-wmt.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ static int wmt_i2c_wait_bus_not_busy(struct wmt_i2c_dev *i2c_dev)
109109
static int wmt_check_status(struct wmt_i2c_dev *i2c_dev)
110110
{
111111
int ret = 0;
112+
unsigned long wait_result;
113+
114+
wait_result = wait_for_completion_timeout(&i2c_dev->complete,
115+
msecs_to_jiffies(500));
116+
if (!wait_result)
117+
return -ETIMEDOUT;
112118

113119
if (i2c_dev->cmd_status & ISR_NACK_ADDR)
114120
ret = -EIO;
@@ -125,7 +131,6 @@ static int wmt_i2c_write(struct i2c_adapter *adap, struct i2c_msg *pmsg,
125131
struct wmt_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
126132
u16 val, tcr_val;
127133
int ret;
128-
unsigned long wait_result;
129134
int xfer_len = 0;
130135

131136
if (pmsg->len == 0) {
@@ -167,12 +172,6 @@ static int wmt_i2c_write(struct i2c_adapter *adap, struct i2c_msg *pmsg,
167172
}
168173

169174
while (xfer_len < pmsg->len) {
170-
wait_result = wait_for_completion_timeout(&i2c_dev->complete,
171-
msecs_to_jiffies(500));
172-
173-
if (wait_result == 0)
174-
return -ETIMEDOUT;
175-
176175
ret = wmt_check_status(i2c_dev);
177176
if (ret)
178177
return ret;
@@ -210,7 +209,6 @@ static int wmt_i2c_read(struct i2c_adapter *adap, struct i2c_msg *pmsg,
210209
struct wmt_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
211210
u16 val, tcr_val;
212211
int ret;
213-
unsigned long wait_result;
214212
u32 xfer_len = 0;
215213

216214
val = readw(i2c_dev->base + REG_CR);
@@ -251,12 +249,6 @@ static int wmt_i2c_read(struct i2c_adapter *adap, struct i2c_msg *pmsg,
251249
}
252250

253251
while (xfer_len < pmsg->len) {
254-
wait_result = wait_for_completion_timeout(&i2c_dev->complete,
255-
msecs_to_jiffies(500));
256-
257-
if (!wait_result)
258-
return -ETIMEDOUT;
259-
260252
ret = wmt_check_status(i2c_dev);
261253
if (ret)
262254
return ret;

0 commit comments

Comments
 (0)