From patchwork Tue Jan 17 10:06:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 643611 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 E4581C63797 for ; Tue, 17 Jan 2023 10:06:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235924AbjAQKGW (ORCPT ); Tue, 17 Jan 2023 05:06:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236177AbjAQKGS (ORCPT ); Tue, 17 Jan 2023 05:06:18 -0500 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 358E8233EB for ; Tue, 17 Jan 2023 02:06:17 -0800 (PST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 666D9471; Tue, 17 Jan 2023 11:06:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1673949975; bh=cr+JQslaV58s0DiIMenMI1qSEERNXogOyCZmYQqXaxw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u+cFnsrRI/IKB5EjeV+EwDIEdD6vK9DRCASW9R0/fPq0jYMjsVUcSkNJ/k8mFDGoU wKTGsJMYJ8aFBm9Z3853pH9qhNfvZMLA2pepbGDpUoqDTgY0QJdal3Os3fBtHp7QRX DM+AAOhwuxSUwGoYWaPBYRrJIwo6n68knRVD2qLA= From: Jacopo Mondi To: Robert Mader , Sakari Ailus , Dave Stevenson , Laurent Pinchart Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH 1/3] media: imx258: Parse and register properties Date: Tue, 17 Jan 2023 11:06:01 +0100 Message-Id: <20230117100603.51631-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230117100603.51631-1-jacopo.mondi@ideasonboard.com> References: <20230117100603.51631-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Robert Mader Analogous to e.g. the imx219. This enables propagating V4L2_CID_CAMERA_ORIENTATION and V4L2_CID_CAMERA_SENSOR_ROTATION values. The motivation is to allow libcamera detect these values from the device tree and propagate them further to e.g. Pipewire. While at it, reserve space for 3 additional controls even if v4l2_ctrl_new_fwnode_properties() can only register 2 of them, to fix the existing implementation which reserve space for 8 controls but actually registers 9. Signed-off-by: Robert Mader Signed-off-by: Jacopo Mondi ---- Changes in v2: - Reserve 11 instead of 10 controls - Change order of variable declaration - Slightly extend description Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx258.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index eab5fc1ee2f7..3b560865b657 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #define IMX258_REG_VALUE_08BIT 1 @@ -1148,6 +1149,7 @@ static const struct v4l2_subdev_internal_ops imx258_internal_ops = { static int imx258_init_controls(struct imx258 *imx258) { struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); + struct v4l2_fwnode_device_properties props; struct v4l2_ctrl_handler *ctrl_hdlr; s64 vblank_def; s64 vblank_min; @@ -1156,7 +1158,7 @@ static int imx258_init_controls(struct imx258 *imx258) int ret; ctrl_hdlr = &imx258->ctrl_handler; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 11); if (ret) return ret; @@ -1232,6 +1234,15 @@ static int imx258_init_controls(struct imx258 *imx258) goto error; } + ret = v4l2_fwnode_device_parse(&client->dev, &props); + if (ret) + goto error; + + ret = v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &imx258_ctrl_ops, + &props); + if (ret) + goto error; + imx258->sd.ctrl_handler = ctrl_hdlr; return 0; From patchwork Tue Jan 17 10:06:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 644498 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 B1EF5C3DA78 for ; Tue, 17 Jan 2023 10:06:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236200AbjAQKGX (ORCPT ); Tue, 17 Jan 2023 05:06:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236168AbjAQKGT (ORCPT ); Tue, 17 Jan 2023 05:06:19 -0500 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 B05603C1D for ; Tue, 17 Jan 2023 02:06:18 -0800 (PST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EC0E04DA; Tue, 17 Jan 2023 11:06:15 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1673949976; bh=cfkzyLcKhj/ywgrgeqLB3xESZbwTqbC7fzhNfn9xhwI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=shPdm8DpnkkF6CWTYHCDfbkpFi1FrKIxFNOcTKIKveSJzboKhQ6lmX7uuAR7EYk70 gWarYW2A04V5c68XGNEu+R0cEnpqZPMUn8crhw1JTi7MZpS2wQ+VolEsz5K3J/EBCi EffoJv4c7NFyqFsv8r3eRSCRuFnF6nJSm9GBDm48= From: Jacopo Mondi To: Robert Mader , Sakari Ailus , Dave Stevenson , Laurent Pinchart Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH 2/3] media: imx258: Register H/V flip controls Date: Tue, 17 Jan 2023 11:06:02 +0100 Message-Id: <20230117100603.51631-3-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230117100603.51631-1-jacopo.mondi@ideasonboard.com> References: <20230117100603.51631-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Register controls for V4L2_CID_HFLIP and V4L2_CID_VFLIP. The controls are registered as read-only and enabled by default, as the driver embeds a 180 degrees rotation in its programming sequences and only supports that mode of operations. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx258.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 3b560865b657..2e0a4ea76589 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -1151,6 +1151,7 @@ static int imx258_init_controls(struct imx258 *imx258) struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); struct v4l2_fwnode_device_properties props; struct v4l2_ctrl_handler *ctrl_hdlr; + struct v4l2_ctrl *vflip, *hflip; s64 vblank_def; s64 vblank_min; s64 pixel_rate_min; @@ -1158,7 +1159,7 @@ static int imx258_init_controls(struct imx258 *imx258) int ret; ctrl_hdlr = &imx258->ctrl_handler; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 11); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 13); if (ret) return ret; @@ -1174,6 +1175,17 @@ static int imx258_init_controls(struct imx258 *imx258) if (imx258->link_freq) imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + /* The driver only supports one bayer order and flips by default. */ + hflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, + V4L2_CID_HFLIP, 1, 1, 1, 1); + if (hflip) + hflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; + + vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, + V4L2_CID_VFLIP, 1, 1, 1, 1); + if (vflip) + vflip->flags |= V4L2_CTRL_FLAG_READ_ONLY; + pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]); pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]); /* By default, PIXEL_RATE is read only */ From patchwork Tue Jan 17 10:06:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 643610 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 5C04FC63797 for ; Tue, 17 Jan 2023 10:06:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236456AbjAQKGZ (ORCPT ); Tue, 17 Jan 2023 05:06:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236322AbjAQKGU (ORCPT ); Tue, 17 Jan 2023 05:06:20 -0500 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 50AC355B9 for ; Tue, 17 Jan 2023 02:06:19 -0800 (PST) Received: from uno.LocalDomain (93-61-96-190.ip145.fastwebnet.it [93.61.96.190]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 7A9607F8; Tue, 17 Jan 2023 11:06:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1673949976; bh=BbVeU0ZB9FlKBNkjcH4UQ7CiKDsYh81QfmeO39Bwbbw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sEo67zANDFNeJf6oWMyLkzO+RT9s3a2gA7Ey3mwxmYEchY0qrN6MtdP+yfjd9oV7z EM/d2XjbqTpPF2VSjdGpUFOY1PzLAF+1yuMvQGPBQVajHOp+5wPSv11R2LhSbsG4M5 KDPcmigBAAAQ07X2yvxMTwDRk1jfic2a/W5RkPaM= From: Jacopo Mondi To: Robert Mader , Sakari Ailus , Dave Stevenson , Laurent Pinchart Cc: Jacopo Mondi , linux-media@vger.kernel.org Subject: [PATCH 3/3] media: imx258: Remove mandatory 180 degrees rotation Date: Tue, 17 Jan 2023 11:06:03 +0100 Message-Id: <20230117100603.51631-4-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230117100603.51631-1-jacopo.mondi@ideasonboard.com> References: <20230117100603.51631-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The "rotation" fwnode device property is intended to allow specify the sensor's physical mounting rotation, so that it can be exposed through the read-only V4L2_CID_CAMERA_SENSOR_ROTATION control and applications can decide how to compensate for that. The imx258 driver has read-only VFLIP and HFLIP enabled, resulting in a 180 degrees image rotation being produced by the sensor. But this doesn't imply that the physical mounting rotation should match the driver's implementation. Now that the driver registers V4L2_CID_CAMERA_SENSOR_ROTATION and V4L2_CID_HFLIP/VFLIP correctly, userspace has all the required information to handle the rotation correctly, hence it is not necessary to require the 'rotation' property to be fixed to 180 degrees in DTS. Signed-off-by: Jacopo Mondi Reviewed-by: Laurent Pinchart --- drivers/media/i2c/imx258.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/media/i2c/imx258.c b/drivers/media/i2c/imx258.c index 2e0a4ea76589..85d73b186111 100644 --- a/drivers/media/i2c/imx258.c +++ b/drivers/media/i2c/imx258.c @@ -1299,14 +1299,6 @@ static int imx258_probe(struct i2c_client *client) return -EINVAL; } - /* - * Check that the device is mounted upside down. The driver only - * supports a single pixel order right now. - */ - ret = device_property_read_u32(&client->dev, "rotation", &val); - if (ret || val != 180) - return -EINVAL; - /* Initialize subdev */ v4l2_i2c_subdev_init(&imx258->sd, client, &imx258_subdev_ops);