Skip to content

Platform Driver and Device Tree Binding

A platform driver is commonly used for devices that are not discoverable by a hardware enumeration bus. On embedded Linux systems, the Device Tree describes the hardware, and the kernel matches Device Tree nodes to platform drivers through the compatible property.

Binding Flow

Device Tree node
    compatible = "myvendor,mygpio-led"
of_device_id table
platform_driver
probe()

Platform Driver Initialization Flow

After a successful match, the kernel invokes the driver's probe() callback.

A typical platform driver initialization sequence is:

probe()


devm_kzalloc()


platform_get_resource()
    (IORESOURCE_MEM)


platform_get_irq()
    (IORESOURCE_IRQ)


platform_set_drvdata()


devm_request_irq()


Driver Ready

The platform driver obtains hardware resources from the platform device created during Device Tree population.

Common resource types include:

Resource Type Description
IORESOURCE_MEM Memory-mapped I/O resource
IORESOURCE_IRQ Interrupt resource

Memory resources are acquired using:

platform_get_resource(
        pdev,
        IORESOURCE_MEM,
        0);

Interrupt resources are acquired using:

platform_get_irq(
        pdev,
        0);

Driver-specific state is typically stored in a private structure and attached to the platform device:

platform_set_drvdata(
        pdev,
        priv);

and retrieved later through:

platform_get_drvdata(
        pdev);

Key Names

Name Role
Device Tree node name Human-readable hardware node name
Device Tree label Internal DTS reference label
compatible Driver matching key
Driver name Kernel-side driver identity
/dev/<name> User-space device node created by the driver

GPIO Resource Mapping

Modern GPIO drivers should request GPIOs by function name, not by global GPIO number.

devm_gpiod_get(dev, "led", GPIOD_OUT_LOW);

This maps to the Device Tree property:

led-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>;

Common Pitfalls

Warning

The Device Tree node name does not decide which driver is used. The compatible string does.

Warning

The name passed to devm_gpiod_get(dev, "xxx", ...) maps to the Device Tree property xxx-gpios.