Linux-Media Archive on lore.kernel.org
 help / color / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: Steve Longerbeam <slongerbeam@gmail.com>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	Rui Miguel Silva <rmfrfs@gmail.com>
Subject: [PATCH v2 11/11] media: imx: utils: Add ability to filter pixel formats by mbus code
Date: Fri, 27 Mar 2020 00:08:40 +0200
Message-ID: <20200326220840.18540-12-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com>

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>
---
 drivers/staging/media/imx/imx-media-capture.c |  5 +++--
 .../staging/media/imx/imx-media-csc-scaler.c  |  2 +-
 drivers/staging/media/imx/imx-media-utils.c   | 21 ++++++++++++++++++-
 drivers/staging/media/imx/imx-media.h         |  2 +-
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c
index 1b3f783f3f72..9924840dd15e 100644
--- a/drivers/staging/media/imx/imx-media-capture.c
+++ b/drivers/staging/media/imx/imx-media-capture.c
@@ -174,7 +174,8 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh,
 		u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ?
 			CS_SEL_YUV : CS_SEL_RGB;
 
-		ret = imx_media_enum_pixel_formats(&fourcc, f->index, cs_sel);
+		ret = imx_media_enum_pixel_formats(&fourcc, f->index, cs_sel,
+						   0);
 		if (ret)
 			return ret;
 	} else {
@@ -221,7 +222,7 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv,
 
 		cc = imx_media_find_pixel_format(fourcc, cs_sel);
 		if (!cc) {
-			imx_media_enum_pixel_formats(&fourcc, 0, cs_sel);
+			imx_media_enum_pixel_formats(&fourcc, 0, cs_sel, 0);
 			cc = imx_media_find_pixel_format(fourcc, cs_sel);
 		}
 	} else {
diff --git a/drivers/staging/media/imx/imx-media-csc-scaler.c b/drivers/staging/media/imx/imx-media-csc-scaler.c
index d8904a78228d..426d1ff3b62c 100644
--- a/drivers/staging/media/imx/imx-media-csc-scaler.c
+++ b/drivers/staging/media/imx/imx-media-csc-scaler.c
@@ -164,7 +164,7 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh,
 	u32 fourcc;
 	int ret;
 
-	ret = imx_media_enum_pixel_formats(&fourcc, f->index, CS_SEL_ANY);
+	ret = imx_media_enum_pixel_formats(&fourcc, f->index, CS_SEL_ANY, 0);
 	if (ret)
 		return ret;
 
diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c
index ff2202e95a48..1efdfa751523 100644
--- a/drivers/staging/media/imx/imx-media-utils.c
+++ b/drivers/staging/media/imx/imx-media-utils.c
@@ -220,7 +220,7 @@ imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel)
 EXPORT_SYMBOL_GPL(imx_media_find_pixel_format);
 
 int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
-				 enum codespace_sel cs_sel)
+				 enum codespace_sel cs_sel, u32 code)
 {
 	bool allow_bayer = cs_sel & CS_SEL_BAYER;
 	unsigned int i;
@@ -237,6 +237,25 @@ int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
 		if (!(cs_sel & fmt_cs_sel) || (!allow_bayer && fmt->bayer))
 			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;
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index bb73a76eea84..bf4daaaf3165 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -160,7 +160,7 @@ enum codespace_sel {
 const struct imx_media_pixfmt *
 imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel);
 int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
-				 enum codespace_sel cs_sel);
+				 enum codespace_sel cs_sel, u32 code);
 const struct imx_media_pixfmt *
 imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel);
 int imx_media_enum_mbus_formats(u32 *code, u32 index,
-- 
Regards,

Laurent Pinchart


      parent reply index

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-26 22:08 [PATCH v2 00/11] media: imx: Miscalleanous format-related cleanups Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 01/11] media: imx: fix and simplify pixel format enumeration Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 02/11] media: imx: fix media bus " Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 03/11] media: imx: utils: Inline init_mbus_colorimetry() in its caller Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 04/11] media: imx: utils: Handle Bayer format lookup through a selection flag Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 05/11] media: imx: utils: Simplify IPU format lookup and enumeration Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 06/11] media: imx: utils: Make imx_media_pixfmt handle variable number of codes Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 07/11] media: imx: utils: Remove unneeded argument to (find|enum)_format() Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 08/11] media: imx: utils: Rename format lookup and enumeration functions Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 09/11] media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_pix_fmt Laurent Pinchart
2020-03-26 22:08 ` [PATCH v2 10/11] media: imx: utils: Decouple mbus- and pixel-based format lookup and enum Laurent Pinchart
2020-03-26 22:08 ` Laurent Pinchart [this message]

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=20200326220840.18540-12-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=linux-media@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=rmfrfs@gmail.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

Linux-Media Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-media/0 linux-media/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-media linux-media/ https://lore.kernel.org/linux-media \
		linux-media@vger.kernel.org
	public-inbox-index linux-media

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-media


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git