Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp388677pxj; Thu, 3 Jun 2021 09:06:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK4WQxke7TU9I+Oo+wV6pRG9bCG0vLOmrmMzMqYovYt5HBpay44uHCrLMXdeCtcL0NZxIa X-Received: by 2002:a17:906:714d:: with SMTP id z13mr141831ejj.48.1622736378194; Thu, 03 Jun 2021 09:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622736378; cv=none; d=google.com; s=arc-20160816; b=hfCDFB4pc3oHyAS9atPMS7eqC0xKv7aeWlNHlIyTPJf7mhMDIeOlmewcTcO/FdeWhz pMHAoi8rT02OM0dYj1YZ96wqd6EJyI8bMmE4tg9J9FV8z/ARWt9c3Pta7EzO2Ma/EEzM ntTnHdbo+K0+bGyM3DGLDJj9NtyzHZazpY3B30copn8a77RKuYsGRhDqtnsVDQx21Tx4 R5vGLprrsqGI64kZ+aA/k/be6fcyjA1pJQzLwTFXjO1BtRvreI71nhnXfh4uVwZ0sFZg R5pmGaLTNRKA6YCvgyEk8vTSeqotoKvlsqEaPL0RAAu/bbQxSjKL+0K+SpH/oKic+BTp 9Vkg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=yTDnD8Gph4aV2KBxrzXIGztevxlERl+Zh0OVsC6XcA8=; b=w41hg/IJke+2SvBEyeNrQwcpivF+brccoP2O9FM3fde+hBlE6sjuqzi0B9BIKuGqpy SCYOawd3Dr3B39i0MeKirZDmPVbQNW2XDAjUUEurZ75g32wJeAALkATXoc6H8wXp3y46 uv3eKJZJj/t1lGDo8lGBDy8BBqe06RJz+NsZQFTwKCe6k3DN/A1bX90vjpqjhVO/TxdQ o+1wzKfRTuVWWaYNFnYhlI32iG1nZcG4MIIm+Va7zVRlNHD1QqRORVtNp2m3HHUKV9// RRt99XK17jS4PbmRhuYV403O34cY+3bMM35CBEIiBUj9TUZzvxkHzzUmlPU4pQse61Go bs9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x18si2449172eji.715.2021.06.03.09.05.50; Thu, 03 Jun 2021 09:06:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbhFCQGE (ORCPT + 99 others); Thu, 3 Jun 2021 12:06:04 -0400 Received: from mga02.intel.com ([134.134.136.20]:57921 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbhFCQGC (ORCPT ); Thu, 3 Jun 2021 12:06:02 -0400 IronPort-SDR: Qj2HdCTAqOIocJSR4ih4ixCNubR3Xn+A5aQ38tL32egjzn6NR3nFoD1AQDSQ8AmqLWKYlkql/O W0YIDNT68UqQ== X-IronPort-AV: E=McAfee;i="6200,9189,10004"; a="191185480" X-IronPort-AV: E=Sophos;i="5.83,246,1616482800"; d="scan'208";a="191185480" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2021 09:04:17 -0700 IronPort-SDR: WlBhSGvApWnSXUgA/aF9FgSiYdLItGd+xvC+yWSzV1TeSCUNXhCZ8qO4CzgF4ofnGhRypSO/YG OSAZrdbZYxyg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,246,1616482800"; d="scan'208";a="617946568" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 03 Jun 2021 09:04:15 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id D8F091FC; Thu, 3 Jun 2021 19:04:38 +0300 (EEST) From: Andy Shevchenko To: Andy Shevchenko , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Jarkko Nikula , Mika Westerberg , wsa@kernel.org Subject: [PATCH resend v1 2/3] i2c: designware: Use DIV_ROUND_CLOSEST() macro Date: Thu, 3 Jun 2021 19:04:32 +0300 Message-Id: <20210603160433.35816-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210603160433.35816-1-andriy.shevchenko@linux.intel.com> References: <20210603160433.35816-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Instead of open-coding DIV_ROUND_CLOSEST() and similar use the macros directly. While at it, replace numbers with predefined SI metric prefixes. No functional change intended. Signed-off-by: Andy Shevchenko --- drivers/i2c/busses/i2c-designware-common.c | 8 ++++---- drivers/i2c/busses/i2c-designware-platdrv.c | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/busses/i2c-designware-common.c b/drivers/i2c/busses/i2c-designware-common.c index fdc34d9e3702..9df101d1a34f 100644 --- a/drivers/i2c/busses/i2c-designware-common.c +++ b/drivers/i2c/busses/i2c-designware-common.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "i2c-designware-core.h" @@ -350,7 +351,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) * * If your hardware is free from tHD;STA issue, try this one. */ - return (ic_clk * tSYMBOL + 500000) / 1000000 - 8 + offset; + return DIV_ROUND_CLOSEST(ic_clk * tSYMBOL, MEGA) - 8 + offset; else /* * Conditional expression: @@ -366,8 +367,7 @@ u32 i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset) * The reason why we need to take into account "tf" here, * is the same as described in i2c_dw_scl_lcnt(). */ - return (ic_clk * (tSYMBOL + tf) + 500000) / 1000000 - - 3 + offset; + return DIV_ROUND_CLOSEST(ic_clk * (tSYMBOL + tf), MEGA) - 3 + offset; } u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) @@ -383,7 +383,7 @@ u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset) * account the fall time of SCL signal (tf). Default tf value * should be 0.3 us, for safety. */ - return ((ic_clk * (tLOW + tf) + 500000) / 1000000) - 1 + offset; + return DIV_ROUND_CLOSEST(ic_clk * (tLOW + tf), MEGA) - 1 + offset; } int i2c_dw_set_sda_hold(struct dw_i2c_dev *dev) diff --git a/drivers/i2c/busses/i2c-designware-platdrv.c b/drivers/i2c/busses/i2c-designware-platdrv.c index 4b37f28ec0c6..099e303d22bb 100644 --- a/drivers/i2c/busses/i2c-designware-platdrv.c +++ b/drivers/i2c/busses/i2c-designware-platdrv.c @@ -31,12 +31,13 @@ #include #include #include +#include #include "i2c-designware-core.h" static u32 i2c_dw_get_clk_rate_khz(struct dw_i2c_dev *dev) { - return clk_get_rate(dev->clk)/1000; + return clk_get_rate(dev->clk) / KILO; } #ifdef CONFIG_ACPI @@ -269,8 +270,7 @@ static int dw_i2c_plat_probe(struct platform_device *pdev) clk_khz = dev->get_clk_rate_khz(dev); if (!dev->sda_hold_time && t->sda_hold_ns) - dev->sda_hold_time = - div_u64(clk_khz * t->sda_hold_ns + 500000, 1000000); + dev->sda_hold_time = DIV_S64_ROUND_CLOSEST(clk_khz * t->sda_hold_ns, MEGA); } adap = &dev->adapter; -- 2.30.2