linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: "Niklas Söderlund" <niklas.soderlund+renesas@ragnatech.se>,
	"Laurent Pinchart" <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
	tomoharu.fukawa.eb@renesas.com,
	Kieran Bingham <kieran.bingham@ideasonboard.com>
Subject: Re: [PATCH v12 29/33] rcar-vin: add link notify for Gen3
Date: Fri, 9 Mar 2018 16:46:38 +0100	[thread overview]
Message-ID: <3305b400-6a8d-6805-08a5-5c1553f676eb@xs4all.nl> (raw)
In-Reply-To: <20180307220511.9826-30-niklas.soderlund+renesas@ragnatech.se>

On 07/03/18 23:05, Niklas Söderlund wrote:
> Add the ability to process media device link change requests. Link
> enabling is a bit complicated on Gen3, whether or not it's possible to
> enable a link depends on what other links already are enabled. On Gen3
> the 8 VINs are split into two subgroup's (VIN0-3 and VIN4-7) and from a
> routing perspective these two groups are independent of each other.
> Each subgroup's routing is controlled by the subgroup VIN master
> instance (VIN0 and VIN4).
> 
> There are a limited number of possible route setups available for each
> subgroup and the configuration of each setup is dictated by the
> hardware. On H3 for example there are 6 possible route setups for each
> subgroup to choose from.
> 
> This leads to the media device link notification code being rather large
> since it will find the best routing configuration to try and accommodate
> as many links as possible. When it's not possible to enable a new link
> due to hardware constrains the link_notifier callback will return
> -EMLINK.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com>

Regards,

	Hans

> 
> ---
> 
> * Changes since v11
> - Fixed spelling
> - Updated comment to clarify the intent that no link can be enabled if
> any video node is open.
> - Use container_of() instead of a loop to find struct vin_dev from the
> video device.
> ---
>  drivers/media/platform/rcar-vin/rcar-core.c | 147 ++++++++++++++++++++++++++++
>  1 file changed, 147 insertions(+)
> 
> diff --git a/drivers/media/platform/rcar-vin/rcar-core.c b/drivers/media/platform/rcar-vin/rcar-core.c
> index 52fad495533bc427..a1c441c1a314feb7 100644
> --- a/drivers/media/platform/rcar-vin/rcar-core.c
> +++ b/drivers/media/platform/rcar-vin/rcar-core.c
> @@ -24,6 +24,7 @@
>  
>  #include <media/v4l2-async.h>
>  #include <media/v4l2-fwnode.h>
> +#include <media/v4l2-mc.h>
>  
>  #include "rcar-vin.h"
>  
> @@ -44,6 +45,151 @@
>   */
>  #define rvin_group_id_to_master(vin) ((vin) < 4 ? 0 : 4)
>  
> +/* -----------------------------------------------------------------------------
> + * Media Controller link notification
> + */
> +
> +/* group lock should be held when calling this function. */
> +static int rvin_group_entity_to_csi_id(struct rvin_group *group,
> +				       struct media_entity *entity)
> +{
> +	struct v4l2_subdev *sd;
> +	unsigned int i;
> +
> +	sd = media_entity_to_v4l2_subdev(entity);
> +
> +	for (i = 0; i < RVIN_CSI_MAX; i++)
> +		if (group->csi[i].subdev == sd)
> +			return i;
> +
> +	return -ENODEV;
> +}
> +
> +static unsigned int rvin_group_get_mask(struct rvin_dev *vin,
> +					enum rvin_csi_id csi_id,
> +					unsigned char channel)
> +{
> +	const struct rvin_group_route *route;
> +	unsigned int mask = 0;
> +
> +	for (route = vin->info->routes; route->mask; route++) {
> +		if (route->vin == vin->id &&
> +		    route->csi == csi_id &&
> +		    route->channel == channel) {
> +			vin_dbg(vin,
> +				"Adding route: vin: %d csi: %d channel: %d\n",
> +				route->vin, route->csi, route->channel);
> +			mask |= route->mask;
> +		}
> +	}
> +
> +	return mask;
> +}
> +
> +/*
> + * Link setup for the links between a VIN and a CSI-2 receiver is a bit
> + * complex. The reason for this is that the register controlling routing
> + * is not present in each VIN instance. There are special VINs which
> + * control routing for themselves and other VINs. There are not many
> + * different possible links combinations that can be enabled at the same
> + * time, therefor all already enabled links which are controlled by a
> + * master VIN need to be taken into account when making the decision
> + * if a new link can be enabled or not.
> + *
> + * 1. Find out which VIN the link the user tries to enable is connected to.
> + * 2. Lookup which master VIN controls the links for this VIN.
> + * 3. Start with a bitmask with all bits set.
> + * 4. For each previously enabled link from the master VIN bitwise AND its
> + *    route mask (see documentation for mask in struct rvin_group_route)
> + *    with the bitmask.
> + * 5. Bitwise AND the mask for the link the user tries to enable to the bitmask.
> + * 6. If the bitmask is not empty at this point the new link can be enabled
> + *    while keeping all previous links enabled. Update the CHSEL value of the
> + *    master VIN and inform the user that the link could be enabled.
> + *
> + * Please note that no link can be enabled if any VIN in the group is
> + * currently open.
> + */
> +static int rvin_group_link_notify(struct media_link *link, u32 flags,
> +				  unsigned int notification)
> +{
> +	struct rvin_group *group = container_of(link->graph_obj.mdev,
> +						struct rvin_group, mdev);
> +	unsigned int master_id, channel, mask_new, i;
> +	unsigned int mask = ~0;
> +	struct media_entity *entity;
> +	struct video_device *vdev;
> +	struct media_pad *csi_pad;
> +	struct rvin_dev *vin = NULL;
> +	int csi_id, ret;
> +
> +	ret = v4l2_pipeline_link_notify(link, flags, notification);
> +	if (ret)
> +		return ret;
> +
> +	/* Only care about link enablement for VIN nodes. */
> +	if (!(flags & MEDIA_LNK_FL_ENABLED) ||
> +	    !is_media_entity_v4l2_video_device(link->sink->entity))
> +		return 0;
> +
> +	/* If any entity is in use don't allow link changes. */
> +	media_device_for_each_entity(entity, &group->mdev)
> +		if (entity->use_count)
> +			return -EBUSY;
> +
> +	mutex_lock(&group->lock);
> +
> +	/* Find the master VIN that controls the routes. */
> +	vdev = media_entity_to_video_device(link->sink->entity);
> +	vin = container_of(vdev, struct rvin_dev, vdev);
> +	master_id = rvin_group_id_to_master(vin->id);
> +
> +	if (WARN_ON(!group->vin[master_id])) {
> +		ret = -ENODEV;
> +		goto out;
> +	}
> +
> +	/* Build a mask for already enabled links. */
> +	for (i = master_id; i < master_id + 4; i++) {
> +		if (!group->vin[i])
> +			continue;
> +
> +		/* Get remote CSI-2, if any. */
> +		csi_pad = media_entity_remote_pad(
> +				&group->vin[i]->vdev.entity.pads[0]);
> +		if (!csi_pad)
> +			continue;
> +
> +		csi_id = rvin_group_entity_to_csi_id(group, csi_pad->entity);
> +		channel = rvin_group_csi_pad_to_channel(csi_pad->index);
> +
> +		mask &= rvin_group_get_mask(group->vin[i], csi_id, channel);
> +	}
> +
> +	/* Add the new link to the existing mask and check if it works. */
> +	csi_id = rvin_group_entity_to_csi_id(group, link->source->entity);
> +	channel = rvin_group_csi_pad_to_channel(link->source->index);
> +	mask_new = mask & rvin_group_get_mask(vin, csi_id, channel);
> +
> +	vin_dbg(vin, "Try link change mask: 0x%x new: 0x%x\n", mask, mask_new);
> +
> +	if (!mask_new) {
> +		ret = -EMLINK;
> +		goto out;
> +	}
> +
> +	/* New valid CHSEL found, set the new value. */
> +	ret = rvin_set_channel_routing(group->vin[master_id], __ffs(mask_new));
> +out:
> +	mutex_unlock(&group->lock);
> +
> +	return ret;
> +}
> +
> +static const struct media_device_ops rvin_media_ops = {
> +	.link_notify = rvin_group_link_notify,
> +};
> +
>  /* -----------------------------------------------------------------------------
>   * Gen3 CSI2 Group Allocator
>   */
> @@ -85,6 +231,7 @@ static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin)
>  	vin_dbg(vin, "found %u enabled VIN's in DT", group->count);
>  
>  	mdev->dev = vin->dev;
> +	mdev->ops = &rvin_media_ops;
>  
>  	match = of_match_node(vin->dev->driver->of_match_table,
>  			      vin->dev->of_node);
> 

  reply	other threads:[~2018-03-09 15:46 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-07 22:04 [PATCH v12 00/33] rcar-vin: Add Gen3 with media controller Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 01/33] dt-bindings: media: rcar_vin: Reverse SoC part number list Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 02/33] dt-bindings: media: rcar_vin: add device tree support for r8a774[35] Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 03/33] rcar-vin: add Gen3 devicetree bindings documentation Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 04/33] rcar-vin: rename poorly named initialize and cleanup functions Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 05/33] rcar-vin: unregister video device on driver removal Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 06/33] rcar-vin: move subdevice handling to async callbacks Niklas Söderlund
2018-03-09 15:16   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 07/33] rcar-vin: move model information to own struct Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 08/33] rcar-vin: move max width and height information to chip information Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 09/33] rcar-vin: move functions regarding scaling Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 10/33] rcar-vin: all Gen2 boards can scale simplify logic Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 11/33] rcar-vin: set a default field to fallback on Niklas Söderlund
2018-03-09 15:25   ` Hans Verkuil
2018-03-09 16:17     ` Niklas Söderlund
2018-03-09 16:28       ` Hans Verkuil
2018-03-09 17:07         ` Niklas Söderlund
2018-03-09 17:13           ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 12/33] rcar-vin: fix handling of single field frames (top, bottom and alternate fields) Niklas Söderlund
2018-03-09 15:28   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 13/33] rcar-vin: update bytesperline and sizeimage calculation Niklas Söderlund
2018-03-09 15:29   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 14/33] rcar-vin: align pixelformat check Niklas Söderlund
2018-03-09 15:30   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 15/33] rcar-vin: break out format alignment and checking Niklas Söderlund
2018-03-09 15:30   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 16/33] rcar-vin: simplify how formats are set and reset Niklas Söderlund
2018-03-09 15:34   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 17/33] rcar-vin: cache video standard Niklas Söderlund
2018-03-09 15:39   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 18/33] rcar-vin: move media bus configuration to struct rvin_dev Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 19/33] rcar-vin: enable Gen3 hardware configuration Niklas Söderlund
2018-03-07 22:04 ` [PATCH v12 20/33] rcar-vin: add function to manipulate Gen3 chsel value Niklas Söderlund
2018-03-09 15:40   ` Hans Verkuil
2018-03-07 22:04 ` [PATCH v12 21/33] rcar-vin: add flag to switch to media controller mode Niklas Söderlund
2018-03-07 22:05 ` [PATCH v12 22/33] rcar-vin: use different v4l2 operations in " Niklas Söderlund
2018-03-07 22:05 ` [PATCH v12 23/33] rcar-vin: force default colorspace for media centric mode Niklas Söderlund
2018-03-09 15:41   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 24/33] rcar-vin: prepare for media controller mode initialization Niklas Söderlund
2018-03-07 22:05 ` [PATCH v12 25/33] rcar-vin: add group allocator functions Niklas Söderlund
2018-03-09 15:42   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 26/33] rcar-vin: change name of video device Niklas Söderlund
2018-03-09 15:43   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 27/33] rcar-vin: add chsel information to rvin_info Niklas Söderlund
2018-03-09 15:43   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 28/33] rcar-vin: parse Gen3 OF and setup media graph Niklas Söderlund
2018-03-09 15:45   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 29/33] rcar-vin: add link notify for Gen3 Niklas Söderlund
2018-03-09 15:46   ` Hans Verkuil [this message]
2018-03-07 22:05 ` [PATCH v12 30/33] rcar-vin: extend {start,stop}_streaming to work with media controller Niklas Söderlund
2018-03-09 15:47   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 31/33] rcar-vin: enable support for r8a7795 Niklas Söderlund
2018-03-09 15:47   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 32/33] rcar-vin: enable support for r8a7796 Niklas Söderlund
2018-03-09 15:48   ` Hans Verkuil
2018-03-07 22:05 ` [PATCH v12 33/33] rcar-vin: enable support for r8a77970 Niklas Söderlund
2018-03-09 15:48   ` Hans Verkuil

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=3305b400-6a8d-6805-08a5-5c1553f676eb@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=niklas.soderlund+renesas@ragnatech.se \
    --cc=tomoharu.fukawa.eb@renesas.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).