From patchwork Thu Mar 26 19:05:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460815 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 6E6F981 for ; Thu, 26 Mar 2020 19:05:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F49B2076A for ; Thu, 26 Mar 2020 19:05:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XAoR2I+u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727989AbgCZTFx (ORCPT ); Thu, 26 Mar 2020 15:05:53 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37155 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727611AbgCZTFx (ORCPT ); Thu, 26 Mar 2020 15:05:53 -0400 Received: by mail-pl1-f194.google.com with SMTP id x1so2521508plm.4 for ; Thu, 26 Mar 2020 12:05: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 :mime-version:content-transfer-encoding; bh=d56l7K4RFMK3f7UGZXvp+con9YG1dwWpCGo9TcNN64A=; b=XAoR2I+udxYKjhz4hwJW/Q8O+q2tBVtAqUi1EXu1YvmaZyh6Gn0W+xPPaBxPVqWEkj Zbb1hSxIsHhWZrkWiBv5fhPvF7sK7qlrJTM88kWgqcT0db1aXdfzH4GxcOuzKVXehBNy cDxdMYNsMC8u6FeWGcOkzJr+MJ5BNbKzq5mWUbzErwZubKPTIYs/ih0tZ9z2TLbOum1j MgBdROo4QiOp9aSfsLhuNo2aFU2PnSNtde5Zyu+M1L8w73XmI0jDGAtSY5GmwKP9XQkk QoztGUsnKe7iGFR3akK8678OSVSz8XeVjjvWtr8s8+1+LHYfZjVGgKu1rJh1ty5LNGaP c+zw== 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:mime-version:content-transfer-encoding; bh=d56l7K4RFMK3f7UGZXvp+con9YG1dwWpCGo9TcNN64A=; b=UVuiLgq5Zj7fW31cD7RnUoIRmqZFxE7s8M5TftX3MeTF8NdN6mb73kHSZfFyF6aind mtI00EP7O3+LWNdab/5haP1MSpAMbbBx3MGGq34HwEY26wX+vZ11dHlou+IBirKF6K46 6iAlfjZRIhCYyrWZA7t6YpjOVgpRcCN3L9m9+0FVg7LckuqhzpQRpbtSZbURX/oA9mRw 1NJrPHO0wSXHWY5EABt8B1FiQtIFPXCeQ6s/Tlos2483W0jHmMKJpB0BCSb7r3JA2owN 0MFllB2fDhqziPNnb+kmOF9mzlwSOHkJhmfE+JrOYiXuiJCyfIvHDtrbVTDw30ouO6qY V+zg== X-Gm-Message-State: ANhLgQ25D3b6f+PZIRgTzrel3eAykSO4AhFs9FgoDu9JxhbtUL3PR5Zi UTI85mu2zUZ/PvfA9DlEP3wQHQ/SbWo= X-Google-Smtp-Source: ADFU+vu2UaGgdqWnrASesCszLK1o/JiRaxt2JVozeap7KtEnf37Zr7rD1LqwP0v8SpZrIJk/IW5A8g== X-Received: by 2002:a17:90a:1d4:: with SMTP id 20mr1494755pjd.95.1585249551340; Thu, 26 Mar 2020 12:05:51 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:50 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH 01/10] media: imx: utils: fix and simplify pixel format enumeration Date: Thu, 26 Mar 2020 12:05:35 -0700 Message-Id: <20200326190544.16349-2-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-1-slongerbeam@gmail.com> MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Philipp Zabel Merge yuv_formats and rgb_formats into a single array. Always loop over all entries, skipping those that 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. Add comment headers that describe functions find_format() and enum_format() and their arguments. 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) slongerbeam: - Renamed index j in enum_format() to "match_index", which makes it more clear that this is a count of the pixel_formats[] entries that match the requested search criteria. - Fixed compile warnings: drivers/staging/media/imx/imx-media-utils.c: In function ‘find_format’: drivers/staging/media/imx/imx-media-utils.c:232:40: warning: comparison between ‘const enum ipu_color_space’ and ‘enum codespace_sel’ [-Wenum-compare] 232 | if ((cs_sel != CS_SEL_ANY && fmt->cs != cs_sel) || | ^~ Signed-off-by: Philipp Zabel Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-utils.c | 179 ++++++-------------- 1 file changed, 53 insertions(+), 126 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index fae981698c49..8ff175b08836 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; - for (i = 0; i < array_size; i++) { - fmt = &array[i]; + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { + enum codespace_sel fmt_cs_sel; - if ((!allow_non_mbus && !fmt->codes[0]) || + fmt = &pixel_formats[i]; + 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,7 +250,7 @@ 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; } @@ -278,86 +258,33 @@ struct imx_media_pixfmt *__find_format(u32 fourcc, 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; - } -} - static int enum_format(u32 *fourcc, u32 *code, u32 index, enum codespace_sel cs_sel, 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, match_index = 0; - 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]; - } - } - break; - default: - return -EINVAL; + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { + enum codespace_sel fmt_cs_sel; + + fmt = &pixel_formats[i]; + 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 == match_index) + break; + + match_index++; } + if (i == ARRAY_SIZE(pixel_formats)) + return -EINVAL; if (fourcc) *fourcc = fmt->fourcc; From patchwork Thu Mar 26 19:05:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460817 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 AD64C1668 for ; Thu, 26 Mar 2020 19:05:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8E8862073E for ; Thu, 26 Mar 2020 19:05:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hz34vNEg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728236AbgCZTFy (ORCPT ); Thu, 26 Mar 2020 15:05:54 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44650 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726340AbgCZTFx (ORCPT ); Thu, 26 Mar 2020 15:05:53 -0400 Received: by mail-pf1-f195.google.com with SMTP id b72so3249030pfb.11 for ; Thu, 26 Mar 2020 12:05: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=xLYZwd0gwNDf1QrH/c7/diJRH1vhJhsgmlo/bWPVYtg=; b=Hz34vNEgxB4DW6uXh6xREtp3MGrd4Jnwol5impFhnFINRgDBHfGrpXiQi7JiAMbKN3 +orm+L8Webs+v4mQP8qv4XdSMywL9ZRQSM0n7iNkIRHnb5XQmnAeusQvdaUI2wnFJZk/ RYZfa+xApfPRmN9xklDXEPSByR2bUpRt+agay4DwzvIl+tReug9qYwgKutQ6u22B3LDj YQwQJoLBBdI1K0IMZmggrIFsuHbNR1g4B06FeUhElbN15v+KkYdXSRepF2M1oJX6mBad cOxP9T33+IpEnYZuSLkleCuAMG9/K2rKpLSZg84lxtLGdL+wgBtLsXt9bR0nIWI/VAY1 bcCQ== 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=xLYZwd0gwNDf1QrH/c7/diJRH1vhJhsgmlo/bWPVYtg=; b=jaEvtDCJ9NM27UuspROYj0U6AE0p1bsF+2ujOlp+3aOoxmsrPlqvzHN7e5SLXlg1X3 87bYUouvO30d+pUUNVCqI9TG8snhosI3V9pT0fOfcR0RtW9VSFivgb0DzGvjwmCgnmJL +vGAZGnUQ6ce1RSMH8/VmBtCQRvgWUWccQBB3stecM9gqHRSQmlsdQR1NZK5DkX0eaMx JEg5asaSnoYX98/hSMMqn/w8a/vQSxj54zwR/5tVYBGd/9U8snspiXrEpEwXopm4S+Eo JPjHdfWKkz65Ai+B4cibODNvgj5Bk/HAU3QB/JOINJ+iltuHGTop5vQb+CwQQZeXFbkB Ws8w== X-Gm-Message-State: ANhLgQ2sGRXBDDWalwUXlUFrNpuLb9KV4RT8/4bNIWd98GBHrmDQor68 7rG5bhQf/FtyMrUlKvqMCAYO9ED73w0= X-Google-Smtp-Source: ADFU+vtMM2JvBUH+xnlhHsmLqdeKY2sE48wd0bmfzDw+RQX1yGtaUocSu+jkqMTHxjKIr5cEH6ODtQ== X-Received: by 2002:a62:160b:: with SMTP id 11mr193010pfw.189.1585249552107; Thu, 26 Mar 2020 12:05:52 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:51 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH 02/10] media: imx: utils: fix media bus format enumeration Date: Thu, 26 Mar 2020 12:05:36 -0700 Message-Id: <20200326190544.16349-3-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-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 --- drivers/staging/media/imx/imx-media-utils.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 8ff175b08836..97568a6ee101 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -264,7 +264,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, bool allow_bayer) { const struct imx_media_pixfmt *fmt; - unsigned int i, match_index = 0; + unsigned int i, j = 0, match_index = 0; for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { enum codespace_sel fmt_cs_sel; @@ -278,18 +278,29 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, (!allow_bayer && fmt->bayer)) continue; - if (index == match_index) + if (fourcc && index == match_index) break; - match_index++; + if (!code) { + match_index++; + continue; + } + + for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (index == match_index) + goto out; + + match_index++; + } } if (i == ARRAY_SIZE(pixel_formats)) return -EINVAL; +out: if (fourcc) *fourcc = fmt->fourcc; if (code) - *code = fmt->codes[0]; + *code = fmt->codes[j]; return 0; } From patchwork Thu Mar 26 19:05:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460819 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 0626681 for ; Thu, 26 Mar 2020 19:05:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC3CE2076A for ; Thu, 26 Mar 2020 19:05:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="He15aY06" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728326AbgCZTFy (ORCPT ); Thu, 26 Mar 2020 15:05:54 -0400 Received: from mail-pj1-f65.google.com ([209.85.216.65]:40345 "EHLO mail-pj1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727939AbgCZTFy (ORCPT ); Thu, 26 Mar 2020 15:05:54 -0400 Received: by mail-pj1-f65.google.com with SMTP id kx8so2805136pjb.5 for ; Thu, 26 Mar 2020 12:05: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=tBQl4xZ+XPJAC9ZGkbcMqT8sniHRBi+uWgBr2NZSgMs=; b=He15aY06wq+LgwAfoU7gjLRKYVJe1TdnMKM0rDXtG6ZS5D0YyC934bYZAvLHx9U392 8L1pgUF3llXNq3ueCGKxLYkCe+yk6zNWtMiGdUJxF9bWMvYCtW5ibZY+H3PCg6COwMFd qWi/5jpdiyPWdZQ6nL5PZAepLcjISHN4EulzlHoefJh+Unqt22SrS3tALAd73v+N73ce GVZltZt9SRPvc4eE8veOq9kwaRnM2idWktW0yUxCPmPhkwXkkUiUhItRHFdJ0lKsUbGl xuDUXXob59umzMPTVw1q+tDmKt5w3CoeMwtliFU1FRZlcMZLtoh/UFw8ikBiySonm5ee Nt+A== 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=tBQl4xZ+XPJAC9ZGkbcMqT8sniHRBi+uWgBr2NZSgMs=; b=l/dk+wSsqPviqpRFr1/9kZL2GvwO2v+9AMU5N0B4yPD0Sn2c6uhomN65NM43LeiiNO dxurZcaKF3w4Qb8+5nAa7jVUt8xUcCA8kn0rEdOBrampnCTAEe6BIDFRvTYBeuHZP84P NiaV5P7L8i2c3Y21ZFmzeYddWwqb0GaYNVUn1w54bTvhOmVDgkum6DnjZkYWSMUho75v PWMhkYV7F8rFdxA6VOXfVYZ+zMLQqQOspxdaHsW9FzfYpyHivRkR2OPDpxk1RkFEqbGa hzfm8zORU3sIeYn54vV6g2zM3ViPg6qPsqxOjblJRepJYsABgBPcDun104lH2wLHHkjL v20w== X-Gm-Message-State: ANhLgQ16M40Nl9O4JzsdUWAO4ayVEgE6icFrtPLnhpyCHXhzVq48yiZt QFbddnMDBaTqw8NCVChIt8354d17exU= X-Google-Smtp-Source: ADFU+vttTy27nl7FOcZOqnsSGFbZMycrVzBvXxM7BT/lTcqZDnOHnMjBrm63t7k2LnF0kSfgLuXOkA== X-Received: by 2002:a17:90a:198b:: with SMTP id 11mr1661780pji.23.1585249553085; Thu, 26 Mar 2020 12:05:53 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:52 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH 03/10] media: imx: utils: Inline init_mbus_colorimetry() in its caller Date: Thu, 26 Mar 2020 12:05:37 -0700 Message-Id: <20200326190544.16349-4-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-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 97568a6ee101..61fbb64777a2 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, @@ -426,7 +413,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 Thu Mar 26 19:05:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460821 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 5A6D381 for ; Thu, 26 Mar 2020 19:05:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2A24D20719 for ; Thu, 26 Mar 2020 19:05:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZGcqR+EH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728443AbgCZTF4 (ORCPT ); Thu, 26 Mar 2020 15:05:56 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:35627 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728405AbgCZTF4 (ORCPT ); Thu, 26 Mar 2020 15:05:56 -0400 Received: by mail-pf1-f196.google.com with SMTP id u68so3272860pfb.2 for ; Thu, 26 Mar 2020 12:05:55 -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=x364dPl1oMc4RVXt9Wtuqox0p77i8WD6c7U7YvfxeoU=; b=ZGcqR+EH1ZcTsuVmm8Aw2HbWJJgk1U1dUYmAfEdpvPxqusQa18+GDN969pcRNA3Gax lUbdGFqP1g0cPuBXE7Vtsz6MwW91qxJRcPme6jYXDpICXxNIDeIux4UdMVFGNIOlr+A6 V6mN/UWW+GXC+7Lu0zwaNCGSt+p9g6w4q9CvwqwqLp0A+95elHc/xo6lRy+2wXsnQStI VZRsA50xHzwFp/h4jyYppEq6tOPIYKMK9sNFOJWBnQ0IIo0N6G+Nqw0174wzSQUkp50K IJIkf73VnjJRtvoYI8z5mc3kW4b4CnwlkEatkvaWktvuvI1wZMbkJE8O6HQtYyrgQUT4 3MXw== 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=x364dPl1oMc4RVXt9Wtuqox0p77i8WD6c7U7YvfxeoU=; b=tX0iMtiXSmdcULiGM0R8qCmXzJbTgpiZU5yJNRyeO1sQHJCEwCCoP/pG7xl0PhkDC9 CZMii5CtkcCquKh4PkI+53VoaL2JLCd1uFRp7iptNa8w9ReNpqlPgSPSzZXdUBqci9VN oVQ3INWnpktQvtwnDEHOPxrMeScYIxYxT//de67GTVmjazrbtYGmtHW85WbtmIuSsHXZ sK8xeWlwBVWwNorln9s3jSk2+vor6rmh3QtJ/uRAX0SbiODZ9LZzpmSl4JCXh5+rpC2Z /e8GnLEhIqJdvXBCd9h9x4VTDrislJbfgIEahQzE8amxkQ7Aw5rB4qkzMHxVjxWnE5vb DHxA== X-Gm-Message-State: ANhLgQ30dHn/RbXV4e9EMGchFRmfdXiXzGFiGLnGolKd1pKOMgCXN5uh 00811wgw2e2ds8e0pdw5+kdvCWjviAg= X-Google-Smtp-Source: ADFU+vvq6vdnF9dwsMJidfzKzEdpPjKopwfapoJctLWc7i8wOTx7nfjZ/Z0CfEB/Sz68WoicGHyu4g== X-Received: by 2002:a63:ce42:: with SMTP id r2mr10563680pgi.106.1585249554108; Thu, 26 Mar 2020 12:05:54 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:53 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH 04/10] media: imx: utils: Handle Bayer format lookup through a selection flag Date: Thu, 26 Mar 2020 12:05:38 -0700 Message-Id: <20200326190544.16349-5-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-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. slongerbeam: - The original patch declared CS_SEL_ANY as a bitfield containing only CS_SEL_YUV | CS_SEL_RGB. It makes more sense to declare CS_SEL_ANY as all of the above (YUV, RGB, BAYER). A new enum is also 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: Laurent Pinchart 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 61fbb64777a2..334c9670e481 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) { const struct imx_media_pixfmt *fmt; int i, j; @@ -223,12 +222,12 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, enum codespace_sel fmt_cs_sel; fmt = &pixel_formats[i]; - 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) @@ -247,8 +246,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) { const struct imx_media_pixfmt *fmt; unsigned int i, j = 0, match_index = 0; @@ -257,12 +255,12 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, enum codespace_sel fmt_cs_sel; fmt = &pixel_formats[i]; - 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 == match_index) @@ -293,30 +291,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); @@ -327,6 +323,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; @@ -336,7 +334,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; @@ -345,7 +343,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]; @@ -365,6 +363,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) @@ -376,7 +376,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) { @@ -404,8 +404,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) @@ -476,7 +476,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) @@ -530,8 +530,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; } @@ -543,8 +543,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 */ @@ -595,7 +595,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 Thu Mar 26 19:05:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460823 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 D579881 for ; Thu, 26 Mar 2020 19:05:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC9902073E for ; Thu, 26 Mar 2020 19:05:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QUtE79rt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728524AbgCZTF6 (ORCPT ); Thu, 26 Mar 2020 15:05:58 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46300 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728405AbgCZTF5 (ORCPT ); Thu, 26 Mar 2020 15:05:57 -0400 Received: by mail-pg1-f193.google.com with SMTP id k191so3361787pgc.13 for ; Thu, 26 Mar 2020 12:05:55 -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=PYb7LeVvOeL2a6oZQDOdPyF6X+hLJ7m1n6ZrjzCa1kg=; b=QUtE79rtONvO/YU0AAIhDWrTWTIkd2Fgu1RrCkOVhsQ0uOtElmNc+8t95IMShtiPMx YkIbln5880fXu0p6cUN6Pga1ogt5dSQfxJP39qFlpJwbpEWMHdRwOvLKTQeTWVH3P3Is RrVB4SdffkfB28ad296peGe4RUoGR9lo0A484VIkvj4yaS845ECP0NXQwsDA9gASCWGX Zz4xodshT3GPUrfbd5X1oeXg7ESTD0v70a5XJVEQnPQlkqbBYYtr9X9Kb5zsID9bFbO2 tpS0v2XBXaFPuJnDIEZoifwiPP9EIBz5258t50uuLLSUis27G+kCR7fP2KfiKavqtGLi j/zQ== 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=PYb7LeVvOeL2a6oZQDOdPyF6X+hLJ7m1n6ZrjzCa1kg=; b=Uk7XIti4Y71JCze22gaX7H6TTICP9hK4YvXxCNNKXzKf+ed6FEXCNGA7Bnc276e/0O uAElzpgu5BKSAxixA06OnKxJ6Y9vNHurXEcOSvEaEPo3zw7wyheE5HkyTxfeO7Qv1GzF KBLCnek8eGBBp3PmjYIHwVuZgniDRqewb5F9kM89YJ4iZ5hvPpCLaEyCnpaFbNvAKssJ gkszONSh9CLBNYuUIElcRM6uyGM+ID1dBnLiN8yVHvfc2UP4WsnyaeTsOZvIw9xNLtXD b8aKpwUecEGRvkCr9PIf/M9IY8ufE97eeh+Wv39q60pcwxsjg9C1uTPluLCCMnWMPYBT RyQw== X-Gm-Message-State: ANhLgQ1CjSJI9jkeuL0ngICPO9mHSiv+tIl+IL0H98k5ZTFI2a1wyr+p odQ/B8fSQ4yJRhoIeg42esMsKqi4jNQ= X-Google-Smtp-Source: ADFU+vslWKyrkWJp08MnSi68nkLL2dbYNjt5GCJuxKMIjzsAdI65q7mKO1qecy8Rlvd8ht2eB2tN0Q== X-Received: by 2002:a63:798a:: with SMTP id u132mr10410681pgc.203.1585249554963; Thu, 26 Mar 2020 12:05:54 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:54 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH 05/10] media: imx: utils: Simplify IPU format lookup and enumeration Date: Thu, 26 Mar 2020 12:05:39 -0700 Message-Id: <20200326190544.16349-6-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart The IPU formats are stored in two separate tables, one for YUV and one for RGB formats. This complicates the lookup and enumeration function without really increasing efficiency, as both tables contain a single element. Merge the two tables and simplify the functions, and move the resulting table next to the functions that use it. slongerbeam: - imx_media_enum_ipu_format() has been modified slightly to make use of a local match_index to compare with the requested index, to be consistent with the other format enumeration functions. Signed-off-by: Laurent Pinchart Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-utils.c | 132 ++++++++------------ 1 file changed, 52 insertions(+), 80 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index 334c9670e481..d27787012ff3 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -186,30 +186,6 @@ static const struct imx_media_pixfmt pixel_formats[] = { }, }; -static const struct imx_media_pixfmt ipu_yuv_formats[] = { - { - .fourcc = V4L2_PIX_FMT_YUV32, - .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, - .cs = IPUV3_COLORSPACE_YUV, - .bpp = 32, - .ipufmt = true, - }, -}; - -#define NUM_IPU_YUV_FORMATS ARRAY_SIZE(ipu_yuv_formats) - -static const struct imx_media_pixfmt ipu_rgb_formats[] = { - { - .fourcc = V4L2_PIX_FMT_XRGB32, - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, - .cs = IPUV3_COLORSPACE_RGB, - .bpp = 32, - .ipufmt = true, - }, -}; - -#define NUM_IPU_RGB_FORMATS ARRAY_SIZE(ipu_rgb_formats) - static const struct imx_media_pixfmt *find_format(u32 fourcc, u32 code, enum codespace_sel cs_sel, @@ -316,81 +292,77 @@ int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel) } EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); +/* ----------------------------------------------------------------------------- + * IPU Formats Lookup and Enumeration + */ + +static const struct imx_media_pixfmt ipu_formats[] = { + { + .fourcc = V4L2_PIX_FMT_YUV32, + .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, + .cs = IPUV3_COLORSPACE_YUV, + .bpp = 32, + .ipufmt = true, + }, { + .fourcc = V4L2_PIX_FMT_XRGB32, + .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .cs = IPUV3_COLORSPACE_RGB, + .bpp = 32, + .ipufmt = true, + }, +}; + const struct imx_media_pixfmt * imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) { - const struct imx_media_pixfmt *array, *fmt, *ret = NULL; - u32 array_size; - int i, j; - - cs_sel &= ~CS_SEL_BAYER; + bool accept_yuv = cs_sel & CS_SEL_YUV; + bool accept_rgb = cs_sel & CS_SEL_RGB; + unsigned int i, j; - switch (cs_sel) { - case CS_SEL_YUV: - array_size = NUM_IPU_YUV_FORMATS; - array = ipu_yuv_formats; - break; - case CS_SEL_RGB: - array_size = NUM_IPU_RGB_FORMATS; - array = ipu_rgb_formats; - break; - case CS_SEL_YUV_RGB: - array_size = NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS; - array = ipu_yuv_formats; - break; - default: + if (!code) return NULL; - } - for (i = 0; i < array_size; i++) { - if (cs_sel == CS_SEL_YUV_RGB && i >= NUM_IPU_YUV_FORMATS) - fmt = &ipu_rgb_formats[i - NUM_IPU_YUV_FORMATS]; - else - fmt = &array[i]; + for (i = 0; i < ARRAY_SIZE(ipu_formats); i++) { + const struct imx_media_pixfmt *fmt = &ipu_formats[i]; - for (j = 0; code && fmt->codes[j]; j++) { - if (code == fmt->codes[j]) { - ret = fmt; - goto out; - } + if ((!accept_yuv && fmt->cs == IPUV3_COLORSPACE_YUV) || + (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) + continue; + + for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (code == fmt->codes[j]) + return fmt; } } -out: - return ret; + return NULL; } EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) { - cs_sel &= ~CS_SEL_BAYER; + bool accept_yuv = cs_sel & CS_SEL_YUV; + bool accept_rgb = cs_sel & CS_SEL_RGB; + unsigned int i, j = 0, match_index = 0; - switch (cs_sel) { - case CS_SEL_YUV: - if (index >= NUM_IPU_YUV_FORMATS) - return -EINVAL; - *code = ipu_yuv_formats[index].codes[0]; - break; - case CS_SEL_RGB: - if (index >= NUM_IPU_RGB_FORMATS) - return -EINVAL; - *code = ipu_rgb_formats[index].codes[0]; - break; - case CS_SEL_YUV_RGB: - if (index >= NUM_IPU_YUV_FORMATS + NUM_IPU_RGB_FORMATS) - return -EINVAL; - if (index >= NUM_IPU_YUV_FORMATS) { - index -= NUM_IPU_YUV_FORMATS; - *code = ipu_rgb_formats[index].codes[0]; - } else { - *code = ipu_yuv_formats[index].codes[0]; + for (i = 0; i < ARRAY_SIZE(ipu_formats); i++) { + const struct imx_media_pixfmt *fmt = &ipu_formats[i]; + + if ((!accept_yuv && fmt->cs == IPUV3_COLORSPACE_YUV) || + (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) + continue; + + for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (index == match_index) { + *code = fmt->codes[j]; + return 0; + } + + match_index++; } - break; - default: - return -EINVAL; } - return 0; + return -EINVAL; } EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format); From patchwork Thu Mar 26 19:05:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460827 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 3306A81 for ; Thu, 26 Mar 2020 19:06:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A86520658 for ; Thu, 26 Mar 2020 19:06:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ElGOqKwT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728546AbgCZTF7 (ORCPT ); Thu, 26 Mar 2020 15:05:59 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:34605 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727770AbgCZTF6 (ORCPT ); Thu, 26 Mar 2020 15:05:58 -0400 Received: by mail-pf1-f196.google.com with SMTP id 23so3280532pfj.1 for ; Thu, 26 Mar 2020 12:05:56 -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=YAfdVyQGDkm6VWMLTayn65guJF0genzcf3gb/T5u/w4=; b=ElGOqKwTsbqdsz8tYWtpmYT/TVny5bA3xiWswtMTolKj6G+DvpYU3tJXfdM8h7AwKw ThuGeQfcEkhGxCIK/0cIJsSmDl2fd3gBV6I3RArE/dv79w9bxk8i03dN4lqDCnFEJIAV 7bO9KGYXABfn3J6AZbd4gBdesIDZ5SSgDkp73jOQUrJX504w5JftEUU4ABSPnqLb5SaP 1TWrJIV2a/FjcCa5cEPoIWJcg6tyAr20BnNq3gMJIqMaJuFigHPkADUertj/hhwP5cv8 xtk+E1iPNcSdWv4ha2dls9FvUzFAktGzGaqhbdoo7K+9F6dJE+q3+vhpQY7vBBa2FjA/ OpOg== 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=YAfdVyQGDkm6VWMLTayn65guJF0genzcf3gb/T5u/w4=; b=poBJljuVO+tUeYjCaPslH97Lj6swrHFxs1cymei8mwi857t+3gf9MIB9b9dPuklMAz SgOl8AoNnbCUWcW9ZGU84aRlBkREoclOW6RifQjjSlbAHfnzRZTdGovPeOgLZUTEM5J/ kAVfLi3rxbhgA9GUknB/QCkLpwNc0vB3H71t77YFXNUuFckL67M6tV/jciSqr/4o+gAl c8tNfpSnK7C+7ZudD/VLa4fmeWS+9SGEFBivwQBkF8ZrZgGoNYqGMznfSE9lU3WEXJmt tD+oRoduCZF3yLtJAdM9xNCBGCiHAb2mYbdF+VDti0Sa/V1ytwBhM2raWwFClBIBUIMw g2EQ== X-Gm-Message-State: ANhLgQ0HYHzu5qz1SV00cM/XP/yVh9tOapyhL+z4sjMCpgfW3byZw6z0 2fwTnIUPeYWBSM2q+w/oUJbZ+Ln9V7E= X-Google-Smtp-Source: ADFU+vsAXFKZULbPZaZ5pSIGGMLRpV2s6z9Iv5caTiYT/Sm9G1iSJLB/RYXY3PrcfZbXWGTbyGUjZQ== X-Received: by 2002:a63:2360:: with SMTP id u32mr10234253pgm.190.1585249555873; Thu, 26 Mar 2020 12:05:55 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:55 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH 06/10] media: imx: utils: Make imx_media_pixfmt handle variable number of codes Date: Thu, 26 Mar 2020 12:05:40 -0700 Message-Id: <20200326190544.16349-7-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart The imx_media_pixfmt structures includes a codes member that stores media bus codes as a fixed array of 4 integers. The functions dealing with the imx_media_pixfmt structures assume that the array of codes is terminated by a 0 elements. This mechanism is fragile, as demonstrated by several instances of the structure contained 4 non-zero codes. Fix this by turning the array into a pointer, and providing an IMX_BUS_FMTS macro to initialize the codes member with a guaranteed 0 element at the end. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 88 ++++++++++++--------- drivers/staging/media/imx/imx-media.h | 2 +- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index d27787012ff3..febcf3203cb1 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -7,6 +7,12 @@ #include #include "imx-media.h" +#define IMX_BUS_FMTS(fmts...) \ + (const u32[]) { \ + fmts, \ + 0 \ + } + /* * List of supported pixel formats for the subdevs. */ @@ -14,18 +20,18 @@ static const struct imx_media_pixfmt pixel_formats[] = { /*** YUV formats start here ***/ { .fourcc = V4L2_PIX_FMT_UYVY, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_UYVY8_1X16 - }, + ), .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, }, { .fourcc = V4L2_PIX_FMT_YUYV, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_YUYV8_2X8, MEDIA_BUS_FMT_YUYV8_1X16 - }, + ), .cs = IPUV3_COLORSPACE_YUV, .bpp = 16, }, { @@ -57,16 +63,16 @@ static const struct imx_media_pixfmt pixel_formats[] = { /*** RGB formats start here ***/ { .fourcc = V4L2_PIX_FMT_RGB565, - .codes = {MEDIA_BUS_FMT_RGB565_2X8_LE}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_RGB565_2X8_LE), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .cycles = 2, }, { .fourcc = V4L2_PIX_FMT_RGB24, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_RGB888_1X24, MEDIA_BUS_FMT_RGB888_2X12_LE - }, + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 24, }, { @@ -75,7 +81,7 @@ static const struct imx_media_pixfmt pixel_formats[] = { .bpp = 24, }, { .fourcc = V4L2_PIX_FMT_XRGB32, - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32), .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, .ipufmt = true, @@ -95,91 +101,91 @@ static const struct imx_media_pixfmt pixel_formats[] = { /*** raw bayer and grayscale formats start here ***/ { .fourcc = V4L2_PIX_FMT_SBGGR8, - .codes = {MEDIA_BUS_FMT_SBGGR8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG8, - .codes = {MEDIA_BUS_FMT_SGBRG8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG8, - .codes = {MEDIA_BUS_FMT_SGRBG8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB8, - .codes = {MEDIA_BUS_FMT_SRGGB8_1X8}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SBGGR16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SBGGR10_1X10, MEDIA_BUS_FMT_SBGGR12_1X12, MEDIA_BUS_FMT_SBGGR14_1X14, MEDIA_BUS_FMT_SBGGR16_1X16 - }, + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGBRG16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SGBRG10_1X10, MEDIA_BUS_FMT_SGBRG12_1X12, MEDIA_BUS_FMT_SGBRG14_1X14, - MEDIA_BUS_FMT_SGBRG16_1X16, - }, + MEDIA_BUS_FMT_SGBRG16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SGRBG16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SGRBG10_1X10, MEDIA_BUS_FMT_SGRBG12_1X12, MEDIA_BUS_FMT_SGRBG14_1X14, - MEDIA_BUS_FMT_SGRBG16_1X16, - }, + MEDIA_BUS_FMT_SGRBG16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_SRGGB16, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_SRGGB10_1X10, MEDIA_BUS_FMT_SRGGB12_1X12, MEDIA_BUS_FMT_SRGGB14_1X14, - MEDIA_BUS_FMT_SRGGB16_1X16, - }, + MEDIA_BUS_FMT_SRGGB16_1X16 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_GREY, - .codes = { + .codes = IMX_BUS_FMTS( MEDIA_BUS_FMT_Y8_1X8, MEDIA_BUS_FMT_Y10_1X10, - MEDIA_BUS_FMT_Y12_1X12, - }, + MEDIA_BUS_FMT_Y12_1X12 + ), .cs = IPUV3_COLORSPACE_RGB, .bpp = 8, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_Y10, - .codes = {MEDIA_BUS_FMT_Y10_1X10}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, }, { .fourcc = V4L2_PIX_FMT_Y12, - .codes = {MEDIA_BUS_FMT_Y12_1X12}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12), .cs = IPUV3_COLORSPACE_RGB, .bpp = 16, .bayer = true, @@ -203,16 +209,16 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, CS_SEL_YUV : CS_SEL_RGB); if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes[0])) + (!allow_non_mbus && !fmt->codes)) continue; if (fourcc && fmt->fourcc == fourcc) return fmt; - if (!code) + if (!code || !fmt->codes) continue; - for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + for (j = 0; fmt->codes[j]; j++) { if (code == fmt->codes[j]) return fmt; } @@ -236,7 +242,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, CS_SEL_YUV : CS_SEL_RGB); if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes[0])) + (!allow_non_mbus && !fmt->codes)) continue; if (fourcc && index == match_index) @@ -247,7 +253,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; j < fmt->codes[j]; j++) { if (index == match_index) goto out; @@ -261,7 +267,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, if (fourcc) *fourcc = fmt->fourcc; if (code) - *code = fmt->codes[j]; + *code = fmt->codes ? fmt->codes[j] : 0; return 0; } @@ -299,13 +305,13 @@ EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); static const struct imx_media_pixfmt ipu_formats[] = { { .fourcc = V4L2_PIX_FMT_YUV32, - .codes = {MEDIA_BUS_FMT_AYUV8_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_AYUV8_1X32), .cs = IPUV3_COLORSPACE_YUV, .bpp = 32, .ipufmt = true, }, { .fourcc = V4L2_PIX_FMT_XRGB32, - .codes = {MEDIA_BUS_FMT_ARGB8888_1X32}, + .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32), .cs = IPUV3_COLORSPACE_RGB, .bpp = 32, .ipufmt = true, @@ -329,7 +335,10 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) continue; - for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (!fmt->codes) + continue; + + for (j = 0; fmt->codes[j]; j++) { if (code == fmt->codes[j]) return fmt; } @@ -352,7 +361,10 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) (!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB)) continue; - for (j = 0; j < ARRAY_SIZE(fmt->codes) && fmt->codes[j]; j++) { + if (!fmt->codes) + continue; + + for (j = 0; j < fmt->codes[j]; j++) { if (index == match_index) { *code = fmt->codes[j]; return 0; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 652673a703cd..917b4db02985 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -69,7 +69,7 @@ enum { struct imx_media_pixfmt { u32 fourcc; - u32 codes[4]; + const u32 *codes; int bpp; /* total bpp */ /* cycles per pixel for generic (bayer) formats for the parallel bus */ int cycles; From patchwork Thu Mar 26 19:05:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460825 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 5F6041668 for ; Thu, 26 Mar 2020 19:05:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 405D72073E for ; Thu, 26 Mar 2020 19:05:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rAsT0F5G" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728525AbgCZTF6 (ORCPT ); Thu, 26 Mar 2020 15:05:58 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:35630 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728472AbgCZTF6 (ORCPT ); Thu, 26 Mar 2020 15:05:58 -0400 Received: by mail-pf1-f193.google.com with SMTP id u68so3272908pfb.2 for ; Thu, 26 Mar 2020 12:05:57 -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=+TAI0q34gHwmtyXjAoNg4OEwV/YTrpyWg3D0Tzerm6M=; b=rAsT0F5GYrv+5odWrECYA72sISvjJTitnt5qOeDvnCu6YuNn9DaCLbr2FZM8vjrXCb JWRiJxQgnuzyjduVSfx9OGeKeS7g+i3REFTiX7cROBI2aAHJKPmJ+rGdnwQkLiv6OXao a6GPto/OixvAj0U3GJ0Rj7oUuRV+9GazY0yCHxfgqFMjvBxwUF+5MEFS/phJxlmGFQxo IcSReN0+FjOzwEkGhhGCA7DdLyAjrVjO5MinPJk0/eekl48OcEy8R8rPdM3Zz74KRs6b G12OwU16NK1wmgVcJ0eBFrvJpu3vzTf/FwvkYesk/Bpccubix9N2vEL15BRjs1D2OLWP c16g== 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=+TAI0q34gHwmtyXjAoNg4OEwV/YTrpyWg3D0Tzerm6M=; b=jL+r6txubrySmCG+KNa/CN0Rgp0aaulSXrALuY0cx2qho5kwq8jh6xW0+GvgqiXF58 fdIimiiRSSo6UurQOPsI7x4ZU791/0uoDmVa5N7zVQLWshvpJ2D+Eox7xZUkyNg69MkM 1R97Y5zfFQMDmi1ih0KeWjTwrzmGYdR0bPudsbC3p8mbTwbsguOrJGF5xlcqpfkguPSS Ku1kPxPaIsWa2BOhi2J8rmzSGiBkq1jxa8KOPwrDaGNDPUD3hiL4j7GHecLedsvlTM3G mMKZDdGJiH5/e8lNmGJqA/c6VmhXK+GhVUbc13zHhX3bMydoJBD4IxBcsYshfTEnPxLt r81Q== X-Gm-Message-State: ANhLgQ1zFiptd8S/lOX4YOjgMwtZk1UVVTG91fHj9VFzLQ+PbW6tIdoy oDmKr2COpOFit38LXaTEs6HLjeQm4vc= X-Google-Smtp-Source: ADFU+vuOUoCDHCW8/3TaILQ+9spX13OXRQr63h0xwVMRz2SN1KshxAkJWfEpZe/fkQXvgto8sh9ROw== X-Received: by 2002:a63:de51:: with SMTP id y17mr10266239pgi.70.1585249556901; Thu, 26 Mar 2020 12:05:56 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:56 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH 07/10] media: imx: utils: Remove unneeded argument to (find|enum)_format() Date: Thu, 26 Mar 2020 12:05:41 -0700 Message-Id: <20200326190544.16349-8-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart The find_format() and enum_format() functions take an argument that tells whether to take into account formats that don't have associated media bus codes. The same information can be deduced from the fourcc argument passed to these functions. Remove the allow_non_mbus argument and use fourcc instead internally. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index febcf3203cb1..e5e9f750f685 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -194,8 +194,7 @@ static const struct imx_media_pixfmt pixel_formats[] = { static const struct imx_media_pixfmt *find_format(u32 fourcc, u32 code, - enum codespace_sel cs_sel, - bool allow_non_mbus) + enum codespace_sel cs_sel) { const struct imx_media_pixfmt *fmt; int i, j; @@ -208,8 +207,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes)) + if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes)) continue; if (fourcc && fmt->fourcc == fourcc) @@ -227,8 +225,7 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, } static int enum_format(u32 *fourcc, u32 *code, u32 index, - enum codespace_sel cs_sel, - bool allow_non_mbus) + enum codespace_sel cs_sel) { const struct imx_media_pixfmt *fmt; unsigned int i, j = 0, match_index = 0; @@ -241,8 +238,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || - (!allow_non_mbus && !fmt->codes)) + if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes)) continue; if (fourcc && index == match_index) @@ -275,26 +271,26 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, const struct imx_media_pixfmt * imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel) { - return find_format(fourcc, 0, cs_sel, true); + return find_format(fourcc, 0, cs_sel); } EXPORT_SYMBOL_GPL(imx_media_find_format); int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel) { - return enum_format(fourcc, NULL, index, cs_sel, true); + return enum_format(fourcc, NULL, index, cs_sel); } EXPORT_SYMBOL_GPL(imx_media_enum_format); const struct imx_media_pixfmt * imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) { - return find_format(0, code, cs_sel, false); + return find_format(0, code, cs_sel); } EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel) { - return enum_format(NULL, code, index, cs_sel, false); + return enum_format(NULL, code, index, cs_sel); } EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); From patchwork Thu Mar 26 19:05:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460831 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 3A7A313A4 for ; Thu, 26 Mar 2020 19:06:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0AB6520658 for ; Thu, 26 Mar 2020 19:06:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j1C0hG33" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728563AbgCZTGB (ORCPT ); Thu, 26 Mar 2020 15:06:01 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:42453 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728472AbgCZTGA (ORCPT ); Thu, 26 Mar 2020 15:06:00 -0400 Received: by mail-pl1-f195.google.com with SMTP id e1so2512172plt.9 for ; Thu, 26 Mar 2020 12:05:58 -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=7mPzpSP6SbB55rI9D/O3yY6A2fh9pgcbD0ddJLfDlX0=; b=j1C0hG33QvPMYZjvIjNeykTm1Z1L4prrsGgh3tZxt3kOFS++TXxKUq1rBRbSJtumKd xKmO6nfH8fdswDhhE+gBK0F+WrJYAvduVmrhpsPaclqnrHU/lOr+DllWvtAVM+fco46x ZI1iZ0cjJT/fCSJG1uzivIKsF7AtfTmfaIkEIc8SUv8PHJR8oLOFyE3cBDQAIWvo2KOh ky0ac+WAZ4L/kUT/yirz9sGdEwx/6cheOY+wSBMI4yeyAl4xwgC2NT2yMV2cgA04srWZ T2wasTnXFKRQMhfGIdADMueaHzdbIhocAo/buFVDd4vJOqvRN6IDOmea3Yb87Av2/4IC Bo7A== 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=7mPzpSP6SbB55rI9D/O3yY6A2fh9pgcbD0ddJLfDlX0=; b=XVWaZUSpfHgL6GS3ywKVfMXWk8D8py+b1B5wFnlDadtg+968/GuaVSt0LWn2Bu3/CA 7R9+hT6Bwo7zz3Z9AmFTLqL8/Z1DvtcbaYezTWYEm956x0CmKv6T2amIwuV6rLZvcuOp N8q2fjF/gcQpI897WTogMrHDoUUygDL34Lzcepf7uNVW9KXhQPi0uPMnSjpuFNIvvi/W 2QxcGs/x/eQ5EdcWcirCFuUDgsWt3Dj3+7ezU9VFM/LhUKf4WA0FSH6yGbvJMvZxMH3k 9mYUkdJQF4H3yQXzvHJ920E6c4nRNe+G1p6LA3VgwZZigkJaUnWL2iPIUHFeaNXDKyX0 T/GA== X-Gm-Message-State: ANhLgQ21JU+1DnpbXiHwqnzEipSYw4xXGXDWapA02NTwf1TYuRp0Q2jO hzPPji83msiwJSUHuLHuNHZ9AyBNgeA= X-Google-Smtp-Source: ADFU+vu9yynu51wr72T3/PS+8YSKramtrp+WC03+vMaJyFcdrkRNNlU6h9KVPABFaNjz0tVXKotBAQ== X-Received: by 2002:a17:902:b207:: with SMTP id t7mr9769033plr.47.1585249557795; Thu, 26 Mar 2020 12:05:57 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:57 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH 08/10] media: imx: utils: Rename format lookup and enumeration functions Date: Thu, 26 Mar 2020 12:05:42 -0700 Message-Id: <20200326190544.16349-9-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart Rename the format lookup and enumeration functions according to their usage: - Rename imx_media_(find|enum)_format() to *_pixel_format() to explicitly state on what formats the functions operate. This aligns the naming scheme with the media bus and IPU format functions that already end with *_mbus_format() and *_ipu_formats(). - Rename all enumeration functions to pluralize 'formats' at the end, as they enumerate multiple formats. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-ic-prp.c | 8 ++--- drivers/staging/media/imx/imx-ic-prpencvf.c | 8 ++--- drivers/staging/media/imx/imx-media-capture.c | 16 +++++----- .../staging/media/imx/imx-media-csc-scaler.c | 3 +- drivers/staging/media/imx/imx-media-csi.c | 15 +++++---- drivers/staging/media/imx/imx-media-utils.c | 31 ++++++++++--------- drivers/staging/media/imx/imx-media-vdic.c | 6 ++-- drivers/staging/media/imx/imx-media.h | 11 ++++--- drivers/staging/media/imx/imx7-media-csi.c | 6 ++-- 9 files changed, 54 insertions(+), 50 deletions(-) diff --git a/drivers/staging/media/imx/imx-ic-prp.c b/drivers/staging/media/imx/imx-ic-prp.c index 9c1f723972e4..50471541f4bc 100644 --- a/drivers/staging/media/imx/imx-ic-prp.c +++ b/drivers/staging/media/imx/imx-ic-prp.c @@ -106,8 +106,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) { case PRP_SINK_PAD: - ret = imx_media_enum_ipu_format(&code->code, code->index, - CS_SEL_YUV_RGB); + ret = imx_media_enum_ipu_formats(&code->code, code->index, + CS_SEL_YUV_RGB); break; case PRP_SRC_PAD_PRPENC: case PRP_SRC_PAD_PRPVF: @@ -182,7 +182,7 @@ static int prp_set_fmt(struct v4l2_subdev *sd, cc = imx_media_find_ipu_format(sdformat->format.code, CS_SEL_YUV_RGB); if (!cc) { - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); cc = imx_media_find_ipu_format(code, CS_SEL_YUV); sdformat->format.code = cc->codes[0]; } @@ -438,7 +438,7 @@ static int prp_registered(struct v4l2_subdev *sd) priv->frame_interval.denominator = 30; /* set a default mbus format */ - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); return imx_media_init_mbus_fmt(&priv->format_mbus, 640, 480, code, V4L2_FIELD_NONE, NULL); } diff --git a/drivers/staging/media/imx/imx-ic-prpencvf.c b/drivers/staging/media/imx/imx-ic-prpencvf.c index 5a22cdc7378a..003ace29ccaf 100644 --- a/drivers/staging/media/imx/imx-ic-prpencvf.c +++ b/drivers/staging/media/imx/imx-ic-prpencvf.c @@ -850,8 +850,8 @@ static int prp_enum_mbus_code(struct v4l2_subdev *sd, if (code->pad >= PRPENCVF_NUM_PADS) return -EINVAL; - return imx_media_enum_ipu_format(&code->code, code->index, - CS_SEL_YUV_RGB); + return imx_media_enum_ipu_formats(&code->code, code->index, + CS_SEL_YUV_RGB); } static int prp_get_fmt(struct v4l2_subdev *sd, @@ -890,7 +890,7 @@ static void prp_try_fmt(struct prp_priv *priv, if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); *cc = imx_media_find_ipu_format(code, CS_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } @@ -1249,7 +1249,7 @@ static int prp_registered(struct v4l2_subdev *sd) u32 code; /* set a default mbus format */ - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); for (i = 0; i < PRPENCVF_NUM_PADS; i++) { ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], 640, 480, code, V4L2_FIELD_NONE, diff --git a/drivers/staging/media/imx/imx-media-capture.c b/drivers/staging/media/imx/imx-media-capture.c index d60b49ec4fa4..1ff992eb4d96 100644 --- a/drivers/staging/media/imx/imx-media-capture.c +++ b/drivers/staging/media/imx/imx-media-capture.c @@ -91,7 +91,7 @@ static int capture_enum_framesizes(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fsize->pixel_format, CS_SEL_ANY); + cc = imx_media_find_pixel_format(fsize->pixel_format, CS_SEL_ANY); if (!cc) return -EINVAL; @@ -133,7 +133,7 @@ static int capture_enum_frameintervals(struct file *file, void *fh, }; int ret; - cc = imx_media_find_format(fival->pixel_format, CS_SEL_ANY); + cc = imx_media_find_pixel_format(fival->pixel_format, CS_SEL_ANY); if (!cc) return -EINVAL; @@ -172,7 +172,7 @@ static int capture_enum_fmt_vid_cap(struct file *file, void *fh, u32 cs_sel = (cc_src->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB; - ret = imx_media_enum_format(&fourcc, f->index, cs_sel); + ret = imx_media_enum_pixel_formats(&fourcc, f->index, cs_sel); if (ret) return ret; } else { @@ -217,10 +217,10 @@ static int __capture_try_fmt_vid_cap(struct capture_priv *priv, CS_SEL_YUV : CS_SEL_RGB; fourcc = f->fmt.pix.pixelformat; - cc = imx_media_find_format(fourcc, cs_sel); + cc = imx_media_find_pixel_format(fourcc, cs_sel); if (!cc) { - imx_media_enum_format(&fourcc, 0, cs_sel); - cc = imx_media_find_format(fourcc, cs_sel); + imx_media_enum_pixel_formats(&fourcc, 0, cs_sel); + cc = imx_media_find_pixel_format(fourcc, cs_sel); } } else { cc_src = imx_media_find_mbus_format(fmt_src->format.code, @@ -789,8 +789,8 @@ int imx_media_capture_device_register(struct imx_media_video_dev *vdev) &fmt_src.format, NULL); vdev->compose.width = fmt_src.format.width; vdev->compose.height = fmt_src.format.height; - vdev->cc = imx_media_find_format(vdev->fmt.fmt.pix.pixelformat, - CS_SEL_ANY); + vdev->cc = imx_media_find_pixel_format(vdev->fmt.fmt.pix.pixelformat, + CS_SEL_ANY); v4l2_info(sd, "Registered %s as /dev/%s\n", vfd->name, video_device_node_name(vfd)); diff --git a/drivers/staging/media/imx/imx-media-csc-scaler.c b/drivers/staging/media/imx/imx-media-csc-scaler.c index 3e1c88938e7d..0aa2493cfc47 100644 --- a/drivers/staging/media/imx/imx-media-csc-scaler.c +++ b/drivers/staging/media/imx/imx-media-csc-scaler.c @@ -164,7 +164,8 @@ static int ipu_csc_scaler_enum_fmt(struct file *file, void *fh, u32 fourcc; int ret; - ret = imx_media_enum_format(&fourcc, f->index, CS_SEL_YUV_RGB); + ret = imx_media_enum_pixel_formats(&fourcc, f->index, + CS_SEL_YUV_RGB); if (ret) return ret; diff --git a/drivers/staging/media/imx/imx-media-csi.c b/drivers/staging/media/imx/imx-media-csi.c index 298294b95293..caab4d0cd5ce 100644 --- a/drivers/staging/media/imx/imx-media-csi.c +++ b/drivers/staging/media/imx/imx-media-csi.c @@ -1238,8 +1238,8 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) { case CSI_SINK_PAD: - ret = imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + CS_SEL_ANY); break; case CSI_SRC_PAD_DIRECT: case CSI_SRC_PAD_IDMAC: @@ -1258,9 +1258,8 @@ static int csi_enum_mbus_code(struct v4l2_subdev *sd, } else { u32 cs_sel = (incc->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB; - ret = imx_media_enum_ipu_format(&code->code, - code->index, - cs_sel); + ret = imx_media_enum_ipu_formats(&code->code, + code->index, cs_sel); } break; default: @@ -1448,7 +1447,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc = imx_media_find_ipu_format(sdformat->format.code, cs_sel); if (!*cc) { - imx_media_enum_ipu_format(&code, 0, cs_sel); + imx_media_enum_ipu_formats(&code, 0, cs_sel); *cc = imx_media_find_ipu_format(code, cs_sel); sdformat->format.code = (*cc)->codes[0]; } @@ -1471,7 +1470,7 @@ static void csi_try_fmt(struct csi_priv *priv, *cc = imx_media_find_mbus_format(sdformat->format.code, CS_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_ANY); *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } @@ -1758,7 +1757,7 @@ static int csi_registered(struct v4l2_subdev *sd) for (i = 0; i < CSI_NUM_PADS; i++) { code = 0; if (i != CSI_SINK_PAD) - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); /* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index e5e9f750f685..ae7396c0b687 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -224,8 +224,8 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, return NULL; } -static int enum_format(u32 *fourcc, u32 *code, u32 index, - enum codespace_sel cs_sel) +static int enum_formats(u32 *fourcc, u32 *code, u32 index, + enum codespace_sel cs_sel) { const struct imx_media_pixfmt *fmt; unsigned int i, j = 0, match_index = 0; @@ -269,17 +269,18 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index, } const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel) +imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel) { return find_format(fourcc, 0, cs_sel); } -EXPORT_SYMBOL_GPL(imx_media_find_format); +EXPORT_SYMBOL_GPL(imx_media_find_pixel_format); -int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel) +int imx_media_enum_pixel_formats(u32 *fourcc, u32 index, + enum codespace_sel cs_sel) { - return enum_format(fourcc, NULL, index, cs_sel); + return enum_formats(fourcc, NULL, index, cs_sel); } -EXPORT_SYMBOL_GPL(imx_media_enum_format); +EXPORT_SYMBOL_GPL(imx_media_enum_pixel_formats); const struct imx_media_pixfmt * imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) @@ -288,11 +289,11 @@ imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) } EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel) +int imx_media_enum_mbus_formats(u32 *code, u32 index, enum codespace_sel cs_sel) { - return enum_format(NULL, code, index, cs_sel); + return enum_formats(NULL, code, index, cs_sel); } -EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format); +EXPORT_SYMBOL_GPL(imx_media_enum_mbus_formats); /* ----------------------------------------------------------------------------- * IPU Formats Lookup and Enumeration @@ -344,7 +345,7 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel) } EXPORT_SYMBOL_GPL(imx_media_find_ipu_format); -int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) +int imx_media_enum_ipu_formats(u32 *code, u32 index, enum codespace_sel cs_sel) { bool accept_yuv = cs_sel & CS_SEL_YUV; bool accept_rgb = cs_sel & CS_SEL_RGB; @@ -372,7 +373,7 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel) return -EINVAL; } -EXPORT_SYMBOL_GPL(imx_media_enum_ipu_format); +EXPORT_SYMBOL_GPL(imx_media_enum_ipu_formats); int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, u32 width, u32 height, u32 code, u32 field, @@ -384,7 +385,7 @@ int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, mbus->height = height; mbus->field = field; if (code == 0) - imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_YUV); lcc = imx_media_find_mbus_format(code, CS_SEL_ANY); if (!lcc) { lcc = imx_media_find_ipu_format(code, CS_SEL_ANY); @@ -523,7 +524,7 @@ int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, if (cc->ipufmt && cc->cs == IPUV3_COLORSPACE_YUV) { u32 code; - imx_media_enum_mbus_format(&code, 0, CS_SEL_YUV); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_YUV); cc = imx_media_find_mbus_format(code, CS_SEL_YUV); } @@ -575,7 +576,7 @@ int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus, { const struct imx_media_pixfmt *fmt; - fmt = imx_media_find_format(image->pix.pixelformat, CS_SEL_ANY); + fmt = imx_media_find_pixel_format(image->pix.pixelformat, CS_SEL_ANY); if (!fmt) return -EINVAL; diff --git a/drivers/staging/media/imx/imx-media-vdic.c b/drivers/staging/media/imx/imx-media-vdic.c index 0d83c2c41606..9dbf63796806 100644 --- a/drivers/staging/media/imx/imx-media-vdic.c +++ b/drivers/staging/media/imx/imx-media-vdic.c @@ -548,7 +548,7 @@ static int vdic_enum_mbus_code(struct v4l2_subdev *sd, if (code->pad >= VDIC_NUM_PADS) return -EINVAL; - return imx_media_enum_ipu_format(&code->code, code->index, CS_SEL_YUV); + return imx_media_enum_ipu_formats(&code->code, code->index, CS_SEL_YUV); } static int vdic_get_fmt(struct v4l2_subdev *sd, @@ -587,7 +587,7 @@ static void vdic_try_fmt(struct vdic_priv *priv, if (!*cc) { u32 code; - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); *cc = imx_media_find_ipu_format(code, CS_SEL_YUV); sdformat->format.code = (*cc)->codes[0]; } @@ -850,7 +850,7 @@ static int vdic_registered(struct v4l2_subdev *sd) for (i = 0; i < VDIC_NUM_PADS; i++) { code = 0; if (i != VDIC_SINK_PAD_IDMAC) - imx_media_enum_ipu_format(&code, 0, CS_SEL_YUV); + imx_media_enum_ipu_formats(&code, 0, CS_SEL_YUV); /* set a default mbus format */ ret = imx_media_init_mbus_fmt(&priv->format_mbus[i], diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 917b4db02985..67983a26e5ff 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -159,14 +159,17 @@ enum codespace_sel { /* imx-media-utils.c */ const struct imx_media_pixfmt * -imx_media_find_format(u32 fourcc, enum codespace_sel cs_sel); -int imx_media_enum_format(u32 *fourcc, u32 index, enum codespace_sel cs_sel); +imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel); +int imx_media_enum_pixel_formats(u32 *fourcc, u32 index, + enum codespace_sel cs_sel); const struct imx_media_pixfmt * imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel); -int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel); +int imx_media_enum_mbus_formats(u32 *code, u32 index, + enum codespace_sel cs_sel); const struct imx_media_pixfmt * imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel); -int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel); +int imx_media_enum_ipu_formats(u32 *code, u32 index, enum codespace_sel cs_sel); + int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus, u32 width, u32 height, u32 code, u32 field, const struct imx_media_pixfmt **cc); diff --git a/drivers/staging/media/imx/imx7-media-csi.c b/drivers/staging/media/imx/imx7-media-csi.c index a469dc76a787..df4dd41b23de 100644 --- a/drivers/staging/media/imx/imx7-media-csi.c +++ b/drivers/staging/media/imx/imx7-media-csi.c @@ -958,8 +958,8 @@ static int imx7_csi_enum_mbus_code(struct v4l2_subdev *sd, switch (code->pad) { case IMX7_CSI_PAD_SINK: - ret = imx_media_enum_mbus_format(&code->code, code->index, - CS_SEL_ANY); + ret = imx_media_enum_mbus_formats(&code->code, code->index, + CS_SEL_ANY); break; case IMX7_CSI_PAD_SRC: if (code->index != 0) { @@ -1036,7 +1036,7 @@ static int imx7_csi_try_fmt(struct imx7_csi *csi, *cc = imx_media_find_mbus_format(sdformat->format.code, CS_SEL_ANY); if (!*cc) { - imx_media_enum_mbus_format(&code, 0, CS_SEL_ANY); + imx_media_enum_mbus_formats(&code, 0, CS_SEL_ANY); *cc = imx_media_find_mbus_format(code, CS_SEL_ANY); sdformat->format.code = (*cc)->codes[0]; } From patchwork Thu Mar 26 19:05:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460829 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 0139081 for ; Thu, 26 Mar 2020 19:06:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5AF320719 for ; Thu, 26 Mar 2020 19:06:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="K98mr/2E" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728547AbgCZTGA (ORCPT ); Thu, 26 Mar 2020 15:06:00 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:36766 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728533AbgCZTGA (ORCPT ); Thu, 26 Mar 2020 15:06:00 -0400 Received: by mail-pg1-f196.google.com with SMTP id j29so3381375pgl.3 for ; Thu, 26 Mar 2020 12:05:59 -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=j354NRPP+bYhEPyv0l/eLWnC/FKJq0l1PwaRMYH1SEA=; b=K98mr/2EPSPry1D6CVXZwN/btfbX99NWR7jA2vI0bBzWspoXAj2nVBwSsIOaLH8K99 nMK17GGVp6Dw/snKF+uNnHAzaGbulASoOFkGRsoZmmiX7p2BQ3HYYtTKUJd7GKSzTHTg RNWArY1CgKHcrZNXLF996z2+dGoNDMJ6CBjK2TgckijJlLWtrCmlUrmIPjiILx8+Huc9 XDSTSMlB4W1AGDE8rXY0XW4T+vq2Hef860nTuCiIrDUhSwial0zSroEtUscWORZZTKX2 ZnZqU7//1EtFw5Obrx9aVMv9WGIziEXqjvH5MMwsvPtgKpXqsR6xCFWxAQuxZ0HlITXL UrCw== 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=j354NRPP+bYhEPyv0l/eLWnC/FKJq0l1PwaRMYH1SEA=; b=NKfBnm+3zQcrjZz8HzzmHKTbugafLtDJr9+2hgpof1X0zrXTOh8NFYq12u1lTel24Z UsrcoqNTfXJjpMMkTAlI9JeAsAGAvag0sJ9kDr24aQC449ecnV7QFg2BQvuKIvhnnSK9 0ZjV4TjG+wlRPlmkVPG/2TLnn5BNXb1rdPduxn2ilYQBJOiyA+yp3tuqp5i9EY/+UEV6 TP0ThEnClzpV/ulJxZFLxAuKwgOmMmy1VG9IvXBKOPCA0Q1vgyZ4MXlRJ27YhhnCzBqp 08huBOi6k727XwwXVG6kxzsF2axSEd2nUnSURso+HUvZogZiZi+6s/n1OZmD/LmEbXCO V9xQ== X-Gm-Message-State: ANhLgQ1ZsB9ffQSxQQq2nQuiHNdTgKG8wzEk73to9YcWlPut9zUjU7KT vcEBjIxT04xGOKpLk04LrKLx7TLJUcY= X-Google-Smtp-Source: ADFU+vtxJapAcqzMUDVtDGOAyUYJg2mhdFfRp6spiUV/DhsLMkCw5bTyKZV25L8O2DPe+T9jIvxvmw== X-Received: by 2002:a63:2d6:: with SMTP id 205mr10350091pgc.257.1585249558597; Thu, 26 Mar 2020 12:05:58 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:58 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva Subject: [PATCH 09/10] media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_pix_fmt Date: Thu, 26 Mar 2020 12:05:43 -0700 Message-Id: <20200326190544.16349-10-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Laurent Pinchart The imx_media_mbus_fmt_to_pix_fmt() function doesn't need to modify its mbus argument. Make it const. Signed-off-by: Laurent Pinchart --- drivers/staging/media/imx/imx-media-utils.c | 2 +- drivers/staging/media/imx/imx-media.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index ae7396c0b687..ef3702703936 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -502,7 +502,7 @@ void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, EXPORT_SYMBOL_GPL(imx_media_try_colorimetry); int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, - struct v4l2_mbus_framefmt *mbus, + const struct v4l2_mbus_framefmt *mbus, const struct imx_media_pixfmt *cc) { u32 width; diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h index 67983a26e5ff..a4885e280b83 100644 --- a/drivers/staging/media/imx/imx-media.h +++ b/drivers/staging/media/imx/imx-media.h @@ -178,7 +178,7 @@ int imx_media_init_cfg(struct v4l2_subdev *sd, void imx_media_try_colorimetry(struct v4l2_mbus_framefmt *tryfmt, bool ic_route); int imx_media_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, - struct v4l2_mbus_framefmt *mbus, + const struct v4l2_mbus_framefmt *mbus, const struct imx_media_pixfmt *cc); int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image, struct v4l2_mbus_framefmt *mbus); From patchwork Thu Mar 26 19:05:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 11460833 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 AFE9D1668 for ; Thu, 26 Mar 2020 19:06:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8862A2078C for ; Thu, 26 Mar 2020 19:06:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nk9YSuhS" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728565AbgCZTGB (ORCPT ); Thu, 26 Mar 2020 15:06:01 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:37162 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728533AbgCZTGB (ORCPT ); Thu, 26 Mar 2020 15:06:01 -0400 Received: by mail-pl1-f195.google.com with SMTP id x1so2521683plm.4 for ; Thu, 26 Mar 2020 12:06:00 -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=NjOy4GFKFVOjgu6LotHMH9B6bYJcmsIghEAgypUB+00=; b=Nk9YSuhS027L6bKqfjs/g47Tu+iWSv5khlv+MSyECpqRQ4eWSrqDIc2RrZjUGPdXd1 EGSKcGmBxpxSCOPN8TgXPGDeSokz7beoyo72MtKYHrqaHCSPWW7tdhGI7SP1QOA9yBko IuPwdYuLnz6uWyqQIgSEc6Rk09Af5aiJOSL5LD50p9siEewQD0MzxVdyScA8uZ93Qjhl na6RCLkWBX8FMX85+MpuMUEnwdsmpbgOtLL0Jh7zyGQ0k8ucwXs6soAGppnstLwi7iFf HaSLa4pRVxm4F4CgXxc2i6ze2dl4P72dfSgGZEKJMgRQdx/hFbNke5qmqzmvZ8CrG9Z3 hqbg== 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=NjOy4GFKFVOjgu6LotHMH9B6bYJcmsIghEAgypUB+00=; b=KHBABKXU1lLZ+l0iuVJ1rRawll7l8slZrRK2MzdZvJdwZCUktC2+qZ5MzUnU8VM8s6 KP4wElldSJ0Zuqy/VHRmMI4tln4U0Bmuet3fBSH/quoXIAeHVLsZW4H75Gx3WYMOHqbs CY5/UeZF26l6SQD3+K6AHqb0fGuWK+6oMnAUjiDBS+qPmRBOQLW4+9KcqJ3+S1j8hcwQ +0HBY7i3h2GRfA8Py9HYp+yaKSxhb9wF+PVx8id1EfBJc9LwoqHDdF6AJ2WmyA9KKTvh Twwz66B2a43ZA3ZPlk7nQzITyx18Cq7kgi5ALXa8NmoTCxz6Tv8b1luOFR3jvFSsOaNe QI5g== X-Gm-Message-State: ANhLgQ2XxpAp7SX+RdT+CyLXYfTIZ3mggIQ74N3t1q5FRwX0F2kZI3zh Yj3d9jE4u+JYGDxNc54BkvsGlHT6/Vs= X-Google-Smtp-Source: ADFU+vs00Pug6wBNqw0Hd91Yzl2NVqEepPOTiODJqwIoWf2BxPzuk3q1W5PEtQBQy1HfjNxQEMmxxg== X-Received: by 2002:a17:90a:2103:: with SMTP id a3mr1577300pje.181.1585249559485; Thu, 26 Mar 2020 12:05:59 -0700 (PDT) Received: from majic.sklembedded.com (c-73-202-231-77.hsd1.ca.comcast.net. [73.202.231.77]) by smtp.googlemail.com with ESMTPSA id q103sm7414623pjc.1.2020.03.26.12.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2020 12:05:59 -0700 (PDT) From: Steve Longerbeam To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Philipp Zabel , Rui Miguel Silva , Steve Longerbeam Subject: [PATCH 10/10] media: imx: utils: Split find|enum_format into fourcc and mbus functions Date: Thu, 26 Mar 2020 12:05:44 -0700 Message-Id: <20200326190544.16349-11-slongerbeam@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200326190544.16349-1-slongerbeam@gmail.com> References: <20200326190544.16349-1-slongerbeam@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org To make the code easier to follow, split up find_format() into separate search functions for pixel formats and media-bus codes. In the process inline the code into the exported functions imx_media_find_pixel_format() and imx_media_find_mbus_format(). Do the equivalent for enum_formats(). Also add comment blocks for the exported find|enum functions. Signed-off-by: Steve Longerbeam --- drivers/staging/media/imx/imx-media-utils.c | 152 +++++++++++++------- 1 file changed, 98 insertions(+), 54 deletions(-) diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c index ef3702703936..a806a146f1a6 100644 --- a/drivers/staging/media/imx/imx-media-utils.c +++ b/drivers/staging/media/imx/imx-media-utils.c @@ -192,12 +192,19 @@ static const struct imx_media_pixfmt pixel_formats[] = { }, }; -static const struct imx_media_pixfmt *find_format(u32 fourcc, - u32 code, - enum codespace_sel cs_sel) +/* + * Search for and return an entry in the pixel_formats[] array that matches + * the requested search criteria. + * + * @fourcc: Search for an entry with the given fourcc pixel format. + * @cs_sel: Search for entries with the given codespace encodings + * (YUV, RGB, and/or BAYER). + */ +const struct imx_media_pixfmt * +imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel) { const struct imx_media_pixfmt *fmt; - int i, j; + int i; for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { enum codespace_sel fmt_cs_sel; @@ -207,13 +214,37 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes)) - continue; - - if (fourcc && fmt->fourcc == fourcc) + if ((fmt_cs_sel & cs_sel) && fmt->fourcc == fourcc) return fmt; + } + + return NULL; +} +EXPORT_SYMBOL_GPL(imx_media_find_pixel_format); + +/* + * Search for and return an entry in the pixel_formats[] array that matches + * the requested search criteria. + * + * @code: Search for an entry with the given media-bus code. + * @cs_sel: Search for entries with the given codespace encodings + * (YUV, RGB, and/or BAYER). + */ +const struct imx_media_pixfmt * +imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) +{ + const struct imx_media_pixfmt *fmt; + int i, j; - if (!code || !fmt->codes) + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { + enum codespace_sel fmt_cs_sel; + + fmt = &pixel_formats[i]; + fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : + ((fmt->cs == IPUV3_COLORSPACE_YUV) ? + CS_SEL_YUV : CS_SEL_RGB); + + if (!(fmt_cs_sel & cs_sel) || !fmt->codes) continue; for (j = 0; fmt->codes[j]; j++) { @@ -221,14 +252,27 @@ static const struct imx_media_pixfmt *find_format(u32 fourcc, return fmt; } } + return NULL; } +EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); -static int enum_formats(u32 *fourcc, u32 *code, u32 index, - enum codespace_sel cs_sel) +/* + * Enumerate entries in the pixel_formats[] array that match the + * requested search criteria. Returns the fourcc that matches the + * search criteria at the requested match index. + * + * @fourcc: The returned fourcc that matches the search criteria at + * the requested match index. + * @index: The requested match index. + * @cs_sel: Include in the enumeration entries with the given codespace + * encodings (YUV, RGB, and/or BAYER). + */ +int imx_media_enum_pixel_formats(u32 *fourcc, u32 index, + enum codespace_sel cs_sel) { const struct imx_media_pixfmt *fmt; - unsigned int i, j = 0, match_index = 0; + unsigned int i, match_index = 0; for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { enum codespace_sel fmt_cs_sel; @@ -238,60 +282,60 @@ static int enum_formats(u32 *fourcc, u32 *code, u32 index, ((fmt->cs == IPUV3_COLORSPACE_YUV) ? CS_SEL_YUV : CS_SEL_RGB); - if (!(fmt_cs_sel & cs_sel) || (!fourcc && !fmt->codes)) + if (!(fmt_cs_sel & cs_sel)) continue; - if (fourcc && index == match_index) - break; - - if (!code) { - match_index++; - continue; + if (index == match_index) { + *fourcc = fmt->fourcc; + return 0; } - for (j = 0; j < fmt->codes[j]; j++) { - if (index == match_index) - goto out; - - match_index++; - } + match_index++; } - if (i == ARRAY_SIZE(pixel_formats)) - return -EINVAL; - -out: - if (fourcc) - *fourcc = fmt->fourcc; - if (code) - *code = fmt->codes ? fmt->codes[j] : 0; - return 0; + return -EINVAL; } +EXPORT_SYMBOL_GPL(imx_media_enum_pixel_formats); -const struct imx_media_pixfmt * -imx_media_find_pixel_format(u32 fourcc, enum codespace_sel cs_sel) +/* + * Enumerate entries in the pixel_formats[] array that match the + * requested search criteria. Returns the media-bus code that matches + * the search criteria at the requested match index. + * + * @code: The returned media-bus code that matches the search criteria at + * the requested match index. + * @index: The requested match index. + * @cs_sel: Include in the enumeration entries with the given codespace + * encodings (YUV, RGB, and/or BAYER). + */ +int imx_media_enum_mbus_formats(u32 *code, u32 index, + enum codespace_sel cs_sel) { - return find_format(fourcc, 0, cs_sel); -} -EXPORT_SYMBOL_GPL(imx_media_find_pixel_format); + const struct imx_media_pixfmt *fmt; + unsigned int i, j = 0, match_index = 0; -int imx_media_enum_pixel_formats(u32 *fourcc, u32 index, - enum codespace_sel cs_sel) -{ - return enum_formats(fourcc, NULL, index, cs_sel); -} -EXPORT_SYMBOL_GPL(imx_media_enum_pixel_formats); + for (i = 0; i < ARRAY_SIZE(pixel_formats); i++) { + enum codespace_sel fmt_cs_sel; -const struct imx_media_pixfmt * -imx_media_find_mbus_format(u32 code, enum codespace_sel cs_sel) -{ - return find_format(0, code, cs_sel); -} -EXPORT_SYMBOL_GPL(imx_media_find_mbus_format); + fmt = &pixel_formats[i]; + fmt_cs_sel = fmt->bayer ? CS_SEL_BAYER : + ((fmt->cs == IPUV3_COLORSPACE_YUV) ? + CS_SEL_YUV : CS_SEL_RGB); -int imx_media_enum_mbus_formats(u32 *code, u32 index, enum codespace_sel cs_sel) -{ - return enum_formats(NULL, code, index, cs_sel); + if (!(fmt_cs_sel & cs_sel) || !fmt->codes) + continue; + + for (j = 0; j < fmt->codes[j]; j++) { + if (index == match_index) { + *code = fmt->codes[j]; + return 0; + } + + match_index++; + } + } + + return -EINVAL; } EXPORT_SYMBOL_GPL(imx_media_enum_mbus_formats);