最近项目需要,需要在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文件,加入头文件:
在mini2440_devices[]平台数组中添加如下代码:
最后需要修改arch/arm/plat-s3c24xx/KConfig文件
找到如下代码段:
图2
图3
图4
图5
最后编译内核
交叉编译:
总结:这里叙述的是驱动移植详细过程,代码的具体含义以及开发板的针脚对应图需要自己去查阅相关资料,这里不再详述。
转载自:http://blog.csdn.net/lxmky/article/details/6858322
//-------------------------------------------------
一下是自己总结的应用层的操作
S3C2440的SPI驱动只是做了一个驱动总线,不关心读取或写入时,最高位的变化,如看手册才明白,有些芯片的SPI协议写操作最高位是1,则 写地址0x6d,则写入的数据是0xed;!!!!
static void write_data(int fd)
{
int ret;
uint8_t tx[2];
tx[0]=0xed; //write 0x6d address SI4432 spi protel write MSB is 1;so is 0xed
tx[1]=0x09;
struct spi_ioc_transfer tr = {
.tx_buf = (unsigned long)&tx,
.rx_buf = (unsigned long)NULL, //
.len = 2,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
.cs_change = 0,
};
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret == 1)
pabort("can't send spi message");
printf("ioctl write data operation return is %d---------\n",ret);
}
static void read_data(int fd)
{
int ret;
uint8_t address=0x6d; //from 0x6d address start read
uint8_t din[100];
memset(din,0,100);//only test
struct spi_ioc_transfer read[2] =
{
{
.tx_buf = (unsigned long)&address,
.rx_buf = (unsigned long)NULL, //when only write data operation, rx_buf must be null
.len = 1,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
.cs_change = 0,
},
{
.tx_buf = (unsigned long)NULL, // when only read data operation ,tx_buf must be null
.rx_buf = (unsigned long)din,
.len =1,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
.cs_change =0, // =0 or =1 ,result is same !!snoguo
}
};
ret = ioctl(fd, SPI_IOC_MESSAGE(2), read);
if (ret == 1)
pabort("can't send spi message");
printf("ioctl read return is %d\n",ret);
// for (ret = 0; ret < ARRAY_SIZE(din); ret++) {
// if (!(ret % 6))
// puts("");
printf("%.2X ", din[0]);
//}
puts("");
}