From: George Stark <gnstark@salutedevices.com>
To: <pavel@ucw.cz>, <lee@kernel.org>, <robh@kernel.org>,
<krzk+dt@kernel.org>, <conor+dt@kernel.org>
Cc: <linux-leds@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <kernel@salutedevices.com>,
George Stark <gnstark@salutedevices.com>
Subject: [PATCH 2/2] leds: pwm: Add optional DT property default-brightness
Date: Tue, 15 Oct 2024 18:14:10 +0300 [thread overview]
Message-ID: <20241015151410.2158102-3-gnstark@salutedevices.com> (raw)
In-Reply-To: <20241015151410.2158102-1-gnstark@salutedevices.com>
When probing if default LED state is on then default brightness will be
applied instead of max brightness.
Signed-off-by: George Stark <gnstark@salutedevices.com>
---
drivers/leds/leds-pwm.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
index 7961dca0db2f..514fc8ca3e80 100644
--- a/drivers/leds/leds-pwm.c
+++ b/drivers/leds/leds-pwm.c
@@ -65,7 +65,8 @@ static int led_pwm_set(struct led_classdev *led_cdev,
__attribute__((nonnull))
static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
- struct led_pwm *led, struct fwnode_handle *fwnode)
+ struct led_pwm *led, struct fwnode_handle *fwnode,
+ unsigned int default_brightness)
{
struct led_pwm_data *led_data = &priv->leds[priv->num_leds];
struct led_init_data init_data = { .fwnode = fwnode };
@@ -104,7 +105,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
/* set brightness */
switch (led->default_state) {
case LEDS_DEFSTATE_ON:
- led_data->cdev.brightness = led->max_brightness;
+ led_data->cdev.brightness = default_brightness;
break;
case LEDS_DEFSTATE_KEEP:
{
@@ -141,6 +142,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
{
struct led_pwm led;
+ unsigned int default_brightness;
int ret;
device_for_each_child_node_scoped(dev, fwnode) {
@@ -160,7 +162,12 @@ static int led_pwm_create_fwnode(struct device *dev, struct led_pwm_priv *priv)
led.default_state = led_init_default_state_get(fwnode);
- ret = led_pwm_add(dev, priv, &led, fwnode);
+ ret = fwnode_property_read_u32(fwnode, "default-brightness",
+ &default_brightness);
+ if (ret < 0 || default_brightness > led.max_brightness)
+ default_brightness = led.max_brightness;
+
+ ret = led_pwm_add(dev, priv, &led, fwnode, default_brightness);
if (ret)
return ret;
}
--
2.25.1
next prev parent reply other threads:[~2024-10-15 15:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 15:14 [PATCH 0/2] leds: pwm: Add default-brightness property George Stark
2024-10-15 15:14 ` [PATCH 1/2] dt-bindings: " George Stark
2024-10-15 22:11 ` Rob Herring (Arm)
2024-10-15 15:14 ` George Stark [this message]
2024-10-31 14:32 ` [PATCH 2/2] leds: pwm: Add optional DT property default-brightness Lee Jones
2024-11-01 15:42 ` George Stark
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=20241015151410.2158102-3-gnstark@salutedevices.com \
--to=gnstark@salutedevices.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=kernel@salutedevices.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-leds@vger.kernel.org \
--cc=pavel@ucw.cz \
--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
all inboxes | Powered by JetHome®