summaryrefslogtreecommitdiff
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
authorClark Wang <xiaoning.wang@nxp.com>2019-03-14 15:28:59 +0800
committerClark Wang <xiaoning.wang@nxp.com>2019-03-14 18:49:52 +0800
commit945b2d92f828dfc6d6e06043b31e357705f9dfb2 (patch)
tree6ce4a516affc19eb67c9af2b96371e4559ba5af5 /drivers/i2c/busses
parent07adc76d3722e95c202b3aadd74d709ec4a2ae65 (diff)
MLK-21140 i2c: rpmsg: ensure received bus_id and addr is same as sent
For some chips may need long time to get the response from M4 sometimes, enlarge timeout to 500ms. Add a judgement to check if the received data is the current transfer wanted. Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/i2c-rpmsg-imx.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/drivers/i2c/busses/i2c-rpmsg-imx.c b/drivers/i2c/busses/i2c-rpmsg-imx.c
index 54fb38ddb517..03e3b5cf8499 100644
--- a/drivers/i2c/busses/i2c-rpmsg-imx.c
+++ b/drivers/i2c/busses/i2c-rpmsg-imx.c
@@ -79,7 +79,7 @@
#include <linux/rpmsg.h>
#define I2C_RPMSG_MAX_BUF_SIZE 16
-#define I2C_RPMSG_TIMEOUT 100 /* unit: ms */
+#define I2C_RPMSG_TIMEOUT 500 /* unit: ms */
#define I2C_RPMSG_CATEGORY 0x09
#define I2C_RPMSG_VERSION 0x0001
@@ -109,6 +109,9 @@ struct i2c_rpmsg_info {
struct i2c_rpmsg_msg *msg;
struct completion cmd_complete;
struct mutex lock;
+
+ u8 bus_id;
+ u16 addr;
};
static struct i2c_rpmsg_info i2c_rpmsg;
@@ -125,6 +128,13 @@ static int i2c_rpmsg_cb(struct rpmsg_device *rpdev, void *data, int len,
if (msg->header.type != I2C_RPMSG_TYPE_RESPONSE)
return -EINVAL;
+ if (msg->bus_id != i2c_rpmsg.bus_id || msg->addr != i2c_rpmsg.addr) {
+ dev_err(&rpdev->dev,
+ "expected bus_id:%d, addr:%2x, received bus_id:%d, addr:%2x\n",
+ i2c_rpmsg.bus_id, i2c_rpmsg.addr, msg->bus_id, msg->addr);
+ return -EINVAL;
+ }
+
if (msg->len > I2C_RPMSG_MAX_BUF_SIZE) {
dev_err(&rpdev->dev,
"%s failed: data length greater than %d, len=%d\n",
@@ -319,6 +329,9 @@ static int i2c_rpbus_xfer(struct i2c_adapter *adapter,
pmsg = &msgs[i];
+ i2c_rpmsg.bus_id = rdata->adapter.nr;
+ i2c_rpmsg.addr = pmsg->addr;
+
if (pmsg->flags & I2C_M_RD) {
ret = i2c_rpmsg_read(pmsg, &i2c_rpmsg,
rdata->adapter.nr, is_last);