From: Guillaume Champagne <champagne.guillaume.c@gmail.com>
To: champagne.guillaume.c@gmail.com, michael.zaidman@gmail.com,
jikos@kernel.org, benjamin.tissoires@redhat.com
Cc: linux-i2c@vger.kernel.org, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mathieu Gallichand <mathieu.gallichand@sonatest.com>
Subject: [PATCH] HID: ft260: fix multi packet i2c transactions
Date: Tue, 24 May 2022 15:24:22 -0400 [thread overview]
Message-ID: <20220524192422.13967-1-champagne.guillaume.c@gmail.com> (raw)
Only trigger START and STOP conditions for the first and last HID
packets when i2c writes are split in multiple packets. Otherwise, slave
i2c devices receive each packet as standalone i2c transactions. Since
i2c slave devices clear their internal state on STOP, this breaks auto
increment of the register address written to.
Concretely, SCL is now held low between processing of HID packets so i2c
slave devices know to keep increment the same register address when the
next bytes arrive.
Co-developed-by: Mathieu Gallichand <mathieu.gallichand@sonatest.com>
Signed-off-by: Mathieu Gallichand <mathieu.gallichand@sonatest.com>
Signed-off-by: Guillaume Champagne <champagne.guillaume.c@gmail.com>
---
drivers/hid/hid-ft260.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
index 79505c64dbfe..9c5912a21ccb 100644
--- a/drivers/hid/hid-ft260.c
+++ b/drivers/hid/hid-ft260.c
@@ -390,6 +390,8 @@ static int ft260_i2c_write(struct ft260_device *dev, u8 addr, u8 *data,
struct hid_device *hdev = dev->hdev;
struct ft260_i2c_write_request_report *rep =
(struct ft260_i2c_write_request_report *)dev->write_buf;
+ bool multi_packet = data_len > FT260_WR_DATA_MAX;
+ u8 packet_flag = multi_packet ? flag & FT260_FLAG_START_REPEATED : flag;
do {
if (data_len <= FT260_WR_DATA_MAX)
@@ -400,7 +402,7 @@ static int ft260_i2c_write(struct ft260_device *dev, u8 addr, u8 *data,
rep->report = FT260_I2C_DATA_REPORT_ID(len);
rep->address = addr;
rep->length = len;
- rep->flag = flag;
+ rep->flag = packet_flag;
memcpy(rep->data, &data[idx], len);
@@ -418,6 +420,12 @@ static int ft260_i2c_write(struct ft260_device *dev, u8 addr, u8 *data,
data_len -= len;
idx += len;
+ if (multi_packet) {
+ if (data_len <= FT260_WR_DATA_MAX)
+ packet_flag = flag & FT260_FLAG_STOP;
+ else
+ packet_flag = FT260_FLAG_NONE;
+ }
} while (data_len > 0);
return 0;
--
2.20.1
next reply other threads:[~2022-05-24 19:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-24 19:24 Guillaume Champagne [this message]
2022-05-25 8:44 ` [PATCH] HID: ft260: fix multi packet i2c transactions Michael Zaidman
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=20220524192422.13967-1-champagne.guillaume.c@gmail.com \
--to=champagne.guillaume.c@gmail.com \
--cc=benjamin.tissoires@redhat.com \
--cc=jikos@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mathieu.gallichand@sonatest.com \
--cc=michael.zaidman@gmail.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;
as well as URLs for NNTP newsgroup(s).