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