xref: /linux/Documentation/devicetree/bindings/writing-bindings.rst (revision bba2c3615bd6cfee7456d1130f2e6b01b3f4e9ba)
1.. SPDX-License-Identifier: GPL-2.0
2
3============================================================
4DOs and DON'Ts for designing and writing Devicetree bindings
5============================================================
6
7This is a list of common review feedback items focused on binding design. With
8every rule, there are exceptions and bindings have many gray areas.
9
10For guidelines related to patches, see
11Documentation/devicetree/bindings/submitting-patches.rst
12
13
14Overall design
15==============
16
17- DO attempt to make bindings complete even if a driver doesn't support some
18  features. For example, if a device has an interrupt, then include the
19  'interrupts' property even if the driver is only polled mode.
20
21- DON'T refer to Linux or "device driver" in bindings. Bindings should be
22  based on what the hardware has, not what an OS and driver currently support.
23
24- DO use node names matching the class of the device. Many standard names are
25  defined in the DT Spec. If there isn't one, consider adding it.
26
27- DO check that the example matches the documentation especially after making
28  review changes.
29
30- DON'T create nodes just for the sake of instantiating drivers. Multi-function
31  devices only need child nodes when the child nodes have their own DT
32  resources. A single node can be multiple providers (e.g. clocks and resets).
33
34- DON'T treat device node names as a stable ABI, but instead use phandles or
35  compatibles to find sibling devices. Exception: sub-nodes of given device
36  could be treated as ABI, if explicitly documented in the bindings.
37
38- DON'T use 'syscon' alone without a specific compatible string. A 'syscon'
39  hardware block should have a compatible string unique enough to infer the
40  register layout of the entire block (at a minimum).
41
42- DON'T use 'simple-mfd' compatible for non-trivial devices, where children
43  depend on some resources from the parent. Similarly, 'simple-bus' should not
44  be used for complex buses and even 'regs' property means device is not
45  a simple bus.
46
47
48Properties
49==========
50
51- DO make 'compatible' properties specific.
52
53   - DON'T use wildcards or device-family names in compatible strings.
54
55   - DO use fallback compatibles when devices are the same as or a superset of
56     prior implementations. Fallback compatibles are applicable especially
57     when sharing a programming interface or when able to discover the
58     variants.
59
60   - DON'T add fake fallback compatibles when software cannot use such to match
61     and bind to a device, and still operate correctly.
62
63   - DO use the commit message to explain why devices that may appear
64     compatible in a diff (e.g. no differences in property use, same handling
65     by the software) but are not made compatible in the binding, are not
66     compatible.
67
68   - DO add new compatibles in case there are new features or bugs.
69
70   - DO use a SoC-specific compatible for all SoC devices, followed by a
71     fallback if appropriate. SoC-specific compatibles are also preferred for
72     the fallbacks.
73
74   - DON'T use bus suffixes to encode the type of interface device is using.
75     The parent bus node already implies that interface.  DON'T add the type of
76     device, if the device cannot be anything else.
77
78- DO use a vendor prefix on device-specific property names. Consider if
79  properties could be common among devices of the same class. Check other
80  existing bindings for similar devices.
81
82- DON'T redefine common properties. Just reference the definition and define
83  constraints specific to the device.
84
85- DON'T add properties to avoid a specific compatible. DON'T add properties if
86  they are implied by (deducible from) the compatible.
87
88- DO use common property unit suffixes for properties with scientific units.
89  Recommended suffixes are listed at
90  https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml
91
92- DO define properties in terms of constraints. How many entries? What are
93  possible values? What is the order? All these constraints represent the ABI
94  as well.
95
96- DON'T make changes that break the ABI without explicit and detailed rationale
97  for why the changes have to be made and their impact. ABI impact goes beyond
98  the Linux kernel, because it also covers other open-source upstream projects.
99
100
101Typical cases and caveats
102=========================
103
104- Phandle entries, like clocks/dmas/interrupts/resets, should always be
105  explicitly ordered. Include the {clock,dma,interrupt,reset}-names if there is
106  more than one phandle. When used, both of these fields need the same
107  constraints (e.g. list of items).
108
109- For names used in {clock,dma,interrupt,reset}-names, do not add any suffix,
110  e.g.: "tx" instead of "txirq" (for interrupt).
111
112- Properties without schema types (e.g. without standard suffix or not defined
113  by schema) need the type, even if this is an enum.
114
115- If schema includes other schema (e.g. /schemas/i2c/i2c-controller.yaml) use
116  "unevaluatedProperties:false". In other cases, usually use
117  "additionalProperties:false".
118
119- For sub-blocks/components of bigger device (e.g. SoC blocks) use rather
120  device-based compatible (e.g. SoC-based compatible), instead of custom
121  versioning of that component.
122  For example use "vendor,soc1234-i2c" instead of "vendor,i2c-v2".
123
124- "syscon" is not a generic property. Use vendor and type, e.g.
125  "vendor,power-manager-syscon".
126
127- Do not add instance index (IDs) properties or custom OF aliases.  If the
128  devices have different programming model, they might need different
129  compatibles.  If such devices use some other device in a different way, e.g.
130  they program the phy differently, use cell/phandle arguments.
131
132- Bindings files should be named like compatible: vendor,device.yaml. In case
133  of multiple compatibles in the binding, use one of the fallbacks or a more
134  generic name, yet still matching compatible style.
135
136Board/SoC .dts Files
137====================
138
139- DO put all MMIO devices under a bus node and not at the top-level.
140
141- DO use non-empty 'ranges' to limit the size of child buses/devices. 64-bit
142  platforms don't need all devices to have 64-bit address and size.
143