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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
|
/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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_F54.h"
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/delay.h> //msleep
#include <linux/file.h> //for file access
#include <linux/syscalls.h> //for file access
#include <linux/uaccess.h> //for file access
#include <linux/firmware.h>
static char line[49152]={0};
int UpperImage[32][32];
int LowerImage[32][32];
int SensorSpeedUpperImage[32][32];
int SensorSpeedLowerImage[32][32];
int ADCUpperImage[32][32];
int ADCLowerImage[32][32];
extern struct i2c_client* ds4_i2c_client;
//extern struct i2c_client *tpd_i2c_client;
extern int touch_i2c_read(struct i2c_client *client, u8 reg, int len, u8 *buf);
extern int touch_i2c_write(struct i2c_client *client, u8 reg, int len, u8 * buf);
extern int synaptics_ts_read ( struct i2c_client *client, u8 reg, int num, u8 *buf );
extern int synaptics_ts_write ( struct i2c_client *client, u8 reg, u8 * buf, int len );
extern int synaptics_ts_read_f54(struct i2c_client * client,u8 reg,int num,u8 * buf);
int Read8BitRegisters(unsigned short regAddr, unsigned char *data, int length)
{
// I2C read
int rst = 0;
if( ds4_i2c_client == NULL)
{
printk("s3528 ds4_i2c_client is null");
return -1;
}
rst = synaptics_ts_read(ds4_i2c_client, regAddr, length, data);
if ( rst < 0 )
{
TPD_ERR ( "Read8BitRegisters read fail\n" );
}
return rst;
}
int ReadF54BitRegisters(unsigned short regAddr, unsigned char *data, int length)
{
TPD_FUN();
// I2C read
int rst = 0;
if( ds4_i2c_client == NULL)
{
printk("s3528 ds4_i2c_client is null");
return -1;
}
rst = synaptics_ts_read_f54(ds4_i2c_client, regAddr, length, data);
if ( rst < 0 )
{
TPD_ERR ( "Read8BitRegisters read fail\n" );
}
return rst;
}
int Write8BitRegisters(unsigned short regAddr, unsigned char *data, int length)
{
// I2C write
int rst = 0;
if(ds4_i2c_client == NULL)
{
printk("s3528 ds4_i2c_client is null");
return -1;
}
rst = synaptics_ts_write(ds4_i2c_client, regAddr, data, length);
if ( rst < 0 )
{
TPD_ERR ( "Write8BitRegisters read fail\n" );
}
return rst;
}
void delayMS_DS5(int val)
{
// Wait for val MS
msleep(val);
}
int write_file(char *filename, char *data)
{
int fd = 0;
fd = sys_open(filename, O_WRONLY|O_CREAT|O_APPEND, 0666);
if (fd < 0) {
printk("[s3528_write_file] : Open file error [ %d ]\n", fd);
return fd;
} else {
sys_write(fd, data, strlen(data));
sys_close(fd);
}
return 0;
}
int write_log_DS5(char *filename, char *data)
{
//extern int f54_window_crack;
//extern int f54_window_crack_check_mode;
int fd;
char *fname = "/mnt/sdcard/touch_self_test.txt";
int cap_file_exist = 0;
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
if(filename == NULL){
fd = sys_open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666);
printk("write log in /mnt/sdcard/touch_self_test.txt\n");
} else{
fd = sys_open(filename, O_WRONLY|O_CREAT, 0666);
printk("write log in /sns/touch/cap_diff_test.txt\n");
}
printk("[s3528-write_log]write file open %s, fd : %d\n", (fd >= 0)? "success": "fail", fd);
if(fd >= 0) {
/*because of erro, this code is blocked.*/
/*if(sys_newstat((char __user *) fname, (struct stat *)&fstat) < 0) {
printk("[Touch] cannot read %s stat info\n", fname);
} else {
if(fstat.st_size > 5 * 1024 * 1024) {
printk("[Touch] delete %s\n", fname);
sys_unlink(fname);
sys_close(fd);
fd = sys_open(fname, O_WRONLY|O_CREAT|O_APPEND, 0644);
if(fd >= 0) {
sys_write(fd, data, strlen(data));
}
} else {
sys_write(fd, data, strlen(data));
}
sys_close(fd);
}*/
sys_write(fd, data, strlen(data));
sys_close(fd);
if(filename != NULL)
cap_file_exist = 1;
}
set_fs(old_fs);
return cap_file_exist;
}
//seungmin.noh
#if 0
void read_log(char *filename, const struct touch_platform_data *pdata)
{
int fd;
char* buf = NULL;
int rx_num = 0;
int tx_num = 0;
int data_pos = 0;
int offset = 0;
struct touch_platform_data *ppdata = (struct touch_platform_data*)pdata;
mm_segment_t old_fs = get_fs();
set_fs(KERNEL_DS);
fd = sys_open(filename, O_RDONLY, 0);
buf = kzalloc(1024, GFP_KERNEL);
printk("[s3528-read_log]read file open %s, fd : %d\n", (fd >= 0)? "success": "fail", fd);
if (fd >= 0) {
printk("[s3528-read_log]open read_log funcion in /sns/touch/cap_diff_test.txt\n",__func__);
while(sys_read(fd, buf, 1024)) {
printk("[s3528-read_log]sys_read success\n");
for(rx_num = 0; rx_num < (ppdata->rx_ch_count) - 1; rx_num++)
{
sscanf(buf + data_pos, "%d%n", &ppdata->rx_cap[rx_num], &offset);
data_pos += offset;
}
for(tx_num = 0; tx_num < (ppdata->tx_ch_count) - 1; tx_num++)
{
sscanf(buf + data_pos, "%d%n", &ppdata->tx_cap[tx_num], &offset);
data_pos += offset;
}
printk("[s3528-read_log]rx_num = %d, tx_num = %d\n", rx_num, tx_num);
printk("[s3528-read_log]rx_ch_count = %d, tx_ch_count = %d\n", ppdata->rx_ch_count, ppdata->tx_ch_count);
if((rx_num == (ppdata->rx_ch_count) -1) && (tx_num == (ppdata->tx_ch_count) -1))
break;
}
sys_close(fd);
}
if(buf)
kfree(buf);
set_fs(old_fs);
}
#endif
#if 0
int get_limit(unsigned char Tx, unsigned char Rx, struct i2c_client client, const struct touch_platform_data *pdata, char *breakpoint, int limit_data[32][32])
{
int p = 0;
int q = 0;
int r = 0;
int cipher = 1;
int ret = 0;
int rx_num = 0;
int tx_num = 0;
const struct firmware *fwlimit = NULL;
printk("[s3528-get_limit] Tx=[%d], Rx=[%d]\n", (int)Tx, (int)Rx);
printk("[s3528-get_limit] breakpoint = [%s]\n", breakpoint);
if (pdata->panel_spec == NULL) {
printk("panel_spec_file name is null\n");
ret = -1;
goto exit;
}
if(request_firmware(&fwlimit, pdata->panel_spec, &client.dev) < 0) {
printk(" request ihex is failed\n");
ret = -1;
goto exit;
}
strcpy(line, fwlimit->data);
q = strstr(line, breakpoint) - line;
if (q < 0) {
printk("failed to find breakpoint. The panel_spec_file is wrong");
ret = -1;
goto exit;
}
memset(limit_data, 0, (TRX_max * TRX_max) * 4);
while(1) {
if (line[q] == ',') {
cipher = 1;
for (p = 1; (line[q - p] >= '0') && (line[q - p] <= '9'); p++) {
limit_data[tx_num][rx_num] += ((line[q - p] - '0') * cipher);
//printk("[r = %d]limit_data[%d][%d] = %d\n", r, tx_num, rx_num, limit_data[tx_num][rx_num]);
cipher *= 10;
}
if(line[q - p] == '-') {
limit_data[tx_num][rx_num] = (-1) * (limit_data[tx_num][rx_num]);
//printk("[r = %d]limit_data[%d][%d] = %d\n", r, tx_num, rx_num, limit_data[tx_num][rx_num]);
}
r++;
if(r % (int)Rx == 0){
rx_num = 0;
tx_num++;
} else {
rx_num++;
}
}
q++;
if (r == (int)Tx * (int)Rx) {
printk("panel_spec_file scanning is success\n");
break;
}
}
if (fwlimit)
release_firmware(fwlimit);
return ret;
exit :
if (fwlimit)
release_firmware(fwlimit);
return ret;
}
#endif
#if 0
void main(void)
/* Please be informed this main() function & related functions are an example for host implementation */
{
PowerOnSensor();
delayMS(400);
F54Test();
PowerOffSensor();
}
#endif
|