input: touchscreen: add touch screen of gslx680 for rk3399-firefly-edp
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / calib_iface_ts.c
1 /*\r
2  * Export interface in /sys/class/touchpanel for calibration.\r
3  *\r
4  * Yongle Lai @ Rockchip - 2010-07-26\r
5  */\r
6 #include <linux/kernel.h>\r
7 #include <linux/module.h>\r
8 #include <linux/init.h>\r
9 #include <linux/device.h>\r
10 #include <linux/err.h>\r
11 \r
12 #include "calibration_ts.h"\r
13 \r
14 /*\r
15  * The sys nodes for touch panel calibration depends on controller's name,\r
16  * such as: /sys/bus/spi/drivers/xpt2046_ts/touchadc\r
17  * If we use another TP controller (not xpt2046_ts), the above path will \r
18  * be unavailable which will cause calibration to be fail.\r
19  *\r
20  * Another choice is: \r
21  *   sys/devices/platform/rockchip_spi_master/spi0.0/driver/touchadc\r
22  * this path request the TP controller will be the first device of SPI.\r
23  *\r
24  * To make TP calibration module in Android be universal, we create\r
25  * a class named touchpanel as the path for calibration interfaces.\r
26  */\r
27  \r
28 /*\r
29  * TPC driver depended.\r
30  */\r
31 extern volatile struct adc_point gADPoint;\r
32 #ifdef TS_PRESSURE\r
33 extern volatile int gZvalue[3];\r
34 #endif\r
35 \r
36 #if 0\r
37 #if defined(CONFIG_MACH_RK2818INFO_IT50) && defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)\r
38         int screen_x[5] = { 50, 750,  50, 750, 400};\r
39         int screen_y[5] = { 40,  40, 440, 440, 240};\r
40         int uncali_x_default[5] = { 3735,  301, 3754,  290, 1993 };\r
41         int uncali_y_default[5] = {  3442,  3497, 413, 459, 1880 };\r
42 #elif defined(CONFIG_MACH_RK2818INFO) && defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI) \r
43         int screen_x[5] = { 50, 750,  50, 750, 400};\r
44         int screen_y[5] = { 40,  40, 440, 440, 240};\r
45         int uncali_x_default[5] = { 438,  565, 3507,  3631, 2105 };\r
46         int uncali_y_default[5] = {  3756,  489, 3792, 534, 2159 };\r
47 #elif (defined(CONFIG_MACH_RAHO) || defined(CONFIG_MACH_RAHOSDK) || defined(CONFIG_MACH_RK2818INFO))&& defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\r
48         int screen_x[5] = { 50, 270,  50, 270, 160}; \r
49         int screen_y[5] = { 40,  40, 440, 440, 240}; \r
50         int uncali_x_default[5] = { 812,  3341, 851,  3371, 2183 };\r
51         int uncali_y_default[5] = {  442,  435, 3193, 3195, 2004 };\r
52 #elif defined(CONFIG_MACH_Z5) && defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)\r
53         int uncali_x_default[5] = {  3267,  831, 3139, 715, 1845 };\r
54         int uncali_y_default[5] = { 3638,  3664, 564,  591, 2087 };\r
55         int screen_x[5] = { 70,  410, 70, 410, 240};\r
56         int screen_y[5] = { 50, 50,  740, 740, 400};\r
57 #endif\r
58 #endif\r
59 int screen_x[5] = { 0 };\r
60 int screen_y[5] = { 0 };\r
61 int uncali_x_default[5] = { 0 };\r
62 int uncali_y_default[5] = { 0 };\r
63 int uncali_x[5] = { 0 };\r
64 int uncali_y[5] = { 0 };\r
65 \r
66 static ssize_t touch_mode_show(struct class *cls, char *_buf)\r
67 {\r
68     int count;\r
69     \r
70         count = sprintf(_buf,"TouchCheck:%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
71                         uncali_x[0], uncali_y[0],\r
72                         uncali_x[1], uncali_y[1],\r
73                         uncali_x[2], uncali_y[2],\r
74                         uncali_x[3], uncali_y[3],\r
75                         uncali_x[4], uncali_y[4]);\r
76 \r
77         printk("buf: %s", _buf);\r
78                 \r
79         return count;\r
80 }\r
81 \r
82 static ssize_t touch_mode_store(struct class *cls, const char *_buf, size_t _count)\r
83 {\r
84     int i, j = 0;\r
85     char temp[5];\r
86 \r
87     //printk("Read data from Android: %s\n", _buf);\r
88     \r
89     for (i = 0; i < 5; i++)\r
90     {\r
91         strncpy(temp, _buf + 5 * (j++), 4);\r
92         uncali_x[i] = simple_strtol(temp, NULL, 10);\r
93         strncpy(temp, _buf + 5 * (j++), 4);\r
94         uncali_y[i] = simple_strtol(temp, NULL, 10);\r
95         printk("SN=%d uncali_x=%d uncali_y=%d\n", \r
96                 i, uncali_x[i], uncali_y[i]);\r
97     }\r
98 \r
99     return _count; \r
100 }\r
101 \r
102 //This code is Touch adc simple value\r
103 static ssize_t touch_adc_show(struct class *cls,char *_buf)\r
104 {\r
105     printk("ADC show: x=%d y=%d\n", gADPoint.x, gADPoint.y);\r
106     \r
107         return sprintf(_buf, "%d,%d\n", gADPoint.x, gADPoint.y);\r
108 }\r
109 \r
110 static ssize_t touch_cali_status(struct class *cls, char *_buf)\r
111 {\r
112     int ret;\r
113     \r
114     ret = TouchPanelSetCalibration(4, screen_x, screen_y, uncali_x, uncali_y);\r
115     if (ret == 1){\r
116         memcpy(uncali_x_default, uncali_x, sizeof(uncali_x));\r
117         memcpy(uncali_y_default, uncali_y, sizeof(uncali_y));\r
118         printk("touch_cali_status-0--%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
119                         uncali_x_default[0], uncali_y_default[0],\r
120                         uncali_x_default[1], uncali_y_default[1],\r
121                         uncali_x_default[2], uncali_y_default[2],\r
122                         uncali_x_default[3], uncali_y_default[3],\r
123                         uncali_x_default[4], uncali_y_default[4]);\r
124         ret = sprintf(_buf, "successful\n");\r
125     }\r
126     else{\r
127         printk("touchpal calibration failed, use default value.\n");\r
128         ret = TouchPanelSetCalibration(4, screen_x, screen_y, uncali_x_default, uncali_y_default);\r
129         printk("touch_cali_status-1---%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
130                         uncali_x_default[0], uncali_y_default[0],\r
131                         uncali_x_default[1], uncali_y_default[1],\r
132                         uncali_x_default[2], uncali_y_default[2],\r
133                         uncali_x_default[3], uncali_y_default[3],\r
134                         uncali_x_default[4], uncali_y_default[4]);\r
135         if (ret == 1){\r
136                 ret = sprintf(_buf, "recovery\n");\r
137         }\r
138         else{\r
139                 ret = sprintf(_buf, "fail\n");\r
140                 }\r
141     }\r
142     \r
143     //printk("Calibration status: _buf=<%s", _buf);\r
144     \r
145         return ret;\r
146 }\r
147 #ifdef TS_PRESSURE\r
148 static ssize_t touch_pressure(struct class *cls,char *_buf)\r
149 {\r
150         printk("enter %s gADPoint.x==%d,gADPoint.y==%d\n",__FUNCTION__,gADPoint.x,gADPoint.y);\r
151         return sprintf(_buf,"%d,%d,%d\n",gZvalue[0],gZvalue[1],gZvalue[2]);\r
152 }\r
153 #endif\r
154 \r
155 static struct class *tp_class = NULL;\r
156 \r
157 static CLASS_ATTR(touchcheck, 0666, touch_mode_show, touch_mode_store);\r
158 static CLASS_ATTR(touchadc, 0666, touch_adc_show, NULL);\r
159 static CLASS_ATTR(calistatus, 0666, touch_cali_status, NULL);\r
160 #ifdef TS_PRESSURE\r
161 static CLASS_ATTR(pressure, 0666, touch_pressure, NULL);\r
162 #endif\r
163 \r
164 int  tp_calib_iface_init(int *x,int *y,int *uncali_x, int *uncali_y)\r
165 {\r
166     int ret = 0;\r
167     int err = 0;\r
168     \r
169     tp_class = class_create(THIS_MODULE, "touchpanel");\r
170     if (IS_ERR(tp_class)) \r
171     {\r
172         printk("Create class touchpanel failed.\n");\r
173         return -ENOMEM;\r
174     }\r
175     \r
176     memcpy(screen_x,x,5*sizeof(int));\r
177         memcpy(screen_y,y,5*sizeof(int));\r
178         memcpy(uncali_x_default,uncali_x,5*sizeof(int));\r
179         memcpy(uncali_y_default,uncali_y,5*sizeof(int));\r
180         \r
181     err = TouchPanelSetCalibration(4, screen_x, screen_y, uncali_x_default, uncali_y_default);\r
182         printk("tp_calib_iface_init---%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
183                         uncali_x_default[0], uncali_y_default[0],\r
184                         uncali_x_default[1], uncali_y_default[1],\r
185                         uncali_x_default[2], uncali_y_default[2],\r
186                         uncali_x_default[3], uncali_y_default[3],\r
187                         uncali_x_default[4], uncali_y_default[4]);\r
188         if (err == 1){\r
189                 printk("Auto set calibration successfully.\n");\r
190         } else {\r
191                 printk("Auto set calibraion failed, reset data again please !");\r
192         }\r
193     \r
194     /*\r
195          * Create ifaces for TP calibration.\r
196          */\r
197     ret =  class_create_file(tp_class, &class_attr_touchcheck);\r
198     ret += class_create_file(tp_class, &class_attr_touchadc);\r
199     ret += class_create_file(tp_class, &class_attr_calistatus);\r
200 #ifdef TS_PRESSURE\r
201    ret += class_create_file(tp_class, &class_attr_pressure);\r
202 #endif\r
203     if (ret)\r
204     {\r
205         printk("Fail to class ifaces for TP calibration.\n");\r
206     }\r
207 \r
208     return ret;\r
209 }\r
210 \r
211 void tp_calib_iface_exit(void)\r
212 {\r
213     class_remove_file(tp_class, &class_attr_touchcheck);\r
214     class_remove_file(tp_class, &class_attr_touchadc);\r
215     class_remove_file(tp_class, &class_attr_calistatus);\r
216 #ifdef TS_PRESSURE\r
217     class_remove_file(tp_class, &class_attr_pressure);\r
218 #endif\r
219     class_destroy(tp_class);\r
220 }\r
221 \r
222 //module_init(tp_calib_iface_init);\r
223 //module_exit(tp_calib_iface_exit);\r
224 \r
225 MODULE_AUTHOR("Yongle Lai");\r
226 MODULE_DESCRIPTION("XPT2046 TPC driver @ Rockchip");\r
227 MODULE_LICENSE("GPL");\r