From: Svyatoslav Ryhel <clamor95@gmail.com>
To: Mauro Carvalho Chehab <mchehab@kernel.org>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Sowjanya Komatineni <skomatineni@nvidia.com>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Svyatoslav Ryhel <clamor95@gmail.com>,
Hans Verkuil <hverkuil+cisco@kernel.org>,
Mikko Perttunen <mperttunen@nvidia.com>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-tegra@vger.kernel.org, linux-staging@lists.linux.dev
Subject: [PATCH v2 15/15] media: tegra-video: vip: Add pad and media operations for VIP
Date: Sun, 29 Nov 2026 20:07:22 +0200 [thread overview]
Message-ID: <20261129180722.142186-16-clamor95@gmail.com> (raw)
In-Reply-To: <20261129180722.142186-1-clamor95@gmail.com>
Implement pad format enumeration, format negotiation clamped to SoC
limits via vi_fmt_align(), and v4l2_subdev_link_validate() for VIP bridge
channels.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
.../media/platform/nvidia/tegra-video/vip.c | 93 ++++++++++++++++++-
1 file changed, 92 insertions(+), 1 deletion(-)
diff --git a/drivers/media/platform/nvidia/tegra-video/vip.c b/drivers/media/platform/nvidia/tegra-video/vip.c
index 040776775aacc..bc925633b5890 100644
--- a/drivers/media/platform/nvidia/tegra-video/vip.c
+++ b/drivers/media/platform/nvidia/tegra-video/vip.c
@@ -21,6 +21,14 @@
#include "vip.h"
#include "video.h"
+static const u32 tegra_vip_mbus_formats[] = {
+ /* YUV422 */
+ MEDIA_BUS_FMT_UYVY8_2X8,
+ MEDIA_BUS_FMT_VYUY8_2X8,
+ MEDIA_BUS_FMT_YUYV8_2X8,
+ MEDIA_BUS_FMT_YVYU8_2X8,
+};
+
static inline struct tegra_vip *host1x_client_to_vip(struct host1x_client *client)
{
return container_of(client, struct tegra_vip, client);
@@ -36,6 +44,77 @@ static inline struct tegra_vip *vip_channel_to_vip(struct tegra_vip_channel *cha
return container_of(chan, struct tegra_vip, chan);
}
+static u32 tegra_vip_get_format_code(u32 code)
+{
+ u32 i;
+
+ for (i = 0; i < ARRAY_SIZE(tegra_vip_mbus_formats); i++)
+ if (tegra_vip_mbus_formats[i] == code)
+ break;
+
+ if (i >= ARRAY_SIZE(tegra_vip_mbus_formats))
+ i = 0;
+
+ return tegra_vip_mbus_formats[i];
+}
+
+static int tegra_vip_enum_bus_code(struct v4l2_subdev *subdev,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_mbus_code_enum *code)
+{
+ const struct v4l2_mbus_framefmt *sink_fmt;
+
+ if (code->pad == TEGRA_VIP_PAD_SINK) {
+ if (code->index >= ARRAY_SIZE(tegra_vip_mbus_formats))
+ return -EINVAL;
+
+ code->code = tegra_vip_mbus_formats[code->index];
+ } else {
+ if (code->index > 0)
+ return -EINVAL;
+
+ sink_fmt = v4l2_subdev_state_get_format(state,
+ TEGRA_VIP_PAD_SINK);
+ code->code = sink_fmt->code;
+ }
+
+ return 0;
+}
+
+static int tegra_vip_set_format(struct v4l2_subdev *subdev,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_format *format)
+{
+ struct tegra_vi_channel *chan = v4l2_get_subdev_hostdata(subdev);
+ struct v4l2_mbus_framefmt *mbus_fmt = &format->format;
+ struct v4l2_mbus_framefmt *sink_fmt, *src_fmt;
+ struct tegra_vi *vi = chan->vi;
+ const struct v4l2_frmsize_stepwise *stepwise = vi->soc->framesize;
+
+ /* The format on the source pad always matches the sink pad */
+ if (format->pad == TEGRA_VIP_PAD_SOURCE)
+ return v4l2_subdev_get_fmt(subdev, state, format);
+
+ sink_fmt = v4l2_subdev_state_get_format(state, TEGRA_VIP_PAD_SINK);
+ src_fmt = v4l2_subdev_state_get_format(state, TEGRA_VIP_PAD_SOURCE);
+ if (!sink_fmt || !src_fmt)
+ return -EINVAL;
+
+ mbus_fmt->code = tegra_vip_get_format_code(mbus_fmt->code);
+ mbus_fmt->field = V4L2_FIELD_NONE;
+
+ mbus_fmt->width = clamp_t(u32, mbus_fmt->width, stepwise->min_width,
+ stepwise->max_width);
+ mbus_fmt->height = clamp_t(u32, mbus_fmt->height, stepwise->min_height,
+ stepwise->max_height);
+
+ *sink_fmt = *mbus_fmt;
+ *src_fmt = *mbus_fmt;
+
+ return 0;
+}
+
/* Find the previous subdev in the pipeline (i.e. the one connected to our sink pad) */
static struct v4l2_subdev *tegra_vip_channel_get_prev_subdev(struct tegra_vip_channel *chan)
{
@@ -104,8 +183,19 @@ static const struct v4l2_subdev_video_ops tegra_vip_video_ops = {
.s_stream = tegra_vip_s_stream,
};
+static const struct v4l2_subdev_pad_ops tegra_vip_pad_ops = {
+ .enum_mbus_code = tegra_vip_enum_bus_code,
+ .get_fmt = v4l2_subdev_get_fmt,
+ .set_fmt = tegra_vip_set_format,
+};
+
static const struct v4l2_subdev_ops tegra_vip_ops = {
- .video = &tegra_vip_video_ops,
+ .video = &tegra_vip_video_ops,
+ .pad = &tegra_vip_pad_ops,
+};
+
+static const struct media_entity_operations tegra_vip_media_ops = {
+ .link_validate = v4l2_subdev_link_validate,
};
static int tegra_vip_channel_of_parse(struct tegra_vip *vip)
@@ -165,6 +255,7 @@ static int tegra_vip_channel_init(struct tegra_vip *vip)
v4l2_set_subdevdata(subdev, &vip->chan);
subdev->fwnode = of_fwnode_handle(vip->chan.of_node);
subdev->entity.function = MEDIA_ENT_F_VID_IF_BRIDGE;
+ subdev->entity.ops = &tegra_vip_media_ops;
subdev->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
err = media_entity_pads_init(&subdev->entity, TEGRA_VIP_PADS_NUM, vip->chan.pads);
--
2.53.0
prev parent reply other threads:[~2026-11-29 18:08 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 18:07 [PATCH v2 00/15] tegra-video: Convert to media-centric pipe Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 01/15] staging: media: tegra-video: Move driver to media/platform/nvidia Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 02/15] media: tegra-video: vi: Drop controls consolidation into VI device Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 03/15] media: tegra-video: vi: Expose all sub-devices in the pipeline Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 04/15] media: tegra-video: vi: Drop subdevice passthrough and input ioctls Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 05/15] media: tegra-video: vi: Build bitmap of formats compatible with CSI/VIP instead of source Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 06/15] media: tegra-video: Expose SoC stepwise frame size limits Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 07/15] media: tegra-video: vi: Match fourcc against channel format bitmap Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 08/15] media: tegra-video: vi: Report stepwise frame sizes instead of querying subdev Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 09/15] media: tegra-video: vi: Configure capture format locally without subdev calls Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 10/15] media: tegra-video: vi: Implement link_validate for video entity Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 11/15] media: tegra-video: video: Resolve video device via media graph on notifications Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 12/15] media: tegra-video: Remove remote source subdev helper Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 13/15] media: tegra-video: csi: Scope pad and state ops to TPG mode Svyatoslav Ryhel
2026-11-29 18:07 ` [PATCH v2 14/15] media: tegra-video: csi: Add pad and media operations for own CSI channels Svyatoslav Ryhel
2026-11-29 18:07 ` Svyatoslav Ryhel [this message]
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=20261129180722.142186-16-clamor95@gmail.com \
--to=clamor95@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil+cisco@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=linux-tegra@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=mchehab@kernel.org \
--cc=mperttunen@nvidia.com \
--cc=skomatineni@nvidia.com \
--cc=thierry.reding@kernel.org \
/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
all inboxes | Powered by JetHome®