Defining GPIO on .DTS file

How to define GPIO on .DST file ?
And Way GPIO#72 is "gpios = <0x14 0x0 0x1>" ?


	leds {
		compatible = "gpio-leds";
		power {
			label = "board:orange:power";
			gpios = <0x11 0x9 0x1>;
		wifi {
			label = "board:red:wifi";
			gpios = <0x14 0x0 0x1>;
			linux,default-trigger = "phy0tpt";
1 Like

You probably meant .DTS aka device tree source file.

You probably meant why.

Anyway, back to your questions. Not sure where exactly you took this representation from, but usually gpios are specified by three items:

  1. Handle (meaning its like a pointer with ampersand aka & notation) to a GPIO controller. So there can really be multiple GPIO controllers (see e.g., also note the ralink,gpio-base there pretty much answering one of your questions),
  2. GPIO number within that controller, and
  3. GPIO flags e.g. whether a GPIO is active high or low (see

Makes sense?

And BTW, usually one should also define resp. pin control stuff for any multi function pins e.g. see

1 Like

Ok, but my problem how to know Handle and GPIO nuimber of this pin.


And Why, this PIN works, which looks wrong.

gpios = <0x14 0x0 0x1>

Is there a table of the GPIO Controller?

gpios = <0x14 0x0 0x1>:

0x14: phandle of GPIO Controller

→ search GPIO controller node with phandle = <0x14> in your dts file

0x0 : GPIO pin number in the controller

→ not a serial number including other controllers

0x1 : GPIO flag

→ Active Low, Open Drain, etc... see gpio.h in the Linux Kernel

1 Like

No, one should rather use ampersand notation in DTS files. However, he did not answer my question about what/where exactly he got his file from. He also did not post the entire file so it is impossible to rely help him.

Nothing wrong at all. I guess, you did not read my note about ralink,gpio-base or did you?

You don't seem to having looked at my answer at all! Good luck...

I think it's probably a dts file converted from dtb.

Okay, and why is he not mentioning that? Anyway, such should never be used verbatim!

This full .dts
I don't know where it comes from, it was given to me.

I am hardware designer.
I'm not good for programming, and not good for English.

I runed the board for attempts.

I have a simple problem, I read all your complicated explanations, but I didn't understand anything.

Only missing, on my board, definition for ETH led.

Then for add new LED i have to create new Controller ?
Like this ?
But in the datasheet I can't find registers, only that the GPIO is # 40

		gpio@688 {
			compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
			reg = <0x688 0x24>;
			interrupt-parent = <0x1>;
			interrupts = <0x6>;
			#gpio-cells = <0x2>;
			ralink,gpio-base = <0x48>;
			ralink,nr-gpio = <0x1>;
			ralink,register-map = [00 04 08 0c 10 14 18 1c 20 24];
			status = "okay";
			linux,phandle = <0x14>;
			phandle = <0x14>;

As mentioned before, such DTS should never ever be used as it is NOT a proper one but rather a disassembled binary one. Modifying any such is just very very delicate.

Okay, then maybe you should start somewhere to learn about device trees in general first.

Then you likely just really don't know anything about device trees which makes what you are trying to achieve very very hard.

You mean one single LED? If so which of the 3 GPIOs you initially mentioned?

No, they are all already there in your DTS but then again as it is not a proper one it is very hard to make them work now.

Well, the datasheet won't really help you much. Remember, a proper Linux driver is trying to abstract all them nitty-gritty such details. So at the end you basically only need to know which GPIO controller instance and what particular GPIO thereof you want.

Anyway, referring to my earlier comment and looking at your DTS:

  1. Please note that, unfortunately, device trees are not quite that generic as you might hope. Meaning, if you do not know where exactly that device tree came from chances are very low that it will be usable together with whatever Linux kernel version you might intend to use it with (unless it really came from somewhere where it got exactly used with that exact same Linux kernel version as well). For now, against best practice, lets hope it might be kinda usable.

  2. Your DTS at line 106 and following contains them GPIO controller nodes. The first controller gpio@600 is even enabled. Those would be the GPIOs from 0 aka ralink,gpio-base to 23 (e.g. the next controller's ralink,gpio-base minus one).

  3. Unfortunately, the next two are disabled. Likely, you would need the gpio@660 one which according to its ralink,gpio-base starts with GPIO 40. Now, I guess, you could set its status to okay and also add a free phandle (e.g. 0x15 as all the others are already used). As mentioned before, in a proper device tree one would use ampersand notation referring to labels which the device tree compiler would then replace with such hex numbers making sure they are all unique. So that node would look as follows:

		gpio@660 {
			compatible = "ralink,mt7620a-gpio", "ralink,rt2880-gpio";
			reg = <0x660 0x24>;
			interrupt-parent = <0x1>;
			interrupts = <0x6>;
			#gpio-cells = <0x2>;
			ralink,gpio-base = <0x28>;
			ralink,nr-gpio = <0x20>;
			ralink,register-map = [00 04 08 0c 10 14 18 1c 20 24];
			status = "okay";
			linux,phandle = <0x15>;
			phandle = <0x15>;
  1. Now your GPIO reference would look as follows:

gpios = <0x15 0x0 0x1>;

Good luck with that.

Even adding

ralink,group = "i2c", "wled", "uartf", "ephy";

Now all are working.

1 Like