Linux-i2c Archive mirror
 help / color / mirror / Atom feed
From: Hans Hu <hanshu-oc@zhaoxin.com>
To: <andi.shyti@kernel.org>, <linux-i2c@vger.kernel.org>, <wsa@kernel.org>
Cc: <hanshu@zhaoxin.com>
Subject: [PATCH v2 2/2] i2c: viai2c: Fix bug for msg->len is 0
Date: Mon, 11 Mar 2024 16:46:55 +0800	[thread overview]
Message-ID: <3fb1398741536232a1e9b54a5de4072420046db5.1710146668.git.hanshu-oc@zhaoxin.com> (raw)
In-Reply-To: <a3c58b7f15276fab324dd1e158a9f00c195f6f0f.1710146668.git.hanshu-oc@zhaoxin.com>

For the case that msg->len is 0(I2C_SMBUS_QUICK), when the interrupt
occurs, it means that the access has completed, viai2c_irq_xfer()
should return 1.

v1->v2:
	Added some code comments; The commit log is adjusted.
	Link: https://lore.kernel.org/all/20240311032600.56244-2-hanshu-oc@zhaoxin.com/

Signed-off-by: Hans Hu <hanshu-oc@zhaoxin.com>
---
 drivers/i2c/busses/i2c-viai2c-common.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-viai2c-common.c b/drivers/i2c/busses/i2c-viai2c-common.c
index 4c208b3a509e..fbb76d7ea3b0 100644
--- a/drivers/i2c/busses/i2c-viai2c-common.c
+++ b/drivers/i2c/busses/i2c-viai2c-common.c
@@ -123,6 +123,14 @@ int viai2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 	return (ret < 0) ? ret : i;
 }
 
+/*
+ * Main process of the byte mode xfer
+ *
+ * Return value indicates whether the transfer is complete
+ *  1: all the data has been successfully transferred
+ *  0: there is still data that needs to be transferred
+ *  -EIO: error occurred
+ */
 static int viai2c_irq_xfer(struct viai2c *i2c)
 {
 	u16 val;
@@ -142,10 +150,11 @@ static int viai2c_irq_xfer(struct viai2c *i2c)
 		if (val & VIAI2C_CSR_RCV_NOT_ACK)
 			return -EIO;
 
+		/* I2C_SMBUS_QUICK */
 		if (msg->len == 0) {
 			val = VIAI2C_CR_TX_END | VIAI2C_CR_CPU_RDY | VIAI2C_CR_ENABLE;
 			writew(val, base + VIAI2C_REG_CR);
-			return 0;
+			return 1;
 		}
 
 		if ((i2c->xfered_len + 1) == msg->len) {
@@ -195,6 +204,7 @@ static irqreturn_t viai2c_isr(int irq, void *data)
 			i2c->ret = viai2c_fifo_irq_xfer(i2c, true);
 	}
 
+	/* All the data has been successfully transferred or error occurred */
 	if (i2c->ret)
 		complete(&i2c->complete);
 
-- 
2.34.1


  reply	other threads:[~2024-03-11  8:47 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-11  8:46 [PATCH v2 1/2] i2c: viai2c: Fix some minor style issues Hans Hu
2024-03-11  8:46 ` Hans Hu [this message]
2024-03-11  9:46   ` [PATCH v2 2/2] i2c: viai2c: Fix bug for msg->len is 0 Andi Shyti
2024-03-11 10:51     ` Hans Hu

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=3fb1398741536232a1e9b54a5de4072420046db5.1710146668.git.hanshu-oc@zhaoxin.com \
    --to=hanshu-oc@zhaoxin.com \
    --cc=andi.shyti@kernel.org \
    --cc=hanshu@zhaoxin.com \
    --cc=linux-i2c@vger.kernel.org \
    --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 read-only IMAP folder(s) and NNTP newsgroup(s).