From nobody Fri Oct 3 11:22:29 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 F0B5633CE81; Mon, 1 Sep 2025 15:05:46 +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=1756739147; cv=none; b=iOLxkABjSfevzhVpJt7ZTB7wkemB4tzxV6B+KVMGK3CghJ50q3JUnHyvjBS7FSKf6575D4y9KcLR49gr3qMLjm+dnpJhYQwzoXetvnfW88EWKKERqI0Rgo9jSxNx/4HY94DxGUqsv9jX+ZSGxV5SSnPsb423zxaVYiYcL95Ydds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=jOvUMaocrhEnRezQ9AILTqpnj23H8z9zfwuanCjxrwo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DL2ygzARsPZNkVr9Rzg2N9my3ARL4JxkalSKBgNOga4arSfupZtjo95X297fBGQ0Fp06YpphIpgwWj/ApFf8Q88b/918fWX0qUoZHmFlhERCc6H4uc8ua0/AQs9Ztmk5HdNxgpkfa1toggCWkbI5x1jj3PuIbCZEv/XfAazbotc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Zg9zfv76; 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="Zg9zfv76" Received: by smtp.kernel.org (Postfix) with ESMTPS id 97590C4CEF1; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739146; bh=jOvUMaocrhEnRezQ9AILTqpnj23H8z9zfwuanCjxrwo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Zg9zfv76/5sxArS4Morpm3TM5oIRX16jauiHMdPKmqLOOC3WjJouXWCUbFBAmsNdF n1Gqvp0Gie3S77GV2Sxgbwx47RECyp4oFv6M9XVSYDKy+Cx5ETTofAm+fYVkhD4Ago DGZphYMuGNJmETXSiRBjkuPUNfdmEs0dY6wKpUcg= 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 89751CA0FFF; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:06 +0200 Subject: [PATCH v7 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: <20250901-ov9282-flash-strobe-v7-1-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=1793; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=jOvUMaocrhEnRezQ9AILTqpnj23H8z9zfwuanCjxrwo=; b=xQ66Po6LAaBNKNWkFs1RK+2cNs2deYefEdW/9XmyPO97jnU703xkVy7KXGOuazGlwJId1gGvD PWOb3smMZZEDjKEF4RKuKy8wiGGkqoRbfEI9yrsj91vZTCZEFZF31Nh 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 Reviewed-by: Laurent Pinchart --- 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 f836512e9debbc65d62a9fe04069b056be42f7b2..a5b7c382d77118eb7966385c5b2= 2d5a89bc2b272 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -1186,6 +1186,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 3 11:22:29 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 06FFC343D8C; Mon, 1 Sep 2025 15:05:46 +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=1756739147; cv=none; b=VDlpfNINIHcOQmeiv7KCcyjkbWSfo3igieCVkDI7clEya2qzXqwQ87hCX9TLufDwENeB/5nIZ9ZPXBNFNnD3ZNBdHHpOtjYpvwHmAKIrsYWltXXnC8zKE7ph+Hgu4XBRxemlJo8O60KL99ZFBjon/Z2dIpv2YIEZkeeUOotilu4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=gr3klb2qn/si0DKlrwgsy7RcVLdFswJfwWGpC4vYwHU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bWwNcTGGJ/cvtBK4VxSmIBawLSds3yzw+uNCz0lJudVuCiPk8fuF6au2KVs4Xffp2fsPgCdwiEX+zRHULdtLGVbcVID9TrPatRXur0Pnjlmux12bB+E/2FxPFFWRphNApdRkdro9ZBA/LNpuJ2sC8324rpyedZjXkPShdSs4RBA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cOzv1ag5; 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="cOzv1ag5" Received: by smtp.kernel.org (Postfix) with ESMTPS id A2B76C4CEF4; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739146; bh=gr3klb2qn/si0DKlrwgsy7RcVLdFswJfwWGpC4vYwHU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cOzv1ag5G42XlBEoqWhWZvgO7WOygo/O+erun3nELVdVMi6R4hBA8BFM+umyOQvz+ C//j5QuceSaVaqKpxpDdZDybDr9DS4dmy6Q4ihz13GXDj7Lh9llQLwJQV4pwCTcH1n fv0q8Dn17whPHif0hOsJ+e93H3rZ9n5JoJt/L334= 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 955E3CA0FF0; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:07 +0200 Subject: [PATCH v7 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: <20250901-ov9282-flash-strobe-v7-2-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=2308; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=gr3klb2qn/si0DKlrwgsy7RcVLdFswJfwWGpC4vYwHU=; b=+GMtDNCAg6zaUQRBR32sNircYZlJevf1Zz/NTChceKaK0wfQmryDyDcKs1Ui2mEs32ijAfa/X IrY+nkH+pwiDfneC2s6q4sAqDQt8pssgswYwRqHapRb2DJVyGhPen1o 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..875d56d7190592c1e5ab7acd617= b76dcec8792da 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 3 11:22:29 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 070773451AB; Mon, 1 Sep 2025 15:05:46 +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=1756739147; cv=none; b=FtbDKLEpSg4ppnZmyk+zCRZ8irhOCpQsNE6984IfZdsjSb1U3Bo/6gslfoQiM/U0Y6XWHVQkUqTwRDQHMUt2c61SbtX7h3PQCacOQkC1vQSZ/VxzcL3jPJr7smkekJr6260ptR7ObdkEM+x2VOjjNG6buIjnAo8cTrD/ygNOe+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=5h7OmJD5PtNvkXILVzg5eDKV/6YNZ11G+Tij3lhOaeE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LSFtq5KdEh+dofkbCQ132ULSL3uJAotE7jZ3QRx+nWpNlQ6l4yDIxMDRamHCAREclxFuvNo8I4iHJR918qocKVUjNoR9Z6x2YXASJIpDaAXiwls/kah8SncbOIo1bW3TMaXjcT0TV8WmvxDU/1Th4DVwDgnU3/kNwigVlvR/Xh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FM2kQiPX; 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="FM2kQiPX" Received: by smtp.kernel.org (Postfix) with ESMTPS id B4C41C4CEF5; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739146; bh=5h7OmJD5PtNvkXILVzg5eDKV/6YNZ11G+Tij3lhOaeE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FM2kQiPX3VS5j68xI5jLlfzp9Q6mEMgcey8zEJXY2bDeTlVc21BIiM5SD1h+b4zvd sEJk+Q9GFcGqaTd4kHMbVFStoqMQ/fniqeGGIlMi3MYAp/IvmQX6lTAbB97z+Ajh12 yaBYlgmOP3Fu+5dwdd0Y4Gs8zWz/hqil2YkOqz3w= 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 A3214CA1007; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:08 +0200 Subject: [PATCH v7 03/10] media: v4l: ctrls: add a control for enabling hw strobe signal 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: <20250901-ov9282-flash-strobe-v7-3-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=2084; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=5h7OmJD5PtNvkXILVzg5eDKV/6YNZ11G+Tij3lhOaeE=; b=rw1kcybSIDOWGaINS1Hbvsrq6PdolMoPzFOK/dCXzHwfo9SXC7aM+fd8E5if/ZRyJScI3Y1Nv SVFYVgPuLElCMDtqp+4YwgRdyG06w5TWSer1cZ+wITgzFYoLoi8W4Al 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_HW_STROBE_SIGNAL to en- or disable the strobe output of v4l2 devices (most likely sensors). Signed-off-by: Richard Leitner --- drivers/media/v4l2-core/v4l2-ctrls-defs.c | 2 ++ include/uapi/linux/v4l2-controls.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-ctrls-defs.c b/drivers/media/v4l2= -core/v4l2-ctrls-defs.c index f9ed7273a9f3eafe01c31b638e1c8d9fcf5424af..e13214ca362b9bdd23021189630= 08b04fcad8d4c 100644 --- a/drivers/media/v4l2-core/v4l2-ctrls-defs.c +++ b/drivers/media/v4l2-core/v4l2-ctrls-defs.c @@ -1136,6 +1136,7 @@ const char *v4l2_ctrl_get_name(u32 id) case V4L2_CID_FLASH_CHARGE: return "Charge"; case V4L2_CID_FLASH_READY: return "Ready to Strobe"; case V4L2_CID_FLASH_DURATION: return "Strobe Duration"; + case V4L2_CID_FLASH_HW_STROBE_SIGNAL: return "Hardware Strobe Signal"; =20 /* JPEG encoder controls */ /* Keep the order of the 'case's the same as in v4l2-controls.h! */ @@ -1282,6 +1283,7 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v= 4l2_ctrl_type *type, case V4L2_CID_FLASH_STROBE_STATUS: case V4L2_CID_FLASH_CHARGE: case V4L2_CID_FLASH_READY: + case V4L2_CID_FLASH_HW_STROBE_SIGNAL: case V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER: case V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE: case V4L2_CID_MPEG_VIDEO_DEC_DISPLAY_DELAY_ENABLE: diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-c= ontrols.h index a5b7c382d77118eb7966385c5b22d5a89bc2b272..2a09815939a6d9abbe2babb3429= e2227970275e1 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -1187,6 +1187,7 @@ enum v4l2_flash_strobe_source { #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) +#define V4L2_CID_FLASH_HW_STROBE_SIGNAL (V4L2_CID_FLASH_CLASS_BASE + 14) =20 =20 /* JPEG-class control IDs */ --=20 2.47.2 From nobody Fri Oct 3 11:22:29 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 071283451AF; Mon, 1 Sep 2025 15:05:46 +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=1756739147; cv=none; b=YGwv0xX7Tj4H/thLZ+Pdzl9J/0CivG2CcfcuAG2nOWTtEHmxLXAT66GVmliDn0LAl+BLPgz3W+UPwjMpJS0QrrBGprmptRkzgJvePodDviWF9WrjNAgW6wxuZrzsqWER0kTES5YrwtzLSaxF+kmoUyKiPuxLVuCbZbDmfzb+Dn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=7gQgghgArSKAOenBb3HDylNmZEFi8UoXEoVb822GcB8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UhgtOkZigjkMjNypRJlNQ62tM+6iP+LBZXPEP1wnocvl1kev39P6N11b5982vJ+MlgX6DxKqIlDcnh6XxykUu4XjSKieTy/XJNSz40XP7ObnG9iq6U+Mq8Rq8Q+gwpxydvMmJK4+xkSZR0Ei451k4Ikyc7FeRsEQzIG8Y3nlyE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=N5tD7WOt; 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="N5tD7WOt" Received: by smtp.kernel.org (Postfix) with ESMTPS id B82C9C4CEFC; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739146; bh=7gQgghgArSKAOenBb3HDylNmZEFi8UoXEoVb822GcB8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=N5tD7WOt2HLiGVypFiA5Kq0R/l5/dHnupfrp0CzY+aivDGvW8/uL4eQSg9c67D1FS 0RIUjt/wXMx97KgIpRdtn+VyCEWjbBh8EYrInufXQdjyeN8G6hNnB/xTJDkYhzyU7e XBY63T7lDcyfX/pTjRmy03qS+R9z8u5cZMJ8CcwQ= 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 B03F2CA100A; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:09 +0200 Subject: [PATCH v7 04/10] Documentation: uAPI: media: add V4L2_CID_FLASH_{DURATION,HW_STROBE_SIGNAL} 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: <20250901-ov9282-flash-strobe-v7-4-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=2808; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=7gQgghgArSKAOenBb3HDylNmZEFi8UoXEoVb822GcB8=; b=QiZKbRQCY/y7P1uLBfJKJQwuefOTmX/uyFOBUDr8tA8D+aBoLRhiO3DvI8crM9Jo3aDs7Tchs I/RXLojlh+tC3oCRSTmrqebkAYQn8Fh5PtCw37IcB8FEUScS/B6UrOd 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 and hardware strobe signal control to v4l uAPI documentation. Additionally add labels for cross-referencing v4l controls. Signed-off-by: Richard Leitner --- .../userspace-api/media/v4l/ext-ctrls-flash.rst | 29 ++++++++++++++++++= ++++ 1 file changed, 29 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..6254420a8ca95929d23ffdc65f4= 0a6e53e30a635 100644 --- a/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst @@ -57,6 +57,8 @@ Flash Control IDs ``V4L2_CID_FLASH_CLASS (class)`` The FLASH class descriptor. =20 +.. _v4l2-cid-flash-led-mode: + ``V4L2_CID_FLASH_LED_MODE (menu)`` Defines the mode of the flash LED, the high-power white LED attached to the flash controller. Setting this control may not be possible in @@ -80,6 +82,8 @@ Flash Control IDs =20 =20 =20 +.. _v4l2-cid-flash-strobe-source: + ``V4L2_CID_FLASH_STROBE_SOURCE (menu)`` Defines the source of the flash LED strobe. =20 @@ -186,3 +190,28 @@ 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: + +``V4L2_CID_FLASH_DURATION (integer)`` + Duration of the flash strobe pulse generated by the strobe source, + typically a camera sensor. This method of controlling flash LED strobe + duration has three prerequisites: the strobe source's + :ref:`hardware strobe signal ` must be + enabled, the flash LED driver's :ref:`flash LED mode ` + must be set to ``V4L2_FLASH_LED_MODE_FLASH``, and the + :ref:`strobe source ` must be configured= to + ``V4L2_FLASH_STROBE_SOURCE_EXTERNAL``. The unit should be microseconds= (=C2=B5s) + if possible. + +.. _v4l2-cid-flash-hw-strobe-signal: + +``V4L2_CID_FLASH_HW_STROBE_SIGNAL (boolean)`` + Enables the output of a hardware strobe signal from the strobe source, + typically a camera sensor. To control a flash LED driver connected to = this + hardware signal, the :ref:`flash LED mode ` + must be set to ``V4L2_FLASH_LED_MODE_FLASH`` and the + :ref:`strobe source ` must be set to + ``V4L2_FLASH_STROBE_SOURCE_EXTERNAL``. Provided the flash LED driver + supports it, the length of the strobe signal can be configured by + adjusting its :ref:`flash duration `. --=20 2.47.2 From nobody Fri Oct 3 11:22:29 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 4AE0D34A327; Mon, 1 Sep 2025 15:05:47 +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=1756739147; cv=none; b=HNsnd7hrA0GQw3JYQsONR66wj6yGqpT5GPZICqDDfnze9q2bJgr736U5O0qEacwFDDmPhIV5Cn/SWeACzToPgvu7e6Bft3loGgmpeH53HLfbDFLcj6ps1FRC8YFEIIpCi+znhmYjAB0Ui48PD5nZMh+5JdY2u1gm2vCDXVJKouk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; 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=KC8rnX515jFnjYy9gpIQDgAq83g0DK9rev7fGUGmOUNQsZAowFdsCLpF9CstxSWRppoXQaVj8VX2Lyqr8x+RRh9S7aX9oljU/aZ2zXRDUPfC88yzjnE6J0XZhhktY5Fv5Bv3jmm2f1OISUvolZdR+L3hOf4OW3+kUjU96Rc3tfk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=HWSpEE1b; 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="HWSpEE1b" Received: by smtp.kernel.org (Postfix) with ESMTPS id C98B4C4CEFE; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739146; bh=FNa/xvakH+OMufv25Oa47P8olVqt6It8kjPg/VhP/1A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HWSpEE1bkwLNslaXbKPTd3rek/QVBLe/iopCxzJ1FSOTUUfLVB6to/Z2nByTDsd+u D1WyKTenSsNBxpQNgEbMJ39We5jRT9VWWXANIugJeWWsYvZ364wmdHzqM/Qvr6dI6U F5FhUaVKL8bd6g1WswhUk9n9+Sur6NzU7tkN88hc= 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 BD68FCA1009; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:10 +0200 Subject: [PATCH v7 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: <20250901-ov9282-flash-strobe-v7-5-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=2191; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=FNa/xvakH+OMufv25Oa47P8olVqt6It8kjPg/VhP/1A=; b=CIbbIj33a6cWBIlMI9+a5I51/fKoYsAqaaW95TT4g2VRYLX4GrZSMfzmR2f36fW9hR4jVCqeh F4+n8hkGwQ5DQG72tbYPM0aJt1cUJDa6hgxkFg0f8l98vGsvjvHHg28 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 3 11:22:29 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 68C6034AAE1; Mon, 1 Sep 2025 15:05:47 +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=1756739147; cv=none; b=P+YflUFG+dGwqGm0/T/JTTbyA8v7lan01/whY3TUI1VobhNi6nSXihIM2px+FWWHEAWtPScqmkP2z610UCB4H0470phhW4V186wCcS/MVrfHZEK9ClHZbl3tdnd4ibhTcqSGVX6faLFfVoFaAwVNpsxidX2hzwj/6thN2baTW9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=DVb2HLHwrfJtO//bc3VRsb0hyCqNgQp8x5qpbcne0Ys=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pDn4uSqgH/UGRNYlE9wDLJOPsXxqg6TkKV+AzLCW/aCvA2wWejXk2hcIGJA/oKwdQVfRd7LYz1NFGZl6kPXYdz+4Sg0qjYLJ192Mz66DoVOsKBtu71gVUswnmQanDT/4Om9E4Y/l7jy8fP3Z80LdBnq+sVeaTpL1ED07QwREqtQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=R8Tw6lqG; 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="R8Tw6lqG" Received: by smtp.kernel.org (Postfix) with ESMTPS id D5050C113D0; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739146; bh=DVb2HLHwrfJtO//bc3VRsb0hyCqNgQp8x5qpbcne0Ys=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=R8Tw6lqGFzNHrKVUp66+BSI+2B+ISF4CotLXzyM8JxwHe+emYHoBAkVxmErJadVyM 1oM92vj8RCqHaF7UpUqDWdTX94+i8SBr2jVTtxy5F8JhW9NR2IhPW3sQCqZh1bcNnL YXRN32w4lDUGR6dNUa4IgS8zTMZ7KmOKLTeDWS/o= 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 C98C9CA1000; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:11 +0200 Subject: [PATCH v7 06/10] media: i2c: ov9282: add hardware strobe signal 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: <20250901-ov9282-flash-strobe-v7-6-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=2400; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=DVb2HLHwrfJtO//bc3VRsb0hyCqNgQp8x5qpbcne0Ys=; b=NoIxg5UUJoAjBg1+tSFc7WCbYqpk+kD72PTLB9X7/WdlNyPPuPoJsE27JX1uokA/XflaX17H8 XFfEGcSLdYUBjACmoyf5ePKZHjlFWUKaTIpuW7v3vGf1kLslXG8cKh2 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_HW_STROBE_SIGNAL enable/disable support using the "strobe output enable" feature of the sensor. 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 | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index f42e0d439753e74d14e3a3592029e48f49234927..ff0f69f0dc3a2d0518806b9ea65= c1b520b5c55fb 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_hw_strobe_signal(struct ov9282 *ov9282, b= ool enable) +{ + u32 current_val; + int ret =3D ov9282_read_reg(ov9282, OV9282_REG_OUTPUT_ENABLE6, 1, + ¤t_val); + if (ret) + return ret; + + if (enable) + 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_HW_STROBE_SIGNAL: + ret =3D ov9282_set_ctrl_flash_hw_strobe_signal(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,9 @@ static int ov9282_init_controls(struct ov9282 *ov9282) OV9282_TIMING_HTS_MAX - mode->width, 1, hblank_min); =20 + /* Flash/Strobe controls */ + v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_HW_STROBE_S= IGNAL, 0, 1, 1, 0); + 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 3 11:22:29 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 491C034A326; Mon, 1 Sep 2025 15:05:47 +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=1756739147; cv=none; b=vBdJ31MnKG1kIdPMmtspPXlX0XMHGwAl31BdvvzyhN5dxw2E7+upjIf7Y0A5RkmeWu+CEvW3O71uwnbK1n12e89aH11sSxzU2+hsG/AoclsoegZKbquNYxCcHJL8h3pU/yRP3DDrkJK5W9tjwfvDx7eCuWI82v9zByfqTpkQTy8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=zHiadu/PJkoFNn6YwHGG0Az+tad6OHewe3uLyIg6GGY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZwG4DbbHS4ziSZFLt38heOMoOl9U/c1VHSV6jzfDILsR41xlPOm9t38h10XV8zHJWfzU2hYz4+xzkr/V0QYZ4wEvPHRomjtrVRD0y0ZuFyQgpVMjSLKRi7Z3McM+/m2ay1ORDCwKi4/4BCGFGG/Wu046qpNhyVHlJob1wF55SOI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=khzMcds9; 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="khzMcds9" Received: by smtp.kernel.org (Postfix) with ESMTPS id DD33CC16AAE; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739146; bh=zHiadu/PJkoFNn6YwHGG0Az+tad6OHewe3uLyIg6GGY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=khzMcds9EocvGOBRIBhpjv5/Uhq+CAd+NQ40WU0JsK2E93mREuF1pGomJLoP2JtWK 5X3mRNsQRZG+PC1KCdXSmlZ1LSnHmkkITnbmRSsCtAeqlpi99uhfs3nqGDbeo5U6nW pUfAKF5B8pZpOHuaWH7Q7+fyafgo3BujSJ3eOvzQ= 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 D5AA9CA0FFF; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:12 +0200 Subject: [PATCH v7 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: <20250901-ov9282-flash-strobe-v7-7-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=3529; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=zHiadu/PJkoFNn6YwHGG0Az+tad6OHewe3uLyIg6GGY=; b=16+arFAFs6tUt862WUqqdOIz7Bp3nAPy/UtsL5FYgvbkTSbwZzg8uWu9c/E/s8JDG9xzMczYM 8QWVBn19fdZCG6Uo4nFG1QD2PPA46RHFlk7XEJiwIbCq4xnO9acYGn4 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 ff0f69f0dc3a2d0518806b9ea65c1b520b5c55fb..c405e3411daf37cf98d5af35357= 02f8321394af5 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_hw_strobe_signal(stru= ct ov9282 *ov9282, bool en 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_HW_STROBE_SIGNAL: ret =3D ov9282_set_ctrl_flash_hw_strobe_signal(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 @@ -1414,6 +1440,9 @@ static int ov9282_init_controls(struct ov9282 *ov9282) /* Flash/Strobe controls */ v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_HW_STROBE_S= IGNAL, 0, 1, 1, 0); =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 3 11:22:29 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 68AFB34A33E; Mon, 1 Sep 2025 15:05:47 +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=1756739147; cv=none; b=tO2fBGerS9VBk2gXc5XL+U25nIzjBxV2OO5Jiv5+WNYyE7jTrwTLNAedqIzf3HzXLhKEbhNDAYkLNJp4evSfNNZMhxj8XA4WxppsCL5E2YJxCTdnYPacHs06bEUTZqKi7epF8BCEfJVzhJ85TcWY/JCWoQxUkAp4lvaKTsE1kHo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=2+Ajed5E1fXJz3nZ8NS8d6YJI4WoVgJl21IHABX6Yk4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eq6t3GF8YcigamJSbQFzAKNT1ARybeH7Pe9ehKfHPtwLTdr8QG+Qgqk6PhInA4yP2ZEN5yGqRLyxSmCBqhzwuJgjr/o3fOiQbSvl9RzjY1/ER8EX1ZDUGtpaMv6Jfue86a7FctIPjp/ynDObRJ0PyN4fryUXrHoWmE8OLlB1QeM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=BSa17T9r; 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="BSa17T9r" Received: by smtp.kernel.org (Postfix) with ESMTPS id EACCEC19421; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739147; bh=2+Ajed5E1fXJz3nZ8NS8d6YJI4WoVgJl21IHABX6Yk4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BSa17T9rYYkWiL0uWAaRAiiDcWIrspdRe7SoBWhpkVX8B5X4no2fkdz4CjMv/Rh0x pjnENJfu+ROFE6BYUwZ5Ju+pXxSfjwy/TZeD2BPacdrdPN7Ku+iB2tUW6SYmeU5a1f HuvqTNvJAGEyXnftupvXe4+2QY27D3tW+lwHMUM4= 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 E1B43CA1007; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:13 +0200 Subject: [PATCH v7 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: <20250901-ov9282-flash-strobe-v7-8-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=1686; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=2+Ajed5E1fXJz3nZ8NS8d6YJI4WoVgJl21IHABX6Yk4=; b=8OHsE22R2cOPgWq3x0l1CfnNzun/KyfadK8N9dqtfPAy9BPhJwFcG3TI2RlZUE+FeJGvRe98H tmsICNYjHadCohKKUclKZBtCYU65z9X+ZzjjCfMwdnUE9djwmUetSDs 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 c405e3411daf37cf98d5af3535702f8321394af5..9efc82a1929a76c6fb245e7dbfb= 5276a133d1c5d 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 @@ -1443,6 +1444,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 3 11:22:29 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 68B9834AAE0; Mon, 1 Sep 2025 15:05:47 +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=1756739147; cv=none; b=sXcelN8yA2ciyoRYygOosDcPr3KF2l0Js0eRpzTKgIjzBpV4sxjBBZxiO+ftUSXqsXHsgntqF3NI1QmVXZJLTAv4xJRv8CG56lgrp+hrtlSHq4/HJPBny8ezifmGePcDqIwQQg32/nMTxzGdJgOO3vfUSWq2yM45ZhefJQ5XdH8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=zpPHdpszebqthTo574ANivruP/PT3WTF/uH/e9F0K+Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nSDa8GfNXgb51Z634QVdUVJtb2xTd0COBzhmM9Rwuu+tiaXH7y4HRLQx/U9YOsetbRTHudLp4CC37SGM4PqvvhjPI1GEIMkHGNX83TmKMiEk2uTreq3kN+UHNkxgHmQSmToZ3R1T3M5aUSTbQqsam9AN7cLHlv5f80vs98yFU0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=mIf25cQV; 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="mIf25cQV" Received: by smtp.kernel.org (Postfix) with ESMTPS id 02767C116C6; Mon, 1 Sep 2025 15:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739147; bh=zpPHdpszebqthTo574ANivruP/PT3WTF/uH/e9F0K+Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mIf25cQV8ZhTdwMszcMm+F1rFA7t1pS9Wyl45cP3mzNddcK2tMoyB5byPfky9NY1v ama5ZVS3Ui3CeOiNgOjX//ue6qdyDSbXbnvEdEwAn/0zD+zkBeyPdJLdEl6jiA9p9z XRh5BX2O/2lguT+GIfaQZh668Up8JyRBCKZkezH4= 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 EE14ECA0FF0; Mon, 1 Sep 2025 15:05:46 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:14 +0200 Subject: [PATCH v7 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: <20250901-ov9282-flash-strobe-v7-9-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=3557; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=zpPHdpszebqthTo574ANivruP/PT3WTF/uH/e9F0K+Q=; b=fdpLvNSFQTEl59tQ4YakjWj1z05zOCV+ppEi1wuerOUr0783No1fAR5HN5UemEDEp2sPKBg5T IUi4JPUzkgHAn4LjpaiRldZVANfx4P4WAnHDgSSEAIrMxjOUzoF+doI 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 9efc82a1929a76c6fb245e7dbfb5276a133d1c5d..b104ae77f00e9e7777342e48b7b= f3caa6d297f69 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_hw_strobe_signal(struc= t ov9282 *ov9282, bool en 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 3 11:22:29 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 5AA8434A329; Mon, 1 Sep 2025 15:05:47 +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=1756739147; cv=none; b=MminJmCgo6Yh87XQDnWLhaeR3keQ56kcuYPx9h9ZDXmdKkp6oJqedTWEmLWXlVsvIwj62RI1sBd+6d5ex+1WaUWJIJ95aJmQgIJmDeglMZYQj1oeqkqPVFdWA/JMlKUMcaTOyVXIru8t0JXiQ1KSpeliaHUTxhKszVrUigY3Zmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756739147; c=relaxed/simple; bh=I5haGetjk5CR5fMUuZoz3rwX2PVyWVsn8Vb9i7Affcg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aTH7e4R/UisDqCPT5gUootB1G49OzewQE81dKCHtuNXay4nahiB/0awVfMvwA8m4myZmJ/hfZKlx4dLimMIEJxkqarXM5+HaMsfj8vAqOLlWzaIqJfHjhW73E1hZQ+j6w3aZ2uZ/YD3cOjm0AppVcRtwK08ZtK+mI5Zrrx89NVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=YKb9wlDx; 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="YKb9wlDx" Received: by smtp.kernel.org (Postfix) with ESMTPS id 137C0C2BCB0; Mon, 1 Sep 2025 15:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1756739147; bh=I5haGetjk5CR5fMUuZoz3rwX2PVyWVsn8Vb9i7Affcg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YKb9wlDxoHkemyeDNWEemnOwySymjJGElXn8tMrjgTfJfd7zab7/W87bug+d9YY4y sMcObFiB4pYEeGjvltYuQjS0vESi52sI59AN0QVgNxSGR6uLvuTw4yLXvNx3ycijX2 j1UPUVniFii06+uG3zvQqe8H1q2Kod9g/MfbAuQQ= 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 08178CA1009; Mon, 1 Sep 2025 15:05:47 +0000 (UTC) From: Richard Leitner Date: Mon, 01 Sep 2025 17:05:15 +0200 Subject: [PATCH v7 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: <20250901-ov9282-flash-strobe-v7-10-d58d5a694afc@linux.dev> References: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> In-Reply-To: <20250901-ov9282-flash-strobe-v7-0-d58d5a694afc@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner , Hans Verkuil X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1756739145; l=3617; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=I5haGetjk5CR5fMUuZoz3rwX2PVyWVsn8Vb9i7Affcg=; b=89ndo5Sw4zw/nKvZB93fs7yxRCVJKeS0iI6Otle9lIxMlvzB4Rz3LpY2Aqd3yHiHOnyYVrQ0u CqGOYzBWPUMBWG+AdLax193OsQiKxpneeKn3J0jH2JyXxGI5vJtkd8H 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 b104ae77f00e9e7777342e48b7bf3caa6d297f69..3253d9f271cb3caef6d85837ebe= c4f5beb466a4d 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 us), 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 @@ -1491,8 +1510,11 @@ static int ov9282_init_controls(struct ov9282 *ov928= 2) /* Flash/Strobe controls */ v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_HW_STROBE_S= IGNAL, 0, 1, 1, 0); =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