`
dazhilao
  • 浏览: 238866 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

.基于S3C2440 Linux2.30.4 SPI驱动移植全过程

阅读更多

原文地址:http://blog.163.com/joyrain_06/blog/static/1788253920113823524293/

一、环境

    硬件:s3c2440

    内核:Linux2.30.4

    交叉编译工具:EABI4.3.3

    开发环境:rhel5.5

二、移植

  1.修改arch/arm/mach-s3c2440/mach-mini2440.c文件:  
 

a.加入头文件

  #include <../mach-s3c2410/include/mach/spi.h>
  #include <linux/spi/spi.h>

  b.加入接口结构

/* SPI */
static struct spi_board_info s3c2410_spi0_board[] = {
        [0] = {
                .modalias = "spidev",
                .bus_num= 0,
                .chip_select= 0,
               /* s3c2410_spi0_platdata.num_cs */
                .irq = IRQ_EINT9,
                .max_speed_hz= 96*1000*1000,
        },
};

static struct s3c2410_spi_info s3c2410_spi0_platdata = {
        .pin_cs = S3C2410_GPG2,
        .num_cs = 1,
        .bus_num = 0,
        .gpio_setup=s3c24xx_spi_gpiocfg_bus0_gpe11_12_13,
};


c.加入设备

static struct platform_device *tq2440_devices[] __initdata = {
        &s3c_device_usb,
        &s3c_device_lcd,
        &s3c_device_wdt,
        &s3c_device_i2c0,
        &s3c_device_iis,
        &s3c_device_rtc,
#ifdef CONFIG_DM9000
        &s3c_device_dm9000,
#endif
        &s3c_device_usbgadget,
        &s3c_device_uda134x,

        &s3c_device_spi0,                 //注意在结构体中的位置,否则会出现编译错误
        //&s3c_device_spi1, //for spi1
};

 

d.注册设备

static void __init tq2440_machine_init(void)
{
        s3c24xx_fb_set_platdata(&tq2440_fb_info);
        s3c_i2c0_set_platdata(NULL);

        platform_add_devices(tq2440_devices, ARRAY_SIZE(tq2440_devices));
        EmbedSky_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; //for spi1
        //spi_register_board_info(s3c2410_spi1_board, ARRAY_SIZE(s3c2410_spi1_board)); //for spi1

        s3c2410_gpio_setpin(S3C2410_GPG12, 0);
        s3c2410_gpio_cfgpin(S3C2410_GPG12, S3C2410_GPIO_OUTPUT);
        s3c24xx_udc_set_platdata(&EmbedSky_udc_cfg);
}

2.修改Kconfig

打开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.

修改为
# SPI default pin configuration code

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.


3.编译内核

#make menuconfig


 System Type  ---> 

  [*] S3C24XX_SPI_BUS0_GPE11_GPE12_GPE13                                                                              

   [ ] S3C24XX_SPI_BUS1_GPG5_GPG6_GPG7

 

  Device Drivers  --->

                          [*] SPI support  --->  

                                                      --- SPI support                                                                                                         
                                                     *** SPI Master Controller Drivers ***                                                                         
                                                     -*-   Utilities for Bitbanging SPI masters           

                                                     <*>   GPIO-based bitbanging SPI Master      

                                                      <*>   Samsung S3C24XX series SPI                                                      

                                                      <*>   Samsung S3C24XX series SPI by GPIO                                           
                                                     *** SPI Protocol Masters ***   

                                                     <*>   User mode SPI device driver support 

                                                     < >   Infineon TLE62X0 (for power switching)  

保存

#make zImage

4.测试

../Documentation/spi

arm-linux-gcc -I/root/linux-2.6.30.4/include spidev_test.c

 

 后会生成a.out的spi测试程序;
拷入文件系统运行可看到结果(将MISO和MOSI短接)

5.结果

./a.out
spi mode: 0
bits per word: 8
max speed: 96000000 Hz (96000 KHz)

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

测试结果正确。

用示波器查看波形t=20ns*2 并且数据波形正确

参考:http://www.arm9home.net/read.php?tid-4422.html

           http://www.arm9home.net/read.php?tid-2378-keyword-spi.html
           http://www.arm9home.net/read.php?tid-3620-keyword-spi.html

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics