我正在尝试使用 Atmels SAMA5d35 MPU 为 SPI 设备编写 linux 设备驱动程序。 Linux 版本为 4.19.30。
我已经在我的设备树中配置了引脚并将状态设置为“okay”。 之后,引脚按预期改变了模式。那么我的问题是,如何在运行时操作引脚模式?我的 SPI 设备并不总是打开,我的驱动程序也不总是加载。在这种情况下,我希望配置的 SPI 引脚将模式更改为普通 GPIO(用于功耗)。
这是驱动程序的任务,还是可以在设备树中定义的东西,例如当驱动程序未加载时?
我尝试实现一个 pinctrl-0 以将引脚设置为 SPI 模式,然后实现一个 pinctrl-1 以将相同的引脚设置为普通 GPIO。我的想法是在设备驱动程序中的这些引脚配置之间切换,但不幸的是,设备树提示 pinctrl-0 和 pinctrl-1 使用相同的引脚(编译正常,但系统无法启动)。虽然这只是我的逻辑想法。我确信有更正确的方法来完成我上面所说的事情。
spi0: spi@f0004000 {
status = "okay";
ext_adc: ads1258@1 {
compatible = "ti,ads1258";
pinctrl-names = "default", "sleep";
pinctrl-0 = <&pinctrl_spi0_default>;
pinctrl-1 = <&pinctrl_spi0_sleep>;
reg = <1>; /* Hardware chipselect SPI0_NPCS1 */
spi-max-frequency = <16000000>; /* According to datasheet */
start-gpios = <&pioD 5 GPIO_ACTIVE_HIGH>;
drdy-gpios = <&pioD 22 GPIO_ACTIVE_LOW>;
enaadc-gpios = <&pioA 26 GPIO_ACTIVE_HIGH>;
};
};
最佳答案
My question is then, how do I manipulate pinmodes during runtime?
这叫做“运行时 pinmuxing”,在 Documentation/pinctrl.txt 中有描述。 .
但您可能不必这样做。
When that is the case I want the configured SPI pins to change mode to normal GPIOs (for power-consumption).
Is it the drivers task to do that, or is it something one can define in the device tree, when the driver for example is not loaded?
(Atmel/Microchip SoC 的)引脚的默认模式是未分配给任何外设模式,并可用作 GPIO。
所有未分配给外围设备或未被驱动程序作为 GPIO 获取的引脚最终都位于可用 GPIO 池中。
因此,当您的 SPI 驱动程序未成功安装时,它将使用的那些引脚将位于可用 GPIO 池中。
I have tried to implement a pinctrl-0 for setting the pins to SPI mode, and then a pinctrl-1 for setting the same pins to normal GPIOs.
分配供 SPI Controller 使用的引脚是正确的,但据我所知,没有将引脚分配为可用 GPIO 的机制。
您只能在 DT 中定义设备(例如 SPI Controller )所需的属性。
没有用于“替代”分配的机制。
I am sure there is a more correct way to do the things I stated above.
如果您的驱动程序未安装,则不应分配其引脚等资源。 SPI 本应使用的引脚将保持未使用状态,并最终进入可用 GPIO 池(除非其他东西声明/请求其中一个引脚)。
因此,您的 DT 需要简单地定义您的设备使用什么,然后就这样。
如果您仍希望驱动程序修改其引脚状态,请研究 Documentation/pinctrl.txt 中标题为“来自驱动程序的引脚控制请求”的部分。 .
关于linux - 处理从设备树到模块的管脚模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57472313/