Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp581303iog; Mon, 13 Jun 2022 08:32:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vc3iyHGgg8+OJEOUxOue2XjeJ2WDwC5yzsGi6wB3uWRP+WnDinqalKWv0v41F61vtJlnIG X-Received: by 2002:a05:6402:3551:b0:431:51e1:856f with SMTP id f17-20020a056402355100b0043151e1856fmr283694edd.323.1655134347054; Mon, 13 Jun 2022 08:32:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655134347; cv=none; d=google.com; s=arc-20160816; b=GjiBZ80qPoRGJukqt6vaEq5nurkDEUGYbky/ZxNPdmoiGOn+vd4evvixLQaBiTn1Un 0pokzy+NCE4jaBp8xRE2MdgG78TxrAfv8zUIpnfwMxdCtECt5jAmU2OMrNVwkVefQ9pU zRSC4Lpj1lfB0aBvrbUpJsWcjJUiu/PRA0XeGje5+iQ+uZ5wsOUkLIWs0lcqBc3NwXXf Nd4LLlrZGhsM8Z7kHzBJFyXz85I1QVffgiXMht5KmqcekWJsBncOi6UAOqoHPdK5IGbH HLV77NFT/QFb7G7yK5G6utYkDwPDKLIOEDTLKnzYjnskCS6tbc5jNFwJ6fohYhKjAjql oILQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=2uowiT1buvbBCXKHgKe9A1LiXhfO89RhjtNlAfD/4tQ=; b=onwy+SrI8S1exHsNdt+gb1tn2CTDWEXC3TthBqgmad5KpVJoMZ9N8SF38ZbEh6O9BP qF8Qtw0NhUbtQ5GEZIyCD8oApBt1BpcXiItrw6izMxkPB0tIEsYqeRWnqkjFsLSvN1Zo hdyftkIiVpSQW/2RilcDLxd3pUnh3AdaQoXWasGOqQg1f9ksQuPLdKw7Z7ojQJisPReL fHeTlqo6KmvxlkLCCTZHY2ZFTEbVQCNyvbcOxm2IxFlafcGmIQ+IpvIhM/xrqKltngK0 wgz9hzcLvbWS9WvRwpdBJmsfGSlnmfqTYUJd5Ck7CDlbaIPrfgCFNTTM+2I1nWfFwhDs crtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="D/atiChO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b18-20020a056402279200b00430262e2b6dsi8673391ede.206.2022.06.13.08.32.02; Mon, 13 Jun 2022 08:32:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="D/atiChO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359327AbiFMNJt (ORCPT + 99 others); Mon, 13 Jun 2022 09:09:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50306 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354659AbiFMM5m (ORCPT ); Mon, 13 Jun 2022 08:57:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D7D7246; Mon, 13 Jun 2022 04:17:22 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1AE55B80D31; Mon, 13 Jun 2022 11:17:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EFAFC3411C; Mon, 13 Jun 2022 11:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655119039; bh=gJVpB7T37wyoUJOyInE1sOTyR+6HawgA6LXykwcBDEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D/atiChOpou+jRD7Caa0+urb4BbP0lq4/0TSoGaU4zvGQ0arFtrr5PM50KPX3nGEb bxqE2RiisYeXCNcQ1y+hNbHMrUCHm0ZlqPjI21Qzcrg9aONhm//rUsOvZoTJQ7HAnU Nu1umWGfFV8GC6fy894ViTToI0IzJTtRIWkNzdsQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lucas Tanure , Michal Simek , Wolfram Sang , Sasha Levin Subject: [PATCH 5.15 119/247] i2c: cadence: Increase timeout per message if necessary Date: Mon, 13 Jun 2022 12:10:21 +0200 Message-Id: <20220613094926.573484420@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094922.843438024@linuxfoundation.org> References: <20220613094922.843438024@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lucas Tanure [ Upstream commit 96789dce043f5bff8b7d62aa28d52a7c59403a84 ] Timeout as 1 second sets an upper limit on the length of the transfer executed, but there is no maximum length of a write or read message set in i2c_adapter_quirks for this controller. This upper limit affects devices that require sending large firmware blobs over I2C. To remove that limitation, calculate the minimal time necessary, plus some wiggle room, for every message and use it instead of the default one second, if more than one second. Signed-off-by: Lucas Tanure Acked-by: Michal Simek Signed-off-by: Wolfram Sang Signed-off-by: Sasha Levin --- drivers/i2c/busses/i2c-cadence.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c index 805c77143a0f..b4c1ad19cdae 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -760,7 +760,7 @@ static void cdns_i2c_master_reset(struct i2c_adapter *adap) static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, struct i2c_adapter *adap) { - unsigned long time_left; + unsigned long time_left, msg_timeout; u32 reg; id->p_msg = msg; @@ -785,8 +785,16 @@ static int cdns_i2c_process_msg(struct cdns_i2c *id, struct i2c_msg *msg, else cdns_i2c_msend(id); + /* Minimal time to execute this message */ + msg_timeout = msecs_to_jiffies((1000 * msg->len * BITS_PER_BYTE) / id->i2c_clk); + /* Plus some wiggle room */ + msg_timeout += msecs_to_jiffies(500); + + if (msg_timeout < adap->timeout) + msg_timeout = adap->timeout; + /* Wait for the signal of completion */ - time_left = wait_for_completion_timeout(&id->xfer_done, adap->timeout); + time_left = wait_for_completion_timeout(&id->xfer_done, msg_timeout); if (time_left == 0) { cdns_i2c_master_reset(adap); dev_err(id->adap.dev.parent, -- 2.35.1