import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / input / touchscreen / mediatek / synaptics_7020_s7 / RefCode_F54_HighResistance.c
1 /*
2 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 Copyright (c) 2011 Synaptics, Inc.
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy of
6 this software and associated documentation files (the "Software"), to deal in
7 the Software without restriction, including without limitation the rights to use,
8 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
9 Software, and to permit persons to whom the Software is furnished to do so,
10 subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in all
13 copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 SOFTWARE.
22 */
23
24 #include "RefCode.h"
25 #include "RefCode_PDTScan.h"
26
27 #ifdef _F54_TEST_
28 unsigned char F54_HighResistance(void)
29 {
30 unsigned char imageBuffer[6];
31 short resistance[3];
32 int i, Result=0;
33 unsigned char command;
34
35 #ifdef F54_Porting
36 int resistanceLimit[3][2] = { {-1000, 450}, {-1000, 450}, {-400, 20} }; //base value * 1000
37 char buf[512] = {0};
38 int ret = 0;
39 #else
40 float resistanceLimit[3][2] = {-1, 0.45, -1, 0.45, -0.4, 0.02};
41 #endif
42
43 #ifdef F54_Porting
44 ret = sprintf(buf, "\nBin #: 12 Name: High Resistance Test\n");
45 #else
46 printk("\nBin #: 12 Name: High Resistance Test\n");
47 #endif
48
49 // Set report mode
50 command = 0x04;
51 writeRMI(F54_Data_Base, &command, 1);
52
53 // Force update
54 command = 0x04;
55 writeRMI(F54_Command_Base, &command, 1);
56
57 do {
58 delayMS(1); //wait 1ms
59 readRMI(F54_Command_Base, &command, 1);
60 } while (command != 0x00);
61
62 command = 0x02;
63 writeRMI(F54_Command_Base, &command, 1);
64
65 do {
66 delayMS(1); //wait 1ms
67 readRMI(F54_Command_Base, &command, 1);
68 } while (command != 0x00);
69
70 command = 0x00;
71 writeRMI(F54_Data_LowIndex, &command, 1);
72 writeRMI(F54_Data_HighIndex, &command, 1);
73
74 // Set the GetReport bit
75 command = 0x01;
76 writeRMI(F54_Command_Base, &command, 1);
77
78 // Wait until the command is completed
79 do {
80 delayMS(1); //wait 1ms
81 readRMI(F54_Command_Base, &command, 1);
82 } while (command != 0x00);
83
84 readRMI(F54_Data_Buffer, imageBuffer, 6);
85
86 #ifdef F54_Porting
87 ret += sprintf(buf+ret, "Parameters:\t");
88 #else
89 printk("Parameters:\t");
90 #endif
91 for(i=0; i<3; i++)
92 {
93 resistance[i] = (short)((imageBuffer[i*2+1] << 8) | imageBuffer[i*2]);
94 #ifdef F54_Porting
95 ret += sprintf(buf+ret, "%d,\t\t", (resistance[i]));
96 #else
97 printk("%1.3f,\t\t", (float)(resistance[i])/1000);
98 #endif
99
100 #ifdef F54_Porting
101 if((resistance[i] >= resistanceLimit[i][0]) && (resistance[i] <= resistanceLimit[i][1])) Result++;
102 #else
103 if((resistance[i]/1000 >= resistanceLimit[i][0]) && (resistance[i]/1000 <= resistanceLimit[i][1])) Result++;
104 #endif
105 }
106 #ifdef F54_Porting
107 ret += sprintf(buf+ret, "\n");
108 ret += sprintf(buf+ret, "Limits:\t\t");
109 #else
110 printk("\n");
111
112 printk("Limits:\t\t");
113 #endif
114 for(i=0; i<3; i++)
115 {
116 #ifdef F54_Porting
117 ret += sprintf(buf+ret, "%d,%d\t", resistanceLimit[i][0], resistanceLimit[i][1]);
118 #else
119 printk("%1.3f,%1.3f\t", resistanceLimit[i][0], resistanceLimit[i][1]);
120 #endif
121 }
122 #ifdef F54_Porting
123 ret += sprintf(buf+ret, "\n");
124 #else
125 printk("\n");
126 #endif
127
128 // Set the Force Cal
129 command = 0x02;
130 writeRMI(F54_Command_Base, &command, 1);
131
132 do {
133 delayMS(1); //wait 1ms
134 readRMI(F54_Command_Base, &command, 1);
135 } while (command != 0x00);
136
137 //enable all the interrupts
138 //Reset
139 command= 0x01;
140 writeRMI(F01_Cmd_Base, &command, 1);
141 delayMS(200);
142 readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
143
144 if(Result == 3)
145 {
146 #ifdef F54_Porting
147 ret += sprintf(buf+ret, "Test Result: Pass\n");
148 write_log(buf);
149 #else
150 printk("Test Result: Pass\n");
151 #endif
152 return 1; //Pass
153 }
154 else
155 {
156 #ifdef F54_Porting
157 ret += sprintf(buf+ret, "Test Result: Fail, Result = %d\n", Result);
158 write_log(buf);
159 #else
160 printk("Test Result: Fail, Result = %d\n", Result);
161 #endif
162 return 0; //Fail
163 }
164 }
165
166 int F54_GetHighResistance(char *buf)
167 {
168 unsigned char imageBuffer[6];
169 short resistance[3];
170 int i, Result=0;
171 unsigned char command;
172
173 int resistanceLimit[3][2] = { {-1000, 450}, {-1000, 450}, {-400, 20} }; //base value * 1000
174 int ret = 0;
175 int waitcount;
176
177 // Set report mode
178 command = 0x04;
179 writeRMI(F54_Data_Base, &command, 1);
180
181 // Force update
182 command = 0x04;
183 writeRMI(F54_Command_Base, &command, 1);
184
185 waitcount = 0;
186 do {
187 if(++waitcount > 500)
188 {
189 pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
190 return ret;
191 }
192 delayMS(1); //wait 1ms
193 readRMI(F54_Command_Base, &command, 1);
194 } while (command != 0x00);
195
196 command = 0x02;
197 writeRMI(F54_Command_Base, &command, 1);
198
199 waitcount = 0;
200 do {
201 if(++waitcount > 500)
202 {
203 pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
204 return ret;
205 }
206 delayMS(1); //wait 1ms
207 readRMI(F54_Command_Base, &command, 1);
208 } while (command != 0x00);
209
210 command = 0x00;
211 writeRMI(F54_Data_LowIndex, &command, 1);
212 writeRMI(F54_Data_HighIndex, &command, 1);
213
214 // Set the GetReport bit
215 command = 0x01;
216 writeRMI(F54_Command_Base, &command, 1);
217
218 // Wait until the command is completed
219 waitcount = 0;
220 do {
221 if(++waitcount > 500)
222 {
223 pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
224 return ret;
225 }
226 delayMS(1); //wait 1ms
227 readRMI(F54_Command_Base, &command, 1);
228 } while (command != 0x00);
229
230 readRMI(F54_Data_Buffer, imageBuffer, 6);
231
232 ret += sprintf(buf+ret, "Params: ");
233 for(i=0; i<3; i++)
234 {
235 resistance[i] = (short)((imageBuffer[i*2+1] << 8) | imageBuffer[i*2]);
236 ret += sprintf(buf+ret, "%d", (resistance[i]));
237 if((resistance[i] >= resistanceLimit[i][0]) && (resistance[i] <= resistanceLimit[i][1]))
238 Result++;
239
240 if(i < 2)
241 ret += sprintf(buf+ret, " ");
242 }
243 ret += sprintf(buf+ret, "\n");
244 ret += sprintf(buf+ret, "Limits: ");
245
246 for(i=0; i<3; i++)
247 {
248 ret += sprintf(buf+ret, "%d,%d", resistanceLimit[i][0], resistanceLimit[i][1]);
249
250 if(i < 2)
251 ret += sprintf(buf+ret, " ");
252 }
253 ret += sprintf(buf+ret, "\n");
254
255 // Set the Force Cal
256 command = 0x02;
257 writeRMI(F54_Command_Base, &command, 1);
258
259 waitcount = 0;
260 do {
261 if(++waitcount > 100)
262 {
263 pr_info("%s[%d], command = %d\n", __func__, __LINE__, command);
264 break;
265 }
266 delayMS(1); //wait 1ms
267 readRMI(F54_Command_Base, &command, 1);
268 } while (command != 0x00);
269
270 if (Result == 3)
271 {
272 ret += sprintf(buf+ret, "RESULT: Pass\n");
273 }
274 else
275 {
276 ret += sprintf(buf+ret, "RESULT: Fail\n");
277 }
278
279 //enable all the interrupts
280 // SetPage(0x00);
281 //Reset
282 command= 0x01;
283 writeRMI(F01_Cmd_Base, &command, 1);
284 delayMS(200);
285 readRMI(F01_Data_Base+1, &command, 1); //Read Interrupt status register to Interrupt line goes to high
286
287 return ret;
288 }
289 #endif
290