--- /dev/null
+/*\r
+ * Export interface in /sys/class/touchpanel for calibration.\r
+ *\r
+ * Yongle Lai @ Rockchip - 2010-07-26\r
+ */\r
+#include <linux/kernel.h>\r
+#include <linux/module.h>\r
+#include <linux/init.h>\r
+#include <linux/device.h>\r
+#include <linux/err.h>\r
+\r
+#include "calibration_ts.h"\r
+\r
+/*\r
+ * The sys nodes for touch panel calibration depends on controller's name,\r
+ * such as: /sys/bus/spi/drivers/xpt2046_ts/touchadc\r
+ * If we use another TP controller (not xpt2046_ts), the above path will \r
+ * be unavailable which will cause calibration to be fail.\r
+ *\r
+ * Another choice is: \r
+ * sys/devices/platform/rockchip_spi_master/spi0.0/driver/touchadc\r
+ * this path request the TP controller will be the first device of SPI.\r
+ *\r
+ * To make TP calibration module in Android be universal, we create\r
+ * a class named touchpanel as the path for calibration interfaces.\r
+ */\r
+ \r
+/*\r
+ * TPC driver depended.\r
+ */\r
+extern volatile struct adc_point gADPoint;\r
+#ifdef TS_PRESSURE\r
+extern volatile int gZvalue[3];\r
+#endif\r
+#ifdef CONFIG_TP_1024x600\r
+int screen_x[5] = {50, 974, 50, 974, 512};\r
+int screen_y[5] = {50, 50, 550, 550, 300};\r
+#endif\r
+\r
+#ifdef CONFIG_TP_800x480\r
+int screen_x[5] = { 50, 750, 50, 750, 400};\r
+int screen_y[5] = { 40, 40, 440, 440, 240};\r
+#endif\r
+\r
+int uncali_x[5] = { 0 };\r
+int uncali_y[5] = { 0 };\r
+\r
+int uncali_x_default[5] = { 3735, 301, 3754, 290, 1993 };\r
+int uncali_y_default[5] = { 3442, 3497, 413, 459, 1880 };\r
+\r
+static ssize_t touch_mode_show(struct class *cls, char *_buf)\r
+{\r
+ int count;\r
+ \r
+ count = sprintf(_buf,"TouchCheck:%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
+ uncali_x[0], uncali_y[0],\r
+ uncali_x[1], uncali_y[1],\r
+ uncali_x[2], uncali_y[2],\r
+ uncali_x[3], uncali_y[3],\r
+ uncali_x[4], uncali_y[4]);\r
+\r
+ printk("buf: %s", _buf);\r
+ \r
+ return count;\r
+}\r
+\r
+static ssize_t touch_mode_store(struct class *cls, const char *_buf, size_t _count)\r
+{\r
+ int i, j = 0;\r
+ char temp[5];\r
+\r
+ //printk("Read data from Android: %s\n", _buf);\r
+ \r
+ for (i = 0; i < 5; i++)\r
+ {\r
+ strncpy(temp, _buf + 5 * (j++), 4);\r
+ uncali_x[i] = simple_strtol(temp, NULL, 10);\r
+ strncpy(temp, _buf + 5 * (j++), 4);\r
+ uncali_y[i] = simple_strtol(temp, NULL, 10);\r
+ printk("SN=%d uncali_x=%d uncali_y=%d\n", \r
+ i, uncali_x[i], uncali_y[i]);\r
+ }\r
+\r
+ return _count; \r
+}\r
+\r
+//This code is Touch adc simple value\r
+static ssize_t touch_adc_show(struct class *cls,char *_buf)\r
+{\r
+ printk("ADC show: x=%d y=%d\n", gADPoint.x, gADPoint.y);\r
+ \r
+ return sprintf(_buf, "%d,%d\n", gADPoint.x, gADPoint.y);\r
+}\r
+\r
+static ssize_t touch_cali_status(struct class *cls, char *_buf)\r
+{\r
+ int ret;\r
+ \r
+ ret = TouchPanelSetCalibration(4, screen_x, screen_y, uncali_x, uncali_y);\r
+ if (ret == 1){\r
+ memcpy(uncali_x_default, uncali_x, sizeof(uncali_x));\r
+ memcpy(uncali_y_default, uncali_y, sizeof(uncali_y));\r
+ printk("touch_cali_status-0--%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
+ uncali_x_default[0], uncali_y_default[0],\r
+ uncali_x_default[1], uncali_y_default[1],\r
+ uncali_x_default[2], uncali_y_default[2],\r
+ uncali_x_default[3], uncali_y_default[3],\r
+ uncali_x_default[4], uncali_y_default[4]);\r
+ ret = sprintf(_buf, "successful\n");\r
+ }\r
+ else{\r
+ printk("touchpal calibration failed, use default value.\n");\r
+ ret = TouchPanelSetCalibration(4, screen_x, screen_y, uncali_x_default, uncali_y_default);\r
+ printk("touch_cali_status-1---%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
+ uncali_x_default[0], uncali_y_default[0],\r
+ uncali_x_default[1], uncali_y_default[1],\r
+ uncali_x_default[2], uncali_y_default[2],\r
+ uncali_x_default[3], uncali_y_default[3],\r
+ uncali_x_default[4], uncali_y_default[4]);\r
+ if (ret == 1){\r
+ ret = sprintf(_buf, "recovery\n");\r
+ }\r
+ else{\r
+ ret = sprintf(_buf, "fail\n");\r
+ }\r
+ }\r
+ \r
+ //printk("Calibration status: _buf=<%s", _buf);\r
+ \r
+ return ret;\r
+}\r
+#ifdef TS_PRESSURE\r
+static ssize_t touch_pressure(struct class *cls,char *_buf)\r
+{\r
+ printk("enter %s gADPoint.x==%d,gADPoint.y==%d\n",__FUNCTION__,gADPoint.x,gADPoint.y);\r
+ return sprintf(_buf,"%d,%d,%d\n",gZvalue[0],gZvalue[1],gZvalue[2]);\r
+}\r
+#endif\r
+\r
+static struct class *tp_class = NULL;\r
+\r
+static CLASS_ATTR(touchcheck, 0666, touch_mode_show, touch_mode_store);\r
+static CLASS_ATTR(touchadc, 0666, touch_adc_show, NULL);\r
+static CLASS_ATTR(calistatus, 0666, touch_cali_status, NULL);\r
+#ifdef TS_PRESSURE\r
+static CLASS_ATTR(pressure, 0666, touch_pressure, NULL);\r
+#endif\r
+\r
+static int __init tp_calib_iface_init(void)\r
+{\r
+ int ret = 0;\r
+ int err = 0;\r
+ \r
+ tp_class = class_create(THIS_MODULE, "touchpanel");\r
+ if (IS_ERR(tp_class)) \r
+ {\r
+ printk("Create class touchpanel failed.\n");\r
+ return -ENOMEM;\r
+ }\r
+ \r
+ err = TouchPanelSetCalibration(4, screen_x, screen_y, uncali_x_default, uncali_y_default);\r
+ printk("tp_calib_iface_init---%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n",\r
+ uncali_x_default[0], uncali_y_default[0],\r
+ uncali_x_default[1], uncali_y_default[1],\r
+ uncali_x_default[2], uncali_y_default[2],\r
+ uncali_x_default[3], uncali_y_default[3],\r
+ uncali_x_default[4], uncali_y_default[4]);\r
+ if (err == 1){\r
+ printk("Auto set calibration successfully.\n");\r
+ } else {\r
+ printk("Auto set calibraion failed, reset data again please !");\r
+ }\r
+ \r
+ /*\r
+ * Create ifaces for TP calibration.\r
+ */\r
+ ret = class_create_file(tp_class, &class_attr_touchcheck);\r
+ ret += class_create_file(tp_class, &class_attr_touchadc);\r
+ ret += class_create_file(tp_class, &class_attr_calistatus);\r
+#ifdef TS_PRESSURE\r
+ ret += class_create_file(tp_class, &class_attr_pressure);\r
+#endif\r
+ if (ret)\r
+ {\r
+ printk("Fail to class ifaces for TP calibration.\n");\r
+ }\r
+\r
+ return ret;\r
+}\r
+\r
+static void __exit tp_calib_iface_exit(void)\r
+{\r
+ class_remove_file(tp_class, &class_attr_touchcheck);\r
+ class_remove_file(tp_class, &class_attr_touchadc);\r
+ class_remove_file(tp_class, &class_attr_calistatus);\r
+#ifdef TS_PRESSURE\r
+ class_remove_file(tp_class, &class_attr_pressure);\r
+#endif\r
+ class_destroy(tp_class);\r
+}\r
+\r
+module_init(tp_calib_iface_init);\r
+module_exit(tp_calib_iface_exit);\r
+\r
+MODULE_AUTHOR("Yongle Lai");\r
+MODULE_DESCRIPTION("XPT2046 TPC driver @ Rockchip");\r
+MODULE_LICENSE("GPL");\r