xref: /openbmc/linux/drivers/gpu/drm/arm/display/include/malidp_utils.h (revision 2f0f2441b4a10948e2ec042b48fef13680387f7c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * (C) COPYRIGHT 2018 ARM Limited. All rights reserved.
4  * Author: James.Qian.Wang <james.qian.wang@arm.com>
5  *
6  */
7 #ifndef _MALIDP_UTILS_
8 #define _MALIDP_UTILS_
9 
10 #include <linux/delay.h>
11 
12 #define has_bit(nr, mask)	(BIT(nr) & (mask))
13 #define has_bits(bits, mask)	(((bits) & (mask)) == (bits))
14 
15 #define dp_for_each_set_bit(bit, mask) \
16 	for_each_set_bit((bit), ((unsigned long *)&(mask)), sizeof(mask) * 8)
17 
18 #define dp_wait_cond(__cond, __tries, __min_range, __max_range)	\
19 ({							\
20 	int num_tries = __tries;			\
21 	while (!__cond && (num_tries > 0)) {		\
22 		usleep_range(__min_range, __max_range);	\
23 		if (__cond)				\
24 			break;				\
25 		num_tries--;				\
26 	}						\
27 	num_tries;					\
28 })
29 
30 /* the restriction of range is [start, end] */
31 struct malidp_range {
32 	u32 start;
33 	u32 end;
34 };
35 
36 static inline void set_range(struct malidp_range *rg, u32 start, u32 end)
37 {
38 	rg->start = start;
39 	rg->end   = end;
40 }
41 
42 static inline bool in_range(struct malidp_range *rg, u32 v)
43 {
44 	return (v >= rg->start) && (v <= rg->end);
45 }
46 
47 #endif /* _MALIDP_UTILS_ */
48