Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | /* |
2 | * Copyright (C) 2013 LG Electironics, Inc. | |
3 | * | |
4 | * This software is licensed under the terms of the GNU General Public | |
5 | * License version 2, as published by the Free Software Foundation, and | |
6 | * may be copied, distributed, and modified under those terms. | |
7 | * | |
8 | * This program is distributed in the hope that it will be useful, | |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 | * GNU General Public License for more details. | |
12 | * | |
13 | */ | |
14 | ||
15 | /**************************************************************************** | |
16 | * Include Files | |
17 | ****************************************************************************/ | |
18 | #include <linux/init.h> | |
19 | #include <linux/module.h> | |
20 | #include <linux/delay.h> | |
21 | #include <linux/i2c.h> | |
22 | #include <linux/input.h> | |
23 | #include <linux/slab.h> | |
24 | #include <linux/gpio.h> | |
25 | #include <linux/sched.h> | |
26 | #include <linux/kthread.h> | |
27 | #include <linux/bitops.h> | |
28 | #include <linux/kernel.h> | |
29 | #include <linux/delay.h> | |
30 | #include <linux/byteorder/generic.h> | |
31 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
32 | #include <linux/earlysuspend.h> | |
33 | #endif | |
34 | #include <linux/interrupt.h> | |
35 | #include <linux/input/mt.h> | |
36 | #include <linux/time.h> | |
37 | #include <linux/rtpm_prio.h> | |
38 | #include <linux/proc_fs.h> | |
39 | #include <linux/jiffies.h> | |
40 | #include <linux/spinlock.h> | |
41 | #include <linux/wakelock.h> | |
42 | #include <linux/dma-mapping.h> | |
43 | ||
44 | #include <mach/wd_api.h> | |
45 | #include <mach/eint.h> | |
46 | #include <mach/mt_wdt.h> | |
47 | #include <mach/mt_gpt.h> | |
48 | #include <mach/mt_reg_base.h> | |
49 | #include <mach/mt_pm_ldo.h> | |
50 | #include <mach/mt_typedefs.h> | |
51 | #include <mach/mt_boot.h> | |
52 | ||
53 | #include <asm/uaccess.h> | |
54 | #include <cust_eint.h> | |
55 | ||
56 | #include "tpd.h" | |
57 | #include "s7020_driver.h" | |
58 | ||
59 | #define LGE_USE_SYNAPTICS_FW_UPGRADE | |
60 | #if defined(LGE_USE_SYNAPTICS_FW_UPGRADE) | |
61 | #include <linux/workqueue.h> | |
62 | #include "s7020_fw.h" | |
63 | #endif | |
64 | ||
65 | #define LGE_USE_SYNAPTICS_F54 | |
66 | #if defined(LGE_USE_SYNAPTICS_F54) | |
67 | #include "RefCode.h" | |
68 | #include "RefCode_PDTScan.h" | |
69 | #endif | |
70 | ||
71 | ||
72 | ||
73 | /**************************************************************************** | |
74 | * Constants / Definitions | |
75 | ****************************************************************************/ | |
76 | #define LGE_TOUCH_NAME "lge_touch" | |
77 | #define TPD_DEV_NAME "synaptics_S7020" | |
78 | ||
79 | #define TPD_I2C_ADDRESS 0x20 | |
80 | ||
81 | #define BUFFER_SIZE 128 | |
82 | ||
83 | #define MAX_NUM_OF_FINGER 10 | |
84 | ||
85 | #define X_POSITION 0 | |
86 | #define Y_POSITION 1 | |
87 | #define XY_POSITION 2 | |
88 | #define WX_WY 3 | |
89 | #define PRESSURE 4 | |
90 | #define NUM_OF_EACH_FINGER_DATA_REG 5 | |
91 | ||
92 | #define MAX_POINT_SIZE_FOR_LPWG 12 | |
93 | ||
94 | #define TOUCH_PRESSED 1 | |
95 | #define TOUCH_RELEASED 0 | |
96 | #define BUTTON_CANCLED 0xFF | |
97 | ||
98 | ||
99 | #define PAGE_MAX_NUM 5 | |
100 | #define PAGE_SELECT_REG 0xFF | |
101 | #define DESCRIPTION_TABLE_START 0xE9 | |
102 | ||
103 | #define RMI_DEVICE_CONTROL 0x01 | |
104 | #define TOUCHPAD_SENSORS 0x11 | |
105 | #define CAPACITIVE_BUTTON_SENSORS 0x1A | |
106 | #define FLASH_MEMORY_MANAGEMENT 0x34 | |
107 | #define MULTI_TAP_GESTURE 0x51 | |
108 | ||
109 | /* Function $01 (RMI_DEVICE_CONTROL) */ | |
110 | #define MANUFACTURER_ID_REG (device_control.query_base) | |
111 | #define FW_REVISION_REG (device_control.query_base+3) | |
112 | #define PRODUCT_ID_REG (device_control.query_base+11) | |
113 | ||
114 | #define DEVICE_CONTROL_REG (device_control.control_base) | |
115 | #define NORMAL_OPERATION_MASK 0x00 | |
116 | #define SENSOR_SLEEP_MASK 0x01 | |
117 | #define NOSLEEP_MASK 0x04 | |
118 | #define CONFIGURED_MASK 0x80 | |
119 | #define INTERRUPT_ENABLE_REG (device_control.control_base+1) | |
120 | #define ABS0_MASK 0x04 | |
121 | #define BUTTON_MASK 0x10 | |
122 | ||
123 | #define DEVICE_STATUS_REG (device_control.data_base) | |
124 | #define DEVICE_FAILURE_MASK 0x03 | |
125 | #define FW_CRC_FAILURE_MASK 0x04 | |
126 | #define FLASH_PROG_MASK 0x40 | |
127 | #define UNCONFIGURED_MASK 0x80 | |
128 | #define INTERRUPT_STATUS_REG (device_control.data_base+1) | |
129 | ||
130 | /* Function $11 (TOUCHPAD_SENSORS) */ | |
131 | #define TWO_D_COMMAND (finger.command_base) | |
132 | ||
133 | #define TWO_D_REPORT_MODE_REG (finger.control_base) | |
134 | #define CONTINUOUS_REPORTING_MODE_MASK 0x0 | |
135 | #define REDUCED_REPORTING_MODE_MASK 0x01 | |
136 | #define WAKEUP_GESTURE_REPORTING_MODE_MASK 0x04 | |
137 | #define ABS_POS_FILTER_MASK 0x08 | |
138 | #define REPORT_BEYOND_CLIP_MASK 0x80 | |
139 | #define TWO_D_DELTA_X_THRESH_REG (finger.control_base+2) | |
140 | #define TWO_D_DELTA_Y_THRESH_REG (finger.control_base+3) | |
141 | #define DELTA_POS_THRESHOLD 1 | |
142 | #define LPWG_CONTROL_REG (finger.control_base+44) | |
143 | ||
144 | #define TWO_D_FINGER_STATE_REG (finger.data_base) | |
145 | #define FINGER_STATE_MASK 0x03 | |
146 | ||
147 | #define TWO_D_EXTENDED_STATUS_REG (finger.data_base+53) | |
148 | ||
149 | /* Function $1A (CAPACITIVE_BUTTON_SENSORS) */ | |
150 | #define BUTTON_DATA_REG (button.data_base) | |
151 | ||
152 | /* Function $34 (FLASH_MEMORY_MANAGEMENT) */ | |
153 | #define FLASH_CONFIG_ID_REG (flash_memory.control_base) | |
154 | ||
155 | #define FLASH_CONTROL_REG (flash_memory.data_base+18) | |
156 | #define FLASH_STATUS_MASK 0xF0 | |
157 | ||
158 | /* Function $51 (MULTI_TAP_GESTURE) */ | |
159 | #define MULTITAP_ENABLE_REG (multi_tap.control_base+22) | |
160 | #define ENABLE_MULTITAP_REPORTING_MASK 0x01 | |
161 | #define MULTITAP_COUNT_REG (multi_tap.control_base+22) | |
162 | #define MAXIMUM_INTERTAP_TIME_REG (multi_tap.control_base+24) | |
163 | #define MAXIMUM_INTERTAP_DISTANCE_REG (multi_tap.control_base+26) | |
164 | ||
165 | #define GESTURE_STATUS_REG (multi_tap.data_base) | |
166 | #define GESTURE_PROPERTY_REG (multi_tap.data_base+1) | |
167 | ||
168 | #define TPD_HAVE_BUTTON | |
169 | ||
170 | #ifdef TPD_HAVE_BUTTON | |
171 | #ifdef LGE_USE_DOME_KEY | |
172 | #define TPD_KEY_COUNT 2 | |
173 | static int tpd_keys_local[TPD_KEY_COUNT] = {KEY_BACK , KEY_MENU}; | |
174 | #else | |
175 | #define TPD_KEY_COUNT 3 | |
176 | static int tpd_keys_local[TPD_KEY_COUNT] = {KEY_BACK, KEY_MENU, KEY_HOMEPAGE}; | |
177 | #endif | |
178 | #endif | |
179 | ||
180 | ||
181 | //#define ONLY_S2202_RESET_PIN | |
182 | #define WXSERIES_FW | |
183 | #define TAP_ZONE_ENABLE | |
184 | #define WORKQUEUE_FW | |
185 | ||
186 | ||
187 | /**************************************************************************** | |
188 | * Macros | |
189 | ****************************************************************************/ | |
190 | #define GET_X_POSITION(high, low) ((int)(high<<4)|(int)(low&0x0F)) | |
191 | #define GET_Y_POSITION(high, low) ((int)(high<<4)|(int)((low&0xF0)>>4)) | |
192 | ||
193 | #define get_time_interval(a,b) a>=b ? a-b : 1000000+a-b | |
194 | #define jitter_abs(x) (x > 0 ? x : -x) | |
195 | #define jitter_sub(x, y) (x > y ? x - y : y - x) | |
196 | ||
197 | #define MS_TO_NS(x) (x * 1E6L) | |
198 | ||
199 | ||
200 | /**************************************************************************** | |
201 | * Type Definitions | |
202 | ****************************************************************************/ | |
203 | typedef struct { | |
204 | u8 query_base; | |
205 | u8 command_base; | |
206 | u8 control_base; | |
207 | u8 data_base; | |
208 | u8 int_source_count; | |
209 | u8 function_exist; | |
210 | } function_descriptor; | |
211 | ||
212 | typedef struct { | |
213 | unsigned char finger_state[3]; | |
214 | unsigned char finger_data[MAX_NUM_OF_FINGER][NUM_OF_EACH_FINGER_DATA_REG]; | |
215 | } touch_sensor_data; | |
216 | ||
217 | typedef struct { | |
218 | unsigned int pos_x[MAX_NUM_OF_FINGER]; | |
219 | unsigned int pos_y[MAX_NUM_OF_FINGER]; | |
220 | unsigned char pressure[MAX_NUM_OF_FINGER]; | |
221 | int total_num; | |
222 | char palm; | |
223 | } touch_finger_info; | |
224 | ||
225 | typedef struct { | |
226 | unsigned int booting; | |
227 | unsigned int reset; | |
228 | } touch_delay; | |
229 | ||
230 | enum { | |
231 | IGNORE_INTERRUPT = 100, | |
232 | NEED_TO_OUT, | |
233 | NEED_TO_INIT, | |
234 | }; | |
235 | ||
236 | enum { | |
237 | IC_CTRL_CODE_NONE = 0, | |
238 | IC_CTRL_BASELINE, | |
239 | IC_CTRL_READ, | |
240 | IC_CTRL_WRITE, | |
241 | IC_CTRL_RESET_CMD, | |
242 | IC_CTRL_REPORT_MODE, | |
243 | IC_CTRL_DOUBLE_TAP_WAKEUP_MODE, | |
244 | }; | |
245 | ||
246 | enum { | |
247 | BASELINE_OPEN = 0, | |
248 | BASELINE_FIX, | |
249 | BASELINE_REBASE, | |
250 | }; | |
251 | ||
252 | enum { | |
253 | TIME_EX_INIT_TIME, | |
254 | TIME_EX_FIRST_INT_TIME, | |
255 | TIME_EX_PREV_PRESS_TIME, | |
256 | TIME_EX_CURR_PRESS_TIME, | |
257 | TIME_EX_BUTTON_PRESS_START_TIME, | |
258 | TIME_EX_BUTTON_PRESS_END_TIME, | |
259 | TIME_EX_FIRST_GHOST_DETECT_TIME, | |
260 | TIME_EX_SECOND_GHOST_DETECT_TIME, | |
261 | TIME_EX_CURR_INT_TIME, | |
262 | TIME_EX_PROFILE_MAX | |
263 | }; | |
264 | ||
265 | enum { | |
266 | LPWG_NONE = 0, | |
267 | LPWG_DOUBLE_TAP, | |
268 | LPWG_MULTI_TAP, | |
269 | }; | |
270 | ||
271 | enum{ | |
272 | LPWG_READ = 1, | |
273 | LPWG_ENABLE, | |
274 | LPWG_LCD_X, | |
275 | LPWG_LCD_Y, | |
276 | LPWG_ACTIVE_AREA_X1, | |
277 | LPWG_ACTIVE_AREA_X2, | |
278 | LPWG_ACTIVE_AREA_Y1, | |
279 | LPWG_ACTIVE_AREA_Y2, | |
280 | LPWG_TAP_COUNT, | |
281 | LPWG_REPLY, | |
282 | }; | |
283 | ||
284 | struct point { | |
285 | int x; | |
286 | int y; | |
287 | }; | |
288 | ||
289 | struct st_i2c_msgs { | |
290 | struct i2c_msg *msg; | |
291 | int count; | |
292 | } i2c_msgs; | |
293 | ||
294 | struct foo_obj{ | |
295 | struct kobject kobj; | |
296 | int interrupt; | |
297 | }; | |
298 | ||
299 | static struct foo_obj *foo_obj; | |
300 | ||
301 | ||
302 | /**************************************************************************** | |
303 | * Variables | |
304 | ****************************************************************************/ | |
305 | static function_descriptor device_control; | |
306 | static function_descriptor finger; | |
307 | static function_descriptor button; | |
308 | static function_descriptor flash_memory; | |
309 | static function_descriptor multi_tap; | |
310 | ||
311 | u8 device_control_page; | |
312 | u8 finger_page; | |
313 | u8 button_page; | |
314 | u8 flash_memory_page; | |
315 | u8 multi_tap_page; | |
316 | ||
317 | u8 button_enable_mask; | |
318 | ||
319 | touch_finger_info pre_touch_info; | |
320 | touch_delay delay_time; | |
321 | char button_prestate[TPD_KEY_COUNT]; | |
322 | char finger_prestate[MAX_NUM_OF_FINGER]; | |
323 | ||
324 | static bool Power_status=0; | |
325 | char knock_on_type; | |
326 | static int knock_on_enable = 0; | |
327 | u8 double_tap_enable = 0; | |
328 | u8 multi_tap_enable = 0; | |
329 | u8 multi_tap_count; | |
330 | u8 lpwg_mode = 0; | |
331 | u32 lcd_touch_ratio_x; | |
332 | u32 lcd_touch_ratio_y; | |
333 | static u8 custom_gesture_status = 0; | |
334 | static u8 gesture_property[MAX_POINT_SIZE_FOR_LPWG*4+1] = {0}; | |
335 | static struct point lpwg_data[MAX_POINT_SIZE_FOR_LPWG+1]; | |
336 | static char *lpwg_uevent[2][2] = { | |
337 | { "TOUCH_GESTURE_WAKEUP=WAKEUP", NULL }, | |
338 | { "TOUCH_GESTURE_WAKEUP=PASSWORD", NULL } | |
339 | }; | |
340 | struct wake_lock knock_code_lock; | |
341 | struct hrtimer multi_tap_timer; | |
342 | struct work_struct multi_tap_work; | |
343 | struct workqueue_struct* touch_multi_tap_wq; | |
344 | ||
345 | /* ghost finger detection */ | |
346 | int x_max; | |
347 | int y_max; | |
348 | static int use_ghost_detection; | |
349 | static int pressure_zero = 0; | |
350 | static int resume_flag = 0; | |
351 | static int ghost_detection = 0; | |
352 | static int ghost_detection_count = 0; | |
353 | static int finger_subtraction_check_count = 0; | |
354 | static int force_continuous_mode = 0; | |
355 | static int ts_rebase_count = 0; | |
356 | static int long_press_check = 0; | |
357 | static int long_press_check_count = 0; | |
358 | static int button_check = 0; | |
359 | static unsigned int button_press_count = 0; | |
360 | static unsigned int old_pos_x = 0; | |
361 | static unsigned int old_pos_y = 0; | |
362 | touch_finger_info old_touch_info; | |
363 | char button_oldstate[TPD_KEY_COUNT]; | |
364 | char finger_oldstate[MAX_NUM_OF_FINGER]; | |
365 | struct timeval t_ex_debug[TIME_EX_PROFILE_MAX]; | |
366 | ||
367 | #if defined(LGE_USE_SYNAPTICS_FW_UPGRADE) | |
368 | char fw_path[256]; | |
369 | unsigned char *fw_start; | |
370 | unsigned long fw_size; | |
371 | bool fw_force_update; | |
372 | bool download_status; /* avoid power off during F/W upgrade */ | |
373 | bool suspend_status; /* avoid power off during F/W upgrade */ | |
374 | bool key_lock_status; | |
375 | struct wake_lock fw_suspend_lock; | |
376 | struct device *touch_fw_dev; | |
377 | struct work_struct work_fw_upgrade; | |
378 | #endif | |
379 | ||
380 | #if defined(LGE_USE_SYNAPTICS_F54) | |
381 | struct i2c_client *ds4_i2c_client; | |
382 | static int f54_fullrawcap_mode = 0; | |
383 | struct device *touch_debug_dev; | |
384 | #endif | |
385 | ||
386 | static u8* I2CDMABuf_va = NULL; | |
387 | static u32 I2CDMABuf_pa = NULL; | |
388 | ||
389 | ||
390 | extern struct tpd_device *tpd; | |
391 | struct i2c_client *tpd_i2c_client = NULL; | |
392 | static int tpd_flag = 0; | |
393 | ||
394 | struct class *touch_class; | |
395 | struct workqueue_struct* touch_wq; | |
396 | ||
397 | static DEFINE_MUTEX(i2c_access); | |
398 | static DECLARE_WAIT_QUEUE_HEAD(tpd_waiter); | |
399 | ||
400 | ||
401 | /**************************************************************************** | |
402 | * Extern Function Prototypes | |
403 | ****************************************************************************/ | |
404 | extern int FirmwareUpgrade ( struct i2c_client *client, const char* fw_path, unsigned long fw_size, unsigned char* fw_start ); | |
405 | extern UINT32 DISP_GetScreenHeight ( void ); | |
406 | extern UINT32 DISP_GetScreenWidth ( void ); | |
407 | extern int mtk_wdt_enable ( enum wk_wdt_en en ); | |
408 | EXPORT_SYMBOL(double_tap_enable); | |
409 | EXPORT_SYMBOL(multi_tap_enable); | |
410 | ||
411 | ||
412 | /**************************************************************************** | |
413 | * Local Function Prototypes | |
414 | ****************************************************************************/ | |
415 | static void touch_eint_interrupt_handler ( void ); | |
416 | void synaptics_initialize ( struct i2c_client *client ); | |
417 | int synaptics_ts_read ( struct i2c_client *client, u8 reg, int num, u8 *buf ); | |
418 | int synaptics_ts_write ( struct i2c_client *client, u8 reg, u8 * buf, int len ); | |
419 | ||
420 | #ifdef WORKQUEUE_FW | |
421 | static int synaptics_firmware_update ( struct work_struct *work_fw_upgrade ); | |
422 | #else | |
423 | static int synaptics_firmware_update ( struct i2c_client *client ); | |
424 | #endif | |
425 | static int synaptics_knock_lpwg ( struct i2c_client* client, u32 code, u32 value, struct point *data ); | |
426 | static void synaptics_reset_pin_power ( int on ); | |
427 | #if ONLY_S2202_RESET_PIN | |
428 | static void synaptics_reset_pin ( int reset_pin ); | |
429 | #endif | |
430 | ||
431 | #ifdef TAP_ZONE_ENABLE | |
432 | #define BLOCK_CHANNEL 1 | |
433 | #define CHANNEL_TX 10 | |
434 | #define CHANNEL_RX 17 | |
435 | static void Set_TapZone(char* arr_tap_zone); | |
436 | #endif | |
437 | /**************************************************************************** | |
438 | * Platform(AP) dependent functions | |
439 | ****************************************************************************/ | |
440 | static void synaptics_setup_eint ( void ) | |
441 | { | |
442 | TPD_FUN (); | |
443 | ||
444 | /* Configure GPIO settings for external interrupt pin */ | |
445 | mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_EINT); | |
446 | mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN); | |
447 | mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE); | |
448 | mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP); | |
449 | ||
450 | msleep(50); | |
451 | ||
452 | /* Configure external interrupt settings for external interrupt pin */ | |
453 | //mt65xx_eint_set_sens ( CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_SENSITIVE ); | |
454 | //mt65xx_eint_set_hw_debounce ( CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_DEBOUNCE_CN ); | |
455 | mt_eint_registration( CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_TYPE, touch_eint_interrupt_handler, 1 ); | |
456 | ||
457 | /* unmask external interrupt */ | |
458 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
459 | ||
460 | } | |
461 | int synaptics_power_vbus( unsigned int on ) | |
462 | { | |
463 | TPD_FUN(); | |
464 | int ret = 0; | |
465 | u8 r_mem = 0; | |
466 | ||
467 | if ( on ) | |
468 | { | |
469 | ||
470 | ret = synaptics_ts_read ( tpd_i2c_client, DEVICE_CONTROL_REG, 1, &r_mem ); | |
471 | if ( ret < 0 ) | |
472 | { | |
473 | TPD_ERR ( "DEVICE_CONTROL_REG read fail\n" ); | |
474 | return ret; | |
475 | } | |
476 | ||
477 | r_mem = (r_mem & 0xFC ) | NOSLEEP_MASK; | |
478 | ||
479 | ret = synaptics_ts_write ( tpd_i2c_client, DEVICE_CONTROL_REG, &r_mem, 1 ); | |
480 | if ( ret < 0 ) | |
481 | { | |
482 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
483 | return ret; | |
484 | } | |
485 | else | |
486 | TPD_LOG("turned on the power ( VGP 1 )\n"); | |
487 | } | |
488 | else | |
489 | { | |
490 | ret = synaptics_ts_read ( tpd_i2c_client, DEVICE_CONTROL_REG, 1, &r_mem ); | |
491 | if ( ret < 0 ) | |
492 | { | |
493 | TPD_ERR ( "DEVICE_CONTROL_REG read fail\n" ); | |
494 | return ret; | |
495 | } | |
496 | ||
497 | r_mem =( r_mem & 0xFC) | SENSOR_SLEEP_MASK; | |
498 | ||
499 | ret = synaptics_ts_write ( tpd_i2c_client, DEVICE_CONTROL_REG, &r_mem, 1 ); | |
500 | if ( ret < 0 ) | |
501 | { | |
502 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
503 | return ret; | |
504 | } | |
505 | else | |
506 | TPD_LOG("turned off the power ( VGP 1 )\n"); | |
507 | } | |
508 | return 1; | |
509 | ||
510 | } | |
511 | void synaptics_power ( unsigned int on ) | |
512 | { | |
513 | TPD_FUN (); | |
514 | ||
515 | if ( on ) | |
516 | { | |
517 | #if 0 | |
518 | hwPowerOn ( MT6323_POWER_LDO_VGP1, VOL_1800, "TP" ); | |
519 | #endif | |
520 | #if defined(ONLY_S2202_RESET_PIN) | |
521 | synaptics_reset_pin ( GPIO_CTP_RST_PIN ); // first | |
522 | #endif | |
523 | hwPowerOn ( MT6323_POWER_LDO_VGP1, VOL_3000, "TP" ); | |
524 | synaptics_reset_pin_power(1); | |
525 | ||
526 | TPD_LOG ( "turned on the power ( VGP1 )\n" ); | |
527 | msleep(delay_time.booting); | |
528 | ||
529 | } | |
530 | else | |
531 | { | |
532 | cancel_work_sync ( &multi_tap_work ); | |
533 | hrtimer_cancel ( &multi_tap_timer ); | |
534 | #if 0 | |
535 | hwPowerDown ( MT6323_POWER_LDO_VGP1, "TP" ); | |
536 | #endif | |
537 | #if 0 | |
538 | /* replace VGP1 setting */ | |
539 | if ( synaptics_power_vbus ( on ) ) | |
540 | TPD_LOG ( "turned 0x%x the power ( VGP1 by reg )\n", on ); | |
541 | #endif | |
542 | hwPowerDown ( MT6323_POWER_LDO_VGP1, "TP" ); | |
543 | synaptics_reset_pin_power(0); | |
544 | ||
545 | TPD_LOG ( "turned off the power ( VGP1 )\n" ); | |
546 | ||
547 | } | |
548 | Power_status = on; | |
549 | ||
550 | } | |
551 | ||
552 | /**************************************************************************** | |
553 | * Synaptics I2C Read / Write Funtions | |
554 | ****************************************************************************/ | |
555 | int i2c_dma_write ( struct i2c_client *client, const uint8_t *buf, int len ) | |
556 | { | |
557 | int i = 0; | |
558 | for ( i = 0 ; i < len ; i++ ) | |
559 | { | |
560 | I2CDMABuf_va[i] = buf[i]; | |
561 | } | |
562 | ||
563 | if ( len < 8 ) | |
564 | { | |
565 | client->addr = client->addr & I2C_MASK_FLAG | I2C_ENEXT_FLAG; | |
566 | return i2c_master_send(client, buf, len); | |
567 | } | |
568 | else | |
569 | { | |
570 | client->addr = client->addr & I2C_MASK_FLAG | I2C_DMA_FLAG | I2C_ENEXT_FLAG; | |
571 | return i2c_master_send(client, I2CDMABuf_pa, len); | |
572 | } | |
573 | } | |
574 | ||
575 | int i2c_dma_read ( struct i2c_client *client, uint8_t *buf, int len ) | |
576 | { | |
577 | int i = 0, ret = 0; | |
578 | if ( len < 8 ) | |
579 | { | |
580 | client->addr = client->addr & I2C_MASK_FLAG | I2C_ENEXT_FLAG; | |
581 | return i2c_master_recv(client, buf, len); | |
582 | } | |
583 | else | |
584 | { | |
585 | client->addr = client->addr & I2C_MASK_FLAG | I2C_DMA_FLAG | I2C_ENEXT_FLAG; | |
586 | ret = i2c_master_recv(client, I2CDMABuf_pa, len); | |
587 | if ( ret < 0 ) | |
588 | { | |
589 | return ret; | |
590 | } | |
591 | ||
592 | for ( i = 0 ; i < len ; i++ ) | |
593 | { | |
594 | buf[i] = I2CDMABuf_va[i]; | |
595 | } | |
596 | } | |
597 | ||
598 | return ret; | |
599 | } | |
600 | ||
601 | static int i2c_msg_transfer ( struct i2c_client *client, struct i2c_msg *msgs, int count ) | |
602 | { | |
603 | int i = 0, ret = 0; | |
604 | for ( i = 0 ; i < count ; i++ ) | |
605 | { | |
606 | if ( msgs[i].flags & I2C_M_RD ) | |
607 | { | |
608 | ret = i2c_dma_read(client, msgs[i].buf, msgs[i].len); | |
609 | } | |
610 | else | |
611 | { | |
612 | ret = i2c_dma_write(client, msgs[i].buf, msgs[i].len); | |
613 | } | |
614 | ||
615 | if ( ret < 0 ) | |
616 | { | |
617 | return ret; | |
618 | } | |
619 | } | |
620 | ||
621 | return 0; | |
622 | } | |
623 | ||
624 | ||
625 | int synaptics_ts_read_f54 ( struct i2c_client *client, u8 reg, int num, u8 *buf ) | |
626 | { | |
627 | int message_count = ( ( num - 1 ) / BUFFER_SIZE ) + 2; | |
628 | int message_rest_count = num % BUFFER_SIZE; | |
629 | int i, data_len; | |
630 | ||
631 | if ( i2c_msgs.msg == NULL || i2c_msgs.count < message_count ) | |
632 | { | |
633 | if ( i2c_msgs.msg != NULL ) | |
634 | kfree(i2c_msgs.msg); | |
635 | ||
636 | #if 0 | |
637 | i2c_msgs.msg = (struct i2c_msg*)kcalloc(message_count, sizeof(struct i2c_msg), GFP_KERNEL); | |
638 | #else | |
639 | i2c_msgs.msg = (struct i2c_msg*)kcalloc(message_count, sizeof(struct i2c_msg), GFP_KERNEL); | |
640 | #endif | |
641 | i2c_msgs.count = message_count; | |
642 | //dev_dbg(&client->dev, "%s: Update message count %d(%d)\n", __func__, i2c_msgs.count, message_count); | |
643 | } | |
644 | ||
645 | i2c_msgs.msg[0].addr = client->addr; | |
646 | i2c_msgs.msg[0].flags = 0; | |
647 | i2c_msgs.msg[0].len = 1; | |
648 | i2c_msgs.msg[0].buf = ® | |
649 | ||
650 | if ( !message_rest_count ) | |
651 | message_rest_count = BUFFER_SIZE; | |
652 | for ( i = 0 ; i < message_count - 1 ; i++ ) | |
653 | { | |
654 | if ( i == message_count - 1 ) | |
655 | data_len = message_rest_count; | |
656 | else | |
657 | data_len = BUFFER_SIZE; | |
658 | ||
659 | i2c_msgs.msg[i + 1].addr = client->addr; | |
660 | i2c_msgs.msg[i + 1].flags = I2C_M_RD; | |
661 | i2c_msgs.msg[i + 1].len = data_len; | |
662 | i2c_msgs.msg[i + 1].buf = buf + BUFFER_SIZE * i; | |
663 | } | |
664 | ||
665 | #if 1 | |
666 | if ( i2c_msg_transfer(client, i2c_msgs.msg, message_count) < 0 ) | |
667 | { | |
668 | #else | |
669 | if (i2c_transfer(client->adapter, i2c_msgs.msg, message_count) < 0) { | |
670 | #endif | |
671 | if ( printk_ratelimit() ) | |
672 | TPD_ERR ( "transfer error\n" ); | |
673 | return -EIO; | |
674 | } | |
675 | else | |
676 | return 0; | |
677 | } | |
678 | ||
679 | int synaptics_ts_read ( struct i2c_client *client, u8 reg, int num, u8 *buf ) | |
680 | { | |
681 | struct i2c_msg msgs[] = { | |
682 | { | |
683 | .addr = client->addr, | |
684 | .flags = 0, | |
685 | .len = 1, | |
686 | .buf = ®, | |
687 | }, | |
688 | { | |
689 | .addr = client->addr, | |
690 | .flags = I2C_M_RD, | |
691 | .len = num, | |
692 | .buf = buf, | |
693 | }, | |
694 | }; | |
695 | ||
696 | #if 1 | |
697 | if ( i2c_msg_transfer(client, msgs, 2) < 0 ) | |
698 | { | |
699 | #else | |
700 | if (i2c_transfer(client->adapter, msgs, 2) < 0) { | |
701 | #endif | |
702 | if ( printk_ratelimit() ) | |
703 | TPD_ERR ( "transfer error\n" ); | |
704 | return -EIO; | |
705 | } | |
706 | else | |
707 | return 0; | |
708 | } | |
709 | EXPORT_SYMBOL ( synaptics_ts_read ); | |
710 | ||
711 | int synaptics_ts_write ( struct i2c_client *client, u8 reg, u8 * buf, int len ) | |
712 | { | |
713 | unsigned char send_buf[len + 1]; | |
714 | struct i2c_msg msgs[] = { | |
715 | { | |
716 | .addr = client->addr, | |
717 | .flags = client->flags, | |
718 | .len = len+1, | |
719 | .buf = send_buf, | |
720 | }, | |
721 | }; | |
722 | ||
723 | send_buf[0] = (unsigned char) reg; | |
724 | memcpy(&send_buf[1], buf, len); | |
725 | ||
726 | #if 1 | |
727 | if ( i2c_msg_transfer(client, msgs, 1) < 0 ) | |
728 | { | |
729 | #else | |
730 | if (i2c_transfer(client->adapter, msgs, 1) < 0) { | |
731 | #endif | |
732 | if ( printk_ratelimit() ) | |
733 | TPD_ERR ( "transfer error\n" ); | |
734 | return -EIO; | |
735 | } | |
736 | else | |
737 | return 0; | |
738 | } | |
739 | EXPORT_SYMBOL ( synaptics_ts_write ); | |
740 | ||
741 | int synaptics_page_data_read ( struct i2c_client *client, u8 page, u8 reg, int size, u8 *data ) | |
742 | { | |
743 | int ret = 0; | |
744 | ||
745 | ret = synaptics_ts_write ( client, PAGE_SELECT_REG, &page, 1 ); | |
746 | if ( ret < 0 ) | |
747 | { | |
748 | TPD_ERR ( "PAGE_SELECT_REG write fail\n" ); | |
749 | return ret; | |
750 | } | |
751 | ||
752 | ret = synaptics_ts_read ( client, reg, size, data ); | |
753 | if ( ret < 0 ) | |
754 | { | |
755 | TPD_ERR ( "synaptics_page_data_read fail\n" ); | |
756 | return ret; | |
757 | } | |
758 | ||
759 | ret = synaptics_ts_write ( client, PAGE_SELECT_REG, &device_control_page, 1 ); | |
760 | if ( ret < 0 ) | |
761 | { | |
762 | TPD_ERR ( "PAGE_SELECT_REG write fail\n" ); | |
763 | return ret; | |
764 | } | |
765 | ||
766 | return 0; | |
767 | } | |
768 | ||
769 | int synaptics_page_data_write ( struct i2c_client *client, u8 page, u8 reg, int size, u8 *data ) | |
770 | { | |
771 | int ret = 0; | |
772 | ||
773 | ret = synaptics_ts_write ( client, PAGE_SELECT_REG, &page, 1 ); | |
774 | if ( ret < 0 ) | |
775 | { | |
776 | TPD_ERR ( "PAGE_SELECT_REG write fail\n" ); | |
777 | return ret; | |
778 | } | |
779 | ||
780 | ret = synaptics_ts_write ( client, reg, data, size ); | |
781 | if ( ret < 0 ) | |
782 | { | |
783 | TPD_ERR ( "synaptics_page_data_write fail\n" ); | |
784 | return ret; | |
785 | } | |
786 | ||
787 | ret = synaptics_ts_write ( client, PAGE_SELECT_REG, &device_control_page, 1 ); | |
788 | if ( ret < 0 ) | |
789 | { | |
790 | TPD_ERR ( "PAGE_SELECT_REG write fail\n" ); | |
791 | return ret; | |
792 | } | |
793 | ||
794 | return 0; | |
795 | } | |
796 | ||
797 | /**************************************************************************** | |
798 | * Touch malfunction Prevention Function | |
799 | ****************************************************************************/ | |
800 | static void synaptics_release_all_finger ( void ) | |
801 | { | |
802 | TPD_FUN (); | |
803 | unsigned int finger_count=0; | |
804 | ||
805 | /* Reset finger position data */ | |
806 | memset(&old_touch_info, 0x0, sizeof(touch_finger_info)); | |
807 | memset(&pre_touch_info, 0x0, sizeof(touch_finger_info)); | |
808 | ||
809 | /* Reset finger & button status data */ | |
810 | memset(finger_oldstate, 0x0, sizeof(char) * MAX_NUM_OF_FINGER); | |
811 | memset(button_oldstate, 0x0, sizeof(char) * TPD_KEY_COUNT); | |
812 | memset(finger_prestate, 0x0, sizeof(char) * MAX_NUM_OF_FINGER); | |
813 | memset(button_prestate, 0x0, sizeof(char) * TPD_KEY_COUNT); | |
814 | ||
815 | #if defined(MT_PROTOCOL_A) | |
816 | input_mt_sync ( tpd->dev ); | |
817 | #else | |
818 | for(finger_count = 0; finger_count < MAX_NUM_OF_FINGER; finger_count++) | |
819 | { | |
820 | input_mt_slot( tpd->dev, finger_count); | |
821 | input_mt_report_slot_state( tpd->dev, MT_TOOL_FINGER, false); | |
822 | } | |
823 | #endif | |
824 | input_sync ( tpd->dev ); | |
825 | } | |
826 | ||
827 | static void Set_TapZone(char* arr_tap_zone) | |
828 | { | |
829 | arr_tap_zone[1] = (x_max / CHANNEL_TX * BLOCK_CHANNEL -1); | |
830 | arr_tap_zone[2] = (y_max / (CHANNEL_RX-1) * BLOCK_CHANNEL -1); | |
831 | arr_tap_zone[4] = (x_max -arr_tap_zone[1]) & 0x00FF; | |
832 | arr_tap_zone[5] = (y_max - arr_tap_zone[2]) & 0x00FF; | |
833 | ||
834 | arr_tap_zone[6] = ((( y_max - arr_tap_zone[2]) & 0xF00) >> 4); | |
835 | arr_tap_zone[6] = arr_tap_zone[6] |(( x_max -arr_tap_zone[1]) &0xF00) >> 8; | |
836 | ||
837 | TPD_LOG("tap_zone : %x %x %x %x %x %x %x\n", arr_tap_zone[0],arr_tap_zone[1],arr_tap_zone[2],arr_tap_zone[3],arr_tap_zone[4], arr_tap_zone[5], arr_tap_zone[6]); | |
838 | ||
839 | } | |
840 | ||
841 | int synaptics_ic_ctrl ( struct i2c_client *client, u8 code, u16 value ) | |
842 | { | |
843 | u8 temp; | |
844 | u8 r_mem = 0; | |
845 | u64 tap_zone = 0; | |
846 | char arr_tap_zone[7] = {0}; | |
847 | TPD_LOG ( "synaptics_ic_ctrl: %d, %d\n", code, value ); | |
848 | ||
849 | switch ( code ) | |
850 | { | |
851 | case IC_CTRL_BASELINE: | |
852 | switch ( value ) | |
853 | { | |
854 | case BASELINE_OPEN: | |
855 | #if 0 | |
856 | if (unlikely(synaptics_page_data_write(client, ANALOG_PAGE, ANALOG_CONTROL_REG, 1, FORCE_FAST_RELAXATION) < 0)) { | |
857 | SYNAPTICS_ERR_MSG("ANALOG_CONTROL_REG write fail\n"); | |
858 | return -EIO; | |
859 | } | |
860 | ||
861 | msleep(10); | |
862 | ||
863 | if (unlikely(synaptics_page_data_write(client, ANALOG_PAGE, ANALOG_COMMAND_REG, 1, FORCE_UPDATE) < 0)) { | |
864 | SYNAPTICS_ERR_MSG("ANALOG_COMMAND_REG write fail\n"); | |
865 | return -EIO; | |
866 | } | |
867 | ||
868 | if (synaptics_rmi4_i2c_debug_mask & SYNAPTICS_RMI4_I2C_DEBUG_FINGER_STATUS) | |
869 | SYNAPTICS_INFO_MSG("BASELINE_OPEN\n"); | |
870 | #endif | |
871 | break; | |
872 | ||
873 | case BASELINE_FIX: | |
874 | #if 0 | |
875 | if (unlikely(synaptics_page_data_write(client, ANALOG_PAGE, ANALOG_CONTROL_REG, 1, 0x00) < 0)) { | |
876 | TOUCH_ERR_MSG("ANALOG_CONTROL_REG write fail\n"); | |
877 | return -EIO; | |
878 | } | |
879 | ||
880 | msleep(10); | |
881 | ||
882 | if (unlikely(synaptics_page_data_write(client, ANALOG_PAGE, ANALOG_COMMAND_REG, 1, FORCE_UPDATE) < 0)) { | |
883 | TOUCH_ERR_MSG("ANALOG_COMMAND_REG write fail\n"); | |
884 | return -EIO; | |
885 | } | |
886 | ||
887 | if (synaptics_rmi4_i2c_debug_mask & SYNAPTICS_RMI4_I2C_DEBUG_FINGER_STATUS) | |
888 | TOUCH_INFO_MSG("BASELINE_FIX\n"); | |
889 | #endif | |
890 | break; | |
891 | ||
892 | case BASELINE_REBASE: | |
893 | /* rebase base line */ | |
894 | if ( finger.function_exist != 0 ) | |
895 | { | |
896 | temp = 0x01; | |
897 | if ( synaptics_ts_write ( client, TWO_D_COMMAND, &temp, 1 ) < 0 ) | |
898 | { | |
899 | TPD_ERR ( "finger baseline reset command write fail\n" ); | |
900 | return -EIO; | |
901 | } | |
902 | } | |
903 | break; | |
904 | ||
905 | default: | |
906 | break; | |
907 | } | |
908 | break; | |
909 | ||
910 | case IC_CTRL_REPORT_MODE: | |
911 | switch ( value ) | |
912 | { | |
913 | case 0: // continuous mode | |
914 | temp = REPORT_BEYOND_CLIP_MASK | ABS_POS_FILTER_MASK | CONTINUOUS_REPORTING_MODE_MASK; | |
915 | if ( synaptics_ts_write ( client, TWO_D_REPORT_MODE_REG, &temp, 1 ) < 0 ) | |
916 | { | |
917 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
918 | return -EIO; | |
919 | } | |
920 | break; | |
921 | ||
922 | case 1: // reduced mode | |
923 | temp = REPORT_BEYOND_CLIP_MASK | ABS_POS_FILTER_MASK | REDUCED_REPORTING_MODE_MASK; | |
924 | if ( synaptics_ts_write ( client, TWO_D_REPORT_MODE_REG, &temp, 1 ) < 0 ) | |
925 | { | |
926 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
927 | return -EIO; | |
928 | } | |
929 | break; | |
930 | ||
931 | default: | |
932 | break; | |
933 | } | |
934 | break; | |
935 | ||
936 | case IC_CTRL_DOUBLE_TAP_WAKEUP_MODE: | |
937 | switch ( value ) | |
938 | { | |
939 | case 0: /* touch double-tap disable */ | |
940 | TPD_LOG ( "ic_ctrl: IC_CTRL_DOUBLE_TAP_WAKEUP_MODE --- OFF\n" ); | |
941 | if ( synaptics_page_data_read ( client, multi_tap_page, MULTITAP_ENABLE_REG, 1, &r_mem ) < 0 ) | |
942 | { | |
943 | TPD_ERR ( "MULTITAP_ENABLE_REG read fail!\n" ); | |
944 | return -EIO; | |
945 | } | |
946 | else | |
947 | { | |
948 | r_mem = r_mem & 0xFE; | |
949 | if ( synaptics_page_data_write ( client, multi_tap_page, MULTITAP_ENABLE_REG, 1, &r_mem ) < 0 ) | |
950 | { | |
951 | TPD_ERR ( "MULTITAP_ENABLE_REG write fail\n" ); | |
952 | return -EIO; | |
953 | } | |
954 | } | |
955 | ||
956 | if ( synaptics_ts_read ( client, TWO_D_REPORT_MODE_REG, 1, &r_mem ) < 0 ) | |
957 | { | |
958 | TPD_ERR ( "TWO_D_REPORT_MODE_REG read fail!\n" ); | |
959 | return -EIO; | |
960 | } | |
961 | else | |
962 | { | |
963 | r_mem = ( r_mem & 0xF8 ) | REDUCED_REPORTING_MODE_MASK; | |
964 | //r_mem = 0x89; | |
965 | if ( synaptics_ts_write ( client, TWO_D_REPORT_MODE_REG, &r_mem, 1) < 0 ) | |
966 | { | |
967 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
968 | return -EIO; | |
969 | } | |
970 | } | |
971 | TPD_LOG ( "TWO_D_REPORT_MODE_REG : %x\n", r_mem ); | |
972 | break; | |
973 | ||
974 | case 1: /* touch double-tap enable */ | |
975 | TPD_LOG ( "ic_ctrl: IC_CTRL_DOUBLE_TAP_WAKEUP_MODE --- ON\n" ); | |
976 | if ( synaptics_page_data_read ( client, multi_tap_page, MULTITAP_ENABLE_REG, 1, &r_mem ) < 0 ) | |
977 | { | |
978 | TPD_ERR ( "MULTITAP_ENABLE_REG read fail!\n" ); | |
979 | return -EIO; | |
980 | } | |
981 | else | |
982 | { | |
983 | r_mem = r_mem | ENABLE_MULTITAP_REPORTING_MASK; | |
984 | if ( synaptics_page_data_write ( client, multi_tap_page, MULTITAP_ENABLE_REG, 1, &r_mem ) < 0 ) | |
985 | { | |
986 | TPD_ERR ( "MULTITAP_ENABLE_REG write fail\n" ); | |
987 | return -EIO; | |
988 | } | |
989 | } | |
990 | ||
991 | if ( synaptics_ts_read ( client, TWO_D_REPORT_MODE_REG, 1, &r_mem ) < 0 ) | |
992 | { | |
993 | TPD_ERR ( "TWO_D_REPORT_MODE_REG read fail!\n" ); | |
994 | return -EIO; | |
995 | } | |
996 | else | |
997 | { | |
998 | r_mem = ( r_mem & 0xF8 ) | WAKEUP_GESTURE_REPORTING_MODE_MASK; | |
999 | //r_mem = 0x8c; | |
1000 | if ( synaptics_ts_write ( client, TWO_D_REPORT_MODE_REG, &r_mem, 1 ) < 0 ) | |
1001 | { | |
1002 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
1003 | return -EIO; | |
1004 | } | |
1005 | } | |
1006 | TPD_LOG ( "TWO_D_REPORT_MODE_REG : %x\n", r_mem ); | |
1007 | ||
1008 | if ( synaptics_ts_read ( client, DEVICE_CONTROL_REG, 1, &r_mem ) < 0 ) | |
1009 | { | |
1010 | TPD_ERR ( "DEVICE_CONTROL_REG read fail!\n" ); | |
1011 | return -EIO; | |
1012 | } | |
1013 | else | |
1014 | { | |
1015 | r_mem = CONFIGURED_MASK; | |
1016 | if ( synaptics_ts_write ( client, DEVICE_CONTROL_REG, &r_mem, 1 ) < 0 ) | |
1017 | { | |
1018 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
1019 | return -EIO; | |
1020 | } | |
1021 | } | |
1022 | #ifdef TAP_ZONE_ENABLE | |
1023 | if ( synaptics_ts_read ( client, LPWG_CONTROL_REG, 7, &arr_tap_zone[0] ) < 0 ) | |
1024 | { | |
1025 | TPD_ERR ( "LPWG_CONTROL_REG read fail\n" ); | |
1026 | return -EIO; | |
1027 | } | |
1028 | ||
1029 | Set_TapZone(arr_tap_zone); | |
1030 | ||
1031 | if ( synaptics_ts_write ( client, LPWG_CONTROL_REG, &arr_tap_zone, 7 ) < 0 ) | |
1032 | { | |
1033 | TPD_ERR ( "LPWG_CONTROL_REG write fail\n" ); | |
1034 | return -EIO; | |
1035 | } | |
1036 | #endif | |
1037 | r_mem = 0x46; | |
1038 | if ( synaptics_page_data_write ( client, multi_tap_page, MAXIMUM_INTERTAP_TIME_REG, 1, &r_mem ) < 0 ) | |
1039 | { | |
1040 | TPD_ERR ( "MAXIMUM_INTERTAP_TIME_REG write fail\n" ); | |
1041 | return -EIO; | |
1042 | } | |
1043 | ||
1044 | r_mem = 0x0A; | |
1045 | if ( synaptics_page_data_write ( client, multi_tap_page, MAXIMUM_INTERTAP_DISTANCE_REG, 1, &r_mem ) < 0 ) | |
1046 | { | |
1047 | TPD_ERR ( "MAXIMUM_INTERTAP_DISTANCE_REG write fail\n" ); | |
1048 | return -EIO; | |
1049 | } | |
1050 | ||
1051 | if ( synaptics_page_data_read ( client, multi_tap_page, MULTITAP_COUNT_REG, 1, &r_mem ) < 0 ) | |
1052 | { | |
1053 | TPD_ERR ( "MULTITAP_COUNT_REG read fail\n" ); | |
1054 | return -EIO; | |
1055 | } | |
1056 | else | |
1057 | { | |
1058 | TPD_LOG ( "TAP COUNT = %d\n", 2 ); // for double tap mode | |
1059 | multi_tap_count = 2; | |
1060 | r_mem = ( r_mem & 0x07 ) | ( 2 << 3 ); | |
1061 | if ( synaptics_page_data_write ( client, multi_tap_page, MULTITAP_COUNT_REG, 1, &r_mem) < 0 ) | |
1062 | { | |
1063 | TPD_ERR ( "MULTITAP_COUNT_REG write fail\n" ); | |
1064 | return -EIO; | |
1065 | } | |
1066 | } | |
1067 | break; | |
1068 | ||
1069 | case 2: /* touch multi tap enable */ | |
1070 | TPD_LOG ( "ic_ctrl: IC_CTRL_MULTI_TAP_WAKEUP_MODE --- ON\n" ); | |
1071 | if ( synaptics_page_data_read ( client, multi_tap_page, MULTITAP_ENABLE_REG, 1, &r_mem ) < 0 ) | |
1072 | { | |
1073 | TPD_ERR ( "MULTITAP_ENABLE_REG read fail!\n" ); | |
1074 | } | |
1075 | else | |
1076 | { | |
1077 | r_mem = r_mem | ENABLE_MULTITAP_REPORTING_MASK; | |
1078 | if ( synaptics_page_data_write ( client, multi_tap_page, MULTITAP_ENABLE_REG, 1, &r_mem ) < 0 ) | |
1079 | { | |
1080 | TPD_ERR ( "MULTITAP_ENABLE_REG write fail\n" ); | |
1081 | return -EIO; | |
1082 | } | |
1083 | } | |
1084 | ||
1085 | if ( synaptics_ts_read ( client, TWO_D_REPORT_MODE_REG, 1, &r_mem ) < 0 ) | |
1086 | { | |
1087 | TPD_ERR ( "TWO_D_REPORT_MODE_REG read fail!\n" ); | |
1088 | return -EIO; | |
1089 | } | |
1090 | else | |
1091 | { | |
1092 | r_mem = ( r_mem & 0xF8 ) | WAKEUP_GESTURE_REPORTING_MODE_MASK; | |
1093 | //r_mem = 0x8c; | |
1094 | if ( synaptics_ts_write ( client, TWO_D_REPORT_MODE_REG, &r_mem, 1 ) < 0 ) | |
1095 | { | |
1096 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
1097 | return -EIO; | |
1098 | } | |
1099 | } | |
1100 | TPD_LOG ( "TWO_D_REPORT_MODE_REG : %x\n", r_mem ); | |
1101 | ||
1102 | if ( synaptics_ts_read ( client, DEVICE_CONTROL_REG, 1, &r_mem ) < 0 ) | |
1103 | { | |
1104 | TPD_ERR ( "DEVICE_CONTROL_REG read fail!\n" ); | |
1105 | return -EIO; | |
1106 | } | |
1107 | else | |
1108 | { | |
1109 | r_mem = CONFIGURED_MASK; | |
1110 | if ( synaptics_ts_write ( client, DEVICE_CONTROL_REG, &r_mem, 1 ) < 0 ) | |
1111 | { | |
1112 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
1113 | return -EIO; | |
1114 | } | |
1115 | } | |
1116 | #ifdef TAP_ZONE_ENABLE | |
1117 | if ( synaptics_ts_read ( client, LPWG_CONTROL_REG, 7, &arr_tap_zone[0] ) < 0 ) | |
1118 | { | |
1119 | TPD_ERR ( "LPWG_CONTROL_REG read fail\n" ); | |
1120 | return -EIO; | |
1121 | } | |
1122 | ||
1123 | Set_TapZone(arr_tap_zone); | |
1124 | ||
1125 | if ( synaptics_ts_write ( client, LPWG_CONTROL_REG, &arr_tap_zone, 7 ) < 0 ) | |
1126 | { | |
1127 | TPD_ERR ( "LPWG_CONTROL_REG write fail\n" ); | |
1128 | return -EIO; | |
1129 | } | |
1130 | #endif | |
1131 | r_mem = 0x46; | |
1132 | if ( synaptics_page_data_write ( client, multi_tap_page, MAXIMUM_INTERTAP_TIME_REG, 1, &r_mem ) < 0 ) | |
1133 | { | |
1134 | TPD_ERR ( "MAXIMUM_INTERTAP_TIME_REG write fail\n" ); | |
1135 | return -EIO; | |
1136 | } | |
1137 | ||
1138 | r_mem = 0xFF; | |
1139 | if ( synaptics_page_data_write ( client, multi_tap_page, MAXIMUM_INTERTAP_DISTANCE_REG, 1, &r_mem) < 0 ) | |
1140 | { | |
1141 | TPD_ERR ( "MAXIMUM_INTERTAP_DISTANCE_REG write fail\n" ); | |
1142 | return -EIO; | |
1143 | } | |
1144 | ||
1145 | synaptics_knock_lpwg ( client, LPWG_TAP_COUNT, multi_tap_count, NULL ); | |
1146 | break; | |
1147 | ||
1148 | default: | |
1149 | break; | |
1150 | } | |
1151 | ||
1152 | default: | |
1153 | break; | |
1154 | } | |
1155 | return 0; | |
1156 | } | |
1157 | ||
1158 | bool chk_time_interval ( struct timeval t_aft, struct timeval t_bef, int t_val ) | |
1159 | { | |
1160 | if ( t_aft.tv_sec - t_bef.tv_sec == 0 ) | |
1161 | { | |
1162 | if ( ( get_time_interval(t_aft.tv_usec, t_bef.tv_usec) ) <= t_val ) | |
1163 | return true; | |
1164 | } | |
1165 | else if ( t_aft.tv_sec - t_bef.tv_sec == 1 ) | |
1166 | { | |
1167 | if ( t_aft.tv_usec + 1000000 - t_bef.tv_usec <= t_val ) | |
1168 | return true; | |
1169 | } | |
1170 | ||
1171 | return false; | |
1172 | } | |
1173 | ||
1174 | int ghost_detect_solution ( void ) | |
1175 | { | |
1176 | int first_int_detection = 0; | |
1177 | int cnt = 0, id = 0; | |
1178 | ||
1179 | if ( resume_flag ) | |
1180 | { | |
1181 | resume_flag = 0; | |
1182 | do_gettimeofday ( &t_ex_debug[TIME_EX_FIRST_INT_TIME] ); | |
1183 | ||
1184 | if ( t_ex_debug[TIME_EX_FIRST_INT_TIME].tv_sec - t_ex_debug[TIME_EX_INIT_TIME].tv_sec == 0 ) | |
1185 | { | |
1186 | if ( ( get_time_interval(t_ex_debug[TIME_EX_FIRST_INT_TIME].tv_usec, t_ex_debug[TIME_EX_INIT_TIME].tv_usec) ) <= 200000 ) | |
1187 | { | |
1188 | first_int_detection = 1; | |
1189 | } | |
1190 | } | |
1191 | else if ( t_ex_debug[TIME_EX_FIRST_INT_TIME].tv_sec - t_ex_debug[TIME_EX_INIT_TIME].tv_sec == 1 ) | |
1192 | { | |
1193 | if ( t_ex_debug[TIME_EX_FIRST_INT_TIME].tv_usec + 1000000 - t_ex_debug[TIME_EX_INIT_TIME].tv_usec <= 200000 ) | |
1194 | { | |
1195 | first_int_detection = 1; | |
1196 | } | |
1197 | } | |
1198 | } | |
1199 | ||
1200 | if ( first_int_detection ) | |
1201 | { | |
1202 | for ( cnt = 0 ; cnt < MAX_NUM_OF_FINGER ; cnt++ ) | |
1203 | { | |
1204 | if ( finger_prestate[cnt] == TOUCH_PRESSED ) | |
1205 | { | |
1206 | TPD_LOG ( "ghost detected within first input time 200ms\n" ); | |
1207 | ghost_detection = 1; | |
1208 | } | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | if ( pressure_zero == 1 ) | |
1213 | { | |
1214 | TPD_LOG ( "ghost detected on pressure\n" ); | |
1215 | ghost_detection = 1; | |
1216 | } | |
1217 | ||
1218 | if ( pre_touch_info.total_num ) | |
1219 | { | |
1220 | if ( old_touch_info.total_num != pre_touch_info.total_num ) | |
1221 | { | |
1222 | if ( old_touch_info.total_num <= pre_touch_info.total_num ) | |
1223 | { | |
1224 | for ( id = 0 ; id < MAX_NUM_OF_FINGER ; id++ ) | |
1225 | { | |
1226 | if ( finger_prestate[id] == TOUCH_PRESSED && finger_oldstate[id] == TOUCH_RELEASED ) | |
1227 | { | |
1228 | break; | |
1229 | } | |
1230 | } | |
1231 | ||
1232 | if ( id < MAX_NUM_OF_FINGER ) | |
1233 | { | |
1234 | memcpy ( &t_ex_debug[TIME_EX_PREV_PRESS_TIME], &t_ex_debug[TIME_EX_CURR_PRESS_TIME], sizeof(struct timeval) ); | |
1235 | do_gettimeofday ( &t_ex_debug[TIME_EX_CURR_PRESS_TIME] ); | |
1236 | ||
1237 | if ( ( pre_touch_info.pos_x[id] > 0 ) && ( pre_touch_info.pos_x[id] < x_max ) | |
1238 | && ( 1 <= old_touch_info.total_num ) && ( 1 <= pre_touch_info.total_num ) | |
1239 | && ( jitter_sub(old_pos_x, pre_touch_info.pos_x[id]) <= 10 ) && ( jitter_sub(old_pos_y, pre_touch_info.pos_y[id]) <= 10 ) ) | |
1240 | { | |
1241 | if ( chk_time_interval ( t_ex_debug[TIME_EX_CURR_PRESS_TIME], t_ex_debug[TIME_EX_PREV_PRESS_TIME], 50000 ) ) | |
1242 | { | |
1243 | ghost_detection = 1; | |
1244 | ghost_detection_count++; | |
1245 | } | |
1246 | } | |
1247 | else if ( ( pre_touch_info.pos_x[id] > 0 ) && ( pre_touch_info.pos_x[id] < x_max ) | |
1248 | && ( old_touch_info.total_num == 0 ) && ( pre_touch_info.total_num == 1 ) | |
1249 | && ( jitter_sub(old_pos_x, pre_touch_info.pos_x[id]) <= 10 ) && ( jitter_sub(old_pos_y, pre_touch_info.pos_y[id]) <= 10 ) ) | |
1250 | { | |
1251 | if ( chk_time_interval ( t_ex_debug[TIME_EX_CURR_PRESS_TIME], t_ex_debug[TIME_EX_PREV_PRESS_TIME], 50000 ) ) | |
1252 | { | |
1253 | ghost_detection = 1; | |
1254 | } | |
1255 | } | |
1256 | else if ( 5 < jitter_sub(old_touch_info.total_num, pre_touch_info.total_num) ) | |
1257 | { | |
1258 | ghost_detection = 1; | |
1259 | } | |
1260 | else | |
1261 | ; //do not anything | |
1262 | ||
1263 | old_pos_x = pre_touch_info.pos_x[id]; | |
1264 | old_pos_y = pre_touch_info.pos_y[id]; | |
1265 | } | |
1266 | } | |
1267 | else | |
1268 | { | |
1269 | memcpy ( &t_ex_debug[TIME_EX_PREV_PRESS_TIME], &t_ex_debug[TIME_EX_CURR_PRESS_TIME], sizeof(struct timeval) ); | |
1270 | do_gettimeofday ( &t_ex_debug[TIME_EX_CURR_INT_TIME] ); | |
1271 | ||
1272 | if ( chk_time_interval ( t_ex_debug[TIME_EX_CURR_INT_TIME], t_ex_debug[TIME_EX_PREV_PRESS_TIME], 10999 ) ) | |
1273 | { | |
1274 | finger_subtraction_check_count++; | |
1275 | } | |
1276 | else | |
1277 | { | |
1278 | finger_subtraction_check_count = 0; | |
1279 | } | |
1280 | ||
1281 | if ( 4 < finger_subtraction_check_count ) | |
1282 | { | |
1283 | finger_subtraction_check_count = 0; | |
1284 | TPD_LOG ( "need_to_rebase finger_subtraction!!!\n" ); | |
1285 | /* rebase is disabled. see TD 41871*/ | |
1286 | //goto out_need_to_rebase; | |
1287 | } | |
1288 | } | |
1289 | } | |
1290 | ||
1291 | if ( force_continuous_mode ) | |
1292 | { | |
1293 | do_gettimeofday ( &t_ex_debug[TIME_EX_CURR_INT_TIME] ); | |
1294 | // if 20 sec have passed since resume, then return to the original report mode. | |
1295 | if ( t_ex_debug[TIME_EX_CURR_INT_TIME].tv_sec - t_ex_debug[TIME_EX_INIT_TIME].tv_sec >= 10 ) | |
1296 | { | |
1297 | if ( synaptics_ic_ctrl ( tpd_i2c_client, IC_CTRL_REPORT_MODE, REDUCED_REPORTING_MODE_MASK ) < 0 ) | |
1298 | { | |
1299 | TPD_ERR ( "IC_CTRL_BASELINE(1) handling fail\n" ); | |
1300 | goto out_need_to_init; | |
1301 | } | |
1302 | force_continuous_mode = 0; | |
1303 | } | |
1304 | ||
1305 | long_press_check = 0; | |
1306 | ||
1307 | for ( cnt = 0 ; cnt < MAX_NUM_OF_FINGER ; cnt++ ) | |
1308 | { | |
1309 | if ( finger_prestate[cnt] == TOUCH_PRESSED ) | |
1310 | { | |
1311 | if ( ( finger_oldstate[cnt] == TOUCH_PRESSED ) && ( jitter_sub(old_touch_info.pos_x[cnt], pre_touch_info.pos_x[cnt]) < 10 ) | |
1312 | && ( jitter_sub(old_touch_info.pos_y[cnt], pre_touch_info.pos_y[cnt]) < 10 ) ) | |
1313 | { | |
1314 | long_press_check = 1; | |
1315 | } | |
1316 | } | |
1317 | } | |
1318 | ||
1319 | if ( long_press_check ) | |
1320 | { | |
1321 | long_press_check_count++; | |
1322 | } | |
1323 | else | |
1324 | { | |
1325 | long_press_check_count = 0; | |
1326 | } | |
1327 | ||
1328 | if ( 500 < long_press_check_count ) | |
1329 | { | |
1330 | long_press_check_count = 0; | |
1331 | TPD_LOG ( "need_to_rebase long press!!!\n" ); | |
1332 | goto out_need_to_rebase; | |
1333 | } | |
1334 | } | |
1335 | } | |
1336 | else if ( !pre_touch_info.total_num ) | |
1337 | { | |
1338 | long_press_check_count = 0; | |
1339 | finger_subtraction_check_count = 0; | |
1340 | } | |
1341 | ||
1342 | button_check = 0; | |
1343 | for ( id = 0 ; id < TPD_KEY_COUNT ; id++ ) | |
1344 | { | |
1345 | if ( button_prestate[id] == TOUCH_PRESSED && button_oldstate[id] == TOUCH_RELEASED ) | |
1346 | { | |
1347 | button_check = 1; | |
1348 | break; | |
1349 | } | |
1350 | } | |
1351 | if ( button_check ) | |
1352 | { | |
1353 | if ( button_press_count == 0 ) | |
1354 | do_gettimeofday ( &t_ex_debug[TIME_EX_BUTTON_PRESS_START_TIME] ); | |
1355 | else | |
1356 | do_gettimeofday ( &t_ex_debug[TIME_EX_BUTTON_PRESS_END_TIME] ); | |
1357 | ||
1358 | button_press_count++; | |
1359 | ||
1360 | if ( 6 <= button_press_count ) | |
1361 | { | |
1362 | if ( chk_time_interval ( t_ex_debug[TIME_EX_BUTTON_PRESS_END_TIME], t_ex_debug[TIME_EX_BUTTON_PRESS_START_TIME], 100000 ) ) | |
1363 | { | |
1364 | TPD_LOG ( "need_to_rebase button zero\n" ); | |
1365 | goto out_need_to_rebase; | |
1366 | } | |
1367 | else | |
1368 | { | |
1369 | button_press_count = 0; | |
1370 | } | |
1371 | } | |
1372 | else | |
1373 | { | |
1374 | if ( !chk_time_interval ( t_ex_debug[TIME_EX_BUTTON_PRESS_END_TIME], t_ex_debug[TIME_EX_BUTTON_PRESS_START_TIME], 100000 ) ) | |
1375 | { | |
1376 | button_press_count = 0; | |
1377 | } | |
1378 | } | |
1379 | } | |
1380 | ||
1381 | if ( ( ghost_detection == 1 ) && ( pre_touch_info.total_num == 0 ) && ( pre_touch_info.palm == 0 ) ) | |
1382 | { | |
1383 | TPD_LOG ( "need_to_rebase zero\n" ); | |
1384 | goto out_need_to_rebase; | |
1385 | } | |
1386 | else if ( ( ghost_detection == 1 ) && ( 3 <= ghost_detection_count ) && ( pre_touch_info.palm == 0 ) ) | |
1387 | { | |
1388 | TPD_LOG ( "need_to_rebase zero 3\n" ); | |
1389 | goto out_need_to_rebase; | |
1390 | } | |
1391 | ||
1392 | return 0; | |
1393 | ||
1394 | out_need_to_rebase: | |
1395 | { | |
1396 | ghost_detection = 0; | |
1397 | ghost_detection_count = 0; | |
1398 | old_pos_x = 0; | |
1399 | old_pos_y = 0; | |
1400 | ts_rebase_count++; | |
1401 | ||
1402 | if ( ts_rebase_count == 1 ) | |
1403 | { | |
1404 | do_gettimeofday ( &t_ex_debug[TIME_EX_FIRST_GHOST_DETECT_TIME] ); | |
1405 | ||
1406 | if ( ( t_ex_debug[TIME_EX_FIRST_GHOST_DETECT_TIME].tv_sec - t_ex_debug[TIME_EX_INIT_TIME].tv_sec ) <= 3 ) | |
1407 | { | |
1408 | ts_rebase_count = 0; | |
1409 | TPD_LOG ( "need_to_init in 3 sec\n" ); | |
1410 | goto out_need_to_init; | |
1411 | } | |
1412 | } | |
1413 | else | |
1414 | { | |
1415 | do_gettimeofday ( &t_ex_debug[TIME_EX_SECOND_GHOST_DETECT_TIME] ); | |
1416 | ||
1417 | if ( ( ( t_ex_debug[TIME_EX_SECOND_GHOST_DETECT_TIME].tv_sec - t_ex_debug[TIME_EX_FIRST_GHOST_DETECT_TIME].tv_sec ) <= 5 ) ) | |
1418 | { | |
1419 | ts_rebase_count = 0; | |
1420 | TPD_LOG ( "need_to_init\n" ); | |
1421 | goto out_need_to_init; | |
1422 | } | |
1423 | else | |
1424 | { | |
1425 | ts_rebase_count = 1; | |
1426 | memcpy ( &t_ex_debug[TIME_EX_FIRST_GHOST_DETECT_TIME], &t_ex_debug[TIME_EX_SECOND_GHOST_DETECT_TIME], sizeof(struct timeval) ); | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | synaptics_release_all_finger (); | |
1431 | if ( synaptics_ic_ctrl ( tpd_i2c_client, IC_CTRL_BASELINE, BASELINE_REBASE ) < 0 ) | |
1432 | { | |
1433 | TPD_ERR ( "IC_CTRL_REBASE(2) handling fail\n" ); | |
1434 | } | |
1435 | TPD_LOG ( "need_to_rebase\n" ); | |
1436 | } | |
1437 | return NEED_TO_OUT; | |
1438 | ||
1439 | out_need_to_init: | |
1440 | return NEED_TO_INIT; | |
1441 | } | |
1442 | ||
1443 | static void synaptics_reset_pin_power ( int on ) | |
1444 | { | |
1445 | TPD_ERR ("on_off:0x%x\n", on); | |
1446 | if ( on ) | |
1447 | { | |
1448 | mt_set_gpio_mode ( GPIO_CTP_RST_PIN, GPIO_MODE_00 ); | |
1449 | mt_set_gpio_dir ( GPIO_CTP_RST_PIN, GPIO_DIR_OUT ); | |
1450 | mt_set_gpio_out ( GPIO_CTP_RST_PIN, GPIO_OUT_ONE ); | |
1451 | msleep(delay_time.reset); | |
1452 | } | |
1453 | else | |
1454 | { | |
1455 | mt_set_gpio_mode ( GPIO_CTP_RST_PIN, GPIO_MODE_00 ); | |
1456 | mt_set_gpio_dir ( GPIO_CTP_RST_PIN, GPIO_DIR_OUT ); | |
1457 | mt_set_gpio_out ( GPIO_CTP_RST_PIN, GPIO_OUT_ZERO ); | |
1458 | } | |
1459 | } | |
1460 | ||
1461 | #if defined(ONLY_S2202_RESET_PIN) | |
1462 | ||
1463 | static void synaptics_reset_pin ( int reset_pin ) | |
1464 | { | |
1465 | TPD_FUN (); | |
1466 | ||
1467 | #if 0 | |
1468 | mt_set_gpio_mode ( reset_pin, GPIO_MODE_00 ); | |
1469 | mt_set_gpio_dir ( reset_pin, GPIO_DIR_OUT ); | |
1470 | mt_set_gpio_out ( reset_pin, GPIO_OUT_ZERO ); | |
1471 | msleep ( 10 ); | |
1472 | mt_set_gpio_mode ( reset_pin, GPIO_MODE_00 ); | |
1473 | mt_set_gpio_dir ( reset_pin, GPIO_DIR_OUT ); | |
1474 | mt_set_gpio_out ( reset_pin, GPIO_OUT_ONE ); | |
1475 | msleep ( 50 ); | |
1476 | #else | |
1477 | synaptics_reset_pin_power(0); | |
1478 | msleep ( 10 ); | |
1479 | synaptics_reset_pin_power(1); | |
1480 | msleep ( 50 ); | |
1481 | ||
1482 | #endif | |
1483 | } | |
1484 | #endif | |
1485 | ||
1486 | static void synaptics_ic_reset ( void ) | |
1487 | { | |
1488 | TPD_FUN (); | |
1489 | ||
1490 | mt_eint_mask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
1491 | ||
1492 | synaptics_power ( 0 ); | |
1493 | mdelay(20); | |
1494 | ||
1495 | synaptics_power ( 1 ); | |
1496 | ||
1497 | synaptics_initialize ( tpd_i2c_client ); | |
1498 | ||
1499 | mt_eint_unmask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
1500 | } | |
1501 | ||
1502 | static int synaptics_ic_status_check ( void ) | |
1503 | { | |
1504 | int ret; | |
1505 | u8 device_status, temp; | |
1506 | device_status = temp = 0; | |
1507 | ||
1508 | /* read device status */ | |
1509 | ret = synaptics_ts_read ( tpd_i2c_client, DEVICE_STATUS_REG, 1, (u8 *) &device_status ); | |
1510 | if ( ret < 0 ) | |
1511 | { | |
1512 | TPD_ERR ( "DEVICE_STATUS_REG read fail\n" ); | |
1513 | return -1; | |
1514 | } | |
1515 | ||
1516 | /* ESD damage check */ | |
1517 | if ( ( device_status & DEVICE_FAILURE_MASK ) == DEVICE_FAILURE_MASK ) | |
1518 | { | |
1519 | TPD_ERR ( "ESD damage occured. Reset Touch IC\n" ); | |
1520 | synaptics_ic_reset (); | |
1521 | return -1; | |
1522 | } | |
1523 | ||
1524 | /* Internal reset check */ | |
1525 | if ( ( ( device_status & UNCONFIGURED_MASK ) >> 7 ) == 1 ) | |
1526 | { | |
1527 | TPD_ERR ( "Touch IC resetted internally. Reconfigure register setting\n"); | |
1528 | synaptics_initialize ( tpd_i2c_client ); | |
1529 | return -1; | |
1530 | } | |
1531 | ||
1532 | /* Palm check */ | |
1533 | ret = synaptics_ts_read ( tpd_i2c_client, TWO_D_EXTENDED_STATUS_REG, 1, &temp ); | |
1534 | if ( ret < 0 ) | |
1535 | { | |
1536 | TPD_ERR ( "TWO_D_EXTENDED_STATUS_REG read fail\n" ); | |
1537 | return -1; | |
1538 | } | |
1539 | old_touch_info.palm = pre_touch_info.palm; | |
1540 | pre_touch_info.palm = temp & 0x2; | |
1541 | ||
1542 | return 0; | |
1543 | } | |
1544 | ||
1545 | void touch_keylock_enable ( int key_lock ) | |
1546 | { | |
1547 | TPD_FUN (); | |
1548 | ||
1549 | if ( !key_lock ) | |
1550 | { | |
1551 | mt_eint_unmask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
1552 | key_lock_status = 0; | |
1553 | } | |
1554 | else | |
1555 | { | |
1556 | mt_eint_mask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
1557 | key_lock_status = 1; | |
1558 | } | |
1559 | } | |
1560 | EXPORT_SYMBOL ( touch_keylock_enable ); | |
1561 | ||
1562 | /**************************************************************************** | |
1563 | * Synaptics Knock_On Funtions | |
1564 | ****************************************************************************/ | |
1565 | static enum hrtimer_restart synaptics_multi_tap_timer_handler ( struct hrtimer *multi_tap_timer ) | |
1566 | { | |
1567 | TPD_FUN (); | |
1568 | queue_work ( touch_multi_tap_wq, &multi_tap_work ); | |
1569 | ||
1570 | return HRTIMER_NORESTART; | |
1571 | } | |
1572 | ||
1573 | static void synaptics_multi_tap_work ( struct work_struct *multi_tap_work ) | |
1574 | { | |
1575 | TPD_FUN (); | |
1576 | u8 r_mem = 0; | |
1577 | ||
1578 | if ( synaptics_ts_read ( tpd_i2c_client, TWO_D_REPORT_MODE_REG, 1, &r_mem ) < 0 ) | |
1579 | { | |
1580 | TPD_ERR ( "TWO_D_REPORT_MODE_REG read fail!\n" ); | |
1581 | } | |
1582 | else | |
1583 | { | |
1584 | r_mem = ( r_mem & 0xF8 ) | WAKEUP_GESTURE_REPORTING_MODE_MASK; | |
1585 | if ( synaptics_ts_write ( tpd_i2c_client, TWO_D_REPORT_MODE_REG, &r_mem, 1 ) < 0 ) | |
1586 | { | |
1587 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
1588 | } | |
1589 | } | |
1590 | ||
1591 | if ( synaptics_ts_read ( tpd_i2c_client, DEVICE_CONTROL_REG, 1, &r_mem ) < 0 ) | |
1592 | { | |
1593 | TPD_ERR ( "DEVICE_CONTROL_REG read fail\n" ); | |
1594 | } | |
1595 | else | |
1596 | { | |
1597 | r_mem = ( r_mem & 0xFC ) | SENSOR_SLEEP_MASK; | |
1598 | if ( synaptics_ts_write ( tpd_i2c_client, DEVICE_CONTROL_REG, &r_mem, 1 ) < 0 ) | |
1599 | { | |
1600 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
1601 | } | |
1602 | } | |
1603 | ||
1604 | /* uevent report */ | |
1605 | kobject_uevent_env ( &foo_obj->kobj, KOBJ_CHANGE, lpwg_uevent[LPWG_MULTI_TAP-1] ); | |
1606 | } | |
1607 | ||
1608 | static int synaptics_knock_check ( void ) | |
1609 | { | |
1610 | TPD_FUN (); | |
1611 | int ret = 0, i = 0; | |
1612 | u8 gesture_status = 0; | |
1613 | u8 r_mem = 0; | |
1614 | ||
1615 | ret = synaptics_page_data_read ( tpd_i2c_client, multi_tap_page, GESTURE_STATUS_REG, 1, (u8 *) &gesture_status ); | |
1616 | if ( ret < 0 ) | |
1617 | { | |
1618 | TPD_ERR ( "GESTURE_STATUS_REG read fail\n" ); | |
1619 | return -1; | |
1620 | } | |
1621 | TPD_LOG ( "MultipleTap gesture status = %d\n", gesture_status ); | |
1622 | custom_gesture_status = gesture_status; | |
1623 | ||
1624 | ret = synaptics_page_data_read ( tpd_i2c_client, multi_tap_page, GESTURE_PROPERTY_REG, multi_tap_count * 4, gesture_property ); | |
1625 | if ( ret < 0 ) | |
1626 | { | |
1627 | TPD_ERR ( "GESTURE_PROPERTY_REG read fail\n" ); | |
1628 | return -1; | |
1629 | } | |
1630 | ||
1631 | if ( double_tap_enable ) | |
1632 | { | |
1633 | /* uevent report */ | |
1634 | kobject_uevent_env ( &foo_obj->kobj, KOBJ_CHANGE, lpwg_uevent[LPWG_DOUBLE_TAP-1] ); | |
1635 | } | |
1636 | else if ( multi_tap_enable ) | |
1637 | { | |
1638 | wake_lock ( &knock_code_lock ); | |
1639 | ||
1640 | if ( custom_gesture_status ) | |
1641 | { | |
1642 | for ( i = 0 ; i < multi_tap_count ; i++ ) | |
1643 | { | |
1644 | TPD_LOG ( "lpwg data %d: [0:0x%-4x 1:0x%-4x 2:0x%-4x 3:0x%-4x]\n", i, gesture_property[4*i], gesture_property[4*i+1], gesture_property[4*i+2], gesture_property[4*i+3] ); | |
1645 | } | |
1646 | } | |
1647 | ||
1648 | if ( synaptics_ts_read ( tpd_i2c_client, TWO_D_REPORT_MODE_REG, 1, &r_mem ) < 0 ) | |
1649 | { | |
1650 | TPD_ERR ( "TWO_D_REPORT_MODE_REG read fail!\n" ); | |
1651 | return -EIO; | |
1652 | } | |
1653 | else | |
1654 | { | |
1655 | r_mem = ( r_mem & 0xF8 ) | REDUCED_REPORTING_MODE_MASK; | |
1656 | if ( synaptics_ts_write ( tpd_i2c_client, TWO_D_REPORT_MODE_REG, &r_mem, 1 ) < 0 ) | |
1657 | { | |
1658 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
1659 | return -EIO; | |
1660 | } | |
1661 | } | |
1662 | ||
1663 | hrtimer_try_to_cancel ( &multi_tap_timer ); | |
1664 | if ( !hrtimer_callback_running ( &multi_tap_timer ) ) | |
1665 | { | |
1666 | TPD_LOG ("timer check\n"); | |
1667 | hrtimer_start ( &multi_tap_timer, ktime_set(0, MS_TO_NS(200)), HRTIMER_MODE_REL ); | |
1668 | } | |
1669 | } | |
1670 | else | |
1671 | { | |
1672 | TPD_ERR ( "Ignore interrupt [double_tap_enable=%d, multi_tap_enable=%d, gesture_status=0x%02x]\n", double_tap_enable, multi_tap_enable, gesture_status ); | |
1673 | return -1; | |
1674 | } | |
1675 | ||
1676 | return 0; | |
1677 | } | |
1678 | ||
1679 | static int synaptics_knock_tap_control ( int on ) | |
1680 | { | |
1681 | TPD_FUN(); | |
1682 | if ( on ) | |
1683 | { | |
1684 | if ( lpwg_mode == LPWG_DOUBLE_TAP ) | |
1685 | { | |
1686 | synaptics_ic_ctrl ( tpd_i2c_client, IC_CTRL_DOUBLE_TAP_WAKEUP_MODE, 1 ); | |
1687 | } | |
1688 | else if ( lpwg_mode == LPWG_MULTI_TAP ) | |
1689 | { | |
1690 | synaptics_ic_ctrl ( tpd_i2c_client, IC_CTRL_DOUBLE_TAP_WAKEUP_MODE, 2 ); | |
1691 | } | |
1692 | } | |
1693 | else | |
1694 | { | |
1695 | synaptics_ic_ctrl ( tpd_i2c_client, IC_CTRL_DOUBLE_TAP_WAKEUP_MODE, 0 ); | |
1696 | } | |
1697 | return 0; | |
1698 | } | |
1699 | ||
1700 | static int synaptics_knock_lpwg ( struct i2c_client* client, u32 code, u32 value, struct point *data ) | |
1701 | { | |
1702 | TPD_FUN(); | |
1703 | u8 buf = 0; | |
1704 | int i = 0, ret = 0; | |
1705 | ||
1706 | if ( code == LPWG_ENABLE || code == LPWG_TAP_COUNT || code == LPWG_REPLY ) | |
1707 | if ( ! Power_status ) | |
1708 | synaptics_power(1); | |
1709 | ||
1710 | switch ( code ) | |
1711 | { | |
1712 | case LPWG_READ: | |
1713 | if ( multi_tap_enable ) | |
1714 | { | |
1715 | if ( custom_gesture_status == 0 ) | |
1716 | { | |
1717 | data[0].x = 1; | |
1718 | data[0].y = 1; | |
1719 | data[1].x = -1; | |
1720 | data[1].y = -1; | |
1721 | break; | |
1722 | } | |
1723 | ||
1724 | for ( i = 0 ; i < multi_tap_count ; i++ ) | |
1725 | { | |
1726 | data[i].x = ( gesture_property[4*i+1] << 8 | gesture_property[4*i] ) / lcd_touch_ratio_x; | |
1727 | data[i].y = ( gesture_property[4*i+3] << 8 | gesture_property[4*i+2] ) / lcd_touch_ratio_y; | |
1728 | TPD_LOG ( "TAP Position x[%3d], y[%3d]\n", data[i].x, data[i].y ); | |
1729 | // '-1' should be assinged to the last data. | |
1730 | // Each data should be converted to LCD-resolution. | |
1731 | } | |
1732 | data[i].x = -1; | |
1733 | data[i].y = -1; | |
1734 | } | |
1735 | break; | |
1736 | ||
1737 | case LPWG_ENABLE: | |
1738 | lpwg_mode = value; | |
1739 | TPD_LOG ( "lpwg_mode=%d, double_tap_enable=%d, multi_tap_enable=%d", lpwg_mode, double_tap_enable, multi_tap_enable ); | |
1740 | ||
1741 | // The 'lpwg_mode' is changed to 'value' but it is applied in suspend-state. | |
1742 | ||
1743 | if ( double_tap_enable || multi_tap_enable ) | |
1744 | { | |
1745 | // IC should sleep when proximity sensor's value is 'NEAR'. | |
1746 | if ( value ) | |
1747 | { | |
1748 | ret = synaptics_ts_read ( client, DEVICE_CONTROL_REG, 1, &buf ); | |
1749 | if ( ret < 0 ) | |
1750 | { | |
1751 | TPD_ERR ( "DEVICE_CONTROL_REG read fail\n" ); | |
1752 | return -1; | |
1753 | } | |
1754 | ||
1755 | buf = ( buf & 0xFC ) | NORMAL_OPERATION_MASK; | |
1756 | ret = synaptics_ts_write ( client, DEVICE_CONTROL_REG, &buf, 1 ); | |
1757 | if ( ret < 0 ) | |
1758 | { | |
1759 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
1760 | return -1; | |
1761 | } | |
1762 | ||
1763 | synaptics_knock_tap_control ( 1 ); | |
1764 | } | |
1765 | else | |
1766 | { | |
1767 | ret = synaptics_ts_read ( client, DEVICE_CONTROL_REG, 1, &buf ); | |
1768 | if ( ret < 0 ) | |
1769 | { | |
1770 | TPD_ERR ( "DEVICE_CONTROL_REG read fail\n" ); | |
1771 | return -1; | |
1772 | } | |
1773 | ||
1774 | buf = ( buf & 0xFC ) | SENSOR_SLEEP_MASK; | |
1775 | ret = synaptics_ts_write ( client, DEVICE_CONTROL_REG, &buf, 1 ); | |
1776 | if ( ret < 0 ) | |
1777 | { | |
1778 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
1779 | return -1; | |
1780 | } | |
1781 | } | |
1782 | } | |
1783 | break; | |
1784 | ||
1785 | case LPWG_LCD_X: | |
1786 | lcd_touch_ratio_x = x_max / value; | |
1787 | TPD_LOG ( "LPWG GET X LCD INFO = %d , RATIO_X = %d", value, lcd_touch_ratio_x ); | |
1788 | break; | |
1789 | ||
1790 | case LPWG_LCD_Y: | |
1791 | // If touch-resolution is not same with LCD-resolution, | |
1792 | // position-data should be converted to LCD-resolution. | |
1793 | lcd_touch_ratio_y = y_max / value; | |
1794 | TPD_LOG ( "LPWG GET Y LCD INFO = %d , RATIO_Y = %d", value, lcd_touch_ratio_y ); | |
1795 | break; | |
1796 | ||
1797 | case LPWG_ACTIVE_AREA_X1: | |
1798 | case LPWG_ACTIVE_AREA_X2: | |
1799 | case LPWG_ACTIVE_AREA_Y1: | |
1800 | case LPWG_ACTIVE_AREA_Y2: | |
1801 | // Quick Cover Area | |
1802 | break; | |
1803 | ||
1804 | case LPWG_TAP_COUNT: | |
1805 | if ( value ) | |
1806 | { | |
1807 | ret = synaptics_page_data_read ( client, multi_tap_page, MULTITAP_COUNT_REG, 1, &buf ); | |
1808 | if ( ret < 0 ) | |
1809 | { | |
1810 | TPD_ERR ( "MULTITAP_COUNT_REG read fail\n" ); | |
1811 | return -1; | |
1812 | } | |
1813 | ||
1814 | TPD_LOG ( "TAP COUNT = %d\n", value ); | |
1815 | buf = ( buf & 0x07 ) | ( value << 3 ); | |
1816 | TPD_LOG ( "MULTITAP_COUNT_REG value 0x%02X\n", buf ); | |
1817 | ||
1818 | ret = synaptics_page_data_write ( client, multi_tap_page, MULTITAP_COUNT_REG, 1, &buf ); | |
1819 | if ( ret < 0 ) | |
1820 | { | |
1821 | TPD_ERR ( "MULTITAP_COUNT_REG write fail\n" ); | |
1822 | return -1; | |
1823 | } | |
1824 | } | |
1825 | multi_tap_count = value; | |
1826 | break; | |
1827 | ||
1828 | case LPWG_REPLY: | |
1829 | // Do something, if you need. | |
1830 | ret = synaptics_ts_read ( client, DEVICE_CONTROL_REG, 1, &buf ); | |
1831 | if ( ret < 0 ) | |
1832 | { | |
1833 | TPD_ERR ( "DEVICE_CONTROL_REG read fail\n" ); | |
1834 | return -1; | |
1835 | } | |
1836 | ||
1837 | buf = ( buf & 0xFC ) | NORMAL_OPERATION_MASK; | |
1838 | ret = synaptics_ts_write ( client, DEVICE_CONTROL_REG, &buf, 1 ); | |
1839 | if ( ret < 0 ) | |
1840 | { | |
1841 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
1842 | return -1; | |
1843 | } | |
1844 | break; | |
1845 | ||
1846 | default: | |
1847 | break; | |
1848 | } | |
1849 | ||
1850 | return 0; | |
1851 | } | |
1852 | ||
1853 | static void synaptics_knock_suspend ( void ) | |
1854 | { | |
1855 | TPD_FUN (); | |
1856 | ||
1857 | if ( !suspend_status && !download_status ) | |
1858 | { | |
1859 | switch ( lpwg_mode ) | |
1860 | { | |
1861 | case LPWG_DOUBLE_TAP: | |
1862 | synaptics_knock_tap_control ( 1 ); | |
1863 | double_tap_enable = 1; | |
1864 | break; | |
1865 | ||
1866 | case LPWG_MULTI_TAP: | |
1867 | synaptics_knock_tap_control ( 1 ); | |
1868 | multi_tap_enable = 1; | |
1869 | break; | |
1870 | ||
1871 | default: | |
1872 | break; | |
1873 | } | |
1874 | ||
1875 | TPD_LOG ( "synaptics_knock_suspend lpwg_mode : %d, %d, %d\n", lpwg_mode, double_tap_enable, multi_tap_enable ); | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | static void synaptics_knock_resume ( void ) | |
1880 | { | |
1881 | TPD_FUN (); | |
1882 | ||
1883 | if ( knock_on_enable ) | |
1884 | { | |
1885 | if ( ! Power_status ) | |
1886 | synaptics_power(1); | |
1887 | synaptics_knock_tap_control(0); | |
1888 | } | |
1889 | else | |
1890 | TPD_ERR("knock_on_enable : 0x%x\n", knock_on_enable); | |
1891 | ||
1892 | } | |
1893 | ||
1894 | /**************************************************************************** | |
1895 | * Touch Interrupt Service Routines | |
1896 | ****************************************************************************/ | |
1897 | static void touch_eint_interrupt_handler ( void ) | |
1898 | { | |
1899 | TPD_DEBUG_PRINT_INT; | |
1900 | ||
1901 | tpd_flag = 1; | |
1902 | wake_up_interruptible ( &tpd_waiter ); | |
1903 | } | |
1904 | ||
1905 | static int synaptics_touch_event_handler ( void *unused ) | |
1906 | { | |
1907 | int ret = 0; | |
1908 | u8 int_status; | |
1909 | u8 int_enable; | |
1910 | u8 finger_count, button_count; | |
1911 | u8 reg_num, finger_order; | |
1912 | u8 button_data; | |
1913 | int width_min = 0, width_max = 0; | |
1914 | int width_orientation; | |
1915 | int index; | |
1916 | touch_sensor_data sensor_data; | |
1917 | touch_finger_info finger_info; | |
1918 | char report_enable = 0; | |
1919 | ||
1920 | struct sched_param param = { .sched_priority = RTPM_PRIO_TPD }; | |
1921 | ||
1922 | sched_setscheduler ( current, SCHED_RR, ¶m ); | |
1923 | ||
1924 | do | |
1925 | { | |
1926 | set_current_state ( TASK_INTERRUPTIBLE ); | |
1927 | wait_event_interruptible ( tpd_waiter, tpd_flag != 0 ); | |
1928 | ||
1929 | tpd_flag = 0; | |
1930 | set_current_state ( TASK_RUNNING ); | |
1931 | ||
1932 | mt_eint_mask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
1933 | mutex_lock ( &i2c_access ); | |
1934 | ||
1935 | index = 0; | |
1936 | memset(&sensor_data, 0x0, sizeof(touch_sensor_data)); | |
1937 | memset(&finger_info, 0x0, sizeof(touch_finger_info)); | |
1938 | pressure_zero = 0; | |
1939 | ||
1940 | ret = synaptics_ic_status_check (); | |
1941 | if ( ret != 0 ) | |
1942 | { | |
1943 | goto exit_work; | |
1944 | } | |
1945 | ||
1946 | /* read interrupt information */ | |
1947 | ret = synaptics_ts_read ( tpd_i2c_client, INTERRUPT_STATUS_REG, 1, (u8 *) &int_status ); | |
1948 | if ( ret < 0 ) | |
1949 | { | |
1950 | TPD_ERR ( "INTERRUPT_STATUS_REG read fail\n" ); | |
1951 | goto exit_work; | |
1952 | } | |
1953 | // TPD_LOG ("int_status = 0x%x\n", int_status); | |
1954 | if ( int_status == 0x40 || int_status == 0 ) | |
1955 | goto exit_work; | |
1956 | ||
1957 | /* Knock On or Knock Code Check */ | |
1958 | if ( suspend_status && knock_on_enable ) | |
1959 | { | |
1960 | if ( download_status == 1 ) | |
1961 | { | |
1962 | TPD_LOG ( "knock_on is not checked (F/W downloading...)\n" ); | |
1963 | } | |
1964 | else | |
1965 | { | |
1966 | ||
1967 | ret = synaptics_knock_check (); | |
1968 | if ( ret != 0 ) | |
1969 | { | |
1970 | TPD_LOG ( "Touch Knock_On fail\n" ); | |
1971 | } | |
1972 | } | |
1973 | ||
1974 | goto exit_work; | |
1975 | } | |
1976 | ||
1977 | ret = synaptics_ts_read ( tpd_i2c_client, INTERRUPT_ENABLE_REG, 1, (u8 *) &int_enable ); | |
1978 | if ( ret < 0 ) | |
1979 | { | |
1980 | TPD_ERR ( "INTERRUPT_ENABLE_REG read fail\n" ); | |
1981 | goto exit_work; | |
1982 | } | |
1983 | ||
1984 | /* read finger state & finger data */ | |
1985 | ret = synaptics_ts_read ( tpd_i2c_client, TWO_D_FINGER_STATE_REG, sizeof(sensor_data), (u8 *) &sensor_data.finger_state[0] ); | |
1986 | if (ret < 0) | |
1987 | { | |
1988 | TPD_ERR ( "TWO_D_FINGER_STATE_REG read fail\n" ); | |
1989 | goto exit_work; | |
1990 | } | |
1991 | ||
1992 | ||
1993 | /* Finger Event Processing */ | |
1994 | if ( ( int_status & ABS0_MASK ) && ( int_enable & ABS0_MASK ) ) | |
1995 | { | |
1996 | for ( finger_count = 0 ; finger_count < MAX_NUM_OF_FINGER ; finger_count++ ) | |
1997 | { | |
1998 | reg_num = finger_count / 4; | |
1999 | finger_order = finger_count % 4; | |
2000 | ||
2001 | if ( ( ( sensor_data.finger_state[reg_num] >> ( finger_order * 2 ) ) & FINGER_STATE_MASK ) == 1 ) | |
2002 | { | |
2003 | finger_info.pos_x[finger_count] = ( int ) GET_X_POSITION(sensor_data.finger_data[finger_count][X_POSITION], sensor_data.finger_data[finger_count][XY_POSITION]); | |
2004 | finger_info.pos_y[finger_count] = ( int ) GET_Y_POSITION(sensor_data.finger_data[finger_count][Y_POSITION], sensor_data.finger_data[finger_count][XY_POSITION]); | |
2005 | ||
2006 | if ( ( ( sensor_data.finger_data[finger_count][WX_WY] & 0xF0 ) >> 4 ) > ( sensor_data.finger_data[finger_count][WX_WY] & 0x0F ) ) | |
2007 | { | |
2008 | width_max = ( sensor_data.finger_data[finger_count][WX_WY] & 0xF0 ) >> 4; | |
2009 | width_min = sensor_data.finger_data[finger_count][WX_WY] & 0x0F; | |
2010 | width_orientation = 0; | |
2011 | } | |
2012 | else | |
2013 | { | |
2014 | width_max = sensor_data.finger_data[finger_count][WX_WY] & 0x0F; | |
2015 | width_min = ( sensor_data.finger_data[finger_count][WX_WY] & 0xF0 ) >> 4; | |
2016 | width_orientation = 1; | |
2017 | } | |
2018 | ||
2019 | finger_info.pressure[finger_count] = sensor_data.finger_data[finger_count][PRESSURE]; | |
2020 | ||
2021 | if ( use_ghost_detection ) | |
2022 | { | |
2023 | if ( finger_info.pressure[finger_count] == 0 ) | |
2024 | pressure_zero = 1; | |
2025 | } | |
2026 | ||
2027 | #if !defined(MT_PROTOCOL_A) | |
2028 | input_mt_slot( tpd->dev, finger_count); | |
2029 | input_mt_report_slot_state( tpd->dev, MT_TOOL_FINGER, true); | |
2030 | #endif | |
2031 | input_report_abs ( tpd->dev, ABS_MT_POSITION_X, finger_info.pos_x[finger_count] ); | |
2032 | input_report_abs ( tpd->dev, ABS_MT_POSITION_Y, finger_info.pos_y[finger_count] ); | |
2033 | input_report_abs ( tpd->dev, ABS_MT_PRESSURE, finger_info.pressure[finger_count] ); | |
2034 | input_report_abs ( tpd->dev, ABS_MT_WIDTH_MAJOR, width_max ); | |
2035 | input_report_abs ( tpd->dev, ABS_MT_WIDTH_MINOR, width_min ); | |
2036 | input_report_abs ( tpd->dev, ABS_MT_ORIENTATION, width_orientation ); | |
2037 | ||
2038 | input_report_abs ( tpd->dev, ABS_MT_TRACKING_ID, finger_count ); | |
2039 | ||
2040 | report_enable = 1; | |
2041 | ||
2042 | old_touch_info.pos_x[finger_count] = pre_touch_info.pos_x[finger_count]; | |
2043 | old_touch_info.pos_y[finger_count] = pre_touch_info.pos_y[finger_count]; | |
2044 | old_touch_info.pressure[finger_count]= pre_touch_info.pressure[finger_count]; | |
2045 | pre_touch_info.pos_x[finger_count] = finger_info.pos_x[finger_count]; | |
2046 | pre_touch_info.pos_y[finger_count] = finger_info.pos_y[finger_count]; | |
2047 | pre_touch_info.pressure[finger_count] = finger_info.pressure[finger_count]; | |
2048 | index++; | |
2049 | ||
2050 | /* ignore Key event during Finger event processing */ | |
2051 | if ( finger_prestate[finger_count] == TOUCH_RELEASED ) | |
2052 | { | |
2053 | finger_oldstate[finger_count] = finger_prestate[finger_count]; | |
2054 | finger_prestate[finger_count] = TOUCH_PRESSED; | |
2055 | TPD_LOG ( "key is %s ( x/y = 0x%x, 0x%x )\n", finger_prestate[finger_count] ? "pressed" : "released", | |
2056 | pre_touch_info.pos_x[finger_count], pre_touch_info.pos_y[finger_count] ); | |
2057 | for ( button_count = 0 ; button_count < TPD_KEY_COUNT ; button_count++ ) | |
2058 | { | |
2059 | if ( button_prestate[button_count] == TOUCH_PRESSED ) | |
2060 | { | |
2061 | input_report_key ( tpd->dev, tpd_keys_local[button_count], BUTTON_CANCLED ); | |
2062 | TPD_LOG ( "Touch KEY[%d] is canceled!\n", button_count + 1 ); | |
2063 | button_prestate[button_count] = TOUCH_RELEASED; | |
2064 | } | |
2065 | } | |
2066 | ||
2067 | /* Button interrupt Disable when first finger pressed */ | |
2068 | if ( int_enable & button_enable_mask ) | |
2069 | { | |
2070 | int_enable = int_enable & ~( button_enable_mask ); | |
2071 | ||
2072 | ret = synaptics_ts_write ( tpd_i2c_client, INTERRUPT_ENABLE_REG, &int_enable, 1 ); | |
2073 | if ( ret < 0 ) | |
2074 | { | |
2075 | TPD_ERR ( "INTERRUPT_ENABLE_REG write fail\n" ); | |
2076 | } | |
2077 | } | |
2078 | } | |
2079 | } | |
2080 | else if ( finger_prestate[finger_count] == TOUCH_PRESSED ) | |
2081 | { | |
2082 | #if !defined(MT_PROTOCOL_A) | |
2083 | input_mt_slot(tpd->dev, finger_count); | |
2084 | input_mt_report_slot_state(tpd->dev, MT_TOOL_FINGER, false); | |
2085 | #endif | |
2086 | finger_oldstate[finger_count] = finger_prestate[finger_count]; | |
2087 | finger_prestate[finger_count] = TOUCH_RELEASED; | |
2088 | TPD_LOG ( "key is %s ( x/y = 0x%x, 0x%x )\n", finger_prestate[finger_count] ? "pressed" : "released", | |
2089 | pre_touch_info.pos_x[finger_count], pre_touch_info.pos_y[finger_count] ); | |
2090 | report_enable = 1; | |
2091 | ||
2092 | /* Button interrupt Enable when all finger released */ | |
2093 | if ( sensor_data.finger_state[0] == 0 && sensor_data.finger_state[1] == 0 ) | |
2094 | { | |
2095 | int_enable = int_enable | button_enable_mask; | |
2096 | ||
2097 | ret = synaptics_ts_write ( tpd_i2c_client, INTERRUPT_ENABLE_REG, &int_enable, 1 ); | |
2098 | if ( ret < 0 ) | |
2099 | { | |
2100 | TPD_ERR ( "INTERRUPT_ENABLE_REG write fail\n" ); | |
2101 | } | |
2102 | } | |
2103 | ||
2104 | pre_touch_info.pos_x[finger_count] = 0; | |
2105 | pre_touch_info.pos_y[finger_count] = 0; | |
2106 | } | |
2107 | ||
2108 | if ( report_enable ) | |
2109 | { | |
2110 | #if defined(MT_PROTOCOL_A) | |
2111 | input_mt_sync ( tpd->dev ); | |
2112 | #endif | |
2113 | report_enable = 0; | |
2114 | } | |
2115 | } | |
2116 | ||
2117 | finger_info.total_num = index; | |
2118 | old_touch_info.total_num = pre_touch_info.total_num; | |
2119 | pre_touch_info.total_num = finger_info.total_num; | |
2120 | ||
2121 | input_sync ( tpd->dev ); | |
2122 | } | |
2123 | ||
2124 | ||
2125 | /* Button Event Processing */ | |
2126 | if ( ( int_status & button_enable_mask ) && ( int_enable & button_enable_mask ) ) | |
2127 | { | |
2128 | /* read button data */ | |
2129 | ret = synaptics_page_data_read ( tpd_i2c_client, button_page, BUTTON_DATA_REG, sizeof(button_data), (u8 *) &button_data ); | |
2130 | if ( ret < 0 ) | |
2131 | { | |
2132 | TPD_ERR ( "BUTTON_DATA_REG read fail\n" ); | |
2133 | goto exit_work; | |
2134 | } | |
2135 | ||
2136 | for ( button_count = 0 ; button_count < TPD_KEY_COUNT ; button_count++ ) | |
2137 | { | |
2138 | if ( ( ( button_data >> button_count ) & 0x1 ) == 1 && ( button_prestate[button_count] == TOUCH_RELEASED ) ) | |
2139 | { | |
2140 | button_oldstate[button_count] = button_prestate[button_count]; | |
2141 | button_prestate[button_count] = TOUCH_PRESSED; | |
2142 | report_enable = 1; | |
2143 | } | |
2144 | else if ( ( ( button_data >> button_count ) & 0x1 ) == 0 && ( button_prestate[button_count] == TOUCH_PRESSED ) ) | |
2145 | { | |
2146 | button_oldstate[button_count] = button_prestate[button_count]; | |
2147 | button_prestate[button_count] = TOUCH_RELEASED; | |
2148 | report_enable = 1; | |
2149 | } | |
2150 | ||
2151 | if ( report_enable ) | |
2152 | { | |
2153 | input_report_key ( tpd->dev, tpd_keys_local[button_count], button_prestate[button_count] ); | |
2154 | TPD_LOG ( "Touch key is %s (keyID = 0x%x)\n", button_prestate[button_count] ? "pressed" : "released", button_count ); | |
2155 | report_enable = 0; | |
2156 | } | |
2157 | } | |
2158 | ||
2159 | input_sync ( tpd->dev ); | |
2160 | } | |
2161 | ||
2162 | if ( use_ghost_detection ) | |
2163 | { | |
2164 | ret = ghost_detect_solution (); | |
2165 | if ( ret == NEED_TO_OUT ) | |
2166 | { | |
2167 | goto exit_work; | |
2168 | } | |
2169 | else if ( ret == NEED_TO_INIT ) | |
2170 | { | |
2171 | synaptics_release_all_finger (); | |
2172 | synaptics_ic_reset (); | |
2173 | synaptics_ic_ctrl ( tpd_i2c_client, IC_CTRL_REPORT_MODE, CONTINUOUS_REPORTING_MODE_MASK ); | |
2174 | force_continuous_mode = 1; | |
2175 | ghost_detection = 0; | |
2176 | ghost_detection_count = 0; | |
2177 | do_gettimeofday ( &t_ex_debug[TIME_EX_INIT_TIME] ); | |
2178 | return; | |
2179 | } | |
2180 | } | |
2181 | exit_work: | |
2182 | mutex_unlock ( &i2c_access ); | |
2183 | mt_eint_unmask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
2184 | } while ( !kthread_should_stop () ); | |
2185 | ||
2186 | return 0; | |
2187 | } | |
2188 | ||
2189 | /**************************************************************************** | |
2190 | * SYSFS function for Touch | |
2191 | ****************************************************************************/ | |
2192 | static ssize_t show_knock_on_type ( struct device *dev, struct device_attribute *attr, char *buf ) | |
2193 | { | |
2194 | int ret = 0; | |
2195 | ||
2196 | ret = sprintf ( buf, "%d\n", knock_on_type ); | |
2197 | ||
2198 | return ret; | |
2199 | } | |
2200 | static DEVICE_ATTR ( knock_on_type, 0664, show_knock_on_type, NULL ); | |
2201 | ||
2202 | static ssize_t show_lpwg_data ( struct device *dev, struct device_attribute *attr, char *buf ) | |
2203 | { | |
2204 | TPD_FUN (); | |
2205 | int i = 0, ret = 0; | |
2206 | ||
2207 | memset(lpwg_data, 0, sizeof(struct point)*MAX_POINT_SIZE_FOR_LPWG); | |
2208 | ||
2209 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_READ, 0, lpwg_data ); | |
2210 | for ( i = 0 ; i < MAX_POINT_SIZE_FOR_LPWG ; i++ ) | |
2211 | { | |
2212 | if ( lpwg_data[i].x == -1 && lpwg_data[i].y == -1 ) | |
2213 | { | |
2214 | break; | |
2215 | } | |
2216 | ret += sprintf ( buf+ret, "%d %d\n", lpwg_data[i].x, lpwg_data[i].y ); | |
2217 | } | |
2218 | ||
2219 | return ret; | |
2220 | } | |
2221 | ||
2222 | static ssize_t store_lpwg_data ( struct device *dev, struct device_attribute *attr, const char *buf, size_t size ) | |
2223 | { | |
2224 | TPD_FUN (); | |
2225 | int reply = 0; | |
2226 | ||
2227 | sscanf ( buf, "%d", &reply ); | |
2228 | TPD_LOG ( "LPWG RESULT = %d ", reply ); | |
2229 | ||
2230 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_REPLY, reply, NULL ); | |
2231 | ||
2232 | wake_unlock ( &knock_code_lock ); | |
2233 | ||
2234 | return size; | |
2235 | } | |
2236 | static DEVICE_ATTR ( lpwg_data, 0664, show_lpwg_data, store_lpwg_data ); | |
2237 | ||
2238 | static ssize_t store_lpwg_notify ( struct device *dev, struct device_attribute *attr, const char *buf, size_t size ) | |
2239 | { | |
2240 | TPD_FUN(); | |
2241 | static int suspend = 0; | |
2242 | int type = 0; | |
2243 | int value[4] = {0}; | |
2244 | ||
2245 | sscanf ( buf, "%d %d %d %d %d", &type, &value[0], &value[1], &value[2], &value[3] ); | |
2246 | TPD_LOG ( "touch notify type = %d , value[0] = %d, value[1] = %d, valeu[2] = %d, value[3] = %d ", type, value[0], value[1], value[2], value[3] ); | |
2247 | ||
2248 | switch ( type ) | |
2249 | { | |
2250 | case 1: | |
2251 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_ENABLE, value[0], NULL ); | |
2252 | ||
2253 | if ( value[0] ) | |
2254 | { | |
2255 | knock_on_enable = 1; | |
2256 | } | |
2257 | else | |
2258 | { | |
2259 | knock_on_enable = 0; | |
2260 | } | |
2261 | ||
2262 | if ( suspend ) | |
2263 | { | |
2264 | synaptics_knock_suspend (); | |
2265 | } | |
2266 | break; | |
2267 | ||
2268 | case 2: | |
2269 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_LCD_X, value[0], NULL ); | |
2270 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_LCD_Y, value[1], NULL ); | |
2271 | break; | |
2272 | ||
2273 | case 3: | |
2274 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_ACTIVE_AREA_X1, value[0], NULL ); | |
2275 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_ACTIVE_AREA_X2, value[1], NULL ); | |
2276 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_ACTIVE_AREA_Y1, value[2], NULL ); | |
2277 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_ACTIVE_AREA_Y2, value[3], NULL ); | |
2278 | break; | |
2279 | ||
2280 | case 4: | |
2281 | synaptics_knock_lpwg ( tpd_i2c_client, LPWG_TAP_COUNT, value[0], NULL ); | |
2282 | break; | |
2283 | ||
2284 | case 6: | |
2285 | if ( value[0] == 0 ) | |
2286 | { | |
2287 | suspend = 1; | |
2288 | if ( knock_on_enable ) | |
2289 | { | |
2290 | synaptics_knock_suspend (); | |
2291 | } | |
2292 | else | |
2293 | TPD_ERR("knock_on_enable : 0x%x\n", knock_on_enable); | |
2294 | } | |
2295 | else if ( value[0] == 1 ) | |
2296 | { | |
2297 | suspend = 0; | |
2298 | if ( knock_on_enable ) | |
2299 | { | |
2300 | synaptics_knock_resume (); | |
2301 | } | |
2302 | else | |
2303 | TPD_ERR("knock_on_enable : 0x%x\n", knock_on_enable); | |
2304 | } | |
2305 | break; | |
2306 | ||
2307 | default: | |
2308 | break; | |
2309 | } | |
2310 | ||
2311 | return size; | |
2312 | } | |
2313 | static DEVICE_ATTR ( lpwg_notify, 0664, NULL, store_lpwg_notify ); | |
2314 | ||
2315 | static int Firmware_verification(char *buf) | |
2316 | { | |
2317 | int ret = 0; | |
2318 | u8 fw_config_id[5] = {0}; | |
2319 | char fw_product_id[11] = {0}; | |
2320 | char manufacture_id = 0; | |
2321 | ||
2322 | TPD_FUN(); | |
2323 | ret += sprintf ( buf+ret, "\n\n\n" ); | |
2324 | write_log ( buf ); | |
2325 | msleep ( 30 ); | |
2326 | //write_time_log (); | |
2327 | msleep ( 30 ); | |
2328 | ||
2329 | ret = synaptics_ts_read ( tpd_i2c_client, PRODUCT_ID_REG, 10, &fw_product_id[0] ); | |
2330 | if ( ret < 0 ) | |
2331 | { | |
2332 | TPD_ERR ( "PRODUCT_ID_REG read fail\n" ); | |
2333 | } | |
2334 | ret = synaptics_ts_read ( tpd_i2c_client, FLASH_CONFIG_ID_REG, 4, &fw_config_id[0] ); | |
2335 | if ( ret < 0 ) | |
2336 | { | |
2337 | TPD_ERR ( "FLASH_CONFIG_ID_REG read fail\n" ); | |
2338 | } | |
2339 | ||
2340 | ret = synaptics_ts_read ( tpd_i2c_client, MANUFACTURER_ID_REG, 1, &manufacture_id ); | |
2341 | if ( ret < 0 ) | |
2342 | { | |
2343 | TPD_ERR ( "MANUFACTURER_ID_REG read fail\n" ); | |
2344 | } | |
2345 | ||
2346 | ret += sprintf ( buf+ret, "IC_FW_Version (RAW) \t: [%02X%02X%02X%02X]\n", fw_config_id[0], fw_config_id[1], fw_config_id[2], fw_config_id[3] ); | |
2347 | ret += sprintf ( buf+ret, "Product_ID \t\t: [%s] \n", fw_product_id ); | |
2348 | ret += sprintf ( buf+ret, "Manufacture_ID \t\t: [%d] \n", manufacture_id ); | |
2349 | ret += sprintf ( buf+ret, "IC_FW_Version\n"); | |
2350 | ||
2351 | ||
2352 | switch(fw_config_id[0] & 0xF0) //maker | |
2353 | { | |
2354 | case 0x00: | |
2355 | ret += sprintf ( buf+ret, "Maker \t\t\t: [ELK] \n"); | |
2356 | break; | |
2357 | case 0x10: | |
2358 | ret += sprintf ( buf+ret, "Maker \t\t\t: [Suntel] \n"); | |
2359 | break; | |
2360 | case 0x20: | |
2361 | ret += sprintf ( buf+ret, "Maker \t\t\t: [Tovis] \n"); | |
2362 | break; | |
2363 | case 0x30: | |
2364 | ret += sprintf ( buf+ret, "Maker \t\t\t: [Innotek] \n"); | |
2365 | break; | |
2366 | default: | |
2367 | break; | |
2368 | } | |
2369 | ||
2370 | switch(fw_config_id[0] & 0x0F) //key | |
2371 | { | |
2372 | case 0x00: | |
2373 | ret += sprintf ( buf+ret, "Key \t\t\t: [No key] \n"); | |
2374 | break; | |
2375 | case 0x01: | |
2376 | ret += sprintf ( buf+ret, "Key \t\t\t: [1 Key] \n"); | |
2377 | break; | |
2378 | case 0x02: | |
2379 | ret += sprintf ( buf+ret, "Key \t\t\t: [2 Key] \n"); | |
2380 | break; | |
2381 | case 0x03: | |
2382 | ret += sprintf ( buf+ret, "Key \t\t\t: [3 Key] \n"); | |
2383 | break; | |
2384 | case 0x04: | |
2385 | ret += sprintf ( buf+ret, "Key \t\t\t: [4Key] \n"); | |
2386 | break; | |
2387 | default: | |
2388 | break; | |
2389 | } | |
2390 | ||
2391 | switch(fw_config_id[1] & 0xF0 ) //Supplier | |
2392 | { | |
2393 | case 0x00: | |
2394 | ret += sprintf ( buf+ret, "Supplier \t\t: [Synaptics] \n"); | |
2395 | break; | |
2396 | default: | |
2397 | break; | |
2398 | } | |
2399 | ||
2400 | ret += sprintf ( buf+ret, "Panel(inch) \t\t: [%d.%d] \n", fw_config_id[1] & 0x0F, fw_config_id[2] & 0xF0); //Panel | |
2401 | ret += sprintf ( buf+ret, "Version \t\t: [v0.%d] \n", fw_config_id[3] & 0xEF); //Panel | |
2402 | ||
2403 | return ret; | |
2404 | } | |
2405 | ||
2406 | static ssize_t show_sd ( struct device *dev, struct device_attribute *attr, char *buf ) | |
2407 | { | |
2408 | int ret = 0; | |
2409 | int rx_to_rx = 0; | |
2410 | int tx_to_tx = 0; | |
2411 | int tx_to_gnd = 0; | |
2412 | int high_registance = 0; | |
2413 | int full_raw_cap = 0; | |
2414 | u8 fw_config_id[5] = {0}; | |
2415 | char fw_product_id[11] = {0}; | |
2416 | ||
2417 | TPD_FUN(); | |
2418 | if ( !suspend_status ) | |
2419 | { | |
2420 | /* | |
2421 | ret = Firmware_verification(buf); | |
2422 | ||
2423 | write_log ( buf ); | |
2424 | msleep ( 30 ); | |
2425 | ||
2426 | SYNA_PDTScan (); | |
2427 | SYNA_ConstructRMI_F54 (); | |
2428 | SYNA_ConstructRMI_F1A (); | |
2429 | ||
2430 | mt_eint_mask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
2431 | rx_to_rx = F54_RxToRxReport(); | |
2432 | ||
2433 | if ( rx_to_rx == 2 ) | |
2434 | { | |
2435 | ret = 0; | |
2436 | ret += sprintf ( buf+ret, "\nRxToRxReport fail!! try again\n" ); | |
2437 | write_log ( buf ); | |
2438 | synaptics_initialize ( tpd_i2c_client ); | |
2439 | mt_eint_unmask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
2440 | ||
2441 | return ret; | |
2442 | } | |
2443 | ||
2444 | tx_to_tx = F54_TxToTxReport (); | |
2445 | tx_to_gnd = F54_TxToGndReport (); | |
2446 | high_registance = F54_HighResistance (); | |
2447 | ||
2448 | if ( get_limit ( numberOfTx, numberOfRx ) < 0 ) | |
2449 | { | |
2450 | TPD_ERR ( "Can not check the limit of rawcap\n" ); | |
2451 | full_raw_cap = F54_FullRawCap ( 5 ); | |
2452 | TPD_LOG ("11\n"); | |
2453 | } | |
2454 | else | |
2455 | { | |
2456 | full_raw_cap = F54_FullRawCap ( 0 ); | |
2457 | TPD_LOG ("33\n"); | |
2458 | } | |
2459 | full_raw_cap = 1; | |
2460 | TPD_LOG ("full_raw_cap=%d\n",full_raw_cap); | |
2461 | */ | |
2462 | ||
2463 | ret += sprintf ( buf+ret, "=======RESULT========\n" ); | |
2464 | ret += sprintf ( buf+ret, "Channel Status : %s\n", ( 1 ) ? "PASS" : "FAIL" ); | |
2465 | ret += sprintf ( buf+ret, "Raw Data : %s\n", (1) ? "PASS" : "FAIL" ); | |
2466 | ||
2467 | synaptics_initialize ( tpd_i2c_client ); | |
2468 | //mt_eint_unmask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
2469 | } | |
2470 | else | |
2471 | { | |
2472 | //write_time_log (); | |
2473 | ret += sprintf ( buf+ret, "state=[suspend]. we cannot use I2C, now. Test Result: Fail\n" ); | |
2474 | } | |
2475 | ||
2476 | return ret; | |
2477 | } | |
2478 | static DEVICE_ATTR ( sd, 0664, show_sd, NULL ); | |
2479 | ||
2480 | static ssize_t show_factory_version ( struct device *dev, struct device_attribute *attr, char *buf ) | |
2481 | { | |
2482 | int ret = 0; | |
2483 | ||
2484 | if ( !suspend_status ) | |
2485 | { | |
2486 | ret = Firmware_verification(buf); | |
2487 | } | |
2488 | else | |
2489 | { | |
2490 | //write_time_log (); | |
2491 | ret += sprintf ( buf+ret, "state=[suspend]. we cannot use I2C, now. Test Result: Fail\n" ); | |
2492 | } | |
2493 | return ret; | |
2494 | } | |
2495 | static DEVICE_ATTR ( factory_version, 0664, show_factory_version, NULL ); | |
2496 | static struct attribute *lge_touch_attrs[] = { | |
2497 | ||
2498 | &dev_attr_knock_on_type.attr, | |
2499 | &dev_attr_lpwg_data.attr, | |
2500 | &dev_attr_lpwg_notify.attr, | |
2501 | &dev_attr_sd.attr, | |
2502 | &dev_attr_factory_version.attr, | |
2503 | NULL, | |
2504 | }; | |
2505 | ||
2506 | static struct attribute_group lge_touch_group = { | |
2507 | .name = LGE_TOUCH_NAME, | |
2508 | .attrs = lge_touch_attrs, | |
2509 | }; | |
2510 | ||
2511 | ||
2512 | #if defined(LGE_USE_SYNAPTICS_F54) | |
2513 | static ssize_t synaptics_show_f54 ( struct device *dev, struct device_attribute *attr, char *buf ) | |
2514 | { | |
2515 | int ret = 0; | |
2516 | ||
2517 | if ( suspend_status == 0 ) | |
2518 | { | |
2519 | SYNA_PDTScan (); | |
2520 | SYNA_ConstructRMI_F54 (); | |
2521 | SYNA_ConstructRMI_F1A (); | |
2522 | ||
2523 | ret = sprintf ( buf, "====== F54 Function Info ======\n" ); | |
2524 | ||
2525 | switch ( f54_fullrawcap_mode ) | |
2526 | { | |
2527 | case 0: | |
2528 | ret += sprintf ( buf + ret, "fullrawcap_mode = For sensor\n" ); | |
2529 | break; | |
2530 | case 1: | |
2531 | ret += sprintf ( buf + ret, "fullrawcap_mode = For FPC\n" ); | |
2532 | break; | |
2533 | case 2: | |
2534 | ret += sprintf ( buf + ret, "fullrawcap_mode = CheckTSPConnection\n" ); | |
2535 | break; | |
2536 | case 3: | |
2537 | ret += sprintf ( buf + ret, "fullrawcap_mode = Baseline\n" ); | |
2538 | break; | |
2539 | case 4: | |
2540 | ret += sprintf ( buf + ret, "fullrawcap_mode = Delta image\n" ); | |
2541 | break; | |
2542 | } | |
2543 | ||
2544 | mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM); | |
2545 | ||
2546 | ret += sprintf ( buf + ret, "F54_FullRawCap(%d) Test Result: %s", f54_fullrawcap_mode, (F54_FullRawCap(f54_fullrawcap_mode) > 0) ? "Pass\n" : "Fail\n" ); | |
2547 | ret += sprintf ( buf + ret, "F54_TxToTxReport() Test Result: %s", (F54_TxToTxReport() > 0) ? "Pass\n" : "Fail\n" ); | |
2548 | ret += sprintf ( buf + ret, "F54_RxToRxReport() Test Result: %s", (F54_RxToRxReport() > 0) ? "Pass\n" : "Fail\n" ); | |
2549 | ret += sprintf ( buf + ret, "F54_TxToGndReport() Test Result: %s", (F54_TxToGndReport() > 0) ? "Pass\n" : "Fail\n" ); | |
2550 | ret += sprintf ( buf + ret, "F54_HighResistance() Test Result: %s", (F54_HighResistance() > 0) ? "Pass\n" : "Fail\n" ); | |
2551 | ||
2552 | mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM); | |
2553 | } | |
2554 | else | |
2555 | { | |
2556 | ret = sprintf ( buf + ret, "state=[suspend]. we cannot use I2C, now. Test Result: Fail\n" ); | |
2557 | } | |
2558 | ||
2559 | return ret; | |
2560 | } | |
2561 | ||
2562 | static ssize_t synaptics_store_f54 ( struct device *dev, struct device_attribute *attr, const char *buf, size_t size ) | |
2563 | { | |
2564 | int ret = 0; | |
2565 | ||
2566 | ret = sscanf ( buf, "%d", &f54_fullrawcap_mode ); | |
2567 | ||
2568 | return size; | |
2569 | } | |
2570 | static DEVICE_ATTR ( f54, 0664, synaptics_show_f54, synaptics_store_f54 ); | |
2571 | #endif | |
2572 | ||
2573 | #if defined(LGE_USE_SYNAPTICS_FW_UPGRADE) | |
2574 | static ssize_t synaptics_store_firmware ( struct device *dev, struct device_attribute *attr, const char *buf, size_t size ) | |
2575 | { | |
2576 | int ret; | |
2577 | char path[256] = {0}; | |
2578 | ||
2579 | sscanf ( buf, "%s", path ); | |
2580 | TPD_LOG ( "Firmware image update: %s\n", path ); | |
2581 | ||
2582 | if ( !strncmp ( path, "1", 1 ) ) | |
2583 | { | |
2584 | fw_force_update = 1; | |
2585 | } | |
2586 | else | |
2587 | { | |
2588 | memcpy ( fw_path, path, sizeof(fw_path) ); | |
2589 | } | |
2590 | ||
2591 | ret = synaptics_firmware_update ( tpd_i2c_client ); | |
2592 | ||
2593 | synaptics_initialize ( tpd_i2c_client ); | |
2594 | ||
2595 | return size; | |
2596 | } | |
2597 | static DEVICE_ATTR ( firmware, 0664, NULL, synaptics_store_firmware ); | |
2598 | #endif | |
2599 | ||
2600 | static ssize_t synaptics_show_version ( struct device *dev, struct device_attribute *attr, char *buf ) | |
2601 | { | |
2602 | char fw_config_id[5] = {0}; | |
2603 | char fw_product_id[11] = {0}; | |
2604 | int ret; | |
2605 | ||
2606 | ret = synaptics_ts_read ( tpd_i2c_client, PRODUCT_ID_REG, 10, &fw_product_id[0] ); | |
2607 | if ( ret < 0 ) | |
2608 | { | |
2609 | TPD_ERR ( "PRODUCT_ID_REG read fail\n" ); | |
2610 | } | |
2611 | ret = synaptics_ts_read ( tpd_i2c_client, FLASH_CONFIG_ID_REG, 4, &fw_config_id[0] ); | |
2612 | if ( ret < 0 ) | |
2613 | { | |
2614 | TPD_ERR ( "FLASH_CONFIG_ID_REG read fail\n" ); | |
2615 | } | |
2616 | return sprintf ( buf, "FW_Version[%02x%02x%02x%02x], HW_Version[%s]\n", fw_config_id[0],fw_config_id[1],fw_config_id[2],fw_config_id[3], fw_product_id); | |
2617 | ||
2618 | } | |
2619 | static DEVICE_ATTR ( version, 0664, synaptics_show_version, NULL ); | |
2620 | ||
2621 | static ssize_t synaptics_store_write ( struct device *dev, struct device_attribute *attr, char *buf, size_t size ) | |
2622 | { | |
2623 | u8 temp = 0; | |
2624 | unsigned int reg = 0; | |
2625 | unsigned int value = 0; | |
2626 | unsigned int page = 0; | |
2627 | int ret; | |
2628 | ||
2629 | sscanf ( buf, "%d %x %x", &page, ®, &value ); | |
2630 | TPD_LOG ( "(write) page=%d, reg=0x%x, value=0x%x\n", page, reg, value ); | |
2631 | ||
2632 | ret = synaptics_page_data_write ( tpd_i2c_client, page, (u8)reg, 1, (u8 *)&value ); | |
2633 | if ( ret < 0 ) | |
2634 | { | |
2635 | TPD_ERR ( "REGISTER write fail\n" ); | |
2636 | } | |
2637 | ||
2638 | return size; | |
2639 | } | |
2640 | static DEVICE_ATTR ( write, 0664, NULL, synaptics_store_write ); | |
2641 | ||
2642 | static ssize_t synaptics_store_read ( struct device *dev, struct device_attribute *attr, char *buf, size_t size ) | |
2643 | { | |
2644 | u8 temp = 0; | |
2645 | unsigned int reg = 0; | |
2646 | unsigned int page = 0; | |
2647 | int ret; | |
2648 | ||
2649 | sscanf ( buf, "%d %x", &page, ® ); | |
2650 | ||
2651 | ret = synaptics_page_data_read ( tpd_i2c_client, page, (u8)reg, 1, &temp ); | |
2652 | if ( ret < 0 ) | |
2653 | { | |
2654 | TPD_ERR ( "REGISTER read fail\n" ); | |
2655 | } | |
2656 | ||
2657 | TPD_LOG ( "(read) page=%d, reg=0x%x, value=0x%x\n", page, reg, temp ); | |
2658 | ||
2659 | return size; | |
2660 | } | |
2661 | static DEVICE_ATTR ( read, 0664, NULL, synaptics_store_read ); | |
2662 | ||
2663 | /**************************************************************************** | |
2664 | * Synaptics_Touch_IC Initialize Function | |
2665 | ****************************************************************************/ | |
2666 | static void read_page_description_table ( struct i2c_client *client ) | |
2667 | { | |
2668 | TPD_FUN (); | |
2669 | int ret = 0; | |
2670 | function_descriptor buffer; | |
2671 | u8 page_num; | |
2672 | u16 u_address; | |
2673 | ||
2674 | memset(&buffer, 0x0, sizeof(function_descriptor)); | |
2675 | ||
2676 | for ( page_num = 0 ; page_num < PAGE_MAX_NUM ; page_num++ ) | |
2677 | { | |
2678 | ret = synaptics_ts_write ( client, PAGE_SELECT_REG, &page_num, 1 ); | |
2679 | if ( ret < 0 ) | |
2680 | { | |
2681 | TPD_ERR ( "PAGE_SELECT_REG write fail (page_num=%d)\n", page_num ); | |
2682 | } | |
2683 | ||
2684 | for ( u_address = DESCRIPTION_TABLE_START ; u_address > 10 ; u_address -= sizeof(function_descriptor) ) | |
2685 | { | |
2686 | ret = synaptics_ts_read ( client, u_address, sizeof(buffer), (u8 *) &buffer ); | |
2687 | if ( ret < 0 ) | |
2688 | { | |
2689 | TPD_ERR ( "function_descriptor read fail\n" ); | |
2690 | return; | |
2691 | } | |
2692 | ||
2693 | TPD_LOG ("buffer.function_exist=%x, page_num=%d\n",buffer.function_exist,page_num); | |
2694 | if ( buffer.function_exist == 0 ) | |
2695 | break; | |
2696 | ||
2697 | switch ( buffer.function_exist ) | |
2698 | { | |
2699 | case RMI_DEVICE_CONTROL: | |
2700 | device_control = buffer; | |
2701 | device_control_page = page_num; | |
2702 | break; | |
2703 | case TOUCHPAD_SENSORS: | |
2704 | finger = buffer; | |
2705 | finger_page = page_num; | |
2706 | break; | |
2707 | case CAPACITIVE_BUTTON_SENSORS: | |
2708 | button = buffer; | |
2709 | button_page = page_num; | |
2710 | break; | |
2711 | case FLASH_MEMORY_MANAGEMENT: | |
2712 | flash_memory = buffer; | |
2713 | flash_memory_page = page_num; | |
2714 | break; | |
2715 | case MULTI_TAP_GESTURE: | |
2716 | multi_tap = buffer; | |
2717 | multi_tap_page = page_num; | |
2718 | break; | |
2719 | } | |
2720 | } | |
2721 | } | |
2722 | ||
2723 | ret = synaptics_ts_write ( client, PAGE_SELECT_REG, &device_control_page, 1 ); | |
2724 | if ( ret < 0 ) | |
2725 | { | |
2726 | TPD_ERR ( "PAGE_SELECT_REG write fail\n" ); | |
2727 | } | |
2728 | } | |
2729 | ||
2730 | #if defined(LGE_USE_SYNAPTICS_FW_UPGRADE) | |
2731 | static int synaptics_firmware_check ( struct i2c_client *client ) | |
2732 | { | |
2733 | TPD_FUN (); | |
2734 | int ret; | |
2735 | u8 device_status = 0; | |
2736 | u8 flash_control = 0; | |
2737 | u8 fw_ver, image_ver; | |
2738 | char fw_config_id[5] = {0}; | |
2739 | char fw_product_id[11] = {0}; | |
2740 | char image_config_id[5] = {0}; | |
2741 | char image_product_id[11] = {0}; | |
2742 | ||
2743 | /* read Firmware information in Download Image */ | |
2744 | fw_start = (unsigned char *) &SynaFirmware[0]; | |
2745 | fw_size = sizeof(SynaFirmware); | |
2746 | strncpy ( image_product_id, &SynaFirmware[0x0040], 6 ); | |
2747 | strncpy ( image_config_id, &SynaFirmware[0xb100], 4 ); | |
2748 | ||
2749 | if ( fw_path[0] != 0 ) | |
2750 | { | |
2751 | TPD_LOG ( "Firmware force update by fw file\n" ); | |
2752 | return -1; | |
2753 | } | |
2754 | else if ( fw_force_update == 1 ) | |
2755 | { | |
2756 | TPD_LOG ( "Firmware force update by buffer 1 [%02x%02x%02x%02x Ver]\n", image_config_id[0], image_config_id[1], image_config_id[2], image_config_id[3] ); | |
2757 | return -1; | |
2758 | } | |
2759 | ||
2760 | ret = synaptics_ts_read ( client, DEVICE_STATUS_REG, 1, &device_status ); | |
2761 | if ( ret < 0 ) | |
2762 | { | |
2763 | TPD_ERR ( "DEVICE_STATUS_REG read fail\n" ); | |
2764 | } | |
2765 | ret = synaptics_ts_read ( client, FLASH_CONTROL_REG, 1, &flash_control ); | |
2766 | if ( ret < 0 ) | |
2767 | { | |
2768 | TPD_ERR ( "FLASH_CONTROL_REG read fail\n" ); | |
2769 | } | |
2770 | ||
2771 | if ( ( device_status & FLASH_PROG_MASK ) || ( device_status & FW_CRC_FAILURE_MASK ) != 0 || ( flash_control & FLASH_STATUS_MASK ) != 0 ) | |
2772 | { | |
2773 | TPD_ERR ( "Firmware has a problem. [device_status=%x, flash_control=%x]\nso it needs Firmware update. [%02x%02x%02x%02x Ver]\n", device_status, flash_control, image_config_id[0], image_config_id[1], image_config_id[2], image_config_id[3] ); | |
2774 | return -1; | |
2775 | } | |
2776 | else | |
2777 | { | |
2778 | /* read Firmware information in Touch IC */ | |
2779 | ret = synaptics_ts_read ( client, PRODUCT_ID_REG, 10, &fw_product_id[0] ); | |
2780 | if ( ret < 0 ) | |
2781 | { | |
2782 | TPD_ERR ( "PRODUCT_ID_REG read fail\n" ); | |
2783 | } | |
2784 | else | |
2785 | { | |
2786 | TPD_LOG ( "PRODUCT_ID_REG : %s \n", fw_product_id ); | |
2787 | } | |
2788 | ||
2789 | ret = synaptics_ts_read ( client, FLASH_CONFIG_ID_REG, 4, &fw_config_id[0] ); | |
2790 | if ( ret < 0 ) | |
2791 | { | |
2792 | TPD_ERR ( "FLASH_CONFIG_ID_REG read fail\n" ); | |
2793 | } | |
2794 | else | |
2795 | { | |
2796 | TPD_LOG ( "FLASH_CONFIG_ID_REG : %02x%02x%02x%02x \n", fw_config_id[0], fw_config_id[1], fw_config_id[2], fw_config_id[3] ); | |
2797 | } | |
2798 | #ifdef WXSERIES_FW | |
2799 | fw_ver = fw_config_id[3] & 0x7F; | |
2800 | image_ver = image_config_id[3] & 0x7F; | |
2801 | #else | |
2802 | fw_ver = ( int ) simple_strtol ( &fw_config_id[3], NULL, 10 ); | |
2803 | image_ver = ( int ) simple_strtol ( &image_config_id[3], NULL, 10 ); | |
2804 | #endif | |
2805 | TPD_LOG("fw_ver : 0x%02x, image_ver : 0x%02x\n", fw_ver , image_ver); | |
2806 | ||
2807 | #if 0 | |
2808 | if ( ( !strcmp ( fw_product_id, image_product_id ) ) && ( image_ver != fw_ver ) ) | |
2809 | #else | |
2810 | if ( ( image_ver != fw_ver ) ) //temp | |
2811 | #endif | |
2812 | { | |
2813 | TPD_LOG ( "[%02x ver ==> %02x ver] Firmware Update\n", fw_ver, image_ver ); | |
2814 | return -1; | |
2815 | } | |
2816 | else | |
2817 | { | |
2818 | TPD_LOG ( "No need to update Firmware\n" ); | |
2819 | return 0; | |
2820 | } | |
2821 | } | |
2822 | } | |
2823 | #ifdef WORKQUEUE_FW | |
2824 | static int synaptics_firmware_update ( struct work_struct *work_fw_upgrade ) | |
2825 | #else | |
2826 | static int synaptics_firmware_update ( struct i2c_client *client ) | |
2827 | #endif | |
2828 | { | |
2829 | TPD_FUN (); | |
2830 | ||
2831 | int ret; | |
2832 | #ifdef WORKQUEUE_FW | |
2833 | struct i2c_client *client; | |
2834 | ||
2835 | if ( tpd_i2c_client != NULL ) | |
2836 | client = tpd_i2c_client; | |
2837 | else | |
2838 | return 0; | |
2839 | #endif | |
2840 | ret = synaptics_firmware_check ( client ); | |
2841 | #if 1//Temp | |
2842 | if ( ret != 0 ) | |
2843 | { | |
2844 | if ( !download_status ) | |
2845 | { | |
2846 | download_status = 1; | |
2847 | wake_lock ( &fw_suspend_lock ); | |
2848 | ||
2849 | mt_eint_mask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
2850 | ||
2851 | if ( !knock_on_enable && suspend_status ) | |
2852 | { | |
2853 | if ( ! Power_status ) | |
2854 | synaptics_power ( 1 ); | |
2855 | } | |
2856 | ||
2857 | mtk_wdt_enable ( WK_WDT_DIS ); | |
2858 | TPD_LOG ( "Watchdog disable\n" ); | |
2859 | ||
2860 | ret = FirmwareUpgrade ( client, fw_path, fw_size, fw_start ); | |
2861 | if ( ret < 0 ) | |
2862 | { | |
2863 | TPD_ERR ( "Firmware update Fail!!!\n" ); | |
2864 | } | |
2865 | else | |
2866 | { | |
2867 | TPD_ERR ( "Firmware upgrade Complete\n" ); | |
2868 | } | |
2869 | ||
2870 | mtk_wdt_enable ( WK_WDT_EN ); | |
2871 | TPD_LOG ( "Watchdog enable\n" ); | |
2872 | mt_eint_unmask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
2873 | ||
2874 | memset(fw_path, 0x00, sizeof(fw_path)); | |
2875 | fw_force_update = 0; | |
2876 | ||
2877 | if ( !knock_on_enable && suspend_status ) | |
2878 | { | |
2879 | synaptics_power ( 0 ); | |
2880 | } | |
2881 | else | |
2882 | { | |
2883 | synaptics_ic_reset (); | |
2884 | } | |
2885 | ||
2886 | wake_unlock ( &fw_suspend_lock ); | |
2887 | download_status = 0; | |
2888 | } | |
2889 | else | |
2890 | { | |
2891 | TPD_ERR ( "Firmware Upgrade process is aready working on\n" ); | |
2892 | } | |
2893 | ||
2894 | read_page_description_table ( client ); | |
2895 | } | |
2896 | #endif | |
2897 | #ifdef WORKQUEUE_FW | |
2898 | synaptics_initialize( client ); | |
2899 | #endif | |
2900 | } | |
2901 | #endif | |
2902 | ||
2903 | void synaptics_initialize ( struct i2c_client *client ) | |
2904 | { | |
2905 | TPD_FUN (); | |
2906 | int ret; | |
2907 | u8 temp = 0; | |
2908 | ||
2909 | ret = synaptics_ts_read ( client, DEVICE_CONTROL_REG, 1, &temp ); | |
2910 | if ( ret < 0 ) | |
2911 | { | |
2912 | TPD_ERR ( "DEVICE_CONTROL_REG read fail\n" ); | |
2913 | } | |
2914 | ||
2915 | // temp = NOSLEEP_MASK | CONFIGURED_MASK; | |
2916 | temp = temp | CONFIGURED_MASK; | |
2917 | ret = synaptics_ts_write ( client, DEVICE_CONTROL_REG, &temp, 1 ); | |
2918 | if ( ret < 0 ) | |
2919 | { | |
2920 | TPD_ERR ( "DEVICE_CONTROL_REG write fail\n" ); | |
2921 | } | |
2922 | ||
2923 | if ( button.function_exist != 0 ) | |
2924 | { | |
2925 | button_enable_mask = BUTTON_MASK; | |
2926 | } | |
2927 | ||
2928 | temp = 0x7F; | |
2929 | ret = synaptics_ts_write ( client, INTERRUPT_ENABLE_REG, &temp, 1 ); | |
2930 | if (ret < 0) | |
2931 | { | |
2932 | TPD_ERR ( "INTERRUPT_ENABLE_REG write fail\n" ); | |
2933 | } | |
2934 | ||
2935 | temp = REDUCED_REPORTING_MODE_MASK | ABS_POS_FILTER_MASK | REPORT_BEYOND_CLIP_MASK; | |
2936 | ret = synaptics_ts_write ( client, TWO_D_REPORT_MODE_REG, &temp, 1 ); | |
2937 | if (ret < 0) | |
2938 | { | |
2939 | TPD_ERR ( "TWO_D_REPORT_MODE_REG write fail\n" ); | |
2940 | } | |
2941 | ||
2942 | temp = (u8) DELTA_POS_THRESHOLD; | |
2943 | ret = synaptics_ts_write ( client, TWO_D_DELTA_X_THRESH_REG, &temp, 1 ); | |
2944 | if (ret < 0) | |
2945 | { | |
2946 | TPD_ERR ( "TWO_D_DELTA_X_THRESH_REG write fail\n" ); | |
2947 | } | |
2948 | ||
2949 | temp = (u8) DELTA_POS_THRESHOLD; | |
2950 | ret = synaptics_ts_write ( client, TWO_D_DELTA_Y_THRESH_REG, &temp, 1 ); | |
2951 | if (ret < 0) | |
2952 | { | |
2953 | TPD_ERR ( "TWO_D_DELTA_Y_THRESH_REG write fail\n" ); | |
2954 | } | |
2955 | ||
2956 | ret = synaptics_ts_read ( client, INTERRUPT_STATUS_REG, 1, &temp ); | |
2957 | if ( ret < 0 ) | |
2958 | { | |
2959 | TPD_ERR ( "INTERRUPT_STATUS_REG read fail\n" ); | |
2960 | } | |
2961 | TPD_LOG ( "INTERRUPT_STATUS_REG value = %d\n", temp ); | |
2962 | ||
2963 | ||
2964 | if ( !knock_on_enable ) | |
2965 | synaptics_knock_tap_control ( 0 ); | |
2966 | double_tap_enable = 0; | |
2967 | multi_tap_enable = 0; | |
2968 | ||
2969 | if ( use_ghost_detection ) | |
2970 | { | |
2971 | synaptics_ic_ctrl ( client, IC_CTRL_REPORT_MODE, REDUCED_REPORTING_MODE_MASK ); | |
2972 | force_continuous_mode = 1; | |
2973 | ghost_detection = 0; | |
2974 | ghost_detection_count = 0; | |
2975 | do_gettimeofday ( &t_ex_debug[TIME_EX_INIT_TIME] ); | |
2976 | } | |
2977 | } | |
2978 | ||
2979 | void synaptics_init_sysfs ( void ) | |
2980 | { | |
2981 | TPD_FUN (); | |
2982 | int err; | |
2983 | ||
2984 | touch_class = class_create(THIS_MODULE, "touch"); | |
2985 | ||
2986 | #if defined(LGE_USE_SYNAPTICS_F54) | |
2987 | touch_debug_dev = device_create ( touch_class, NULL, 0, NULL, "debug" ); | |
2988 | err = device_create_file ( touch_debug_dev, &dev_attr_f54 ); | |
2989 | if ( err ) | |
2990 | { | |
2991 | TPD_ERR ( "Touchscreen : [f54] touch device_create_file Fail\n" ); | |
2992 | device_remove_file ( touch_debug_dev, &dev_attr_f54 ); | |
2993 | } | |
2994 | #endif | |
2995 | ||
2996 | #if defined(LGE_USE_SYNAPTICS_FW_UPGRADE) | |
2997 | touch_fw_dev = device_create ( touch_class, NULL, 0, NULL, "firmware" ); | |
2998 | err = device_create_file ( touch_fw_dev, &dev_attr_firmware ); | |
2999 | if ( err ) | |
3000 | { | |
3001 | TPD_ERR ( "Touchscreen : [firmware] touch device_create_file Fail\n" ); | |
3002 | device_remove_file ( touch_fw_dev, &dev_attr_firmware ); | |
3003 | } | |
3004 | ||
3005 | err = device_create_file ( touch_fw_dev, &dev_attr_version ); | |
3006 | if ( err ) | |
3007 | { | |
3008 | TPD_ERR ( "Touchscreen : [version] touch device_create_file Fail\n" ); | |
3009 | device_remove_file ( touch_fw_dev, &dev_attr_version ); | |
3010 | } | |
3011 | #endif | |
3012 | ||
3013 | err = device_create_file ( touch_fw_dev, &dev_attr_write ); | |
3014 | if ( err ) | |
3015 | { | |
3016 | TPD_ERR ( "Touchscreen : [write] touch device_create_file Fail\n" ); | |
3017 | device_remove_file ( touch_fw_dev, &dev_attr_write ); | |
3018 | } | |
3019 | ||
3020 | err = device_create_file ( touch_fw_dev, &dev_attr_read ); | |
3021 | if ( err ) | |
3022 | { | |
3023 | TPD_ERR ( "Touchscreen : [read] touch device_create_file Fail\n" ); | |
3024 | device_remove_file ( touch_fw_dev, &dev_attr_read ); | |
3025 | } | |
3026 | ||
3027 | sysfs_create_group(tpd->dev->dev.kobj.parent , &lge_touch_group); | |
3028 | } | |
3029 | EXPORT_SYMBOL ( synaptics_init_sysfs ); | |
3030 | ||
3031 | #define to_foo_obj(x) container_of(x, struct foo_obj, kobj) | |
3032 | struct foo_attribute { | |
3033 | struct attribute attr; | |
3034 | ssize_t (*show)(struct foo_obj *foo, struct foo_attribute *attr, char *buf); | |
3035 | ssize_t (*store)(struct foo_obj *foo, struct foo_attribute *attr, const char *buf, size_t count); | |
3036 | }; | |
3037 | #define to_foo_attr(x) container_of(x, struct foo_attribute, attr) | |
3038 | static ssize_t foo_attr_show(struct kobject *kobj, | |
3039 | struct attribute *attr, | |
3040 | char *buf){ | |
3041 | struct foo_attribute *attribute; | |
3042 | struct foo_obj *foo; | |
3043 | ||
3044 | attribute = to_foo_attr(attr); | |
3045 | foo = to_foo_obj(kobj); | |
3046 | ||
3047 | if (!attribute->show) | |
3048 | return -EIO; | |
3049 | ||
3050 | return attribute->show(foo, attribute, buf); | |
3051 | } | |
3052 | static ssize_t foo_attr_store(struct kobject *kobj, | |
3053 | struct attribute *attr, | |
3054 | const char *buf, size_t len) | |
3055 | { | |
3056 | struct foo_attribute *attribute; | |
3057 | struct foo_obj *foo; | |
3058 | ||
3059 | attribute = to_foo_attr(attr); | |
3060 | foo = to_foo_obj(kobj); | |
3061 | ||
3062 | if (!attribute->store) | |
3063 | return -EIO; | |
3064 | ||
3065 | return attribute->store(foo, attribute, buf, len); | |
3066 | } | |
3067 | static const struct sysfs_ops foo_sysfs_ops = { | |
3068 | .show = foo_attr_show, | |
3069 | .store = foo_attr_store, | |
3070 | }; | |
3071 | static void foo_release(struct kobject *kobj) | |
3072 | { | |
3073 | struct foo_obj *foo; | |
3074 | ||
3075 | foo = to_foo_obj(kobj); | |
3076 | kfree(foo); | |
3077 | } | |
3078 | ||
3079 | static ssize_t foo_show(struct foo_obj *foo_obj, struct foo_attribute *attr, | |
3080 | char *buf) | |
3081 | { | |
3082 | return sprintf(buf, "%d\n", foo_obj->interrupt); | |
3083 | } | |
3084 | static ssize_t foo_store(struct foo_obj *foo_obj, struct foo_attribute *attr, | |
3085 | const char *buf, size_t count) | |
3086 | { | |
3087 | sscanf(buf, "%du", &foo_obj->interrupt); | |
3088 | return count; | |
3089 | } | |
3090 | static struct foo_attribute foo_attribute =__ATTR(interrupt, 0664, foo_show, foo_store); | |
3091 | static struct attribute *foo_default_attrs[] = { | |
3092 | &foo_attribute.attr, | |
3093 | NULL, /* need to NULL terminate the list of attributes */ | |
3094 | }; | |
3095 | static struct kobj_type foo_ktype = { | |
3096 | .sysfs_ops = &foo_sysfs_ops, | |
3097 | .release = foo_release, | |
3098 | .default_attrs = foo_default_attrs, | |
3099 | }; | |
3100 | static struct kset *example_kset; | |
3101 | ||
3102 | static struct foo_obj *create_foo_obj(const char *name){ | |
3103 | struct foo_obj *foo; | |
3104 | int retval; | |
3105 | foo = kzalloc(sizeof(*foo), GFP_KERNEL); | |
3106 | if (!foo) | |
3107 | return NULL; | |
3108 | foo->kobj.kset = example_kset; | |
3109 | retval = kobject_init_and_add(&foo->kobj, &foo_ktype, NULL, "%s", name); | |
3110 | if (retval) { | |
3111 | kobject_put(&foo->kobj); | |
3112 | return NULL; | |
3113 | } | |
3114 | kobject_uevent(&foo->kobj, KOBJ_ADD); | |
3115 | return foo; | |
3116 | } | |
3117 | ||
3118 | ||
3119 | /**************************************************************************** | |
3120 | * I2C BUS Related Functions | |
3121 | ****************************************************************************/ | |
3122 | static int synaptics_i2c_probe ( struct i2c_client *client, const struct i2c_device_id *id ) | |
3123 | { | |
3124 | TPD_FUN (); | |
3125 | int i, err = 0, ret = 0; | |
3126 | char temp[5] = {0}; | |
3127 | struct task_struct *thread = NULL; | |
3128 | struct foo_obj *foo; | |
3129 | ||
3130 | /* i2c_check_functionality */ | |
3131 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { | |
3132 | TPD_ERR("i2c functionality check error\n"); | |
3133 | ret = -ENODEV; | |
3134 | goto err_check_functionality_failed; | |
3135 | } | |
3136 | ||
3137 | /* delay time configuration */ | |
3138 | delay_time.booting = 200; | |
3139 | delay_time.reset = 5; | |
3140 | ||
3141 | /* the choice of ghost_detection */ | |
3142 | use_ghost_detection = 0; | |
3143 | ||
3144 | /* X, Y max touch position */ | |
3145 | x_max = DISP_GetScreenWidth (); | |
3146 | y_max = DISP_GetScreenHeight (); | |
3147 | ||
3148 | tpd_i2c_client = client; | |
3149 | #if defined(LGE_USE_SYNAPTICS_F54) | |
3150 | ds4_i2c_client = client; | |
3151 | #endif | |
3152 | ||
3153 | /* Turn on the power for TOUCH */ | |
3154 | synaptics_power ( 1 ); | |
3155 | ||
3156 | #ifdef TPD_HAVE_BUTTON | |
3157 | for ( i = 0 ; i < TPD_KEY_COUNT ; i++ ) | |
3158 | { | |
3159 | input_set_capability ( tpd->dev, EV_KEY, tpd_keys_local[i] ); | |
3160 | } | |
3161 | #endif | |
3162 | #ifdef WORKQUEUE_FW | |
3163 | INIT_WORK(&work_fw_upgrade, synaptics_firmware_update); | |
3164 | #endif | |
3165 | ||
3166 | thread = kthread_run ( synaptics_touch_event_handler, 0, TPD_DEVICE ); | |
3167 | if ( IS_ERR ( thread ) ) | |
3168 | { | |
3169 | err = PTR_ERR ( thread ); | |
3170 | TPD_ERR ( "failed to create kernel thread: %d\n", err ); | |
3171 | } | |
3172 | ||
3173 | /* Configure external ( GPIO ) interrupt */ | |
3174 | synaptics_setup_eint (); | |
3175 | ||
3176 | /* find register map */ | |
3177 | read_page_description_table ( client ); | |
3178 | ||
3179 | /* Initialize for Knock function */ | |
3180 | knock_on_type = 1; | |
3181 | example_kset = kset_create_and_add("lge", NULL, kernel_kobj); | |
3182 | foo_obj = create_foo_obj(LGE_TOUCH_NAME); | |
3183 | ||
3184 | touch_multi_tap_wq = create_singlethread_workqueue ( "touch_multi_tap_wq" ); | |
3185 | if ( touch_multi_tap_wq ) | |
3186 | { | |
3187 | INIT_WORK ( &multi_tap_work, synaptics_multi_tap_work ); | |
3188 | hrtimer_init ( &multi_tap_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL ); | |
3189 | multi_tap_timer.function = synaptics_multi_tap_timer_handler; | |
3190 | } | |
3191 | wake_lock_init ( &knock_code_lock, WAKE_LOCK_SUSPEND, "knock_code" ); | |
3192 | ||
3193 | #if defined(LGE_USE_SYNAPTICS_FW_UPGRADE) | |
3194 | wake_lock_init ( &fw_suspend_lock, WAKE_LOCK_SUSPEND, "fw_wakelock" ); | |
3195 | ||
3196 | /* Touch Firmware Update */ | |
3197 | #ifdef WORKQUEUE_FW | |
3198 | queue_work(touch_wq, &work_fw_upgrade); | |
3199 | #else | |
3200 | ||
3201 | /* Touch Firmware Update */ | |
3202 | ret = synaptics_firmware_update ( client ); | |
3203 | #endif // WORKQUEUE_FW | |
3204 | #endif | |
3205 | ||
3206 | #ifndef WORKQUEUE_FW | |
3207 | /* Touch IC initialize */ | |
3208 | synaptics_initialize ( client ); | |
3209 | ||
3210 | #endif | |
3211 | ||
3212 | tpd_load_status = 1; | |
3213 | ||
3214 | return 0; | |
3215 | ||
3216 | err_check_functionality_failed: | |
3217 | return ret; | |
3218 | } | |
3219 | ||
3220 | static int synaptics_i2c_remove(struct i2c_client *client) | |
3221 | { | |
3222 | TPD_FUN (); | |
3223 | return 0; | |
3224 | } | |
3225 | ||
3226 | static int synaptics_i2c_detect ( struct i2c_client *client, struct i2c_board_info *info ) | |
3227 | { | |
3228 | TPD_FUN (); | |
3229 | strcpy ( info->type, "mtk-tpd" ); | |
3230 | return 0; | |
3231 | } | |
3232 | ||
3233 | static const struct i2c_device_id tpd_i2c_id[] = { { TPD_DEV_NAME, 0 }, {} }; | |
3234 | ||
3235 | static struct i2c_driver tpd_i2c_driver = { | |
3236 | .driver.name = "mtk-tpd", | |
3237 | .probe = synaptics_i2c_probe, | |
3238 | .remove = synaptics_i2c_remove, | |
3239 | // .remove = __devexit_p(synaptics_i2c_remove), | |
3240 | .detect = synaptics_i2c_detect, | |
3241 | .id_table = tpd_i2c_id, | |
3242 | }; | |
3243 | ||
3244 | /**************************************************************************** | |
3245 | * Linux Device Driver Related Functions | |
3246 | ****************************************************************************/ | |
3247 | static int synaptics_local_init ( void ) | |
3248 | { | |
3249 | TPD_FUN (); | |
3250 | ||
3251 | if ( i2c_add_driver ( &tpd_i2c_driver ) != 0 ) | |
3252 | { | |
3253 | TPD_ERR ( "i2c_add_driver failed\n" ); | |
3254 | return -1; | |
3255 | } | |
3256 | ||
3257 | if ( tpd_load_status == 0 ) | |
3258 | { | |
3259 | TPD_ERR ( "touch driver probing failed\n" ); | |
3260 | i2c_del_driver ( &tpd_i2c_driver ); | |
3261 | return -1; | |
3262 | } | |
3263 | ||
3264 | tpd_type_cap = 1; | |
3265 | ||
3266 | return 0; | |
3267 | } | |
3268 | ||
3269 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
3270 | static void synaptics_suspend ( struct early_suspend *h ) | |
3271 | { | |
3272 | TPD_FUN (); | |
3273 | ||
3274 | suspend_status = 1; | |
3275 | ||
3276 | if ( use_ghost_detection ) | |
3277 | { | |
3278 | resume_flag = 0; | |
3279 | } | |
3280 | ||
3281 | synaptics_release_all_finger (); | |
3282 | ||
3283 | TPD_LOG("knock_on_enable : 0x%x, download_status : 0x%x\n", knock_on_enable, download_status); | |
3284 | ||
3285 | if ( !knock_on_enable && !download_status ) | |
3286 | { | |
3287 | mt_eint_mask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
3288 | synaptics_power ( 0 ); | |
3289 | } | |
3290 | } | |
3291 | ||
3292 | static void synaptics_resume ( struct early_suspend *h ) | |
3293 | { | |
3294 | TPD_FUN (); | |
3295 | ||
3296 | if ( use_ghost_detection ) | |
3297 | { | |
3298 | resume_flag = 1; | |
3299 | ts_rebase_count = 0; | |
3300 | } | |
3301 | ||
3302 | if ( suspend_status && !download_status ) | |
3303 | { | |
3304 | if ( !knock_on_enable ) | |
3305 | { | |
3306 | if ( ! Power_status ) | |
3307 | synaptics_power ( 1 ); | |
3308 | ||
3309 | synaptics_release_all_finger (); | |
3310 | msleep ( 10 ); | |
3311 | ||
3312 | synaptics_initialize ( tpd_i2c_client ); | |
3313 | } | |
3314 | else | |
3315 | { | |
3316 | synaptics_ic_reset (); | |
3317 | } | |
3318 | } | |
3319 | ||
3320 | if ( key_lock_status == 0 ) | |
3321 | { | |
3322 | mt_eint_unmask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
3323 | } | |
3324 | else | |
3325 | { | |
3326 | mt_eint_mask ( CUST_EINT_TOUCH_PANEL_NUM ); | |
3327 | } | |
3328 | ||
3329 | suspend_status = 0; | |
3330 | } | |
3331 | #endif | |
3332 | ||
3333 | static struct i2c_board_info __initdata i2c_tpd = { I2C_BOARD_INFO ( TPD_DEV_NAME, TPD_I2C_ADDRESS ) }; | |
3334 | ||
3335 | static struct tpd_driver_t tpd_device_driver = { | |
3336 | .tpd_device_name = TPD_DEV_NAME, | |
3337 | .tpd_local_init = synaptics_local_init, | |
3338 | #ifdef CONFIG_HAS_EARLYSUSPEND | |
3339 | .suspend = synaptics_suspend, | |
3340 | .resume = synaptics_resume, | |
3341 | #endif | |
3342 | #ifdef TPD_HAVE_BUTTON | |
3343 | .tpd_have_button = 1, | |
3344 | #else | |
3345 | .tpd_have_button = 0, | |
3346 | #endif | |
3347 | }; | |
3348 | ||
3349 | static int __init synaptics_driver_init ( void ) | |
3350 | { | |
3351 | TPD_FUN (); | |
3352 | int ret; | |
3353 | ||
3354 | I2CDMABuf_va = (u8 *) dma_alloc_coherent ( NULL, 4096, &I2CDMABuf_pa, GFP_KERNEL ); | |
3355 | if ( !I2CDMABuf_va ) | |
3356 | { | |
3357 | TPD_ERR ( "Allocate Touch DMA I2C Buffer failed!\n" ); | |
3358 | return ENOMEM; | |
3359 | } | |
3360 | #ifdef WORKQUEUE_FW | |
3361 | touch_wq = create_singlethread_workqueue("touch_wq"); | |
3362 | if (!touch_wq) { | |
3363 | TPD_ERR("CANNOT create new workqueue\n"); | |
3364 | ret = -ENOMEM; | |
3365 | goto err_work_queue; | |
3366 | } | |
3367 | #endif | |
3368 | i2c_register_board_info ( 0, &i2c_tpd, 1 ); | |
3369 | if ( tpd_driver_add ( &tpd_device_driver ) < 0 ) | |
3370 | { | |
3371 | TPD_ERR ( "tpd_driver_add failed\n" ); | |
3372 | } | |
3373 | ||
3374 | return 0; | |
3375 | ||
3376 | err_work_queue: | |
3377 | return ret; | |
3378 | } | |
3379 | ||
3380 | static void __exit synaptics_driver_exit ( void ) | |
3381 | { | |
3382 | TPD_FUN (); | |
3383 | ||
3384 | tpd_driver_remove ( &tpd_device_driver ); | |
3385 | ||
3386 | if ( I2CDMABuf_va ) | |
3387 | { | |
3388 | dma_free_coherent ( NULL, 4096, I2CDMABuf_va, I2CDMABuf_pa ); | |
3389 | I2CDMABuf_va = NULL; | |
3390 | I2CDMABuf_pa = 0; | |
3391 | } | |
3392 | if ( touch_multi_tap_wq ) | |
3393 | { | |
3394 | destroy_workqueue ( touch_multi_tap_wq ); | |
3395 | } | |
3396 | } | |
3397 | ||
3398 | ||
3399 | module_init ( synaptics_driver_init ); | |
3400 | module_exit ( synaptics_driver_exit ); | |
3401 | ||
3402 | MODULE_DESCRIPTION ( "Synaptics 2200 Touchscreen Driver for MTK platform" ); | |
3403 | MODULE_AUTHOR ( "Junmo Kang <junmo.kang@lge.com>" ); | |
3404 | MODULE_LICENSE ( "GPL" ); | |
3405 | ||
3406 | /* End Of File */ |