From patchwork Thu Mar 26 22:08:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 210408 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AEF1C2D0E5 for ; Thu, 26 Mar 2020 22:08:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2344220714 for ; Thu, 26 Mar 2020 22:08:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XCnxW9X3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726540AbgCZWIy (ORCPT ); Thu, 26 Mar 2020 18:08:54 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:42042 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726281AbgCZWIy (ORCPT ); Thu, 26 Mar 2020 18:08:54 -0400 Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BF9A8A48; Thu, 26 Mar 2020 23:08:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585260532; bh=XxJyzqsrNNzj60RoVdpmfidB2zury/Vxt3Y9cqoPg+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XCnxW9X3wmguqZnKtCjvui4UQ5uCc1sUBD3+Eov/dUCPU7qdTr3yDydpBiarZK6Ww eYRvL632NnLcjGTHzOsA8aPq+36o+7+p0Ra/0NcjL2GAbYIaTSsRSlHmGc/vNMYGJp L3F2qg/RiF0WTQrp7jU8WeUb3nO66LGTzlrBshbE= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 01/11] media: imx: fix and simplify pixel format enumeration Date: Fri, 27 Mar 2020 00:08:30 +0200 Message-Id: <20200326220840.18540-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> References: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Philipp Zabel Merge yuv_formats and rgb_formats into a single array. Always loop over all entries, skipping those that are incompatible with the requested enumeration. This simplifies the code, lets us get rid of the manual counting of array entries, and stops accidentally ignoring some non-mbus RGB formats. Before: $ v4l2-ctl -d /dev/video14 --list-formats-out ioctl: VIDIOC_ENUM_FMT Type: Video Output [0]: 'UYVY' (UYVY 4:2:2) [1]: 'YUYV' (YUYV 4:2:2) [2]: 'YU12' (Planar YUV 4:2:0) [3]: 'YV12' (Planar YVU 4:2:0) [4]: '422P' (Planar YUV 4:2:2) [5]: 'NV12' (Y/CbCr 4:2:0) [6]: 'NV16' (Y/CbCr 4:2:2) [7]: 'RGBP' (16-bit RGB 5-6-5) [8]: 'RGB3' (24-bit RGB 8-8-8) [9]: 'BX24' (32-bit XRGB 8-8-8-8) After: $ v4l2-ctl -d /dev/video14 --list-formats-out ioctl: VIDIOC_ENUM_FMT Type: Video Output [0]: 'UYVY' (UYVY 4:2:2) [1]: 'YUYV' (YUYV 4:2:2) [2]: 'YU12' (Planar YUV 4:2:0) [3]: 'YV12' (Planar YVU 4:2:0) [4]: '422P' (Planar YUV 4:2:2) [5]: 'NV12' (Y/CbCr 4:2:0) [6]: 'NV16' (Y/CbCr 4:2:2) [7]: 'RGBP' (16-bit RGB 5-6-5) [8]: 'RGB3' (24-bit RGB 8-8-8) [9]: 'BGR3' (24-bit BGR 8-8-8) [10]: 'BX24' (32-bit XRGB 8-8-8-8) [11]: 'XR24' (32-bit BGRX 8-8-8-8) [12]: 'RX24' (32-bit XBGR 8-8-8-8) [13]: 'XB24' (32-bit RGBX 8-8-8-8) Signed-off-by: Philipp Zabel [Make loop counters unsigned] [Fix colorspace comparison error] [Decrement index instead of adding a counter] [Return directly from within loop instead of breaking] Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 191 ++++++-------------- 1 file changed, 58 insertions(+), 133 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index fae981698c49..afd62be51e87 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -9,12 +9,9 @@ /* * List of supported pixel formats for the subdevs. - * - * In all of these tables, the non-mbus formats (with no - * mbus codes) must all fall at the end of the table. */ - -static const struct imx_media_pixfmt yuv_formats[] = { +static const struct imx_media_pixfmt pixel_formats[] = { + /*** YUV formats start here ***/ { .fourcc = V4L2_PIX_FMT_UYVY, .codes = { @@ -31,12 +28,7 @@ static const struct imx_media_pixfmt yuv_formats[] = { }, .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, - }, - /*** - * non-mbus YUV formats start here. NOTE! when adding non-mbus - * formats, NUM_NON_MBUS_YUV_FORMATS must be updated below. - ***/ - { + }, { .fourcc = V4L2_PIX_FMT_YUV420, .cs = IPUV3_COLORSPACE_YUV, .bpp = 12, @@ -62,13 +54,7 @@ static const struct imx_media_pixfmt yuv_formats[] = { .bpp = 16, .planar = true, }, -}; - -#define NUM_NON_MBUS_YUV_FORMATS 5 -#define NUM_YUV_FORMATS ARRAY_SIZE(yuv_formats) -#define NUM_MBUS_YUV_FORMATS (NUM_YUV_FORMATS - NUM_NON_MBUS_YUV_FORMATS) - -static const struct imx_media_pixfmt rgb_formats[] = { + /*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565, .codes = {MEDIA_BUS_FMT_RGB565_2X8_LE}, @@ -83,12 +69,28 @@ static const struct imx_media_pixfmt rgb_formats[] = { }, .cs = IPUV3_COLORSPACE_RGB, .bpp = 24, + }, { + .fourcc = V4L2_PIX_FMT_BGR24, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 24, }, { .fourcc = V4L2_PIX_FMT_XRGB32, .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, .ipufmt = true, + }, { + .fourcc = V4L2_PIX_FMT_XBGR32, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, + }, { + .fourcc = V4L2_PIX_FMT_BGRX32, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, + }, { + .fourcc = V4L2_PIX_FMT_RGBX32, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, }, /*** raw bayer and grayscale formats start here ***/ { @@ -182,33 +184,8 @@ static const struct imx_media_pixfmt rgb_formats[] = { .bpp = 16, .bayer = true, }, - /*** - * non-mbus RGB formats start here. NOTE! when adding non-mbus - * formats, NUM_NON_MBUS_RGB_FORMATS must be updated below. - ***/ - { - .fourcc = V4L2_PIX_FMT_BGR24, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 24, - }, { - .fourcc = V4L2_PIX_FMT_XBGR32, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 32, - }, { - .fourcc = V4L2_PIX_FMT_BGRX32, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 32, - }, { - .fourcc = V4L2_PIX_FMT_RGBX32, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 32, - }, }; -#define NUM_NON_MBUS_RGB_FORMATS 2 -#define NUM_RGB_FORMATS ARRAY_SIZE(rgb_formats) -#define NUM_MBUS_RGB_FORMATS (NUM_RGB_FORMATS - NUM_NON_MBUS_RGB_FORMATS) - static const struct imx_media_pixfmt ipu_yuv_formats[] = { { .fourcc = V4L2_PIX_FMT_YUV32, @@ -247,20 +224,24 @@ static void init_mbus_colorimetry(struct v4l2_mbus_framefmt *mbus, } static const -struct imx_media_pixfmt *__find_format(u32 fourcc, - u32 code, - bool allow_non_mbus, - bool allow_bayer, - const struct imx_media_pixfmt *array, - u32 array_size) +struct imx_media_pixfmt *find_format(u32 fourcc, + u32 code, + enum codespace_sel cs_sel, + bool allow_non_mbus, + bool allow_bayer) { - const struct imx_media_pixfmt *fmt; - int i, j; + unsigned int i; - for (i = 0; i < array_size; i++) { - fmt = &array[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; - if ((!allow_non_mbus && !fmt->codes[0]) || + fmt_cs_sel = fmt->cs == IPUV3_COLORSPACE_YUV + ? CS_SEL_YUV : CS_SEL_RGB; + + if ((cs_sel != CS_SEL_ANY && fmt_cs_sel != cs_sel) || + (!allow_non_mbus && !fmt->codes[0]) || (!allow_bayer && fmt->bayer)) continue; @@ -270,39 +251,13 @@ struct imx_media_pixfmt *__find_format(u32 fourcc, if (!code) continue; - for (j = 0; fmt->codes[j]; j++) { + for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { if (code == fmt->codes[j]) return fmt; } } - return NULL; -} -static const struct imx_media_pixfmt *find_format(u32 fourcc, - u32 code, - enum codespace_sel cs_sel, - bool allow_non_mbus, - bool allow_bayer) -{ - const struct imx_media_pixfmt *ret; - - switch (cs_sel) { - case CS_SEL_YUV: - return __find_format(fourcc, code, allow_non_mbus, allow_bayer, - yuv_formats, NUM_YUV_FORMATS); - case CS_SEL_RGB: - return __find_format(fourcc, code, allow_non_mbus, allow_bayer, - rgb_formats, NUM_RGB_FORMATS); - case CS_SEL_ANY: - ret = __find_format(fourcc, code, allow_non_mbus, allow_bayer, - yuv_formats, NUM_YUV_FORMATS); - if (ret) - return ret; - return __find_format(fourcc, code, allow_non_mbus, allow_bayer, - rgb_formats, NUM_RGB_FORMATS); - default: - return NULL; - } + return NULL; } static int enum_format(u32 *fourcc, u32 *code, u32 index, @@ -310,61 +265,31 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, bool allow_non_mbus, bool allow_bayer) { - const struct imx_media_pixfmt *fmt; - u32 mbus_yuv_sz = NUM_MBUS_YUV_FORMATS; - u32 mbus_rgb_sz = NUM_MBUS_RGB_FORMATS; - u32 yuv_sz = NUM_YUV_FORMATS; - u32 rgb_sz = NUM_RGB_FORMATS; + unsigned int i; - switch (cs_sel) { - case CS_SEL_YUV: - if (index >= yuv_sz || - (!allow_non_mbus && index >= mbus_yuv_sz)) - return -EINVAL; - fmt = &yuv_formats[index]; - break; - case CS_SEL_RGB: - if (index >= rgb_sz || - (!allow_non_mbus && index >= mbus_rgb_sz)) - return -EINVAL; - fmt = &rgb_formats[index]; - if (!allow_bayer && fmt->bayer) - return -EINVAL; - break; - case CS_SEL_ANY: - if (!allow_non_mbus) { - if (index >= mbus_yuv_sz) { - index -= mbus_yuv_sz; - if (index >= mbus_rgb_sz) - return -EINVAL; - fmt = &rgb_formats[index]; - if (!allow_bayer && fmt->bayer) - return -EINVAL; - } else { - fmt = &yuv_formats[index]; - } - } else { - if (index >= yuv_sz + rgb_sz) - return -EINVAL; - if (index >= yuv_sz) { - fmt = &rgb_formats[index - yuv_sz]; - if (!allow_bayer && fmt->bayer) - return -EINVAL; - } else { - fmt = &yuv_formats[index]; - } + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { + const struct imx_media_pixfmt *fmt = &pixel_formats[i]; + enum codespace_sel fmt_cs_sel; + + fmt_cs_sel = fmt->cs == IPUV3_COLORSPACE_YUV + ? CS_SEL_YUV : CS_SEL_RGB; + + if ((cs_sel != CS_SEL_ANY && fmt_cs_sel != cs_sel) || + (!allow_non_mbus && !fmt->codes[0]) || + (!allow_bayer && fmt->bayer)) + continue; + + if (index == 0) { + if (fourcc) + *fourcc = fmt->fourcc; + if (code) + *code = fmt->codes[0]; } - break; - default: - return -EINVAL; - } - if (fourcc) - *fourcc = fmt->fourcc; - if (code) - *code = fmt->codes[0]; + index--; + } - return 0; + return -EINVAL; } const struct imx_media_pixfmt * From patchwork Thu Mar 26 22:08:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 210407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEE20C43331 for ; Thu, 26 Mar 2020 22:08:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7EE6B20714 for ; Thu, 26 Mar 2020 22:08:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="kX4uN6Fc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727393AbgCZWI5 (ORCPT ); Thu, 26 Mar 2020 18:08:57 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:42062 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbgCZWI5 (ORCPT ); Thu, 26 Mar 2020 18:08:57 -0400 Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DF3A71467; Thu, 26 Mar 2020 23:08:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585260534; bh=UsQCkAUumjc6wPYHUE8Ls9UDasxUNc6eWQeMIKItgE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kX4uN6FcypDC2WlfyDxJgbgY5UuE3jYfTgxYcqhg1oaV3tLrM4QBMqBWeocKqdqZz vDCg8omHI4xzD1xPJdsSbimRRUbfBqH8J7FXX05kU52z+VddKVXpSRTcwB5h8iVoKl FwDlRRyQdyUrExkxoaOVlpi+f8mUCWjgKYuVyhEM= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 05/11] media: imx: utils: Simplify IPU format lookup and enumeration Date: Fri, 27 Mar 2020 00:08:34 +0200 Message-Id: <20200326220840.18540-6-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> References: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- drivers/staging/media/imx/imx-media-utils.c | 128 ++++++++------------ 1 file changed, 50 insertions(+), 78 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index ff1dd4f0a8c6..490f743c4e77 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, @@ -320,77 +296,73 @@ 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; - - 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_ANY: - array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS; - array = ipu_yuv_formats; - break; - default: + bool accept_yuv = cs_sel & CS_SEL_YUV; + bool accept_rgb = cs_sel & CS_SEL_RGB; + unsigned int i, j; + + if (!code) return NULL; - } - for (i = 0; i < array_size; i++) { - if (cs_sel == CS_SEL_ANY && 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]; - 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; 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) { - 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_ANY: - 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]; + bool accept_yuv = cs_sel & CS_SEL_YUV; + bool accept_rgb = cs_sel & CS_SEL_RGB; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(ipu_formats); i++) { + const struct imx_media_pixfmt *fmt = &ipu_formats[i]; + + if ((!accept_yuv && fmt->cs == IPUV3_COLORSPACE_YUV) || + (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) + continue; + + if (index-- == 0) { + *code = fmt->codes[0]; + return 0; } - break; - default: - return -EINVAL; } - return 0; + return -EINVAL; } EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format); From patchwork Thu Mar 26 22:08:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 210406 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD94C2D0E5 for ; Thu, 26 Mar 2020 22:09:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 56D1F20719 for ; Thu, 26 Mar 2020 22:09:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nkyqw43E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727495AbgCZWI7 (ORCPT ); Thu, 26 Mar 2020 18:08:59 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:42062 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbgCZWI7 (ORCPT ); Thu, 26 Mar 2020 18:08:59 -0400 Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6D064144E; Thu, 26 Mar 2020 23:08:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585260534; bh=49OTC1NJ6la6Ufglp/I5A1NL0U+4sfONZyx6DxaOOYs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nkyqw43E5INyLZq3BJFy6vFloG3z04BoaaTf1TLVIh1BRNy+r3AdxodBqq7tFkb9k fD5nPmX9mkpmt5FoqimghmtIv1zJidiVzY8hZYsljWIXHO7ZA1qU07IhqKapGsPu+2 hyzQzFH7zneWrFpuseiYNyIs+5IV999aM3YhtaRA= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 06/11] media: imx: utils: Make imx_media_pixfmt handle variable number of codes Date: Fri, 27 Mar 2020 00:08:35 +0200 Message-Id: <20200326220840.18540-7-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> References: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The imx_media_pixfmt structures includes a codes member that stores media bus codes as a fixed array of 4 integers. The functions dealing with the imx_media_pixfmt structures assume that the array of codes is terminated by a 0 elements. This mechanism is fragile, as demonstrated by several instances of the structure contained 4 non-zero codes. Fix this by turning the array into a pointer, and providing an IMX_BUS_FMTS macro to initialize the codes member with a guaranteed 0 element at the end. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 81 ++++++++++++--------- drivers/staging/media/imx/imx-media.h | 2 +- 2 files changed, 48 insertions(+), 35 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 490f743c4e77..2dcb6285a6c0 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -10,22 +10,29 @@ /* * List of supported pixel formats for the subdevs. */ + +#define IMX_BUS_FMTS(fmts...) \ + (const u32[]) { \ + fmts, \ + 0 \ + } + static const struct imx_media_pixfmt pixel_formats[] = { /*** YUV formats start here ***/ { .fourcc = V4L2_PIX_FMT_UYVY, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_UYVY8_1X16 - }, + ), .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, }, { .fourcc = V4L2_PIX_FMT_YUYV, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_YUYV8_2X8, MEDIA_BUS_FMT_YUYV8_1X16 - }, + ), .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, }, { @@ -57,16 +64,16 @@ static const struct imx_media_pixfmt pixel_formats[] = { /*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565, - .codes = {MEDIA_BUS_FMT_RGB565_2X8_LE}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_RGB565_2X8_LE), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .cycles = 2, }, { .fourcc = V4L2_PIX_FMT_RGB24, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_RGB888_1X24, MEDIA_BUS_FMT_RGB888_2X12_LE - }, + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 24, }, { @@ -75,7 +82,7 @@ static const struct imx_media_pixfmt pixel_formats[] = { .bpp = 24, }, { .fourcc = V4L2_PIX_FMT_XRGB32, - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32), .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, .ipufmt = true, @@ -95,91 +102,91 @@ static const struct imx_media_pixfmt pixel_formats[] = { /*** raw bayer and grayscale formats start here ***/ { .fourcc = V4L2_PIX_FMT_SBGGR8, - .codes = {MEDIA_BUS_FMT_SBGGR8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, - .codes = {MEDIA_BUS_FMT_SGBRG8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, - .codes = {MEDIA_BUS_FMT_SGRBG8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, - .codes = {MEDIA_BUS_FMT_SRGGB8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR14_1X14, MEDIA_BUS_FMT_SBGGR16_1X16 - }, + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG14_1X14, - MEDIA_BUS_FMT_SGBRG16_1X16, - }, + MEDIA_BUS_FMT_SGBRG16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG14_1X14, - MEDIA_BUS_FMT_SGRBG16_1X16, - }, + MEDIA_BUS_FMT_SGRBG16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB14_1X14, - MEDIA_BUS_FMT_SRGGB16_1X16, - }, + MEDIA_BUS_FMT_SRGGB16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_GREY, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y10_1X10, - MEDIA_BUS_FMT_Y12_1X12, - }, + MEDIA_BUS_FMT_Y12_1X12 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_Y10, - .codes = {MEDIA_BUS_FMT_Y10_1X10}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_Y12, - .codes = {MEDIA_BUS_FMT_Y12_1X12}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, @@ -206,7 +213,7 @@ struct imx_media_pixfmt *find_format(u32 fourcc, ? CS_SEL_YUV : CS_SEL_RGB; if ((cs_sel != CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0]) || + (!allow_non_mbus && !fmt->codes) || (!allow_bayer && fmt->bayer)) continue; @@ -216,7 +223,7 @@ struct imx_media_pixfmt *find_format(u32 fourcc, if (!code) continue; - for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + for (j = 0; fmt->codes[j]; j++) { if (code == fmt->codes[j]) return fmt; } @@ -243,7 +250,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ? CS_SEL_YUV : CS_SEL_RGB; if ((cs_sel != CS_SEL_ANY && fmt_cs_sel != cs_sel) || - (!allow_non_mbus && !fmt->codes[0]) || + (!allow_non_mbus && !fmt->codes) || (!allow_bayer && fmt->bayer)) continue; @@ -257,7 +264,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, continue; } - for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + for (j = 0; fmt->codes[j]; j++) { if (index == 0) { *code = fmt->codes[j]; return 0; @@ -303,13 +310,13 @@ EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); static const struct imx_media_pixfmt ipu_formats[] = { { .fourcc = V4L2_PIX_FMT_YUV32, - .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_AYUV8_1X32), .cs = IPUV3_COLORSPACE_YUV, .bpp = 32, .ipufmt = true, }, { .fourcc = V4L2_PIX_FMT_XRGB32, - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32), .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, .ipufmt = true, @@ -333,6 +340,9 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) continue; + if (!fmt->codes) + continue; + for (j = 0; fmt->codes[j]; j++) { if (code == fmt->codes[j]) return fmt; @@ -356,6 +366,9 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) continue; + if (!fmt->codes) + continue; + if (index-- == 0) { *code = fmt->codes[0]; return 0; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index dc6f8fe7c66c..9cedc27a6b4a 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -69,7 +69,7 @@ enum { struct imx_media_pixfmt { u32 fourcc; - u32 codes[4]; + const u32 *codes; int bpp; /* total bpp */ /* cycles per pixel for generic (bayer) formats for the parallel bus */ int cycles; From patchwork Thu Mar 26 22:08:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 210404 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B555C43331 for ; Thu, 26 Mar 2020 22:09:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 34CBF20719 for ; Thu, 26 Mar 2020 22:09:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="oBbj8iX7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727505AbgCZWJC (ORCPT ); Thu, 26 Mar 2020 18:09:02 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:42046 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727547AbgCZWJC (ORCPT ); Thu, 26 Mar 2020 18:09:02 -0400 Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7D52218B1; Thu, 26 Mar 2020 23:08:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585260535; bh=+IzZa7KCXfrh0piaRdwdLhE95lIUxxsyMg5y5Oe6c3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oBbj8iX7jP0HV0O9dDzk7d/bZq/rRbeHt+8LgYdBOcL+X3iE1Xi+a6yB3bS3o2te0 Y4/ZDn1DnBoXZ7B1BX8GZ7YKqpRo23RMfUeWw2cffKsMZVBguUSFmnN2Dswg7PguAB K8PMWPmBPmy9HuDpCI4rhQNfFzbqKPJVPo68XET0= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 08/11] media: imx: utils: Rename format lookup and enumeration functions Date: Fri, 27 Mar 2020 00:08:37 +0200 Message-Id: <20200326220840.18540-9-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> References: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Rename the format lookup and enumeration functions according to their usage: - Rename imx_media_(find|enum)_format() to *_pixel_format() to explicitly state on what formats the functions operate. This aligns the naming scheme with the media bus and IPU format functions that already end with *_mbus_format() and *_ipu_formats(). - Rename all enumeration functions to pluralize 'formats' at the end, as they enumerate multiple formats. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-ic-prp.c | 8 ++--- drivers/staging/media/imx/imx-ic-prpencvf.c | 6 ++-- drivers/staging/media/imx/imx-media-capture.c | 20 +++++------ .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 15 ++++----- drivers/staging/media/imx/imx-media-utils.c | 33 ++++++++++--------- drivers/staging/media/imx/imx-media-vdic.c | 6 ++-- drivers/staging/media/imx/imx-media.h | 11 ++++--- drivers/staging/media/imx/imx7-media-csi.c | 6 ++-- 9 files changed, 55 insertions(+), 52 deletions(-) diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index 2a4f77e83ed3..ce10004ca01b 100644 --- a/drivers/staging/media/imx/imx-ic-prp.c +++ b/drivers/staging/media/imx/imx-ic-prp.c @@ -106,8 +106,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) { case PRP_SINK_PAD: - ret = imx_media_enum_ipu_format(&code->code, code->index, - CS_SEL_ANY); + ret = imx_media_enum_ipu_formats(&code->code, code->index, + CS_SEL_ANY); break; case PRP_SRC_PAD_PRPENC: case PRP_SRC_PAD_PRPVF: @@ -182,7 +182,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd, cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_ANY); if (!cc) { - imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_ANY); cc = imx_media_find_ipu_format(code, CS_SEL_ANY); sdformat->format.code = cc->codes[0]; } @@ -438,7 +438,7 @@ static int prp_registered(struct v4l2_subdev *sd) priv->frame_interval.denominator = 30; /* set a default mbus format */ - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); return imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code, V4L2_FIELD_NONE, NULL); } diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index 09c4e3f33807..ec814acc3485 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -850,7 +850,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, if (code->pad >= PRPENCVF_NUM_PADS) return -EINVAL; - return imx_media_enum_ipu_format(&code->code, code->index, CS_SEL_ANY); + return imx_media_enum_ipu_formats(&code->code, code->index, CS_SEL_ANY); } static int prp_get_fmt(struct v4l2_subdev *sd, @@ -889,7 +889,7 @@ static void prp_try_fmt(struct prp_priv *priv, if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_ANY); *cc = imx_media_find_ipu_format(code, CS_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } @@ -1248,7 +1248,7 @@ static int prp_registered(struct v4l2_subdev *sd) u32 code; /* set a default mbus format */ - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); for (i = 0; i < PRPENCVF_NUM_PADS; i++) { ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], 640, 480, code, V4L2_FIELD_NONE, diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index 93a9ecdf0789..1b3f783f3f72 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -91,8 +91,8 @@ static int capture_enum_framesizes(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fsize->pixel_format, - CS_SEL_ANY | CS_SEL_BAYER); + cc = imx_media_find_pixel_format(fsize->pixel_format, + CS_SEL_ANY | CS_SEL_BAYER); if (!cc) return -EINVAL; @@ -134,8 +134,8 @@ static int capture_enum_frameintervals(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fival->pixel_format, - CS_SEL_ANY | CS_SEL_BAYER); + cc = imx_media_find_pixel_format(fival->pixel_format, + CS_SEL_ANY | CS_SEL_BAYER); if (!cc) return -EINVAL; @@ -174,7 +174,7 @@ 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_format(&fourcc, f->index, cs_sel); + ret = imx_media_enum_pixel_formats(&fourcc, f->index, cs_sel); if (ret) return ret; } else { @@ -219,10 +219,10 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, CS_SEL_YUV : CS_SEL_RGB; fourcc = f->fmt.pix.pixelformat; - cc = imx_media_find_format(fourcc, cs_sel); + cc = imx_media_find_pixel_format(fourcc, cs_sel); if (!cc) { - imx_media_enum_format(&fourcc, 0, cs_sel); - cc = imx_media_find_format(fourcc, cs_sel); + imx_media_enum_pixel_formats(&fourcc, 0, cs_sel); + cc = imx_media_find_pixel_format(fourcc, cs_sel); } } else { cc_src = imx_media_find_mbus_format(fmt_src->format.code, @@ -791,8 +791,8 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) &fmt_src.format, NULL); vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; - vdev->cc = imx_media_find_format(vdev->fmt.fmt.pix.pixelformat, - CS_SEL_ANY); + vdev->cc = imx_media_find_pixel_format(vdev->fmt.fmt.pix.pixelformat, + CS_SEL_ANY); v4l2_info(sd, "Registered %s as /dev/%s\n", vfd->name, video_device_node_name(vfd)); diff --git a/drivers/staging/media/imx/imx-media-csc-scaler.c b/drivers/staging/media/imx/imx-media-csc-scaler.c index 2cc77f6e84b6..d8904a78228d 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_format(&fourcc, f->index, CS_SEL_ANY); + ret = imx_media_enum_pixel_formats(&fourcc, f->index, CS_SEL_ANY); if (ret) return ret; diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index fecbb39c5a85..b90413850474 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1239,8 +1239,8 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) { case CSI_SINK_PAD: - ret = imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY | CS_SEL_BAYER); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + CS_SEL_ANY | CS_SEL_BAYER); break; case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_IDMAC: @@ -1259,9 +1259,8 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, } else { u32 cs_sel = (incc->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB; - ret = imx_media_enum_ipu_format(&code->code, - code->index, - cs_sel); + ret = imx_media_enum_ipu_formats(&code->code, + code->index, cs_sel); } break; default: @@ -1450,7 +1449,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc = imx_media_find_ipu_format(sdformat->format.code, cs_sel); if (!*cc) { - imx_media_enum_ipu_format(&code, 0, cs_sel); + imx_media_enum_ipu_formats(&code, 0, cs_sel); *cc = imx_media_find_ipu_format(code, cs_sel); sdformat->format.code = (*cc)->codes[0]; } @@ -1473,7 +1472,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc = imx_media_find_mbus_format(sdformat->format.code, CS_SEL_ANY | CS_SEL_BAYER); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_ANY); *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } @@ -1760,7 +1759,7 @@ static int csi_registered(struct v4l2_subdev *sd) for (i = 0; i < CSI_NUM_PADS; i++) { code = 0; if (i != CSI_SINK_PAD) - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); /* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index cbf441716cab..5c096f631236 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -231,8 +231,8 @@ struct imx_media_pixfmt *find_format(u32 fourcc, return NULL; } -static int enum_format(u32 *fourcc, u32 *code, u32 index, - enum codespace_sel cs_sel) +static int enum_formats(u32 *fourcc, u32 *code, u32 index, + enum codespace_sel cs_sel) { bool allow_bayer = cs_sel & CS_SEL_BAYER; unsigned int i; @@ -276,17 +276,18 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, } const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel) +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_format); +EXPORT_SYMBOL_GPL(imx_media_find_pixel_format); -int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel) +int imx_media_enum_pixel_formats(u32 *fourcc, u32 index, + enum codespace_sel cs_sel) { - return enum_format(fourcc, NULL, index, cs_sel); + return enum_formats(fourcc, NULL, index, cs_sel); } -EXPORT_SYMBOL_GPL(imx_media_enum_format); +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) @@ -295,11 +296,11 @@ imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) } EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel) +int imx_media_enum_mbus_formats(u32 *code, u32 index, enum codespace_sel cs_sel) { - return enum_format(NULL, code, index, cs_sel); + return enum_formats(NULL, code, index, cs_sel); } -EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); +EXPORT_SYMBOL_GPL(imx_media_enum_mbus_formats); /* ----------------------------------------------------------------------------- * IPU Formats Lookup and Enumeration @@ -351,7 +352,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) } EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); -int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) +int imx_media_enum_ipu_formats(u32 *code, u32 index, enum codespace_sel cs_sel) { bool accept_yuv = cs_sel & CS_SEL_YUV; bool accept_rgb = cs_sel & CS_SEL_RGB; @@ -375,7 +376,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) return -EINVAL; } -EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format); +EXPORT_SYMBOL_GPL(imx_media_enum_ipu_formats); int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, u32 width, u32 height, u32 code, u32 field, @@ -387,7 +388,7 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->height = height; mbus->field = field; if (code == 0) - imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_YUV); lcc = imx_media_find_mbus_format(code, CS_SEL_ANY); if (!lcc) { lcc = imx_media_find_ipu_format(code, CS_SEL_ANY); @@ -528,7 +529,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, if (cc->ipufmt && cc->cs == IPUV3_COLORSPACE_YUV) { u32 code; - imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_YUV); cc = imx_media_find_mbus_format(code, CS_SEL_YUV); } @@ -580,8 +581,8 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, { const struct imx_media_pixfmt *fmt; - fmt = imx_media_find_format(image->pix.pixelformat, - CS_SEL_ANY | CS_SEL_BAYER); + fmt = imx_media_find_pixel_format(image->pix.pixelformat, + CS_SEL_ANY | CS_SEL_BAYER); if (!fmt) return -EINVAL; diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c index 0d83c2c41606..9dbf63796806 100644 --- a/drivers/staging/media/imx/imx-media-vdic.c +++ b/drivers/staging/media/imx/imx-media-vdic.c @@ -548,7 +548,7 @@ static int vdic_enum_mbus_code(struct v4l2_subdev *sd, if (code->pad >= VDIC_NUM_PADS) return -EINVAL; - return imx_media_enum_ipu_format(&code->code, code->index, CS_SEL_YUV); + return imx_media_enum_ipu_formats(&code->code, code->index, CS_SEL_YUV); } static int vdic_get_fmt(struct v4l2_subdev *sd, @@ -587,7 +587,7 @@ static void vdic_try_fmt(struct vdic_priv *priv, if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); *cc = imx_media_find_ipu_format(code, CS_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } @@ -850,7 +850,7 @@ static int vdic_registered(struct v4l2_subdev *sd) for (i = 0; i < VDIC_NUM_PADS; i++) { code = 0; if (i != VDIC_SINK_PAD_IDMAC) - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); /* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 9cedc27a6b4a..cd80f1c59a5c 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -158,14 +158,17 @@ enum codespace_sel { /* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel); -int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel); +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); const struct imx_media_pixfmt * imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel); +int imx_media_enum_mbus_formats(u32 *code, u32 index, + enum codespace_sel cs_sel); const struct imx_media_pixfmt * imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel); -int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel); +int imx_media_enum_ipu_formats(u32 *code, u32 index, enum codespace_sel cs_sel); + int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, u32 width, u32 height, u32 code, u32 field, const struct imx_media_pixfmt **cc); diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index 0e0f087f40c2..e60a4345b0b6 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -958,8 +958,8 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) { case IMX7_CSI_PAD_SINK: - ret = imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY | CS_SEL_BAYER); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + CS_SEL_ANY | CS_SEL_BAYER); break; case IMX7_CSI_PAD_SRC: if (code->index != 0) { @@ -1037,7 +1037,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, *cc = imx_media_find_mbus_format(sdformat->format.code, CS_SEL_ANY | CS_SEL_BAYER); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_ANY); *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } From patchwork Thu Mar 26 22:08:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 210405 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6527EC43331 for ; Thu, 26 Mar 2020 22:09:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A90520714 for ; Thu, 26 Mar 2020 22:09:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="KL/WebyW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727585AbgCZWJA (ORCPT ); Thu, 26 Mar 2020 18:09:00 -0400 Received: from perceval.ideasonboard.com ([213.167.242.64]:42062 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbgCZWJA (ORCPT ); Thu, 26 Mar 2020 18:09:00 -0400 Received: from pendragon.bb.dnainternet.fi (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 0B2E2A4C; Thu, 26 Mar 2020 23:08:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1585260536; bh=XKAM1thYt6evx0tN+HkAX2G2XSGfilT0Q/Gqcz+bukA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KL/WebyWbHqpePN49b9yPClgr4D35qIpv+z93K7thOjGXPYQ2torM9mB5DhH3/iKa 9F9V1OJ33tk7P1egLrXeTOAUDf9/3OwKj68DnzoEMgEnt2QMgHWgw0V/7sXqSM1BC7 8UtK4GjmnJ95WGBa1WBkhmPOUW8c0l+1df1sYX+8= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Steve Longerbeam , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 09/11] media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_pix_fmt Date: Fri, 27 Mar 2020 00:08:38 +0200 Message-Id: <20200326220840.18540-10-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> References: <20200326220840.18540-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The imx_media_mbus_fmt_to_pix_fmt() function doesn't need to modify its mbus argument. Make it const. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 2 +- drivers/staging/media/imx/imx-media.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 5c096f631236..c22e222866e8 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -506,7 +506,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, EXPORT_SYMBOL_GPL(imx_media_try_colorimetry); int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, - struct v4l2_mbus_framefmt *mbus, + const struct v4l2_mbus_framefmt *mbus, const struct imx_media_pixfmt *cc) { u32 width; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index cd80f1c59a5c..bb73a76eea84 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -177,7 +177,7 @@ int imx_media_init_cfg(struct v4l2_subdev *sd, void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, bool ic_route); int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, - struct v4l2_mbus_framefmt *mbus, + const struct v4l2_mbus_framefmt *mbus, const struct imx_media_pixfmt *cc); int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image, struct v4l2_mbus_framefmt *mbus);