From patchwork Fri Feb 18 18:34:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 12751745 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1ACF9C433EF for ; Fri, 18 Feb 2022 18:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QOxUV/PPA5BD02enSCro9EZwcybJoB0bjJx3i4D6zA8=; b=b/LLX9AbVRdnWU QHeHS+i3Y+qwmfsIZUkO+vLcupUbPRo9hrqYOcXIz6zS/KPXofQkrQHhRJFzPR2Ve6OtIKM4DTmLB I76p9iRkH1CnQRCZbA/t0F4r4dCAzNojfYHxC3VGV2W9Dpd+DaJ+gFqeC3XuhBJuGoXXDpyO0c5S/ LGSCCALflIePeTrd2bx45cMJ5auwegG8/SY48z4WZLyf4GV4/6S9sCdPQ91fhZapLelTWQM+1GpRM fKiIt63zMOPZjeLCjhP3cjFbtrsaezJHpcE1LgXXBTm6ofUhmy8RYri3rcedeMGz7nOqp2jXzCF3X viein1kMUiqan0FdSMqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL87k-00FWVj-Au; Fri, 18 Feb 2022 18:36:56 +0000 Received: from relay2-d.mail.gandi.net ([2001:4b98:dc4:8::222]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nL86p-00FW6k-8k for linux-arm-kernel@lists.infradead.org; Fri, 18 Feb 2022 18:36:01 +0000 Received: (Authenticated sender: jacopo@jmondi.org) by mail.gandi.net (Postfix) with ESMTPSA id 0106540002; Fri, 18 Feb 2022 18:35:54 +0000 (UTC) From: Jacopo Mondi To: slongerbeam@gmail.com, p.zabel@pengutronix.de, shawnguo@kernel.org, s.hauer@pengutronix.de, festevam@gmail.com, mchehab@kernel.org, hverkuil-cisco@xs4all.nl, laurent.pinchart@ideasonboard.com, martin.kepplinger@puri.sm, rmfrfs@gmail.com, xavier.roumegue@oss.nxp.com, alexander.stein@ew.tq-group.com, dorota.czaplejewicz@puri.sm Cc: kernel@pengutronix.de, linux-imx@nxp.com, linux-media@vger.kernel.org, linux-staging@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Jacopo Mondi Subject: [PATCH v2 7/7] media: imx: imx-mipi-csis: Add output format Date: Fri, 18 Feb 2022 19:34:21 +0100 Message-Id: <20220218183421.583874-8-jacopo@jmondi.org> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20220218183421.583874-1-jacopo@jmondi.org> References: <20220218183421.583874-1-jacopo@jmondi.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220218_103559_639455_05C7634B X-CRM114-Status: GOOD ( 14.46 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Due to how pixel components are transmitted on the CSI-2 serial bus and how they are stored in memory by the CSI-2 receiver, the component ordering might change and the image formats on the sink and source pads of the receiver should reflect it. For RGB24, in example, the component ordering on the wire as described by the CSI-2 specification matches the BGR888 format, while once stored in in memory by the CSIS receiver they match the RGB888 format. Add an additional .output field to struct csis_pix_format to allow propagating the correct format to the source pad after a format configuration on the sink. The change is only relevant for RGB24 but paves the way for further format translations in future. Signed-off-by: Jacopo Mondi --- drivers/media/platform/imx/imx-mipi-csis.c | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/imx/imx-mipi-csis.c b/drivers/media/platform/imx/imx-mipi-csis.c index fdf133f81c5b..128f4180d1e9 100644 --- a/drivers/media/platform/imx/imx-mipi-csis.c +++ b/drivers/media/platform/imx/imx-mipi-csis.c @@ -351,6 +351,7 @@ struct csis_pix_format { u32 code; u32 data_type; u8 width; + u32 output; }; static const struct csis_pix_format mipi_csis_formats[] = { @@ -359,95 +360,117 @@ static const struct csis_pix_format mipi_csis_formats[] = { .code = MEDIA_BUS_FMT_UYVY8_1X16, .data_type = MIPI_CSI2_DATA_TYPE_YUV422_8, .width = 16, + .output = MEDIA_BUS_FMT_UYVY8_1X16, }, /* RGB formats. */ { .code = MEDIA_BUS_FMT_RGB565_1X16, .data_type = MIPI_CSI2_DATA_TYPE_RGB565, .width = 16, + .output = MEDIA_BUS_FMT_RGB565_1X16, }, { .code = MEDIA_BUS_FMT_BGR888_1X24, .data_type = MIPI_CSI2_DATA_TYPE_RGB888, .width = 24, + .output = MEDIA_BUS_FMT_RGB888_1X24, }, /* RAW (Bayer and greyscale) formats. */ { .code = MEDIA_BUS_FMT_SBGGR8_1X8, .data_type = MIPI_CSI2_DATA_TYPE_RAW8, .width = 8, + .output = MEDIA_BUS_FMT_SBGGR8_1X8, }, { .code = MEDIA_BUS_FMT_SGBRG8_1X8, .data_type = MIPI_CSI2_DATA_TYPE_RAW8, .width = 8, + .output = MEDIA_BUS_FMT_SGBRG8_1X8, }, { .code = MEDIA_BUS_FMT_SGRBG8_1X8, .data_type = MIPI_CSI2_DATA_TYPE_RAW8, .width = 8, + .output = MEDIA_BUS_FMT_SGRBG8_1X8, }, { .code = MEDIA_BUS_FMT_SRGGB8_1X8, .data_type = MIPI_CSI2_DATA_TYPE_RAW8, .width = 8, + .output = MEDIA_BUS_FMT_SRGGB8_1X8, }, { .code = MEDIA_BUS_FMT_Y8_1X8, .data_type = MIPI_CSI2_DATA_TYPE_RAW8, .width = 8, + .output = MEDIA_BUS_FMT_Y8_1X8, }, { .code = MEDIA_BUS_FMT_SBGGR10_1X10, .data_type = MIPI_CSI2_DATA_TYPE_RAW10, .width = 10, + .output = MEDIA_BUS_FMT_SBGGR10_1X10, }, { .code = MEDIA_BUS_FMT_SGBRG10_1X10, .data_type = MIPI_CSI2_DATA_TYPE_RAW10, .width = 10, + .output = MEDIA_BUS_FMT_SGBRG10_1X10, }, { .code = MEDIA_BUS_FMT_SGRBG10_1X10, .data_type = MIPI_CSI2_DATA_TYPE_RAW10, .width = 10, + .output = MEDIA_BUS_FMT_SGRBG10_1X10, }, { .code = MEDIA_BUS_FMT_SRGGB10_1X10, .data_type = MIPI_CSI2_DATA_TYPE_RAW10, .width = 10, + .output = MEDIA_BUS_FMT_SRGGB10_1X10, }, { .code = MEDIA_BUS_FMT_Y10_1X10, .data_type = MIPI_CSI2_DATA_TYPE_RAW10, .width = 10, + .output = MEDIA_BUS_FMT_Y10_1X10, }, { .code = MEDIA_BUS_FMT_SBGGR12_1X12, .data_type = MIPI_CSI2_DATA_TYPE_RAW12, .width = 12, + .output = MEDIA_BUS_FMT_SBGGR12_1X12, }, { .code = MEDIA_BUS_FMT_SGBRG12_1X12, .data_type = MIPI_CSI2_DATA_TYPE_RAW12, .width = 12, + .output = MEDIA_BUS_FMT_SGBRG12_1X12, }, { .code = MEDIA_BUS_FMT_SGRBG12_1X12, .data_type = MIPI_CSI2_DATA_TYPE_RAW12, .width = 12, + .output = MEDIA_BUS_FMT_SGRBG12_1X12, }, { .code = MEDIA_BUS_FMT_SRGGB12_1X12, .data_type = MIPI_CSI2_DATA_TYPE_RAW12, .width = 12, + .output = MEDIA_BUS_FMT_SRGGB12_1X12, }, { .code = MEDIA_BUS_FMT_Y12_1X12, .data_type = MIPI_CSI2_DATA_TYPE_RAW12, .width = 12, + .output = MEDIA_BUS_FMT_Y12_1X12, }, { .code = MEDIA_BUS_FMT_SBGGR14_1X14, .data_type = MIPI_CSI2_DATA_TYPE_RAW14, .width = 14, + .output = MEDIA_BUS_FMT_SBGGR14_1X14, }, { .code = MEDIA_BUS_FMT_SGBRG14_1X14, .data_type = MIPI_CSI2_DATA_TYPE_RAW14, .width = 14, + .output = MEDIA_BUS_FMT_SGBRG14_1X14, }, { .code = MEDIA_BUS_FMT_SGRBG14_1X14, .data_type = MIPI_CSI2_DATA_TYPE_RAW14, .width = 14, + .output = MEDIA_BUS_FMT_SGRBG14_1X14, }, { .code = MEDIA_BUS_FMT_SRGGB14_1X14, .data_type = MIPI_CSI2_DATA_TYPE_RAW14, .width = 14, + .output = MEDIA_BUS_FMT_SRGGB14_1X14, } }; @@ -1090,7 +1113,11 @@ static int mipi_csis_set_fmt(struct v4l2_subdev *sd, /* Propagate the format from sink to source. */ fmt = mipi_csis_get_format(state, sd_state, sdformat->which, CSIS_PAD_SOURCE); - *fmt = sdformat->format; + + /* The format on the source pad might change due to unpacking. */ + fmt->code = csis_fmt->output; + fmt->width = sdformat->format.width; + fmt->height = sdformat->format.height; /* Store the CSIS format descriptor for active formats. */ if (sdformat->which == V4L2_SUBDEV_FORMAT_ACTIVE)