Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3021047pxp; Tue, 22 Mar 2022 10:24:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOJAGsVrzpcXu1RMHbx0n7I9TwBJmXlStO1QA/oIe6i577Q7z6qr/4rsDSO+Wgs3VISlfH X-Received: by 2002:a17:907:8a0d:b0:6d6:dae9:7263 with SMTP id sc13-20020a1709078a0d00b006d6dae97263mr26616855ejc.671.1647969850433; Tue, 22 Mar 2022 10:24:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647969850; cv=none; d=google.com; s=arc-20160816; b=cbnY0huUTX/FcsiSn8D9fbooKXlPTKRNwLaXuAB5KFXhZYZVzD0XanTwUjYP750PPw 0I/w9URgPXHD9Mm7xXAMdgaiHvt/jb9/r4UeDjj2EK6inS4fCBY1c10mCxPQ0Z4DOdHV yyzC9pLs758LLlCYfKf0EPoasFX8/C6shWfwRvXFooAerRHWvTgE+mRYT4GERH49abJs h0LcqlGCq8MmVXIqHQ3F5mqwqpV4FfZrSBY6rwSJz51GxsFT7PYoWDLCBl+Ncdq2SjQ6 aYZIXDoK3p5YFaU0UO+Cuilnq8+OQOAQqcPozhkn9nHgofcBeVPvmWXDqdeyPMaQA/MG jWaA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=wvFFWe6KXU0sAEdB3wRb1n1+e3ss17FGilikjP3h2kU=; b=losxw9Hl8BXBq2qP7aUsxXhvij9MHTC9Fs81giSZTlenSuN6nOuSmaoc3FnrcGVMM6 IaSN+2GRSJUoFpwQihYTt5Cs+evIKzDNKEUsWN7rtLJ0xGXTqaGtzOOlKbWhqothV6Cl C6vb/68em9A9/qGecNeK2neY2NynOQGo0xYpZKPz9u2N8rY7Ee+muNPrLBUZ4M2duCHw vINpRzFT2JW5GmsJea1MdyExFl+PtzghAYltkkZGKGL0akEqNtAhLq6V8B8qTPB/+WxD 9+RVTtRK0jRocPfzXhgtRPukhQui2IS/RuIl+lYOopUf0uxt5SJQa6SjvZRKcuraEPz9 ESsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=Jn+Ar+Qs; 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=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x40-20020a50baab000000b00418dacea57fsi11888933ede.467.2022.03.22.10.23.44; Tue, 22 Mar 2022 10:24:10 -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=@cirrus.com header.s=PODMain02222019 header.b=Jn+Ar+Qs; 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=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238742AbiCVPwK (ORCPT + 99 others); Tue, 22 Mar 2022 11:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238737AbiCVPwH (ORCPT ); Tue, 22 Mar 2022 11:52:07 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D2066AF9; Tue, 22 Mar 2022 08:50:40 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 22M6UdfS028345; Tue, 22 Mar 2022 10:50:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=wvFFWe6KXU0sAEdB3wRb1n1+e3ss17FGilikjP3h2kU=; b=Jn+Ar+QsB7sa7PTbu0hhsY8fpLFkFuI237ACqpp+e/0bvcri41gRixZG3obcfcm97fnM gtWsm9eOkoMLLh/BnHAQm4J7L6iHlvhSCJt6Tqw4S8cIVK0VptATwyfqv/UxITCj1+oa zKMNEjO+1LmnR/V6JykKH5YfSHgqh2C0trig1nbhVXfHHLjcyCqK64T/4c80gM2ENh2u O75QoBQCDPL4ilSbW3y4f8m6h6b9a+w59rbs9sSZu82BT0SwWxBTGV6BOYlNkr5pKVxv EGOtVHTIEWAuMG0xU3Qtx/Sc7JcslDMGbhUKdIoMK+r0UXRbdBbPzcoRGamJu6deASrw rA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3ewbknc23q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Tue, 22 Mar 2022 10:50:35 -0500 Received: from EDIEX01.ad.cirrus.com (198.61.84.80) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Tue, 22 Mar 2022 15:50:33 +0000 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by EDIEX01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.1.2375.18 via Frontend Transport; Tue, 22 Mar 2022 15:50:33 +0000 Received: from aryzen.ad.cirrus.com (unknown [198.61.65.125]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 3DDE2459; Tue, 22 Mar 2022 15:50:33 +0000 (UTC) From: Lucas Tanure To: Michal Simek , Shubhrajyoti Datta CC: , , , , Lucas Tanure Subject: [PATCH v2] i2c: cadence: Increase timeout per message if necessary Date: Tue, 22 Mar 2022 15:50:31 +0000 Message-ID: <20220322155031.7942-1-tanureal@opensource.cirrus.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: Qm9LyfE38WjTG-FXU3vt5EROaXYXEjm_ X-Proofpoint-GUID: Qm9LyfE38WjTG-FXU3vt5EROaXYXEjm_ X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,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 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 --- 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