Linux2.6.32下SPI驱动的移植如下图所示:
下面需要修改部分内核代码,具体操作如下:
1. 修改arch/arm/mach-s3c2440/mach-mini2440.c文件
在include头文件代码行之后增加如下代码
//spi add by shiguang
#include <linux/spi/spi.h>
#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,
};
//end add spi
然后在函数__initmini2440_machine_init的开头增加下列代码
//spi add by shiguang
s3c_device_spi0.dev.platform_data=&s3c2410_spi0_platdata;
spi_register_board_info(s3c2410_spi0_board,ARRAY_SIZE(s3c2410_spi0_board));
//end spi
在mini2440_devices数组的最后中添加
&s3c_device_spi0,// add by shiguang
2.修改drivers/spi/spi_s3c24xx.c文件
在文件开头增加下列代码
//add by shiguang
#include <mach/regs-gpio.h>
在s3c24xx_spi_initialsetup函数结尾增加下列代码
// add by shiguang
s3c2410_gpio_cfgpin(hw->pdata->pin_cs,S3C2410_GPIO_OUTPUT);
s3c2410_gpio_cfgpin(0x8B, S3C2410_GPIO_SFN2);
s3c2410_gpio_cfgpin(0x8C, S3C2410_GPIO_SFN2);
s3c2410_gpio_cfgpin(0x8D, S3C2410_GPIO_SFN2);
// end add
3. 最后重新编译内核
重启mini2440,查看/dev下的设备文件
[root@ShiGuang /]# ls /dev/spidev0.0 -l
crw-rw---- 1 root root 153, 0 Jan 1 08:00 /dev/spidev0.0
[root@ShiGuang /]#
4. 应用程序测试
![](http://hi.csdn.net/attachment/201108/19/0_1313722457W6Kg.gif)
![大笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif)