Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp654432ybz; Fri, 1 May 2020 06:15:24 -0700 (PDT) X-Google-Smtp-Source: APiQypKESncxu3fQ7/ifJymsu37sovRX+eHqOR+cMjat00WsjFVkB0Xzy+Npg+Auaw6hkFHtVIQz X-Received: by 2002:a17:906:2558:: with SMTP id j24mr3248333ejb.72.1588338924131; Fri, 01 May 2020 06:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588338924; cv=none; d=google.com; s=arc-20160816; b=D4jiv9WIaL37JBuXs2B/gBecxnaywbwBJTGfGZVq9aZuMbE+Fm9zmiaXMsWDHYJ9pb ZWVOZlFMuRdlKWp7eOmEKJvhWmBlgb6RS/IBUgAh/qxIlDLV7Id/jQco0pZe1AEHSv45 ocwTp7oIgKRD3dluZU8HqKfd9s4ZCaZpLBiDZse6sOvHCG1CTvI9blQxF+bO1CGH9N0s O2UXJg58k33Q00GkfB6wtc8ZZqzAnjTOfP41Sv2NOnbV6gmNLcyzQVRO7L1PTPEgvtOd 8PMlNn5/FUiyyq4LNU6/QTYXXdOnMy3RXcPl0sp2VUnks98xgVRiXMXWnUgdkDWrsPCc 08pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=d4rDdOU/mmZoj82ujDYi3VxojM3VTrhL9ipvTNQ0yL0=; b=ctf1K9ZV404dKh7qKZ9adWlE79LabUAreNYCdlrmfIdck2xk1vVraqiR2jlq+9s3t4 C+TF0+HrORFKs7TjSMl6zwBAuE09//XjMjC4eD0rPQjxlQbzldtIbCbUZr3RyGro0Jzh O47s9C0yR0grVitNhsgEaipJksAVMS+f9kCPb8C68O3X5U5AaamKl8D2eHgw9VEr4fgF a6i0EVdvnn+TNBqIly5DqfaLUjx+i4RYGYU639Ltv5P4oTpwN6aS51qAwSMbw/mEydYj 6hubggEJUOW31THPfr7VrNZUtv02LBGFZzrYOjUFefQS2088W/CvV2csXdwaIMlP23jI pOow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=Ic6Xh4P4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd12si1647034edb.506.2020.05.01.06.15.00; Fri, 01 May 2020 06:15:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail header.b=Ic6Xh4P4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728867AbgEANLQ (ORCPT + 99 others); Fri, 1 May 2020 09:11:16 -0400 Received: from mail-40131.protonmail.ch ([185.70.40.131]:36266 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728787AbgEANLO (ORCPT ); Fri, 1 May 2020 09:11:14 -0400 Date: Fri, 01 May 2020 13:11:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail; t=1588338670; bh=d4rDdOU/mmZoj82ujDYi3VxojM3VTrhL9ipvTNQ0yL0=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=Ic6Xh4P44xCHOLYTghd/ERQGPGrSuCgzYuYHIM6bni3Odq2+0B9Vv8mQIE65bwRJ7 ZuJ0u4MZZNiEw/wTCx5DAIN0BD/dHwoQUqAY6FXmt1VvRG2rXUuH3EIcu1xo/SN5TN FP+zEw6TN2GbHMRTZvwNF5rebcxolfkQ6r7ebB3s= To: linux-media@vger.kernel.org From: =?UTF-8?Q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= Cc: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , Hans Verkuil , linux-kernel@vger.kernel.org, lkcamp@lists.libreplanetbr.org Reply-To: =?UTF-8?Q?N=C3=ADcolas_F=2E_R=2E_A=2E_Prado?= Subject: [PATCH v4 1/3] media: vimc: Support multiple media bus codes for each pixelformat Message-ID: <20200501131045.1849315-2-nfraprado@protonmail.com> In-Reply-To: <20200501131045.1849315-1-nfraprado@protonmail.com> References: <20200501131045.1849315-1-nfraprado@protonmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mail.protonmail.ch Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Change vimc_pix_map_list to allow multiple media bus codes to map to the same pixelformat, making it possible to add media bus codes for which there are no pixelformat. Acked-by: Helen Koike Signed-off-by: N=C3=ADcolas F. R. A. Prado --- Changes in v4: None Changes in v3: - Make loop in vimc_mbus_code_by_index() clearer by using break instead of = if - Use VIMC_PIX_FMT_MAX_CODES define instead of hardcoded value for the size= of code array in struct vimc_pix_map Changes in v2: - Fix vimc_mbus_code_by_index not checking code array bounds - Fix array formatting - Rename variables - Change code array size - Add comment about vimc_mbus_code_by_index return value drivers/media/test-drivers/vimc/vimc-common.c | 71 ++++++++++++------- drivers/media/test-drivers/vimc/vimc-common.h | 13 +++- drivers/media/test-drivers/vimc/vimc-scaler.c | 10 ++- drivers/media/test-drivers/vimc/vimc-sensor.c | 6 +- 4 files changed, 68 insertions(+), 32 deletions(-) diff --git a/drivers/media/test-drivers/vimc/vimc-common.c b/drivers/media/= test-drivers/vimc/vimc-common.c index c95c17c048f2..e11107e4796c 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.c +++ b/drivers/media/test-drivers/vimc/vimc-common.c @@ -19,19 +19,19 @@ static const struct vimc_pix_map vimc_pix_map_list[] = =3D { =20 =09/* RGB formats */ =09{ -=09=09.code =3D MEDIA_BUS_FMT_BGR888_1X24, +=09=09.code =3D { MEDIA_BUS_FMT_BGR888_1X24 }, =09=09.pixelformat =3D V4L2_PIX_FMT_BGR24, =09=09.bpp =3D 3, =09=09.bayer =3D false, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_RGB888_1X24, +=09=09.code =3D { MEDIA_BUS_FMT_RGB888_1X24 }, =09=09.pixelformat =3D V4L2_PIX_FMT_RGB24, =09=09.bpp =3D 3, =09=09.bayer =3D false, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_ARGB8888_1X32, +=09=09.code =3D { MEDIA_BUS_FMT_ARGB8888_1X32 }, =09=09.pixelformat =3D V4L2_PIX_FMT_ARGB32, =09=09.bpp =3D 4, =09=09.bayer =3D false, @@ -39,49 +39,49 @@ static const struct vimc_pix_map vimc_pix_map_list[] = =3D { =20 =09/* Bayer formats */ =09{ -=09=09.code =3D MEDIA_BUS_FMT_SBGGR8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SBGGR8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SBGGR8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGBRG8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SGBRG8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGBRG8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGRBG8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SGRBG8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGRBG8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SRGGB8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SRGGB8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SRGGB8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SBGGR10_1X10, +=09=09.code =3D { MEDIA_BUS_FMT_SBGGR10_1X10 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SBGGR10, =09=09.bpp =3D 2, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGBRG10_1X10, +=09=09.code =3D { MEDIA_BUS_FMT_SGBRG10_1X10 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGBRG10, =09=09.bpp =3D 2, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGRBG10_1X10, +=09=09.code =3D { MEDIA_BUS_FMT_SGRBG10_1X10 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGRBG10, =09=09.bpp =3D 2, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SRGGB10_1X10, +=09=09.code =3D { MEDIA_BUS_FMT_SRGGB10_1X10 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SRGGB10, =09=09.bpp =3D 2, =09=09.bayer =3D true, @@ -89,25 +89,25 @@ static const struct vimc_pix_map vimc_pix_map_list[] = =3D { =20 =09/* 10bit raw bayer a-law compressed to 8 bits */ =09{ -=09=09.code =3D MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SBGGR10ALAW8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGBRG10ALAW8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGRBG10ALAW8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SRGGB10ALAW8, =09=09.bpp =3D 1, =09=09.bayer =3D true, @@ -115,49 +115,49 @@ static const struct vimc_pix_map vimc_pix_map_list[] = =3D { =20 =09/* 10bit raw bayer DPCM compressed to 8 bits */ =09{ -=09=09.code =3D MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SBGGR10DPCM8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGBRG10DPCM8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGRBG10DPCM8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, +=09=09.code =3D { MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SRGGB10DPCM8, =09=09.bpp =3D 1, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SBGGR12_1X12, +=09=09.code =3D { MEDIA_BUS_FMT_SBGGR12_1X12 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SBGGR12, =09=09.bpp =3D 2, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGBRG12_1X12, +=09=09.code =3D { MEDIA_BUS_FMT_SGBRG12_1X12 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGBRG12, =09=09.bpp =3D 2, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SGRBG12_1X12, +=09=09.code =3D { MEDIA_BUS_FMT_SGRBG12_1X12 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SGRBG12, =09=09.bpp =3D 2, =09=09.bayer =3D true, =09}, =09{ -=09=09.code =3D MEDIA_BUS_FMT_SRGGB12_1X12, +=09=09.code =3D { MEDIA_BUS_FMT_SRGGB12_1X12 }, =09=09.pixelformat =3D V4L2_PIX_FMT_SRGGB12, =09=09.bpp =3D 2, =09=09.bayer =3D true, @@ -182,13 +182,32 @@ const struct vimc_pix_map *vimc_pix_map_by_index(unsi= gned int i) =09return &vimc_pix_map_list[i]; } =20 +const u32 vimc_mbus_code_by_index(unsigned int index) +{ +=09unsigned int i, j; + +=09for (i =3D 0; i < ARRAY_SIZE(vimc_pix_map_list); i++) { +=09=09for (j =3D 0; j < ARRAY_SIZE(vimc_pix_map_list[i].code); j++) { +=09=09=09if (!vimc_pix_map_list[i].code[j]) +=09=09=09=09break; + +=09=09=09if (!index) +=09=09=09=09return vimc_pix_map_list[i].code[j]; +=09=09=09index--; +=09=09} +=09} +=09return 0; +} + const struct vimc_pix_map *vimc_pix_map_by_code(u32 code) { -=09unsigned int i; +=09unsigned int i, j; =20 =09for (i =3D 0; i < ARRAY_SIZE(vimc_pix_map_list); i++) { -=09=09if (vimc_pix_map_list[i].code =3D=3D code) -=09=09=09return &vimc_pix_map_list[i]; +=09=09for (j =3D 0; j < ARRAY_SIZE(vimc_pix_map_list[i].code); j++) { +=09=09=09if (vimc_pix_map_list[i].code[j] =3D=3D code) +=09=09=09=09return &vimc_pix_map_list[i]; +=09=09} =09} =09return NULL; } diff --git a/drivers/media/test-drivers/vimc/vimc-common.h b/drivers/media/= test-drivers/vimc/vimc-common.h index 487bd020f85c..dfebf6f75cfc 100644 --- a/drivers/media/test-drivers/vimc/vimc-common.h +++ b/drivers/media/test-drivers/vimc/vimc-common.h @@ -32,6 +32,8 @@ #define VIMC_IS_SRC(pad)=09(pad) #define VIMC_IS_SINK(pad)=09(!(pad)) =20 +#define VIMC_PIX_FMT_MAX_CODES 1 + /** * vimc_colorimetry_clamp - Adjust colorimetry parameters * @@ -70,7 +72,7 @@ do {=09=09=09=09=09=09=09=09=09\ * V4L2_PIX_FMT_* fourcc pixelformat and its bytes per pixel (bpp) */ struct vimc_pix_map { -=09unsigned int code; +=09unsigned int code[VIMC_PIX_FMT_MAX_CODES]; =09unsigned int bpp; =09u32 pixelformat; =09bool bayer; @@ -169,6 +171,15 @@ extern struct vimc_ent_type vimc_cap_type; */ const struct vimc_pix_map *vimc_pix_map_by_index(unsigned int i); =20 +/** + * vimc_mbus_code_by_index - get mbus code by its index + * + * @index:=09=09index of the mbus code in vimc_pix_map_list + * + * Returns 0 if no mbus code is found for the given index. + */ +const u32 vimc_mbus_code_by_index(unsigned int index); + /** * vimc_pix_map_by_code - get vimc_pix_map struct by media bus code * diff --git a/drivers/media/test-drivers/vimc/vimc-scaler.c b/drivers/media/= test-drivers/vimc/vimc-scaler.c index 465b906b7497..02615ded1c93 100644 --- a/drivers/media/test-drivers/vimc/vimc-scaler.c +++ b/drivers/media/test-drivers/vimc/vimc-scaler.c @@ -110,13 +110,19 @@ static int vimc_sca_enum_mbus_code(struct v4l2_subdev= *sd, =09=09=09=09 struct v4l2_subdev_pad_config *cfg, =09=09=09=09 struct v4l2_subdev_mbus_code_enum *code) { -=09const struct vimc_pix_map *vpix =3D vimc_pix_map_by_index(code->index); +=09const u32 mbus_code =3D vimc_mbus_code_by_index(code->index); +=09const struct vimc_pix_map *vpix; + +=09if (!mbus_code) +=09=09return -EINVAL; + +=09vpix =3D vimc_pix_map_by_code(mbus_code); =20 =09/* We don't support bayer format */ =09if (!vpix || vpix->bayer) =09=09return -EINVAL; =20 -=09code->code =3D vpix->code; +=09code->code =3D mbus_code; =20 =09return 0; } diff --git a/drivers/media/test-drivers/vimc/vimc-sensor.c b/drivers/media/= test-drivers/vimc/vimc-sensor.c index 228120b3a6dd..9391f5b5c58a 100644 --- a/drivers/media/test-drivers/vimc/vimc-sensor.c +++ b/drivers/media/test-drivers/vimc/vimc-sensor.c @@ -52,12 +52,12 @@ static int vimc_sen_enum_mbus_code(struct v4l2_subdev *= sd, =09=09=09=09 struct v4l2_subdev_pad_config *cfg, =09=09=09=09 struct v4l2_subdev_mbus_code_enum *code) { -=09const struct vimc_pix_map *vpix =3D vimc_pix_map_by_index(code->index); +=09const u32 mbus_code =3D vimc_mbus_code_by_index(code->index); =20 -=09if (!vpix) +=09if (!mbus_code) =09=09return -EINVAL; =20 -=09code->code =3D vpix->code; +=09code->code =3D mbus_code; =20 =09return 0; } --=20 2.26.2