@@ -49,6 +49,8 @@
#define I2C_HID_PWR_ON 0x00
#define I2C_HID_PWR_SLEEP 0x01
+#define SET_PWR_RETRIES 2
+
/* debug option */
static bool debug;
module_param(debug, bool, 0444);
@@ -343,14 +345,26 @@ static int i2c_hid_set_power(struct i2c_client *client, int power_state)
{
struct i2c_hid *ihid = i2c_get_clientdata(client);
int ret;
+ int retry;
i2c_hid_dbg(ihid, "%s\n", __func__);
- ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
- 0, NULL, 0, NULL, 0);
- if (ret)
- dev_err(&client->dev, "failed to change power setting.\n");
+ /*
+ * Some Weida's controllers require Set_Power twice on resume.
+ * The 1st cmd wakeup the controller and the 2nd cmd will be executed.
+ * It should be safe to controllers of other vendors.
+ */
+ for (retry = 0; retry < SET_PWR_RETRIES; retry++) {
+ ret = __i2c_hid_command(client, &hid_set_power_cmd,
+ power_state, 0, NULL, 0, NULL, 0);
+
+ if (!ret)
+ goto set_power_exit;
+ }
+
+ dev_err(&client->dev, "failed to change power setting.\n");
+set_power_exit:
return ret;
}