From: Michael Zaidman <michael.zaidman@gmail.com>
To: jikos@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
linux-i2c@vger.kernel.org, germain.hebert@ca.abb.com,
Enrik.Berkhan@inka.de,
Michael Zaidman <michael.zaidman@gmail.com>,
Guillaume Champagne <champagne.guillaume.c@gmail.com>
Subject: [PATCH v3 03/12] HID: ft260: support i2c writes larger than HID report size
Date: Sun, 30 Oct 2022 22:33:54 +0200 [thread overview]
Message-ID: <20221030203403.4637-4-michael.zaidman@gmail.com> (raw)
In-Reply-To: <20221030203403.4637-1-michael.zaidman@gmail.com>
To support longer than one HID report size write, the driver splits a
single i2c message data payload into multiple i2c messages of HID report
size. However, it does not replicate the offset bytes within the EEPROM
chip in every consequent HID report because it is not and should not be
aware of the EEPROM type. It breaks the i2c write message integrity and
causes the EEPROM device not to acknowledge the second HID report keeping
the i2c bus busy until the ft260 controller reports failure.
This patch preserves the i2c write message integrity by manipulating the
i2c flag bits across multiple HID reports to be seen by the EEPROM device
as a single i2c write transfer.
Before:
$ sudo ./i2cperf -f 2 -o 2 -s 64 -r 0-0xff 13 0x51 -S
Error: Sending messages failed: Input/output error
[ +3.667741] ft260_i2c_write: rep 0xde addr 0x51 off 0 len 60 d[0] 0x0
[ +0.007330] ft260_hid_output_report_check_status: wait 6400 usec, len 64
[ +0.000203] ft260_xfer_status: bus_status 0x40, clock 100
[ +0.000001] ft260_i2c_write: rep 0xd1 addr 0x51 off 60 len 6 d[0] 0x0
[ +0.002337] ft260_hid_output_report_check_status: wait 1000 usec, len 10
[ +0.000157] ft260_xfer_status: bus_status 0x2e, clock 100
[ +0.000241] ft260_i2c_reset: done
[ +0.000003] ft260_i2c_write: failed to start transfer, ret -5
After:
$ sudo ./i2cperf -f 2 -o 2 -s 128 -r 0-0xff 13 0x51 -S
Fill block with increment via i2ctransfer by chunks
-------------------------------------------------------------------
data rate(bps) efficiency(%) data size(B) total IOs IO size(B)
-------------------------------------------------------------------
71260 86 256 2 128
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
Tested-by: Guillaume Champagne <champagne.guillaume.c@gmail.com>
---
drivers/hid/hid-ft260.c | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
index 44106cadd746..cec83f69ebdc 100644
--- a/drivers/hid/hid-ft260.c
+++ b/drivers/hid/hid-ft260.c
@@ -378,41 +378,46 @@ static int ft260_hid_output_report_check_status(struct ft260_device *dev,
}
static int ft260_i2c_write(struct ft260_device *dev, u8 addr, u8 *data,
- int data_len, u8 flag)
+ int len, u8 flag)
{
- int len, ret, idx = 0;
+ int ret, wr_len, idx = 0;
struct hid_device *hdev = dev->hdev;
struct ft260_i2c_write_request_report *rep =
(struct ft260_i2c_write_request_report *)dev->write_buf;
+ rep->flag = FT260_FLAG_START;
+
do {
- if (data_len <= FT260_WR_DATA_MAX)
- len = data_len;
- else
- len = FT260_WR_DATA_MAX;
+ if (len <= FT260_WR_DATA_MAX) {
+ wr_len = len;
+ if (flag == FT260_FLAG_START_STOP)
+ rep->flag |= FT260_FLAG_STOP;
+ } else {
+ wr_len = FT260_WR_DATA_MAX;
+ }
- rep->report = FT260_I2C_DATA_REPORT_ID(len);
+ rep->report = FT260_I2C_DATA_REPORT_ID(wr_len);
rep->address = addr;
- rep->length = len;
- rep->flag = flag;
+ rep->length = wr_len;
- memcpy(rep->data, &data[idx], len);
+ memcpy(rep->data, &data[idx], wr_len);
- ft260_dbg("rep %#02x addr %#02x off %d len %d d[0] %#02x\n",
- rep->report, addr, idx, len, data[0]);
+ ft260_dbg("rep %#02x addr %#02x off %d len %d wlen %d flag %#x d[0] %#02x\n",
+ rep->report, addr, idx, len, wr_len,
+ rep->flag, data[0]);
ret = ft260_hid_output_report_check_status(dev, (u8 *)rep,
- len + 4);
+ wr_len + 4);
if (ret < 0) {
- hid_err(hdev, "%s: failed to start transfer, ret %d\n",
- __func__, ret);
+ hid_err(hdev, "%s: failed with %d\n", __func__, ret);
return ret;
}
- data_len -= len;
- idx += len;
+ len -= wr_len;
+ idx += wr_len;
+ rep->flag = 0;
- } while (data_len > 0);
+ } while (len > 0);
return 0;
}
--
2.34.1
next prev parent reply other threads:[~2022-10-30 20:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 20:33 [PATCH v3 00/12] HID: ft260: fixes and performance improvements Michael Zaidman
2022-10-30 20:33 ` [PATCH v3 01/12] HID: ft260: ft260_xfer_status routine cleanup Michael Zaidman
2022-10-30 20:33 ` [PATCH v3 02/12] HID: ft260: improve i2c write performance Michael Zaidman
2022-10-30 20:33 ` Michael Zaidman [this message]
2022-10-30 20:33 ` [PATCH v3 04/12] HID: ft260: support i2c reads greater than HID report size Michael Zaidman
2022-10-30 20:33 ` [PATCH v3 05/12] HID: ft260: improve i2c large reads performance Michael Zaidman
2022-10-30 20:33 ` [PATCH v3 06/12] HID: ft260: do not populate /dev/hidraw device Michael Zaidman
2022-10-30 20:33 ` [PATCH v3 07/12] HID: ft260: skip unexpected HID input reports Michael Zaidman
2022-10-30 20:33 ` [PATCH v3 08/12] HID: ft260: remove SMBus Quick command support Michael Zaidman
2022-10-30 20:34 ` [PATCH v3 09/12] HID: ft260: missed NACK from big i2c read Michael Zaidman
2022-10-30 20:34 ` [PATCH v3 10/12] HID: ft260: wake up device from power saving mode Michael Zaidman
2022-10-31 17:12 ` Enrik Berkhan
2022-10-30 20:34 ` [PATCH v3 11/12] HID: ft260: fix a NULL pointer dereference in ft260_i2c_write Michael Zaidman
2022-10-30 20:34 ` [PATCH v3 12/12] HID: ft260: missed NACK from busy device 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=20221030203403.4637-4-michael.zaidman@gmail.com \
--to=michael.zaidman@gmail.com \
--cc=Enrik.Berkhan@inka.de \
--cc=champagne.guillaume.c@gmail.com \
--cc=germain.hebert@ca.abb.com \
--cc=jikos@kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).