Short answer: not quite, and this trips up a lot of people writing devicetree bindings. A child node's compatible doesn't override the parent's compatible. What it overrides is which binding validates the child.
How Zephyr finds a child node's binding
Zephyr finds a node's binding in one of two ways.
1. The child has no compatible
It's validated against the parent's child-binding: block. This is how gpio-leds, gpio-keys and pwm-leds work.
controller@40000000 {
compatible = "vendor,my-controller";
channel_0 {
channel-id = <0>;
};
};
2. The child has its own compatible
It's validated only against its own binding file. The parent's child-binding is ignored for that node.
controller@40000000 {
compatible = "vendor,my-controller";
special_channel {
compatible = "vendor,special-channel";
channel-id = <2>;
};
};
Key takeaways
- The parent's
compatibleis untouched. The two are independent. - The bindings are never merged. If the child needs
channel-id, its own binding must declare it. - The child's matching compatible becomes its own, so it can be bound to its own driver via
DT_DRV_COMPAT. - A typo in the child's
compatiblemeans no binding matches, and you silently lose thechild-bindingvalidation too. Watch your build warnings. - Siblings under one parent can mix both approaches.
- For shared properties, use
include:in the YAML files.
Rule of thumb:
child-bindingis the default description for children. An explicitcompatibleopts a child out of it.
Have you run into this while writing custom bindings? I'd like to hear about your experience.