media: imx: utils: Add ability to filter pixel formats by mbus code
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 15 Feb 2021 04:26:30 +0000 (05:26 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Thu, 11 Mar 2021 10:59:46 +0000 (11:59 +0100)
Add a media bus code argument to the imx_media_enum_pixel_formats(). If
set to a non-zero value, the function will only consider pixel formats
that match the given media bus code.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rui Miguel Silva <rmfrfs@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/imx/imx-media-capture.c
drivers/staging/media/imx/imx-media-csc-scaler.c
drivers/staging/media/imx/imx-media-utils.c
drivers/staging/media/imx/imx-media.h

index e10ce103a5b4ff4fe7fe79d5f9d479711677a6ce..bea3467e017cf9529d7a88789ceba0d59095f5ff 100644 (file)
@@ -174,7 +174,8 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
                        (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
                        PIXFMT_SEL_YUV : PIXFMT_SEL_RGB;
 
-               ret = imx_media_enum_pixel_formats(&fourcc, f->index, fmt_sel);
+               ret = imx_media_enum_pixel_formats(&fourcc, f->index, fmt_sel,
+                                                  0);
                if (ret)
                        return ret;
        } else {
@@ -223,7 +224,7 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
 
                cc = imx_media_find_pixel_format(fourcc, fmt_sel);
                if (!cc) {
-                       imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel);
+                       imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel, 0);
                        cc = imx_media_find_pixel_format(fourcc, fmt_sel);
                }
        } else {
index 63a0204502a8bb4bf552e0ed68339a5124c41bc2..eb6da9b9d8ba8f3791e80cedf0287f539d1b82eb 100644 (file)
@@ -167,7 +167,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,
        int ret;
 
        ret = imx_media_enum_pixel_formats(&fourcc, f->index,
-                                          PIXFMT_SEL_YUV_RGB);
+                                          PIXFMT_SEL_YUV_RGB, 0);
        if (ret)
                return ret;
 
index c2088f7ceef5528cc70ee4bd047d74dbc82840fa..5128915a5d6f47a100bbbdd4bf17b788d37c676f 100644 (file)
@@ -283,9 +283,11 @@ EXPORT_SYMBOL_GPL(imx_media_find_mbus_format);
  * @index: The requested match index.
  * @fmt_sel: Include in the enumeration entries with the given selection
  *           criteria.
+ * @code: If non-zero, only include in the enumeration entries matching this
+ *     media bus code.
  */
 int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
-                                enum imx_pixfmt_sel fmt_sel)
+                                enum imx_pixfmt_sel fmt_sel, u32 code)
 {
        bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU;
        unsigned int i;
@@ -306,6 +308,25 @@ int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
                if (!(fmt_sel & sel))
                        continue;
 
+               /*
+                * If a media bus code is specified, only consider formats that
+                * match it.
+                */
+               if (code) {
+                       unsigned int j;
+
+                       if (!fmt->codes)
+                               continue;
+
+                       for (j = 0; fmt->codes[j]; j++) {
+                               if (code == fmt->codes[j])
+                                       break;
+                       }
+
+                       if (!fmt->codes[j])
+                               continue;
+               }
+
                if (index == 0) {
                        *fourcc = fmt->fourcc;
                        return 0;
index 1abb9bb88c12c864962c5a151f47e034408a3eae..085110eec87eab194ecf63abfa876ed089919dc5 100644 (file)
@@ -170,7 +170,7 @@ struct imx_media_dev {
 const struct imx_media_pixfmt *
 imx_media_find_pixel_format(u32 fourcc, enum imx_pixfmt_sel sel);
 int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
-                                enum imx_pixfmt_sel sel);
+                                enum imx_pixfmt_sel sel, u32 code);
 const struct imx_media_pixfmt *
 imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel sel);
 int imx_media_enum_mbus_formats(u32 *code, u32 index,