tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / input / touchscreen / ist30xxa / ist30xx.c
1 /*
2  *  Copyright (C) 2010,Imagis Technology Co. Ltd. All Rights Reserved.
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/version.h>
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/input.h>
20 #include <linux/interrupt.h>
21 #include <linux/i2c.h>
22 #include <linux/delay.h>
23 #include <linux/slab.h>
24
25 #include <linux/platform_device.h>
26 #include <linux/device.h>
27 #include <linux/mutex.h>
28 #include <mach/gpio.h>
29 #include <linux/input/mt.h>
30
31 #include "ist30xx.h"
32 #include "ist30xx_update.h"
33 #include "ist30xx_tracking.h"
34
35 #ifdef CONFIG_OF
36 #include <linux/of_gpio.h>
37 #include <linux/of_device.h>
38 #endif
39
40 #if IST30XX_DEBUG
41 #include "ist30xx_misc.h"
42 #endif
43 #if IST30XX_CMCS_TEST
44 #include "ist30xx_cmcs.h"
45 #endif
46 #if SEC_FACTORY_MODE
47 #include "ist30xx_sec.h"
48 extern int sec_touch_sysfs(struct ist30xx_data *data);
49 extern int sec_fac_cmd_init(struct ist30xx_data *data);
50 #endif
51
52 #define MAX_ERR_CNT             (100)
53
54 #if IST30XX_USE_KEY
55 int ist30xx_key_code[] = { 0, KEY_MENU, KEY_BACK };
56 #endif
57
58 DEFINE_MUTEX(ist30xx_mutex);
59
60 volatile bool ist30xx_irq_working = false;
61 static bool ist30xx_initialized = 0;
62 struct ist30xx_data *ts_data;
63 static struct delayed_work work_reset_check;
64 #if IST30XX_EVENT_MODE
65 static struct delayed_work work_noise_protect, work_debug_algorithm;
66 #endif
67
68 static int ist30xx_power_status = -1;
69 static int ist30xx_ta_status = -1;
70 static int ist30xx_noise_mode = -1;
71
72 #if IST30XX_INTERNAL_BIN && IST30XX_UPDATE_BY_WORKQUEUE
73 static struct delayed_work work_fw_update;
74 #endif
75
76 int ist30xx_report_rate = -1;
77 int ist30xx_idle_rate = -1;
78
79 u32 event_ms = 0, timer_ms = 0;
80 u32 ist30xx_scan_count = 0;
81 int ist30xx_scan_retry = 0;
82
83 #if IST30XX_EVENT_MODE
84 static struct timer_list event_timer;
85 static struct timespec t_current;               // ns
86 int timer_period_ms = 500;                      // 0.5sec
87 #define EVENT_TIMER_INTERVAL            (HZ * timer_period_ms / 1000)
88 #endif  // IST30XX_EVENT_MODE
89
90 char *ist_vdd_name = "vddsim2";
91
92 #if IST30XX_DEBUG
93 extern TSP_INFO ist30xx_tsp_info;
94 extern TKEY_INFO ist30xx_tkey_info;
95 #endif
96
97
98 int ist30xx_dbg_level = IST30XX_DEBUG_LEVEL;
99 void tsp_printk(int level, const char *fmt, ...)
100 {
101         struct va_format vaf;
102         va_list args;
103         int r;
104
105         if (ist30xx_dbg_level < level)
106                 return;
107
108         va_start(args, fmt);
109
110         vaf.fmt = fmt;
111         vaf.va = &args;
112
113         r = printk("%s %pV", IST30XX_DEBUG_TAG, &vaf);
114
115         va_end(args);
116 }
117
118 long get_milli_second(void)
119 {
120 #if IST30XX_EVENT_MODE
121         ktime_get_ts(&t_current);
122
123         return t_current.tv_sec * 1000 + t_current.tv_nsec / 1000000;
124 #else
125         return 0;
126 #endif  // IST30XX_EVENT_MODE
127 }
128
129 int ist30xx_intr_wait(long ms)
130 {
131         long start_ms = get_milli_second();
132         long curr_ms = 0;
133
134         while (1) {
135                 if (!ist30xx_irq_working)
136                         break;
137
138                 curr_ms = get_milli_second();
139                 if ((curr_ms < 0) || (start_ms < 0) || (curr_ms - start_ms > ms)) {
140                         tsp_info("%s() timeout(%dms)\n", __func__, ms);
141                         return -EPERM;
142                 }
143
144                 msleep(2);
145         }
146         return 0;
147 }
148
149 void ist30xx_disable_irq(struct ist30xx_data *data)
150 {
151         if (likely(data->irq_enabled)) {
152                 ist30xx_tracking(TRACK_INTR_DISABLE);
153                 disable_irq(data->client->irq);
154                 data->irq_enabled = 0;
155                 data->status.event_mode = false;
156         }
157 }
158
159 void ist30xx_enable_irq(struct ist30xx_data *data)
160 {
161         if (likely(!data->irq_enabled)) {
162                 ist30xx_tracking(TRACK_INTR_ENABLE);
163                 enable_irq(data->client->irq);
164                 msleep(10);
165                 data->irq_enabled = 1;
166                 data->status.event_mode = true;
167         }
168 }
169
170 int ist30xx_max_error_cnt = MAX_ERR_CNT;
171 int ist30xx_error_cnt = 0;
172 void ist30xx_scheduled_reset(void)
173 {
174         if (likely(ist30xx_initialized))
175                 schedule_delayed_work(&work_reset_check, 0);
176 }
177
178 static void ist30xx_request_reset(void)
179 {
180         ist30xx_error_cnt++;
181         if (unlikely(ist30xx_error_cnt >= ist30xx_max_error_cnt)) {
182                 tsp_info("%s()\n", __func__);
183                 ist30xx_scheduled_reset();
184                 ist30xx_error_cnt = 0;
185         }
186 }
187
188 #define NOISE_MODE_TA       (0)
189 #define NOISE_MODE_CALL     (1)
190 #define NOISE_MODE_COVER    (2)
191 #define NOISE_MODE_POWER        (8)
192 void ist30xx_start(struct ist30xx_data *data)
193 {
194         if (ist30xx_initialized) {
195 #if IST30XX_EVENT_MODE
196         ist30xx_scan_count = 0;
197         ist30xx_scan_retry = 0;
198                 mod_timer(&event_timer, get_jiffies_64() + EVENT_TIMER_INTERVAL * 2);
199 #endif
200         }
201
202         ist30xx_tracking(ist30xx_ta_status ?
203                          TRACK_CMD_TACON : TRACK_CMD_TADISCON);
204
205         ist30xx_noise_mode &= ~(1 << NOISE_MODE_TA);
206         ist30xx_noise_mode |= (ist30xx_ta_status << NOISE_MODE_TA);
207
208         ist30xx_noise_mode &= ~(1 << NOISE_MODE_POWER);
209         ist30xx_noise_mode |= (ist30xx_power_status << NOISE_MODE_POWER);
210                                  
211         ist30xx_noise_mode |= (TSP_LOCAL_CODE << 16);
212         ist30xx_write_cmd(data->client, CMD_SET_NOISE_MODE, ist30xx_noise_mode);
213
214         tsp_info("%s(), local : %d, mode : 0x%x\n", __func__,
215                  (ist30xx_noise_mode >> 16) & 0xFFFF, ist30xx_noise_mode & 0xFFFF);
216
217         if (ist30xx_report_rate >= 0) {
218                 ist30xx_write_cmd(data->client, CMD_SET_REPORT_RATE,
219                                   ist30xx_report_rate);
220                 tsp_info(" reporting rate : %dus\n", ist30xx_report_rate);
221         }
222
223         if (ist30xx_idle_rate >= 0) {
224                 ist30xx_write_cmd(data->client, CMD_SET_IDLE_TIME, ist30xx_idle_rate);
225                 tsp_info(" idle rate : %dus\n", ist30xx_idle_rate);
226         }
227
228         ist30xx_cmd_start_scan(data->client);
229 }
230
231
232 int ist30xx_get_ver_info(struct ist30xx_data *data)
233 {
234         int ret;
235
236         data->fw.prev_core_ver = data->fw.core_ver;
237         data->fw.prev_param_ver = data->fw.param_ver;
238         data->fw.core_ver = data->fw.param_ver = 0;
239
240         ret = ist30xx_read_cmd(data->client, CMD_GET_FW_VER, &data->fw.core_ver);
241         if (unlikely(ret))
242                 return ret;
243
244         ret = ist30xx_read_cmd(data->client, CMD_GET_PARAM_VER,
245                                &data->fw.param_ver);
246         if (unlikely(ret))
247                 return ret;
248
249         ret = ist30xx_read_cmd(data->client, CMD_GET_SUB_VER, &data->fw.sub_ver);
250         if (unlikely(ret))
251                 return ret;
252
253         tsp_info("IC version read core: %x, param: %x, sub: %x\n",
254                  data->fw.core_ver, data->fw.param_ver, data->fw.sub_ver);
255
256         return 0;
257 }
258
259 #if IST30XX_DEBUG
260 void ist30xx_print_info(void)
261 {
262         TSP_INFO *tsp = &ist30xx_tsp_info;
263         TKEY_INFO *tkey = &ist30xx_tkey_info;
264
265         tsp_info("*** TSP/TKEY info ***\n");
266         tsp_info("tscn finger num : %d\n", tsp->finger_num);
267         tsp_info("tscn dir swap: %d, flip x: %d, y: %d\n",
268                  tsp->dir.swap_xy, tsp->dir.flip_x, tsp->dir.flip_y);
269         tsp_info("tscn ch_num tx: %d, rx: %d\n",
270                  tsp->ch_num.tx, tsp->ch_num.rx);
271         tsp_info("tscn width: %d, height: %d\n",
272                  tsp->width, tsp->height);
273         tsp_info("tkey enable: %d, key num: %d, axis rx: %d \n",
274                  tkey->enable, tkey->key_num, tkey->axis_rx);
275         tsp_info("tkey ch_num[0] %d, [1] %d, [2] %d, [3] %d, [4] %d\n",
276                  tkey->ch_num[0], tkey->ch_num[1], tkey->ch_num[2],
277                  tkey->ch_num[3], tkey->ch_num[4]);
278 }
279 #endif
280
281 #define CALIB_MSG_MASK          (0xF0000FFF)
282 #define CALIB_MSG_VALID         (0x80000CAB)
283 #define TRACKING_INTR_VALID     (0x127EA597)
284 u32 tracking_intr_value = TRACKING_INTR_VALID;
285 int ist30xx_get_info(struct ist30xx_data *data)
286 {
287         int ret;
288         u32 calib_msg;
289         u32 ms;
290
291         mutex_lock(&ist30xx_mutex);
292         ist30xx_disable_irq(data);
293
294 #if IST30XX_INTERNAL_BIN
295 #if IST30XX_DEBUG
296 #if IST30XX_UPDATE_BY_WORKQUEUE
297         ist30xx_get_update_info(data, data->fw.buf, data->fw.buf_size);
298 #endif
299         ist30xx_get_tsp_info(data);
300         ist30xx_get_tkey_info(data);
301 #endif  // IST30XX_DEBUG
302 #else
303
304         ret = ist30xx_get_ver_info(data);
305         if (unlikely(ret))
306                 goto get_info_end;
307
308 #if IST30XX_DEBUG
309         ret = ist30xx_tsp_update_info();
310         if (unlikely(ret))
311                 goto get_info_end;
312
313         ret = ist30xx_tkey_update_info();
314         if (unlikely(ret))
315                 goto get_info_end;
316 #endif  // IST30XX_DEBUG
317 #endif  // IST30XX_INTERNAL_BIN
318
319 #if IST30XX_DEBUG
320         ist30xx_print_info();
321         data->max_fingers = ist30xx_tsp_info.finger_num;
322         data->max_keys = ist30xx_tkey_info.key_num;
323 #endif  // IST30XX_DEBUG
324
325         ret = ist30xx_read_cmd(ts_data->client, CMD_GET_CALIB_RESULT, &calib_msg);
326         if (likely(ret == 0)) {
327                 tsp_info("calib status: 0x%08x\n", calib_msg);
328                 ms = get_milli_second();
329                 ist30xx_put_track_ms(ms);
330                 ist30xx_put_track(&tracking_intr_value, 1);
331                 ist30xx_put_track(&calib_msg, 1);
332                 if ((calib_msg & CALIB_MSG_MASK) != CALIB_MSG_VALID ||
333                     CALIB_TO_STATUS(calib_msg) > 0) {
334                         ist30xx_calibrate(IST30XX_FW_UPDATE_RETRY);
335                         ist30xx_reset(false);
336                 }
337         }
338
339 #if (IST30XX_EVENT_MODE && IST30XX_CHECK_CALIB)
340         if (likely(!data->status.update)) {
341                 ret = ist30xx_cmd_check_calib(data->client);
342                 if (likely(!ret)) {
343                         data->status.calib = 1;
344                         data->status.calib_msg = 0;
345                         event_ms = (u32)get_milli_second();
346                         data->status.event_mode = true;
347                 }
348         }
349 #else
350         ist30xx_start(ts_data);
351 #endif
352
353 #if !(IST30XX_INTERNAL_BIN)
354 get_info_end:
355 #endif
356         if (likely(ret == 0))
357                 ist30xx_enable_irq(data);
358         mutex_unlock(&ist30xx_mutex);
359
360         return ret;
361 }
362
363 #define PRESS_MSG_MASK          (0x01)
364 #define MULTI_MSG_MASK          (0x02)
365 #define PRESS_MSG_KEY           (0x6)
366 #define TOUCH_DOWN_MESSAGE      ("p")
367 #define TOUCH_UP_MESSAGE        ("r")
368 #define TOUCH_MOVE_MESSAGE      (" ")
369 bool tsp_touched[IST30XX_MAX_MT_FINGERS] = { false, };
370 bool tkey_pressed[IST30XX_MAX_KEYS] = { false, };
371 void print_tsp_event(finger_info *finger)
372 {
373         int idx = finger->bit_field.id - 1;
374         bool press;
375
376         press = PRESSED_FINGER(ts_data->t_status, finger->bit_field.id);
377
378         if (press) {
379                 if (tsp_touched[idx] == false) { // touch down
380                         tsp_notc("%s%d (%d, %d)\n",
381                                  TOUCH_DOWN_MESSAGE, finger->bit_field.id,
382                                  finger->bit_field.x, finger->bit_field.y);
383                         tsp_touched[idx] = true;
384                 } else {                    // touch move
385                         tsp_debug("%s%d (%d, %d)\n",
386                                   TOUCH_MOVE_MESSAGE, finger->bit_field.id,
387                                   finger->bit_field.x, finger->bit_field.y);
388                 }
389         } else {
390                 if (tsp_touched[idx] == true) { // touch up
391                         tsp_notc("%s%d\n", TOUCH_UP_MESSAGE, finger->bit_field.id);
392                         tsp_touched[idx] = false;
393                 }
394         }
395 }
396
397 void print_tkey_event(int id)
398 {
399         int idx = id - 1;
400         bool press = PRESSED_KEY(ts_data->t_status, id);
401
402         if (press) {
403                 if (tkey_pressed[idx] == false) { // tkey down
404                         tsp_notc("k %s%d\n", TOUCH_DOWN_MESSAGE, id);
405                         tkey_pressed[idx] = true;
406                 }
407         } else {
408                 if (tkey_pressed[idx] == true) { // tkey up
409                         tsp_notc("k %s%d\n", TOUCH_UP_MESSAGE, id);
410                         tkey_pressed[idx] = false;
411                 }
412         }
413 }
414
415 static void release_finger(int id)
416 {
417         input_mt_slot(ts_data->input_dev, id - 1);
418         input_mt_report_slot_state(ts_data->input_dev, MT_TOOL_FINGER, false);
419
420         ist30xx_tracking(TRACK_POS_FINGER + id);
421         tsp_info("%s() %d\n", __func__, id);
422
423         tsp_touched[id - 1] = false;
424
425         input_sync(ts_data->input_dev);
426 }
427
428 #define CANCEL_KEY  (0xFF)
429 #define RELEASE_KEY (0)
430 static void release_key(int id, u8 key_status)
431 {
432         input_report_key(ts_data->input_dev, ist30xx_key_code[id], key_status);
433
434         ist30xx_tracking(TRACK_POS_KEY + id);
435         tsp_info("%s() key%d, status: %d\n", __func__, id, key_status);
436
437         tkey_pressed[id - 1] = false;
438
439         input_sync(ts_data->input_dev);
440 }
441
442 static void clear_input_data(struct ist30xx_data *data)
443 {
444         int id = 1;
445         u32 status;
446
447         status = PARSE_FINGER_STATUS(data->t_status);
448         while (status) {
449                 if (status & 1)
450                         release_finger(id);
451                 status >>= 1;
452                 id++;
453         }
454
455         id = 1;
456         status = PARSE_KEY_STATUS(data->t_status);
457         while (status) {
458                 if (status & 1)
459                         release_key(id, RELEASE_KEY);
460                 status >>= 1;
461                 id++;
462         }
463         data->t_status = 0;
464 }
465
466 static int check_report_fingers(struct ist30xx_data *data, int finger_counts)
467 {
468         int i;
469         finger_info *fingers = (finger_info *)data->fingers;
470
471         /* current finger info */
472         for (i = 0; i < finger_counts; i++) {
473                 if (unlikely((fingers[i].bit_field.x > IST30XX_MAX_X) ||
474                              (fingers[i].bit_field.y > IST30XX_MAX_Y))) {
475                         tsp_warn("Invalid touch data - %d: %d(%d, %d), 0x%08x\n", i,
476                                  fingers[i].bit_field.id,
477                                  fingers[i].bit_field.x,
478                                  fingers[i].bit_field.y,
479                                  fingers[i].full_field);
480
481                         fingers[i].bit_field.id = 0;
482                         ist30xx_tracking(TRACK_POS_UNKNOWN);
483                         return -EPERM;
484                 }
485         }
486
487     return 0;
488 }
489
490 static int check_valid_coord(u32 *msg, int cnt)
491 {
492         int ret = 0;
493         u8 *buf = (u8 *)msg;
494         u8 chksum1 = msg[0] >> 24;
495         u8 chksum2 = 0;
496
497         msg[0] &= 0x00FFFFFF;
498
499         cnt *= IST30XX_DATA_LEN;
500
501         while (cnt--)
502                 chksum2 += *buf++;
503
504         if (chksum1 != chksum2) {
505                 tsp_err("intr chksum: %02x, %02x\n", chksum1, chksum2);
506                 ret = -EPERM;
507         }
508
509         return (chksum1 == chksum2) ? 0 : -EPERM;
510 }
511
512 static void report_input_data(struct ist30xx_data *data, int finger_counts,
513                               int key_counts)
514 {
515         int id;
516         bool press = false;
517         finger_info *fingers = (finger_info *)data->fingers;
518         int idx = 0;
519         u32 status;
520
521         status = PARSE_FINGER_STATUS(data->t_status);
522         for (id = 0; id < IST30XX_MAX_MT_FINGERS; id++) {
523                 press = (status & (1 << id)) ? true : false;
524
525                 input_mt_slot(data->input_dev, id);
526                 input_mt_report_slot_state(data->input_dev, MT_TOOL_FINGER, press);
527
528                 fingers[idx].bit_field.id = id + 1;
529                 print_tsp_event(&fingers[idx]);
530
531                 if (press == false)
532                         continue;
533
534                 input_report_abs(data->input_dev, ABS_MT_POSITION_X,
535                                  fingers[idx].bit_field.x);
536                 input_report_abs(data->input_dev, ABS_MT_POSITION_Y,
537                                  fingers[idx].bit_field.y);
538                 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR,
539                                  fingers[idx].bit_field.area);
540                 idx++;
541         }
542
543 #if IST30XX_USE_KEY
544         status = PARSE_KEY_STATUS(data->t_status);
545         for (id = 0; id < data->max_keys; id++) {
546                 press = (status & (1 << id)) ? true : false;
547
548                 input_report_key(data->input_dev, ist30xx_key_code[id + 1], press);
549
550                 print_tkey_event(id + 1);
551         }
552 #endif  // IST30XX_USE_KEY
553
554         ist30xx_error_cnt = 0;
555         ist30xx_scan_retry = 0;
556
557         input_sync(data->input_dev);
558 }
559
560 /*
561  * CMD : CMD_GET_COORD
562  *
563  *   1st  [31:24]   [23:21]   [20:16]   [15:12]   [11:10]   [9:0]
564  *        Checksum  KeyCnt    KeyStatus FingerCnt Rsvd.     FingerStatus
565  *   2nd  [31:28]   [27:24]   [23:12]   [11:0]
566  *        ID        Area      X         Y
567  */
568 u32 intr_debug_addr, intr_debug2_addr, intr_debug3_addr = 0;
569 u32 intr_debug_size, intr_debug2_size, intr_debug3_size = 0;
570 static irqreturn_t ist30xx_irq_thread(int irq, void *ptr)
571 {
572         int i, ret;
573         int key_cnt, finger_cnt, read_cnt;
574         struct ist30xx_data *data = ts_data;
575         int offset = 1;
576         u32 msg[IST30XX_MAX_MT_FINGERS + offset];
577         u32 ms;
578
579         ist30xx_irq_working = true;
580
581         if (unlikely(!data->irq_enabled))
582                 goto irq_end;
583
584         ms = get_milli_second();
585
586         memset(msg, 0, sizeof(msg));
587
588         ret = ist30xx_get_position(data->client, msg, 1);
589         if (unlikely(ret))
590                 goto irq_err;
591
592         tsp_verb("intr msg: 0x%08x\n", *msg);
593
594         if (unlikely(*msg == 0xE11CE970))     // TSP IC Exception
595                 goto irq_ic_err;
596
597         if (unlikely(*msg == 0 || *msg == 0xFFFFFFFF))  // Unknown CMD
598                 goto irq_err;
599
600         event_ms = ms;
601         ist30xx_put_track_ms(event_ms);
602         ist30xx_put_track(&tracking_intr_value, 1);
603         ist30xx_put_track(msg, 1);
604
605         if (unlikely((*msg & CALIB_MSG_MASK) == CALIB_MSG_VALID)) {
606                 data->status.calib_msg = *msg;
607                 tsp_info("calib status: 0x%08x\n", data->status.calib_msg);
608
609                 goto irq_end;
610 #if IST30XX_CHKIC
611         } else if (*msg == IST30XX_CHKIC_END) {
612                 data->status.chkic_msg = *msg;
613                 tsp_info("IC check status: 0x%08x\n", data->status.chkic_msg);
614
615                 goto irq_end;
616 #endif
617         }
618
619 #if IST30XX_ENABLE_GESTURE
620         ret = PARSE_GESTURE_MESSAGE(*msg);
621         if (unlikely(ret > 0)) {
622                 tsp_info("Gesture ID: %d (0x%08x)\n", ret, *msg);
623                 ist30xx_gesture_cmd(data, ret);
624
625                 goto irq_end;
626         }
627 #endif
628
629         memset(data->fingers, 0, sizeof(data->fingers));
630
631         /* Unknown interrupt data for extend coordinate */
632         if (unlikely(!CHECK_INTR_STATUS(*msg)))
633                 goto irq_err;
634
635         data->t_status = *msg;
636         key_cnt = PARSE_KEY_CNT(data->t_status);
637         finger_cnt = PARSE_FINGER_CNT(data->t_status);
638         read_cnt = finger_cnt;
639
640         if (unlikely((finger_cnt > data->max_fingers) ||
641                      (key_cnt > data->max_keys))) {
642                 tsp_warn("Invalid touch count - finger: %d(%d), key: %d(%d)\n",
643                          finger_cnt, data->max_fingers, key_cnt, data->max_keys);
644                 goto irq_err;
645         }
646
647         if (read_cnt > 0) {
648 #if I2C_BURST_MODE
649                 ret = ist30xx_get_position(data->client, &msg[offset], read_cnt);
650                 if (unlikely(ret))
651                         goto irq_err;
652
653                 for (i = 0; i < read_cnt; i++)
654                         data->fingers[i].full_field = msg[i + offset];
655 #else
656                 for (i = 0; i < read_cnt; i++) {
657                         ret = ist30xx_get_position(data->client, &msg[i + offset], 1);
658                         if (unlikely(ret))
659                                 goto irq_err;
660
661                         data->fingers[i].full_field = msg[i + offset];
662                 }
663 #endif          // I2C_BURST_MODE
664
665                 ist30xx_put_track(msg + offset, read_cnt);
666                 for (i = 0; i < read_cnt; i++)
667                         tsp_verb("intr msg(%d): 0x%08x\n", i + offset, msg[i + offset]);
668         }
669
670         ret = check_valid_coord(&msg[0], read_cnt + 1);
671         if (unlikely(ret < 0))
672                 goto irq_err;
673
674         if (unlikely(check_report_fingers(data, finger_cnt)))
675                 goto irq_end;
676
677         report_input_data(data, finger_cnt, key_cnt);
678
679     if (intr_debug2_addr > 0 && intr_debug2_size > 0) {
680         tsp_notc("Intr_debug2 (addr: 0x%08x)\n", intr_debug2_addr);
681                 for (i = 0; i < intr_debug2_size; i++) {
682             ist30xx_read_buf(data->client, 
683                 intr_debug2_addr + IST30XX_DATA_LEN * i, &msg[i], 1);
684
685             tsp_notc("\t%08x\n", msg[i]);
686         }
687         ist30xx_put_track(msg, intr_debug2_size);
688         }
689
690     if (intr_debug3_addr > 0 && intr_debug3_size > 0) {
691         tsp_notc("Intr_debug3 (addr: 0x%08x)\n", intr_debug3_addr);
692                 for (i = 0; i < intr_debug3_size; i++) {
693             ist30xx_read_buf(data->client, 
694                 intr_debug3_addr + IST30XX_DATA_LEN * i, &msg[i], 1);
695
696             tsp_notc("\t%08x\n", msg[i]);
697         }
698         ist30xx_put_track(msg, intr_debug3_size);
699         }
700
701         goto irq_end;
702
703 irq_err:
704         tsp_err("intr msg: 0x%08x, ret: %d\n", msg[0], ret);
705         ist30xx_request_reset();
706 irq_end:
707         ist30xx_irq_working = false;
708         event_ms = (u32)get_milli_second();
709         return IRQ_HANDLED;
710
711 irq_ic_err:
712         tsp_err("Occured IC exception\n");
713         ist30xx_scheduled_reset();
714         ist30xx_irq_working = false;
715         event_ms = (u32)get_milli_second();
716         return IRQ_HANDLED;
717 }
718
719 #ifdef CONFIG_HAS_EARLYSUSPEND
720 #define ist30xx_suspend NULL
721 #define ist30xx_resume  NULL
722 static void ist30xx_early_suspend(struct early_suspend *h)
723 {
724         struct ist30xx_data *data = container_of(h, struct ist30xx_data,
725                                                  early_suspend);
726
727         mutex_lock(&ist30xx_mutex);
728         ist30xx_disable_irq(data);
729         del_timer(&event_timer);
730         cancel_delayed_work_sync(&work_noise_protect);
731         cancel_delayed_work_sync(&work_reset_check);
732         cancel_delayed_work_sync(&work_debug_algorithm);
733         ist30xx_internal_suspend(data);
734         clear_input_data(data);
735         mutex_unlock(&ist30xx_mutex);
736 }
737 static void ist30xx_late_resume(struct early_suspend *h)
738 {
739         struct ist30xx_data *data = container_of(h, struct ist30xx_data,
740                                                  early_suspend);
741
742     ist30xx_power_status = 1;
743
744         mutex_lock(&ist30xx_mutex);
745         ist30xx_internal_resume(data);
746         ist30xx_start(data);
747         ist30xx_enable_irq(data);
748         mutex_unlock(&ist30xx_mutex);
749 }
750 #else
751 static int ist30xx_suspend(struct device *dev)
752 {
753         struct i2c_client *client = to_i2c_client(dev);
754         struct ist30xx_data *data = i2c_get_clientdata(client);
755
756         mutex_lock(&ist30xx_mutex);
757         ist30xx_disable_irq(data);
758         del_timer(&event_timer);
759         cancel_delayed_work_sync(&work_noise_protect);
760         cancel_delayed_work_sync(&work_reset_check);
761         cancel_delayed_work_sync(&work_debug_algorithm);
762         ist30xx_internal_suspend(data);
763         clear_input_data(data);
764         mutex_unlock(&ist30xx_mutex);
765
766         return 0;
767 }
768 static int ist30xx_resume(struct device *dev)
769 {
770         struct i2c_client *client = to_i2c_client(dev);
771         struct ist30xx_data *data = i2c_get_clientdata(client);
772
773     ist30xx_power_status = 1;
774
775         mutex_lock(&ist30xx_mutex);
776         ist30xx_internal_resume(data);
777         ist30xx_start(data);
778         ist30xx_enable_irq(data);
779         mutex_unlock(&ist30xx_mutex);
780
781         return 0;
782 }
783 #endif // CONFIG_HAS_EARLYSUSPEND
784
785 static void ist30xx_shutdown(struct i2c_client *client)
786 {
787         struct ist30xx_data *data = i2c_get_clientdata(client);
788
789         if(ist30xx_initialized)
790         {
791         mutex_lock(&ist30xx_mutex);
792         ist30xx_disable_irq(data);
793         ist30xx_internal_suspend(data);
794         mutex_unlock(&ist30xx_mutex);
795
796         del_timer_sync(&event_timer);
797         }
798
799 }
800
801 void ist30xx_set_ta_mode(bool charging)
802 {
803         tsp_info("%s(), charging = %d\n", __func__, charging);
804
805         if (unlikely(charging == ist30xx_ta_status))
806                 return;
807
808         if (unlikely(ist30xx_noise_mode == -1)) {
809                 ist30xx_ta_status = charging ? 1 : 0;
810                 return;
811         }
812
813         ist30xx_ta_status = charging ? 1 : 0;
814
815         ist30xx_scheduled_reset();
816 }
817 EXPORT_SYMBOL(ist30xx_set_ta_mode);
818
819 void ist30xx_set_call_mode(int mode)
820 {
821         tsp_info("%s(), mode = %d\n", __func__, mode);
822
823         if (unlikely(mode == ((ist30xx_noise_mode >> NOISE_MODE_CALL) & 1)))
824                 return;
825
826         ist30xx_noise_mode &= ~(1 << NOISE_MODE_CALL);
827         if (mode)
828                 ist30xx_noise_mode |= (1 << NOISE_MODE_CALL);
829
830         ist30xx_scheduled_reset();
831 }
832 EXPORT_SYMBOL(ist30xx_set_call_mode);
833
834 void ist30xx_set_cover_mode(int mode)
835 {
836         tsp_info("%s(), mode = %d\n", __func__, mode);
837
838         if (unlikely(mode == ((ist30xx_noise_mode >> NOISE_MODE_COVER) & 1)))
839                 return;
840
841         ist30xx_noise_mode &= ~(1 << NOISE_MODE_COVER);
842         if (mode)
843                 ist30xx_noise_mode |= (1 << NOISE_MODE_COVER);
844
845         ist30xx_scheduled_reset();
846 }
847 EXPORT_SYMBOL(ist30xx_set_cover_mode);
848
849 void charger_enable(int enable)
850 {
851         bool charging = enable ? true : false;
852
853         ist30xx_set_ta_mode(charging);
854 }
855
856 static void reset_work_func(struct work_struct *work)
857 {
858         if (unlikely((ts_data == NULL) || (ts_data->client == NULL)))
859                 return;
860
861         tsp_info("Request reset function\n");
862
863         if (likely((ist30xx_initialized == 1) && (ts_data->status.power == 1) &&
864                    (ts_data->status.update != 1) && (ts_data->status.calib != 1))) {
865                 mutex_lock(&ist30xx_mutex);
866                 ist30xx_disable_irq(ts_data);
867                 clear_input_data(ts_data);
868                 ist30xx_reset(false);
869                 ist30xx_start(ts_data);
870                 ist30xx_enable_irq(ts_data);
871                 mutex_unlock(&ist30xx_mutex);
872         }
873 }
874
875 #if IST30XX_INTERNAL_BIN && IST30XX_UPDATE_BY_WORKQUEUE
876 static void fw_update_func(struct work_struct *work)
877 {
878         if (unlikely((ts_data == NULL) || (ts_data->client == NULL)))
879                 return;
880
881         tsp_info("FW update function\n");
882
883         if (likely(ist30xx_auto_bin_update(ts_data)))
884                 ist30xx_disable_irq(ts_data);
885 }
886 #endif // IST30XX_INTERNAL_BIN && IST30XX_UPDATE_BY_WORKQUEUE
887
888
889 #if IST30XX_EVENT_MODE
890 u32 ist30xx_max_scan_retry = 2;
891 u32 ist30xx_algr_addr = 0, ist30xx_algr_size = 0;
892
893 #define SCAN_STATUS_MAGIC       (0x3C000000)
894 #define SCAN_STATUS_MASK        (0xFF000000)
895 #define FINGER_CNT_MASK         (0x00F00000)
896 #define SCAN_CNT_MASK           (0x000FFFFF)
897 #define GET_FINGER_CNT(n)       ((n & FINGER_CNT_MASK) >> 20)
898 #define GET_SCAN_CNT(n)         (n & SCAN_CNT_MASK)
899 static void noise_work_func(struct work_struct *work)
900 {
901 #if IST30XX_NOISE_MODE
902         int ret;
903         u32 scan_status = 0;
904
905         ret = ist30xx_read_cmd(ts_data->client, IST30XXB_MEM_COUNT, &scan_status);
906         if (unlikely(ret)) {
907                 tsp_warn("Mem scan count read fail!\n");
908                 goto retry_timer;
909         }
910
911         ist30xx_put_track_ms(timer_ms);
912         ist30xx_put_track(&scan_status, 1);
913
914         tsp_verb("scan status: 0x%x\n", scan_status);
915
916         /* Check valid scan count */
917         if (unlikely((scan_status & SCAN_STATUS_MASK) != SCAN_STATUS_MAGIC)) {
918                 tsp_warn("Scan status is not corrected! (0x%08x)\n", scan_status);
919                 goto retry_timer;
920         }
921
922         /* Status of IC is idle */
923         if (GET_FINGER_CNT(scan_status) == 0) {
924                 if ((PARSE_FINGER_CNT(ts_data->t_status) > 0) ||
925                     (PARSE_KEY_CNT(ts_data->t_status) > 0))
926                         clear_input_data(ts_data);
927         }
928
929         scan_status &= SCAN_CNT_MASK;
930
931         /* Status of IC is lock-up */
932         if (unlikely(scan_status == ist30xx_scan_count)) {
933                 tsp_warn("TSP IC is not responded! (0x%08x)\n", scan_status);
934                 goto retry_timer;
935         } else {
936                 ist30xx_scan_retry = 0;
937         }
938
939         ist30xx_scan_count = scan_status;
940
941         return;
942
943 retry_timer:
944         ist30xx_scan_retry++;
945         tsp_warn("Retry scan status!(%d)\n", ist30xx_scan_retry);
946
947         if (unlikely(ist30xx_scan_retry == ist30xx_max_scan_retry)) {
948                 ist30xx_scheduled_reset();
949                 ist30xx_scan_retry = 0;
950         }
951 #endif  // IST30XX_NOISE_MODE
952 }
953
954 static void debug_work_func(struct work_struct *work)
955 {
956 #if IST30XX_ALGORITHM_MODE
957         int ret = -EPERM;
958     int i;
959         u32 *buf32;
960
961     buf32 = kzalloc(ist30xx_algr_size, GFP_KERNEL);
962
963     for (i = 0; i < ist30xx_algr_size; i++) {
964         ret = ist30xx_read_buf(ts_data->client, 
965                 ist30xx_algr_addr + IST30XX_DATA_LEN * i, &buf32[i], 1);
966         if (ret) {
967                     tsp_warn("Algorithm mem addr read fail!\n");
968                 return;
969             }
970     }
971
972     ist30xx_put_track(buf32, ist30xx_algr_size);
973
974         tsp_debug(" 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
975                   buf32[0], buf32[1], buf32[2], buf32[3], buf32[4]);
976 #endif
977 }
978
979 void timer_handler(unsigned long data)
980 {
981         struct ist30xx_status *status = &ts_data->status;
982
983         if (ist30xx_irq_working)
984                 goto restart_timer;
985
986         if (status->event_mode) {
987                 if (likely((status->power == 1) && (status->update != 1))) {
988                         timer_ms = (u32)get_milli_second();
989                         if (unlikely(status->calib == 1)) { // Check calibration
990                                 if ((status->calib_msg & CALIB_MSG_MASK) == CALIB_MSG_VALID) {
991                                         tsp_info("Calibration check OK!!\n");
992                                         schedule_delayed_work(&work_reset_check, 0);
993                                         status->calib = 0;
994                                 } else if (timer_ms - event_ms >= 3000) { // 3second
995                                         tsp_info("calibration timeout over 3sec\n");
996                                         schedule_delayed_work(&work_reset_check, 0);
997                                         status->calib = 0;
998                                 }
999                         } else if (likely(status->noise_mode)) {
1000                                 if (timer_ms - event_ms > 100)     // 100ms after last interrupt
1001                                         schedule_delayed_work(&work_noise_protect, 0);
1002                         }
1003
1004 #if IST30XX_ALGORITHM_MODE
1005                         if ((ist30xx_algr_addr >= IST30XXB_ACCESS_ADDR) &&
1006                             (ist30xx_algr_size > 0)) {
1007                 if (timer_ms - event_ms > 100)     // 100ms after last interrupt
1008                                     schedule_delayed_work(&work_debug_algorithm, 0);
1009             }
1010 #endif
1011                 }
1012         }
1013
1014 restart_timer:
1015         mod_timer(&event_timer, get_jiffies_64() + EVENT_TIMER_INTERVAL);
1016 }
1017 #endif // IST30XX_EVENT_MODE
1018
1019 static int ist30xx_probe(struct i2c_client *client, 
1020                         const struct i2c_device_id *id)
1021 {
1022         int ret;
1023         int retry = 3;
1024         struct ist30xx_data *data;
1025         struct input_dev *input_dev;
1026     int ist_gpio = 0;    
1027
1028     tsp_info("##### IST30XX(Ver%d) Initialize #####\n", IST30XX_DD_VERSION);
1029
1030     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
1031                 printk(KERN_INFO "i2c_check_functionality error\n");
1032                 return -EIO;
1033         }
1034         tsp_info("%s(), the i2c addr=0x%x\n", __func__, client->addr);
1035
1036         data = kzalloc(sizeof(*data), GFP_KERNEL);
1037         if (!data)
1038                 return -ENOMEM;
1039
1040 #ifdef CONFIG_OF
1041     struct device_node *np = client->dev.of_node;
1042
1043     tsp_info("the client->dev.of_node=0x%x\n", client->dev.of_node);
1044         
1045     if (client->dev.of_node){
1046         ist_gpio = of_get_gpio(np, 0);
1047         of_property_read_string(np, "tsp_pwr_name", &ist_vdd_name);
1048         tsp_info("gpio id=%d,power name:%s\n", ist_gpio,ist_vdd_name);
1049     }
1050 #endif
1051
1052         input_dev = input_allocate_device();
1053         if (unlikely(!input_dev)) {
1054                 ret = -ENOMEM;
1055                 tsp_err("%s(), input_allocate_device failed (%d)\n",
1056                         __func__, ret);
1057                 goto err_alloc_dev;
1058         }
1059
1060 #ifndef CONFIG_OF
1061     ist_gpio = 82;
1062     ist_vdd_name = "vddsim2";
1063 #endif
1064
1065     /* configure touchscreen interrupt gpio */
1066         ret = gpio_request(ist_gpio, "ist30xx_irq_gpio");
1067       printk("[TSP]request gpio id = %d\n", ist_gpio);
1068         if (ret) {
1069                 tsp_err("unable to request gpio.(%s)\r\n",input_dev->name);
1070                 goto err_init_drv;
1071         }
1072
1073         client->irq = gpio_to_irq(ist_gpio);
1074         printk("[TSP] client->irq : %d\n", client->irq);
1075
1076     data->max_fingers = data->max_keys = IST30XX_MAX_MT_FINGERS;
1077         data->irq_enabled = 1;
1078         data->client = client;
1079     data->input_dev = input_dev;
1080     i2c_set_clientdata(client, data);
1081     
1082     input_mt_init_slots(input_dev, IST30XX_MAX_MT_FINGERS, 0);
1083
1084         input_dev->name = "ist30xx_ts_input";
1085         input_dev->id.bustype = BUS_I2C;
1086         input_dev->dev.parent = &client->dev;
1087
1088         set_bit(EV_ABS, input_dev->evbit);
1089         set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
1090
1091         input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, IST30XX_MAX_X, 0, 0);
1092         input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, IST30XX_MAX_Y, 0, 0);
1093         input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, IST30XX_MAX_W, 0, 0);    
1094
1095 #if IST30XX_USE_KEY
1096         {
1097                 int i;
1098                 set_bit(EV_KEY, input_dev->evbit);
1099                 set_bit(EV_SYN, input_dev->evbit);
1100                 for (i = 1; i < ARRAY_SIZE(ist30xx_key_code); i++)
1101                         set_bit(ist30xx_key_code[i], input_dev->keybit);
1102         }
1103 #endif
1104
1105         input_set_drvdata(input_dev, data);
1106         ret = input_register_device(input_dev);
1107         if (unlikely(ret)) {
1108                 input_free_device(input_dev);
1109                 goto err_reg_dev;
1110         }
1111
1112 #ifdef CONFIG_HAS_EARLYSUSPEND
1113         data->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
1114         data->early_suspend.suspend = ist30xx_early_suspend;
1115         data->early_suspend.resume = ist30xx_late_resume;
1116         register_early_suspend(&data->early_suspend);
1117 #endif
1118
1119         ts_data = data;
1120
1121         ret = ist30xx_init_system();
1122         if (unlikely(ret)) {
1123                 tsp_err("chip initialization failed\n");
1124                 goto err_init_drv;
1125         }
1126
1127         ret = ist30xx_init_update_sysfs();
1128         if (unlikely(ret))
1129                 goto err_init_drv;
1130
1131 #if IST30XX_DEBUG
1132         ret = ist30xx_init_misc_sysfs();
1133         if (unlikely(ret))
1134                 goto err_init_drv;
1135 #endif
1136
1137 #if IST30XX_CMCS_TEST
1138         ret = ist30xx_init_cmcs_sysfs();
1139         if (unlikely(ret))
1140                 goto err_init_drv;
1141 #endif
1142
1143 #if SEC_FACTORY_MODE
1144         ret = sec_fac_cmd_init(data);
1145         if (unlikely(ret))
1146                 goto err_init_drv;
1147         ret = sec_touch_sysfs(data);
1148         if (unlikely(ret))
1149                 goto err_init_drv;
1150 #endif
1151
1152 #if IST30XX_TRACKING_MODE
1153         ret = ist30xx_init_tracking_sysfs();
1154         if (unlikely(ret))
1155                 goto err_init_drv;
1156 #endif
1157
1158         ret = request_threaded_irq(client->irq, NULL, ist30xx_irq_thread,
1159                                    IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "ist30xx_ts", data);
1160         if (unlikely(ret))
1161                 goto err_irq;
1162
1163         ist30xx_disable_irq(data);
1164
1165         while ((data->chip_id != IST30XXB_CHIP_ID) &&
1166                (data->chip_id != IST3038_CHIP_ID)) {
1167                 ret = ist30xx_read_cmd(data->client, IST30XXB_REG_CHIPID,
1168                                        &data->chip_id);
1169                 if (unlikely(ret)) {
1170                         tsp_info("tspid: %x\n", data->chip_id);
1171                         ist30xx_reset(false);
1172                 }
1173
1174                 if (data->chip_id == 0x3000B)
1175                         data->chip_id = IST30XXB_CHIP_ID;
1176
1177         if (data->chip_id == 0x3038B)
1178                         data->chip_id = IST3038_CHIP_ID;
1179
1180                 if (retry-- == 0)
1181                         break;
1182         }
1183
1184         retry = 3;
1185         while (retry-- > 0) {
1186                 ret = ist30xx_read_cmd(data->client, IST30XXB_REG_TSPTYPE,
1187                                        &data->tsp_type);
1188
1189                 tsp_info("tsptype: %x\n", data->tsp_type);
1190                 data->tsp_type = IST30XXB_PARSE_TSPTYPE(data->tsp_type);
1191
1192                 if (likely(ret == 0))
1193                         break;
1194
1195                 if (unlikely(retry == 0))
1196                         goto err_irq;
1197         }
1198
1199         tsp_info("TSP IC: %x, TSP Vendor: %x\n", data->chip_id, data->tsp_type);
1200
1201         data->status.event_mode = false;
1202
1203 #if IST30XX_INTERNAL_BIN
1204 #if IST30XX_UPDATE_BY_WORKQUEUE
1205         INIT_DELAYED_WORK(&work_fw_update, fw_update_func);
1206         schedule_delayed_work(&work_fw_update, IST30XX_UPDATE_DELAY);
1207 #else
1208         ret = ist30xx_auto_bin_update(data);
1209         if (unlikely(ret != 0))
1210                 goto err_irq;
1211 #endif
1212 #endif  // IST30XX_INTERNAL_BIN
1213
1214         if (ist30xx_ta_status < 0)
1215                 ist30xx_ta_status = 0;
1216
1217         if (ist30xx_power_status < 0)
1218                 ist30xx_power_status = 0;
1219
1220         if (ist30xx_noise_mode < 0)
1221                 ist30xx_noise_mode = 0;
1222
1223         ret = ist30xx_get_info(data);
1224         tsp_info("Get info: %s\n", (ret == 0 ? "success" : "fail"));
1225
1226         INIT_DELAYED_WORK(&work_reset_check, reset_work_func);
1227 #if IST30XX_EVENT_MODE
1228         INIT_DELAYED_WORK(&work_noise_protect, noise_work_func);
1229         INIT_DELAYED_WORK(&work_debug_algorithm, debug_work_func);
1230 #endif
1231
1232 #if IST30XX_EVENT_MODE
1233         init_timer(&event_timer);
1234         event_timer.function = timer_handler;
1235         event_timer.expires = jiffies_64 + (EVENT_TIMER_INTERVAL);
1236         mod_timer(&event_timer, get_jiffies_64() + EVENT_TIMER_INTERVAL);
1237 #endif
1238
1239         ist30xx_initialized = 1;
1240     tsp_info("Probe end\n");
1241
1242         return 0;
1243
1244 err_irq:
1245         tsp_info("ChipID: %x\n", data->chip_id);
1246         ist30xx_disable_irq(data);
1247         free_irq(client->irq, data);
1248 err_init_drv:
1249         data->status.event_mode = false;
1250         tsp_err("Error, ist30xx init driver\n");
1251         ist30xx_power_off();
1252 #ifdef CONFIG_HAS_EARLYSUSPEND  
1253         unregister_early_suspend(&data->early_suspend);
1254 #endif  
1255         input_unregister_device(input_dev);
1256         return 0;
1257
1258 err_reg_dev:
1259 err_alloc_dev:
1260         tsp_err("Error, ist30xx mem free\n");
1261         kfree(data);
1262         return 0;
1263 }
1264
1265
1266 static int __exit ist30xx_remove(struct i2c_client *client)
1267 {
1268         struct ist30xx_data *data = i2c_get_clientdata(client);
1269
1270 #ifdef CONFIG_HAS_EARLYSUSPEND
1271         unregister_early_suspend(&data->early_suspend);
1272 #endif
1273
1274     ist30xx_disable_irq(data);
1275         free_irq(client->irq, data);
1276         ist30xx_power_off();
1277
1278         input_unregister_device(data->input_dev);
1279         kfree(data);
1280
1281         return 0;
1282 }
1283
1284
1285 static struct i2c_device_id ist30xx_idtable[] = {
1286         { IST30XX_DEV_NAME, 0 },
1287         {},
1288 };
1289 MODULE_DEVICE_TABLE(i2c, ist30xx_idtable);
1290
1291 #ifdef CONFIG_HAS_EARLYSUSPEND
1292 static const struct dev_pm_ops ist30xx_pm_ops = {
1293         .suspend        = ist30xx_suspend,
1294         .resume         = ist30xx_resume,
1295 };
1296 #endif
1297
1298 #ifdef CONFIG_OF                
1299 static const struct of_device_id ist30xxb_ts_of_match[] = {
1300         { .compatible = "Imagis,IST30XX", },
1301         { }
1302 };                                      
1303 #endif
1304
1305 static struct i2c_driver ist30xx_i2c_driver = {
1306         .id_table       = ist30xx_idtable,
1307         .probe          = ist30xx_probe,
1308         .remove         = __exit_p(ist30xx_remove),
1309         .shutdown       = ist30xx_shutdown,    
1310         .driver         = {
1311                 .owner  = THIS_MODULE,
1312                 .name   = IST30XX_DEV_NAME,
1313 #ifdef CONFIG_HAS_EARLYSUSPEND
1314                 .pm     = &ist30xx_pm_ops,
1315 #endif
1316
1317 #ifdef CONFIG_OF
1318         .of_match_table = ist30xxb_ts_of_match,
1319 #endif        
1320         },
1321 };
1322
1323 static int __init ist30xx_init(void)
1324 {
1325     tsp_info("Imagis init called\n");
1326         return i2c_add_driver(&ist30xx_i2c_driver);
1327 }
1328
1329
1330 static void __exit ist30xx_exit(void)
1331 {
1332         i2c_del_driver(&ist30xx_i2c_driver);
1333 }
1334
1335 module_init(ist30xx_init);
1336 module_exit(ist30xx_exit);
1337
1338 MODULE_DESCRIPTION("Imagis IST30XX touch driver");
1339 MODULE_LICENSE("GPL");