10a1b9293SMaxime Ripard# SPDX-License-Identifier: GPL-2.0 20a1b9293SMaxime Ripard%YAML 1.2 30a1b9293SMaxime Ripard--- 40a1b9293SMaxime Ripard$id: http://devicetree.org/schemas/spi/spi-controller.yaml# 50a1b9293SMaxime Ripard$schema: http://devicetree.org/meta-schemas/core.yaml# 60a1b9293SMaxime Ripard 7ab040c42SKrzysztof Kozlowskititle: SPI Controller Common Properties 80a1b9293SMaxime Ripard 90a1b9293SMaxime Ripardmaintainers: 100a1b9293SMaxime Ripard - Mark Brown <broonie@kernel.org> 110a1b9293SMaxime Ripard 120a1b9293SMaxime Riparddescription: | 130a1b9293SMaxime Ripard SPI busses can be described with a node for the SPI controller device 140a1b9293SMaxime Ripard and a set of child nodes for each SPI slave on the bus. The system SPI 150a1b9293SMaxime Ripard controller may be described for use in SPI master mode or in SPI slave mode, 160a1b9293SMaxime Ripard but not for both at the same time. 170a1b9293SMaxime Ripard 180a1b9293SMaxime Ripardproperties: 190a1b9293SMaxime Ripard $nodename: 200a1b9293SMaxime Ripard pattern: "^spi(@.*|-[0-9a-f])*$" 210a1b9293SMaxime Ripard 220a1b9293SMaxime Ripard "#address-cells": 23faaa30ddSZhen Lei enum: [0, 1] 240a1b9293SMaxime Ripard 250a1b9293SMaxime Ripard "#size-cells": 260a1b9293SMaxime Ripard const: 0 270a1b9293SMaxime Ripard 280a1b9293SMaxime Ripard cs-gpios: 290a1b9293SMaxime Ripard description: | 300a1b9293SMaxime Ripard GPIOs used as chip selects. 310a1b9293SMaxime Ripard If that property is used, the number of chip selects will be 320a1b9293SMaxime Ripard increased automatically with max(cs-gpios, hardware chip selects). 330a1b9293SMaxime Ripard 347f01494fSManivannan Sadhasivam So if, for example, the controller has 4 CS lines, and the 350a1b9293SMaxime Ripard cs-gpios looks like this 360a1b9293SMaxime Ripard cs-gpios = <&gpio1 0 0>, <0>, <&gpio1 1 0>, <&gpio1 2 0>; 370a1b9293SMaxime Ripard 380a1b9293SMaxime Ripard Then it should be configured so that num_chipselect = 4, with 390a1b9293SMaxime Ripard the following mapping 400a1b9293SMaxime Ripard cs0 : &gpio1 0 0 410a1b9293SMaxime Ripard cs1 : native 420a1b9293SMaxime Ripard cs2 : &gpio1 1 0 430a1b9293SMaxime Ripard cs3 : &gpio1 2 0 440a1b9293SMaxime Ripard 452fee9583SH. Nikolaus Schaller The second flag of a gpio descriptor can be GPIO_ACTIVE_HIGH (0) 462fee9583SH. Nikolaus Schaller or GPIO_ACTIVE_LOW(1). Legacy device trees often use 0. 472fee9583SH. Nikolaus Schaller 482fee9583SH. Nikolaus Schaller There is a special rule set for combining the second flag of an 492fee9583SH. Nikolaus Schaller cs-gpio with the optional spi-cs-high flag for SPI slaves. 502fee9583SH. Nikolaus Schaller 512fee9583SH. Nikolaus Schaller Each table entry defines how the CS pin is to be physically 522fee9583SH. Nikolaus Schaller driven (not considering potential gpio inversions by pinmux): 532fee9583SH. Nikolaus Schaller 542fee9583SH. Nikolaus Schaller device node | cs-gpio | CS pin state active | Note 552fee9583SH. Nikolaus Schaller ================+===============+=====================+===== 562fee9583SH. Nikolaus Schaller spi-cs-high | - | H | 572fee9583SH. Nikolaus Schaller - | - | L | 582fee9583SH. Nikolaus Schaller spi-cs-high | ACTIVE_HIGH | H | 592fee9583SH. Nikolaus Schaller - | ACTIVE_HIGH | L | 1 602fee9583SH. Nikolaus Schaller spi-cs-high | ACTIVE_LOW | H | 2 612fee9583SH. Nikolaus Schaller - | ACTIVE_LOW | L | 622fee9583SH. Nikolaus Schaller 632fee9583SH. Nikolaus Schaller Notes: 642fee9583SH. Nikolaus Schaller 1) Should print a warning about polarity inversion. 652fee9583SH. Nikolaus Schaller Here it would be wise to avoid and define the gpio as 662fee9583SH. Nikolaus Schaller ACTIVE_LOW. 672fee9583SH. Nikolaus Schaller 2) Should print a warning about polarity inversion 682fee9583SH. Nikolaus Schaller because ACTIVE_LOW is overridden by spi-cs-high. 692fee9583SH. Nikolaus Schaller Should be generally avoided and be replaced by 702fee9583SH. Nikolaus Schaller spi-cs-high + ACTIVE_HIGH. 712fee9583SH. Nikolaus Schaller 720a1b9293SMaxime Ripard num-cs: 730a1b9293SMaxime Ripard $ref: /schemas/types.yaml#/definitions/uint32 740a1b9293SMaxime Ripard description: 750a1b9293SMaxime Ripard Total number of chip selects. 760a1b9293SMaxime Ripard 770a1b9293SMaxime Ripard spi-slave: 780a1b9293SMaxime Ripard $ref: /schemas/types.yaml#/definitions/flag 790a1b9293SMaxime Ripard description: 800a1b9293SMaxime Ripard The SPI controller acts as a slave, instead of a master. 810a1b9293SMaxime Ripard 82f88321a3SRob Herring slave: 830a1b9293SMaxime Ripard type: object 840a1b9293SMaxime Ripard 850a1b9293SMaxime Ripard properties: 860a1b9293SMaxime Ripard compatible: 870a1b9293SMaxime Ripard description: 880a1b9293SMaxime Ripard Compatible of the SPI device. 890a1b9293SMaxime Ripard 900a1b9293SMaxime Ripard required: 910a1b9293SMaxime Ripard - compatible 920a1b9293SMaxime Ripard 93f88321a3SRob HerringpatternProperties: 940a1b9293SMaxime Ripard "^.*@[0-9a-f]+$": 950a1b9293SMaxime Ripard type: object 96dca66935SRob Herring $ref: spi-peripheral-props.yaml 97*e62fc182SRob Herring additionalProperties: true 980a1b9293SMaxime Ripard 99233363abSKrzysztof Kozlowski properties: 10041f53a65SKrzysztof Kozlowski spi-3wire: 10141f53a65SKrzysztof Kozlowski $ref: /schemas/types.yaml#/definitions/flag 10241f53a65SKrzysztof Kozlowski description: 10341f53a65SKrzysztof Kozlowski The device requires 3-wire mode. 10441f53a65SKrzysztof Kozlowski 105233363abSKrzysztof Kozlowski spi-cpha: 106233363abSKrzysztof Kozlowski $ref: /schemas/types.yaml#/definitions/flag 107233363abSKrzysztof Kozlowski description: 108233363abSKrzysztof Kozlowski The device requires shifted clock phase (CPHA) mode. 109233363abSKrzysztof Kozlowski 110233363abSKrzysztof Kozlowski spi-cpol: 111233363abSKrzysztof Kozlowski $ref: /schemas/types.yaml#/definitions/flag 112233363abSKrzysztof Kozlowski description: 113233363abSKrzysztof Kozlowski The device requires inverse clock polarity (CPOL) mode. 114233363abSKrzysztof Kozlowski 1150a1b9293SMaxime Ripard required: 1160a1b9293SMaxime Ripard - compatible 1170a1b9293SMaxime Ripard - reg 1180a1b9293SMaxime Ripard 119f88321a3SRob HerringallOf: 120f88321a3SRob Herring - if: 121f88321a3SRob Herring not: 122f88321a3SRob Herring required: 123f88321a3SRob Herring - spi-slave 124f88321a3SRob Herring then: 125f88321a3SRob Herring properties: 126f88321a3SRob Herring "#address-cells": 127f88321a3SRob Herring const: 1 128f88321a3SRob Herring else: 129f88321a3SRob Herring properties: 130f88321a3SRob Herring "#address-cells": 131f88321a3SRob Herring const: 0 132f88321a3SRob Herring 1336a0e321eSRob HerringadditionalProperties: true 1346a0e321eSRob Herring 1350a1b9293SMaxime Ripardexamples: 1360a1b9293SMaxime Ripard - | 13728ffe8bfSRob Herring spi@80010000 { 1380a1b9293SMaxime Ripard #address-cells = <1>; 1390a1b9293SMaxime Ripard #size-cells = <0>; 14028ffe8bfSRob Herring compatible = "fsl,imx28-spi"; 14128ffe8bfSRob Herring reg = <0x80010000 0x2000>; 14228ffe8bfSRob Herring interrupts = <96>; 14328ffe8bfSRob Herring dmas = <&dma_apbh 0>; 14428ffe8bfSRob Herring dma-names = "rx-tx"; 1450a1b9293SMaxime Ripard 14628ffe8bfSRob Herring display@0 { 14728ffe8bfSRob Herring compatible = "lg,lg4573"; 1480a1b9293SMaxime Ripard spi-max-frequency = <1000000>; 1490a1b9293SMaxime Ripard reg = <0>; 1500a1b9293SMaxime Ripard }; 1510a1b9293SMaxime Ripard 15228ffe8bfSRob Herring sensor@1 { 15328ffe8bfSRob Herring compatible = "bosch,bme680"; 1540a1b9293SMaxime Ripard spi-max-frequency = <100000>; 1550a1b9293SMaxime Ripard reg = <1>; 1560a1b9293SMaxime Ripard }; 157eba53685SMiquel Raynal 158eba53685SMiquel Raynal flash@2 { 159eba53685SMiquel Raynal compatible = "jedec,spi-nor"; 160eba53685SMiquel Raynal spi-max-frequency = <50000000>; 161eba53685SMiquel Raynal reg = <2>, <3>; 162eba53685SMiquel Raynal stacked-memories = /bits/ 64 <0x10000000 0x10000000>; 163eba53685SMiquel Raynal }; 1640a1b9293SMaxime Ripard }; 165