Skip to content

Commit 462e980

Browse files
Hans Huwsakernel
authored andcommitted
i2c: wmt: Reduce redundant: bus busy check
Put wmt_i2c_wait_bus_not_busy() in a more appropriate place to reduce code redundancy Signed-off-by: Hans Hu <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent a835523 commit 462e980

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

drivers/i2c/busses/i2c-wmt.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ static int wmt_i2c_write(struct i2c_adapter *adap, struct i2c_msg *pmsg,
128128
unsigned long wait_result;
129129
int xfer_len = 0;
130130

131-
if (!(pmsg->flags & I2C_M_NOSTART)) {
132-
ret = wmt_i2c_wait_bus_not_busy(i2c_dev);
133-
if (ret < 0)
134-
return ret;
135-
}
136-
137131
if (pmsg->len == 0) {
138132
/*
139133
* We still need to run through the while (..) once, so
@@ -219,12 +213,6 @@ static int wmt_i2c_read(struct i2c_adapter *adap, struct i2c_msg *pmsg,
219213
unsigned long wait_result;
220214
u32 xfer_len = 0;
221215

222-
if (!(pmsg->flags & I2C_M_NOSTART)) {
223-
ret = wmt_i2c_wait_bus_not_busy(i2c_dev);
224-
if (ret < 0)
225-
return ret;
226-
}
227-
228216
val = readw(i2c_dev->base + REG_CR);
229217
val &= ~CR_TX_END;
230218
writew(val, i2c_dev->base + REG_CR);
@@ -297,11 +285,18 @@ static int wmt_i2c_xfer(struct i2c_adapter *adap,
297285
struct i2c_msg *pmsg;
298286
int i, is_last;
299287
int ret = 0;
288+
struct wmt_i2c_dev *i2c_dev = i2c_get_adapdata(adap);
300289

301290
for (i = 0; ret >= 0 && i < num; i++) {
302291
is_last = ((i + 1) == num);
303292

304293
pmsg = &msgs[i];
294+
if (!(pmsg->flags & I2C_M_NOSTART)) {
295+
ret = wmt_i2c_wait_bus_not_busy(i2c_dev);
296+
if (ret < 0)
297+
return ret;
298+
}
299+
305300
if (pmsg->flags & I2C_M_RD)
306301
ret = wmt_i2c_read(adap, pmsg, is_last);
307302
else

0 commit comments

Comments
 (0)