主题 : 有谁使用过mini6410写过操作SPI的驱动程序? 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 66437
精华: 0
发帖: 4
金钱: 20 两
威望: 4 点
综合积分: 8 分
注册时间: 2012-03-30
最后登录: 2017-09-13
楼主  发表于: 2012-03-30 14:09

 有谁使用过mini6410写过操作SPI的驱动程序?

各位好:最近正在mini6410板上写一个操作SPI读取数据的驱动程序,mini6410有关SPI的配置寄存器有些多,功能比mini2440的SPI多加了很多功能,因为本人刚刚开始嵌入式开发,所以不是很熟,请问mini6410配置SPI和读写数据的流程是啥?最好可以辅以源码,不胜感谢!
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2012-04-01 10:03
如果你是为SPI接口的外设周边设备写驱动,那基本上不用关心mini6410的SPI配置。那是内核里S3C6410的SPI Controller驱动的事情。你所要做的是

1. Review你的外设周边硬件连接,确定使用的是6410的SPI0还是SPI1;
2. 确保SPI Controller相关的GPIO, 即SPIx_CLK, SPIx_MISO, SPIx_MOSI, SPIx_CS(如果使用了的话)正确配置了功能;
3. 加入内核中的S3C6410 SPI Controller支持,包括
  3.1. 在mach-mini6410.c里注册相应的s3c64xx_device_spi0或s3c64xx_device_spi1设备
  3. 2 在内核配置中enable S3C6410 SPI Controller;
4. 注册SPI外设周边设备信息。在mach-mini6410.c里通过定义一个spi_board_info结构并且调用spi_register_board_info()来实现。
这里需要注意的是,如果你希望开发一个内核中的SPI外设周边驱动来控制你的硬件,spi_board_info里的modalias栏位需要和周边设备驱动里定义的spi_driver结构里的driver->name栏位保持一致。如果你从用户空间通过/dev/spidev.0这样的设备节点来控制,modalias需要设成"spidev"
5. 如果在步骤4中你选择前者,你需要写一个内核中的SPI周边设备驱动,可以参考drivers/video/backlight/ltv350qv.c。这是一个SPI接口的LCD panel驱动。

关于步骤3和4, 可以参考http://www.aiothome.net/read.php?tid-10788.html

另外,如果你对S3C6410的SPI controller感兴趣,可以去看看它的源代码(在drivers/spi/spi_s3c64xx.c)。S3C6410 SPI Controller的配置和控制流程参考S3C6410 User Manual的29.6.1节"SETTING SEQUENCE OF SPECIAL FUNCTION REGISTER"。
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."
专注与嵌入式linux的图像,视频方向的开发。
级别: 侠客
UID: 9607
精华: 0
发帖: 81
金钱: 405 两
威望: 81 点
综合积分: 162 分
注册时间: 2009-10-07
最后登录: 2015-02-02
2楼  发表于: 2012-07-12 17:13
版主你好,我按照http://www.aiothome.net/read.php?tid-10788.html 的步骤,做了如下操作:

步骤1 增加头文件
  #include <plat/s3c64xx-spi.h>    //gzj++
   #include <linux/spi/spi.h>   //gjz++
步骤2 配置内核选项
Device Drivers  ---> [*] SPI support  ---> <M>   Samsung S3C24XX series SPI
                                           <M>   User mode SPI device driver support      
步骤三:
   增加 &s3c64xx_device_spi0, 到 --->>> [static struct platform_device *mini6410_devices[]] 的末尾    
   增加 add [obj-y       +=dev-spi.o] 到 arch/arm/mach-s3c64xx/Makefile
   在头文件语句的下面增加  
     static void  cs_set_level(unsigned line_id, int lvl) {
    gpio_direction_output(line_id, lvl);
};
static struct s3c64xx_spi_csinfo s3c64xx_spi0_csinfo = {
  .fb_delay=100,
  .line=S3C64XX_GPC(3),
  .set_level=cs_set_level,
};
static struct spi_board_info s3c6410_spi0_board[] = {
[0] = {
.modalias = "spidev",
.bus_num= 0,
.chip_select= 0, //必须小于s3c6410_spi0_platdata.num_cs
.irq =IRQ_SPI0,
.max_speed_hz= 500*1000,
.mode=SPI_MODE_0,
.controller_data=&s3c64xx_spi0_csinfo,
},
};
在mini6410_machine_init(before platform_add_devices)中增加
[ s3c64xx_spi_set_info(0,0,1);   //gzj++
       //s3c64xx_spi_set_info(1,0,1);

       spi_register_board_info(s3c6410_spi0_board, ARRAY_SIZE(s3c6410_spi0_board));
     // spi_register_board_info(s3c6410_spi1_board, ARRAY_SIZE(s3c6410_spi1_board));
  ]
    
步骤四:
        do make zImage
        do make
然后再6410的板子上执行:
             insmod spi_s3c64xx.ko  
             insmod spidev.ko  
            
            
             结果打印的信息是这样的:
            
[root@FriendlyARM plg]# insmod spi_s3c64xx.ko
:99 gpio_ensure_requested+0x48/0xf4()
autorequest GPIO-20
Modules linked in: spi_s3c64xx(+)
[<c0173c44>] (unwind_backtrace+0x0/0xe4) from [<c0182ea0>] (warn_slowpath_common
+0x4c/0x64)
[<c0182ea0>] (warn_slowpath_common+0x4c/0x64) from [<c0182f38>] (warn_slowpath_f
mt+0x2c/0x3c)
[<c0182f38>] (warn_slowpath_fmt+0x2c/0x3c) from [<c02df5ac>] (gpio_ensure_reques
ted+0x48/0xf4)
[<c02df5ac>] (gpio_ensure_requested+0x48/0xf4) from [<c02df79c>] (gpio_direction
_output+0x68/0x120)
[<c02df79c>] (gpio_direction_output+0x68/0x120) from [<bf00061c>] (s3c64xx_spi_s
etup+0x1f4/0x210 [spi_s3c64xx])
[<bf00061c>] (s3c64xx_spi_setup+0x1f4/0x210 [spi_s3c64xx]) from [<c0330914>] (sp
i_setup+0x40/0x48)
[<c0330914>] (spi_setup+0x40/0x48) from [<c0330b9c>] (spi_add_device+0xa0/0x118)

[<c0330b9c>] (spi_add_device+0xa0/0x118) from [<c0330c94>] (spi_new_device+0x80/
0xa4)
[<c0330c94>] (spi_new_device+0x80/0xa4) from [<c0330cd8>] (spi_match_master_to_b
oardinfo+0x20/0x40)
[<c0330cd8>] (spi_match_master_to_boardinfo+0x20/0x40) from [<c0330dcc>] (spi_re
gister_master+0xd4/0x118)
[<c0330dcc>] (spi_register_master+0xd4/0x118) from [<bf0043d4>] (s3c64xx_spi_pro
be+0x3d4/0x4a8 [spi_s3c64xx])
[<bf0043d4>] (s3c64xx_spi_probe+0x3d4/0x4a8 [spi_s3c64xx]) from [<c0300b40>] (pl
atform_drv_probe+0x14/0x18)
[<c0300b40>] (platform_drv_probe+0x14/0x18) from [<c02ffd34>] (driver_probe_devi
ce+0xa8/0x158)
[<c02ffd34>] (driver_probe_device+0xa8/0x158) from [<c02ffe44>] (__driver_attach
+0x60/0x84)
[<c02ffe44>] (__driver_attach+0x60/0x84) from [<c02ff01c>] (bus_for_each_dev+0x4
c/0x78)
[<c02ff01c>] (bus_for_each_dev+0x4c/0x78) from [<c02ff6b8>] (bus_add_driver+0xa8
/0x224)
[<c02ff6b8>] (bus_add_driver+0xa8/0x224) from [<c0300090>] (driver_register+0xa8
/0x12c)
[<c0300090>] (driver_register+0xa8/0x12c) from [<c0300da4>] (platform_driver_pro
be+0x18/0x8c)
[<c0300da4>] (platform_driver_probe+0x18/0x8c) from [<c01644d8>] (do_one_initcal
l+0xbc/0x190)
[<c01644d8>] (do_one_initcall+0xbc/0x190) from [<c01aa098>] (sys_init_module+0x1
58c/0x1754)
[<c01aa098>] (sys_init_module+0x158c/0x1754) from [<c016e5e0>] (ret_fast_syscall
+0x0/0x30)
---[ end trace 3539e128fcc177dd ]---



请问下为什么,是不是spi的7F00B000这个地址让别的给占用了,我没有发现那个驱动占用这个地址啊!!!

请教一下
专注与嵌入式linux的图像,视频方向的开发。
级别: 侠客
UID: 9607
精华: 0
发帖: 81
金钱: 405 两
威望: 81 点
综合积分: 162 分
注册时间: 2009-10-07
最后登录: 2015-02-02
3楼  发表于: 2012-08-01 18:07
顶一下,希望能得到解决,谢谢!
级别: 新手上路
UID: 81714
精华: 0
发帖: 9
金钱: 50 两
威望: 10 点
综合积分: 18 分
注册时间: 2012-11-13
最后登录: 2013-07-05
4楼  发表于: 2012-11-25 22:01
MARK。。。最近被SPI整的头晕脑帐。。。