[ 0.669149] OF: /soc/spi@401d8000: 无法获取谢谢
针对 S32G3 DSPI_1 无法驱动 GPIO 片选的问题,以下是逐步解决方案:
cs-gpios 属性<&gpio控制器 引脚编号 激活极性>。例如:cs-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>, /* 原生 CS0 */
<&gpio0 3 GPIO_ACTIVE_LOW>, /* 原生 CS3 */
<&gpio0 4 GPIO_ACTIVE_LOW>, /* 原生 CS4 */
<&gpio0 12 GPIO_ACTIVE_LOW>; /* GPIO PC_12 */引脚编号 是否正确。例如,PC_12 的实际 GPIO 编号可能为 (C组编号 * 32) + 12(需参考芯片手册)。num-cs 属性num-cs 必须覆盖所有原生片选 + GPIO 片选。例如,若原生支持 0~4,则:num-cs = <5>; /* 支持 CS0~CS4 + GPIO CS */pinctrl_spi1: spi1grp {
fsl,pins = <
S32G3_PC12_GPIO /* 将 PC_12 设为 GPIO */
... /* 其他 SPI 引脚配置 */
>;
};gpio@40081000 { /* GPIO 控制器 */
...
pc12 {
gpio-hog;
gpios = <12 GPIO_ACTIVE_LOW>;
output-high; /* 初始化为高电平 */
line-name = "spi1-cs-gpio";
};
};cs-gpios 列表末尾。dmesg 查看内核日志,搜索错误信息:dmesg | grep spispi driver rejected cs-gpios 或 invalid GPIO CS。cs_change 属性cs_change = 1,确保片选在传输间保持有效:struct spi_transfer t = {
.tx_buf = tx_data,
.len = len,
.cs_change = 1, /* 保持 CS 有效 */
};spi-cpol 和 spi-cpha:spi-device@3 {
compatible = "vendor,device";
reg = <3>;
spi-max-frequency = <1000000>;
spi-cpol; /* 根据设备要求设置 */
spi-cpha;
};&dspi1 {
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_spi1>;
num-cs = <5>; /* 覆盖 CS0~CS4 */
cs-gpios = <&gpio0 0 GPIO_ACTIVE_LOW>,
<&gpio0 3 GPIO_ACTIVE_LOW>,
<&gpio0 4 GPIO_ACTIVE_LOW>,
<&gpio0 12 GPIO_ACTIVE_LOW>; /* PC_12 作为 GPIO CS */
spi-device@3 {
compatible = "vendor,device";
reg = <3>; /* 对应 cs-gpios 中的第四个条目 */
spi-max-frequency = <1000000>;
};
};
&pinctrl {
pinctrl_spi1: spi1grp {
fsl,pins = <
S32G3_PC12_GPIO /* 确保 PC_12 复用为 GPIO */
S32G3_PA0_DSPI1_SIN /* 其他 SPI 引脚配置 */
S32G3_PA1_DSPI1_SOUT
S32G3_PA2_DSPI1_SCK
>;
};
};通过以上步骤,应能解决 GPIO 片选未被驱动的问题。如仍遇到问题,建议在驱动代码中添加调试打印,跟踪片选切换逻辑。
举报
更多回帖