全部博文(776)
分类: LINUX
2011-01-06 23:12:52
1、在配置Linux 编译选项时,开启相应的SPI 选项,如下所示
-> Device Drivers
-> SPI support
SPI support
*** SPI Master Controller Drivers ***
-*- Bitbanging SPI master
<*> Samsung S3C24XX series SPI
< > Samsung S3C24XX series SPI by GPIO
*** SPI Protocol Masters ***
< > SPI EEPROMs from most vendors
<*> User mode SPI device driver support
< > Infineon TLE62X0 (for power switching)
设置完成保存。
2.驱动文件mcp251x.c mcp251x.h can.h
文件mcp251x.c放在目录drivers/net/can/下;
文件mcp251x.h放在目录include/linux/can/platform/下;
文件can.h放在目录include/linux/can/下
3.添加配置文件drivers/net/can/Kconfig
在文件中添加
config CAN_MCP251X
tristate "Microchip 251x series SPI CAN Controller"
depends on CAN && SPI
default N
---help---
Say Y here if you want support for the Microchip 251x series of
SPI based CAN controllers.
4.在drivers/net/can/Makefile文件中添加编译文件
obj-$(CONFIG_CAN_MCP251X) += mcp251x.o
5. 修改文件arch/arm/mach-s3c2410/mach-smdk2410.c中添加spi板级启动信息
#include
#include
#include
static struct mcp251x_platform_data mcp251x_info = {
.f_osc = 16000000,
//.oscillator_frequency = 19000000,
//.board_specific_setup = myboard_mcp251x_initfunc,
//.device_reset = myboard_mcp251x_reset,
//.transceiver_enable = NULL,
};
static struct spi_board_info spi_board_info[] __initdata = {
[0]=
{
.modalias = "mcp251x", //这个名称一定要与mcp251x.c驱动中
//proc函数中的.name要一致
.platform_data = &mcp251x_info, //上面的结构体
.irq = IRQ_EINT3, 中断端口号
.max_speed_hz = 8000000, //spi最大的速度
.bus_num = 0, //spi0,1中选择spi0口
.chip_select = 0, //多个芯片选择
},
};
static struct s3c2410_spi_info s3c2410_spi0_platdata = {
.pin_cs = S3C2410_GPG2, //片选端口指定
.num_cs = 1, //总共端口数
// .bus_num = 0,
};
smdk2410_devices数组中添加
&s3c_device_spi0,
smdk2410_init函数中添加
s3c_device_spi0.dev.platform_data= &s3c2410_spi0_platdata;
spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
6.重新编译内核
启动信息中有如下内容,说明成功了:
7 执行命令cat /proc/devices
显示252 mcp251x
添加设备文件 mknod /dev/mcp251x c 252 0
执行应用程序
./can_test
显示如下
基本完成,接下来是接上硬件调试了