fdt_support: Add fdt_for_each_node_by_compatible() helper macro
Add macro fdt_for_each_node_by_compatible() to allow iterating over
fdt nodes by compatible string.
Convert various usages of
off = fdt_node_offset_by_compatible(fdt, start, compat);
while (off > 0) {
code();
off = fdt_node_offset_by_compatible(fdt, off, compat);
}
and similar, to
fdt_for_each_node_by_compatible(off, fdt, start, compat)
code();
Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/pci/pcie_layerscape_fixup_common.c b/drivers/pci/pcie_layerscape_fixup_common.c
index faccf6c..095874a 100644
--- a/drivers/pci/pcie_layerscape_fixup_common.c
+++ b/drivers/pci/pcie_layerscape_fixup_common.c
@@ -48,8 +48,7 @@
const fdt32_t *prop;
u32 ob_wins, ib_wins;
- off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
- while (off != -FDT_ERR_NOTFOUND) {
+ fdt_for_each_node_by_compatible(off, fdt, -1, "fsl,lx2160a-pcie") {
fdt_setprop(fdt, off, "compatible", "fsl,ls2088a-pcie",
strlen("fsl,ls2088a-pcie") + 1);
@@ -89,14 +88,10 @@
fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
fdt_delprop(fdt, off, "apio-wins");
fdt_delprop(fdt, off, "ppio-wins");
- off = fdt_node_offset_by_compatible(fdt, off,
- "fsl,lx2160a-pcie");
}
/* Fixup PCIe EP nodes */
- off = -1;
- off = fdt_node_offset_by_compatible(fdt, off, "fsl,lx2160a-pcie-ep");
- while (off != -FDT_ERR_NOTFOUND) {
+ fdt_for_each_node_by_compatible(off, fdt, -1, "fsl,lx2160a-pcie-ep") {
fdt_setprop_string(fdt, off, "compatible",
"fsl,lx2160ar2-pcie-ep");
prop = fdt_getprop(fdt, off, "apio-wins", NULL);
@@ -113,9 +108,6 @@
fdt_setprop_u32(fdt, off, "num-ib-windows", ib_wins);
fdt_setprop_u32(fdt, off, "num-ob-windows", ob_wins);
fdt_delprop(fdt, off, "apio-wins");
-
- off = fdt_node_offset_by_compatible(fdt, off,
- "fsl,lx2160a-pcie-ep");
}
return 0;