mini2440移植之SPI驱动

时间:2021-06-06 04:31:11

目标平台:mini2440

内核:linux2.6.32.2

1,修改arch/arm/mach-s3c2440/mach-mini2440.c文件,加入头文件:

#include <linux/spi/spi.h>
#include <../mach-s3c2410/include/mach/spi.h>
然后加入如下代码:
static struct spi_board_info s3c2410_spi0_board[] =
{
[0] = {
.modalias = "spidev",
.bus_num = 0,
.chip_select = 0,
.irq = IRQ_EINT9,
.max_speed_hz = 500 * 1000,
}
};

static struct s3c2410_spi_info s3c2410_spi0_platdata = {
.pin_cs = S3C2410_GPG(2),
.num_cs = 1,
.bus_num = 0,
.gpio_setup = s3c24xx_spi_gpiocfg_bus0_gpe11_12_13,
};

static struct spi_board_info s3c2410_spi1_board[] =
{
[0] = {
.modalias = "spidev",
.bus_num = 1,
.chip_select = 0,
.irq = IRQ_EINT2,
.max_speed_hz = 500 * 1000,
}
};


static struct s3c2410_spi_info s3c2410_spi1_platdata = {
.pin_cs = S3C2410_GPG(3),
.num_cs = 1,
.bus_num = 1,
.gpio_setup = s3c24xx_spi_gpiocfg_bus1_gpg5_6_7,
};
注意:这在2.6.29中可行,但是在2.6.32源代码中没有定义S3C2410_GPG2宏定义,要使用S3C2410_GPG(2)宏定义。移植过程中,尤其要注意,不同内核版本对结构体,函数等表示方法的变化

在mini2440_devices[]平台数组中添加如下代码:

static struct platform_device *mini2440_devices[] __initdata = {
&s3c_device_usb,
&s3c_device_lcd,
&s3c_device_wdt,
&s3c_device_i2c0,
&s3c_device_iis,
&s3c_device_rtc,
&s3c_device_nand,//NAND
&mini2440_device_eth,//DM9000
&s3c_device_spi0,//spi
&s3c_device_spi1,//spi
};
最后在mini2440_machine_init函数中加入如下代码:
static void __init mini2440_machine_init(void)
{
s3c24xx_fb_set_platdata(&mini2440_fb_info);
s3c_i2c0_set_platdata(NULL);

platform_add_devices(mini2440_devices, ARRAY_SIZE(mini2440_devices));
//smdk_machine_init();
//SPI
s3c_device_spi0.dev.platform_data= &s3c2410_spi0_platdata;
spi_register_board_info(s3c2410_spi0_board, ARRAY_SIZE(s3c2410_spi0_board));
s3c_device_spi1.dev.platform_data= &s3c2410_spi1_platdata;
spi_register_board_info(s3c2410_spi1_board, ARRAY_SIZE(s3c2410_spi1_board));
}

最后需要修改arch/arm/plat-s3c24xx/KConfig文件

找到如下代码段:

config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13
bool
help
SPI GPIO configuration code for BUS0 when connected to
GPE11, GPE12 and GPE13.

config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7
bool
help
SPI GPIO configuration code for BUS 1 when connected to
GPG5, GPG6 and GPG7.
修改为

config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13
bool "S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13"
help
SPI GPIO configuration code for BUS0 when connected to
GPE11, GPE12 and GPE13.

config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7
bool "S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7"
help
SPI GPIO configuration code for BUS 1 when connected to
GPG5, GPG6 and GPG7.
最后我们配置编译文件:
make menuconfig
图1

mini2440移植之SPI驱动
图2

mini2440移植之SPI驱动
图3

mini2440移植之SPI驱动

图4

mini2440移植之SPI驱动
图5

mini2440移植之SPI驱动

编译内核

make zImage
将编译好的内核导入开发板,并且编译Linux Source自带的测试程序,在Documentation/spi下,修改spidev_test.c文件,将device name改为/dev/spidev1.0

将编译好的文件下载到开发板上,并且将开发板的SPI MOI和MIO短接,也就是让SPI自己发送自己接收,执行文件