From patchwork Wed Apr 30 17:44:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 4095391 Return-Path: X-Original-To: patchwork-linux-samsung-soc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 61FFB9F169 for ; Wed, 30 Apr 2014 17:46:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8ED2E202EA for ; Wed, 30 Apr 2014 17:46:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B6FBE201D5 for ; Wed, 30 Apr 2014 17:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759308AbaD3Roh (ORCPT ); Wed, 30 Apr 2014 13:44:37 -0400 Received: from mail-qc0-f202.google.com ([209.85.216.202]:51776 "EHLO mail-qc0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759256AbaD3Rof (ORCPT ); Wed, 30 Apr 2014 13:44:35 -0400 Received: by mail-qc0-f202.google.com with SMTP id x13so298248qcv.5 for ; Wed, 30 Apr 2014 10:44:34 -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=wD87vaKrAOrbxVrrLMjgbS7cyFX0X2teQFclFXp0K5k=; b=Fhe4HkebhsZ1/3I2Lznu0MokE0Ek3sUC5sPiEfeipz4PxOvx+hYUWqsvyeuwpNEmlh 2yvZMoTR8YBrpjOpiilaLtSCI7TtkfP22PPUdvrnEX33/HOTknu85oJrGwuJn6MDdcOd c2KH/5SR0ojZRZE2n6Ube1vw2f+jUaUHGdeD8/ZRi7cz49o12QIBqOdIMUN0FskLNlAZ oIxhvsaEwEzpvtfQDaiUQkhL65YWLSo4U8/S6XDvtLjELa6bgBeJbUlkW4WRpEwAS3qi SJBUKBBdMvw4uofVPCidKM4n0EYOsvhFIDi473b5fUzPq+P/bo7KycUv0U+UY0V76m9t hs6w== X-Gm-Message-State: ALoCoQn4xape5rm+uTOx5hRr7o+svJuIG3RAtdLYVQ/dFQAUgIvuOSmPPOXFkijkr876jQ1dLtH+QXZKkeyrt3mGXs26sfzX1Ljoh5P4hIfE29Pj9lt5HMj1QCLIDInr3x+dfyvezDdlnFxPzBq4PRlu2v4TjLQcj89/Rg1la9IKo8zhB8G/xTKBYnCD7z+8LjNBcXR/P/ue+KOku9fkLiEcyBuoYO9QEQ== X-Received: by 10.224.29.129 with SMTP id q1mr3089984qac.3.1398879874752; Wed, 30 Apr 2014 10:44:34 -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 y50si3078864yhk.4.2014.04.30.10.44.34 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Apr 2014 10:44:34 -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 9216B5A418D; Wed, 30 Apr 2014 10:44:34 -0700 (PDT) Received: by tictac.mtv.corp.google.com (Postfix, from userid 121310) id 46C9E80FC7; Wed, 30 Apr 2014 10:44:34 -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 v3 3/7] mfd: cros_ec: spi: Make the cros_ec_spi timeout more reliable Date: Wed, 30 Apr 2014 10:44:06 -0700 Message-Id: <1398879850-9111-4-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 1.9.1.423.g4596e3a In-Reply-To: <1398879850-9111-1-git-send-email-dianders@chromium.org> References: <1398879850-9111-1-git-send-email-dianders@chromium.org> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 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 Acked-by: Lee Jones Reviewed-by: Simon Glass Tested-by: Andrew Bresticker Tested-by: Stephen Warren --- Changes in v3: None 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