xref: /linux/Documentation/devicetree/bindings/spi/spi-controller.yaml (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
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
70a1b9293SMaxime Ripardtitle: SPI Controller Generic Binding
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
96*dca66935SRob Herring    $ref: spi-peripheral-props.yaml
970a1b9293SMaxime Ripard
980a1b9293SMaxime Ripard    required:
990a1b9293SMaxime Ripard      - compatible
1000a1b9293SMaxime Ripard      - reg
1010a1b9293SMaxime Ripard
102f88321a3SRob HerringallOf:
103f88321a3SRob Herring  - if:
104f88321a3SRob Herring      not:
105f88321a3SRob Herring        required:
106f88321a3SRob Herring          - spi-slave
107f88321a3SRob Herring    then:
108f88321a3SRob Herring      properties:
109f88321a3SRob Herring        "#address-cells":
110f88321a3SRob Herring          const: 1
111f88321a3SRob Herring    else:
112f88321a3SRob Herring      properties:
113f88321a3SRob Herring        "#address-cells":
114f88321a3SRob Herring          const: 0
115f88321a3SRob Herring
1166a0e321eSRob HerringadditionalProperties: true
1176a0e321eSRob Herring
1180a1b9293SMaxime Ripardexamples:
1190a1b9293SMaxime Ripard  - |
12028ffe8bfSRob Herring    spi@80010000 {
1210a1b9293SMaxime Ripard        #address-cells = <1>;
1220a1b9293SMaxime Ripard        #size-cells = <0>;
12328ffe8bfSRob Herring        compatible = "fsl,imx28-spi";
12428ffe8bfSRob Herring        reg = <0x80010000 0x2000>;
12528ffe8bfSRob Herring        interrupts = <96>;
12628ffe8bfSRob Herring        dmas = <&dma_apbh 0>;
12728ffe8bfSRob Herring        dma-names = "rx-tx";
1280a1b9293SMaxime Ripard
12928ffe8bfSRob Herring        display@0 {
13028ffe8bfSRob Herring            compatible = "lg,lg4573";
1310a1b9293SMaxime Ripard            spi-max-frequency = <1000000>;
1320a1b9293SMaxime Ripard            reg = <0>;
1330a1b9293SMaxime Ripard        };
1340a1b9293SMaxime Ripard
13528ffe8bfSRob Herring        sensor@1 {
13628ffe8bfSRob Herring            compatible = "bosch,bme680";
1370a1b9293SMaxime Ripard            spi-max-frequency = <100000>;
1380a1b9293SMaxime Ripard            reg = <1>;
1390a1b9293SMaxime Ripard        };
140eba53685SMiquel Raynal
141eba53685SMiquel Raynal        flash@2 {
142eba53685SMiquel Raynal          compatible = "jedec,spi-nor";
143eba53685SMiquel Raynal          spi-max-frequency = <50000000>;
144eba53685SMiquel Raynal          reg = <2>, <3>;
145eba53685SMiquel Raynal          stacked-memories = /bits/ 64 <0x10000000 0x10000000>;
146eba53685SMiquel Raynal        };
1470a1b9293SMaxime Ripard    };
148