From: Kamlakant Patel <kamlakant.patel@cavium.com>
To: linux-i2c@vger.kernel.org, linux-acpi@vger.kernel.org
Cc: Kamlakant Patel <kamlakant.patel@cavium.com>,
Wolfram Sang <wsa@the-dreams.de>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
Jayachandran C <jnair@caviumnetworks.com>
Subject: [PATCH 3/3] i2c: xlp9xx: Handle I2C_M_RECV_LEN in msg->flags
Date: Wed, 27 Sep 2017 20:22:23 +0530 [thread overview]
Message-ID: <1506523943-8632-4-git-send-email-kamlakant.patel@cavium.com> (raw)
In-Reply-To: <1506523943-8632-1-git-send-email-kamlakant.patel@cavium.com>
The driver needs to handle the flag I2C_M_RECV_LEN during receive to
support SMBus emulation.
Update receive logic to handle the case where the length is received
as the first byte of a transaction.
Also update the code to handle I2C_CLIENT_PEC, which is set when the
client sends a packet error checking code byte.
Signed-off-by: Jayachandran C <jnair@caviumnetworks.com>
Signed-off-by: Kamlakant Patel <kamlakant.patel@cavium.com>
---
drivers/i2c/busses/i2c-xlp9xx.c | 30 +++++++++++++++++++++++++++---
1 file changed, 27 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c
index f0bef2d..91c0369 100644
--- a/drivers/i2c/busses/i2c-xlp9xx.c
+++ b/drivers/i2c/busses/i2c-xlp9xx.c
@@ -82,6 +82,8 @@ struct xlp9xx_i2c_dev {
struct completion msg_complete;
int irq;
bool msg_read;
+ bool len_recv;
+ bool client_pec;
u32 __iomem *base;
u32 msg_buf_remaining;
u32 msg_len;
@@ -143,10 +145,25 @@ static void xlp9xx_i2c_fill_tx_fifo(struct xlp9xx_i2c_dev *priv)
static void xlp9xx_i2c_drain_rx_fifo(struct xlp9xx_i2c_dev *priv)
{
u32 len, i;
- u8 *buf = priv->msg_buf;
+ u8 rlen, *buf = priv->msg_buf;
len = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_FIFOWCNT) &
XLP9XX_I2C_FIFO_WCNT_MASK;
+ if (!len)
+ return;
+ if (priv->len_recv) {
+ /* read length byte */
+ rlen = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
+ *buf++ = rlen;
+ len--;
+ if (priv->client_pec)
+ ++rlen;
+ /* update remaining bytes and message length */
+ priv->msg_buf_remaining = rlen;
+ priv->msg_len = rlen + 1;
+ priv->len_recv = false;
+ }
+
len = min(priv->msg_buf_remaining, len);
for (i = 0; i < len; i++, buf++)
*buf = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_MRXFIFO);
@@ -230,7 +247,7 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
int last_msg)
{
unsigned long timeleft;
- u32 intr_mask, cmd, val;
+ u32 intr_mask, cmd, val, len;
priv->msg_buf = msg->buf;
priv->msg_buf_remaining = priv->msg_len = msg->len;
@@ -263,9 +280,13 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
else
val &= ~XLP9XX_I2C_CTRL_ADDMODE;
+ priv->len_recv = (msg->flags & I2C_M_RECV_LEN);
+ len = priv->len_recv ? XLP9XX_I2C_FIFO_SIZE : msg->len;
+ priv->client_pec = (msg->flags & I2C_CLIENT_PEC);
+
/* set data length to be transferred */
val = (val & ~XLP9XX_I2C_CTRL_MCTLEN_MASK) |
- (msg->len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
+ (len << XLP9XX_I2C_CTRL_MCTLEN_SHIFT);
xlp9xx_write_i2c_reg(priv, XLP9XX_I2C_CTRL, val);
/* fill fifo during tx */
@@ -312,6 +333,9 @@ static int xlp9xx_i2c_xfer_msg(struct xlp9xx_i2c_dev *priv, struct i2c_msg *msg,
return -ETIMEDOUT;
}
+ /* update msg->len with actual received length */
+ if (msg->flags & I2C_M_RECV_LEN)
+ msg->len = priv->msg_len;
return 0;
}
--
2.7.4
next prev parent reply other threads:[~2017-09-27 14:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-27 14:52 [PATCH 0/3] i2c-xlp9xx: update i2c driver to handle I2C_M_RECV_LEN flag Kamlakant Patel
2017-09-27 14:52 ` [PATCH 1/3] ACPI / APD: Add clock frequency for ThunderX2 I2C controller Kamlakant Patel
2017-09-28 8:45 ` Mika Westerberg
2017-09-27 14:52 ` [PATCH 2/3] i2c: xlp9xx: Get clock frequency with clk API Kamlakant Patel
2017-09-28 8:49 ` Mika Westerberg
2017-09-27 14:52 ` Kamlakant Patel [this message]
2017-09-28 8:50 ` [PATCH 3/3] i2c: xlp9xx: Handle I2C_M_RECV_LEN in msg->flags Mika Westerberg
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=1506523943-8632-4-git-send-email-kamlakant.patel@cavium.com \
--to=kamlakant.patel@cavium.com \
--cc=jnair@caviumnetworks.com \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=wsa@the-dreams.de \
/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).