# SPI

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

串行外设接口 (SPI) 是在全双工模式下工作的同步串行数据链路。SPI 又称为 4 线制串行总线。
Figure : SPI 数据流
                
                <!--?xml version="1.0" encoding="UTF-8" standalone="no"?-->

<!-- 由 Microsoft Visio, SVG Export 生成 spi-data-flow.svg Page-1 -->
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:v="http://schemas.microsoft.com/visio/2003/SVGExtensions/" width="6.821in" height="4.50438in" viewbox="0 0 491.112 324.315" xml:space="preserve" color-interpolation-filters="sRGB" class="st14"><v:documentproperties v:langid="2052">	<v:userdefs>		<v:ud v:nameu="msvNoAutoConnect" v:val="VT0(1):26"></v:ud>	</v:userdefs></v:documentproperties>
<style>.svg-1 .st1 { fill: #ffffff; stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 0.75 }
.svg-1 .st2 { fill: #ffffff; visibility: hidden }
.svg-1 .st3 { stroke: #3253dc; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st4 { marker-end: url("#mrkr4-14"); stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st5 { fill: #000000; fill-opacity: 1; stroke: #000000; stroke-opacity: 1; stroke-width: 0.28409090909091 }
.svg-1 .st6 { marker-start: url("#mrkr4-30"); stroke: #000000; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st7 { marker-start: url("#mrkr4-35"); stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st8 { fill: #ffffff; fill-opacity: 1; stroke: #ffffff; stroke-opacity: 1; stroke-width: 0.28409090909091 }
.svg-1 .st9 { fill: #000000; font-family: 黑体; font-size: 1.24999em; font-weight: bold }
.svg-1 .st10 { fill: #000000; font-family: Calibri; font-size: 1.00001em }
.svg-1 .st11 { fill: none; visibility: hidden }
.svg-1 .st12 { stroke: none; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1 }
.svg-1 .st13 { fill: #000000; font-family: 黑体; font-size: 1.00001em }
.svg-1 .st14 { fill: none; fill-rule: evenodd; font-size: 12px; overflow: visible; stroke-linecap: square; stroke-miterlimit: 3 }</style>
<defs id="Markers">	<g id="lend4">		<path d="M 2 1 L 0 0 L 2 -1 L 2 1 " style="stroke:none"></path>	</g>	<marker id="mrkr4-14" class="st5" v:arrowtype="4" v:arrowsize="2" v:setback="6.68" refx="-6.68" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend4" transform="scale(-3.52,-3.52) "></use>	</marker>	<marker id="mrkr4-30" class="st5" v:arrowtype="4" v:arrowsize="2" v:setback="0" refx="0" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend4" transform="scale(3.52) "></use>	</marker>	<marker id="mrkr4-35" class="st8" v:arrowtype="4" v:arrowsize="2" v:setback="7.04" refx="7.04" orient="auto" markerunits="strokeWidth" overflow="visible">		<use xlink:href="#lend4" transform="scale(3.52) "></use>	</marker></defs><g v:mid="1" v:index="1" v:groupcontext="backgroundPage">	<v:userdefs>		<v:ud v:nameu="msvVisioCreated" v:prompt="" v:val="VT0(0):26"></v:ud>	</v:userdefs>	<title>VBackground-1</title>	<v:pageproperties width="6.821" height="4.50438" v:drawingscale="0.0393701" v:pagescale="0.0393701" v:drawingunits="24" v:shadowoffsetx="8.50394" v:shadowoffsety="-8.50394"></v:pageproperties>	<g id="shape1-1" v:mid="1" v:groupcontext="shape" transform="translate(0,-0.00018)">		<title>Solid</title>		<v:userdefs>			<v:ud v:nameu="Background" v:val="VT0(0):26"></v:ud>			<v:ud v:nameu="visVersion" v:val="VT0(15):26"></v:ud>			<v:ud v:nameu="msvShapeCategories" v:prompt="" v:val="VT4(DoNotContain)"></v:ud>			<v:ud v:nameu="msvVisioCreated" v:prompt="" v:val="VT0(0):26"></v:ud>		</v:userdefs>		<rect x="0" y="0.00036" width="491.112" height="324.315" class="st1"></rect>	</g></g><g v:mid="0" v:index="2" v:groupcontext="foregroundPage">	<title>Page-1</title>	<v:pageproperties v:drawingscale="0.0393701" v:pagescale="0.0393701" v:drawingunits="24" v:shadowoffsetx="8.50394" v:shadowoffsety="-8.50394"></v:pageproperties>	<g id="shape1-3" v:mid="1" v:groupcontext="shape" transform="translate(25.871,-25.8703)">		<title>Rectangle</title>		<v:userdefs>			<v:ud v:nameu="visVersion" v:val="VT0(15):26"></v:ud>		</v:userdefs>		<rect x="0" y="51.7414" width="127.559" height="272.574" class="st2"></rect>		<rect x="0" y="51.7414" width="127.559" height="272.574" class="st3"></rect>	</g>	<g id="shape2-6" v:mid="2" v:groupcontext="shape" transform="translate(337.682,-25.8703)">		<title>Rectangle.2</title>		<v:userdefs>			<v:ud v:nameu="visVersion" v:val="VT0(15):26"></v:ud>		</v:userdefs>		<rect x="0" y="51.7414" width="127.559" height="272.574" class="st2"></rect>		<rect x="0" y="51.7414" width="127.559" height="272.574" class="st3"></rect>	</g>	<g id="shape3-9" v:mid="3" v:groupcontext="shape" transform="translate(153.43,-232.795)">		<title>工作表.3</title>		<path d="M0 324.32 L177.21 324.32 L177.21 324.32 L177.57 324.32" class="st4"></path>	</g>	<g id="shape4-15" v:mid="4" v:groupcontext="shape" transform="translate(153.43,-176.102)">		<title>工作表.4</title>		<path d="M0 324.32 L177.21 324.32 L177.21 324.32 L177.57 324.32" class="st4"></path>	</g>	<g id="shape5-20" v:mid="5" v:groupcontext="shape" transform="translate(153.43,-119.409)">		<title>工作表.5</title>		<path d="M0 324.32 L177.21 324.32 L177.21 324.32 L177.57 324.32" class="st4"></path>	</g>	<g id="shape6-25" v:mid="6" v:groupcontext="shape" transform="translate(153.43,-62.7166)">		<title>工作表.6</title>		<path d="M0 324.32 L6.68 324.32 L7.04 324.32 L184.25 324.32" class="st6"></path>	</g>	<g id="shape7-31" v:mid="7" v:groupcontext="shape" transform="translate(40.0442,-261.147)">		<title>工作表.7</title>		<desc>Controller</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="49.6063" cy="310.142" width="99.22" height="28.3465"></v:textrect>		<path d="M0 324.32 L99.21 324.32 L99.21 295.97 L0 295.97 L0 324.32" class="st7"></path>		<text x="27.02" y="315.13" class="st9" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>控制器</text>		</g>	<g id="shape8-37" v:mid="8" v:groupcontext="shape" transform="translate(366.028,-261.147)">		<title>工作表.8</title>		<desc>Target</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="38.2677" cy="312.268" width="76.54" height="24.0945"></v:textrect>		<path d="M0 324.32 L76.54 324.32 L76.54 300.22 L0 300.22 L0 324.32" class="st7"></path>		<text x="23.21" y="317.26" class="st9" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>目标</text>		</g>	<g id="shape9-42" v:mid="9" v:groupcontext="shape" transform="translate(74.0599,-225.713)">		<title>工作表.9</title>		<desc>SPI_CS_N</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="39.685" cy="317.229" width="79.38" height="14.1732"></v:textrect>		<path d="M0 324.32 L79.37 324.32 L79.37 310.14 L0 310.14 L0 324.32" class="st7"></path>		<text x="29.03" y="320.83" class="st10" v:langid="1033"><v:paragraph v:horizalign="2"></v:paragraph><v:tablist></v:tablist>SPI_CS_N</text>		</g>	<g id="shape10-47" v:mid="10" v:groupcontext="shape" transform="translate(78.3119,-169.021)">		<title>工作表.10</title>		<desc>SPI_CLK</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="37.5591" cy="317.229" width="75.13" height="14.1732"></v:textrect>		<path d="M0 324.32 L75.12 324.32 L75.12 310.14 L0 310.14 L0 324.32" class="st7"></path>		<text x="32.73" y="320.83" class="st10" v:langid="1033"><v:paragraph v:horizalign="2"></v:paragraph><v:tablist></v:tablist>SPI_CLK</text>		</g>	<g id="shape11-52" v:mid="11" v:groupcontext="shape" transform="translate(54.2174,-109.493)">		<title>工作表.11</title>		<desc>SPI_DATA_MO_SI</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="49.6063" cy="314.394" width="99.22" height="19.8425"></v:textrect>		<path d="M0 324.32 L99.21 324.32 L99.21 304.47 L0 304.47 L0 324.32" class="st7"></path>		<text x="8.69" y="317.99" class="st10" v:langid="1033"><v:paragraph v:horizalign="2"></v:paragraph><v:tablist></v:tablist>SPI_DATA_MO_SI</text>		</g>	<g id="shape12-57" v:mid="12" v:groupcontext="shape" transform="translate(54.2174,-52.7998)">		<title>工作表.12</title>		<desc>SPI_DATA_MI_SO</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="49.6063" cy="314.394" width="99.22" height="19.8425"></v:textrect>		<path d="M0 324.32 L99.21 324.32 L99.21 304.47 L0 304.47 L0 324.32" class="st7"></path>		<text x="8.69" y="317.99" class="st10" v:langid="1033"><v:paragraph v:horizalign="2"></v:paragraph><v:tablist></v:tablist>SPI_DATA_MI_SO</text>		</g>	<g id="shape13-62" v:mid="13" v:groupcontext="shape" transform="translate(337.682,-222.879)">		<title>工作表.13</title>		<desc>SPI_CS_N</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="41.1024" cy="314.394" width="82.21" height="19.8425"></v:textrect>		<rect x="0" y="304.473" width="82.2047" height="19.8425" class="st11"></rect>		<rect x="0" y="304.473" width="82.2047" height="19.8425" class="st12"></rect>		<text x="4" y="317.99" class="st10" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>SPI_CS_N</text>		</g>	<g id="shape14-66" v:mid="14" v:groupcontext="shape" transform="translate(337.682,-166.186)">		<title>工作表.14</title>		<desc>SPI_CLK</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="35.4331" cy="314.394" width="70.87" height="19.8425"></v:textrect>		<rect x="0" y="304.473" width="70.8661" height="19.8425" class="st11"></rect>		<rect x="0" y="304.473" width="70.8661" height="19.8425" class="st12"></rect>		<text x="4" y="317.99" class="st10" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>SPI_CLK</text>		</g>	<g id="shape15-70" v:mid="15" v:groupcontext="shape" transform="translate(337.682,-109.493)">		<title>工作表.15</title>		<desc>SPI_DATA_MO_SI</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="49.6063" cy="314.394" width="99.22" height="19.8425"></v:textrect>		<rect x="0" y="304.473" width="99.2126" height="19.8425" class="st11"></rect>		<rect x="0" y="304.473" width="99.2126" height="19.8425" class="st12"></rect>		<text x="4" y="317.99" class="st10" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>SPI_DATA_MO_SI</text>		</g>	<g id="shape16-74" v:mid="16" v:groupcontext="shape" transform="translate(337.682,-52.0908)">		<title>工作表.16</title>		<desc>SPI_DATA_MI_SO</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="49.6063" cy="313.685" width="99.22" height="21.2598"></v:textrect>		<rect x="0" y="303.056" width="99.2126" height="21.2598" class="st11"></rect>		<rect x="0" y="303.056" width="99.2126" height="21.2598" class="st12"></rect>		<text x="4" y="317.29" class="st10" v:langid="1033"><v:paragraph></v:paragraph><v:tablist></v:tablist>SPI_DATA_MI_SO</text>		</g>	<g id="shape17-78" v:mid="17" v:groupcontext="shape" transform="translate(181.776,-232.8)">		<title>工作表.17</title>		<desc>Chip select active low</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="63.7795" cy="314.394" width="127.57" height="19.8425"></v:textrect>		<rect x="0" y="304.473" width="127.559" height="19.8425" class="st11"></rect>		<rect x="0" y="304.473" width="127.559" height="19.8425" class="st12"></rect>		<text x="21.78" y="318.39" class="st13" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>片选低电平有效</text>		</g>	<g id="shape18-82" v:mid="18" v:groupcontext="shape" transform="translate(187.744,-176.107)">		<title>工作表.18</title>		<desc>Clock</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="56.6929" cy="317.229" width="113.4" height="14.1732"></v:textrect>		<rect x="0" y="310.142" width="113.386" height="14.1732" class="st11"></rect>		<rect x="0" y="310.142" width="113.386" height="14.1732" class="st12"></rect>		<text x="44.69" y="321.22" class="st13" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>时钟</text>		</g>	<g id="shape19-86" v:mid="19" v:groupcontext="shape" transform="translate(181.776,-119.414)">		<title>工作表.19</title>		<desc>Data</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="59.5276" cy="317.229" width="119.07" height="14.1732"></v:textrect>		<rect x="0" y="310.142" width="119.055" height="14.1732" class="st11"></rect>		<rect x="0" y="310.142" width="119.055" height="14.1732" class="st12"></rect>		<text x="47.53" y="321.22" class="st13" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>数据</text>		</g>	<g id="shape20-90" v:mid="20" v:groupcontext="shape" transform="translate(181.776,-62.7214)">		<title>工作表.20</title>		<desc>Data</desc>		<v:userdefs></v:userdefs>		<v:textblock v:margins="rect(4,4,4,4)" v:tabspace="42.5197"></v:textblock>		<v:textrect cx="58.8189" cy="317.229" width="117.64" height="14.1732"></v:textrect>		<rect x="0" y="310.142" width="117.638" height="14.1732" class="st11"></rect>		<rect x="0" y="310.142" width="117.638" height="14.1732" class="st12"></rect>		<text x="46.82" y="321.22" class="st13" v:langid="1033"><v:paragraph v:horizalign="1"></v:paragraph><v:tablist></v:tablist>数据</text>		</g></g>
</svg>

SPI 核心支持双向 SPI 标准、点对点和控制器-目标协议。SPI 核心使用四条片选线路(<var class="keyword varname">SPI_CS#_N</var>)来选择进行通信的目标设备。以下两条数据线路支持双向数据传输。
- SPI\_DATA\_MO\_SI：控制器数据输出，目标数据输入。
- SPI\_DATA\_MI\_SO：控制器数据输入，目标数据输出。

| 数据信号 | MOSI：控制器数据输出，目标数据输入。 |
| --- | --- |
| 数据信号 | MISO：控制器数据输入，目标数据输出。 |
| 控制信号 | SCLK：由控制器生成并输入所有目标的时钟。 |
| 控制信号 | CS：片选，当控制器置位其 <var class="keyword varname">CS_N</var> 信号时选择目标。 |
|  |  |

## SPI 特性

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节介绍了 SPI 串行引擎传输模式以及使用每种模式的不同场景。此外，还介绍各种子系统 SPI 驱动程序中支持的 FIFO 和 DMA。

Table : SPI 传输模式

| 子系统 | 传输方式 | 说明 |
| :--- | :--- | :--- |
| Linux | <ul class="ul" id="spi_features__ul_xkv_gyg_rcc"><br>                                    <li class="li">FIFO（低速）</li><br><br>                                    <li class="li">CPU DMA（高速）</li><br><br>                                    <li class="li">GSI</li><br><br>                                </ul> | 支持最大 50 MHz 的配置速度。 |
| Boot | FIFO | <ul class="ul" id="spi_features__ul_xcm_cjh_rcc"><br>                                    <li class="li">传输速率最高 50 MHz。主机根据请求的频率设置最接近的 SPI 时钟频率。</li><br><br>                                    <li class="li">每字传输 4 位到 32 位。</li><br><br>                                    <li class="li">每条总线最多有 4 个片选 (CS)。</li><br><br>                                    <li class="li">boot 中不支持 GSI 模式。</li><br><br>                                    <li class="li">驱动程序以轮询模式执行。</li><br><br>                                </ul> |
| aDSP | <ul class="ul" id="spi_features__ul_qh1_gjh_rcc"><br>                                    <li class="li">全双工 </li><br><br>                                    <li class="li">半双工</li><br><br>                                    <li class="li">同步之比较</li><br><br>                                    <li class="li">串行通讯</li><br><br>                                </ul> | <ul class="ul" id="spi_features__ul_u4m_jjh_rcc"><br>                                    <li class="li">没有显式的通信组帧、错误校验或定义的数据字长。 </li><br><br>                                    <li class="li">完全是原始位级别的通信。</li><br><br>                                    <li class="li">传输速率最高 50 MHz。主机根据请求的频率设置最接近的 SPI 时钟频率。</li><br><br>                                    <li class="li">每字传输 4 位到 32 位。</li><br><br>                                    <li class="li">每条总线最多有 4 个片选 (CS)。</li><br><br>                                </ul> |

## SPI 接口

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节提供有关子系统驱动程序、内核设备树节点和相关文档的信息。

Table : SPI 接口：Linux

| 文件类型 | 说明 |
| --- | --- |
| 设备树源 | <ul class="ul" id="spi_interface__ul_ysx_dgf_ncc"><br>                                    <li class="li">QCS6490 和 QCS5430：<a href="https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi" target="_blank" class="xref cursorpointer" onclick="Window.BookmapComponent.navigateExternalFile('https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi')">https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi</a></li><br><br>                                    <li class="li">QCS9075: <a href="https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi" target="_blank" class="xref cursorpointer" onclick="Window.BookmapComponent.navigateExternalFile('https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi')">https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi</a></li><br><br>                                    <li class="li">有关 QUP v3 串行引擎设备节点的信息，可参见内核文档，相关网址如下： <a href="https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/spi/qcom%2Cspi-geni-qcom.yaml" target="_blank" class="xref cursorpointer" onclick="Window.BookmapComponent.navigateExternalFile('https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/spi/qcom%2Cspi-geni-qcom.yaml')">https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/spi/qcom%2Cspi-geni-qcom.yaml</a></li><br><br>                                </ul> |
| `Pinctrl` 设置 | <ul class="ul" id="spi_interface__ul_o3f_rkf_ncc"><br>                                    <li class="li">QCS6490 和 QCS5430：<a href="https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi" target="_blank" class="xref cursorpointer" onclick="Window.BookmapComponent.navigateExternalFile('https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi')">https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi</a></li><br><br>                                    <li class="li">QCS9075: <a href="https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi" target="_blank" class="xref cursorpointer" onclick="Window.BookmapComponent.navigateExternalFile('https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi')">https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi</a></li><br><br>                                </ul> |
| TEE 设置 | <ul class="ul" id="spi_interface__ul_hxy_tp3_vdc"><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/qup_accesscontrol/qupv3/config/&lt;chipset&gt;/QUPAC_Access.c</span></li><br><br>                                </ul> |

Table : SPI 接口：Boot

| 文件类型 | 说明 |
| --- | --- |
| QUP v3 串行引擎配置 | <ul class="ul" id="spi_interface__ul_fkh_45n_rzb"><br>                                    <li class="li">QUP v3 串行引擎：<span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/BOOT.MXF.1.0.c1/boot_images/boot/Settings/Soc/&lt;chipset&gt;/Core/Buses/qup_common/&lt;chipset&gt;-qupv3.dtsi</span></li><br><br>                                    <li class="li">GPIO 配置：<span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/BOOT.MXF.1.0.c1/boot_images/boot/Settings/Soc/&lt;chipset&gt;/Core/Buses/qup_common/&lt;chipset&gt;-qupv3-pinctrl.dtsi</span></li><br><br>                                </ul> |
| TEE 设置 | <ul class="ul" id="spi_interface__ul_lml_5p3_vdc"><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/qup_accesscontrol/qupv3/config/&lt;chipset&gt;/QUPAC_Access.c</span></li><br><br>                                </ul> |

Table : SPI 接口：aDSP/SLPI/SDC

| 文件类型 | 说明 |
| --- | --- |
| QUP v3 串行引擎配置 | <ul class="ul" id="spi_interface__ul_vds_kvn_rzb"><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_common/config/&lt;chipset&gt;/adsp/ssc/qup_devcfg.c</span></li><br><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_fw/config/&lt;chipset&gt;/fw_devcfg.c</span></li><br><br>                                    <li class="li"><span class="ph filepath">settings/buses/qup_common/config/&lt;chipset&gt;<br>                                            /adsp/ssc/qup_devcfg.json</span></li><br><br>                                </ul> |
| 固件配置设置 | <ul class="ul" id="spi_interface__ul_wpr_p5j_51c"><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_fw/config/&lt;chipset&gt;/fw_devcfg.c</span></li><br><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/ADSP.HT.5.5.c8/adsp_proc/core/settings/buses/qup_fw/config/&lt;chipset&gt;/fw_devcfg.xml</span></li><br><br>                                </ul> |

Table : SPI 接口：TEE

| 文件类型 | 说明 |
| --- | --- |
| QUP v3 串行引擎配置 | <ul class="ul" id="spi_interface__ul_xr2_vvn_rzb"><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/spi/qupv3/config/&lt;chipset&gt;/tz/spi_devcfg_user.c</span></li><br><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/spi/qupv3/config/&lt;chipset&gt;/tz/spi_devcfg_user.h</span></li><br><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/spi/qupv3/config/&lt;chipset&gt;/tz/spi_devcfg.xml</span></li><br><br>                                </ul> |
| TEE 设置 | <ul class="ul" id="spi_interface__ul_ekb_vp3_vdc"><br>                                    <li class="li"><span class="ph filepath">/firmware/qualcomm-linux-spf-1-0_ap_standard_oem_nomodem/TZ.XF.5.0/trustzone_images/core/settings/buses/qup_accesscontrol/qupv3/config/&lt;chipset&gt;/QUPAC_Access.c</span></li><br><br>                                </ul> |

### SPI API

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节列出了以下子系统的 SPI API。
- Linux：
    - [https://github.com/torvalds/linux/blob/master/include/uapi/linux/spi/spidev.h](https://github.com/torvalds/linux/blob/master/include/uapi/linux/spi/spidev.h).
    - [https://github.com/torvalds/linux/blob/master/include/linux/spi/spi.h](https://github.com/torvalds/linux/blob/master/include/linux/spi/spi.h).
- Boot：boot\_images/boot/QcomPkg/Include/SpiApi.h
- aDSP/SDC: adsp\_proc/core/api/buses/spi\_api.h

## SPI 软件

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节提供有关 SPI 设备树配置和设备节点文档的信息。

### Linux

关于设备 SPI 详细信息，请参阅以下 DTSI 文件。
- QCS6490 和 QCS5430：[https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi](https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi)
- QCS9075: [https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi)

有关特定于 SPI 设备节点的内核文档的更多信息，可访问 [https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/spi/qcom%2Cspi-geni-qcom.yaml](https://github.com/torvalds/linux/blob/master/Documentation/devicetree/bindings/spi/qcom%2Cspi-geni-qcom.yaml)。SPI 驱动程序文件位于 [https://github.com/torvalds/linux/blob/master/drivers/spi/spi-geni-qcom.c](https://github.com/torvalds/linux/blob/master/drivers/spi/spi-geni-qcom.c)。

    spi@a98000 {
    compatible = "qcom,geni-spi";
    reg = <0 0x00a98000 0 0x4000>;
    clocks = <&gcc GCC_QUPV3_WRAP1_S6_CLK>;
    clock-names = "se";
    pinctrl-names = "default";
    pinctrl-0 = <&qup_spi14_data_clk>, <&qup_spi14_cs>;
    interrupts = <GIC_SPI 368 IRQ_TYPE_LEVEL_HIGH>;
    #address-cells = <1>;
    #size-cells = <0>;
    power-domains = <&rpmhpd SC7280_CX>;
    operating-points-v2 = <&qup_opp_table>;
    interconnects = <&clk_virt MASTER_QUP_CORE_1 0 &clk_virt SLAVE_QUP_CORE_1 0>,	<&gem_noc MASTER_APPSS_PROC 0 &cnoc2 SLAVE_QUP_1 0>;
    interconnect-names = "qup-core", "qup-config";	dmas = <&gpi_dma1 0 6 QCOM_GPI_SPI>,       <&gpi_dma1 1 6 QCOM_GPI_SPI>;
    dma-names = "tx", "rx";
    status = "disabled";
    };Copy to clipboard

有关特定于 GPIO `pinctrl`配置的内核文档，请参阅以下文件。
- QCS6490 和 QCS5430：[https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi](https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi)
- QCS9075: [https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi)
- Documentation/devicetree/bindings/pinctrl/qcom,&lt;chipset&gt;-tlmm.yaml

QUP v3 串行引擎 GPIO 的相应配置存在并映射到 pinctrl.dtsi 文件中。

例如：

    qup_spi14_data_clk: qup-spi14-data-clk-state {			pins = "gpio56", "gpio57", "gpio58";			function = "qup16";		};
    		qup_spi14_cs: qup-spi14-cs-state {			pins = "gpio59";			function = "qup16";		};
    		qup_spi14_cs_gpio: qup-spi14-cs-gpio-state {			pins = "gpio59";			function = "gpio";		};
    		qup_spi15_data_clk: qup-spi15-data-clk-state {			pins = "gpio60", "gpio61", "gpio62";			function = "qup17";		};Copy to clipboard

在位于 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/TZ.XF.5.0/trustzone\_images/core/settings/buses/qup\_accesscontrol/qupv3/config/&lt;chipset&gt;/QUPAC\_Access.c 的文件中确保特定串行引擎的协议配置采用 SPI 协议。根据需要修改所需的设置，或者参考针对 QUP v3 串行引擎实例分配的默认设置。

以下是用于启用 SPI 的配置示例。

    { QUPV3_0_SE3, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // CAN SPI
    { QUPV3_1_SE3, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_FIFO, AC_HLOS,            FALSE, TRUE,  TRUE }, // LS1 SPI
    { QUPV3_1_SE4, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_GSI,  AC_TZ,              FALSE, TRUE,  TRUE }, // SPI -NFC ESE
    { QUPV3_1_SE6, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_GSI,  AC_HLOS,            FALSE, TRUE,  FALSE}, // FP
    { QUPV3_SSC_SE2, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_GSI, AC_ADSP_Q6_ELF,  FALSE,      FALSE, FALSE }, // IMU_SPICopy to clipboard

### Boot

根据 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/BOOT.MXF.1.0.c1/boot\_images/boot/Settings/Soc/&lt;chipset&gt;/Core/Buses/qup\_common/&lt;chipset&gt;-qupv3.dtsi 文件中的 Qualcomm Linux 芯片产品要求配置 QUP v3 设置。

注释： 请将 QUP v3 包装器节点状态更新为 `okay`，并将相应的串行引擎节点更新为 `disabled` 状态，以便启用所需的 QUP v3 串行引擎。

以下示例节点有助于在 boot 中配置 QUP v3 串行引擎。

**QUP 包装器节点示例**

           /* QUPV3_0  wrapper  instance */
        TOP_QUP_0{ 
            compatible = "qcom,qup-controller";
            qup_id                      = /bits/  8 <(QUP_0)>;
            core_base_addr              = <QUPV3_0_CORE_BASE_ADDRESS>;
            common_base_addr            = <(QUPV3_0_CORE_COMMON_BASE_ADDRESS)>;
            se_wrapper_base_addr        = <(QUPV3_0_CORE_SE_BASE_ADDRESS)>;
            core_frequency              = <100000000>;
            qup_flags                   = <(QUP_FLAGS_UNUSED)>;
            num_se                      = /bits/ 8 <8>;
            status                      = "okay"; 
    Copy to clipboard

**串行引擎实例的示例节点**

    /*TOP_QUP_0_SE_0  Instance */ 
            TOP_QUP_0_SE_0{
              status                      = "disabled";  (updated to okay if you need the instance to be enabled)
                core_offset                 = <0x00000000>;
                se_flags                    = <(USES_DDR_BUFFER | USES_INTERNAL_DDR_MEM | ENABLE_FATAL_ON_TIMEOUT | POLLED_MODE)>;
                se_index                    = /bits/  8 <0>;
                FIFO_MODE                   = /bits/  8 <1>;
                protocol_supported          = <(I2C_SUPPORTED | UART_SUPPORTED | SPI_SUPPORTED)>;
                interface_supported         = <CORE_IRQ>;
               * gpi_index                   = /bits/ 8 <0xFF>;
                core_irq                    = /bits/ 16 <0>;
                pdc_irq                     = /bits/ 16 <0>;
                gpio_int_num                = /bits/ 16 <0>;
                i2c_hub                     = /bits/ 8  <0>;
                i2c_mm                      = /bits/ 16 <0>;
                SE_EXCLUSIVE                = /bits/  8 <1>;
                pinctrl-names               = "i2c-default", "i2c-sleep","spi-default", "spi-sleep","uart-default", "uart-sleep";
                pinctrl-0                   = <&top_qup0_se0_i2c_active>;
                pinctrl-1                   = <&top_qup0_se0_i2c_sleep>;
                pinctrl-2                   = <&top_qup0_se0_spi_active>;
                pinctrl-3                   = <&top_qup0_se0_spi_sleep>;
                pinctrl-4                   = <&top_qup0_se0_uart_active>;
                pinctrl-5                   = <&top_qup0_se0_uart_sleep>;
    
                se_clock                    = "gcc_qupv3_wrap0_s0_clk";
            };
    Copy to clipboard

关于 `pinctrl` 定义，请参阅 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/BOOT.MXF.1.0.c1/boot\_images/boot/Settings/Soc/&lt;chipset&gt;/Core/Buses/qup\_common/&lt;chipset&gt;-qupv3-pinctrl.dtsi 处的 GPIO 配置文件。

示例 GPIO 配置：

    #define top_qup0_se1_i2c_active_cfg  GPIO_CFG(GPIO_INPUT,GPIO_PULL_UP,GPIO_DRIVE_STRENGTH(200),GPIO_STRONG_PULL)Copy to clipboard

- 当要求与默认配置不同时，请在 `<chipset>-qupv3-pinctrl.dtsi` 中使用 GPIO 配置修改宏。
- 关于宏定义，请参阅 Settings/Include/gpio-dt.h 处的头文件路径。

替换示例 TLMM 节点中的宏。

      /*TOP_QUP0_se1_pinctrl*/
        top_qup0_se1_i2c_active: top_qup0_se1_i2c_active{
        --    config = <&qup0_l0_1 top_qup_i2c_active_cfg>,
                     <&qup0_l1_1 top_qup_i2c_active_cfg>;
       ++  config = <&qup0_l0_1 top_qup0_se1_i2c_active_cfg>,
                     <&qup0_l1_1 top_qup0_se1_i2c_active_cfg>;
        };
    Copy to clipboard

注释： 在更改统一可扩展固件接口 (UEFI) 配置之前验证 TEE 设置。确保串行引擎节点处于 FIFO\_MODE，并且可供应用处理器访问。验证加载的协议是否符合要求。

### aDSP/SDC

在 aDSP 子系统的启动序列期间，将执行 SSC QUP 的固件加载。配置文件位于在 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/ADSP.HT.5.5.c8/adsp\_proc/core/settings/buses/qup\_fw/config/&lt;chipset&gt;/fw\_devcfg.c 和 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/ADSP.HT.5.5.c8/adsp\_proc/core/settings/buses/qup\_fw/config/&lt;chipset&gt;/fw\_devcfg.xml 的 aDSP 编译版本中。

以下配置是向 SSC QUP SE4 中加载 SPI 固件的示例。

    se_cfg se4_cfg = { 0x90000, SE_PROTOCOL_SPI,   	GSI,     TRUE, TRUE };Copy to clipboard

**GPIO 配置**：QUP 通用驱动中的每个串行引擎都配置了默认的 GPIO 配置。QUP 通用驱动程序根据 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/ADSP.HT.5.5.c8/adsp\_proc/core/settings/buses/qup\_common/config/&lt;chipset&gt;/adsp/ssc/qup\_instance\_mapping.c 处串行引擎中加载的协议获取 GPIO 配置。

可按照如下所示覆盖默认 GPIO 配置。

    {      .instance_id          =  5 ,         //Instance ID
            .qup              =  QUP_SSC,    //QUP Type
            .se_index         =  4,          //SE ID
            .se_data          =  NULL,       //devcfg_map
            .protocol_io_cfg  =  {
                                    TLMM_MAP(TLMM_GPIO_KEEPER ,TLMM_GPIO_2MA,TLMM_GPIO_KEEPER ),              //SLEEP CFG
                                    TLMM_MAP(TLMM_GPIO_NO_PULL,TLMM_GPIO_6MA,TLMM_GPIO_KEEPER ),              //SPI CFG
                                    TLMM_MAP(TLMM_GPIO_NO_PULL,TLMM_GPIO_2MA,TLMM_GPIO_NO_PULL),              //UART CFG
                                    TLMM_MAP(TLMM_GPIO_PULL_UP,TLMM_GPIO_2MA,TLMM_GPIO_NO_PULL),              //I2C CFG
                                    TLMM_MAP(TLMM_GPIO_PULL_UP,TLMM_GPIO_2MA,TLMM_GPIO_KEEPER )               //I3C CFG
                                 },
            .se_exclusive     =  TRUE,
    }
    Copy to clipboard

TLMM\_MAP 是用于初始化工作和休眠状态 GPIO 配置的宏。以下为 TLMM\_MAP 宏的使用示例。

    TLMM_MAP (active state pull type, drive strength, sleep state pull type)Copy to clipboard

### TEE

QUP v3 访问配置设置位于 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/TZ.XF.5.0/trustzone\_images/core/settings/buses/spi/qupv3/interface/spi\_devcfg.h。

要在 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/TZ.XF.5.0/trustzone\_images/core/settings/buses/spi/qupv3/config/&lt;chipset&gt;/tz/spi\_devcfg\_user.h 中启用 SPI 的 QUP v3 串行引擎，请添加 `#define TZ_USE_SPI_X`（<var class="keyword varname">X</var> 是 SPI 串行引擎编号），如下所示。

    #define TZ_USE_SPI_13 //NFC-eseCopy to clipboard

    #define TZ_USE_SPI_14 //Touch-SPICopy to clipboard

    #define TZ_USE_SPI_15 //FP sensorCopy to clipboard

`TZ_USE_SPI_<num>` 编号基于串行引擎的序列号（从 1 开始）。例如，如果有两个 QUP： QUPV3\_0（具有七个串行引擎）和 QUPV3\_1（具有八个串行引擎），则用户必须启用 QUPV3\_2\_SE2。宏应为 TZ\_USE\_SPI\_9。

**GPIO 配置**：在以下示例中，根据 MISO 的 PIN 起始索引在 settings/buses/spi/qupv3/config/&lt;chipset&gt;/tz/spi\_devcfg\_user.c 处配置驱动器强度和上下拉。

    spi_plat_device_config_user spi_device_user_config_0 =
     
        {2,2,2,2,-1,-1,-1},    //.drive_strength index: 0 - MISO, 1 - MOSI, 2 - SCLK, 3 - CS_0, 4- CS_1, 5- CS_2, 6- CS_3
                                    	                 value: 0 - 2MA, 1 - 4MA, 2 - 6MA
        {1,1,0,1,-1,-1,-1},    //.pull index: 0 - MISO, 1 - MOSI, 2 - SCLK, 3 - CS_0, 4- CS_1, 5- CS_2, 6- CS_3
                                    value: 0 - NO_PULL, 1 = PULL_DOWN, 2 = KEEPER, 3 = PULL_UP
        0xFF,                 //.gpii_idx 
        0,                   //.mode_select  not supported for TZ
        0,                   //.flags not supported for TZ
    };
    Copy to clipboard

TEE 子系统的访问控制权限在 /firmware/qualcomm-linux-spf-1-0\_ap\_standard\_oem\_nomodem/TZ.XF.5.0/trustzone\_images/core/settings/buses/qup\_accesscontrol/qupv3/config/&lt;chipset&gt;/QUPAC\_Access.c 的 QUPAC 策略中配置。

    const QUPv3_se_security_permissions_type qupv3_perms_iot_rb3[] =
    {
      /*   PeriphID,         ProtocolID,               Mode,  NsOwner,       bAllowFifo, bLoad, bModExcl  */
      { QUPV3_0_SE0, QUPV3_PROTOCOL_I2C,     QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // LT9611 and QPS615 I2C
      { QUPV3_0_SE1, QUPV3_PROTOCOL_I2C,     QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // APPS I2C - PCIE/ USB Type C
      { QUPV3_0_SE2, QUPV3_PROTOCOL_I2C,     QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // SMB / LS1 I2C
      { QUPV3_0_SE3, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // CAN SPI
      { QUPV3_0_SE4, QUPV3_PROTOCOL_UART_4W, QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // LS1 UART
      { QUPV3_0_SE5, QUPV3_PROTOCOL_UART_2W, QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  FALSE, FALSE }, // Debug UART
      { QUPV3_0_SE6, QUPV3_PROTOCOL_UART_2W, QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // WLAN UART
      { QUPV3_0_SE7, QUPV3_PROTOCOL_UART_4W, QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // Hastings BT
      { QUPV3_1_SE0, QUPV3_PROTOCOL_SPMI,    QUPV3_MODE_FIFO, AC_ADSP_Q6_ELF,     TRUE,  TRUE,  FALSE }, // QuP SPMI
      { QUPV3_1_SE1, QUPV3_PROTOCOL_I2C,     QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // NFC I2C
      { QUPV3_1_SE2, QUPV3_PROTOCOL_I2C,     QUPV3_MODE_FIFO, AC_HLOS,            TRUE,  TRUE,  FALSE }, // HDMI OUT for VIDEOIOBoard
      { QUPV3_1_SE3, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_FIFO, AC_HLOS,            FALSE, TRUE,  TRUE }, // LS1 SPI
      { QUPV3_1_SE4, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_GSI,  AC_TZ,              FALSE, TRUE,  TRUE }, // SPI -NFC ESE
      { QUPV3_1_SE5, QUPV3_PROTOCOL_I2C,     QUPV3_MODE_GSI,  AC_HLOS,            FALSE, TRUE,  FALSE}, // Legacy Touch
      { QUPV3_1_SE6, QUPV3_PROTOCOL_SPI,     QUPV3_MODE_GSI,  AC_HLOS,            FALSE, TRUE,  FALSE}, // FP
      /*QUPV3_1_SE7*/
    };Copy to clipboard

## SPI 启动

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节介绍如何启用 Qualcomm Linux SPI 驱动程序。

### Linux

要验证与设备的 SPI 通信，必须启用内核配置。`CONFIG_SPI_SPIDEV=m` 设置在相应的 `<chipset> defconfig` 文件中启用。启用内核设备树中的特定 QUP v3 SPI 串行引擎实例。

## SPI 配置

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节提供有关 SPI 软件驱动程序内核配置和设备树节点更改的信息。

### Linux

需要以下驱动程序内核配置才能支持 SPI 接口。
- 驱动程序源文件，位于[https://github.com/torvalds/linux/blob/master/drivers/spi/spi-geni-qcom.c](https://github.com/torvalds/linux/blob/master/drivers/spi/spi-geni-qcom.c)
- 内核 `defconfig` 文件位于 &lt;workspace\_path\_of\_LINUX\_kernel\_image&gt;/sources/kernel
                            /kernel\_platform/kernel/arch/arm64/configs/qcom\_defconfig

必须启用以下内核配置。
- `CONFIG_QCOM_GENI_SE=y`
- `CONFIG_SPI_QCOM_GENI=m`
- `CONFIG_SPI_SPIDEV=m` 用于配置用户空间应用程序
- `CONFIG_QCOM_GPI_DMA=m` 用于启用 GSI 支持

要启用 SPI 节点进行环回验证，需对 /arch/arm64/boot/dts/qcom/&lt;chipset&gt;.dtsi 文件应用以下补丁。

    diff --git a/arch/arm64/boot/dts/qcom/<chipset>.dtsi b/arch/arm64/boot/dts/qcom/<chipset>.dtsi
    index 82dfa3e..344e99a 100644
    --- a/arch/arm64/boot/dts/qcom/<chipset>.dtsi
    +++ b/arch/arm64/boot/dts/qcom/<chipset>.dtsi
    @@ -6760,3 +6760,12 @@
    <GIC_PPI 10 IRQ_TYPE_LEVEL_LOW>;
     };
     };
    +
    +&spi14 {
    +        status = "ok";
    +        spidev@0 {
    +                compatible = "spidev";
    +                spi-max-frequency = <50000000>;
    +                reg = <0>;
    +        };
    +};
    
    diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
    index d13dc15..36d7914 100644
    --- a/drivers/spi/spidev.c
    +++ b/drivers/spi/spidev.c
    @@ -84,7 +84,7 @@
    static LIST_HEAD(device_list);
    static DEFINE_MUTEX(device_list_lock);
     
    -static unsigned bufsiz = 4096;
    +static unsigned bufsiz = 35000;
    module_param(bufsiz, uint, S_IRUGO);
    MODULE_PARM_DESC(bufsiz, "data bytes in biggest supported SPI message");
     
    @@ -742,6 +742,7 @@
     	{ .compatible = "semtech,sx1301", .data = &spidev_of_check },
     	{ .compatible = "silabs,em3581", .data = &spidev_of_check },
     	{ .compatible = "silabs,si3210", .data = &spidev_of_check },
    +	{ .compatible = "spidev"},
    {},
     };
     MODULE_DEVICE_TABLE(of, spidev_dt_ids);
    Copy to clipboard

注释： 您应该编译内核配置和设备树更改。内核编译完成后，可以将镜像加载至设备上来验证接口。关于接口验证的信息，请参阅 [SPI 验证](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html#spi_verification) 部分。

## SPI 验证

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节介绍 SPI 驱动程序的验证步骤和测试结果。

### Linux

要交叉编译 SPI 工具，应按照以下步骤操作。
1. 从 yocto/build-qcom-wayland/tmp-glibc/work-shared/&lt;chipset&gt;/kernel-source/tools/spi 访问 SPI 工具。有关 SPI 工具的更多详细信息，可访问 [https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/spi](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/tools/spi)。
2. 安装交叉编译器。

        sudo apt-get install gcc-aarch64-linux-gnuCopy to clipboard
3. 通过运行以下命令搭建交叉编译环境。

        export ARCH=arm64export CROSS_COMPILE=aarch64-linux-gnu-Copy to clipboard
4. 通过运行以下命令编译工具。

        makeCopy to clipboard

### 验证 SPI 设备

通过在 SSH shell 中检查 `dev` 节点 (`/dev/spidev1.0`) 来验证驱动程序。

1. 请执行以下操作，以便验证 SPI 驱动程序：
    1. 以 Permissive 模式打开 SSH shell。有关如何运行 SSH 的详细信息，请参阅[使用 SSH](https://docs.qualcomm.com/bundle/publicresource/topics/80-70017-254/how_to.html) 部分。
    2. 安装文件系统。

            mount -o remount,rw /usrCopy to clipboard
    3. 使用 SCP 或类似工具传输文件。关于 SSH 操作的详细信息，请参阅 [使用 SSH](https://docs.qualcomm.com/bundle/publicresource/topics/80-70017-254/how_to.html) 部分。
        例如， `scp spidev_test
                                root@10.92.175.138:/bin`。
    4. 分配执行权限。

            chmod 777 spidev_testCopy to clipboard
2. 验证 SPI 设备。命令格式 `./spidev_test -D
                        /dev/<spidev_node>`

        ./spidev_test -D /dev/spidev1.0
        ./spidev_test -D /dev/spidev3.0
        Copy to clipboard

随即显示以下输出。

        spi mode: 0x0
        bits per word: 8
        max speed: 500000 Hz (500 KHz)Copy to clipboard

运行以下命令可获得使用信息。

    ./spidev_test -helpCopy to clipboard

随即显示以下输出。

    -D --device   device to use (default /dev/spidev1.1)
    -s --speed    max speed (Hz)
    -d --delay    delay (usec)
    -b --bpw      bits per word
    -i --input    input data from a file (e.g. "test.bin")
    -o --output   output data to a file (e.g. "results.bin")
    -l --loop     loopback
    -H --cpha     clock phase
    -O --cpol     clock polarity
    -L --lsb      least significant bit first
    -C --cs-high  chip select active high
    -3 --3wire    SI/SO signals shared
    -v --verbose  Verbose (show tx buffer)
    -p  Send data (e.g. "1234\xde\xad")
    -N --no-cs    no chip select
      -R --ready    slave pulls low to pause
      -2 --dual     dual transfer
      -4 --quad     quad transfer
      -8 --octal    octal transfer
      -S --size     transfer size
      -I --iter     iterationsCopy to clipboard

## SPI 调试

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

本节介绍用于启用 SPI 传输失败日志的 SPI 软件驱动程序的默认日志方法。

### Linux

通过动态调试方法启用 SPI 驱动程序日志。启用 &lt;workspace\_path\_of\_LINUX\_kernel\_image&gt;/sources/kernel/kernel\_platform/kernel/arch/arm64/configs/qcom\_defconfig 中的 `CONFIG_DYNAMIC_DEBUG`，以支持内核驱动程序的动态调试。

请运行以下命令，以便启用并查看内核日志 (`dmesg`) 中的 SPI 驱动程序日志。

    mount -t debugfs none /sys/kernel/debug
    echo -n "file spi-geni-qcom.c +p" > /sys/kernel/debug/dynamic_debug/control
    echo -n "file qcom-geni-se.c  +p" > /sys/kernel/debug/dynamic_debug/control
    echo -n "file spidev.c +p" > /sys/kernel/debug/dynamic_debug/control
    echo -n "file gpi.c +p" > /sys/kernel/debug/dynamic_debug/controlCopy to clipboard

## SPI 示例

Source: [https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html](https://docs.qualcomm.com/doc/80-70017-8SC/topic/spi.html)

有关上游设备树参考的信息，请参阅以下 DTSI 文件。
- QCS6490 和 QCS5430：[https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi](https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/sc7280.dtsi)
- QCS9075: [https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi)

有关 Qualcomm Linux 硬件 SoC 的设备树节点的信息，请参阅以下 DTSI 文件。
- QCS6490 和 QCS5430：[https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts](https://git.linaro.org/kernel-org/linux-next.git/tree/arch/arm64/boot/dts/qcom/qcs6490-rb3gen2.dts)
- QCS9075: [https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi](https://github.com/torvalds/linux/blob/master/arch/arm64/boot/dts/qcom/sa8775p.dtsi)

Last Published: Jan 22, 2025

[Previous Topic
UART](https://docs.qualcomm.com/bundle/publicresource/80-70017-8SC/topics/uart.md) [Next Topic
I2C](https://docs.qualcomm.com/bundle/publicresource/80-70017-8SC/topics/i2c.md)