From patchwork Mon Mar 12 13:14:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Sahu X-Patchwork-Id: 884494 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=codeaurora.org header.i=@codeaurora.org header.b="PdzquOKs"; dkim=pass (1024-bit key) header.d=codeaurora.org header.i=@codeaurora.org header.b="k3czAZjm"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 400JRb6HVBz9sMQ for ; Tue, 13 Mar 2018 00:16:59 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932365AbeCLNP6 (ORCPT ); Mon, 12 Mar 2018 09:15:58 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:42184 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932333AbeCLNPx (ORCPT ); Mon, 12 Mar 2018 09:15:53 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 5C5BB60590; Mon, 12 Mar 2018 13:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520860553; bh=Jtcaff9UeqTOHsqqROrxeYLAPCHW5dbMo9cP/uvNdII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PdzquOKslr0Av29XLzjNE7f+uUw6Id8fzCI+JW5oyB0nJKCPTSrfrBXXb6FD2UbTt GAdXyNqQPKPIoCWOwXcq58rXYdj17k8Bk0GkSZuxX+6ZPMNayEqNXwDKBhrUIAgn1N zyKon7OJwIDISZ4CQpwQUPHnMdCK0xamXRWjqGv0= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED, T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from absahu-linux.qualcomm.com (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: absahu@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id EDC3F60817; Mon, 12 Mar 2018 13:15:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520860552; bh=Jtcaff9UeqTOHsqqROrxeYLAPCHW5dbMo9cP/uvNdII=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k3czAZjmBsVFfrDrxOWqxCI+2OFb99+J2OuMW7ECbXKBG2ySLWX82ZBBvG4UdWmql MpdMGimCsfh4++D6HN/ULaw2YgOBNPZwVzkfPiba6BcNZfHbZVaC+xFQrTtlKDidVW cODafalXSyve0ZHBtTSbwrhI/WdFxTU9hTmY9UgI= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org EDC3F60817 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=absahu@codeaurora.org From: Abhishek Sahu To: Andy Gross , Wolfram Sang Cc: David Brown , Sricharan R , Austin Christ , linux-arm-msm@vger.kernel.org, linux-soc@vger.kernel.org, linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Abhishek Sahu Subject: [PATCH v2 09/13] i2c: qup: change completion timeout according to transfer length Date: Mon, 12 Mar 2018 18:44:58 +0530 Message-Id: <1520860502-14886-10-git-send-email-absahu@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1520860502-14886-1-git-send-email-absahu@codeaurora.org> References: <1520860502-14886-1-git-send-email-absahu@codeaurora.org> Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Currently the completion timeout is being taken according to maximum transfer length which is too high if SCL is operating in high frequency. This patch calculates timeout on the basis of one-byte transfer time and uses the same for completion timeout. Signed-off-by: Abhishek Sahu Reviewed-by: Andy Gross --- * Changes from v1: 1. Added comments to explain TOUT_MIN drivers/i2c/busses/i2c-qup.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/busses/i2c-qup.c b/drivers/i2c/busses/i2c-qup.c index bf1b7ee..13c751e 100644 --- a/drivers/i2c/busses/i2c-qup.c +++ b/drivers/i2c/busses/i2c-qup.c @@ -121,8 +121,12 @@ #define MX_TX_RX_LEN SZ_64K #define MX_BLOCKS (MX_TX_RX_LEN / QUP_READ_LIMIT) -/* Max timeout in ms for 32k bytes */ -#define TOUT_MAX 300 +/* + * Minimum transfer timeout for i2c transfers in seconds. It will be added on + * the top of maximum transfer time calculated from i2c bus speed to compensate + * the overheads. + */ +#define TOUT_MIN 2 /* Default values. Use these if FW query fails */ #define DEFAULT_CLK_FREQ 100000 @@ -163,6 +167,7 @@ struct qup_i2c_dev { int in_blk_sz; unsigned long one_byte_t; + unsigned long xfer_timeout; struct qup_i2c_block blk; struct i2c_msg *msg; @@ -849,7 +854,7 @@ static int qup_i2c_bam_do_xfer(struct qup_i2c_dev *qup, struct i2c_msg *msg, dma_async_issue_pending(qup->brx.dma); } - if (!wait_for_completion_timeout(&qup->xfer, TOUT_MAX * HZ)) { + if (!wait_for_completion_timeout(&qup->xfer, qup->xfer_timeout)) { dev_err(qup->dev, "normal trans timed out\n"); ret = -ETIMEDOUT; } @@ -1605,6 +1610,8 @@ static int qup_i2c_probe(struct platform_device *pdev) */ one_bit_t = (USEC_PER_SEC / clk_freq) + 1; qup->one_byte_t = one_bit_t * 9; + qup->xfer_timeout = TOUT_MIN * HZ + + usecs_to_jiffies(MX_TX_RX_LEN * qup->one_byte_t); dev_dbg(qup->dev, "IN:block:%d, fifo:%d, OUT:block:%d, fifo:%d\n", qup->in_blk_sz, qup->in_fifo_sz,