1 /*
2  * Copyright (c) 2020 Nuvoton Technology Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _NUVOTON_NPCX_REG_ACCESS_H
8 #define _NUVOTON_NPCX_REG_ACCESS_H
9 
10 /*
11  * NPCX register bit/field access operations
12  */
13 #define IS_BIT_SET(reg, bit)        (((reg >> bit) & (0x1)) != 0)
14 
15 #define GET_POS_FIELD(pos, size)    pos
16 #define GET_SIZE_FIELD(pos, size)   size
17 #define FIELD_POS(field)            GET_POS_##field
18 #define FIELD_SIZE(field)           GET_SIZE_##field
19 
20 #define GET_FIELD(reg, field) \
21 	_GET_FIELD_(reg, FIELD_POS(field), FIELD_SIZE(field))
22 #define _GET_FIELD_(reg, f_pos, f_size) (((reg)>>(f_pos)) & ((1<<(f_size))-1))
23 
24 #define SET_FIELD(reg, field, value) \
25 	_SET_FIELD_(reg, FIELD_POS(field), FIELD_SIZE(field), value)
26 #define _SET_FIELD_(reg, f_pos, f_size, value) \
27 	((reg) = ((reg) & (~(((1 << (f_size))-1) << (f_pos)))) \
28 			| ((value) << (f_pos)))
29 
30 #define GET_FIELD_POS(field) \
31 	_GET_FIELD_POS_(FIELD_POS(field))
32 #define _GET_FIELD_POS_(f_ops) f_ops
33 
34 #define GET_FIELD_SZ(field) \
35 	_GET_FIELD_SZ_(FIELD_SIZE(field))
36 #define _GET_FIELD_SZ_(f_ops) f_ops
37 
38 #endif /* _NUVOTON_NPCX_REG_ACCESS_H */
39