Jump to content

DTB - Howto add LEDs?


Recommended Posts

Hi All,

 

as I understand, new kernel does not support script.bin any more and uses something called Device Tree Blob.

In source (DTS) file of this hell are two sections concerning LEDs:

		pinctrl at 01c20800 {
			led_pins_lamobo: led_pins at 0 {
				allwinner,pins = "PH2";
				allwinner,function = "gpio_out";
				allwinner,drive = <1>;
				allwinner,pull = <0>;
                              }

and this one:

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

		green {
			label = "lamobo:green:usr";
			gpios = <&pio 7 24 0>;
			default-state = "on";
		};
	};

Is here somebody, who understand structure of this file and parameters? Resp. when I want to add LED, which sections and how to add?

Link to comment
Share on other sites

Hi,

 

my LEDs are working already, I will describe shortly, howto: (for example two leds connected to GPIO PI03 and PI19)

 

Install DTC, device tree compiler. Take your DTB file and convert to DTS. Output DTS is little bit more human readable than examples I posted before.

 

Find section "pinctrl@01c20800" and to the end of this section add two LED subsection:

                        led_pins@0 {
                                allwinner,pins = "PI";
                                allwinner,function = "gpio_out";
                                allwinner,drive = <0x1>;
                                allwinner,pull = <0x0>;
                                linux,phandle = <0x38>;
                                phandle = <0x38>;
                        };
                        led_pins@1 {
                                allwinner,pins = "PI";
                                allwinner,function = "gpio_out";
                                allwinner,drive = <0x1>;
                                allwinner,pull = <0x0>;
                                linux,phandle = <0x3A>;
                                phandle = <0x3A>;

"allwinner,pins" must be "PI", beacause both of my leds are connected to the PI ports(PI03 and PI19). "linux,phandle" I simply find unused interrupt numbers and used them for my leds.

 

In main section of DTS file add:

        led1 {
                compatible = "gpio-leds";
                pinctrl-names = "default";
                pinctrl-0 = <0x38>;

                blue1 {
                        label = "lamobo:blue1:usr";
                        gpios = <0x19 0x8 0x03 0x0>;
                        default-state = "on";
                };
        };
        led2 {
                compatible = "gpio-leds";
                pinctrl-names = "default";
                pinctrl-0 = <0x3A>;

                blue2 {
                        label = "lamobo:blue2:usr";
                        gpios = <0x19 0x8 0x13 0x0>;
                        default-state = "on";
                };
        };


Where pinctrl-0 is phandle from first section and gpios parameters: 0x19 - i dont know; Second parameter is GPIO port group, for P>I< ports is 8 (A=0, B=1 ...), third parameter is port number.

Then use device tree compiler and convert your DTS->DTB. Take your DTB file, replace original in boot folder or where you have it. Reboot!

 

Enjoy!

 

Link to comment
Share on other sites

It depends, which kernel do you use. If you use new kernel, you have to follow my instruction above. After reboot, you will see all registered leds in /sys/class/leds :

root@LamoboRouter:~# ls /sys/class/leds
lamobo:blue1:usr    lamobo:green:usr    lamobo:red2:usr     lamobo:yellow2:usr
lamobo:blue2:usr    lamobo:red1:usr     lamobo:yellow1:usr

Then you check available triggers for a LED:

root@LamoboRouter:/sys/class/leds/lamobo:green:usr# cat trigger
none rc-feedback mmc0 [timer] default-on netdev
root@LamoboRouter:/sys/class/leds/lamobo:green:usr#

You can see available triggers here. Then type

echo mmc0 > /sys/class/leds/lamobo:green:usr/trigger

Now your green led is triggered by MMC activity.

Link to comment
Share on other sites

Hello,

 

I used to work with script.bin to configure LED and Battery management on my Olimex A20 Lime2. It was pretty easy. 

Since I switched to kernel 4.1 I had to deal with device tree which is terrible to understand.

 

I would like to do a simple thing : change my Led conf. @petrmaje I fallowed your indication but I can't find a way to adapt it on my board.

 

Below is what I have :

                        led_pins@0 {
                                allwinner,pins = "PH2";
                                allwinner,function = "gpio_out";
                                allwinner,drive = <0x1>;
                                allwinner,pull = <0x0>;
                                linux,phandle = <0x35>;
                                phandle = <0x35>;
                        };

and

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

                green {
                        label = "a20-olinuxino-lime2:green:usr";
                        gpios = <0x1a 0x7 0x2 0x0>;
                        default-state = "on";
                };
        };

The gpio declaration is not clear at all

gpios = <0x1a 0x7 0x2 0x0>;

I don't know how to modify it to GPIO 3 PIN 33 (PH20)

 

 

Sometime on the web, I find this

gpios = <&gpio3 20 0>;

But same, it does not work.

 

Any clue ?

Link to comment
Share on other sites

Hello,

 

I used to work with script.bin to configure LED and Battery management on my Olimex A20 Lime2. It was pretty easy. 

Since I switched to kernel 4.1 I had to deal with device tree which is terrible to understand.

 

I would like to do a simple thing : change my Led conf. @petrmaje I fallowed your indication but I can't find a way to adapt it on my board.

 

Below is what I have :

                        led_pins@0 {
                                allwinner,pins = "PH2";
                                allwinner,function = "gpio_out";
                                allwinner,drive = <0x1>;
                                allwinner,pull = <0x0>;
                                linux,phandle = <0x35>;
                                phandle = <0x35>;
                        };

and

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

                green {
                        label = "a20-olinuxino-lime2:green:usr";
                        gpios = <0x1a 0x7 0x2 0x0>;
                        default-state = "on";
                };
        };

The gpio declaration is not clear at all

gpios = <0x1a 0x7 0x2 0x0>;

I don't know how to modify it to GPIO 3 PIN 33 (PH20)

 

 

Sometime on the web, I find this

gpios = <&gpio3 20 0>;

But same, it does not work.

 

Any clue ?

The key is to reverse compile dtb to dts, then you get easy readable format of the file. So when you want to change this led to PH20, try this:

 

in first section: allwinner,pins = "PH20"

 

in second section:

 

gpios = <0x1a 0x7 0x14 0x0>;

 

This should work.

I found this way by reverse engineering, but once more gpios parameters:

 

0x1a - I dont konow

0x7 - port group, group is "H"=7 (A=0 etc)

0x14 - port number is 20 (PH20) and when you convert 20 to hexadecimal = 0x14.

 

PM

Link to comment
Share on other sites

Wooww !! Great !

 

Thank you for your great recipe, it is working great !

So the only way to work with device tree is to reverse engineer the code ?

 

It was really hard to find the right info on the net ! I hope it is going to be a little bit easier for battery management, not sure :s 

Link to comment
Share on other sites

I found some documents on the net, but they did not help ... :( So I did it my way :D :D

 

Wooww !! Great !

 

Thank you for your great recipe, it is working great !

So the only way to work with device tree is to reverse engineer the code ?

 

It was really hard to find the right info on the net ! I hope it is going to be a little bit easier for battery management, not sure :s 

Link to comment
Share on other sites

Welcome to ARMBIAN 5.68 user-built Debian GNU/Linux 9 (stretch) 4.14.92-sunxi

/dts-v1/;
/plugin/;

/ {
compatible = "allwinner,sun8i-h3";

fragment@0 {
  target = <&pio>;
  __overlay__ {
   gpio_pin: gpio_pin {
    pins = "PA6","PA3";
    function = "gpio_out";
   };
  };
};

fragment@1 {
  target-path = "/";
  __overlay__ {
   gpiopull: gpiopull {
    compatible = "gpio-leds";
    pinctrl-names = "default";
    pinctrl-0 = <&gpio_pin>;
    status = "okay";
    gpio_out_6 {
     label = "5-ka:red";
     gpios = <&pio 0 6 0>;  /* PA6 GPIO_ACTIVE_LOW */
     linux,default-trigger = "cpu";
    };
    gpio_out_3 {
     label = "5-ka:green";
     gpios = <&pio 0 3 1>;  /* PA3 GPIO_ACTIVE_HI */
     default-state = "om";
     linux,default-trigger = "heartbeat";
    };

   };
  };
};
};

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines