Skip to content

Commit

Permalink
leds: pwm: Allow automatic labels for DT based devices
Browse files Browse the repository at this point in the history
If LEDs are configured through device tree and the property 'label' is
omitted, the label is supposed to be generated from the properties
'function' and 'color' if present.  While this works fine for e.g. the
'leds-gpio' driver, it did not for 'leds-pwm'.

The reason is, you get this label naming magic only if you add a LED
device through 'devm_led_classdev_register_ext()' and pass a pointer to
the current device tree node.

For the following node from dts the LED appeared as 'led-5' in sysfs
before and as 'red:debug' after this change.

        pwm_leds {
                compatible = "pwm-leds";

                led-5 {
                        function = LED_FUNCTION_DEBUG;
                        color = <LED_COLOR_ID_RED>;
                        pwms = <&pwm0 2 10000000 0>;
                        max-brightness = <127>;

                        linux,default-trigger = "heartbeat";
                        panic-indicator;
                };
        };

Signed-off-by: Alexander Dahl <[email protected]>
Cc: Marek Behún <[email protected]>
Signed-off-by: Pavel Machek <[email protected]>
  • Loading branch information
LeSpocky authored and pavelmachek committed Sep 26, 2020
1 parent 03eb2ca commit de73f27
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/leds/leds-pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,
struct led_pwm *led, struct fwnode_handle *fwnode)
{
struct led_pwm_data *led_data = &priv->leds[priv->num_leds];
struct led_init_data init_data = { .fwnode = fwnode };
int ret;

led_data->active_low = led->active_low;
Expand All @@ -87,7 +88,7 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv,

pwm_init_state(led_data->pwm, &led_data->pwmstate);

ret = devm_led_classdev_register(dev, &led_data->cdev);
ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data);
if (ret) {
dev_err(dev, "failed to register PWM led for %s: %d\n",
led->name, ret);
Expand Down

0 comments on commit de73f27

Please sign in to comment.