From patchwork Thu Jul 30 15:04:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: HungNien Chen X-Patchwork-Id: 6903501 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C183CC05AC for ; Thu, 30 Jul 2015 15:04:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A04D520569 for ; Thu, 30 Jul 2015 15:04:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4CB8B2057F for ; Thu, 30 Jul 2015 15:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752262AbbG3PEo (ORCPT ); Thu, 30 Jul 2015 11:04:44 -0400 Received: from ml01.weidahitech.com ([61.222.87.235]:2023 "EHLO ml01.weidahitech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751916AbbG3PEn (ORCPT ); Thu, 30 Jul 2015 11:04:43 -0400 Received: from mail01.advancedsilicon.com.tw (mail01.wht.local [192.168.10.15]) by ml01.weidahitech.com (8.13.8/8.13.8) with ESMTP id t6UF3cte014007; Thu, 30 Jul 2015 23:03:38 +0800 Received: from LabPC08.WHT.local ([192.168.10.88]) by mail01.advancedsilicon.com.tw with Microsoft SMTPSVC(6.0.3790.4675); Thu, 30 Jul 2015 23:04:33 +0800 From: HungNien Chen To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, dmitry.torokhov@gmail.com, HungNien Chen Subject: [PATCH] Input: wdt87xx_i2c - Add retries for the I2C transfer functions Date: Thu, 30 Jul 2015 23:04:31 +0800 Message-Id: <1438268671-5245-1-git-send-email-hn.chen@weidahitech.com> X-Mailer: git-send-email 1.9.1 X-OriginalArrivalTime: 30 Jul 2015 15:04:33.0470 (UTC) FILETIME=[0AFB4DE0:01D0CAD9] Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There are 2 reasons for the modification: 1. The touch algorithm will change the controller freq to do the de-noise when there are noises coming and it has the risk to make i2c data error. For the driver, it has no idea if the fw is just doing the de-noise. 2. In old firmware, it has the possibility to get the transfer packet error caused by the controller's fifo underflow when the controller change the freq to the lowest one. Add the retry loop in transfer functions to overcome this kind of temporary transfer packet errors. Signed-off-by: HungNien Chen --- drivers/input/touchscreen/wdt87xx_i2c.c | 95 +++++++++++++++++---------------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/drivers/input/touchscreen/wdt87xx_i2c.c b/drivers/input/touchscreen/wdt87xx_i2c.c index 515c20a..20d845d 100644 --- a/drivers/input/touchscreen/wdt87xx_i2c.c +++ b/drivers/input/touchscreen/wdt87xx_i2c.c @@ -23,7 +23,7 @@ #include #define WDT87XX_NAME "wdt87xx_i2c" -#define WDT87XX_DRV_VER "0.9.7" +#define WDT87XX_DRV_VER "0.9.8" #define WDT87XX_FW_NAME "wdt87xx_fw.bin" #define WDT87XX_CFG_NAME "wdt87xx_cfg.bin" @@ -220,26 +220,25 @@ static int wdt87xx_get_desc(struct i2c_client *client, u8 desc_idx, u8 *buf, size_t len) { u8 tx_buf[] = { 0x22, 0x00, 0x10, 0x0E, 0x23, 0x00 }; - int error; + int error, retry_cnt; tx_buf[2] |= desc_idx & 0xF; - error = wdt87xx_i2c_xfer(client, tx_buf, sizeof(tx_buf), - buf, len); + for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) { + error = wdt87xx_i2c_xfer(client, tx_buf, sizeof(tx_buf), + buf, len); + mdelay(WDT_COMMAND_DELAY_MS); + if (!error && buf[0] == len) + return 0; + } + if (error) { dev_err(&client->dev, "get desc failed: %d\n", error); return error; } - if (buf[0] != len) { - dev_err(&client->dev, "unexpected response to get desc: %d\n", - buf[0]); - return -EINVAL; - } - - mdelay(WDT_COMMAND_DELAY_MS); - - return 0; + dev_err(&client->dev, "unexpected response to get desc: %d\n", buf[0]); + return -EINVAL; } static int wdt87xx_get_string(struct i2c_client *client, u8 str_idx, @@ -248,30 +247,30 @@ static int wdt87xx_get_string(struct i2c_client *client, u8 str_idx, u8 tx_buf[] = { 0x22, 0x00, 0x13, 0x0E, str_idx, 0x23, 0x00 }; u8 rx_buf[PKT_WRITE_SIZE]; size_t rx_len = len + 2; - int error; + int error, retry_cnt; if (rx_len > sizeof(rx_buf)) return -EINVAL; - error = wdt87xx_i2c_xfer(client, tx_buf, sizeof(tx_buf), - rx_buf, rx_len); + for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) { + error = wdt87xx_i2c_xfer(client, tx_buf, sizeof(tx_buf), + rx_buf, rx_len); + mdelay(WDT_COMMAND_DELAY_MS); + if (!error && rx_buf[1] == 0x03) { + rx_len = min_t(size_t, len, rx_buf[0]); + memcpy(buf, &rx_buf[2], rx_len); + return 0; + } + } + if (error) { dev_err(&client->dev, "get string failed: %d\n", error); return error; } - if (rx_buf[1] != 0x03) { - dev_err(&client->dev, "unexpected response to get string: %d\n", - rx_buf[1]); - return -EINVAL; - } - - rx_len = min_t(size_t, len, rx_buf[0]); - memcpy(buf, &rx_buf[2], rx_len); - - mdelay(WDT_COMMAND_DELAY_MS); - - return 0; + dev_err(&client->dev, "unexpected response to get string: %d\n", + rx_buf[1]); + return -EINVAL; } static int wdt87xx_get_feature(struct i2c_client *client, @@ -281,7 +280,7 @@ static int wdt87xx_get_feature(struct i2c_client *client, u8 rx_buf[PKT_WRITE_SIZE]; size_t tx_len = 0; size_t rx_len = buf_size + 2; - int error; + int error, retry_cnt; if (rx_len > sizeof(rx_buf)) return -EINVAL; @@ -300,18 +299,20 @@ static int wdt87xx_get_feature(struct i2c_client *client, tx_buf[tx_len++] = 0x23; tx_buf[tx_len++] = 0x00; - error = wdt87xx_i2c_xfer(client, tx_buf, tx_len, rx_buf, rx_len); - if (error) { - dev_err(&client->dev, "get feature failed: %d\n", error); - return error; + for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) { + error = wdt87xx_i2c_xfer(client, tx_buf, tx_len, + rx_buf, rx_len); + mdelay(WDT_COMMAND_DELAY_MS); + if (!error) { + rx_len = min_t(size_t, buf_size, + get_unaligned_le16(rx_buf)); + memcpy(buf, &rx_buf[2], rx_len); + return 0; + } } - rx_len = min_t(size_t, buf_size, get_unaligned_le16(rx_buf)); - memcpy(buf, &rx_buf[2], rx_len); - - mdelay(WDT_COMMAND_DELAY_MS); - - return 0; + dev_err(&client->dev, "get feature failed: %d\n", error); + return error; } static int wdt87xx_set_feature(struct i2c_client *client, @@ -319,7 +320,7 @@ static int wdt87xx_set_feature(struct i2c_client *client, { u8 tx_buf[PKT_WRITE_SIZE]; int tx_len = 0; - int error; + int error, retry_cnt; /* Set feature command packet */ tx_buf[tx_len++] = 0x22; @@ -343,15 +344,15 @@ static int wdt87xx_set_feature(struct i2c_client *client, memcpy(&tx_buf[tx_len], buf, buf_size); tx_len += buf_size; - error = i2c_master_send(client, tx_buf, tx_len); - if (error < 0) { - dev_err(&client->dev, "set feature failed: %d\n", error); - return error; + for (retry_cnt = 0; retry_cnt < MAX_RETRIES; retry_cnt++) { + error = i2c_master_send(client, tx_buf, tx_len); + mdelay(WDT_COMMAND_DELAY_MS); + if (error >= 0) + return 0; } - mdelay(WDT_COMMAND_DELAY_MS); - - return 0; + dev_err(&client->dev, "set feature failed: %d\n", error); + return error; } static int wdt87xx_send_command(struct i2c_client *client, int cmd, int value)