linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacopo Mondi <jacopo@jmondi.org>
To: Steve Longerbeam <slongerbeam@gmail.com>
Cc: linux-media@vger.kernel.org
Subject: Re: [PATCH v2 02/23] media: entity: Modify default behavior of media_entity_get_fwnode_pad
Date: Thu, 28 Nov 2019 13:04:11 +0100	[thread overview]
Message-ID: <20191128120411.x7avm62lyq36gdya@uno.localdomain> (raw)
In-Reply-To: <20191124190703.12138-3-slongerbeam@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5616 bytes --]

Hi Steve,

On Sun, Nov 24, 2019 at 11:06:42AM -0800, Steve Longerbeam wrote:
> Modify the default behavior of media_entity_get_fwnode_pad() (when the
> entity does not provide the get_fwnode_pad op) to first assume the entity
> implements a 1:1 mapping between fwnode port number and media pad index.
>
> If the 1:1 mapping is not valid, e.g. the port number falls outside the
> entity's pad index range, or the pad at that port number doesn't match the
> given direction_flags, fall-back to the previous behavior that searches
> the entity for the first pad that matches the given direction_flags.
>
> The previous default behavior can choose the wrong pad for entities with
> multiple sink or source pads. With this change the function will choose
> the correct pad index if the entity implements a 1:1 port to pad mapping
> at that port.
>
> Add some comments to the @get_fwnode_pad operation to make it more clear
> under what conditions entities must implement the operation.
>

I understand the rationale behind this, but this is not better than
assuming the first pad with a matching direction flag is the right
one imho.

This should help for subdevices with multiple sink/sources, but they
should really implement get_fwnode_pad() instead of relying on yet another
assumption as we had "the first pad with matching direction is the right
one" and now we also have "the pad at index endpoint.port is the right
one". As you've been testing it, how many of the current mailine
supported devices actually need this and could not:
1) Implement get_fwnode_pad() as you are doing for adv748x
2) Keep assuming the first pad with a matching flag is the correct one

Thanks
   j
> Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
> ---
>  drivers/media/mc/mc-entity.c | 25 ++++++++++++++++++++-----
>  include/media/media-entity.h | 21 +++++++++++++++------
>  2 files changed, 35 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/media/mc/mc-entity.c b/drivers/media/mc/mc-entity.c
> index c333320f790a..47a39d9383d8 100644
> --- a/drivers/media/mc/mc-entity.c
> +++ b/drivers/media/mc/mc-entity.c
> @@ -370,22 +370,37 @@ int media_entity_get_fwnode_pad(struct media_entity *entity,
>  				unsigned long direction_flags)
>  {
>  	struct fwnode_endpoint endpoint;
> -	unsigned int i;
>  	int ret;
>
> +	ret = fwnode_graph_parse_endpoint(fwnode, &endpoint);
> +	if (ret)
> +		return ret;
> +
>  	if (!entity->ops || !entity->ops->get_fwnode_pad) {
> +		unsigned int i;
> +
> +		/*
> +		 * for the default case, first try a 1:1 mapping between
> +		 * fwnode port number and pad index.
> +		 */
> +		ret = endpoint.port;
> +		if (ret < entity->num_pads &&
> +		    (entity->pads[ret].flags & direction_flags))
> +			return ret;
> +
> +		/*
> +		 * if that didn't work search the entity for the first
> +		 * pad that matches the @direction_flags.
> +		 */
>  		for (i = 0; i < entity->num_pads; i++) {
>  			if (entity->pads[i].flags & direction_flags)
>  				return i;
>  		}
>
> +		/* else fail */
>  		return -ENXIO;
>  	}
>
> -	ret = fwnode_graph_parse_endpoint(fwnode, &endpoint);
> -	if (ret)
> -		return ret;
> -
>  	ret = entity->ops->get_fwnode_pad(entity, &endpoint);
>  	if (ret < 0)
>  		return ret;
> diff --git a/include/media/media-entity.h b/include/media/media-entity.h
> index cde80ad029b7..ed00adb4313b 100644
> --- a/include/media/media-entity.h
> +++ b/include/media/media-entity.h
> @@ -199,6 +199,12 @@ struct media_pad {
>   * @get_fwnode_pad:	Return the pad number based on a fwnode endpoint or
>   *			a negative value on error. This operation can be used
>   *			to map a fwnode to a media pad number. Optional.
> + *			Entities do not need to implement this operation
> + *			unless two conditions are met:
> + *			- the entity has more than one sink and/or source
> + *			  pad, _and_
> + *			- the entity does not implement a 1:1 mapping of
> + *			  fwnode port numbers to pad indexes.
>   * @link_setup:		Notify the entity of link changes. The operation can
>   *			return an error, in which case link setup will be
>   *			cancelled. Optional.
> @@ -858,21 +864,24 @@ struct media_link *media_entity_find_link(struct media_pad *source,
>  struct media_pad *media_entity_remote_pad(const struct media_pad *pad);
>
>  /**
> - * media_entity_get_fwnode_pad - Get pad number from fwnode
> + * media_entity_get_fwnode_pad - Get pad number from an endpoint fwnode
>   *
>   * @entity: The entity
> - * @fwnode: Pointer to the fwnode_handle which should be used to find the pad
> + * @fwnode: Pointer to the endpoint fwnode_handle which should be used to
> + *          find the pad
>   * @direction_flags: Expected direction of the pad, as defined in
>   *		     :ref:`include/uapi/linux/media.h <media_header>`
>   *		     (seek for ``MEDIA_PAD_FL_*``)
>   *
>   * This function can be used to resolve the media pad number from
> - * a fwnode. This is useful for devices which use more complex
> - * mappings of media pads.
> + * an endpoint fwnode. This is useful for devices which use more
> + * complex mappings of media pads.
>   *
>   * If the entity does not implement the get_fwnode_pad() operation
> - * then this function searches the entity for the first pad that
> - * matches the @direction_flags.
> + * then this function first assumes the entity implements a 1:1 mapping
> + * between fwnode port number and media pad index. If the 1:1 mapping
> + * is not valid, then the function searches the entity for the first pad
> + * that matches the @direction_flags.
>   *
>   * Return: returns the pad number on success or a negative error code.
>   */
> --
> 2.17.1
>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2019-11-28 12:02 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-24 19:06 [PATCH v2 00/23] media: imx: Create media links in bound notifiers Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 01/23] media: entity: Pass entity to get_fwnode_pad operation Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 02/23] media: entity: Modify default behavior of media_entity_get_fwnode_pad Steve Longerbeam
2019-11-28 12:04   ` Jacopo Mondi [this message]
2019-12-14 21:29     ` Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 03/23] media: entity: Convert media_entity_get_fwnode_pad() args to const Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 04/23] media: Move v4l2_fwnode_parse_link from v4l2 to driver base Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 05/23] media: entity: Add functions to convert fwnode endpoints to media links Steve Longerbeam
2019-11-28 13:46   ` Jacopo Mondi
2019-12-14 21:31     ` Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 06/23] media: adv748x: csi2: Implement get_fwnode_pad Steve Longerbeam
2019-11-28 11:53   ` Jacopo Mondi
2019-12-14 20:43     ` Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 07/23] media: rcar-csi2: Fix fwnode media link creation Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 08/23] media: cadence: csi2rx: " Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 09/23] media: sun6i: " Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 10/23] media: st-mipid02: " Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 11/23] media: stm32-dcmi: " Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 12/23] media: sunxi: " Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 13/23] media: v4l2-fwnode: Pass notifier to v4l2_async_register_fwnode_subdev() Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 14/23] media: video-mux: Create media links in bound notifier Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 15/23] media: imx: mipi csi-2: " Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 16/23] media: imx7-mipi-csis: " Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 17/23] media: imx7-media-csi: " Steve Longerbeam
2019-11-26 22:49   ` Rui Miguel Silva
2019-11-24 19:06 ` [PATCH v2 18/23] media: imx: csi: Implement get_fwnode_pad Steve Longerbeam
2019-11-24 19:06 ` [PATCH v2 19/23] media: imx: csi: Embed notifier in struct csi_priv Steve Longerbeam
2019-11-24 19:07 ` [PATCH v2 20/23] media: imx: csi: Create media links in bound notifier Steve Longerbeam
2019-11-24 19:07 ` [PATCH v2 21/23] media: imx: csi: Lookup upstream endpoint with imx_media_get_pad_fwnode Steve Longerbeam
2019-11-24 19:07 ` [PATCH v2 22/23] media: imx: Create missing links from CSI-2 receiver Steve Longerbeam
2019-11-24 19:07 ` [PATCH v2 23/23] media: imx: TODO: Remove media link creation todos Steve Longerbeam
2019-11-27  2:10 ` [PATCH v2 00/23] media: imx: Create media links in bound notifiers Adam Ford
2019-11-27  2:23   ` Steve Longerbeam
2019-11-27  2:31     ` Adam Ford
2019-12-16 17:20 ` Adam Ford
2020-02-02 19:30   ` Steve Longerbeam
2020-02-04 10:53     ` Adam Ford
2020-02-05  0:44       ` Steve Longerbeam

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=20191128120411.x7avm62lyq36gdya@uno.localdomain \
    --to=jacopo@jmondi.org \
    --cc=linux-media@vger.kernel.org \
    --cc=slongerbeam@gmail.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).