[PATCH v7 01/16] device property: Add fwnode_graph_get_port_by_id()

Sakari Ailus sakari.ailus at linux.intel.com
Mon Aug 10 01:26:09 PDT 2026


Hi Chen-Yu,

On Fri, Jul 24, 2026 at 04:43:10PM +0800, Chen-Yu Tsai wrote:
> In some cases the driver needs a reference to the port firmware node.
> Once such case is the upcoming USB power sequencing integration. The
> USB hub port is tied to the corresponding port firmware node if it
> exists.
> 
> Provide a helper for this.
> 
> Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski at oss.qualcomm.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko at linux.intel.com>
> Signed-off-by: Chen-Yu Tsai <wenst at chromium.org>
> ---
> Changes since v5:
> - Dropped left-over declaration in header (Sashiko)
> 
> Changes since v4:
> - Added flags parameter so users can specify whether incomplete ports
>   are returned or not (Sashiko)
> 
> Changes since v2:
> - Moved "Return:" kernel-doc section to the end. (Andy)
> 
> Changes since v1:
> - New patch
> ---
>  drivers/base/property.c  | 29 +++++++++++++++++++++++++++++
>  include/linux/property.h |  2 ++
>  2 files changed, 31 insertions(+)
> 
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index 9387bb83eb54..950defc0c55a 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -1346,6 +1346,35 @@ int fwnode_graph_parse_endpoint(const struct fwnode_handle *fwnode,
>  }
>  EXPORT_SYMBOL(fwnode_graph_parse_endpoint);
>  
> +/**
> + * fwnode_graph_get_port_by_id - get the port matching a given id
> + * @fwnode: parent fwnode_handle containing the graph
> + * @id: id of the port
> + * @flags: fwnode lookup flags
> + *
> + * The caller is responsible for calling fwnode_handle_put() on the returned
> + * fwnode pointer.
> + *
> + * Does not return ports that belong to disabled devices or endpoints that
> + * are unconnected, unless FWNODE_GRAPH_DEVICE_DISABLED is passed in @flags.

The function also does not return ports that have no endpoints. I don't
think it'd be very useful to do that either, instead this should be still
documented.

> + *
> + * Return: A 'port' firmware node pointer with refcount incremented.
> + */
> +struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode,
> +						  u32 id,
> +						  unsigned long flags)
> +{
> +	struct fwnode_handle *ep;
> +
> +	ep = fwnode_graph_get_endpoint_by_id(fwnode, id, 0,
> +					     flags | FWNODE_GRAPH_ENDPOINT_NEXT);
> +	if (!ep)
> +		return NULL;
> +
> +	return fwnode_get_next_parent(ep);
> +}
> +EXPORT_SYMBOL_GPL(fwnode_graph_get_port_by_id);
> +
>  const void *device_get_match_data(const struct device *dev)
>  {
>  	return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
> diff --git a/include/linux/property.h b/include/linux/property.h
> index 14c304db4664..01ea010cb2f9 100644
> --- a/include/linux/property.h
> +++ b/include/linux/property.h
> @@ -505,6 +505,8 @@ int fwnode_get_phy_mode(const struct fwnode_handle *fwnode);
>  
>  void __iomem *fwnode_iomap(struct fwnode_handle *fwnode, int index);
>  
> +struct fwnode_handle *fwnode_graph_get_port_by_id(struct fwnode_handle *fwnode, u32 id,
> +						  unsigned long flags);
>  struct fwnode_handle *fwnode_graph_get_next_endpoint(
>  	const struct fwnode_handle *fwnode, struct fwnode_handle *prev);
>  struct fwnode_handle *

-- 
Kind regards,

Sakari Ailus



More information about the linux-arm-kernel mailing list