1、内核自带的SPI相关的驱动文件
项目中有CPU与FPGA进行通信,用到SPI接口:
SPI头文件在:
linux-kernel/include/linux/spi.h
SPI实现在:
linux-kernel/drivers/spi/spi.c omap2_mcspi.c spidev.c
DVS8168开发板在以下文件中初始化SPI:
linux-kernel/arch/arm/mach-omap2/board-ti8168evm.c
上述文件中有:
const struct flash_platform_data ti816x_spi_flash =
{
.type = "w25x32",
.name = "spi_flash",
.parts = ti816x_spi_partitions,
.nr_parts = ARRAY_SIZE(ti816x_spi_partitions),
}; struct spi_board_info __initdata ti816x_spi_slave_info[] =
{
{
.modalias = "m25p80",
.platform_data = &ti816x_spi_flash,
.irq = -,
.max_speed_hz = ,
.bus_num = ,
.chip_select = ,
},
}; static void __init ti816x_spi_init(void)
{
spi_register_board_info(ti816x_spi_slave_info,
ARRAY_SIZE(ti816x_spi_slave_info));
}
修改board-ti8168evm.c 初始化我们自己的SPI设备,如下:
// Dragon add
struct spi_board_info __initdata fpga_spi_slave_info[] = {
{
.modalias = "spidev",
.max_speed_hz = , // 48 Mbps
.bus_num = ,
.chip_select = ,
.mode = SPI_MODE_1,
},
}; // Dragon modified
static void __init ti816x_spi_init(void)
{
spi_register_board_info(fpga_spi_slave_info,
ARRAY_SIZE(fpga_spi_slave_info));
}
2、重新编译内核,同时选择生成spi设备驱动
$ make menuconfig CROSS_COMPILE=arm-none-linux-gnueabi- ARCH=arm
(1)Device drivers -> Memory tech... -> Self-contained --> 取消 support most spi Flash
影响:取消文件(/drivers/mtd/devices/mtd_m25p80.c)
(2)D-evice drivers --> SPI Support --> 勾选 Utilities & Mcspi driver & User mode SPI
影响:加入文件(/drivers/spi/spi_bitbang.c /drivers/spi/omap2_mcspi.c /drivers/spi/spidev.c)
linux-kenel/drivers/spidev.c 实现用户态spi设备驱动的功能
3、编译内核自带spi应用程序,验证SPI功能(注意MISO要与MOSI相连,以实现回环测试)如下:
linux-kenel\Documentation\spi\spidev_test.c
示波器截图,黄色为SCLK,蓝色为MOSI
发送数据与接收数据相同,则说明SPI通信成功!