Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1415177pxk; Sun, 13 Sep 2020 01:45:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEU/18BcHw6/JL2VzxwUJAnwrHP0vgnMPFJCgHJ6E0zJ1KPygjuh+xZk7vlAbEN7SyVJ2P X-Received: by 2002:a50:8e17:: with SMTP id 23mr11647469edw.31.1599986712587; Sun, 13 Sep 2020 01:45:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599986712; cv=none; d=google.com; s=arc-20160816; b=PpvF+qJbaEiKIgnS1/TxS5Rzovv+vFFA0X7lEGnmJbXksSfB8e7FJmEbYWrENSJjMG huLTDQVyvBqPVHFHdt23FUxyoGgOuRLlBlSGpjio7JLBkv1hMop81KE7w+eTRvG+1w8b xatT4CmJq0Hnpl6FjsHJkiSuH+Vlc3dTpmFzMJCWTMpiUgQqAmcZuoHGI0YianfJfPs5 oK3zBi3AFyhBZSU/QCAkb6jYALF0qAcb6VccoYFh/i1FQZTr/tvN0X+wvxbtBXpIBKQ1 pbcSthlhfeclXZubhETZPiwqQRaiDp8ZSL/XAHoxz/Ptm3YtcDRz0JhnJ2VNaGkyFdzx 1qEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=NWPCM95Jy2jcUDCt/7JKciRdRd6ZqKhPdOh02zVP2WY=; b=phsev89xro56MX1pn13KUDJjPWpdz4La/kNPBzSnlId0Dd3fJN33M29h1AGGdzrOSs FUt03i096A7ZZvmGc5NkhfAZKgwws2oK4i374v9sMeOszemay6je4pK4lqHKm9/01iwQ p58n4zh8UgoisBu6Ocvn9ZacVZNXd/d5K7t+QJP/r8YCSdc9yczAldN6FG7QjcBN+tM4 UTUPa9Uk9NdR4ilxbp2T4RrLLBwiM4blPbyHVQhg6qqFfH/svz2AeLliyGYlyYXuFj2F ijCRWebSdOndk0WPuGTycuKdwRwWv7/B/8me4hcDdj3fmT1YZPSdxx6vxae03lmmQQwS HZIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e9ID21zf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k10si4529134ejd.657.2020.09.13.01.44.50; Sun, 13 Sep 2020 01:45:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=e9ID21zf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726047AbgIMIoB (ORCPT + 99 others); Sun, 13 Sep 2020 04:44:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725899AbgIMIn6 (ORCPT ); Sun, 13 Sep 2020 04:43:58 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF98EC061573; Sun, 13 Sep 2020 01:43:57 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id fa1so3888749pjb.0; Sun, 13 Sep 2020 01:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NWPCM95Jy2jcUDCt/7JKciRdRd6ZqKhPdOh02zVP2WY=; b=e9ID21zfyOzkuDF3fBH/KTxyhXXlhaDMc4LSK7ayHMycUkioT/QXADEHbhQHiLO0+S r5QfSR9R6qhaMva2dtcOU3d2je6WczL1zSkQ1mJMR/HIA0E77nj7nLUUACaBSnkMWomd PRbWcdsewzcsrGaGwmvrhu3aGvRUgut+dG0uIGgnhPqsVAO09ehPpQl16I575qTcdde5 bV94fL1Ibl04oOCSen93nsCYtXw05R+C9aCWwrfgkuZX5Q0BrTojjpNyAz/P1ueGMjpU 2z9S5c5SCVt7zUUZfGzPS9J5ALNHVOPYmYYq87wW2S1XyMamil5qTcLBYbiIwoL5iDzp WoRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NWPCM95Jy2jcUDCt/7JKciRdRd6ZqKhPdOh02zVP2WY=; b=AFH0B47swaMOUcKVwheDV6g4pnGVe1Gz7iMGM83+8/u2U0swpj5Y7NzNrZu4HrQyNK cjPFZk6KjT7IqzwRNWtztGWf0ozLbYBeyF9CKR19mPXpYa/MjguFsfY8HHRBwB/HLQFN jV02dgihQVX8cTTE3tUhoyIdo5bboz3PGv2jotshoVu1XsrLT7Q/ihIT0XiGXA2BzwYM h2zwzLS2W0w/grT73J9Y6EVG3DKUsvTaQCCGpalf9Ta96OKsbyePVOOOszveWvUfSTIP ORng3ikJXxkTeOF4rzZ7f/oEdnkufpdktgKARv8ime0R6Jdt5J7VPp9j9/YcfuLKWstW OJKw== X-Gm-Message-State: AOAM531wJ+XVDTPkzM6T2L0WKlj8cso2IZYi9Nz4YEGMlsVGYWANyPng jRN/n9CGBxy0BlloNQsbxfVEWfT6+FhXWCLZ3aE= X-Received: by 2002:a17:90a:b387:: with SMTP id e7mr9444554pjr.228.1599986637349; Sun, 13 Sep 2020 01:43:57 -0700 (PDT) MIME-Version: 1.0 References: <20200912005521.26319-1-jiada_wang@mentor.com> In-Reply-To: <20200912005521.26319-1-jiada_wang@mentor.com> From: Andy Shevchenko Date: Sun, 13 Sep 2020 11:43:41 +0300 Message-ID: Subject: Re: [PATCH v4 1/1] Input: atmel_mxt_ts - implement I2C retries To: Jiada Wang Cc: nick@shmanahar.org, Dmitry Torokhov , linux-input , Linux Kernel Mailing List , Dmitry Osipenko , Eugeniu Rosca , Andrew_Gabbasov@mentor.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Sep 12, 2020 at 3:55 AM Jiada Wang wrote: > > From: Nick Dyer > > Some maXTouch chips (eg mXT1386) will not respond on the first I2C request > when they are in a sleep state. It must be retried after a delay for the > chip to wake up. > > Signed-off-by: Nick Dyer > [gdavis: Forward port and fix conflicts.] > Signed-off-by: George G. Davis > [jiada: return exact errno when i2c_transfer & i2c_master_send fails > rename "retry" to "retried" and keep its order in length > set "ret" to correct errno before calling dev_err() > remove reduntant conditional] redundant > Signed-off-by: Jiada Wang > Reviewed-by: Dmitry Osipenko > Tested-by: Dmitry Osipenko ... > + bool retried = false; I thought Dmitry wants that to be retry > u8 buf[2]; > int ret; > - ret = i2c_transfer(client->adapter, xfer, 2); > - if (ret == 2) { > - ret = 0; > - } else { > - if (ret >= 0) > - ret = -EIO; > +retry_read: > + ret = i2c_transfer(client->adapter, xfer, ARRAY_SIZE(xfer)); > + if (ret != ARRAY_SIZE(xfer)) { I'm wondering why you can't leave 2 as is and change it to ARRAY_SIZE in a separate patch? Also why switch from positive to negative conditional? > + if (!retried) { > + dev_dbg(&client->dev, "i2c retry\n"); > + msleep(MXT_WAKEUP_TIME); > + retried = true; > + goto retry_read; > + } > + ret = ret < 0 ? ret : -EIO; > dev_err(&client->dev, "%s: i2c transfer failed (%d)\n", > __func__, ret); > + return ret; > } > > - return ret; > + return 0; > } .. > + bool retried = false; Same comments here, in this function. > +retry_write: > ret = i2c_master_send(client, buf, count); > - if (ret == count) { > - ret = 0; > - } else { > - if (ret >= 0) > - ret = -EIO; > + if (ret != count) { > + if (!retried) { > + dev_dbg(&client->dev, "i2c retry\n"); > + msleep(MXT_WAKEUP_TIME); > + retried = true; > + goto retry_write; > + } > + ret = ret < 0 ? ret : -EIO; > dev_err(&client->dev, "%s: i2c send failed (%d)\n", > __func__, ret); > + } else { > + ret = 0; > } -- With Best Regards, Andy Shevchenko