From patchwork Sat Aug 29 20:38:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 254879 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=-12.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 EAB83C28E83 for ; Sat, 29 Aug 2020 20:38:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFBE020CC7 for ; Sat, 29 Aug 2020 20:38:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sang-engineering.com header.i=@sang-engineering.com header.b="gD9BnwzA" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728417AbgH2UiX (ORCPT ); Sat, 29 Aug 2020 16:38:23 -0400 Received: from www.zeus03.de ([194.117.254.33]:58354 "EHLO mail.zeus03.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728491AbgH2UiW (ORCPT ); Sat, 29 Aug 2020 16:38:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=sang-engineering.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=k1; bh=f5gjPSE4jbm4N/ jLLF41Zghd+zThCN6fEw+rdAJVkOs=; b=gD9BnwzAU+jcynIvj9Xsmo2SGDMMg+ SfOF7lJPfdTmiZUz3gJ/JuMJisFiO6Gzeb2jQOyi01Dd82JQWQn503Ar/DxvQku4 ElMk2PwnUKGWo3dWr5ziSU5ZuK1Xa1AmaN1nWclJrXlCkPSYLc0dpBbA6jk2ctcM Bctmx1xIfrl1Q= Received: (qmail 1629979 invoked from network); 29 Aug 2020 22:38:20 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 29 Aug 2020 22:38:20 +0200 X-UD-Smtp-Session: l3s3148p1@6bRgJgqu/tAgAwDPXyCvAAFyN1rCWI+G From: Wolfram Sang To: linux-i2c@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Wolfram Sang Subject: [PATCH 2/2] i2c: rcar: refactor and shorten timeout when resetting Date: Sat, 29 Aug 2020 22:38:10 +0200 Message-Id: <20200829203810.1467-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200829203810.1467-1-wsa+renesas@sang-engineering.com> References: <20200829203810.1467-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org LOOP_TIMEOUT was only used back then because we didn't want to introduce another constant. The timeout value can easily be a magnitude shorter because the typical range is 3us - 8us. Refactor the code to use the poll_timeout helper, use a specific timeout value and get rid of the ugly LOOP_TIMEOUT constant. Signed-off-by: Wolfram Sang --- drivers/i2c/busses/i2c-rcar.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index ef10514f6215..217def2d7cb4 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -150,9 +150,6 @@ struct rcar_i2c_priv { #define rcar_i2c_priv_to_dev(p) ((p)->adap.dev.parent) #define rcar_i2c_is_recv(p) ((p)->msg->flags & I2C_M_RD) -#define LOOP_TIMEOUT 1024 - - static void rcar_i2c_write(struct rcar_i2c_priv *priv, int reg, u32 val) { writel(val, priv->io + reg); @@ -765,20 +762,14 @@ static void rcar_i2c_release_dma(struct rcar_i2c_priv *priv) /* I2C is a special case, we need to poll the status of a reset */ static int rcar_i2c_do_reset(struct rcar_i2c_priv *priv) { - int i, ret; + int ret; ret = reset_control_reset(priv->rstc); if (ret) return ret; - for (i = 0; i < LOOP_TIMEOUT; i++) { - ret = reset_control_status(priv->rstc); - if (ret == 0) - return 0; - udelay(1); - } - - return -ETIMEDOUT; + return read_poll_timeout_atomic(reset_control_status, ret, ret == 0, 1, + 100, false, priv->rstc); } static int rcar_i2c_master_xfer(struct i2c_adapter *adap,