writing-bindings.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 use 'syscon' alone without a specific compatible string. A 'syscon'
  24. hardware block should have a compatible string unique enough to infer the
  25. register layout of the entire block (at a minimum).
  26. Properties
  27. ==========
  28. - DO make 'compatible' properties specific. DON'T use wildcards in compatible
  29. strings. DO use fallback compatibles when devices are the same as or a subset
  30. of prior implementations. DO add new compatibles in case there are new
  31. features or bugs.
  32. - DO use a vendor prefix on device-specific property names. Consider if
  33. properties could be common among devices of the same class. Check other
  34. existing bindings for similar devices.
  35. - DON'T redefine common properties. Just reference the definition and define
  36. constraints specific to the device.
  37. - DO use common property unit suffixes for properties with scientific units.
  38. Recommended suffixes are listed at
  39. https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml
  40. - DO define properties in terms of constraints. How many entries? What are
  41. possible values? What is the order?
  42. Typical cases and caveats
  43. =========================
  44. - Phandle entries, like clocks/dmas/interrupts/resets, should always be
  45. explicitly ordered. Include the {clock,dma,interrupt,reset}-names if there is
  46. more than one phandle. When used, both of these fields need the same
  47. constraints (e.g. list of items).
  48. - For names used in {clock,dma,interrupt,reset}-names, do not add any suffix,
  49. e.g.: "tx" instead of "txirq" (for interrupt).
  50. - Properties without schema types (e.g. without standard suffix or not defined
  51. by schema) need the type, even if this is an enum.
  52. - If schema includes other schema (e.g. /schemas/i2c/i2c-controller.yaml) use
  53. "unevaluatedProperties:false". In other cases, usually use
  54. "additionalProperties:false".
  55. - For sub-blocks/components of bigger device (e.g. SoC blocks) use rather
  56. device-based compatible (e.g. SoC-based compatible), instead of custom
  57. versioning of that component.
  58. For example use "vendor,soc1234-i2c" instead of "vendor,i2c-v2".
  59. - "syscon" is not a generic property. Use vendor and type, e.g.
  60. "vendor,power-manager-syscon".
  61. Board/SoC .dts Files
  62. ====================
  63. - DO put all MMIO devices under a bus node and not at the top-level.
  64. - DO use non-empty 'ranges' to limit the size of child buses/devices. 64-bit
  65. platforms don't need all devices to have 64-bit address and size.