forked from otya128/tbs6812_drv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbsecp3-asi.c
103 lines (76 loc) · 2.36 KB
/
tbsecp3-asi.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "tbsecp3.h"
u8 asi_CheckFree(struct tbsecp3_dev *dev,int asi_base_addr, unsigned char OpbyteNum)
{
unsigned char tmpbuf[4];
int i;
int j=500;
if(OpbyteNum==2)
j=400;
else if(OpbyteNum==1)
j=200;
//pauseThread(OpbyteNum+1);
tmpbuf[0] = 0;
for(i=0;(i<j) && (tmpbuf[0] != 1);i++)
{
*(u32 *)tmpbuf = tbs_read(asi_base_addr, ASI_STATUS );
}
//return (tmpbuf[0] == 1);
if(tmpbuf[0] == 1)
return true;
else
{
printk("----------asi spi interface check error! %x\n",tmpbuf[0]);
return false;
}
}
bool asi_chip_reset(struct tbsecp3_dev *dev,int asi_base_addr)
{
unsigned char tmpbuf[4];
tmpbuf[0] = 0;
tbs_write( asi_base_addr, ASI_CHIP_RST, *(u32 *)&tmpbuf[0]);
msleep(20);
tmpbuf[0] = 1;
tbs_write( asi_base_addr, ASI_CHIP_RST, *(u32 *)&tmpbuf[0]);
msleep(100);
return true ;
}
int asi_read16bit(struct tbsecp3_dev *dev,int asi_base_addr,int reg_addr)
{
unsigned char tmpbuf[4];
int regData;
tmpbuf[0] = (unsigned char) (reg_addr>>8)&0xff; //read_address, msb first;
tmpbuf[1] = (unsigned char)(reg_addr&0xff);
tmpbuf[0] += 0x80; //read data;
tbs_write( asi_base_addr, ASI_SPI_CMD, *(u32 *)&tmpbuf[0]);
tmpbuf[0] = 0xf0; //cs low,cs high, write, read;
tmpbuf[1] = 0x20; // 2 bytes command for writing;
tmpbuf[1] += 0x02; //read 2 bytes data;
tbs_write( asi_base_addr, ASI_SPI_CONFIG, *(u32 *)&tmpbuf[0]);
if(asi_CheckFree(dev,asi_base_addr,2)== false)
{
printk(" spi_read16bit error!\n");
return false;
}
*(u32 *)tmpbuf = tbs_read(asi_base_addr, ASI_SPI_RD_32 );
regData = ((tmpbuf[0]<<8) | tmpbuf[1]);
return regData;
}
bool asi_write16bit(struct tbsecp3_dev *dev,int asi_base_addr, int reg_addr, int data16bit)
{
unsigned char tmpbuf[4];
int regData;
tmpbuf[0] = (unsigned char) (reg_addr>>8)&0xff; //read_address, msb first;
tmpbuf[1] = (unsigned char)(reg_addr&0xff);
tmpbuf[2] = (unsigned char) (data16bit>>8)&0xff; //read_address, msb first;
tmpbuf[3] = (unsigned char)(data16bit&0xff);
tbs_write( asi_base_addr, ASI_SPI_CMD, *(u32 *)&tmpbuf[0]);
tmpbuf[0] = 0xe0; //cs low,cs high, write, no read;
tmpbuf[1] = 0x40; // 4 bytes command for writing;
tbs_write( asi_base_addr, ASI_SPI_CONFIG, *(u32 *)&tmpbuf[0]);
if(asi_CheckFree(dev,asi_base_addr,2)== false)
{
printk(" spi_write16bit error!\n");
return false;
}
return true ;
}