From patchwork Tue Apr 18 10:04:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 13215380 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 28A9BC77B71 for ; Tue, 18 Apr 2023 10:05:07 +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=kkuvD5GCoqNr6w1LkYb2TCh+QJiPBsvglCKfSueRsXI=; b=U09agMZYXxe6QK zDoe7Pbsoxw+qdAFBeNcz7/+H72R3Qzsapml4yk3KRbq8cNT+yi/ds4JA70OU/TdD+Bqg7pOcjlK5 bCrp6AbfuZSWRpQBvak7QqzVM0Hxl8X2RZqDtoSsSHuHgVuMvHNoEaTW/1H/HK/fun6YhjWV9To3X iazukOCJ5X9D0sYmkkUZwPTO3oYx5eO8s+wNtEqcdElzZbClLO0QoRWgFhyRFnEl3V2CQ15AStR+L 1Xzt+M4r5NpcHAmFkr1Aydwq+L+tL4xq7zKn+VAmr9P5LkytkAJtGOGq5wFBrBTrdPWDlNz+k8f7z m7kYTdThtPOEyDvT48Sw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1poiC4-001a0F-2k; Tue, 18 Apr 2023 10:04:12 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1poiC1-001ZzN-2R for linux-arm-kernel@lists.infradead.org; Tue, 18 Apr 2023 10:04:11 +0000 Received: from pendragon.ideasonboard.com (133-32-181-51.west.xps.vectant.ne.jp [133.32.181.51]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 4895EF07; Tue, 18 Apr 2023 12:03:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1681812240; bh=10Ei9nqKwkA5fMOTYYArhMOWhmSN1lqc3pFQPXZlkdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pFJbZUvpZT1D9OZph+BhxCv1j8C8xzR7iW7bdcPsrhBJbkoUt72tr+TZ6NFgUrMVF cuNNB/NlxF7I6pG45mvROm9upuCLH52sXp9hPWBU2EZe54HLdpin19lH/xSNz2Q2Jm c1QnR8Apdf2AvWeu7rkbAsuYPxbcnYGQJZpaUk1U= From: Laurent Pinchart To: linux-media@vger.kernel.org, Alexander Stein Cc: Rui Miguel Silva , Mauro Carvalho Chehab , Shawn Guo , Sascha Hauer , Fabio Estevam , Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org Subject: [PATCH] media: imx: imx7-media-csi: Init default format with __imx7_csi_video_try_fmt() Date: Tue, 18 Apr 2023 13:04:17 +0300 Message-Id: <20230418100417.20428-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230418071439.197735-1-alexander.stein@ew.tq-group.com> References: <20230418071439.197735-1-alexander.stein@ew.tq-group.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230418_030409_943113_558EFE43 X-CRM114-Status: GOOD ( 15.12 ) 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 Use the __imx7_csi_video_try_fmt() helper function to initialize the default format at probe time. This improves consistency by using the same code path for both default initialization and validation at runtime, and allows dropping the now unused imx7_csi_find_pixel_format() function. Signed-off-by: Laurent Pinchart --- Hi Alexander, This is an additional cleanup that applies on top of "[PATCH v2 0/3] Fix imx7-media-csi format settings". I've only compile-tested it as I'm currently lacking access to test hardware. Would you be able to test the patch ? If so, could you please include it in the v2 of your series ? --- drivers/media/platform/nxp/imx7-media-csi.c | 55 +++------------------ 1 file changed, 6 insertions(+), 49 deletions(-) diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c index 5240670476b2..e52d617eea59 100644 --- a/drivers/media/platform/nxp/imx7-media-csi.c +++ b/drivers/media/platform/nxp/imx7-media-csi.c @@ -1014,39 +1014,6 @@ static int imx7_csi_enum_mbus_formats(u32 *code, u32 index) return -EINVAL; } -static int imx7_csi_mbus_fmt_to_pix_fmt(struct v4l2_pix_format *pix, - const struct v4l2_mbus_framefmt *mbus, - const struct imx7_csi_pixfmt *cc) -{ - u32 width; - u32 stride; - - if (!cc) { - cc = imx7_csi_find_mbus_format(mbus->code); - if (!cc) - return -EINVAL; - } - - /* Round up width for minimum burst size */ - width = round_up(mbus->width, 8); - - /* Round up stride for IDMAC line start address alignment */ - stride = round_up((width * cc->bpp) >> 3, 8); - - pix->width = width; - pix->height = mbus->height; - pix->pixelformat = cc->fourcc; - pix->colorspace = mbus->colorspace; - pix->xfer_func = mbus->xfer_func; - pix->ycbcr_enc = mbus->ycbcr_enc; - pix->quantization = mbus->quantization; - pix->field = mbus->field; - pix->bytesperline = stride; - pix->sizeimage = stride * pix->height; - - return 0; -} - /* ----------------------------------------------------------------------------- * Video Capture Device - IOCTLs */ @@ -1618,22 +1585,14 @@ static struct imx7_csi_vb2_buffer *imx7_csi_video_next_buf(struct imx7_csi *csi) return buf; } -static int imx7_csi_video_init_format(struct imx7_csi *csi) +static void imx7_csi_video_init_format(struct imx7_csi *csi) { - struct v4l2_mbus_framefmt format = { }; + struct v4l2_pix_format *pixfmt = &csi->vdev_fmt; - format.code = IMX7_CSI_DEF_MBUS_CODE; - format.width = IMX7_CSI_DEF_PIX_WIDTH; - format.height = IMX7_CSI_DEF_PIX_HEIGHT; - format.field = V4L2_FIELD_NONE; + pixfmt->width = IMX7_CSI_DEF_PIX_WIDTH; + pixfmt->height = IMX7_CSI_DEF_PIX_HEIGHT; - imx7_csi_mbus_fmt_to_pix_fmt(&csi->vdev_fmt, &format, NULL); - csi->vdev_compose.width = format.width; - csi->vdev_compose.height = format.height; - - csi->vdev_cc = imx7_csi_find_pixel_format(csi->vdev_fmt.pixelformat); - - return 0; + csi->vdev_cc = __imx7_csi_video_try_fmt(pixfmt, &csi->vdev_compose); } static int imx7_csi_video_register(struct imx7_csi *csi) @@ -1646,9 +1605,7 @@ static int imx7_csi_video_register(struct imx7_csi *csi) vdev->v4l2_dev = v4l2_dev; /* Initialize the default format and compose rectangle. */ - ret = imx7_csi_video_init_format(csi); - if (ret < 0) - return ret; + imx7_csi_video_init_format(csi); /* Register the video device. */ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);