xref: /freebsd/sys/contrib/device-tree/Bindings/example-schema.yaml (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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
14c66ec88fSEmmanuel Vadottitle: An example schema annotated with jsonschema details
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
55c66ec88fSEmmanuel Vadot          - enum:
56c66ec88fSEmmanuel Vadot              - vendor,soc1-ip
57c66ec88fSEmmanuel Vadot        # additionalItems being false is implied
58c66ec88fSEmmanuel Vadot        # minItems/maxItems equal to 2 is implied
59c66ec88fSEmmanuel Vadot      - items:
60c66ec88fSEmmanuel Vadot          # 'const' is just a special case of an enum with a single possible value
61c66ec88fSEmmanuel Vadot          - const: vendor,soc1-ip
62c66ec88fSEmmanuel Vadot
63c66ec88fSEmmanuel Vadot  reg:
64c66ec88fSEmmanuel Vadot    # The core schema already checks that reg values are numbers, so device
65c66ec88fSEmmanuel Vadot    # specific schema don't need to do those checks.
66c66ec88fSEmmanuel Vadot    # The description of each element defines the order and implicitly defines
67c66ec88fSEmmanuel Vadot    # the number of reg entries.
68c66ec88fSEmmanuel Vadot    items:
69c66ec88fSEmmanuel Vadot      - description: core registers
70c66ec88fSEmmanuel Vadot      - description: aux registers
71c66ec88fSEmmanuel Vadot    # minItems/maxItems equal to 2 is implied
72c66ec88fSEmmanuel Vadot
73c66ec88fSEmmanuel Vadot  reg-names:
74c66ec88fSEmmanuel Vadot    # The core schema enforces this (*-names) is a string array
75c66ec88fSEmmanuel Vadot    items:
76c66ec88fSEmmanuel Vadot      - const: core
77c66ec88fSEmmanuel Vadot      - const: aux
78c66ec88fSEmmanuel Vadot
79c66ec88fSEmmanuel Vadot  clocks:
80c66ec88fSEmmanuel Vadot    # Cases that have only a single entry just need to express that with maxItems
81c66ec88fSEmmanuel Vadot    maxItems: 1
82c66ec88fSEmmanuel Vadot    description: bus clock. A description is only needed for a single item if
83c66ec88fSEmmanuel Vadot      there's something unique to add.
846be33864SEmmanuel Vadot      The items should have a fixed order, so pattern matching names are
856be33864SEmmanuel Vadot      discouraged.
86c66ec88fSEmmanuel Vadot
87c66ec88fSEmmanuel Vadot  clock-names:
88c66ec88fSEmmanuel Vadot    items:
89c66ec88fSEmmanuel Vadot      - const: bus
90c66ec88fSEmmanuel Vadot
91c66ec88fSEmmanuel Vadot  interrupts:
92c66ec88fSEmmanuel Vadot    # Either 1 or 2 interrupts can be present
93c66ec88fSEmmanuel Vadot    minItems: 1
94c66ec88fSEmmanuel Vadot    items:
95c66ec88fSEmmanuel Vadot      - description: tx or combined interrupt
96c66ec88fSEmmanuel Vadot      - description: rx interrupt
97c66ec88fSEmmanuel Vadot    description:
98c66ec88fSEmmanuel Vadot      A variable number of interrupts warrants a description of what conditions
99c66ec88fSEmmanuel Vadot      affect the number of interrupts. Otherwise, descriptions on standard
100c66ec88fSEmmanuel Vadot      properties are not necessary.
1016be33864SEmmanuel Vadot      The items should have a fixed order, so pattern matching names are
1026be33864SEmmanuel Vadot      discouraged.
103c66ec88fSEmmanuel Vadot
104c66ec88fSEmmanuel Vadot  interrupt-names:
105c66ec88fSEmmanuel Vadot    # minItems must be specified here because the default would be 2
106c66ec88fSEmmanuel Vadot    minItems: 1
107c66ec88fSEmmanuel Vadot    items:
108c66ec88fSEmmanuel Vadot      - const: tx irq
109c66ec88fSEmmanuel Vadot      - const: rx irq
110c66ec88fSEmmanuel Vadot
111c66ec88fSEmmanuel Vadot  # Property names starting with '#' must be quoted
112c66ec88fSEmmanuel Vadot  '#interrupt-cells':
113c66ec88fSEmmanuel Vadot    # A simple case where the value must always be '2'.
114c66ec88fSEmmanuel Vadot    # The core schema handles that this must be a single integer.
115c66ec88fSEmmanuel Vadot    const: 2
116c66ec88fSEmmanuel Vadot
117c66ec88fSEmmanuel Vadot  interrupt-controller: true
118c66ec88fSEmmanuel Vadot    # The core checks this is a boolean, so just have to list it here to be
119c66ec88fSEmmanuel Vadot    # valid for this binding.
120c66ec88fSEmmanuel Vadot
121c66ec88fSEmmanuel Vadot  clock-frequency:
1228cc087a1SEmmanuel Vadot    # The type is set in the core schema. Per-device schema only need to set
123c66ec88fSEmmanuel Vadot    # constraints on the possible values.
124c66ec88fSEmmanuel Vadot    minimum: 100
125c66ec88fSEmmanuel Vadot    maximum: 400000
126c66ec88fSEmmanuel Vadot    # The value that should be used if the property is not present
127c66ec88fSEmmanuel Vadot    default: 200
128c66ec88fSEmmanuel Vadot
129c66ec88fSEmmanuel Vadot  foo-gpios:
130c66ec88fSEmmanuel Vadot    maxItems: 1
131c66ec88fSEmmanuel Vadot    description: A connection of the 'foo' gpio line.
132c66ec88fSEmmanuel Vadot
133c66ec88fSEmmanuel Vadot  # *-supply is always a single phandle, so nothing more to define.
134c66ec88fSEmmanuel Vadot  foo-supply: true
135c66ec88fSEmmanuel Vadot
1368cc087a1SEmmanuel Vadot  # Vendor-specific properties
137c66ec88fSEmmanuel Vadot  #
1388cc087a1SEmmanuel Vadot  # Vendor-specific properties have slightly different schema requirements than
139c66ec88fSEmmanuel Vadot  # common properties. They must have at least a type definition and
140c66ec88fSEmmanuel Vadot  # 'description'.
141c66ec88fSEmmanuel Vadot  vendor,int-property:
1428cc087a1SEmmanuel Vadot    description: Vendor-specific properties must have a description
143c66ec88fSEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32
144c66ec88fSEmmanuel Vadot    enum: [2, 4, 6, 8, 10]
145c66ec88fSEmmanuel Vadot
146c66ec88fSEmmanuel Vadot  vendor,bool-property:
1478cc087a1SEmmanuel Vadot    description: Vendor-specific properties must have a description. Boolean
148c66ec88fSEmmanuel Vadot      properties are one case where the json-schema 'type' keyword can be used
149c66ec88fSEmmanuel Vadot      directly.
150c66ec88fSEmmanuel Vadot    type: boolean
151c66ec88fSEmmanuel Vadot
152c66ec88fSEmmanuel Vadot  vendor,string-array-property:
1538cc087a1SEmmanuel Vadot    description: Vendor-specific properties should reference a type in the
154c66ec88fSEmmanuel Vadot      core schema.
155c66ec88fSEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/string-array
156c66ec88fSEmmanuel Vadot    items:
157c66ec88fSEmmanuel Vadot      - enum: [foo, bar]
158c66ec88fSEmmanuel Vadot      - enum: [baz, boo]
159c66ec88fSEmmanuel Vadot
160c66ec88fSEmmanuel Vadot  vendor,property-in-standard-units-microvolt:
1618cc087a1SEmmanuel Vadot    description: Vendor-specific properties having a standard unit suffix
162c66ec88fSEmmanuel Vadot      don't need a type.
163c66ec88fSEmmanuel Vadot    enum: [ 100, 200, 300 ]
164c66ec88fSEmmanuel Vadot
165c9ccf3a3SEmmanuel Vadot  vendor,int-array-variable-length-and-constrained-values:
166c9ccf3a3SEmmanuel Vadot    description: Array might define what type of elements might be used (e.g.
167c9ccf3a3SEmmanuel Vadot      their range).
168c9ccf3a3SEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32-array
169c9ccf3a3SEmmanuel Vadot    minItems: 2
170c9ccf3a3SEmmanuel Vadot    maxItems: 3
171c9ccf3a3SEmmanuel Vadot    items:
172c9ccf3a3SEmmanuel Vadot      minimum: 0
173c9ccf3a3SEmmanuel Vadot      maximum: 8
174c9ccf3a3SEmmanuel Vadot
175c66ec88fSEmmanuel Vadot  child-node:
176c66ec88fSEmmanuel Vadot    description: Child nodes are just another property from a json-schema
177c66ec88fSEmmanuel Vadot      perspective.
178c66ec88fSEmmanuel Vadot    type: object  # DT nodes are json objects
179c66ec88fSEmmanuel Vadot    properties:
180c66ec88fSEmmanuel Vadot      vendor,a-child-node-property:
181c66ec88fSEmmanuel Vadot        description: Child node properties have all the same schema
182c66ec88fSEmmanuel Vadot          requirements.
183c66ec88fSEmmanuel Vadot        type: boolean
184c66ec88fSEmmanuel Vadot
185c66ec88fSEmmanuel Vadot    required:
186c66ec88fSEmmanuel Vadot      - vendor,a-child-node-property
187c66ec88fSEmmanuel Vadot
188c66ec88fSEmmanuel Vadot# Describe the relationship between different properties
189c66ec88fSEmmanuel Vadotdependencies:
190c66ec88fSEmmanuel Vadot  # 'vendor,bool-property' is only allowed when 'vendor,string-array-property'
191c66ec88fSEmmanuel Vadot  # is present
192c66ec88fSEmmanuel Vadot  vendor,bool-property: [ 'vendor,string-array-property' ]
193c66ec88fSEmmanuel Vadot  # Expressing 2 properties in both orders means all of the set of properties
194c66ec88fSEmmanuel Vadot  # must be present or none of them.
195c66ec88fSEmmanuel Vadot  vendor,string-array-property: [ 'vendor,bool-property' ]
196c66ec88fSEmmanuel Vadot
197c66ec88fSEmmanuel Vadotrequired:
198c66ec88fSEmmanuel Vadot  - compatible
199c66ec88fSEmmanuel Vadot  - reg
200c66ec88fSEmmanuel Vadot  - interrupts
201c66ec88fSEmmanuel Vadot  - interrupt-controller
202c66ec88fSEmmanuel Vadot
203c66ec88fSEmmanuel Vadot# if/then schema can be used to handle conditions on a property affecting
204c66ec88fSEmmanuel Vadot# another property. A typical case is a specific 'compatible' value changes the
205c66ec88fSEmmanuel Vadot# constraints on other properties.
206c66ec88fSEmmanuel Vadot#
207c66ec88fSEmmanuel Vadot# For multiple 'if' schema, group them under an 'allOf'.
208c66ec88fSEmmanuel Vadot#
209c66ec88fSEmmanuel Vadot# If the conditionals become too unweldy, then it may be better to just split
210c66ec88fSEmmanuel Vadot# the binding into separate schema documents.
2116be33864SEmmanuel VadotallOf:
2126be33864SEmmanuel Vadot  - if:
213c66ec88fSEmmanuel Vadot      properties:
214c66ec88fSEmmanuel Vadot        compatible:
215c66ec88fSEmmanuel Vadot          contains:
216c66ec88fSEmmanuel Vadot            const: vendor,soc2-ip
217c66ec88fSEmmanuel Vadot    then:
218c66ec88fSEmmanuel Vadot      required:
219c66ec88fSEmmanuel Vadot        - foo-supply
220c9ccf3a3SEmmanuel Vadot    else:
221c9ccf3a3SEmmanuel Vadot      # If otherwise the property is not allowed:
222c9ccf3a3SEmmanuel Vadot      properties:
223c9ccf3a3SEmmanuel Vadot        foo-supply: false
2246be33864SEmmanuel Vadot  # Altering schema depending on presence of properties is usually done by
2256be33864SEmmanuel Vadot  # dependencies (see above), however some adjustments might require if:
2266be33864SEmmanuel Vadot  - if:
2276be33864SEmmanuel Vadot      required:
2286be33864SEmmanuel Vadot        - vendor,bool-property
2296be33864SEmmanuel Vadot    then:
2306be33864SEmmanuel Vadot      properties:
2316be33864SEmmanuel Vadot        vendor,int-property:
2326be33864SEmmanuel Vadot          enum: [2, 4, 6]
233c66ec88fSEmmanuel Vadot
234c66ec88fSEmmanuel Vadot# Ideally, the schema should have this line otherwise any other properties
235c66ec88fSEmmanuel Vadot# present are allowed. There's a few common properties such as 'status' and
236c66ec88fSEmmanuel Vadot# 'pinctrl-*' which are added automatically by the tooling.
237c66ec88fSEmmanuel Vadot#
238c66ec88fSEmmanuel Vadot# This can't be used in cases where another schema is referenced
239c66ec88fSEmmanuel Vadot# (i.e. allOf: [{$ref: ...}]).
2406be33864SEmmanuel Vadot# If and only if another schema is referenced and arbitrary children nodes can
2416be33864SEmmanuel Vadot# appear, "unevaluatedProperties: false" could be used.  A typical example is
2426be33864SEmmanuel Vadot# an I2C controller where no name pattern matching for children can be added.
243c66ec88fSEmmanuel VadotadditionalProperties: false
244c66ec88fSEmmanuel Vadot
245c66ec88fSEmmanuel Vadotexamples:
246c66ec88fSEmmanuel Vadot  # Examples are now compiled with dtc and validated against the schemas
247c66ec88fSEmmanuel Vadot  #
248c66ec88fSEmmanuel Vadot  # Examples have a default #address-cells and #size-cells value of 1. This can
249c66ec88fSEmmanuel Vadot  # be overridden or an appropriate parent bus node should be shown (such as on
250c66ec88fSEmmanuel Vadot  # i2c buses).
251c66ec88fSEmmanuel Vadot  #
252*d5b0e70fSEmmanuel Vadot  # Any includes used have to be explicitly included. Use 4-space indentation.
253c66ec88fSEmmanuel Vadot  - |
254c66ec88fSEmmanuel Vadot    node@1000 {
255c66ec88fSEmmanuel Vadot        compatible = "vendor,soc4-ip", "vendor,soc1-ip";
256c66ec88fSEmmanuel Vadot        reg = <0x1000 0x80>,
257c66ec88fSEmmanuel Vadot              <0x3000 0x80>;
258c66ec88fSEmmanuel Vadot        reg-names = "core", "aux";
259c66ec88fSEmmanuel Vadot        interrupts = <10>;
260c66ec88fSEmmanuel Vadot        interrupt-controller;
261c66ec88fSEmmanuel Vadot    };
262