Device Tree, Driver, and /dev Node Mapping¶
Core Concept¶
The Device Tree describes hardware and binds it to a kernel driver through the
compatibleproperty.
The driver then creates/dev/mygpioas the user-space interface.
Three-Layer Architecture Overview¶
[Device Tree / Hardware Description]
mygpio-led
compatible = "myvendor,mygpio-led"
led-gpios = <...>
↓ (match)
[Kernel Driver]
mygpio driver
mygpio_probe()
↓ (create device node)
[User Space]
/dev/mygpio
Naming Reference Table¶
| Name | Location | Purpose | Used By |
|---|---|---|---|
/dev/mygpio |
User space | Device operation interface | User space |
mygpio |
Driver / macro | Driver name and device node name | Kernel |
mygpio-led |
DT node name | Device Tree node name | DTS |
mygpio_led |
DT label | Internal DTS reference label | DTS |
myvendor,mygpio-led |
compatible | Driver matching identifier | Kernel |
"led" |
gpiod API | GPIO function name | Driver |
led-gpios |
DT property | GPIO hardware mapping | Device Tree |
Detailed Naming Explanation¶
1️⃣ /dev/mygpio (User-Space Interface)¶
👉 This creates:
Purpose¶
Provides a user-space interface for device operation:
echo 1 > /dev/mygpiocat /dev/mygpio
2️⃣ compatible (Device Tree ↔ Driver Binding)¶
Device Tree:
Driver:
Purpose¶
Determines:
Which kernel driver should handle this Device Tree node.
3️⃣ mygpio-led (DT Node Name)¶
Purpose¶
Used only as a readable node name in the Device Tree source.
Important¶
- Does NOT affect driver matching
- Does NOT become the
/devnode name
4️⃣ mygpio_led: (DT Label)¶
Purpose¶
Used as an internal DTS reference label.
Can be referenced by other nodes through phandles.
5️⃣ gpiod "led" vs led-gpios¶
Driver:
Device Tree:
Core Naming Rule¶
Examples:
| Driver | Device Tree |
|---|---|
"led" |
led-gpios |
"reset" |
reset-gpios |
"irq" |
irq-gpios |
Correct Interpretation¶
"led"represents a GPIO function name, NOT a GPIO number.
gpiod Design Philosophy¶
Legacy GPIO API¶
Problems¶
- Driver is tightly coupled to GPIO numbers
- Poor portability
- Hardware configuration hardcoded inside driver
Modern GPIO Design (gpiod + Device Tree)¶
Driver perspective:
"I want the GPIO used for the LED function."
Device Tree perspective:
"The LED is connected to GPIO17."
Kernel responsibility:
Map the function to the actual GPIO hardware.
GPIO Data Flow¶
devm_gpiod_get(dev, "led", ...)
↓
DT: led-gpios = <&gpio 17 ...>
↓
GPIO subsystem
↓
gpio_desc
↓
gpiod_set_value()
Common Mistakes¶
Inconsistent Naming¶
Driver:
Device Tree:
👉 ❌ Driver will fail to find the GPIO property.
❌ Invalid Property Name¶
👉 ❌ The kernel GPIO framework will not recognize it.
Quick Reference¶
Device Tree¶
compatible→ selects driverxxx-gpios→ GPIO hardware mapping
Driver¶
"xxx"→ maps toxxx-gpiosprobe()→ initializes device
User Space¶
/dev/xxx→ device operation interface