1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * (C) Copyright 2010 4 * Texas Instruments, <www.ti.com> 5 * Aneesh V <aneesh@ti.com> 6 */ 7 #ifndef _UTILS_H_ 8 #define _UTILS_H_ 9 10 static 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 26 static 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 40