From patchwork Sat Apr 4 22:41:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474479 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 76C53912 for ; Sat, 4 Apr 2020 22:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4C221206F8 for ; Sat, 4 Apr 2020 22:41:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hCsGnt1q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726364AbgDDWlm (ORCPT ); Sat, 4 Apr 2020 18:41:42 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:43688 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbgDDWll (ORCPT ); Sat, 4 Apr 2020 18:41:41 -0400 Received: by mail-pf1-f193.google.com with SMTP id f206so5555591pfa.10 for ; Sat, 04 Apr 2020 15:41:40 -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=hCsGnt1qu/aY1oklb+aFQKNkIUzDDOpXmkZPueoZpB+qSFXg8U3Tg4SkeD8x33jB9q 2drBM31OwHq0AF/TJGdsvcjIvHwkE0aIKPSSrRCxfueEyoay+1BF8P59HiW6CRGNxt39 TpQ9o+cc76rZ7ud3IgeKJQFxz0iz2eX1qimmdu1Nf96vsipyMb3fLZ68WNOzg/b4KEem mgTS9n3WMWqOYqlspsKhe+e/jKhRW0Jn+XArOEHGpPZG/iMqjZncQEKJtddZr69UjUDk 83ohAzEduCtO425Yc+VX9FAmAEiBmPq95zrRuHSR+yDA0+0OALfslKtGpzxLMMNxk9Cl vNVg== 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=uMuq+FV5YbL525BNTKnYhcgEdgyHPOHPDMf5Ci7HeZFW0uPlYjC9ve9tRURLdeJQ2a 6NtgYxIAvYPW6tPyU3LjRk8urH6n0M3aSa7awnGLqyp/iMvcowckk9F6yosBM8somLuv cGj/xB6vXpeISO65dXt+36qhToa/d3jEsU0twggUJu28WwgZ7ZVp55MsStry5TO1bgsk cMsgq9RsfBc6LEJ7Cgjj/Bh++RMzKz0HdDzsEs6h1PYB5DByXdwHik9q11PgvZwyH+XM NpoiGRDapT2KYFZyTCxSRNt9vZ1xC4QOy4a+3byrBzR4g+anKXDMfI0dR7hXly4Tirde 5cGw== X-Gm-Message-State: AGi0PuZ5pV1Ho0Bkm8mcQSiGk3aqueDIFtCS/qy/yBYxPrViNuVHDyHJ Dm+WxD+nUpClAI5fg66zhw1/bQhfPMs= X-Google-Smtp-Source: APiQypLsX8f2T3zYNI2l0fPdu7Eb9SQm5raWq2NfzHYBh31gQE+Z8vDMIpX+KGzOpK+FaqFM7boEfw== X-Received: by 2002:aa7:9d0a:: with SMTP id k10mr15309618pfp.266.1586040099542; Sat, 04 Apr 2020 15:41:39 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:38 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 01/11] media: imx: utils: fix and simplify pixel format enumeration Date: Sat, 4 Apr 2020 15:41:20 -0700 Message-Id: <20200404224130.23118-2-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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 Apr 4 22:41:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474481 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 A16F11805 for ; Sat, 4 Apr 2020 22:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 80676206CC for ; Sat, 4 Apr 2020 22:41:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eY1DG2EJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726365AbgDDWlm (ORCPT ); Sat, 4 Apr 2020 18:41:42 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41852 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbgDDWlm (ORCPT ); Sat, 4 Apr 2020 18:41:42 -0400 Received: by mail-pf1-f193.google.com with SMTP id a24so5554692pfc.8 for ; Sat, 04 Apr 2020 15:41:41 -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=eY1DG2EJxOUR0cSgODlE0GxMRL/eM5R5DN49c7kfQ337/4V2tLt/x5qjM8nATeEXCM f7QmGHFi7I7wPbspABpEQkk6R6GC+6pJxB0xg9vCWK0Z+FaR2IKPoQNhn6+OCiKs/8DU GFIkjT1bO1T1LG8gBlJCuuA0IpubzBJPZonnQG0rg/ITbI1ghJDpJgpnlqjX0W4G3zf9 VsRxnmPOC5x5p+YZJRFWiRAyDAyEybO+5DITJFcUo2l3h8Sg5ZEsECiZ/Shx2hMNjo/7 sJgDAot76LFWJ4Bv1wSvDfvmARuWvPPBeQ2dDobSt7P+fTK3k/2DXHC64+FvyapdVK/M ratw== 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=Ze0loA2TnMql8Q2ehnAoS6ISqblwDfiuRT/+905UjTAllDVx6mzZRgKqs0biwsiwkp GTB7A8M0ZuyLdm6Fp9q7zeob2sM+aE9Gb5ymq0L4nCUWC9JADyqNHK80OnFn5D73LBbL 4g6u12yytsCeQ5a2PPphH6SAA9HtUsFgay44EO93cO7yWaIW5rChSbQxyJQNvFrAHGft 4COL99rHY9ETUQn4rCpLS/ZpSGcGybVxzL6dayJ7UUAJheNZdeS+nL8iE/BMrYBcDx5Y LX2gyYGHDGlg8Ew/PVzkU2AyDE3aNWosdfnc62LatZfIxKuIt8Tt8h3yusCBwKMKY35f mcxw== X-Gm-Message-State: AGi0PuYqYI1GoriLV/avbFcYkUV36LIttZxCjVRNKwbqjPZKi35EqduP cjqOi7avNkFOPpCTrLnO+Fz+4gjKxTM= X-Google-Smtp-Source: APiQypIHLFQliHcE/PH9zAk5SjEMu3Kl09gVSkWXd72154oXFBj0yn0Mdv9PKLbZv8EzObpNP6lQEA== X-Received: by 2002:a63:5e44:: with SMTP id s65mr15140616pgb.112.1586040101040; Sat, 04 Apr 2020 15:41:41 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:40 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 02/11] media: imx: utils: fix media bus format enumeration Date: Sat, 4 Apr 2020 15:41:21 -0700 Message-Id: <20200404224130.23118-3-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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 Apr 4 22:41:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474483 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 D5F24159A for ; Sat, 4 Apr 2020 22:41:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AB42B206CC for ; Sat, 4 Apr 2020 22:41:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UPJxoEsQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726380AbgDDWlo (ORCPT ); Sat, 4 Apr 2020 18:41:44 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:40688 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbgDDWln (ORCPT ); Sat, 4 Apr 2020 18:41:43 -0400 Received: by mail-pf1-f193.google.com with SMTP id c20so5558679pfi.7 for ; Sat, 04 Apr 2020 15:41:43 -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=UPJxoEsQLaSAAg+RZOwaayl8ZEAwHcYenJnUOeoyZ/cY4emK7+2kIi1FkQTzitJGsn BxByGnlX0sJ8p+wSCRRyeA6NjhcvTMENUTcYO1orYjI3PRBoA9aAm68PSE4z0h11ohqC HD2FixreSlC3vBohyaT9BiopmMoMNGm6pm7Wl1HXfWS1+rFVayACnKPatNdOCVD3rIvm YU4SVy0iNMCgTO0eMRE5Bh0JBTkiKMr1CaxTajdHsNAyRMzvHVFdfJcmQl2c2aolUzZR vPLIX71lwQVYj7gxMakt1acl3+ThD8JNh2ewMB8jsM5349V9WIrkE2BD92eCpHlxg4sh 2kug== 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=CuJyBV5TsdPv6NKjVpLbLP7vExWn2KbWeG1qD4D6dW4zXOuxIa8Fd+Bz9EHxqew/bp uSLMZKKQ2FuQFQ3K6f6embVXNpR4KQ6qQIB0X2SAZt3saeKsqXsKSyrvFYnyKdnvIrbT pSNVVU7PGuYQWaCsPONIrBcTDBbQDX2Dsz2vOzewQihwc6RqX+ixSx+IxlPdLyT4mHXX 3PYITRXh+RMrKKTQS1YEzt6P70MV/Ax5IZzMZMYarOHcJydvNrfgCRIYZQy9pZ7Gu9a+ ZT2TWndA3pZUlUg55hShytTPeMhY7dpTuDrmAExsPsiF6wDR5ln2DO4EhZcCbYiGcZ0r mCMg== X-Gm-Message-State: AGi0PuavhYgEwF+9qMXAXh6BY5s/kVqA1h5UItfx6TqstOkDQ5H7kTC5 yDZl4+KeCSsD98CxXd8JcMDnMd6q2x0= X-Google-Smtp-Source: APiQypJFH06/AVG9Wa4y6iKbXnxZhAzBARKyyzNnNdVH9uNdGMVhBaO5SCPKsCsgoEax5sqNc08qfw== X-Received: by 2002:a63:e856:: with SMTP id a22mr13888418pgk.283.1586040102362; Sat, 04 Apr 2020 15:41:42 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:41 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 03/11] media: imx: utils: Inline init_mbus_colorimetry() in its caller Date: Sat, 4 Apr 2020 15:41:22 -0700 Message-Id: <20200404224130.23118-4-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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 Apr 4 22:41:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474485 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 16A8D19BE for ; Sat, 4 Apr 2020 22:41:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DF820206CC for ; Sat, 4 Apr 2020 22:41:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TrBWvt9y" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726397AbgDDWlq (ORCPT ); Sat, 4 Apr 2020 18:41:46 -0400 Received: from mail-pj1-f67.google.com ([209.85.216.67]:40939 "EHLO mail-pj1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbgDDWlq (ORCPT ); Sat, 4 Apr 2020 18:41:46 -0400 Received: by mail-pj1-f67.google.com with SMTP id kx8so4728689pjb.5 for ; Sat, 04 Apr 2020 15:41:44 -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=TrBWvt9yZRyAWIUtCwwwmv1JL9i2s5JEry397jrJ7QuRa233I/1lYd0vabzDf+lPL+ DQz4SlBF66HEkKx3S5wxfV+E7OCvAS9qpUDu6Al9mzf28HNuEE+Z4/DTRNFqERSB+0q1 c7MaY5Zjt7WOzyK/0xu7smOXrS92qWE3oF/uInWA/Eb6kIBjx37WJE2Zim5DPmVxYyoh FHLX1zmUMiG3V/txRRB2QA2/V1xq3tLFgEwfbkUzB5IE7zcQ/wP+PUTmdFGZlJ2GE7ow OkKYyCtTzBFkGHLVVMzUAcbttsVpugEJJj43OaoUyd7PtGofTahCb/51GQnxliALyL/8 dPvQ== 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=q9LWv5sf6cf/DhWI33urQevK/YTGjKyAd7v3VHmbffY+Cpi2AdQI8TWU08il0BEnMT nNzuws3tjKg37YCzHqU11BcSYhX3DqUimgQXaVfO0+w6nHpMdvvP/o9pSZH7rIHrTCKw LDGy7Vf8m1gYG/YIrtbA0yS9gYn1c1mUA+214tFTTY5syUQlPEQgxLBSll/sy/oGvQCA tWnkP59XH9jsnRM4dr4rFxxd6z2K8WMEVNvk8YhMPN9LX4p5dcSVFhsK6LTKZQgN/+Ua dMZYp+ksIG+2VWJuXD1SE7WduTfuwuMwqJwhHIr3mK+2ms/x33UNdLTx3avSoraN9rnO CN6w== X-Gm-Message-State: AGi0PuYXTbv2bqTZWMWAmcfQpUeKmqwhd9J71MyHdmOrKH++hkoLrV65 1LSTsUhrYc+rabW/ETWoyaUuC9XVU4w= X-Google-Smtp-Source: APiQypJHer65wJRAjobgSflx+L/O8E1kgT581jhJ0R9yYqHXGK4zAMYzX2Ck0pGmvJr8SDLlwOmOhA== X-Received: by 2002:a17:90b:254:: with SMTP id fz20mr17997790pjb.27.1586040103608; Sat, 04 Apr 2020 15:41:43 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:43 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 04/11] media: imx: utils: Handle Bayer format lookup through a selection flag Date: Sat, 4 Apr 2020 15:41:23 -0700 Message-Id: <20200404224130.23118-5-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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 Apr 4 22:41:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474487 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 413821892 for ; Sat, 4 Apr 2020 22:41:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 203A8206CC for ; Sat, 4 Apr 2020 22:41:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oUvYdos9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726402AbgDDWlr (ORCPT ); Sat, 4 Apr 2020 18:41:47 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:42458 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726386AbgDDWlr (ORCPT ); Sat, 4 Apr 2020 18:41:47 -0400 Received: by mail-pl1-f194.google.com with SMTP id e1so4329967plt.9 for ; Sat, 04 Apr 2020 15:41:46 -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=Hm/mNH7apseCUYqxYslpH+fDkB0zbNidDdEszx+Vm8k=; b=oUvYdos9DXAMSW8R1MbB/RRg+CNG60HHaxtWJdvw0qTeermCz5mnrrrioCRpQCFkvG 322TF/pFzGnqUGrFqmi9bvhkfqt5Lch2f+Km4ig2H1y9FqFeq6RPiAMZx2JBb3ScDYJz j4OT79CJdgCkMOX/C5qOORQ/LCC7hqq1gdCnJDRZg4u3hUpxo7IXX5ymJHOdo57M+lwK AN15gWS1644/trkxbnMA93ibnImnBL0+cdCnFyIMtKy4TWd/X5bNgZvrcmSW+86stVpK x9y3VVo4/prfzZ6GVeyo/WrtJ81l3FAgJ2KPQFEcS1JbHvCpLLvoXF1pyhnYJb1Ws4U9 0Pfg== 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=Hm/mNH7apseCUYqxYslpH+fDkB0zbNidDdEszx+Vm8k=; b=PXV2BYn8K4aB/ZC41tKvGC02Pu45h25SnCk/8qfbNjr+c04bdUSKA09e3aKyYC26wG t/QGwiB0Sp/QPSZ1VQYDgN3Uen8pHerNLgFBZnAyeCJNV/7oQ3rk4ByRYSterLW1ZKd+ tcvBxtLrH0B+hLnoJ7ZYBxmjTMGmPo9kCH5jjQzt7xrB2HVdIf62MGPCa8RFCpmHrzxc nk/9lb6bibIqgsEu1GThw3X34UTH8q2lA5YhpvVr7WplhrlMsqMEiAGyFrBabAzHmeN2 +mOtqvo1PfAwIxAP9uqGM0XkE5OmA33niFhgJnGymjt4lf5Rk92P3TQ8dB9sHN4flV93 lgrA== X-Gm-Message-State: AGi0PubJ9vldwaLEbjaUQQeoVQqtTRKmbmJNI31fh60mITmt8RI0Vqt3 9bmKGSSZr0+M10cTSSZsNROIDczn3xk= X-Google-Smtp-Source: APiQypKeWAOvL0+3rV6oGoK695tI/oDuT+C4dxj1kyANMnJ3tJQ5nhdKeDrbIWLWmgXFBR2A/wBbeA== X-Received: by 2002:a17:90a:26ed:: with SMTP id m100mr17944778pje.130.1586040104802; Sat, 04 Apr 2020 15:41:44 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:44 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 05/11] media: imx: utils: Rename pixel format selection enumeration Date: Sat, 4 Apr 2020 15:41:24 -0700 Message-Id: <20200404224130.23118-6-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org After the introduction of the CS_SEL_BAYER flag, the "codespace" pixel format selection enumeration wording no longer makes sense (and even before, when selecting between YUV or RGB formats, "codespace" was a misuse of the term). Rename - 'enum codespace_sel' to 'enum imx_pixfmt_sel' - CS_SEL_* to PIXFMT_SEL_* - local vars named cs_sel to fmt_sel or just sel No functional changes. Signed-off-by: Steve Longerbeam Reviewed-by: Laurent Pinchart --- drivers/staging/media/imx/imx-ic-prp.c | 10 +-- drivers/staging/media/imx/imx-ic-prpencvf.c | 11 +-- drivers/staging/media/imx/imx-media-capture.c | 36 ++++---- .../staging/media/imx/imx-media-csc-scaler.c | 2 +- drivers/staging/media/imx/imx-media-csi.c | 33 ++++---- drivers/staging/media/imx/imx-media-utils.c | 84 ++++++++++--------- drivers/staging/media/imx/imx-media-vdic.c | 12 +-- drivers/staging/media/imx/imx-media.h | 28 +++---- drivers/staging/media/imx/imx7-media-csi.c | 11 +-- 9 files changed, 120 insertions(+), 107 deletions(-) diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index 9c1f723972e4..5b0571285939 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_YUV_RGB); + PIXFMT_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_YUV_RGB); + PIXFMT_SEL_YUV_RGB); if (!cc) { - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); - cc = imx_media_find_ipu_format(code, CS_SEL_YUV); + imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV); + cc = imx_media_find_ipu_format(code, PIXFMT_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_format(&code, 0, PIXFMT_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..adf8f9c9130c 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -851,7 +851,7 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, return -EINVAL; return imx_media_enum_ipu_format(&code->code, code->index, - CS_SEL_YUV_RGB); + PIXFMT_SEL_YUV_RGB); } static int prp_get_fmt(struct v4l2_subdev *sd, @@ -886,12 +886,13 @@ 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_YUV_RGB); + *cc = imx_media_find_ipu_format(sdformat->format.code, + PIXFMT_SEL_YUV_RGB); if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); - *cc = imx_media_find_ipu_format(code, CS_SEL_YUV); + imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV); + *cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } @@ -1249,7 +1250,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_format(&code, 0, PIXFMT_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..ac48cbe35323 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_format(fsize->pixel_format, PIXFMT_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_format(fival->pixel_format, PIXFMT_SEL_ANY); if (!cc) return -EINVAL; @@ -167,17 +167,19 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, return ret; } - cc_src = imx_media_find_ipu_format(fmt_src.format.code, CS_SEL_ANY); + cc_src = imx_media_find_ipu_format(fmt_src.format.code, + PIXFMT_SEL_ANY); if (cc_src) { - u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB; + enum imx_pixfmt_sel fmt_sel = + (cc_src->cs == IPUV3_COLORSPACE_YUV) ? + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB; - ret = imx_media_enum_format(&fourcc, f->index, cs_sel); + ret = imx_media_enum_format(&fourcc, f->index, fmt_sel); if (ret) return ret; } else { cc_src = imx_media_find_mbus_format(fmt_src.format.code, - CS_SEL_ANY); + PIXFMT_SEL_ANY); if (WARN_ON(!cc_src)) return -EINVAL; @@ -209,22 +211,24 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, { const struct imx_media_pixfmt *cc, *cc_src; - cc_src = imx_media_find_ipu_format(fmt_src->format.code, CS_SEL_ANY); + cc_src = imx_media_find_ipu_format(fmt_src->format.code, + PIXFMT_SEL_ANY); if (cc_src) { - u32 fourcc, cs_sel; + enum imx_pixfmt_sel fmt_sel; + u32 fourcc; - cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB; + fmt_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ? + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB; fourcc = f->fmt.pix.pixelformat; - cc = imx_media_find_format(fourcc, cs_sel); + cc = imx_media_find_format(fourcc, fmt_sel); if (!cc) { - imx_media_enum_format(&fourcc, 0, cs_sel); - cc = imx_media_find_format(fourcc, cs_sel); + imx_media_enum_format(&fourcc, 0, fmt_sel); + cc = imx_media_find_format(fourcc, fmt_sel); } } else { cc_src = imx_media_find_mbus_format(fmt_src->format.code, - CS_SEL_ANY); + PIXFMT_SEL_ANY); if (WARN_ON(!cc_src)) return -EINVAL; @@ -790,7 +794,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); + PIXFMT_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..ddb70da56853 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_YUV_RGB); + ret = imx_media_enum_format(&fourcc, f->index, PIXFMT_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..7a8bb28d7eab 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); + incc = imx_media_find_mbus_format(infmt->code, PIXFMT_SEL_ANY); switch (code->pad) { case CSI_SINK_PAD: ret = imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY); + PIXFMT_SEL_ANY); break; case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_IDMAC: @@ -1256,11 +1256,13 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, } code->code = infmt->code; } else { - u32 cs_sel = (incc->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB; + enum imx_pixfmt_sel fmt_sel = + (incc->cs == IPUV3_COLORSPACE_YUV) ? + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB; + ret = imx_media_enum_ipu_format(&code->code, code->index, - cs_sel); + fmt_sel); } break; default: @@ -1433,7 +1435,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); + incc = imx_media_find_mbus_format(infmt->code, PIXFMT_SEL_ANY); sdformat->format.width = compose->width; sdformat->format.height = compose->height; @@ -1442,14 +1444,15 @@ static void csi_try_fmt(struct csi_priv *priv, sdformat->format.code = infmt->code; *cc = incc; } else { - u32 cs_sel = (incc->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB; + enum imx_pixfmt_sel fmt_sel = + (incc->cs == IPUV3_COLORSPACE_YUV) ? + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB; *cc = imx_media_find_ipu_format(sdformat->format.code, - cs_sel); + fmt_sel); if (!*cc) { - imx_media_enum_ipu_format(&code, 0, cs_sel); - *cc = imx_media_find_ipu_format(code, cs_sel); + imx_media_enum_ipu_format(&code, 0, fmt_sel); + *cc = imx_media_find_ipu_format(code, fmt_sel); sdformat->format.code = (*cc)->codes[0]; } } @@ -1469,10 +1472,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); + PIXFMT_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); - *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); + imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_ANY); + *cc = imx_media_find_mbus_format(code, PIXFMT_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } @@ -1758,7 +1761,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_format(&code, 0, PIXFMT_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 6a3b0b737e5f..beaa920d7ac7 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -212,21 +212,21 @@ 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, + enum imx_pixfmt_sel fmt_sel, bool allow_non_mbus) { 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; + enum imx_pixfmt_sel sel; unsigned int j; - fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : + sel = fmt->bayer ? PIXFMT_SEL_BAYER : ((fmt->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB); + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || + if (!(fmt_sel & sel) || (!allow_non_mbus && !fmt->codes[0])) continue; @@ -246,21 +246,21 @@ 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, + enum imx_pixfmt_sel fmt_sel, bool allow_non_mbus) { 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; + enum imx_pixfmt_sel sel; unsigned int j; - fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : + sel = fmt->bayer ? PIXFMT_SEL_BAYER : ((fmt->cs == IPUV3_COLORSPACE_YUV) ? - CS_SEL_YUV : CS_SEL_RGB); + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || + if (!(fmt_sel & sel) || (!allow_non_mbus && !fmt->codes[0])) continue; @@ -288,50 +288,51 @@ 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_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel) { - return find_format(fourcc, 0, cs_sel, true); + return find_format(fourcc, 0, fmt_sel, true); } EXPORT_SYMBOL_GPL(imx_media_find_format); -int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel) +int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel fmt_sel) { - return enum_format(fourcc, NULL, index, cs_sel, true); + return enum_format(fourcc, NULL, index, fmt_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) +imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel fmt_sel) { - return find_format(0, code, cs_sel, false); + return find_format(0, code, fmt_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) +int imx_media_enum_mbus_format(u32 *code, u32 index, + enum imx_pixfmt_sel fmt_sel) { - return enum_format(NULL, code, index, cs_sel, false); + return enum_format(NULL, code, index, fmt_sel, false); } EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); const struct imx_media_pixfmt * -imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) +imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel) { const struct imx_media_pixfmt *array, *fmt, *ret = NULL; u32 array_size; int i, j; - cs_sel &= ~CS_SEL_BAYER; + fmt_sel &= ~PIXFMT_SEL_BAYER; - switch (cs_sel) { - case CS_SEL_YUV: + switch (fmt_sel) { + case PIXFMT_SEL_YUV: array_size = NUM_IPU_YUV_FORMATS; array = ipu_yuv_formats; break; - case CS_SEL_RGB: + case PIXFMT_SEL_RGB: array_size = NUM_IPU_RGB_FORMATS; array = ipu_rgb_formats; break; - case CS_SEL_YUV_RGB: + case PIXFMT_SEL_YUV_RGB: array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS; array = ipu_yuv_formats; break; @@ -340,7 +341,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_YUV_RGB && i >= NUM_IPU_YUV_FORMATS) + if (fmt_sel == PIXFMT_SEL_YUV_RGB && i >= NUM_IPU_YUV_FORMATS) fmt = &ipu_rgb_formats[i - NUM_IPU_YUV_FORMATS]; else fmt = &array[i]; @@ -358,22 +359,23 @@ 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_format(u32 *code, u32 index, + enum imx_pixfmt_sel fmt_sel) { - cs_sel &= ~CS_SEL_BAYER; + fmt_sel &= ~PIXFMT_SEL_BAYER; - switch (cs_sel) { - case CS_SEL_YUV: + switch (fmt_sel) { + case PIXFMT_SEL_YUV: if (index >= NUM_IPU_YUV_FORMATS) return -EINVAL; *code = ipu_yuv_formats[index].codes[0]; break; - case CS_SEL_RGB: + case PIXFMT_SEL_RGB: if (index >= NUM_IPU_RGB_FORMATS) return -EINVAL; *code = ipu_rgb_formats[index].codes[0]; break; - case CS_SEL_YUV_RGB: + case PIXFMT_SEL_YUV_RGB: if (index >= NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS) return -EINVAL; if (index >= NUM_IPU_YUV_FORMATS) { @@ -401,10 +403,10 @@ 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); - lcc = imx_media_find_mbus_format(code, CS_SEL_ANY); + imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_YUV); + lcc = imx_media_find_mbus_format(code, PIXFMT_SEL_ANY); if (!lcc) { - lcc = imx_media_find_ipu_format(code, CS_SEL_ANY); + lcc = imx_media_find_ipu_format(code, PIXFMT_SEL_ANY); if (!lcc) return -EINVAL; } @@ -473,9 +475,9 @@ 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); + cc = imx_media_find_mbus_format(tryfmt->code, PIXFMT_SEL_ANY); if (!cc) - cc = imx_media_find_ipu_format(tryfmt->code, CS_SEL_ANY); + cc = imx_media_find_ipu_format(tryfmt->code, PIXFMT_SEL_ANY); if (cc && cc->cs == IPUV3_COLORSPACE_RGB) is_rgb = true; @@ -525,10 +527,10 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, u32 stride; if (!cc) { - cc = imx_media_find_ipu_format(mbus->code, CS_SEL_ANY); + cc = imx_media_find_ipu_format(mbus->code, PIXFMT_SEL_ANY); if (!cc) cc = imx_media_find_mbus_format(mbus->code, - CS_SEL_ANY); + PIXFMT_SEL_ANY); if (!cc) return -EINVAL; } @@ -540,8 +542,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); - cc = imx_media_find_mbus_format(code, CS_SEL_YUV); + imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_YUV); + cc = imx_media_find_mbus_format(code, PIXFMT_SEL_YUV); } /* Round up width for minimum burst size */ @@ -592,7 +594,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_format(image->pix.pixelformat, PIXFMT_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..9807d578ce89 100644 --- a/drivers/staging/media/imx/imx-media-vdic.c +++ b/drivers/staging/media/imx/imx-media-vdic.c @@ -548,7 +548,8 @@ 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_format(&code->code, code->index, + PIXFMT_SEL_YUV); } static int vdic_get_fmt(struct v4l2_subdev *sd, @@ -583,12 +584,13 @@ static void vdic_try_fmt(struct vdic_priv *priv, { struct v4l2_mbus_framefmt *infmt; - *cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_YUV); + *cc = imx_media_find_ipu_format(sdformat->format.code, + PIXFMT_SEL_YUV); if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); - *cc = imx_media_find_ipu_format(code, CS_SEL_YUV); + imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV); + *cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } @@ -850,7 +852,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_format(&code, 0, PIXFMT_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 652673a703cd..ac7c521d8148 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -79,6 +79,14 @@ struct imx_media_pixfmt { bool ipufmt; /* is one of the IPU internal formats */ }; +enum imx_pixfmt_sel { + PIXFMT_SEL_YUV = BIT(0), /* select YUV formats */ + PIXFMT_SEL_RGB = BIT(1), /* select RGB formats */ + PIXFMT_SEL_BAYER = BIT(2), /* select BAYER formats */ + PIXFMT_SEL_YUV_RGB = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB, + PIXFMT_SEL_ANY = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB | PIXFMT_SEL_BAYER, +}; + struct imx_media_buffer { struct vb2_v4l2_buffer vbuf; /* v4l buffer must be first */ struct list_head list; @@ -149,24 +157,16 @@ struct imx_media_dev { struct v4l2_subdev *sync_sd[2][NUM_IPU_SUBDEVS]; }; -enum codespace_sel { - 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); -int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel); +imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel sel); +int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel 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); +imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel sel); +int imx_media_enum_mbus_format(u32 *code, u32 index, enum imx_pixfmt_sel 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); +imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel sel); +int imx_media_enum_ipu_format(u32 *code, u32 index, enum imx_pixfmt_sel 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..bffc0d7588b1 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); + PIXFMT_SEL_ANY); break; case IMX7_CSI_PAD_SRC: if (code->index != 0) { @@ -1019,7 +1019,8 @@ 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); + in_cc = imx_media_find_mbus_format(in_fmt->code, + PIXFMT_SEL_ANY); sdformat->format.width = in_fmt->width; sdformat->format.height = in_fmt->height; @@ -1034,10 +1035,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); + PIXFMT_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); - *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); + imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_ANY); + *cc = imx_media_find_mbus_format(code, PIXFMT_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } From patchwork Sat Apr 4 22:41:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474489 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 6BF8A912 for ; Sat, 4 Apr 2020 22:41:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4AE7D206CC for ; Sat, 4 Apr 2020 22:41:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="YBqz+f2g" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726407AbgDDWls (ORCPT ); Sat, 4 Apr 2020 18:41:48 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:54259 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbgDDWls (ORCPT ); Sat, 4 Apr 2020 18:41:48 -0400 Received: by mail-pj1-f66.google.com with SMTP id l36so4777115pjb.3 for ; Sat, 04 Apr 2020 15:41:47 -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=EcTDLFhvGpvi6g8cUCv+01OFktX8xLdGrm4JHbsNcWY=; b=YBqz+f2gsGcI3B2HE/Kpwn9jV/s40rTHCn1QsndGnOzOwr4NJ5Y+9mpwV1ngRrxHYa P698uA92gFWvFIb13cIt2EBfiFGFvut9gbUN0+HOFP3TWtLNiBnFP+E+gw93CJ1ixm9j TyEM4XTtDRJddxhbVJ3vPDRWLnF9A6sqW7phnwBequM1b+tQe+RXFR3LH5PQvUPCbzyJ SphpZkWv1m9vUY8KTb+O+0XV58nmKYScl3MjECXw4xuc2mkDQnFxKepLinziKFvSsmcq WAD402gEXuomltycW3L2o/mQt0J2EqDO5uxvnJ9+MEQRmt2/GpFfX+RgeMdmHZ+i6+lw zjkQ== 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=EcTDLFhvGpvi6g8cUCv+01OFktX8xLdGrm4JHbsNcWY=; b=slgMsTjLAJ97trXqonQzJ1d2+VIuR/Cr+p0803p67cSTLPuZ3P4mTFBfjGsiPIiJFU UBaP7wUWAiuiUrK4C7Eh8A+QMkaC4fAyv+uhN0/sS9Wr2hK+TToXhZ0kAMksSAAhNuvn 4JxZwpqT0l68sUCtkSnKU28jMett3clGypB8e/deSY80yB2tNj4XlRLW/giLgTPXgCnC H503oXslnCg5vp1Wva88Nwx+Tr/ROkUKYgY8OrT8mq460xfBxvSXBOPOgM48pbZITBKm NtZuBItpHw+/GBT9T/4VyKv9dEoy7T48eaCrv6UKIdFAajPsXo/IC+/DP2MxCXoIBqcW rZDg== X-Gm-Message-State: AGi0PuZDppmjBECpDqUfzrD8qOcxoyjecDqpHj1EQd1kCD5Flw7uNz6U GcaE2OqAfttJCsXLsXJpGg/Ig4qdqwM= X-Google-Smtp-Source: APiQypIZ4AlkZux17oJrc3OO0Z0wusDGm3aflACFcrcCBcfnFVscfPiv+DWiJ9THE4npQxztaCrRRg== X-Received: by 2002:a17:90a:f0c6:: with SMTP id fa6mr17925897pjb.5.1586040106260; Sat, 04 Apr 2020 15:41:46 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:45 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 06/11] media: imx: utils: Introduce PIXFMT_SEL_IPU Date: Sat, 4 Apr 2020 15:41:25 -0700 Message-Id: <20200404224130.23118-7-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a PIXFMT_SEL_IPU selection flag, to select only the IPU-internal pixel formats, and move the single-entry IPU-internal pixel format arrays into pixel_formats[]. imx_media_find_ipu_format() and imx_media_enum_ipu_format() can now simply call find_format() and enum_format(). The RGB32 format is both an IPU-internal format, and an in-memory format via idmac channels that is supported by the IPUv3 driver, so it appears twice in pixel_formats[], one with ipufmt=false for the in-memory format, and again with ipufmt=true for the IPU-internal format. Signed-off-by: Steve Longerbeam Reviewed-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 118 +++++--------------- drivers/staging/media/imx/imx-media.h | 1 + 2 files changed, 27 insertions(+), 92 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index beaa920d7ac7..873fdcee7d37 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -53,7 +53,13 @@ static const struct imx_media_pixfmt pixel_formats[] = { .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, .planar = true, - }, + }, { + .fourcc = V4L2_PIX_FMT_YUV32, + .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, + .cs = IPUV3_COLORSPACE_YUV, + .bpp = 32, + .ipufmt = true, + }, /*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565, @@ -73,6 +79,11 @@ static const struct imx_media_pixfmt pixel_formats[] = { .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, }, { .fourcc = V4L2_PIX_FMT_XRGB32, .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, @@ -186,42 +197,24 @@ 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 imx_pixfmt_sel fmt_sel, bool allow_non_mbus) { + bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; unsigned int i; + fmt_sel &= ~PIXFMT_SEL_IPU; + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { const struct imx_media_pixfmt *fmt = &pixel_formats[i]; enum imx_pixfmt_sel sel; unsigned int j; + if (sel_ipu != fmt->ipufmt) + continue; + sel = fmt->bayer ? PIXFMT_SEL_BAYER : ((fmt->cs == IPUV3_COLORSPACE_YUV) ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); @@ -249,13 +242,19 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, enum imx_pixfmt_sel fmt_sel, bool allow_non_mbus) { + bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; unsigned int i; + fmt_sel &= ~PIXFMT_SEL_IPU; + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { const struct imx_media_pixfmt *fmt = &pixel_formats[i]; enum imx_pixfmt_sel sel; unsigned int j; + if (sel_ipu != fmt->ipufmt) + continue; + sel = fmt->bayer ? PIXFMT_SEL_BAYER : ((fmt->cs == IPUV3_COLORSPACE_YUV) ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); @@ -317,79 +316,14 @@ EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); const struct imx_media_pixfmt * imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel) { - const struct imx_media_pixfmt *array, *fmt, *ret = NULL; - u32 array_size; - int i, j; - - fmt_sel &= ~PIXFMT_SEL_BAYER; - - switch (fmt_sel) { - case PIXFMT_SEL_YUV: - array_size = NUM_IPU_YUV_FORMATS; - array = ipu_yuv_formats; - break; - case PIXFMT_SEL_RGB: - array_size = NUM_IPU_RGB_FORMATS; - array = ipu_rgb_formats; - break; - case PIXFMT_SEL_YUV_RGB: - array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS; - array = ipu_yuv_formats; - break; - default: - return NULL; - } - - for (i = 0; i < array_size; i++) { - if (fmt_sel == PIXFMT_SEL_YUV_RGB && i >= NUM_IPU_YUV_FORMATS) - fmt = &ipu_rgb_formats[i - NUM_IPU_YUV_FORMATS]; - else - fmt = &array[i]; - - for (j = 0; code && fmt->codes[j]; j++) { - if (code == fmt->codes[j]) { - ret = fmt; - goto out; - } - } - } - -out: - return ret; + return find_format(0, code, fmt_sel | PIXFMT_SEL_IPU, false); } EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); int imx_media_enum_ipu_format(u32 *code, u32 index, enum imx_pixfmt_sel fmt_sel) { - fmt_sel &= ~PIXFMT_SEL_BAYER; - - switch (fmt_sel) { - case PIXFMT_SEL_YUV: - if (index >= NUM_IPU_YUV_FORMATS) - return -EINVAL; - *code = ipu_yuv_formats[index].codes[0]; - break; - case PIXFMT_SEL_RGB: - if (index >= NUM_IPU_RGB_FORMATS) - return -EINVAL; - *code = ipu_rgb_formats[index].codes[0]; - break; - case PIXFMT_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]; - } - break; - default: - return -EINVAL; - } - - return 0; + return enum_format(NULL, code, index, fmt_sel | PIXFMT_SEL_IPU, false); } EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format); diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index ac7c521d8148..c61592750729 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -83,6 +83,7 @@ enum imx_pixfmt_sel { PIXFMT_SEL_YUV = BIT(0), /* select YUV formats */ PIXFMT_SEL_RGB = BIT(1), /* select RGB formats */ PIXFMT_SEL_BAYER = BIT(2), /* select BAYER formats */ + PIXFMT_SEL_IPU = BIT(3), /* select IPU-internal formats */ PIXFMT_SEL_YUV_RGB = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB, PIXFMT_SEL_ANY = PIXFMT_SEL_YUV | PIXFMT_SEL_RGB | PIXFMT_SEL_BAYER, }; From patchwork Sat Apr 4 22:41:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474491 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 B75A7912 for ; Sat, 4 Apr 2020 22:41:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 82E4620709 for ; Sat, 4 Apr 2020 22:41:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iPTOMHwR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbgDDWlu (ORCPT ); Sat, 4 Apr 2020 18:41:50 -0400 Received: from mail-pj1-f68.google.com ([209.85.216.68]:54386 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726334AbgDDWlu (ORCPT ); Sat, 4 Apr 2020 18:41:50 -0400 Received: by mail-pj1-f68.google.com with SMTP id np9so4774318pjb.4 for ; Sat, 04 Apr 2020 15:41:48 -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=+gRbj1EwQ2AuAigFe2j8F+9sCnMZ/tJQWs+Wu7BH92E=; b=iPTOMHwROIXuqqLxyHOoHqlvU/UspVXo+qWOtpNH8QO4bSAJ2cZf+rTWbG3ucT9yO0 ucz2n16JhOxYkD5g7A+L2Qifl3v1Oxk1GrlD/CHYrf1eeC69w7P8kmajAC2liwQPe25c ALxikCP4OSpo8QOMMFPObmDUg9js1wWQoz/rz8z6jNohP3sTlPDlirjRoq1LlX9D/MR2 hAufhf1rERsSSjMFYqNSzo82gcoBWUowM12OD/SBLu9nkNc3YEGd8kMPnicDrG7LZ/aa ySVKp3fIMvbEdG04rgy2zT6rFSs8xKZ1iuXnO4bdpoSlg+D3XCNiNvR+WmuJ8f6AjZ7g HNgQ== 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=+gRbj1EwQ2AuAigFe2j8F+9sCnMZ/tJQWs+Wu7BH92E=; b=asdZm2P/QPTffz1+zxRQkYJdaDqr4wkJp9t3WDKLxvk5wfWDXuZIh5u9X+zO9ICCNF K3JurMVjEIEfbfueYh3li40Ll67R3uDMaxhLsTH6ZDF+KSqAZAOq5lt5SUfTki3xXFiI R4F6bWrEXTNCIEUjsMTF3POXaziVWC5us6Se0EOZdp6el7FcP3x24Uy+lyacSs8/9oeN Wsn1sDG8PwDZirpl3KaBLFaJtsOSE1kuBs97dUJPha+v49qwo60gE4IGbnzaGubEiLdc FtOzqlRJqgOvj4tiLP4Z3sjgPykbEBnDdJX5rEjRBIdW2dnf2qNYx/atYIJrxufrI3Om Inqg== X-Gm-Message-State: AGi0PuYjdL7b4HHJcxXyQHP9Z+IHqQnU9y3JiixRHwhuv9hFoBT46aC/ AzYUrTwUQfbCRLS24WT1vndEFvwMQPU= X-Google-Smtp-Source: APiQypJlaGI8k6R/+R+N/K2kTqfU6hD9Q6NqP7aJur6EvV751hv+tMZe/MuhPeJY1XfsgMk9J2lzXA== X-Received: by 2002:a17:90a:3783:: with SMTP id v3mr18547225pjb.31.1586040107529; Sat, 04 Apr 2020 15:41:47 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:46 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 07/11] media: imx: utils: Make imx_media_pixfmt handle variable number of codes Date: Sat, 4 Apr 2020 15:41:26 -0700 Message-Id: <20200404224130.23118-8-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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 include 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 element. This mechanism is fragile, as demonstrated by several instances of the structure containing 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 [Fixed a NULL deref of the codes pointer in a couple places] [Added more comments for the struct imx_media_pixfmt members, includung a bold NOTE! for future developers that codes pointer is NULL for the in-memory-only formats] Signed-off-by: Steve Longerbeam Reviewed-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-capture.c | 4 +- drivers/staging/media/imx/imx-media-utils.c | 74 ++++++++++--------- drivers/staging/media/imx/imx-media.h | 7 +- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index ac48cbe35323..32d5b05097a9 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -95,7 +95,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, if (!cc) return -EINVAL; - fse.code = cc->codes[0]; + fse.code = cc->codes ? cc->codes[0] : 0; ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_size, NULL, &fse); if (ret) @@ -137,7 +137,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, if (!cc) return -EINVAL; - fie.code = cc->codes[0]; + fie.code = cc->codes ? cc->codes[0] : 0; ret = v4l2_subdev_call(priv->src_sd, pad, enum_frame_interval, NULL, &fie); diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 873fdcee7d37..bd8ebbf0b26d 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -7,6 +7,8 @@ #include #include "imx-media.h" +#define IMX_BUS_FMTS(fmt...) (const u32[]) {fmt, 0} + /* * List of supported pixel formats for the subdevs. */ @@ -14,18 +16,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, }, { @@ -55,7 +57,7 @@ static const struct imx_media_pixfmt pixel_formats[] = { .planar = true, }, { .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, @@ -63,16 +65,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, }, { @@ -81,12 +83,12 @@ 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, }, { .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, @@ -106,91 +108,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, @@ -220,16 +222,16 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); if (!(fmt_sel & 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; } @@ -260,7 +262,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes[0])) + (!allow_non_mbus && !fmt->codes)) continue; if (fourcc && index == 0) { @@ -273,7 +275,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; @@ -529,7 +531,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, PIXFMT_SEL_ANY); - if (!fmt) + if (!fmt || !fmt->codes || !fmt->codes[0]) return -EINVAL; memset(mbus, 0, sizeof(*mbus)); diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index c61592750729..459ec15bcdaf 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -68,8 +68,13 @@ enum { #define IMX_MEDIA_EOF_TIMEOUT 1000 struct imx_media_pixfmt { + /* the in-memory FourCC pixel format */ u32 fourcc; - u32 codes[4]; + /* + * the set of equivalent media bus codes for the fourcc. + * NOTE! codes pointer is NULL for in-memory-only formats. + */ + const u32 *codes; int bpp; /* total bpp */ /* cycles per pixel for generic (bayer) formats for the parallel bus */ int cycles; From patchwork Sat Apr 4 22:41:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474493 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 E1B7E159A for ; Sat, 4 Apr 2020 22:41:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0DA920709 for ; Sat, 4 Apr 2020 22:41:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DygPbOgI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726420AbgDDWlv (ORCPT ); Sat, 4 Apr 2020 18:41:51 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46438 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbgDDWlu (ORCPT ); Sat, 4 Apr 2020 18:41:50 -0400 Received: by mail-pf1-f194.google.com with SMTP id q3so5537197pff.13 for ; Sat, 04 Apr 2020 15:41:49 -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=9ab691Q0eg7P5uD9OBbEfp0PkghC2D9TBmGEsQ+98EA=; b=DygPbOgIpS5ctd6ZJKexodNBtQwla2vQpTOmgQ2lUNGNxI2NEN4wdwRheaOjRAgTew lliMTmZFYkMbEJGjN9tBdxvGZ1ZCLORyTi90h2Fml/600QFbw4lKYMYaSS8ovXBNOHeG 8tc0zVQ5e7IybPA5mcA9/SQL0sxlVGuPr69d/xb2QFnYqN4tpXDNuTCfzw8RiWE9ZAwz uYxskI2rsyL/bDI3LBvm3o1Fi+2SLp0kHIpaNHZ7rlqH+2NZT7nIWQMJI6p40veLMDWO bXI9dQPrRj13txt0zfTrtdFQn6/9DD8PR+LzFoYGxF51vIyHrEuuhFCZrHnrvruHw7KY 8hnQ== 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=9ab691Q0eg7P5uD9OBbEfp0PkghC2D9TBmGEsQ+98EA=; b=B5UnPZlU4JcBZ5/ybIh/4BgK8J7jxwwku3B7EitIpTg9vsxnmQ23oR4Ce+fbFza+vD lN42hpCIogboXRUS/XRylPPsdd0vfx0e2lkCCj/W2x2JJUNlzdxS6iVXEBWjJCXwohc8 R2tJxFx6orlF3uIGYGBFndJPALu/NhxcgTr+whIv/B+JEo/tr6nwlAJ6nre6b2jUypxb nAeY2dIKKOPBdDmTtaDqNcInt8RASjwp5QqVfC3FZWJKAjFZxEBf3WwFddbgZF3234ye ywEbJeJy7Lp7r/rG4uzGMYOXcppwSdB7TDmuA9P67dDcfskHN31Z5audeCHLEMT3yPSV WQiA== X-Gm-Message-State: AGi0PuYwyTG9dRLYFXax8W+a2LPBmQjPjLuq4ysOa9eCpkq5ArYs3oXi ETbUhmEGjDCjHfgQ+cXKCp1jLv2ndfU= X-Google-Smtp-Source: APiQypK4yXMzxBub74B7JLkcpGIuI/SO1Ns4UGrrN149kqPONZNppT4jboGoTLIYaA1DbpMtCS37tQ== X-Received: by 2002:a63:741b:: with SMTP id p27mr14518731pgc.68.1586040108712; Sat, 04 Apr 2020 15:41:48 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:48 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 08/11] media: imx: utils: Split find|enum_format into fourcc and mbus functions Date: Sat, 4 Apr 2020 15:41:27 -0700 Message-Id: <20200404224130.23118-9-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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, and inline find_format() into the exported functions imx_media_find_format() and imx_media_find_mbus_format(). Do the equivalent for enum_format(). Also add comment blocks for the exported find|enum functions. Signed-off-by: Steve Longerbeam Reviewed-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 148 +++++++++++++------- 1 file changed, 100 insertions(+), 48 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index bd8ebbf0b26d..a18d826996d1 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -199,10 +199,15 @@ static const struct imx_media_pixfmt pixel_formats[] = { }, }; -static const struct imx_media_pixfmt *find_format(u32 fourcc, - u32 code, - enum imx_pixfmt_sel fmt_sel, - bool allow_non_mbus) +/* + * Search for and return an entry in the pixel_formats[] array that matches + * the requested selection criteria. + * + * @fourcc: Search for an entry with the given fourcc pixel format. + * @fmt_sel: Allow entries only with the given selection criteria. + */ +const struct imx_media_pixfmt * +imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel) { bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; unsigned int i; @@ -212,7 +217,6 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { const struct imx_media_pixfmt *fmt = &pixel_formats[i]; enum imx_pixfmt_sel sel; - unsigned int j; if (sel_ipu != fmt->ipufmt) continue; @@ -221,14 +225,42 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); - if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes)) + if ((fmt_sel & sel) && fmt->fourcc == fourcc) + return fmt; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(imx_media_find_format); + +/* + * Search for and return an entry in the pixel_formats[] array that matches + * the requested selection criteria. + * + * @code: Search for an entry with the given media-bus code. + * @fmt_sel: Allow entries only with the given selection criteria. + */ +const struct imx_media_pixfmt * +imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel fmt_sel) +{ + bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; + unsigned int i; + + fmt_sel &= ~PIXFMT_SEL_IPU; + + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { + const struct imx_media_pixfmt *fmt = &pixel_formats[i]; + enum imx_pixfmt_sel sel; + unsigned int j; + + if (sel_ipu != fmt->ipufmt) continue; - if (fourcc && fmt->fourcc == fourcc) - return fmt; + sel = fmt->bayer ? PIXFMT_SEL_BAYER : + ((fmt->cs == IPUV3_COLORSPACE_YUV) ? + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); - if (!code || !fmt->codes) + if (!(fmt_sel & sel) || !fmt->codes) continue; for (j = 0; fmt->codes[j]; j++) { @@ -239,10 +271,21 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, return NULL; } +EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); -static int enum_format(u32 *fourcc, u32 *code, u32 index, - enum imx_pixfmt_sel fmt_sel, - bool allow_non_mbus) +/* + * Enumerate entries in the pixel_formats[] array that match the + * requested selection criteria. Returns the fourcc that matches the + * selection 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. + * @fmt_sel: Include in the enumeration entries with the given selection + * criteria. + */ +int imx_media_enum_format(u32 *fourcc, u32 index, + enum imx_pixfmt_sel fmt_sel) { bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; unsigned int i; @@ -252,7 +295,6 @@ 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 imx_pixfmt_sel sel; - unsigned int j; if (sel_ipu != fmt->ipufmt) continue; @@ -261,19 +303,54 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); - if (!(fmt_sel & sel) || - (!allow_non_mbus && !fmt->codes)) + if (!(fmt_sel & 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_format); + +/* + * 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. + * @fmt_sel: Include in the enumeration entries with the given selection + * criteria. + */ +int imx_media_enum_mbus_format(u32 *code, u32 index, + enum imx_pixfmt_sel fmt_sel) +{ + bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; + unsigned int i; + + fmt_sel &= ~PIXFMT_SEL_IPU; + + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { + const struct imx_media_pixfmt *fmt = &pixel_formats[i]; + enum imx_pixfmt_sel sel; + unsigned int j; + + if (sel_ipu != fmt->ipufmt) + continue; + + sel = fmt->bayer ? PIXFMT_SEL_BAYER : + ((fmt->cs == IPUV3_COLORSPACE_YUV) ? + PIXFMT_SEL_YUV : PIXFMT_SEL_RGB); + + if (!(fmt_sel & sel) || !fmt->codes) continue; - } for (j = 0; fmt->codes[j]; j++) { if (index == 0) { @@ -287,45 +364,20 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, return -EINVAL; } - -const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel) -{ - return find_format(fourcc, 0, fmt_sel, true); -} -EXPORT_SYMBOL_GPL(imx_media_find_format); - -int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel fmt_sel) -{ - return enum_format(fourcc, NULL, index, fmt_sel, true); -} -EXPORT_SYMBOL_GPL(imx_media_enum_format); - -const struct imx_media_pixfmt * -imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel fmt_sel) -{ - return find_format(0, code, fmt_sel, false); -} -EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); - -int imx_media_enum_mbus_format(u32 *code, u32 index, - enum imx_pixfmt_sel fmt_sel) -{ - return enum_format(NULL, code, index, fmt_sel, false); -} EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); const struct imx_media_pixfmt * imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel) { - return find_format(0, code, fmt_sel | PIXFMT_SEL_IPU, false); + return imx_media_find_mbus_format(code, fmt_sel | PIXFMT_SEL_IPU); } EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); int imx_media_enum_ipu_format(u32 *code, u32 index, enum imx_pixfmt_sel fmt_sel) { - return enum_format(NULL, code, index, fmt_sel | PIXFMT_SEL_IPU, false); + return imx_media_enum_mbus_format(code, index, + fmt_sel | PIXFMT_SEL_IPU); } EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format); From patchwork Sat Apr 4 22:41:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474495 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 21AFF912 for ; Sat, 4 Apr 2020 22:41:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1DFE2071C for ; Sat, 4 Apr 2020 22:41:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SbNxtQ4w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726426AbgDDWlw (ORCPT ); Sat, 4 Apr 2020 18:41:52 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:32911 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbgDDWlw (ORCPT ); Sat, 4 Apr 2020 18:41:52 -0400 Received: by mail-pg1-f193.google.com with SMTP id d17so5564272pgo.0 for ; Sat, 04 Apr 2020 15:41:51 -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=clGD2QDr97AF3QsGLBXiX8qnz+V+UWP1JhkG4nbI/yk=; b=SbNxtQ4wfYheY0FNaf1O7UevVQyD2Swuz8GPw3DWBqG0dyB5rT+VBL62/F/MCgZ5R0 6Pn9iNVBCAmm3mhiWR20WqDJNV6q/AW3HI1BDEuTN4fEro36Msl8wnHwBmRSERGiNQqQ 3HVjbTZ6DitYBDOMfQstzkniwTqZ7Xi2q9mnvMhPGYTqPDB6qtqd1VzxPdjGILXGNMQN Khwv2jKVjwddeJhzxXpDBJkaJIPnrqIzM4LHHUH3osEQ8mpQO8HyRugy9yDZGpI7C1T4 YTqy4fihMhRnSv326nqz4/8MWx0+2snnvCvmn2Yt4ZUACbVQh0IX3mFa8JZdn78GbT50 +VHA== 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=clGD2QDr97AF3QsGLBXiX8qnz+V+UWP1JhkG4nbI/yk=; b=haTwdDCTnokdzPkJNBvcwsJXEUNK8IC9UxtCCzBR56hj6TlDlNA07kFQtWWAhbfFae P476MHWLWYsmYRFLSEpzPddR2/R7Mbe8GMRYWoMeniP7ynJ3MDIRN0wH55zjUL9HS7gt 6IgxIJ2YoOzElbWBwFUerxNm5/crKfU6ecdRXM4ircFWAK7GFRgCN0Pcotjo5ujlaPsz /LQBbDb7t5K+JAeRRIz7X0lkSUJrhc+98FQ1S9KNddyBiPas2uF5RiR4aqZyNhEMfkFS 8hwZqwqaCOUJTsM2nOLs4o0Im9OB0uTYtNawHX+eg3eWzyEjhzO+aEs9J3tfFe2n9Ggn RU3g== X-Gm-Message-State: AGi0PuaffR51AYBHTgfP3hjW1roOZ9QYwShBPoKcVcAFulstb9+oEibZ piTQwfWCA9W3R07MhKb2fcyO29iTagQ= X-Google-Smtp-Source: APiQypJ+wT3ecd54spP3LVVD057jFnKU9E9pzQ+0Uzy8/Fk6OEUdqDcbTUaAhh/U9niJceDj5SfWKA== X-Received: by 2002:a63:ef04:: with SMTP id u4mr14529357pgh.292.1586040109956; Sat, 04 Apr 2020 15:41:49 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:49 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 09/11] media: imx: utils: Rename format lookup and enumeration functions Date: Sat, 4 Apr 2020 15:41:28 -0700 Message-Id: <20200404224130.23118-10-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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 | 9 ++--- drivers/staging/media/imx/imx-ic-prpencvf.c | 9 ++--- 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 | 16 ++++----- drivers/staging/media/imx/imx-media-utils.c | 35 ++++++++++--------- drivers/staging/media/imx/imx-media-vdic.c | 8 ++--- drivers/staging/media/imx/imx-media.h | 11 +++--- drivers/staging/media/imx/imx7-media-csi.c | 6 ++-- 9 files changed, 61 insertions(+), 52 deletions(-) diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index 5b0571285939..f7c9e00897be 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, - PIXFMT_SEL_YUV_RGB); + ret = imx_media_enum_ipu_formats(&code->code, code->index, + PIXFMT_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, PIXFMT_SEL_YUV_RGB); if (!cc) { - imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, PIXFMT_SEL_YUV); cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV); sdformat->format.code = cc->codes[0]; } @@ -438,7 +438,8 @@ 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, PIXFMT_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, PIXFMT_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 adf8f9c9130c..9a09cec67829 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, - PIXFMT_SEL_YUV_RGB); + return imx_media_enum_ipu_formats(&code->code, code->index, + PIXFMT_SEL_YUV_RGB); } static int prp_get_fmt(struct v4l2_subdev *sd, @@ -891,7 +891,7 @@ static void prp_try_fmt(struct prp_priv *priv, if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, PIXFMT_SEL_YUV); *cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } @@ -1250,7 +1250,8 @@ static int prp_registered(struct v4l2_subdev *sd) u32 code; /* set a default mbus format */ - imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, PIXFMT_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 32d5b05097a9..6ac9e37a7249 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, PIXFMT_SEL_ANY); + cc = imx_media_find_pixel_format(fsize->pixel_format, PIXFMT_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, PIXFMT_SEL_ANY); + cc = imx_media_find_pixel_format(fival->pixel_format, PIXFMT_SEL_ANY); if (!cc) return -EINVAL; @@ -174,7 +174,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, (cc_src->cs == IPUV3_COLORSPACE_YUV) ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB; - ret = imx_media_enum_format(&fourcc, f->index, fmt_sel); + ret = imx_media_enum_pixel_formats(&fourcc, f->index, fmt_sel); if (ret) return ret; } else { @@ -221,10 +221,10 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, PIXFMT_SEL_YUV : PIXFMT_SEL_RGB; fourcc = f->fmt.pix.pixelformat; - cc = imx_media_find_format(fourcc, fmt_sel); + cc = imx_media_find_pixel_format(fourcc, fmt_sel); if (!cc) { - imx_media_enum_format(&fourcc, 0, fmt_sel); - cc = imx_media_find_format(fourcc, fmt_sel); + imx_media_enum_pixel_formats(&fourcc, 0, fmt_sel); + cc = imx_media_find_pixel_format(fourcc, fmt_sel); } } else { cc_src = imx_media_find_mbus_format(fmt_src->format.code, @@ -793,8 +793,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, - PIXFMT_SEL_ANY); + vdev->cc = imx_media_find_pixel_format(vdev->fmt.fmt.pix.pixelformat, + PIXFMT_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 ddb70da56853..489b6c1529f3 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, PIXFMT_SEL_YUV_RGB); + ret = imx_media_enum_pixel_formats(&fourcc, f->index, + PIXFMT_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 7a8bb28d7eab..75a7daf309bd 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, - PIXFMT_SEL_ANY); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + PIXFMT_SEL_ANY); break; case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_IDMAC: @@ -1260,9 +1260,9 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, (incc->cs == IPUV3_COLORSPACE_YUV) ? PIXFMT_SEL_YUV : PIXFMT_SEL_RGB; - ret = imx_media_enum_ipu_format(&code->code, - code->index, - fmt_sel); + ret = imx_media_enum_ipu_formats(&code->code, + code->index, + fmt_sel); } break; default: @@ -1451,7 +1451,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc = imx_media_find_ipu_format(sdformat->format.code, fmt_sel); if (!*cc) { - imx_media_enum_ipu_format(&code, 0, fmt_sel); + imx_media_enum_ipu_formats(&code, 0, fmt_sel); *cc = imx_media_find_ipu_format(code, fmt_sel); sdformat->format.code = (*cc)->codes[0]; } @@ -1474,7 +1474,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc = imx_media_find_mbus_format(sdformat->format.code, PIXFMT_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_ANY); + imx_media_enum_mbus_formats(&code, 0, PIXFMT_SEL_ANY); *cc = imx_media_find_mbus_format(code, PIXFMT_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } @@ -1761,7 +1761,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, PIXFMT_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, PIXFMT_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 a18d826996d1..c77a0cf5cbc9 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -207,7 +207,7 @@ static const struct imx_media_pixfmt pixel_formats[] = { * @fmt_sel: Allow entries only with the given selection criteria. */ const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel) +imx_media_find_pixel_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel) { bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; unsigned int i; @@ -231,7 +231,7 @@ imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel fmt_sel) return NULL; } -EXPORT_SYMBOL_GPL(imx_media_find_format); +EXPORT_SYMBOL_GPL(imx_media_find_pixel_format); /* * Search for and return an entry in the pixel_formats[] array that matches @@ -284,8 +284,8 @@ EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); * @fmt_sel: Include in the enumeration entries with the given selection * criteria. */ -int imx_media_enum_format(u32 *fourcc, u32 index, - enum imx_pixfmt_sel fmt_sel) +int imx_media_enum_pixel_formats(u32 *fourcc, u32 index, + enum imx_pixfmt_sel fmt_sel) { bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; unsigned int i; @@ -316,7 +316,7 @@ int imx_media_enum_format(u32 *fourcc, u32 index, return -EINVAL; } -EXPORT_SYMBOL_GPL(imx_media_enum_format); +EXPORT_SYMBOL_GPL(imx_media_enum_pixel_formats); /* * Enumerate entries in the pixel_formats[] array that match the @@ -329,8 +329,8 @@ EXPORT_SYMBOL_GPL(imx_media_enum_format); * @fmt_sel: Include in the enumeration entries with the given selection * criteria. */ -int imx_media_enum_mbus_format(u32 *code, u32 index, - enum imx_pixfmt_sel fmt_sel) +int imx_media_enum_mbus_formats(u32 *code, u32 index, + enum imx_pixfmt_sel fmt_sel) { bool sel_ipu = fmt_sel & PIXFMT_SEL_IPU; unsigned int i; @@ -364,7 +364,7 @@ int imx_media_enum_mbus_format(u32 *code, u32 index, return -EINVAL; } -EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); +EXPORT_SYMBOL_GPL(imx_media_enum_mbus_formats); const struct imx_media_pixfmt * imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel) @@ -373,13 +373,13 @@ imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel fmt_sel) } EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); -int imx_media_enum_ipu_format(u32 *code, u32 index, - enum imx_pixfmt_sel fmt_sel) +int imx_media_enum_ipu_formats(u32 *code, u32 index, + enum imx_pixfmt_sel fmt_sel) { - return imx_media_enum_mbus_format(code, index, - fmt_sel | PIXFMT_SEL_IPU); + return imx_media_enum_mbus_formats(code, index, + fmt_sel | PIXFMT_SEL_IPU); } -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, @@ -390,8 +390,10 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->width = width; mbus->height = height; mbus->field = field; + if (code == 0) - imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_YUV); + imx_media_enum_mbus_formats(&code, 0, PIXFMT_SEL_YUV); + lcc = imx_media_find_mbus_format(code, PIXFMT_SEL_ANY); if (!lcc) { lcc = imx_media_find_ipu_format(code, PIXFMT_SEL_ANY); @@ -530,7 +532,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, PIXFMT_SEL_YUV); + imx_media_enum_mbus_formats(&code, 0, PIXFMT_SEL_YUV); cc = imx_media_find_mbus_format(code, PIXFMT_SEL_YUV); } @@ -582,7 +584,8 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, { const struct imx_media_pixfmt *fmt; - fmt = imx_media_find_format(image->pix.pixelformat, PIXFMT_SEL_ANY); + fmt = imx_media_find_pixel_format(image->pix.pixelformat, + PIXFMT_SEL_ANY); if (!fmt || !fmt->codes || !fmt->codes[0]) return -EINVAL; diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c index 9807d578ce89..303b5407fb64 100644 --- a/drivers/staging/media/imx/imx-media-vdic.c +++ b/drivers/staging/media/imx/imx-media-vdic.c @@ -548,8 +548,8 @@ 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, - PIXFMT_SEL_YUV); + return imx_media_enum_ipu_formats(&code->code, code->index, + PIXFMT_SEL_YUV); } static int vdic_get_fmt(struct v4l2_subdev *sd, @@ -589,7 +589,7 @@ static void vdic_try_fmt(struct vdic_priv *priv, if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, PIXFMT_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, PIXFMT_SEL_YUV); *cc = imx_media_find_ipu_format(code, PIXFMT_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } @@ -852,7 +852,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, PIXFMT_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, PIXFMT_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 459ec15bcdaf..24a993b3216b 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -165,14 +165,17 @@ struct imx_media_dev { /* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum imx_pixfmt_sel sel); -int imx_media_enum_format(u32 *fourcc, u32 index, enum imx_pixfmt_sel sel); +imx_media_find_pixel_format(u32 fourcc, enum imx_pixfmt_sel sel); +int imx_media_enum_pixel_formats(u32 *fourcc, u32 index, + enum imx_pixfmt_sel sel); const struct imx_media_pixfmt * imx_media_find_mbus_format(u32 code, enum imx_pixfmt_sel sel); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum imx_pixfmt_sel sel); +int imx_media_enum_mbus_formats(u32 *code, u32 index, + enum imx_pixfmt_sel sel); const struct imx_media_pixfmt * imx_media_find_ipu_format(u32 code, enum imx_pixfmt_sel sel); -int imx_media_enum_ipu_format(u32 *code, u32 index, enum imx_pixfmt_sel sel); +int imx_media_enum_ipu_formats(u32 *code, u32 index, + enum imx_pixfmt_sel 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 bffc0d7588b1..d87e6612ae48 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, - PIXFMT_SEL_ANY); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + PIXFMT_SEL_ANY); break; case IMX7_CSI_PAD_SRC: if (code->index != 0) { @@ -1037,7 +1037,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, *cc = imx_media_find_mbus_format(sdformat->format.code, PIXFMT_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, PIXFMT_SEL_ANY); + imx_media_enum_mbus_formats(&code, 0, PIXFMT_SEL_ANY); *cc = imx_media_find_mbus_format(code, PIXFMT_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } From patchwork Sat Apr 4 22:41:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474499 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 CFBFD913 for ; Sat, 4 Apr 2020 22:41:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AE97220709 for ; Sat, 4 Apr 2020 22:41:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z229zu7p" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726444AbgDDWly (ORCPT ); Sat, 4 Apr 2020 18:41:54 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:37623 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbgDDWly (ORCPT ); Sat, 4 Apr 2020 18:41:54 -0400 Received: by mail-pf1-f196.google.com with SMTP id u65so5571891pfb.4 for ; Sat, 04 Apr 2020 15:41:52 -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=+/VYda9ZgC7JPVkGjZAW3fELwXUs4vVMudsN+klC3Tg=; b=Z229zu7pK9KJqy+g3mq/6kwMbg2ckIXHcXfq3dyMpc46krSEVW/bOnBRgYRLRi9fJE LV86XhthpdlOcdnVXunJEA9gWdlxOZukQS9fI8mrQXYq3qB3XarpEylXyx6beT8jU8bE /QyLvZU9o+aqYVgciy7khdUxDC9KKjsztyyg3lVLYZjHEuv7TABlRCwkKvwlihrNxCp9 O/yP73ACRIx3m3hTuj5Qbreo21VA/g2rY2Wlpsi5bi/fq+On6zNivvlGNl8ZOn/a0Xfk gOtXeZfrxVXpICrMUhi77FSfHQk3Az869uOI0MIzyIxZ/571SUrlsigBfm0qHZc4i/Oq Ol8Q== 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=+/VYda9ZgC7JPVkGjZAW3fELwXUs4vVMudsN+klC3Tg=; b=FimeeKwHMMDFrgQKwx5PnFkTlu8JSLe+Wvr3O3Yav52h9IklZQYQQQvWWKJG+4EqS7 at5S0ctlElEHeLqe51j86fi4NCoztv5H+E44CTfTgWbj2wdFDkqTzYHPqv7N11ic5WT5 SM2uLBbjE8RBfjTMmBlSiKxbz9SA6tQfB/kAuAcRU5+ukG3WW5KaDi4MCPTPm7gCfKCG mnmACkx67hSiDtO461oYapjZvS7HS7dEnkZxGXNsjOGXvWkUmcMQwH+NnH0qHgxYbT/r vA5mcf5WBwi8kGz6aW/GJlNrG3KcUJ34z+eBLniyfXhpIXX2Qdd9/p0pC3lGwfrm1KOD 1boA== X-Gm-Message-State: AGi0PubwszObBvz17Sh3LMJpsjzs7Es0Uo9i4jIRnIGsoPNTH2IedFkl IeIl1nD/+3K0o6ZSfV4XYZVboOFOh8E= X-Google-Smtp-Source: APiQypI8jpuRAfICK8EDUbu1U96k20jGZ9UUB8cl7ulpyRrew2ud/0daA8pZ+SDpeICcTrFnRk1gSQ== X-Received: by 2002:a63:5645:: with SMTP id g5mr15448326pgm.268.1586040111128; Sat, 04 Apr 2020 15:41:51 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:50 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 10/11] media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_* Date: Sat, 4 Apr 2020 15:41:29 -0700 Message-Id: <20200404224130.23118-11-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-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() and imx_media_mbus_fmt_to_ipu_image() functions do not need to modify their mbus argument. Make them const. Signed-off-by: Laurent Pinchart [Constified mbus arg to imx_media_mbus_fmt_to_ipu_image() as well] Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-utils.c | 4 ++-- drivers/staging/media/imx/imx-media.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index c77a0cf5cbc9..b8ee005e4445 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -510,7 +510,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; @@ -562,7 +562,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_pix_fmt); int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image, - struct v4l2_mbus_framefmt *mbus) + const struct v4l2_mbus_framefmt *mbus) { int ret; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 24a993b3216b..c03114a6f6c8 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -184,10 +184,10 @@ 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); + const struct v4l2_mbus_framefmt *mbus); int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, struct ipu_image *image); void imx_media_grp_id_to_sd_name(char *sd_name, int sz, From patchwork Sat Apr 4 22:41:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11474497 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 B1CCB912 for ; Sat, 4 Apr 2020 22:41:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FE4B20709 for ; Sat, 4 Apr 2020 22:41:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zevq47a5" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726443AbgDDWly (ORCPT ); Sat, 4 Apr 2020 18:41:54 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:35222 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726408AbgDDWlx (ORCPT ); Sat, 4 Apr 2020 18:41:53 -0400 Received: by mail-pj1-f65.google.com with SMTP id g9so4749182pjp.0 for ; Sat, 04 Apr 2020 15:41:53 -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=acKMT5mBAUXJL5E/oW3H1v6FNP93v7Ap4h7BIdGPoxM=; b=Zevq47a5M5KQNmjbAb+ibYc6WkIeB3ViNiMIWTnTsz68+ol5llbdxiOJz6EjAh8+Ug Kf5hjHE91ZLcAvO0o70GYORooXOl9XcREtg65tXDw1S/WhPW9KeEb2AFjcbwxGtAeUPN 5OToPDRoocP9t570Ye3e26Q4W0LnI0R0eiPNoxN+hL94dSuqqgtOefbn0njHMRRANXHR 7FhDSXKUBz1aIjzGlEXdfpEZWnlmO5K916cFnn5FTiXf6L5QZIaxpJIQnMjNwnhHTVCK oOowN84Mw9rSbbRvokJicgbz4uHXqZNJ/KsKLulklfmuwiEh9Nt5G8Lb3sk/oWeW4vno nntg== 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=acKMT5mBAUXJL5E/oW3H1v6FNP93v7Ap4h7BIdGPoxM=; b=SaPUC7PspqEtACz2Ao75MHGTUKi43kxfy/ho5ne/sO/HsPUnSdBPK8tJC71sIVlAx1 bsv38bE7GOG5Qf3MIjkQRgbJ7n5k5REeVr6FDhHXTwrecG7Ox2Jis0igWN7HCjTPZgF0 kai+nvOsBSZNVZNv7GulnMyGZ2Ip656Ke9WyRpwRmq2i5lvm5hydCgxhdLzAMpRE5g3G CG62PfKPxV5yjqqwpV9DCwvRTfwNmzGz8bGREGg1LU27fcoFKl8NF81NIyweiICUfUlV 4dYTJ4hmlU1W66Lz4dO0FaGWH35GNTmaECqzQAQF0ovHJrdP6nLqyLNhtyx6Yr7FM+5b XDiA== X-Gm-Message-State: AGi0Puai6YThJPjAAo0NYBfgXwmO31PiUPa3o8v0T2w1WlTPAtvvf4Ag pqx1mdVaSDDpvWUsFC0B1nw+TsJNWiM= X-Google-Smtp-Source: APiQypI8tgYIvxRPxBCUPnnRGjaX70mjGhxOuwji/Q+xN2OaD5Yy92XA8y5os8IoLFJuiS825Z2oFA== X-Received: by 2002:a17:902:598e:: with SMTP id p14mr12988990pli.276.1586040112430; Sat, 04 Apr 2020 15:41:52 -0700 (PDT) Received: from mappy.world.mentorg.com (c-107-3-184-99.hsd1.ca.comcast.net. [107.3.184.99]) by smtp.gmail.com with ESMTPSA id o11sm8690989pjb.18.2020.04.04.15.41.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2020 15:41:51 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH v6 11/11] media: imx: utils: Constify ipu_image argument to imx_media_ipu_image_to_mbus_fmt() Date: Sat, 4 Apr 2020 15:41:30 -0700 Message-Id: <20200404224130.23118-12-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200404224130.23118-1-slongerbeam@gmail.com> References: <20200404224130.23118-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The imx_media_ipu_image_to_mbus_fmt() function doesn't need to modify its ipu_image argument. Make it const. Signed-off-by: Steve Longerbeam Reviewed-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 b8ee005e4445..c00f253976f5 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -580,7 +580,7 @@ int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image, EXPORT_SYMBOL_GPL(imx_media_mbus_fmt_to_ipu_image); int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, - struct ipu_image *image) + const struct ipu_image *image) { const struct imx_media_pixfmt *fmt; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index c03114a6f6c8..af806ecc67a9 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -189,7 +189,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image, const struct v4l2_mbus_framefmt *mbus); int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, - struct ipu_image *image); + const struct ipu_image *image); void imx_media_grp_id_to_sd_name(char *sd_name, int sz, u32 grp_id, int ipu_id); struct v4l2_subdev *