diff mbox series

[3/4] lib: div64: Add support for round up of div64_u64

Message ID f9fdcba76cd692ae436b1d7883b490e3dc207231.1645626962.git.michal.simek@xilinx.com
State Accepted
Commit 3adc17f60bf804fd8fe25e7c20399243f26d7f49
Delegated to: Michal Simek
Headers show
Series mmc: zynq_sdhci: Add support for dynamic IP configuration | expand

Commit Message

Michal Simek Feb. 23, 2022, 2:36 p.m. UTC
From: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>

Most of the frequencies are not rounded up to a proper number.
When we need to devide these frequencies to get a number for example
frequency in Mhz, we see it as one less than the actual intended value.
Ex: If we want to get Mhz from frequency 199999994hz, we will calculate
it using div64_u64(199999994, 1000000) and we will get 199Mhz in place
of 200Mhz.

Add a macro DIV64_U64_ROUND_UP for rounding up div64_u64. This is taken
from linux 'commit 68600f623d69("mm: don't miss the last page because of
round-off error")'.

Signed-off-by: Ashok Reddy Soma <ashok.reddy.soma@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

 include/linux/math64.h | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/math64.h b/include/linux/math64.h
index 08584c8f237f..eaa9fd5b9685 100644
--- a/include/linux/math64.h
+++ b/include/linux/math64.h
@@ -48,6 +48,9 @@  static inline u64 div64_u64(u64 dividend, u64 divisor)
 	return dividend / divisor;
 }
 
+#define DIV64_U64_ROUND_UP(ll, d)	\
+	({ u64 _tmp = (d); div64_u64((ll) + _tmp - 1, _tmp); })
+
 /**
  * div64_s64 - signed 64bit divide with 64bit divisor
  */