Skip to content

struct of_device_id

Purpose

struct of_device_id defines Device Tree compatible strings that a driver can match.

It is the bridge between a Device Tree node and a kernel driver.

#include <linux/of.h>
#include <linux/mod_devicetable.h>

Typical Usage

static const struct of_device_id my_of_match[] = {
    { .compatible = "myvendor,my-device" },
    { }
};
MODULE_DEVICE_TABLE(of, my_of_match);

In the platform driver:

.driver = {
    .name = "my-driver",
    .of_match_table = my_of_match,
},

In Device Tree:

compatible = "myvendor,my-device";

Common Pitfalls

  • mismatch between DTS compatible and driver match table
  • missing terminating empty entry { }
  • missing MODULE_DEVICE_TABLE(of, ...)
  • using a generic compatible string that does not describe the actual hardware