From patchwork Tue Jun 17 07:31:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 897443 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66D631DF269; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=l8/or2e0SSTNq+0bb8X5tzI9nmU/AsZzmZlabnijfvi+JrwscYBwropb7uC/Rx8FNURKooNr3jdp9/qsMZlxbdFYTSzjjvGmltlBWyjNvIYwWQR8c0YE/H2YJc1LCzbSU+EW9HgX42wOB5Y/MzsMF4SGT81L9Wnt2SaM2PURMC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VgqQw9wyIQoKpz45eYMxibWGAVt0fV3/OMKVUfDVhsGf/I+zT3IfMfRZY/Hwtq4IPh7sx/+7pikWhlfq7mMwiyKT6rrYZNGC/BBO4vsiqKdUYgnDqnTCXq0DyZ79jzNxzfzd7H1wGvOQpxKVesKAohfYGbhTP0mdRtLNPFxL1eU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PL9s16Jj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PL9s16Jj" Received: by smtp.kernel.org (Postfix) with ESMTPS id D1744C4CEF0; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145502; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PL9s16JjyRvKIYWjase40Bs4Ka11Fm5EgK28szx2xE+e8KLno+2E5XiCx1W60ogRo 4NKwALHMGsq9W0k4iUZAVdlH/dtX2DAQrP/+GiQfpEAZgl5u+Giv0secRCH5FTj5J9 /Mvtl06RKApT1DA0qb5VmkQAwNKT6JMA7FB9gt+s= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id C28BEC71136; Tue, 17 Jun 2025 07:31:42 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:37 +0200 Subject: [PATCH v5 03/10] media: v4l2-flash: fix flash_timeout comment Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250617-ov9282-flash-strobe-v5-3-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=878; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=8XoXfLI3glbsttjIv49MTkNU8w73Ts/XjbKrGmMzkd0=; b=nPouAY8N5zq1XIMQ6rZ1Q6GzebMfWi0D9HB7LZ8Xg6r4imr5Qm6mrjxTs9/UdOwDbDXkp1HJu W2Ze+5AQ3w7Ax3ibt1oJ/EgVjSr7MfgqeyTvsYMveLRaGLiDCNQ1LyF X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 The comment for the flash_timeout setter mentioned it is the "flash duration". Fix this by changing it to "flash timeout". Signed-off-by: Richard Leitner --- include/linux/led-class-flash.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/led-class-flash.h b/include/linux/led-class-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 Tue Jun 17 07:31:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 897440 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 893F728D8EF; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=qUbJvNYWctg69SUmAAm8NQqK7yzX3JwIwnttYdG6HrVv3SDwrDY244GMyh5IqO1/vNxxgG2IX92qOh5Kg5o8PC70UdnKOT41xabIXt1Ra3792d4YvEE2fnzAJq8h4Uotg1pmX0PYPC3FZLTQOl1+gVc/VisP/KaLNFwsUVqlho8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=oUO3rGrZkpHIi+iMi+rCIYqbermkEnOKYHA1KrimKQ4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MsCt+sI1rCKJ5+q5E5/HWkhN07KIbrKrqVWsYke8dwmDpJwvES5RWoT+JUHiy5zYZW/+xPunpmAoflRY7DkOM1hQV6BZrsrKYGsdvViz4EN67hN3SMDh7D/OEfBPJGvpz5KkkJ+v3GJpNLbiwYtS0UHC9ztJw1c1v9mHaGHYCdM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FApXZNeJ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FApXZNeJ" Received: by smtp.kernel.org (Postfix) with ESMTPS id 2464CC4CEED; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=oUO3rGrZkpHIi+iMi+rCIYqbermkEnOKYHA1KrimKQ4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FApXZNeJQrH5oX4VUZoebh3loCH96YxFWLJrBSrUqMaul91yxobC6ykJ2aFkMU2xb fZ7AGKF1DBIdMMhrpAifIUH48zENP4lE0W+6hpI/ErflJQY4qusIwCz1FA4b/zD5XK 97N3sgXBHZC/mimoMChfHAiIcd6p5/cLV5KU2FII= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 189E7C71136; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:41 +0200 Subject: [PATCH v5 07/10] media: i2c: ov9282: add strobe_duration v4l2 control Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250617-ov9282-flash-strobe-v5-7-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=3465; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=oUO3rGrZkpHIi+iMi+rCIYqbermkEnOKYHA1KrimKQ4=; b=NgECwZ1ajnQD/6frScq4DKWGtzmK1kmPmz75ObFUf6bRiVxSFuQiVuC5e53YELEuSi8OkLPJR FFO+JGPesWFA3w83C8M2XFW0VGY6DWi3tbvmHW2i7YV1AHiLlXMaDZF X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add V4L2_CID_FLASH_DURATION support using the "strobe_frame_span" feature of the sensor. This is implemented by transforming the given µ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..871cd7e796531c1f958790eba733290d39e99f0c 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, u32 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 Tue Jun 17 07:31:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 897442 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 725F6273D7B; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=mDuuyL51OKUOeSDBKQrPkwchL8EbD3GZ9F0BztBvSoWUoPvTEtTbUR1+TXoyc3wHVTA+wKDKpGkiQPzVpndpRBiNijWeNCReAN4iC8fQdL4xycQyLGyNhbOatrRmvKWmXwwk1X1DrMHWbgCMBiQc6+AffFVjybyUFehRsDtOB54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=UWUot8+GzH895q5xNuCz1v5OHUINGbiHBZ3BD3ADYX4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=U0e6cfUgk0qg+bOqcNEdLwF8xAaI8oJ6K8VK9JFfBcuKbXrW6Ebq91A0ckvny6ub1f8dB7I9AgBhK6k45EPYNc5kHsNLf08r7iWTXJxqUykadeSPZ4Pyu29MCMSghs/MbotXctcslk4ZlUrFVYQjkeH5c3zayMz+lS/8JjbyUoQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=UARdv7I/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="UARdv7I/" Received: by smtp.kernel.org (Postfix) with ESMTPS id 313DDC4CEF2; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=UWUot8+GzH895q5xNuCz1v5OHUINGbiHBZ3BD3ADYX4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UARdv7I/4Cy3lX75c/r+cKTu/Lsy/s5V6FHoCzpAA+WiQqB9b2/bCNwhAtfhhWHx8 ujZjq1BB0V3AoQGm+CtNG0LHu845wtZrHSih7k5Ko8AF3f1w0MGqeC0wVlnR1FQYE4 sOJgeKXmiY3dmz/cKDQRt8oAn+2sBVNnjx1BlxD8= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2946AC71157; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:42 +0200 Subject: [PATCH v5 08/10] media: i2c: ov9282: add strobe_source v4l2 control Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250617-ov9282-flash-strobe-v5-8-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=1686; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=UWUot8+GzH895q5xNuCz1v5OHUINGbiHBZ3BD3ADYX4=; b=bpEuNPOqTYYT+fcLwGMXZjghWxiPYLrLi73EcKzRLU5ASu8f6ar0V8AC+nHaGIyKnpr7IIxG9 jAa1lH+mK6MCneclEgl6k/tR9Yn8dEiXLLG3mDllUqRMCrYCvmOM5UV X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 Add read-only V4L2_CID_FLASH_STROBE_SOURCE control. Its value is fixed to V4L2_FLASH_STROBE_SOURCE_EXTERNAL as the camera sensor triggers the strobe based on its register settings. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index 871cd7e796531c1f958790eba733290d39e99f0c..2d77b9108bcd2499a40418919e260e7d53a9a64e 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 Tue Jun 17 07:31:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Leitner X-Patchwork-Id: 897441 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72697288C06; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; cv=none; b=oBpBfYUo49QxrVkwEWu2x4LGiJGhv2LSEkbdO7sYMLk1K2R4RSbE4EJYgJLkPbhHcuok5eKCHZntLIG+J/K5N0kF1E5TTj97H1p6DlpF5lJ+EzHSEPptL/T/wIwYWB55eLgrndxUbLxmRd/O4kmxalnK7AeV3sR5Ut6tc6agJ0I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750145503; c=relaxed/simple; bh=u0EumBQgKw9tRo8pqtn52kIAYiMwEBU7JZR3hZra7Is=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lCn1RcX2mpUAWtDVH1hghcXSLi1SQbInjnL/J23QoWF1WlZSotoVnVWfE/q7khFis/SJNlC7JJSkB0SSBSPw0Tx5Q43TbMHzTEKWdVFwekD27rGOy1cViEpm8ADk2gy1bXS1RkM2y1tnNMz8TmVn7Yj5Q5NrJe7mAgqhnLD9RlQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=XCGFuS5h; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="XCGFuS5h" Received: by smtp.kernel.org (Postfix) with ESMTPS id 4CB2BC113CF; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux.dev; s=korg; t=1750145503; bh=u0EumBQgKw9tRo8pqtn52kIAYiMwEBU7JZR3hZra7Is=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XCGFuS5hBYCwlYFw1Y3fgv0PsACKMp9WD4NnXUCS1RsgSXzDBxUA4qC/yXGYronur F2Iv82L2Bx8Kd+0ECt5jGSoCiWd+XuCzYpe/dwWu7Tw6/TMssq1S8JG8S8JMNkSlUZ KmNSh8dEXjBYsSCPwKb354KaZp+t/fiS8kXsFBf8= Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43077C7115E; Tue, 17 Jun 2025 07:31:43 +0000 (UTC) From: Richard Leitner Date: Tue, 17 Jun 2025 09:31:44 +0200 Subject: [PATCH v5 10/10] media: i2c: ov9282: dynamic flash_duration maximum Precedence: bulk X-Mailing-List: linux-leds@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250617-ov9282-flash-strobe-v5-10-9762da74d065@linux.dev> References: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> In-Reply-To: <20250617-ov9282-flash-strobe-v5-0-9762da74d065@linux.dev> To: Sakari Ailus , Dave Stevenson , Mauro Carvalho Chehab , Lee Jones , Pavel Machek , Laurent Pinchart Cc: Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-leds@vger.kernel.org, Richard Leitner X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1750145501; l=3576; i=richard.leitner@linux.dev; s=20250225; h=from:subject:message-id; bh=u0EumBQgKw9tRo8pqtn52kIAYiMwEBU7JZR3hZra7Is=; b=/smZRi59dZATDPo+9atyjcxBHAC0WosfiTD+9aXjXRMdnnm1P/xAhwInYBkmUB2XwJY2lsD8N TSgOKWvD3ITDu4IYepSKddgDmHRuP6Nb/bDtec4ci3t8gbHUQ1AwmxM X-Developer-Key: i=richard.leitner@linux.dev; a=ed25519; pk=8hZNyyyQFqZ5ruVJsSGBSPIrmJpfDm5HwHU4QVOP1Pk= X-Endpoint-Received: by B4 Relay for richard.leitner@linux.dev/20250225 with auth_id=350 This patch sets the current exposure time as maximum for the flash_duration control. As Flash/Strobes which are longer than the exposure time have no effect. Signed-off-by: Richard Leitner --- drivers/media/i2c/ov9282.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/drivers/media/i2c/ov9282.c b/drivers/media/i2c/ov9282.c index 1f4bca29cd793e99c473aff9c8b7e200e3d598bc..2fd0d63b8071d434c05a98f4d0169c4fb83f7cfe 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 *ov9282, mode->vblank_max, 1, mode->vblank); } +static u32 ov9282_exposure_to_us(struct ov9282 *ov9282, u32 exposure) +{ + /* calculate exposure time in µs */ + u32 frame_width = ov9282->cur_mode->width + ov9282->hblank_ctrl->val; + u32 trow_us = (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 *ov9282, static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32 gain) { int ret; + u32 exposure_us = ov9282_exposure_to_us(ov9282, exposure); - dev_dbg(ov9282->dev, "Set exp %u, analog gain %u", - exposure, gain); + dev_dbg(ov9282->dev, "Set exp %u (~%u µs), analog gain %u", + exposure, exposure_us, gain); ret = ov9282_write_reg(ov9282, OV9282_REG_HOLD, 1, 1); if (ret) @@ -635,6 +647,12 @@ static int ov9282_update_exp_gain(struct ov9282 *ov9282, u32 exposure, u32 gain) goto error_release_group_hold; ret = ov9282_write_reg(ov9282, OV9282_REG_AGAIN, 1, gain); + if (ret) + goto error_release_group_hold; + + ret = __v4l2_ctrl_modify_range(ov9282->flash_duration, + 0, exposure_us, 1, + OV9282_FLASH_DURATION_DEFAULT); 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; @@ -1495,8 +1514,11 @@ 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); + exposure_us = ov9282_exposure_to_us(ov9282, OV9282_EXPOSURE_DEFAULT); + ov9282->flash_duration = v4l2_ctrl_new_std(ctrl_hdlr, + &ov9282_ctrl_ops, V4L2_CID_FLASH_DURATION, + 0, exposure_us, + 1, OV9282_FLASH_DURATION_DEFAULT); ctrl = v4l2_ctrl_new_std_menu(ctrl_hdlr, &ov9282_ctrl_ops, V4L2_CID_FLASH_STROBE_SOURCE,