- 论坛徽章:
- 0
|
我在使用TI 6467的SPI支持扩展触摸屏功能时遇到了问题。
使用了xpt2046芯片,与dm6467的spi_sclk,spi_scs0,spi_miso,spi_mosi连接
以下为我所修改的步骤:
1)make meunconfig选择SPI support,并选择spidev的功能(置为M),DaVinci SPI EEPROM功能不支持。
选择如下:
x x [*] SPI support x x
x x --- SPI Master Controller Drivers x x
x x <*> SPI controller driver for DaVinci SoC x x
x x [*] Set DaVinci SPI to DMA mode x x
x x --- Bitbanging SPI master x x
x x --- SPI Protocol Masters x x
x x < > TSC2102 codec support x x
x x <M> User mode SPI device driver support x x
x x < > DaVinci SPI EEPROM
2)davinci_spi_platform.c在spi_board_info dm6467_spi_board_info[]中添加:
{
.modalias = "spidev",
.mode = SPI_MODE_0,
.irq = 0,
.max_speed_hz = 2 * 1000 * 1000 /* max sample rate at 3V */ ,
.bus_num = 0,
.chip_select = 0,
},
3)编译,并将uImage烧死到板上,
此时/sys目录下,spi相关目录文件:
./class/spi_master
./class/spi_master/spi0
./bus/spi
./bus/spi/devices/spi0.0
./devices/platform/dm_spi.0/spi0.0
./devices/platform/dm_spi.0/spi_master:spi0
同时insmod spidev.ko
/dev目录下出现spidev0.0
root@iview:/dev# ls -al | grep spidev0.0
crw-rw---- 1 root root 153, 0 Jan 1 00:02 spidev0.0
4).使用Documentation\spi下spidev_test.c测试spidev.ko
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <asm/types.h>
#include <linux/spi/spidev.h>
#include <asm-generic/ioctl.h>
static int verbose;
static void do_read(int fd, int len)
{
unsigned char buf[32], *bp;
int status; /* read at least 2 bytes, no more than 32 */
if (len < 2)
len = 2;
else if (len > sizeof(buf))
len = sizeof(buf);
memset(buf, 0, sizeof buf);
status = read(fd, buf, len);
if (status < 0)
{
perror("read");
return;
}
if (status != len) {
fprintf(stderr, "short read\n");
return;
}
printf("read(%2d, %2d): %02x %02x,", len, status, buf[0], buf[1]);
status -= 2;
bp = buf + 2;
while (status-- > 0)
{
printf(" %02x", *bp++);
}
printf("\n");
return;
}
static void do_msg(int fd, int len)
{
struct spi_ioc_transfer xfer[2];
unsigned char buf[32], *bp;
int status;
memset(xfer, 0, sizeof xfer);
memset(buf, 0, sizeof buf);
if (len > sizeof buf)
len = sizeof buf;
buf[0] = 0xaa;
xfer[0].tx_buf = (__u64) buf;
xfer[0].len = 1;
xfer[1].rx_buf = (__u64) buf;
xfer[1].len = len;
status = ioctl(fd, SPI_IOC_MESSAGE(2), xfer);
if (status < 0) {
perror("SPI_IOC_MESSAGE");
printf("SPI_IOC_MESSAGE error!");
return;
}
printf("response(%2d, %2d): ", len, status);
for (bp = buf; len; len--)
printf(" %02x", *bp++);
printf("\n");
return;
}
static void dumpstat(const char *name, int fd)
{
__u8 mode, lsb, bits, alsb;
__u32 speed;
if (ioctl(fd, SPI_IOC_RD_MODE, &mode) < 0)
{
perror("SPI rd_mode");
return;
}
if (ioctl(fd, SPI_IOC_RD_LSB_FIRST, &alsb) < 0)
{
perror("SPI rd_lsb_fist");
return;
}
if (ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0)
{
perror("SPI bits_per_word");
return;
}
if (ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed) < 0)
{
perror("SPI max_speed_hz");
return;
}
printf("%s: spi mode %d, %d bits %sper word, %d Hz max\n",
name, mode, bits, lsb ? "(lsb first) " : "", speed);
return;
}
int main (int argc, char **argv)
{
int c;
int readcount = 0;
int msglen = 0;
int fd;
char name[64];
strcpy(name, "/dev/spidev0.0");
fd = open(name, O_RDWR);
if (fd < 0)
{
perror("open");
return 1;
}
dumpstat(name, fd);
msglen = 32;
readcount = 32;
if (msglen)
{
do_msg(fd, msglen);
}
if (readcount)
{
do_read(fd, readcount);
}
close(fd);
return 0;
}
5).运行spidevtest,输出:
/dev/spidev0.0: spi mode 0, 8 bits (lsb first) per word, 2000000 Hz max
除此之外没有其它输出.
spidev_test.c 中调用do_msg(),ioctl(fd, SPI_IOC_MESSAGE(2), xfer);调用,整个程序没有反应
6).跟踪发现spidev_message里调用spi_sync,spi slave 设备没有数据响应
7).用示波器测量没有时钟信号
我遇到的问题现象如上,dm6467的引角应该都不需要配置,都没有复用,难道我还有什么地方漏了吗? |
|