← Documents Documentation/devicetree/bindings/spi/spi-controller.yaml GitHub 원문 ↗

Linux 6.18.37 · Devicetree Bindings / SPI

SPI controller common properties

SPI controller와 peripheral의 공통 속성, CS polarity, FIFO·mode 조건과 예제를 설명합니다.

Source pathDocumentation/devicetree/bindings/spi/spi-controller.yaml
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약과 해설

spi-controller.yaml:1-216

SPI controller와 peripheral의 공통 속성, CS polarity, FIFO·mode 조건과 예제를 설명합니다. 접을 수 있는 영어 원문 전체와 줄 좌표를 보존하고, 한국어 전문 번역에서는 compatible·property·symbol·source path·표·수치·조건부 제약·예제 코드를 원형대로 유지합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 # SPDX-License-Identifier: GPL-2.0
2 %YAML 1.2
3 ---
4 $id: http://devicetree.org/schemas/spi/spi-controller.yaml#
5 $schema: http://devicetree.org/meta-schemas/core.yaml#
6
7 title: SPI Controller Common Properties
8
9 maintainers:
10 - Mark Brown <broonie@kernel.org>
11
12 description: |
13 SPI busses can be described with a node for the SPI controller device
14 and a set of child nodes for each SPI slave on the bus. The system SPI
15 controller may be described for use in SPI master mode or in SPI slave mode,
16 but not for both at the same time.
17
18 properties:
19 $nodename:
20 pattern: "^spi(@.*|-([0-9]|[1-9][0-9]+))?$"
21
22 "#address-cells":
23 enum: [0, 1]
24
25 "#size-cells":
26 const: 0
27
28 cs-gpios:
29 description: |
30 GPIOs used as chip selects.
31 If that property is used, the number of chip selects will be
32 increased automatically with max(cs-gpios, hardware chip selects).
33
34 So if, for example, the controller has 4 CS lines, and the
35 cs-gpios looks like this
36 cs-gpios = <&gpio1 0 0>, <0>, <&gpio1 1 0>, <&gpio1 2 0>;
37
38 Then it should be configured so that num_chipselect = 4, with
39 the following mapping
40 cs0 : &gpio1 0 0
41 cs1 : native
42 cs2 : &gpio1 1 0
43 cs3 : &gpio1 2 0
44
45 The second flag of a gpio descriptor can be GPIO_ACTIVE_HIGH (0)
46 or GPIO_ACTIVE_LOW(1). Legacy device trees often use 0.
47
48 There is a special rule set for combining the second flag of an
49 cs-gpio with the optional spi-cs-high flag for SPI slaves.
50
51 Each table entry defines how the CS pin is to be physically
52 driven (not considering potential gpio inversions by pinmux):
53
54 device node | cs-gpio | CS pin state active | Note
55 ================+===============+=====================+=====
56 spi-cs-high | - | H |
57 - | - | L |
58 spi-cs-high | ACTIVE_HIGH | H |
59 - | ACTIVE_HIGH | L | 1
60 spi-cs-high | ACTIVE_LOW | H | 2
61 - | ACTIVE_LOW | L |
62
63 Notes:
64 1) Should print a warning about polarity inversion.
65 Here it would be wise to avoid and define the gpio as
66 ACTIVE_LOW.
67 2) Should print a warning about polarity inversion
68 because ACTIVE_LOW is overridden by spi-cs-high.
69 Should be generally avoided and be replaced by
70 spi-cs-high + ACTIVE_HIGH.
71
72 The simplest way to obtain an active-high CS signal is to configure the
73 controller's cs-gpio property with the ACTIVE_HIGH flag and set the
74 peripheral's spi-cs-high property. See example below for a better
75 understanding.
76
77 fifo-depth:
78 $ref: /schemas/types.yaml#/definitions/uint32
79 description:
80 Size of the RX and TX data FIFOs in bytes.
81
82 rx-fifo-depth:
83 $ref: /schemas/types.yaml#/definitions/uint32
84 description:
85 Size of the RX data FIFO in bytes.
86
87 tx-fifo-depth:
88 $ref: /schemas/types.yaml#/definitions/uint32
89 description:
90 Size of the TX data FIFO in bytes.
91
92 num-cs:
93 $ref: /schemas/types.yaml#/definitions/uint32
94 description:
95 Total number of chip selects.
96
97 spi-slave:
98 $ref: /schemas/types.yaml#/definitions/flag
99 description:
100 The SPI controller acts as a slave, instead of a master.
101
102 slave:
103 type: object
104
105 properties:
106 compatible:
107 description:
108 Compatible of the SPI device.
109
110 required:
111 - compatible
112
113 patternProperties:
114 "^.*@[0-9a-f]+$":
115 type: object
116 $ref: spi-peripheral-props.yaml
117 additionalProperties: true
118
119 properties:
120 spi-3wire:
121 $ref: /schemas/types.yaml#/definitions/flag
122 description:
123 The device requires 3-wire mode.
124
125 spi-cpha:
126 $ref: /schemas/types.yaml#/definitions/flag
127 description:
128 The device requires shifted clock phase (CPHA) mode.
129
130 spi-cpol:
131 $ref: /schemas/types.yaml#/definitions/flag
132 description:
133 The device requires inverse clock polarity (CPOL) mode.
134
135 required:
136 - compatible
137 - reg
138
139 dependencies:
140 rx-fifo-depth: [ tx-fifo-depth ]
141 tx-fifo-depth: [ rx-fifo-depth ]
142
143 allOf:
144 - if:
145 not:
146 required:
147 - spi-slave
148 then:
149 properties:
150 "#address-cells":
151 const: 1
152 else:
153 properties:
154 "#address-cells":
155 const: 0
156 - not:
157 required:
158 - fifo-depth
159 - rx-fifo-depth
160 - not:
161 required:
162 - fifo-depth
163 - tx-fifo-depth
164
165 additionalProperties: true
166
167 examples:
168 - |
169 spi@80010000 {
170 #address-cells = <1>;
171 #size-cells = <0>;
172 compatible = "fsl,imx28-spi";
173 reg = <0x80010000 0x2000>;
174 interrupts = <96>;
175 dmas = <&dma_apbh 0>;
176 dma-names = "rx-tx";
177
178 display@0 {
179 compatible = "lg,lg4573";
180 spi-max-frequency = <1000000>;
181 reg = <0>;
182 };
183
184 sensor@1 {
185 compatible = "bosch,bme680";
186 spi-max-frequency = <100000>;
187 reg = <1>;
188 };
189
190 flash@2 {
191 compatible = "jedec,spi-nor";
192 spi-max-frequency = <50000000>;
193 reg = <2>, <3>;
194 stacked-memories = /bits/ 64 <0x10000000 0x10000000>;
195 };
196 };
197
198 - |
199 #include <dt-bindings/gpio/gpio.h>
200
201 spi@20204000 {
202 #address-cells = <1>;
203 #size-cells = <0>;
204 compatible = "brcm,bcm2835-spi";
205 reg = <0x7e204000 0x1000>;
206 interrupts = <2 22>;
207 clocks = <&clk_spi>;
208 cs-gpios = <&gpio 8 GPIO_ACTIVE_HIGH>;
209
210 display@0 {
211 compatible = "lg,lg4573";
212 spi-max-frequency = <1000000>;
213 reg = <0>;
214 spi-cs-high;
215 };
216 };
217

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

SPI controller 공통 schema

1-17

이 GPL-2.0 YAML schema는 SPI controller 공통 속성을 정의합니다. Schema ID는 `http://devicetree.org/schemas/spi/spi-controller.yaml#`, maintainer는 Mark Brown입니다.

SPI bus는 controller device node와 bus 위 각 SPI peripheral의 child node 집합으로 기술합니다. System SPI controller는 master mode 또는 slave mode 중 하나로만 기술할 수 있고 동시에 두 mode로 사용할 수 없습니다.

Node 이름과 bus cell

18-27

Controller node 이름은 정규식 `^spi(@.*|-([0-9]|[1-9][0-9]+))?$`를 따릅니다. `#address-cells`는 0 또는 1이고 `#size-cells`는 0으로 고정됩니다.

GPIO와 native chip-select 매핑

28-46

`cs-gpios`는 chip-select로 사용하는 GPIO 목록입니다. 이 속성을 사용하면 chip-select 수는 `max(cs-gpios, hardware chip selects)`로 자동 증가합니다.

예를 들어 hardware CS line이 4개이고 `cs-gpios = <&gpio1 0 0>, <0>, <&gpio1 1 0>, <&gpio1 2 0>;`이면 `num_chipselect = 4`이며 빈 둘째 항목은 native CS를 뜻합니다. GPIO descriptor의 둘째 flag는 `GPIO_ACTIVE_HIGH(0)` 또는 `GPIO_ACTIVE_LOW(1)`이고 legacy device tree는 흔히 0을 사용합니다.

cs-gpios와 hardware CS 매핑
Chip select구동 sourceDescriptor
CS0GPIO`&gpio1 0 0`
CS1Native controller CS`<0>`
CS2GPIO`&gpio1 1 0`
CS3GPIO`&gpio1 2 0`

원문 4-line 예제를 chip-select 번호별로 구조화했습니다.

spi-cs-high와 GPIO polarity 조합

47-75

SPI peripheral의 선택적 `spi-cs-high`와 `cs-gpio`의 둘째 flag를 조합하는 특별 규칙이 있습니다. 표의 active state는 pinmux가 가할 수 있는 GPIO inversion은 고려하지 않은 물리적 CS pin 구동 상태입니다.

CS polarity 조합표
Peripheral flagcs-gpio flagActive stateNote
`spi-cs-high`없음H
없음없음L
`spi-cs-high``ACTIVE_HIGH`H
없음`ACTIVE_HIGH`L1
`spi-cs-high``ACTIVE_LOW`H2
없음`ACTIVE_LOW`L
undefinedundefined
undefinedundefined

H는 active-high, L은 active-low로 구동되는 상태입니다.

Active-high CS를 얻는 가장 단순한 방법은 controller의 `cs-gpio`를 `ACTIVE_HIGH`로 지정하고 peripheral에 `spi-cs-high`를 설정하는 것입니다.

FIFO depth, chip-select 수와 slave mode

76-112

`fifo-depth`는 RX와 TX data FIFO의 공통 크기, `rx-fifo-depth`와 `tx-fifo-depth`는 각 방향 FIFO 크기이며 단위는 byte입니다. `num-cs`는 chip-select 총수입니다.

Flag `spi-slave`를 지정하면 controller가 master 대신 slave로 동작합니다. `slave` object는 SPI device의 `compatible`을 필수로 포함합니다.

Peripheral child와 SPI mode flag

113-138

정규식 `^.*@[0-9a-f]+$`에 맞는 child는 `spi-peripheral-props.yaml`을 참조하고 추가 속성을 허용합니다. Child에는 `compatible`과 `reg`가 필수입니다.

`spi-3wire`는 장치가 3-wire mode를 요구함을, `spi-cpha`는 shifted clock phase(CPHA)를, `spi-cpol`은 inverse clock polarity(CPOL)를 요구함을 나타내는 flag입니다.

FIFO dependency와 master/slave address cell

139-166

`rx-fifo-depth`와 `tx-fifo-depth`는 서로 의존하므로 한쪽을 쓰면 다른 쪽도 필요합니다. 공통 `fifo-depth`와 방향별 `rx-fifo-depth` 또는 `tx-fifo-depth`를 동시에 지정할 수 없습니다.

`spi-slave`가 없으면 master mode이므로 `#address-cells`는 1입니다. `spi-slave`가 있으면 slave mode이므로 `#address-cells`는 0입니다. 이 공통 schema는 controller별 확장을 위해 최상위 추가 속성을 허용합니다.

Master controller와 세 peripheral 예제

167-197

첫 예제는 `fsl,imx28-spi` master controller에 display, sensor, flash child를 둡니다. Flash는 chip select 2와 3을 묶어 두 개의 `0x10000000` stacked memory를 구성합니다.

spi@80010000 {
    #address-cells = <1>;
    #size-cells = <0>;
    compatible = "fsl,imx28-spi";
    reg = <0x80010000 0x2000>;
    interrupts = <96>;
    dmas = <&dma_apbh 0>;
    dma-names = "rx-tx";

    display@0 {
        compatible = "lg,lg4573";
        spi-max-frequency = <1000000>;
        reg = <0>;
    };

    sensor@1 {
        compatible = "bosch,bme680";
        spi-max-frequency = <100000>;
        reg = <1>;
    };

    flash@2 {
        compatible = "jedec,spi-nor";
        spi-max-frequency = <50000000>;
        reg = <2>, <3>;
        stacked-memories = /bits/ 64 <0x10000000 0x10000000>;
    };
};

Active-high GPIO chip-select 예제

198-216

둘째 예제는 BCM2835 SPI controller의 GPIO 8을 `GPIO_ACTIVE_HIGH`로 지정하고 display child에 `spi-cs-high`를 설정해 active-high CS를 구성합니다.

#include <dt-bindings/gpio/gpio.h>

spi@20204000 {
    #address-cells = <1>;
    #size-cells = <0>;
    compatible = "brcm,bcm2835-spi";
    reg = <0x7e204000 0x1000>;
    interrupts = <2 22>;
    clocks = <&clk_spi>;
    cs-gpios = <&gpio 8 GPIO_ACTIVE_HIGH>;

    display@0 {
        compatible = "lg,lg4573";
        spi-max-frequency = <1000000>;
        reg = <0>;
        spi-cs-high;
    };
};