device/mmio.h: Add more bit field helpers
For fields with single bit, it's easier to declare as DEFINE_BIT(name, bit) Change-Id: If20e6b1809073b2c0dc84190edc25b207bf332b7 Signed-off-by: Hung-Te Lin <hungte@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/35787 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Yu-Ping Wu <yupingso@google.com>
This commit is contained in:
parent
2431a707d3
commit
dafb66142e
|
@ -63,6 +63,10 @@ static inline void buffer_to_fifo32(void *buffer, size_t size, void *fifo,
|
||||||
* - high_bit: highest bit that's part of the bit field.
|
* - high_bit: highest bit that's part of the bit field.
|
||||||
* - low_bit: lowest bit in the bit field.
|
* - low_bit: lowest bit in the bit field.
|
||||||
*
|
*
|
||||||
|
* To define a field with a single bit:
|
||||||
|
*
|
||||||
|
* DEFINE_BIT(name, bit)
|
||||||
|
*
|
||||||
* To extract one field value from a raw reg value:
|
* To extract one field value from a raw reg value:
|
||||||
*
|
*
|
||||||
* EXTRACT_BITFIELD(value, name);
|
* EXTRACT_BITFIELD(value, name);
|
||||||
|
@ -85,7 +89,7 @@ static inline void buffer_to_fifo32(void *buffer, size_t size, void *fifo,
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
* DEFINE_BITFIELD(DISP_TYPE, 2, 1)
|
* DEFINE_BITFIELD(DISP_TYPE, 2, 1)
|
||||||
* DEFINE_BITFIELD(DISP_EN, 0, 0)
|
* DEFINE_BIT(DISP_EN, 0)
|
||||||
*
|
*
|
||||||
* SET32_BITFIELDS(&disp_regs.ctrl, DISP_TYPE, 2);
|
* SET32_BITFIELDS(&disp_regs.ctrl, DISP_TYPE, 2);
|
||||||
* SET32_BITFIELDS(&disp_regs.ctrl, DISP_EN, 0);
|
* SET32_BITFIELDS(&disp_regs.ctrl, DISP_EN, 0);
|
||||||
|
@ -118,6 +122,8 @@ static inline void buffer_to_fifo32(void *buffer, size_t size, void *fifo,
|
||||||
name##_BITFIELD_SIZE = (high_bit) - (low_bit) + 1, \
|
name##_BITFIELD_SIZE = (high_bit) - (low_bit) + 1, \
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define DEFINE_BIT(name, bit) DEFINE_BITFIELD(name, bit, bit)
|
||||||
|
|
||||||
#define _BF_MASK(name, value) \
|
#define _BF_MASK(name, value) \
|
||||||
(((1 << name##_BITFIELD_SIZE) - 1) << name##_BITFIELD_SHIFT)
|
(((1 << name##_BITFIELD_SIZE) - 1) << name##_BITFIELD_SHIFT)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue