From patchwork Wed May 7 07:51:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888387 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 1A099221263; Wed, 7 May 2025 07:52:21 +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=1746604342; cv=none; b=fq620okQWQ/7IuQW+7lhuhh7Z+tV3zDYN4dUmnkvT///HDFsKUFRdhc2ryPlrWPrVY+cqMwyXsGwZvRrg11MA1UdTU5Gpun0rnqSO15GXc8d/E6vBjB8nB3NVlW2o4wJkTwbsMAwKIdPvEKUUCDveWmipP6SERYgZBYDMSfAmKM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=0nzpfTzsTCcWDqac7ZTk2BZgJrXNm8rZpSw6OMimBsU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DQOdj73zLrpYfUzaBSWtnFC57f43YNv51UdfPKA4BzNeBbFci+UyO/VwlSNO5NMVMCNIQXw12pUIHVgLr1wQ12Xjl8xJ4R/qbozp+MKQAM9sjJ+x9dc9nOZbcRmLr+rcSCUYybR6ZEelRcRCDksOAu3s01AboUZ2e2qoEubZe7k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=S3Wo3hG8; 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="S3Wo3hG8" Received: by smtp.kernel.org (Postfix) with ESMTPS id 956A9C4CEEE; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=0nzpfTzsTCcWDqac7ZTk2BZgJrXNm8rZpSw6OMimBsU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=S3Wo3hG85g7wVju04EV7FIznxnH8vKnrueaMvjmvKzZ6ytBfPQMIR+Yr2EQrweJpJ AC6tkO+gOCNxar9ki5sjnuapjUFII7gW3eRGLWGdf31ReOjAptXLbYyMXLUxDGD9Ze F3d16/bVuA/lm1S0Hr/r1BxBmxDJDWaSNeJdfSqo= 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 8AEACC3ABB6; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:30 +0200 Subject: [PATCH v4 01/10] media: v4l: ctrls: add a control for flash/strobe duration Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-1-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=1793; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=0nzpfTzsTCcWDqac7ZTk2BZgJrXNm8rZpSw6OMimBsU=; b=N9DzPtzRdXQB1V4N/WXrsdb69R9cQzPbFuYPlMyrCKHSAjKtCHVtxj9Nc6Ku1Ve9PR7I+Xfl4 l366x+8CNm8D11O8iEB2lL4e3otJGna6b2I1GWPQfJjJMuR2Rb+aR9z 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..f9ed7273a9f3eafe01c31b638e1c8d9fcf5424af 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"; /* 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-controls.h index 72e32814ea83dee5f1202c1249eac7cf3b85a22a..72c6bd26e2dfa23a0224e745e5cd07c9fca0c8b5 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -1180,6 +1180,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) /* JPEG-class control IDs */ From patchwork Wed May 7 07:51:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888728 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 1A1BB22128F; Wed, 7 May 2025 07:52:21 +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=1746604342; cv=none; b=IXYLwbCtmkU8/21z9WJaU3OROnKOQmiflq42mpg+7Wd3zAu68Cw+g7d5rlxH0w2apCDxt3s4+cwbKYMW/6gn0L3PXEonYuP+j1UMs2IZKOWf2w3lZjH/EMkU3K5oEbQSHLi/ebJJV68AtE7lwCKsnhR+xUhCasLFuDM9E5+NCSI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=HDEsgaluUKEPdxixqt/Aekf5T3lFNnaVwddtdEWptfw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=F+L6lVzLP8ZVKusJFrrOE3/zJB5w75ns8fgMBSPD6whq4D5BWiXoCK6V9f9ABNXuDIOOT6l93YVjpbYzxyZsl4VMAqexoJNVyVzEfThLPpKXzaZt17HnP1HfIw59lo1nUSLVX7D4gu7/qFKSmbq7ZWvgEDWwNyiJ1h/nngCttOg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=hTaDlHRU; 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="hTaDlHRU" Received: by smtp.kernel.org (Postfix) with ESMTPS id A1E87C4CEF0; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=HDEsgaluUKEPdxixqt/Aekf5T3lFNnaVwddtdEWptfw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hTaDlHRUIBy1bwLIoANv0KIi88k2EkNnh9a3D4AocBMggKEqmkxjXmg8phe1wKK9r RM0TPbQ9Xw23TRA8bz/CsknxHwSqkv/suOnzxv4F7vBUN0fCQItasXhM/QxcnjquoC F4MqHebHz+e4WSQlrljXVA834ySDKmj30VBFRtmc= 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 97323C3ABC5; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:31 +0200 Subject: [PATCH v4 02/10] leds: flash: add support for flash/stobe duration Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-2-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=2827; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=HDEsgaluUKEPdxixqt/Aekf5T3lFNnaVwddtdEWptfw=; b=L6C9/W6cdHBb+g9hw0+DOmZZ250LALX105tP2ZD+8LdwzzyUF8269B56sm6ZnMm6F2OMB67lj A4h36ScTg2cA3ODn+fvPpSpqgbr8GuZSB7/8QHmL6ayvwNbPq0ulaAd 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 leds driver. Signed-off-by: Richard Leitner --- drivers/leds/led-class-flash.c | 15 +++++++++++++++ include/linux/led-class-flash.h | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/drivers/leds/led-class-flash.c b/drivers/leds/led-class-flash.c index f4e26ce84862c05092a9598e63ed301967852f13..165035a8826ca7d44a5cd265a5130a76c6e94347 100644 --- a/drivers/leds/led-class-flash.c +++ b/drivers/leds/led-class-flash.c @@ -440,6 +440,21 @@ int led_update_flash_brightness(struct led_classdev_flash *fled_cdev) } EXPORT_SYMBOL_GPL(led_update_flash_brightness); +int led_set_flash_duration(struct led_classdev_flash *fled_cdev, u32 duration) +{ + struct led_classdev *led_cdev = &fled_cdev->led_cdev; + struct led_flash_setting *s = &fled_cdev->duration; + + s->val = duration; + led_clamp_align(s); + + if (!(led_cdev->flags & LED_SUSPENDED)) + return call_flash_op(fled_cdev, duration_set, s->val); + + return 0; +} +EXPORT_SYMBOL_GPL(led_set_flash_duration); + MODULE_AUTHOR("Jacek Anaszewski "); MODULE_DESCRIPTION("LED Flash class interface"); MODULE_LICENSE("GPL v2"); diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-flash.h index 36df927ec4b7dcaf9074c6ef32ac8ce83a87a79d..21ec856c36bc67decda46aa8ff1c040ffdcf1181 100644 --- a/include/linux/led-class-flash.h +++ b/include/linux/led-class-flash.h @@ -45,6 +45,8 @@ struct led_flash_ops { int (*timeout_set)(struct led_classdev_flash *fled_cdev, u32 timeout); /* get the flash LED fault */ int (*fault_get)(struct led_classdev_flash *fled_cdev, u32 *fault); + /* set flash duration */ + int (*duration_set)(struct led_classdev_flash *fled_cdev, u32 duration); }; /* @@ -75,6 +77,9 @@ struct led_classdev_flash { /* flash timeout value in microseconds along with its constraints */ struct led_flash_setting timeout; + /* flash timeout value in microseconds along with its constraints */ + struct led_flash_setting duration; + /* LED Flash class sysfs groups */ const struct attribute_group *sysfs_groups[LED_FLASH_SYSFS_GROUPS_SIZE]; }; @@ -209,4 +214,15 @@ int led_set_flash_timeout(struct led_classdev_flash *fled_cdev, u32 timeout); */ int led_get_flash_fault(struct led_classdev_flash *fled_cdev, u32 *fault); +/** + * led_set_flash_duration - set flash LED duration + * @fled_cdev: the flash LED to set + * @timeout: the flash duration to set it to + * + * Set the flash strobe duration. + * + * Returns: 0 on success or negative error value on failure + */ +int led_set_flash_duration(struct led_classdev_flash *fled_cdev, u32 duration); + #endif /* __LINUX_FLASH_LEDS_H_INCLUDED */ From patchwork Wed May 7 07:51:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888729 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 1A15E22128E; Wed, 7 May 2025 07:52:21 +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=1746604342; cv=none; b=ubHUzdcHlWSrgGDeggxKf3A01upnyBcM0LXfZyoKWRrSpOTBdIshiwrmDlk4Ci8cEUCWbrS69DjXJQ7fRUNBCRb6JhOWysiJNWLRu4BrHzLant9jfHFni8zQtKNRwMkkb1lEtpFyXT3r6fPcjFfDipZx0RXAMK6lEEw9qjW5rxY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; 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=dJNSISG2F7fptSSoe12Fjmo6EN/vVtveaOd062YtRQa7SRv9YEIFUX7wo3SgN6zEkWCAyvf0IZTJXvCVsGCo6/x9QmW4WkUBIpoI+zLSx+4mD0xB5gXpdVb6Ku3akIdz4iDOCbuIfQZSDvywzN/Ny+Y7mb2AlfjCtYrmJOfMfJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=q+URzq/s; 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="q+URzq/s" Received: by smtp.kernel.org (Postfix) with ESMTPS id AE1A3C4CEF3; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=FrCl/fSGFBnOk0+MAcM+KHDO4zcSf1DpGTy1y8P+ack=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=q+URzq/sbJMHpQqdlTTWPoGx7zGSLFLXb62D/DlmPT/JlIP4sZePZwBVpiivcIaZu 1JQEVBVYr2yPHb8wSQ5pKPjDbki4pufGXvexc4AEohV4fD5yHVQGwj8F6A/KpM944Z vgB3fUwUeWaPqtZIZEZaKB9URx7tTPi7Or/MzFaE= 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 A32BFC3ABC7; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:32 +0200 Subject: [PATCH v4 03/10] media: v4l2-flash: add support for flash/strobe duration Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-3-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=2303; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=FrCl/fSGFBnOk0+MAcM+KHDO4zcSf1DpGTy1y8P+ack=; b=LFm6jfHw/aS94xmb1iqQDZ/pOyYg2GDZlwq24FcY8iKN5HTpl3F3nH3MhreBtkYeZHtBpElL0 mCum4SwegdSAk84ivRqh2Lu8bIgT6Ud7qg6e0ENe+jDVyAywfGp5BOa 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..69b6c2026e0ad905aaebcdabe1e7002fc48f9e2c 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); } return -EINVAL; @@ -424,6 +431,14 @@ static void __fill_ctrl_init_data(struct v4l2_flash *v4l2_flash, ctrl_cfg->flags = 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 = V4L2_CID_FLASH_DURATION; + ctrl_cfg = &ctrl_init_data[FLASH_DURATION].config; + __lfs_to_v4l2_ctrl_config(&fled_cdev->duration, ctrl_cfg); + ctrl_cfg->id = V4L2_CID_FLASH_DURATION; + } } static int v4l2_flash_init_controls(struct v4l2_flash *v4l2_flash, @@ -543,6 +558,16 @@ static int __sync_device_with_v4l2_controls(struct v4l2_flash *v4l2_flash) return ret; } + if (ctrls[FLASH_DURATION]) { + if (WARN_ON_ONCE(!fled_cdev)) + return -EINVAL; + + ret = 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 From patchwork Wed May 7 07:51:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888386 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 2D167221291; Wed, 7 May 2025 07:52:21 +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=1746604342; cv=none; b=mIEy2SQb0/Y6CVYjq4rlXnARp2/JoiX/pbFIUaf6tBTkCyNy5yquf/g5n4OAh62rD99G3oWHqIW09oveBxcVDfAPK0p0xS62sG4+pcf5zvSmIY4J9WcMQx2llGKp1rXW1HYiLU2H7tIpFM1QM+AvfR3lyQan5+MNGsX/eyrAzEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ut+k9vFeI3iTtaIvpxzXAaeoqHeLq3XsLNIzH7+uUbjfPqgAPmt6rGoi+sFr749gBA0maDwvNZkvZE1FgQAlFKoF96t5zbvB1aRrxwfqT3tk8m74SQyU+nGFhQ8Tvln+UAYsXOg/Kp0G3eJ2GLYLL52QlMui4FBubMlnhT8H1NQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=B1vmsQRK; 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="B1vmsQRK" Received: by smtp.kernel.org (Postfix) with ESMTPS id B7EA8C4CEF1; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=B1vmsQRKT5UJb1lRFC1PRFDgDduKUgj9imFffCj9TTmmrFXPfUlehLJC0z8VStTcC HRsh2EBLX90MQCJHmOTjIysEOwR3KSO5oT9Nmk/XAwAgC5EY4B5C0ATyLLOg/cc2xX 9gSTG6Usd+KkgAXJzOYNdD/2scKHQHYAS8tcyKxQ= 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 AE3F5C3ABC6; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:33 +0200 Subject: [PATCH v4 04/10] media: v4l2-flash: fix flash_timeout comment Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-4-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=878; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; b=b2Nu8Rc5xjROLfjqidwVk6M111UQMbP4ju6/jmlZi4aCroekRypMRf54JGKcAOzlwN4LmC0a2 R5aMxYdUac9DWdDxNqwee9VzCOlRqZlcvZpxX+OWOdpW9qrwepzz0bX 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-flash.h index 21ec856c36bc67decda46aa8ff1c040ffdcf1181..775a96217518936633541c7a5d394502dbf04f83 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_flash *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 */ From patchwork Wed May 7 07:51:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888384 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 7CFD6221D80; Wed, 7 May 2025 07:52:22 +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=1746604342; cv=none; b=Cshu/PfAEeVEWMlhiASet3euo5SiT68OVBFhwRd8j/JDBPWOgzq/apMYPDOyP3PYTTvEEDTfl73oT+Z7SxjXEsOXEqmwGcdsXvhjm5R5AGVdglfb9PJEFpwn50U6uxjOAlaQfo7+BLs/oh/pa82JIYIetgb7Vlz6kGtrusBSJKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=16N0ehkJWytFD5jx5wDbSTZhtNf5Qf6vx2SOhlkAC1Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UEUDAIzNLTiZGSCZDDEna/4WJ/h2EN5jf574HHyhjwhH9fZ8XaNf1uHOfRRba+KPmfBAoiDux8CEc0BDPEb3PqEUZPQapTHSX/rLR/hehUMtIFU6BrJT2soQkSZLyuEqdH53vVYauRm8aE0azbwMwQ9k/ckTfB7rVAgKw41TAh4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=q5cYV6Ax; 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="q5cYV6Ax" Received: by smtp.kernel.org (Postfix) with ESMTPS id C0144C4AF0E; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=16N0ehkJWytFD5jx5wDbSTZhtNf5Qf6vx2SOhlkAC1Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=q5cYV6AxCe9qy4dmK2YfbzIXWmoB9a0x9HrZU77jhl7VOyObGl2FfnlmKxUXwKMC3 qjmX3estUJfFhEp1vQXgAUGKhXz20SoeNaT1/kMpytGsqq/nmlvD95y8lmrH3r8rhi uIvF37jUxf2orKzbXRYvW8S3UMOHoPmFDIeh6dFU= 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 B99C3C3ABC8; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:34 +0200 Subject: [PATCH v4 05/10] Documentation: uAPI: media: add V4L2_CID_FLASH_DURATION Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-5-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=1038; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=16N0ehkJWytFD5jx5wDbSTZhtNf5Qf6vx2SOhlkAC1Y=; b=/I5T0pCsjZEp4kUhnrtVRfvxoNLTul5W3RVOawLehNl9mE9tS/opp8ie52Nl0r6WLnDclK2yj XmuajaKLaKsDQ44H/Lyj9cFX8RR259TN4NcSLalpvo9+lRVIK8bMXcb 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/Documentation/userspace-api/media/v4l/ext-ctrls-flash.rst index d22c5efb806a183a3ad67ec3e6550b002a51659a..03a58ef94be7c870f55d5a9bb09503995dbfb402 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 (µs) + if possible. From patchwork Wed May 7 07:51:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888385 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 5F871221710; Wed, 7 May 2025 07:52:22 +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=1746604342; cv=none; b=VDvXlGvmrDHr4zGEViwYVaTHMcoaamQ+BweDAWeY+VgqYfHAlZPRiLoXWBh/1HUIJtuSg02Shs8G2I6NRuUZ4hBHnFrX01gy8rwO0sQi0LRNfLRN/G7CQ2+7dAkkh0XiLRP0JFpCWWtnjzKiy3GUW421cAjOFirMe9PCsSZ5INE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; 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=eXAB84oGZUxKrKpLvKETuVXhII1ScQP8HWRJkIq7yHhHkzWPUYdy/RaKwuLIPjT9ZnZ2HPmteCXQx17XDQn73XY2lb0L6iuoIbJo0uBnmVZgj0dEHu8MxZwqFjbHdQueT9WPSGDZxabX+MjWpoCsL7+tq/HbKCQLAO0mW3exHRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=efqgVTqr; 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="efqgVTqr" Received: by smtp.kernel.org (Postfix) with ESMTPS id CC387C4CEF5; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=FNa/xvakH+OMufv25Oa47P8olVqt6It8kjPg/VhP/1A=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=efqgVTqrXtnPdwLl4uWtfPRpr2qVZBZtuGM+3fzfQx2f/QpWQgcRgFhpqMdhkd2JT 1pbpHGLjfwP3iYvfjnlgba/Hzc3qzq0wyQ/hNotuBjUetdpN21Lozqh9B8tPtubSut JZcQsRIO/PcqgjFJdzUI9ktDAE6sZQFzDWTqsKO4= 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 C3F01C3ABC5; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:35 +0200 Subject: [PATCH v4 06/10] media: i2c: ov9282: add output enable register definitions Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-6-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=2191; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=FNa/xvakH+OMufv25Oa47P8olVqt6It8kjPg/VhP/1A=; b=SwzocbauHwPRNtcubYFHktRBBs0jHcsZ9HRKoOhf7PB0ZiEwXdDuvU43Nwtjab+iv/unURujW zlA0Bowk+aOAZ65ItVZZi5++M6M+FMSItKc/qWNl0g+OB57fr2AlcAA 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..f42e0d439753e74d14e3a3592029e48f49234927 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 +/* 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[] = { {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}, From patchwork Wed May 7 07:51:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888383 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 803DD221D88; Wed, 7 May 2025 07:52:22 +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=1746604342; cv=none; b=PsmZPOr+ypWuQ6qvhw6p9bd3OeGtlsTGUePh77XtzVs5Q+YiiCowCOkCzqECzmCbLewkWm8wGDitRqVfscEhy7MzJM+Gvshek34N5sp9g9irLahbo3C1CZ9FHPUcH38XnFwzJ95ujNWOvhbSjvBljSeuzWw/T1/hQ4uKZ/aVoqY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=vj4AZ2VwKF/zDloCshyajTedmued0DDmjMCD6CM2Ep8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GDDHuzoFmuSBXjEEIcOD+x/qquBh3i5WRdncvpicnRgKiRwdH7zQ+DSXIFHknZtIF0966wY4GimfSALr3giSeO8H0s08Dji/XFJVhdz4ht/ViVxVaO2pyACO7CeaEZCJn19ia/VZKTz8pSdT87pzyJVuIXZYCjhmO7SBUZutlaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=RWJwmAyH; 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="RWJwmAyH" Received: by smtp.kernel.org (Postfix) with ESMTPS id D81D6C4CEF9; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=vj4AZ2VwKF/zDloCshyajTedmued0DDmjMCD6CM2Ep8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RWJwmAyHSypXEoWtaUIf+ITOOZaMNGAjSSW8czKmr527r1PaUB0vlWz7FVgvcr5q/ erep/EcEzOYvqFhzQXU99haEzejVptUGjpFnG9BCKyRxqlfFnNcAXOJkASKtPy8tZ8 /cLFlWR5wZUBJTfjXChIuIwdJWxI7aWYqiMnmCqY= 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 D1BF4C3ABC0; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:36 +0200 Subject: [PATCH v4 07/10] media: i2c: ov9282: add led_mode v4l2 control Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-7-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=2663; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=vj4AZ2VwKF/zDloCshyajTedmued0DDmjMCD6CM2Ep8=; b=tfNHFWJ8FRso9WuMaIOv3IfWaC05MnFKIpbuE4ZpjAaOTDPPx1INoUgTPoq6cDgHZNkmZAMck PLCcl5XCqQqBv2YXrZf+j0PSdq/THm3/pAnJmtgONVZFUdHA6+qg8bq 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..b6de96997426f7225a061bfdc841aa062e8d0891 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); } +static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) +{ + u32 current_val; + int ret = ov9282_read_reg(ov9282, OV9282_REG_OUTPUT_ENABLE6, 1, + ¤t_val); + if (ret) + return ret; + + if (mode == V4L2_FLASH_LED_MODE_FLASH) + current_val |= OV9282_OUTPUT_ENABLE6_STROBE; + else + current_val &= ~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 = ov9282_write_reg(ov9282, OV9282_REG_TIMING_HTS, 2, (ctrl->val + ov9282->cur_mode->width) >> 1); break; + case V4L2_CID_FLASH_LED_MODE: + ret = ov9282_set_ctrl_flash_led_mode(ov9282, ctrl->val); + break; default: dev_err(ov9282->dev, "Invalid control %d", ctrl->id); ret = -EINVAL; @@ -1326,7 +1346,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282) u32 lpfr; int ret; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 11); if (ret) return ret; @@ -1391,6 +1411,13 @@ static int ov9282_init_controls(struct ov9282 *ov9282) OV9282_TIMING_HTS_MAX - mode->width, 1, hblank_min); + /* 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 = v4l2_fwnode_device_parse(ov9282->dev, &props); if (!ret) { /* Failure sets ctrl_hdlr->error, which we check afterwards anyway */ From patchwork Wed May 7 07:51:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888725 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 7EC30221D83; Wed, 7 May 2025 07:52:22 +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=1746604342; cv=none; b=A2Be+MASb327ibHpGY4e8V3pVgFRMBgFwFbsCilkzb/sy6vkqW0YyJLZmP1EPjD61JQ4Jt0AG0lF9gejxKJU2iTVoIZJM5zBpdvB6ypK42F4/w7cIte4KSI93OkC0YOkIgtBl9ikgzLe7HksKeUxffAa5TYXL/U3ROXbVRm83LA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=GwAJbtPkRHjKJSJXD8je918r9KcSpVtLEPvHlE3Ftbo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sY/WVGTGLD2HCEeFEvbig8RjpL5V0fYEU4Z0Myww2YfW9Hq+pG9zF68wZT1qrjp/nMEQrEdsk6agSziiSHIsjF5Ai5wUkfV7B1KfdhMGt83SxhakOx1I/kUH/kKODQdcRZAQbQ9cpfwdSmBre01Ov0syueSo/zVZ5sT0XCrj4QY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=zPzu92A2; 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="zPzu92A2" Received: by smtp.kernel.org (Postfix) with ESMTPS id E1E88C4CEFE; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604341; bh=GwAJbtPkRHjKJSJXD8je918r9KcSpVtLEPvHlE3Ftbo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=zPzu92A2zbQ1giPlEA/lHKJ2nrC4UZiYSiMY53Zs9XF/rT0uYC2iuuQ575o6zF8PY PR1F8//XNZtwGaMmxYmsCrMutXLen4prVBLeknxvR6owoULCLoyx/gXn3Kzgn+/Cla J6KOKTwbEynnMetdmeFyPyo4EHezTGjAbA1WErB0= 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 DCE55C3ABC9; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:37 +0200 Subject: [PATCH v4 08/10] media: i2c: ov9282: add strobe_duration v4l2 control Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-8-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=3465; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=GwAJbtPkRHjKJSJXD8je918r9KcSpVtLEPvHlE3Ftbo=; b=YLTqVL/QOzefO13jNk2snq6EPLc1gQYk/jRaF7MdoabQc56jJxDsp3dZPGm+VYAMBmUcvksZM Oc0rzOjl5PsDSGR34GRO0/oFN6BzPXisC+JFSwmJxXqwTInSSJ46LPo 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 µs 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..0bbdf08d7cda8f72e05fdc292aa69a4c821e4e03 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) +/* Flash/Strobe control registers */ +#define OV9282_REG_FLASH_DURATION 0x3925 +#define OV9282_FLASH_DURATION_DEFAULT 0x0000001A + /* Input clock rate */ #define OV9282_INCLK_RATE 24000000 @@ -687,6 +691,25 @@ static int ov9282_set_ctrl_flash_led_mode(struct ov9282 *ov9282, int mode) current_val); } +static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, int value) +{ + /* + * Calculate "strobe_frame_span" increments from a given value (µs). + * 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 = 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) & 0xff); + return ov9282_write_reg(ov9282, OV9282_REG_FLASH_DURATION + 3, 1, val & 0xff); +} + /** * 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 = ov9282_set_ctrl_flash_led_mode(ov9282, ctrl->val); break; + case V4L2_CID_FLASH_DURATION: + ret = ov9282_set_ctrl_flash_duration(ov9282, ctrl->val); + break; default: dev_err(ov9282->dev, "Invalid control %d", ctrl->id); ret = -EINVAL; @@ -1346,7 +1372,7 @@ static int ov9282_init_controls(struct ov9282 *ov9282) u32 lpfr; int ret; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 11); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12); if (ret) return ret; @@ -1418,6 +1444,9 @@ static int ov9282_init_controls(struct ov9282 *ov9282) (1 << V4L2_FLASH_LED_MODE_TORCH), V4L2_FLASH_LED_MODE_NONE); + v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, + 0, 13900, 1, 8); + ret = v4l2_fwnode_device_parse(ov9282->dev, &props); if (!ret) { /* Failure sets ctrl_hdlr->error, which we check afterwards anyway */ From patchwork Wed May 7 07:51:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888726 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 661A7221714; Wed, 7 May 2025 07:52:22 +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=1746604342; cv=none; b=RKH7OJhaW/do5tUafbalobg+oSTFb01XHOuNxSQdGnmz3IIqLCKJym3+mQyALIDHK7PMLx2IY/JyMZaHJJ8mcO6U2NiabE6ZhfCh9LVY6rIbvDRr3vbxIH+/0kfmApmXRpKHXEwdYPxTHBXTPNXKEvyUIwmhLnzrYGAydQQYBFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=8vJtoHTUTJrvONHO5vnxfREHXCoupGjqP9LZtMbdTp8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mru9ZFJupZpu6+QBdIm246g/3YNEbFtVnKqIgYEP9jtLAZdn/qHcR0vTBXqSF4i9KeHF3IfBD4Ml05Gk4ODUGWGJYOwP00gQs7gVpwZ00uvVkDTY4Qu3V5A++u5nH5glzmEUz/6RjGC8eQ75aVVa/RgDRJ4/kSqODX96zJ9ccTE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PGMt9oQO; 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="PGMt9oQO" Received: by smtp.kernel.org (Postfix) with ESMTPS id EEF1CC113D0; Wed, 7 May 2025 07:52:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604342; bh=8vJtoHTUTJrvONHO5vnxfREHXCoupGjqP9LZtMbdTp8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PGMt9oQOsYotDBMsn7k486+WMP5WTS84j7pDuFbS35v3uPj8uV46xVLj2tR5m/HEv b+0exnAtZsjcAoy2RYIh3YZCJ+pFft3zIMjak4w4uSVuqV1vi77cRfz64nmwxwOYwL SzouXkWG3jIhEc82XnGlrUKrabnewuRxwSi1FkjA= 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 E8067C3ABC6; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:38 +0200 Subject: [PATCH v4 09/10] media: i2c: ov9282: add strobe_source v4l2 control Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-9-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=1686; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=8vJtoHTUTJrvONHO5vnxfREHXCoupGjqP9LZtMbdTp8=; b=E2JTQ4G5ISf8J+ZKkw1SGv3NDaPKG+xpsxVH4/leWk99GZAKugTPnIkldfWZKDFoLfftzorYx /jPLVRjZTXrAG12ZOmNS/C2KL9YDeIDnIu8eITOyobyCMUpJsackX5D 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 0bbdf08d7cda8f72e05fdc292aa69a4c821e4e03..09d522d5977ec6fb82028ddb6015f05c9328191d 100644 --- a/drivers/media/i2c/ov9282.c +++ b/drivers/media/i2c/ov9282.c @@ -1368,11 +1368,12 @@ static int ov9282_init_controls(struct ov9282 *ov9282) struct v4l2_ctrl_handler *ctrl_hdlr = &ov9282->ctrl_handler; const struct ov9282_mode *mode = ov9282->cur_mode; struct v4l2_fwnode_device_properties props; + struct v4l2_ctrl *ctrl; u32 hblank_min; u32 lpfr; int ret; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 12); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 13); if (ret) return ret; @@ -1447,6 +1448,14 @@ static int ov9282_init_controls(struct ov9282 *ov9282) v4l2_ctrl_new_std(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, 0, 13900, 1, 8); + ctrl = 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 |= V4L2_CTRL_FLAG_READ_ONLY; + ret = v4l2_fwnode_device_parse(ov9282->dev, &props); if (!ret) { /* Failure sets ctrl_hdlr->error, which we check afterwards anyway */ From patchwork Wed May 7 07:51:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 888727 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 5D370221708; Wed, 7 May 2025 07:52:22 +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=1746604342; cv=none; b=FRkGtFsGBYgRVn1Gv9rzr2nrIbkdTBXMGNadamLxlNdVQN0IO+tzbltJbHL6huL91y74TKfvPirpcCltQ37u+8aStqYXFW2B+E7CZ4K7hZXxceTd0NRrSVhKaCgTBFurSN4BteQ1jy4xebS6JSM9U7hvxWe3qRvVRTqQHUEoifQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746604342; c=relaxed/simple; bh=u2k9w+GukQmHB16zuirE+3M5ybc3Bh0/CkI9yc+9KRw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jvlDi515/sokttxdzO3oE2oeSAG9w1wE+1C+ubEf5ihYex43L6U240aEu3ALXd1EqXo4vsbe4wOWJu3WLWYjzrrvdwZm6caXYikoFR4yIdHdmRVxxciQQ12KAq7LovCZbvoD/py5JJadTTvYva3mHe5lzdwcdPL38cR9sjdeYAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ShMWxKV9; 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="ShMWxKV9" Received: by smtp.kernel.org (Postfix) with ESMTPS id 03B2DC116B1; Wed, 7 May 2025 07:52:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1746604342; bh=u2k9w+GukQmHB16zuirE+3M5ybc3Bh0/CkI9yc+9KRw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ShMWxKV9AI5rOpsPspKoLO+DUIOItMSYj2ecYzesT3PwYi0AS+roJRtrxp1Gi6Jjq hY3Oe871ZK91Iy7R4hNtZ+f9UZ1jpQjjvO6Rm+PpNV3HRinNLGM/k2sNg8dShec8DB isc/Ax7x49IWLNGQg6E3npyQSxysh8FIb5hOZRMY= 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 F25D3C3ABC0; Wed, 7 May 2025 07:52:21 +0000 (UTC) From: Richard Leitner Date: Wed, 07 May 2025 09:51:39 +0200 Subject: [PATCH v4 10/10] media: i2c: ov9282: implement try_ctrl for strobe_duration Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250507-ov9282-flash-strobe-v4-10-72b299c1b7c9@linux.dev> References: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@linux.dev> In-Reply-To: <20250507-ov9282-flash-strobe-v4-0-72b299c1b7c9@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=1746604340; l=3563; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=u2k9w+GukQmHB16zuirE+3M5ybc3Bh0/CkI9yc+9KRw=; b=N5Qmr+jFg9FjDlbZPon+ZQts18zYI0WCVHVozEDdHbQTS+N8S4mLLpcHEynAYMyRxvZCfOkkx sv0W2fUIVQdDc7j/UkTO8T9vZ5WoKZGXuomklIuDUEcAj9TxglnjqqO 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 µs strobe duration for the given value and returns it back to the caller. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 56 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index 09d522d5977ec6fb82028ddb6015f05c9328191d..f75882dcb73bea0e00e2cb37ffc19ec3c3a8b126 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 +#define OV9282_STROBE_SPAN_FACTOR 192 + static const char * const ov9282_supply_names[] = { "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); } -static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, int value) +static u32 ov9282_us_to_flash_duration(struct ov9282 *ov9282, u32 value) { /* * Calculate "strobe_frame_span" increments from a given value (µs). @@ -702,7 +704,31 @@ static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, int value) * The formula below is interpolated from different modes/framerates * and should work quite well for most settings. */ - u32 val = value * 192 / (ov9282->cur_mode->width + ov9282->hblank_ctrl->val); + u32 frame_width = 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 µs result. + */ + u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val; + u64 ns = value * 1000 * frame_width / OV9282_STROBE_SPAN_FACTOR; + u32 us = ns / 1000; + u32 remainder = ns % 1000; + + if (remainder > 0) + us++; + return us; +} + +static int ov9282_set_ctrl_flash_duration(struct ov9282 *ov9282, int value) +{ + u32 val = ov9282_us_to_flash_duration(ov9282, value); 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 +818,35 @@ static int ov9282_set_ctrl(struct v4l2_ctrl *ctrl) return ret; } +static int ov9282_try_ctrl(struct v4l2_ctrl *ctrl) +{ + struct ov9282 *ov9282 = + container_of(ctrl->handler, struct ov9282, ctrl_handler); + + if (ctrl->id == V4L2_CID_FLASH_DURATION) { + u32 fd = ov9282_us_to_flash_duration(ov9282, ctrl->val); + u32 us = ctrl->val; + u32 us0 = ov9282_flash_duration_to_us(ov9282, fd); + u32 us1 = ov9282_flash_duration_to_us(ov9282, (fd + 1)); + + if ((us1 - us) < (us - us0)) + ctrl->val = us1; + else + ctrl->val = us0; + + if (us != 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 = { .s_ctrl = ov9282_set_ctrl, + .try_ctrl = ov9282_try_ctrl, }; /**