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>
Subject: [PATCH v2 05/10] media: imx: utils: Simplify IPU format lookup and enumeration
Date: Sat, 28 Mar 2020 16:09:57 -0700 [thread overview]
Message-ID: <20200328231002.649-6-slongerbeam@gmail.com> (raw)
In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com>
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
The IPU formats are stored in two separate tables, one for YUV and one
for RGB formats. This complicates the lookup and enumeration function
without really increasing efficiency, as both tables contain a single
element. Merge the two tables and simplify the functions, and move the
resulting table next to the functions that use it.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
drivers/staging/media/imx/imx-media-utils.c | 134 ++++++++------------
1 file changed, 54 insertions(+), 80 deletions(-)
diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c
index 6a3b0b737e5f..981a8b540a3c 100644
--- a/drivers/staging/media/imx/imx-media-utils.c
+++ b/drivers/staging/media/imx/imx-media-utils.c
@@ -186,30 +186,6 @@ static const struct imx_media_pixfmt pixel_formats[] = {
},
};
-static const struct imx_media_pixfmt ipu_yuv_formats[] = {
- {
- .fourcc = V4L2_PIX_FMT_YUV32,
- .codes = {MEDIA_BUS_FMT_AYUV8_1X32},
- .cs = IPUV3_COLORSPACE_YUV,
- .bpp = 32,
- .ipufmt = true,
- },
-};
-
-#define NUM_IPU_YUV_FORMATS ARRAY_SIZE(ipu_yuv_formats)
-
-static const struct imx_media_pixfmt ipu_rgb_formats[] = {
- {
- .fourcc = V4L2_PIX_FMT_XRGB32,
- .codes = {MEDIA_BUS_FMT_ARGB8888_1X32},
- .cs = IPUV3_COLORSPACE_RGB,
- .bpp = 32,
- .ipufmt = true,
- },
-};
-
-#define NUM_IPU_RGB_FORMATS ARRAY_SIZE(ipu_rgb_formats)
-
static const struct imx_media_pixfmt *find_format(u32 fourcc,
u32 code,
enum codespace_sel cs_sel,
@@ -313,81 +289,79 @@ int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel)
}
EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format);
+/* -----------------------------------------------------------------------------
+ * IPU Formats Lookup and Enumeration
+ */
+
+static const struct imx_media_pixfmt ipu_formats[] = {
+ {
+ .fourcc = V4L2_PIX_FMT_YUV32,
+ .codes = {MEDIA_BUS_FMT_AYUV8_1X32},
+ .cs = IPUV3_COLORSPACE_YUV,
+ .bpp = 32,
+ .ipufmt = true,
+ }, {
+ .fourcc = V4L2_PIX_FMT_XRGB32,
+ .codes = {MEDIA_BUS_FMT_ARGB8888_1X32},
+ .cs = IPUV3_COLORSPACE_RGB,
+ .bpp = 32,
+ .ipufmt = true,
+ },
+};
+
const struct imx_media_pixfmt *
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)
{
- const struct imx_media_pixfmt *array, *fmt, *ret = NULL;
- u32 array_size;
- int i, j;
-
- cs_sel &= ~CS_SEL_BAYER;
+ bool accept_yuv = cs_sel & CS_SEL_YUV;
+ bool accept_rgb = cs_sel & CS_SEL_RGB;
+ unsigned int i;
- switch (cs_sel) {
- case CS_SEL_YUV:
- array_size = NUM_IPU_YUV_FORMATS;
- array = ipu_yuv_formats;
- break;
- case CS_SEL_RGB:
- array_size = NUM_IPU_RGB_FORMATS;
- array = ipu_rgb_formats;
- break;
- case CS_SEL_YUV_RGB:
- array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS;
- array = ipu_yuv_formats;
- break;
- default:
+ if (!code)
return NULL;
- }
- for (i = 0; i < array_size; i++) {
- if (cs_sel == CS_SEL_YUV_RGB && i >= NUM_IPU_YUV_FORMATS)
- fmt = &ipu_rgb_formats[i - NUM_IPU_YUV_FORMATS];
- else
- fmt = &array[i];
+ for (i = 0; i < ARRAY_SIZE(ipu_formats); i++) {
+ const struct imx_media_pixfmt *fmt = &ipu_formats[i];
+ unsigned int j;
- for (j = 0; code && fmt->codes[j]; j++) {
- if (code == fmt->codes[j]) {
- ret = fmt;
- goto out;
- }
+ if ((!accept_yuv && fmt->cs == IPUV3_COLORSPACE_YUV) ||
+ (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB))
+ continue;
+
+ for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) {
+ if (code == fmt->codes[j])
+ return fmt;
}
}
-out:
- return ret;
+ return NULL;
}
EXPORT_SYMBOL_GPL(imx_media_find_ipu_format);
int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel)
{
- cs_sel &= ~CS_SEL_BAYER;
+ bool accept_yuv = cs_sel & CS_SEL_YUV;
+ bool accept_rgb = cs_sel & CS_SEL_RGB;
+ unsigned int i;
- switch (cs_sel) {
- case CS_SEL_YUV:
- if (index >= NUM_IPU_YUV_FORMATS)
- return -EINVAL;
- *code = ipu_yuv_formats[index].codes[0];
- break;
- case CS_SEL_RGB:
- if (index >= NUM_IPU_RGB_FORMATS)
- return -EINVAL;
- *code = ipu_rgb_formats[index].codes[0];
- break;
- case CS_SEL_YUV_RGB:
- if (index >= NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS)
- return -EINVAL;
- if (index >= NUM_IPU_YUV_FORMATS) {
- index -= NUM_IPU_YUV_FORMATS;
- *code = ipu_rgb_formats[index].codes[0];
- } else {
- *code = ipu_yuv_formats[index].codes[0];
+ for (i = 0; i < ARRAY_SIZE(ipu_formats); i++) {
+ const struct imx_media_pixfmt *fmt = &ipu_formats[i];
+ unsigned int j;
+
+ if ((!accept_yuv && fmt->cs == IPUV3_COLORSPACE_YUV) ||
+ (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB))
+ continue;
+
+ for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) {
+ if (index == 0) {
+ *code = fmt->codes[j];
+ return 0;
+ }
+
+ index--;
}
- break;
- default:
- return -EINVAL;
}
- return 0;
+ return -EINVAL;
}
EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format);
--
2.17.1
next 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 ` Steve Longerbeam [this message]
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 ` [PATCH v2 10/10] media: imx: utils: Split find|enum_format into fourcc and mbus functions Steve Longerbeam
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-6-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.