Adding SPI driver to Linux

Forum about Parallella boot process, linux kernel, distros, SD-cards, etc.

Adding SPI driver to Linux

Postby wiegmink » Thu Mar 30, 2017 12:44 pm

Hi all,

I'm trying to add the SPI driver to Linux. It shouldn't be that difficult (other members have done it before), but somehow I have the feeling that I'm either doing something wrong or missing a step (or maybe both). I still need to flash the FSBL to get things working (well not sure I'm using EMIO and a custom component in the PL), but anyway I expect a device to appear in /dev when I perform the following steps.

Kernel configuration:
Code: Select all
       CONFIG_SPI=y
      CONFIG_SPI_MASTER=y
      CONFIG_SPI_AXI_SPI_ENGINE=y
      CONFIG_SPI_BITBANG=y
      CONFIG_SPI_CADENCE=y
      CONFIG_SPI_XCOMM=y
      CONFIG_SPI_AD9250FMC=y
      CONFIG_SPI_XILINX=y
      CONFIG_SPI_ZYNQ_QSPI=y
      CONFIG_SPI_SPIDEV=y


I used http://parallella.org/forums/viewtopic.php?f=48&t=1657&p=10228&hilit=SPI&sid=0ebf5693a58db60dadc033e44999115a&sid=0ebf5693a58db60dadc033e44999115a#p10724 as a guideline for rebuilding the kernel.

DT (used the original headless as base and modified the code as follows):
Code: Select all
                   spi@e0006000 {
                           compatible = "xlnx,zynq-spi-r1p6";
                           reg = <0xe0006000 0x1000>;
                           status = "okay";
                           interrupt-parent = <0x3>;
                           interrupts = <0x0 0x1a 0x4>;
                           clocks = <0x1 0x19 0x1 0x22>;
                           clock-names = "ref_clk", "pclk";
                           #address-cells = <0x1>;
                           #size-cells = <0x0>;
                           is-decoded-cs = <0x0>;
                           num-cs = <0x3>;
   
                     // Added
                     spidev@0 {
                         compatible="spidev";
                         reg = <1>; //chipselect
                         spi-max-frequency= <800000>;
                         bus-num = <1>;
                     };
         };


Now after reboot I would expect a device to appear in /dev ( https://parallella.org/forums/viewtopic.php?f=10&t=382). No messages in the log. I do see that entries are added in /sys:
Code: Select all
lcc@parallella:/sys/devices/soc0/amba/e0006000.spi/spi_master/spi32766/spi32766.1$ ls -l
total 0
-r--r--r-- 1 root root 4096 Mar 30 09:36 modalias
lrwxrwxrwx 1 root root    0 Mar 30 09:36 of_node -> ../../../../../../../firmware/devicetree/base/amba/spi@e0006000/spidev@0
drwxr-xr-x 2 root root    0 Mar 30 09:36 power
drwxr-xr-x 2 root root    0 Mar 30 09:36 statistics
lrwxrwxrwx 1 root root    0 Mar 30 09:36 subsystem -> ../../../../../../../bus/spi
-rw-r--r-- 1 root root 4096 Mar 30 09:36 uevent
lcc@parallella:/sys/devices/soc0/amba/e0006000.spi/spi_master/spi32766/spi32766.1$


I did not make any changes in Linux sources. Is it correct to expect a device to be created in /dev after these steps? You help is appreciated.

Cheers,
Klaas
Cheers,
Klaas
wiegmink
 
Posts: 8
Joined: Mon Mar 13, 2017 10:40 am
Location: Netherlands

Re: Adding SPI driver to Linux

Postby wiegmink » Fri Mar 31, 2017 6:25 am

Hi all,

Pretty sure there wasn't a device when I posted the question. But now there is (maybe it's my eyesight):
Code: Select all
crw------- 1 root root 153,   0 Mar 30 15:10 spidev32766.1


Thanks. I'll continue testing. Question closed.
Cheers,
Klaas
wiegmink
 
Posts: 8
Joined: Mon Mar 13, 2017 10:40 am
Location: Netherlands

Re: Adding SPI driver to Linux

Postby olajep » Sat Apr 01, 2017 8:18 am

Glad you found a solution!
Just wanted to point out that in this case (and many others) there's no need to recompile the kernel. It's sufficient to change the devicetree.
The dtc command can be used to decompile / compile the devicetree.dtb in the boot partition on the sd card
Code: Select all
$ cd /tmp
$ sudo mount /dev/mmcblk0 /mnt
$ cp /mnt/devicetree.dtb .
$ dtc -I dts -O dtb -o devicetree.dtb devicetree.dts
open devicetree.dts in an editor
add your spidev entry (don't forget to set status = "okay" in the parent controller)
$ dtc -I dtb -O dts -o devicetree.dts new.dtb
$ sudo cp new.dtb /mnt/devicetree.dtb .
$ sync
$ sudo umount /mnt
$ reboot


// Ola
_start = 266470723;
olajep
 
Posts: 110
Joined: Mon Dec 17, 2012 3:24 am
Location: Sweden


Return to Linux/U-Boot

Who is online

Users browsing this forum: No registered users and 1 guest