From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>,
linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-renesas-soc@vger.kernel.org,
Biju Das <biju.das.jz@bp.renesas.com>,
Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Subject: Re: [PATCH v3 13/17] media: rzg2l-cru: video: Implement .link_validate() callback
Date: Thu, 3 Oct 2024 17:51:12 +0300 [thread overview]
Message-ID: <20241003145112.GE5468@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20241001140919.206139-14-prabhakar.mahadev-lad.rj@bp.renesas.com>
Hi Prabhakar,
Thank you for the patch.
On Tue, Oct 01, 2024 at 03:09:15PM +0100, Prabhakar wrote:
> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Implement the `.link_validate()` callback for the video node and move the
> format checking into this function. This change allows the removal of
> `rzg2l_cru_mc_validate_format()`.
>
> Suggested-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> ---
> v2->v3
> - New patch
> ---
> .../platform/renesas/rzg2l-cru/rzg2l-video.c | 99 ++++++++++---------
> 1 file changed, 55 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> index ceb9012c9d70..c6c82b9b130a 100644
> --- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> +++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-video.c
> @@ -189,46 +189,6 @@ static void rzg2l_cru_buffer_queue(struct vb2_buffer *vb)
> spin_unlock_irqrestore(&cru->qlock, flags);
> }
>
> -static int rzg2l_cru_mc_validate_format(struct rzg2l_cru_dev *cru,
> - struct v4l2_subdev *sd,
> - struct media_pad *pad)
> -{
> - struct v4l2_subdev_format fmt = {
> - .which = V4L2_SUBDEV_FORMAT_ACTIVE,
> - };
> -
> - fmt.pad = pad->index;
> - if (v4l2_subdev_call_state_active(sd, pad, get_fmt, &fmt))
> - return -EPIPE;
> -
> - switch (fmt.format.code) {
> - case MEDIA_BUS_FMT_UYVY8_1X16:
> - break;
> - default:
> - return -EPIPE;
> - }
> -
> - switch (fmt.format.field) {
> - case V4L2_FIELD_TOP:
> - case V4L2_FIELD_BOTTOM:
> - case V4L2_FIELD_NONE:
> - case V4L2_FIELD_INTERLACED_TB:
> - case V4L2_FIELD_INTERLACED_BT:
> - case V4L2_FIELD_INTERLACED:
> - case V4L2_FIELD_SEQ_TB:
> - case V4L2_FIELD_SEQ_BT:
> - break;
> - default:
> - return -EPIPE;
> - }
> -
> - if (fmt.format.width != cru->format.width ||
> - fmt.format.height != cru->format.height)
> - return -EPIPE;
> -
> - return 0;
> -}
> -
> static void rzg2l_cru_set_slot_addr(struct rzg2l_cru_dev *cru,
> int slot, dma_addr_t addr)
> {
> @@ -531,10 +491,6 @@ static int rzg2l_cru_set_stream(struct rzg2l_cru_dev *cru, int on)
> return stream_off_ret;
> }
>
> - ret = rzg2l_cru_mc_validate_format(cru, sd, pad);
> - if (ret)
> - return ret;
> -
> pipe = media_entity_pipeline(&sd->entity) ? : &cru->vdev.pipe;
> ret = video_device_pipeline_start(&cru->vdev, pipe);
> if (ret)
> @@ -995,6 +951,60 @@ static const struct v4l2_file_operations rzg2l_cru_fops = {
> .read = vb2_fop_read,
> };
>
> +/* -----------------------------------------------------------------------------
> + * Media entity operations
> + */
> +
> +static int rzg2l_cru_video_link_validate(struct media_link *link)
> +{
> + struct v4l2_subdev_format fmt = {
> + .which = V4L2_SUBDEV_FORMAT_ACTIVE,
> + };
> + struct v4l2_subdev *subdev;
> + struct media_entity *entity;
> + struct rzg2l_cru_dev *cru;
> + struct media_pad *remote;
> + int ret;
> +
> + entity = link->sink->entity;
> + remote = link->source;
> +
> + subdev = media_entity_to_v4l2_subdev(remote->entity);
> + fmt.pad = remote->index;
> + ret = v4l2_subdev_call(subdev, pad, get_fmt, NULL, &fmt);
> + if (ret < 0)
> + return ret == -ENOIOCTLCMD ? -EINVAL : ret;
> +
> + if (!rzg2l_cru_ip_code_to_fmt(fmt.format.code))
> + return -EPIPE;
Here you should check that the format on the subdev matches the format
on the video device.
> +
> + switch (fmt.format.field) {
> + case V4L2_FIELD_TOP:
> + case V4L2_FIELD_BOTTOM:
> + case V4L2_FIELD_NONE:
> + case V4L2_FIELD_INTERLACED_TB:
> + case V4L2_FIELD_INTERLACED_BT:
> + case V4L2_FIELD_INTERLACED:
> + case V4L2_FIELD_SEQ_TB:
> + case V4L2_FIELD_SEQ_BT:
> + break;
> + default:
> + return -EPIPE;
> + }
Instead of checking the field here, shouldn't it be forced to a valid
value in the subdev .set_fmt() function ? The link validation handler is
responsible for validating that the configuration of the two sides of
the link (IP subdev and video device) match. The driver shouldn't allow
setting formats that can't be supported.
What you should check here is that the field of the subdev and the
field of the video device match.
> +
> + cru = container_of(media_entity_to_video_device(entity),
You can drop the local entity variable and write
cru = container_of(media_entity_to_video_device(link->sink->entity),
> + struct rzg2l_cru_dev, vdev);
> + if (fmt.format.width != cru->format.width ||
> + fmt.format.height != cru->format.height)
> + return -EPIPE;
> +
> + return 0;
> +}
> +
> +static const struct media_entity_operations rzg2l_cru_video_media_ops = {
> + .link_validate = rzg2l_cru_video_link_validate,
> +};
> +
> static void rzg2l_cru_v4l2_init(struct rzg2l_cru_dev *cru)
> {
> struct video_device *vdev = &cru->vdev;
> @@ -1006,6 +1016,7 @@ static void rzg2l_cru_v4l2_init(struct rzg2l_cru_dev *cru)
> vdev->lock = &cru->lock;
> vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
> vdev->device_caps |= V4L2_CAP_IO_MC;
> + vdev->entity.ops = &rzg2l_cru_video_media_ops;
> vdev->fops = &rzg2l_cru_fops;
> vdev->ioctl_ops = &rzg2l_cru_ioctl_ops;
>
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2024-10-03 14:51 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 14:09 [PATCH v3 00/17] media: platform: rzg2l-cru: CSI-2 and CRU enhancements Prabhakar
2024-10-01 14:09 ` [PATCH v3 01/17] media: rzg2l-cru: Use RZG2L_CRU_IP_SINK/SOURCE enum entries Prabhakar
2024-10-01 14:09 ` [PATCH v3 02/17] media: rzg2l-cru: Mark sink and source pad with MUST_CONNECT flag Prabhakar
2024-10-01 14:09 ` [PATCH v3 03/17] media: rzg2l-cru: csi2: " Prabhakar
2024-10-01 14:09 ` [PATCH v3 04/17] media: rzg2l-cru: csi2: Use ARRAY_SIZE() in media_entity_pads_init() Prabhakar
2024-10-01 14:09 ` [PATCH v3 05/17] media: rzg2l-cru: csi2: Implement .get_frame_desc() Prabhakar
2024-10-01 14:09 ` [PATCH v3 06/17] media: rzg2l-cru: Retrieve virtual channel information Prabhakar
2024-10-01 14:09 ` [PATCH v3 07/17] media: rzg2l-cru: Remove `channel` member from `struct rzg2l_cru_csi` Prabhakar
2024-10-01 14:09 ` [PATCH v3 08/17] media: rzg2l-cru: Use MIPI CSI-2 data types for ICnMC_INF definitions Prabhakar
2024-10-01 14:09 ` [PATCH v3 09/17] media: rzg2l-cru: Remove unused fields from rzg2l_cru_ip_format struct Prabhakar
2024-10-01 14:09 ` [PATCH v3 10/17] media: rzg2l-cru: Simplify handling of supported formats Prabhakar
2024-10-03 14:25 ` Laurent Pinchart
2024-10-03 20:28 ` Lad, Prabhakar
2024-10-01 14:09 ` [PATCH v3 11/17] media: rzg2l-cru: Use `rzg2l_cru_ip_formats` array in enum_frame_size Prabhakar
2024-10-01 14:09 ` [PATCH v3 12/17] media: rzg2l-cru: csi2: Remove unused field from rzg2l_csi2_format Prabhakar
2024-10-01 14:09 ` [PATCH v3 13/17] media: rzg2l-cru: video: Implement .link_validate() callback Prabhakar
2024-10-03 14:51 ` Laurent Pinchart [this message]
2024-10-07 10:48 ` Lad, Prabhakar
2024-10-01 14:09 ` [PATCH v3 14/17] media: rzg2l-cru: csi2: Use rzg2l_csi2_formats array in enum_frame_size Prabhakar
2024-10-01 14:09 ` [PATCH v3 15/17] media: rzg2l-cru: Refactor ICnDMR register configuration Prabhakar
2024-10-03 14:34 ` Laurent Pinchart
2024-10-03 20:20 ` Lad, Prabhakar
2024-10-01 14:09 ` [PATCH v3 16/17] media: rzg2l-cru: Add support to capture 8bit raw sRGB Prabhakar
2024-10-01 14:09 ` [PATCH v3 17/17] media: rzg2l-cru: Move register definitions to a separate file Prabhakar
2024-10-03 14:36 ` Laurent Pinchart
2024-10-03 20:23 ` Lad, Prabhakar
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=20241003145112.GE5468@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=fabrizio.castro.jz@renesas.com \
--cc=hverkuil-cisco@xs4all.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=prabhakar.csengg@gmail.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=sakari.ailus@linux.intel.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