Forums » Software Development »
spi1 usage in a custom board
Added by Ehsan Kooh over 10 years ago
Hi everybody.
I am a newby in Linux development. I have my custom board based on MityDSP138F with two ICs attached over SPI bus.
SPI signals (MISO, MOSI, and CLK) are attached to SPI1 bus. Chip Selects signal are attached to pins 53 and 57 and they are used as GPIO.
How I could access my IC devices from my user space program? Should I write my own driver for both the devices?
I read some on driver development and I understood that Linux offer a SPI driver for the controller to drive the physical SPI hardware.
Then the developer should develop its own driver for each of the devices attached to the SPI bus. Finally a custom baseboard file should be written in order to bind the controller driver to the slaves drivers.
If I wrote the specific driver for my device, how could I have access to SPI bus? By simply calling the functions I will implement in the driver?
My need is simply to drive two chip select signals and send some data to the two devices that act both as slaves.
In particular the two ICs are PLLs who need to be configured at the startup of the Mity.
Do you have any suggestion? Or some starting point?
Thank you in advance for all your kind support.
Best.
Ehsan
Replies (3)
RE: spi1 usage in a custom board - Added by Jonathan Cormier over 10 years ago
If they only need to be configured on bootup it might be easier to do it from u-boot. You could try enabling the spi command: CONFIG_CMD_SPI. You could then test your spi commands and could put them as part of the bootcmd variable so they are executed on boot.
Alternatively you could checkout our board/davinci/mityomapl138/config_block.c file. This has commands to talk to both our i2c eeprom and the SPI Nor which you can use as examples.
RE: spi1 usage in a custom board - Added by Ehsan Kooh over 10 years ago
Maybe I was not clear...
I do not want to modify uboot. It works good for me as it is.
I would like to configure our SPI using the linux kernel. As written in the previous post my custom board based on MityDSP138F has two ICs attached over SPI bus. SPI signals (MISO, MOSI, and CLK) are attached to SPI1 bus. Chip Selects signal are attached to pins 53 and 57 and they are used as GPIO.
How can I configure this behavior?
Do I have to modify something in a file in this directory MDK_2013-12-18/sw/ARM/linux/linux-davinci/arch/arm/mach-davinci (e.g baseboard-industrialio.c) before compiling the kernel?
Do I have to write my own driver and include it somewhere?
Could I use spidev userspace for this purpose?
Thanks.
RE: spi1 usage in a custom board - Added by Michael Williamson over 10 years ago
Hello,
Yes, for the 3.2 kernel provided, you need to create (or modify) a baseboard file as you have suggested. If you have a custom board, we recommend you copy the baseboard-industrialio.c file to a new file and modify it to represent the devices and pinmux configuration for your board. If you make a new file, you'll also need to add it to the Makefile in the same folder and update the Kconfig to add a new baseboard option.
For your SPI devices, you will need to make sure all of the pinmuxes are set for the pins in question, and then update the spi device initialization tables. If you want to use spidev (and control your devices in userspace), then you'll need to add an entry for spidev in the spi device initialization tables for each chip select entry. You should be able to do all of this in that one C file.
There should be some examples of spidev in some of the other baseboard-*.c files (custom board files developed for other I/O boards) you should be able to reference.
We can also help generate a kernel/BSP for your board under a small contract if that would be of any use.
-Mike