public inbox for linux-leds@vger.kernel.org
 help / color / mirror / Atom feed
From: Rudraksha Gupta via B4 Relay <devnull+guptarud.gmail.com@kernel.org>
To: Lee Jones <lee@kernel.org>, Pavel Machek <pavel@kernel.org>,
	 Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	 Conor Dooley <conor+dt@kernel.org>,
	Linus Walleij <linusw@kernel.org>,
	 Bjorn Andersson <andersson@kernel.org>,
	 Konrad Dybcio <konradybcio@kernel.org>
Cc: linux-leds@vger.kernel.org, devicetree@vger.kernel.org,
	 linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	 Rudraksha Gupta <guptarud@gmail.com>
Subject: [PATCH 2/3] leds: flash: rt8515: Support single-GPIO flash ICs with unlock gate
Date: Fri, 06 Mar 2026 16:58:03 -0800	[thread overview]
Message-ID: <20260306-expressatt_camera_flash-v1-2-b1996f7cdfdd@gmail.com> (raw)
In-Reply-To: <20260306-expressatt_camera_flash-v1-0-b1996f7cdfdd@gmail.com>

From: Rudraksha Gupta <guptarud@gmail.com>

Extend the RT8515 driver to support flash ICs that use only a single
GPIO for both flash and torch modes (no separate ENT pin), with an
optional unlock GPIO that gates the flash circuit.

Signed-off-by: Rudraksha Gupta <guptarud@gmail.com>
---
 drivers/leds/flash/leds-rt8515.c | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/flash/leds-rt8515.c b/drivers/leds/flash/leds-rt8515.c
index f6b439674c03..3164bf91e4c9 100644
--- a/drivers/leds/flash/leds-rt8515.c
+++ b/drivers/leds/flash/leds-rt8515.c
@@ -52,6 +52,7 @@ struct rt8515 {
 	struct regulator *reg;
 	struct gpio_desc *enable_torch;
 	struct gpio_desc *enable_flash;
+	struct gpio_desc *unlock_gpio;
 	struct timer_list powerdown_timer;
 	u32 max_timeout; /* Flash max timeout */
 	int flash_max_intensity;
@@ -66,7 +67,10 @@ static struct rt8515 *to_rt8515(struct led_classdev_flash *fled)
 static void rt8515_gpio_led_off(struct rt8515 *rt)
 {
 	gpiod_set_value(rt->enable_flash, 0);
-	gpiod_set_value(rt->enable_torch, 0);
+	if (rt->enable_torch)
+		gpiod_set_value(rt->enable_torch, 0);
+	if (rt->unlock_gpio)
+		gpiod_set_value_cansleep(rt->unlock_gpio, 0);
 }
 
 static void rt8515_gpio_brightness_commit(struct gpio_desc *gpiod,
@@ -99,11 +103,19 @@ static int rt8515_led_brightness_set(struct led_classdev *led,
 		/* Off */
 		rt8515_gpio_led_off(rt);
 	} else if (brightness < RT8515_TORCH_MAX) {
-		/* Step it up to movie mode brightness using the flash pin */
-		rt8515_gpio_brightness_commit(rt->enable_torch, brightness);
+		/* Unlock the flash circuit if needed */
+		if (rt->unlock_gpio)
+			gpiod_set_value_cansleep(rt->unlock_gpio, 1);
+		/* Step it up to movie mode brightness */
+		rt8515_gpio_brightness_commit(rt->enable_torch ?
+				rt->enable_torch : rt->enable_flash, brightness);
 	} else {
+		/* Unlock the flash circuit if needed */
+		if (rt->unlock_gpio)
+			gpiod_set_value_cansleep(rt->unlock_gpio, 1);
 		/* Max torch brightness requested */
-		gpiod_set_value(rt->enable_torch, 1);
+		gpiod_set_value(rt->enable_torch ? rt->enable_torch :
+				rt->enable_flash, 1);
 	}
 
 	mutex_unlock(&rt->lock);
@@ -121,6 +133,9 @@ static int rt8515_led_flash_strobe_set(struct led_classdev_flash *fled,
 	mutex_lock(&rt->lock);
 
 	if (state) {
+		/* Unlock the flash circuit if needed */
+		if (rt->unlock_gpio)
+			gpiod_set_value_cansleep(rt->unlock_gpio, 1);
 		/* Enable LED flash mode and set brightness */
 		rt8515_gpio_brightness_commit(rt->enable_flash, brightness);
 		/* Set timeout */
@@ -298,12 +313,23 @@ static int rt8515_probe(struct platform_device *pdev)
 		return dev_err_probe(dev, PTR_ERR(rt->enable_flash),
 				     "cannot get ENF (enable flash) GPIO\n");
 
-	/* ENT - Enable Torch line */
-	rt->enable_torch = devm_gpiod_get(dev, "ent", GPIOD_OUT_LOW);
+	/* ENT - Enable Torch line (optional for single-GPIO flash ICs) */
+	rt->enable_torch = devm_gpiod_get_optional(dev, "ent", GPIOD_OUT_LOW);
 	if (IS_ERR(rt->enable_torch))
 		return dev_err_probe(dev, PTR_ERR(rt->enable_torch),
 				     "cannot get ENT (enable torch) GPIO\n");
 
+	/* Optional unlock GPIO (e.g. PMIC MPP to gate flash circuit) */
+	rt->unlock_gpio = devm_gpiod_get_optional(dev, "unlock", GPIOD_OUT_LOW);
+	if (IS_ERR(rt->unlock_gpio))
+		return dev_err_probe(dev, PTR_ERR(rt->unlock_gpio),
+				     "cannot get unlock GPIO\n");
+
+	/* Exactly one of ENT or unlock must be provided */
+	if (!rt->enable_torch == !rt->unlock_gpio)
+		return dev_err_probe(dev, -EINVAL,
+				     "exactly one of ent-gpios or unlock-gpios is required\n");
+
 	child = device_get_next_child_node(dev, NULL);
 	if (!child) {
 		dev_err(dev,

-- 
2.53.0



  parent reply	other threads:[~2026-03-07  0:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-07  0:58 [PATCH 0/3] Samsung Expressatt: Camera Flash Rudraksha Gupta via B4 Relay
2026-03-07  0:58 ` [PATCH 1/3] dt-bindings: leds: rt8515: Support single-GPIO flash ICs with unlock gate Rudraksha Gupta via B4 Relay
2026-03-07 15:46   ` Krzysztof Kozlowski
2026-03-18 18:35     ` Rudraksha Gupta
2026-03-08 23:20   ` Linus Walleij
2026-03-18 18:36     ` Rudraksha Gupta
2026-03-07  0:58 ` Rudraksha Gupta via B4 Relay [this message]
2026-03-08 23:24   ` [PATCH 2/3] leds: flash: " Linus Walleij
2026-03-07  0:58 ` [PATCH 3/3] ARM: dts: qcom: msm8960: expressatt: Add camera flash Rudraksha Gupta via B4 Relay
2026-03-07  8:23   ` David Heidelberg
2026-03-18 18:39     ` Rudraksha Gupta
2026-03-08 23:37   ` Linus Walleij

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260306-expressatt_camera_flash-v1-2-b1996f7cdfdd@gmail.com \
    --to=devnull+guptarud.gmail.com@kernel.org \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=guptarud@gmail.com \
    --cc=konradybcio@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=pavel@kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox