aboutsummaryrefslogtreecommitdiff
path: root/drivers/input/touchscreen/mediatek/synaptics_2200/RefCode_F54_HighResistance.c
blob: 27c50456c8964c2407aeaa07f31394638a2e4086 (plain) (blame)
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
/*
   +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   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.h"
#include "RefCode_PDTScan.h"

#ifdef _F54_TEST_
unsigned char F54_HighResistance(void)
{
	unsigned char imageBuffer[6];
	short resistance[3];
	int i, Result=0;
	unsigned char command;

#ifdef F54_Porting
	int resistanceLimit[3][2] = { {-1000, 450}, {-1000, 450}, {-400, 20} };	//base value * 1000
	char buf[512] = {0};
	int ret = 0;
#else
	float resistanceLimit[3][2] = {-1, 0.45, -1, 0.45, -0.4, 0.02};
#endif

#ifdef F54_Porting
	ret = sprintf(buf, "\nBin #: 12		Name: High Resistance Test\n");
#else
	printk("\nBin #: 12		Name: High Resistance Test\n");
#endif

   // Set report mode
   command = 0x04;
   writeRMI(F54_Data_Base, &command, 1);

   // Force update
   command = 0x04;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);
	  
   command = 0x02;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

   command = 0x00;
   writeRMI(F54_Data_LowIndex, &command, 1);
   writeRMI(F54_Data_HighIndex, &command, 1);
   
   // Set the GetReport bit
   command = 0x01;
   writeRMI(F54_Command_Base, &command, 1);

   // Wait until the command is completed
   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);

	readRMI(F54_Data_Buffer, imageBuffer, 6);

#ifdef F54_Porting
	ret += sprintf(buf+ret, "Parameters:\t");
#else
	printk("Parameters:\t");	
#endif
	for(i=0; i<3; i++)
	{
		resistance[i] = (short)((imageBuffer[i*2+1] << 8) | imageBuffer[i*2]);
#ifdef F54_Porting
		ret += sprintf(buf+ret, "%d,\t\t", (resistance[i]));
#else
		printk("%1.3f,\t\t", (float)(resistance[i])/1000);
#endif

#ifdef F54_Porting
		if((resistance[i] >= resistanceLimit[i][0]) && (resistance[i] <= resistanceLimit[i][1]))	Result++;
#else
		if((resistance[i]/1000 >= resistanceLimit[i][0]) && (resistance[i]/1000 <= resistanceLimit[i][1]))	Result++;
#endif		
	}
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n");
	ret += sprintf(buf+ret, "Limits:\t\t");
#else
	printk("\n");

	printk("Limits:\t\t");
#endif
	for(i=0; i<3; i++)
	{
#ifdef F54_Porting	
		ret += sprintf(buf+ret, "%d,%d\t", resistanceLimit[i][0], resistanceLimit[i][1]);
#else
		printk("%1.3f,%1.3f\t", resistanceLimit[i][0], resistanceLimit[i][1]);
#endif
	}
#ifdef F54_Porting
	ret += sprintf(buf+ret, "\n");
#else
	printk("\n");
#endif
	
   // Set the Force Cal
   command = 0x02;
   writeRMI(F54_Command_Base, &command, 1);

   do {
		delayMS(1); //wait 1ms
        readRMI(F54_Command_Base, &command, 1);
   } while (command != 0x00);
	  
   //enable all the interrupts
   //Reset
   command= 0x01;
   writeRMI(F01_Cmd_Base, &command, 1);
   delayMS(200);
   readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

   if(Result == 3)
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Pass\n");
		write_log(buf);
#else
		printk("Test Result: Pass\n");
#endif
		return 1; //Pass
	}
   else
	{
#ifdef F54_Porting
		ret += sprintf(buf+ret, "Test Result: Fail, Result = %d\n", Result);
		write_log(buf);
#else	
		printk("Test Result: Fail, Result = %d\n", Result);
#endif
		return 0; //Fail
	}
}

int F54_GetHighResistance(char *buf)
{
	unsigned char imageBuffer[6];
	short resistance[3];
	int i, Result=0;
	unsigned char command;

	int resistanceLimit[3][2] = { {-1000, 450}, {-1000, 450}, {-400, 20} };	//base value * 1000
	int ret = 0;
	int waitcount;

	// Set report mode
	command = 0x04;
	writeRMI(F54_Data_Base, &command, 1);

	// Force update
	command = 0x04;
	writeRMI(F54_Command_Base, &command, 1);

	waitcount = 0;
	do {
		if(++waitcount > 500)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			return ret;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	command = 0x02;
	writeRMI(F54_Command_Base, &command, 1);

	waitcount = 0;
	do {
		if(++waitcount > 500)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			return ret;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	command = 0x00;
	writeRMI(F54_Data_LowIndex, &command, 1);
	writeRMI(F54_Data_HighIndex, &command, 1);

	// Set the GetReport bit
	command = 0x01;
	writeRMI(F54_Command_Base, &command, 1);

	// Wait until the command is completed
	waitcount = 0;
	do {
		if(++waitcount > 500)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			return ret;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	readRMI(F54_Data_Buffer, imageBuffer, 6);

	ret += sprintf(buf+ret, "Params: ");
	for(i=0; i<3; i++)
	{
		resistance[i] = (short)((imageBuffer[i*2+1] << 8) | imageBuffer[i*2]);
		ret += sprintf(buf+ret, "%d", (resistance[i]));
		if((resistance[i] >= resistanceLimit[i][0]) && (resistance[i] <= resistanceLimit[i][1]))
			Result++;

		if(i < 2)
			ret += sprintf(buf+ret, " ");
	}
	ret += sprintf(buf+ret, "\n");
	ret += sprintf(buf+ret, "Limits: ");

	for(i=0; i<3; i++)
	{
		ret += sprintf(buf+ret, "%d,%d", resistanceLimit[i][0], resistanceLimit[i][1]);

		if(i < 2)
			ret += sprintf(buf+ret, " ");
	}
	ret += sprintf(buf+ret, "\n");

	// Set the Force Cal
	command = 0x02;
	writeRMI(F54_Command_Base, &command, 1);

	waitcount = 0;
	do {
		if(++waitcount > 100)
		{
			pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
			break;
		}
		delayMS(1); //wait 1ms
		readRMI(F54_Command_Base, &command, 1);
	} while (command != 0x00);

	if (Result == 3)
	{
		ret += sprintf(buf+ret, "RESULT: Pass\n");
	}
	else
	{
		ret += sprintf(buf+ret, "RESULT: Fail\n");
	}

	//enable all the interrupts
	//	SetPage(0x00);
	//Reset
	command= 0x01;
	writeRMI(F01_Cmd_Base, &command, 1);
	delayMS(200);
	readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high

	return ret;
}
#endif