From nobody Fri Oct 10 09:48:03 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 365001C7017; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=nabDwQNXcJpvvtTQxKw9ndRSK4SSaCcaOOJ9xUMwdTAypYUk7wSBh7aw51Fcy8BFO5pUz4/GOaE5WqLAxV1gC/1CyGVBHeUjFe8J2rPNjabnmGJuAlK8Dd7F8DCWYeqP7WqfP6W7S59FFmI+07KpYja/03a/Q74lC055k3e/8HM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=0nzpfTzsTCcWDqac7ZTk2BZgJrXNm8rZpSw6OMimBsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fi+GWsUCsG5g7dpXq8wuOE6Vd0Y4sdnJYbQOy2oUJwznG3h5kjAtdy9u8MidAKlQH5Ttw4Jx/JXp2QpccYDr74/6S/SYEtr+B3C/KY5nE92h3nfeJg7vM+MNHBxQdlitBV+KbDj6Grl5bRvEGbz8/SFr7ZzMuPymoSI3Tcq0BYs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=VZYe2P2c; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="VZYe2P2c" Received: by smtp.kernel.org (Postfix) with ESMTPS id BE962C4CEEE; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145502; bh=0nzpfTzsTCcWDqac7ZTk2BZgJrXNm8rZpSw6OMimBsU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VZYe2P2c9nRVPwi4sQS7LrTIF+Z8CEa62BbeXRIHmLdXkkZM7rtnuTy8x/NKk3yyg 0yQKRsBOEDXdIYoXiNGkeJ66Ip8XHDmdk3jF0/YmXvy5IRLDeLz2jmolhM19W5Lj70 Spx2CU6BRV63DRHt6SMpBKwHNodpvN86eXoWRWGs= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2290C71155; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:35 +0200 Subject: [PATCH v5 01/10] media: v4l: ctrls: add a control for flash/strobe duration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-1-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=1793; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=0nzpfTzsTCcWDqac7ZTk2BZgJrXNm8rZpSw6OMimBsU=; b=wpZpWeC5n9BpiJxIykqqP21yGU7SfQez/GtwiE9pwmPFtM8egKR3TrSk80LMBIBck+v27JtVL XY95kdiDh1zBpbKyK28QbruxN13uQhUw2Z2dhtbBtMTeb4HX2bjFYGB X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add a control V4L2_CID_FLASH_DURATION to set the duration of a flash/strobe pulse. This is different to the V4L2_CID_FLASH_TIMEOUT control, as the timeout defines a limit after which the flash is "forcefully" turned off again. On the other hand the new V4L2_CID_FLASH_DURATION is the desired length of the flash/strobe pulse. Signed-off-by: Richard Leitner --- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 1 + include/uapi/linux/v4l2-controls.h | 1 + 2 files changed, 2 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2= -core/v4l2-ctrls-defs.c index 1ea52011247accc51d0261f56eab1cf13c0624a0..f9ed7273a9f3eafe01c31b638e1= c8d9fcf5424af 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c @@ -1135,6 +1135,7 @@ const char *v4l2_ctrl_get_name(u32 id) case V4L2_CID_FLASH_FAULT: return "Faults"; case V4L2_CID_FLASH_CHARGE: return "Charge"; case V4L2_CID_FLASH_READY: return "Ready to Strobe"; + case V4L2_CID_FLASH_DURATION: return "Strobe Duration"; =20 /* JPEG encoder controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */ diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-c= ontrols.h index 72e32814ea83dee5f1202c1249eac7cf3b85a22a..72c6bd26e2dfa23a0224e745e5c= d07c9fca0c8b5 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -1180,6 +1180,7 @@ enum v4l2_flash_strobe_source { =20 #define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11) #define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12) +#define V4L2_CID_FLASH_DURATION (V4L2_CID_FLASH_CLASS_BASE + 13) =20 =20 /* JPEG-class control IDs */ --=20 2.47.2 From nobody Fri Oct 10 09:48:03 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33912136A; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=nZg0rMwE9KWxWsbmbqtR4Lq0yQWMD9eFp1lp+SNZzecCDiPTguNp0rfDcj2UyvRILg6JfyKf+XDzfZPTymSQ91qQa1fXXdN4lj/iIFMvOeih0qhUXgvYhCnAVeXZB27+DxDCauP+T+9gZL6IKLlcx02z7LKIagJXou2rGGvYAzw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=FrCl/fSGFBnOk0+MAcM+KHDO4zcSf1DpGTy1y8P+ack=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lAm7NvX4rFXyKaoLNJJIwUUfxBqeUlCpSKO3nlS245207heUe83GMcM8l2Pp0QSBSxNxwd+uheND5HWQIhDD58pieaq7IAJpNImCcYbF6ccLtosjoyaviwoPRZK9DlhgV/sOSvvKohEwDHrLNL8C/ELg7Lm1xVWJhtbwMbbDgMI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=0c1nJcL6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="0c1nJcL6" Received: by smtp.kernel.org (Postfix) with ESMTPS id C42FCC4AF0B; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145502; bh=FrCl/fSGFBnOk0+MAcM+KHDO4zcSf1DpGTy1y8P+ack=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=0c1nJcL69M6vekzc5cJBP1WmMzNxszsUzMx9ymqObEkRfWBo8L2B2UONgojLRZjN+ IAKXuXX5G7M/jagiHzT74yVwktqiO4GcSt9fAfiR3Amsw7M9aZeAKOTeIUmF+wkoid nW2NubFhcGmzAzytAngNhr96D83TRDpEzNENHQ40= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1E69C71157; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:36 +0200 Subject: [PATCH v5 02/10] media: v4l2-flash: add support for flash/strobe duration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-2-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=2303; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=FrCl/fSGFBnOk0+MAcM+KHDO4zcSf1DpGTy1y8P+ack=; b=3UFNRqcZuesqNlodPeYt8efWwjzdPgRjCVXwRt/jIpJBrLTp9ghLKj6Wf9kqDIIYXrsUjEqZy Rz92q8lYGiSC1l1yvAJh2SwGAKIGx/nzJJZeSn3Pi/6+Wxkko2LY2Xy X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add support for the new V4L2_CID_FLASH_DURATION control to the v4l2 flash led class. Signed-off-by: Richard Leitner --- drivers/media/v4l2-core/v4l2-flash-led-class.c | 25 ++++++++++++++++++++++= +++ 1 file changed, 25 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-flash-led-class.c b/drivers/media= /v4l2-core/v4l2-flash-led-class.c index 355595a0fefac72c2f6941a30fa430d37dbdccfe..69b6c2026e0ad905aaebcdabe1e= 7002fc48f9e2c 100644 --- a/drivers/media/v4l2-core/v4l2-flash-led-class.c +++ b/drivers/media/v4l2-core/v4l2-flash-led-class.c @@ -29,6 +29,7 @@ enum ctrl_init_data_id { INDICATOR_INTENSITY, FLASH_TIMEOUT, STROBE_SOURCE, + FLASH_DURATION, /* * Only above values are applicable to * the 'ctrls' array in the struct v4l2_flash. @@ -298,6 +299,12 @@ static int v4l2_flash_s_ctrl(struct v4l2_ctrl *c) * microamperes for flash intensity units. */ return led_set_flash_brightness(fled_cdev, c->val); + case V4L2_CID_FLASH_DURATION: + /* + * No conversion is needed as LED Flash class also uses + * microseconds for flash duration units. + */ + return led_set_flash_duration(fled_cdev, c->val); } =20 return -EINVAL; @@ -424,6 +431,14 @@ static void __fill_ctrl_init_data(struct v4l2_flash *v= 4l2_flash, ctrl_cfg->flags =3D V4L2_CTRL_FLAG_VOLATILE | V4L2_CTRL_FLAG_EXECUTE_ON_WRITE; } + + /* Init FLASH_DURATION ctrl data */ + if (has_flash_op(fled_cdev, duration_set)) { + ctrl_init_data[FLASH_DURATION].cid =3D V4L2_CID_FLASH_DURATION; + ctrl_cfg =3D &ctrl_init_data[FLASH_DURATION].config; + __lfs_to_v4l2_ctrl_config(&fled_cdev->duration, ctrl_cfg); + ctrl_cfg->id =3D V4L2_CID_FLASH_DURATION; + } } =20 static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash, @@ -543,6 +558,16 @@ static int __sync_device_with_v4l2_controls(struct v4l= 2_flash *v4l2_flash) return ret; } =20 + if (ctrls[FLASH_DURATION]) { + if (WARN_ON_ONCE(!fled_cdev)) + return -EINVAL; + + ret =3D led_set_flash_duration(fled_cdev, + ctrls[FLASH_DURATION]->val); + if (ret < 0) + return ret; + } + /* * For some hardware arrangements setting strobe source may affect * torch mode. Synchronize strobe source setting only if not in torch --=20 2.47.2 From nobody Fri Oct 10 09:48:03 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66D631DF269; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=l8/or2e0SSTNq+0bb8X5tzI9nmU/AsZzmZlabnijfvi+JrwscYBwropb7uC/Rx8FNURKooNr3jdp9/qsMZlxbdFYTSzjjvGmltlBWyjNvIYwWQR8c0YE/H2YJc1LCzbSU+EW9HgX42wOB5Y/MzsMF4SGT81L9Wnt2SaM2PURMC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VgqQw9wyIQoKpz45eYMxibWGAVt0fV3/OMKVUfDVhsGf/I+zT3IfMfRZY/Hwtq4IPh7sx/+7pikWhlfq7mMwiyKT6rrYZNGC/BBO4vsiqKdUYgnDqnTCXq0DyZ79jzNxzfzd7H1wGvOQpxKVesKAohfYGbhTP0mdRtLNPFxL1eU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PL9s16Jj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PL9s16Jj" Received: by smtp.kernel.org (Postfix) with ESMTPS id D1744C4CEF0; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145502; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PL9s16JjyRvKIYWjase40Bs4Ka11Fm5EgK28szx2xE+e8KLno+2E5XiCx1W60ogRo 4NKwALHMGsq9W0k4iUZAVdlH/dtX2DAQrP/+GiQfpEAZgl5u+Giv0secRCH5FTj5J9 /Mvtl06RKApT1DA0qb5VmkQAwNKT6JMA7FB9gt+s= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C28BEC71136; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:37 +0200 Subject: [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-3-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=878; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; b=nPouAY8N5zq1XIMQ6rZ1Q6GzebMfWi0D9HB7LZ8Xg6r4imr5Qm6mrjxTs9/UdOwDbDXkp1HJu W2Ze+5AQ3w7Ax3ibt1oJ/EgVjSr7MfgqeyTvsYMveLRaGLiDCNQ1LyF X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 The comment for the flash_timeout setter mentioned it is the "flash duration". Fix this by changing it to "flash timeout". Signed-off-by: Richard Leitner --- include/linux/led-class-flash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flas= h.h index 21ec856c36bc67decda46aa8ff1c040ffdcf1181..775a96217518936633541c7a5d3= 94502dbf04f83 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -197,7 +197,7 @@ int led_update_flash_brightness(struct led_classdev_fla= sh *fled_cdev); * @fled_cdev: the flash LED to set * @timeout: the flash timeout to set it to * - * Set the flash strobe duration. + * Set the flash strobe timeout. * * Returns: 0 on success or negative error value on failure */ --=20 2.47.2 From nobody Fri Oct 10 09:48:03 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67D011E22FC; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=n13qEHlmOGVGQmoRO5IcmUmQOWFP6QHhQIDRvjnXtEYdb+6Oz/Fns+Rw2SIOMg8dpOHp2tETJWwBABtEbhqPtPjTQzeEVDvqZq4Wx3E4t3ekESkAra48mZtO0jGsYfFCZFpff5Cl0NNa78WF5PQUcxohYtN+fDl7Lz3fawQ35Is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=16N0ehkJWytFD5jx5wDbSTZhtNf5Qf6vx2SOhlkAC1Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Uq4uQWXOrlsDAXWlVwcXbw96vo/J0sLisIG9GfBQz102DKAOZc6LuzSzyqW82nrvtlRoRI/q8qKVls6hWwUvcXQuZzr1hkeQU9HxQUNRjC0CrCqiJXUSR2duIZRK8TMxf1MI7/s+cT6nL9UtJFQ3KrT9NETOqdqQIVDsSy1VHlU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=W5Tk7Xrx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="W5Tk7Xrx" Received: by smtp.kernel.org (Postfix) with ESMTPS id E25E1C4CEF7; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145502; bh=16N0ehkJWytFD5jx5wDbSTZhtNf5Qf6vx2SOhlkAC1Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=W5Tk7XrxMVaiCjlLaD1ZsDEg4V2ER7IWbKshfxw58qGO6EVp4dPdbZf5ZyVrgyae9 dA1BBOWSVHUe0kELvGOZyL0RcoHolq84w/wqMLLcRXpMcqo208MLflX48XDDYmmGqS OjATOlbLd0U/C94stJk9iHjzhUycyGwwgWULh5kU= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id D215FC7115D; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:38 +0200 Subject: [PATCH v5 04/10] Documentation: uAPI: media: add V4L2_CID_FLASH_DURATION Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-4-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=1038; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=16N0ehkJWytFD5jx5wDbSTZhtNf5Qf6vx2SOhlkAC1Y=; b=DVSTCYqNJufAJ3eLL86OJ8J58+xjr+B8yJkFVS4dnrxT53dv3Po4+gGFv81Z2jtJs1PWzSllW aOcTeZmAgFCAt8ZqtbtsOFUemwNxb+Wi1pxyh4nONJ4MIdO/ea56VsE X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add the new strobe_duration control to v4l uAPI documentation. Signed-off-by: Richard Leitner --- Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst b/Do= cumentation/userspace-api/media/v4l/ext-ctrls-flash.rst index d22c5efb806a183a3ad67ec3e6550b002a51659a..03a58ef94be7c870f55d5a9bb09= 503995dbfb402 100644 --- a/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst @@ -186,3 +186,8 @@ Flash Control IDs charged before strobing. LED flashes often require a cooldown period after strobe during which another strobe will not be possible. This is a read-only control. + +``V4L2_CID_FLASH_DURATION (integer)`` + Duration the flash should be on when the flash LED is in flash mode + (V4L2_FLASH_LED_MODE_FLASH). The unit should be microseconds (=C2=B5s) + if possible. --=20 2.47.2 From nobody Fri Oct 10 09:48:03 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8A4D828DB52; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=SXLRlgS0wnsgK9cCh54rQTmOZFoCxPTH2nkIBAKhbcVlL73UACHUf5lCmFfVNLC8fOuSO0Nc9ytoHUuF3M5KwARFi4VzR1Ei19AVaPs31iadih7/06uVqj+Hmgt7i6Bn26I7BiYcd3r7+9eRVYCaSI6vuRd7q56gLg+bsrt/S7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=FNa/xvakH+OMufv25Oa47P8olVqt6It8kjPg/VhP/1A=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LE2uA8Qfbf5vAX+IurIPSN5GmzQT4/clF/4r7r8XG9HLjhJ5y9QWnndEtdFwoxOml6urwUcphpjGSKy0ZylXn4dZNrXTNo4TvFZNXfvI9APnIQWzvY7gU06q3WkzafF/dpd2fbu/ctZgCe/x3THpS26oyW1E9De+mei2qz2mvyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=u+C33yKj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="u+C33yKj" Received: by smtp.kernel.org (Postfix) with ESMTPS id EC810C4CEFA; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=FNa/xvakH+OMufv25Oa47P8olVqt6It8kjPg/VhP/1A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=u+C33yKjXOjHiWhPF2bwaYwZp2z6MwnkTJqtd2RbK5L4K/xKxXO7IJSNvUyeo9gnB ix5wZQkm0clWeWiZN1egHGOT+0ogiHJToOJW25QHABZcju+keO/CW6dNhiuRWBKoXd Pk3GnzZFuolqXz55q3Il8rlAsYeyPTiV6xygXbhY= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3A58C71157; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:39 +0200 Subject: [PATCH v5 05/10] media: i2c: ov9282: add output enable register definitions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-5-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=2191; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=FNa/xvakH+OMufv25Oa47P8olVqt6It8kjPg/VhP/1A=; b=uUHWJ+/yb+PEiHD9pRblZN7qf/jGLbObljhh9njTTbUrU1jtNojkc0ELLkEDGzT8KfWB2yLiO H9L+gNjKJLOBAleI3wzW224Y0zaf/P1/kqeHcew5Bq2WhAS12C8w71g X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add #define's for the output enable registers (0x3004, 0x3005, 0x3006), also known as SC_CTRL_04, SC_CTRL_05, SC_CTRL_04. Use those register definitions instead of the raw values in the `common_regs` struct. All values are based on the OV9281 datasheet v1.53 (january 2019). Reviewed-by: Dave Stevenson Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index c882a021cf18852237bf9b9524d3de0c5b48cbcb..f42e0d439753e74d14e3a359202= 9e48f49234927 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -37,6 +37,29 @@ #define OV9282_REG_ID 0x300a #define OV9282_ID 0x9281 =20 +/* Output enable registers */ +#define OV9282_REG_OUTPUT_ENABLE4 0x3004 +#define OV9282_OUTPUT_ENABLE4_GPIO2 BIT(1) +#define OV9282_OUTPUT_ENABLE4_D9 BIT(0) + +#define OV9282_REG_OUTPUT_ENABLE5 0x3005 +#define OV9282_OUTPUT_ENABLE5_D8 BIT(7) +#define OV9282_OUTPUT_ENABLE5_D7 BIT(6) +#define OV9282_OUTPUT_ENABLE5_D6 BIT(5) +#define OV9282_OUTPUT_ENABLE5_D5 BIT(4) +#define OV9282_OUTPUT_ENABLE5_D4 BIT(3) +#define OV9282_OUTPUT_ENABLE5_D3 BIT(2) +#define OV9282_OUTPUT_ENABLE5_D2 BIT(1) +#define OV9282_OUTPUT_ENABLE5_D1 BIT(0) + +#define OV9282_REG_OUTPUT_ENABLE6 0x3006 +#define OV9282_OUTPUT_ENABLE6_D0 BIT(7) +#define OV9282_OUTPUT_ENABLE6_PCLK BIT(6) +#define OV9282_OUTPUT_ENABLE6_HREF BIT(5) +#define OV9282_OUTPUT_ENABLE6_STROBE BIT(3) +#define OV9282_OUTPUT_ENABLE6_ILPWM BIT(2) +#define OV9282_OUTPUT_ENABLE6_VSYNC BIT(1) + /* Exposure control */ #define OV9282_REG_EXPOSURE 0x3500 #define OV9282_EXPOSURE_MIN 1 @@ -213,9 +236,9 @@ static const struct ov9282_reg common_regs[] =3D { {0x0302, 0x32}, {0x030e, 0x02}, {0x3001, 0x00}, - {0x3004, 0x00}, - {0x3005, 0x00}, - {0x3006, 0x04}, + {OV9282_REG_OUTPUT_ENABLE4, 0x00}, + {OV9282_REG_OUTPUT_ENABLE5, 0x00}, + {OV9282_REG_OUTPUT_ENABLE6, OV9282_OUTPUT_ENABLE6_ILPWM}, {0x3011, 0x0a}, {0x3013, 0x18}, {0x301c, 0xf0}, --=20 2.47.2 From nobody Fri Oct 10 09:48:03 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B9AD28DB57; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=mzrvLNZGVKE91KvvCUhV6Ca0T9eeeZQ4sWx99nEqOR19J5w3wrULyd0/7qbjcNrFYn1gmWnioMxDbVFEy7ASuSZ1lKvP8ZKaD0iVbhnrwOAFekrL2FcaiV0WQM3Jek3wG+imKHUaVov09kPTEGSm3iPyK9L13SyU0JEtljok5+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=vj4AZ2VwKF/zDloCshyajTedmued0DDmjMCD6CM2Ep8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QxrR/gcdhkTlHVipM9l85OpNZxn/0G8kGkyMpHc+qYWksKaFM+Wo1nnwFhXUFCtm5arw7g/WY4EPzjI6IuIw2gdtvjJlNkYAw/n8gMY874RYlZ6SOe0D8fgrHlKoJLMGrFLXuh/W8QUlfyfKgDQoWGbFqeombRXmf7ga+w8mVnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=xFsADBPi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="xFsADBPi" Received: by smtp.kernel.org (Postfix) with ESMTPS id 12C62C4CEFE; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=vj4AZ2VwKF/zDloCshyajTedmued0DDmjMCD6CM2Ep8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=xFsADBPiHh0jBYzZXOoksSQlOTztWxmmO7oeYF+E/RDVQsGPSF+2JfEnY4YePmSOb E4KIJz4hrE6YOdXfqtNP/ifCLzCw10zDyO39Ye3t4nFYjsnVlfcAOXrAhK+aSTrTnD aT7e0uDeg3P0r6KxBemLJ9Vns/cUQOvu2yjb7IMo= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 093D2C7114A; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:40 +0200 Subject: [PATCH v5 06/10] media: i2c: ov9282: add led_mode v4l2 control Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-6-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=2663; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=vj4AZ2VwKF/zDloCshyajTedmued0DDmjMCD6CM2Ep8=; b=gkGMtTqdRP2ZqpP/QeyIOA+7vgfR8r6qWp3xe3u8MCx7IPMK1bjL0jhOcL4ZnE49sggj2kVSv 9Trv1X7E37uBELtjEKqhBqjfi9z30J8HF9khw4BMwgIUJAiPAuJ9lFZ X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add V4L2_CID_FLASH_LED_MODE support using the "strobe output enable" feature of the sensor. This implements following modes: - V4L2_FLASH_LED_MODE_NONE, which disables the strobe output - V4L2_FLASH_LED_MODE_FLASH, which enables the strobe output All values are based on the OV9281 datasheet v1.53 (january 2019) and tested using an ov9281 VisionComponents module. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index f42e0d439753e74d14e3a3592029e48f49234927..b6de96997426f7225a061bfdc84= 1aa062e8d0891 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -670,6 +670,23 @@ static int ov9282_set_ctrl_vflip(struct ov9282 *ov9282= , int value) current_val); } =20 +static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) +{ + u32 current_val; + int ret =3D ov9282_read_reg(ov9282, OV9282_REG_OUTPUT_ENABLE6, 1, + ¤t_val); + if (ret) + return ret; + + if (mode =3D=3D V4L2_FLASH_LED_MODE_FLASH) + current_val |=3D OV9282_OUTPUT_ENABLE6_STROBE; + else + current_val &=3D ~OV9282_OUTPUT_ENABLE6_STROBE; + + return ov9282_write_reg(ov9282, OV9282_REG_OUTPUT_ENABLE6, 1, + current_val); +} + /** * ov9282_set_ctrl() - Set subdevice control * @ctrl: pointer to v4l2_ctrl structure @@ -736,6 +753,9 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl) ret =3D ov9282_write_reg(ov9282, OV9282_REG_TIMING_HTS, 2, (ctrl->val + ov9282->cur_mode->width) >> 1); break; + case V4L2_CID_FLASH_LED_MODE: + ret =3D ov9282_set_ctrl_flash_led_mode(ov9282, ctrl->val); + break; default: dev_err(ov9282->dev, "Invalid control %d", ctrl->id); ret =3D -EINVAL; @@ -1326,7 +1346,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282) u32 lpfr; int ret; =20 - ret =3D v4l2_ctrl_handler_init(ctrl_hdlr, 10); + ret =3D v4l2_ctrl_handler_init(ctrl_hdlr, 11); if (ret) return ret; =20 @@ -1391,6 +1411,13 @@ static int ov9282_init_controls(struct ov9282 *ov928= 2) OV9282_TIMING_HTS_MAX - mode->width, 1, hblank_min); =20 + /* Flash/Strobe controls */ + v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov9282_ctrl_ops, + V4L2_CID_FLASH_LED_MODE, + V4L2_FLASH_LED_MODE_TORCH, + (1 << V4L2_FLASH_LED_MODE_TORCH), + V4L2_FLASH_LED_MODE_NONE); + ret =3D v4l2_fwnode_device_parse(ov9282->dev, &props); if (!ret) { /* Failure sets ctrl_hdlr->error, which we check afterwards anyway */ --=20 2.47.2 From nobody Fri Oct 10 09:48:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 893F728D8EF; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=qUbJvNYWctg69SUmAAm8NQqK7yzX3JwIwnttYdG6HrVv3SDwrDY244GMyh5IqO1/vNxxgG2IX92qOh5Kg5o8PC70UdnKOT41xabIXt1Ra3792d4YvEE2fnzAJq8h4Uotg1pmX0PYPC3FZLTQOl1+gVc/VisP/KaLNFwsUVqlho8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=oUO3rGrZkpHIi+iMi+rCIYqbermkEnOKYHA1KrimKQ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MsCt+sI1rCKJ5+q5E5/HWkhN07KIbrKrqVWsYke8dwmDpJwvES5RWoT+JUHiy5zYZW/+xPunpmAoflRY7DkOM1hQV6BZrsrKYGsdvViz4EN67hN3SMDh7D/OEfBPJGvpz5KkkJ+v3GJpNLbiwYtS0UHC9ztJw1c1v9mHaGHYCdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FApXZNeJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FApXZNeJ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2464CC4CEED; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=oUO3rGrZkpHIi+iMi+rCIYqbermkEnOKYHA1KrimKQ4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FApXZNeJQrH5oX4VUZoebh3loCH96YxFWLJrBSrUqMaul91yxobC6ykJ2aFkMU2xb fZ7AGKF1DBIdMMhrpAifIUH48zENP4lE0W+6hpI/ErflJQY4qusIwCz1FA4b/zD5XK 97N3sgXBHZC/mimoMChfHAiIcd6p5/cLV5KU2FII= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 189E7C71136; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:41 +0200 Subject: [PATCH v5 07/10] media: i2c: ov9282: add strobe_duration v4l2 control Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-7-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=3465; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=oUO3rGrZkpHIi+iMi+rCIYqbermkEnOKYHA1KrimKQ4=; b=NgECwZ1ajnQD/6frScq4DKWGtzmK1kmPmz75ObFUf6bRiVxSFuQiVuC5e53YELEuSi8OkLPJR FFO+JGPesWFA3w83C8M2XFW0VGY6DWi3tbvmHW2i7YV1AHiLlXMaDZF X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add V4L2_CID_FLASH_DURATION support using the "strobe_frame_span" feature of the sensor. This is implemented by transforming the given =C2=B5s value by an interpolated formula to a "span step width" value and writing it to register PWM_CTRL_25, PWM_CTRL_26, PWM_CTRL_27, PWM_CTRL_28 (0x3925, 0x3926, 0x3927, 0x3928). The maximum control value is set to the period of the current default framerate. All register values are based on the OV9281 datasheet v1.53 (jan 2019) and tested using an ov9281 VisionComponents module. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index b6de96997426f7225a061bfdc841aa062e8d0891..871cd7e796531c1f958790eba73= 3290d39e99f0c 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -97,6 +97,10 @@ #define OV9282_REG_MIPI_CTRL00 0x4800 #define OV9282_GATED_CLOCK BIT(5) =20 +/* Flash/Strobe control registers */ +#define OV9282_REG_FLASH_DURATION 0x3925 +#define OV9282_FLASH_DURATION_DEFAULT 0x0000001a + /* Input clock rate */ #define OV9282_INCLK_RATE 24000000 =20 @@ -687,6 +691,25 @@ static int ov9282_set_ctrl_flash_led_mode(struct ov928= 2 *ov9282, int mode) current_val); } =20 +static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, u32 value) +{ + /* + * Calculate "strobe_frame_span" increments from a given value (=C2=B5s). + * This is quite tricky as "The step width of shift and span is + * programmable under system clock domain.", but it's not documented + * how to program this step width (at least in the datasheet available + * to the author at time of writing). + * The formula below is interpolated from different modes/framerates + * and should work quite well for most settings. + */ + u32 val =3D value * 192 / (ov9282->cur_mode->width + ov9282->hblank_ctrl-= >val); + + ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION, 1, (val >> 24) & 0xff= ); + ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 1, 1, (val >> 16) & = 0xff); + ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 2, 1, (val >> 8) & 0= xff); + return ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 3, 1, val & 0= xff); +} + /** * ov9282_set_ctrl() - Set subdevice control * @ctrl: pointer to v4l2_ctrl structure @@ -756,6 +779,9 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_FLASH_LED_MODE: ret =3D ov9282_set_ctrl_flash_led_mode(ov9282, ctrl->val); break; + case V4L2_CID_FLASH_DURATION: + ret =3D ov9282_set_ctrl_flash_duration(ov9282, ctrl->val); + break; default: dev_err(ov9282->dev, "Invalid control %d", ctrl->id); ret =3D -EINVAL; @@ -1346,7 +1372,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282) u32 lpfr; int ret; =20 - ret =3D v4l2_ctrl_handler_init(ctrl_hdlr, 11); + ret =3D v4l2_ctrl_handler_init(ctrl_hdlr, 12); if (ret) return ret; =20 @@ -1418,6 +1444,9 @@ static int ov9282_init_controls(struct ov9282 *ov9282) (1 << V4L2_FLASH_LED_MODE_TORCH), V4L2_FLASH_LED_MODE_NONE); =20 + v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, + 0, 13900, 1, 8); + ret =3D v4l2_fwnode_device_parse(ov9282->dev, &props); if (!ret) { /* Failure sets ctrl_hdlr->error, which we check afterwards anyway */ --=20 2.47.2 From nobody Fri Oct 10 09:48:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 725F6273D7B; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=mDuuyL51OKUOeSDBKQrPkwchL8EbD3GZ9F0BztBvSoWUoPvTEtTbUR1+TXoyc3wHVTA+wKDKpGkiQPzVpndpRBiNijWeNCReAN4iC8fQdL4xycQyLGyNhbOatrRmvKWmXwwk1X1DrMHWbgCMBiQc6+AffFVjybyUFehRsDtOB54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=UWUot8+GzH895q5xNuCz1v5OHUINGbiHBZ3BD3ADYX4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U0e6cfUgk0qg+bOqcNEdLwF8xAaI8oJ6K8VK9JFfBcuKbXrW6Ebq91A0ckvny6ub1f8dB7I9AgBhK6k45EPYNc5kHsNLf08r7iWTXJxqUykadeSPZ4Pyu29MCMSghs/MbotXctcslk4ZlUrFVYQjkeH5c3zayMz+lS/8JjbyUoQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=UARdv7I/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="UARdv7I/" Received: by smtp.kernel.org (Postfix) with ESMTPS id 313DDC4CEF2; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=UWUot8+GzH895q5xNuCz1v5OHUINGbiHBZ3BD3ADYX4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UARdv7I/4Cy3lX75c/r+cKTu/Lsy/s5V6FHoCzpAA+WiQqB9b2/bCNwhAtfhhWHx8 ujZjq1BB0V3AoQGm+CtNG0LHu845wtZrHSih7k5Ko8AF3f1w0MGqeC0wVlnR1FQYE4 sOJgeKXmiY3dmz/cKDQRt8oAn+2sBVNnjx1BlxD8= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2946AC71157; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:42 +0200 Subject: [PATCH v5 08/10] media: i2c: ov9282: add strobe_source v4l2 control Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-8-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=1686; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=UWUot8+GzH895q5xNuCz1v5OHUINGbiHBZ3BD3ADYX4=; b=bpEuNPOqTYYT+fcLwGMXZjghWxiPYLrLi73EcKzRLU5ASu8f6ar0V8AC+nHaGIyKnpr7IIxG9 jAa1lH+mK6MCneclEgl6k/tR9Yn8dEiXLLG3mDllUqRMCrYCvmOM5UV X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add read-only V4L2_CID_FLASH_STROBE_SOURCE control. Its value is fixed to V4L2_FLASH_STROBE_SOURCE_EXTERNAL as the camera sensor triggers the strobe based on its register settings. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index 871cd7e796531c1f958790eba733290d39e99f0c..2d77b9108bcd2499a40418919e2= 60e7d53a9a64e 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -1368,11 +1368,12 @@ static int ov9282_init_controls(struct ov9282 *ov92= 82) struct v4l2_ctrl_handler *ctrl_hdlr =3D &ov9282->ctrl_handler; const struct ov9282_mode *mode =3D ov9282->cur_mode; struct v4l2_fwnode_device_properties props; + struct v4l2_ctrl *ctrl; u32 hblank_min; u32 lpfr; int ret; =20 - ret =3D v4l2_ctrl_handler_init(ctrl_hdlr, 12); + ret =3D v4l2_ctrl_handler_init(ctrl_hdlr, 13); if (ret) return ret; =20 @@ -1447,6 +1448,14 @@ static int ov9282_init_controls(struct ov9282 *ov928= 2) v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, 0, 13900, 1, 8); =20 + ctrl =3D v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov9282_ctrl_ops, + V4L2_CID_FLASH_STROBE_SOURCE, + V4L2_FLASH_STROBE_SOURCE_EXTERNAL, + ~(1 << V4L2_FLASH_STROBE_SOURCE_EXTERNAL), + V4L2_FLASH_STROBE_SOURCE_EXTERNAL); + if (ctrl) + ctrl->flags |=3D V4L2_CTRL_FLAG_READ_ONLY; + ret =3D v4l2_fwnode_device_parse(ov9282->dev, &props); if (!ret) { /* Failure sets ctrl_hdlr->error, which we check afterwards anyway */ --=20 2.47.2 From nobody Fri Oct 10 09:48:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7253122AE45; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=mjUIAR6MY8nO1vnpMPR5QbiTmHQgOPsT9eMlvJTWBH8o4KJxRV1A/xst8cJlXSypziywkMu7imw7BJ73Rfatg0Chgyzejkg/rAifoQZSSRzsQr8s/GoU5p/xnl9wk/zuf0mr1QNEgB/+8SiTOkhyZlgL60U9rvWkAq7ifjeFpks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=N7cxIQN6Xv0wE74O59AbStDajdQPgGvjHQmafDljbdA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=niJDWPs7wZcpQ1nuJhQaDUI1bvInk8UFSqNMTHUeqWAldgPIL8LcFDOeKDc4ZMfStbv+mDxfEXbNkp74Lz6iu4eC1Rh3TYOLkI5vvEvCbx7X1g7Kjby4GL4CjrTGJyEXP/t5DMNKUKWYAoEoTTbZ6AR5pK9QR0qW1iTwLK5t7I4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=vmCdZZjj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="vmCdZZjj" Received: by smtp.kernel.org (Postfix) with ESMTPS id 3EAB7C4CEFD; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=N7cxIQN6Xv0wE74O59AbStDajdQPgGvjHQmafDljbdA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=vmCdZZjjdAzVlYw533oEp5gac8Ump7xyp7z3f9MKg0ZhOZaavqzGcFwQTj265M47L 43sRFUtjpIf1qVQZGx1mYJf5QKrDxJq2jhcsVR+nROhoE2umufCWOq2y0eZklU1tbv PZXd91H+q9/2oKmxwp/Yijoq3onr6F/O7voT2JTQ= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36663C7115D; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:43 +0200 Subject: [PATCH v5 09/10] media: i2c: ov9282: implement try_ctrl for strobe_duration Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-9-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=3551; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=N7cxIQN6Xv0wE74O59AbStDajdQPgGvjHQmafDljbdA=; b=fdl3inKMgvhpPI2PHcHHcZ8fsLbLgLfEVPSeMsJSf3g4eiVUNuxskBMPTvq2B/NeOcFvLBRj3 hLw+H2YEYrkCHiyK6zg/wYqY7Q9eNfw7rwtdb7yt7vFQ2lcX10EObt7 X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 As the granularity of the hardware supported values is lower than the control value, implement a try_ctrl() function for V4L2_CID_FLASH_DURATION. This function calculates the nearest possible =C2=B5s strobe duration for the given value and returns it back to the caller. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 54 ++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index 2d77b9108bcd2499a40418919e260e7d53a9a64e..1f4bca29cd793e99c473aff9c8b= 7e200e3d598bc 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -128,6 +128,8 @@ #define OV9282_REG_MIN 0x00 #define OV9282_REG_MAX 0xfffff =20 +#define OV9282_STROBE_SPAN_FACTOR 192 + static const char * const ov9282_supply_names[] =3D { "avdd", /* Analog power */ "dovdd", /* Digital I/O power */ @@ -691,7 +693,7 @@ static int ov9282_set_ctrl_flash_led_mode(struct ov9282= *ov9282, int mode) current_val); } =20 -static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, u32 value) +static u32 ov9282_us_to_flash_duration(struct ov9282 *ov9282, u32 value) { /* * Calculate "strobe_frame_span" increments from a given value (=C2=B5s). @@ -702,7 +704,27 @@ static int ov9282_set_ctrl_flash_duration(struct ov928= 2 *ov9282, u32 value) * The formula below is interpolated from different modes/framerates * and should work quite well for most settings. */ - u32 val =3D value * 192 / (ov9282->cur_mode->width + ov9282->hblank_ctrl-= >val); + u32 frame_width =3D ov9282->cur_mode->width + ov9282->hblank_ctrl->val; + + return value * OV9282_STROBE_SPAN_FACTOR / frame_width; +} + +static u32 ov9282_flash_duration_to_us(struct ov9282 *ov9282, u32 value) +{ + /* + * As the calculation in ov9282_us_to_flash_duration uses an integer + * divison calculate in ns here to get more precision. Then check if + * we need to compensate that divison by incrementing the =C2=B5s result. + */ + u32 frame_width =3D ov9282->cur_mode->width + ov9282->hblank_ctrl->val; + u64 ns =3D value * 1000 * frame_width / OV9282_STROBE_SPAN_FACTOR; + + return DIV_ROUND_UP(ns, 1000); +} + +static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, u32 value) +{ + u32 val =3D ov9282_us_to_flash_duration(ov9282, value); =20 ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION, 1, (val >> 24) & 0xff= ); ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 1, 1, (val >> 16) & = 0xff); @@ -792,9 +814,37 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl) return ret; } =20 +static int ov9282_try_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ov9282 *ov9282 =3D + container_of(ctrl->handler, struct ov9282, ctrl_handler); + + if (ctrl->id =3D=3D V4L2_CID_FLASH_DURATION) { + u32 fd =3D ov9282_us_to_flash_duration(ov9282, ctrl->val); + u32 us =3D ctrl->val; + + /* get nearest strobe_duration value */ + u32 us0 =3D ov9282_flash_duration_to_us(ov9282, fd); + u32 us1 =3D ov9282_flash_duration_to_us(ov9282, (fd + 1)); + + if (abs(us1 - us) < abs(us - us0)) + ctrl->val =3D us1; + else + ctrl->val =3D us0; + + if (us !=3D ctrl->val) { + dev_dbg(ov9282->dev, "using next valid strobe_duration %u instead of %u= \n", + ctrl->val, us); + } + } + + return 0; +} + /* V4l2 subdevice control ops*/ static const struct v4l2_ctrl_ops ov9282_ctrl_ops =3D { .s_ctrl =3D ov9282_set_ctrl, + .try_ctrl =3D ov9282_try_ctrl, }; =20 /** --=20 2.47.2 From nobody Fri Oct 10 09:48:04 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72697288C06; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=oBpBfYUo49QxrVkwEWu2x4LGiJGhv2LSEkbdO7sYMLk1K2R4RSbE4EJYgJLkPbhHcuok5eKCHZntLIG+J/K5N0kF1E5TTj97H1p6DlpF5lJ+EzHSEPptL/T/wIwYWB55eLgrndxUbLxmRd/O4kmxalnK7AeV3sR5Ut6tc6agJ0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=u0EumBQgKw9tRo8pqtn52kIAYiMwEBU7JZR3hZra7Is=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lCn1RcX2mpUAWtDVH1hghcXSLi1SQbInjnL/J23QoWF1WlZSotoVnVWfE/q7khFis/SJNlC7JJSkB0SSBSPw0Tx5Q43TbMHzTEKWdVFwekD27rGOy1cViEpm8ADk2gy1bXS1RkM2y1tnNMz8TmVn7Yj5Q5NrJe7mAgqhnLD9RlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XCGFuS5h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XCGFuS5h" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4CB2BC113CF; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=u0EumBQgKw9tRo8pqtn52kIAYiMwEBU7JZR3hZra7Is=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XCGFuS5hBYCwlYFw1Y3fgv0PsACKMp9WD4NnXUCS1RsgSXzDBxUA4qC/yXGYronur F2Iv82L2Bx8Kd+0ECt5jGSoCiWd+XuCzYpe/dwWu7Tw6/TMssq1S8JG8S8JMNkSlUZ KmNSh8dEXjBYsSCPwKb354KaZp+t/fiS8kXsFBf8= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43077C7115E; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:44 +0200 Subject: [PATCH v5 10/10] media: i2c: ov9282: dynamic flash_duration maximum Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250617-ov9282-flash-strobe-v5-10-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=3576; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=u0EumBQgKw9tRo8pqtn52kIAYiMwEBU7JZR3hZra7Is=; b=/smZRi59dZATDPo+9atyjcxBHAC0WosfiTD+9aXjXRMdnnm1P/xAhwInYBkmUB2XwJY2lsD8N TSgOKWvD3ITDu4IYepSKddgDmHRuP6Nb/bDtec4ci3t8gbHUQ1AwmxM X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 This patch sets the current exposure time as maximum for the flash_duration control. As Flash/Strobes which are longer than the exposure time have no effect. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index 1f4bca29cd793e99c473aff9c8b7e200e3d598bc..2fd0d63b8071d434c05a98f4d01= 69c4fb83f7cfe 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -198,6 +198,7 @@ struct ov9282_mode { * @exp_ctrl: Pointer to exposure control * @again_ctrl: Pointer to analog gain control * @pixel_rate: Pointer to pixel rate control + * @flash_duration: Pointer to flash duration control * @vblank: Vertical blanking in lines * @noncontinuous_clock: Selection of CSI2 noncontinuous clock mode * @cur_mode: Pointer to current selected sensor mode @@ -220,6 +221,7 @@ struct ov9282 { struct v4l2_ctrl *again_ctrl; }; struct v4l2_ctrl *pixel_rate; + struct v4l2_ctrl *flash_duration; u32 vblank; bool noncontinuous_clock; const struct ov9282_mode *cur_mode; @@ -611,6 +613,15 @@ static int ov9282_update_controls(struct ov9282 *ov928= 2, mode->vblank_max, 1, mode->vblank); } =20 +static u32 ov9282_exposure_to_us(struct ov9282 *ov9282, u32 exposure) +{ + /* calculate exposure time in =C2=B5s */ + u32 frame_width =3D ov9282->cur_mode->width + ov9282->hblank_ctrl->val; + u32 trow_us =3D (frame_width * 1000000UL) / ov9282->pixel_rate->val; + + return exposure * trow_us; +} + /** * ov9282_update_exp_gain() - Set updated exposure and gain * @ov9282: pointer to ov9282 device @@ -622,9 +633,10 @@ static int ov9282_update_controls(struct ov9282 *ov928= 2, static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32= gain) { int ret; + u32 exposure_us =3D ov9282_exposure_to_us(ov9282, exposure); =20 - dev_dbg(ov9282->dev, "Set exp %u, analog gain %u", - exposure, gain); + dev_dbg(ov9282->dev, "Set exp %u (~%u =C2=B5s), analog gain %u", + exposure, exposure_us, gain); =20 ret =3D ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 1); if (ret) @@ -635,6 +647,12 @@ static int ov9282_update_exp_gain(struct ov9282 *ov928= 2, u32 exposure, u32 gain) goto error_release_group_hold; =20 ret =3D ov9282_write_reg(ov9282, OV9282_REG_AGAIN, 1, gain); + if (ret) + goto error_release_group_hold; + + ret =3D __v4l2_ctrl_modify_range(ov9282->flash_duration, + 0, exposure_us, 1, + OV9282_FLASH_DURATION_DEFAULT); =20 error_release_group_hold: ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 0); @@ -1420,6 +1438,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282) struct v4l2_fwnode_device_properties props; struct v4l2_ctrl *ctrl; u32 hblank_min; + u32 exposure_us; u32 lpfr; int ret; =20 @@ -1495,8 +1514,11 @@ static int ov9282_init_controls(struct ov9282 *ov928= 2) (1 << V4L2_FLASH_LED_MODE_TORCH), V4L2_FLASH_LED_MODE_NONE); =20 - v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, - 0, 13900, 1, 8); + exposure_us =3D ov9282_exposure_to_us(ov9282, OV9282_EXPOSURE_DEFAULT); + ov9282->flash_duration =3D v4l2_ctrl_new_std(ctrl_hdlr, + &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, + 0, exposure_us, + 1, OV9282_FLASH_DURATION_DEFAULT); =20 ctrl =3D v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_STROBE_SOURCE, --=20 2.47.2