SPI device access using SPIDEV
I think that with the Atmel boards, you are supposed to register the devices with the at91_add_device_spi function. It would then be:
at91_add_device_spi(spidev_board_info, ARRAY_SIZE(spidev_board_info));
At least you have to make sure that this function gets called by your board support file board-sam9x5ek.c
so that the SPI master controller gets initialized. If this is done, your above proposed initialization is correct.
stef
Updated on June 13, 2022Comments
-
stef almost 2 years
I want to access an SPI device (an optical mouse device from Avago Tech) on an embedded Linux system using the SPIDEV driver. The device is connected to SPI0.
I enabled SPI and "User mode SPI device driver support" in menuconfig > "Device Drivers" > "SPI".
I added the code to the board.c file
static struct spi_board_info spidev_board_info[] { { .modalias = "spidev", .max_speed_hz = 1000000, .bus_num = 1, .chips_select = 0, .mode = SPI_MODE_3, }, { .modalias = "spidev", .max_speed_hz = 1000000, .bus_num = 1, .chips_select = 1, .mode = SPI_MODE_3, }, }; spi_register_board_info(spidev_board_info, ARRAY_SIZE(spidev_board_info));
I tried both 500000 and 1000000 as max_speed_hz (1Mhz being the highest allowed by the sensor). SPI_MODE_3 is correct, checked on the datasheet. bus_num = 1 should correct as it refers to SPI0 (I also tried = 0 out of curiosity).
I checked the electrical connections and are all working.
The kernel compiles and the image starts correctly, but I cannot find any device in /sys/class/spidev/ (neither in /sys/bus/spi/...). No reference to SPI appears during system boot either.
Any idea on where the problem can be?