xref: /freebsd-src/sys/contrib/device-tree/Bindings/spi/spi-controller.yaml (revision 01950c46b8155250f64374fb72fc11faa44bf099)
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
78bab661aSEmmanuel Vadottitle: SPI Controller Common Properties
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:
20f126890aSEmmanuel Vadot    pattern: "^spi(@.*|-([0-9]|[1-9][0-9]+))?$"
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
72*01950c46SEmmanuel Vadot  fifo-depth:
73*01950c46SEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32
74*01950c46SEmmanuel Vadot    description:
75*01950c46SEmmanuel Vadot      Size of the RX and TX data FIFOs in bytes.
76*01950c46SEmmanuel Vadot
77*01950c46SEmmanuel Vadot  rx-fifo-depth:
78*01950c46SEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32
79*01950c46SEmmanuel Vadot    description:
80*01950c46SEmmanuel Vadot      Size of the RX data FIFO in bytes.
81*01950c46SEmmanuel Vadot
82*01950c46SEmmanuel Vadot  tx-fifo-depth:
83*01950c46SEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32
84*01950c46SEmmanuel Vadot    description:
85*01950c46SEmmanuel Vadot      Size of the TX data FIFO in bytes.
86*01950c46SEmmanuel Vadot
87c66ec88fSEmmanuel Vadot  num-cs:
88c66ec88fSEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/uint32
89c66ec88fSEmmanuel Vadot    description:
90c66ec88fSEmmanuel Vadot      Total number of chip selects.
91c66ec88fSEmmanuel Vadot
92c66ec88fSEmmanuel Vadot  spi-slave:
93c66ec88fSEmmanuel Vadot    $ref: /schemas/types.yaml#/definitions/flag
94c66ec88fSEmmanuel Vadot    description:
95c66ec88fSEmmanuel Vadot      The SPI controller acts as a slave, instead of a master.
96c66ec88fSEmmanuel Vadot
975956d97fSEmmanuel 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
1085956d97fSEmmanuel VadotpatternProperties:
109c66ec88fSEmmanuel Vadot  "^.*@[0-9a-f]+$":
110c66ec88fSEmmanuel Vadot    type: object
111c9ccf3a3SEmmanuel Vadot    $ref: spi-peripheral-props.yaml
112fac71e4eSEmmanuel Vadot    additionalProperties: true
113c66ec88fSEmmanuel Vadot
114b97ee269SEmmanuel Vadot    properties:
1157ef62cebSEmmanuel Vadot      spi-3wire:
1167ef62cebSEmmanuel Vadot        $ref: /schemas/types.yaml#/definitions/flag
1177ef62cebSEmmanuel Vadot        description:
1187ef62cebSEmmanuel Vadot          The device requires 3-wire mode.
1197ef62cebSEmmanuel Vadot
120b97ee269SEmmanuel Vadot      spi-cpha:
121b97ee269SEmmanuel Vadot        $ref: /schemas/types.yaml#/definitions/flag
122b97ee269SEmmanuel Vadot        description:
123b97ee269SEmmanuel Vadot          The device requires shifted clock phase (CPHA) mode.
124b97ee269SEmmanuel Vadot
125b97ee269SEmmanuel Vadot      spi-cpol:
126b97ee269SEmmanuel Vadot        $ref: /schemas/types.yaml#/definitions/flag
127b97ee269SEmmanuel Vadot        description:
128b97ee269SEmmanuel Vadot          The device requires inverse clock polarity (CPOL) mode.
129b97ee269SEmmanuel Vadot
130c66ec88fSEmmanuel Vadot    required:
131c66ec88fSEmmanuel Vadot      - compatible
132c66ec88fSEmmanuel Vadot      - reg
133c66ec88fSEmmanuel Vadot
134*01950c46SEmmanuel Vadotdependencies:
135*01950c46SEmmanuel Vadot  rx-fifo-depth: [ tx-fifo-depth ]
136*01950c46SEmmanuel Vadot  tx-fifo-depth: [ rx-fifo-depth ]
137*01950c46SEmmanuel Vadot
1385956d97fSEmmanuel VadotallOf:
1395956d97fSEmmanuel Vadot  - if:
1405956d97fSEmmanuel Vadot      not:
1415956d97fSEmmanuel Vadot        required:
1425956d97fSEmmanuel Vadot          - spi-slave
1435956d97fSEmmanuel Vadot    then:
1445956d97fSEmmanuel Vadot      properties:
1455956d97fSEmmanuel Vadot        "#address-cells":
1465956d97fSEmmanuel Vadot          const: 1
1475956d97fSEmmanuel Vadot    else:
1485956d97fSEmmanuel Vadot      properties:
1495956d97fSEmmanuel Vadot        "#address-cells":
1505956d97fSEmmanuel Vadot          const: 0
151*01950c46SEmmanuel Vadot  - not:
152*01950c46SEmmanuel Vadot      required:
153*01950c46SEmmanuel Vadot        - fifo-depth
154*01950c46SEmmanuel Vadot        - rx-fifo-depth
155*01950c46SEmmanuel Vadot  - not:
156*01950c46SEmmanuel Vadot      required:
157*01950c46SEmmanuel Vadot        - fifo-depth
158*01950c46SEmmanuel Vadot        - tx-fifo-depth
1595956d97fSEmmanuel Vadot
1606be33864SEmmanuel VadotadditionalProperties: true
1616be33864SEmmanuel Vadot
162c66ec88fSEmmanuel Vadotexamples:
163c66ec88fSEmmanuel Vadot  - |
1642eb4d8dcSEmmanuel Vadot    spi@80010000 {
165c66ec88fSEmmanuel Vadot        #address-cells = <1>;
166c66ec88fSEmmanuel Vadot        #size-cells = <0>;
1672eb4d8dcSEmmanuel Vadot        compatible = "fsl,imx28-spi";
1682eb4d8dcSEmmanuel Vadot        reg = <0x80010000 0x2000>;
1692eb4d8dcSEmmanuel Vadot        interrupts = <96>;
1702eb4d8dcSEmmanuel Vadot        dmas = <&dma_apbh 0>;
1712eb4d8dcSEmmanuel Vadot        dma-names = "rx-tx";
172c66ec88fSEmmanuel Vadot
1732eb4d8dcSEmmanuel Vadot        display@0 {
1742eb4d8dcSEmmanuel Vadot            compatible = "lg,lg4573";
175c66ec88fSEmmanuel Vadot            spi-max-frequency = <1000000>;
176c66ec88fSEmmanuel Vadot            reg = <0>;
177c66ec88fSEmmanuel Vadot        };
178c66ec88fSEmmanuel Vadot
1792eb4d8dcSEmmanuel Vadot        sensor@1 {
1802eb4d8dcSEmmanuel Vadot            compatible = "bosch,bme680";
181c66ec88fSEmmanuel Vadot            spi-max-frequency = <100000>;
182c66ec88fSEmmanuel Vadot            reg = <1>;
183c66ec88fSEmmanuel Vadot        };
184c9ccf3a3SEmmanuel Vadot
185c9ccf3a3SEmmanuel Vadot        flash@2 {
186c9ccf3a3SEmmanuel Vadot            compatible = "jedec,spi-nor";
187c9ccf3a3SEmmanuel Vadot            spi-max-frequency = <50000000>;
188c9ccf3a3SEmmanuel Vadot            reg = <2>, <3>;
189c9ccf3a3SEmmanuel Vadot            stacked-memories = /bits/ 64 <0x10000000 0x10000000>;
190c9ccf3a3SEmmanuel Vadot        };
191c66ec88fSEmmanuel Vadot    };
192