18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
28c2ecf20Sopenharmony_ci# Copyright 2018 Linaro Ltd.
38c2ecf20Sopenharmony_ci%YAML 1.2
48c2ecf20Sopenharmony_ci---
58c2ecf20Sopenharmony_ci# All the top-level keys are standard json-schema keywords except for
68c2ecf20Sopenharmony_ci# 'maintainers' and 'select'
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci# $id is a unique identifier based on the filename. There may or may not be a
98c2ecf20Sopenharmony_ci# file present at the URL.
108c2ecf20Sopenharmony_ci$id: http://devicetree.org/schemas/example-schema.yaml#
118c2ecf20Sopenharmony_ci# $schema is the meta-schema this schema should be validated with.
128c2ecf20Sopenharmony_ci$schema: http://devicetree.org/meta-schemas/core.yaml#
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_cititle: An example schema annotated with jsonschema details
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cimaintainers:
178c2ecf20Sopenharmony_ci  - Rob Herring <robh@kernel.org>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_cidescription: |
208c2ecf20Sopenharmony_ci  A more detailed multi-line description of the binding.
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci  Details about the hardware device and any links to datasheets can go here.
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci  Literal blocks are marked with the '|' at the beginning. The end is marked by
258c2ecf20Sopenharmony_ci  indentation less than the first line of the literal block. Lines also cannot
268c2ecf20Sopenharmony_ci  begin with a tab character.
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ciselect: false
298c2ecf20Sopenharmony_ci  # 'select' is a schema applied to a DT node to determine if this binding
308c2ecf20Sopenharmony_ci  # schema should be applied to the node. It is optional and by default the
318c2ecf20Sopenharmony_ci  # possible compatible strings are extracted and used to match.
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci  # In this case, a 'false' schema will never match.
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciproperties:
368c2ecf20Sopenharmony_ci  # A dictionary of DT properties for this binding schema
378c2ecf20Sopenharmony_ci  compatible:
388c2ecf20Sopenharmony_ci    # More complicated schema can use oneOf (XOR), anyOf (OR), or allOf (AND)
398c2ecf20Sopenharmony_ci    # to handle different conditions.
408c2ecf20Sopenharmony_ci    # In this case, it's needed to handle a variable number of values as there
418c2ecf20Sopenharmony_ci    # isn't another way to express a constraint of the last string value.
428c2ecf20Sopenharmony_ci    # The boolean schema must be a list of schemas.
438c2ecf20Sopenharmony_ci    oneOf:
448c2ecf20Sopenharmony_ci      - items:
458c2ecf20Sopenharmony_ci          # items is a list of possible values for the property. The number of
468c2ecf20Sopenharmony_ci          # values is determined by the number of elements in the list.
478c2ecf20Sopenharmony_ci          # Order in lists is significant, order in dicts is not
488c2ecf20Sopenharmony_ci          # Must be one of the 1st enums followed by the 2nd enum
498c2ecf20Sopenharmony_ci          #
508c2ecf20Sopenharmony_ci          # Each element in items should be 'enum' or 'const'
518c2ecf20Sopenharmony_ci          - enum:
528c2ecf20Sopenharmony_ci              - vendor,soc4-ip
538c2ecf20Sopenharmony_ci              - vendor,soc3-ip
548c2ecf20Sopenharmony_ci              - vendor,soc2-ip
558c2ecf20Sopenharmony_ci          - enum:
568c2ecf20Sopenharmony_ci              - vendor,soc1-ip
578c2ecf20Sopenharmony_ci        # additionalItems being false is implied
588c2ecf20Sopenharmony_ci        # minItems/maxItems equal to 2 is implied
598c2ecf20Sopenharmony_ci      - items:
608c2ecf20Sopenharmony_ci          # 'const' is just a special case of an enum with a single possible value
618c2ecf20Sopenharmony_ci          - const: vendor,soc1-ip
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci  reg:
648c2ecf20Sopenharmony_ci    # The core schema already checks that reg values are numbers, so device
658c2ecf20Sopenharmony_ci    # specific schema don't need to do those checks.
668c2ecf20Sopenharmony_ci    # The description of each element defines the order and implicitly defines
678c2ecf20Sopenharmony_ci    # the number of reg entries.
688c2ecf20Sopenharmony_ci    items:
698c2ecf20Sopenharmony_ci      - description: core registers
708c2ecf20Sopenharmony_ci      - description: aux registers
718c2ecf20Sopenharmony_ci    # minItems/maxItems equal to 2 is implied
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci  reg-names:
748c2ecf20Sopenharmony_ci    # The core schema enforces this (*-names) is a string array
758c2ecf20Sopenharmony_ci    items:
768c2ecf20Sopenharmony_ci      - const: core
778c2ecf20Sopenharmony_ci      - const: aux
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci  clocks:
808c2ecf20Sopenharmony_ci    # Cases that have only a single entry just need to express that with maxItems
818c2ecf20Sopenharmony_ci    maxItems: 1
828c2ecf20Sopenharmony_ci    description: bus clock. A description is only needed for a single item if
838c2ecf20Sopenharmony_ci      there's something unique to add.
848c2ecf20Sopenharmony_ci      The items should have a fixed order, so pattern matching names are
858c2ecf20Sopenharmony_ci      discouraged.
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci  clock-names:
888c2ecf20Sopenharmony_ci    items:
898c2ecf20Sopenharmony_ci      - const: bus
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci  interrupts:
928c2ecf20Sopenharmony_ci    # Either 1 or 2 interrupts can be present
938c2ecf20Sopenharmony_ci    minItems: 1
948c2ecf20Sopenharmony_ci    maxItems: 2
958c2ecf20Sopenharmony_ci    items:
968c2ecf20Sopenharmony_ci      - description: tx or combined interrupt
978c2ecf20Sopenharmony_ci      - description: rx interrupt
988c2ecf20Sopenharmony_ci    description:
998c2ecf20Sopenharmony_ci      A variable number of interrupts warrants a description of what conditions
1008c2ecf20Sopenharmony_ci      affect the number of interrupts. Otherwise, descriptions on standard
1018c2ecf20Sopenharmony_ci      properties are not necessary.
1028c2ecf20Sopenharmony_ci      The items should have a fixed order, so pattern matching names are
1038c2ecf20Sopenharmony_ci      discouraged.
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci  interrupt-names:
1068c2ecf20Sopenharmony_ci    # minItems must be specified here because the default would be 2
1078c2ecf20Sopenharmony_ci    minItems: 1
1088c2ecf20Sopenharmony_ci    maxItems: 2
1098c2ecf20Sopenharmony_ci    items:
1108c2ecf20Sopenharmony_ci      - const: tx irq
1118c2ecf20Sopenharmony_ci      - const: rx irq
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci  # Property names starting with '#' must be quoted
1148c2ecf20Sopenharmony_ci  '#interrupt-cells':
1158c2ecf20Sopenharmony_ci    # A simple case where the value must always be '2'.
1168c2ecf20Sopenharmony_ci    # The core schema handles that this must be a single integer.
1178c2ecf20Sopenharmony_ci    const: 2
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci  interrupt-controller: true
1208c2ecf20Sopenharmony_ci    # The core checks this is a boolean, so just have to list it here to be
1218c2ecf20Sopenharmony_ci    # valid for this binding.
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci  clock-frequency:
1248c2ecf20Sopenharmony_ci    # The type is set in the core schema. Per device schema only need to set
1258c2ecf20Sopenharmony_ci    # constraints on the possible values.
1268c2ecf20Sopenharmony_ci    minimum: 100
1278c2ecf20Sopenharmony_ci    maximum: 400000
1288c2ecf20Sopenharmony_ci    # The value that should be used if the property is not present
1298c2ecf20Sopenharmony_ci    default: 200
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci  foo-gpios:
1328c2ecf20Sopenharmony_ci    maxItems: 1
1338c2ecf20Sopenharmony_ci    description: A connection of the 'foo' gpio line.
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci  # *-supply is always a single phandle, so nothing more to define.
1368c2ecf20Sopenharmony_ci  foo-supply: true
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci  # Vendor specific properties
1398c2ecf20Sopenharmony_ci  #
1408c2ecf20Sopenharmony_ci  # Vendor specific properties have slightly different schema requirements than
1418c2ecf20Sopenharmony_ci  # common properties. They must have at least a type definition and
1428c2ecf20Sopenharmony_ci  # 'description'.
1438c2ecf20Sopenharmony_ci  vendor,int-property:
1448c2ecf20Sopenharmony_ci    description: Vendor specific properties must have a description
1458c2ecf20Sopenharmony_ci    $ref: /schemas/types.yaml#/definitions/uint32
1468c2ecf20Sopenharmony_ci    enum: [2, 4, 6, 8, 10]
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci  vendor,bool-property:
1498c2ecf20Sopenharmony_ci    description: Vendor specific properties must have a description. Boolean
1508c2ecf20Sopenharmony_ci      properties are one case where the json-schema 'type' keyword can be used
1518c2ecf20Sopenharmony_ci      directly.
1528c2ecf20Sopenharmony_ci    type: boolean
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci  vendor,string-array-property:
1558c2ecf20Sopenharmony_ci    description: Vendor specific properties should reference a type in the
1568c2ecf20Sopenharmony_ci      core schema.
1578c2ecf20Sopenharmony_ci    $ref: /schemas/types.yaml#/definitions/string-array
1588c2ecf20Sopenharmony_ci    items:
1598c2ecf20Sopenharmony_ci      - enum: [foo, bar]
1608c2ecf20Sopenharmony_ci      - enum: [baz, boo]
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_ci  vendor,property-in-standard-units-microvolt:
1638c2ecf20Sopenharmony_ci    description: Vendor specific properties having a standard unit suffix
1648c2ecf20Sopenharmony_ci      don't need a type.
1658c2ecf20Sopenharmony_ci    enum: [ 100, 200, 300 ]
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci  child-node:
1688c2ecf20Sopenharmony_ci    description: Child nodes are just another property from a json-schema
1698c2ecf20Sopenharmony_ci      perspective.
1708c2ecf20Sopenharmony_ci    type: object  # DT nodes are json objects
1718c2ecf20Sopenharmony_ci    properties:
1728c2ecf20Sopenharmony_ci      vendor,a-child-node-property:
1738c2ecf20Sopenharmony_ci        description: Child node properties have all the same schema
1748c2ecf20Sopenharmony_ci          requirements.
1758c2ecf20Sopenharmony_ci        type: boolean
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci    required:
1788c2ecf20Sopenharmony_ci      - vendor,a-child-node-property
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ci# Describe the relationship between different properties
1818c2ecf20Sopenharmony_cidependencies:
1828c2ecf20Sopenharmony_ci  # 'vendor,bool-property' is only allowed when 'vendor,string-array-property'
1838c2ecf20Sopenharmony_ci  # is present
1848c2ecf20Sopenharmony_ci  vendor,bool-property: [ 'vendor,string-array-property' ]
1858c2ecf20Sopenharmony_ci  # Expressing 2 properties in both orders means all of the set of properties
1868c2ecf20Sopenharmony_ci  # must be present or none of them.
1878c2ecf20Sopenharmony_ci  vendor,string-array-property: [ 'vendor,bool-property' ]
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cirequired:
1908c2ecf20Sopenharmony_ci  - compatible
1918c2ecf20Sopenharmony_ci  - reg
1928c2ecf20Sopenharmony_ci  - interrupts
1938c2ecf20Sopenharmony_ci  - interrupt-controller
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci# if/then schema can be used to handle conditions on a property affecting
1968c2ecf20Sopenharmony_ci# another property. A typical case is a specific 'compatible' value changes the
1978c2ecf20Sopenharmony_ci# constraints on other properties.
1988c2ecf20Sopenharmony_ci#
1998c2ecf20Sopenharmony_ci# For multiple 'if' schema, group them under an 'allOf'.
2008c2ecf20Sopenharmony_ci#
2018c2ecf20Sopenharmony_ci# If the conditionals become too unweldy, then it may be better to just split
2028c2ecf20Sopenharmony_ci# the binding into separate schema documents.
2038c2ecf20Sopenharmony_ciallOf:
2048c2ecf20Sopenharmony_ci  - if:
2058c2ecf20Sopenharmony_ci      properties:
2068c2ecf20Sopenharmony_ci        compatible:
2078c2ecf20Sopenharmony_ci          contains:
2088c2ecf20Sopenharmony_ci            const: vendor,soc2-ip
2098c2ecf20Sopenharmony_ci    then:
2108c2ecf20Sopenharmony_ci      required:
2118c2ecf20Sopenharmony_ci        - foo-supply
2128c2ecf20Sopenharmony_ci  # Altering schema depending on presence of properties is usually done by
2138c2ecf20Sopenharmony_ci  # dependencies (see above), however some adjustments might require if:
2148c2ecf20Sopenharmony_ci  - if:
2158c2ecf20Sopenharmony_ci      required:
2168c2ecf20Sopenharmony_ci        - vendor,bool-property
2178c2ecf20Sopenharmony_ci    then:
2188c2ecf20Sopenharmony_ci      properties:
2198c2ecf20Sopenharmony_ci        vendor,int-property:
2208c2ecf20Sopenharmony_ci          enum: [2, 4, 6]
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci# Ideally, the schema should have this line otherwise any other properties
2238c2ecf20Sopenharmony_ci# present are allowed. There's a few common properties such as 'status' and
2248c2ecf20Sopenharmony_ci# 'pinctrl-*' which are added automatically by the tooling.
2258c2ecf20Sopenharmony_ci#
2268c2ecf20Sopenharmony_ci# This can't be used in cases where another schema is referenced
2278c2ecf20Sopenharmony_ci# (i.e. allOf: [{$ref: ...}]).
2288c2ecf20Sopenharmony_ci# If and only if another schema is referenced and arbitrary children nodes can
2298c2ecf20Sopenharmony_ci# appear, "unevaluatedProperties: false" could be used.  A typical example is
2308c2ecf20Sopenharmony_ci# an I2C controller where no name pattern matching for children can be added.
2318c2ecf20Sopenharmony_ciadditionalProperties: false
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ciexamples:
2348c2ecf20Sopenharmony_ci  # Examples are now compiled with dtc and validated against the schemas
2358c2ecf20Sopenharmony_ci  #
2368c2ecf20Sopenharmony_ci  # Examples have a default #address-cells and #size-cells value of 1. This can
2378c2ecf20Sopenharmony_ci  # be overridden or an appropriate parent bus node should be shown (such as on
2388c2ecf20Sopenharmony_ci  # i2c buses).
2398c2ecf20Sopenharmony_ci  #
2408c2ecf20Sopenharmony_ci  # Any includes used have to be explicitly included.
2418c2ecf20Sopenharmony_ci  - |
2428c2ecf20Sopenharmony_ci    node@1000 {
2438c2ecf20Sopenharmony_ci          compatible = "vendor,soc4-ip", "vendor,soc1-ip";
2448c2ecf20Sopenharmony_ci          reg = <0x1000 0x80>,
2458c2ecf20Sopenharmony_ci                <0x3000 0x80>;
2468c2ecf20Sopenharmony_ci          reg-names = "core", "aux";
2478c2ecf20Sopenharmony_ci          interrupts = <10>;
2488c2ecf20Sopenharmony_ci          interrupt-controller;
2498c2ecf20Sopenharmony_ci    };
250