]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arm/cpu/armv7/omap-common/utils.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / arm / cpu / armv7 / omap-common / utils.c
CommitLineData
095aea29
A
1/*
2 * Copyright 2011 Linaro Limited
3 * Aneesh V <aneesh@ti.com>
4 *
1a459660 5 * SPDX-License-Identifier: GPL-2.0+
095aea29
A
6 */
7#include <common.h>
8static void do_cancel_out(u32 *num, u32 *den, u32 factor)
9{
10 while (1) {
11 if (((*num)/factor*factor == (*num)) &&
12 ((*den)/factor*factor == (*den))) {
13 (*num) /= factor;
14 (*den) /= factor;
15 } else
16 break;
17 }
18}
19
20/*
21 * Cancel out the denominator and numerator of a fraction
22 * to get smaller numerator and denominator.
23 */
24void cancel_out(u32 *num, u32 *den, u32 den_limit)
25{
26 do_cancel_out(num, den, 2);
27 do_cancel_out(num, den, 3);
28 do_cancel_out(num, den, 5);
29 do_cancel_out(num, den, 7);
30 do_cancel_out(num, den, 11);
31 do_cancel_out(num, den, 13);
32 do_cancel_out(num, den, 17);
33 while ((*den) > den_limit) {
34 *num /= 2;
35 /*
36 * Round up the denominator so that the final fraction
37 * (num/den) is always <= the desired value
38 */
39 *den = (*den + 1) / 2;
40 }
41}