Skip to content

Commit bb7c020

Browse files
Hans Huwsakernel
authored andcommitted
i2c: wmt: Reduce redundant: REG_CR setting
These Settings for the same register, REG_CR, can be put together to reduce code redundancy. Signed-off-by: Hans Hu <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent 4c541c6 commit bb7c020

File tree

1 file changed

+9
-26
lines changed

1 file changed

+9
-26
lines changed

drivers/i2c/busses/i2c-wmt.c

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ static int wmt_i2c_write(struct wmt_i2c_dev *i2c_dev, struct i2c_msg *pmsg,
143143
if (!(pmsg->flags & I2C_M_NOSTART)) {
144144
val = readw(i2c_dev->base + REG_CR);
145145
val &= ~CR_TX_END;
146-
writew(val, i2c_dev->base + REG_CR);
147-
148-
val = readw(i2c_dev->base + REG_CR);
149146
val |= CR_CPU_RDY;
150147
writew(val, i2c_dev->base + REG_CR);
151148
}
@@ -201,24 +198,15 @@ static int wmt_i2c_read(struct wmt_i2c_dev *i2c_dev, struct i2c_msg *pmsg)
201198
u32 xfer_len = 0;
202199

203200
val = readw(i2c_dev->base + REG_CR);
204-
val &= ~CR_TX_END;
205-
writew(val, i2c_dev->base + REG_CR);
201+
val &= ~(CR_TX_END | CR_TX_NEXT_NO_ACK);
206202

207-
val = readw(i2c_dev->base + REG_CR);
208-
val &= ~CR_TX_NEXT_NO_ACK;
209-
writew(val, i2c_dev->base + REG_CR);
210-
211-
if (!(pmsg->flags & I2C_M_NOSTART)) {
212-
val = readw(i2c_dev->base + REG_CR);
203+
if (!(pmsg->flags & I2C_M_NOSTART))
213204
val |= CR_CPU_RDY;
214-
writew(val, i2c_dev->base + REG_CR);
215-
}
216205

217-
if (pmsg->len == 1) {
218-
val = readw(i2c_dev->base + REG_CR);
206+
if (pmsg->len == 1)
219207
val |= CR_TX_NEXT_NO_ACK;
220-
writew(val, i2c_dev->base + REG_CR);
221-
}
208+
209+
writew(val, i2c_dev->base + REG_CR);
222210

223211
reinit_completion(&i2c_dev->complete);
224212

@@ -240,15 +228,10 @@ static int wmt_i2c_read(struct wmt_i2c_dev *i2c_dev, struct i2c_msg *pmsg)
240228
pmsg->buf[xfer_len] = readw(i2c_dev->base + REG_CDR) >> 8;
241229
xfer_len++;
242230

243-
if (xfer_len == pmsg->len - 1) {
244-
val = readw(i2c_dev->base + REG_CR);
245-
val |= (CR_TX_NEXT_NO_ACK | CR_CPU_RDY);
246-
writew(val, i2c_dev->base + REG_CR);
247-
} else {
248-
val = readw(i2c_dev->base + REG_CR);
249-
val |= CR_CPU_RDY;
250-
writew(val, i2c_dev->base + REG_CR);
251-
}
231+
val = readw(i2c_dev->base + REG_CR) | CR_CPU_RDY;
232+
if (xfer_len == pmsg->len - 1)
233+
val |= CR_TX_NEXT_NO_ACK;
234+
writew(val, i2c_dev->base + REG_CR);
252235
}
253236

254237
return 0;

0 commit comments

Comments
 (0)