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,
Fabrizio Castro <fabrizio.castro@bp.renesas.com>,
Biju Das <biju.das@bp.renesas.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Simon Horman <horms+renesas@verge.net.au>
Subject: [PATCH v5 3/6] math64: New DIV64_U64_ROUND_CLOSEST helper
Date: Mon, 11 Feb 2019 14:58:55 +0100 [thread overview]
Message-ID: <20190211135858.23635-4-horms+renesas@verge.net.au> (raw)
In-Reply-To: <20190211135858.23635-1-horms+renesas@verge.net.au>
Provide DIV64_U64_ROUND_CLOSEST helper which performs division rounded to
the closes 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 ovefolow occurs if either the dividend or divisor is 32bit.
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
---
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-02-11 13:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-11 13:58 [PATCH v5 0/6] clk: renesas: r8a77990, r8a774c0: Add Z2 clock Simon Horman
2019-02-11 13:58 ` [PATCH v5 1/6] clk: renesas: rcar-gen3: Parameterise Z and Z2 clock fixed divisor Simon Horman
2019-02-11 13:58 ` [PATCH v5 2/6] clk: renesas: rcar-gen3: Parameterise Z and Z2 clock offset Simon Horman
2019-02-11 13:58 ` Simon Horman [this message]
2019-02-11 15:22 ` [PATCH v5 3/6] math64: New DIV64_U64_ROUND_CLOSEST helper Sergei Shtylyov
2019-02-11 15:44 ` Geert Uytterhoeven
2019-02-11 13:58 ` [PATCH v5 4/6] clk: renesas: rcar-gen3: Support Z and Z2 clocks with high frequency parents Simon Horman
2019-02-11 13:58 ` [PATCH v5 5/6] clk: renesas: r8a77990: Add Z2 clock Simon Horman
2019-02-11 13:58 ` [PATCH v5 6/6] clk: renesas: r8a774c0: " Simon Horman
2019-02-15 13:17 ` Simon Horman
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=20190211135858.23635-4-horms+renesas@verge.net.au \
--to=horms+renesas@verge.net.au \
--cc=akpm@linux-foundation.org \
--cc=biju.das@bp.renesas.com \
--cc=fabrizio.castro@bp.renesas.com \
--cc=geert+renesas@glider.be \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@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).