can2--tiny6410移植mcp2515驱动

根据te6410

移植mcp2515到tiny6410,将tiny按照te的连线如下


tiny6410,linux2.6.38移植mcp251x
使用spi1,eint8

1.修改板子文件mach-mini6410.c,加入plateform平台设备
先加入头文件

//for spi  add by medconn
#include <plat/s3c64xx-spi.h>
#include <linux/spi/spi.h>
#include <linux/can.h>
//for mcp251x  add by medconn
#include <linux/can/platform/mcp251x.h>
#include <mach/gpio-bank-c.h>
 
在static struct platform_device *mini6410_devices[] __initdata 函数中加入
spi的平台设备
//&s3c64xx_device_spi0,
&s3c64xx_device_spi1,

加入spi板子信息,这里使用eint8,飞凌使用的是eint16

/*add by medconn for mcp251x*/
static void  cs_set_level(unsigned line_id, int lvl) {
    gpio_direction_output(line_id, lvl);
};
static struct s3c64xx_spi_csinfo s3c64xx_spi1_csinfo = {
   .fb_delay=0x3,
   .line=S3C64XX_GPC(7),
   .set_level=cs_set_level,
};
static int mcp251x_ioSetup(struct spi_device *spi)
{
// printk(KERN_INFO "mcp251x: setup gpio pins CS and External Int\n");
        printk("mcp251x_ioSetup\n");
//s3c_gpio_setpull(S3C64XX_GPL(8), S3C_GPIO_PULL_UP); // External interrupt from CAN controller--eint16(gpl8)
//s3c_gpio_cfgpin(S3C64XX_GPL(8), S3C_GPIO_SFN(3));  // External interrupt from CAN controller (hopefully external interrupt)--eint16(gpl8)
s3c_gpio_setpull(S3C64XX_GPN(8), S3C_GPIO_PULL_UP); // External interrupt from CAN controller--eint8(gpn8)
s3c_gpio_cfgpin(S3C64XX_GPN(8), S3C_GPIO_SFN(2));  // External interrupt from CAN controller (hopefully external interrupt)--eint8(gpn8)
s3c_gpio_setpull(S3C64XX_GPC(7), S3C_GPIO_PULL_NONE); // Manual chip select pin as used in 6410_set_cs
s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C_GPIO_OUTPUT); // Manual chip select pin as used in 6410_set_cs
return 0;
}
static struct mcp251x_platform_data mcp251x_info = {
.oscillator_frequency = 16000000,
.board_specific_setup = mcp251x_ioSetup,
.transceiver_enable = NULL,
.power_enable = NULL,
};
static struct spi_board_info __initdata forlinx6410_mc251x_info[]  = {
{
.modalias = "mcp2515", 
.platform_data = &mcp251x_info,
//.irq = IRQ_EINT(16),//--eint16(gpl8)
.irq = IRQ_EINT(8),
.max_speed_hz = 10*1000*1000, 
.bus_num = 1,
.chip_select = 0,
.mode = SPI_MODE_0, 
.controller_data=&s3c64xx_spi1_csinfo,
},
};
 
在static void __init mini6410_machine_init(void) 中加入几行,注册板子文件
//by medconn
s3c64xx_spi_set_info(0,0,1);
s3c64xx_spi_set_info(1,0,1);
spi_register_board_info(forlinx6410_mc251x_info,ARRAY_SIZE(forlinx6410_mc251x_info));
platform_add_devices(mini6410_devices, ARRAY_SIZE(mini6410_devices));
 
2.此时编译会出现错误 s3c64xx_device_spi0 符号链接出错,原因是s3c64xx_device_spi0所在文件dev-spi.c没有编译进内核,修改
arch/arm/mach-s3c64xx/Kconfig的
在config MACH_MINI6410 所属项目下加入一行
select S3C64XX_DEV_SPI 
 
3.tiny6410默认没有配置spi主控制器驱动,所以需要配置一下
Device Drivers  ---> [*] SPI support  --->   <*>   Samsung S3C64XX series type SPI 
                                             <*>   GPIO-based bitbanging SPI Master  
 
4.修改mcp251x驱动
使用自带的mcp251x.c也可以,但是传输一会又失败了
使用我们的mcp251x.c,需修改line1131左右的一行为,否则在2.6.38下编译不通过
priv->wq = create_freezable_workqueue("mcp251x_wq"); 
tiny6410默认没有配置mcp251x驱动,配置一下
[*] Networking support  --->   <*>   CAN bus subsystem support  --->  <*>   Raw CAN Protocol (raw access with CAN-ID filtering)    
                                                                      <*>   Broadcast Manager CAN Protocol (with content filtering)  
                                                                      CAN Device Drivers  ---> <*> Platform CAN drivers with Netlink support  
                                                                                               [*]   CAN bit-timing calculation 
                                                                                               <*>   Microchip MCP251x SPI CAN controllers 
重新编译烧写即可。



posted on 2012-07-12 20:15  _song  阅读(754)  评论(0编辑  收藏  举报