Attention is currently required from: Julius Werner.
Yidi Lin has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/78799?usp=email )
Change subject: Use common GCD function ......................................................................
Use common GCD function
Change-Id: I30e4b02a9ca6a15c9bc4edcf4143ffa13a21a732 Signed-off-by: Yidi Lin yidilin@chromium.org --- M src/drivers/analogix/anx7625/anx7625.c M src/northbridge/intel/ironlake/quickpath.c M src/soc/rockchip/rk3288/clock.c M src/soc/rockchip/rk3399/clock.c 4 files changed, 6 insertions(+), 54 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/99/78799/1
diff --git a/src/drivers/analogix/anx7625/anx7625.c b/src/drivers/analogix/anx7625/anx7625.c index e3a5111..3fb4d4c 100644 --- a/src/drivers/analogix/anx7625/anx7625.c +++ b/src/drivers/analogix/anx7625/anx7625.c @@ -4,6 +4,7 @@ #include <delay.h> #include <device/i2c_simple.h> #include <edid.h> +#include <gcd.h> #include <gpio.h> #include <string.h> #include <types.h> @@ -152,21 +153,6 @@ return 0; }
-static unsigned long gcd(unsigned long a, unsigned long b) -{ - if (a == 0) - return b; - - while (b != 0) { - if (a > b) - a = a - b; - else - b = b - a; - } - - return a; -} - /* Reduce fraction a/b */ static void anx7625_reduction_of_a_fraction(unsigned long *_a, unsigned long *_b) diff --git a/src/northbridge/intel/ironlake/quickpath.c b/src/northbridge/intel/ironlake/quickpath.c index 8a0e01c..e7fca10 100644 --- a/src/northbridge/intel/ironlake/quickpath.c +++ b/src/northbridge/intel/ironlake/quickpath.c @@ -6,28 +6,12 @@ #include <delay.h> #include <device/pci_def.h> #include <device/pci_ops.h> +#include <gcd.h> #include <northbridge/intel/ironlake/raminit.h> #include <types.h>
#define NORTHBRIDGE PCI_DEV(0, 0, 0)
-static unsigned int gcd(unsigned int a, unsigned int b) -{ - unsigned int t; - if (a > b) { - t = a; - a = b; - b = t; - } - /* invariant a < b. */ - while (a) { - t = b % a; - b = a; - a = t; - } - return b; -} - static inline int div_roundup(int a, int b) { return DIV_ROUND_UP(a, b); diff --git a/src/soc/rockchip/rk3288/clock.c b/src/soc/rockchip/rk3288/clock.c index c2f93f5..956fa25 100644 --- a/src/soc/rockchip/rk3288/clock.c +++ b/src/soc/rockchip/rk3288/clock.c @@ -5,6 +5,7 @@ #include <console/console.h> #include <delay.h> #include <lib.h> +#include <gcd.h> #include <soc/addressmap.h> #include <soc/clock.h> #include <soc/grf.h> @@ -438,16 +439,6 @@ } }
-static u32 clk_gcd(u32 a, u32 b) -{ - while (b != 0) { - int r = b; - b = a % b; - a = r; - } - return a; -} - void rkclk_configure_i2s(unsigned int hz) { int n, d; @@ -462,7 +453,7 @@ 1 << 15 | 0 << 12 | 1 << 8 | 0 << 0));
/* set frac divider */ - v = clk_gcd(GPLL_HZ, hz); + v = gcd(GPLL_HZ, hz); n = (GPLL_HZ / v) & (0xffff); d = (hz / v) & (0xffff); assert(hz == GPLL_HZ / n * d); diff --git a/src/soc/rockchip/rk3399/clock.c b/src/soc/rockchip/rk3399/clock.c index 75af695b..364876d 100644 --- a/src/soc/rockchip/rk3399/clock.c +++ b/src/soc/rockchip/rk3399/clock.c @@ -4,6 +4,7 @@ #include <console/console.h> #include <device/mmio.h> #include <delay.h> +#include <gcd.h> #include <soc/addressmap.h> #include <soc/clock.h> #include <soc/grf.h> @@ -776,16 +777,6 @@ return freq; }
-static u32 clk_gcd(u32 a, u32 b) -{ - while (b != 0) { - int r = b; - b = a % b; - a = r; - } - return a; -} - void rkclk_configure_i2s(unsigned int hz) { int n, d; @@ -805,7 +796,7 @@ RK_CLRBITS(1 << 12 | 1 << 5 | 1 << 4 | 1 << 3));
/* set frac divider */ - v = clk_gcd(CPLL_HZ, hz); + v = gcd(CPLL_HZ, hz); n = (CPLL_HZ / v) & (0xffff); d = (hz / v) & (0xffff); assert(hz == (u64)CPLL_HZ * d / n);