Skip to content

Commit 1236373

Browse files
MichaelZaidmangregkh
authored andcommitted
HID: ft260: wake up device from power saving mode
[ Upstream commit 4b3da68 ] 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> Signed-off-by: Jiri Kosina <jkosina@suse.cz> Stable-dep-of: bf3e39d ("HID: ft260: fix stack-use-after-return write in I2C read race") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d9cd8c2 commit 1236373

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

drivers/hid/hid-ft260.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ MODULE_PARM_DESC(debug, "Toggle FT260 debugging messages");
3131
#define FT260_REPORT_MAX_LENGTH (64)
3232
#define FT260_I2C_DATA_REPORT_ID(len) (FT260_I2C_REPORT_MIN + (len - 1) / 4)
3333

34+
#define FT260_WAKEUP_NEEDED_AFTER_MS (4800) /* 5s minus 200ms margin */
35+
3436
/*
3537
* The ft260 input report format defines 62 bytes for the data payload, but
3638
* when requested 62 bytes, the controller returns 60 and 2 in separate input
@@ -237,6 +239,7 @@ struct ft260_device {
237239
struct completion wait;
238240
struct mutex lock;
239241
u8 write_buf[FT260_REPORT_MAX_LENGTH];
242+
unsigned long need_wakeup_at;
240243
u8 *read_buf;
241244
u16 read_idx;
242245
u16 read_len;
@@ -306,6 +309,20 @@ static int ft260_xfer_status(struct ft260_device *dev)
306309
struct ft260_get_i2c_status_report report;
307310
int ret;
308311

312+
if (time_is_before_jiffies(dev->need_wakeup_at)) {
313+
ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS,
314+
(u8 *)&report, sizeof(report));
315+
if (unlikely(ret < 0)) {
316+
hid_err(hdev, "failed to retrieve status: %d, no wakeup\n",
317+
ret);
318+
} else {
319+
dev->need_wakeup_at = jiffies +
320+
msecs_to_jiffies(FT260_WAKEUP_NEEDED_AFTER_MS);
321+
ft260_dbg("bus_status %#02x, wakeup\n",
322+
report.bus_status);
323+
}
324+
}
325+
309326
ret = ft260_hid_feature_report_get(hdev, FT260_I2C_STATUS,
310327
(u8 *)&report, sizeof(report));
311328
if (unlikely(ret < 0)) {

0 commit comments

Comments
 (0)