Linux,Spidev:为什么不应该直接将其放置在devicetree中? [英] Linux, spidev: why it shouldn't be directly in devicetree?

查看:280
本文介绍了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:为什么它不应该直接位于devicetree中?

spidev: why it shouldn't be directly in devicetree?

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

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

马克·布朗写道:

因为spidev是Linux如何控制设备而不是控制设备的详细信息 系统中的硬件描述,我们永远不应该有节点 在DT中被描述为"spidev",任何SPI设备都可能是spidev,因此 只是不是有用的描述.

Since spidev is a detail of how Linux controls a device rather than a description of the hardware in the system we should never have a node described as "spidev" in DT, any SPI device could be a spidev so this is just not a useful description.

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

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

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

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

您无需在设备树源中明确使用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" },
     {},
 }



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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆