Skip to content

Commit ab5ec06

Browse files
kennylevinsenJiri Kosina
authored andcommitted
HID: i2c-hid: Retry address probe after delay
Some STM microcontrollers need 400µs after rising clock edge in order to come out of their deep sleep state. This in turn means that our address probe will fail as the device is not ready to service it. Retry the probe once after a delay to see if the device came alive, otherwise treat the device as missing. Link: https://lore.kernel.org/all/[email protected]/#t Co-developed-by: Radoslaw Biernacki <[email protected]> Co-developed-by: Lukasz Majczak <[email protected]> Signed-off-by: Kenny Levinsen <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 3e78a6c commit ab5ec06

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

drivers/hid/i2c-hid/i2c-hid-core.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct)
164164
return quirks;
165165
}
166166

167+
static int i2c_hid_probe_address(struct i2c_hid *ihid)
168+
{
169+
int ret;
170+
171+
/*
172+
* Some STM-based devices need 400µs after a rising clock edge to wake
173+
* from deep sleep, in which case the first read will fail. Try after a
174+
* short sleep to see if the device came alive on the bus. Certain
175+
* Weida Tech devices also need this.
176+
*/
177+
ret = i2c_smbus_read_byte(ihid->client);
178+
if (ret < 0) {
179+
usleep_range(400, 500);
180+
ret = i2c_smbus_read_byte(ihid->client);
181+
}
182+
return ret < 0 ? ret : 0;
183+
}
184+
167185
static int i2c_hid_xfer(struct i2c_hid *ihid,
168186
u8 *send_buf, int send_len, u8 *recv_buf, int recv_len)
169187
{
@@ -1014,8 +1032,7 @@ static int __i2c_hid_core_probe(struct i2c_hid *ihid)
10141032
struct hid_device *hid = ihid->hid;
10151033
int ret;
10161034

1017-
/* Make sure there is something at this address */
1018-
ret = i2c_smbus_read_byte(client);
1035+
ret = i2c_hid_probe_address(ihid);
10191036
if (ret < 0) {
10201037
i2c_hid_dbg(ihid, "nothing at this address: %d\n", ret);
10211038
return -ENXIO;

0 commit comments

Comments
 (0)