From patchwork Tue Apr 22 16:45:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 341407 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 5F0DF140121 for ; Wed, 23 Apr 2014 02:47:41 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933347AbaDVQq3 (ORCPT ); Tue, 22 Apr 2014 12:46:29 -0400 Received: from mail-oa0-f74.google.com ([209.85.219.74]:58892 "EHLO mail-oa0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933197AbaDVQqV (ORCPT ); Tue, 22 Apr 2014 12:46:21 -0400 Received: by mail-oa0-f74.google.com with SMTP id i4so840737oah.3 for ; Tue, 22 Apr 2014 09:46:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gqX+qUdqQidWCcuU5wJKgd91pf3wlhreS1EkU6m+/Zg=; b=S6ba0v620cTlHJ4nUawKGUzp4+2UbqCAeXxCtd50EXAYK6aoh/DHx4mG1oTzigh5AQ BG8OG89UCHLVf7NN1vY3w4ArdLMhHycjaL3bUgk9a0FykujLXWhNc09PVLdMhGVknALL HZEiyeERTl+z1D8xJRgEQYp02UWsaMaUOQtKZR4PPLk6oyTO4Bycj3xSTHoO67vheqIm eOgmIp5h9AKUuKhqR6ruAtfalwL66xA9/c5bG40PH4n/QisTqqHhnb1an9glTYnq1bjm ynd7MPakGAvSAtiP5Mf8jqUmypGuNu4p6gXjyYkxvhXDziLbrjCTF/Qa/1IRyju6A5dP yMkw== X-Gm-Message-State: ALoCoQnyR7T+cK/YK3Iz4ej3VZuwhX69cMAopTgBi0pTNkVYyot9X59YVbHSI5JwRt67ItRhRgBkiZpBiGS+ocyeS/Ebr6ivBWc57W8Tpx/clYLxmhz7ngN6StJDR4A0Ibqcsykf5nS/kuQ7Oq5r77vVRuyPCAha4M2x28dymuoKb4Ps/hzNDD6iTg92deE1si5aKGcPoUMg/GxvoRTpQClrihy2s0GS2w== X-Received: by 10.42.185.1 with SMTP id cm1mr19609257icb.10.1398185180859; Tue, 22 Apr 2014 09:46:20 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id r61si5667230yhf.1.2014.04.22.09.46.20 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Apr 2014 09:46:20 -0700 (PDT) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.72.141]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id AA1BE5A431B; Tue, 22 Apr 2014 09:46:20 -0700 (PDT) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id 5E4DA80FF3; Tue, 22 Apr 2014 09:46:20 -0700 (PDT) From: Doug Anderson To: lee.jones@linaro.org, swarren@nvidia.com, wsa@the-dreams.de Cc: abrestic@chromium.org, dgreid@chromium.org, olof@lixom.net, sjg@chromium.org, linux-samsung-soc@vger.kernel.org, linux-tegra@vger.kernel.org, Doug Anderson , sameo@linux.intel.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/7] mfd: cros_ec: spi: Make the cros_ec_spi timeout more reliable Date: Tue, 22 Apr 2014 09:45:50 -0700 Message-Id: <1398185154-19404-4-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.9.1.423.g4596e3a In-Reply-To: <1398185154-19404-1-git-send-email-dianders@chromium.org> References: <1398185154-19404-1-git-send-email-dianders@chromium.org> Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org The cros_ec_spi transfer had two problems with its timeout code: 1. It looked at the timeout even in the case that it found valid data. 2. If the cros_ec_spi code got switched out for a while, it's possible it could get a timeout after a single loop. Let's be paranoid and make sure we do one last transfer after the timeout expires. Signed-off-by: Doug Anderson Reviewed-by: Simon Glass Tested-by: Andrew Bresticker Tested-by: Stephen Warren --- Changes in v2: None drivers/mfd/cros_ec_spi.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c index a2a605d..4f863c3 100644 --- a/drivers/mfd/cros_ec_spi.c +++ b/drivers/mfd/cros_ec_spi.c @@ -113,7 +113,9 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, /* Receive data until we see the header byte */ deadline = jiffies + msecs_to_jiffies(EC_MSG_DEADLINE_MS); - do { + while (true) { + unsigned long start_jiffies = jiffies; + memset(&trans, 0, sizeof(trans)); trans.cs_change = 1; trans.rx_buf = ptr = ec_dev->din; @@ -134,12 +136,19 @@ static int cros_ec_spi_receive_response(struct cros_ec_device *ec_dev, break; } } + if (ptr != end) + break; - if (time_after(jiffies, deadline)) { + /* + * Use the time at the start of the loop as a timeout. This + * gives us one last shot at getting the transfer and is useful + * in case we got context switched out for a while. + */ + if (time_after(start_jiffies, deadline)) { dev_warn(ec_dev->dev, "EC failed to respond in time\n"); return -ETIMEDOUT; } - } while (ptr == end); + } /* * ptr now points to the header byte. Copy any valid data to the