From patchwork Sat Mar 28 23:09:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463801 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 143036CA for ; Sat, 28 Mar 2020 23:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3F6D2074A for ; Sat, 28 Mar 2020 23:10:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jRKDcoYo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727469AbgC1XKQ (ORCPT ); Sat, 28 Mar 2020 19:10:16 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39531 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727176AbgC1XKP (ORCPT ); Sat, 28 Mar 2020 19:10:15 -0400 Received: by mail-pf1-f193.google.com with SMTP id k15so1433489pfh.6 for ; Sat, 28 Mar 2020 16:10:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ryysd62XzKXqT6N7Bd+7N9GE4k/LSFv+zAgtQQw9MoU=; b=jRKDcoYo+ZZ4bhwEvs+TFos8yan2h5sh2teMNz1iGhJoffXZ1PCmpITS9e4oX0gWD7 Wu7PJGScqlLpSppaUEsa2iSvdJbWc9dpjnKkxec+t801q3HDow00rRm04cd6PNVjRenb 1tZR8Y17ujZ2dxOkDNLRJxyAUOnZFJpERQOa5sDqeTRoHKx2+g2n/ialhKis8U2OO+uV dAyOsTdzfSmqHzCyFi8U9n6C12MV6f27qTCdKEo13yRKgkeK2M69rcDhdXDFVvSxm3JG UQeCBGgJFZBGGe+ZcliNduGJbsi04e+XbRGT5M4cI65dbuyH0MDCV1NylN24boj/KQXF q5fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ryysd62XzKXqT6N7Bd+7N9GE4k/LSFv+zAgtQQw9MoU=; b=B/vns+RhJPlocS6SnRRlnCDv2Xydfj9otrLHBaGIziNtMwt5BAOidZwKP2Ho75cEQB Wi4tbU5z8XOqbUbycNynWoENL3PzTE5gmQxtlK7Ipv1P2Mkxad04V0ZS/XvfXc3itwAK 8tZvXRVp4/R/IY+CtcG4+BAwPm3dTVWN2FXt2QrhEUalSQQi/ycf/0/Zqx23xSFUFyr3 lH2O/+8Q//od6PMvT/3acmrX26nlBGl1G2tX+cpYfMWEPNGyPWYZE2b0qGmwOpfoliwA jfoHxOvtsp8pBV+yazDpLX9xoQ/kuY4Z7xLqf8D/knOxTQz/N78mYp0ikabkzxQElbGu MG1Q== X-Gm-Message-State: ANhLgQ3t+sHDYHYgLNrnGsnj7TPBUFwTqHGG53ibtHN5ss2EJtsSUf6A ni6/58u87YYyPx4fcxv2iVdAbyWjtpo= X-Google-Smtp-Source: ADFU+vtIn6peD+p1X0wnhMJ3OdShTbO+P/Lxoc2SNe4uJfUD38iar1smPf1+sZJyTaPOIQOwhp85jQ== X-Received: by 2002:a63:a74e:: with SMTP id w14mr6065441pgo.231.1585437011797; Sat, 28 Mar 2020 16:10:11 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:11 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v2 01/10] media: imx: utils: fix and simplify pixel format enumeration Date: Sat, 28 Mar 2020 16:09:53 -0700 Message-Id: <20200328231002.649-2-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> 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 do not match the requested search criteria. 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] [Decrement index instead of adding a counter] [Return directly from within loop instead of breaking] Signed-off-by: Laurent Pinchart [Fix colorspace comparison error] Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-utils.c | 193 ++++++-------------- 1 file changed, 59 insertions(+), 134 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index fae981698c49..39469031e510 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, @@ -246,21 +223,24 @@ static void init_mbus_colorimetry(struct v4l2_mbus_framefmt *mbus, mbus->ycbcr_enc); } -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) +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 *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 +250,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 +264,32 @@ 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]; + return 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 Sat Mar 28 23:09:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463799 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5149A159A for ; Sat, 28 Mar 2020 23:10:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 25A242073B for ; Sat, 28 Mar 2020 23:10:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="anAB6EDh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727452AbgC1XKP (ORCPT ); Sat, 28 Mar 2020 19:10:15 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42968 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727417AbgC1XKP (ORCPT ); Sat, 28 Mar 2020 19:10:15 -0400 Received: by mail-pf1-f195.google.com with SMTP id 22so6557876pfa.9 for ; Sat, 28 Mar 2020 16:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qYBkInbfk4Je9+caiy8b4edch0lbPftvhGVf+jVJIDU=; b=anAB6EDhcVT9Zg8ob97ljvYhNEiqhCYITTFVeXsHNTTUzTy7Za06TBaIPRp773hhNG 6AlGtu0pwtm+vpkUtqW2oITBvgmryiYp1O5gZoC5Px/fGjMnUliV030iMYG/LFdI7g23 pXO6uB8xtDmlU0ZIBjapfKWf/cz3pkNJtm38OjjWSyX481SU7ed8heo6RAgM6SJERCHy ZYJj4HwNVuTznB0sOD8Qb5q3yjbEnSYAjeRxM/zUnFAqFvm0NgdT+E81dybetalKI86c +sjj8cTW9wn+PHQ2GnPTviLA+gjO4TFypq6tSHE9aGCTflH2FWhee+ZBtEToHjIDVaox 9OVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qYBkInbfk4Je9+caiy8b4edch0lbPftvhGVf+jVJIDU=; b=o56mRCSwm/2a48mgJlWeLjgMMwSk6tWvxsDd1uIU31bvb32xcjspSRKLfP7+z4qNAm 8m2KtjI6qlQYxt8k6LtV4GuIatY+20sImHDPAx80BukziHvFibumSZx1bVkV89IwZELc Jn0vZZzWIrE+pcOtkcGalaQEqddspqh3uey8hsXAdJ146HKlva2w+zrv6UogWWLFJ2z+ vyFe34AprDIRjw6aVJAsnteTV6xJvny1YKFf0VqfQqWtK7HUkQJ5Oe1Hus4qswdi9cYR ZnyxDUWDWG0EZOjQ7aPNumPoLWTOniDC5bFQlTJaPlalhN7Vd6t49HWXNUBUra2BrshO GnpA== X-Gm-Message-State: ANhLgQ0EUnuyJQrY4jnHO1TAZ5YNjGXKl6IMT9E8TI0euV0bcpWyA0+n YKeF1XxKfVUm6nMt44O3YucSTzfCmt4= X-Google-Smtp-Source: ADFU+vvs0GRMLlXlKyswEhGwxUY4ZYd3Jm8NbDHsS49eYzlYJEWw1gsEI31VN2I3oaUfR+ya2nVM1g== X-Received: by 2002:aa7:99c8:: with SMTP id v8mr5891491pfi.151.1585437013727; Sat, 28 Mar 2020 16:10:13 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:13 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 02/10] media: imx: utils: fix media bus format enumeration Date: Sat, 28 Mar 2020 16:09:54 -0700 Message-Id: <20200328231002.649-3-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Philipp Zabel Iterate over all media bus formats, not just over the first format in each imx_media_pixfmt entry. Before: $ v4l2-ctl -d $(media-ctl -e ipu1_csi0) --list-subdev-mbus-codes 0 ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x100a: MEDIA_BUS_FMT_RGB888_1X24 0x100d: MEDIA_BUS_FMT_ARGB8888_1X32 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x3007: MEDIA_BUS_FMT_SBGGR10_1X10 0x300e: MEDIA_BUS_FMT_SGBRG10_1X10 0x300a: MEDIA_BUS_FMT_SGRBG10_1X10 0x300f: MEDIA_BUS_FMT_SRGGB10_1X10 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x200a: MEDIA_BUS_FMT_Y10_1X10 After: $ v4l2-ctl -d $(media-ctl -e ipu1_csi0) --list-subdev-mbus-codes 0 ioctl: VIDIOC_SUBDEV_ENUM_MBUS_CODE (pad=0) 0x2006: MEDIA_BUS_FMT_UYVY8_2X8 0x200f: MEDIA_BUS_FMT_UYVY8_1X16 0x2008: MEDIA_BUS_FMT_YUYV8_2X8 0x2011: MEDIA_BUS_FMT_YUYV8_1X16 0x1008: MEDIA_BUS_FMT_RGB565_2X8_LE 0x100a: MEDIA_BUS_FMT_RGB888_1X24 0x100c: MEDIA_BUS_FMT_RGB888_2X12_LE 0x100d: MEDIA_BUS_FMT_ARGB8888_1X32 0x3001: MEDIA_BUS_FMT_SBGGR8_1X8 0x3013: MEDIA_BUS_FMT_SGBRG8_1X8 0x3002: MEDIA_BUS_FMT_SGRBG8_1X8 0x3014: MEDIA_BUS_FMT_SRGGB8_1X8 0x3007: MEDIA_BUS_FMT_SBGGR10_1X10 0x3008: MEDIA_BUS_FMT_SBGGR12_1X12 0x3019: MEDIA_BUS_FMT_SBGGR14_1X14 0x301d: MEDIA_BUS_FMT_SBGGR16_1X16 0x300e: MEDIA_BUS_FMT_SGBRG10_1X10 0x3010: MEDIA_BUS_FMT_SGBRG12_1X12 0x301a: MEDIA_BUS_FMT_SGBRG14_1X14 0x301e: MEDIA_BUS_FMT_SGBRG16_1X16 0x300a: MEDIA_BUS_FMT_SGRBG10_1X10 0x3011: MEDIA_BUS_FMT_SGRBG12_1X12 0x301b: MEDIA_BUS_FMT_SGRBG14_1X14 0x301f: MEDIA_BUS_FMT_SGRBG16_1X16 0x300f: MEDIA_BUS_FMT_SRGGB10_1X10 0x3012: MEDIA_BUS_FMT_SRGGB12_1X12 0x301c: MEDIA_BUS_FMT_SRGGB14_1X14 0x3020: MEDIA_BUS_FMT_SRGGB16_1X16 0x2001: MEDIA_BUS_FMT_Y8_1X8 0x200a: MEDIA_BUS_FMT_Y10_1X10 0x2013: MEDIA_BUS_FMT_Y12_1X12 Signed-off-by: Philipp Zabel [Decrement index to replace loop counter k] [Return directly from within the loops] Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 22 +++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 39469031e510..00a71f01786c 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -269,6 +269,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 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; + unsigned int j; fmt_cs_sel = (fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB; @@ -278,15 +279,24 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, (!allow_bayer && fmt->bayer)) continue; - if (index == 0) { - if (fourcc) - *fourcc = fmt->fourcc; - if (code) - *code = fmt->codes[0]; + if (fourcc && index == 0) { + *fourcc = fmt->fourcc; return 0; } - index--; + if (!code) { + index--; + continue; + } + + for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (index == 0) { + *code = fmt->codes[j]; + return 0; + } + + index--; + } } return -EINVAL; From patchwork Sat Mar 28 23:09:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A57741667 for ; Sat, 28 Mar 2020 23:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 853402074A for ; Sat, 28 Mar 2020 23:10:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CDoulhxe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727485AbgC1XKQ (ORCPT ); Sat, 28 Mar 2020 19:10:16 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35729 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727417AbgC1XKQ (ORCPT ); Sat, 28 Mar 2020 19:10:16 -0400 Received: by mail-pl1-f195.google.com with SMTP id c12so2232504plz.2 for ; Sat, 28 Mar 2020 16:10:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=CwMotThQ9KwnaApySbZIN99PefRmZ9AR8BTcnm4Sl0o=; b=CDoulhxeryTOyqjePm2MyaWP2k8gZTxlUYgqZPPDUSy9WNIga76ODt8oyfEIcIxnmf t/nzAK9hLku3RVulWQyk5DBeqvoxkYFSx8Tbm2hmUZ15Ljlt2qo2zaW6l2Q8p7gNcDl8 ycBb0ZviypHqGvLwqD9sf83aO5hGAqGOZMqFBI/wASEMwoz6YoGN7meLG36ykvN7xeeG sLm1uZ4agsqgqtW7t6S0b7M4hrKmKn4cQCSUpyeGSaB0gVPrN/Lwq2kRoByB1xhUF8ps NJzxKXswA+TwyTMfoGyH32y36r9I9JVwNgrIzcckZ63HggfwCV1MHZnofPEbQXX4TtND 53tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CwMotThQ9KwnaApySbZIN99PefRmZ9AR8BTcnm4Sl0o=; b=Ukf27JUQfsIWcR5ASGDvQcQ9XABQngZ0SvMzYA4TTSNBukrQUkBDuVoEMd4Ys0UmP+ nq11k3pulO/8C8601wHTLunnbeSS7X9Po1/uisYDi4uK4gKMzEpNGMqQv2D/6R2gAoPM nO4Hp+D1Cl2Yf53Bon5s4EuaJMMusq1ypqzShU2aA7ib80SXj8iTpLbi75av390kSj+s wtjbB8lqcHDCQasJH1iH6v3sHZ/DeZd74+xABlBmh0NeUDzaJ0xHom7HkwXo4QNGlxaX v7Aw6Z/zRUsesBURH7nZLndeUeRJVuK0FKxvedTdCLpwTWJZm4kXH/6mCG6oLt47tXMp J4gg== X-Gm-Message-State: ANhLgQ3zYvYX1SGqzpyYXYxnRlzVUKwpQPaEYqnTM3qispFClHtcXvcb ae1lZE89O8PaH1cprQ8gGL/Fqq46xSw= X-Google-Smtp-Source: ADFU+vsVlBMIUrBRiRSL6/E7wBVewzKDsn5Z5Oqn3zwL71fGnP1aBoox4S9DTJiJiXJK4rUhv2TL7w== X-Received: by 2002:a17:902:9003:: with SMTP id a3mr5669809plp.331.1585437014798; Sat, 28 Mar 2020 16:10:14 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:14 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 03/10] media: imx: utils: Inline init_mbus_colorimetry() in its caller Date: Sat, 28 Mar 2020 16:09:55 -0700 Message-Id: <20200328231002.649-4-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart The init_mbus_colorimetry() function is small and used in a single place. The code becomes easier to follow if it gets inline in its caller. Do so. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 24 +++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 00a71f01786c..cf0aba8d53ba 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -210,19 +210,6 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = { #define NUM_IPU_RGB_FORMATS ARRAY_SIZE(ipu_rgb_formats) -static void init_mbus_colorimetry(struct v4l2_mbus_framefmt *mbus, - const struct imx_media_pixfmt *fmt) -{ - mbus->colorspace = (fmt->cs == IPUV3_COLORSPACE_RGB) ? - V4L2_COLORSPACE_SRGB : V4L2_COLORSPACE_SMPTE170M; - mbus->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(mbus->colorspace); - mbus->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(mbus->colorspace); - mbus->quantization = - V4L2_MAP_QUANTIZATION_DEFAULT(fmt->cs == IPUV3_COLORSPACE_RGB, - mbus->colorspace, - mbus->ycbcr_enc); -} - static const struct imx_media_pixfmt *find_format(u32 fourcc, u32 code, enum codespace_sel cs_sel, @@ -423,7 +410,16 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, } mbus->code = code; - init_mbus_colorimetry(mbus, lcc); + + mbus->colorspace = (lcc->cs == IPUV3_COLORSPACE_RGB) ? + V4L2_COLORSPACE_SRGB : V4L2_COLORSPACE_SMPTE170M; + mbus->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(mbus->colorspace); + mbus->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(mbus->colorspace); + mbus->quantization = + V4L2_MAP_QUANTIZATION_DEFAULT(lcc->cs == IPUV3_COLORSPACE_RGB, + mbus->colorspace, + mbus->ycbcr_enc); + if (cc) *cc = lcc; From patchwork Sat Mar 28 23:09:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463805 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1ABA3159A for ; Sat, 28 Mar 2020 23:10:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D102B206F2 for ; Sat, 28 Mar 2020 23:10:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TnFrT42c" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727588AbgC1XKT (ORCPT ); Sat, 28 Mar 2020 19:10:19 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46991 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727417AbgC1XKS (ORCPT ); Sat, 28 Mar 2020 19:10:18 -0400 Received: by mail-pg1-f196.google.com with SMTP id k191so6667530pgc.13 for ; Sat, 28 Mar 2020 16:10:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XqyZ8zUVuzNWJxJzzLA7mPwlsD8pN5hvx+oOen4DW78=; b=TnFrT42coKpy9660N4uRz6y4C5E/wLeP4gLhpj6OhpNNej2Rf6AmTH0wXzIf07usre hWnzehg+VNKi7N1yNsPA/DvPmpTH80SsIWFrE2iE2vJYVSbcLDtLpZuT3tjc4UM2ixbg F+aeuC1HsT+y0F7WbRLNExb7UgYkR2/TPqseykbRiKVxNTooxT2jhrrrOTbtxWzBVVeJ 5DSuiVWxZE+Dg1wdWFsPqFwkgV8AyZSW6akqoO0E3ejBBFOkUMQLYoanMr0Cjo2aXeFd cCxsUI1Ao8q1uLW5iGqpGcOPQQz02abbwg/gdIorvuvEOcuOg2igU9oIyqs6Y9BJLgK8 eBog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XqyZ8zUVuzNWJxJzzLA7mPwlsD8pN5hvx+oOen4DW78=; b=WbfcqvWO0jq1xTKBP5m8baVTDBYwfkK/kbXYlj5qHhBJdF6wR1HAa28UwmX22VTt71 tlGmfAg9GnkV4vBpKxUXIvQ5Q2eVm+KpE8MyNQHs8FADG6DDhRJpk0H79k3oy1GAVibS Lqz/V/CTyGQY6wMTkgX2Eg6ksT89+YiqTTbG600M6o1REZ6+WCK+tUPAnSjUEgg9l8P3 LBCSznPLLakhyBX/po6aNKRZcHHN0XAc7CL5OUQeJQwTuLjviryLp6PXO8WnCdDhOmD0 bOD1k14KfEWT1KIonu2fOF9Kq4dsJPk3fnseS151wmQoXE2UoRxOG+MPK4W+lLm7Qn+X HcDg== X-Gm-Message-State: ANhLgQ1uH/n6YBGbFarM+kbG1L355yNvqBxnSICSig7XuxJhSpnOiHit zKF834GPG/C7+f1O649nsQSzMaD0Ubo= X-Google-Smtp-Source: ADFU+vsD9CBKWNsOhwUoSbuGmac8ZRB3v1mzsvrBZNWoaVC/NHPy5EFGkuVqedFHce3aPPDXY8kJ2Q== X-Received: by 2002:aa7:96ae:: with SMTP id g14mr5893923pfk.216.1585437016409; Sat, 28 Mar 2020 16:10:16 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:15 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v2 04/10] media: imx: utils: Handle Bayer format lookup through a selection flag Date: Sat, 28 Mar 2020 16:09:56 -0700 Message-Id: <20200328231002.649-5-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart The format lookup (and enumeration) functions take a boolean flag to tell if Bayer formats should be considered. This leads to hard to read lines such as return enum_format(fourcc, NULL, index, cs_sel, true, false); where the boolean parameters can easily be mixed. To make the code clearer, add a CS_SEL_BAYER flag that can be passed through the codespace_sel parameter of the lookup functions to replace the bool parameter. Signed-off-by: Laurent Pinchart [Instead of declaring CS_SEL_ANY as a bitfield containing only CS_SEL_YUV | CS_SEL_RGB, declare CS_SEL_ANY as all of the above (YUV, RGB, BAYER). A new enum is declared for the YUV | RGB selection as CS_SEL_YUV_RGB, and that is used by sub-devices that don't support BAYER and only allow selecting and enumerating YUV or RGB encodings. CS_SEL_ANY is now only used by the CSI sub-devices and the attached capture interfaces, since only those devices support BAYER formats.] Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-ic-prp.c | 8 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 +-- drivers/staging/media/imx/imx-media-capture.c | 14 ++-- .../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 | 68 +++++++++---------- drivers/staging/media/imx/imx-media.h | 16 ++--- drivers/staging/media/imx/imx7-media-csi.c | 12 ++-- 8 files changed, 70 insertions(+), 74 deletions(-) diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index 2a4f77e83ed3..9c1f723972e4 100644 --- a/drivers/staging/media/imx/imx-ic-prp.c +++ b/drivers/staging/media/imx/imx-ic-prp.c @@ -107,7 +107,7 @@ 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); + CS_SEL_YUV_RGB); break; case PRP_SRC_PAD_PRPENC: case PRP_SRC_PAD_PRPVF: @@ -180,10 +180,10 @@ static int prp_set_fmt(struct v4l2_subdev *sd, MIN_H, MAX_H, H_ALIGN, S_ALIGN); cc = imx_media_find_ipu_format(sdformat->format.code, - CS_SEL_ANY); + CS_SEL_YUV_RGB); if (!cc) { - imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); - cc = imx_media_find_ipu_format(code, CS_SEL_ANY); + imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + cc = imx_media_find_ipu_format(code, CS_SEL_YUV); sdformat->format.code = cc->codes[0]; } diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index 09c4e3f33807..5a22cdc7378a 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -850,7 +850,8 @@ 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_format(&code->code, code->index, + CS_SEL_YUV_RGB); } static int prp_get_fmt(struct v4l2_subdev *sd, @@ -885,12 +886,12 @@ static void prp_try_fmt(struct prp_priv *priv, { struct v4l2_mbus_framefmt *infmt; - *cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_ANY); + *cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_YUV_RGB); if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_ANY); - *cc = imx_media_find_ipu_format(code, CS_SEL_ANY); + imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + *cc = imx_media_find_ipu_format(code, CS_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index d37b776ff86d..d60b49ec4fa4 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY, true); + cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY); if (!cc) return -EINVAL; @@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY, true); + cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY); if (!cc) return -EINVAL; @@ -177,7 +177,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, return ret; } else { cc_src = imx_media_find_mbus_format(fmt_src.format.code, - CS_SEL_ANY, true); + CS_SEL_ANY); if (WARN_ON(!cc_src)) return -EINVAL; @@ -217,14 +217,14 @@ 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, false); + cc = imx_media_find_format(fourcc, cs_sel); if (!cc) { imx_media_enum_format(&fourcc, 0, cs_sel); - cc = imx_media_find_format(fourcc, cs_sel, false); + cc = imx_media_find_format(fourcc, cs_sel); } } else { cc_src = imx_media_find_mbus_format(fmt_src->format.code, - CS_SEL_ANY, true); + CS_SEL_ANY); if (WARN_ON(!cc_src)) return -EINVAL; @@ -790,7 +790,7 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) 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, false); + 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..3e1c88938e7d 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_format(&fourcc, f->index, CS_SEL_YUV_RGB); 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 e76a6a85baa3..298294b95293 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1234,12 +1234,12 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, mutex_lock(&priv->lock); infmt = __csi_get_fmt(priv, cfg, CSI_SINK_PAD, code->which); - incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY, true); + incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY); switch (code->pad) { case CSI_SINK_PAD: ret = imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY, true); + CS_SEL_ANY); break; case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_IDMAC: @@ -1433,8 +1433,7 @@ static void csi_try_fmt(struct csi_priv *priv, switch (sdformat->pad) { case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_IDMAC: - incc = imx_media_find_mbus_format(infmt->code, - CS_SEL_ANY, true); + incc = imx_media_find_mbus_format(infmt->code, CS_SEL_ANY); sdformat->format.width = compose->width; sdformat->format.height = compose->height; @@ -1470,12 +1469,10 @@ static void csi_try_fmt(struct csi_priv *priv, MIN_H, MAX_H, H_ALIGN, S_ALIGN); *cc = imx_media_find_mbus_format(sdformat->format.code, - CS_SEL_ANY, true); + CS_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, - CS_SEL_ANY, false); - *cc = imx_media_find_mbus_format(code, - CS_SEL_ANY, false); + imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index cf0aba8d53ba..6a3b0b737e5f 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -213,8 +213,7 @@ static const struct imx_media_pixfmt ipu_rgb_formats[] = { static const struct imx_media_pixfmt *find_format(u32 fourcc, u32 code, enum codespace_sel cs_sel, - bool allow_non_mbus, - bool allow_bayer) + bool allow_non_mbus) { unsigned int i; @@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, enum codespace_sel fmt_cs_sel; unsigned int j; - fmt_cs_sel = (fmt->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB; + fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : + ((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)) + if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0])) continue; if (fourcc && fmt->fourcc == fourcc) @@ -248,8 +247,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, static int enum_format(u32 *fourcc, u32 *code, u32 index, enum codespace_sel cs_sel, - bool allow_non_mbus, - bool allow_bayer) + bool allow_non_mbus) { unsigned int i; @@ -258,12 +256,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, enum codespace_sel fmt_cs_sel; unsigned int j; - fmt_cs_sel = (fmt->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB; + fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : + ((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)) + if (!(fmt_cs_sel & cs_sel) || + (!allow_non_mbus && !fmt->codes[0])) continue; if (fourcc && index == 0) { @@ -290,30 +288,28 @@ 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, bool allow_bayer) +imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel) { - return find_format(fourcc, 0, cs_sel, true, allow_bayer); + return find_format(fourcc, 0, cs_sel, true); } EXPORT_SYMBOL_GPL(imx_media_find_format); int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel) { - return enum_format(fourcc, NULL, index, cs_sel, true, false); + return enum_format(fourcc, NULL, index, cs_sel, true); } EXPORT_SYMBOL_GPL(imx_media_enum_format); const struct imx_media_pixfmt * -imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel, - bool allow_bayer) +imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) { - return find_format(0, code, cs_sel, false, allow_bayer); + return find_format(0, code, cs_sel, false); } EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel, - bool allow_bayer) +int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel) { - return enum_format(NULL, code, index, cs_sel, false, allow_bayer); + return enum_format(NULL, code, index, cs_sel, false); } EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); @@ -324,6 +320,8 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) u32 array_size; int i, j; + cs_sel &= ~CS_SEL_BAYER; + switch (cs_sel) { case CS_SEL_YUV: array_size = NUM_IPU_YUV_FORMATS; @@ -333,7 +331,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) array_size = NUM_IPU_RGB_FORMATS; array = ipu_rgb_formats; break; - case CS_SEL_ANY: + case CS_SEL_YUV_RGB: array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS; array = ipu_yuv_formats; break; @@ -342,7 +340,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) } for (i = 0; i < array_size; i++) { - if (cs_sel == CS_SEL_ANY && i >= NUM_IPU_YUV_FORMATS) + 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]; @@ -362,6 +360,8 @@ 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; + switch (cs_sel) { case CS_SEL_YUV: if (index >= NUM_IPU_YUV_FORMATS) @@ -373,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) return -EINVAL; *code = ipu_rgb_formats[index].codes[0]; break; - case CS_SEL_ANY: + case CS_SEL_YUV_RGB: if (index >= NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS) return -EINVAL; if (index >= NUM_IPU_YUV_FORMATS) { @@ -401,8 +401,8 @@ 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, false); - lcc = imx_media_find_mbus_format(code, CS_SEL_ANY, false); + imx_media_enum_mbus_format(&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); if (!lcc) @@ -473,7 +473,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, const struct imx_media_pixfmt *cc; bool is_rgb = false; - cc = imx_media_find_mbus_format(tryfmt->code, CS_SEL_ANY, true); + cc = imx_media_find_mbus_format(tryfmt->code, CS_SEL_ANY); if (!cc) cc = imx_media_find_ipu_format(tryfmt->code, CS_SEL_ANY); if (cc && cc->cs == IPUV3_COLORSPACE_RGB) @@ -527,8 +527,8 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, if (!cc) { cc = imx_media_find_ipu_format(mbus->code, CS_SEL_ANY); if (!cc) - cc = imx_media_find_mbus_format(mbus->code, CS_SEL_ANY, - true); + cc = imx_media_find_mbus_format(mbus->code, + CS_SEL_ANY); if (!cc) return -EINVAL; } @@ -540,8 +540,8 @@ 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, false); - cc = imx_media_find_mbus_format(code, CS_SEL_YUV, false); + imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); + cc = imx_media_find_mbus_format(code, CS_SEL_YUV); } /* Round up width for minimum burst size */ @@ -592,7 +592,7 @@ 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, true); + fmt = imx_media_find_format(image->pix.pixelformat, CS_SEL_ANY); if (!fmt) return -EINVAL; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 11861191324a..652673a703cd 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -150,20 +150,20 @@ struct imx_media_dev { }; enum codespace_sel { - CS_SEL_YUV = 0, - CS_SEL_RGB, - CS_SEL_ANY, + CS_SEL_YUV = BIT(0), + CS_SEL_RGB = BIT(1), + CS_SEL_BAYER = BIT(2), + CS_SEL_YUV_RGB = CS_SEL_YUV | CS_SEL_RGB, + CS_SEL_ANY = CS_SEL_YUV | CS_SEL_RGB | CS_SEL_BAYER, }; /* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel, bool allow_bayer); +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); const struct imx_media_pixfmt * -imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel, - bool allow_bayer); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel, - bool allow_bayer); +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); 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); diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index acbdffb77668..a469dc76a787 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -959,7 +959,7 @@ 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, true); + CS_SEL_ANY); break; case IMX7_CSI_PAD_SRC: if (code->index != 0) { @@ -1019,8 +1019,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, switch (sdformat->pad) { case IMX7_CSI_PAD_SRC: - in_cc = imx_media_find_mbus_format(in_fmt->code, CS_SEL_ANY, - true); + in_cc = imx_media_find_mbus_format(in_fmt->code, CS_SEL_ANY); sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height; @@ -1035,11 +1034,10 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, break; case IMX7_CSI_PAD_SINK: *cc = imx_media_find_mbus_format(sdformat->format.code, - CS_SEL_ANY, true); + CS_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY, false); - *cc = imx_media_find_mbus_format(code, CS_SEL_ANY, - false); + imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } From patchwork Sat Mar 28 23:09:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463807 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C84B8159A for ; Sat, 28 Mar 2020 23:10:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DD912074A for ; Sat, 28 Mar 2020 23:10:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YTT04pLn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727593AbgC1XKU (ORCPT ); Sat, 28 Mar 2020 19:10:20 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:40297 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbgC1XKT (ORCPT ); Sat, 28 Mar 2020 19:10:19 -0400 Received: by mail-pl1-f194.google.com with SMTP id h11so5060109plk.7 for ; Sat, 28 Mar 2020 16:10:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ml/BZ3+EzOb+wiPBn+JlPv4MuJ1Ay5R+hGTw435LtZo=; b=YTT04pLndCM2qCgsdPdX37+iAKI/rQm2Q5UNATXy0ApiICIntkq4taFFfKix8f0IBE a4l7k2furVY6iyBBmJrzrUvn1MER2/gIUNeRYOFnpFd8AJzsBBtGYeAz8u+jQcSRvWD7 5+L9BQnRtucExClGUdf24qGyduZWxd8pO/eTc7Z11HvyvzMM2jhprInrU8+iBmVO7JIu VF8e6mDVZYmmb6iigRPONsoGgxPqD+O0lapUM2hnjlmtEx8LKagF6n50nJB6k59bqbRc RiQcQS6VdpQKi28lH8MdDde8/A1LuAU3YxOwOYjvyo23qT2D973NvdHH+0uNy2dp6gfW 21VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ml/BZ3+EzOb+wiPBn+JlPv4MuJ1Ay5R+hGTw435LtZo=; b=hjtYOzS2+53aliCo5bu0vjaHUVP5HN9oWvDRhpi9xa6rjhJSFymaL55bLNKMmNAKce mke7Eaivd42Z+Jo6hVIKfHrx2ZGli1R8rW8E7K/ytt9StMuWnCF+H0D3sr+2wNc6GfJx 1cEaJkmx2mEEC9iTOA1fQO6Rie5u7jgCD44mlrmHHZlI+R/5SKd9yyuqHZsYStLwjXUr W0KQbOwnQrRTHdiTQegjv1qZn3b7Rz0Ko6+aFNQhKda3F1QTXeK2L2N2DiJMu16FFr+3 Rkq7w/RrPR3GgVZBv4Ojf9D+BAAqn8pfP6FrcIdFAxLxI1JHa6o+SDdi6EEdsa/nkNDy L/hg== X-Gm-Message-State: ANhLgQ1F4HWSv+AZEfzHszzLZ2xGw2q1E8nUgf42NMTOiFZSHXq4uMgE Fa8MvT3Wts0Q61mFb0yVXAAcB47MQdI= X-Google-Smtp-Source: ADFU+vvzDpJDt3Fx8YyH1yVhEqYdAiRKnIRPm/5TcVxarC2gHtnWuMRw6As8s0QaApw4pfm9tD1c8g== X-Received: by 2002:a17:902:ba8e:: with SMTP id k14mr5892030pls.103.1585437018053; Sat, 28 Mar 2020 16:10:18 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:17 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 05/10] media: imx: utils: Simplify IPU format lookup and enumeration Date: Sat, 28 Mar 2020 16:09:57 -0700 Message-Id: <20200328231002.649-6-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart 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 | 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); From patchwork Sat Mar 28 23:09:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463809 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1CB966CA for ; Sat, 28 Mar 2020 23:10:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4C4F206F2 for ; Sat, 28 Mar 2020 23:10:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n4MphPQe" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727620AbgC1XKV (ORCPT ); Sat, 28 Mar 2020 19:10:21 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40299 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbgC1XKU (ORCPT ); Sat, 28 Mar 2020 19:10:20 -0400 Received: by mail-pl1-f196.google.com with SMTP id h11so5060124plk.7 for ; Sat, 28 Mar 2020 16:10:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4wDBpf2VgaVayCY8YAUcbDDSNWf1nPlDGIitFBAhbgU=; b=n4MphPQeSbXu+tWqFxfikIb8D+YF/kcvJfKbFti14dKe7wnEshnmuKtR7h1xv8YTN/ ILZJlrty8QYYnEvAPgX0j1CaMMzmwHFeT9nqSKPBBCCsNkrRHLUlJfLGlFBnOCqLwREo /73kTmeJzuDn+30WExXjaIkadsuLRcfculyVvEzm/VXOXN9WXLh5/mCXDjgE2J928/VW Tf5M7gNW0HFyjt/9akpFY/jPR3htni0atkhZ20qEEs8csM8J38kAg42UynTkJ5EccRps fFiVt8YF2JoPAdrfVeUAiB/SCWaVXrPYR6vFvmaZzvufPI0cj8+FCG8mlI1KbRkf63Tk q7vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4wDBpf2VgaVayCY8YAUcbDDSNWf1nPlDGIitFBAhbgU=; b=ElIlJ8UHhEOzoTWgzfMpRx8FNDtShgibFfK6YBGaZFPpKD/UMTEFnfxZPHuJjCQl3Z SEw99De+wJpyu0Bvb/YfZyVS3qW5P3V8fq/ZNgc8yMItFoqXib5f/ckmp3DyJORVE42k O+WM5lA5jTh5UV9k+npbnJvf43mO7DSvwNsPZOSTuk5DnbsLZb/UQ+GMM2nWYxx1vRPw gN4dRaYc8wxb5tz+ut7yengg05Vv4UrjWk6W79dYntGAOYuDCqxNKh11ozhNbFEFBHo8 7P7+qo3PH+dDW2W2ca0DAoKWZKPU1hh0wWTWx3KVORS/ZVdAQR4we/mwQFnKDLSMw0E6 khTA== X-Gm-Message-State: ANhLgQ23+//gSp3A7MVtfIsikq2KCMKqjuVZ2HZDnDGUoQNau6PYqOod xV47G2P7auoijA7AGqbYDrooXt+lhaA= X-Google-Smtp-Source: ADFU+vvnLpumH9s86yubhKP63yzZgn/bK77sFiPrZepKh2Mp+VoYA+YUevcHuwEXwsKmeR2eojWPhw== X-Received: by 2002:a17:902:c595:: with SMTP id p21mr5864951plx.17.1585437019469; Sat, 28 Mar 2020 16:10:19 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:19 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 06/10] media: imx: utils: Make imx_media_pixfmt handle variable number of codes Date: Sat, 28 Mar 2020 16:09:58 -0700 Message-Id: <20200328231002.649-7-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart 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 | 86 ++++++++++++--------- drivers/staging/media/imx/imx-media.h | 2 +- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 981a8b540a3c..0904b6479577 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -7,6 +7,12 @@ #include #include "imx-media.h" +#define IMX_BUS_FMTS(fmts...) \ + (const u32[]) { \ + fmts, \ + 0 \ + } + /* * List of supported pixel formats for the subdevs. */ @@ -14,18 +20,18 @@ 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 +63,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 +81,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 +101,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, @@ -203,16 +209,16 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, CS_SEL_YUV : CS_SEL_RGB); if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes[0])) + (!allow_non_mbus && !fmt->codes)) continue; if (fourcc && fmt->fourcc == fourcc) return fmt; - if (!code) + if (!code || !fmt->codes) 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; } @@ -237,7 +243,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, CS_SEL_YUV : CS_SEL_RGB); if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes[0])) + (!allow_non_mbus && !fmt->codes)) continue; if (fourcc && index == 0) { @@ -250,7 +256,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; @@ -296,13 +302,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, @@ -327,7 +333,10 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) continue; - for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (!fmt->codes) + continue; + + for (j = 0; fmt->codes[j]; j++) { if (code == fmt->codes[j]) return fmt; } @@ -351,7 +360,10 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) continue; - for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (!fmt->codes) + continue; + + for (j = 0; fmt->codes[j]; j++) { if (index == 0) { *code = fmt->codes[j]; return 0; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 652673a703cd..917b4db02985 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 Sat Mar 28 23:09:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463811 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 795CD159A for ; Sat, 28 Mar 2020 23:10:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 58C552074A for ; Sat, 28 Mar 2020 23:10:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oPmy75dj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727666AbgC1XKW (ORCPT ); Sat, 28 Mar 2020 19:10:22 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:46996 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbgC1XKW (ORCPT ); Sat, 28 Mar 2020 19:10:22 -0400 Received: by mail-pg1-f195.google.com with SMTP id k191so6667593pgc.13 for ; Sat, 28 Mar 2020 16:10:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aOtb35FNMsD5Jp3maP5fsa6UUEhYC9vPFnZgmX7lerM=; b=oPmy75djLG0BB3xnqvSAtxiYDDmUhDJ+NEF4lKuLDORW/YFmhbjScf7J3KkXUp5GzP z6zEJGtP/XyQAbblst0BWjmzxkPTZRC5uHuQYiYDu+GfZ8seJLyWu66d18UTeLadv03t LYmRLiSDlpl0bs+Ka0lT/2cD/Wo5XRJ2/5xP7GS/JT8k10N3mTL26PSN7VpQvEojsqfM THEFXGtI7ZUw0jXqvONKAVuiOR/Y/i/RzV3RSRMV9MZeNT6WuUoA0prFnVr7uBscAO5S QNKNQ7b/AIK7kGSe1XBB0sCAFKe8gyuNrSpDfG4/PN9wXXLvA57QJEi6CwThv0LvXaRe 9+Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aOtb35FNMsD5Jp3maP5fsa6UUEhYC9vPFnZgmX7lerM=; b=pzN1vFEnhGM94tcOw8YCtUbBimF1T7d7+x2GeY3XT+FKiQ4MeRx4BfGRelA5ynhAss e2zDHTTccj7jztRc4gkJqeAjkcFpq5OzZt3ONZYCRnMBMiqmjHnMtA3I4rKEKtFySqBw bSrCJr41tm2VAojljQFeq2yCFMtobNgkEu0QRefUM0l5OvunySKwCUaZUy7iZb4azWKA PXHCrJ8VJqS/Rme05DJkiqr8XLYv/kKXuUx9zMNMYA6Bu5vqhB/019tr3mCepynrvRe4 APGM902EjTWTkdmZ83Hg+8Axdr4K6X4tJYb4t4w3xcsg4kiAnw0yXzKrSUQ6z2f0+dy3 4h2w== X-Gm-Message-State: ANhLgQ1KOgInC+gz7BpaioPZq/1jQCKx6ZX8gsqkth6743J4e7TE0UfO LKAaG+OuMLVTG6CbTnhcT30RFJOQTbo= X-Google-Smtp-Source: ADFU+vsLKFY+SKismv88IXNq6dsnKNPMRU574u43EVOHcWzJsBiiSYc5q2w32Z1INydINI8qF54mrQ== X-Received: by 2002:a63:f113:: with SMTP id f19mr6521993pgi.168.1585437020842; Sat, 28 Mar 2020 16:10:20 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:20 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 07/10] media: imx: utils: Remove unneeded argument to (find|enum)_format() Date: Sat, 28 Mar 2020 16:09:59 -0700 Message-Id: <20200328231002.649-8-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart The find_format() and enum_format() functions take an argument that tells whether to take into account formats that don't have associated media bus codes. The same information can be deduced from the fourcc argument passed to these functions. Remove the allow_non_mbus argument and use fourcc instead internally. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 0904b6479577..33c874668ad4 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -194,8 +194,7 @@ 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, - bool allow_non_mbus) + enum codespace_sel cs_sel) { unsigned int i; @@ -208,8 +207,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes)) + if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes)) continue; if (fourcc && fmt->fourcc == fourcc) @@ -228,8 +226,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, } static int enum_format(u32 *fourcc, u32 *code, u32 index, - enum codespace_sel cs_sel, - bool allow_non_mbus) + enum codespace_sel cs_sel) { unsigned int i; @@ -242,8 +239,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes)) + if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes)) continue; if (fourcc && index == 0) { @@ -272,26 +268,26 @@ 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) { - return find_format(fourcc, 0, cs_sel, true); + return find_format(fourcc, 0, cs_sel); } EXPORT_SYMBOL_GPL(imx_media_find_format); int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel) { - return enum_format(fourcc, NULL, index, cs_sel, true); + return enum_format(fourcc, NULL, index, cs_sel); } EXPORT_SYMBOL_GPL(imx_media_enum_format); const struct imx_media_pixfmt * imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) { - return find_format(0, code, cs_sel, false); + return find_format(0, code, 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) { - return enum_format(NULL, code, index, cs_sel, false); + return enum_format(NULL, code, index, cs_sel); } EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); From patchwork Sat Mar 28 23:10:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463817 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D1B21667 for ; Sat, 28 Mar 2020 23:10:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 215DB2074A for ; Sat, 28 Mar 2020 23:10:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C0z6xjWE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727801AbgC1XK0 (ORCPT ); Sat, 28 Mar 2020 19:10:26 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:50648 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727725AbgC1XK0 (ORCPT ); Sat, 28 Mar 2020 19:10:26 -0400 Received: by mail-pj1-f66.google.com with SMTP id v13so5732745pjb.0 for ; Sat, 28 Mar 2020 16:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cux4DklEFWIT57sTLXAkS/5MG6rGPZDIgDkQLle/cxY=; b=C0z6xjWEWxwDkkoF0KH/uddY687WN93P/tq9cdOHd0d0gSTCdyHcdzwQoYb9RV1pO2 wCyyXNuK10aZiBuuwIXHjfKp9a550wPszjBUDwpH+wQ21zZNO0VbIK4mmveFFkhHygYd 7E8L/Cf4odsjJzQQf1/PU1kVnQyutmADiqXX9l9hvtA2o9HEc1/WX9g0e1KkVnNa6dM/ Yo6vBlFBy8chOT43z9hmpCRe0ebNIS0oGQI2D73CaEUzDHhiDF5TMr7KpFLjhRxEPq/p enjHRlTnRf5qQI1OspAhIwfh2BofcVyvuQHlWC9VkaFean35l2gQ5O98rhplaU1MQukY etZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cux4DklEFWIT57sTLXAkS/5MG6rGPZDIgDkQLle/cxY=; b=b2d5IiIWkNfK+ii3kBBR4a2K3CmmCJx8KPb4BUwXhn/6zKX1REtHZ/nmpqHWbHqxE7 A8YbdA3UgxB0qWNb3AG7qQCHtCAabmKBgL1/1ysTJa3dc/WGoGA2cL/reTngI51uj7zV ml1B3nrVL/9JKH58bcSF4PA/MEhVTM3ruKB58gi7dkoLrJ+ciFx+hvST7zx6h2TDk8NZ uK8Y8AQW/Ez3shqNvMZdPr0RKpfz35kkalM82n7TNovhb3wlkZYk4E2dc/DH7HH15c39 56+osdxqlxxaYdzxNBSk0xrxFcc7i/coR56v0HtUPjmI7AHdozQIT4Ut+jAIoA/uIhm+ 9A0Q== X-Gm-Message-State: ANhLgQ3FSAVP2WPEwZvCOzG5wZgP8jPU3L0S598TGuHIryua8WI3mpYF 56Yx7Qs7ESZJce+Wju8+EVCZt+L4GGo= X-Google-Smtp-Source: ADFU+vuEyfhjEy7EjNUkM+2DVLZP5jb2x1g14gmXMgX91p385Ie1+maOCeiCGIqbi6GxWQjzF+MLCg== X-Received: by 2002:a17:902:561:: with SMTP id 88mr6022309plf.78.1585437021956; Sat, 28 Mar 2020 16:10:21 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:21 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 08/10] media: imx: utils: Rename format lookup and enumeration functions Date: Sat, 28 Mar 2020 16:10:00 -0700 Message-Id: <20200328231002.649-9-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart 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 | 8 ++--- drivers/staging/media/imx/imx-media-capture.c | 16 +++++----- .../staging/media/imx/imx-media-csc-scaler.c | 3 +- drivers/staging/media/imx/imx-media-csi.c | 15 +++++---- drivers/staging/media/imx/imx-media-utils.c | 31 ++++++++++--------- 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, 54 insertions(+), 50 deletions(-) diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index 9c1f723972e4..50471541f4bc 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_YUV_RGB); + ret = imx_media_enum_ipu_formats(&code->code, code->index, + CS_SEL_YUV_RGB); 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_YUV_RGB); if (!cc) { - 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]; } @@ -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 5a22cdc7378a..003ace29ccaf 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -850,8 +850,8 @@ 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_YUV_RGB); + return imx_media_enum_ipu_formats(&code->code, code->index, + CS_SEL_YUV_RGB); } static int prp_get_fmt(struct v4l2_subdev *sd, @@ -890,7 +890,7 @@ static void prp_try_fmt(struct prp_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]; } @@ -1249,7 +1249,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 d60b49ec4fa4..1ff992eb4d96 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY); + cc = imx_media_find_pixel_format(fsize->pixel_format, CS_SEL_ANY); if (!cc) return -EINVAL; @@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY); + cc = imx_media_find_pixel_format(fival->pixel_format, CS_SEL_ANY); if (!cc) return -EINVAL; @@ -172,7 +172,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 { @@ -217,10 +217,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, @@ -789,8 +789,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 3e1c88938e7d..0aa2493cfc47 100644 --- a/drivers/staging/media/imx/imx-media-csc-scaler.c +++ b/drivers/staging/media/imx/imx-media-csc-scaler.c @@ -164,7 +164,8 @@ 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_YUV_RGB); + ret = imx_media_enum_pixel_formats(&fourcc, f->index, + CS_SEL_YUV_RGB); 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 298294b95293..caab4d0cd5ce 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1238,8 +1238,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); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + CS_SEL_ANY); break; case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_IDMAC: @@ -1258,9 +1258,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: @@ -1448,7 +1447,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]; } @@ -1471,7 +1470,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc = imx_media_find_mbus_format(sdformat->format.code, CS_SEL_ANY); 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]; } @@ -1758,7 +1757,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 33c874668ad4..5198af5d17d6 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -225,8 +225,8 @@ static const 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) { unsigned int i; @@ -266,17 +266,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) @@ -285,11 +286,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 @@ -342,7 +343,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; @@ -371,7 +372,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, @@ -383,7 +384,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); @@ -522,7 +523,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); } @@ -574,7 +575,7 @@ 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); + fmt = imx_media_find_pixel_format(image->pix.pixelformat, CS_SEL_ANY); 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 917b4db02985..67983a26e5ff 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -159,14 +159,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 a469dc76a787..df4dd41b23de 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); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + CS_SEL_ANY); break; case IMX7_CSI_PAD_SRC: if (code->index != 0) { @@ -1036,7 +1036,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, *cc = imx_media_find_mbus_format(sdformat->format.code, CS_SEL_ANY); 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 Sat Mar 28 23:10:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463813 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A172159A for ; Sat, 28 Mar 2020 23:10:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 499132074A for ; Sat, 28 Mar 2020 23:10:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="EC9Elvez" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727771AbgC1XKY (ORCPT ); Sat, 28 Mar 2020 19:10:24 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:34814 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbgC1XKY (ORCPT ); Sat, 28 Mar 2020 19:10:24 -0400 Received: by mail-pf1-f195.google.com with SMTP id 23so6583376pfj.1 for ; Sat, 28 Mar 2020 16:10:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2r+BGMcE4zz/s+rSEZSFvyUchfyTpyNZWNxDY3jvnBI=; b=EC9ElvezSOAKdORKf2y0hfBd8nJ8mzskgJrCLxWZDaRBqnFFhI84EUtB3aUqkW7JiG RIv3SY2RVKYomd09cq0J0IGbxQyMelbXJr4P8QJFmZ69baZIKDtTZdJrJBKQg13Bphek mtR8I06OXWzBYYYknC/CoMudTa8sk0P85xR+hQOuguX9hb5tp5JyMYjk00a6Wq/I4OB/ LTo2ScTVaIlXaJuTPdCme+c7oUI0vofgmzayIyMO1wlFcOiqKIL6NuYdVHTSTM0GMdUi 8rbs9l3oS8mAxbzpyLqDRP0HuaByu70+mXhGDa3bw/v85O19FD08F/8det49G6w5/Ix4 PknQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=2r+BGMcE4zz/s+rSEZSFvyUchfyTpyNZWNxDY3jvnBI=; b=fY9RLfNIVNAGEOTzXLBwRT1+l4dx1TNOvNgea7s5kBf9NkO/+YqVqkkJURXn1zJNj9 I8rT+rXEAM2tBd05+UeC7i6YpAS+CgkvlBuLBzLC4lJ4FFHDHVVi4d2nCfSMion5YP3b q6dZi9OgULDmbdZ7Hl/eJH2gLYUcZPLOYCEo2fRGn6ddztdWMcEaQWkT02twBiIFmZC/ nrwpf6z+z9xtY1qoZuNQZH3z99YzrK5w31HppgB9c9CqsXbrELHfZb8/P0n60fMJVr/a UPZpmWyPK43l3f1xZQIu+Ea+IDkqzkHI/ew7+5qqGE+L4qP9ihltEEop1498jrnV3wNo jJhw== X-Gm-Message-State: ANhLgQ1rdHaVJllbYn/1Dmw0EbIxh2qfgvljNysI+Lx+vb4E4wIW0gmL VmAMq9IUWFzHurmdoLDIkUPgrORKKzY= X-Google-Smtp-Source: ADFU+vvLC/Jx1CyMCBPRCsSXLzWR4jToLowuaRxaPRgMeIKikDDdjoZ4ccRlwO2eitwm6+vL9ElMkg== X-Received: by 2002:a63:2642:: with SMTP id m63mr6184385pgm.258.1585437023285; Sat, 28 Mar 2020 16:10:23 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:22 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH v2 09/10] media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_pix_fmt Date: Sat, 28 Mar 2020 16:10:01 -0700 Message-Id: <20200328231002.649-10-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart 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 5198af5d17d6..54f6ded0f7c6 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -501,7 +501,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 67983a26e5ff..a4885e280b83 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -178,7 +178,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); From patchwork Sat Mar 28 23:10:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11463815 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11DB86CA for ; Sat, 28 Mar 2020 23:10:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DB5842073B for ; Sat, 28 Mar 2020 23:10:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jOUmvJ65" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727797AbgC1XK0 (ORCPT ); Sat, 28 Mar 2020 19:10:26 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:33469 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727506AbgC1XKZ (ORCPT ); Sat, 28 Mar 2020 19:10:25 -0400 Received: by mail-pj1-f68.google.com with SMTP id jz1so5340227pjb.0 for ; Sat, 28 Mar 2020 16:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rlGQd07hYQ4jOoVjLagH/BqY8mPdrgQV3Nmqy310vig=; b=jOUmvJ65cxclAVxVxbJiLnZDg9aVWXiNY7oQOCbph2/vc0VobcZOjm7eFodP8wAkYF jppcPBwBAlE16MzFuQr4q/CMSqVNk6aa3DrPx/vIUjLMaCsYIrUU/2OsSTRLioEgE6VM 0LvoPox2B/X1zvZ3wbaek4sP8kgLbqoMt3obH9bljbQz+ib5cIealJHqlrrphemU+alj 8q/DHcShCANGPBvqACUBy1XHnmfmh1QHJ55mTY3Vjtcp4l9FCbhyFamy9vO5f5vwHQ1t NW3beAhJGpZppnPZoG6kempbUvA1RRwMc16UXePvMAy1Ip37lOSx2hr/MW7wOAHaVQBJ PODg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rlGQd07hYQ4jOoVjLagH/BqY8mPdrgQV3Nmqy310vig=; b=QZDDdm5I9Hj62iAmj2QIa45rrdPnDcD6CB+k8ynsLcy4TWEbxWafpwcx1h8FDfMaLw QJfBgwuJFZyI2rXpBsdOQBZAiyzUVlq3KCdKp9JeSEu15lq91SB6MnbKM1XO357Imdw3 /SDJu9hluQLgTC3vEegSJQYJaDUVJyFpTjJ/4656s9rbBFQpGHg77E1kITdGxzJui1m1 DJU1rMIrcu6y69QUPuvXboigB/aSBQweeSESF7vQarB8egi1dNuGn4zDGHRXlso0sH4Y oJqsxzzZA4/ST6zEAaTJSQdaF0i7FWcjjj6YOldX86DP9sA3fFKLmri+LuqRm5Jhs+CR QuhA== X-Gm-Message-State: ANhLgQ0pS4GzkJmq6mepbnmZjCdknjY9dbqUSfzNPEinvs1zaSeh+C7T SydFv83ProDqaGk59Xv3iVNhp7kflHU= X-Google-Smtp-Source: ADFU+vvJb0TUzFGhV/olzHHHqJiYxNVvSFFyJz++/66AMv5w8C8TY90hdnwcEHlzgCCV2QCDH1YXaw== X-Received: by 2002:a17:90a:1acd:: with SMTP id p71mr7688100pjp.112.1585437024392; Sat, 28 Mar 2020 16:10:24 -0700 (PDT) Received: from mappy.nv.charter.com ([2600:6c4e:200:e053:3081:8132:c81a:db99]) by smtp.gmail.com with ESMTPSA id w74sm3978602pfd.112.2020.03.28.16.10.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Mar 2020 16:10:24 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam 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 Message-Id: <20200328231002.649-11-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200328231002.649-1-slongerbeam@gmail.com> References: <20200328231002.649-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 --- 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); /* -----------------------------------------------------------------------------