Make LEDs work on a new device

I'm porting OpenWRT onto a custom device. I wrote a .dts file, but can't get LEDs working. echo "default-on" > /sys/class/leds/device:*/trigger and echo 1 > /sys/class/leds/device:*/brightness commands have no effect. echo 5xx > /sys/class/gpio/export returns an error ash: write error: Resource busy.

The leds_gpio kernel module is loaded, and here is /sys/kernel/debug/gpio file contents:

gpiochip0: GPIOs 512-543, parent: platform/1e000600.gpio, 1e000600.gpio-bank0:
 gpio-515 (                    |i2c_ctrl            ) out hi 
 gpio-516 (                    |i2c_ctrl            ) out hi 
 gpio-525 (                    |device:green:lan3    ) out hi ACTIVE LOW
 gpio-526 (                    |device:green:wan     ) out hi ACTIVE LOW
 gpio-527 (                    |device:green:lan2    ) out hi ACTIVE LOW
 gpio-528 (                    |device:green:lan1    ) out hi ACTIVE LOW
 gpio-529 (                    |device:green:lan4    ) out hi ACTIVE LOW
 gpio-530 (                    |wps                 ) in  hi ACTIVE LOW
 gpio-531 (                    |reset               ) out hi ACTIVE LOW
 gpio-534 (                    |usb-pwr             ) out hi 
 gpio-538 (                    |device:red:power-r   ) out hi ACTIVE LOW
 gpio-539 (                    |device:blue:power-b  ) out hi ACTIVE LOW
 gpio-540 (                    |device:green:wlan1   ) out hi ACTIVE LOW
 gpio-543 (                    |device:green:power-g ) out hi ACTIVE LOW

gpiochip1: GPIOs 544-575, parent: platform/1e000600.gpio, 1e000600.gpio-bank1:
 gpio-545 (                    |device:green:wlan0   ) out hi ACTIVE LOW

gpiochip2: GPIOs 576-607, parent: platform/1e000600.gpio, 1e000600.gpio-bank2:

Below is the list of additions I made.

Part of the .dts file (unrelated parts removed):

/ {
	leds {
		compatible = "gpio-leds";

		led_power_r: power-r {
			label = "device:red:power-r";
			function = LED_FUNCTION_INDICATOR;
			gpios = <&gpio 26 GPIO_ACTIVE_LOW>;
		};

		led_power_g: power-g {
			label = "device:green:power-g";
			function = LED_FUNCTION_POWER;
			gpios = <&gpio 31 GPIO_ACTIVE_LOW>;
		};

		led_power_b: power-b {
			label = "device:blue:power-b";
			function = LED_FUNCTION_STATUS;
			gpios = <&gpio 27 GPIO_ACTIVE_LOW>;
		};

		wan {
			// Port 3
			label = "device:green:wan";
			function = LED_FUNCTION_WAN;
			gpios = <&gpio 14 GPIO_ACTIVE_LOW>;
		};

		lan1 {
			// Port 0
			label = "device:green:lan1";
			function = LED_FUNCTION_LAN;
			gpios = <&gpio 16 GPIO_ACTIVE_LOW>;
		};

		wlan0 {
			// WiFi 2.4G Activity
			label = "device:green:wlan0";
			function = LED_FUNCTION_WLAN_2GHZ;
			gpios = <&gpio 33 GPIO_ACTIVE_LOW>;
		};

		wlan1 {
			// WiFi 5G Activity
			label = "device:green:wlan1";
			function = LED_FUNCTION_WLAN_5GHZ;
			gpios = <&gpio 28 GPIO_ACTIVE_LOW>;
		};
	};
};

&gpio {
	status = "okay";
};

&state_default {
	gpio {
		ralink,group = "wdt", "rgmii2", "jtag", "mdio", "uart3";
		ralink,function = "gpio";
	};
};

The list of packages required by the device:

  DEVICE_PACKAGES :=  kmod-mt7621 kmod-mt76x2 \
                      kmod-usb2 kmod-usb3 kmod-usb-storage-extras \
                      swconfig xl2tpd kmod-l2tp-eth kmod-l2tp-ip \
                      kmod-leds-gpio kmod-ledtrig-default-on \
                      kmod-ledtrig-gpio kmod-ledtrig-heartbeat \
                      kmod-ledtrig-netdev kmod-ledtrig-oneshot \
                      kmod-ledtrig-timer kmod-ledtrig-transient \
                      automount kmod-mtd-rw

What am I missing?

Custom device? OK answered my own question in your other thread.
Cuman Spectra AC 12-G?

Yep, it is.

P.S. I'm a junior, have Linux experience but a newbie to embedded, so I follow and learn from other code snippets and ask stupid questions here.

1 Like

heres how i did mine, I've included all relevant parts from my dts from another board. The leds work and are configurable via cl or luci -> system -> led config

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>


	aliases {
		...
		
		led-boot = &led_system_blue;
		led-failsafe = &led_status_white;
		led-running = &led_status_white;
		led-upgrade = &led_system_blue;
	};

...

leds {
		compatible = "gpio-leds";
		pinctrl-0 = <&leds_pins>;
		pinctrl-names = "default";

		led_system_blue: led_system_blue {
			label = "led_system_blue";
			gpio = <&tlmm 24 0>;
			default-state = "on";
		};
		
		led_status_white: led_status_white {
			label = "led_status_white";
			gpio = <&tlmm 23 0>;
			default-state = "off";
		};
	};

...

&tlmm {
	...
	
	leds_pins: leds_pins {
		led_system_blue {
			pins = "gpio24";
			function = "gpio";
			drive-strength = <8>;
			bias-pull-down;
		};
		
		led_status_white {
			pins = "gpio23";
			function = "gpio";
			drive-strength = <8>;
			bias-pull-down;
		};
	};
...

perhaps it will help you.

Well, I found it. The problem was in ralink,group and ralink,function here:

&state_default {
	gpio {
		ralink,group = "wdt", "rgmii2", "jtag", "mdio", "uart3";
		ralink,function = "gpio";
	};
};

It should be groups and function respectively. Perhaps I followed some old code when writing it...

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.