本文介绍了Linux,Spidev:为什么不应该直接将其放置在devicetree中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想定义一个具有用户模式访问权限的SPI设备,例如 http://linux-sunxi中所述.org/SPIdev

I want to define a SPI device with usermode access, as explained for example in http://linux-sunxi.org/SPIdev

在这些示例之后,我在设备树中添加了以下内容:

Following these examples, I added in the devicetree this :

&ecspi1 {
     .... other stuff ...
    mydev@0 {
       compatible = "spidev";
       spi-max-frequency = <5000000>;
       reg = <2>; /*chipselect*/
    };
};

平台为i.MX6. ecspi1似乎是他们的SPI控制器.然后我确实得到了/dev/spi0.2和/sys/class/spidev/spidev0.2

The platform is i.MX6. ecspi1 seems to be their SPI controller.Then I indeed get /dev/spi0.2 and /sys/class/spidev/spidev0.2

但是在内核跟踪中有一个警告说:

But in kernel trace there's a WARNING saying this:

spidev spi0.2:越野车DT:spidev直接列在DT中

spidev spi0.2: buggy DT: spidev listed directly in DT

那么应该如何描述spidev?正确的语法是什么?

So how else the spidev should be described? What is the right syntax?

推荐答案

设备树应描述主板的硬件,但spidev没有描述/识别任何硬件.

The Device Tree should describe the board's hardware, butspidev does not describe/identify any hardware.

马克·布朗写道:

此内核补丁的原理和解决方法是 https://patchwork.kernel.org/patch/6113191/

The rationale and workaround for this kernel patch is https://patchwork.kernel.org/patch/6113191/

您无需在设备树源中明确使用spidev,而是需要标识您要控制的实际设备,例如

Instead of explicit use of spidev in your Device Tree source, you instead need to identify the actual device that you're controlling, e.g.

     mydev@0 {
-       compatible = "spidev";
+       compatible = "my_spi_device";
        spi-max-frequency = <5000000>;

然后(如Geert Uytterhoeven解释的那样),修改 通过将您设备的兼容值添加到 spidev_dt_ids [] 数组

Then (as Geert Uytterhoeven explains), modify drivers/spi/spidev.c in the kernel source code by adding the compatible value for your device to the spidev_dt_ids[] array

 static const struct of_device_id spidev_dt_ids[] = {
     { .compatible = "rohm,dh2228fv" },
     { .compatible = "lineartechnology,ltc2488" },
     { .compatible = "ge,achc" },
     { .compatible = "semtech,sx1301" },
+    { .compatible = "my_spi_device" },
     {},
 }


本文.
只需将"spidev"兼容的字符串替换为已经存在的适当字符串即可:


An alternate solution, which involves a quick-n-dirty change to just the Device Tree, is suggested by this article.
Simply replace the "spidev" compatible string with a proper string that already does exist:

     mydev@0 {
-       compatible = "spidev";
+       compatible = "rohm,dh2228fv";  /* actually spidev for my_spi_dev */
        spi-max-frequency = <5000000>;

由于"rohm,dh2228fv"已经在 spidev_dt_ids [] 列表中,因此无需对 drivers/spi/spidev.c 进行编辑.

Since "rohm,dh2228fv" is already in the spidev_dt_ids[] list, no edit to drivers/spi/spidev.c is needed.

这篇关于Linux,Spidev:为什么不应该直接将其放置在devicetree中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 18:32