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:
Interrupt resources are acquired using:
Driver-specific state is typically stored in a private structure and attached to the platform device:
and retrieved later through:
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.
This maps to the Device Tree property:
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.
Related Notes¶
- Device Tree, Driver, and
/devNode Mapping - Device Tree Overlay
- Linux Device Model
- Platform Bus Internals
- Platform Driver Development
Related Labs¶
- Day08 - Device Model Exploration
- Day09 - GPIO Driver
- Day72 - Platform Bus Internals
- Day73 - Platform Driver Development