diff mbox series

[v3,02/12] i2c: wmt: Reduce redundant: wait event complete

Message ID 5931f8affc8992a229a4bae5bf9a8ad04a564107.1698889581.git.hanshu-oc@zhaoxin.com
State New
Headers show
Series i2c: add zhaoxin i2c controller driver | expand

Commit Message

Hans Hu Nov. 2, 2023, 2:53 a.m. UTC
Put the handling of interrupt events in a function class
to reduce code redundancy.

Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com>
---
 drivers/i2c/busses/i2c-wmt.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

Comments

Wolfram Sang Dec. 22, 2023, 9:34 a.m. UTC | #1
On Thu, Nov 02, 2023 at 10:53:52AM +0800, Hans Hu wrote:
> Put the handling of interrupt events in a function class
> to reduce code redundancy.
> 
> Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com>

Applied to for-next, thanks!
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-wmt.c b/drivers/i2c/busses/i2c-wmt.c
index d554c6377533..1b31330ba4eb 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;