Re: [PATCH 4/4] leds: netdev trigger: allow setting initial values in device tree

From: Rasmus Villemoes
Date: Thu Mar 14 2019 - 07:26:45 EST


On 14/03/2019 11.29, Pavel Machek wrote:
> On Wed 2019-03-13 21:26:15, Rasmus Villemoes wrote:
>> It can be quite convenient to initialize a netdev-triggered LED with a
>> device name and setting the rx,tx,link properties from device tree,
>> instead of having to do that in an init script in userspace.
>>
>> + The optional child node netdev can be used to
>> + configure initial values for the link, rx, tx and
>> + device_name properties. For example, setting
>> + linux,default-trigger = "netdev" and adding the child
>> + node
>> +
>> + netdev {
>> + rx;
>> + tx;
>> + link;
>> + device-name = "can0";
>> + };
>> +
>> + can be used to replace 'linux,default-trigger =
>> + "can0-rxtx"' that relies on the deprecated
>> + CONFIG_CAN_LEDS.
>
> I'm sorry, but no, not like this. I see it works for you, only having
> single can device, but it would quickly break with two of them and two
> ethernets are rather common.
>
> So this will need to be device = <&phandle_of_ethernet_device> or
> something like that. There may be example with usb port triggers.

Huh? I have two CAN devices, and there are two LEDs on the front panel
labeled CAN-A and CAN-B; my device tree nodes for that are

cana {
label = "cana:green:activity";
gpios = <&gpio0 10 0>;
default-state = "off";
linux,default-trigger = "netdev";

netdev {
rx;
tx;
link;
device-name = "can0";
};
};

canb {
label = "canb:green:activity";
gpios = <&gpio0 5 0>;
default-state = "off";
linux,default-trigger = "netdev";

netdev {
rx;
tx;
link;
device-name = "can1";
};
};

and this works just fine. The only change from the old DT is the
addition of the netdev nodes and changing linux,default-trigger from
"can0-rxtx", "can1-rxtx" to both "netdev".

Rasmus