1.. _dt-bindings-file-syntax: 2 3Devicetree bindings syntax 4########################## 5 6This page documents the syntax of Zephyr's bindings format. Zephyr bindings 7files are YAML files. A :ref:`simple example <dt-bindings-simple-example>` was 8given in the introduction page. 9 10.. contents:: Contents 11 :local: 12 :depth: 3 13 14Top level keys 15************** 16 17The top level of a bindings file maps keys to values. The top-level keys look 18like this: 19 20.. code-block:: yaml 21 22 # A high level description of the device the binding applies to: 23 description: | 24 This is the Vendomatic company's foo-device. 25 26 Descriptions which span multiple lines (like this) are OK, 27 and are encouraged for complex bindings. 28 29 See https://yaml-multiline.info/ for formatting help. 30 31 # You can include definitions from other bindings using this syntax: 32 include: other.yaml 33 34 # Used to match nodes to this binding: 35 compatible: "manufacturer,foo-device" 36 37 properties: 38 # Requirements for and descriptions of the properties that this 39 # binding's nodes need to satisfy go here. 40 41 child-binding: 42 # You can constrain the children of the nodes matching this binding 43 # using this key. 44 45 # If the node describes bus hardware, like an SPI bus controller 46 # on an SoC, use 'bus:' to say which one, like this: 47 bus: spi 48 49 # If the node instead appears as a device on a bus, like an external 50 # SPI memory chip, use 'on-bus:' to say what type of bus, like this. 51 # Like 'compatible', this key also influences the way nodes match 52 # bindings. 53 on-bus: spi 54 55 foo-cells: 56 # "Specifier" cell names for the 'foo' domain go here; example 'foo' 57 # values are 'gpio', 'pwm', and 'dma'. See below for more information. 58 59These keys are explained in the following sections. 60 61.. _dt-bindings-description: 62 63Description 64*********** 65 66A free-form description of node hardware goes here. You can put links to 67datasheets or example nodes or properties as well. 68 69.. _dt-bindings-compatible: 70 71Compatible 72********** 73 74This key is used to match nodes to this binding as described in 75:ref:`dt-binding-compat`. It should look like this in a binding file: 76 77.. code-block:: YAML 78 79 # Note the comma-separated vendor prefix and device name 80 compatible: "manufacturer,device" 81 82This devicetree node would match the above binding: 83 84.. code-block:: devicetree 85 86 device { 87 compatible = "manufacturer,device"; 88 }; 89 90Assuming no binding has ``compatible: "manufacturer,device-v2"``, it would also 91match this node: 92 93.. code-block:: devicetree 94 95 device-2 { 96 compatible = "manufacturer,device-v2", "manufacturer,device"; 97 }; 98 99Each node's ``compatible`` property is tried in order. The first matching 100binding is used. The :ref:`on-bus: <dt-bindings-on-bus>` key can be used to 101refine the search. 102 103If more than one binding for a compatible is found, an error is raised. 104 105The ``manufacturer`` prefix identifies the device vendor. See 106:zephyr_file:`dts/bindings/vendor-prefixes.txt` for a list of accepted vendor 107prefixes. The ``device`` part is usually from the datasheet. 108 109Some bindings apply to a generic class of devices which do not have a specific 110vendor. In these cases, there is no vendor prefix. One example is the 111:dtcompatible:`gpio-leds` compatible which is commonly used to describe board 112LEDs connected to GPIOs. 113 114.. _dt-bindings-properties: 115 116Properties 117********** 118 119The ``properties:`` key describes properties that nodes which match the binding 120contain. For example, a binding for a UART peripheral might look something like 121this: 122 123.. code-block:: YAML 124 125 compatible: "manufacturer,serial" 126 127 properties: 128 reg: 129 type: array 130 description: UART peripheral MMIO register space 131 required: true 132 current-speed: 133 type: int 134 description: current baud rate 135 required: true 136 137In this example, a node with compatible ``"manufacturer,serial"`` must contain 138a node named ``current-speed``. The property's value must be a single integer. 139Similarly, the node must contain a ``reg`` property. 140 141The build system uses bindings to generate C macros for devicetree properties 142that appear in DTS files. You can read more about how to get property values in 143source code from these macros in :ref:`dt-from-c`. Generally speaking, the 144build system only generates macros for properties listed in the ``properties:`` 145key for the matching binding. Properties not mentioned in the binding are 146generally ignored by the build system. 147 148The one exception is that the build system will always generate macros for 149standard properties, like :ref:`reg <dt-important-props>`, whose meaning is 150defined by the devicetree specification. This happens regardless of whether the 151node has a matching binding or not. 152 153Property entry syntax 154===================== 155 156Property entries in ``properties:`` are written in this syntax: 157 158.. code-block:: none 159 160 <property name>: 161 required: <true | false> 162 type: <string | int | boolean | array | uint8-array | string-array | 163 phandle | phandles | phandle-array | path | compound> 164 deprecated: <true | false> 165 default: <default> 166 description: <description of the property> 167 enum: 168 - <item1> 169 - <item2> 170 ... 171 - <itemN> 172 const: <string | int | array | uint8-array | string-array> 173 specifier-space: <space-name> 174 175.. _dt-bindings-example-properties: 176 177Example property definitions 178============================ 179 180Here are some more examples. 181 182.. code-block:: YAML 183 184 properties: 185 # Describes a property like 'current-speed = <115200>;'. We pretend that 186 # it's obligatory for the example node and set 'required: true'. 187 current-speed: 188 type: int 189 required: true 190 description: Initial baud rate for bar-device 191 192 # Describes an optional property like 'keys = "foo", "bar";' 193 keys: 194 type: string-array 195 description: Keys for bar-device 196 197 # Describes an optional property like 'maximum-speed = "full-speed";' 198 # the enum specifies known values that the string property may take 199 maximum-speed: 200 type: string 201 description: Configures USB controllers to work up to a specific speed. 202 enum: 203 - "low-speed" 204 - "full-speed" 205 - "high-speed" 206 - "super-speed" 207 208 # Describes an optional property like 'resolution = <16>;' 209 # the enum specifies known values that the int property may take 210 resolution: 211 type: int 212 enum: 213 - 8 214 - 16 215 - 24 216 - 32 217 218 # Describes a required property '#address-cells = <1>'; the const 219 # specifies that the value for the property is expected to be the value 1 220 "#address-cells": 221 type: int 222 required: true 223 const: 1 224 225 int-with-default: 226 type: int 227 default: 123 228 description: Value for int register, default is power-up configuration. 229 230 array-with-default: 231 type: array 232 default: [1, 2, 3] # Same as 'array-with-default = <1 2 3>' 233 234 string-with-default: 235 type: string 236 default: "foo" 237 238 string-array-with-default: 239 type: string-array 240 default: ["foo", "bar"] # Same as 'string-array-with-default = "foo", "bar"' 241 242 uint8-array-with-default: 243 type: uint8-array 244 default: [0x12, 0x34] # Same as 'uint8-array-with-default = [12 34]' 245 246required 247======== 248 249Adding ``required: true`` to a property definition will fail the build if a 250node matches the binding, but does not contain the property. 251 252The default setting is ``required: false``; that is, properties are optional by 253default. Using ``required: false`` is therefore redundant and strongly 254discouraged. 255 256type 257==== 258 259The type of a property constrains its values. The following types are 260available. See :ref:`dt-writing-property-values` for more details about writing 261values of each type in a DTS file. See :ref:`dt-phandles` for more information 262about the ``phandle*`` type properties. 263 264.. list-table:: 265 :header-rows: 1 266 :widths: 1 3 2 267 268 * - Type 269 - Description 270 - Example in DTS 271 272 * - ``string`` 273 - exactly one string 274 - ``status = "disabled";`` 275 276 * - ``int`` 277 - exactly one 32-bit value (cell) 278 - ``current-speed = <115200>;`` 279 280 * - ``boolean`` 281 - flags that don't take a value when true, and are absent if false 282 - ``hw-flow-control;`` 283 284 * - ``array`` 285 - zero or more 32-bit values (cells) 286 - ``offsets = <0x100 0x200 0x300>;`` 287 288 * - ``uint8-array`` 289 - zero or more bytes, in hex ('bytestring' in the Devicetree specification) 290 - ``local-mac-address = [de ad be ef 12 34];`` 291 292 * - ``string-array`` 293 - zero or more strings 294 - ``dma-names = "tx", "rx";`` 295 296 * - ``phandle`` 297 - exactly one phandle 298 - ``interrupt-parent = <&gic>;`` 299 300 * - ``phandles`` 301 - zero or more phandles 302 - ``pinctrl-0 = <&usart2_tx_pd5 &usart2_rx_pd6>;`` 303 304 * - ``phandle-array`` 305 - a list of phandles and 32-bit cells (usually specifiers) 306 - ``dmas = <&dma0 2>, <&dma0 3>;`` 307 308 * - ``path`` 309 - a path to a node as a phandle path reference or path string 310 - ``zephyr,bt-c2h-uart = &uart0;`` or 311 ``foo = "/path/to/some/node";`` 312 313 * - ``compound`` 314 - a catch-all for more complex types (no macros will be generated) 315 - ``foo = <&label>, [01 02];`` 316 317deprecated 318========== 319 320A property with ``deprecated: true`` indicates to both the user and the tooling 321that the property is meant to be phased out. 322 323The tooling will report a warning if the devicetree includes the property that 324is flagged as deprecated. (This warning is upgraded to an error in the 325:ref:`twister_script` for upstream pull requests.) 326 327The default setting is ``deprecated: false``. Using ``deprecated: false`` is 328therefore redundant and strongly discouraged. 329 330.. _dt-bindings-default: 331 332default 333======= 334 335The optional ``default:`` setting gives a value that will be used if the 336property is missing from the devicetree node. 337 338For example, with this binding fragment: 339 340.. code-block:: YAML 341 342 properties: 343 foo: 344 type: int 345 default: 3 346 347If property ``foo`` is missing in a matching node, then the output will be as 348if ``foo = <3>;`` had appeared in the DTS (except YAML data types are used for 349the default value). 350 351Note that combining ``default:`` with ``required: true`` will raise an error. 352 353For rules related to ``default`` in upstream Zephyr bindings, see 354:ref:`dt-bindings-default-rules`. 355 356See :ref:`dt-bindings-example-properties` for examples. Putting ``default:`` on 357any property type besides those used in :ref:`dt-bindings-example-properties` 358will raise an error. 359 360enum 361==== 362 363The ``enum:`` line is followed by a list of values the property may contain. If 364a property value in DTS is not in the ``enum:`` list in the binding, an error 365is raised. See :ref:`dt-bindings-example-properties` for examples. 366 367const 368===== 369 370This specifies a constant value the property must take. It is mainly useful for 371constraining the values of common properties for a particular piece of 372hardware. 373 374.. _dt-bindings-specifier-space: 375 376specifier-space 377=============== 378 379.. warning:: 380 381 It is an abuse of this feature to use it to name properties in 382 unconventional ways. 383 384 For example, this feature is not meant for cases like naming a property 385 ``my-pin``, then assigning it to the "gpio" specifier space using this 386 feature. Properties which refer to GPIOs should use conventional names, i.e. 387 end in ``-gpios`` or ``-gpio``. 388 389This property, if present, manually sets the specifier space associated with a 390property with type ``phandle-array``. 391 392Normally, the specifier space is encoded implicitly in the property name. A 393property named ``foos`` with type ``phandle-array`` implicitly has specifier 394space ``foo``. As a special case, ``*-gpios`` properties have specifier space 395"gpio", so that ``foo-gpios`` will have specifier space "gpio" rather than 396"foo-gpio". 397 398You can use ``specifier-space`` to manually provide a space if 399using this convention would result in an awkward or unconventional name. 400 401For example: 402 403.. code-block:: YAML 404 405 compatible: ... 406 properties: 407 bar: 408 type: phandle-array 409 specifier-space: my-custom-space 410 411Above, the ``bar`` property's specifier space is set to "my-custom-space". 412 413You could then use the property in a devicetree like this: 414 415.. code-block:: DTS 416 417 controller1: custom-controller@1000 { 418 #my-custom-space-cells = <2>; 419 }; 420 421 controller2: custom-controller@2000 { 422 #my-custom-space-cells = <1>; 423 }; 424 425 my-node { 426 bar = <&controller1 10 20>, <&controller2 30>; 427 }; 428 429Generally speaking, you should reserve this feature for cases where the 430implicit specifier space naming convention doesn't work. One appropriate 431example is an ``mboxes`` property with specifier space "mbox", not "mboxe". You 432can write this property as follows: 433 434.. code-block:: YAML 435 436 properties: 437 mboxes: 438 type: phandle-array 439 specifier-space: mbox 440 441.. _dt-bindings-child: 442 443Child-binding 444************* 445 446``child-binding`` can be used when a node has children that all share the same 447properties. Each child gets the contents of ``child-binding`` as its binding, 448though an explicit ``compatible = ...`` on the child node takes precedence, if 449a binding is found for it. 450 451Consider a binding for a PWM LED node like this one, where the child nodes are 452required to have a ``pwms`` property: 453 454.. code-block:: devicetree 455 456 pwmleds { 457 compatible = "pwm-leds"; 458 459 red_pwm_led { 460 pwms = <&pwm3 4 15625000>; 461 }; 462 green_pwm_led { 463 pwms = <&pwm3 0 15625000>; 464 }; 465 /* ... */ 466 }; 467 468The binding would look like this: 469 470.. code-block:: YAML 471 472 compatible: "pwm-leds" 473 474 child-binding: 475 description: LED that uses PWM 476 477 properties: 478 pwms: 479 type: phandle-array 480 required: true 481 482``child-binding`` also works recursively. For example, this binding: 483 484.. code-block:: YAML 485 486 compatible: foo 487 488 child-binding: 489 child-binding: 490 properties: 491 my-property: 492 type: int 493 required: true 494 495will apply to the ``grandchild`` node in this DTS: 496 497.. code-block:: devicetree 498 499 parent { 500 compatible = "foo"; 501 child { 502 grandchild { 503 my-property = <123>; 504 }; 505 }; 506 }; 507 508.. _dt-bindings-bus: 509 510Bus 511*** 512 513If the node is a bus controller, use ``bus:`` in the binding to say what type 514of bus. For example, a binding for a SPI peripheral on an SoC would look like 515this: 516 517.. code-block:: YAML 518 519 compatible: "manufacturer,spi-peripheral" 520 bus: spi 521 # ... 522 523The presence of this key in the binding informs the build system that the 524children of any node matching this binding appear on this type of bus. 525 526This in turn influences the way ``on-bus:`` is used to match bindings for the 527child nodes. 528 529For a single bus supporting multiple protocols, e.g. I3C and I2C, the ``bus:`` 530in the binding can have a list as value: 531 532.. code-block:: YAML 533 534 compatible: "manufacturer,i3c-controller" 535 bus: [i3c, i2c] 536 # ... 537 538.. _dt-bindings-on-bus: 539 540On-bus 541****** 542 543If the node appears as a device on a bus, use ``on-bus:`` in the binding to say 544what type of bus. 545 546For example, a binding for an external SPI memory chip should include this line: 547 548.. code-block:: YAML 549 550 on-bus: spi 551 552And a binding for an I2C based temperature sensor should include this line: 553 554.. code-block:: YAML 555 556 on-bus: i2c 557 558When looking for a binding for a node, the build system checks if the binding 559for the parent node contains ``bus: <bus type>``. If it does, then only 560bindings with a matching ``on-bus: <bus type>`` and bindings without an 561explicit ``on-bus`` are considered. Bindings with an explicit ``on-bus: <bus 562type>`` are searched for first, before bindings without an explicit ``on-bus``. 563The search repeats for each item in the node's ``compatible`` property, in 564order. 565 566This feature allows the same device to have different bindings depending on 567what bus it appears on. For example, consider a sensor device with compatible 568``manufacturer,sensor`` which can be used via either I2C or SPI. 569 570The sensor node may therefore appear in the devicetree as a child node of 571either an SPI or an I2C controller, like this: 572 573.. code-block:: devicetree 574 575 spi-bus@0 { 576 /* ... some compatible with 'bus: spi', etc. ... */ 577 578 sensor@0 { 579 compatible = "manufacturer,sensor"; 580 reg = <0>; 581 /* ... */ 582 }; 583 }; 584 585 i2c-bus@0 { 586 /* ... some compatible with 'bus: i2c', etc. ... */ 587 588 sensor@79 { 589 compatible = "manufacturer,sensor"; 590 reg = <79>; 591 /* ... */ 592 }; 593 }; 594 595You can write two separate binding files which match these individual sensor 596nodes, even though they have the same compatible: 597 598.. code-block:: YAML 599 600 # manufacturer,sensor-spi.yaml, which matches sensor@0 on the SPI bus: 601 compatible: "manufacturer,sensor" 602 on-bus: spi 603 604 # manufacturer,sensor-i2c.yaml, which matches sensor@79 on the I2C bus: 605 compatible: "manufacturer,sensor" 606 properties: 607 uses-clock-stretching: 608 type: boolean 609 on-bus: i2c 610 611Only ``sensor@79`` can have a ``use-clock-stretching`` property. The 612bus-sensitive logic ignores :file:`manufacturer,sensor-i2c.yaml` when searching 613for a binding for ``sensor@0``. 614 615.. _dt-bindings-cells: 616 617Specifier cell names (\*-cells) 618******************************* 619 620This section documents how to name the cells in a specifier within a binding. 621These concepts are discussed in detail later in this guide in 622:ref:`dt-phandle-arrays`. 623 624Consider a binding for a node whose phandle may appear in a ``phandle-array`` 625property, like the PWM controllers ``pwm1`` and ``pwm2`` in this example: 626 627.. code-block:: DTS 628 629 pwm1: pwm@deadbeef { 630 compatible = "foo,pwm"; 631 #pwm-cells = <2>; 632 }; 633 634 pwm2: pwm@deadbeef { 635 compatible = "bar,pwm"; 636 #pwm-cells = <1>; 637 }; 638 639 my-node { 640 pwms = <&pwm1 1 2000>, <&pwm2 3000>; 641 }; 642 643The bindings for compatible ``"foo,pwm"`` and ``"bar,pwm"`` must give a name to 644the cells that appear in a PWM specifier using ``pwm-cells:``, like this: 645 646.. code-block:: YAML 647 648 # foo,pwm.yaml 649 compatible: "foo,pwm" 650 ... 651 pwm-cells: 652 - channel 653 - period 654 655 # bar,pwm.yaml 656 compatible: "bar,pwm" 657 ... 658 pwm-cells: 659 - period 660 661A ``*-names`` (e.g. ``pwm-names``) property can appear on the node as well, 662giving a name to each entry. 663 664This allows the cells in the specifiers to be accessed by name, e.g. using APIs 665like :c:macro:`DT_PWMS_CHANNEL_BY_NAME`. 666 667If the specifier is empty (e.g. ``#clock-cells = <0>``), then ``*-cells`` can 668either be omitted (recommended) or set to an empty array. Note that an empty 669array is specified as e.g. ``clock-cells: []`` in YAML. 670 671.. _dt-bindings-include: 672 673Include 674******* 675 676Bindings can include other files, which can be used to share common property 677definitions between bindings. Use the ``include:`` key for this. Its value is 678either a string or a list. 679 680In the simplest case, you can include another file by giving its name as a 681string, like this: 682 683.. code-block:: YAML 684 685 include: foo.yaml 686 687If any file named :file:`foo.yaml` is found (see 688:ref:`dt-where-bindings-are-located` for the search process), it will be 689included into this binding. 690 691Included files are merged into bindings with a simple recursive dictionary 692merge. The build system will check that the resulting merged binding is 693well-formed. It is allowed to include at any level, including ``child-binding``, 694like this: 695 696.. code-block:: YAML 697 698 # foo.yaml will be merged with content at this level 699 include: foo.yaml 700 701 child-binding: 702 # bar.yaml will be merged with content at this level 703 include: bar.yaml 704 705It is an error if a key appears with a different value in a binding and in a 706file it includes, with one exception: a binding can have ``required: true`` for 707a :ref:`property definition <dt-bindings-properties>` for which the included 708file has ``required: false``. The ``required: true`` takes precedence, allowing 709bindings to strengthen requirements from included files. 710 711Note that weakening requirements by having ``required: false`` where the 712included file has ``required: true`` is an error. This is meant to keep the 713organization clean. 714 715The file :zephyr_file:`base.yaml <dts/bindings/base/base.yaml>` contains 716definitions for many common properties. When writing a new binding, it is a 717good idea to check if :file:`base.yaml` already defines some of the needed 718properties, and include it if it does. 719 720Note that you can make a property defined in base.yaml obligatory like this, 721taking :ref:`reg <dt-important-props>` as an example: 722 723.. code-block:: YAML 724 725 reg: 726 required: true 727 728This relies on the dictionary merge to fill in the other keys for ``reg``, like 729``type``. 730 731To include multiple files, you can use a list of strings: 732 733.. code-block:: YAML 734 735 include: 736 - foo.yaml 737 - bar.yaml 738 739This includes the files :file:`foo.yaml` and :file:`bar.yaml`. (You can 740write this list in a single line of YAML as ``include: [foo.yaml, bar.yaml]``.) 741 742When including multiple files, any overlapping ``required`` keys on properties 743in the included files are ORed together. This makes sure that a ``required: 744true`` is always respected. 745 746In some cases, you may want to include some property definitions from a file, 747but not all of them. In this case, ``include:`` should be a list, and you can 748filter out just the definitions you want by putting a mapping in the list, like 749this: 750 751.. code-block:: YAML 752 753 include: 754 - name: foo.yaml 755 property-allowlist: 756 - i-want-this-one 757 - and-this-one 758 - name: bar.yaml 759 property-blocklist: 760 - do-not-include-this-one 761 - or-this-one 762 763Each map element must have a ``name`` key which is the filename to include, and 764may have ``property-allowlist`` and ``property-blocklist`` keys that filter 765which properties are included. 766 767You cannot have a single map element with both ``property-allowlist`` and 768``property-blocklist`` keys. A map element with neither ``property-allowlist`` 769nor ``property-blocklist`` is valid; no additional filtering is done. 770 771You can freely intermix strings and mappings in a single ``include:`` list: 772 773.. code-block:: YAML 774 775 include: 776 - foo.yaml 777 - name: bar.yaml 778 property-blocklist: 779 - do-not-include-this-one 780 - or-this-one 781 782Finally, you can filter from a child binding like this: 783 784.. code-block:: YAML 785 786 include: 787 - name: bar.yaml 788 child-binding: 789 property-allowlist: 790 - child-prop-to-allow 791 792Nexus nodes and maps 793******************** 794 795All ``phandle-array`` type properties support mapping through ``*-map`` 796properties, e.g. ``gpio-map``, as defined by the Devicetree specification. 797 798This is used, for example, to define connector nodes for common breakout 799headers, such as the ``arduino_header`` nodes that are conventionally defined 800in the devicetrees for boards with Arduino compatible expansion headers. 801