From patchwork Mon Nov 7 10:38:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HungNien Chen X-Patchwork-Id: 9414683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 837B060512 for ; Mon, 7 Nov 2016 10:42:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 73FEA28ACB for ; Mon, 7 Nov 2016 10:42:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 686C428B49; Mon, 7 Nov 2016 10:42:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E22E28ACB for ; Mon, 7 Nov 2016 10:42:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750745AbcKGKm3 (ORCPT ); Mon, 7 Nov 2016 05:42:29 -0500 Received: from ml01.weidahitech.com ([61.222.87.235]:2962 "EHLO ml01.weidahitech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752029AbcKGKm3 (ORCPT ); Mon, 7 Nov 2016 05:42:29 -0500 X-Greylist: delayed 310 seconds by postgrey-1.27 at vger.kernel.org; Mon, 07 Nov 2016 05:42:28 EST Received: from mail02.WHT.local (mail02.wht.local [192.168.10.16]) by ml01.weidahitech.com (8.13.8/8.13.8) with ESMTP id uA7AaaFd026903; Mon, 7 Nov 2016 18:36:36 +0800 Received: from x-Veriton-M4620G.WHT.local (192.168.10.88) by MAIL02.WHT.local (192.168.10.16) with Microsoft SMTP Server id 14.2.347.0; Mon, 7 Nov 2016 18:36:37 +0800 From: To: CC: , , , HungNien Chen Subject: [PATCH] HID: i2c-hid: add retry in set power for fixing weida's issue Date: Mon, 7 Nov 2016 18:38:58 +0800 Message-ID: <1478515138-1922-1-git-send-email-hn.chen@weidahitech.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: HungNien Chen Just modify the set_power function to send the command twice. It should be ok for other contorllers since it will jump out the loop after the first command send out. If this is not a proper modification, please tell me a proper way to fix this kind of issue. Signed-off-by: HungNien Chen --- drivers/hid/i2c-hid/i2c-hid.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index b3ec4f2..d7423d9 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -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; }