SPI ports

Started by KNK, August 24, 2013, 10:26:02 PM

Previous topic - Next topic

KNK

Hello,
i have just started my A20 for a fist time today, so apologies if this a stupid and already answered question, but need to use the SPI ports for my application and can't figure it out or find relevant info while searching the forum or web.
I have looked at the A13 python code, but don't know how/where to find the addresses for the SPI ports of A20 and there is no software section for it at all.
What i need is the values for _SC_PAGESIZE and SW_PORTC_IO_BASE for the code below:

PageSize = sysconf(_SC_PAGESIZE);
PageMask = (~(PageSize-1));

addr_start = SW_PORTC_IO_BASE & PageMask;
addr_offset = SW_PORTC_IO_BASE & ~PageMask;

gpio_map = (void *)mmap(0, PageSize*2, PROT_READ|PROT_WRITE, MAP_SHARED, fd, addr_start);

KNK

Does anyone know how SPI ports should be defined in the fex file ... is the section below correct for UEXT1 (copied from A13 example with small modification) and what it should be for UEXT2

[spi_devices]
spi_dev_num = 2

[spi_board0]
modalias = "spi-sun7i"
max_speed_hz = 100000000
bus_num = 2
chip_select = 0
mode = 0
spi_irq = port:PB04<6><default><default><default>

the problem is that there is no /dev/spi* interface even the driver is compiled in the kernel i.e. not as module

Mouchon

may be look at

[spiX_para]
spi_used = 0


in the fex file where X=0,1,2,3

but you should take care that spi 0 is shared with  uart6 and uart7
and other devices

see http://linux-sunxi.org/A20/PIO

regards

KNK

#3
Yes, i have looked at spiX_para, but there is a different piece of information there. I have also read the board PDF and looked the chip documentation and kernel source code, but ...
This is my first time dealing with embedded Linux systems and it is a bit difficult for me yet to get the whole picture, so maybe i am missing something basic here:

1. I am not sure if the name of the section should be spi_board0 or spi_board1 for spi1, but dmesg shows that it is asking for board0 and as spi0 is set to used = 0 my guess is that spi1 is board0.

2. modalias = "spi-sun7i" ... seems to be OK or i should create different alias for each port?

3. max_speed_hz = 100000000 - i got this from the chip documentation 100MHz max speed, but now i see that in mach/spi.h it is defined as:
/* spi controller just suppport 20Mhz */
#define SPI_MAX_FREQUENCY       80000000
and few lines below "int max_speed_hz;       // 80MHz", so it seems 20MHz is a typo and the max is 80000000 - will change that

4. "bus_num = 2" - don't know where to get the info for it ... should it be the MUX column (i.e. 3 from MUX 3) or bus_num = 1, because it's on PA or something else?

5. chip_select = 0 and mode = 0 are OK, because both UEXT1 and UEXT2 have CS0 exported only and the mode depend on the connected hardware

6. spi_irq - if i understand properly this should be an available/unused EINT pin from PH MUX6 or PI MUX 4

Thanks for your help

  EDIT: (from the kernel module source) looks like bus_num should be 1 for SPI1 (2 for SPI2) and then section name spi_board0 seems logical for the first device
now only IRQ remains unclear - should it be some specific pin or any unused is OK?

KNK

Added to the fex file

[spi_devices]
spi_dev_num = 2

[spi_board0]
modalias = "spi-sun7i"
max_speed_hz = 80000000
bus_num = 1
chip_select = 0
mode = 0
spi_irq = port:PI14<4><default><default><default>

[spi_board1]
modalias = "spi-sun7i"
max_speed_hz = 80000000
bus_num = 2
chip_select = 0
mode = 0
spi_irq = port:PI15<4><default><default><default>

but still no spi in /dev even it is now present in /sys and no errors reported in dmesg:

[    1.800345] [spi-inf] sun7i spi init
[    1.803939] [spi-inf] spi_sun7i_init: spi_used: 0x6
[    1.808857] [spi-inf] sun7i_spi_register_spidev: found 2 spi devices in sys_config
[    1.816446] [spi-inf] boards_num       modalias         max_spd_hz       bus_num  cs   mode
[    1.824813] [spi-inf] 0                spi-sun7i        80000000         1        0    0   
[    1.833166] [spi-inf] 1                spi-sun7i        80000000         2        0    0   
[    1.841526] [spi-inf] sun7i_spi_norflash: Register norflash:at25df641 information OK
[    1.849520] [spi-inf] sun7i_spi_probe: spi1 dma type: dedicate
[    1.855377] [spi-inf] sun7i_spi_probe: spi1 cs bitmap: 0x1
[    1.861120] [spi-inf] sun7i_spi_set_mclk: spi1 source = sata_pll, src_clk = 600000000, mclk 100000000
[    1.870579] [spi-inf] sun7i_spi_probe: reuuimlla's SoC SPI Driver loaded for Bus SPI1 with 2 Slaves at most
[    1.880339] [spi-inf] sun7i_spi_probe: spi1 driver probe succeed, base f0036000, irq 43, dma_id_rx 9, dma_id_tx 25
[    1.890726] [spi-inf] sun7i_spi_probe: spi2 dma type: dedicate
[    1.896573] [spi-inf] sun7i_spi_probe: spi2 cs bitmap: 0x1
[    1.902314] [spi-inf] sun7i_spi_set_mclk: spi2 source = sata_pll, src_clk = 600000000, mclk 100000000
[    1.911731] [spi-inf] sun7i_spi_probe: reuuimlla's SoC SPI Driver loaded for Bus SPI2 with 2 Slaves at most
[    1.921489] [spi-inf] sun7i_spi_probe: spi2 driver probe succeed, base f0038000, irq 44, dma_id_rx 29, dma_id_tx 26


HalfHour

Hi All,
Also using an A20 board, and need to access the SPI1 interface. Having trouble identifying what I need to do to get a user-mode driver working.

KNK

There is no driver for the SPI in the latest kernel (images 3 and 4). The logs above are from the 3.3cb kernel, but still couldn't get it to register in /dev and gave up

KNK

QuoteThe Ultimate A20-OLinuXino #Debian #Linux image done!
And still no SPI support :(

Mouchon

i have a partial (half duplex) spi support kernel working but still need more investigation to enable full duplex support. If needed i can make an image with my wip.

Mouchon

forget to say to have /dev/spidevX.Y

you need to change modalias in your fex file with modalias="spidev"



KNK

Quote from: Mouchon on November 06, 2013, 11:59:12 AM
forget to say to have /dev/spidevX.Y

you need to change modalias in your fex file with modalias="spidev"
I did for the previous image (v3 and v4), but there is just no driver compiled in the kernel.
I have tried to compile the kernel driver from https://github.com/linux-sunxi/linux-sunxi/drivers/spi/spi_sunxi.c but it only supports sun4i and sun5i platforms - no sun7i and there are no changes since when I've tried

Thank you for your suggestion. No need of a full image - the compiled module, git url or just a patch would suffice. I will probably need a full duplex (not sure yet), but may try to extend the driver myself.

WIll-tm

Hi everyone,

I came across this topic several times, looking for a solution to make SPI work on my Cubieboard2 (A20 based).
I finally got it working and made a blog post about it : http://will-tm.com/spi-on-the-cubieboard2/, I think it might be useful if some of you are still looking for way to enable an SPI master on A20 devices.
I also share a precompiled kernel (with modules), script.fex, script.fex, kernel source code and defconfig.

Will.

dave-at-axon

Hi Will,

Thanks for the effort.

I followed your blog and I now have SPI for UEXT1 and 2 on my Android system. Well, it's compiled and they appear as devices as I have not written any test for it yet :)


Mouchon

does it support full duplex ?

WIll-tm

I didn't get a chance to test it, but looking at the source code of the driver, it looks like it does.
I just realized that "full_duplex" and "manual_cs" flags are not parsed from the script.fex but full duplex mode seams to activate itself as long as a write buffer AND a read buffer are given to the spi_ioc_transfer.