Skip to content

Commit

Permalink
dts: edtlib: Add 'type: path' for path references
Browse files Browse the repository at this point in the history
Add binding support for a 'path' property type, for properties that are
assigned node paths. Usually, paths are assigned with path references
like 'foo = &label' (common in /chosen), but plain strings are accepted
as well as long as they're valid paths.

The 'path' type is mostly for completeness at this point, but might be
useful for #21623.
The support is there already in dtlib.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
  • Loading branch information
ulfalizer authored and galak committed Jan 8, 2020
1 parent 960779a commit 23a5b49
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
12 changes: 11 additions & 1 deletion dts/binding-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,19 @@ on-bus: <string describing bus type, e.g. "i2c">
# All phandle-array properties support mapping through *-map properties,
# e.g. gpio-map. See the devicetree spec.
#
# - 'type: path' is for properties that are assigned a path. Usually, this
# would be done with a path reference:
#
# foo = &label;
#
# Plain strings are accepted too, and are verified to be a path to an
# existing node:
#
# foo = "/path/to/some/node";
#
# - 'type: compound' is a catch-all for more complex types, e.g.
#
# foo = <&label1>, [01 02];
# foo = <&label>, [01 02];
#
# 'type: array' and the other array types also allow splitting the value into
# several <> blocks, e.g. like this:
Expand Down
10 changes: 7 additions & 3 deletions scripts/dts/edtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,9 @@ def _prop_val(self, name, prop_type, required, default):

return self._standard_phandle_val_list(prop)

if prop_type == "path":
return self.edt._node2enode[prop.to_path()]

# prop_type == "compound". We have already checked that the 'type:'
# value is valid, in _check_binding().
#
Expand Down Expand Up @@ -1438,7 +1441,8 @@ class Property:
- For 'type: int/array/string/string-array', 'val' is what you'd expect
(a Python integer or string, or a list of them)
- For 'type: phandle', 'val' is the pointed-to Node instance
- For 'type: phandle' and 'type: path', 'val' is the pointed-to Node
instance
- For 'type: phandles', 'val' is a list of the pointed-to Node
instances
Expand Down Expand Up @@ -1651,7 +1655,7 @@ def _check_prop_type_and_default(prop_name, prop_type, required, default,

ok_types = {"boolean", "int", "array", "uint8-array", "string",
"string-array", "phandle", "phandles", "phandle-array",
"compound"}
"path", "compound"}

if prop_type not in ok_types:
_err("'{}' in 'properties:' in {} has unknown type '{}', expected one "
Expand All @@ -1670,7 +1674,7 @@ def _check_prop_type_and_default(prop_name, prop_type, required, default,
return

if prop_type in {"boolean", "compound", "phandle", "phandles",
"phandle-array"}:
"phandle-array", "path"}:
_err("'default:' can't be combined with 'type: {}' for '{}' in "
"'properties:' in {}".format(prop_type, prop_name, binding_path))

Expand Down
3 changes: 3 additions & 0 deletions scripts/dts/test-bindings/props.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ properties:
# too
foo-gpios:
type: phandle-array

path:
type: path
1 change: 1 addition & 0 deletions scripts/dts/test.dts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
phandle-refs = < &{/props/ctrl-1} &{/props/ctrl-2} >;
phandle-array-foos = < &{/props/ctrl-1} 1 &{/props/ctrl-2} 2 3 >;
foo-gpios = < &{/props/ctrl-1} 1 >;
path = &{/props/ctrl-1};

ctrl-1 {
compatible = "phandle-array-controller-1";
Expand Down
3 changes: 3 additions & 0 deletions scripts/dts/testedtlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ def verify_streq(actual, expected):
verify_streq(edt.get_node("/props").props["foo-gpios"],
"<Property, name: foo-gpios, type: phandle-array, value: [<ControllerAndData, controller: <Node /props/ctrl-1 in 'test.dts', binding test-bindings/phandle-array-controller-1.yaml>, data: OrderedDict([('gpio-one', 1)])>]>")

verify_streq(edt.get_node("/props").props["path"],
"<Property, name: path, type: path, value: <Node /props/ctrl-1 in 'test.dts', binding test-bindings/phandle-array-controller-1.yaml>>")

#
# Test <prefix>-map, via gpio-map (the most common case)
#
Expand Down

0 comments on commit 23a5b49

Please sign in to comment.