From: Frank Li <Frank.li@oss.nxp.com>
To: Jiaqi Shi <shijiaqi_develop@163.com>
Cc: linux-media@vger.kernel.org, imx@lists.linux.dev,
linux-staging@lists.linux.dev, slongerbeam@gmail.com,
p.zabel@pengutronix.de, mchehab@kernel.org,
gregkh@linuxfoundation.org, Frank.Li@nxp.com,
kernel@pengutronix.de, festevam@gmail.com
Subject: Re: [PATCH v8 1/2] media: imx: remove legacy video node control and format handling
Date: Tue, 1 Dec 2026 10:21:40 -0600 [thread overview]
Message-ID: <aw70FGD_BhkVbKp4@SMW015318> (raw)
In-Reply-To: <20261201152647.847238-2-shijiaqi_develop@163.com>
On Tue, Dec 01, 2026 at 11:26:46PM +0800, Jiaqi Shi wrote:
> Remove control inheritance from pipeline subdevices to video nodes.
> Userspace should access controls through subdev nodes instead.
>
> Use source-independent format ioctls for all capture nodes and
> initialize them to the existing UYVY 640x480 default instead of the
> source subdev active format. Keep stream-time format validation.
>
> Update the usage documentation and remove the completed TODO entries.
>
> Signed-off-by: Jiaqi Shi <shijiaqi_develop@163.com>
> ---
> Documentation/admin-guide/media/imx.rst | 20 +-
> drivers/staging/media/imx/TODO | 10 -
> drivers/staging/media/imx/imx-ic-prpencvf.c | 10 +-
> drivers/staging/media/imx/imx-media-capture.c | 401 +++++++-----------
> drivers/staging/media/imx/imx-media-csi.c | 10 +-
> .../staging/media/imx/imx-media-dev-common.c | 113 +----
> drivers/staging/media/imx/imx-media-utils.c | 9 +-
> drivers/staging/media/imx/imx-media.h | 11 +-
> 8 files changed, 177 insertions(+), 407 deletions(-)
>
> diff --git a/Documentation/admin-guide/media/imx.rst b/Documentation/admin-guide/media/imx.rst
> index bb68100d8acb..812c6ac09ab8 100644
> --- a/Documentation/admin-guide/media/imx.rst
> +++ b/Documentation/admin-guide/media/imx.rst
> @@ -394,13 +394,9 @@ scaling up to 1024x1024, CSC, flip, and rotation:
> Usage Notes
> -----------
>
> -To aid in configuration and for backward compatibility with V4L2
> -applications that access controls only from video device nodes, the
> -capture device interfaces inherit controls from the active entities
> -in the current pipeline, so controls can be accessed either directly
> -from the subdev or from the active capture device interface. For
> -example, the FIM controls are available either from the ipuX_csiY
> -subdevs or from the active capture device.
> +Controls for pipeline entities are accessed through their subdev device
> +nodes. For example, the FIM controls are available from the ipuX_csiY
> +subdevs.
>
> The following are specific usage notes for the Sabre* reference
> boards:
> @@ -483,7 +479,7 @@ NTSC, or 'alternate'):
> media-ctl -V "'ipu1_csi0_mux':2 [fmt:UYVY2X8/720x480]"
> media-ctl -V "'ipu1_csi0':2 [fmt:AYUV32/720x480]"
> # Configure "ipu1_csi0 capture" interface (assumed at /dev/video4)
> - v4l2-ctl -d4 --set-fmt-video=field=interlaced_bt
> + v4l2-ctl -d4 --set-fmt-video=width=720,height=480,field=interlaced_bt
>
> Streaming can then begin on /dev/video4. The v4l2-ctl tool can also be
> used to select any supported YUV pixelformat on /dev/video4.
> @@ -510,7 +506,7 @@ alternating fields (field type 'seq-tb' for PAL, or 'alternate').
> media-ctl -V "'ipu1_ic_prp':2 [fmt:AYUV32/720x576 field:none]"
> media-ctl -V "'ipu1_ic_prpvf':1 [fmt:AYUV32/720x576 field:none]"
> # Configure "ipu1_ic_prpvf capture" interface (assumed at /dev/video2)
> - v4l2-ctl -d2 --set-fmt-video=field=none
> + v4l2-ctl -d2 --set-fmt-video=width=720,height=576,field=none
>
> Streaming can then begin on /dev/video2. The v4l2-ctl tool can also be
> used to select any supported YUV pixelformat on /dev/video2.
> @@ -541,7 +537,7 @@ NTSC, or 'alternate'):
> media-ctl -V "'ipu1_csi0_mux':5 [fmt:UYVY2X8/720x480]"
> media-ctl -V "'ipu1_csi0':2 [fmt:AYUV32/720x480]"
> # Configure "ipu1_csi0 capture" interface (assumed at /dev/video0)
> - v4l2-ctl -d0 --set-fmt-video=field=interlaced_bt
> + v4l2-ctl -d0 --set-fmt-video=width=720,height=480,field=interlaced_bt
>
> Streaming can then begin on /dev/video0. The v4l2-ctl tool can also be
> used to select any supported YUV pixelformat on /dev/video0.
> @@ -568,7 +564,7 @@ alternating fields (field type 'seq-tb' for PAL, or 'alternate').
> media-ctl -V "'ipu1_ic_prp':2 [fmt:AYUV32/720x576 field:none]"
> media-ctl -V "'ipu1_ic_prpvf':1 [fmt:AYUV32/720x576 field:none]"
> # Configure "ipu1_ic_prpvf capture" interface (assumed at /dev/video2)
> - v4l2-ctl -d2 --set-fmt-video=field=none
> + v4l2-ctl -d2 --set-fmt-video=width=720,height=576,field=none
>
> Streaming can then begin on /dev/video2. The v4l2-ctl tool can also be
> used to select any supported YUV pixelformat on /dev/video2.
> @@ -652,7 +648,7 @@ shows colorspace conversion and scaling at IC output.
> media-ctl -V "'ipu1_ic_prp':1 [fmt:AYUV32/640x480]"
> media-ctl -V "'ipu1_ic_prpenc':1 [fmt:ARGB8888_1X32/800x600]"
> # Set a format at the capture interface
> - v4l2-ctl -d /dev/video1 --set-fmt-video=pixelformat=RGB3
> + v4l2-ctl -d /dev/video1 --set-fmt-video=width=800,height=600,pixelformat=RGB3
>
> Streaming can then begin on "ipu1_ic_prpenc capture" node.
>
> diff --git a/drivers/staging/media/imx/TODO b/drivers/staging/media/imx/TODO
> index 11c9e10d34ae..43cd030d4bbd 100644
> --- a/drivers/staging/media/imx/TODO
> +++ b/drivers/staging/media/imx/TODO
> @@ -1,13 +1,3 @@
>
> - The Frame Interval Monitor could be exported to v4l2-core for
> general use.
> -
> -- This media driver supports inheriting V4L2 controls to the
> - video capture devices, from the subdevices in the capture device's
> - pipeline. The controls for each capture device are updated in the
> - link_notify callback when the pipeline is modified. This feature should be
> - removed, userspace should use the subdev-based userspace API instead.
> -
> -- Similarly to the legacy control handling, legacy format handling where
> - formats on the video nodes are influenced by the active format of the
> - connected subdev should be removed.
> diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c
> index aaa2248780a8..979d124c19ea 100644
> --- a/drivers/staging/media/imx/imx-ic-prpencvf.c
> +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c
> @@ -203,7 +203,7 @@ static void prp_vb2_buf_done(struct prp_priv *priv, struct ipuv3_channel *ch)
>
> done = priv->active_vb2_buf[priv->ipu_buf_num];
> if (done) {
> - done->vbuf.field = vdev->fmt.field;
> + done->vbuf.field = vdev->stream_field;
> done->vbuf.sequence = priv->frame_sequence;
> vb = &done->vbuf.vb2_buf;
> vb->timestamp = ktime_get_ns();
> @@ -362,6 +362,7 @@ static int prp_setup_channel(struct prp_priv *priv,
>
> memset(&image, 0, sizeof(image));
> image.pix = vdev->fmt;
> + image.pix.field = vdev->stream_field;
> image.rect = vdev->compose;
>
> /*
> @@ -1279,13 +1280,13 @@ static int prp_registered(struct v4l2_subdev *sd)
>
> priv->vdev = imx_media_capture_device_init(ic_priv->ipu_dev,
> &ic_priv->sd,
> - PRPENCVF_SRC_PAD, true);
> + PRPENCVF_SRC_PAD, true, true);
> if (IS_ERR(priv->vdev))
> return PTR_ERR(priv->vdev);
>
> ret = imx_media_capture_device_register(priv->vdev, 0);
> if (ret)
> - goto remove_vdev;
> + return ret;
>
> ret = prp_init_controls(priv);
> if (ret)
> @@ -1295,8 +1296,6 @@ static int prp_registered(struct v4l2_subdev *sd)
>
> unreg_vdev:
> imx_media_capture_device_unregister(priv->vdev);
> -remove_vdev:
> - imx_media_capture_device_remove(priv->vdev);
This part belong to bug fix, missed imx_media_capture_device_remove()
at error path, user seperate patch to fix it.
> return ret;
> }
>
> @@ -1305,7 +1304,6 @@ static void prp_unregistered(struct v4l2_subdev *sd)
> struct prp_priv *priv = sd_to_priv(sd);
>
> imx_media_capture_device_unregister(priv->vdev);
> - imx_media_capture_device_remove(priv->vdev);
why remove it here?
>
> v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
> }
> diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
> index 9216a221b72f..2bd3f336b36b 100644
> --- a/drivers/staging/media/imx/imx-media-capture.c
> +++ b/drivers/staging/media/imx/imx-media-capture.c
> @@ -5,6 +5,7 @@
> * Copyright (c) 2012-2016 Mentor Graphics Inc.
> */
> #include <linux/delay.h>
> +#include <linux/math64.h>
> #include <linux/module.h>
> #include <linux/pinctrl/consumer.h>
> #include <linux/platform_device.h>
> @@ -12,7 +13,6 @@
> #include <linux/slab.h>
> #include <linux/spinlock.h>
> #include <linux/timer.h>
> -#include <media/v4l2-ctrls.h>
> #include <media/v4l2-device.h>
> #include <media/v4l2-event.h>
> #include <media/v4l2-fwnode.h>
> @@ -35,16 +35,13 @@ struct capture_priv {
>
> struct v4l2_subdev *src_sd; /* Source subdev */
> int src_sd_pad; /* Source subdev pad */
> + bool ic_route; /* Source is an IC entity */
>
> struct mutex mutex; /* Protect vdev operations */
>
> struct vb2_queue q; /* The videobuf2 queue */
> struct list_head ready_q; /* List of queued buffers */
> spinlock_t q_lock; /* Protect ready_q */
> -
> - struct v4l2_ctrl_handler ctrl_hdlr; /* Controls inherited from subdevs */
> -
> - bool legacy_api; /* Use the legacy (pre-MC) API */
> };
>
> #define to_capture_priv(v) container_of(v, struct capture_priv, vdev)
> @@ -56,25 +53,33 @@ struct capture_priv {
> * MC-Centric Video IOCTLs
> */
>
> +static enum imx_pixfmt_sel capture_format_sel(struct capture_priv *priv)
> +{
> + return priv->ic ? PIXFMT_SEL_YUV_RGB : PIXFMT_SEL_ANY;
> +}
> +
> static const struct imx_media_pixfmt *capture_find_format(u32 code, u32 fourcc)
> {
> const struct imx_media_pixfmt *cc;
> + unsigned int i;
>
> cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV_RGB);
> if (cc) {
> enum imx_pixfmt_sel fmt_sel = cc->cs == IPUV3_COLORSPACE_YUV
> - ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
> -
> - cc = imx_media_find_pixel_format(fourcc, fmt_sel);
> - if (!cc) {
> - imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
> - cc = imx_media_find_pixel_format(fourcc, fmt_sel);
> - }
> + ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
>
> - return cc;
> + return imx_media_find_pixel_format(fourcc, fmt_sel);
> }
>
> - return imx_media_find_mbus_format(code, PIXFMT_SEL_ANY);
> + cc = imx_media_find_pixel_format(fourcc, PIXFMT_SEL_ANY);
> + if (!cc || !cc->codes)
> + return NULL;
> +
> + for (i = 0; cc->codes[i]; i++)
> + if (cc->codes[i] == code)
> + return cc;
> +
> + return NULL;
> }
>
> static int capture_querycap(struct file *file, void *fh,
> @@ -93,19 +98,24 @@ static int capture_querycap(struct file *file, void *fh,
> static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
> struct v4l2_fmtdesc *f)
> {
> + struct capture_priv *priv = video_drvdata(file);
> +
> return imx_media_enum_pixel_formats(&f->pixelformat, f->index,
> - PIXFMT_SEL_ANY, f->mbus_code);
> + capture_format_sel(priv),
> + f->mbus_code);
> }
>
> static int capture_enum_framesizes(struct file *file, void *fh,
> struct v4l2_frmsizeenum *fsize)
> {
> + struct capture_priv *priv = video_drvdata(file);
> const struct imx_media_pixfmt *cc;
>
> if (fsize->index > 0)
> return -EINVAL;
>
> - cc = imx_media_find_pixel_format(fsize->pixel_format, PIXFMT_SEL_ANY);
> + cc = imx_media_find_pixel_format(fsize->pixel_format,
> + capture_format_sel(priv));
> if (!cc)
> return -EINVAL;
>
> @@ -136,39 +146,70 @@ static int capture_g_fmt_vid_cap(struct file *file, void *fh,
> }
>
> static const struct imx_media_pixfmt *
> -__capture_try_fmt(struct v4l2_pix_format *pixfmt, struct v4l2_rect *compose)
> +__capture_try_fmt(struct capture_priv *priv, struct v4l2_pix_format *pixfmt,
> + struct v4l2_rect *compose)
> {
> struct v4l2_mbus_framefmt fmt_src;
> const struct imx_media_pixfmt *cc;
> + enum imx_pixfmt_sel fmt_sel = capture_format_sel(priv);
> + int ret;
>
> /*
> * Find the pixel format, default to the first supported format if not
> * found.
> */
> - cc = imx_media_find_pixel_format(pixfmt->pixelformat, PIXFMT_SEL_ANY);
> + cc = imx_media_find_pixel_format(pixfmt->pixelformat, fmt_sel);
> if (!cc) {
> imx_media_enum_pixel_formats(&pixfmt->pixelformat, 0,
> - PIXFMT_SEL_ANY, 0);
> + fmt_sel, 0);
> cc = imx_media_find_pixel_format(pixfmt->pixelformat,
> - PIXFMT_SEL_ANY);
> + fmt_sel);
> }
>
> - /* Allow IDMAC interweave but enforce field order from source. */
> - if (V4L2_FIELD_IS_INTERLACED(pixfmt->field)) {
> - switch (pixfmt->field) {
> - case V4L2_FIELD_SEQ_TB:
> - pixfmt->field = V4L2_FIELD_INTERLACED_TB;
> - break;
> - case V4L2_FIELD_SEQ_BT:
> - pixfmt->field = V4L2_FIELD_INTERLACED_BT;
> - break;
> - default:
> - break;
> - }
> + switch (pixfmt->field) {
> + case V4L2_FIELD_ANY:
> + pixfmt->field = V4L2_FIELD_NONE;
> + break;
> + case V4L2_FIELD_NONE:
> + case V4L2_FIELD_INTERLACED:
> + case V4L2_FIELD_INTERLACED_TB:
> + case V4L2_FIELD_INTERLACED_BT:
> + case V4L2_FIELD_SEQ_TB:
> + case V4L2_FIELD_SEQ_BT:
> + case V4L2_FIELD_ALTERNATE:
> + break;
> + default:
> + pixfmt->field = V4L2_FIELD_NONE;
> + break;
> }
>
> + /* Clamp dimensions to prevent zero-sized buffers. */
> + pixfmt->width = clamp(pixfmt->width, 1, 65535);
> + pixfmt->height = clamp(pixfmt->height, 1, 65535);
> +
> v4l2_fill_mbus_format(&fmt_src, pixfmt, 0);
> - imx_media_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src, cc);
> + if (cc->cs == IPUV3_COLORSPACE_RGB &&
> + fmt_src.quantization == V4L2_QUANTIZATION_DEFAULT)
> + fmt_src.quantization = V4L2_QUANTIZATION_FULL_RANGE;
> + imx_media_try_colorimetry(&fmt_src, priv->ic_route);
> +
> + ret = imx_media_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src, cc);
> + if (ret) {
> + u64 divisor = (u64)pixfmt->bytesperline *
> + (cc->planar ? cc->bpp : 8);
> +
> + if (!divisor)
> + return NULL;
> +
> + fmt_src.height = div64_u64((u64)U32_MAX * 8, divisor);
> + if (!fmt_src.height)
> + return NULL;
> +
> + pixfmt->height = fmt_src.height;
> + ret = imx_media_mbus_fmt_to_pix_fmt(pixfmt, &fmt_src, cc);
> + if (ret)
> + return NULL;
> + }
>
> if (compose) {
> compose->width = fmt_src.width;
> @@ -181,7 +222,11 @@ __capture_try_fmt(struct v4l2_pix_format *pixfmt, struct v4l2_rect *compose)
> static int capture_try_fmt_vid_cap(struct file *file, void *fh,
> struct v4l2_format *f)
> {
> - __capture_try_fmt(&f->fmt.pix, NULL);
> + struct capture_priv *priv = video_drvdata(file);
> +
> + if (!__capture_try_fmt(priv, &f->fmt.pix, NULL))
> + return -EINVAL;
> +
> return 0;
> }
>
> @@ -196,10 +241,13 @@ static int capture_s_fmt_vid_cap(struct file *file, void *fh,
> return -EBUSY;
> }
>
> - cc = __capture_try_fmt(&f->fmt.pix, &priv->vdev.compose);
> + cc = __capture_try_fmt(priv, &f->fmt.pix, &priv->vdev.compose);
> + if (!cc)
> + return -EINVAL;
Can you split to more small patches, such as just add priv for
__capture_try_fmt()
Frank
next prev parent reply other threads:[~2026-12-01 16:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 15:26 [PATCH v8 0/2] media: imx: staging cleanup and remove frame interval monitor Jiaqi Shi
2026-12-01 15:26 ` [PATCH v8 1/2] media: imx: remove legacy video node control and format handling Jiaqi Shi
2026-12-01 16:21 ` Frank Li [this message]
2026-12-01 15:26 ` [PATCH v8 2/2] media: imx: remove frame interval monitor Jiaqi Shi
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=aw70FGD_BhkVbKp4@SMW015318 \
--to=frank.li@oss.nxp.com \
--cc=Frank.Li@nxp.com \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-media@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=shijiaqi_develop@163.com \
--cc=slongerbeam@gmail.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