From patchwork Tue Jul 25 20:02:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 710055 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FE73C001DF for ; Tue, 25 Jul 2023 20:02:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230356AbjGYUCq (ORCPT ); Tue, 25 Jul 2023 16:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47702 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230036AbjGYUCp (ORCPT ); Tue, 25 Jul 2023 16:02:45 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56F4413D for ; Tue, 25 Jul 2023 13:02:44 -0700 (PDT) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9308FA06; Tue, 25 Jul 2023 22:01:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690315304; bh=N/G4Rw52ADbI9DKz4l6i2bEU2g7eQa+T2Gx17itGjGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IlHwV6i+p/Butfc7liOuutQDU7rMKI1H0gTn7MKxdJS9JNeIFN1XbEZXujpBAMAAp m/j5XDASDx/H9wRV14VpzjcV9AHNJL2R7XA7rqPt9zU0VASKFCzGDcOM1ySZdWVl7i Hmh0fJz4fc0+2dxXrjsfRBvZJZfB5orq69rC+aHM= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Rui Miguel Silva , Alexander Stein , Tim Harvey , Fabio Estevam , NXP Linux Team , Pengutronix Kernel Team , Martin Kepplinger , Purism Kernel Team Subject: [PATCH v3 1/3] media: imx: imx7-media-csi: Fix applying format constraints Date: Tue, 25 Jul 2023 23:02:47 +0300 Message-Id: <20230725200249.15447-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230725200249.15447-1-laurent.pinchart@ideasonboard.com> References: <20230725200249.15447-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Fabio Estevam v4l_bound_align_image() aligns to a multiple of 2 to the power of walign, not to walign. Depending on the pixel format, this causes the image width to be aligned to 16 or 256 pixels instead of 4 or 8 as required by the hardware. Fix it by rounding and clamping the width and height manually. Reported-by: Tim Harvey Closes: https://lore.kernel.org/linux-media/CAJ+vNU0BOVLTL17ofgHwtexbpuMYwH_aGUC==EXABUtHHiv_ag@mail.gmail.com Fixes: 6f482c4729d9 ("media: imx: imx7-media-csi: Get rid of superfluous call to imx7_csi_mbus_fmt_to_pix_fmt") Co-developed-by: Alexander Stein Signed-off-by: Alexander Stein Signed-off-by: Fabio Estevam Signed-off-by: Laurent Pinchart --- Changes since v2: - Don't export clamp_roundup() from v4l2-common.c - Simply clamp the height as no alignment is needed - Add required includes --- drivers/media/platform/nxp/imx7-media-csi.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c index 2ec1f3cd56a0..5684ecd2e3fe 100644 --- a/drivers/media/platform/nxp/imx7-media-csi.c +++ b/drivers/media/platform/nxp/imx7-media-csi.c @@ -9,7 +9,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -1137,8 +1139,9 @@ __imx7_csi_video_try_fmt(struct v4l2_pix_format *pixfmt, * TODO: Implement configurable stride support. */ walign = 8 * 8 / cc->bpp; - v4l_bound_align_image(&pixfmt->width, 1, 0xffff, walign, - &pixfmt->height, 1, 0xffff, 1, 0); + pixfmt->width = clamp(round_up(pixfmt->width, walign), walign, + round_down(65535U, walign)); + pixfmt->height = clamp(pixfmt->height, 1U, 65535U); pixfmt->bytesperline = pixfmt->width * cc->bpp / 8; pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height; From patchwork Tue Jul 25 20:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 710054 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3282AEB64DD for ; Tue, 25 Jul 2023 20:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230508AbjGYUCt (ORCPT ); Tue, 25 Jul 2023 16:02:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230466AbjGYUCs (ORCPT ); Tue, 25 Jul 2023 16:02:48 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F21D11AA for ; Tue, 25 Jul 2023 13:02:46 -0700 (PDT) Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E730EBA; Tue, 25 Jul 2023 22:01:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1690315307; bh=Z6CZgG7T8JEZSovTygTu1oLATimETM1rJjKJucL9X4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cjOek2R5dn3GjicXsQAURkAyAomfZiuCnAo72dV/8w6O/AEQOIcUOrZeqVcv6SyNb o1B8YJt6tJa6DTEWIGXPl0dTPBOtM12s+cdABZp8rFZoU3mLGMzTDFvrTRxKU6wAZF k+ExiWwm1a4IDWOz+odaHih0Oc1JOjteePaIAj4M= From: Laurent Pinchart To: linux-media@vger.kernel.org Cc: Rui Miguel Silva , Alexander Stein , Tim Harvey , Fabio Estevam , NXP Linux Team , Pengutronix Kernel Team , Martin Kepplinger , Purism Kernel Team Subject: [PATCH v3 3/3] media: imx: imx7-media-csi: Include headers explicitly Date: Tue, 25 Jul 2023 23:02:49 +0300 Message-Id: <20230725200249.15447-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230725200249.15447-1-laurent.pinchart@ideasonboard.com> References: <20230725200249.15447-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Include all the headers that the driver needs explicitly instead of relying on indirect inclusion. While at it, drop a few unneeded headers. Signed-off-by: Laurent Pinchart --- drivers/media/platform/nxp/imx7-media-csi.c | 27 ++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/drivers/media/platform/nxp/imx7-media-csi.c b/drivers/media/platform/nxp/imx7-media-csi.c index 3aa7978d3f8a..95e9f22f21be 100644 --- a/drivers/media/platform/nxp/imx7-media-csi.c +++ b/drivers/media/platform/nxp/imx7-media-csi.c @@ -3,31 +3,46 @@ * V4L2 Capture CSI Subdev for Freescale i.MX6UL/L / i.MX7 SOC * * Copyright (c) 2019 Linaro Ltd - * */ #include +#include +#include #include +#include +#include +#include #include +#include +#include +#include +#include #include -#include #include #include +#include #include -#include -#include #include -#include +#include #include #include +#include +#include #include +#include +#include +#include +#include +#include #include -#include +#include #include #include #include +#include #include +#include #define IMX7_CSI_PAD_SINK 0 #define IMX7_CSI_PAD_SRC 1