input: touch: sharp: update to version 9.
[linux-3.10.git] / drivers / input / touchscreen / lr388k7_ts.c
1 /*
2  * LR388K7 touchscreen driver
3  *
4  * Copyright (C) 2014, Sharp Corporation
5  *
6  * Author: Makoto Itsuki <itsuki.makoto@sharp.co.jp>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  */
14
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/input.h>
18 #include <linux/interrupt.h>
19 #include <linux/delay.h>
20 #include <linux/gpio.h>
21 #include <linux/of.h>
22 #include <linux/of_device.h>
23 #include <linux/of_gpio.h>
24 #include <linux/pm.h>
25 #include <linux/spi/spi.h>
26 #include <linux/spi/lr388k7_ts.h>
27 #include <linux/input/mt.h>
28 #include <linux/miscdevice.h>
29 #include <linux/sysfs.h>
30 #include <linux/clk.h>
31 #include <linux/regulator/consumer.h>
32 #include <linux/uaccess.h>
33 #include <linux/workqueue.h>
34
35 /* DEBUG */
36 #ifndef DEBUG_LR388K7
37 #define DEBUG_LR388K7
38 #endif
39
40 /* INPUT_ENABLE */
41 #define INPUT_ENABLE
42 /* ACTIVE */
43 /* #define ACTIVE_ENABLE */
44 /* UDEV */
45 #define UDEV_ENABLE
46
47
48 #ifdef __min
49 #undef __min
50 #define __min(x, y) ((x) < (y) ? (x) : (y))
51 #else
52 #define __min(x, y) ((x) < (y) ? (x) : (y))
53 #endif
54
55 #ifdef __max
56 #undef __max
57 #define __max(x, y) ((x) > (y) ? (x) : (y))
58 #else
59 #define __max(x, y) ((x) > (y) ? (x) : (y))
60 #endif
61
62 #ifdef __neg_chk
63 #undef __neg_chk
64 #define __neg_chk(a) ((a) < 0 ? 0 : (a))
65 #else
66 #define __neg_chk(a) ((a) < 0 ? 0 : (a))
67 #endif
68
69
70 #define MAX_16BIT                       0xffff
71 #define MAX_12BIT                       0xfff
72 #define MAX_10BIT                       0x3ff
73 #define K7_MAX_TOUCH_NUM (10)
74 #define K7_MAX_SPEED_HZ (25000000)
75 #define K7_RD_HEADER_SIZE (5)
76 #define K7_WR_OPCODE (0x02)
77 #define K7_RD_OPCODE (0x0B)
78 #define K7_STATE_CTL_ADDR (0x000024)
79 #define K7_INT_STATUS_ADDR (0x000000)
80 #define K7_IND_DONE_ADDR (0x0003E1)
81 #define K7_DATA_OFFSET (0x1000)
82 #define K7_DATA_HEADER_WORD_SIZE (0x08)
83 #define K7_DATA_HEADER_BYTE_SIZE (K7_DATA_HEADER_WORD_SIZE * 2)
84 #define K7_DATA_READ_SIZE (K7_DATA_HEADER_BYTE_SIZE + K7_RD_HEADER_SIZE)
85 #define K7_DATA_SIZE (8800 + K7_DATA_READ_SIZE)
86 #define K7_CMD_DATA_OFFSET (0x030400)
87 #define K7_CMD_DATA_SIZE (251 + K7_RD_HEADER_SIZE)
88 #define K7_Q_SIZE (8)
89 #define K7_DRIVER_VERSION (9)
90 #define K7_INT_STATUS_MASK_DATA (0x01)
91 #define K7_INT_STATUS_MASK_BOOT (0x02)
92 #define K7_INT_STATUS_MASK_CMD  (0x04)
93 #define K7_INT_STATUS_MASK_ERR  (0x08)
94 #define K7_INT_STATUS_MASK_CRC  (0x10)
95 #define K7_POWER_CTL_TAP_WAKEUP (0x00)
96 #define K7_POWER_CTL_SLEEP (0x01)
97 #define K7_POWER_CTL_RESUME (0x02)
98 #define K7_REMOTE_WAKEUP_CODE (0xEA)
99 #define K7_DEFAULT_MODE (3)
100
101 enum K7_SCAN_STATE_OPTIONS {
102         K7_SCAN_STATE_IDLE = 0,
103         K7_SCAN_STATE_ACTIVE,
104 };
105
106 enum K7_SLOW_SCAN_OPTIONS {
107         K7_SLOW_SCAN_30 = 30,
108         K7_SLOW_SCAN_60 = 60,
109         K7_SLOW_SCAN_100 = 100,
110         K7_SLOW_SCAN_120 = 120,
111 };
112
113 enum K7_NUM_TAP_OPTIONS {
114         K7_NUM_TAP_2 = 2,
115         K7_NUM_TAP_3,
116         K7_NUM_TAP_4,
117 };
118
119 struct lr388k7_ts_parameter {
120         u32 u32_pid;
121         bool b_is_init_finish;
122         bool b_is_calc_finish;
123         bool b_is_suspended;
124         bool b_is_reset;
125         u32 u32SCK;
126         u16 u16fw_ver;
127         u16 u16module_ver;
128         struct workqueue_struct *st_wq_k7;
129         struct work_struct st_work_k7;
130 };
131
132 struct lr388k7 {
133         struct spi_device       *spi;
134         struct device           *dev;
135         struct input_dev        *idev;
136 #if defined(ACTIVE_ENABLE)
137         struct input_dev        *idev_active;
138         int                     tool;
139         unsigned int            gpio_clk_sel;
140 #endif
141         char                    phys[32];
142         struct mutex            mutex;
143         unsigned int            irq;
144         unsigned int            gpio_reset;
145         unsigned int            gpio_irq;
146         spinlock_t              lock;
147         struct timer_list       timer;
148         unsigned int            max_num_touch;
149         int                     max_x;
150         int                     max_y;
151         int                     max_z;
152         int                     platform_id;
153         bool                    flip_x;
154         bool                    flip_y;
155         bool                    swap_xy;
156         bool                    opened;
157         bool                    suspended;
158         bool                    b_eraser_active;
159         struct clk              *clk;
160         struct regulator        *regulator_3v3;
161         struct regulator        *regulator_1v8;
162 };
163
164 struct lr388k7_queue_info {
165         u8(*p_queue)[K7_DATA_SIZE];
166         u16 u16_front;
167         u16 u16_rear;
168 };
169
170 struct lr388k7_cmd_queue_info {
171         u8(*p_queue)[K7_CMD_DATA_SIZE];
172         u16 u16_front;
173         u16 u16_rear;
174 };
175
176 struct lr388k7_touch_report {
177         u8 u8_num_of_touch;
178         struct st_touch_point_t tc[K7_MAX_TOUCH_NUM];
179 };
180
181 #if defined(ACTIVE_ENABLE)
182 struct lr388k7_active_report {
183         s16 x;
184         s16 y;
185         u16 z;
186         u8 status;
187 };
188 #endif
189
190
191 #if defined(UDEV_ENABLE)
192 struct lr388k7_udev_event {
193         u8 str[512];
194 };
195 #endif
196
197 static int dev_open(struct inode *inode, struct file *filp);
198 static int dev_release(struct inode *inode, struct file *filp);
199 static ssize_t
200 dev_read(struct file *filp, char __user *buf, size_t count, loff_t *pos);
201 static ssize_t
202 dev_write(struct file *filp, const char __user *buf,
203           size_t count, loff_t *pos);
204 static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
205
206 static const struct file_operations dev_fops = {
207         .owner = THIS_MODULE,
208         .open = dev_open,
209         .release = dev_release,
210         .read = dev_read,
211         .write = dev_write,
212         .unlocked_ioctl = dev_ioctl,
213         .compat_ioctl = dev_ioctl,
214 };
215
216 static struct miscdevice lr388k7_ts_miscdev = {
217         .minor = MISC_DYNAMIC_MINOR,
218         .name = "touch",
219         .fops = &dev_fops,
220 };
221
222 static struct spi_device *g_spi;
223 static struct lr388k7_ts_parameter g_st_state;
224 static struct lr388k7_queue_info g_st_q;
225 static struct lr388k7_cmd_queue_info g_st_cmd_q;
226 static struct lr388k7_ts_dbg g_st_dbg;
227 static u8 g_u8_mode;
228 static u8 g_u8_scan;
229 static u32 g_u32_raw_data_size = 50 * 88 * 2;
230
231 #define IS_DBG (g_st_dbg.u8ForceCap == 1 || \
232                 g_st_dbg.u8Dump == 1 || \
233                 g_st_dbg.slowscan.enable == 1 ? true : false)
234
235 static int lr388k7_spi_write(u8 *txbuf, size_t len);
236 static int lr388k7_spi_read(u8 *txbuf, u8 *rxbuf, size_t len);
237 static void lr388k7_init_parameter(void);
238 static long lr388k7_spi_read_cmd_data(u8 *p, size_t count);
239 static int lr388k7_input_enable(struct input_dev *idev);
240 static int lr388k7_input_disable(struct input_dev *idev);
241
242 static void lr388k7_queue_reset(void)
243 {
244         g_st_q.u16_rear = 0;
245         g_st_q.u16_front = 0;
246         g_st_cmd_q.u16_rear = 0;
247         g_st_cmd_q.u16_front = 0;
248 }
249
250 static int lr388k7_hardreset(unsigned long wait)
251 {
252         struct lr388k7 *ts = spi_get_drvdata(g_spi);
253         if (!ts)
254                 return false;
255
256         gpio_set_value(ts->gpio_reset, 0);
257         g_st_state.b_is_reset = true;
258         usleep_range(wait * 1000, wait * 1000 + 1000);
259         gpio_set_value(ts->gpio_reset, 1);
260         g_st_state.b_is_reset = false;
261         return true;
262 }
263
264 #if defined(ACTIVE_ENABLE)
265 static int lr388k7_set_clk_sel(unsigned int sel)
266 {
267         struct lr388k7 *ts = spi_get_drvdata(g_spi);
268
269         if (!ts)
270                 return false;
271
272         if (!sel)
273                 gpio_set_value(ts->gpio_clk_sel, 0);
274         else
275                 gpio_set_value(ts->gpio_clk_sel, 1);
276         return true;
277 }
278 #endif
279
280 static int lr388k7_queue_init(void)
281 {
282         lr388k7_queue_reset();
283         /*
284          * Memory Allocation
285          */
286         g_st_q.p_queue = kmalloc(K7_DATA_SIZE * K7_Q_SIZE, GFP_KERNEL);
287         if (g_st_q.p_queue == NULL)
288                 return -ENOMEM;
289
290         g_st_cmd_q.p_queue = kmalloc(K7_CMD_DATA_SIZE * K7_Q_SIZE, GFP_KERNEL);
291         if (g_st_cmd_q.p_queue == NULL) {
292                 kfree(g_st_q.p_queue);
293                 return -ENOMEM;
294         }
295
296         return 0;
297 }
298
299 static void lr388k7_queue_free(void)
300 {
301         if (!g_st_q.p_queue)
302                 return;
303         kfree(g_st_q.p_queue);
304         g_st_q.p_queue = NULL;
305
306         if (!g_st_cmd_q.p_queue)
307                 return;
308         kfree(g_st_cmd_q.p_queue);
309         g_st_cmd_q.p_queue = NULL;
310 }
311
312
313 static int lr388k7_queue_is_full(void)
314 {
315         u16 u16_front = g_st_q.u16_front;
316         if (g_st_q.u16_rear + 1 == u16_front)
317                 return 1;
318
319         if ((g_st_q.u16_rear == (K7_Q_SIZE - 1)) && (u16_front == 0))
320                 return 1;
321
322         return 0;
323 }
324
325 static int lr388k7_queue_is_empty(void)
326 {
327         if (g_st_q.u16_rear == g_st_q.u16_front)
328                 return 1;
329         return 0;
330 }
331
332 static int lr388k7_cmd_queue_is_full(void)
333 {
334         u16 u16_front = g_st_cmd_q.u16_front;
335         if (g_st_cmd_q.u16_rear + 1 == u16_front)
336                 return 1;
337
338         if ((g_st_cmd_q.u16_rear == (K7_Q_SIZE - 1)) && (u16_front == 0))
339                 return 1;
340
341         return 0;
342 }
343
344 static int lr388k7_cmd_queue_is_empty(void)
345 {
346         if (g_st_cmd_q.u16_rear == g_st_cmd_q.u16_front)
347                 return 1;
348         return 0;
349 }
350
351 static void *lr388k7_enqueue_start(void)
352 {
353         if (!g_st_q.p_queue)
354                 return NULL;
355
356         if (!lr388k7_queue_is_full())
357                 return &g_st_q.p_queue[g_st_q.u16_rear];
358
359         return NULL;
360 }
361
362 static void lr388k7_enqueue_finish(void)
363 {
364         if (g_st_q.u16_rear == (K7_Q_SIZE - 1))
365                 g_st_q.u16_rear = 0;
366         else
367                 g_st_q.u16_rear++;
368 }
369
370 static void *lr388k7_dequeue_start(void)
371 {
372         if (!lr388k7_queue_is_empty())
373                 return &g_st_q.p_queue[g_st_q.u16_front];
374
375         return NULL;
376 }
377
378 static void lr388k7_dequeue_finish(void)
379 {
380         if (g_st_q.u16_front == (K7_Q_SIZE - 1))
381                 g_st_q.u16_front = 0;
382         else
383                 g_st_q.u16_front++;
384 }
385
386 static int lr388k7_queue_read_raw_data(u8 *p, u32 u32_len)
387 {
388         u8 *p_queue;
389         u32 u32_ret;
390         p_queue = lr388k7_dequeue_start();
391         if (!p_queue)
392                 return 0;
393
394         u32_ret = copy_to_user(p, p_queue, u32_len);
395         if (u32_ret != 0)
396                 return 0;
397
398         lr388k7_dequeue_finish();
399         return 1;
400 }
401
402 static void *lr388k7_cmd_enqueue_start(void)
403 {
404         if (!g_st_cmd_q.p_queue)
405                 return NULL;
406
407         if (!lr388k7_cmd_queue_is_full())
408                 return &g_st_cmd_q.p_queue[g_st_cmd_q.u16_rear];
409
410         return NULL;
411 }
412
413 static void lr388k7_cmd_enqueue_finish(void)
414 {
415         if (g_st_cmd_q.u16_rear == (K7_Q_SIZE - 1))
416                 g_st_cmd_q.u16_rear = 0;
417         else
418                 g_st_cmd_q.u16_rear++;
419 }
420
421 static void *lr388k7_cmd_dequeue_start(void)
422 {
423         if (!lr388k7_cmd_queue_is_empty())
424                 return &g_st_cmd_q.p_queue[g_st_cmd_q.u16_front];
425
426         return NULL;
427 }
428
429 static void lr388k7_cmd_dequeue_finish(void)
430 {
431         if (g_st_cmd_q.u16_front == (K7_Q_SIZE - 1))
432                 g_st_cmd_q.u16_front = 0;
433         else
434                 g_st_cmd_q.u16_front++;
435 }
436
437 static int lr388k7_cmd_queue_read(u8 *p, u32 u32_len)
438 {
439         u8 *p_queue;
440         u32 u32_ret;
441         p_queue = lr388k7_cmd_dequeue_start();
442         if (!p_queue)
443                 return 0;
444
445         u32_ret = copy_to_user(p, p_queue, u32_len);
446         if (u32_ret != 0)
447                 return 0;
448
449         lr388k7_cmd_dequeue_finish();
450         return 1;
451 }
452
453 static u8 lr388k7_clear_irq(void)
454 {
455         u8 u8_tx_buf[K7_RD_HEADER_SIZE + 1], u8_rx_buf[K7_RD_HEADER_SIZE + 1];
456         u8 u8Ret = 0;
457         size_t count = 1;
458
459         if (g_st_state.b_is_reset)
460                 return u8Ret;
461
462         u8_tx_buf[0] = K7_RD_OPCODE;
463         u8_tx_buf[1] = (K7_INT_STATUS_ADDR >> 16) & 0xFF;
464         u8_tx_buf[2] = (K7_INT_STATUS_ADDR >>  8) & 0xFF;
465         u8_tx_buf[3] = (K7_INT_STATUS_ADDR >>  0) & 0xFF;
466         u8_tx_buf[4] = 0x00;
467
468         g_st_state.u32SCK = 0;
469
470         if (lr388k7_spi_read(u8_tx_buf, u8_rx_buf, count))
471                 u8Ret = u8_rx_buf[K7_RD_HEADER_SIZE];
472
473         g_st_state.u32SCK = g_spi->max_speed_hz;
474
475         return u8Ret;
476 }
477
478 static long lr388k7_ts_get_mode(u8 *p)
479 {
480         ssize_t status = 0;
481
482         if (p == 0) {
483                 status = -EFAULT;
484                 goto exit_get_mode;
485         }
486
487         if (copy_to_user(p, &g_u8_mode, sizeof(u8)))
488                 status = -EFAULT;
489
490  exit_get_mode:
491         return status;
492 }
493
494 static long lr388k7_ts_get_debug_status(u8 *p)
495 {
496         ssize_t status = 0;
497
498         if (p == 0) {
499                 status = -EFAULT;
500                 goto exit_get_debug_status;
501         }
502
503         if (copy_to_user(p, &g_st_dbg, sizeof(struct lr388k7_ts_dbg)))
504                 status = -EFAULT;
505
506  exit_get_debug_status:
507         return status;
508 }
509
510 static void lr388k7_indicate_done(void)
511 {
512 #if 0
513         u8 u8_buf[5];
514         size_t count = 0;
515
516         u8_buf[count++] = K7_WR_OPCODE;
517         u8_buf[count++] = (K7_IND_DONE_ADDR >> 16) & 0xFF;
518         u8_buf[count++] = (K7_IND_DONE_ADDR >>  8) & 0xFF;
519         u8_buf[count++] = (K7_IND_DONE_ADDR >>  0) & 0xFF;
520         u8_buf[count++] = 0x01;
521         lr388k7_spi_write(u8_buf, count);
522 #endif
523 }
524
525 static int lr388k7_read_data(u8 *p)
526 {
527         u8 *p_tx_buf;
528         size_t count = 0;
529         ssize_t status = 0;
530
531         /*
532          * Memory Allocation
533          */
534         count = (size_t)g_u32_raw_data_size;
535
536         p_tx_buf = kmalloc(K7_DATA_READ_SIZE + count, GFP_KERNEL);
537         if (p_tx_buf == NULL) {
538                 status = -ENOMEM;
539                 goto exit_read_data;
540         }
541
542         p_tx_buf[0] = K7_RD_OPCODE;
543         p_tx_buf[1] = (K7_DATA_OFFSET >> 16) & 0xFF;
544         p_tx_buf[2] = (K7_DATA_OFFSET >>  8) & 0xFF;
545         p_tx_buf[3] = (K7_DATA_OFFSET >>  0) & 0xFF;
546         p_tx_buf[4] = 0x00;
547
548         if (lr388k7_spi_read(p_tx_buf, p, K7_DATA_HEADER_BYTE_SIZE + count))
549                 status = count;
550         else{
551                 status = -EFAULT;
552                 goto exit_read_data_free_tx;
553         }
554
555  exit_read_data_free_tx:
556         kfree(p_tx_buf);
557  exit_read_data:
558         if (status < 0)
559                 return 0;
560         return 1;
561 }
562
563 int lr388k7_send_signal(int pid, int n_info)
564 {
565         struct siginfo info;
566         struct task_struct *t;
567         int ret = 0;
568
569         static DEFINE_MUTEX(lock);
570
571         if (!pid)
572                 return ret;
573
574         mutex_lock(&lock);
575
576         /*
577          * Set signal parameters
578          */
579         memset(&info, 0, sizeof(struct siginfo));
580         info.si_signo = LR388K7_SIGNAL;
581         info.si_code = SI_QUEUE;
582         info.si_int = n_info;/*real time signals may have 32 bits of data. */
583
584         rcu_read_lock();
585         /* To avoid link error for module build, it was replaced by pid_task.
586         t = find_task_by_vpid(pid);
587         */
588         t = pid_task(find_vpid(pid), PIDTYPE_PID);
589         rcu_read_unlock();
590         if (t == NULL) {
591                 dev_err(&g_spi->dev, " : no such pid\n");
592                 ret = -ENODEV;
593         } else{
594                 ret = send_sig_info(LR388K7_SIGNAL, &info, t);
595         }
596
597         if (ret < 0)
598                 dev_err(&g_spi->dev, " : sending signal\n");
599
600         mutex_unlock(&lock);
601
602         return ret;
603 }
604
605 static void lr388k7_read_spec_size(void)
606 {
607         int n_ret;
608         u8 *p_buf;
609
610         p_buf = kmalloc(K7_DATA_SIZE, GFP_KERNEL);
611         if (p_buf) {
612                 n_ret = lr388k7_read_data((u8 *)p_buf);
613                 kfree(p_buf);
614         } else {
615                 dev_err(&g_spi->dev, " : %d\n", -ENOMEM);
616         }
617 }
618
619 static bool lr388k7_check_status(void)
620 {
621         u8 u8_tx_buf[K7_RD_HEADER_SIZE + 1], u8_rx_buf[K7_RD_HEADER_SIZE + 1];
622         u8 u8Ret = 0;
623         size_t count = 1;
624
625         u8_tx_buf[0] = K7_RD_OPCODE;
626         u8_tx_buf[1] = (K7_CMD_DATA_OFFSET >> 16) & 0xFF;
627         u8_tx_buf[2] = (K7_CMD_DATA_OFFSET >>  8) & 0xFF;
628         u8_tx_buf[3] = (K7_CMD_DATA_OFFSET >>  0) & 0xFF;
629         u8_tx_buf[4] = 0x00;
630
631         g_st_state.u32SCK = 0;
632
633         if (lr388k7_spi_read(u8_tx_buf, u8_rx_buf, count)) {
634                 u8Ret = u8_rx_buf[K7_RD_HEADER_SIZE];
635
636                 if (u8Ret == K7_REMOTE_WAKEUP_CODE)
637                         return true;
638         }
639
640         g_st_state.u32SCK = g_spi->max_speed_hz;
641
642         return false;
643 }
644
645 static void lr388k7_event_handler(u8 u8Status)
646 {
647         void *p_q_buf;
648         void *p_cmd_q_buf;
649         int n_ret;
650
651         if (u8Status & K7_INT_STATUS_MASK_BOOT) {
652                 /*
653                  * Let module know device has booted up.
654                  */
655 #if defined(DEBUG_LR388K7)
656                 dev_info(&g_spi->dev, "boot\n");
657 #endif
658                 lr388k7_send_signal(g_st_state.u32_pid, LR388K7_SIGNAL_BOOT);
659         }
660
661         if (u8Status & K7_INT_STATUS_MASK_CRC)
662                 lr388k7_send_signal(g_st_state.u32_pid, LR388K7_SIGNAL_CRCE);
663
664         if (u8Status & K7_INT_STATUS_MASK_DATA) {
665
666                 /*
667                  * Handle data
668                  */
669                 if (g_st_state.b_is_init_finish) {
670
671                         /*
672                          * Get pointer of queue buffer
673                          */
674                         p_q_buf = lr388k7_enqueue_start();
675                         if (p_q_buf) {
676                                 n_ret = lr388k7_read_data((u8 *)p_q_buf);
677                                 if (n_ret)
678                                         lr388k7_enqueue_finish();
679                         } else {
680                                 lr388k7_read_spec_size();
681                         }
682                 } else {
683                         lr388k7_read_spec_size();
684                 }
685
686                 if (g_st_state.b_is_calc_finish) {
687                         g_st_state.b_is_calc_finish = 0;
688                         lr388k7_send_signal(
689                                             g_st_state.u32_pid,
690                                             LR388K7_SIGNAL_INTR
691                                             );
692                 }
693                 lr388k7_indicate_done();
694         }
695
696         if (u8Status & K7_INT_STATUS_MASK_CMD) {
697
698                 /*
699                  * Process command result
700                  */
701                 p_cmd_q_buf = lr388k7_cmd_enqueue_start();
702                 if (p_cmd_q_buf) {
703                         n_ret = lr388k7_spi_read_cmd_data(
704                                                           (u8 *)p_cmd_q_buf,
705                                                           K7_CMD_DATA_SIZE
706                                                           - K7_RD_HEADER_SIZE
707                                                           );
708                         if (n_ret) {
709                                 lr388k7_cmd_enqueue_finish();
710                                 lr388k7_send_signal(
711                                                     g_st_state.u32_pid,
712                                                     LR388K7_SIGNAL_CMDR
713                                                     );
714                         }
715                 }
716         }
717 }
718
719 static void lr388k7_work_handler(struct work_struct *work)
720 {
721         struct lr388k7 *ts = spi_get_drvdata(g_spi);
722         u8 u8_status;
723         int irq_value;
724
725         if (g_st_state.b_is_suspended) {
726                 dev_dbg(
727                         &g_spi->dev,
728                         "[WARN] work handler is called regardless of b_is_suspended\n");
729                 return;
730         }
731
732         mutex_lock(&ts->mutex);
733
734         /*
735          * Clear Interrupt
736          */
737         u8_status = lr388k7_clear_irq();
738
739         while (u8_status) {
740
741                 lr388k7_event_handler(u8_status);
742
743                 /*
744                  * Check if irq is already cleared.
745                  */
746                 irq_value = gpio_get_value(ts->gpio_irq);
747
748                 if (!irq_value)
749                         u8_status = lr388k7_clear_irq();
750                 else
751                         u8_status = 0;
752         }
753
754         mutex_unlock(&ts->mutex);
755 }
756
757 static void lr388k7_enable_irq(struct lr388k7 *ts)
758 {
759         if (g_st_dbg.wakeup.enable == 1)
760                 disable_irq_wake(ts->irq);
761         else
762                 enable_irq(ts->irq);
763 }
764
765 static void lr388k7_disable_irq(struct lr388k7 *ts)
766 {
767         if (g_st_dbg.wakeup.enable == 1)
768                 enable_irq_wake(ts->irq);
769         else
770                 disable_irq(ts->irq);
771 }
772
773 static irqreturn_t lr388k7_wakeup_thread(int irq, void *_ts)
774 {
775         struct lr388k7 *ts = (struct lr388k7 *)_ts;
776         struct input_dev *input_dev = ts->idev;
777         u8 u8_status;
778
779         dev_info(&g_spi->dev, "[ENTER] Wakeup thread\n");
780
781         u8_status = lr388k7_clear_irq();
782         if (u8_status & K7_INT_STATUS_MASK_CMD) {
783                 if (!lr388k7_check_status()) {
784                         lr388k7_event_handler(u8_status);
785                         return IRQ_HANDLED;
786                 }
787         }
788
789         dev_info(&g_spi->dev, "Tap wakeup\n");
790
791         input_report_key(input_dev, KEY_POWER, 1);
792         input_sync(input_dev);
793         input_report_key(input_dev, KEY_POWER, 0);
794         input_sync(input_dev);
795
796         if (u8_status & K7_INT_STATUS_MASK_DATA) {
797                 dev_info(&g_spi->dev, "[DATA] Wakeup thread\n");
798                 lr388k7_read_spec_size();
799         }
800
801         if (g_st_state.b_is_suspended)
802                 g_st_state.b_is_suspended = false;
803
804         dev_info(&g_spi->dev, "[EXIT] Wakeup thread\n");
805
806         return IRQ_HANDLED;
807 }
808
809 static irqreturn_t lr388k7_irq_thread(int irq, void *_ts)
810 {
811         struct lr388k7 *ts = (struct lr388k7 *)_ts;
812         struct input_dev *input_dev = ts->idev;
813
814         if (g_u8_scan == K7_SCAN_STATE_IDLE) {
815                 input_event(input_dev, EV_MSC, MSC_ACTIVITY, 1);
816                 input_sync(input_dev);
817         }
818
819         if (g_st_state.b_is_suspended) {
820                 if (g_st_dbg.wakeup.enable == 1) {
821                         dev_info(&g_spi->dev, "Throw IRQ_WAKE_THREAD\n");
822                         return IRQ_WAKE_THREAD;
823                 }
824                 return IRQ_HANDLED;
825         }
826
827         queue_work(g_st_state.st_wq_k7, &g_st_state.st_work_k7);
828         return IRQ_HANDLED;
829 }
830
831 static void lr388k7_start_scan(struct lr388k7 *ts)
832 {
833         lr388k7_enable_irq(ts);
834 }
835
836 static void lr388k7_stop_scan(struct lr388k7 *ts)
837 {
838         lr388k7_disable_irq(ts);
839 }
840
841 /* must be called with ts->mutex held */
842 static void __lr388k7_disable(struct lr388k7 *ts)
843 {
844         lr388k7_stop_scan(ts);
845 }
846
847 /* must be called with ts->mutex held */
848 static void __lr388k7_enable(struct lr388k7 *ts)
849 {
850         lr388k7_start_scan(ts);
851 }
852
853 static ssize_t lr388k7_ts_force_cap_show(struct device *dev,
854                                          struct device_attribute *attr,
855                                          char *buf)
856 {
857         return sprintf(buf, "%d\n", g_st_dbg.u8ForceCap);
858 }
859
860 static ssize_t lr388k7_ts_force_cap_store(struct device *dev,
861                                           struct device_attribute *attr,
862                                           const char *buf,
863                                           size_t count)
864 {
865         ssize_t ret;
866
867         ret = (ssize_t)count;
868
869         if (g_st_state.b_is_suspended)
870                 return ret;
871
872         if (count != 1)
873                 return ret;
874
875         if (buf[0] == '0')
876                 g_st_dbg.u8ForceCap = 0;
877         else if (buf[0] == '1')
878                 g_st_dbg.u8ForceCap = 1;
879
880         lr388k7_send_signal(g_st_state.u32_pid, LR388K7_SIGNAL_CTRL);
881
882         return ret;
883 }
884
885 static ssize_t lr388k7_ts_dump_show(struct device *dev,
886                                     struct device_attribute *attr,
887                                     char *buf)
888 {
889         return sprintf(buf, "%d\n", g_st_dbg.u8Dump);
890 }
891
892 static ssize_t lr388k7_ts_dump_store(struct device *dev,
893                                      struct device_attribute *attr,
894                                      const char *buf,
895                                      size_t count)
896 {
897         ssize_t ret;
898
899         ret = (ssize_t)count;
900
901         if (g_st_state.b_is_suspended)
902                 return ret;
903
904         if (count != 1)
905                 return ret;
906
907         if (buf[0] == '0')
908                 g_st_dbg.u8Dump = 0;
909         else if (buf[0] == '1')
910                 g_st_dbg.u8Dump = 1;
911
912         lr388k7_send_signal(g_st_state.u32_pid, LR388K7_SIGNAL_CTRL);
913
914         return ret;
915 }
916
917 static ssize_t lr388k7_ts_report_mode_show(struct device *dev,
918                                     struct device_attribute *attr,
919                                     char *buf)
920 {
921         return sprintf(buf, "%d\n", g_u8_mode);
922 }
923
924 static ssize_t lr388k7_ts_report_mode_store(struct device *dev,
925                                      struct device_attribute *attr,
926                                      const char *buf,
927                                      size_t count)
928 {
929         ssize_t ret;
930         u8 prev_mode = g_u8_mode;
931
932         ret = (ssize_t)count;
933
934         if (count != 2)
935                 return ret;
936
937         if (buf[0] >= 0x30 && buf[0] <= 0x36)
938                 g_u8_mode = (u8)buf[0] - 0x30;
939
940         if (prev_mode != g_u8_mode)
941                 lr388k7_send_signal(g_st_state.u32_pid,
942                                     LR388K7_SIGNAL_MODE);
943
944         return ret;
945 }
946
947 static ssize_t lr388k7_ts_version_show(struct device *dev,
948         struct device_attribute *attr,
949         char *buf)
950 {
951         return sprintf(buf, "FW %d, Driver %d, Module %d\n",
952                        g_st_state.u16fw_ver,
953                        K7_DRIVER_VERSION,
954                        g_st_state.u16module_ver
955                        );
956 }
957
958 static ssize_t lr388k7_ts_version_store(struct device *dev,
959         struct device_attribute *attr,
960         const char *buf, size_t count)
961 {
962         return count;
963 }
964
965
966 static ssize_t lr388k7_ts_slowscan_enable_store(struct device *dev,
967         struct device_attribute *attr,
968         const char *buf, size_t count)
969 {
970         unsigned long val;
971         ssize_t err;
972         ssize_t ret;
973         if (count < 2)
974                 return -EINVAL;
975
976         if (g_st_state.b_is_suspended &&
977             g_st_dbg.wakeup.enable == 0)
978                 return -EINVAL;
979
980         ret = (ssize_t) count;
981
982         if (count == 2) {
983                 if (buf[0] == '0') {
984                         g_st_dbg.slowscan.enable = 0;
985                         lr388k7_send_signal(g_st_state.u32_pid,
986                                             LR388K7_SIGNAL_CTRL);
987                 } else if (buf[0] == '1') {
988                         g_st_dbg.slowscan.enable = 1;
989                         lr388k7_send_signal(g_st_state.u32_pid,
990                                             LR388K7_SIGNAL_CTRL);
991                 }
992         } else if ((buf[0] == '2') && (buf[1] == ' ')) {
993                 err = kstrtoul(&buf[2], 10, &val);
994
995                 if (err) {
996                         ret = err;
997                 } else {
998                         /* check if prefined value*/
999                         if ((val == K7_SLOW_SCAN_30) ||
1000                             (val == K7_SLOW_SCAN_60) ||
1001                             (val == K7_SLOW_SCAN_100) ||
1002                             (val == K7_SLOW_SCAN_120)) {
1003                                 g_st_dbg.slowscan.scan_rate = (u16)val;
1004                                 g_st_dbg.slowscan.enable = 1;
1005                                 lr388k7_send_signal(g_st_state.u32_pid,
1006                                                     LR388K7_SIGNAL_CTRL);
1007                         }
1008                 }
1009         }
1010
1011         return ret;
1012 }
1013
1014 static ssize_t lr388k7_ts_slowscan_enable_show(struct device *dev,
1015         struct device_attribute *attr,
1016         char *buf)
1017 {
1018         return sprintf(buf, "Slow Scan:%s Scan Rate:%dHz\n",
1019                        g_st_dbg.slowscan.enable ?
1020                        "Enabled" : "Disabled",
1021                        g_st_dbg.slowscan.scan_rate);
1022 }
1023
1024 static ssize_t lr388k7_ts_wakeup_enable_store(struct device *dev,
1025         struct device_attribute *attr,
1026         const char *buf, size_t count)
1027 {
1028         ssize_t ret;
1029
1030         if (count < 2)
1031                 return -EINVAL;
1032
1033         if (g_st_state.b_is_suspended &&
1034             g_st_dbg.wakeup.enable == 0)
1035                 return -EINVAL;
1036
1037         ret = (ssize_t) count;
1038
1039         if (count == 2) {
1040                 if (buf[0] == '0') {
1041                         g_st_dbg.wakeup.enable = 0;
1042                         lr388k7_send_signal(g_st_state.u32_pid,
1043                                             LR388K7_SIGNAL_CTRL);
1044                 }
1045         } else if ((buf[0] == '1') && (buf[1] == ' ')) {
1046                 /* check if prefined value*/
1047                 if ((buf[2] == '2') ||
1048                     (buf[2] == '3') ||
1049                     (buf[2] == '4')) {
1050                         g_st_dbg.wakeup.num_tap = buf[2] - 0x30;
1051                         g_st_dbg.wakeup.enable = 1;
1052                         lr388k7_send_signal(g_st_state.u32_pid,
1053                                             LR388K7_SIGNAL_CTRL);
1054                 }
1055         }
1056
1057         return ret;
1058 }
1059
1060 static ssize_t lr388k7_ts_wakeup_enable_show(struct device *dev,
1061         struct device_attribute *attr,
1062         char *buf)
1063 {
1064         return sprintf(buf, "wakeup_enable:%s Number of taps:%d\n",
1065                        g_st_dbg.wakeup.enable ?
1066                        "Enabled" : "Disabled",
1067                        g_st_dbg.wakeup.num_tap);
1068 }
1069
1070 #if defined(DEBUG_LR388K7)
1071 static ssize_t lr388k7_ts_check_state_store(struct device *dev,
1072         struct device_attribute *attr,
1073         const char *buf, size_t count)
1074 {
1075         ssize_t ret;
1076         ret = (ssize_t) count;
1077         return ret;
1078 }
1079
1080 static ssize_t lr388k7_ts_check_state_show(struct device *dev,
1081         struct device_attribute *attr,
1082         char *buf)
1083 {
1084         struct lr388k7 *ts = spi_get_drvdata(g_spi);
1085         u8 u8_tx_buf[K7_RD_HEADER_SIZE + 5], u8_rx_buf[K7_RD_HEADER_SIZE + 5];
1086         u8 u8Ret;
1087         u8 u8HWR;
1088         u32 u32RES, u32FWR;
1089         size_t count = 0;
1090
1091         u8_tx_buf[count++] = K7_RD_OPCODE;
1092         u8_tx_buf[count++] = (K7_STATE_CTL_ADDR >> 16) & 0xFF;
1093         u8_tx_buf[count++] = (K7_STATE_CTL_ADDR >>  8) & 0xFF;
1094         u8_tx_buf[count++] = (K7_STATE_CTL_ADDR >>  0) & 0xFF;
1095         u8_tx_buf[count++] = 0x00;
1096
1097         g_st_state.u32SCK = 0;
1098
1099         if (lr388k7_spi_read(u8_tx_buf, u8_rx_buf, count)) {
1100                 u8Ret = u8_rx_buf[K7_RD_HEADER_SIZE];
1101         } else {
1102                 return sprintf(buf, "status :IRQ(%s) Failed to read\n",
1103                        gpio_get_value(ts->gpio_irq) ?
1104                        "High" : "Low"
1105                        );
1106         }
1107
1108         count = 0;
1109         u8_tx_buf[count++] = K7_RD_OPCODE;
1110         u8_tx_buf[count++] = 0x00;
1111         u8_tx_buf[count++] = 0x02;
1112         u8_tx_buf[count++] = 0xAC;
1113         u8_tx_buf[count++] = 0x00;
1114
1115         g_st_state.u32SCK = 0;
1116
1117         if (lr388k7_spi_read(u8_tx_buf, u8_rx_buf, count)) {
1118                 u8HWR = u8_rx_buf[K7_RD_HEADER_SIZE];
1119         } else {
1120                 return sprintf(buf, "status :IRQ(%s) Failed to read\n",
1121                        gpio_get_value(ts->gpio_irq) ?
1122                        "High" : "Low"
1123                        );
1124         }
1125
1126         count = 0;
1127         u8_tx_buf[count++] = K7_RD_OPCODE;
1128         u8_tx_buf[count++] = 0x00;
1129         u8_tx_buf[count++] = 0x02;
1130         u8_tx_buf[count++] = 0xB0;
1131         u8_tx_buf[count++] = 0x00;
1132         u8_tx_buf[count++] = 0x00;
1133         u8_tx_buf[count++] = 0x00;
1134         u8_tx_buf[count++] = 0x00;
1135
1136         g_st_state.u32SCK = 0;
1137
1138         if (lr388k7_spi_read(u8_tx_buf, u8_rx_buf, count)) {
1139                 u32FWR = u8_rx_buf[K7_RD_HEADER_SIZE] |
1140                         u8_rx_buf[K7_RD_HEADER_SIZE + 1] << 8 |
1141                         u8_rx_buf[K7_RD_HEADER_SIZE + 2] << 16 |
1142                         u8_rx_buf[K7_RD_HEADER_SIZE + 3] << 24;
1143         } else {
1144                 return sprintf(buf, "status :IRQ(%s) Failed to read\n",
1145                        gpio_get_value(ts->gpio_irq) ?
1146                        "High" : "Low"
1147                        );
1148         }
1149
1150         count = 0;
1151         u8_tx_buf[count++] = K7_RD_OPCODE;
1152         u8_tx_buf[count++] = 0x00;
1153         u8_tx_buf[count++] = 0x00;
1154         u8_tx_buf[count++] = 0x40;
1155         u8_tx_buf[count++] = 0x00;
1156         u8_tx_buf[count++] = 0x00;
1157         u8_tx_buf[count++] = 0x00;
1158         u8_tx_buf[count++] = 0x00;
1159
1160         g_st_state.u32SCK = 0;
1161
1162         if (lr388k7_spi_read(u8_tx_buf, u8_rx_buf, count)) {
1163                 u32RES = u8_rx_buf[K7_RD_HEADER_SIZE] |
1164                         u8_rx_buf[K7_RD_HEADER_SIZE + 1] << 8 |
1165                         u8_rx_buf[K7_RD_HEADER_SIZE + 2] << 16 |
1166                         u8_rx_buf[K7_RD_HEADER_SIZE + 3] << 24;
1167         } else {
1168                 return sprintf(buf, "status :IRQ(%s) Failed to read\n",
1169                        gpio_get_value(ts->gpio_irq) ?
1170                        "High" : "Low"
1171                        );
1172         }
1173
1174         g_st_state.u32SCK = g_spi->max_speed_hz;
1175
1176         return sprintf(
1177                        buf,
1178                        "IRQ(%s) status=0x%02X, HWRev=%d, FWRev=0x%0X, Res=0x%04X\n",
1179                        gpio_get_value(ts->gpio_irq) ?
1180                        "High" : "Low",
1181                        u8Ret,
1182                        u8HWR,
1183                        u32FWR,
1184                        u32RES
1185                        );
1186 }
1187 #endif
1188
1189 static DEVICE_ATTR(force_cap, 0666, lr388k7_ts_force_cap_show,
1190                         lr388k7_ts_force_cap_store);
1191 static DEVICE_ATTR(dump, 0666, lr388k7_ts_dump_show,
1192                         lr388k7_ts_dump_store);
1193 static DEVICE_ATTR(report_mode, 0640, lr388k7_ts_report_mode_show,
1194                         lr388k7_ts_report_mode_store);
1195 static DEVICE_ATTR(version, 0640,
1196                    lr388k7_ts_version_show,
1197                    lr388k7_ts_version_store);
1198 static DEVICE_ATTR(slowscan_enable, 0640,
1199                    lr388k7_ts_slowscan_enable_show,
1200                    lr388k7_ts_slowscan_enable_store);
1201 static DEVICE_ATTR(wakeup_enable, 0640,
1202                    lr388k7_ts_wakeup_enable_show,
1203                    lr388k7_ts_wakeup_enable_store);
1204 #if defined(DEBUG_LR388K7)
1205 static DEVICE_ATTR(check_state, 0666,
1206                    lr388k7_ts_check_state_show,
1207                    lr388k7_ts_check_state_store);
1208 #endif
1209
1210
1211 static struct attribute *lr388k7_ts_attributes[] = {
1212         &dev_attr_force_cap.attr,
1213         &dev_attr_dump.attr,
1214         &dev_attr_report_mode.attr,
1215         &dev_attr_version.attr,
1216         &dev_attr_slowscan_enable.attr,
1217         &dev_attr_wakeup_enable.attr,
1218 #if defined(DEBUG_LR388K7)
1219         &dev_attr_check_state.attr,
1220 #endif
1221         NULL
1222 };
1223
1224 static const struct attribute_group lr388k7_ts_attr_group = {
1225         .attrs = lr388k7_ts_attributes,
1226 };
1227
1228 static int lr388k7_open(struct input_dev *input)
1229 {
1230         struct lr388k7 *ts = input_get_drvdata(input);
1231
1232         dev_info(&ts->spi->dev, "[ENTER] open\n");
1233
1234         mutex_lock(&ts->mutex);
1235
1236         __lr388k7_enable(ts);
1237
1238         ts->opened = true;
1239
1240         mutex_unlock(&ts->mutex);
1241
1242         dev_info(&ts->spi->dev, "[EXIT] open\n");
1243         return 0;
1244 }
1245
1246 static void lr388k7_close(struct input_dev *input)
1247 {
1248         struct lr388k7 *ts = input_get_drvdata(input);
1249         mutex_lock(&ts->mutex);
1250
1251         __lr388k7_disable(ts);
1252
1253         ts->opened = false;
1254
1255         mutex_unlock(&ts->mutex);
1256 }
1257
1258
1259 #if defined(UDEV_ENABLE)
1260 static void lr388k7_send_udev_event(void *p)
1261 {
1262         struct lr388k7_udev_event *p_udev_event;
1263         char *envp[2];
1264         char *event;
1265
1266         if (!p)
1267                 return;
1268
1269         p_udev_event = kmalloc(
1270                                sizeof(struct lr388k7_udev_event),
1271                                GFP_KERNEL);
1272
1273         if (!p_udev_event)
1274                 return;
1275
1276         if (copy_from_user(p_udev_event,
1277                           p,
1278                           sizeof(struct lr388k7_udev_event))) {
1279                 kfree(p_udev_event);
1280                 return;
1281         }
1282
1283         event = kasprintf(GFP_KERNEL, "TRIGGER=%s", p_udev_event->str);
1284         if (event) {
1285                 envp[0] = event;
1286                 envp[1] = NULL;
1287                 kobject_uevent_env(&lr388k7_ts_miscdev.this_device->kobj,
1288                                    KOBJ_CHANGE,
1289                                    envp);
1290                 kfree(event);
1291         }
1292         kfree(p_udev_event);
1293 }
1294 #endif
1295
1296 #if defined(ACTIVE_ENABLE)
1297 static void lr388k7_active_report(void *p)
1298 {
1299         struct lr388k7_active_report *p_active_report;
1300         struct lr388k7 *ts = spi_get_drvdata(g_spi);
1301         struct input_dev *input_dev = ts->idev_active;
1302         int x, y, z;
1303         int tool = 0;
1304         u8 status;
1305
1306         if (!p)
1307                 return;
1308
1309         /*
1310          * Memory Allocation
1311          */
1312         p_active_report = kmalloc(
1313                                  sizeof(struct lr388k7_active_report),
1314                                  GFP_KERNEL);
1315         if (!p_active_report)
1316                 return;
1317
1318         if (copy_from_user(p_active_report,
1319                            p,
1320                            sizeof(struct lr388k7_active_report))) {
1321                 kfree(p_active_report);
1322                 return;
1323         }
1324
1325         status = p_active_report->status;
1326
1327         /* Get current tool */
1328         if (status & 0x0C)
1329                 tool = BTN_TOOL_RUBBER;
1330         else
1331                 tool = BTN_TOOL_PEN;
1332
1333         if (!status)
1334                 tool = 0; /* Reset */
1335
1336         /* Check if tool changed then notify input subsystem */
1337         if (ts->tool != tool) {
1338                 if (ts->tool) {
1339                         /* Reset old tool state */
1340                         input_report_key(input_dev, BTN_TOUCH, 0);
1341                         input_report_key(input_dev, BTN_STYLUS, 0);
1342                         input_report_abs(input_dev, ABS_PRESSURE, 0);
1343                 }
1344                 input_report_key(input_dev, ts->tool, 0);
1345                 input_sync(input_dev);
1346
1347                 /* Update current*/
1348                 ts->tool = tool;
1349                 if (tool)
1350                         input_report_key(input_dev, tool, 1);
1351         }
1352
1353         if (tool) {
1354                 x = p_active_report->x;
1355                 y = p_active_report->y;
1356                 z = p_active_report->z;
1357
1358                 input_report_abs(input_dev, ABS_X, x);
1359                 input_report_abs(input_dev, ABS_Y, y);
1360                 input_report_abs(input_dev, ABS_PRESSURE, z);
1361                 input_report_key(input_dev, BTN_TOUCH, status & 0x09);
1362                 input_report_key(input_dev, BTN_STYLUS, status & 0x10);
1363                 input_sync(input_dev);
1364         }
1365
1366         kfree(p_active_report);
1367 }
1368 #endif
1369
1370 #if defined(PROTOCOL_A)
1371 static void lr388k7_touch_report(void *p)
1372 {
1373         u8 u8_num, i, u8_num_of_touch;
1374         struct lr388k7_touch_report *p_touch_report;
1375         struct lr388k7 *ts = spi_get_drvdata(g_spi);
1376         struct input_dev *input_dev = ts->idev;
1377         bool b_is_eraser = false;
1378
1379         if (!p)
1380                 return;
1381
1382         /*
1383          * Memory Allocation
1384          */
1385         p_touch_report = kmalloc(
1386                                  sizeof(struct lr388k7_touch_report),
1387                                  GFP_KERNEL);
1388         if (!p_touch_report)
1389                 return;
1390
1391         if (copy_from_user(p_touch_report,
1392                            p,
1393                            sizeof(struct lr388k7_touch_report))) {
1394                 kfree(p_touch_report);
1395                 return;
1396         }
1397
1398         u8_num = p_touch_report->u8_num_of_touch;
1399
1400         if (u8_num == 0) {
1401                 if (ts->b_eraser_active) {
1402                         ts->b_eraser_active = false;
1403                         input_report_key(input_dev, BTN_TOOL_RUBBER, 0);
1404                 }
1405                 input_mt_sync(input_dev);
1406                 input_sync(input_dev);
1407                 kfree(p_touch_report);
1408                 return;
1409         }
1410         u8_num_of_touch = 0;
1411
1412         for (i = 0; i < u8_num; i++) {
1413
1414 #if defined(DEBUG_LR388K7_REPORT)
1415                 dev_info(&g_spi->dev, "ID=%2d, status=%02d, x=%5d, y=%5d, w=%d, h=%d, z=%5d, num=%2d\n",
1416                          p_touch_report->tc[i] . id,
1417                          p_touch_report->tc[i] . status,
1418                          p_touch_report->tc[i] . x,
1419                          p_touch_report->tc[i] . y,
1420                          p_touch_report->tc[i] . width,
1421                          p_touch_report->tc[i] . height,
1422                          p_touch_report->tc[i] . z,
1423                          u8_num
1424                          );
1425 #endif
1426
1427                 if ((p_touch_report->tc[i] . status & 0x80) != 0)
1428                         b_is_eraser = true;
1429                 else
1430                         b_is_eraser = false;
1431
1432                 if (b_is_eraser) {
1433                         input_report_key(input_dev, BTN_TOOL_RUBBER, 1);
1434                         ts->b_eraser_active = true;
1435                 } else if ((p_touch_report->tc[i] . status & 0x7F) <= 3 ||
1436                           (p_touch_report->tc[i] . status & 0x7F) == 8)
1437                         input_report_abs(input_dev,
1438                                          ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
1439                 else if ((p_touch_report->tc[i] . status & 0x7F) <= 7 ||
1440                          (p_touch_report->tc[i] . status & 0x7F) == 12)
1441                         input_report_abs(input_dev,
1442                                          ABS_MT_TOOL_TYPE, MT_TOOL_PEN);
1443                 input_report_abs(input_dev,
1444                                  ABS_MT_TRACKING_ID,
1445                                  p_touch_report->tc[i] .id);
1446                 input_report_abs(input_dev,
1447                                  ABS_MT_POSITION_X,
1448                                  p_touch_report->tc[i] . x);
1449                 input_report_abs(input_dev,
1450                                  ABS_MT_POSITION_Y,
1451                                  p_touch_report->tc[i] . y);
1452                 input_report_abs(input_dev,
1453                                  ABS_MT_PRESSURE,
1454                                  p_touch_report->tc[i] . z);
1455 #if 0
1456                 input_report_abs(input_dev,
1457                                  ABS_MT_TOUCH_MAJOR,
1458                                  p_touch_report->tc[i] .width);
1459                 input_report_abs(input_dev,
1460                                  ABS_MT_TOUCH_MINOR,
1461                                  p_touch_report->tc[i] .height);
1462 #endif
1463                 input_mt_sync(input_dev);
1464                 u8_num_of_touch++;
1465         }
1466         input_sync(input_dev);
1467
1468         kfree(p_touch_report);
1469 }
1470 #else /* PROTOCOL_B */
1471 static void lr388k7_touch_report(void *p)
1472 {
1473         u8 u8_num, i;
1474         struct lr388k7_touch_report *p_touch_report;
1475         struct lr388k7 *ts = spi_get_drvdata(g_spi);
1476         struct input_dev *input_dev = ts->idev;
1477
1478         if (!p)
1479                 return;
1480
1481         /*
1482          * Memory Allocation
1483          */
1484         p_touch_report = kmalloc(
1485                                  sizeof(struct lr388k7_touch_report),
1486                                  GFP_KERNEL);
1487         if (!p_touch_report)
1488                 return;
1489
1490         if (copy_from_user(p_touch_report,
1491                            p,
1492                            sizeof(struct lr388k7_touch_report))) {
1493                 kfree(p_touch_report);
1494                 return;
1495         }
1496
1497         u8_num = p_touch_report->u8_num_of_touch;
1498
1499         for (i = 0; i < u8_num; i++) {
1500
1501 #if defined(DEBUG_LR388K7_REPORT)
1502                 dev_info(&g_spi->dev, "ID=%2d, status=%02d, x=%5d, y=%5d, w=%d, h=%d, z=%5d, num=%2d\n",
1503                          p_touch_report->tc[i] . id,
1504                          p_touch_report->tc[i] . status,
1505                          p_touch_report->tc[i] . x,
1506                          p_touch_report->tc[i] . y,
1507                          p_touch_report->tc[i] . width,
1508                          p_touch_report->tc[i] . height,
1509                          p_touch_report->tc[i] . z,
1510                          u8_num
1511                          );
1512 #endif
1513                 input_mt_slot(input_dev,
1514                               p_touch_report->tc[i] . id);
1515                 if (((p_touch_report->tc[i] . status & 0x7F) == 8) ||
1516                     ((p_touch_report->tc[i] . status & 0x7F) == 12) ||
1517                     ((p_touch_report->tc[i] . status & 0x7F) == 14)) {
1518                         input_mt_report_slot_state(input_dev,
1519                                                    MT_TOOL_FINGER,
1520                                                    false);
1521                         continue;
1522                 }
1523
1524                 if ((p_touch_report->tc[i] . status & 0x7F) <= 3)
1525                         input_report_abs(input_dev,
1526                                          ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
1527                 else if (((p_touch_report->tc[i] . status & 0x7F) <= 7) ||
1528                          ((p_touch_report->tc[i] . status & 0x7F) > 12))
1529                         input_report_abs(input_dev,
1530                                          ABS_MT_TOOL_TYPE, MT_TOOL_PEN);
1531                 input_report_abs(input_dev,
1532                                  ABS_MT_TRACKING_ID,
1533                                  p_touch_report->tc[i] .id);
1534                 input_report_abs(input_dev,
1535                                  ABS_MT_POSITION_X,
1536                                  p_touch_report->tc[i].x);
1537                 input_report_abs(input_dev,
1538                                  ABS_MT_POSITION_Y,
1539                                  p_touch_report->tc[i].y);
1540                 input_report_abs(input_dev,
1541                                  ABS_MT_PRESSURE,
1542                                  p_touch_report->tc[i] . z);
1543         }
1544         input_sync(input_dev);
1545 }
1546 #endif /* #if defined(PROTOCOL_A) */
1547
1548 static int dev_open(struct inode *inode, struct file *filp)
1549 {
1550 #if defined(DEBUG_LR388K7)
1551         dev_info(&g_spi->dev, "dev_open\n");
1552 #endif
1553
1554         return 0;
1555 }
1556
1557 static int dev_release(struct inode *inode, struct file *filp)
1558 {
1559         int ret;
1560 #if defined(DEBUG_LR388K7)
1561         dev_info(&g_spi->dev, "dev_release\n");
1562 #endif
1563         g_st_state.b_is_init_finish = 0;
1564
1565         ret = lr388k7_hardreset(1);
1566
1567         return 0;
1568 }
1569
1570 /**
1571  * @brief lr388k7 spi interface
1572  * @param[in] txbuf command to read data
1573  * @param[in] rxbuf data to be read
1574  * @param[in] len length of data
1575  * @retval TRUE if success, otherwise FALSE
1576  */
1577 static int lr388k7_spi_read(u8 *txbuf, u8 *rxbuf, size_t len)
1578 {
1579         static DEFINE_MUTEX(lock);
1580
1581         int status;
1582         struct spi_message msg;
1583         struct spi_transfer t = {
1584                 .bits_per_word  = 8,
1585                 .tx_buf = txbuf,
1586                 .rx_buf = rxbuf,
1587                 .speed_hz =
1588                 g_st_state.u32SCK == 0 ? 12000000 : g_spi->max_speed_hz,
1589                 /*    .speed_hz           = 18000000, */
1590         };
1591
1592         mutex_lock(&lock);
1593
1594         t.len = len + K7_RD_HEADER_SIZE;
1595
1596         spi_message_init(&msg);
1597         spi_message_add_tail(&t, &msg);
1598         status = spi_sync(g_spi, &msg);
1599
1600         mutex_unlock(&lock);
1601
1602         if (status)
1603                 return false;
1604
1605         return true;
1606 }
1607
1608 static long lr388k7_spi_read_cmd_data(u8 *p, size_t count)
1609 {
1610         u8 *p_tx_buf;
1611         ssize_t status = 0;
1612
1613         /*
1614          * Memory Allocation
1615          */
1616         p_tx_buf = kmalloc(count + K7_RD_HEADER_SIZE, GFP_KERNEL);
1617         if (p_tx_buf == NULL) {
1618                 status = -ENOMEM;
1619                 goto exit_dev_read_cmd_data;
1620         }
1621
1622         /*
1623          * Clear and Set command to read data
1624          */
1625         memset(p_tx_buf, 0, count + K7_RD_HEADER_SIZE);
1626
1627         p_tx_buf[0] = K7_RD_OPCODE;
1628         p_tx_buf[1] = (K7_CMD_DATA_OFFSET >> 16) & 0xFF;
1629         p_tx_buf[2] = (K7_CMD_DATA_OFFSET >>  8) & 0xFF;
1630         p_tx_buf[3] = (K7_CMD_DATA_OFFSET >>  0) & 0xFF;
1631         p_tx_buf[4] = 0x00;
1632
1633         /*
1634          * Read data
1635          */
1636         if (lr388k7_spi_read(p_tx_buf, p, count))
1637                 status = count;
1638         else
1639                 status = -EFAULT;
1640
1641         kfree(p_tx_buf);
1642
1643  exit_dev_read_cmd_data:
1644         return status;
1645 }
1646
1647 static long lr388k7_spi_read_wo_limit(u8 *p, size_t count)
1648 {
1649         u8 *p_buf;
1650         u8 *p_tx_buf;
1651         ssize_t status = 0;
1652
1653         /*
1654          * Memory Allocation
1655          */
1656         p_buf = kmalloc(count + K7_RD_HEADER_SIZE, GFP_KERNEL);
1657         if (p_buf == NULL) {
1658                 status = -ENOMEM;
1659                 goto ext_dev_read_wo_limit;
1660         }
1661
1662         p_tx_buf = kmalloc(count + K7_RD_HEADER_SIZE, GFP_KERNEL);
1663         if (p_tx_buf == NULL) {
1664                 status = -ENOMEM;
1665                 goto ext_dev_read_wo_limit_free;
1666         }
1667
1668         /*
1669          * Clear and Set command to read data
1670          */
1671         memset(p_tx_buf, 0, count + K7_RD_HEADER_SIZE);
1672
1673         if (copy_from_user(p_tx_buf, p, K7_RD_HEADER_SIZE)) {
1674                 status = -EFAULT;
1675                 goto ext_dev_read_wo_limit_free_tx;
1676         }
1677
1678         /*
1679          * Read data
1680          */
1681         if (lr388k7_spi_read(p_tx_buf, p_buf, count)) {
1682                 if (copy_to_user(p, &p_buf[K7_RD_HEADER_SIZE], count)) {
1683                         status = -EFAULT;
1684                         goto ext_dev_read_wo_limit_free_tx;
1685                 }
1686
1687                 status = count;
1688
1689         } else
1690                 status = -EFAULT;
1691
1692  ext_dev_read_wo_limit_free_tx:
1693         kfree(p_tx_buf);
1694  ext_dev_read_wo_limit_free:
1695         kfree(p_buf);
1696  ext_dev_read_wo_limit:
1697         return status;
1698 }
1699
1700 static long lr388k7_spi_read_from_ioctl(u8 *p, size_t count)
1701 {
1702         u8 *p_buf;
1703         u8 *p_tx_buf;
1704         ssize_t status = 0;
1705
1706         /*
1707          * Memory Allocation
1708          */
1709         p_buf = kmalloc(count + K7_RD_HEADER_SIZE, GFP_KERNEL);
1710         if (p_buf == NULL) {
1711                 status = -ENOMEM;
1712                 goto ext_dev_read_from_ioctl;
1713         }
1714
1715         p_tx_buf = kmalloc(count + K7_RD_HEADER_SIZE, GFP_KERNEL);
1716         if (p_tx_buf == NULL) {
1717                 status = -ENOMEM;
1718                 goto ext_dev_read_from_ioctl_free;
1719         }
1720
1721         /*
1722          * Clear and Set command to read data
1723          */
1724         memset(p_tx_buf, 0, count + K7_RD_HEADER_SIZE);
1725
1726         if (copy_from_user(p_tx_buf, p, K7_RD_HEADER_SIZE)) {
1727                 status = -EFAULT;
1728                 goto ext_dev_read_from_ioctl_free_tx;
1729         }
1730
1731         g_st_state.u32SCK = 0;
1732         /*
1733          * Read data
1734          */
1735         if (lr388k7_spi_read(p_tx_buf, p_buf, count)) {
1736                 if (copy_to_user(p, &p_buf[K7_RD_HEADER_SIZE], count)) {
1737                         status = -EFAULT;
1738                         goto ext_dev_read_from_ioctl_free_tx;
1739                 }
1740
1741                 status = count;
1742
1743         } else
1744                 status = -EFAULT;
1745
1746  ext_dev_read_from_ioctl_free_tx:
1747         kfree(p_tx_buf);
1748  ext_dev_read_from_ioctl_free:
1749         kfree(p_buf);
1750  ext_dev_read_from_ioctl:
1751         g_st_state.u32SCK = g_spi->max_speed_hz;
1752         return status;
1753 }
1754
1755 static ssize_t
1756 dev_read(struct file *filp, char __user *buf, size_t count, loff_t *pos)
1757 {
1758 #if 0
1759         u8 *p_buf;
1760         ssize_t status = 0;
1761
1762         p_buf = kmalloc(count + K7_RD_HEADER_SIZE, GFP_KERNEL);
1763         if (!p_buf) {
1764                 status = -ENOMEM;
1765                 goto exit_dev_read;
1766         }
1767
1768         memset(p_buf, 0, count + K7_RD_HEADER_SIZE);
1769
1770         if (copy_from_user(p_buf, buf, K7_RD_HEADER_SIZE)) {
1771                 status = -EFAULT;
1772                 goto exit_dev_read_free;
1773         }
1774
1775         if (lr388k7_spi_read(p_buf, count)) {
1776                 if (copy_to_user(buf, &p_buf[K7_RD_HEADER_SIZE], count)) {
1777                         status = -EFAULT;
1778                         goto exit_dev_read_free;
1779                 }
1780
1781                 status = count;
1782
1783         } else
1784                 status = -EFAULT;
1785
1786  exit_dev_read_free:
1787         kfree(p_buf);
1788  exit_dev_read:
1789         return status;
1790 #else
1791         return 0;
1792 #endif
1793 }
1794
1795 /**
1796  * @brief lr388k7 spi interface
1797  * @param[in] txbuf data to be written
1798  * @param[in] len length of data
1799  * @retval TRUE if success, otherwise FALSE
1800  */
1801 static int lr388k7_spi_write(u8 *txbuf, size_t len)
1802 {
1803         static DEFINE_MUTEX(lock);
1804         int status;
1805
1806         mutex_lock(&lock);
1807
1808         /*It returns zero on succcess,else a negative error code. */
1809         status = spi_write(g_spi, txbuf, len);
1810
1811         mutex_unlock(&lock);
1812
1813         if (status)
1814                 return false;
1815
1816         return true;
1817 }
1818
1819 static u32 lr388k7_get_platform_id(u8 *p)
1820 {
1821         u32 ret;
1822         struct lr388k7 *ts = spi_get_drvdata(g_spi);
1823
1824         ret = copy_to_user(p,
1825                            &ts->platform_id,
1826                            sizeof(ts->platform_id));
1827
1828         return ret;
1829 }
1830
1831 static u32 lr388k7_get_value(u8 *arg, unsigned int index)
1832 {
1833         u32 ret = 0;
1834         switch (index) {
1835         case LR388K7_GET_PLATFORM_ID:
1836                 ret = lr388k7_get_platform_id(arg);
1837                 break;
1838         default:
1839                 ret = -EINVAL;
1840                 break;
1841         }
1842         return ret;
1843 }
1844
1845
1846 static ssize_t
1847 dev_write(struct file *filp, const char __user *buf,
1848                 size_t count, loff_t *pos)
1849 {
1850         u8 *p_buf;
1851         ssize_t status = 0;
1852
1853         p_buf = kmalloc(count, GFP_KERNEL);
1854         if (!p_buf) {
1855                 status = -ENOMEM;
1856                 goto exit_dev_write;
1857         }
1858
1859         if (copy_from_user(p_buf, buf, count)) {
1860                 status = -EFAULT;
1861                 goto exit_dev_write_free;
1862         }
1863
1864         if (lr388k7_spi_write(p_buf, count))
1865                 status = count;
1866         else
1867                 status = -EFAULT;
1868
1869  exit_dev_write_free:
1870         kfree(p_buf);
1871  exit_dev_write:
1872         return status;
1873 }
1874
1875 static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1876 {
1877         long ret = true;
1878         unsigned int index;
1879
1880         index = (cmd >> 16) & 0xFFFF;
1881
1882         switch (cmd & 0xFFFF) {
1883         case LR388K7_IOCTL_TOUCH_REPORT:
1884                 lr388k7_touch_report((void *) arg);
1885                 break;
1886
1887         case LR388K7_IOCTL_READ_REGISTER:
1888                 ret = lr388k7_spi_read_from_ioctl((u8 *) arg, index);
1889                 break;
1890
1891         case LR388K7_IOCTL_READ_WO_LIMIT:
1892                 ret = lr388k7_spi_read_wo_limit((u8 *) arg, index);
1893                 break;
1894
1895         case LR388K7_IOCTL_SET_HAL_PID:
1896                 g_st_state.u32_pid = arg;
1897                 g_st_state.b_is_calc_finish = 1;
1898                 break;
1899
1900         case LR388K7_IOCTL_READ_RAW_DATA:
1901                 ret = lr388k7_queue_read_raw_data((u8 *) arg, index);
1902                 break;
1903
1904         case LR388K7_IOCTL_READ_CMD_DATA:
1905                 ret = lr388k7_cmd_queue_read((u8 *) arg, index);
1906                 break;
1907
1908         case LR388K7_IOCTL_FINISH_CALC:
1909                 g_st_state.b_is_calc_finish = 1;
1910                 break;
1911
1912         case LR388K7_IOCTL_SET_RAW_DATA_SIZE:
1913                 g_u32_raw_data_size = arg;
1914                 break;
1915
1916         case LR388K7_IOCTL_SET_REVISION:
1917                 g_st_state.u16fw_ver = (arg & 0xFFFF0000) >> 16;
1918                 g_st_state.u16module_ver = arg & 0x0000FFFF;
1919
1920                 dev_info(&g_spi->dev, "Version %d.%d.%d\n",
1921                          g_st_state.u16fw_ver,
1922                          K7_DRIVER_VERSION,
1923                          g_st_state.u16module_ver
1924                          );
1925                 break;
1926
1927         case LR388K7_IOCTL_GET_DEBUG_STATUS:
1928                 lr388k7_ts_get_debug_status((u8 *)arg);
1929                 break;
1930
1931         case LR388K7_IOCTL_SET_MODE:
1932                 g_u8_mode = (u8)arg;
1933                 break;
1934
1935         case LR388K7_IOCTL_GET_MODE:
1936                 lr388k7_ts_get_mode((u8 *)arg);
1937                 break;
1938
1939         case LR388K7_IOCTL_RESET:
1940                 ret = lr388k7_hardreset(arg);
1941                 break;
1942
1943         case LR388K7_IOCTL_CLEAR_BUFFER:
1944                 lr388k7_queue_reset();
1945                 g_st_state.b_is_init_finish = arg;
1946                 if (g_st_state.b_is_init_finish)
1947                         lr388k7_send_signal(g_st_state.u32_pid,
1948                                             LR388K7_SIGNAL_MODE);
1949                 break;
1950
1951         case LR388K7_IOCTL_ACTIVE_REPORT:
1952 #if defined(ACTIVE_ENABLE)
1953                 lr388k7_active_report((void *) arg);
1954 #endif
1955                 break;
1956
1957         case LR388K7_IOCTL_GET_VALUE:
1958                 ret = lr388k7_get_value((u8 *)arg, index);
1959                 break;
1960
1961         case LR388K7_IOCTL_SET_CLK_SEL:
1962 #if defined(ACTIVE_ENABLE)
1963                 lr388k7_set_clk_sel((unsigned int)arg);
1964 #endif
1965                 break;
1966
1967         case LR388K7_IOCTL_SET_STATE:
1968                 g_u8_scan = (u8)arg;
1969                 break;
1970
1971 #if defined(UDEV_ENABLE)
1972         case LR388K7_IOCTL_SEND_UDEV:
1973                 lr388k7_send_udev_event((void *)arg);
1974                 break;
1975 #endif
1976
1977         default:
1978                 ret = false;
1979                 break;
1980         }
1981
1982         return ret;
1983 }
1984
1985 static void lr388k7_init_parameter(void)
1986 {
1987         g_u8_mode = K7_DEFAULT_MODE;
1988         g_u8_scan = K7_SCAN_STATE_IDLE;
1989         g_st_state.u32_pid = 0;
1990         g_st_state.b_is_init_finish = false;
1991         g_st_state.b_is_suspended = false;
1992         g_st_state.b_is_reset = false;
1993         g_st_state.u32SCK = 0;
1994         lr388k7_queue_reset();
1995
1996         g_st_dbg.slowscan.enable = 0;
1997         g_st_dbg.slowscan.scan_rate = K7_SLOW_SCAN_60;
1998         g_st_dbg.wakeup.enable = 0;
1999         g_st_dbg.wakeup.num_tap = K7_NUM_TAP_2;
2000         g_st_dbg.u8ForceCap = 0;
2001         g_st_dbg.u8Dump = 0;
2002 }
2003
2004 static void lr388k7_init_ts(void)
2005 {
2006         lr388k7_init_parameter();
2007         memset(&g_st_state, 0, sizeof(struct lr388k7_ts_parameter));
2008
2009         g_st_state.st_wq_k7 = create_singlethread_workqueue("lr388k7_work");
2010         INIT_WORK(&g_st_state.st_work_k7, lr388k7_work_handler);
2011 }
2012
2013 static struct lr388k7_platform_data *lr388k7_parse_dt(struct device *dev,
2014                                                       int irq)
2015 {
2016         struct lr388k7_platform_data *pdata;
2017         struct device_node *np = dev->of_node;
2018         int ret, val, irq_gpio;
2019         const char *str;
2020
2021         pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
2022         if (!pdata)
2023                 return ERR_PTR(-ENOMEM);
2024
2025         pdata->gpio_reset = of_get_named_gpio_flags(np, "reset-gpio", 0, NULL);
2026         if (!gpio_is_valid(pdata->gpio_reset)) {
2027                 dev_err(dev, "Invalid reset-gpio\n");
2028                 return ERR_PTR(-EINVAL);
2029         }
2030         ret = gpio_request(pdata->gpio_reset, "reset-gpio");
2031         if (ret < 0) {
2032                 dev_err(dev, "gpio_request failed\n");
2033                 return ERR_PTR(-EINVAL);
2034         }
2035         gpio_direction_output(pdata->gpio_reset, 0);
2036
2037         ret = of_property_read_u32(np, "interrupts", &irq_gpio);
2038         if (!gpio_is_valid(irq_gpio)) {
2039                 dev_err(dev, "Invalid irq-gpio\n");
2040                 ret = -EINVAL;
2041                 goto exit_release_reset_gpio;
2042         }
2043         ret = gpio_request(irq_gpio, "irq-gpio");
2044         if (ret < 0) {
2045                 dev_err(dev, "irq_request fail\n");
2046                 ret = -EINVAL;
2047                 goto exit_release_reset_gpio;
2048         }
2049         gpio_direction_input(irq_gpio);
2050         pdata->gpio_irq = irq_gpio;
2051
2052         ret = of_property_read_u32(np, "x-max", &val);
2053         if (ret < 0)
2054                 goto exit_release_all_gpio;
2055         pdata->ts_x_max = val;
2056
2057         ret = of_property_read_u32(np, "y-max", &val);
2058         if (ret < 0)
2059                 goto exit_release_all_gpio;
2060         pdata->ts_y_max = val;
2061
2062         ret = of_property_read_u32(np, "z-max", &val);
2063         if (ret < 0)
2064                 goto exit_release_all_gpio;
2065         pdata->ts_pressure_max = val;
2066
2067         ret = of_property_read_u32(np, "touch-num-max", &val);
2068         if (ret < 0)
2069                 goto exit_release_all_gpio;
2070         pdata->ts_touch_num_max = val;
2071
2072         ret = of_property_read_string(np, "name-of-clock", &str);
2073         if (ret < 0)
2074                 goto exit_release_all_gpio;
2075         pdata->name_of_clock = (char *)str;
2076
2077         ret = of_property_read_string(np, "name-of-clock-con", &str);
2078         if (ret < 0)
2079                 goto exit_release_all_gpio;
2080         pdata->name_of_clock_con = (char *)str;
2081
2082 #if defined(ACTIVE_ENABLE)
2083         pdata->gpio_clk_sel = of_get_named_gpio_flags(np,
2084                                                       "clock-sel-gpio",
2085                                                       0,
2086                                                       NULL);
2087         if (!gpio_is_valid(pdata->gpio_clk_sel)) {
2088                 dev_err(dev, "Invalid clock-sel-gpio\n");
2089                 return ERR_PTR(-EINVAL);
2090         }
2091         ret = gpio_request(pdata->gpio_clk_sel, "clock-sel-gpio");
2092         if (ret < 0) {
2093                 dev_err(dev, "gpio_request failed\n");
2094                 return ERR_PTR(-EINVAL);
2095         }
2096         gpio_direction_output(pdata->gpio_clk_sel, 0);
2097 #endif
2098
2099         ret = of_property_read_u32(np, "platform-id", &val);
2100         if (ret < 0)
2101                 goto exit_release_all_gpio;
2102         pdata->platform_id = val;
2103
2104         return pdata;
2105
2106  exit_release_all_gpio:
2107         gpio_free(irq_gpio);
2108  exit_release_reset_gpio:
2109         gpio_free(pdata->gpio_reset);
2110         return ERR_PTR(ret);
2111 }
2112
2113 static int lr388k7_probe(struct spi_device *spi)
2114 {
2115         struct lr388k7_platform_data *pdata;/* = spi->dev.platform_data;*/
2116         struct lr388k7 *ts;
2117         struct input_dev *input_dev;
2118 #if defined(ACTIVE_ENABLE)
2119         struct input_dev *input_dev_active;
2120 #endif
2121         struct device *dev;
2122         int error;
2123
2124         dev = &spi->dev;
2125         dev_info(dev, "[ENTER] probe\n");
2126
2127         lr388k7_init_ts();
2128
2129         g_spi = spi;
2130
2131         if (spi->irq <= 0) {
2132                 dev_dbg(dev, "no irq\n");
2133                 return -ENODEV;
2134         }
2135
2136         spi->mode = SPI_MODE_3;
2137         spi->bits_per_word = 8;
2138         if (!spi->max_speed_hz)
2139                 spi->max_speed_hz = K7_MAX_SPEED_HZ;
2140
2141         error = spi_setup(spi);
2142         if (error)
2143                 return error;
2144
2145         ts = kzalloc(sizeof(*ts), GFP_KERNEL);
2146         input_dev = input_allocate_device();
2147 #if defined(ACTIVE_ENABLE)
2148         input_dev_active = input_allocate_device();
2149         if (!ts || !input_dev || !input_dev_active) {
2150 #else
2151         if (!ts || !input_dev) {
2152 #endif
2153                 error = -ENOMEM;
2154                 goto err_free_mem;
2155         }
2156
2157
2158         ts->spi = spi;
2159         ts->dev = dev;
2160         ts->idev = input_dev;
2161 #if defined(ACTIVE_ENABLE)
2162         ts->idev_active = input_dev_active;
2163 #endif
2164         ts->irq = spi->irq;
2165
2166         if (dev->of_node) {
2167
2168                 dev_info(dev, "DT support\n");
2169                 /* Loading data from DT */
2170                 pdata = lr388k7_parse_dt(dev, spi->irq);
2171                 if (IS_ERR(pdata)) {
2172                         dev_err(dev, "failed to parse device tree\n");
2173                         error = -EINVAL;
2174                         goto err_free_mem;
2175                 }
2176                 dev->platform_data = pdata;
2177         } else {
2178                 /* Non-DT */
2179                 dev_info(dev, "Non-DT\n");
2180         }
2181
2182         pdata = dev->platform_data;
2183
2184         ts->max_num_touch = __min(pdata->ts_touch_num_max, K7_MAX_TOUCH_NUM);
2185         ts->max_x       = pdata->ts_x_max ? : MAX_16BIT;
2186         ts->max_y       = pdata->ts_y_max ? : MAX_16BIT;
2187         ts->max_z       = pdata->ts_pressure_max ? : MAX_16BIT;
2188         ts->swap_xy     = false;
2189         ts->flip_x      = false;
2190         ts->flip_y      = false;
2191         ts->gpio_reset  = pdata->gpio_reset;
2192         ts->gpio_irq  = pdata->gpio_irq;
2193         ts->b_eraser_active = false;
2194 #if defined(ACTIVE_ENABLE)
2195         ts->tool        = 0;
2196         ts->gpio_clk_sel = pdata->gpio_clk_sel;
2197 #endif
2198         ts->platform_id = pdata->platform_id;
2199
2200         mutex_init(&ts->mutex);
2201
2202         spin_lock_init(&ts->lock);
2203
2204         snprintf(ts->phys,
2205                  sizeof(ts->phys),
2206                  "%s/input-ts",
2207                  dev_name(dev));
2208
2209         /* misc */
2210         if (misc_register(&lr388k7_ts_miscdev) != 0) {
2211                 dev_err(dev, "cannot register miscdev\n");
2212                 error = -ENOMEM;
2213                 goto err_free_mem;
2214         }
2215
2216 #if defined(DEBUG_LR388K7)
2217         dev_info(&spi->dev, "Success register miscdev\n");
2218 #endif
2219
2220         if (lr388k7_queue_init()) {
2221                 dev_err(dev, "Cannot allocate queue memory\n");
2222                 error = -ENOMEM;
2223                 goto err_free_mem;
2224         }
2225
2226 #if defined(ACTIVE_ENABLE)
2227         /* Select external clock */
2228         gpio_set_value(ts->gpio_clk_sel, 0);
2229 #endif
2230         /* Reset assert */
2231         gpio_set_value(ts->gpio_reset, 0);
2232         g_st_state.b_is_reset = true;
2233
2234         /* regulator */
2235         ts->regulator_3v3 = devm_regulator_get(&g_spi->dev, "avdd");
2236         if (IS_ERR(ts->regulator_3v3)) {
2237                 dev_err(dev,
2238                         "LR388K7 TS: regulator_get failed: %ld\n",
2239                         PTR_ERR(ts->regulator_3v3));
2240                 return -ENODEV;
2241         }
2242
2243         ts->regulator_1v8 = devm_regulator_get(&g_spi->dev, "dvdd");
2244         if (IS_ERR(ts->regulator_1v8)) {
2245                 dev_err(dev,
2246                         "LR388K7 TS: regulator_get failed: %ld\n",
2247                         PTR_ERR(ts->regulator_1v8));
2248                 return -ENODEV;
2249         }
2250
2251         /* Enable 1v8 first*/
2252         error = regulator_enable(ts->regulator_1v8);
2253         if (error < 0)
2254                 dev_err(dev,
2255                         "LR388K7 TS: regulator enable failed: %d\n",
2256                         error);
2257         usleep_range(5000, 6000);
2258         error = regulator_enable(ts->regulator_3v3);
2259         if (error < 0)
2260                 dev_err(dev,
2261                         "LR388K7 TS: regulator enable failed: %d\n",
2262                         error);
2263
2264         /* clk */
2265         if (pdata->name_of_clock || pdata->name_of_clock_con) {
2266                 ts->clk =
2267                         clk_get_sys(pdata->name_of_clock,
2268                                     pdata->name_of_clock_con);
2269                 if (IS_ERR(ts->clk)) {
2270                         dev_err(dev,
2271                                 "failed to get touch_clk:(%s, %s)\n",
2272                                 pdata->name_of_clock,
2273                                 pdata->name_of_clock_con);
2274                         error = -EINVAL;
2275                         goto err_free_mem;
2276                 }
2277         }
2278
2279         if (ts->clk)
2280                 clk_enable(ts->clk);
2281
2282         input_dev->name = "touch";
2283         input_dev->phys = ts->phys;
2284         input_dev->id.bustype = BUS_SPI;
2285         input_dev->dev.parent = &spi->dev;
2286         __set_bit(EV_SYN, input_dev->evbit);
2287         __set_bit(EV_ABS, input_dev->evbit);
2288         __set_bit(EV_KEY, input_dev->evbit);
2289         __set_bit(KEY_POWER, input_dev->keybit);
2290
2291         if (ts->swap_xy) {
2292                 input_set_abs_params(input_dev,
2293                                      ABS_MT_POSITION_X,
2294                                      0,
2295                                      ts->max_y,
2296                                      0,
2297                                      0);
2298                 input_set_abs_params(input_dev,
2299                                      ABS_MT_POSITION_Y,
2300                                      0,
2301                                      ts->max_x,
2302                                      0,
2303                                      0);
2304         } else {
2305                 input_set_abs_params(input_dev,
2306                                      ABS_MT_POSITION_X,
2307                                      0,
2308                                      ts->max_x,
2309                                      0,
2310                                      0);
2311                 input_set_abs_params(input_dev,
2312                                      ABS_MT_POSITION_Y,
2313                                      0, ts->max_y,
2314                                      0,
2315                                      0);
2316         }
2317         input_set_abs_params(input_dev,
2318                              ABS_MT_PRESSURE,
2319                              0,
2320                              ts->max_z,
2321                              0,
2322                              0);
2323         input_set_abs_params(input_dev,
2324                              ABS_MT_TOOL_TYPE,
2325                              0,
2326                              MT_TOOL_MAX,
2327                              0,
2328                              0);
2329 #if defined(PROTOCOL_A)
2330         __set_bit(BTN_TOOL_RUBBER, input_dev->keybit);
2331
2332         input_set_abs_params(input_dev,
2333                              ABS_MT_TRACKING_ID,
2334                              0,
2335                              ts->max_num_touch,
2336                              0,
2337                              0);
2338 #else /* PROTOCOL B */
2339         error = input_mt_init_slots(input_dev,
2340                                     ts->max_num_touch,
2341                                     0);
2342         if (error) {
2343                 dev_err(dev, "Failed to mt_init_slots err: %d\n", error);
2344                 goto err_free_mem;
2345         }
2346
2347 #endif
2348
2349         input_set_capability(input_dev, EV_MSC, MSC_ACTIVITY);
2350
2351         input_dev->open = lr388k7_open;
2352         input_dev->close = lr388k7_close;
2353         input_dev->enable = lr388k7_input_enable;
2354         input_dev->disable = lr388k7_input_disable;
2355         input_dev->enabled = true;
2356         input_set_drvdata(input_dev, ts);
2357
2358 #if defined(ACTIVE_ENABLE)
2359         input_dev_active->name = "touch_active";
2360         input_dev_active->phys = ts->phys;
2361         input_dev_active->id.bustype = BUS_SPI;
2362         input_dev_active->dev.parent = &spi->dev;
2363
2364         __set_bit(EV_ABS, input_dev_active->evbit);
2365         __set_bit(EV_KEY, input_dev_active->evbit);
2366         __set_bit(INPUT_PROP_POINTER, input_dev_active->propbit);
2367         __set_bit(BTN_TOUCH, input_dev_active->keybit);
2368         __set_bit(BTN_TOOL_PEN, input_dev_active->keybit);
2369         __set_bit(BTN_TOOL_RUBBER, input_dev_active->keybit);
2370         __set_bit(BTN_STYLUS, input_dev_active->keybit);
2371
2372         if (ts->swap_xy) {
2373                 input_set_abs_params(input_dev_active,
2374                                      ABS_X,
2375                                      0,
2376                                      ts->max_y,
2377                                      0,
2378                                      0);
2379                 input_set_abs_params(input_dev_active,
2380                                      ABS_Y,
2381                                      0,
2382                                      ts->max_x,
2383                                      0,
2384                                      0);
2385         } else {
2386                 input_set_abs_params(input_dev_active,
2387                                      ABS_X,
2388                                      0,
2389                                      ts->max_x,
2390                                      0,
2391                                      0);
2392                 input_set_abs_params(input_dev_active,
2393                                      ABS_Y,
2394                                      0, ts->max_y,
2395                                      0,
2396                                      0);
2397         }
2398         input_set_abs_params(input_dev_active,
2399                              ABS_PRESSURE,
2400                              0,
2401                              MAX_10BIT,
2402                              0,
2403                              0);
2404         input_set_drvdata(input_dev_active, ts);
2405 #endif
2406
2407 #if 0
2408         error = request_irq(spi->irq, lr388k7_irq_thread,
2409                             IRQF_TRIGGER_FALLING,
2410                             "lr388k7_ts", ts);
2411 #else
2412         error = request_threaded_irq(spi->irq,
2413                                      lr388k7_irq_thread,
2414                                      lr388k7_wakeup_thread,
2415                                      IRQF_TRIGGER_FALLING,
2416                                      "lr388k7_ts", ts);
2417
2418 #endif
2419
2420         if (error) {
2421                 dev_err(dev, "Failed to request irq, err: %d\n", error);
2422                 goto err_free_mem;
2423         }
2424
2425         lr388k7_disable_irq(ts);
2426
2427         spi_set_drvdata(spi, ts);
2428
2429         error = sysfs_create_link(&dev->kobj,
2430                                   &lr388k7_ts_miscdev.this_device->kobj,
2431                                   "touch");
2432         if (error) {
2433                 dev_err(dev, "failed to create sysfs group\n");
2434                 goto err_clear_drvdata;
2435         }
2436
2437         error = input_register_device(ts->idev);
2438         if (error) {
2439                 dev_err(dev,
2440                         "Failed to register input device, err: %d\n", error);
2441                 goto err_clear_drvdata;
2442         }
2443
2444 #if defined(ACTIVE_ENABLE)
2445         error = input_register_device(ts->idev_active);
2446         if (error) {
2447                 dev_err(dev,
2448                         "Failed to register input active device , err: %d\n",
2449                         error);
2450                 goto err_clear_drvdata;
2451         }
2452 #endif
2453
2454         error = sysfs_create_group(&lr388k7_ts_miscdev.this_device->kobj,
2455                                    &lr388k7_ts_attr_group);
2456         if (error) {
2457                 dev_err(dev, "failed to create sysfs group\n");
2458                 goto err_clear_drvdata;
2459         }
2460
2461         /* Enable async suspend/resume to reduce LP0 latency */
2462         device_enable_async_suspend(dev);
2463
2464         dev_info(dev, "[EXIT] probe\n");
2465         return 0;
2466
2467  err_clear_drvdata:
2468         spi_set_drvdata(spi, NULL);
2469         free_irq(spi->irq, ts);
2470  err_free_mem:
2471 #if defined(ACTIVE_ENABLE)
2472         input_free_device(input_dev_active);
2473 #endif
2474         input_free_device(input_dev);
2475         kfree(ts);
2476         return error;
2477 }
2478
2479 static int lr388k7_remove(struct spi_device *spi)
2480 {
2481         struct lr388k7 *ts = spi_get_drvdata(spi);
2482
2483         lr388k7_queue_free();
2484
2485         if (g_st_state.st_wq_k7)
2486                 destroy_workqueue(g_st_state.st_wq_k7);
2487
2488         sysfs_remove_group(&lr388k7_ts_miscdev.this_device->kobj,
2489                            &lr388k7_ts_attr_group);
2490
2491         sysfs_remove_link(&ts->dev->kobj, "touch");
2492
2493         misc_deregister(&lr388k7_ts_miscdev);
2494         free_irq(ts->spi->irq, ts);
2495
2496         gpio_free(ts->gpio_reset);
2497         gpio_free(ts->gpio_irq);
2498 #if defined(ACTIVE_ENABLE)
2499         gpio_free(ts->gpio_clk_sel);
2500 #endif
2501         input_unregister_device(ts->idev);
2502
2503         kfree(ts);
2504
2505         spi_set_drvdata(spi, NULL);
2506         return 0;
2507 }
2508
2509 static void lr388k7_shutdown(struct spi_device *spi)
2510 {
2511         struct lr388k7 *ts = spi_get_drvdata(spi);
2512
2513         free_irq(ts->irq, ts);
2514
2515         if (ts->regulator_3v3)
2516                 regulator_disable(ts->regulator_3v3);
2517
2518         if (ts->regulator_1v8)
2519                 regulator_disable(ts->regulator_1v8);
2520 }
2521
2522 static void lr388k7_ctrl_resume(struct lr388k7 *ts)
2523 {
2524         u8 u8_buf[5];
2525         size_t count = 0;
2526
2527         u8_buf[count++] = K7_WR_OPCODE;
2528         u8_buf[count++] = (K7_STATE_CTL_ADDR >> 16) & 0xFF;
2529         u8_buf[count++] = (K7_STATE_CTL_ADDR >>  8) & 0xFF;
2530         u8_buf[count++] = (K7_STATE_CTL_ADDR >>  0) & 0xFF;
2531         u8_buf[count++] = K7_POWER_CTL_RESUME;
2532         lr388k7_spi_write(u8_buf, count);
2533 }
2534
2535 static void lr388k7_start(struct lr388k7 *ts)
2536 {
2537         int error;
2538
2539         g_st_state.b_is_suspended = false;
2540
2541         mutex_lock(&ts->mutex);
2542
2543         if (g_st_dbg.wakeup.enable == 1) {
2544                 lr388k7_ctrl_resume(ts);
2545                 mutex_unlock(&ts->mutex);
2546                 return;
2547         }
2548
2549         /* Reset assert */
2550         gpio_set_value(ts->gpio_reset, 0);
2551         g_st_state.b_is_reset = true;
2552
2553         /*
2554          * Enable regulator, if necessary
2555          */
2556         /* Enable 1v8 first*/
2557         error = regulator_enable(ts->regulator_1v8);
2558         if (error < 0)
2559                 dev_err(&g_spi->dev,
2560                         "LR388K7 TS: regulator enable failed: %d\n", error);
2561
2562         error = regulator_enable(ts->regulator_3v3);
2563         if (error < 0)
2564                 dev_err(&g_spi->dev,
2565                         "LR388K7 TS: regulator enable failed: %d\n", error);
2566
2567         usleep_range(5000, 6000);
2568
2569         /*
2570          * Enable clock, if necessary
2571          */
2572         if (ts->clk)
2573                 clk_enable(ts->clk);
2574
2575         /* Reset deassert */
2576         gpio_set_value(ts->gpio_reset, 1);
2577         g_st_state.b_is_reset = false;
2578
2579         usleep_range(12000, 13000);
2580
2581         mutex_unlock(&ts->mutex);
2582 }
2583
2584 static void lr388k7_ctrl_suspend(struct lr388k7 *ts)
2585 {
2586         u8 u8_buf[5];
2587         size_t count = 0;
2588         int error;
2589         u8 u8_status = 0;
2590         int irq_value;
2591
2592         mutex_lock(&ts->mutex);
2593
2594         if (g_st_dbg.wakeup.enable == 1) {
2595                 u8_buf[count++] = K7_WR_OPCODE;
2596                 u8_buf[count++] = (K7_STATE_CTL_ADDR >> 16) & 0xFF;
2597                 u8_buf[count++] = (K7_STATE_CTL_ADDR >>  8) & 0xFF;
2598                 u8_buf[count++] = (K7_STATE_CTL_ADDR >>  0) & 0xFF;
2599                 u8_buf[count++] = K7_POWER_CTL_TAP_WAKEUP;
2600                 lr388k7_spi_write(u8_buf, count);
2601
2602                 irq_value = gpio_get_value(ts->gpio_irq);
2603
2604                 if (!irq_value) {
2605                         u8_status = lr388k7_clear_irq();
2606
2607                         lr388k7_event_handler(u8_status);
2608                 }
2609
2610                 mutex_unlock(&ts->mutex);
2611                 return;
2612         }
2613
2614
2615         /* Disable (3.3V) */
2616         if (ts->regulator_3v3) {
2617                 error = regulator_disable(ts->regulator_3v3);
2618                 if (error < 0)
2619                         dev_err(&g_spi->dev,
2620                                 "lr388k7 regulator 3.3V disable failed: %d\n",
2621                                 error);
2622         }
2623         /* handle platforms w/ and w/out regulator switches */
2624         /* 2) delay for platforms w/ regulator switches */
2625         /* usleep_range(15000, 20000);  */ /*msleep(15); */
2626         /* 3) disable clock */
2627         if (ts->clk)
2628                 clk_disable(ts->clk);
2629         /* 4) disable 1.8 */
2630         if (ts->regulator_1v8 && ts->regulator_3v3) {
2631                 error = regulator_disable(ts->regulator_1v8);
2632                 if (error < 0)
2633                         dev_err(&g_spi->dev,
2634                                 "lr388k7 1.8V disable failed: %d\n",
2635                                 error);
2636         }
2637
2638         mutex_unlock(&ts->mutex);
2639 }
2640
2641 static void lr388k7_stop(struct lr388k7 *ts)
2642 {
2643         flush_workqueue(g_st_state.st_wq_k7);
2644
2645         lr388k7_ctrl_suspend(ts);
2646 }
2647
2648 #ifdef CONFIG_PM
2649 static int lr388k7_suspend(struct device *dev)
2650 {
2651         struct lr388k7 *ts = dev_get_drvdata(dev);
2652
2653         if (g_st_state.b_is_suspended)
2654                 return 0;
2655
2656         lr388k7_disable_irq(ts);
2657
2658         lr388k7_stop(ts);
2659
2660         lr388k7_send_signal(g_st_state.u32_pid, LR388K7_SIGNAL_SLEP);
2661
2662         g_st_state.b_is_suspended = true;
2663
2664         return 0;
2665 }
2666
2667 static int lr388k7_resume(struct device *dev)
2668 {
2669         struct lr388k7 *ts = dev_get_drvdata(dev);
2670         u8 u8_status = 0;
2671         int irq_value;
2672         lr388k7_start(ts);
2673
2674         lr388k7_send_signal(g_st_state.u32_pid, LR388K7_SIGNAL_WAKE);
2675
2676         lr388k7_enable_irq(ts);
2677
2678         if (IS_DBG) {
2679                 g_st_dbg.u8ForceCap = 0;
2680                 g_st_dbg.u8Dump = 0;
2681                 g_st_dbg.slowscan.enable = 0;
2682
2683                 lr388k7_send_signal(g_st_state.u32_pid, LR388K7_SIGNAL_CTRL);
2684         }
2685
2686         if (g_st_dbg.wakeup.enable == 0)
2687                 return 0;
2688
2689         /* check irq */
2690         irq_value = gpio_get_value(ts->gpio_irq);
2691         if (!irq_value) {
2692
2693                 u8_status = lr388k7_clear_irq();
2694
2695                 while (u8_status) {
2696
2697                         lr388k7_event_handler(u8_status);
2698                         irq_value = gpio_get_value(ts->gpio_irq);
2699
2700                         if (!irq_value)
2701                                 u8_status = lr388k7_clear_irq();
2702                         else
2703                                 u8_status = 0;
2704                 }
2705         }
2706
2707         return 0;
2708 }
2709 #endif /*CONFIG_PM */
2710
2711 static int lr388k7_input_enable(struct input_dev *idev)
2712 {
2713         struct lr388k7 *ts = input_get_drvdata(idev);
2714         int err = 0;
2715 #if defined(DEBUG_LR388K7)
2716         dev_info(ts->dev, "[ENTER] input enable\n");
2717 #endif
2718
2719 #ifdef CONFIG_PM
2720         err = lr388k7_resume(ts->dev);
2721 #endif
2722
2723 #if defined(DEBUG_LR388K7)
2724         dev_info(ts->dev, "[EXIT] input enable\n");
2725 #endif
2726         return 0;
2727 }
2728
2729 static int lr388k7_input_disable(struct input_dev *idev)
2730 {
2731         struct lr388k7 *ts = input_get_drvdata(idev);
2732         int err = 0;
2733 #if defined(DEBUG_LR388K7)
2734         dev_info(ts->dev, "[ENTER] input disable\n");
2735 #endif
2736
2737 #ifdef CONFIG_PM
2738         err = lr388k7_suspend(ts->dev);
2739 #endif
2740
2741 #if defined(DEBUG_LR388K7)
2742         dev_info(ts->dev, "[EXIT] input disable\n");
2743 #endif
2744         return 0;
2745 }
2746
2747 #if defined(CONFIG_PM) & !defined(INPUT_ENABLE)
2748 static const struct dev_pm_ops lr388k7_pm_ops = {
2749         .suspend = lr388k7_suspend,
2750         .resume = lr388k7_resume,
2751 };
2752 #endif
2753
2754 static const struct of_device_id lr388k7_ts_match[] = {
2755         { .compatible = "sharp,lr388k7_ts" },
2756         { },
2757 };
2758 MODULE_DEVICE_TABLE(of, lr388k7_ts_match);
2759
2760 static struct spi_driver lr388k7_driver = {
2761         .driver = {
2762                 .name   = "lr388k7_ts",
2763                 .owner  = THIS_MODULE,
2764 #if defined(CONFIG_PM) & !defined(INPUT_ENABLE)
2765                 .pm     = &lr388k7_pm_ops,
2766 #endif
2767                 .of_match_table = lr388k7_ts_match,
2768         },
2769         .probe  = lr388k7_probe,
2770         .remove = lr388k7_remove,
2771         .shutdown = lr388k7_shutdown,
2772 };
2773
2774 module_spi_driver(lr388k7_driver);
2775
2776 MODULE_AUTHOR("Makoto Itsuki <itsuki.makoto@sharp.co.jp>");
2777 MODULE_DESCRIPTION("LR388K7 Touchscreen Driver");
2778 MODULE_LICENSE("GPL");