media: imx: staging cleanup and remove frame interval monitor
v8 cover media: imx: staging cleanup and remove frame interval monitor
Changes in v8:
- Rebase onto the linux-media media-committers next branch. v7 was generated against Linus' master, which has diverged from the media tree (e.g. devm_kzalloc_obj vs devm_kzalloc), so the CI could not apply it. The patches now apply cleanly on top of media-committers next.
- Follow-up on the FIM removal: with FIM and the CSI core ops gone, the CSI subdev no longer registers any control or event, so drop the empty ctrl_hdlr, its init/free, and V4L2_SUBDEV_FL_HAS_EVENTS.
Patch 1 removes legacy control inheritance and source-dependent format handling from the capture video nodes. legacy_api is intentionally left
enabled: the remaining legacy-only ioctls (STD, frame-interval) are outside the TODO scope, and the MC path does not yet implement g_selection or SOURCE_CHANGE, so switching would silently drop them.
Patch 2 removes the i.MX-private frame interval monitor, as the media maintainer did not want it exported to v4l2-core and considers it dubious; it is disabled by default, undocumented for real use, and has no standard equivalent.
Validation:
- builds on media-committers next; applies cleanly with git am
- checkpatch.pl --strict is clean
- i.MX register-level and hardware DMA paths remain untested
Jiaqi Shi (2):
media: imx: remove legacy video node control and format handling
media: imx: remove frame interval monitor
Documentation/admin-guide/media/imx.rst | 31 +- .../userspace-api/media/drivers/imx-uapi.rst | 125 ----- .../userspace-api/media/drivers/index.rst | 1 - MAINTAINERS | 2 - drivers/staging/media/imx/Makefile | 2 +- drivers/staging/media/imx/TODO | 13 - drivers/staging/media/imx/imx-ic-prp.c | 1 - drivers/staging/media/imx/imx-ic-prpencvf.c | 11 +- drivers/staging/media/imx/imx-media-capture.c | 418 ++++++----------- drivers/staging/media/imx/imx-media-csi.c | 84 +--- .../staging/media/imx/imx-media-dev-common.c | 113 +---- drivers/staging/media/imx/imx-media-dev.c | 1 - drivers/staging/media/imx/imx-media-fim.c | 430 ------------------ drivers/staging/media/imx/imx-media-utils.c | 9 +- drivers/staging/media/imx/imx-media-vdic.c | 1 - drivers/staging/media/imx/imx-media.h | 21 +- include/linux/imx-media.h | 25 - include/media/imx.h | 11 - 18 files changed, 182 insertions(+), 1117 deletions(-) delete mode 100644 Documentation/userspace-api/media/drivers/imx-uapi.rst delete mode 100644 drivers/staging/media/imx/TODO delete mode 100644 drivers/staging/media/imx/imx-media-fim.c delete mode 100644 include/linux/imx-media.h delete mode 100644 include/media/imx.h
Signature · 1 line
2.53.0
PATCH v8 1/2 media: imx: remove legacy video node control and format handling
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.
--- 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(-)
Documentation/admin-guide/media/imx.rst +8 -12
@@ -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.
drivers/staging/media/imx/TODO +0 -10
@@ -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.
drivers/staging/media/imx/imx-ic-prpencvf.c +4 -6
@@ -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);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);v4l2_ctrl_handler_free (&priv->ctrl_hdlr); }
drivers/staging/media/imx/imx-media-capture.c +148 -253
584 lines not on this page · raw message
drivers/staging/media/imx/imx-media-csi.c +4 -6
@@ -266,7 +266,7 @@ static void csi_vb2_buf_done(struct csi_priv *priv) 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 ();
@@ -423,6 +423,7 @@ static int csi_idmac_setup_channel(struct csi_priv *priv,memset (&image,0 ,sizeof (image)); image.pix = vdev->fmt; + image.pix.field = vdev->stream_field; image.rect = vdev->compose;csi_idmac_setup_vb2_buf (priv, phys);
@@ -1815,7 +1816,7 @@ static int csi_registered(struct v4l2_subdev *sd) } priv->vdev =imx_media_capture_device_init (priv->sd.dev, &priv->sd, -CSI_SRC_PAD_IDMAC , true); +CSI_SRC_PAD_IDMAC , true, false);if (IS_ERR (priv->vdev)) { ret =PTR_ERR (priv->vdev); goto free_fim;
@@ -1823,12 +1824,10 @@ static int csi_registered(struct v4l2_subdev *sd) ret =imx_media_capture_device_register (priv->vdev,0 );if (ret) - goto remove_vdev; + goto free_fim;return 0 ; -remove_vdev: -imx_media_capture_device_remove (priv->vdev); free_fim:if (priv->fim)imx_media_fim_free (priv->fim);
@@ -1842,7 +1841,6 @@ static void csi_unregistered(struct v4l2_subdev *sd)struct csi_priv *priv =v4l2_get_subdevdata (sd);imx_media_capture_device_unregister (priv->vdev); -imx_media_capture_device_remove (priv->vdev);if (priv->fim)imx_media_fim_free (priv->fim);
drivers/staging/media/imx/imx-media-dev-common.c +1 -112
131 lines not on this page · raw message
drivers/staging/media/imx/imx-media-utils.c +7 -2
@@ -494,6 +494,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, {u32 width;u32 stride; +u64 sizeimage;if (!cc) { cc = imx_media_find_ipu_format(mbus->code,
@@ -534,8 +535,12 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, pix->quantization = mbus->quantization; pix->field = mbus->field; pix->bytesperline = stride; - pix->sizeimage = cc->planar ? ((stride * pix->height * cc->bpp) >>3 ) : - stride * pix->height; + sizeimage = (u64 )stride * pix->height; +if (cc->planar) + sizeimage = (sizeimage * cc->bpp) >>3 ; +if (sizeimage >U32_MAX ) +return -EINVAL ; + pix->sizeimage = sizeimage;return 0 ; }
drivers/staging/media/imx/imx-media.h +5 -6
@@ -109,6 +109,8 @@ struct imx_media_video_dev {/* the user format */ struct v4l2_pix_format fmt; +/* field order resolved for the current stream */ +u32 stream_field;/* the compose rectangle */ struct v4l2_rect compose;const struct imx_media_pixfmt *cc;
@@ -125,10 +127,8 @@ static inline struct imx_media_buffer *to_imx_media_vb(struct vb2_buffer *vb) }/* -* to support control inheritance to video devices, this -* retrieves a pad's list_head of video devices that can -* be reached from the pad. Note that only the lists in -* source pads get populated, sink pads have empty lists. +* Retrieve a pad's list of video devices reachable from the pad for +* subdev event forwarding. Only source pad lists are populated. */ static inline struct list_head *to_pad_vdev_list (struct v4l2_subdev *sd,int pad_index)
@@ -270,8 +270,7 @@ int imx_media_ic_unregister(struct v4l2_subdev *sd);/* imx-media-capture.c */ struct imx_media_video_dev *imx_media_capture_device_init (struct device *dev,struct v4l2_subdev *src_sd, -int pad,bool legacy_api); -void imx_media_capture_device_remove (struct imx_media_video_dev *vdev); +int pad,bool legacy_api,bool ic_route);int imx_media_capture_device_register (struct imx_media_video_dev *vdev,u32 link_flags);void imx_media_capture_device_unregister (struct imx_media_video_dev *vdev);
Signature · 1 line
2.53.0
Re: [PATCH v8 1/2] media: imx: remove legacy video node control and format handling
Quoted 143 lines · Jiaqi Shi
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 <[email protected]>--- 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(-)Documentation/admin-guide/media/imx.rst +8
-12@@ -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.drivers/staging/media/imx/TODO +0
-10@@ -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.drivers/staging/media/imx/imx-ic-prpencvf.c +4
-3@@ -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)
drivers/staging/media/imx/imx-ic-prpencvf.c static int prp_registered(struct v4l2_subdev *sd) · line 1299
Quoted 5 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-2@@ -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.
drivers/staging/media/imx/imx-ic-prpencvf.c static void prp_unregistered(struct v4l2_subdev *sd) · line 1308
Quoted 8 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-1return 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?
Quoted 213 lines
drivers/staging/media/imx/imx-ic-prpencvf.c +0
-0v4l2_ctrl_handler_free (&priv->ctrl_hdlr); }drivers/staging/media/imx/imx-media-capture.c +79
-34@@ -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 ; }
drivers/staging/media/imx/imx-media-capture.c static int capture_s_fmt_vid_cap(struct file *file, void *fh, · line 246
Quoted 7 lines
drivers/staging/media/imx/imx-media-capture.c +3
-1@@ -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
Re: [PATCH v8 1/2] media: imx: remove legacy video node control and format handling
Hi Frank,
Quoted 4 lines · Frank Li
This part belong to bug fix, missed
imx_media_capture_device_remove()at error path, user seperate patch to fix it.why remove it here?
Let me clarify, because I see this as a consequence of dropping the control inheritance, not as a separate bug fix.
Once capture video nodes no longer inherit controls from the pipeline, the per-video-device control handler (priv->ctrl_hdlr) is never populated anymore. imx_media_capture_device_remove() only frees that handler, so it becomes a no-op and is removed together with its call sites:
- prp_registered(): on register failure it used to jump to remove_vdev and free the (now non-existent) handler; with the handler gone, a plain "return ret" is correct.
- prp_unregistered(): it no longer calls remove(), because that function no longer exists. The ctrl_hdlr freed on the next line is the PRP subdev's own handler, not the video node's.
So I don't think the original error path had a bug; it is the removal of the handler that made remove() unnecessary. If you still see a separate bug here, could you point out what it is? I want to make sure I fix the right thing.
Quoted 2 lines
Can you split to more small patches, such as just add priv for
__capture_try_fmt()
Agreed, the current patch is too large and mixes several independent changes. I will split it into smaller patches, roughly in this order:
- remove subdev control inheritance (and the now-unused video-node control handler together with imx_media_capture_device_remove())
- remove legacy format handling
- improve format validation: pass priv to __capture_try_fmt() for ic_route, sanitize field, clamp dimensions, resolve colorimetry, and handle size overflow
Regards,
Jiaqi
PATCH v8 2/2 media: imx: remove frame interval monitor
In reply to Jiaqi ShiThe frame interval monitor is an i.MX-private feature that measures CSI frame intervals using private controls and a private event. It is disabled by default, is only wired into the CSI driver, and aside from the driver-specific UAPI page has no documentation.
There is no evidence of a real userspace consumer, and the media maintainer considers it dubious for v4l2-core. Remove it rather than exporting it to the core as previously suggested in the TODO.
This drops imx-media-fim.c, the private control and event definitions in include/linux/imx-media.h along with the include/media/imx.h wrapper, the CSI integration, the capture event subscriptions, the driver-specific UAPI documentation, and the remaining TODO entry.
--- Documentation/admin-guide/media/imx.rst | 15 +- .../userspace-api/media/drivers/imx-uapi.rst | 125 ----- .../userspace-api/media/drivers/index.rst | 1 - MAINTAINERS | 2 - drivers/staging/media/imx/Makefile | 2 +- drivers/staging/media/imx/TODO | 3 - drivers/staging/media/imx/imx-ic-prp.c | 1 - drivers/staging/media/imx/imx-ic-prpencvf.c | 1 - drivers/staging/media/imx/imx-media-capture.c | 17 - drivers/staging/media/imx/imx-media-csi.c | 76 +--- drivers/staging/media/imx/imx-media-dev.c | 1 - drivers/staging/media/imx/imx-media-fim.c | 430 ------------------ drivers/staging/media/imx/imx-media-vdic.c | 1 - drivers/staging/media/imx/imx-media.h | 10 - include/linux/imx-media.h | 25 - include/media/imx.h | 11 - 16 files changed, 8 insertions(+), 713 deletions(-) delete mode 100644 Documentation/userspace-api/media/drivers/imx-uapi.rst delete mode 100644 drivers/staging/media/imx/TODO delete mode 100644 drivers/staging/media/imx/imx-media-fim.c delete mode 100644 include/linux/imx-media.h delete mode 100644 include/media/imx.h
Documentation/admin-guide/media/imx.rst +1 -14
@@ -98,9 +98,6 @@ Some of the features of this driver include: CSI. There is also support in the future for sending frames to the VDIC from memory buffers via output/mem2mem devices. -- Includes a Frame Interval Monitor (FIM) that can correct vertical sync - problems with the ADV718x video decoders. - Topology --------
@@ -220,8 +217,6 @@ or unqualified interlaced). The capture interface will enforce the same field order as the source pad field order (interlaced-bt if source pad is seq-bt, interlaced-tb if source pad is seq-tb). -For events produced by ipuX_csiY, see ref:`imx_api_ipuX_csiY`. - Cropping in ipuX_csiY ---------------------
@@ -266,11 +261,6 @@ rate by half at the IDMAC output source pad: media-ctl -V "'ipu1_csi0':0[fmt:UYVY2X8/640x480@1/60]" media-ctl -V "'ipu1_csi0':2[fmt:UYVY2X8/640x480@1/30]" -Frame Interval Monitor in ipuX_csiY ------------------------------------ - -See ref:`imx_api_FIM`. - ipuX_vdic ---------
@@ -395,8 +385,7 @@ Usage Notes ----------- Controls for pipeline entities are accessed through their subdev device -nodes. For example, the FIM controls are available from the ipuX_csiY -subdevs. +nodes. The following are specific usage notes for the Sabre* reference boards:
@@ -690,8 +679,6 @@ File list --------- drivers/staging/media/imx/ -include/media/imx.h -include/linux/imx-media.h References ----------
Documentation/userspace-api/media/drivers/imx-uapi.rst deleted +0 -125
125 lines not on this page · raw message
Documentation/userspace-api/media/drivers/index.rst +0 -1
@@ -32,7 +32,6 @@ For more details see the file COPYING in the source distribution of Linux. cx2341x-uapi dcmipp dw100 - imx-uapi mali-c55 max2175 npcm-video
MAINTAINERS +0 -2
@@ -16787,8 +16787,6 @@ T: git git://linuxtv.org/media.git F: Documentation/admin-guide/media/imx.rst F: Documentation/devicetree/bindings/media/fsl,imx6-mipi-csi2.yaml F: drivers/staging/media/imx/ -F: include/linux/imx-media.h -F: include/media/imx.h MEDIA DRIVERS FOR FREESCALE IMX7/8 M: Laurent Pinchart <[email protected]>
drivers/staging/media/imx/Makefile +1 -1
@@ -6,7 +6,7 @@ imx6-media-objs := imx-media-dev.o imx-media-internal-sd.o \ imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o imx-media-vdic.o \ imx-media-csc-scaler.o -imx6-media-csi-objs := imx-media-csi.o imx-media-fim.o +imx6-media-csi-objs := imx-media-csi.o obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx6-media.o
drivers/staging/media/imx/TODO deleted +0 -3
@@ -1,3 +0,0 @@ - -- The Frame Interval Monitor could be exported to v4l2-core for - general use.
drivers/staging/media/imx/imx-ic-prp.c +0 -1
@@ -18,7 +18,6 @@#include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-subdev.h> -#include <media/imx.h> #include "imx-media.h" #include "imx-ic.h"
drivers/staging/media/imx/imx-ic-prpencvf.c +0 -1
@@ -19,7 +19,6 @@#include <media/v4l2-ioctl.h> #include <media/v4l2-mc.h> #include <media/v4l2-subdev.h> -#include <media/imx.h> #include "imx-media.h" #include "imx-ic.h"
drivers/staging/media/imx/imx-media-capture.c +0 -17
@@ -21,7 +21,6 @@#include <media/v4l2-subdev.h> #include <media/videobuf2-dma-contig.h> #include <video/imx-ipu-v3.h> -#include <media/imx.h> #include "imx-media.h" #define IMX_CAPTURE_NAME "imx-capture"
@@ -282,17 +281,6 @@ static int capture_g_selection(struct file *file, void *fh,return 0 ; } -static int capture_subscribe_event (struct v4l2_fh *fh, -const struct v4l2_event_subscription *sub) -{ -switch (sub->type) { -case V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR : -return v4l2_event_subscribe (fh, sub,0 ,NULL ); -default : -return -EINVAL ; - } -} -static const struct v4l2_ioctl_ops capture_ioctl_ops = { .vidioc_querycap = capture_querycap,
@@ -314,9 +302,6 @@ static const struct v4l2_ioctl_ops capture_ioctl_ops = { .vidioc_expbuf = vb2_ioctl_expbuf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, - - .vidioc_subscribe_event = capture_subscribe_event, - .vidioc_unsubscribe_event = v4l2_event_unsubscribe, };/* -----------------------------------------------------------------------------
@@ -431,8 +416,6 @@ static int capture_legacy_subscribe_event(struct v4l2_fh *fh, const struct v4l2_event_subscription *sub) {switch (sub->type) { -case V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR : -return v4l2_event_subscribe (fh, sub,0 ,NULL );case V4L2_EVENT_SOURCE_CHANGE :return v4l2_src_change_event_subscribe (fh, sub);default :
drivers/staging/media/imx/imx-media-csi.c +6 -70
215 lines not on this page · raw message
drivers/staging/media/imx/imx-media-dev.c +0 -1
@@ -8,7 +8,6 @@#include <linux/platform_device.h> #include <media/v4l2-async.h> #include <media/v4l2-event.h> -#include <media/imx.h> #include "imx-media.h" static inline struct imx_media_dev *notifier2dev (struct v4l2_async_notifier *n)
drivers/staging/media/imx/imx-media-fim.c deleted +0 -430
430 lines not on this page · raw message
drivers/staging/media/imx/imx-media-vdic.c +0 -1
@@ -9,7 +9,6 @@#include <media/v4l2-ioctl.h> #include <media/v4l2-mc.h> #include <media/v4l2-subdev.h> -#include <media/imx.h> #include "imx-media.h" /*
drivers/staging/media/imx/imx-media.h +0 -10
@@ -234,16 +234,6 @@ struct imx_media_dev *imx_media_dev_init(struct device *dev,int imx_media_dev_notifier_register (struct imx_media_dev *imxmd,const struct v4l2_async_notifier_operations *ops); -/* imx-media-fim.c */ -struct imx_media_fim ; -void imx_media_fim_eof_monitor (struct imx_media_fim *fim,ktime_t timestamp); -void imx_media_fim_set_stream (struct imx_media_fim *fim, -const struct v4l2_fract *frame_interval, -bool on); -int imx_media_fim_add_controls (struct imx_media_fim *fim); -struct imx_media_fim *imx_media_fim_init (struct v4l2_subdev *sd); -void imx_media_fim_free (struct imx_media_fim *fim); -/* imx-media-internal-sd.c */ int imx_media_register_ipu_internal_subdevs (struct imx_media_dev *imxmd,struct v4l2_subdev *csi);
include/linux/imx-media.h deleted +0 -25
@@ -1,25 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* Copyright (c) 2014-2017 Mentor Graphics Inc. -*/ - -#ifndef __LINUX_IMX_MEDIA_H__ -#define __LINUX_IMX_MEDIA_H__ - -/* -* events from the subdevs -*/ -#define V4L2_EVENT_IMX_CLASS V4L2_EVENT_PRIVATE_START -#define V4L2_EVENT_IMX_FRAME_INTERVAL_ERROR (V4L2_EVENT_IMX_CLASS + 1) - -enum imx_ctrl_id { -V4L2_CID_IMX_FIM_ENABLE = (V4L2_CID_USER_IMX_BASE +0 ), -V4L2_CID_IMX_FIM_NUM , -V4L2_CID_IMX_FIM_TOLERANCE_MIN , -V4L2_CID_IMX_FIM_TOLERANCE_MAX , -V4L2_CID_IMX_FIM_NUM_SKIP , -V4L2_CID_IMX_FIM_ICAP_EDGE , -V4L2_CID_IMX_FIM_ICAP_CHANNEL , -}; - -#endif
include/media/imx.h deleted +0 -11
@@ -1,11 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ -/* -* Copyright (c) 2014-2017 Mentor Graphics Inc. -*/ - -#ifndef __MEDIA_IMX_H__ -#define __MEDIA_IMX_H__ - -#include <linux/imx-media.h> - -#endif
Signature · 1 line
2.53.0