kernel.h: implement DIV_ROUND_CLOSEST_ULL
authorJavi Merino <[email protected]>
Thu, 16 Apr 2015 19:43:45 +0000 (12:43 -0700)
committerLinus Torvalds <[email protected]>
Fri, 17 Apr 2015 13:03:55 +0000 (09:03 -0400)
We have grown a number of different implementations of
DIV_ROUND_CLOSEST_ULL throughout the kernel.  Move the i915 one to
kernel.h so that it can be reused.

Signed-off-by: Javi Merino <[email protected]>
Reviewed-by: Jeff Epler <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Guenter Roeck <[email protected]>
Acked-by: Daniel Vetter <[email protected]>
Cc: "Rafael J. Wysocki" <[email protected]>
Cc: Alex Elder <[email protected]>
Cc: Antti Palosaari <[email protected]>
Cc: Javi Merino <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Mike Turquette <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: Stephen Hemminger <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
drivers/gpu/drm/i915/intel_drv.h
drivers/gpu/drm/i915/intel_panel.c
include/linux/kernel.h

index eef79ccd0b7ca9c20329021175543720e2756a9b..ba243db3584008ae9d7c4b39e0bbaa1bbab96583 100644 (file)
@@ -36,9 +36,6 @@
 #include <drm/drm_dp_mst_helper.h>
 #include <drm/drm_rect.h>
 
-#define DIV_ROUND_CLOSEST_ULL(ll, d)   \
-({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; })
-
 /**
  * _wait_for - magic (register) wait macro
  *
index d8686ce89160a7d5851f695f1416e66dcd77bf40..08532d4ffe0ac13b130475c8b747e5bea3653f60 100644 (file)
@@ -30,6 +30,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/kernel.h>
 #include <linux/moduleparam.h>
 #include "intel_drv.h"
 
index d6d630d31ef308377730e30fda2f9fc799992c94..3a5b48e52a9ee3ce035a7a36a9cf35a2cc807bcb 100644 (file)
                (((__x) - ((__d) / 2)) / (__d));        \
 }                                                      \
 )
+/*
+ * Same as above but for u64 dividends. divisor must be a 32-bit
+ * number.
+ */
+#define DIV_ROUND_CLOSEST_ULL(x, divisor)(             \
+{                                                      \
+       typeof(divisor) __d = divisor;                  \
+       unsigned long long _tmp = (x) + (__d) / 2;      \
+       do_div(_tmp, __d);                              \
+       _tmp;                                           \
+}                                                      \
+)
 
 /*
  * Multiplies an integer by a fraction, while avoiding unnecessary