Message ID | 1466808476-32690-11-git-send-email-benh@kernel.crashing.org |
---|---|
State | Accepted |
Headers | show |
On Sat, 2016-06-25 at 08:47 +1000, Benjamin Herrenschmidt wrote: > This accessor tests the "status" property allowing us to represent > disabled devices in the device-tree. It will be used by PHB4 initially > but its usage could be made more widespread. > > Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> > --- > core/device.c | 10 ++++++++++ > include/device.h | 2 ++ > 2 files changed, 12 insertions(+) > > diff --git a/core/device.c b/core/device.c > index 4818d40..9e7ef0d 100644 > --- a/core/device.c > +++ b/core/device.c > @@ -910,3 +910,13 @@ u64 dt_translate_address(const struct dt_node *node, unsigned int index, > /* XXX TODO */ > return dt_get_address(node, index, out_size); > } > + > +bool dt_node_is_enabled(struct dt_node *node) > +{ > + const struct dt_property *p = dt_find_property(node, "status"); > + > + if (!p) > + return true; > + > + return p->len > 1 && p->prop[0] == 'o' && p->prop[1] == 'k'; Minor nit... Should this just be p->len == 2 rather than > 1 ? Otherwise we could match on 'ok_everyone_dont_use_this_really_broken_node'. Some braces would be nice too. Mikey > +} > diff --git a/include/device.h b/include/device.h > index 28dbd5d..ed4fc46 100644 > --- a/include/device.h > +++ b/include/device.h > @@ -161,6 +161,8 @@ struct dt_node *dt_find_compatible_node_on_chip(struct dt_node *root, > for (node = NULL; \ > (node = dt_find_compatible_node_on_chip(root, node,\ > compat, chip_id)) != NULL;) > +/* Check status property */ > +bool dt_node_is_enabled(struct dt_node *node); > > /* Build the full path for a node. Return a new block of memory, caller > * shall free() it
On Wed, 2016-07-06 at 16:47 +1000, Michael Neuling wrote: > Minor nit... Should this just be p->len == 2 rather than > 1 ? > Otherwise > we could match on 'ok_everyone_dont_use_this_really_broken_node'. > > Some braces would be nice too. That's what Linux does. Some device trees contain "okay" Cheers, Ben.
On Wed, 2016-07-06 at 17:19 +1000, Benjamin Herrenschmidt wrote: > On Wed, 2016-07-06 at 16:47 +1000, Michael Neuling wrote: > > > > Minor nit... Should this just be p->len == 2 rather than > 1 ? > > Otherwise > > we could match on 'ok_everyone_dont_use_this_really_broken_node'. > > > > Some braces would be nice too. > That's what Linux does. Some device trees contain "okay" Arrh, ok... eer ... okay.. umm.. whatever. Acked-by: Michael Neuling <mikey@neuling.org>
diff --git a/core/device.c b/core/device.c index 4818d40..9e7ef0d 100644 --- a/core/device.c +++ b/core/device.c @@ -910,3 +910,13 @@ u64 dt_translate_address(const struct dt_node *node, unsigned int index, /* XXX TODO */ return dt_get_address(node, index, out_size); } + +bool dt_node_is_enabled(struct dt_node *node) +{ + const struct dt_property *p = dt_find_property(node, "status"); + + if (!p) + return true; + + return p->len > 1 && p->prop[0] == 'o' && p->prop[1] == 'k'; +} diff --git a/include/device.h b/include/device.h index 28dbd5d..ed4fc46 100644 --- a/include/device.h +++ b/include/device.h @@ -161,6 +161,8 @@ struct dt_node *dt_find_compatible_node_on_chip(struct dt_node *root, for (node = NULL; \ (node = dt_find_compatible_node_on_chip(root, node,\ compat, chip_id)) != NULL;) +/* Check status property */ +bool dt_node_is_enabled(struct dt_node *node); /* Build the full path for a node. Return a new block of memory, caller * shall free() it
This accessor tests the "status" property allowing us to represent disabled devices in the device-tree. It will be used by PHB4 initially but its usage could be made more widespread. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> --- core/device.c | 10 ++++++++++ include/device.h | 2 ++ 2 files changed, 12 insertions(+)