dts: devicetree.h: add DT_REG_HAS_NAME
Add DT_REG_HAS_NAME, DT_REG_ADDR_BY_NAME_OR, DT_REG_SIZE_BY_NAME_OR, DT_INST_REG_HAS_NAME, DT_INST_REG_SIZE_BY_NAME_OR and DT_INST_REG_ADDR_BY_NAME_OR. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
parent
88760196c6
commit
fb8b30d8d0
3 changed files with 72 additions and 0 deletions
1
doc/build/dts/macros.bnf
vendored
1
doc/build/dts/macros.bnf
vendored
|
|
@ -35,6 +35,7 @@ node-macro =/ %s"DT_N" path-id %s"_REG_IDX_" DIGIT
|
|||
%s"_VAL_" ( %s"ADDRESS" / %s"SIZE")
|
||||
node-macro =/ %s"DT_N" path-id %s"_REG_NAME_" dt-name
|
||||
%s"_VAL_" ( %s"ADDRESS" / %s"SIZE")
|
||||
node-macro =/ %s"DT_N" path-id %s"_REG_NAME_" dt-name "_EXISTS"
|
||||
; The interrupts property is also special.
|
||||
node-macro =/ %s"DT_N" path-id %s"_IRQ_NUM"
|
||||
node-macro =/ %s"DT_N" path-id %s"_IRQ_LEVEL"
|
||||
|
|
|
|||
|
|
@ -2229,6 +2229,20 @@
|
|||
#define DT_REG_HAS_IDX(node_id, idx) \
|
||||
IS_ENABLED(DT_CAT4(node_id, _REG_IDX_, idx, _EXISTS))
|
||||
|
||||
/**
|
||||
* @brief Is @p name a valid register block name?
|
||||
*
|
||||
* If this returns 1, then DT_REG_ADDR_BY_NAME(node_id, name) or
|
||||
* DT_REG_SIZE_BY_NAME(node_id, name) are valid.
|
||||
* If it returns 0, it is an error to use those macros with name @p name.
|
||||
* @param node_id node identifier
|
||||
* @param name name to check
|
||||
* @return 1 if @p name is a valid register block name,
|
||||
* 0 otherwise.
|
||||
*/
|
||||
#define DT_REG_HAS_NAME(node_id, name) \
|
||||
IS_ENABLED(DT_CAT4(node_id, _REG_NAME_, name, _EXISTS))
|
||||
|
||||
/**
|
||||
* @brief Get the base address of the register block at index @p idx
|
||||
* @param node_id node identifier
|
||||
|
|
@ -2291,6 +2305,18 @@
|
|||
#define DT_REG_ADDR_BY_NAME(node_id, name) \
|
||||
DT_CAT4(node_id, _REG_NAME_, name, _VAL_ADDRESS)
|
||||
|
||||
/**
|
||||
* @brief Like DT_REG_ADDR_BY_NAME(), but with a fallback to @p default_value
|
||||
* @param node_id node identifier
|
||||
* @param name lowercase-and-underscores register specifier name
|
||||
* @param default_value a fallback value to expand to
|
||||
* @return address of the register block specified by name if present,
|
||||
* @p default_value otherwise
|
||||
*/
|
||||
#define DT_REG_ADDR_BY_NAME_OR(node_id, name, default_value) \
|
||||
COND_CODE_1(DT_REG_HAS_NAME(node_id, name), \
|
||||
(DT_REG_ADDR_BY_NAME(node_id, name)), (default_value))
|
||||
|
||||
/**
|
||||
* @brief 64-bit version of DT_REG_ADDR_BY_NAME()
|
||||
*
|
||||
|
|
@ -2315,6 +2341,19 @@
|
|||
#define DT_REG_SIZE_BY_NAME(node_id, name) \
|
||||
DT_CAT4(node_id, _REG_NAME_, name, _VAL_SIZE)
|
||||
|
||||
/**
|
||||
* @brief Like DT_REG_SIZE_BY_NAME(), but with a fallback to @p default_value
|
||||
* @param node_id node identifier
|
||||
* @param name lowercase-and-underscores register specifier name
|
||||
* @param default_value a fallback value to expand to
|
||||
* @return size of the register block specified by name if present,
|
||||
* @p default_value otherwise
|
||||
*/
|
||||
#define DT_REG_SIZE_BY_NAME_OR(node_id, name, default_value) \
|
||||
COND_CODE_1(DT_REG_HAS_NAME(node_id, name), \
|
||||
(DT_REG_SIZE_BY_NAME(node_id, name)), (default_value))
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
@ -4068,6 +4107,15 @@
|
|||
*/
|
||||
#define DT_INST_REG_HAS_IDX(inst, idx) DT_REG_HAS_IDX(DT_DRV_INST(inst), idx)
|
||||
|
||||
/**
|
||||
* @brief is @p name a valid register block name on a `DT_DRV_COMPAT` instance?
|
||||
* @param inst instance number
|
||||
* @param name name to check
|
||||
* @return 1 if @p name is a valid register block name,
|
||||
* 0 otherwise.
|
||||
*/
|
||||
#define DT_INST_REG_HAS_NAME(inst, name) DT_REG_HAS_NAME(DT_DRV_INST(inst), name)
|
||||
|
||||
/**
|
||||
* @brief Get a `DT_DRV_COMPAT` instance's idx-th register block's address
|
||||
* @param inst instance number
|
||||
|
|
@ -4094,6 +4142,17 @@
|
|||
#define DT_INST_REG_ADDR_BY_NAME(inst, name) \
|
||||
DT_REG_ADDR_BY_NAME(DT_DRV_INST(inst), name)
|
||||
|
||||
/**
|
||||
* @brief Like DT_INST_REG_ADDR_BY_NAME(), but with a fallback to @p default_value
|
||||
* @param inst instance number
|
||||
* @param name lowercase-and-underscores register specifier name
|
||||
* @param default_value a fallback value to expand to
|
||||
* @return address of the register block specified by name if present,
|
||||
* @p default_value otherwise
|
||||
*/
|
||||
#define DT_INST_REG_ADDR_BY_NAME_OR(inst, name, default_value) \
|
||||
DT_REG_ADDR_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
|
||||
|
||||
/**
|
||||
* @brief 64-bit version of DT_INST_REG_ADDR_BY_NAME()
|
||||
*
|
||||
|
|
@ -4118,6 +4177,17 @@
|
|||
#define DT_INST_REG_SIZE_BY_NAME(inst, name) \
|
||||
DT_REG_SIZE_BY_NAME(DT_DRV_INST(inst), name)
|
||||
|
||||
/**
|
||||
* @brief Like DT_INST_REG_SIZE_BY_NAME(), but with a fallback to @p default_value
|
||||
* @param inst instance number
|
||||
* @param name lowercase-and-underscores register specifier name
|
||||
* @param default_value a fallback value to expand to
|
||||
* @return size of the register block specified by name if present,
|
||||
* @p default_value otherwise
|
||||
*/
|
||||
#define DT_INST_REG_SIZE_BY_NAME_OR(inst, name, default_value) \
|
||||
DT_REG_SIZE_BY_NAME_OR(DT_DRV_INST(inst), name, default_value)
|
||||
|
||||
/**
|
||||
* @brief Get a `DT_DRV_COMPAT`'s (only) register block address
|
||||
* @param inst instance number
|
||||
|
|
|
|||
|
|
@ -423,6 +423,7 @@ def write_regs(node):
|
|||
idx_vals.append((idx_macro,
|
||||
f"{reg.addr} /* {hex(reg.addr)} */"))
|
||||
if reg.name:
|
||||
name_vals.append((f"{path_id}_REG_NAME_{reg.name}_EXISTS", 1))
|
||||
name_macro = f"{path_id}_REG_NAME_{reg.name}_VAL_ADDRESS"
|
||||
name_vals.append((name_macro, f"DT_{idx_macro}"))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue