From: Steve Longerbeam <slongerbeam@gmail.com>
To: linux-media@vger.kernel.org
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Rui Miguel Silva <rmfrfs@gmail.com>,
Steve Longerbeam <slongerbeam@gmail.com>
Subject: [PATCH v2 10/10] media: imx: utils: Split find|enum_format into fourcc and mbus functions
Date: Sat, 28 Mar 2020 16:10:02 -0700 [thread overview]
Message-ID: <20200328231002.649-11-slongerbeam@gmail.com> (raw)
In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com>
To make the code easier to follow, split up find_format() into separate
search functions for pixel formats and media-bus codes. In the process
inline the code into the exported functions imx_media_find_pixel_format()
and imx_media_find_mbus_format(). Do the equivalent for enum_formats().
Also add comment blocks for the exported find|enum functions.
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
---
drivers/staging/media/imx/imx-media-utils.c | 131 +++++++++++++-------
1 file changed, 88 insertions(+), 43 deletions(-)
diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c
index 54f6ded0f7c6..c9783b06bdde 100644
--- a/drivers/staging/media/imx/imx-media-utils.c
+++ b/drivers/staging/media/imx/imx-media-utils.c
@@ -192,28 +192,58 @@ static const struct imx_media_pixfmt pixel_formats[] = {
},
};
-static const struct imx_media_pixfmt *find_format(u32 fourcc,
- u32 code,
- enum codespace_sel cs_sel)
+/*
+ * Search for and return an entry in the pixel_formats[] array that matches
+ * the requested search criteria.
+ *
+ * @fourcc: Search for an entry with the given fourcc pixel format.
+ * @cs_sel: Search for entries with the given codespace encodings
+ * (YUV, RGB, and/or BAYER).
+ */
+const struct imx_media_pixfmt *
+imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
const struct imx_media_pixfmt *fmt = &pixel_formats[i];
enum codespace_sel fmt_cs_sel;
- unsigned int j;
fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER :
((fmt->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB);
- if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes))
- continue;
-
- if (fourcc && fmt->fourcc == fourcc)
+ if ((fmt_cs_sel & cs_sel) && fmt->fourcc == fourcc)
return fmt;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL_GPL(imx_media_find_pixel_format);
+
+/*
+ * Search for and return an entry in the pixel_formats[] array that matches
+ * the requested search criteria.
+ *
+ * @code: Search for an entry with the given media-bus code.
+ * @cs_sel: Search for entries with the given codespace encodings
+ * (YUV, RGB, and/or BAYER).
+ */
+const struct imx_media_pixfmt *
+imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel)
+{
+ unsigned int i;
- if (!code || !fmt->codes)
+ for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
+ const struct imx_media_pixfmt *fmt = &pixel_formats[i];
+ enum codespace_sel fmt_cs_sel;
+ unsigned int j;
+
+ fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER :
+ ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
+ CS_SEL_YUV : CS_SEL_RGB);
+
+ if (!(fmt_cs_sel & cs_sel) || !fmt->codes)
continue;
for (j = 0; fmt->codes[j]; j++) {
@@ -224,33 +254,74 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc,
return NULL;
}
+EXPORT_SYMBOL_GPL(imx_media_find_mbus_format);
-static int enum_formats(u32 *fourcc, u32 *code, u32 index,
- enum codespace_sel cs_sel)
+/*
+ * Enumerate entries in the pixel_formats[] array that match the
+ * requested search criteria. Returns the fourcc that matches the
+ * search criteria at the requested match index.
+ *
+ * @fourcc: The returned fourcc that matches the search criteria at
+ * the requested match index.
+ * @index: The requested match index.
+ * @cs_sel: Include in the enumeration entries with the given codespace
+ * encodings (YUV, RGB, and/or BAYER).
+ */
+int imx_media_enum_pixel_formats(u32 *fourcc, u32 index,
+ enum codespace_sel cs_sel)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
const struct imx_media_pixfmt *fmt = &pixel_formats[i];
enum codespace_sel fmt_cs_sel;
- unsigned int j;
fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER :
((fmt->cs == IPUV3_COLORSPACE_YUV) ?
CS_SEL_YUV : CS_SEL_RGB);
- if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes))
+ if (!(fmt_cs_sel & cs_sel))
continue;
- if (fourcc && index == 0) {
+ if (index == 0) {
*fourcc = fmt->fourcc;
return 0;
}
- if (!code) {
- index--;
+ index--;
+ }
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(imx_media_enum_pixel_formats);
+
+/*
+ * Enumerate entries in the pixel_formats[] array that match the
+ * requested search criteria. Returns the media-bus code that matches
+ * the search criteria at the requested match index.
+ *
+ * @code: The returned media-bus code that matches the search criteria at
+ * the requested match index.
+ * @index: The requested match index.
+ * @cs_sel: Include in the enumeration entries with the given codespace
+ * encodings (YUV, RGB, and/or BAYER).
+ */
+int imx_media_enum_mbus_formats(u32 *code, u32 index,
+ enum codespace_sel cs_sel)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) {
+ const struct imx_media_pixfmt *fmt = &pixel_formats[i];
+ enum codespace_sel fmt_cs_sel;
+ unsigned int j;
+
+ fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER :
+ ((fmt->cs == IPUV3_COLORSPACE_YUV) ?
+ CS_SEL_YUV : CS_SEL_RGB);
+
+ if (!(fmt_cs_sel & cs_sel) || !fmt->codes)
continue;
- }
for (j = 0; fmt->codes[j]; j++) {
if (index == 0) {
@@ -264,32 +335,6 @@ static int enum_formats(u32 *fourcc, u32 *code, u32 index,
return -EINVAL;
}
-
-const struct imx_media_pixfmt *
-imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel)
-{
- return find_format(fourcc, 0, 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)
-{
- return enum_formats(fourcc, NULL, index, cs_sel);
-}
-EXPORT_SYMBOL_GPL(imx_media_enum_pixel_formats);
-
-const struct imx_media_pixfmt *
-imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel)
-{
- return find_format(0, code, cs_sel);
-}
-EXPORT_SYMBOL_GPL(imx_media_find_mbus_format);
-
-int imx_media_enum_mbus_formats(u32 *code, u32 index, enum codespace_sel cs_sel)
-{
- return enum_formats(NULL, code, index, cs_sel);
-}
EXPORT_SYMBOL_GPL(imx_media_enum_mbus_formats);
/* -----------------------------------------------------------------------------
--
2.17.1
prev parent reply other threads:[~2020-03-28 23:10 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-28 23:09 [PATCH v2 00/10] media: imx: Miscellaneous format-related cleanups Steve Longerbeam
2020-03-28 23:09 ` [PATCH v2 01/10] media: imx: utils: fix and simplify pixel format enumeration Steve Longerbeam
2020-03-28 23:09 ` [PATCH v2 02/10] media: imx: utils: fix media bus " Steve Longerbeam
2020-03-28 23:09 ` [PATCH v2 03/10] media: imx: utils: Inline init_mbus_colorimetry() in its caller Steve Longerbeam
2020-03-28 23:09 ` [PATCH v2 04/10] media: imx: utils: Handle Bayer format lookup through a selection flag Steve Longerbeam
2020-03-28 23:09 ` [PATCH v2 05/10] media: imx: utils: Simplify IPU format lookup and enumeration Steve Longerbeam
2020-03-28 23:09 ` [PATCH v2 06/10] media: imx: utils: Make imx_media_pixfmt handle variable number of codes Steve Longerbeam
2020-03-28 23:09 ` [PATCH v2 07/10] media: imx: utils: Remove unneeded argument to (find|enum)_format() Steve Longerbeam
2020-03-28 23:10 ` [PATCH v2 08/10] media: imx: utils: Rename format lookup and enumeration functions Steve Longerbeam
2020-03-28 23:10 ` [PATCH v2 09/10] media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_pix_fmt Steve Longerbeam
2020-03-28 23:10 ` Steve Longerbeam [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=20200328231002.649-11-slongerbeam@gmail.com \
--to=slongerbeam@gmail.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=rmfrfs@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.