xref: /freebsd/sys/contrib/device-tree/Bindings/example-schema.yaml (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1c66ec88fSEmmanuel Vadot# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2c66ec88fSEmmanuel Vadot# Copyright 2018 Linaro Ltd.
3c66ec88fSEmmanuel Vadot%YAML 1.2
4c66ec88fSEmmanuel Vadot---
5c66ec88fSEmmanuel Vadot# All the top-level keys are standard json-schema keywords except for
6c66ec88fSEmmanuel Vadot# 'maintainers' and 'select'
7c66ec88fSEmmanuel Vadot
8c66ec88fSEmmanuel Vadot# $id is a unique identifier based on the filename. There may or may not be a
9c66ec88fSEmmanuel Vadot# file present at the URL.
10c66ec88fSEmmanuel Vadot$id: http://devicetree.org/schemas/example-schema.yaml#
11c66ec88fSEmmanuel Vadot# $schema is the meta-schema this schema should be validated with.
12c66ec88fSEmmanuel Vadot$schema: http://devicetree.org/meta-schemas/core.yaml#
13c66ec88fSEmmanuel Vadot
148bab661aSEmmanuel Vadottitle: An Example Device
15c66ec88fSEmmanuel Vadot
16c66ec88fSEmmanuel Vadotmaintainers:
17c66ec88fSEmmanuel Vadot  - Rob Herring <robh@kernel.org>
18c66ec88fSEmmanuel Vadot
19c66ec88fSEmmanuel Vadotdescription: |
20c66ec88fSEmmanuel Vadot  A more detailed multi-line description of the binding.
21c66ec88fSEmmanuel Vadot
22c66ec88fSEmmanuel Vadot  Details about the hardware device and any links to datasheets can go here.
23c66ec88fSEmmanuel Vadot
24c66ec88fSEmmanuel Vadot  Literal blocks are marked with the '|' at the beginning. The end is marked by
25c66ec88fSEmmanuel Vadot  indentation less than the first line of the literal block. Lines also cannot
26c66ec88fSEmmanuel Vadot  begin with a tab character.
27c66ec88fSEmmanuel Vadot
28c66ec88fSEmmanuel Vadotselect: false
29c66ec88fSEmmanuel Vadot  # 'select' is a schema applied to a DT node to determine if this binding
30c66ec88fSEmmanuel Vadot  # schema should be applied to the node. It is optional and by default the
31c66ec88fSEmmanuel Vadot  # possible compatible strings are extracted and used to match.
32c66ec88fSEmmanuel Vadot
33c66ec88fSEmmanuel Vadot  # In this case, a 'false' schema will never match.
34c66ec88fSEmmanuel Vadot
35c66ec88fSEmmanuel Vadotproperties:
36c66ec88fSEmmanuel Vadot  # A dictionary of DT properties for this binding schema
37c66ec88fSEmmanuel Vadot  compatible:
38c66ec88fSEmmanuel Vadot    # More complicated schema can use oneOf (XOR), anyOf (OR), or allOf (AND)
39c66ec88fSEmmanuel Vadot    # to handle different conditions.
40c66ec88fSEmmanuel Vadot    # In this case, it's needed to handle a variable number of values as there
41c66ec88fSEmmanuel Vadot    # isn't another way to express a constraint of the last string value.
42c66ec88fSEmmanuel Vadot    # The boolean schema must be a list of schemas.
43c66ec88fSEmmanuel Vadot    oneOf:
44c66ec88fSEmmanuel Vadot      - items:
45c66ec88fSEmmanuel Vadot          # items is a list of possible values for the property. The number of
46c66ec88fSEmmanuel Vadot          # values is determined by the number of elements in the list.
47c66ec88fSEmmanuel Vadot          # Order in lists is significant, order in dicts is not
48c66ec88fSEmmanuel Vadot          # Must be one of the 1st enums followed by the 2nd enum
49c66ec88fSEmmanuel Vadot          #
50c66ec88fSEmmanuel Vadot          # Each element in items should be 'enum' or 'const'
51c66ec88fSEmmanuel Vadot          - enum:
52c66ec88fSEmmanuel Vadot              - vendor,soc4-ip
53c66ec88fSEmmanuel Vadot              - vendor,soc3-ip
54c66ec88fSEmmanuel Vadot              - vendor,soc2-ip
55*f126890aSEmmanuel Vadot          - const: vendor,soc1-ip
56c66ec88fSEmmanuel Vadot        # additionalItems being false is implied
57c66ec88fSEmmanuel Vadot        # minItems/maxItems equal to 2 is implied
58c66ec88fSEmmanuel Vadot      - items:
59c66ec88fSEmmanuel Vadot          # 'const' is just a special case of an enum with a single possible value
60c66ec88fSEmmanuel Vadot          - const: vendor,soc1-ip
61c66ec88fSEmmanuel Vadot
62c66ec88fSEmmanuel Vadot  reg:
63c66ec88fSEmmanuel Vadot    # The core schema already checks that reg values are numbers, so device
64c66ec88fSEmmanuel Vadot    # specific schema don't need to do those checks.
65c66ec88fSEmmanuel Vadot    # The description of each element defines the order and implicitly defines
66c66ec88fSEmmanuel Vadot    # the number of reg entries.
67c66ec88fSEmmanuel Vadot    items:
68c66ec88fSEmmanuel Vadot      - description: core registers
69c66ec88fSEmmanuel Vadot      - description: aux registers
70c66ec88fSEmmanuel Vadot    # minItems/maxItems equal to 2 is implied
71c66ec88fSEmmanuel Vadot
72c66ec88fSEmmanuel Vadot  reg-names:
73c66ec88fSEmmanuel Vadot    # The core schema enforces this (*-names) is a string array
74c66ec88fSEmmanuel Vadot    items:
75c66ec88fSEmmanuel Vadot      - const: core
76c66ec88fSEmmanuel Vadot      - const: aux
77c66ec88fSEmmanuel Vadot
78c66ec88fSEmmanuel Vadot  clocks:
79c66ec88fSEmmanuel Vadot    # Cases that have only a single entry just need to express that with maxItems
80c66ec88fSEmmanuel Vadot    maxItems: 1
81c66ec88fSEmmanuel Vadot    description: bus clock. A description is only needed for a single item if
82c66ec88fSEmmanuel Vadot      there's something unique to add.
836be33864SEmmanuel Vadot      The items should have a fixed order, so pattern matching names are
846be33864SEmmanuel Vadot      discouraged.
85c66ec88fSEmmanuel Vadot
86c66ec88fSEmmanuel Vadot  clock-names:
87*f126890aSEmmanuel Vadot    # For single-entry lists in clocks, resets etc., the xxx-names often do not
88*f126890aSEmmanuel Vadot    # bring any value, especially if they copy the IP block name.  In such case
89*f126890aSEmmanuel Vadot    # just skip the xxx-names.
90c66ec88fSEmmanuel Vadot    items:
91c66ec88fSEmmanuel Vadot      - const: bus
92c66ec88fSEmmanuel Vadot
93c66ec88fSEmmanuel Vadot  interrupts:
94c66ec88fSEmmanuel Vadot    # Either 1 or 2 interrupts can be present
95c66ec88fSEmmanuel Vadot    minItems: 1
96c66ec88fSEmmanuel Vadot    items:
97c66ec88fSEmmanuel Vadot      - description: tx or combined interrupt
98c66ec88fSEmmanuel Vadot      - description: rx interrupt
99c66ec88fSEmmanuel Vadot    description:
100c66ec88fSEmmanuel Vadot      A variable number of interrupts warrants a description of what conditions
101c66ec88fSEmmanuel Vadot      affect the number of interrupts. Otherwise, descriptions on standard
102c66ec88fSEmmanuel Vadot      properties are not necessary.
1036be33864SEmmanuel Vadot      The items should have a fixed order, so pattern matching names are
1046be33864SEmmanuel Vadot      discouraged.
105c66ec88fSEmmanuel Vadot
106c66ec88fSEmmanuel Vadot  interrupt-names:
107c66ec88fSEmmanuel Vadot    # minItems must be specified here because the default would be 2
108c66ec88fSEmmanuel Vadot    minItems: 1
109c66ec88fSEmmanuel Vadot    items:
110c66ec88fSEmmanuel Vadot      - const: tx irq
111c66ec88fSEmmanuel Vadot      - const: rx irq
112c66ec88fSEmmanuel Vadot
113c66ec88fSEmmanuel Vadot  # Property names starting with '#' must be quoted
114c66ec88fSEmmanuel Vadot  '#interrupt-cells':
115c66ec88fSEmmanuel Vadot    # A simple case where the value must always be '2'.
116c66ec88fSEmmanuel Vadot    # The core schema handles that this must be a single integer.
117c66ec88fSEmmanuel Vadot    const: 2
118c66ec88fSEmmanuel Vadot
119c66ec88fSEmmanuel Vadot  interrupt-controller: true
120c66ec88fSEmmanuel Vadot    # The core checks this is a boolean, so just have to list it here to be
121c66ec88fSEmmanuel Vadot    # valid for this binding.
122c66ec88fSEmmanuel Vadot
123c66ec88fSEmmanuel Vadot  clock-frequency:
1248cc087a1SEmmanuel Vadot    # The type is set in the core schema. Per-device schema only need to set
125c66ec88fSEmmanuel Vadot    # constraints on the possible values.
126c66ec88fSEmmanuel Vadot    minimum: 100
127c66ec88fSEmmanuel Vadot    maximum: 400000
128c66ec88fSEmmanuel Vadot    # The value that should be used if the property is not present
129c66ec88fSEmmanuel Vadot    default: 200
130c66ec88fSEmmanuel Vadot
131c66ec88fSEmmanuel Vadot  foo-gpios:
132c66ec88fSEmmanuel Vadot    maxItems: 1
133c66ec88fSEmmanuel Vadot    description: A connection of the 'foo' gpio line.
134c66ec88fSEmmanuel Vadot
135c66ec88fSEmmanuel Vadot  # *-supply is always a single phandle, so nothing more to define.
136c66ec88fSEmmanuel Vadot  foo-supply: true
137c66ec88fSEmmanuel Vadot
1388cc087a1SEmmanuel Vadot  # Vendor-specific properties
139c66ec88fSEmmanuel Vadot  #
1408cc087a1SEmmanuel Vadot  # Vendor-specific properties have slightly different schema requirements than
141c66ec88fSEmmanuel Vadot  # common properties. They must have at least a type definition and
142c66ec88fSEmmanuel Vadot  # 'description'.
143c66ec88fSEmmanuel Vadot  vendor,int-property:
1448cc087a1SEmmanuel Vadot    description: Vendor-specific properties must have a description
145c66ec88fSEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32
146c66ec88fSEmmanuel Vadot    enum: [2, 4, 6, 8, 10]
147c66ec88fSEmmanuel Vadot
148c66ec88fSEmmanuel Vadot  vendor,bool-property:
1498cc087a1SEmmanuel Vadot    description: Vendor-specific properties must have a description. Boolean
150c66ec88fSEmmanuel Vadot      properties are one case where the json-schema 'type' keyword can be used
151c66ec88fSEmmanuel Vadot      directly.
152c66ec88fSEmmanuel Vadot    type: boolean
153c66ec88fSEmmanuel Vadot
154c66ec88fSEmmanuel Vadot  vendor,string-array-property:
1558cc087a1SEmmanuel Vadot    description: Vendor-specific properties should reference a type in the
156c66ec88fSEmmanuel Vadot      core schema.
157c66ec88fSEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/string-array
158c66ec88fSEmmanuel Vadot    items:
159c66ec88fSEmmanuel Vadot      - enum: [foo, bar]
160c66ec88fSEmmanuel Vadot      - enum: [baz, boo]
161c66ec88fSEmmanuel Vadot
162c66ec88fSEmmanuel Vadot  vendor,property-in-standard-units-microvolt:
1638cc087a1SEmmanuel Vadot    description: Vendor-specific properties having a standard unit suffix
164c66ec88fSEmmanuel Vadot      don't need a type.
165c66ec88fSEmmanuel Vadot    enum: [ 100, 200, 300 ]
166c66ec88fSEmmanuel Vadot
167c9ccf3a3SEmmanuel Vadot  vendor,int-array-variable-length-and-constrained-values:
168c9ccf3a3SEmmanuel Vadot    description: Array might define what type of elements might be used (e.g.
169c9ccf3a3SEmmanuel Vadot      their range).
170c9ccf3a3SEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32-array
171c9ccf3a3SEmmanuel Vadot    minItems: 2
172c9ccf3a3SEmmanuel Vadot    maxItems: 3
173c9ccf3a3SEmmanuel Vadot    items:
174c9ccf3a3SEmmanuel Vadot      minimum: 0
175c9ccf3a3SEmmanuel Vadot      maximum: 8
176c9ccf3a3SEmmanuel Vadot
177c66ec88fSEmmanuel Vadot  child-node:
178c66ec88fSEmmanuel Vadot    description: Child nodes are just another property from a json-schema
179c66ec88fSEmmanuel Vadot      perspective.
180c66ec88fSEmmanuel Vadot    type: object  # DT nodes are json objects
181fac71e4eSEmmanuel Vadot    # Child nodes also need additionalProperties or unevaluatedProperties
182fac71e4eSEmmanuel Vadot    additionalProperties: false
183c66ec88fSEmmanuel Vadot    properties:
184c66ec88fSEmmanuel Vadot      vendor,a-child-node-property:
185c66ec88fSEmmanuel Vadot        description: Child node properties have all the same schema
186c66ec88fSEmmanuel Vadot          requirements.
187c66ec88fSEmmanuel Vadot        type: boolean
188c66ec88fSEmmanuel Vadot
189c66ec88fSEmmanuel Vadot    required:
190c66ec88fSEmmanuel Vadot      - vendor,a-child-node-property
191c66ec88fSEmmanuel Vadot
192c66ec88fSEmmanuel Vadot# Describe the relationship between different properties
193c66ec88fSEmmanuel Vadotdependencies:
194c66ec88fSEmmanuel Vadot  # 'vendor,bool-property' is only allowed when 'vendor,string-array-property'
195c66ec88fSEmmanuel Vadot  # is present
196c66ec88fSEmmanuel Vadot  vendor,bool-property: [ 'vendor,string-array-property' ]
197c66ec88fSEmmanuel Vadot  # Expressing 2 properties in both orders means all of the set of properties
198c66ec88fSEmmanuel Vadot  # must be present or none of them.
199c66ec88fSEmmanuel Vadot  vendor,string-array-property: [ 'vendor,bool-property' ]
200c66ec88fSEmmanuel Vadot
201c66ec88fSEmmanuel Vadotrequired:
202c66ec88fSEmmanuel Vadot  - compatible
203c66ec88fSEmmanuel Vadot  - reg
204c66ec88fSEmmanuel Vadot  - interrupts
205c66ec88fSEmmanuel Vadot  - interrupt-controller
206c66ec88fSEmmanuel Vadot
207c66ec88fSEmmanuel Vadot# if/then schema can be used to handle conditions on a property affecting
208c66ec88fSEmmanuel Vadot# another property. A typical case is a specific 'compatible' value changes the
209c66ec88fSEmmanuel Vadot# constraints on other properties.
210c66ec88fSEmmanuel Vadot#
211c66ec88fSEmmanuel Vadot# For multiple 'if' schema, group them under an 'allOf'.
212c66ec88fSEmmanuel Vadot#
213c66ec88fSEmmanuel Vadot# If the conditionals become too unweldy, then it may be better to just split
214c66ec88fSEmmanuel Vadot# the binding into separate schema documents.
2156be33864SEmmanuel VadotallOf:
2166be33864SEmmanuel Vadot  - if:
217c66ec88fSEmmanuel Vadot      properties:
218c66ec88fSEmmanuel Vadot        compatible:
219c66ec88fSEmmanuel Vadot          contains:
220c66ec88fSEmmanuel Vadot            const: vendor,soc2-ip
221c66ec88fSEmmanuel Vadot    then:
222c66ec88fSEmmanuel Vadot      required:
223c66ec88fSEmmanuel Vadot        - foo-supply
224c9ccf3a3SEmmanuel Vadot    else:
225c9ccf3a3SEmmanuel Vadot      # If otherwise the property is not allowed:
226c9ccf3a3SEmmanuel Vadot      properties:
227c9ccf3a3SEmmanuel Vadot        foo-supply: false
2286be33864SEmmanuel Vadot  # Altering schema depending on presence of properties is usually done by
2296be33864SEmmanuel Vadot  # dependencies (see above), however some adjustments might require if:
2306be33864SEmmanuel Vadot  - if:
2316be33864SEmmanuel Vadot      required:
2326be33864SEmmanuel Vadot        - vendor,bool-property
2336be33864SEmmanuel Vadot    then:
2346be33864SEmmanuel Vadot      properties:
2356be33864SEmmanuel Vadot        vendor,int-property:
2366be33864SEmmanuel Vadot          enum: [2, 4, 6]
237c66ec88fSEmmanuel Vadot
238c66ec88fSEmmanuel Vadot# Ideally, the schema should have this line otherwise any other properties
239c66ec88fSEmmanuel Vadot# present are allowed. There's a few common properties such as 'status' and
240c66ec88fSEmmanuel Vadot# 'pinctrl-*' which are added automatically by the tooling.
241c66ec88fSEmmanuel Vadot#
242c66ec88fSEmmanuel Vadot# This can't be used in cases where another schema is referenced
243c66ec88fSEmmanuel Vadot# (i.e. allOf: [{$ref: ...}]).
2446be33864SEmmanuel Vadot# If and only if another schema is referenced and arbitrary children nodes can
2456be33864SEmmanuel Vadot# appear, "unevaluatedProperties: false" could be used.  A typical example is
2466be33864SEmmanuel Vadot# an I2C controller where no name pattern matching for children can be added.
247c66ec88fSEmmanuel VadotadditionalProperties: false
248c66ec88fSEmmanuel Vadot
249c66ec88fSEmmanuel Vadotexamples:
250c66ec88fSEmmanuel Vadot  # Examples are now compiled with dtc and validated against the schemas
251c66ec88fSEmmanuel Vadot  #
252c66ec88fSEmmanuel Vadot  # Examples have a default #address-cells and #size-cells value of 1. This can
253c66ec88fSEmmanuel Vadot  # be overridden or an appropriate parent bus node should be shown (such as on
254c66ec88fSEmmanuel Vadot  # i2c buses).
255c66ec88fSEmmanuel Vadot  #
256d5b0e70fSEmmanuel Vadot  # Any includes used have to be explicitly included. Use 4-space indentation.
257c66ec88fSEmmanuel Vadot  - |
258c66ec88fSEmmanuel Vadot    node@1000 {
259c66ec88fSEmmanuel Vadot        compatible = "vendor,soc4-ip", "vendor,soc1-ip";
260c66ec88fSEmmanuel Vadot        reg = <0x1000 0x80>,
261c66ec88fSEmmanuel Vadot              <0x3000 0x80>;
262c66ec88fSEmmanuel Vadot        reg-names = "core", "aux";
263c66ec88fSEmmanuel Vadot        interrupts = <10>;
264c66ec88fSEmmanuel Vadot        interrupt-controller;
265c66ec88fSEmmanuel Vadot    };
266