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, Enrik.Berkhan@inka.de,
Michael Zaidman <michael.zaidman@gmail.com>
Subject: [PATCH v4 10/13] HID: ft260: wake up device from power saving mode
Date: Sat, 5 Nov 2022 23:11:48 +0200 [thread overview]
Message-ID: <20221105211151.7094-11-michael.zaidman@gmail.com> (raw)
In-Reply-To: <20221105211151.7094-1-michael.zaidman@gmail.com>
The FT260 can enter a power saving mode after being idle for longer
than 5 seconds.
When being woken up from power saving mode by an I2C write request,
a possible NACK is not correctly reported by the controller. As a
workaround, the driver will issue an I2C status report two times in
ft260_xfer_status() after the chip has been idle for more than 5s.
Co-developed-by: Enrik Berkhan <Enrik.Berkhan@inka.de>
Signed-off-by: Enrik Berkhan <Enrik.Berkhan@inka.de>
Signed-off-by: Michael Zaidman <michael.zaidman@gmail.com>
---
drivers/hid/hid-ft260.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/drivers/hid/hid-ft260.c b/drivers/hid/hid-ft260.c
index 40fae81386e3..ac133980dfe9 100644
--- a/drivers/hid/hid-ft260.c
+++ b/drivers/hid/hid-ft260.c
@@ -31,6 +31,8 @@ MODULE_PARM_DESC(debug, "Toggle FT260 debugging messages");
#define FT260_REPORT_MAX_LENGTH (64)
#define FT260_I2C_DATA_REPORT_ID(len) (FT260_I2C_REPORT_MIN + (len - 1) / 4)
+#define FT260_WAKEUP_NEEDED_AFTER_MS (4800) /* 5s minus 200ms margin */
+
/*
* The ft260 input report format defines 62 bytes for the data payload, but
* when requested 62 bytes, the controller returns 60 and 2 in separate input
@@ -237,6 +239,7 @@ struct ft260_device {
struct completion wait;
struct mutex lock;
u8 write_buf[FT260_REPORT_MAX_LENGTH];
+ unsigned long need_wakeup_at;
u8 *read_buf;
u16 read_idx;
u16 read_len;
@@ -306,6 +309,20 @@ static int ft260_xfer_status(struct ft260_device *dev)
struct ft260_get_i2c_status_report report;
int ret;
+ if (time_is_before_jiffies(dev->need_wakeup_at)) {
+ ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS,
+ (u8 *)&report, sizeof(report));
+ if (unlikely(ret < 0)) {
+ hid_err(hdev, "failed to retrieve status: %d, no wakeup\n",
+ ret);
+ } else {
+ dev->need_wakeup_at = jiffies +
+ msecs_to_jiffies(FT260_WAKEUP_NEEDED_AFTER_MS);
+ ft260_dbg("bus_status %#02x, wakeup\n",
+ report.bus_status);
+ }
+ }
+
ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS,
(u8 *)&report, sizeof(report));
if (unlikely(ret < 0)) {
--
2.34.1
next prev parent reply other threads:[~2022-11-05 21:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-05 21:11 [PATCH v4 00/13] HID: ft260: fixes and performance improvements Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 01/13] HID: ft260: ft260_xfer_status routine cleanup Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 02/13] HID: ft260: improve i2c write performance Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 03/13] HID: ft260: support i2c writes larger than HID report size Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 04/13] HID: ft260: support i2c reads greater " Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 05/13] HID: ft260: improve i2c large reads performance Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 06/13] HID: ft260: do not populate /dev/hidraw device Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 07/13] HID: ft260: skip unexpected HID input reports Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 08/13] HID: ft260: remove SMBus Quick command support Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 09/13] HID: ft260: missed NACK from big i2c read Michael Zaidman
2022-11-05 21:11 ` Michael Zaidman [this message]
2022-11-05 21:11 ` [PATCH v4 11/13] HID: ft260: fix a NULL pointer dereference in ft260_i2c_write Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 12/13] HID: ft260: missed NACK from busy device Michael Zaidman
2022-11-05 21:11 ` [PATCH v4 13/13] HID: ft260: fix 'cast to restricted' kernel CI bot warnings Michael Zaidman
2022-11-11 10:19 ` [PATCH v4 00/13] HID: ft260: fixes and performance improvements Jiri Kosina
2022-11-11 17:13 ` 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=20221105211151.7094-11-michael.zaidman@gmail.com \
--to=michael.zaidman@gmail.com \
--cc=Enrik.Berkhan@inka.de \
--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).