mini2440 SPI驱动移植

来源:互联网 发布:mac安装双系统win7 编辑:程序博客网 时间:2024/05/18 04:51
 2013-07-12 15:30:17

分类: 嵌入式

        最近项目需要,需要在mini2440上移植SPI驱动,板子需要驱动SPI设备,上网找了很多资源,但是很多都是
有问题,最终在基本理解驱动结构的前提下,将SPI驱动顺利移植到mini2440。

        我使用的内核版本是2.6.32.2,这个版本和2.6。29不一样,网上很多版本都是关于2.6.29,如果完全按照网
上步骤,编译会出现问题,我做的步骤如下:

1、在Linux Source Code中修改arch/arm/mach-s3c2440/mach-mini2440.c文件,加入头文件:

[cpp] view plaincopy
  1. #include <linux/spi/spi.h>  
  2. #include <../mach-s3c2410/include/mach/spi.h>  
        然后加入如下代码:
[cpp] view plaincopy
  1. static struct spi_board_info s3c2410_spi0_board[] =  
  2. {  
  3.         [0] = {  
  4.                 .modalias = "spidev",  
  5.                 .bus_num = 0,  
  6.                 .chip_select = 0,  
  7.                 .irq = IRQ_EINT9,  
  8.                 .max_speed_hz = 500 * 1000,  
  9.                 }  
  10. };  
  11.   
  12. static struct s3c2410_spi_info s3c2410_spi0_platdata = {  
  13.         .pin_cs = S3C2410_GPG(2),  
  14.         .num_cs = 1,  
  15.         .bus_num = 0,  
  16.         .gpio_setup = s3c24xx_spi_gpiocfg_bus0_gpe11_12_13,  
  17. };  
  18.   
  19. static struct spi_board_info s3c2410_spi1_board[] =  
  20. {  
  21.         [0] = {  
  22.                 .modalias = "spidev",  
  23.                 .bus_num = 1,  
  24.                 .chip_select = 0,  
  25.                 .irq = IRQ_EINT2,  
  26.                 .max_speed_hz = 500 * 1000,  
  27.                 }  
  28. };  
  29.   
  30.   
  31. static struct s3c2410_spi_info s3c2410_spi1_platdata = {  
  32.         .pin_cs = S3C2410_GPG(3),  
  33.         .num_cs = 1,  
  34.         .bus_num = 1,  
  35.         .gpio_setup = s3c24xx_spi_gpiocfg_bus1_gpg5_6_7,  
  36. };  
        这里需要了解驱动架构,其中移植过程中容易出问题的地方时S3C2410_GPG(2)和S3C2410_GPG(3)两处地
方,网上一般给的源代码是S3C2410_GPG2,这在2.6.29中可行,但是在2.6.32源代码中没有定义S3C2410_GPG2
宏定义,要使用S3C2410_GPG(2)宏定义。

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

[cpp] view plaincopy
  1. &s3c_device_spi0,  
  2. &s3c_device_spi1,  
        最后在mini2440_machine_init函数中加入如下代码:
[cpp] view plaincopy
  1. s3c_device_spi0.dev.platform_data= &s3c2410_spi0_platdata;  
  2. spi_register_board_info(s3c2410_spi0_board, ARRAY_SIZE(s3c2410_spi0_board));  
  3. s3c_device_spi1.dev.platform_data= &s3c2410_spi1_platdata;  
  4. spi_register_board_info(s3c2410_spi1_board, ARRAY_SIZE(s3c2410_spi1_board));  

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

        找到如下代码段:

[cpp] view plaincopy
  1. config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13  
  2.         bool   
  3.         help  
  4.           SPI GPIO configuration code for BUS0 when connected to  
  5.           GPE11, GPE12 and GPE13.  
  6.   
  7. config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7  
  8.         bool   
  9.         help  
  10.           SPI GPIO configuration code for BUS 1 when connected to  
  11.           GPG5, GPG6 and GPG7.  
        修改为
[cpp] view plaincopy
  1. config S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13  
  2.         bool "S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13"  
  3.         help  
  4.           SPI GPIO configuration code for BUS0 when connected to  
  5.           GPE11, GPE12 and GPE13.  
  6.   
  7. config S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7  
  8.         bool "S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7"  
  9.         help  
  10.           SPI GPIO configuration code for BUS 1 when connected to  
  11.           GPG5, GPG6 and GPG7.  
        最后我们配置编译文件:
[cpp] view plaincopy
  1. make menuconfig  





        最后编译内核

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

        交叉编译:

[cpp] view plaincopy
  1. arm-linux-gcc -I ~/linux-2.6.32.2/include/ spidev_test.c  
        将编译好的文件下载到开发板上,并且将开发板的SPI MOI和MIO短接,也就是让SPI自己发送自己接收,执行文件,我
们看到如下结果:
[cpp] view plaincopy
  1. FF FF FF FF FF FF  
  2. 40 00 00 00 00 95  
  3. FF FF FF FF FF FF  
  4. FF FF FF FF FF FF  
  5. FF FF FF FF FF FF  
  6. DE AD BE EF BA AD  
  7. F0 0D  
        说明驱动移植成功。

        总结:这里叙述的是驱动移植详细过程,代码的具体含义以及开发板的针脚对应图需要自己去查阅相关资料,这里不再详述。

0 0