From patchwork Wed Sep 6 20:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13375934 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82593EE14C3 for ; Wed, 6 Sep 2023 20:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243739AbjIFUAr (ORCPT ); Wed, 6 Sep 2023 16:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243412AbjIFUAf (ORCPT ); Wed, 6 Sep 2023 16:00:35 -0400 Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD38A19A2 for ; Wed, 6 Sep 2023 13:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=XoiQxYsYwOkc6ek7lwwO9Ez6SawCuS1deuBN1MfPurg=; b=Egtst9 yM4k4fxaCGvLCDq51Lf7uyTG7MU4U4qeniiDJpCo5XtVXBUGvTkJUR75yFlHTaRh EMpQorbsTg34hDpsm0NoOIXEPdp8bNM1VA2xD2rEchBy7DWSUsqsDG71Sv9CdTaF acai0tkQAscVvRkbywFCqUuCAKnGXprBQe4HKmb6vlbYS9hGRb/kCJBqLqd0Feez tMEu0TDRY8fzz4nEb8yvOSiEaL5UjaHZscFsODjwxbM83EHsnngPUrC+26X1n9eU NQiAm3/cojYKFG2iU0C+1n8sgLsZ4w0KcK25SN2vaiOJEVorpHxbwDrZgVzxXf2I yQI+sJqnXiNS0X3g== Received: (qmail 2929796 invoked from network); 6 Sep 2023 22:00:27 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Sep 2023 22:00:27 +0200 X-UD-Smtp-Session: l3s3148p1@xLTUMbYEFIsgAQnoAFZhALrSGIaWNE/A From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] i2c: rcar: avoid non-standard use of goto Date: Wed, 6 Sep 2023 22:00:19 +0200 Message-Id: <20230906200024.5305-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> References: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Kernel functions goto somewhere on error conditions. Using goto for the default path is irritating. Let's bail out on error instead and use a proper retval. Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven --- I dropped the Rev-bys because I think the changes are not trivial. YMMV. drivers/i2c/busses/i2c-rcar.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index a32a93f9a60d..49dfbeebf6b8 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -317,12 +317,12 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) for (scgd = 0; scgd < 0x40; scgd++) { scl = ick / (20 + (scgd * 8) + round); if (scl <= t.bus_freq_hz) - goto scgd_find; + break; } - dev_err(dev, "it is impossible to calculate best SCL\n"); - return -EIO; -scgd_find: + if (scgd == 0x40) + goto err_no_val; + dev_dbg(dev, "clk %d/%d(%lu), round %u, CDF:0x%x, SCGD: 0x%x\n", scl, t.bus_freq_hz, rate, round, cdf, scgd); @@ -330,6 +330,10 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) priv->icccr = scgd << cdf_width | cdf; return 0; + +err_no_val: + dev_err(dev, "it is impossible to calculate best SCL\n"); + return -EINVAL; } /* From patchwork Wed Sep 6 20:00:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13375935 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5D48EE14D7 for ; Wed, 6 Sep 2023 20:00:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243412AbjIFUAu (ORCPT ); Wed, 6 Sep 2023 16:00:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243608AbjIFUAg (ORCPT ); Wed, 6 Sep 2023 16:00:36 -0400 Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADA1F19AA for ; Wed, 6 Sep 2023 13:00:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=VJ3mLrt5G3E1weRn20fSYxodtrWVlLm96b4uFr3fzos=; b=aZkUzC 6+9fOrQWoPE38eJ2s/a9wtqjWxSe09Lk7hVxr9EaWPgXmsAdKltFIBL6ocJlPUD+ 3yXiLSSRcaB6GxzZTBlem1/JbPKjFVUcLlCbSGeH986ofxC3uzVBmphK6wM8Qzs+ CnrhsLBDZeZ3tIwuw3kW/+nwpae/bdDgRpmffk75K8lYv2/2gP+WnVfEP88dVqZF T1dW1aRqgSRcALSqQ5vLM4Pxge8LB9Au6uOfveg35m4d0Fs/fh1WVyl1ii7oysyT EerjpVimxgAk5ONL0lWoveZumXoHNvNUo2ZDlbLIPQ7aaQpoJXOE5jXB5Wh8FM4d xiFh9DwHXLP3F+ng== Received: (qmail 2929830 invoked from network); 6 Sep 2023 22:00:27 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Sep 2023 22:00:27 +0200 X-UD-Smtp-Session: l3s3148p1@iKnfMbYEJIsgAQnoAFZhALrSGIaWNE/A From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] i2c: rcar: properly format a debug output Date: Wed, 6 Sep 2023 22:00:20 +0200 Message-Id: <20230906200024.5305-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> References: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Use proper types and spacing. Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven --- drivers/i2c/busses/i2c-rcar.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 49dfbeebf6b8..4bf47e35094f 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -323,7 +323,7 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) if (scgd == 0x40) goto err_no_val; - dev_dbg(dev, "clk %d/%d(%lu), round %u, CDF:0x%x, SCGD: 0x%x\n", + dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u, SCGD: %u\n", scl, t.bus_freq_hz, rate, round, cdf, scgd); /* keep icccr value */ From patchwork Wed Sep 6 20:00:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13375939 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 898B3EE14D6 for ; Wed, 6 Sep 2023 20:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243955AbjIFUBK (ORCPT ); Wed, 6 Sep 2023 16:01:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243650AbjIFUAl (ORCPT ); Wed, 6 Sep 2023 16:00:41 -0400 Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C8D519B4 for ; Wed, 6 Sep 2023 13:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=xJsHUvQhrLbRjhVbZzw9GQZf+nq+ia33sWzU4P2ylJo=; b=LLsSji ouIYueos70JY0o2u+vtusywFfMoaEnLidS6PvOdmV4mHgxGynGnGfcixrXic068k IetzyAorzwCMqmRanV98lI/fGLmh+onLxnL3uUgb5e6RpTjzOSYt0wDjvJ/21Ah1 +0kKr8neBy5ptgfxZjICHX2SJzuJsfRYN5sVo5mRwYDnpXfXYf8+l6EIBtYzSD6a tbLBr2+rSAZwzYLg7rP8iCn7bzZSqr8zPOwAfSHPEKD8U9bbZWvT5ClvSkyB+rUP nSxkHiT+2kemliuzqSYlp1moanQNvTaTFoYz9QrFDavMhQa3XCGZcnYvemLSG2hL RG+5fConjg1c2SAA== Received: (qmail 2929864 invoked from network); 6 Sep 2023 22:00:28 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Sep 2023 22:00:28 +0200 X-UD-Smtp-Session: l3s3148p1@CvrqMbYELIsgAQnoAFZhALrSGIaWNE/A From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] i2c: rcar: calculate divider instead of brute-forcing it Date: Wed, 6 Sep 2023 22:00:21 +0200 Message-Id: <20230906200024.5305-4-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> References: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Instead of trying all values, we can actually compute it as the comment suggests. It is unclear what the comment means with "involved", it works nicely. Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven --- @Geert: I hope the formulas are more clear now? @Andi: I don't think that replacing 0x3f with a define helps understanding the code, but I am open for discussion. drivers/i2c/busses/i2c-rcar.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 4bf47e35094f..2585092bed52 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -303,24 +303,16 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) round = (round + 500) / 1000; /* - * SCL = ick / (20 + SCGD * 8 + F[(ticf + tr + intd) * ick]) - * - * Calculation result (= SCL) should be less than - * bus_speed for hardware safety - * - * We could use something along the lines of - * div = ick / (bus_speed + 1) + 1; - * scgd = (div - 20 - round + 7) / 8; - * scl = ick / (20 + (scgd * 8) + round); - * (not fully verified) but that would get pretty involved + * SCL = ick / (20 + 8 * SCGD + F[(ticf + tr + intd) * ick]) + * 20 + 8 * SCGD + F[...] = ick / SCL + * SCGD = ((ick / SCL) - 20 - F[...]) / 8 + * Result (= SCL) should be less than bus_speed for hardware safety */ - for (scgd = 0; scgd < 0x40; scgd++) { - scl = ick / (20 + (scgd * 8) + round); - if (scl <= t.bus_freq_hz) - break; - } + scgd = DIV_ROUND_UP(ick, t.bus_freq_hz ?: 1); + scgd = DIV_ROUND_UP(scgd - 20 - round, 8); + scl = ick / (20 + 8 * scgd + round); - if (scgd == 0x40) + if (scgd > 0x3f) goto err_no_val; dev_dbg(dev, "clk %u/%u(%lu), round %u, CDF: %u, SCGD: %u\n", From patchwork Wed Sep 6 20:00:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13375938 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05E50EE14C3 for ; Wed, 6 Sep 2023 20:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243684AbjIFUBH (ORCPT ); Wed, 6 Sep 2023 16:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243707AbjIFUAr (ORCPT ); Wed, 6 Sep 2023 16:00:47 -0400 Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F269319B9 for ; Wed, 6 Sep 2023 13:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=qBxfS0Tf9/DuCfn43C/vkUHINEKl9b1xtv2hh3LyJBc=; b=WtJQe8 FjFl6HiiP8WWG9mzP6zVQ7QuR9MoB+naxEwOr9MyS8o7x3/QlrqH5XO/TebRww0W fAErrRq3ehSD9b9bm3pBZtJ2XMU8A5p9ZRq5cISp7MVKNxmso+NseOJmbYm0g7Yb iFhNpMwcxmXXPXyXu29BSGqnjX4sHnm1YuhfxsgeHQLnXgDCcAkXi8BnLNzQIFN4 CbbNdCpLNlF5jf9omb0zI1vEAof9brCMHSK7WLxJIFC1u2z4P/79658OfngiAd4k TFjxOYyEvw22CxnANUlUvi8C7z6+USSe0O3Dqd3TuYwHxCBv99BqC2omwJTG9lTu tjiE0VEaYSBWu3Xg== Received: (qmail 2929897 invoked from network); 6 Sep 2023 22:00:29 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Sep 2023 22:00:29 +0200 X-UD-Smtp-Session: l3s3148p1@Rij2MbYENIsgAQnoAFZhALrSGIaWNE/A From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] i2c: rcar: remove open coded DIV_ROUND_CLOSEST Date: Wed, 6 Sep 2023 22:00:22 +0200 Message-Id: <20230906200024.5305-5-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> References: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org It improves readability if we use the available helper. Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven --- drivers/i2c/busses/i2c-rcar.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-rcar.c b/drivers/i2c/busses/i2c-rcar.c index 2585092bed52..5e97635faf78 100644 --- a/drivers/i2c/busses/i2c-rcar.c +++ b/drivers/i2c/busses/i2c-rcar.c @@ -291,16 +291,15 @@ static int rcar_i2c_clock_calculate(struct rcar_i2c_priv *priv) ick = rate / (cdf + 1); /* - * it is impossible to calculate large scale - * number on u32. separate it + * It is impossible to calculate a large scale number on u32. Separate it. * * F[(ticf + tr + intd) * ick] with sum = (ticf + tr + intd) * = F[sum * ick / 1000000000] * = F[(ick / 1000000) * sum / 1000] */ sum = t.scl_fall_ns + t.scl_rise_ns + t.scl_int_delay_ns; - round = (ick + 500000) / 1000000 * sum; - round = (round + 500) / 1000; + round = DIV_ROUND_CLOSEST(ick, 1000000); + round = DIV_ROUND_CLOSEST(round * sum, 1000); /* * SCL = ick / (20 + 8 * SCGD + F[(ticf + tr + intd) * ick]) From patchwork Wed Sep 6 20:00:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 13375937 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB069EE14D0 for ; Wed, 6 Sep 2023 20:01:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243632AbjIFUBB (ORCPT ); Wed, 6 Sep 2023 16:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243684AbjIFUAr (ORCPT ); Wed, 6 Sep 2023 16:00:47 -0400 Received: from mail.zeus03.de (www.zeus03.de [194.117.254.33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31F65D7 for ; Wed, 6 Sep 2023 13:00:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= sang-engineering.com; h=from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; s=k1; bh=b7rT9wKJbxCEtc/9yaA+sRK1E4pHjRX6I/sjz0k8OFI=; b=XkyC9W SX7VufPiTrmKAmknt+S/jhNIMLXAsM5CelCu9rasnkZBlJcVz8lYKgvAJAxTrKcU RoPxNqXTxx20jVaGWZiq9/umbtkdM3Zb5qIBjrCrXIiCiXdBJZhwBnh2R7zdA3gI 9jb6wJ2weDhLDQ/eeaVN1SURDC4aUPY0mjBhzyxhHASxPL6EZ8pzanDZI4eu0I+X oAXFMUq0iR32cGvVPNedhwQ1HcupXLGPJK20bTqs/gGM+XWqHMo5N0lP52Iq5pXB YF0zz1cvHcT4k0gaI1Fqo1xYTtRkjosts1lpOZgxuZNc1yfatSkuyYO3sLrNIWa/ mhya5NnN/zYNuIzw== Received: (qmail 2929932 invoked from network); 6 Sep 2023 22:00:30 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 6 Sep 2023 22:00:30 +0200 X-UD-Smtp-Session: l3s3148p1@kxsBMrYEOIsgAQnoAFZhALrSGIaWNE/A From: Wolfram Sang To: linux-renesas-soc@vger.kernel.org Cc: Wolfram Sang , Chris Brandt , Andi Shyti , linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] i2c: riic: avoid potential division by zero Date: Wed, 6 Sep 2023 22:00:23 +0200 Message-Id: <20230906200024.5305-6-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> References: <20230906200024.5305-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Value comes from DT, so it could be 0. Unlikely, but could be. Signed-off-by: Wolfram Sang Reviewed-by: Geert Uytterhoeven --- drivers/i2c/busses/i2c-riic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c index f0ee8871d5ae..e43ff483c56e 100644 --- a/drivers/i2c/busses/i2c-riic.c +++ b/drivers/i2c/busses/i2c-riic.c @@ -313,7 +313,7 @@ static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t) * frequency with only 62 clock ticks max (31 high, 31 low). * Aim for a duty of 60% LOW, 40% HIGH. */ - total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz); + total_ticks = DIV_ROUND_UP(rate, t->bus_freq_hz ?: 1); for (cks = 0; cks < 7; cks++) { /*