All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: George Stark <gnstark@salutedevices.com>
Cc: pavel@ucw.cz, robh@kernel.org, krzk+dt@kernel.org,
	conor+dt@kernel.org, linux-leds@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@salutedevices.com
Subject: Re: [PATCH 2/2] leds: pwm: Add optional DT property default-brightness
Date: Thu, 31 Oct 2024 14:32:50 +0000	[thread overview]
Message-ID: <20241031143250.GH10824@google.com> (raw)
In-Reply-To: <20241015151410.2158102-3-gnstark@salutedevices.com>

On Tue, 15 Oct 2024, George Stark wrote:

> 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);

This creates a lot more hopping around than is necessary.

Since led_pwm_add() already has access to the fwnode, why not look up
the property in there instead, thus massively simplifying things.


>  		if (ret)
>  			return ret;
>  	}
> -- 
> 2.25.1
> 

-- 
Lee Jones [李琼斯]

  reply	other threads:[~2024-10-31 14:32 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 ` [PATCH 2/2] leds: pwm: Add optional DT property default-brightness George Stark
2024-10-31 14:32   ` Lee Jones [this message]
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=20241031143250.GH10824@google.com \
    --to=lee@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gnstark@salutedevices.com \
    --cc=kernel@salutedevices.com \
    --cc=krzk+dt@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.