From: Roman Vivchar via B4 Relay <devnull+rva333.protonmail.com@kernel.org>
To: Sean Young <sean@mess.org>, 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>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>
Cc: linux-media@vger.kernel.org, linux-leds@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Roman Vivchar <rva333@protonmail.com>
Subject: [PATCH 2/2] media: pwm-ir-tx: add regulator support
Date: Mon, 02 Nov 2026 17:22:57 +0200 [thread overview]
Message-ID: <20261102-6768-irled-v1-2-c7064f3afed1@protonmail.com> (raw)
In-Reply-To: <20261102-6768-irled-v1-0-c7064f3afed1@protonmail.com>
From: Roman Vivchar <rva333@protonmail.com>
On some boards, the IR LED shares a power rail with other components.
If that rail is turned off, IR transmission can't function properly.
Add optional regulator support to ensure the power supply is enabled when
needed.
Signed-off-by: Roman Vivchar <rva333@protonmail.com>
---
drivers/media/rc/pwm-ir-tx.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
diff --git a/drivers/media/rc/pwm-ir-tx.c b/drivers/media/rc/pwm-ir-tx.c
index 047472dc9244..f9c95d034493 100644
--- a/drivers/media/rc/pwm-ir-tx.c
+++ b/drivers/media/rc/pwm-ir-tx.c
@@ -10,6 +10,7 @@
#include <linux/slab.h>
#include <linux/of.h>
#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
#include <linux/hrtimer.h>
#include <linux/completion.h>
#include <media/rc-core.h>
@@ -19,6 +20,7 @@
struct pwm_ir {
struct pwm_device *pwm;
+ struct regulator *reg;
struct hrtimer timer;
struct completion tx_done;
struct pwm_state *state;
@@ -63,10 +65,16 @@ static int pwm_ir_tx_sleep(struct rc_dev *dev, unsigned int *txbuf,
struct pwm_ir *pwm_ir = dev->priv;
struct pwm_device *pwm = pwm_ir->pwm;
struct pwm_state state;
- int i;
+ int i, ret;
ktime_t edge;
long delta;
+ if (pwm_ir->reg) {
+ ret = regulator_enable(pwm_ir->reg);
+ if (ret)
+ return ret;
+ }
+
pwm_init_state(pwm, &state);
state.period = DIV_ROUND_CLOSEST(NSEC_PER_SEC, pwm_ir->carrier);
@@ -87,6 +95,12 @@ static int pwm_ir_tx_sleep(struct rc_dev *dev, unsigned int *txbuf,
state.enabled = false;
pwm_apply_might_sleep(pwm, &state);
+ if (pwm_ir->reg) {
+ ret = regulator_disable(pwm_ir->reg);
+ if (ret)
+ return ret;
+ }
+
return count;
}
@@ -96,6 +110,7 @@ static int pwm_ir_tx_atomic(struct rc_dev *dev, unsigned int *txbuf,
struct pwm_ir *pwm_ir = dev->priv;
struct pwm_device *pwm = pwm_ir->pwm;
struct pwm_state state;
+ int ret;
pwm_init_state(pwm, &state);
@@ -107,10 +122,22 @@ static int pwm_ir_tx_atomic(struct rc_dev *dev, unsigned int *txbuf,
pwm_ir->txbuf_index = 0;
pwm_ir->state = &state;
+ if (pwm_ir->reg) {
+ ret = regulator_enable(pwm_ir->reg);
+ if (ret)
+ return ret;
+ }
+
hrtimer_start(&pwm_ir->timer, 0, HRTIMER_MODE_REL);
wait_for_completion(&pwm_ir->tx_done);
+ if (pwm_ir->reg) {
+ ret = regulator_disable(pwm_ir->reg);
+ if (ret)
+ return ret;
+ }
+
return count;
}
@@ -157,6 +184,14 @@ static int pwm_ir_probe(struct platform_device *pdev)
if (IS_ERR(pwm_ir->pwm))
return PTR_ERR(pwm_ir->pwm);
+ pwm_ir->reg = devm_regulator_get_optional(&pdev->dev, "power");
+ if (IS_ERR(pwm_ir->reg)) {
+ if (PTR_ERR(pwm_ir->reg) != -ENODEV)
+ return PTR_ERR(pwm_ir->reg);
+
+ pwm_ir->reg = NULL;
+ }
+
pwm_ir->carrier = 38000;
pwm_ir->duty_cycle = 50;
--
2.56.0
prev parent reply other threads:[~2026-11-02 15:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 15:22 [PATCH 0/2] media: pwm-ir-tx: " Roman Vivchar via B4 Relay
2026-11-02 15:22 ` [PATCH 1/2] dt-bindings: leds: irled: pwm-ir-tx: add power supply support Roman Vivchar via B4 Relay
2026-11-06 12:54 ` Krzysztof Kozlowski
2026-11-02 15:22 ` Roman Vivchar via B4 Relay [this message]
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=20261102-6768-irled-v1-2-c7064f3afed1@protonmail.com \
--to=devnull+rva333.protonmail.com@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=pavel@kernel.org \
--cc=robh@kernel.org \
--cc=rva333@protonmail.com \
--cc=sean@mess.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
all inboxes | Powered by JetHome®