input: touchscreen: add touch screen of gslx680 for rk3399-firefly-edp
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / ts_lib / tslib.c
1 /*
2  * tslib/tslib.c
3  *
4  * This file is placed under the LGPL.  Please see the file
5  * COPYING for more details.
6  *
7  */
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/interrupt.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/fcntl.h>
14 #include <linux/delay.h>
15 #include <linux/device.h>
16 //#include <asm/typedef.h>
17 #include <mach/iomux.h>
18 #include <asm/uaccess.h>
19 #include <asm/types.h>
20 #include <asm/io.h>
21 #include <asm/delay.h>
22 #include "tslib.h"
23
24 struct tslib_info *g_tslib_inf = NULL;
25
26 int sqr(int x)
27 {
28         return x * x;
29 }
30
31 int tslib_init(struct tslib_info *info, void *raw_read)
32 {
33         struct tslib_info *tslib_inf = info;
34         struct tslib_variance *var = NULL;
35         struct tslib_dejitter *djt = NULL;
36
37         if(raw_read == NULL)
38                 return -1;
39         
40         memset(tslib_inf, 0, sizeof(struct tslib_info));
41
42         var = kmalloc(sizeof(struct tslib_variance), GFP_KERNEL);
43         if (var == NULL)
44                 goto failed1;
45         memset(var, 0, sizeof(struct tslib_variance));
46
47         djt = kmalloc(sizeof(struct tslib_dejitter), GFP_KERNEL);
48         if (djt == NULL)
49                 goto failed2;
50
51         memset(djt, 0, sizeof(struct tslib_dejitter));
52
53         var->flags = 0;
54         var->delta = sqr(VARIANCE_DELTA);
55
56         djt->head = 0;
57         djt->delta = sqr(DEJITTER_DELTA);
58
59         tslib_inf->raw_read = raw_read;
60         tslib_inf->var = var;
61         tslib_inf->djt = djt;
62
63         g_tslib_inf = tslib_inf;
64
65         return 0;
66         
67 failed2:
68         kfree(var);
69 failed1:
70         return -1;
71 }