2 * Export interface in /sys/class/touchpanel for calibration.
\r
4 * Yongle Lai @ Rockchip - 2010-07-26
\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
12 #include "calibration_ts.h"
\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
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
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
29 * TPC driver depended.
\r
31 extern volatile struct adc_point gADPoint;
\r
33 extern volatile int gZvalue[3];
\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
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
66 static ssize_t touch_mode_show(struct class *cls, char *_buf)
\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
77 printk("buf: %s", _buf);
\r
82 static ssize_t touch_mode_store(struct class *cls, const char *_buf, size_t _count)
\r
87 //printk("Read data from Android: %s\n", _buf);
\r
89 for (i = 0; i < 5; i++)
\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
102 //This code is Touch adc simple value
\r
103 static ssize_t touch_adc_show(struct class *cls,char *_buf)
\r
105 printk("ADC show: x=%d y=%d\n", gADPoint.x, gADPoint.y);
\r
107 return sprintf(_buf, "%d,%d\n", gADPoint.x, gADPoint.y);
\r
110 static ssize_t touch_cali_status(struct class *cls, char *_buf)
\r
114 ret = TouchPanelSetCalibration(4, screen_x, screen_y, uncali_x, uncali_y);
\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
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
136 ret = sprintf(_buf, "recovery\n");
\r
139 ret = sprintf(_buf, "fail\n");
\r
143 //printk("Calibration status: _buf=<%s", _buf);
\r
148 static ssize_t touch_pressure(struct class *cls,char *_buf)
\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
155 static struct class *tp_class = NULL;
\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
161 static CLASS_ATTR(pressure, 0666, touch_pressure, NULL);
\r
164 int tp_calib_iface_init(int *x,int *y,int *uncali_x, int *uncali_y)
\r
169 tp_class = class_create(THIS_MODULE, "touchpanel");
\r
170 if (IS_ERR(tp_class))
\r
172 printk("Create class touchpanel failed.\n");
\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
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
189 printk("Auto set calibration successfully.\n");
\r
191 printk("Auto set calibraion failed, reset data again please !");
\r
195 * Create ifaces for TP calibration.
\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
201 ret += class_create_file(tp_class, &class_attr_pressure);
\r
205 printk("Fail to class ifaces for TP calibration.\n");
\r
211 void tp_calib_iface_exit(void)
\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
217 class_remove_file(tp_class, &class_attr_pressure);
\r
219 class_destroy(tp_class);
\r
222 //module_init(tp_calib_iface_init);
\r
223 //module_exit(tp_calib_iface_exit);
\r
225 MODULE_AUTHOR("Yongle Lai");
\r
226 MODULE_DESCRIPTION("XPT2046 TPC driver @ Rockchip");
\r
227 MODULE_LICENSE("GPL");
\r