From patchwork Sun Feb 2 15:50:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 61392 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyHV6-00H8vc-EJ; Sun, 02 Feb 2020 15:49:32 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727073AbgBBPuq (ORCPT + 1 other); Sun, 2 Feb 2020 10:50:46 -0500 Received: from mail-40131.protonmail.ch ([185.70.40.131]:12946 "EHLO mail-40131.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbgBBPuq (ORCPT ); Sun, 2 Feb 2020 10:50:46 -0500 Date: Sun, 02 Feb 2020 15:50:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1580658642; bh=JGfmEE34wwCHJbRehi9mkBdjd8a9QxVtXocWsQWMo1I=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References: Feedback-ID:From; b=HtaeTKt4nNPP9Q6S6kU5kFqfPmE8nrkMAFD+0E1QAFF0mDno7NOb/Z7MyERDihzpE aKBNR07Zq/g2PZ2a/tCA6z5F6BwXuDrfqN4zWKke9yNJKGf5sSaWTMd8InU6aUXuuB 8r+6FNrscLXUwHRl3UArQezU+X0cZjdiMDU0uLcM= To: linux-media@vger.kernel.org From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Cc: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , Hans Verkuil , linux-kernel@vger.kernel.org, lkcamp@lists.libreplanetbr.org Reply-To: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Subject: [PATCH 1/3] media: vimc: Support multiple buscodes for each pixelformat Message-ID: <20200202155019.1029993-2-nfraprado@protonmail.com> In-Reply-To: <20200202155019.1029993-1-nfraprado@protonmail.com> References: <20200202155019.1029993-1-nfraprado@protonmail.com> Feedback-ID: cwTKJQq-dqva77NrgNeIaWzOvcDQqfI9VSy7DoyJdvgY6-nEE7fD-E-3GiKFHexW4OBWbzutmMZN6q4SflMDRw==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,BAYES_05, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@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. Signed-off-by: Nícolas F. R. A. Prado --- drivers/media/platform/vimc/vimc-common.c | 68 ++++++++++++++--------- drivers/media/platform/vimc/vimc-common.h | 9 ++- drivers/media/platform/vimc/vimc-scaler.c | 10 +++- drivers/media/platform/vimc/vimc-sensor.c | 6 +- 4 files changed, 61 insertions(+), 32 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-common.c b/drivers/media/platform/vimc/vimc-common.c index 16ce9f3b7c75..55797e5ab2b1 100644 --- a/drivers/media/platform/vimc/vimc-common.c +++ b/drivers/media/platform/vimc/vimc-common.c @@ -19,19 +19,19 @@ static const struct vimc_pix_map vimc_pix_map_list[] = { /* RGB formats */ { - .code = MEDIA_BUS_FMT_BGR888_1X24, + .code = {MEDIA_BUS_FMT_BGR888_1X24}, .pixelformat = V4L2_PIX_FMT_BGR24, .bpp = 3, .bayer = false, }, { - .code = MEDIA_BUS_FMT_RGB888_1X24, + .code = {MEDIA_BUS_FMT_RGB888_1X24}, .pixelformat = V4L2_PIX_FMT_RGB24, .bpp = 3, .bayer = false, }, { - .code = MEDIA_BUS_FMT_ARGB8888_1X32, + .code = {MEDIA_BUS_FMT_ARGB8888_1X32}, .pixelformat = V4L2_PIX_FMT_ARGB32, .bpp = 4, .bayer = false, @@ -39,49 +39,49 @@ static const struct vimc_pix_map vimc_pix_map_list[] = { /* Bayer formats */ { - .code = MEDIA_BUS_FMT_SBGGR8_1X8, + .code = {MEDIA_BUS_FMT_SBGGR8_1X8}, .pixelformat = V4L2_PIX_FMT_SBGGR8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGBRG8_1X8, + .code = {MEDIA_BUS_FMT_SGBRG8_1X8}, .pixelformat = V4L2_PIX_FMT_SGBRG8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGRBG8_1X8, + .code = {MEDIA_BUS_FMT_SGRBG8_1X8}, .pixelformat = V4L2_PIX_FMT_SGRBG8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SRGGB8_1X8, + .code = {MEDIA_BUS_FMT_SRGGB8_1X8}, .pixelformat = V4L2_PIX_FMT_SRGGB8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SBGGR10_1X10, + .code = {MEDIA_BUS_FMT_SBGGR10_1X10}, .pixelformat = V4L2_PIX_FMT_SBGGR10, .bpp = 2, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGBRG10_1X10, + .code = {MEDIA_BUS_FMT_SGBRG10_1X10}, .pixelformat = V4L2_PIX_FMT_SGBRG10, .bpp = 2, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGRBG10_1X10, + .code = {MEDIA_BUS_FMT_SGRBG10_1X10}, .pixelformat = V4L2_PIX_FMT_SGRBG10, .bpp = 2, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SRGGB10_1X10, + .code = {MEDIA_BUS_FMT_SRGGB10_1X10}, .pixelformat = V4L2_PIX_FMT_SRGGB10, .bpp = 2, .bayer = true, @@ -89,25 +89,25 @@ static const struct vimc_pix_map vimc_pix_map_list[] = { /* 10bit raw bayer a-law compressed to 8 bits */ { - .code = MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8, + .code = {MEDIA_BUS_FMT_SBGGR10_ALAW8_1X8}, .pixelformat = V4L2_PIX_FMT_SBGGR10ALAW8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8, + .code = {MEDIA_BUS_FMT_SGBRG10_ALAW8_1X8}, .pixelformat = V4L2_PIX_FMT_SGBRG10ALAW8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8, + .code = {MEDIA_BUS_FMT_SGRBG10_ALAW8_1X8}, .pixelformat = V4L2_PIX_FMT_SGRBG10ALAW8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8, + .code = {MEDIA_BUS_FMT_SRGGB10_ALAW8_1X8}, .pixelformat = V4L2_PIX_FMT_SRGGB10ALAW8, .bpp = 1, .bayer = true, @@ -115,49 +115,49 @@ static const struct vimc_pix_map vimc_pix_map_list[] = { /* 10bit raw bayer DPCM compressed to 8 bits */ { - .code = MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8, + .code = {MEDIA_BUS_FMT_SBGGR10_DPCM8_1X8}, .pixelformat = V4L2_PIX_FMT_SBGGR10DPCM8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8, + .code = {MEDIA_BUS_FMT_SGBRG10_DPCM8_1X8}, .pixelformat = V4L2_PIX_FMT_SGBRG10DPCM8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8, + .code = {MEDIA_BUS_FMT_SGRBG10_DPCM8_1X8}, .pixelformat = V4L2_PIX_FMT_SGRBG10DPCM8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8, + .code = {MEDIA_BUS_FMT_SRGGB10_DPCM8_1X8}, .pixelformat = V4L2_PIX_FMT_SRGGB10DPCM8, .bpp = 1, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SBGGR12_1X12, + .code = {MEDIA_BUS_FMT_SBGGR12_1X12}, .pixelformat = V4L2_PIX_FMT_SBGGR12, .bpp = 2, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGBRG12_1X12, + .code = {MEDIA_BUS_FMT_SGBRG12_1X12}, .pixelformat = V4L2_PIX_FMT_SGBRG12, .bpp = 2, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SGRBG12_1X12, + .code = {MEDIA_BUS_FMT_SGRBG12_1X12}, .pixelformat = V4L2_PIX_FMT_SGRBG12, .bpp = 2, .bayer = true, }, { - .code = MEDIA_BUS_FMT_SRGGB12_1X12, + .code = {MEDIA_BUS_FMT_SRGGB12_1X12}, .pixelformat = V4L2_PIX_FMT_SRGGB12, .bpp = 2, .bayer = true, @@ -182,13 +182,29 @@ const struct vimc_pix_map *vimc_pix_map_by_index(unsigned int i) return &vimc_pix_map_list[i]; } +const u32 vimc_mbus_code_by_index(unsigned int i) +{ + unsigned int j, k; + + for (j = 0; j < ARRAY_SIZE(vimc_pix_map_list); j++) { + for (k = 0; vimc_pix_map_list[j].code[k]; k++) { + if (!i) + return vimc_pix_map_list[j].code[k]; + i--; + } + } + return 0; +} + const struct vimc_pix_map *vimc_pix_map_by_code(u32 code) { - unsigned int i; + unsigned int i, j; for (i = 0; i < ARRAY_SIZE(vimc_pix_map_list); i++) { - if (vimc_pix_map_list[i].code == code) - return &vimc_pix_map_list[i]; + for (j = 0; j < ARRAY_SIZE(vimc_pix_map_list[i].code); j++) { + if (vimc_pix_map_list[i].code[j] == code) + return &vimc_pix_map_list[i]; + } } return NULL; } diff --git a/drivers/media/platform/vimc/vimc-common.h b/drivers/media/platform/vimc/vimc-common.h index 87eb8259c2a8..132a5889f1ea 100644 --- a/drivers/media/platform/vimc/vimc-common.h +++ b/drivers/media/platform/vimc/vimc-common.h @@ -69,7 +69,7 @@ do { \ * V4L2_PIX_FMT_* fourcc pixelformat and its bytes per pixel (bpp) */ struct vimc_pix_map { - unsigned int code; + unsigned int code[3]; unsigned int bpp; u32 pixelformat; bool bayer; @@ -171,6 +171,13 @@ void vimc_sen_rm(struct vimc_device *vimc, struct vimc_ent_device *ved); */ const struct vimc_pix_map *vimc_pix_map_by_index(unsigned int i); +/** + * vimc_mbus_code_by_index - get mbus code by its index + * + * @i: index of the mbus code in vimc_pix_map_list + */ +const u32 vimc_mbus_code_by_index(unsigned int i); + /** * vimc_pix_map_by_code - get vimc_pix_map struct by media bus code * diff --git a/drivers/media/platform/vimc/vimc-scaler.c b/drivers/media/platform/vimc/vimc-scaler.c index e2e551bc3ded..d2ba0a2cfcc4 100644 --- a/drivers/media/platform/vimc/vimc-scaler.c +++ b/drivers/media/platform/vimc/vimc-scaler.c @@ -110,13 +110,19 @@ static int vimc_sca_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) { - const struct vimc_pix_map *vpix = vimc_pix_map_by_index(code->index); + const u32 mbus_code = vimc_mbus_code_by_index(code->index); + const struct vimc_pix_map *vpix; + + if (!mbus_code) + return -EINVAL; + + vpix = vimc_pix_map_by_code(mbus_code); /* We don't support bayer format */ if (!vpix || vpix->bayer) return -EINVAL; - code->code = vpix->code; + code->code = mbus_code; return 0; } diff --git a/drivers/media/platform/vimc/vimc-sensor.c b/drivers/media/platform/vimc/vimc-sensor.c index 32380f504591..9f4dd7fee9ab 100644 --- a/drivers/media/platform/vimc/vimc-sensor.c +++ b/drivers/media/platform/vimc/vimc-sensor.c @@ -52,12 +52,12 @@ static int vimc_sen_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) { - const struct vimc_pix_map *vpix = vimc_pix_map_by_index(code->index); + const u32 mbus_code = vimc_mbus_code_by_index(code->index); - if (!vpix) + if (!mbus_code) return -EINVAL; - code->code = vpix->code; + code->code = mbus_code; return 0; } From patchwork Sun Feb 2 15:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 61393 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyHVB-00H8vr-5Z; Sun, 02 Feb 2020 15:49:37 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726992AbgBBPuv (ORCPT + 1 other); Sun, 2 Feb 2020 10:50:51 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:11801 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbgBBPuv (ORCPT ); Sun, 2 Feb 2020 10:50:51 -0500 Date: Sun, 02 Feb 2020 15:50:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1580658649; bh=zW6Svbt5NnA5y5wS8kTvIgyaL51d8CkmvjMU7/bynj8=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References: Feedback-ID:From; b=Xxm6BKKnOQVIA6ZIVgLDrqD0Nvpz3FfUy+5UCbJ88JgDtT0EqMdi2fopJb5LYWxgx U4dE6cffhaQn+ea6YMF6o755OwZZe238gWMe4TG9O2dfyg1+kUyHtr/exOPpFsdBJr RG1TPErAcFpAsGCd/LCkVggf+v0SqBep07FLjUJ8= To: linux-media@vger.kernel.org From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Cc: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , Hans Verkuil , linux-kernel@vger.kernel.org, lkcamp@lists.libreplanetbr.org Reply-To: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Subject: [PATCH 2/3] media: vimc: Add GBR media bus code Message-ID: <20200202155019.1029993-3-nfraprado@protonmail.com> In-Reply-To: <20200202155019.1029993-1-nfraprado@protonmail.com> References: <20200202155019.1029993-1-nfraprado@protonmail.com> Feedback-ID: cwTKJQq-dqva77NrgNeIaWzOvcDQqfI9VSy7DoyJdvgY6-nEE7fD-E-3GiKFHexW4OBWbzutmMZN6q4SflMDRw==:Ext:ProtonMail MIME-Version: 1.0 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=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add missing GBR888_1X24 media bus code in the vimc_pix_map_list. Since there is no pixel format for it, use the pixelformat for RGB. Co-developed-by: Vitor Massaru Iha Signed-off-by: Vitor Massaru Iha Signed-off-by: Nícolas F. R. A. Prado --- drivers/media/platform/vimc/vimc-common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/media/platform/vimc/vimc-common.c b/drivers/media/platform/vimc/vimc-common.c index 55797e5ab2b1..591a50f63766 100644 --- a/drivers/media/platform/vimc/vimc-common.c +++ b/drivers/media/platform/vimc/vimc-common.c @@ -25,7 +25,7 @@ static const struct vimc_pix_map vimc_pix_map_list[] = { .bayer = false, }, { - .code = {MEDIA_BUS_FMT_RGB888_1X24}, + .code = {MEDIA_BUS_FMT_RGB888_1X24, MEDIA_BUS_FMT_GBR888_1X24}, .pixelformat = V4L2_PIX_FMT_RGB24, .bpp = 3, .bayer = false, From patchwork Sun Feb 2 15:50:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= X-Patchwork-Id: 61394 X-Patchwork-Delegate: hverkuil@xs4all.nl Received: from vger.kernel.org ([209.132.180.67]) by www.linuxtv.org with esmtp (Exim 4.92) (envelope-from ) id 1iyHVF-00H8vr-Tm; Sun, 02 Feb 2020 15:49:42 +0000 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727145AbgBBPu7 (ORCPT + 1 other); Sun, 2 Feb 2020 10:50:59 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:22736 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726881AbgBBPu7 (ORCPT ); Sun, 2 Feb 2020 10:50:59 -0500 Date: Sun, 02 Feb 2020 15:50:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1580658657; bh=6kUBFxuC2rO7/kfngE/XoXma3JcXpxCqXT3zxI0Rd0Y=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References: Feedback-ID:From; b=q0CxtXNIZLgcY7UFWJbjtll1UPkYMV+czY3JTpRMle7TMfUupVBspGV7O4E1nLzOE O8Q91Vg0KwNBHIKvDjgiqNZUU5FjwhogCz2uJGSqkL/idXSAM9aEfdnr+BR69esiF/ 0BUBrP91sn3t/n7RjmlqE52SGAms5zXAXuD0MI68= To: linux-media@vger.kernel.org From: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Cc: Helen Koike , Shuah Khan , Mauro Carvalho Chehab , Hans Verkuil , linux-kernel@vger.kernel.org, lkcamp@lists.libreplanetbr.org Reply-To: =?utf-8?b?TsOtY29sYXMgRi4gUi4gQS4gUHJhZG8=?= Subject: [PATCH 3/3] media: vimc: deb: Add support for GBR and BGR bus formats on source pad Message-ID: <20200202155019.1029993-4-nfraprado@protonmail.com> In-Reply-To: <20200202155019.1029993-1-nfraprado@protonmail.com> References: <20200202155019.1029993-1-nfraprado@protonmail.com> Feedback-ID: cwTKJQq-dqva77NrgNeIaWzOvcDQqfI9VSy7DoyJdvgY6-nEE7fD-E-3GiKFHexW4OBWbzutmMZN6q4SflMDRw==:Ext:ProtonMail MIME-Version: 1.0 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=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add support for GBR and BGR media bus formats for the source pad of debayer subdevices. Co-developed-by: Vitor Massaru Iha Signed-off-by: Vitor Massaru Iha Signed-off-by: Nícolas F. R. A. Prado --- drivers/media/platform/vimc/vimc-debayer.c | 53 +++++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/drivers/media/platform/vimc/vimc-debayer.c b/drivers/media/platform/vimc/vimc-debayer.c index 5d1b67d684bb..463cafbe107e 100644 --- a/drivers/media/platform/vimc/vimc-debayer.c +++ b/drivers/media/platform/vimc/vimc-debayer.c @@ -51,6 +51,11 @@ static const struct v4l2_mbus_framefmt sink_fmt_default = { .colorspace = V4L2_COLORSPACE_DEFAULT, }; +static const u32 src_rgb_codes[] = { + MEDIA_BUS_FMT_BGR888_1X24, + MEDIA_BUS_FMT_RGB888_1X24, + MEDIA_BUS_FMT_GBR888_1X24}; + static const struct vimc_deb_pix_map vimc_deb_pix_map_list[] = { { .code = MEDIA_BUS_FMT_SBGGR8_1X8, @@ -148,14 +153,11 @@ static int vimc_deb_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_mbus_code_enum *code) { - /* We only support one format for source pads */ if (VIMC_IS_SRC(code->pad)) { - struct vimc_deb_device *vdeb = v4l2_get_subdevdata(sd); - - if (code->index) + if (code->index >= ARRAY_SIZE(src_rgb_codes)) return -EINVAL; - code->code = vdeb->src_code; + code->code = src_rgb_codes[code->index]; } else { if (code->index >= ARRAY_SIZE(vimc_deb_pix_map_list)) return -EINVAL; @@ -170,7 +172,7 @@ static int vimc_deb_enum_frame_size(struct v4l2_subdev *sd, struct v4l2_subdev_pad_config *cfg, struct v4l2_subdev_frame_size_enum *fse) { - struct vimc_deb_device *vdeb = v4l2_get_subdevdata(sd); + int i; if (fse->index) return -EINVAL; @@ -181,8 +183,13 @@ static int vimc_deb_enum_frame_size(struct v4l2_subdev *sd, if (!vpix) return -EINVAL; - } else if (fse->code != vdeb->src_code) { - return -EINVAL; + } else { + for (i = 0; i < ARRAY_SIZE(src_rgb_codes); i++) { + if (src_rgb_codes[i] == fse->code) + break; + } + if (i == ARRAY_SIZE(src_rgb_codes)) + return -EINVAL; } fse->min_width = VIMC_FRAME_MIN_WIDTH; @@ -237,6 +244,8 @@ static int vimc_deb_set_fmt(struct v4l2_subdev *sd, { struct vimc_deb_device *vdeb = v4l2_get_subdevdata(sd); struct v4l2_mbus_framefmt *sink_fmt; + unsigned int i; + u32 *src_code; if (fmt->which == V4L2_SUBDEV_FORMAT_ACTIVE) { /* Do not change the format while stream is on */ @@ -244,8 +253,10 @@ static int vimc_deb_set_fmt(struct v4l2_subdev *sd, return -EBUSY; sink_fmt = &vdeb->sink_fmt; + src_code = &vdeb->src_code; } else { sink_fmt = v4l2_subdev_get_try_format(sd, cfg, 0); + src_code = &v4l2_subdev_get_try_format(sd, cfg, 1)->code; } /* @@ -253,9 +264,17 @@ static int vimc_deb_set_fmt(struct v4l2_subdev *sd, * it is propagated from the sink */ if (VIMC_IS_SRC(fmt->pad)) { + u32 code = fmt->format.code; + fmt->format = *sink_fmt; - /* TODO: Add support for other formats */ - fmt->format.code = vdeb->src_code; + + for (i = 0; i < ARRAY_SIZE(src_rgb_codes); i++) { + if (src_rgb_codes[i] == code) { + *src_code = src_rgb_codes[i]; + break; + } + } + fmt->format.code = *src_code; } else { /* Set the new format in the sink pad */ vimc_deb_adjust_sink_fmt(&fmt->format); @@ -291,11 +310,21 @@ static void vimc_deb_set_rgb_mbus_fmt_rgb888_1x24(struct vimc_deb_device *vdeb, unsigned int col, unsigned int rgb[3]) { + const struct vimc_pix_map *vpix; unsigned int i, index; + vpix = vimc_pix_map_by_code(vdeb->src_code); index = VIMC_FRAME_INDEX(lin, col, vdeb->sink_fmt.width, 3); - for (i = 0; i < 3; i++) - vdeb->src_frame[index + i] = rgb[i]; + for (i = 0; i < 3; i++) { + switch (vpix->pixelformat) { + case V4L2_PIX_FMT_RGB24: + vdeb->src_frame[index + i] = rgb[i]; + break; + case V4L2_PIX_FMT_BGR24: + vdeb->src_frame[index + i] = rgb[2-i]; + break; + } + } } static int vimc_deb_s_stream(struct v4l2_subdev *sd, int enable)