Skip to content

Commit

Permalink
UPSTREAM: dm: core: Add ofnode_for_each_subnode()
Browse files Browse the repository at this point in the history
Add a convenience macro to iterate over subnodes of a node. Make use of
this where appropriate in the code.

Change-Id: Iae0fb554472d0b5819d26becbbcf8909ff891514
Signed-off-by: Simon Glass <[email protected]>
Signed-off-by: Kever Yang <[email protected]>
(cherry picked from commit 3991f42)
  • Loading branch information
sjg20 authored and keveryang committed Jan 16, 2018
1 parent 0c69cd5 commit 17c82fd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
8 changes: 2 additions & 6 deletions arch/arm/mach-tegra/xusb-padctl-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,7 @@ tegra_xusb_padctl_config_parse_dt(struct tegra_xusb_padctl *padctl,

config->name = ofnode_get_name(node);

for (subnode = ofnode_first_subnode(node);
ofnode_valid(subnode);
subnode = ofnode_next_subnode(subnode)) {
ofnode_for_each_subnode(subnode, node) {
struct tegra_xusb_padctl_group *group;
int err;

Expand Down Expand Up @@ -256,9 +254,7 @@ static int tegra_xusb_padctl_parse_dt(struct tegra_xusb_padctl *padctl,
return err;
}

for (subnode = ofnode_first_subnode(node);
ofnode_valid(subnode);
subnode = ofnode_next_subnode(subnode)) {
ofnode_for_each_subnode(subnode, node) {
struct tegra_xusb_padctl_config *config = &padctl->config;

debug("%s: subnode=%s\n", __func__, ofnode_get_name(subnode));
Expand Down
9 changes: 5 additions & 4 deletions drivers/core/ofnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,11 @@ int ofnode_decode_display_timing(ofnode parent, int index,
if (!ofnode_valid(timings))
return -EINVAL;

for (i = 0, node = ofnode_first_subnode(timings);
ofnode_valid(node) && i != index;
node = ofnode_first_subnode(node))
i++;
i = 0;
ofnode_for_each_subnode(node, timings) {
if (i++ == index)
break;
}

if (!ofnode_valid(node))
return -EINVAL;
Expand Down
3 changes: 1 addition & 2 deletions drivers/misc/cros_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,7 @@ int cros_ec_decode_ec_flash(struct udevice *dev, struct fdt_cros_ec *config)

config->flash_erase_value = ofnode_read_s32_default(flash_node,
"erase-value", -1);
for (node = ofnode_first_subnode(flash_node); ofnode_valid(node);
node = ofnode_next_subnode(node)) {
ofnode_for_each_subnode(node, flash_node) {
const char *name = ofnode_get_name(node);
enum ec_flash_region region;

Expand Down
4 changes: 1 addition & 3 deletions drivers/power/pmic/pmic-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ int pmic_bind_children(struct udevice *pmic, ofnode parent,
debug("%s for '%s' at node offset: %d\n", __func__, pmic->name,
dev_of_offset(pmic));

for (node = ofnode_first_subnode(parent);
ofnode_valid(node);
node = ofnode_next_subnode(node)) {
ofnode_for_each_subnode(node, parent) {
node_name = ofnode_get_name(node);

debug("* Found child node: '%s'\n", node_name);
Expand Down
24 changes: 24 additions & 0 deletions include/dm/ofnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -628,4 +628,28 @@ int ofnode_read_resource(ofnode node, uint index, struct resource *res);
int ofnode_read_resource_byname(ofnode node, const char *name,
struct resource *res);

/**
* ofnode_for_each_subnode() - iterate over all subnodes of a parent
*
* @node: child node (ofnode, lvalue)
* @parent: parent node (ofnode)
*
* This is a wrapper around a for loop and is used like so:
*
* ofnode node;
*
* ofnode_for_each_subnode(node, parent) {
* Use node
* ...
* }
*
* Note that this is implemented as a macro and @node is used as
* iterator in the loop. The parent variable can be a constant or even a
* literal.
*/
#define ofnode_for_each_subnode(node, parent) \
for (node = ofnode_first_subnode(parent); \
ofnode_valid(node); \
node = ofnode_next_subnode(node))

#endif

0 comments on commit 17c82fd

Please sign in to comment.