Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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*/
    };
};

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: buggy DT: spidev listed directly in DT

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

like image 647
ddbug Avatar asked Dec 05 '18 14:12

ddbug


2 Answers

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

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

Mark Brown wrote:

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.

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


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

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>;

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>;

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

like image 82
sawdust Avatar answered Sep 23 '22 04:09

sawdust


To avoid this issue just use linux,spidev instead of spidev:

&spi0 {
    mydev@0 {
       compatible = "linux,spidev";
    };
};
like image 33
Compholio Avatar answered Sep 20 '22 04:09

Compholio