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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Copyright (c) 2011 Synaptics, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
*/
#include "RefCode_CustomerImplementation.h"
#include <linux/delay.h> //msleep
#include <linux/gpio.h> //gpio_get_value
#include <linux/file.h> //for file access
#include <linux/syscalls.h> //for file access
#include <linux/uaccess.h> //for file access
#include <mach/mt_gpio.h>
#include "cust_gpio_usage.h"
static char currentPage;
static char line[4096]={0};
int LimitFile[30][46*2];
//float LimitFile[30][46*2];
void device_I2C_read(unsigned char add, unsigned char *value, unsigned short len)
{
// I2C read
if(ds4_i2c_client == NULL) {
printk("[Touch] ds4_i2c_client is NULL\n");
return;
} else {
if(synaptics_ts_read(ds4_i2c_client, add, len, value) < 0) return;
}
}
void device_I2C_write(unsigned char add, unsigned char *value, unsigned short len)
{
// I2C write
if(ds4_i2c_client == NULL) {
printk("[Touch] ds4_i2c_client is NULL\n");
return;
} else {
if(synaptics_ts_write(ds4_i2c_client, add, value, len) < 0) return;
}
}
void InitPage(void)
{
currentPage = 0;
}
void SetPage(unsigned char page)
{
device_I2C_write(0xFF, &page, 1); //changing page
}
void readRMI(unsigned short add, unsigned char *value, unsigned short len)
{
unsigned char temp;
temp = add >> 8;
if(temp != currentPage)
{
currentPage = temp;
SetPage(currentPage);
}
device_I2C_read(add & 0xFF, value, len);
}
void longReadRMI(unsigned short add, unsigned char *value, unsigned short len)
{
unsigned char temp;
temp = add >> 8;
if(temp != currentPage)
{
currentPage = temp;
SetPage(currentPage);
}
if(ds4_i2c_client == NULL) {
printk("[Touch] ds4_i2c_client is NULL\n");
return;
} else {
if(synaptics_ts_read_f54(ds4_i2c_client, (add & 0xFF), len, value) < 0) return;
}
}
void writeRMI(unsigned short add, unsigned char *value, unsigned short len)
{
unsigned char temp;
temp = add >> 8;
if(temp != currentPage)
{
currentPage = temp;
SetPage(currentPage);
}
device_I2C_write(add & 0xFF, value, len);
}
void delayMS(int val)
{
msleep(val);
// Wait for val MS
}
void cleanExit(int code)
{
//FIXME: add kernel exit function
return;
}
int waitATTN(int code, int time)
{
int trial_us=0;
while ((mt_get_gpio_in(GPIO_CTP_EINT_PIN) != 0) && (trial_us < (time * 1000))) {
udelay(1);
trial_us++;
}
if (mt_get_gpio_in(GPIO_CTP_EINT_PIN) != 0)
return -EBUSY;
else
return 1;
}
void write_log(char *data)
{
int fd;
char *fname = "/mnt/sdcard/synaptics_f54_log.txt";
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
fd = sys_open(fname, O_WRONLY|O_CREAT|O_APPEND, 0644);
if (fd >= 0)
{
sys_write(fd, data, strlen(data));
sys_close(fd);
}
set_fs(old_fs);
}
int get_limit( unsigned char Tx, unsigned char Rx)
{
int fd, i, j;
char *fname = "/mnt/sdcard/synaptics_f54_limit.txt";
char buff[5]={0};
int p = 0;
int q = 0;
int ret = 0;
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
fd = sys_open(fname, O_RDONLY, 0);
if ( fd < 0 ) ret = 0;
else {
memset(LimitFile, 0, sizeof(LimitFile));
memset(line, 0, sizeof(line));
sys_read(fd, line, sizeof(line));
for(i = 0; i < Tx; i++) {
for(j = 0; j < Rx; j++) {
while(1) {
if( line[q] != ',' && line[q] != '\r' && line[q] != '\n' ) {
buff[p++] = line[q++];
} else if(line[q] == ',') {
p=0; q++;
LimitFile[i][j] = (int)simple_strtol(&buff[0], NULL, 10);
//printk("LimitFile[%d][%d]=%d ", i, j, LimitFile[i][j]);
memset(buff, 0, sizeof(buff));
break;
} else {
q++;
}
}
}
}
ret = 1;
}
sys_close(fd);
set_fs(old_fs);
return ret;
}
#if 0
int waitATTN(unsigned char set, int val)
{
if(set ==1)
{
// Wait ATTN for val MS
// If get ATTN within val MS, return 1;
// else, return 0;
}
else
{
// Wait no ATTN for val MS
// If get ATTN within val MS, return 1;
// else, return 0;
}
}
void main(void)
/* Please be informed this main() function is an example for host implementation */
{
// Run PDT Scan
SYNA_PDTScan();
SYNA_ConstructRMI_F54();
SYNA_ConstructRMI_F1A();
// Run test functions
F54_FullRawCap(0);
// Check FW information including product ID
FirmwareCheck();
}
#endif
|