lkml.org 
[lkml]   [2021]   [Dec]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 3/8] device property: Helper to match multiple connections
On 28-12-21, 09:04, Bjorn Andersson wrote:
> On Tue 28 Dec 05:09 PST 2021, Dmitry Baryshkov wrote:
>
> > On 28/12/2021 08:21, Bjorn Andersson wrote:
> > > In some cases multiple connections with the same connection id
> > > needs to be resolved from a fwnode graph.
> > >
> > > One such example is when separate hardware is used for performing muxing and/or
> > > orientation switching of the SuperSpeed and SBU lines in a USB-C
> > > connector. In this case the connector needs to belong to a graph with
> > > multiple matching remote endpoints, and the TypeC controller needs to be
> > > able to resolve them both.
> > >
> > > Add a new API that allows this kind of lookup.
> > >
> > > Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> > > ---
> > > drivers/base/property.c | 94 ++++++++++++++++++++++++++++++++++++++++
> > > include/linux/property.h | 5 +++
> > > 2 files changed, 99 insertions(+)
> > >
> > > diff --git a/drivers/base/property.c b/drivers/base/property.c
> > > index cbe4fa298413..0aa0296fd991 100644
> > > --- a/drivers/base/property.c
> > > +++ b/drivers/base/property.c
> > > @@ -1180,6 +1180,36 @@ fwnode_graph_devcon_match(struct fwnode_handle *fwnode, const char *con_id,
> > > return NULL;
> > > }
> > > +static unsigned int fwnode_graph_devcon_matches(struct fwnode_handle *fwnode,
> > > + const char *con_id, void *data,
> > > + devcon_match_fn_t match,
> > > + void **matches,
> > > + unsigned int matches_len)
> > > +{
> > > + struct fwnode_handle *node;
> > > + struct fwnode_handle *ep;
> > > + unsigned int count = 0;
> > > + void *ret;
> > > +
> > > + fwnode_graph_for_each_endpoint(fwnode, ep) {
> > > + if (count >= matches_len) {
> > > + fwnode_handle_put(ep);
> > > + return count;
> > > + }
> > > +
> > > + node = fwnode_graph_get_remote_port_parent(ep);
> > > + if (!fwnode_device_is_available(node))
> > > + continue;
> > > +
> > > + ret = match(node, con_id, data);
> > > + fwnode_handle_put(node);
> > > +
> > > + if (ret)
> > > + matches[count++] = ret;
> > > + }
> > > + return count;
> > > +}
> >
> > This API doesn't let it's user know if there are more matches found in the
> > device tree or not. I'd suggest to add 'count' mode that would return the
> > amount of found matches if (matches == NULL) && (matches_len == 0).

But the API does call each match
>
> Unfortunately in this code path we don't know how to "free" the objects
> returned by match(), e.g. see how typec_switch_match() returns wrapper
> of a refcounted device.
>
> So we must return all the match results to the caller to it can free
> things up based on its knowledge of what matches[] actually contains..

ACPI walk has similar APIs, I can think of acpi_walk_namespace() which I
have used in past and does similar walk in namespace but for devices and
calls the match()

--
~Vinod

\
 
 \ /
  Last update: 2021-12-29 06:41    [W:0.090 / U:0.036 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site