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. 84*6be33864SEmmanuel Vadot The items should have a fixed order, so pattern matching names are 85*6be33864SEmmanuel 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 maxItems: 2 95c66ec88fSEmmanuel Vadot items: 96c66ec88fSEmmanuel Vadot - description: tx or combined interrupt 97c66ec88fSEmmanuel Vadot - description: rx interrupt 98c66ec88fSEmmanuel Vadot description: 99c66ec88fSEmmanuel Vadot A variable number of interrupts warrants a description of what conditions 100c66ec88fSEmmanuel Vadot affect the number of interrupts. Otherwise, descriptions on standard 101c66ec88fSEmmanuel Vadot properties are not necessary. 102*6be33864SEmmanuel Vadot The items should have a fixed order, so pattern matching names are 103*6be33864SEmmanuel Vadot discouraged. 104c66ec88fSEmmanuel Vadot 105c66ec88fSEmmanuel Vadot interrupt-names: 106c66ec88fSEmmanuel Vadot # minItems must be specified here because the default would be 2 107c66ec88fSEmmanuel Vadot minItems: 1 108c66ec88fSEmmanuel Vadot maxItems: 2 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: 124c66ec88fSEmmanuel 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 138c66ec88fSEmmanuel Vadot # Vendor specific properties 139c66ec88fSEmmanuel Vadot # 140c66ec88fSEmmanuel 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: 144c66ec88fSEmmanuel 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: 149c66ec88fSEmmanuel 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: 155c66ec88fSEmmanuel 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: 163c66ec88fSEmmanuel 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 167c66ec88fSEmmanuel Vadot child-node: 168c66ec88fSEmmanuel Vadot description: Child nodes are just another property from a json-schema 169c66ec88fSEmmanuel Vadot perspective. 170c66ec88fSEmmanuel Vadot type: object # DT nodes are json objects 171c66ec88fSEmmanuel Vadot properties: 172c66ec88fSEmmanuel Vadot vendor,a-child-node-property: 173c66ec88fSEmmanuel Vadot description: Child node properties have all the same schema 174c66ec88fSEmmanuel Vadot requirements. 175c66ec88fSEmmanuel Vadot type: boolean 176c66ec88fSEmmanuel Vadot 177c66ec88fSEmmanuel Vadot required: 178c66ec88fSEmmanuel Vadot - vendor,a-child-node-property 179c66ec88fSEmmanuel Vadot 180c66ec88fSEmmanuel Vadot# Describe the relationship between different properties 181c66ec88fSEmmanuel Vadotdependencies: 182c66ec88fSEmmanuel Vadot # 'vendor,bool-property' is only allowed when 'vendor,string-array-property' 183c66ec88fSEmmanuel Vadot # is present 184c66ec88fSEmmanuel Vadot vendor,bool-property: [ 'vendor,string-array-property' ] 185c66ec88fSEmmanuel Vadot # Expressing 2 properties in both orders means all of the set of properties 186c66ec88fSEmmanuel Vadot # must be present or none of them. 187c66ec88fSEmmanuel Vadot vendor,string-array-property: [ 'vendor,bool-property' ] 188c66ec88fSEmmanuel Vadot 189c66ec88fSEmmanuel Vadotrequired: 190c66ec88fSEmmanuel Vadot - compatible 191c66ec88fSEmmanuel Vadot - reg 192c66ec88fSEmmanuel Vadot - interrupts 193c66ec88fSEmmanuel Vadot - interrupt-controller 194c66ec88fSEmmanuel Vadot 195c66ec88fSEmmanuel Vadot# if/then schema can be used to handle conditions on a property affecting 196c66ec88fSEmmanuel Vadot# another property. A typical case is a specific 'compatible' value changes the 197c66ec88fSEmmanuel Vadot# constraints on other properties. 198c66ec88fSEmmanuel Vadot# 199c66ec88fSEmmanuel Vadot# For multiple 'if' schema, group them under an 'allOf'. 200c66ec88fSEmmanuel Vadot# 201c66ec88fSEmmanuel Vadot# If the conditionals become too unweldy, then it may be better to just split 202c66ec88fSEmmanuel Vadot# the binding into separate schema documents. 203*6be33864SEmmanuel VadotallOf: 204*6be33864SEmmanuel Vadot - if: 205c66ec88fSEmmanuel Vadot properties: 206c66ec88fSEmmanuel Vadot compatible: 207c66ec88fSEmmanuel Vadot contains: 208c66ec88fSEmmanuel Vadot const: vendor,soc2-ip 209c66ec88fSEmmanuel Vadot then: 210c66ec88fSEmmanuel Vadot required: 211c66ec88fSEmmanuel Vadot - foo-supply 212*6be33864SEmmanuel Vadot # Altering schema depending on presence of properties is usually done by 213*6be33864SEmmanuel Vadot # dependencies (see above), however some adjustments might require if: 214*6be33864SEmmanuel Vadot - if: 215*6be33864SEmmanuel Vadot required: 216*6be33864SEmmanuel Vadot - vendor,bool-property 217*6be33864SEmmanuel Vadot then: 218*6be33864SEmmanuel Vadot properties: 219*6be33864SEmmanuel Vadot vendor,int-property: 220*6be33864SEmmanuel Vadot enum: [2, 4, 6] 221c66ec88fSEmmanuel Vadot 222c66ec88fSEmmanuel Vadot# Ideally, the schema should have this line otherwise any other properties 223c66ec88fSEmmanuel Vadot# present are allowed. There's a few common properties such as 'status' and 224c66ec88fSEmmanuel Vadot# 'pinctrl-*' which are added automatically by the tooling. 225c66ec88fSEmmanuel Vadot# 226c66ec88fSEmmanuel Vadot# This can't be used in cases where another schema is referenced 227c66ec88fSEmmanuel Vadot# (i.e. allOf: [{$ref: ...}]). 228*6be33864SEmmanuel Vadot# If and only if another schema is referenced and arbitrary children nodes can 229*6be33864SEmmanuel Vadot# appear, "unevaluatedProperties: false" could be used. A typical example is 230*6be33864SEmmanuel Vadot# an I2C controller where no name pattern matching for children can be added. 231c66ec88fSEmmanuel VadotadditionalProperties: false 232c66ec88fSEmmanuel Vadot 233c66ec88fSEmmanuel Vadotexamples: 234c66ec88fSEmmanuel Vadot # Examples are now compiled with dtc and validated against the schemas 235c66ec88fSEmmanuel Vadot # 236c66ec88fSEmmanuel Vadot # Examples have a default #address-cells and #size-cells value of 1. This can 237c66ec88fSEmmanuel Vadot # be overridden or an appropriate parent bus node should be shown (such as on 238c66ec88fSEmmanuel Vadot # i2c buses). 239c66ec88fSEmmanuel Vadot # 240c66ec88fSEmmanuel Vadot # Any includes used have to be explicitly included. 241c66ec88fSEmmanuel Vadot - | 242c66ec88fSEmmanuel Vadot node@1000 { 243c66ec88fSEmmanuel Vadot compatible = "vendor,soc4-ip", "vendor,soc1-ip"; 244c66ec88fSEmmanuel Vadot reg = <0x1000 0x80>, 245c66ec88fSEmmanuel Vadot <0x3000 0x80>; 246c66ec88fSEmmanuel Vadot reg-names = "core", "aux"; 247c66ec88fSEmmanuel Vadot interrupts = <10>; 248c66ec88fSEmmanuel Vadot interrupt-controller; 249c66ec88fSEmmanuel Vadot }; 250