linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: linux-i2c@vger.kernel.org
Cc: Marek Vasut <marex@denx.de>,
	Michal Simek <michal.simek@xilinx.com>,
	Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>,
	Wolfram Sang <wsa@kernel.org>
Subject: [PATCH 4/5] i2c: xiic: Switch from waitqueue to completion
Date: Sat, 13 Jun 2020 17:07:50 +0200	[thread overview]
Message-ID: <20200613150751.114595-4-marex@denx.de> (raw)
In-Reply-To: <20200613150751.114595-1-marex@denx.de>

There will never be threads queueing up in the xiic_xmit(), use
completion synchronization primitive to wait for the interrupt
handler thread to complete instead as it is much better fit and
there is no need to overload it for this purpose.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Cc: Wolfram Sang <wsa@kernel.org>
---
 drivers/i2c/busses/i2c-xiic.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 87eca9d46afd9..e4c3427b2f3f5 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -23,7 +23,7 @@
 #include <linux/platform_device.h>
 #include <linux/i2c.h>
 #include <linux/interrupt.h>
-#include <linux/wait.h>
+#include <linux/completion.h>
 #include <linux/platform_data/i2c-xiic.h>
 #include <linux/io.h>
 #include <linux/slab.h>
@@ -48,7 +48,7 @@ enum xiic_endian {
  * struct xiic_i2c - Internal representation of the XIIC I2C bus
  * @dev:	Pointer to device structure
  * @base:	Memory base of the HW registers
- * @wait:	Wait queue for callers
+ * @completion:	Completion for callers
  * @adap:	Kernel adapter representation
  * @tx_msg:	Messages from above to be sent
  * @lock:	Mutual exclusion
@@ -63,7 +63,7 @@ enum xiic_endian {
 struct xiic_i2c {
 	struct device		*dev;
 	void __iomem		*base;
-	wait_queue_head_t	wait;
+	struct completion	completion;
 	struct i2c_adapter	adap;
 	struct i2c_msg		*tx_msg;
 	struct mutex		lock;
@@ -365,7 +365,7 @@ static void xiic_wakeup(struct xiic_i2c *i2c, int code)
 	i2c->rx_msg = NULL;
 	i2c->nmsgs = 0;
 	i2c->state = code;
-	wake_up(&i2c->wait);
+	complete(&i2c->completion);
 }
 
 static irqreturn_t xiic_process(int irq, void *dev_id)
@@ -677,6 +677,7 @@ static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num)
 
 	i2c->tx_msg = msgs;
 	i2c->nmsgs = num;
+	init_completion(&i2c->completion);
 
 	ret = xiic_reinit(i2c);
 	if (!ret)
@@ -703,23 +704,24 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
 	err = xiic_start_xfer(i2c, msgs, num);
 	if (err < 0) {
 		dev_err(adap->dev.parent, "Error xiic_start_xfer\n");
-		goto out;
+		return err;
 	}
 
-	if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) ||
-		(i2c->state == STATE_DONE), HZ)) {
-		mutex_lock(&i2c->lock);
-		err = (i2c->state == STATE_DONE) ? num : -EIO;
-		goto out;
-	} else {
-		mutex_lock(&i2c->lock);
+	err = wait_for_completion_interruptible_timeout(&i2c->completion,
+							XIIC_I2C_TIMEOUT);
+	mutex_lock(&i2c->lock);
+	if (err == 0) {	/* Timeout */
 		i2c->tx_msg = NULL;
 		i2c->rx_msg = NULL;
 		i2c->nmsgs = 0;
 		err = -ETIMEDOUT;
-		goto out;
+	} else if (err < 0) {	/* Completion error */
+		i2c->tx_msg = NULL;
+		i2c->rx_msg = NULL;
+		i2c->nmsgs = 0;
+	} else {
+		err = (i2c->state == STATE_DONE) ? num : -EIO;
 	}
-out:
 	mutex_unlock(&i2c->lock);
 	pm_runtime_mark_last_busy(i2c->dev);
 	pm_runtime_put_autosuspend(i2c->dev);
@@ -781,7 +783,6 @@ static int xiic_i2c_probe(struct platform_device *pdev)
 	i2c->adap.dev.of_node = pdev->dev.of_node;
 
 	mutex_init(&i2c->lock);
-	init_waitqueue_head(&i2c->wait);
 
 	i2c->clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(i2c->clk)) {
-- 
2.26.2


  parent reply	other threads:[~2020-06-13 15:08 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-13 15:07 [PATCH 1/5] i2c: xiic: Fix broken locking on tx_msg Marek Vasut
2020-06-13 15:07 ` [PATCH 2/5] i2c: xiic: Drop broken interrupt handler Marek Vasut
2020-06-17 12:25   ` Shubhrajyoti Datta
2020-06-17 12:31     ` Marek Vasut
2020-06-26 12:13   ` Raviteja Narayanam
2020-06-28 23:41     ` Marek Vasut
2020-06-29 12:52       ` Raviteja Narayanam
2020-06-29 21:50         ` Marek Vasut
2020-07-08 15:23           ` Raviteja Narayanam
2020-08-19 17:42             ` Marek Vasut
2020-08-24  8:27               ` Raviteja Narayanam
2020-08-24 11:58                 ` Marek Vasut
2020-08-25  9:44                   ` Raviteja Narayanam
2020-08-25 20:50                     ` Marek Vasut
2020-09-07  8:51                       ` Raviteja Narayanam
2020-09-08 14:04                         ` Marek Vasut
2020-09-11 10:28                           ` Michal Simek
2020-06-13 15:07 ` [PATCH 3/5] i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process() Marek Vasut
2020-06-26 12:13   ` Raviteja Narayanam
2020-07-08 15:23     ` Raviteja Narayanam
2020-06-13 15:07 ` Marek Vasut [this message]
2020-06-26 12:13   ` [PATCH 4/5] i2c: xiic: Switch from waitqueue to completion Raviteja Narayanam
2020-06-28 23:41     ` Marek Vasut
2020-06-29 12:53       ` Raviteja Narayanam
2020-06-29 21:52         ` Marek Vasut
2020-06-13 15:07 ` [PATCH 5/5] i2c: xiic: Only ever transfer single message Marek Vasut
2020-06-13 19:33   ` Wolfram Sang
2020-06-13 19:37     ` Marek Vasut
2020-06-13 19:42       ` Wolfram Sang
2020-07-13  8:37         ` Michal Simek
2020-06-26 12:14   ` Raviteja Narayanam
2020-06-26 12:11 ` [PATCH 1/5] i2c: xiic: Fix broken locking on tx_msg Raviteja Narayanam
2020-06-28 23:18   ` Marek Vasut
2020-06-29 12:52     ` Raviteja Narayanam
2020-07-08 15:23       ` Raviteja Narayanam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200613150751.114595-4-marex@denx.de \
    --to=marex@denx.de \
    --cc=linux-i2c@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=shubhrajyoti.datta@xilinx.com \
    --cc=wsa@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).