blob: eee60c50e993149826b23a1deff2d81ff47c9f30 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Aneesh V2c451f72011-06-16 23:30:47 +00002/*
3 * (C) Copyright 2010
4 * Texas Instruments, <www.ti.com>
5 * Aneesh V <aneesh@ti.com>
Aneesh V2c451f72011-06-16 23:30:47 +00006 */
7#ifndef _UTILS_H_
8#define _UTILS_H_
9
10static inline s32 log_2_n_round_up(u32 n)
11{
12 s32 log2n = -1;
13 u32 temp = n;
14
15 while (temp) {
16 log2n++;
17 temp >>= 1;
18 }
19
20 if (n & (n - 1))
21 return log2n + 1; /* not power of 2 - round up */
22 else
23 return log2n; /* power of 2 */
24}
25
26static inline s32 log_2_n_round_down(u32 n)
27{
28 s32 log2n = -1;
29 u32 temp = n;
30
31 while (temp) {
32 log2n++;
33 temp >>= 1;
34 }
35
36 return log2n;
37}
38
39#endif