158fbe999SRob Herring# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 200ce8a80SRob Herring# Copyright 2018 Linaro Ltd. 300ce8a80SRob Herring%YAML 1.2 400ce8a80SRob Herring--- 500ce8a80SRob Herring# All the top-level keys are standard json-schema keywords except for 600ce8a80SRob Herring# 'maintainers' and 'select' 700ce8a80SRob Herring 843c63c15SSimon Horman# $id is a unique identifier based on the filename. There may or may not be a 900ce8a80SRob Herring# file present at the URL. 10238415f7SGeert Uytterhoeven$id: http://devicetree.org/schemas/example-schema.yaml# 1100ce8a80SRob Herring# $schema is the meta-schema this schema should be validated with. 12238415f7SGeert Uytterhoeven$schema: http://devicetree.org/meta-schemas/core.yaml# 1300ce8a80SRob Herring 143367934dSKrzysztof Kozlowskititle: An Example Device 1500ce8a80SRob Herring 1600ce8a80SRob Herringmaintainers: 1700ce8a80SRob Herring - Rob Herring <robh@kernel.org> 1800ce8a80SRob Herring 1900ce8a80SRob Herringdescription: | 2000ce8a80SRob Herring A more detailed multi-line description of the binding. 2100ce8a80SRob Herring 2200ce8a80SRob Herring Details about the hardware device and any links to datasheets can go here. 2300ce8a80SRob Herring 2400ce8a80SRob Herring Literal blocks are marked with the '|' at the beginning. The end is marked by 2500ce8a80SRob Herring indentation less than the first line of the literal block. Lines also cannot 2600ce8a80SRob Herring begin with a tab character. 2700ce8a80SRob Herring 2800ce8a80SRob Herringselect: false 2900ce8a80SRob Herring # 'select' is a schema applied to a DT node to determine if this binding 3000ce8a80SRob Herring # schema should be applied to the node. It is optional and by default the 3100ce8a80SRob Herring # possible compatible strings are extracted and used to match. 3200ce8a80SRob Herring 3300ce8a80SRob Herring # In this case, a 'false' schema will never match. 3400ce8a80SRob Herring 3500ce8a80SRob Herringproperties: 3600ce8a80SRob Herring # A dictionary of DT properties for this binding schema 3700ce8a80SRob Herring compatible: 3800ce8a80SRob Herring # More complicated schema can use oneOf (XOR), anyOf (OR), or allOf (AND) 3900ce8a80SRob Herring # to handle different conditions. 4000ce8a80SRob Herring # In this case, it's needed to handle a variable number of values as there 4100ce8a80SRob Herring # isn't another way to express a constraint of the last string value. 4200ce8a80SRob Herring # The boolean schema must be a list of schemas. 4300ce8a80SRob Herring oneOf: 4400ce8a80SRob Herring - items: 4500ce8a80SRob Herring # items is a list of possible values for the property. The number of 4600ce8a80SRob Herring # values is determined by the number of elements in the list. 4700ce8a80SRob Herring # Order in lists is significant, order in dicts is not 4800ce8a80SRob Herring # Must be one of the 1st enums followed by the 2nd enum 4900ce8a80SRob Herring # 5000ce8a80SRob Herring # Each element in items should be 'enum' or 'const' 5100ce8a80SRob Herring - enum: 5200ce8a80SRob Herring - vendor,soc4-ip 5300ce8a80SRob Herring - vendor,soc3-ip 5400ce8a80SRob Herring - vendor,soc2-ip 5500ce8a80SRob Herring - const: vendor,soc1-ip 5600ce8a80SRob Herring # additionalItems being false is implied 5700ce8a80SRob Herring # minItems/maxItems equal to 2 is implied 5800ce8a80SRob Herring - items: 5900ce8a80SRob Herring # 'const' is just a special case of an enum with a single possible value 6000ce8a80SRob Herring - const: vendor,soc1-ip 6100ce8a80SRob Herring 6200ce8a80SRob Herring reg: 6300ce8a80SRob Herring # The core schema already checks that reg values are numbers, so device 6400ce8a80SRob Herring # specific schema don't need to do those checks. 6500ce8a80SRob Herring # The description of each element defines the order and implicitly defines 6600ce8a80SRob Herring # the number of reg entries. 6700ce8a80SRob Herring items: 6800ce8a80SRob Herring - description: core registers 6900ce8a80SRob Herring - description: aux registers 7000ce8a80SRob Herring # minItems/maxItems equal to 2 is implied 7100ce8a80SRob Herring 7200ce8a80SRob Herring reg-names: 7300ce8a80SRob Herring # The core schema enforces this (*-names) is a string array 7458fbe999SRob Herring items: 7500ce8a80SRob Herring - const: core 7600ce8a80SRob Herring - const: aux 7700ce8a80SRob Herring 7800ce8a80SRob Herring clocks: 7900ce8a80SRob Herring # Cases that have only a single entry just need to express that with maxItems 8000ce8a80SRob Herring maxItems: 1 8100ce8a80SRob Herring description: bus clock. A description is only needed for a single item if 8258fbe999SRob Herring there's something unique to add. 8358fbe999SRob Herring The items should have a fixed order, so pattern matching names are 84873462adSGeert Uytterhoeven discouraged. 8573f76a41SKrzysztof Kozlowski 8600ce8a80SRob Herring clock-names: 8700ce8a80SRob Herring # For single-entry lists in clocks, resets etc., the xxx-names often do not 8800ce8a80SRob Herring # bring any value, especially if they copy the IP block name. In such case 8900ce8a80SRob Herring # just skip the xxx-names. 9000ce8a80SRob Herring items: 9100ce8a80SRob Herring - const: bus 9200ce8a80SRob Herring 9300ce8a80SRob Herring interrupts: 9400ce8a80SRob Herring # Either 1 or 2 interrupts can be present 9500ce8a80SRob Herring minItems: 1 9600ce8a80SRob Herring items: 9700ce8a80SRob Herring - description: tx or combined interrupt 9800ce8a80SRob Herring - description: rx interrupt 9900ce8a80SRob Herring description: 10000ce8a80SRob Herring A variable number of interrupts warrants a description of what conditions 101873462adSGeert Uytterhoeven affect the number of interrupts. Otherwise, descriptions on standard 10273f76a41SKrzysztof Kozlowski properties are not necessary. 10300ce8a80SRob Herring The items should have a fixed order, so pattern matching names are 10400ce8a80SRob Herring discouraged. 10500ce8a80SRob Herring 10600ce8a80SRob Herring interrupt-names: 10700ce8a80SRob Herring # minItems must be specified here because the default would be 2 10800ce8a80SRob Herring minItems: 1 10900ce8a80SRob Herring items: 11000ce8a80SRob Herring - const: tx irq 11100ce8a80SRob Herring - const: rx irq 11200ce8a80SRob Herring 11300ce8a80SRob Herring # Property names starting with '#' must be quoted 11400ce8a80SRob Herring '#interrupt-cells': 11500ce8a80SRob Herring # A simple case where the value must always be '2'. 11600ce8a80SRob Herring # The core schema handles that this must be a single integer. 11700ce8a80SRob Herring const: 2 11800ce8a80SRob Herring 11900ce8a80SRob Herring interrupt-controller: true 12000ce8a80SRob Herring # The core checks this is a boolean, so just have to list it here to be 12100ce8a80SRob Herring # valid for this binding. 12237ef2c34SSimon Glass 12300ce8a80SRob Herring clock-frequency: 12400ce8a80SRob Herring # The type is set in the core schema. Per-device schema only need to set 12500ce8a80SRob Herring # constraints on the possible values. 12600ce8a80SRob Herring minimum: 100 12700ce8a80SRob Herring maximum: 400000 12800ce8a80SRob Herring # The value that should be used if the property is not present 12900ce8a80SRob Herring default: 200 13000ce8a80SRob Herring 13100ce8a80SRob Herring foo-gpios: 13200ce8a80SRob Herring maxItems: 1 13358fbe999SRob Herring description: A connection of the 'foo' gpio line. 13458fbe999SRob Herring 13558fbe999SRob Herring # *-supply is always a single phandle, so nothing more to define. 13637ef2c34SSimon Glass foo-supply: true 13758fbe999SRob Herring 13837ef2c34SSimon Glass # Vendor-specific properties 13958fbe999SRob Herring # 14058fbe999SRob Herring # Vendor-specific properties have slightly different schema requirements than 14100ce8a80SRob Herring # common properties. They must have at least a type definition and 14237ef2c34SSimon Glass # 'description'. 1433d21a460SRob Herring vendor,int-property: 1443d21a460SRob Herring description: Vendor-specific properties must have a description 14500ce8a80SRob Herring $ref: /schemas/types.yaml#/definitions/uint32 14600ce8a80SRob Herring enum: [2, 4, 6, 8, 10] 14737ef2c34SSimon Glass 14858fbe999SRob Herring vendor,bool-property: 14958fbe999SRob Herring description: Vendor-specific properties must have a description. Boolean 15000ce8a80SRob Herring properties are one case where the json-schema 'type' keyword can be used 15100ce8a80SRob Herring directly. 15200ce8a80SRob Herring type: boolean 15337ef2c34SSimon Glass 15400ce8a80SRob Herring vendor,string-array-property: 1553d21a460SRob Herring description: Vendor-specific properties should reference a type in the 1563d21a460SRob Herring core schema. 15700ce8a80SRob Herring $ref: /schemas/types.yaml#/definitions/string-array 15800ce8a80SRob Herring items: 15900ce8a80SRob Herring - enum: [foo, bar] 1602fa0a530SRob Herring - enum: [baz, boo] 16137ef2c34SSimon Glass 16258fbe999SRob Herring vendor,property-in-standard-units-microvolt: 16358fbe999SRob Herring description: Vendor-specific properties having a standard unit suffix 16458fbe999SRob Herring don't need a type. 165418adabeSKrzysztof Kozlowski enum: [ 100, 200, 300 ] 166418adabeSKrzysztof Kozlowski 167418adabeSKrzysztof Kozlowski vendor,int-array-variable-length-and-constrained-values: 168418adabeSKrzysztof Kozlowski description: Array might define what type of elements might be used (e.g. 169418adabeSKrzysztof Kozlowski their range). 170418adabeSKrzysztof Kozlowski $ref: /schemas/types.yaml#/definitions/uint32-array 171418adabeSKrzysztof Kozlowski minItems: 2 172418adabeSKrzysztof Kozlowski maxItems: 3 173418adabeSKrzysztof Kozlowski items: 174418adabeSKrzysztof Kozlowski minimum: 0 17558fbe999SRob Herring maximum: 8 17658fbe999SRob Herring 17758fbe999SRob Herring child-node: 17858fbe999SRob Herring description: Child nodes are just another property from a json-schema 179*e62fc182SRob Herring perspective. 180*e62fc182SRob Herring type: object # DT nodes are json objects 18158fbe999SRob Herring # Child nodes also need additionalProperties or unevaluatedProperties 18258fbe999SRob Herring additionalProperties: false 18358fbe999SRob Herring properties: 18458fbe999SRob Herring vendor,a-child-node-property: 18558fbe999SRob Herring description: Child node properties have all the same schema 18658fbe999SRob Herring requirements. 18758fbe999SRob Herring type: boolean 18858fbe999SRob Herring 18958fbe999SRob Herring required: 19058fbe999SRob Herring - vendor,a-child-node-property 19158fbe999SRob Herring 19258fbe999SRob Herring# Describe the relationship between different properties 19358fbe999SRob Herringdependencies: 194f516fb70SRob Herring # 'vendor,bool-property' is only allowed when 'vendor,string-array-property' 19558fbe999SRob Herring # is present 19658fbe999SRob Herring vendor,bool-property: [ 'vendor,string-array-property' ] 197f516fb70SRob Herring # Expressing 2 properties in both orders means all of the set of properties 19858fbe999SRob Herring # must be present or none of them. 19900ce8a80SRob Herring vendor,string-array-property: [ 'vendor,bool-property' ] 20000ce8a80SRob Herring 20100ce8a80SRob Herringrequired: 20200ce8a80SRob Herring - compatible 20300ce8a80SRob Herring - reg 20400ce8a80SRob Herring - interrupts 20558fbe999SRob Herring - interrupt-controller 20658fbe999SRob Herring 20758fbe999SRob Herring# if/then schema can be used to handle conditions on a property affecting 20858fbe999SRob Herring# another property. A typical case is a specific 'compatible' value changes the 20958fbe999SRob Herring# constraints on other properties. 21058fbe999SRob Herring# 21158fbe999SRob Herring# For multiple 'if' schema, group them under an 'allOf'. 21258fbe999SRob Herring# 21373f76a41SKrzysztof Kozlowski# If the conditionals become too unweldy, then it may be better to just split 21473f76a41SKrzysztof Kozlowski# the binding into separate schema documents. 21558fbe999SRob HerringallOf: 21658fbe999SRob Herring - if: 21758fbe999SRob Herring properties: 21858fbe999SRob Herring compatible: 21958fbe999SRob Herring contains: 22058fbe999SRob Herring const: vendor,soc2-ip 22158fbe999SRob Herring then: 222418adabeSKrzysztof Kozlowski required: 223418adabeSKrzysztof Kozlowski - foo-supply 224418adabeSKrzysztof Kozlowski else: 225418adabeSKrzysztof Kozlowski # If otherwise the property is not allowed: 22673f76a41SKrzysztof Kozlowski properties: 22773f76a41SKrzysztof Kozlowski foo-supply: false 22873f76a41SKrzysztof Kozlowski # Altering schema depending on presence of properties is usually done by 22973f76a41SKrzysztof Kozlowski # dependencies (see above), however some adjustments might require if: 23073f76a41SKrzysztof Kozlowski - if: 23173f76a41SKrzysztof Kozlowski required: 23273f76a41SKrzysztof Kozlowski - vendor,bool-property 23373f76a41SKrzysztof Kozlowski then: 23473f76a41SKrzysztof Kozlowski properties: 23558fbe999SRob Herring vendor,int-property: 23658fbe999SRob Herring enum: [2, 4, 6] 23758fbe999SRob Herring 23858fbe999SRob Herring# Ideally, the schema should have this line otherwise any other properties 23958fbe999SRob Herring# present are allowed. There's a few common properties such as 'status' and 24058fbe999SRob Herring# 'pinctrl-*' which are added automatically by the tooling. 24158fbe999SRob Herring# 24273f76a41SKrzysztof Kozlowski# This can't be used in cases where another schema is referenced 243873462adSGeert Uytterhoeven# (i.e. allOf: [{$ref: ...}]). 244873462adSGeert Uytterhoeven# If and only if another schema is referenced and arbitrary children nodes can 24558fbe999SRob Herring# appear, "unevaluatedProperties: false" could be used. A typical example is 24658fbe999SRob Herring# an I2C controller where no name pattern matching for children can be added. 24700ce8a80SRob HerringadditionalProperties: false 24858fbe999SRob Herring 24958fbe999SRob Herringexamples: 25058fbe999SRob Herring # Examples are now compiled with dtc and validated against the schemas 25158fbe999SRob Herring # 25258fbe999SRob Herring # Examples have a default #address-cells and #size-cells value of 1. This can 25358fbe999SRob Herring # be overridden or an appropriate parent bus node should be shown (such as on 2547a150b0dSKrzysztof Kozlowski # i2c buses). 25500ce8a80SRob Herring # 25600ce8a80SRob Herring # Any includes used have to be explicitly included. Use 4-space indentation. 25700ce8a80SRob Herring - | 25800ce8a80SRob Herring node@1000 { 25900ce8a80SRob Herring compatible = "vendor,soc4-ip", "vendor,soc1-ip"; 26000ce8a80SRob Herring reg = <0x1000 0x80>, 26100ce8a80SRob Herring <0x3000 0x80>; 26200ce8a80SRob Herring reg-names = "core", "aux"; 26300ce8a80SRob Herring interrupts = <10>; 264 interrupt-controller; 265 }; 266