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