Re: [PATCH leds + devicetree v2 1/2] leds: trigger: add trigger sources validating method and helper functions

From: Pavel Machek
Date: Wed Nov 25 2020 - 05:33:04 EST


Hi!

> Currently we use the `linux,default-trigger` device tree property of a
> LED to define the default trigger which should be activated for a LED.
>
> But the LED device tree binding also documents the `trigger-sources`
> property, which specifies the source device which should be triggering
> the LED.
>
> The `trigger-sources` property is currently implemented only in
> drivers/usb/core/ledtrig-usbport.c.
>
> Lets add a method to struct led_trigger which, if implemented, can check
> whether this trigger should be enabled as default. This check shall be
> done by checking whether the specified `trigger-sources` refers to a
> device compatible with the trigger. For this two new helper functions,
> of_led_count_trigger_sources and of_led_get_trigger_source, are
> implemented.

> +int of_led_count_trigger_sources(struct led_classdev *led_cdev)
> +{
> + struct device_node *np;
> + int count;
> +
> + np = dev_of_node(led_cdev->dev);
> + if (!np)
> + return 0;
> +
> + count = of_count_phandle_with_args(np, "trigger-sources",
> + "#trigger-source-cells");
> + if (count == -ENOENT)
> + return 0;
> + else if (count < 0)
> + dev_warn(led_cdev->dev,
> + "Failed parsing trigger sources for %pOF!\n", np);
> +
> + return count;
> +}

Will this need of_node_put() somewhere?

Best regards,
Pavel

--
http://www.livejournal.com/~pavelmachek

Attachment: signature.asc
Description: Digital signature