From: Manikanta Guntupalli <manikanta.guntupalli@amd.com>
To: <michal.simek@xilinx.com>, <michal.simek@amd.com>,
<devicetree@vger.kernel.org>, <andrew@lunn.ch>,
<robh+dt@kernel.org>, <krzysztof.kozlowski+dt@linaro.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-i2c@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <git@amd.com>, <manikanta.guntupalli@amd.com>,
<srinivas.goud@amd.com>, <shubhrajyoti.datta@amd.com>,
<manion05gk@gmail.com>,
Raviteja Narayanam <raviteja.narayanam@xilinx.com>
Subject: [PATCH V4 2/9] i2c: xiic: Fix Rx and Tx paths in standard mode
Date: Thu, 2 Feb 2023 15:11:31 +0530 [thread overview]
Message-ID: <1675330898-563-3-git-send-email-manikanta.guntupalli@amd.com> (raw)
In-Reply-To: <1675330898-563-1-git-send-email-manikanta.guntupalli@amd.com>
From: Raviteja Narayanam <raviteja.narayanam@xilinx.com>
repeated start
When a combined message request comes from user space, the
controller has to initiate repeated start sequence. In standard
mode, this repeated start sequence is corrupted if there is still
data in the Tx FIFO.
So, always make sure that all the bytes are completely transmitted
out of the FIFO by waiting for TXEMPTY, if the previous message is
of Tx type.
Signed-off-by: Raviteja Narayanam <raviteja.narayanam@xilinx.com>
Signed-off-by: Manikanta Guntupalli <manikanta.guntupalli@amd.com>
Acked-by: Michal Simek <michal.simek@amd.com>
---
drivers/i2c/busses/i2c-xiic.c | 53 +++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c
index 839564054501..86da622e060c 100644
--- a/drivers/i2c/busses/i2c-xiic.c
+++ b/drivers/i2c/busses/i2c-xiic.c
@@ -61,6 +61,7 @@ enum xiic_endian {
* @state: See STATE_
* @singlemaster: Indicates bus is single master
* @dynamic: Mode of controller
+ * @prev_msg_tx: Previous message is Tx
*/
struct xiic_i2c {
struct device *dev;
@@ -78,6 +79,7 @@ struct xiic_i2c {
enum xilinx_i2c_state state;
bool singlemaster;
bool dynamic;
+ bool prev_msg_tx;
};
#define XIIC_MSB_OFFSET 0
@@ -280,6 +282,24 @@ static int xiic_clear_rx_fifo(struct xiic_i2c *i2c)
return 0;
}
+static int xiic_wait_tx_empty(struct xiic_i2c *i2c)
+{
+ u8 isr;
+ unsigned long timeout;
+
+ timeout = jiffies + XIIC_I2C_TIMEOUT;
+ for (isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET);
+ !(isr & XIIC_INTR_TX_EMPTY_MASK);
+ isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET)) {
+ if (time_after(jiffies, timeout)) {
+ dev_err(i2c->dev, "Timeout waiting at Tx empty\n");
+ return -ETIMEDOUT;
+ }
+ }
+
+ return 0;
+}
+
static int xiic_reinit(struct xiic_i2c *i2c)
{
int ret;
@@ -685,6 +705,20 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
local_irq_restore(flags);
} else {
+ /*
+ * If previous message is Tx, make sure that Tx FIFO is empty
+ * before starting a new transfer as the repeated start in
+ * standard mode can corrupt the transaction if there are
+ * still bytes to be transmitted in FIFO
+ */
+ if (i2c->prev_msg_tx) {
+ int status;
+
+ status = xiic_wait_tx_empty(i2c);
+ if (status)
+ return;
+ }
+
cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET);
/* Set Receive fifo depth */
@@ -739,6 +773,8 @@ static void xiic_start_recv(struct xiic_i2c *i2c)
/* Enable interrupts */
xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK);
+
+ i2c->prev_msg_tx = false;
}
static void xiic_start_send(struct xiic_i2c *i2c)
@@ -773,6 +809,19 @@ static void xiic_start_send(struct xiic_i2c *i2c)
xiic_fill_tx_fifo(i2c);
} else {
+ /*
+ * If previous message is Tx, make sure that Tx FIFO is empty
+ * before starting a new transfer as the repeated start in
+ * standard mode can corrupt the transaction if there are
+ * still bytes to be transmitted in FIFO
+ */
+ if (i2c->prev_msg_tx) {
+ int status;
+
+ status = xiic_wait_tx_empty(i2c);
+ if (status)
+ return;
+ }
/* Check if RSTA should be set */
cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET);
if (cr & XIIC_CR_MSMS_MASK) {
@@ -803,6 +852,7 @@ static void xiic_start_send(struct xiic_i2c *i2c)
XIIC_INTR_TX_ERROR_MASK |
XIIC_INTR_BNB_MASK);
}
+ i2c->prev_msg_tx = true;
}
static void __xiic_start_xfer(struct xiic_i2c *i2c)
@@ -866,6 +916,9 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
/* Decide standard mode or Dynamic mode */
i2c->dynamic = true;
+ /* Initialize prev message type */
+ i2c->prev_msg_tx = false;
+
/*
* If number of messages is 1 and read length is > 255 bytes,
* enter standard mode
--
2.25.1
next prev parent reply other threads:[~2023-02-02 9:43 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-02 9:41 [PATCH V4 0/9] Added Standard mode and SMBus support Manikanta Guntupalli
2023-02-02 9:41 ` [PATCH V4 1/9] i2c: xiic: Add standard mode support for > 255 byte Manikanta Guntupalli
2023-02-03 16:35 ` Wolfram Sang
2023-02-02 9:41 ` Manikanta Guntupalli [this message]
2023-02-03 16:35 ` [PATCH V4 2/9] i2c: xiic: Fix Rx and Tx paths in standard mode Wolfram Sang
2023-02-02 9:41 ` [PATCH V4 3/9] i2c: xiic: Switch to Xiic standard mode for i2c-read Manikanta Guntupalli
2023-02-03 16:35 ` Wolfram Sang
2023-02-02 9:41 ` [PATCH V4 4/9] i2c: xiic: Add wait for FIFO empty in send_tx Manikanta Guntupalli
2023-02-03 16:35 ` Wolfram Sang
2023-02-02 9:41 ` [PATCH V4 5/9] i2c: xiic: Add smbus_block_read functionality Manikanta Guntupalli
2023-02-03 16:37 ` Wolfram Sang
2023-02-02 9:41 ` [PATCH V4 6/9] i2c: xiic: Remove interrupt enable/disable in Rx path Manikanta Guntupalli
2023-02-03 16:37 ` Wolfram Sang
2023-02-02 9:41 ` [PATCH V4 7/9] dt-bindings: i2c: xiic: Add 'xlnx,axi-iic-2.1' to Manikanta Guntupalli
2023-02-02 9:46 ` Krzysztof Kozlowski
2023-02-02 9:41 ` [PATCH V4 8/9] i2c: xiic: Update compatible with new IP version Manikanta Guntupalli
2023-02-02 9:41 ` [PATCH V4 9/9] i2c: xiic: Add SCL frequency configuration support Manikanta Guntupalli
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=1675330898-563-3-git-send-email-manikanta.guntupalli@amd.com \
--to=manikanta.guntupalli@amd.com \
--cc=andrew@lunn.ch \
--cc=devicetree@vger.kernel.org \
--cc=git@amd.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manion05gk@gmail.com \
--cc=michal.simek@amd.com \
--cc=michal.simek@xilinx.com \
--cc=raviteja.narayanam@xilinx.com \
--cc=robh+dt@kernel.org \
--cc=shubhrajyoti.datta@amd.com \
--cc=srinivas.goud@amd.com \
/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
all inboxes | Powered by JetHome®