1c66ec88fSEmmanuel Vadot# SPDX-License-Identifier: GPL-2.0 2c66ec88fSEmmanuel Vadot%YAML 1.2 3c66ec88fSEmmanuel Vadot--- 4c66ec88fSEmmanuel Vadot$id: http://devicetree.org/schemas/spi/spi-controller.yaml# 5c66ec88fSEmmanuel Vadot$schema: http://devicetree.org/meta-schemas/core.yaml# 6c66ec88fSEmmanuel Vadot 7c66ec88fSEmmanuel Vadottitle: SPI Controller Generic Binding 8c66ec88fSEmmanuel Vadot 9c66ec88fSEmmanuel Vadotmaintainers: 10c66ec88fSEmmanuel Vadot - Mark Brown <broonie@kernel.org> 11c66ec88fSEmmanuel Vadot 12c66ec88fSEmmanuel Vadotdescription: | 13c66ec88fSEmmanuel Vadot SPI busses can be described with a node for the SPI controller device 14c66ec88fSEmmanuel Vadot and a set of child nodes for each SPI slave on the bus. The system SPI 15c66ec88fSEmmanuel Vadot controller may be described for use in SPI master mode or in SPI slave mode, 16c66ec88fSEmmanuel Vadot but not for both at the same time. 17c66ec88fSEmmanuel Vadot 18c66ec88fSEmmanuel Vadotproperties: 19c66ec88fSEmmanuel Vadot $nodename: 20c66ec88fSEmmanuel Vadot pattern: "^spi(@.*|-[0-9a-f])*$" 21c66ec88fSEmmanuel Vadot 22c66ec88fSEmmanuel Vadot "#address-cells": 236be33864SEmmanuel Vadot enum: [0, 1] 24c66ec88fSEmmanuel Vadot 25c66ec88fSEmmanuel Vadot "#size-cells": 26c66ec88fSEmmanuel Vadot const: 0 27c66ec88fSEmmanuel Vadot 28c66ec88fSEmmanuel Vadot cs-gpios: 29c66ec88fSEmmanuel Vadot description: | 30c66ec88fSEmmanuel Vadot GPIOs used as chip selects. 31c66ec88fSEmmanuel Vadot If that property is used, the number of chip selects will be 32c66ec88fSEmmanuel Vadot increased automatically with max(cs-gpios, hardware chip selects). 33c66ec88fSEmmanuel Vadot 34c66ec88fSEmmanuel Vadot So if, for example, the controller has 4 CS lines, and the 35c66ec88fSEmmanuel Vadot cs-gpios looks like this 36c66ec88fSEmmanuel Vadot cs-gpios = <&gpio1 0 0>, <0>, <&gpio1 1 0>, <&gpio1 2 0>; 37c66ec88fSEmmanuel Vadot 38c66ec88fSEmmanuel Vadot Then it should be configured so that num_chipselect = 4, with 39c66ec88fSEmmanuel Vadot the following mapping 40c66ec88fSEmmanuel Vadot cs0 : &gpio1 0 0 41c66ec88fSEmmanuel Vadot cs1 : native 42c66ec88fSEmmanuel Vadot cs2 : &gpio1 1 0 43c66ec88fSEmmanuel Vadot cs3 : &gpio1 2 0 44c66ec88fSEmmanuel Vadot 455def4c47SEmmanuel Vadot The second flag of a gpio descriptor can be GPIO_ACTIVE_HIGH (0) 465def4c47SEmmanuel Vadot or GPIO_ACTIVE_LOW(1). Legacy device trees often use 0. 475def4c47SEmmanuel Vadot 485def4c47SEmmanuel Vadot There is a special rule set for combining the second flag of an 495def4c47SEmmanuel Vadot cs-gpio with the optional spi-cs-high flag for SPI slaves. 505def4c47SEmmanuel Vadot 515def4c47SEmmanuel Vadot Each table entry defines how the CS pin is to be physically 525def4c47SEmmanuel Vadot driven (not considering potential gpio inversions by pinmux): 535def4c47SEmmanuel Vadot 545def4c47SEmmanuel Vadot device node | cs-gpio | CS pin state active | Note 555def4c47SEmmanuel Vadot ================+===============+=====================+===== 565def4c47SEmmanuel Vadot spi-cs-high | - | H | 575def4c47SEmmanuel Vadot - | - | L | 585def4c47SEmmanuel Vadot spi-cs-high | ACTIVE_HIGH | H | 595def4c47SEmmanuel Vadot - | ACTIVE_HIGH | L | 1 605def4c47SEmmanuel Vadot spi-cs-high | ACTIVE_LOW | H | 2 615def4c47SEmmanuel Vadot - | ACTIVE_LOW | L | 625def4c47SEmmanuel Vadot 635def4c47SEmmanuel Vadot Notes: 645def4c47SEmmanuel Vadot 1) Should print a warning about polarity inversion. 655def4c47SEmmanuel Vadot Here it would be wise to avoid and define the gpio as 665def4c47SEmmanuel Vadot ACTIVE_LOW. 675def4c47SEmmanuel Vadot 2) Should print a warning about polarity inversion 685def4c47SEmmanuel Vadot because ACTIVE_LOW is overridden by spi-cs-high. 695def4c47SEmmanuel Vadot Should be generally avoided and be replaced by 705def4c47SEmmanuel Vadot spi-cs-high + ACTIVE_HIGH. 715def4c47SEmmanuel Vadot 72c66ec88fSEmmanuel Vadot num-cs: 73c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/uint32 74c66ec88fSEmmanuel Vadot description: 75c66ec88fSEmmanuel Vadot Total number of chip selects. 76c66ec88fSEmmanuel Vadot 77c66ec88fSEmmanuel Vadot spi-slave: 78c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/flag 79c66ec88fSEmmanuel Vadot description: 80c66ec88fSEmmanuel Vadot The SPI controller acts as a slave, instead of a master. 81c66ec88fSEmmanuel Vadot 826be33864SEmmanuel VadotallOf: 836be33864SEmmanuel Vadot - if: 846be33864SEmmanuel Vadot not: 856be33864SEmmanuel Vadot required: 86c66ec88fSEmmanuel Vadot - spi-slave 876be33864SEmmanuel Vadot then: 886be33864SEmmanuel Vadot properties: 896be33864SEmmanuel Vadot "#address-cells": 906be33864SEmmanuel Vadot const: 1 916be33864SEmmanuel Vadot else: 926be33864SEmmanuel Vadot properties: 936be33864SEmmanuel Vadot "#address-cells": 946be33864SEmmanuel Vadot const: 0 95c66ec88fSEmmanuel Vadot 96c66ec88fSEmmanuel VadotpatternProperties: 97c66ec88fSEmmanuel Vadot "^slave$": 98c66ec88fSEmmanuel Vadot type: object 99c66ec88fSEmmanuel Vadot 100c66ec88fSEmmanuel Vadot properties: 101c66ec88fSEmmanuel Vadot compatible: 102c66ec88fSEmmanuel Vadot description: 103c66ec88fSEmmanuel Vadot Compatible of the SPI device. 104c66ec88fSEmmanuel Vadot 105c66ec88fSEmmanuel Vadot required: 106c66ec88fSEmmanuel Vadot - compatible 107c66ec88fSEmmanuel Vadot 108c66ec88fSEmmanuel Vadot "^.*@[0-9a-f]+$": 109c66ec88fSEmmanuel Vadot type: object 110c66ec88fSEmmanuel Vadot 111c66ec88fSEmmanuel Vadot properties: 112c66ec88fSEmmanuel Vadot compatible: 113c66ec88fSEmmanuel Vadot description: 114c66ec88fSEmmanuel Vadot Compatible of the SPI device. 115c66ec88fSEmmanuel Vadot 116c66ec88fSEmmanuel Vadot reg: 117c66ec88fSEmmanuel Vadot minimum: 0 118c66ec88fSEmmanuel Vadot maximum: 256 119c66ec88fSEmmanuel Vadot description: 120c66ec88fSEmmanuel Vadot Chip select used by the device. 121c66ec88fSEmmanuel Vadot 122c66ec88fSEmmanuel Vadot spi-3wire: 123c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/flag 124c66ec88fSEmmanuel Vadot description: 125c66ec88fSEmmanuel Vadot The device requires 3-wire mode. 126c66ec88fSEmmanuel Vadot 127c66ec88fSEmmanuel Vadot spi-cpha: 128c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/flag 129c66ec88fSEmmanuel Vadot description: 130c66ec88fSEmmanuel Vadot The device requires shifted clock phase (CPHA) mode. 131c66ec88fSEmmanuel Vadot 132c66ec88fSEmmanuel Vadot spi-cpol: 133c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/flag 134c66ec88fSEmmanuel Vadot description: 135c66ec88fSEmmanuel Vadot The device requires inverse clock polarity (CPOL) mode. 136c66ec88fSEmmanuel Vadot 137c66ec88fSEmmanuel Vadot spi-cs-high: 138c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/flag 139c66ec88fSEmmanuel Vadot description: 140c66ec88fSEmmanuel Vadot The device requires the chip select active high. 141c66ec88fSEmmanuel Vadot 142c66ec88fSEmmanuel Vadot spi-lsb-first: 143c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/flag 144c66ec88fSEmmanuel Vadot description: 145c66ec88fSEmmanuel Vadot The device requires the LSB first mode. 146c66ec88fSEmmanuel Vadot 147c66ec88fSEmmanuel Vadot spi-max-frequency: 148c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/uint32 149c66ec88fSEmmanuel Vadot description: 150c66ec88fSEmmanuel Vadot Maximum SPI clocking speed of the device in Hz. 151c66ec88fSEmmanuel Vadot 152c66ec88fSEmmanuel Vadot spi-rx-bus-width: 153c66ec88fSEmmanuel Vadot description: 154c66ec88fSEmmanuel Vadot Bus width to the SPI bus used for read transfers. 1555def4c47SEmmanuel Vadot If 0 is provided, then no RX will be possible on this device. 156c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/uint32 1575def4c47SEmmanuel Vadot enum: [0, 1, 2, 4, 8] 158c66ec88fSEmmanuel Vadot default: 1 159c66ec88fSEmmanuel Vadot 160c66ec88fSEmmanuel Vadot spi-rx-delay-us: 161c66ec88fSEmmanuel Vadot description: 162c66ec88fSEmmanuel Vadot Delay, in microseconds, after a read transfer. 163c66ec88fSEmmanuel Vadot 164c66ec88fSEmmanuel Vadot spi-tx-bus-width: 165c66ec88fSEmmanuel Vadot description: 166c66ec88fSEmmanuel Vadot Bus width to the SPI bus used for write transfers. 1675def4c47SEmmanuel Vadot If 0 is provided, then no TX will be possible on this device. 168c66ec88fSEmmanuel Vadot $ref: /schemas/types.yaml#/definitions/uint32 1695def4c47SEmmanuel Vadot enum: [0, 1, 2, 4, 8] 170c66ec88fSEmmanuel Vadot default: 1 171c66ec88fSEmmanuel Vadot 172c66ec88fSEmmanuel Vadot spi-tx-delay-us: 173c66ec88fSEmmanuel Vadot description: 174c66ec88fSEmmanuel Vadot Delay, in microseconds, after a write transfer. 175c66ec88fSEmmanuel Vadot 176c66ec88fSEmmanuel Vadot required: 177c66ec88fSEmmanuel Vadot - compatible 178c66ec88fSEmmanuel Vadot - reg 179c66ec88fSEmmanuel Vadot 1806be33864SEmmanuel VadotadditionalProperties: true 1816be33864SEmmanuel Vadot 182c66ec88fSEmmanuel Vadotexamples: 183c66ec88fSEmmanuel Vadot - | 184*2eb4d8dcSEmmanuel Vadot spi@80010000 { 185c66ec88fSEmmanuel Vadot #address-cells = <1>; 186c66ec88fSEmmanuel Vadot #size-cells = <0>; 187*2eb4d8dcSEmmanuel Vadot compatible = "fsl,imx28-spi"; 188*2eb4d8dcSEmmanuel Vadot reg = <0x80010000 0x2000>; 189*2eb4d8dcSEmmanuel Vadot interrupts = <96>; 190*2eb4d8dcSEmmanuel Vadot dmas = <&dma_apbh 0>; 191*2eb4d8dcSEmmanuel Vadot dma-names = "rx-tx"; 192c66ec88fSEmmanuel Vadot 193*2eb4d8dcSEmmanuel Vadot display@0 { 194*2eb4d8dcSEmmanuel Vadot compatible = "lg,lg4573"; 195c66ec88fSEmmanuel Vadot spi-max-frequency = <1000000>; 196c66ec88fSEmmanuel Vadot reg = <0>; 197c66ec88fSEmmanuel Vadot }; 198c66ec88fSEmmanuel Vadot 199*2eb4d8dcSEmmanuel Vadot sensor@1 { 200*2eb4d8dcSEmmanuel Vadot compatible = "bosch,bme680"; 201c66ec88fSEmmanuel Vadot spi-max-frequency = <100000>; 202c66ec88fSEmmanuel Vadot reg = <1>; 203c66ec88fSEmmanuel Vadot }; 204c66ec88fSEmmanuel Vadot }; 205