scripts: kconfig: Add unit divisor to dt_node_int_prop_int/hex functions
Added a unit divisor option to the dt_node_int_prop_int and
dt_node_int_prop_hex functions to allow retrieval of DTS items as
a size value of K, M, or G divisor similar to the dt_node_reg_size_int
function.
Signed-off-by: David Leach <david.leach@nxp.com>
diff --git a/scripts/kconfig/kconfigfunctions.py b/scripts/kconfig/kconfigfunctions.py
index 5ff335c..210353f 100644
--- a/scripts/kconfig/kconfigfunctions.py
+++ b/scripts/kconfig/kconfigfunctions.py
@@ -168,7 +168,19 @@
return node.regs[int(index)].size >> _dt_units_to_scale(unit)
-def _node_int_prop(node, prop):
+def _node_int_prop(node, prop, unit=None):
+ """
+ This function takes a 'node' and will look to see if that 'node' has a
+ property called 'prop' and if that 'prop' is an integer type will return
+ the value of the property 'prop' as either a string int or string hex
+ value, if not we return 0.
+
+ The function will divide the value based on 'unit':
+ None No division
+ 'k' or 'K' divide by 1024 (1 << 10)
+ 'm' or 'M' divide by 1,048,576 (1 << 20)
+ 'g' or 'G' divide by 1,073,741,824 (1 << 30)
+ """
if not node:
return 0
@@ -178,7 +190,7 @@
if node.props[prop].type != "int":
return 0
- return node.props[prop].val
+ return node.props[prop].val >> _dt_units_to_scale(unit)
def _dt_chosen_reg_addr(kconf, chosen, index=0, unit=None):
@@ -349,15 +361,20 @@
return "n"
-def dt_node_int_prop(kconf, name, path, prop):
+def dt_node_int_prop(kconf, name, path, prop, unit=None):
"""
This function takes a 'path' and property name ('prop') looks for an EDT
node at that path. If it finds an EDT node, it will look to see if that
node has a property called 'prop' and if that 'prop' is an integer type
will return the value of the property 'prop' as either a string int or
string hex value, if not we return 0.
- """
+ The function will divide the value based on 'unit':
+ None No division
+ 'k' or 'K' divide by 1024 (1 << 10)
+ 'm' or 'M' divide by 1,048,576 (1 << 20)
+ 'g' or 'G' divide by 1,073,741,824 (1 << 30)
+ """
if doc_mode or edt is None:
return "0"
@@ -367,9 +384,9 @@
return "0"
if name == "dt_node_int_prop_int":
- return str(_node_int_prop(node, prop))
+ return str(_node_int_prop(node, prop, unit))
if name == "dt_node_int_prop_hex":
- return hex(_node_int_prop(node, prop))
+ return hex(_node_int_prop(node, prop, unit))
def dt_compat_enabled(kconf, _, compat):
@@ -472,8 +489,8 @@
"dt_node_reg_size_hex": (dt_node_reg, 1, 3),
"dt_node_has_bool_prop": (dt_node_has_bool_prop, 2, 2),
"dt_node_has_prop": (dt_node_has_prop, 2, 2),
- "dt_node_int_prop_int": (dt_node_int_prop, 2, 2),
- "dt_node_int_prop_hex": (dt_node_int_prop, 2, 2),
+ "dt_node_int_prop_int": (dt_node_int_prop, 2, 3),
+ "dt_node_int_prop_hex": (dt_node_int_prop, 2, 3),
"dt_nodelabel_has_compat": (dt_nodelabel_has_compat, 2, 2),
"dt_nodelabel_path": (dt_nodelabel_path, 1, 1),
"shields_list_contains": (shields_list_contains, 1, 1),