lkml.org 
[lkml]   [2020]   [Nov]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 07/18] software_node: Add support for fwnode_graph*() family of functions
From
Date
Hi Laurent

On 30/11/2020 16:25, Laurent Pinchart wrote:
> Hi Daniel and Heikki,
>
> Thank you for the patch.
>
> On Mon, Nov 30, 2020 at 01:31:18PM +0000, Daniel Scally wrote:
>> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>>
>> From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>>
> There seems to be one From: line too many. You can drop the one in the
> commit message, git-format-patch will add it automatically.
Ah! Thanks, sorry about that
>> This implements the remaining .graph_* callbacks in the
>> fwnode operations vector for the software nodes. That makes
> s/vector/structure/ ?
Yeah, sure.
>> the fwnode_graph*() functions available in the drivers also
>> when software nodes are used.
>>
>> The implementation tries to mimic the "OF graph" as much as
>> possible, but there is no support for the "reg" device
>> property. The ports will need to have the index in their
>> name which starts with "port" (for example "port0", "port1",
>> ...) and endpoints will use the index of the software node
>> that is given to them during creation. The port nodes can
>> also be grouped under a specially named "ports" subnode,
>> just like in DT, if necessary.
> I'm not very familiar with swnodes, but could we name ports port@n
> instead of portn to mimic OF nodes ?
Yes, I don't see any reason why not.
>
>> The remote-endpoints are reference properties under the
>> endpoint nodes that are named "remote-endpoint".
>>
>> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
>> Co-developed-by: Daniel Scally <djrscally@gmail.com>
>> Signed-off-by: Daniel Scally <djrscally@gmail.com>
>> ---
>> changes since RFC v3:
>> - Simplified software_node_get_next_endpoint() a little
>> - Squared away references in software_node_get_next_endpoint()
>> and swnode_graph_find_next_port(), since they were affected by
>> the change to the earlier patch that had *get_next_child() also
>> put the previous reference.
>> - Dropped Andy's R-b, since the code changed.
>> changes in RFC v3:
>> - removed software_node_device_is_available
>> - moved the change to software_node_get_next_child to a separate
>> patch
>> - switched to use fwnode_handle_put() in graph_get_next_endpoint()
>> instead of software_node_put()
>>
>> changes in RFC v2:
>> - added software_node_device_is_available
>> - altered software_node_get_next_child to get references
>> - altered software_node_get_next_endpoint to release references
>> to ports and avoid passing invalid combinations of swnodes to
>> software_node_get_next_child
>> - altered swnode_graph_find_next_port to release port rather than
>> old
>>
>> drivers/base/swnode.c | 110 +++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 109 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
>> index 9bd0bb77ad5b..0c7a8d6b9ea8 100644
>> --- a/drivers/base/swnode.c
>> +++ b/drivers/base/swnode.c
>> @@ -540,6 +540,110 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
>> return 0;
>> }
>>
>> +static struct fwnode_handle *
>> +swnode_graph_find_next_port(const struct fwnode_handle *parent,
>> + struct fwnode_handle *port)
>> +{
>> + struct fwnode_handle *old = port;
>> +
>> + while ((port = software_node_get_next_child(parent, old))) {
>> + if (!strncmp(to_swnode(port)->node->name, "port", 4))
>> + return port;
>> + old = port;
>> + }
>> +
>> + return NULL;
>> +}
>> +
>> +static struct fwnode_handle *
>> +software_node_graph_get_next_endpoint(const struct fwnode_handle *fwnode,
>> + struct fwnode_handle *endpoint)
>> +{
>> + struct swnode *swnode = to_swnode(fwnode);
>> + struct fwnode_handle *old = endpoint;
>> + struct fwnode_handle *parent;
>> + struct fwnode_handle *port;
>> +
>> + if (!swnode)
>> + return NULL;
>> +
>> + if (endpoint) {
>> + port = software_node_get_parent(endpoint);
>> + parent = software_node_get_parent(port);
>> + } else {
>> + parent = software_node_get_named_child_node(fwnode, "ports");
>> + if (!parent)
>> + parent = software_node_get(&swnode->fwnode);
>> +
>> + port = swnode_graph_find_next_port(parent, NULL);
>> + }
>> +
>> + for (; port; port = swnode_graph_find_next_port(parent, port)) {
>> + endpoint = software_node_get_next_child(port, old);
>> + if (endpoint) {
>> + fwnode_handle_put(port);
>> + break;
>> + }
>> +
>> + /* No more endpoints for that port, so stop passing old */
>> + old = NULL;
>> + }
>> +
>> + fwnode_handle_put(parent);
>> +
>> + return endpoint;
>> +}
>> +
>> +static struct fwnode_handle *
>> +software_node_graph_get_remote_endpoint(const struct fwnode_handle *fwnode)
>> +{
>> + struct swnode *swnode = to_swnode(fwnode);
>> + const struct software_node_ref_args *ref;
>> + const struct property_entry *prop;
>> +
>> + if (!swnode)
>> + return NULL;
>> +
>> + prop = property_entry_get(swnode->node->properties, "remote-endpoint");
>> + if (!prop || prop->type != DEV_PROP_REF || prop->is_inline)
>> + return NULL;
>> +
>> + ref = prop->pointer;
>> +
>> + return software_node_get(software_node_fwnode(ref[0].node));
>> +}
>> +
>> +static struct fwnode_handle *
>> +software_node_graph_get_port_parent(struct fwnode_handle *fwnode)
>> +{
>> + struct swnode *swnode = to_swnode(fwnode);
>> + struct fwnode_handle *parent;
>> +
>> + if (!strcmp(swnode->parent->node->name, "ports"))
>> + parent = &swnode->parent->parent->fwnode;
>> + else
>> + parent = &swnode->parent->fwnode;
>> +
>> + return software_node_get(parent);
>> +}
>> +
>> +static int
>> +software_node_graph_parse_endpoint(const struct fwnode_handle *fwnode,
>> + struct fwnode_endpoint *endpoint)
>> +{
>> + struct swnode *swnode = to_swnode(fwnode);
>> + int ret;
>> +
>> + ret = kstrtou32(swnode->parent->node->name + 4, 10, &endpoint->port);
> If we use port@, s/4/5/. But I suppose we also want to support the case
> where a single port is used, with its name set to "port" ? The logic
> would then need to be a tad more complex. Not sure if the consistency is
> worth the additional complexity, up to you.
I'm conflicted; consistency is good but in my mind keeping the name as
"port@0" for a single port rather than dropping the suffix is the better
approach anyway.
>> + if (ret)
>> + return ret;
>> +
>> + endpoint->id = swnode->id;
>> + endpoint->local_fwnode = fwnode;
>> +
>> + return 0;
>> +}
>> +
>> static const struct fwnode_operations software_node_ops = {
>> .get = software_node_get,
>> .put = software_node_put,
>> @@ -551,7 +655,11 @@ static const struct fwnode_operations software_node_ops = {
>> .get_parent = software_node_get_parent,
>> .get_next_child_node = software_node_get_next_child,
>> .get_named_child_node = software_node_get_named_child_node,
>> - .get_reference_args = software_node_get_reference_args
>> + .get_reference_args = software_node_get_reference_args,
>> + .graph_get_next_endpoint = software_node_graph_get_next_endpoint,
>> + .graph_get_remote_endpoint = software_node_graph_get_remote_endpoint,
>> + .graph_get_port_parent = software_node_graph_get_port_parent,
>> + .graph_parse_endpoint = software_node_graph_parse_endpoint,
>> };
>>
>> /* -------------------------------------------------------------------------- */

\
 
 \ /
  Last update: 2020-12-01 00:36    [W:0.670 / U:0.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site