]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arm/include/asm/utils.h
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / arch / arm / include / asm / utils.h
CommitLineData
2c451f78
A
1/*
2 * (C) Copyright 2010
3 * Texas Instruments, <www.ti.com>
4 * Aneesh V <aneesh@ti.com>
5 *
1a459660 6 * SPDX-License-Identifier: GPL-2.0+
2c451f78
A
7 */
8#ifndef _UTILS_H_
9#define _UTILS_H_
10
11static inline s32 log_2_n_round_up(u32 n)
12{
13 s32 log2n = -1;
14 u32 temp = n;
15
16 while (temp) {
17 log2n++;
18 temp >>= 1;
19 }
20
21 if (n & (n - 1))
22 return log2n + 1; /* not power of 2 - round up */
23 else
24 return log2n; /* power of 2 */
25}
26
27static inline s32 log_2_n_round_down(u32 n)
28{
29 s32 log2n = -1;
30 u32 temp = n;
31
32 while (temp) {
33 log2n++;
34 temp >>= 1;
35 }
36
37 return log2n;
38}
39
40#endif