How Device Tree Overlay Works

Hello All,

I am a newbie to Linux and trying to figure out how device tree overlay works…

So after googling for many days, I came up with below device tree:


/dts-v1/;
/plugin/;

/ {
compatible = “ti,beaglebone”, “ti,beaglebone-black”;

/* identification */
part-number = “MY-LED”;
version = “00A0”;

/* state the resources this cape uses /
exclusive-use =
/
the pin header uses /
“P9.12”, /
GPIO*/
/* the hardware ip uses */
“gpio0”;

fragment@0 {
target = <&am33xx_pinmux>;
overlay {
bb_mygpio_pins: pinmux_bb_mygpio_pins {
pinctrl-single,pins = <
0x870 0x07 /* output mode | MODE7, see Pin_Configuration.pdf in BBB */

;
};
};
};

fragment@1 {
target = <&ocp>; /* not sure why it is not gpio0 */
overlay {
status = “okay”;
pinctrl-names = “default”;
pinctrl-0 = <&bb_mygpio_pins>;
};
};
};

I was able to "build" the dtc and generated MY-LED-00A0.dtbo

I then copied the MY-LED-00A0.dtbo to /lib/firmware

Then i echoed it to slots:
echo MY-LED > $SLOTS

and cat $SLOTS gives me below result:


root@beaglebone:/lib/firmware# cat $SLOTS
0: 54:PF—
1: 55:PF—
2: 56:PF—
3: 57:PF—
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
9: ff:P-O-L Override Board Name,00A0,Override Manuf,MY-LED

By looks of this, MY_LED seems to be loaded...

The main confusion is how can I use MY-LED?
Where are the files for MY-LED present?

Any help or guidance is much appreciated.

A good tutorial here:
http://derekmolloy.ie/gpios-on-the-beaglebone-black-using-device-tree-overlays/
simple example:

cd /sys/class/gpio

cd gpio60
echo 60 > export

echo out > direction

echo 1 > value

good luck
Jan

You need to do

echo 60 > export

Before

cd gpio60

Thanks Jan and Dacobi for your valuable comments.

There is one small confusion. I declared the pin to be an output pin in my device tree overlay:

0x870 0x07 /* output mode | MODE7, see Pin_Configuration.pdf in BBB */

but after exporting pin as you guys mentioned and looking at the direction, I get it as ‘in’

`
root@beaglebone:/sys/class/gpio/gpio60# cat direction
in

`

The below steps described by Jan could be done without the use of device overlay

`

cd /sys/class/gpio
cd gpio60
echo 60 > export
echo out > direction

echo 1 > value
`

So why do we need device overlay :frowning:

Please help me get rid of this confusion. It is driving me mad…

HK!

As far as I can tell from the pins pdf (in the video) the address of
gpio60 is 0x878 where 0x870 is gpio30.
So if you echo 30 > export and check the direction there it should be out.

But you don't need to use the DTS unless you have to change from the
default mode of the pin (for instance pull-op/down resistors)

One of the main reason of the device overlay is to stop having different kernel for different plateform ! In the device overlay you specify your hardware at boot. Most of the time you don’t change your connection after the boot !

In the kernel 3.14, there is no capemanager, so you need to recompile the dts file to specify which cape you want. ( include device tree file of the cap ) .

That it !

I tried your suggestion but it didn’t work :frowning:

In the video as well, Derek had to change the pin direction to “out” manually.

I think I am simply missing the big point of what device overlay does…

@Dacobi: Can you please clarify your comment regarding "default mode of the pin (for instance pull-op/down resistors) "

Is Direction of pin independent of what you menationed?

`

root@beaglebone:/sys/class/gpio/gpio30# cat $SLOTS
0: 54:PF—
1: 55:PF—
2: 56:PF—
3: 57:PF—
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
8: ff:P-O-L Override Board Name,00A0,Override Manuf,MY-LED
root@beaglebone:/sys/class/gpio/gpio30# cat direction
in
root@beaglebone:/sys/class/gpio/gpio30#

`

@Mickae1:

Also my kernel is 3.18

`

root@beaglebone:/sys/class/gpio/gpio30# uname -r
3.8.13-bone47

`