Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12435 Discussions

Altera SPI linux kernel module documentation

Altera_Forum
Honored Contributor II
1,299 Views

Hello, I would like to know if there is a documentation page for the spi_altera linux kernel module.  

 

Currently I am trying to use an Altera SPI(3 Wire Serial) bus master controller on QSYS, bridged under a PCI express interface of a Cyclone IV board. So I wish to access a spi device through the spi master controller firmware on the Cyclone IV board via PCI-E from my Ubuntu x86 PC.  

 

Using my custom kernel module I can successful read and write to an On Chip RAM firmware and some output pins . I have instantiated the altera spi kernel module to access the spi controller through my module, creating the "/sys/class/spi_master/spi0" directory, but I don't know how to use it, so I found out that I need a protocol driver to actually create an /dev/ entry. I tried to configure a spi_board_info on my kernel module and associate the spidev protocol driver, as in: 

 

static struct spi_board_info my_spi_board_info[] = { 

.modalias = "spidev", 

.max_speed_hz = 127551, 

.bus_num = 0, 

.chip_select = 0, 

.mode = SPI_CPOL | SPI_CPHA, 

 

 

but I don't know what to do now, on some examples across the internet I saw people using "spi_register_board_info(my_spi_board_info, ARRAY_SIZE(my_spi_board_info));" on the init part of the spi module instantialization to associate this struct with the controller, that gives the message "undefined reference to spi_register_board_info(..." even when I have the "#include </linux/spi/spi.h>" line. 

 

I tried to associate this with the platform_data, as I saw on other example, as in: 

 

 

static struct spi_board_info my_spi_board_info[] = { 

.modalias = "spidev", 

.max_speed_hz = 127551, 

.bus_num = 0, 

.chip_select = 0, 

.mode = SPI_CPOL | SPI_CPHA, 

 

static struct altera_spi_platform_data my_spi_plat_data = { //<=== 

.pin_cs = 0, 

.board_info = my_spi_board_info, 

.board_size = ARRAY_SIZE(my_spi_board_info), 

 

... 

 

static int my_spi_i2c_init(struct my_device *my_device){ 

 

int status, i; 

 

if (!(my_spi = (struct platform_device *) kzalloc(sizeof(struct platform_device)* ARRAY_SIZE(spi_master_resource),GFP_KERNEL))){ 

status = -ENOMEM; 

return status; 

 

spi_master_resource[0].start = my_device->base_addr_pci + SPI_0_OFFT; 

spi_master_resource[0].end = (spi_master_resource[0].start + SPI_0_SIZE) - 1; 

spi_master_resource[0].flags = IORESOURCE_MEM; 

 

my_spi->name = "spi_altera"; 

my_spi->id = 0; 

my_spi->num_resources = ARRAY_SIZE(spi_master_resource); 

my_spi->resource = spi_master_resource; 

 

my_spi->dev.platform_data = &my_spi_plat_data; //<=== 

 

status = platform_device_register(my_spi); 

 

... 

 

spi = platform_get_drvdata(my_spi); 

 

return status; 

 

 

As I adapted my_spi_plat_data data directly from another spi driver example, of other device, I found nowhere where the struct altera_spi_platform_data is defined,, only that on the official altera kernel module source file spi-altera.c it is used. So the compiler says: 

 

"error : variable 'my_spi_plat_data' has initializer but imcomplete type" 

 

 

How I can use spidev with my spi altera bus controller device, is there any example on how to use it? I must reiterate that I'm not using Linux on NIOS II, but a Linux x86 PC connected to my fpga board through PCI express.
0 Kudos
0 Replies
Reply