2 * Copyright 2011 Linaro Limited
3 * Aneesh V <aneesh@ti.com>
5 * SPDX-License-Identifier: GPL-2.0+
8 static void do_cancel_out(u32 *num, u32 *den, u32 factor)
11 if (((*num)/factor*factor == (*num)) &&
12 ((*den)/factor*factor == (*den))) {
21 * Cancel out the denominator and numerator of a fraction
22 * to get smaller numerator and denominator.
24 void cancel_out(u32 *num, u32 *den, u32 den_limit)
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) {
36 * Round up the denominator so that the final fraction
37 * (num/den) is always <= the desired value
39 *den = (*den + 1) / 2;