3559AV100 sensor hub添加DMA模式

在主soc中使用sensor hub外围资源,使能shub spi0添加DMA驱动支持
1.进入linux目录,打开menu菜单
make ARCH=arm64 CROSS_COMPILE=aarch64-himix100-linux- menuconfig

2.打开驱动支持
Device Drivers —>
[]DMA Engine support —>
<
> Hisilicon EDMAC Controller support
[] Renesas SuperH DMA Engine support
<
> Hisilicon EDMAC Controller support
(8) hiedmac channel num

3.在hi3559av100-demb.dts修改shub spi0属性
spi_bus5: spi@18080000 {
compatible = “arm,pl022”, “arm,primecell”;
arm,primecell-periphid = <0x00800022>;
reg = <0x18080000 0x1000>, <0x18030088 0x4>;
interrupts = <0 198 4>;
clocks = <&clock_shub HI3559AV100_SHUB_SPI0_CLK>;
clock-names = “apb_pclk”;
#address-cells = <1>;
#size-cells = <0>;
status = “disabled”;
num-cs = <3>;
dmas = <&hiedmacv310_2 1 1>, <&hiedmacv310_2 0 0>;
dma-names = “tx”,“rx”;
hisi,spi_cs_sb = <0>;
hisi,spi_cs_mask_bit = <0x3>;
};

备注:
HI3559AV100_SHUB_SPI0_CLK指定为shub spi0;
hiedmacv310_2 指定使用dmac2,只有dmac2才支持dma模式(芯片手册指明);

4.在hi3559av100.dtsi修改spi_bus5属性
&spi_bus5{
status = “okay”;
spidev@0 {
compatible = “rohm,dh2228fv”;
reg = <0>;
pl022,interface = <0>;
pl022,com-mode = <2>;
spi-max-frequency = <48000000>;
rx-level-trig = <3>;
tx-level-trig = <3>;
};
spidev@1 {
compatible = “rohm,dh2228fv”;
reg = <1>;
pl022,interface = <0>;
pl022,com-mode = <0>;
spi-max-frequency = <48000000>;
};
spidev@2 {
compatible = “rohm,dh2228fv”;
reg = <2>;
pl022,interface = <0>;
pl022,com-mode = <0>;
spi-max-frequency = <48000000>;
};
};

备注:
com-mode为传输模式,2为dma传输模式;
rx-level-trig, tx-level-trig为spi fifo的传输级别,3对应为16;

5.测试的spi test

#include
#include
#include

#include
#include
#include
#include
#include
#include

#include
#include
#include
#include

//aarch64-himix100-linux-gcc -o spi_dma_test spi_dma_test.c

#define TEST_SPI_CLK 16000000 //25000000 16000000 12000000 8000000
char file_name[] = “/dev/spidev5.0”;
unsigned int speed = TEST_SPI_CLK;//TEST_SPI_CLK 48000000
unsigned int bit = 8;
int fd =-1;

void myspi_transfer(int fd)
{
int ret = -1;

unsigned char tx[41024] = {
1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36
};
unsigned char rx[4
1024] = { 0x00 };
memset(tx,0x55,4*1024);
#if 1
struct spi_ioc_transfer tr = {
.tx_buf = (__u64)tx,
.rx_buf = (__u64)rx,
.len = 4096,
.delay_usecs = 0,
.speed_hz = TEST_SPI_CLK,
.bits_per_word = 8,
.cs_change = 0, //for CS Deselect
};
#endif
printf("\n %d \n",TEST_SPI_CLK);
while(1)
{
#if 1
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
printf(“can’t send spi message”);
#endif
}

}

int main()
{
int ret;
int tmp;
system(“himm 0x1f0010c8 0x00001401”); //spi4 clock
system(“himm 0x1f0010cc 0x00001401”); //spi4 sd0
system(“himm 0x1f0010d0 0x00001401”); //spi4 sdi
system(“himm 0x1f0010d4 0x00001401”); //spi4 csn0
system(“himm 0x1f0010d8 0x00001401”); //spi4 csn1
system(“himm 0x1f0010dc 0x00001401”); //spi4 csn2
system(“himm 0x1f0010e0 0x00001401”); //spi4 csn3
system(“himm 0x18020020 0x02022222”);
system(“himm 0x18050000 0x00001401”); //spi5 clock sensorhub
system(“himm 0x18050004 0x00001401”); //spi5 sd0
system(“himm 0x18050008 0x00001401”); //spi5 sdi
system(“himm 0x1805000c 0x00001401”); //spi5 csn0
system(“himm 0x18050070 0x00001402”); //spi5 csn1
system(“himm 0x18050074 0x00001402”); //spi5 csn2
fd = open(file_name, O_RDWR );
if(fd < 0){
printf(“open spi port is error!\r\n”);
return -1;
}else{
printf(“open spi port is success!\r\n”);
}
tmp = SPI_MODE_3;//| SPI_LSB_FIRST
ret = ioctl(fd,SPI_IOC_WR_MODE, &tmp);
if (ret) {
printf(“set spi mode fail!\n”);
goto end1;
}else{
printf(“set spi mode success!\n”);
}

#if 1
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bit);
if (ret == -1)
printf(“can’t set bits per word”);
ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bit);
if (ret == -1)
printf(“can’t get bits per word”);
#endif

#if 1
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf(“can’t set max speed hz”);
ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
printf(“can’t get max speed hz”);
#endif
myspi_transfer(fd);

end1:
close(fd);
return 0;
}

你可能感兴趣的:(海思平台开发,3559AV100,海思,DMA,sensorhub)