Skip to content
systemcoding.dev
Embedded Linux

Understanding compatible Strings and How Drivers Match Them

How a device tree compatible list is written, why the most specific name comes first, and how the kernel scores matches. Covers fallback strings and modaliases.

6 min read
Summarize in AI
Flat illustration of a single-board computer with its SoC, memory, header and ports, with the Linux, Raspberry Pi and NXP logos.

Two lines of a device tree decide whether a piece of hardware works at all: the compatible property of its node and the match table in its driver. Both are lists of strings, they must share one entry, and the order inside the node's list matters more than newcomers expect. This post concentrates on the device tree side of the question: how a compatible list is written, why it nearly always has two or three entries, how the kernel ranks the matches and how the same string reaches a loadable module through its alias. It complements the kernel side, where the driver tables and the bus code are covered, by looking at what an author of a .dts file has to get right. The examples refer to Linux 6.12.

The format of a string

A compatible value is a list of strings, each of the form "manufacturer,model". The manufacturer is a vendor prefix registered in Documentation/devicetree/bindings/vendor-prefixes.yaml, in lowercase, and the model is the part name the vendor uses:

dts
serial@10000000 {
	compatible = "ns16550a";
	reg = <0x10000000 0x100>;
};

ethernet@20000000 {
	compatible = "ti,am3352-cpsw", "ti,cpsw";
	reg = <0x20000000 0x1000>;
};

The first entry has no vendor prefix because it is a historic generic name; new strings always carry one. The second node shows the usual pattern: the most specific string first (ti,am3352-cpsw, the exact block in that SoC) followed by one or more less specific ones that name a family or a base design (ti,cpsw). Entries are ordered from specific to general.

Why a list rather than one string? Because hardware comes in families. A vendor reuses a UART design across ten chips, and a driver written for the base design should work on all of them. The node names the exact chip first, so a driver that needs a chip specific workaround can claim it, and the family string after it, so the generic driver works if the specific one does not exist. A device tree author lists every string a driver might want.

How the kernel ranks a match

When the kernel creates a device from a node and looks for a driver, it compares the node's list to each driver's of_match_table. A driver declares its table like this:

c
static const struct of_device_id cpsw_of_match[] = {
	{ .compatible = "ti,am3352-cpsw" },
	{ .compatible = "ti,cpsw" },
	{ }
};
MODULE_DEVICE_TABLE(of, cpsw_of_match);

Matching is by position in the node's list. The function of_match_node() scores each table entry by the index of the first matching string in the node's compatible: a match with the first string scores best, the second next, and so on. The entry with the best score wins. If two drivers both claim the node, the one that matched the earlier string takes it.

This makes the list order a real decision. Take a node with compatible = "acme,uart-v2", "acme,uart" and two drivers: a generic acme,uart driver and a newer acme,uart-v2 driver with extra features. The node's first string matches the v2 driver, which wins. If a board author wrote the strings in the other order, the generic driver would score best and the v2 features would silently go unused. Both would probe, and only a log line would hint at which one ran.

The same ranking applies to a board's root compatible, which platform code uses to select machine specific setup:

dts
/ {
	compatible = "acme,demo-board", "vendor,example-soc";
};

Board first, SoC second, always. Code that handles the SoC family matches the second string, and board quirks match the first.

From string to module

A string is also how the right module loads. The MODULE_DEVICE_TABLE(of, ...) line in a driver exports each entry as a module alias. You can read the aliases with modinfo:

Shell
modinfo -F alias ti_cpsw | head -3
Text
of:N*T*Cti,am3352-cpswC*
of:N*T*Cti,am3352-cpsw
of:N*T*Cti,cpsw

The format is of:N<name>T<type>C<compatible>, with * standing for "any". When the kernel registers a node, it sends a uevent whose MODALIAS contains one such string per entry in the node's list. udev (or mdev on small systems) runs modprobe with each alias, and modprobe finds the module whose alias matches. Look at what the kernel says about a device:

Shell
cat /sys/bus/platform/devices/20000000.ethernet/modalias
cat /sys/bus/platform/devices/20000000.ethernet/uevent
Text
of:NethernetT(null)Cti,am3352-cpswCti,cpsw
DRIVER=cpsw
OF_NAME=ethernet
OF_FULLNAME=/ocp/ethernet@20000000
OF_COMPATIBLE_0=ti,am3352-cpsw
OF_COMPATIBLE_1=ti,cpsw
OF_COMPATIBLE_N=2
MODALIAS=of:NethernetT(null)Cti,am3352-cpswCti,cpsw

The device and file names depend on your board. OF_COMPATIBLE_0 and OF_COMPATIBLE_1 are the list in order, and DRIVER names the one that bound. If a device has no DRIVER line, no driver matched, and the aliases tell you which module name to search for with modinfo on every module.

Writing a good compatible

When you write a node, follow four rules.

Use the string from the binding. Do not invent one. The binding file under Documentation/devicetree/bindings/ lists exactly which strings are valid, and make dtbs_check flags a node whose list is not in it. If the exact chip has no entry, add a binding rather than reuse a nearby string.

Put the specific string first and keep the fallback. If a binding says the compatible is "vendor,chip-a", "vendor,family", write both, in that order. Omitting the fallback breaks kernels that only know the family driver.

Do not use wildcards. "vendor,chip-*" is not a pattern, it is a literal string that nobody matches. Names that include a generic part, such as "vendor,uart", are only for family strings the binding defines.

Do not put a driver name in it. A compatible describes hardware, not Linux. Strings like "linux,spidev" are rejected by review because they leak implementation into the description.

Failure modes

Most mismatches look the same from the outside: the device exists, nothing happens. Check them in order. Print OF_COMPATIBLE_0 from uevent, and compare to a driver table with grep -R "<string>" drivers/. A typo such as "ti,am3352-cpws" is common and invisible on read. Then check that the driver is built (zcat /proc/config.gz | grep CPSW) and its dependencies probed, because a driver that is present but deferring shows up in /sys/kernel/debug/devices_deferred.

There is one legitimate special case: driver_override. Writing a driver name into /sys/bus/platform/devices/<dev>/driver_override forces a match regardless of strings, which is how userspace drivers are bound to a device. Treat it as a debugging tool, never as part of a design.

When this does not apply: on ACPI systems, matching uses _HID identifiers, and PCI uses vendor and device numbers. The kernel's of_match_table is specific to device trees.

Share

Keep reading

Flat illustration of user space above the system call boundary, the kernel and the hardware, with the Linux, C and GNU logos.
Kernels

Write a Pin Controller Driver With pinctrl

Write a Linux 6.12 pin controller driver: pinctrl_desc, pins, groups and functions, the set_mux callback, and the device tree states that consumers select.

8 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.