From patchwork Tue Sep 15 14:11:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 309657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40915C433E2 for ; Tue, 15 Sep 2020 23:37:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07E6F21D91 for ; Tue, 15 Sep 2020 23:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600213022; bh=8qEbwZBxtEgDfYP9qnMdSRs8/OFIdeZZilH0RYpyRJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=VIkn1aID4p8gpAz8KoZVfNqL2ckkHur+h2Ntgyi77hIbQD8yu3qI+sQ0Gqjfi00Ol rHSawE3c5WC7GUudaan90Bcq6ViVJZKJj1kX738kORvemaIFinS5oGZw8hOi2Pd2RS KdDrTfSH6MhbxQtf9NFqwPNzz2efQRazhYaPxiws= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727171AbgIOXhB (ORCPT ); Tue, 15 Sep 2020 19:37:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:47680 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727137AbgIOOfY (ORCPT ); Tue, 15 Sep 2020 10:35:24 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F40E42222C; Tue, 15 Sep 2020 14:25:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600179946; bh=8qEbwZBxtEgDfYP9qnMdSRs8/OFIdeZZilH0RYpyRJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k512jr85D8/tLFWnu/Y55IoG0LZQbl66AK7+36B1MPl3VxPq3X3u7XR6igDGTamLG 98rAonQrMbwT6Lpx+OLloGIWfW5JRkzaw55BV0VBQHclg51uVfFfe66iSJkmqPhkAN w6HwLowWUovn8r4dgi5zO/UQHoMPPZKZVU9gMew0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tali Perry , Avi Fishman , Joel Stanley , Alex Qiu , Wolfram Sang , Sasha Levin Subject: [PATCH 5.8 047/177] i2c: npcm7xx: Fix timeout calculation Date: Tue, 15 Sep 2020 16:11:58 +0200 Message-Id: <20200915140655.878792942@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200915140653.610388773@linuxfoundation.org> References: <20200915140653.610388773@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Tali Perry [ Upstream commit 06be67266a0c9a6a1ffb330a4ab50c2f21612e2b ] timeout_usec value calculation was wrong, the calculated value was in msec instead of usec. Fixes: 56a1485b102e ("i2c: npcm7xx: Add Nuvoton NPCM I2C controller driver") Signed-off-by: Tali Perry Reviewed-by: Avi Fishman Reviewed-by: Joel Stanley Reviewed-by: Alex Qiu Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- 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 75f07138a6fa2..dfcf04e1967f1 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);