All of lore.kernel.org
 help / color / mirror / Atom feed
From: biju.das@bp.renesas.com (Biju Das)
To: cip-dev@lists.cip-project.org
Subject: [cip-dev] [PATCH 4.19.y-cip 14/23] math64: New DIV64_U64_ROUND_CLOSEST helper
Date: Mon, 15 Jul 2019 14:29:59 +0100	[thread overview]
Message-ID: <1563197408-59548-15-git-send-email-biju.das@bp.renesas.com> (raw)
In-Reply-To: <1563197408-59548-1-git-send-email-biju.das@bp.renesas.com>

From: Simon Horman <horms+renesas@verge.net.au>

commit cb8be119d21d8a0affc3598a928dd0baf5da238f upstream.

Provide DIV64_U64_ROUND_CLOSEST helper which performs division rounded to
the closest integer using an unsigned 64bit dividend and divisor.

This will be used in a follow-up patch to allow calculation of clock
divisors with high frequency parents in the R-Car Gen3 CPG MSSR driver
where overflow occurs if either the dividend or divisor is 32bit.

Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Biju Das <biju.das@bp.renesas.com>
---
 include/linux/math64.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/math64.h b/include/linux/math64.h
index bb2c84a..65bef21 100644
--- a/include/linux/math64.h
+++ b/include/linux/math64.h
@@ -284,4 +284,17 @@ static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 divisor)
 #define DIV64_U64_ROUND_UP(ll, d)	\
 	({ u64 _tmp = (d); div64_u64((ll) + _tmp - 1, _tmp); })
 
+/**
+ * DIV64_U64_ROUND_CLOSEST - unsigned 64bit divide with 64bit divisor rounded to nearest integer
+ * @dividend: unsigned 64bit dividend
+ * @divisor: unsigned 64bit divisor
+ *
+ * Divide unsigned 64bit dividend by unsigned 64bit divisor
+ * and round to closest integer.
+ *
+ * Return: dividend / divisor rounded to nearest integer
+ */
+#define DIV64_U64_ROUND_CLOSEST(dividend, divisor)	\
+	({ u64 _tmp = (divisor); div64_u64((dividend) + _tmp / 2, _tmp); })
+
 #endif /* _LINUX_MATH64_H */
-- 
2.7.4

  parent reply	other threads:[~2019-07-15 13:29 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-15 13:29 [cip-dev] [PATCH 4.19.y-cip 00/23] Clock enhancements Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 01/23] clk: renesas: r8a774a1: Add CPEX clock Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 02/23] clk: renesas: rcar-gen3: Set state when registering SD clocks Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 03/23] clk: renesas: rcar-gen3: Add documentation for " Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 04/23] clk: renesas: rcar-gen3: Add HS400 quirk for SD clock Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 05/23] clk: renesas: Remove usage of CLK_IS_BASIC Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 06/23] clk: renesas: r8a774a1: Add missing CANFD clock Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 07/23] clk: renesas: rcar-gen3: Factor out cpg_reg_modify() Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 08/23] clk: renesas: rcar-gen3: Add spinlock Biju Das
2019-07-16 11:17   ` Pavel Machek
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 09/23] clk: renesas: r8a774a1: Fix LAST_DT_CORE_CLK Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 10/23] clk: renesas: rcar-gen3: Pass name/offset to cpg_sd_clk_register() Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 11/23] clk: renesas: rcar-gen3: Parameterise Z and Z2 clock fixed divisor Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 12/23] clk: renesas: rcar-gen3: Parameterise Z and Z2 clock offset Biju Das
2019-07-15 13:29 ` [cip-dev] [PATCH 4.19.y-cip 13/23] clk: renesas: rcar-gen3: Remove CLK_TYPE_GEN3_Z2 Biju Das
2019-07-15 13:29 ` Biju Das [this message]
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 15/23] clk: renesas: rcar-gen3: Support Z and Z2 clocks with high frequency parents Biju Das
2019-07-16 11:22   ` Pavel Machek
2019-07-16 12:01     ` Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 16/23] clk: renesas: r8a774c0: Add Z2 clock Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 17/23] clk: renesas: rcar-gen3: Correct parent clock of EHCI/OHCI Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 18/23] clk: renesas: rcar-gen3: Correct parent clock of HS-USB Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 19/23] clk: renesas: rcar-gen3: Correct parent clock of SYS-DMAC Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 20/23] clk: renesas: rcar-gen3: Correct parent clock of Audio-DMAC Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 21/23] clk: renesas: rcar-gen3: Fix cpg_sd_clock_round_rate() return value Biju Das
2019-07-16 11:24   ` Pavel Machek
2019-07-16 11:56     ` Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 22/23] clk: renesas: rcar-gen3: Remove unused variable Biju Das
2019-07-15 13:30 ` [cip-dev] [PATCH 4.19.y-cip 23/23] arm64: dts: renesas: r8a774c0: Add OPPs table for cpu devices Biju Das
2019-07-15 19:50 ` [cip-dev] [PATCH 4.19.y-cip 00/23] Clock enhancements Pavel Machek
2019-07-15 21:57   ` Pavel Machek
2019-07-16  6:45   ` Biju Das
2019-07-16 11:28 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1563197408-59548-15-git-send-email-biju.das@bp.renesas.com \
    --to=biju.das@bp.renesas.com \
    --cc=cip-dev@lists.cip-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.