Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp567498pxk; Sun, 30 Aug 2020 14:34:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyopaaFxdt3QGHn+m2EEUUmPooKKBD5+eZQTMfS+mIFntV7mD9QYPFKFRMQMZUHG2DIJvMj X-Received: by 2002:a17:906:a053:: with SMTP id bg19mr9503072ejb.444.1598823244473; Sun, 30 Aug 2020 14:34:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598823244; cv=none; d=google.com; s=arc-20160816; b=Gl2HqGZQoZ6vxu8ZoTWGdZdmjk/Qyj+tzinsgBo5grJoLi8w0KeLGZm/x/ugSrDdRo XFcQq+yDNS1Ln9SdvxFxe7zcvt6ZznTMVSk3UPCnHjNakVbUStlHPaSgInjfkTBzkxZg KXG2C9BcSAyJhC61JMiOqrdTGDCaQStu8mB9RUS3qBa+ruO0O/Po0bNMOQjcoxnmPQkj wFnYb7TlNR7oW0IcdYC1ntoDKGBPJRjjFh3BFdBBH90jFlwIRBL+UfMo6bwfg2rJRZPr l8vVRuC6a+sR+uF5XND9pWrE5jIILUD/LJhTlGl7oUWcqg3vjmdoQ0ixWFjhO9iv5a7z bXdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Na851ZUtnc84m/rwos2zZqbYxygcEp9IBY49moX9nyw=; b=Lubrg55p+ttPTMXnJ7cdQHP06en6VuqPA1nNBG9gNCQykZW6mnWMIUMzOstKSOmp6Z ZF4af+uaItJC5aYmRb34qXj2j9H6H2ZBns8S0Iv+ZXVLdDKBrT/cYPF+7iQyuCD21D+e uy0TuTnBqiAISqkHKWpoq74Y/HY2bMFXJdWaDr9PoCse0QduoI+IAwL4p4GKWjIA0eJd Jf9ouorp0dy+JqKCBsPGFq8XxZBDEAO4aeX9uAfPiRTN+GeKRsHJ3c+QUW13zFnujcSH lpRtzxeb40/fuRLeSt8CE1BR2Y6KZ1uZd5l7tFc3sYFVca2+5QXqX+g7TD1w1eEUBUGe 3VPw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 bj23si4281410ejb.94.2020.08.30.14.33.41; Sun, 30 Aug 2020 14:34:04 -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; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726350AbgH3VcL (ORCPT + 99 others); Sun, 30 Aug 2020 17:32:11 -0400 Received: from 212.199.177.27.static.012.net.il ([212.199.177.27]:53800 "EHLO herzl.nuvoton.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726178AbgH3VcJ (ORCPT ); Sun, 30 Aug 2020 17:32:09 -0400 Received: from taln60.nuvoton.co.il (ntil-fw [212.199.177.25]) by herzl.nuvoton.co.il (8.13.8/8.13.8) with ESMTP id 07ULVNUJ011608; Mon, 31 Aug 2020 00:31:23 +0300 Received: by taln60.nuvoton.co.il (Postfix, from userid 20088) id BA033639D3; Mon, 31 Aug 2020 00:31:23 +0300 (IDT) From: Tali Perry To: kunyi@google.com, xqiu@google.com, benjaminfair@google.com, avifishman70@gmail.com, joel@jms.id.au, tmaimon77@gmail.com, wsa@the-dreams.de Cc: linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, linux-kernel@vger.kernel.org, Tali Perry Subject: [PATCH v3] i2c: npcm7xx: Fix timeout calculation Date: Mon, 31 Aug 2020 00:31:21 +0300 Message-Id: <20200830213121.239533-1-tali.perry1@gmail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org timeout_usec value calculation was wrong, the calculated value was in msec instead of usec. Signed-off-by: Tali Perry Reviewed-by: Avi Fishman --- drivers/i2c/busses/i2c-npcm7xx.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 75f07138a6fa..dfcf04e1967f 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2093,8 +2093,12 @@ static int npcm_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, } } - /* Adaptive TimeOut: astimated time in usec + 100% margin */ - timeout_usec = (2 * 10000 / bus->bus_freq) * (2 + nread + nwrite); + /* + * Adaptive TimeOut: estimated time in usec + 100% margin: + * 2: double the timeout for clock stretching case + * 9: bits per transaction (including the ack/nack) + */ + timeout_usec = (2 * 9 * USEC_PER_SEC / bus->bus_freq) * (2 + nread + nwrite); timeout = max(msecs_to_jiffies(35), usecs_to_jiffies(timeout_usec)); if (nwrite >= 32 * 1024 || nread >= 32 * 1024) { dev_err(bus->dev, "i2c%d buffer too big\n", bus->num); base-commit: d012a7190fc1fd72ed48911e77ca97ba4521bccd -- 2.22.0