mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiada Wang <jiada_wang@mentor.com>
To: <nick@shmanahar.org>, <dmitry.torokhov@gmail.com>
Cc: <linux-input@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<erosca@de.adit-jv.com>, <Andrew_Gabbasov@mentor.com>,
	<digetx@gmail.com>, <jiada_wang@mentor.com>
Subject: [PATCH 1/1] Input: atmel_mxt_ts: split large i2c transfers into blocks
Date: Wed, 29 Jul 2020 18:22:52 +0900	[thread overview]
Message-ID: <20200729092252.6394-1-jiada_wang@mentor.com> (raw)

From: Jiada wang <jiada_wang@mentor.com>

Some I2C controllers constrain maximum transferred data in an I2C
transaction by set max_[read|write]_len of i2c_adapter_quirk.
Large i2c transfer transaction beyond this limitation may fail to complete,
cause I2C controller driver aborts the transaction and returns failure.

Therefore this patch was created to split large i2c transaction into
smaller chunks which can complete within max_[read|write]_len defined
by I2C controller driver.

CC: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Jiada wang <jiada_wang@mentor.com>
---
 drivers/input/touchscreen/atmel_mxt_ts.c | 60 ++++++++++++++++++++++--
 1 file changed, 55 insertions(+), 5 deletions(-)

diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c
index a2189739e30f..d7c3c24aa663 100644
--- a/drivers/input/touchscreen/atmel_mxt_ts.c
+++ b/drivers/input/touchscreen/atmel_mxt_ts.c
@@ -620,8 +620,8 @@ static int mxt_send_bootloader_cmd(struct mxt_data *data, bool unlock)
 	return 0;
 }
 
-static int __mxt_read_reg(struct i2c_client *client,
-			       u16 reg, u16 len, void *val)
+static int __mxt_read_chunk(struct i2c_client *client,
+			    u16 reg, u16 len, void *val)
 {
 	struct i2c_msg xfer[2];
 	u8 buf[2];
@@ -655,8 +655,33 @@ static int __mxt_read_reg(struct i2c_client *client,
 	return ret;
 }
 
-static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
-			   const void *val)
+static int __mxt_read_reg(struct i2c_client *client,
+			  u16 reg, u16 len, void *buf)
+{
+	const struct i2c_adapter_quirks *quirks = client->adapter->quirks;
+	u16 size, offset = 0, max_read_len = len;
+	int ret;
+
+	if (quirks && quirks->max_read_len)
+		max_read_len = quirks->max_read_len;
+
+	while (offset < len) {
+		size = min_t(u16, max_read_len, len - offset);
+
+		ret = __mxt_read_chunk(client,
+				       reg + offset,
+				       size, buf + offset);
+		if (ret)
+			return ret;
+
+		offset += size;
+	}
+
+	return 0;
+}
+
+static int __mxt_write_chunk(struct i2c_client *client, u16 reg, u16 len,
+			     const void *val)
 {
 	u8 *buf;
 	size_t count;
@@ -685,9 +710,34 @@ static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
 	return ret;
 }
 
+static int __mxt_write_reg(struct i2c_client *client, u16 reg, u16 len,
+			   const void *val)
+{
+	const struct i2c_adapter_quirks *quirks = client->adapter->quirks;
+	u16 size, offset = 0, max_write_len = len;
+	int ret;
+
+	if (quirks && quirks->max_write_len)
+		max_write_len = quirks->max_write_len;
+
+	while (offset < len) {
+		size = min_t(u16, max_write_len, len - offset);
+
+		ret = __mxt_write_chunk(client,
+					reg + offset,
+					size, val + offset);
+		if (ret)
+			return ret;
+
+		offset += size;
+	}
+
+	return 0;
+}
+
 static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val)
 {
-	return __mxt_write_reg(client, reg, 1, &val);
+	return __mxt_write_chunk(client, reg, 1, &val);
 }
 
 static struct mxt_object *
-- 
2.17.1


             reply	other threads:[~2020-07-29  9:23 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29  9:22 Jiada Wang [this message]
2020-07-30  5:54 ` Dmitry Torokhov

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=20200729092252.6394-1-jiada_wang@mentor.com \
    --to=jiada_wang@mentor.com \
    --cc=Andrew_Gabbasov@mentor.com \
    --cc=digetx@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=erosca@de.adit-jv.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nick@shmanahar.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

all inboxes | Powered by JetHome®