Skip to content

Device Tree, Driver, and /dev Node Mapping

Core Concept

The Device Tree describes hardware and binds it to a kernel driver through the compatible property.
The driver then creates /dev/mygpio as 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)

#define DEVICE_NAME "mygpio"
device_create(..., DEVICE_NAME);

👉 This creates:

/dev/mygpio

Purpose

Provides a user-space interface for device operation:

  • echo 1 > /dev/mygpio
  • cat /dev/mygpio

2️⃣ compatible (Device Tree ↔ Driver Binding)

Device Tree:

compatible = "myvendor,mygpio-led";

Driver:

static const struct of_device_id mygpio_of_match[] = {
    { .compatible = "myvendor,mygpio-led" },
};

Purpose

Determines:

Which kernel driver should handle this Device Tree node.


3️⃣ mygpio-led (DT Node Name)

mygpio-led {
    ...
};

Purpose

Used only as a readable node name in the Device Tree source.

Important

  • Does NOT affect driver matching
  • Does NOT become the /dev node name

4️⃣ mygpio_led: (DT Label)

mygpio_led: mygpio-led {
};

Purpose

Used as an internal DTS reference label.

Can be referenced by other nodes through phandles.


5️⃣ gpiod "led" vs led-gpios

Driver:

devm_gpiod_get(dev, "led", GPIOD_OUT_LOW);

Device Tree:

led-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;

Core Naming Rule

"xxx" → "xxx-gpios"

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

gpio_request(17);

Problems

  • Driver is tightly coupled to GPIO numbers
  • Poor portability
  • Hardware configuration hardcoded inside driver

Modern GPIO Design (gpiod + Device Tree)

devm_gpiod_get(dev, "led", ...)

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:

devm_gpiod_get(dev, "led", ...)

Device Tree:

my-led-gpios = <...>;

👉 ❌ Driver will fail to find the GPIO property.


❌ Invalid Property Name

led_gpio = <...>;

👉 ❌ The kernel GPIO framework will not recognize it.


Quick Reference


Device Tree

  • compatible → selects driver
  • xxx-gpios → GPIO hardware mapping

Driver

  • "xxx" → maps to xxx-gpios
  • probe() → initializes device

User Space

  • /dev/xxx → device operation interface

Summary

Device Tree (describes hardware)
        ↓ compatible
Kernel Driver (controls hardware)
        ↓ device_create
/dev/mygpio (user-space interface)