Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp443436iog; Mon, 13 Jun 2022 06:06:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxNswMJcORpUZEOM5hMqmFq2v44HKTYwlSyBwKC45R/W1oKOTT3Pc34srHNJ+dfJm1bcVZb X-Received: by 2002:a17:906:891:b0:70b:c30e:c1f1 with SMTP id n17-20020a170906089100b0070bc30ec1f1mr49273811eje.733.1655125603630; Mon, 13 Jun 2022 06:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125603; cv=none; d=google.com; s=arc-20160816; b=UlUx9XMfaMWLNmnXN2buazaTyn/oXpxVtcG8eeNR6wBPBhjTFeHw7z6ghROaaagiAd cmuV6Z3J7GfJHHRaLc8BTBWU6e+To8S8/c6QW7Afe1iI+w4hHFtYzt3Ilav7gFBC52ji tTZTaKM3PIJOy3EBwlpfmRALodo35jvUqtC7ap37gqbjJss2BOOizB/qwlN0Q3H+YvOx NUwPZCVQmXq85oUycE8qEiQDHh5zPmQl0PhBaN0hd8SyjG4qX8oIzHGlTUkGfvOHqeoz 9MOm1G13h76+2O3U0OEsD65C+JHYz1Rm/N8oF6QejPGhvzQ9kwuedWHj9OJYKJLGkl1T BBDg== 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=FqWofxAvZo75r1e0DCK0T9Q+UtrXnbvyYHaf4CZQzqI=; b=mPRqKNWCLXvY49T/vuh/JG8PQk6BTrw/CVOiJFJYFyOeObnZXIoOkZt2ld3WU2wJBN LJbWRfcO+hoVh37hPpfQUho8klEjYrokWL8tTP0z2C51kmGZk1QQzlwW01AGRhsfj2Kz /XT7Xuc1t/G7VgEBdSK35aCGEutsSD2DTMlntUdUq8HF+hGYmymMkPCCb/NnF++xhyuT tpVI31iZClJNooXS3TOfqbF8FMtti0vn8GvCRpJcz4/Q7VPg0clCfpNmndLUi1Ukcl0n kmyYQuvXbJOZZx3+yREvLVJsp0TidZPZBn2+b+lvspSrSnr8bCfvsOLWGcgSe1Gi+TZw rQ6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XoDnEN2m; 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 w5-20020a1709061f0500b00711fe0e94d3si6972661ejj.524.2022.06.13.06.06.09; Mon, 13 Jun 2022 06:06:43 -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=XoDnEN2m; 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 S1355952AbiFMLnK (ORCPT + 99 others); Mon, 13 Jun 2022 07:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354988AbiFMLh4 (ORCPT ); Mon, 13 Jun 2022 07:37:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2AB24507F; Mon, 13 Jun 2022 03:48:21 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 8859460AEB; Mon, 13 Jun 2022 10:48:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 988DCC34114; Mon, 13 Jun 2022 10:48:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117301; bh=6CXYLaPR3cZEPhBGn7qYmfqLElRp0KzwtIAkLwt4JR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XoDnEN2mEbJ0IdLEdRmRn2TynUmPfBabAWtVlbeGPIs11zS5ax3ljEQ+SYfDh1A+r iLpg5VzfK1/OzaS5lvnpWjRDkeB/+hY1XPLVBxnZR6tPDMDgFV9zl8X+qKpukHZmfV WD4EBX1ovse7toSJghF73m5A7+LmW6b/po9yfVOY= 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.4 341/411] i2c: cadence: Increase timeout per message if necessary Date: Mon, 13 Jun 2022 12:10:14 +0200 Message-Id: <20220613094938.937589519@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094928.482772422@linuxfoundation.org> References: <20220613094928.482772422@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 17f0dd1f891e..8a3a0991bc1c 100644 --- a/drivers/i2c/busses/i2c-cadence.c +++ b/drivers/i2c/busses/i2c-cadence.c @@ -506,7 +506,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; @@ -531,8 +531,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