From: Philipp Zabel <p.zabel@pengutronix.de>
To: Grant Likely <grant.likely@linaro.org>
Cc: Russell King - ARM Linux <linux@arm.linux.org.uk>,
Mauro Carvalho Chehab <m.chehab@samsung.com>,
Rob Herring <robh+dt@kernel.org>,
Sylwester Nawrocki <s.nawrocki@samsung.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Tomi Valkeinen <tomi.valkeinen@ti.com>,
Kyungmin Park <kyungmin.park@samsung.com>,
linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
devicetree@vger.kernel.org,
Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
Philipp Zabel <philipp.zabel@gmail.com>
Subject: Re: [PATCH v4 1/3] [media] of: move graph helpers from drivers/media/v4l2-core to drivers/of
Date: Wed, 26 Feb 2014 16:24:57 +0100 [thread overview]
Message-ID: <1393428297.3248.92.camel@paszta.hi.pengutronix.de> (raw)
In-Reply-To: <20140226113729.A9D5AC40A89@trevor.secretlab.ca>
Hi Grant,
Am Mittwoch, den 26.02.2014, 11:37 +0000 schrieb Grant Likely:
[...]
> > drivers/media/v4l2-core/v4l2-of.c | 117 ----------------------
> > drivers/of/Makefile | 1 +
> > drivers/of/of_graph.c | 134 ++++++++++++++++++++++++++
>
> Nah. Just put it into drivers/of/base.c. This isn't a separate subsystem
> and the functions are pretty basic.
Ok.
[...]
> > +struct device_node *of_graph_get_next_endpoint(const struct device_node *parent,
> > + struct device_node *prev)
> > +{
> > + struct device_node *endpoint;
> > + struct device_node *port = NULL;
> > +
> > + if (!parent)
> > + return NULL;
> > +
> > + if (!prev) {
> > + struct device_node *node;
> > + /*
> > + * It's the first call, we have to find a port subnode
> > + * within this node or within an optional 'ports' node.
> > + */
> > + node = of_get_child_by_name(parent, "ports");
> > + if (node)
> > + parent = node;
> > +
> > + port = of_get_child_by_name(parent, "port");
>
> If you've got a "ports" node, then I would expect every single child to
> be a port. Should not need the _by_name variant.
The 'ports' node is optional. It is only needed if the parent node has
its own #address-cells and #size-cells properties. If the ports are
direct children of the device node, there might be other nodes than
ports:
device {
#address-cells = <1>;
#size-cells = <0>;
port@0 {
endpoint { ... };
};
port@1 {
endpoint { ... };
};
some-other-child { ... };
};
device {
#address-cells = <x>;
#size-cells = <y>;
ports {
#address-cells = <1>;
#size-cells = <0>;
port@0 {
endpoint { ... };
};
port@1 {
endpoint { ... };
};
};
some-other-child { ... };
};
The helper should find the two endpoints in both cases.
Tomi suggests an even more compact form for devices with just one port:
device {
endpoint { ... };
some-other-child { ... };
};
> It seems that this function is merely a helper to get all grandchildren
> of a node (with some very minor constraints). That could be generalized
> and simplified. If the function takes the "ports" node as an argument
> instead of the parent, then there is a greater likelyhood that other
> code can make use of it...
>
> Thinking further. I think the semantics of this whole feature basically
> boil down to this:
>
> #define for_each_grandchild_of_node(parent, child, grandchild) \
> for_each_child_of_node(parent, child) \
> for_each_child_of_node(child, grandchild)
>
> Correct? Or in this specific case:
>
> parent = of_get_child_by_name(np, "ports")
> for_each_grandchild_of_node(parent, child, grandchild) {
> ...
> }
Hmm, that would indeed be a bit more generic, but it doesn't handle the
optional 'ports' subnode and doesn't allow for other child nodes in the
device node.
> Finally, looking at the actual patch, is any of this actually needed.
> All of the users updated by this patch only ever handle a single
> endpoint. Have I read it correctly? Are there any users supporting
> multiple endpoints?
Yes, mainline currently only contains simple cases. I have posted i.MX6
patches that use this scheme for the output path:
http://www.spinics.net/lists/arm-kernel/msg310817.html
http://www.spinics.net/lists/arm-kernel/msg310821.html
> > +
> > + if (port) {
> > + /* Found a port, get an endpoint. */
> > + endpoint = of_get_next_child(port, NULL);
> > + of_node_put(port);
> > + } else {
> > + endpoint = NULL;
> > + }
> > +
> > + if (!endpoint)
> > + pr_err("%s(): no endpoint nodes specified for %s\n",
> > + __func__, parent->full_name);
> > + of_node_put(node);
>
> If you 'return endpoint' here, then the else block can go down a level.
Note that this patch is a straight move of existing code.
I can follow up with code beautification and ...
> > + } else {
> > + port = of_get_parent(prev);
> > + if (!port)
> > + /* Hm, has someone given us the root node ?... */
> > + return NULL;
>
> WARN_ONCE(). That's a very definite coding failure if that happens.
... with a fix for this.
> > +
> > + /* Avoid dropping prev node refcount to 0. */
> > + of_node_get(prev);
> > + endpoint = of_get_next_child(port, prev);
> > + if (endpoint) {
> > + of_node_put(port);
> > + return endpoint;
> > + }
> > +
> > + /* No more endpoints under this port, try the next one. */
> > + do {
> > + port = of_get_next_child(parent, port);
> > + if (!port)
> > + return NULL;
> > + } while (of_node_cmp(port->name, "port"));
> > +
> > + /* Pick up the first endpoint in this port. */
> > + endpoint = of_get_next_child(port, NULL);
> > + of_node_put(port);
> > + }
> > +
> > + return endpoint;
> > +}
> > +EXPORT_SYMBOL(of_graph_get_next_endpoint);
> > +
> > +/**
> > + * of_graph_get_remote_port_parent() - get remote port's parent node
> > + * @node: pointer to a local endpoint device_node
> > + *
> > + * Return: Remote device node associated with remote endpoint node linked
> > + * to @node. Use of_node_put() on it when done.
> > + */
> > +struct device_node *of_graph_get_remote_port_parent(
> > + const struct device_node *node)
> > +{
> > + struct device_node *np;
> > + unsigned int depth;
> > +
> > + /* Get remote endpoint node. */
> > + np = of_parse_phandle(node, "remote-endpoint", 0);
> > +
> > + /* Walk 3 levels up only if there is 'ports' node. */
>
> This needs a some explaining. My reading of the binding pattern is that
> it will always be a fixed number of levels. Why is this test fuzzy?
[...]
See above. The ports subnode level is optional. In most cases, the port
nodes will be direct children of the device node.
Walking up 3 levels from the endpoint node will return the device if
there was a ports node. If there is no ports node, we only have to walk
up two levels.
regards
Philipp
next prev parent reply other threads:[~2014-02-26 15:24 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-25 14:58 [PATCH v4 0/3] Move device tree graph parsing helpers to drivers/of Philipp Zabel
[not found] ` < 1393428297.3248.92.camel@paszta.hi.pengutronix.de>
[not found] ` <20140307171804. EF245C40A32@trevor.secretlab.ca>
[not found] ` < 1393340304-19005-2-git-send-email-p.zabel@pengutronix.de>
[not found] ` <20140226113729. A9D5AC40A89@trevor.secretlab.ca>
[not found] ` < 20140226113729.A9D5AC40A89@trevor.secretlab.ca>
[not found] ` < 1393340304-19005-4-git-send-email-p.zabel@pengutronix.de>
2014-02-25 14:58 ` [PATCH v4 1/3] [media] of: move graph helpers from drivers/media/v4l2-core " Philipp Zabel
2014-02-26 11:37 ` Grant Likely
2014-02-26 15:24 ` Philipp Zabel [this message]
2014-03-07 17:18 ` Grant Likely
2014-03-08 10:46 ` Tomi Valkeinen
2014-03-08 12:23 ` Grant Likely
2014-03-08 15:50 ` Laurent Pinchart
2014-03-20 22:23 ` Grant Likely
[not found] ` <20140320222347.CAB6DC412EA-WNowdnHR2B42iJbIjFUEsiwD8/FfD2ys@public.gmane.org>
2014-03-20 22:32 ` Laurent Pinchart
2014-03-21 13:37 ` Tomi Valkeinen
2014-03-21 14:10 ` Sylwester Nawrocki
[not found] ` <532C408D.4070002-l0cyMroinI0@public.gmane.org>
2014-03-21 14:13 ` Laurent Pinchart
2014-03-21 14:22 ` Tomi Valkeinen
[not found] ` <532C4B3C.4030406-l0cyMroinI0@public.gmane.org>
2014-03-21 14:30 ` Laurent Pinchart
2014-03-10 6:34 ` Tomi Valkeinen
2014-03-20 22:26 ` Grant Likely
2014-03-08 12:07 ` Philipp Zabel
[not found] ` <CA+gwMcfgKre8S4KHPvTVuAuz672aehGrN1UfFpwKAueTAcrMZQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-08 15:54 ` Laurent Pinchart
2014-03-10 6:00 ` Tomi Valkeinen
[not found] ` <531D54E2.8030303-l0cyMroinI0@public.gmane.org>
2014-03-10 13:57 ` Laurent Pinchart
2014-03-10 8:58 ` Andrzej Hajda
[not found] ` <531D7E9F.3090708-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
2014-03-10 9:29 ` Tomi Valkeinen
2014-03-10 11:42 ` Laurent Pinchart
2014-03-11 13:55 ` Andrzej Hajda
2014-03-20 22:33 ` Grant Likely
2014-02-25 14:58 ` [PATCH v4 2/3] [media] of: move common endpoint parsing " Philipp Zabel
2014-02-25 14:58 ` [PATCH v4 3/3] Documentation: of: Document graph bindings Philipp Zabel
2014-02-26 13:14 ` Tomi Valkeinen
2014-02-26 14:57 ` Philipp Zabel
[not found] ` <1393426623.3248.70.camel-+qGW7pzALmz7o/J7KWpOmN53zsg1cpMQ@public.gmane.org>
2014-02-26 14:50 ` Tomi Valkeinen
2014-02-26 15:47 ` Philipp Zabel
[not found] ` <1393429676.3248.110.camel-+qGW7pzALmz7o/J7KWpOmN53zsg1cpMQ@public.gmane.org>
2014-02-27 8:08 ` Tomi Valkeinen
2014-02-27 10:52 ` Philipp Zabel
2014-02-27 10:41 ` Tomi Valkeinen
[not found] ` < 530DFF4C.8080807@ti.com>
[not found] ` <530DFF4C.8080807-l0cyMroinI0@public.gmane.org>
2014-03-07 18:11 ` Grant Likely
2014-03-08 9:35 ` Tomi Valkeinen
2014-03-08 12:25 ` Grant Likely
2014-03-08 15:43 ` Laurent Pinchart
2014-03-10 6:53 ` Tomi Valkeinen
[not found] ` <531D6178.3070906-l0cyMroinI0@public.gmane.org>
2014-03-11 13:47 ` Sylwester Nawrocki
2014-03-07 17:20 ` Grant Likely
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1393428297.3248.92.camel@paszta.hi.pengutronix.de \
--to=p.zabel@pengutronix.de \
--cc=devicetree@vger.kernel.org \
--cc=g.liakhovetski@gmx.de \
--cc=grant.likely@linaro.org \
--cc=kyungmin.park@samsung.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=m.chehab@samsung.com \
--cc=philipp.zabel@gmail.com \
--cc=robh+dt@kernel.org \
--cc=s.nawrocki@samsung.com \
--cc=tomi.valkeinen@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).