[PATCH v1 06/13] media: tegra-video: vi: Populate stepwise frame sizes via vi_fmt_align
From: Svyatoslav Ryhel
Date: Wed Nov 25 2026 - 06:08:58 EST
Extend tegra_vi_ops.vi_fmt_align() with a struct v4l2_frmsize_stepwise
pointer so tegra20_fmt_align() and tegra210_fmt_align() can report
SoC-specific minimum/maximum dimensions and step alignment directly
instead of duplicating limits.
This will be needed later when converting the remaining ioctl operations.
Signed-off-by: Svyatoslav Ryhel <clamor95@xxxxxxxxx>
---
.../platform/nvidia/tegra-video/tegra20.c | 18 +++++++++++++++++-
.../platform/nvidia/tegra-video/tegra210.c | 18 +++++++++++++++++-
drivers/media/platform/nvidia/tegra-video/vi.c | 8 ++++----
drivers/media/platform/nvidia/tegra-video/vi.h | 11 ++++++++---
4 files changed, 46 insertions(+), 9 deletions(-)
diff --git a/drivers/media/platform/nvidia/tegra-video/tegra20.c b/drivers/media/platform/nvidia/tegra-video/tegra20.c
index cdadff98eae75..f8d2b5e1b4131 100644
--- a/drivers/media/platform/nvidia/tegra-video/tegra20.c
+++ b/drivers/media/platform/nvidia/tegra-video/tegra20.c
@@ -447,8 +447,24 @@ static void tegra20_channel_host1x_syncpt_free(struct tegra_vi_channel *chan)
host1x_syncpt_put(chan->frame_start_sp[0]);
}
-static void tegra20_fmt_align(struct v4l2_pix_format *pix, unsigned int bpp)
+static void tegra20_fmt_align(struct v4l2_pix_format *pix,
+ struct v4l2_frmsize_stepwise *stepwise,
+ unsigned int bpp)
{
+ if (stepwise) {
+ stepwise->min_width = TEGRA20_MIN_WIDTH;
+ stepwise->min_height = TEGRA20_MIN_HEIGHT;
+
+ stepwise->max_width = TEGRA20_MAX_WIDTH;
+ stepwise->max_height = TEGRA20_MAX_HEIGHT;
+
+ /* Size must be div2 */
+ stepwise->step_width = 2;
+ stepwise->step_height = 2;
+
+ return;
+ }
+
pix->width = clamp(pix->width, TEGRA20_MIN_WIDTH, TEGRA20_MAX_WIDTH);
pix->height = clamp(pix->height, TEGRA20_MIN_HEIGHT, TEGRA20_MAX_HEIGHT);
diff --git a/drivers/media/platform/nvidia/tegra-video/tegra210.c b/drivers/media/platform/nvidia/tegra-video/tegra210.c
index 82d054c9c34c5..90d984790696f 100644
--- a/drivers/media/platform/nvidia/tegra-video/tegra210.c
+++ b/drivers/media/platform/nvidia/tegra-video/tegra210.c
@@ -229,12 +229,28 @@ static void tegra210_channel_host1x_syncpt_free(struct tegra_vi_channel *chan)
}
}
-static void tegra210_fmt_align(struct v4l2_pix_format *pix, unsigned int bpp)
+static void tegra210_fmt_align(struct v4l2_pix_format *pix,
+ struct v4l2_frmsize_stepwise *stepwise,
+ unsigned int bpp)
{
unsigned int min_bpl;
unsigned int max_bpl;
unsigned int bpl;
+ if (stepwise) {
+ stepwise->min_width = TEGRA210_MIN_WIDTH;
+ stepwise->min_height = TEGRA210_MAX_WIDTH;
+
+ stepwise->max_width = TEGRA210_MIN_HEIGHT;
+ stepwise->max_height = TEGRA210_MAX_HEIGHT;
+
+ /* Size must be div2 */
+ stepwise->step_width = 2;
+ stepwise->step_height = 2;
+
+ return;
+ }
+
/*
* The transfer alignment requirements are expressed in bytes.
* Clamp the requested width and height to the limits.
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.c b/drivers/media/platform/nvidia/tegra-video/vi.c
index 5b38bae648686..b523750725254 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.c
+++ b/drivers/media/platform/nvidia/tegra-video/vi.c
@@ -441,7 +441,7 @@ static int __tegra_channel_try_format(struct tegra_vi_channel *chan,
goto out_free;
v4l2_fill_pix_format(pix, &fmt.format);
- chan->vi->ops->vi_fmt_align(pix, fmtinfo->bpp);
+ chan->vi->ops->vi_fmt_align(pix, NULL, fmtinfo->bpp);
out_free:
__v4l2_subdev_state_free(sd_state);
@@ -495,7 +495,7 @@ static int tegra_channel_set_format(struct file *file, void *fh,
return ret;
v4l2_fill_pix_format(pix, &fmt.format);
- chan->vi->ops->vi_fmt_align(pix, fmtinfo->bpp);
+ chan->vi->ops->vi_fmt_align(pix, NULL, fmtinfo->bpp);
chan->format = *pix;
chan->fmtinfo = fmtinfo;
@@ -531,7 +531,7 @@ static int tegra_channel_set_subdev_active_fmt(struct tegra_vi_channel *chan)
chan->format.bytesperline = chan->format.width * chan->fmtinfo->bpp;
chan->format.sizeimage = chan->format.bytesperline *
chan->format.height;
- chan->vi->ops->vi_fmt_align(&chan->format, chan->fmtinfo->bpp);
+ chan->vi->ops->vi_fmt_align(&chan->format, NULL, chan->fmtinfo->bpp);
tegra_channel_update_gangports(chan);
return 0;
@@ -845,7 +845,7 @@ static int tegra_channel_init(struct tegra_vi_channel *chan)
chan->format.height = TEGRA_DEF_HEIGHT;
chan->format.bytesperline = TEGRA_DEF_WIDTH * chan->fmtinfo->bpp;
chan->format.sizeimage = chan->format.bytesperline * TEGRA_DEF_HEIGHT;
- vi->ops->vi_fmt_align(&chan->format, chan->fmtinfo->bpp);
+ vi->ops->vi_fmt_align(&chan->format, NULL, chan->fmtinfo->bpp);
ret = vi->ops->channel_host1x_syncpt_init(chan);
if (ret)
diff --git a/drivers/media/platform/nvidia/tegra-video/vi.h b/drivers/media/platform/nvidia/tegra-video/vi.h
index 46328e488aa38..ac86f11588f95 100644
--- a/drivers/media/platform/nvidia/tegra-video/vi.h
+++ b/drivers/media/platform/nvidia/tegra-video/vi.h
@@ -45,8 +45,11 @@ struct tegra_vi_channel;
* @vi_enable: soc-specific operations needed to enable/disable the VI peripheral
* @channel_host1x_syncpt_init: initialize synchronization points
* @channel_host1x_syncpt_free: free all synchronization points
- * @vi_fmt_align: modify `pix` to fit the hardware alignment
- * requirements and fill image geometry
+ * @vi_fmt_align: if @stepwise is passed, it is filled with SoC-specific
+ * alignment restrictions and maximum/minimum frame dimensions,
+ * while other parameters are ignored. If @pix and @bpp are
+ * passed, @pix is modified to fit the hardware alignment
+ * requirements and fill the image geometry.
* @channel_queue_setup: additional operations at the end of vb2_ops::queue_setup
* @vi_start_streaming: starts media pipeline, subdevice streaming, sets up
* VI for capture and runs capture start and capture finish
@@ -58,7 +61,9 @@ struct tegra_vi_ops {
int (*vi_enable)(struct tegra_vi *vi, bool on);
int (*channel_host1x_syncpt_init)(struct tegra_vi_channel *chan);
void (*channel_host1x_syncpt_free)(struct tegra_vi_channel *chan);
- void (*vi_fmt_align)(struct v4l2_pix_format *pix, unsigned int bpp);
+ void (*vi_fmt_align)(struct v4l2_pix_format *pix,
+ struct v4l2_frmsize_stepwise *stepwise,
+ unsigned int bpp);
void (*channel_queue_setup)(struct tegra_vi_channel *chan);
int (*vi_start_streaming)(struct vb2_queue *vq, u32 count);
void (*vi_stop_streaming)(struct vb2_queue *vq);
--
2.53.0