Path: blob/master/Documentation/devicetree/bindings/example-schema.yaml
26301 views
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)1# Copyright 2018 Linaro Ltd.2%YAML 1.23---4# All the top-level keys are standard json-schema keywords except for5# 'maintainers' and 'select'67# $id is a unique identifier based on the filename. There may or may not be a8# file present at the URL.9$id: http://devicetree.org/schemas/example-schema.yaml#10# $schema is the meta-schema this schema should be validated with.11$schema: http://devicetree.org/meta-schemas/core.yaml#1213title: An Example Device1415maintainers:16- Rob Herring <robh@kernel.org>1718description: |19A more detailed multi-line description of the binding.2021Details about the hardware device and any links to datasheets can go here.2223Literal blocks are marked with the '|' at the beginning. The end is marked by24indentation less than the first line of the literal block. Lines also cannot25begin with a tab character.2627select: false28# 'select' is a schema applied to a DT node to determine if this binding29# schema should be applied to the node. It is optional and by default the30# possible compatible strings are extracted and used to match.3132# In this case, a 'false' schema will never match.3334properties:35# A dictionary of DT properties for this binding schema36compatible:37# More complicated schema can use oneOf (XOR), anyOf (OR), or allOf (AND)38# to handle different conditions.39# In this case, it's needed to handle a variable number of values as there40# isn't another way to express a constraint of the last string value.41# The boolean schema must be a list of schemas.42oneOf:43- items:44# items is a list of possible values for the property. The number of45# values is determined by the number of elements in the list.46# Order in lists is significant, order in dicts is not47# Must be one of the 1st enums followed by the 2nd enum48#49# Each element in items should be 'enum' or 'const'50- enum:51- vendor,soc4-ip52- vendor,soc3-ip53- vendor,soc2-ip54- const: vendor,soc1-ip55# additionalItems being false is implied56# minItems/maxItems equal to 2 is implied57- items:58# 'const' is just a special case of an enum with a single possible value59- const: vendor,soc1-ip6061reg:62# The core schema already checks that reg values are numbers, so device63# specific schema don't need to do those checks.64# The description of each element defines the order and implicitly defines65# the number of reg entries.66items:67- description: core registers68- description: aux registers69# minItems/maxItems equal to 2 is implied7071reg-names:72# The core schema enforces this (*-names) is a string array73items:74- const: core75- const: aux7677clocks:78# Cases that have only a single entry just need to express that with maxItems79maxItems: 180description: bus clock. A description is only needed for a single item if81there's something unique to add.82The items should have a fixed order, so pattern matching names are83discouraged.8485clock-names:86# For single-entry lists in clocks, resets etc., the xxx-names often do not87# bring any value, especially if they copy the IP block name. In such case88# just skip the xxx-names.89items:90- const: bus9192interrupts:93# Either 1 or 2 interrupts can be present94minItems: 195items:96- description: tx or combined interrupt97- description: rx interrupt98description:99A variable number of interrupts warrants a description of what conditions100affect the number of interrupts. Otherwise, descriptions on standard101properties are not necessary.102The items should have a fixed order, so pattern matching names are103discouraged.104105interrupt-names:106# minItems must be specified here because the default would be 2107minItems: 1108items:109- const: tx irq110- const: rx irq111112# Property names starting with '#' must be quoted113'#interrupt-cells':114# A simple case where the value must always be '2'.115# The core schema handles that this must be a single integer.116const: 2117118interrupt-controller: true119# The core checks this is a boolean, so just have to list it here to be120# valid for this binding.121122clock-frequency:123# The type is set in the core schema. Per-device schema only need to set124# constraints on the possible values.125minimum: 100126maximum: 400000127# The value that should be used if the property is not present128default: 200129130foo-gpios:131maxItems: 1132description: A connection of the 'foo' gpio line.133134# *-supply is always a single phandle, so nothing more to define.135foo-supply: true136137# Vendor-specific properties138#139# Vendor-specific properties have slightly different schema requirements than140# common properties. They must have at least a type definition and141# 'description'.142vendor,int-property:143description: Vendor-specific properties must have a description144$ref: /schemas/types.yaml#/definitions/uint32145enum: [2, 4, 6, 8, 10]146147vendor,bool-property:148description: Vendor-specific properties must have a description. Boolean149properties are one case where the json-schema 'type' keyword can be used150directly.151type: boolean152153vendor,string-array-property:154description: Vendor-specific properties should reference a type in the155core schema.156$ref: /schemas/types.yaml#/definitions/string-array157items:158- enum: [foo, bar]159- enum: [baz, boo]160161vendor,property-in-standard-units-microvolt:162description: Vendor-specific properties having a standard unit suffix163don't need a type.164enum: [ 100, 200, 300 ]165166vendor,int-array-variable-length-and-constrained-values:167description: Array might define what type of elements might be used (e.g.168their range).169$ref: /schemas/types.yaml#/definitions/uint32-array170minItems: 2171maxItems: 3172items:173minimum: 0174maximum: 8175176child-node:177description: Child nodes are just another property from a json-schema178perspective.179type: object # DT nodes are json objects180# Child nodes also need additionalProperties or unevaluatedProperties, where181# 'false' should be used in most cases (see 'child-node-with-own-schema'182# below).183additionalProperties: false184properties:185vendor,a-child-node-property:186description: Child node properties have all the same schema187requirements.188type: boolean189190required:191- vendor,a-child-node-property192193child-node-with-own-schema:194description: |195Child node with their own compatible and device schema which ends in196'additionalProperties: false' or 'unevaluatedProperties: false' can197mention only the compatible and use here 'additionalProperties: true'.198type: object199additionalProperties: true200properties:201compatible:202const: vendor,sub-device203204# Describe the relationship between different properties205dependencies:206# 'vendor,bool-property' is only allowed when 'vendor,string-array-property'207# is present208vendor,bool-property: [ 'vendor,string-array-property' ]209# Expressing 2 properties in both orders means all of the set of properties210# must be present or none of them.211vendor,string-array-property: [ 'vendor,bool-property' ]212213required:214- compatible215- reg216- interrupts217- interrupt-controller218219# if/then schema can be used to handle conditions on a property affecting220# another property. A typical case is a specific 'compatible' value changes the221# constraints on other properties.222#223# For multiple 'if' schema, group them under an 'allOf'.224#225# If the conditionals become too unweldy, then it may be better to just split226# the binding into separate schema documents.227allOf:228- if:229properties:230compatible:231contains:232const: vendor,soc2-ip233then:234required:235- foo-supply236else:237# If otherwise the property is not allowed:238properties:239foo-supply: false240# Altering schema depending on presence of properties is usually done by241# dependencies (see above), however some adjustments might require if:242- if:243required:244- vendor,bool-property245then:246properties:247vendor,int-property:248enum: [2, 4, 6]249250# Ideally, the schema should have this line otherwise any other properties251# present are allowed. There's a few common properties such as 'status' and252# 'pinctrl-*' which are added automatically by the tooling.253#254# This can't be used in cases where another schema is referenced255# (i.e. allOf: [{$ref: ...}]).256# If and only if another schema is referenced and arbitrary children nodes can257# appear, "unevaluatedProperties: false" could be used. A typical example is258# an I2C controller where no name pattern matching for children can be added.259additionalProperties: false260261examples:262# Examples are now compiled with dtc and validated against the schemas263#264# Examples have a default #address-cells and #size-cells value of 1. This can265# be overridden or an appropriate parent bus node should be shown (such as on266# i2c buses).267#268# Any includes used have to be explicitly included. Use 4-space indentation.269- |270node@1000 {271compatible = "vendor,soc4-ip", "vendor,soc1-ip";272reg = <0x1000 0x80>,273<0x3000 0x80>;274reg-names = "core", "aux";275interrupts = <10>;276interrupt-controller;277#interrupt-cells = <2>;278};279280281