From: Simon Horman <horms+renesas@verge.net.au>
To: Geert Uytterhoeven <geert+renesas@glider.be>
Cc: Magnus Damm <magnus.damm@gmail.com>,
linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org,
Simon Horman <horms+renesas@verge.net.au>
Subject: [PATCH v6 4/7] math64: New DIV64_U64_ROUND_CLOSEST helper
Date: Mon, 25 Mar 2019 17:35:53 +0100 [thread overview]
Message-ID: <20190325163556.22025-5-horms+renesas@verge.net.au> (raw)
In-Reply-To: <20190325163556.22025-1-horms+renesas@verge.net.au>
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>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
v6
- Updated changelog as per suggestions from
Sergei Shtylyov and Geert Uytterhoeven
- Added Reviewed-by tag from Geert Uytterhoeven
v5
- New separate patch to add DIV64_U64_ROUND_CLOSEST
---
include/linux/math64.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/linux/math64.h b/include/linux/math64.h
index bb2c84afb80c..65bef21cdddb 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.11.0
next prev parent reply other threads:[~2019-03-25 16:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-25 16:35 [PATCH v6 0/7] clk: renesas: r8a77990, r8a774c0: Add Z2 clock Simon Horman
2019-03-25 16:35 ` [PATCH v6 1/7] clk: renesas: rcar-gen3: Parameterise Z and Z2 clock fixed divisor Simon Horman
2019-03-25 16:35 ` [PATCH v6 2/7] clk: renesas: rcar-gen3: Parameterise Z and Z2 clock offset Simon Horman
2019-03-25 16:35 ` [PATCH v6 3/7] clk: renesas: rcar-gen3: Remove CLK_TYPE_GEN3_Z2 Simon Horman
2019-03-25 17:49 ` Geert Uytterhoeven
2019-03-25 16:35 ` Simon Horman [this message]
2019-03-25 16:35 ` [PATCH v6 5/7] clk: renesas: rcar-gen3: Support Z and Z2 clocks with high frequency parents Simon Horman
2019-03-25 16:35 ` [PATCH v6 6/7] clk: renesas: r8a77990: Add Z2 clock Simon Horman
2019-03-25 16:35 ` [PATCH v6 7/7] clk: renesas: r8a774c0: " Simon Horman
2019-03-26 10:40 ` [PATCH v6 0/7] clk: renesas: r8a77990, " Geert Uytterhoeven
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=20190325163556.22025-5-horms+renesas@verge.net.au \
--to=horms+renesas@verge.net.au \
--cc=geert+renesas@glider.be \
--cc=linux-clk@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).