writing-bindings.rst 5.5 KB

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