mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 09/15] media: tegra-video: vi: Configure capture format locally without subdev calls
Date: Sun, 29 Nov 2026 20:07:16 +0200	[thread overview]
Message-ID: <20261129180722.142186-10-clamor95@gmail.com> (raw)
In-Reply-To: <20261129180722.142186-1-clamor95@gmail.com>

Simplify __tegra_channel_try_format() and tegra_channel_set_format() to
validate, align, and store the capture pixel format locally on the video
channel instead of querying or setting formats on the remote subdevice
and allocating temporary subdev state.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
 .../media/platform/nvidia/tegra-video/vi.c    | 90 +++----------------
 1 file changed, 12 insertions(+), 78 deletions(-)

diff --git a/drivers/media/platform/nvidia/tegra-video/vi.c b/drivers/media/platform/nvidia/tegra-video/vi.c
index b41158760f007..c292443783b14 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.c
+++ b/drivers/media/platform/nvidia/tegra-video/vi.c
@@ -366,37 +366,11 @@ static int tegra_channel_get_format(struct file *file, void *fh,
 }
 
 static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
-				      struct v4l2_pix_format *pix)
+				      struct v4l2_pix_format *pix,
+				      const struct tegra_video_format **tfmtinfo)
 {
 	const struct tegra_video_format *fmtinfo;
-	static struct lock_class_key key;
-	struct v4l2_subdev *subdev;
-	struct v4l2_subdev_format fmt = {
-		.which = V4L2_SUBDEV_FORMAT_TRY,
-	};
-	struct v4l2_subdev_state *sd_state;
-	struct v4l2_subdev_frame_size_enum fse = {
-		.which = V4L2_SUBDEV_FORMAT_TRY,
-	};
-	struct v4l2_subdev_selection sdsel = {
-		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
-		.target = V4L2_SEL_TGT_CROP_BOUNDS,
-	};
-	struct v4l2_rect *try_crop;
-	int ret = 0;
-
-	subdev = tegra_channel_get_remote_source_subdev(chan);
-	if (!subdev)
-		return -ENODEV;
 
-	/*
-	 * FIXME: Drop this call, drivers are not supposed to use
-	 * __v4l2_subdev_state_alloc().
-	 */
-	sd_state = __v4l2_subdev_state_alloc(subdev, "tegra:state->lock",
-					     &key);
-	if (IS_ERR(sd_state))
-		return PTR_ERR(sd_state);
 	/*
 	 * Retrieve the format information and if requested format isn't
 	 * supported, keep the current format.
@@ -408,42 +382,18 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
 		fmtinfo = tegra_get_format_by_fourcc(chan, pix->pixelformat);
 	}
 
-	pix->field = V4L2_FIELD_NONE;
-	fmt.pad = 0;
-	v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
+	if (tfmtinfo)
+		*tfmtinfo = fmtinfo;
 
-	/*
-	 * Attempt to obtain the format size from subdev.
-	 * If not available, try to get crop boundary from subdev.
-	 */
-	try_crop = v4l2_subdev_state_get_crop(sd_state, 0);
-	fse.code = fmtinfo->code;
-	ret = v4l2_subdev_call(subdev, pad, enum_frame_size, sd_state, &fse);
-	if (ret) {
-		if (!v4l2_subdev_has_op(subdev, pad, get_selection) ||
-		    v4l2_subdev_call(subdev, pad, get_selection, NULL, NULL, &sdsel)) {
-			try_crop->width = 0;
-			try_crop->height = 0;
-		} else {
-			try_crop->width = sdsel.r.width;
-			try_crop->height = sdsel.r.height;
-		}
-	} else {
-		try_crop->width = fse.max_width;
-		try_crop->height = fse.max_height;
-	}
-
-	ret = v4l2_subdev_call(subdev, pad, set_fmt, NULL, sd_state, &fmt);
-	if (ret < 0)
-		goto out_free;
+	pix->field = V4L2_FIELD_NONE;
+	pix->colorspace = chan->format.colorspace;
+	pix->xfer_func = V4L2_XFER_FUNC_DEFAULT;
+	pix->ycbcr_enc = V4L2_YCBCR_ENC_DEFAULT;
+	pix->quantization = V4L2_QUANTIZATION_DEFAULT;
 
-	v4l2_fill_pix_format(pix, &fmt.format);
 	chan->vi->ops->vi_fmt_align(pix, fmtinfo->bpp);
 
-out_free:
-	__v4l2_subdev_state_free(sd_state);
-
-	return ret;
+	return 0;
 }
 
 static int tegra_channel_try_format(struct file *file, void *fh,
@@ -451,7 +401,7 @@ static int tegra_channel_try_format(struct file *file, void *fh,
 {
 	struct tegra_vi_channel *chan = video_drvdata(file);
 
-	return __tegra_channel_try_format(chan, &format->fmt.pix);
+	return __tegra_channel_try_format(chan, &format->fmt.pix, NULL);
 }
 
 static void tegra_channel_update_gangports(struct tegra_vi_channel *chan)
@@ -467,10 +417,6 @@ static int tegra_channel_set_format(struct file *file, void *fh,
 {
 	struct tegra_vi_channel *chan = video_drvdata(file);
 	const struct tegra_video_format *fmtinfo;
-	struct v4l2_subdev_format fmt = {
-		.which = V4L2_SUBDEV_FORMAT_ACTIVE,
-	};
-	struct v4l2_subdev *subdev;
 	struct v4l2_pix_format *pix = &format->fmt.pix;
 	int ret;
 
@@ -478,22 +424,10 @@ static int tegra_channel_set_format(struct file *file, void *fh,
 		return -EBUSY;
 
 	/* get supported format by try_fmt */
-	ret = __tegra_channel_try_format(chan, pix);
+	ret = __tegra_channel_try_format(chan, pix, &fmtinfo);
 	if (ret)
 		return ret;
 
-	fmtinfo = tegra_get_format_by_fourcc(chan, pix->pixelformat);
-
-	fmt.pad = 0;
-	v4l2_fill_mbus_format(&fmt.format, pix, fmtinfo->code);
-	subdev = tegra_channel_get_remote_source_subdev(chan);
-	ret = v4l2_subdev_call(subdev, pad, set_fmt, NULL, NULL, &fmt);
-	if (ret < 0)
-		return ret;
-
-	v4l2_fill_pix_format(pix, &fmt.format);
-	chan->vi->ops->vi_fmt_align(pix, fmtinfo->bpp);
-
 	chan->format = *pix;
 	chan->fmtinfo = fmtinfo;
 	tegra_channel_update_gangports(chan);
-- 
2.53.0


  parent reply	other threads:[~2026-11-29 18:07 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 ` Svyatoslav Ryhel [this message]
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 ` [PATCH v2 15/15] media: tegra-video: vip: Add pad and media operations for VIP Svyatoslav Ryhel

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-10-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®