summaryrefslogtreecommitdiff
path: root/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts
diff options
context:
space:
mode:
Diffstat (limited to 'ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts')
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Kconfig16
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Makefile33
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyp140_i2c.c1412
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp.h696
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp_fw_upgrade.c993
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/debug.txt3
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.c1094
-rwxr-xr-xANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.h120
8 files changed, 4367 insertions, 0 deletions
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Kconfig b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Kconfig
new file mode 100755
index 00000000..3a8e1de0
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Kconfig
@@ -0,0 +1,16 @@
+#
+# CYP140 capacity touch screen driver configuration
+#
+config TOUCHSCREEN_CYP140
+ tristate "CYPRESS CYP140 I2C Capacitive Touchscreen Input Driver Support"
+ depends on ARCH_WMT
+ default m
+ help
+ Say Y here if you have an WMT based board with touchscreen
+ attached to it.
+
+ If unsure, say N.
+
+ To compile this driver as a module, choose M here: the
+ module will be called s_wmt_ts_cyp140
+
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Makefile b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Makefile
new file mode 100755
index 00000000..46229059
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/Makefile
@@ -0,0 +1,33 @@
+#KERNELDIR=/home/hangyan/android8850/kernel/ANDROID_3.0.8
+KERNELDIR=../../../../
+CROSS = arm_1103_le-
+CC= $(CROSS)gcc
+LD= $(CROSS)ld
+STRIP = $(CROSS)strip
+
+DEBUG = n
+
+# Add your debugging flag (or not) to EXTRA_CFLAGS
+ifeq ($(DEBUG),y)
+# DEBFLAGS = -O -g -DSCULL_DEBUG # "-O" is needed to expand inlines
+DEBFLAGS = -O0 -g -DSCULL_DEBUG # "-O" is needed to expand inlines
+
+else
+ DEBFLAGS = -O2 -Wall
+endif
+
+EXTRA_CFLAGS += $(DEBFLAGS)
+
+
+MY_MODULE_NAME=s_wmt_ts_cyp140
+
+obj-$(CONFIG_TOUCHSCREEN_CYP140) := $(MY_MODULE_NAME).o
+#obj-m := $(MY_MODULE_NAME).o
+$(MY_MODULE_NAME)-objs := cyp140_i2c.o wmt_ts.o cyttsp_fw_upgrade.o
+
+default:
+ $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
+ rm -rf *.o *~ core .depend .*.cmd *.mod.c .tmp_versions *.order *.symvers
+
+clean:
+ rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions *.order *.symvers
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyp140_i2c.c b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyp140_i2c.c
new file mode 100755
index 00000000..ca4717ac
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyp140_i2c.c
@@ -0,0 +1,1412 @@
+/* drivers/input/touchscreen/cyp140_i2c.c
+ * This software is licensed under the terms of the GNU General Public
+ * License version 2, as published by the Free Software Foundation, and
+ * may be copied, distributed, and modified under those terms.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * ZEITEC Semiconductor Co., Ltd
+ * Tel: +886-3-579-0045
+ * Fax: +886-3-579-9960
+ * http://www.zeitecsemi.com
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/input.h>
+#include <linux/platform_device.h>
+#include <linux/jiffies.h>
+#include <linux/io.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#ifdef CONFIG_HAS_EARLYSUSPEND
+#include <linux/earlysuspend.h>
+#endif
+#include <linux/slab.h>
+#include <linux/irq.h>
+#include <linux/errno.h>
+#include <linux/sched.h>
+#include <linux/kthread.h>
+#include <linux/bitops.h>
+
+#include "wmt_ts.h"
+#define TP_POINTS_CNT 5
+#define U8 unsigned char
+//fw update.
+//#include "cyp140_fw.h"
+
+//****************************add for cyp140 2013-1-6
+//extern struct tpd_device *tpd;
+static struct i2c_client *i2c_client = NULL;
+static struct task_struct *thread = NULL;
+
+static DECLARE_WAIT_QUEUE_HEAD(waiter);
+
+#define TPD_DEVICE "cyp140"
+static int tpd_load_status = 0;//add !!!2013-1-6
+//static struct early_suspend early_suspend;
+
+#ifdef CONFIG_HAS_EARLYSUSPEND
+static struct early_suspend early_suspend;
+static void tpd_early_suspend(struct early_suspend *handler);
+static void tpd_late_resume(struct early_suspend *handler);
+#endif
+
+static int tilt = 1, rev_x = -1, rev_y = 1;
+static int max_x = 1024, max_y = 600;
+//static int max_x = 800, max_y = 480;
+
+//extern void mt65xx_eint_unmask(unsigned int line);
+//extern void mt65xx_eint_mask(unsigned int line);
+//extern void mt65xx_eint_set_hw_debounce(kal_uint8 eintno, kal_uint32 ms);
+//extern kal_uint32 mt65xx_eint_set_sens(kal_uint8 eintno, kal_bool sens);
+//extern mt65xx_eint_set_polarity(unsigned int eint_num, unsigned int pol);
+//extern void mt65xx_eint_registration(kal_uint8 eintno, kal_bool Dbounce_En,
+ // kal_bool ACT_Polarity, void (EINT_FUNC_PTR)(void),
+ // kal_bool auto_umask);
+
+
+static irqreturn_t tpd_eint_interrupt_handler(int irq, void *dev_id);
+//static int tpd_get_bl_info(int show);
+static int __devinit tpd_probe(struct i2c_client *client);
+//static int tpd_detect(struct i2c_client *client, int kind, struct i2c_board_info *info);
+//static int __devexit tpd_remove(struct i2c_client *client);
+static int touch_event_handler(void *unused);
+//static int tpd_initialize(struct i2c_client * client);
+
+
+volatile static int tpd_flag = 0;//0; debug 2013-5-6
+
+#ifdef TPD_HAVE_BUTTON
+static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS;
+static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM;
+#endif
+
+#define TPD_OK 0
+//#define TPD_EREA_Y 799
+//#define TPD_EREA_X 479
+#define TPD_EREA_Y 479
+#define TPD_EREA_X 319
+
+#define TPD_DISTANCE_LIMIT 100
+
+#define TPD_REG_BASE 0x00
+#define TPD_SOFT_RESET_MODE 0x01
+#define TPD_OP_MODE 0x00
+#define TPD_LOW_PWR_MODE 0x04
+#define TPD_SYSINFO_MODE 0x10
+#define GET_HSTMODE(reg) ((reg & 0x70) >> 4) // in op mode or not
+#define GET_BOOTLOADERMODE(reg) ((reg & 0x10) >> 4) // in bl mode
+//#define GPIO_CTP_EN_PIN_M_GPIO 0
+//#define GPIO_CTP_EN_PIN 0xff
+
+static u8 bl_cmd[] = {
+ 0x00, 0x00, 0xFF, 0xA5,
+ 0x00, 0x01, 0x02,
+ 0x03, 0x04, 0x05,
+ 0x06, 0x07};
+//exit bl mode
+struct tpd_operation_data_t{
+ U8 hst_mode;
+ U8 tt_mode;
+ U8 tt_stat;
+
+ U8 x1_M,x1_L;
+ U8 y1_M,y1_L;
+ U8 x5_M;
+ U8 touch12_id;
+
+ U8 x2_M,x2_L;
+ U8 y2_M,y2_L;
+ U8 x5_L;
+ U8 gest_cnt;
+ U8 gest_id;
+ //U8 gest_set;
+
+
+ U8 x3_M,x3_L;
+ U8 y3_M,y3_L;
+ U8 y5_M;
+ U8 touch34_id;
+
+ U8 x4_M,x4_L;
+ U8 y4_M,y4_L;
+ U8 y5_L;
+
+ //U8 x5_M,x5_L;
+ U8 Undefinei1B;
+ U8 Undefined1C;
+ U8 Undefined1D;
+ U8 GEST_SET;
+ U8 touch5_id;
+};
+
+struct tpd_bootloader_data_t{
+ U8 bl_file;
+ U8 bl_status;
+ U8 bl_error;
+ U8 blver_hi,blver_lo;
+ U8 bld_blver_hi,bld_blver_lo;
+
+ U8 ttspver_hi,ttspver_lo;
+ U8 appid_hi,appid_lo;
+ U8 appver_hi,appver_lo;
+
+ U8 cid_0;
+ U8 cid_1;
+ U8 cid_2;
+
+};
+
+struct tpd_sysinfo_data_t{
+ U8 hst_mode;
+ U8 mfg_cmd;
+ U8 mfg_stat;
+ U8 cid[3];
+ u8 tt_undef1;
+
+ u8 uid[8];
+ U8 bl_verh;
+ U8 bl_verl;
+
+ u8 tts_verh;
+ u8 tts_verl;
+
+ U8 app_idh;
+ U8 app_idl;
+ U8 app_verh;
+ U8 app_verl;
+
+ u8 tt_undef2[6];
+ U8 act_intrvl;
+ U8 tch_tmout;
+ U8 lp_intrvl;
+
+};
+
+struct touch_info {
+ int x[5];
+ int y[5];
+ int p[5];
+ int id[5];
+ int count;
+};
+
+struct id_info{
+ int pid1;
+ int pid2;
+ int reportid1;
+ int reportid2;
+ int id1;
+ int id2;
+
+};
+static struct tpd_operation_data_t g_operation_data;
+//static struct tpd_bootloader_data_t g_bootloader_data;
+//static struct tpd_sysinfo_data_t g_sysinfo_data;
+
+//********************************************************
+
+/* -------------- global variable definition -----------*/
+#define _MACH_MSM_TOUCH_H_
+
+#define ZET_TS_ID_NAME "cyp140-ts"
+
+#define MJ5_TS_NAME "cyp140_touchscreen"
+
+//#define TS_INT_GPIO S3C64XX_GPN(9) /*s3c6410*/
+//#define TS1_INT_GPIO AT91_PIN_PB17 /*AT91SAM9G45 external*/
+//#define TS1_INT_GPIO AT91_PIN_PA27 /*AT91SAM9G45 internal*/
+//#define TS_RST_GPIO S3C64XX_GPN(10)
+
+#define TS_RST_GPIO
+#define TPINFO 1
+#define X_MAX 800 //1024
+#define Y_MAX 480 //576
+#define FINGER_NUMBER 5
+#define KEY_NUMBER 3 //0
+#define P_MAX 1
+#define D_POLLING_TIME 25000
+#define U_POLLING_TIME 25000
+#define S_POLLING_TIME 100
+#define REPORT_POLLING_TIME 5
+
+#define MAX_KEY_NUMBER 8
+#define MAX_FINGER_NUMBER 16
+#define TRUE 1
+#define FALSE 0
+
+//#define debug_mode 1
+//#define DPRINTK(fmt,args...) do { if (debug_mode) printk(KERN_EMERG "[%s][%d] "fmt"\n", __FUNCTION__, __LINE__, ##args);} while(0)
+
+//#define TRANSLATE_ENABLE 1
+#define TOPRIGHT 0
+#define TOPLEFT 1
+#define BOTTOMRIGHT 2
+#define BOTTOMLEFT 3
+#define ORIGIN BOTTOMRIGHT
+
+#define TIME_CHECK_CHARGE 3000
+
+struct msm_ts_platform_data {
+ unsigned int x_max;
+ unsigned int y_max;
+ unsigned int pressure_max;
+};
+
+struct tpd_device{
+ struct i2c_client * client;//i2c_ts;
+ struct work_struct work1;
+ struct input_dev *input;
+ struct timer_list polling_timer;
+ struct delayed_work work; // for polling
+ struct workqueue_struct *queue;
+#ifdef CONFIG_HAS_EARLYSUSPEND
+ struct early_suspend early_suspend;
+#endif
+ unsigned int gpio; /* GPIO used for interrupt of TS1*/
+ unsigned int irq;
+ unsigned int x_max;
+ unsigned int y_max;
+ unsigned int pressure_max;
+};
+//
+struct tpd_device *tpd;
+
+
+//static int l_suspend = 0; // 1:suspend, 0:normal state
+
+//static int resetCount = 0; //albert++ 20120807
+
+
+//static u16 polling_time = S_POLLING_TIME;
+
+//static int l_powermode = -1;
+//static struct mutex i2c_mutex;
+
+
+//static int __devinit cyp140_ts_probe(struct i2c_client *client, const struct i2c_device_id *id);
+//static int __devexit cyp140_ts_remove(struct i2c_client *dev);
+
+
+
+
+
+//static int filterCount = 0;
+//static u32 filterX[MAX_FINGER_NUMBER][2], filterY[MAX_FINGER_NUMBER][2];
+
+//static u8 key_menu_pressed = 0x1;
+//static u8 key_back_pressed = 0x1;
+//static u8 key_search_pressed = 0x1;
+
+//static u16 ResolutionX=X_MAX;
+//static u16 ResolutionY=Y_MAX;
+//static u16 FingerNum=0;
+//static u16 KeyNum=0;
+//static int bufLength=0;
+//static u8 xyExchange=0;
+//static u16 inChargerMode = 0;
+//static struct i2c_client *this_client;
+struct workqueue_struct *ts_wq = NULL;
+#if 0
+static int l_tskey[4][2] = {
+ {KEY_BACK,0},
+ {KEY_MENU,0},
+ {KEY_HOME,0},
+ {KEY_SEARCH,0},
+};
+#endif
+u8 pc[8];
+// {IC Model, FW Version, FW version,Codebase Type=0x08, Customer ID, Project ID, Config Board No, Config Serial No}
+
+//Touch Screen
+/*static const struct i2c_device_id cyp140_ts_idtable[] = {
+ { ZET_TS_ID_NAME, 0 },
+ { }
+};
+
+static struct i2c_driver cyp140_ts_driver = {
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = ZET_TS_ID_NAME,
+ },
+ .probe = cyp140_ts_probe,
+ .remove = __devexit_p(cyp140_ts_remove),
+ .id_table = cyp140_ts_idtable,
+};
+*/
+
+
+/***********************************************************************
+ [function]:
+ callback: Timer Function if there is no interrupt fuction;
+ [parameters]:
+ arg[in]: arguments;
+ [return]:
+ NULL;
+************************************************************************/
+
+
+//extern int wmt_i2c_xfer_continue_if_4(struct i2c_msg *msg, unsigned int num,int bus_id);
+/***********************************************************************
+ [function]:
+ callback: read data by i2c interface;
+ [parameters]:
+ client[in]: struct i2c_client — represent an I2C slave device;
+ data [out]: data buffer to read;
+ length[in]: data length to read;
+ [return]:
+ Returns negative errno, else the number of messages executed;
+************************************************************************/
+int cyp140_i2c_read_tsdata(struct i2c_client *client, u8 *data, u8 length)
+{
+ struct i2c_msg msg;
+ msg.addr = client->addr;
+ msg.flags = I2C_M_RD;
+ msg.len = length;
+ msg.buf = data;
+ return i2c_transfer(client->adapter,&msg, 1);
+
+ /*int rc = 0;
+
+ memset(data, 0, length);
+ rc = i2c_master_recv(client, data, length);
+ if (rc <= 0)
+ {
+ errlog("error!\n");
+ return -EINVAL;
+ } else if (rc != length)
+ {
+ dbg("want:%d,real:%d\n", length, rc);
+ }
+ return rc;*/
+}
+
+/***********************************************************************
+ [function]:
+ callback: write data by i2c interface;
+ [parameters]:
+ client[in]: struct i2c_client — represent an I2C slave device;
+ data [out]: data buffer to write;
+ length[in]: data length to write;
+ [return]:
+ Returns negative errno, else the number of messages executed;
+************************************************************************/
+int cyp140_i2c_write_tsdata(struct i2c_client *client, u8 *data, u8 length)
+{
+ struct i2c_msg msg;
+ msg.addr = client->addr;
+ msg.flags = 0;
+ msg.len = length;
+ msg.buf = data;
+ return i2c_transfer(client->adapter,&msg, 1);
+
+ /*int ret = i2c_master_recv(client, data, length);
+ if (ret <= 0)
+ {
+ errlog("error!\n");
+ }
+ return ret;
+ */
+}
+
+/***********************************************************************
+ [function]:
+ callback: coordinate traslating;
+ [parameters]:
+ px[out]: value of X axis;
+ py[out]: value of Y axis;
+ p [in]: pressed of released status of fingers;
+ [return]:
+ NULL;
+************************************************************************/
+void touch_coordinate_traslating(u32 *px, u32 *py, u8 p)
+{
+ int i;
+ u8 pressure;
+
+ #if ORIGIN == TOPRIGHT
+ for(i=0;i<MAX_FINGER_NUMBER;i++){
+ pressure = (p >> (MAX_FINGER_NUMBER-i-1)) & 0x1;
+ if(pressure)
+ {
+ px[i] = X_MAX - px[i];
+ }
+ }
+ #elif ORIGIN == BOTTOMRIGHT
+ for(i=0;i<MAX_FINGER_NUMBER;i++){
+ pressure = (p >> (MAX_FINGER_NUMBER-i-1)) & 0x1;
+ if(pressure)
+ {
+ px[i] = X_MAX - px[i];
+ py[i] = Y_MAX - py[i];
+ }
+ }
+ #elif ORIGIN == BOTTOMLEFT
+ for(i=0;i<MAX_FINGER_NUMBER;i++){
+ pressure = (p >> (MAX_FINGER_NUMBER-i-1)) & 0x1;
+ if(pressure)
+ {
+ py[i] = Y_MAX - py[i];
+ }
+ }
+ #endif
+}
+
+/***********************************************************************
+ [function]:
+ callback: reset function;
+ [parameters]:
+ void;
+ [return]:
+ void;
+************************************************************************/
+void ctp_reset(void)
+{
+#if defined(TS_RST_GPIO)
+ //reset mcu
+ /* gpio_direction_output(TS_RST_GPIO, 1);
+ msleep(1);
+ gpio_direction_output(TS_RST_GPIO, 0);
+ msleep(10);
+ gpio_direction_output(TS_RST_GPIO, 1);
+ msleep(20);*/
+ wmt_rst_output(1);
+ msleep(1);
+ wmt_rst_output(0);
+ msleep(10);
+ wmt_rst_output(1);
+ msleep(20);
+ dbg("has done\n");
+#else
+ u8 ts_reset_cmd[1] = {0xb0};
+ cyp140_i2c_write_tsdata(this_client, ts_reset_cmd, 1);
+#endif
+
+}
+
+//*************************************************
+#if 1
+#include <linux/sched.h> //wake_up_process()
+#include <linux/kthread.h> //kthread_create()、kthread_run()
+//#include <err.h> //IS_ERR()、PTR_ERR()
+
+void cyttsp_sw_reset(void);
+//static struct task_struct *esd_task;
+volatile bool need_rst_flag = 0;
+volatile int tp_interrupt_flag = 0;
+volatile int tp_suspend_flag = 0;
+volatile int tp_reseting_flag = 0;
+
+void cyttsp_print_reg(struct i2c_client *client)
+{
+#if 1
+ char buffer[20];
+ int status=0;
+ int i;
+
+ status = i2c_smbus_read_i2c_block_data(i2c_client, 0x00, 16, &(buffer[0]));
+
+ printk("++++cyttsp_print_reg=%d: ",status);
+ for(i = 0; i<16;i++)
+ printk(" %02x", buffer[i]);
+ printk("\n");
+#endif
+
+}
+
+int exit_boot_mode(void)
+{
+
+ //int retval = TPD_OK;
+
+ char buffer[2];
+ int status=0;
+ status = i2c_smbus_read_i2c_block_data(i2c_client, 0x01, 1, &(buffer[0]));
+ if(status<0) {
+ printk ("++++exit_boot_mode failed---1\n");
+ return status;
+ }
+ else
+ {
+ if(buffer[0] & 0x10)
+ {
+ status = i2c_master_send(i2c_client, bl_cmd, 12);
+ if( status < 0)
+ {
+ printk ("++++exit_boot_mode failed---2\n");
+ return status;
+ }
+ else
+ {
+ //printk("++++exit_boot_mode ok\n");
+ }
+ msleep(300);
+ status = i2c_smbus_read_i2c_block_data(i2c_client, 0x01, 1, &(buffer[0]));
+ if(status<0) {
+ printk ("++++exit_boot_mode set failed\n");
+ return status;
+ }
+// printk("++++exit_boot_mode set: 0x%x\n",buffer[0]);
+ cyttsp_print_reg(i2c_client);
+ }
+ else
+ {
+ // printk("++++exit_boot_mode-- not in bootmode\n");
+ }
+
+ }
+ return 0;
+
+}
+
+void esd_check(void)
+{
+ if(need_rst_flag)
+ {
+ if(tp_suspend_flag == 0)
+ {
+ printk("++++esd_check---rst\n");
+ //mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
+ tp_reseting_flag = 1;
+ cyttsp_sw_reset();
+ tp_reseting_flag = 0;
+ //mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
+ }
+ need_rst_flag = 0;
+ }
+}
+static int fp_count = 0;
+#if 0 //close 2013-1-6
+void esd_thread(void)
+{
+ static int i = 0, j = 0;
+ while(1)
+ {
+ printk("++++esd_thread, need_rst_flag=%d, fp_count=%d\n", need_rst_flag,fp_count);
+ fp_count = 0;
+ if(need_rst_flag)
+ {
+ j = 0;
+ while(tp_interrupt_flag==1 && j<200) //wujinyou
+ {
+ j ++;
+ if(tp_suspend_flag)
+ msleep(1000);
+ else
+ msleep(10);
+ }
+ if(tp_suspend_flag == 0)
+ {
+ printk("++++esd_thread, start reset, mask int\n");
+ //mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
+ tp_reseting_flag = 1;
+ cyttsp_sw_reset();
+ i = 0;
+ need_rst_flag = 0;
+ tp_reseting_flag = 0;
+ //mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
+ }
+ }
+ msleep(1000);
+ i ++;
+ if(i == 10)
+ {
+ i = 0;
+ //cyttsp_sw_reset();
+ //need_rst_flag = 1;
+ }
+ }
+}
+static int esd_init_thread(void)
+{
+ int err;
+ printk("++++%s, line %d----\n", __FUNCTION__, __LINE__);
+
+ esd_task = kthread_create(esd_thread, NULL, "esd_task");
+
+ if(IS_ERR(esd_task)){
+ printk("++++Unable to start kernel thread.\n");
+ err = PTR_ERR(esd_task);
+ esd_task = NULL;
+ return err;
+ }
+
+ wake_up_process(esd_task);
+
+ return 0;
+
+}
+#endif //close 2013-1-6
+
+#endif
+
+static void tpd_down(int x, int y, int p) {
+
+
+ //printk("<<<<<<x,y (%d, %d)\n", x, y);//debug 2013-5-6
+
+//printk("++++tpd_down: %d,%d,%d\n", x, y, p);
+#if 0 //def TPD_HAVE_BUTTON
+ if (boot_mode != NORMAL_BOOT) {
+ if(y > 480) {
+ tpd_button(x, y, 1);
+ }
+ }
+#endif
+ //*****here process x y coord and then report!!!! 2013-1-7
+
+#if 1//0
+ int tmp;
+ if (tilt)
+ {
+ tmp = x;
+ x = y;
+ y =tmp;
+ }
+ if (rev_x < 0)
+ x = max_x -x;
+ if (rev_y < 0)
+ y = max_y -y;
+
+
+#endif
+ if (wmt_ts_get_lcdexchg()) {
+ int t;
+ t = x;
+ x = y;
+ y = max_x - t;
+ }
+
+ //printk("<<<<<< transfer x,y (%d, %d)\n", x, y);//debug 2013-5-6
+
+ input_report_abs(tpd->input, ABS_PRESSURE,p);
+ input_report_key(tpd->input, BTN_TOUCH, 1);
+ //input_report_abs(tpd->input,ABS_MT_TRACKING_ID,i);
+ input_report_abs(tpd->input, ABS_MT_TOUCH_MAJOR, 1);
+ input_report_abs(tpd->input, ABS_MT_POSITION_X, x);
+ input_report_abs(tpd->input, ABS_MT_POSITION_Y, y);
+ ////TPD_DEBUG("Down x:%4d, y:%4d, p:%4d \n ", x, y, p);
+ input_mt_sync(tpd->input);
+ //TPD_DOWN_DEBUG_TRACK(x,y);
+ fp_count ++;
+}
+
+static void tpd_up(int x, int y,int p) {
+
+ input_report_abs(tpd->input, ABS_PRESSURE, 0);
+ input_report_key(tpd->input, BTN_TOUCH, 0);
+ // input_report_abs(tpd->input,ABS_MT_TRACKING_ID,i);
+ input_report_abs(tpd->input, ABS_MT_TOUCH_MAJOR, 0);
+ //input_report_abs(tpd->input, ABS_MT_POSITION_X, x);
+ //input_report_abs(tpd->input, ABS_MT_POSITION_Y, y); //!!!!
+ //TPD_DEBUG("Up x:%4d, y:%4d, p:%4d \n", x, y, 0);
+ input_mt_sync(tpd->input);
+ // TPD_UP_DEBUG_TRACK(x,y);
+}
+void test_retval(s32 ret)
+{
+#if 1
+ if(ret<0)
+ {
+ need_rst_flag = 1;
+ printk("++++test_retval=1-------\n");
+ }
+#endif
+}
+static int tpd_touchinfo(struct touch_info *cinfo, struct touch_info *pinfo)
+{
+
+ s32 retval;
+ static u8 tt_mode;
+ //pinfo->count = cinfo->count;
+ u8 data0,data1;
+
+ memcpy(pinfo, cinfo, sizeof(struct touch_info));
+ memset(cinfo, 0, sizeof(struct touch_info));
+// printk("pinfo->count =%d\n",pinfo->count);
+
+ retval = i2c_smbus_read_i2c_block_data(i2c_client, TPD_REG_BASE, 8, (u8 *)&g_operation_data);
+ retval += i2c_smbus_read_i2c_block_data(i2c_client, TPD_REG_BASE + 8, 8, (((u8 *)(&g_operation_data)) + 8));
+ retval += i2c_smbus_read_i2c_block_data(i2c_client, TPD_REG_BASE + 16, 8, (((u8 *)(&g_operation_data)) + 16));
+ retval += i2c_smbus_read_i2c_block_data(i2c_client, TPD_REG_BASE + 24, 8, (((u8 *)(&g_operation_data)) + 24));
+
+
+ //cyttsp_print_reg(i2c_client);
+ ////TPD_DEBUG("received raw data from touch panel as following:\n");
+
+ /*("hst_mode = %02X, tt_mode = %02X, tt_stat = %02X\n", \
+ g_operation_data.hst_mode,\
+ g_operation_data.tt_mode,\
+ g_operation_data.tt_stat); */
+
+ cinfo->count = (g_operation_data.tt_stat & 0x0f) ; //point count
+
+ //TPD_DEBUG("cinfo->count =%d\n",cinfo->count);
+
+ //TPD_DEBUG("Procss raw data...\n");
+
+ cinfo->x[0] = (( g_operation_data.x1_M << 8) | ( g_operation_data.x1_L)); //point 1
+ cinfo->y[0] = (( g_operation_data.y1_M << 8) | ( g_operation_data.y1_L));
+ cinfo->p[0] = 0;//g_operation_data.z1;
+
+ //printk("Before: cinfo->x0 = %3d, cinfo->y0 = %3d, cinfo->p0 = %3d cinfo->id0 = %3d\n", cinfo->x[0] ,cinfo->y[0] ,cinfo->p[0], cinfo->id[0]);
+ if(cinfo->x[0] < 1) cinfo->x[0] = 1;
+ if(cinfo->y[0] < 1) cinfo->y[0] = 1;
+ cinfo->id[0] = ((g_operation_data.touch12_id & 0xf0) >>4) -1;
+ //printk("After: cinfo->x0 = %3d, cinfo->y0 = %3d, cinfo->p0 = %3d cinfo->id0 = %3d\n", cinfo->x[0] ,cinfo->y[0] ,cinfo->p[0], cinfo->id[0]);
+
+ if(cinfo->count >1)
+ {
+ cinfo->x[1] = (( g_operation_data.x2_M << 8) | ( g_operation_data.x2_L)); //point 2
+ cinfo->y[1] = (( g_operation_data.y2_M << 8) | ( g_operation_data.y2_L));
+ cinfo->p[1] = 0;//g_operation_data.z2;
+
+ //printk("before: cinfo->x2 = %3d, cinfo->y2 = %3d, cinfo->p2 = %3d\n", cinfo->x2, cinfo->y2, cinfo->p2);
+ if(cinfo->x[1] < 1) cinfo->x[1] = 1;
+ if(cinfo->y[1] < 1) cinfo->y[1] = 1;
+ cinfo->id[1] = ((g_operation_data.touch12_id & 0x0f)) -1;
+ //printk("After: cinfo->x[1] = %3d, cinfo->y[1] = %3d, cinfo->p[1] = %3d, cinfo->id[1] = %3d\n", cinfo->x[1], cinfo->y[1], cinfo->p[1], cinfo->id[1]);
+
+ if (cinfo->count > 2)
+ {
+ cinfo->x[2]= (( g_operation_data.x3_M << 8) | ( g_operation_data.x3_L)); //point 3
+ cinfo->y[2] = (( g_operation_data.y3_M << 8) | ( g_operation_data.y3_L));
+ cinfo->p[2] = 0;//g_operation_data.z3;
+ cinfo->id[2] = ((g_operation_data.touch34_id & 0xf0) >> 4) -1;
+
+ //printk("before: cinfo->x[2] = %3d, cinfo->y[2] = %3d, cinfo->p[2] = %3d\n", cinfo->x[2], cinfo->y[2], cinfo->p[2]);
+ if(cinfo->x[2] < 1) cinfo->x[2] = 1;
+ if(cinfo->y[2]< 1) cinfo->y[2] = 1;
+ //printk("After: cinfo->x[2]= %3d, cinfo->y[2] = %3d, cinfo->p[2]= %3d, cinfo->id[2] = %3d\n", cinfo->x[2], cinfo->y[2], cinfo->p[2], cinfo->id[2]);
+
+ if (cinfo->count > 3)
+ {
+ cinfo->x[3] = (( g_operation_data.x4_M << 8) | ( g_operation_data.x4_L)); //point 3
+ cinfo->y[3] = (( g_operation_data.y4_M << 8) | ( g_operation_data.y4_L));
+ cinfo->p[3] = 0;//g_operation_data.z4;
+ cinfo->id[3] = ((g_operation_data.touch34_id & 0x0f)) -1;
+
+ //printk("before: cinfo->x[3] = %3d, cinfo->y[3] = %3d, cinfo->p[3] = %3d, cinfo->id[3] = %3d\n", cinfo->x[3], cinfo->y[3], cinfo->p[3], cinfo->id[3]);
+ //printk("before: x4_M = %3d, x4_L = %3d\n", g_operation_data.x4_M, g_operation_data.x4_L);
+ if(cinfo->x[3] < 1) cinfo->x[3] = 1;
+ if(cinfo->y[3] < 1) cinfo->y[3] = 1;
+ //printk("After: cinfo->x[3] = %3d, cinfo->y[3] = %3d, cinfo->p[3]= %3d, cinfo->id[3] = %3d\n", cinfo->x[3], cinfo->y[3], cinfo->p[3], cinfo->id[3]);
+ }
+ if (cinfo->count > 4)
+ {
+ cinfo->x[4] = (( g_operation_data.x5_M << 8) | ( g_operation_data.x5_L)); //point 3
+ cinfo->y[4] = (( g_operation_data.y5_M << 8) | ( g_operation_data.y5_L));
+ cinfo->p[4] = 0;//g_operation_data.z4;
+ cinfo->id[4] = ((g_operation_data.touch5_id & 0xf0) >> 4) -1;
+
+ //printk("before: cinfo->x[4] = %3d, cinfo->y[4] = %3d, cinfo->id[4] = %3d\n", cinfo->x[4], cinfo->y[4], cinfo->id[4]);
+ //printk("before: x5_M = %3d, x5_L = %3d\n", g_operation_data.x5_M, g_operation_data.x5_L);
+ if(cinfo->x[4] < 1) cinfo->x[4] = 1;
+ if(cinfo->y[4] < 1) cinfo->y[4] = 1;
+ //printk("After: cinfo->x[4] = %3d, cinfo->y[4] = %3d, cinfo->id[4] = %3d\n", cinfo->x[4], cinfo->y[4], cinfo->id[4]);
+ }
+ }
+
+ }
+
+ if (!cinfo->count) return true; // this is a touch-up event
+
+ if (g_operation_data.tt_mode & 0x20) {
+ //TPD_DEBUG("uffer is not ready for use!\n");
+ memcpy(cinfo, pinfo, sizeof(struct touch_info));
+ return false;
+ }//return false; // buffer is not ready for use// buffer is not ready for use
+
+ // data toggle
+
+ data0 = i2c_smbus_read_i2c_block_data(i2c_client, TPD_REG_BASE, 1, (u8*)&g_operation_data);
+ ////TPD_DEBUG("before hst_mode = %02X \n", g_operation_data.hst_mode);
+
+ if((g_operation_data.hst_mode & 0x80)==0)
+ g_operation_data.hst_mode = g_operation_data.hst_mode|0x80;
+ else
+ g_operation_data.hst_mode = g_operation_data.hst_mode & (~0x80);
+
+ ////TPD_DEBUG("after hst_mode = %02X \n", g_operation_data.hst_mode);
+ data1 = i2c_smbus_write_i2c_block_data(i2c_client, TPD_REG_BASE, sizeof(g_operation_data.hst_mode), &g_operation_data.hst_mode);
+
+
+ if (tt_mode == g_operation_data.tt_mode) {
+ //TPD_DEBUG("sampling not completed!\n");
+ memcpy(cinfo, pinfo, sizeof(struct touch_info));
+ return false;
+ }// sampling not completed
+ else
+ tt_mode = g_operation_data.tt_mode;
+
+ return true;
+
+};
+
+static int touch_event_handler(void *unused)
+{
+ int i,j;
+ int keeppoint[5];
+ struct touch_info cinfo, pinfo;
+ struct sched_param param = { .sched_priority = 70/*RTPM_PRIO_TPD*/ };
+ sched_setscheduler(current, SCHED_RR, &param);
+
+ do
+ {
+ //printk("++++%s, line %d----unmask int\n", __FUNCTION__, __LINE__);
+ // mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
+ wmt_enable_gpirq();
+ set_current_state(TASK_INTERRUPTIBLE);
+ tp_interrupt_flag = 0;
+ //printk("++++%s, line %d----end\n", __FUNCTION__, __LINE__);
+ wait_event_interruptible(waiter,tpd_flag!=0);
+// printk("++++%s, line %d----start\n", __FUNCTION__, __LINE__);
+
+ tpd_flag = 0; //debg 2013-5-6
+ set_current_state(TASK_RUNNING);
+
+ exit_boot_mode();
+ if (tpd_touchinfo(&cinfo, &pinfo))
+ {
+ memset(keeppoint, 0x0, sizeof(keeppoint));
+ if(cinfo.count >0 && cinfo.count < (TP_POINTS_CNT+1))
+ {
+ switch(cinfo.count)
+ {
+ case 5:
+ {
+ tpd_down(cinfo.x[4], cinfo.y[4], cinfo.p[4]);
+ }
+ case 4:
+ {
+ tpd_down(cinfo.x[3], cinfo.y[3], cinfo.p[3]);
+ }
+ case 3:
+ {
+ tpd_down(cinfo.x[2], cinfo.y[2], cinfo.p[2]);
+ }
+ case 2:
+ {
+ tpd_down(cinfo.x[1], cinfo.y[1], cinfo.p[1]);
+ }
+ case 1:
+ {
+ tpd_down(cinfo.x[0], cinfo.y[0], cinfo.p[0]);
+ }
+ default:
+ break;
+ }
+ for(i = 0; i < cinfo.count; i++)
+ for(j = 0; j < pinfo.count; j++)
+ {
+ if(cinfo.id[i] == pinfo.id[j])keeppoint[j] = 1;
+ else if(keeppoint[j] != 1)keeppoint[j] = 0;
+ }
+
+ for(j = 0; j < pinfo.count; j++)
+ {
+ if(keeppoint[j] != 1)
+ {
+ tpd_up(pinfo.x[j], pinfo.y[j], pinfo.p[j]);
+ }
+ }
+
+ }
+ else if(cinfo.count == 0 && pinfo.count !=0)
+ {
+ switch(pinfo.count )
+ {
+ case 5:
+ {
+ tpd_up(pinfo.x[4], pinfo.y[4], pinfo.p[4]);
+ }
+ case 4:
+ {
+ tpd_up(pinfo.x[3], pinfo.y[3], pinfo.p[3]);
+ }
+ case 3:
+ {
+ tpd_up(pinfo.x[2], pinfo.y[2], pinfo.p[2]);
+ }
+ case 2:
+ {
+ tpd_up(pinfo.x[1], pinfo.y[1], pinfo.p[1]);
+ }
+ case 1:
+ {
+ tpd_up(pinfo.x[0], pinfo.y[0], pinfo.p[0]);
+ }
+ default:
+ break;
+ }
+ }
+
+ input_sync(tpd->input);
+
+ }
+
+
+
+ }while(!kthread_should_stop());
+ tp_interrupt_flag = 0;
+
+ return 0;
+}
+
+
+
+
+static irqreturn_t tpd_eint_interrupt_handler(int irq, void *dev_id)
+{
+ static int i = 0;
+ i ++;
+ //printk("++++eint=%d\n",i);
+
+ //mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
+// printk("++++%s, line %d, tpd_flag=%d,i=%d\n", __FUNCTION__, __LINE__, tpd_flag,i);
+
+ if (wmt_is_tsint())
+ {
+ // printk("<<<<in %s\n", __FUNCTION__);
+ wmt_clr_int();
+ //return IRQ_HANDLED;//!!!!!
+ if (wmt_is_tsirq_enable())
+ {
+ wmt_disable_gpirq();
+ }
+ tp_interrupt_flag = 1;
+ ////TPD_DEBUG("TPD interrupt has been triggered\n");
+ //if(tpd_flag)
+ //return;
+ tpd_flag = 1;
+ wake_up_interruptible(&waiter);
+
+ return IRQ_HANDLED;
+
+ }
+ return IRQ_NONE;
+}
+static void ctp_power_on(int on)
+{
+ printk("++++ctp_power_on = %d\n",on);
+ //return ;
+
+ if(on == 1)
+ {
+ //mt_set_gpio_mode(GPIO_CTP_EN_PIN, GPIO_CTP_EN_PIN_M_GPIO);
+ //mt_set_gpio_dir(GPIO_CTP_EN_PIN, GPIO_DIR_OUT);
+ //mt_set_gpio_out(GPIO_CTP_EN_PIN, GPIO_OUT_ONE);
+ ;
+
+ }
+ else
+ {
+ //return -EIO;
+ ;
+ }
+}
+//}
+
+#include "cyttsp.h"
+extern void cyttsp_fw_upgrade(void);
+void cyttsp_hw_reset(void)
+{
+ ctp_power_on(0); //wujinyou
+ msleep(200);
+
+ ctp_power_on(1); //wujinyou
+ msleep(100);
+ //mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
+// mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
+ //mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE);
+ msleep(100);
+ //mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ZERO);
+ msleep(100);
+}
+void cyttsp_sw_reset(void)
+{
+ //int retval = TPD_OK;
+// int status = 0;
+ printk("++++cyttsp_sw_reset---------start\n");
+#if 0//1
+ mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
+ mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
+ mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE);
+ msleep(20);
+ ctp_power_on(0);
+ msleep(200);
+ #if 1
+ ctp_power_on(1);
+ #endif
+
+ msleep(20);
+ mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ZERO);
+ msleep(100);
+
+ ////TPD_DEBUG("TPD wake up\n");
+ status = i2c_master_send(i2c_client, bl_cmd, 12);
+ if( status < 0)
+ {
+ printk("++++ [cyttsp_sw_reset], cyttsp tpd exit bootloader mode failed--tpd_resume!\n");
+ return status;
+ }
+ msleep(300);
+ //exit_boot_mode();
+ //mt65xx_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
+#endif
+ printk("++++cyttsp_sw_reset---------end\n");
+ //return retval;
+}
+
+
+//***************cyp140 probe 2013-1-6
+// wmtenv set wmt.io.touch 1:cyp140:7:600:1024:4:0:1:-1:5 //ok 2013-5-8
+static int __devinit tpd_probe(struct i2c_client *client)
+{
+ struct input_dev *input_dev;
+ int retval = TPD_OK;
+ int gpio_irq = wmt_ts_get_irqgpnum();
+ int gpio_rst = wmt_ts_get_resetgpnum();
+ //int result;
+ i2c_client = client;
+
+ retval = gpio_request(gpio_irq, "ts_irq");
+ if (retval < 0) {
+ printk("gpio(%d) touchscreen irq request fail\n", gpio_irq);
+ return retval;
+ }
+
+ retval = gpio_request(gpio_rst, "ts_rst");
+ if (retval < 0) {
+ printk("gpio(%d) touchscreen reset request fail\n", gpio_rst);
+ goto Fail_request_rstgpio;
+ }
+ //char buffer[2];
+ //int status=0;
+
+ //int res_x, res_y;
+
+ printk("<<< enter %s: %d\n",__FUNCTION__, __LINE__);
+
+#if 1 //0
+ tilt = wmt_ts_get_xaxis();
+ rev_x = wmt_ts_get_xdir();
+ rev_y = wmt_ts_get_ydir();
+#if 0
+ if (tilt){
+ max_y = wmt_ts_get_resolvX();
+ max_x = wmt_ts_get_resolvY();
+ }
+ else
+ {
+ max_x = wmt_ts_get_resolvX();
+ max_y =wmt_ts_get_resolvY();
+ }
+#else
+ max_x = wmt_ts_get_resolvX();
+ max_y =wmt_ts_get_resolvY();
+#endif
+
+#endif
+#if 0
+ if (0)
+ {
+ res_x = max_y;
+ res_y = max_x;
+ }
+ else
+ {
+ res_x = max_x;
+ res_y = max_y;
+ }
+ max_x = res_x;
+ max_y = res_y;
+#endif
+ //************************add input device 2013-1-6
+ tpd = kzalloc(sizeof(struct tpd_device), GFP_KERNEL);
+
+ input_dev = input_allocate_device();
+ if (!input_dev || !tpd) {
+ return -ENOMEM;
+ }
+
+ tpd->client/*i2c_ts*/ = client;
+ i2c_set_clientdata(client, tpd);
+ tpd->input = input_dev;
+
+ input_dev->name = "touch_cyp140"; //MJ5_TS_NAME;
+ input_dev->phys = "cyp140_touch/input0";
+ input_dev->id.bustype = BUS_HOST;
+ input_dev->id.vendor = 0x0001;
+ input_dev->id.product = 0x0002;
+ input_dev->id.version = 0x0100;
+
+ input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+ set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
+ if (wmt_ts_get_lcdexchg()) {
+ input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, max_y/*480*//*600*//*ResolutionX*//*ResolutionX*/, 0, 0);
+ input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, max_x /*ResolutionY*//*800*//* 1024*/, 0, 0);
+ } else {
+ input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, max_x/*480*//*600*//*ResolutionX*//*ResolutionX*/, 0, 0);
+ input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, max_y /*ResolutionY*//*800*//* 1024*/, 0, 0);
+ }
+
+ set_bit(KEY_BACK, input_dev->keybit);
+ set_bit(KEY_HOME, input_dev->keybit);
+ set_bit(KEY_MENU, input_dev->keybit);
+ retval = input_register_device(input_dev);
+ if (retval)
+ {
+ printk("%s input register device error!!\n", __FUNCTION__);
+ goto E_REG_INPUT;
+ }
+ //****************************
+ //ctp_power_on(1); //wujinyou //!!!!2013-1-6
+
+ msleep(1000);
+
+ //printk("<<<<here ??/\n");
+ //************************add for wmt 2013-1-6
+ wmt_tsreset_init();
+ wmt_set_rst_pull(1);
+ //wmt_enable_rst_pull(1);
+ wmt_rst_output(1);
+
+ wmt_set_gpirq(IRQ_TYPE_EDGE_FALLING);
+ //wmt_set_gpirq(IRQ_TYPE_EDGE_RISING); //debug 2013-5-8 also no interrupt
+ wmt_disable_gpirq();
+
+ tpd->irq = wmt_get_tsirqnum();
+ retval = request_irq(tpd->irq, tpd_eint_interrupt_handler,IRQF_SHARED, "cypcm", tpd);
+ //****************************************
+
+ printk("tpd_probe request_irq retval=%d!\n",retval);
+ msleep(100);
+ msleep(1000);
+
+ cust_ts.client = i2c_client;
+// cyttsp_fw_upgrade(); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+#if 0 //by linda 20130126
+ status = i2c_smbus_read_i2c_block_data(i2c_client, 0x01, 1, &(buffer[0]));
+ printk("tpd_probe request_irq status=%d!\n",status);
+
+ retval = i2c_master_send(i2c_client, bl_cmd, 12);
+ if( retval < 0)
+ {
+ printk("tpd_probe i2c_master_send retval=%d!\n",retval);
+
+ //return retval;
+ goto I2C_ERR;
+ }
+#else
+ retval = exit_boot_mode();
+ if (retval)
+ {
+ printk("%s exit_boot_mod error!\n", __FUNCTION__);
+ goto I2C_ERR;
+ }
+
+#endif
+/*
+ msleep(1000);
+ retval = i2c_smbus_read_i2c_block_data(i2c_client, 0x00, 1, &(buffer[0]));
+ if(retval<0) {
+ retval = i2c_smbus_read_i2c_block_data(i2c_client, 0x00, 1, &(buffer[0]));
+ if(retval<0) {
+ printk("error read !%d\n", __LINE__);
+
+ goto I2C_ERR;
+ }
+ }
+*/
+ //TPD_DEBUG("[mtk-tpd], cyttsp tpd_i2c_probe success!!\n");
+ tpd_load_status = 1;
+ thread = kthread_run(touch_event_handler, 0, TPD_DEVICE);
+ if (IS_ERR(thread)) {
+ retval = PTR_ERR(thread);
+ return retval;
+
+ }
+
+
+ msleep(100);
+ printk("++++tpd_probe,retval=%d\n", retval);
+#ifdef CONFIG_HAS_EARLYSUSPEND
+ tpd->early_suspend.suspend = tpd_early_suspend,
+ tpd->early_suspend.resume = tpd_late_resume,
+ tpd->early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB + 1;//,EARLY_SUSPEND_LEVEL_DISABLE_FB + 2;
+ register_early_suspend(&tpd->early_suspend);
+#endif
+ //disable_irq(cyp140_ts->irq);
+
+ wmt_enable_gpirq();
+
+//cust_timer_init();
+// esd_init_thread(); //close it 2013-1-6
+ return 0; //retval;
+ I2C_ERR:
+ free_irq(tpd->irq, tpd);
+ input_unregister_device(input_dev); //
+ E_REG_INPUT:
+ input_free_device(input_dev);
+ kfree(tpd);
+ //return retval;
+ Fail_request_rstgpio:
+ gpio_free(gpio_rst);
+ gpio_free(gpio_irq);
+ return retval;
+
+}
+//*******************************
+
+//module_init(cyp140_ts_init);
+static int tpd_local_init(void)
+{
+ if (tpd_probe(ts_get_i2c_client()))// ????
+ {
+ return -1;
+ }
+
+
+ if(tpd_load_status == 0){
+ //return -1;
+ ;
+ }
+
+#ifdef TPD_HAVE_BUTTON
+ tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data
+ boot_mode = get_boot_mode();
+#endif
+ return 0;//!!!!2013-1-7
+}
+
+//**********************suspend & resume
+static int tpd_resume(/*struct i2c_client *client*/struct platform_device *pdev)
+{
+ int retval = TPD_OK;
+ int status = 0;
+ printk("++++%s, line %d----end\n", __FUNCTION__, __LINE__);
+ //mt65xx_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
+ msleep(100);
+ #if 1
+ ctp_power_on(1);
+ #endif
+
+ msleep(1);
+ wmt_rst_output(0);
+ msleep(1);
+ wmt_rst_output(1);
+ msleep(100);
+
+ wmt_set_gpirq(IRQ_TYPE_EDGE_FALLING);//sometimes gpio7 will in low after resume 2013-5-9
+ wmt_enable_gpirq();
+ printk("++++%s, line %d----end\n", __FUNCTION__, __LINE__);
+
+ //TPD_DEBUG("TPD wake up\n");
+
+ #if 0 //0 // by linda 20120126 change rambo 2013-5-6
+ status = i2c_master_send(i2c_client, bl_cmd, 12);
+ #else
+ exit_boot_mode();
+ #endif
+ printk("++++%s, line %d----end\n", __FUNCTION__, __LINE__);
+
+ if( status < 0)
+ {
+ printk("++++ [mtk-tpd], cyttsp tpd exit bootloader mode failed--tpd_resume!\n");
+ return status;
+ }
+ //exit_boot_mode();
+ printk("++++%s, line %d----end\n", __FUNCTION__, __LINE__);
+ msleep(300);
+ //wmt_enable_gpirq(); //debg 2013-5-6
+ tp_suspend_flag = 0;
+ return retval;
+}
+
+static int tpd_suspend(/*struct i2c_client *client*/struct platform_device *pdev, pm_message_t message)
+{
+ int i = 0;
+ int retval = TPD_OK;
+ //u8 sleep_mode = 0x02; // 0x02--CY_DEEP_SLEEP_MODE, 0x04--CY_LOW_PWR_MODE
+ //TPD_DEBUG("TPD enter sleep\n");
+ //u8 sleep_reg[2] = {0, 2};
+ printk("++++%s, line %d----end\n", __FUNCTION__, __LINE__);
+ wmt_disable_gpirq();
+ //wmt_disable_gpirq(); //dbg 2013-5-6
+
+ while((tp_reseting_flag || tp_interrupt_flag) && i<30)
+ {
+ i ++;
+ msleep(100);
+ }
+ tp_suspend_flag = 1;
+#if 1
+ //retval = i2c_smbus_write_i2c_block_data(i2c_client,0x00,sizeof(sleep_mode), &sleep_mode);
+ //retval = i2c_master_send(i2c_client, sleep_reg, 2); //send cmd error -5!
+ msleep(1);
+ ctp_power_on(0);
+ mdelay(1);
+#else
+ mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
+ mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
+ mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE);
+#endif
+
+ return retval;
+}
+
+#ifdef CONFIG_HAS_EARLYSUSPEND
+static void tpd_early_suspend(struct early_suspend *handler)
+{
+ tpd_suspend(i2c_client, PMSG_SUSPEND);
+}
+
+static void tpd_late_resume(struct early_suspend *handler)
+{
+ tpd_resume(i2c_client);
+}
+#endif
+//****************************
+
+
+static void cyp140_ts_exit(void)
+{
+ printk("<<<%s\n", __FUNCTION__);
+
+ wmt_disable_gpirq();
+ free_irq(tpd->irq, tpd);
+ //kthread_stop(thread); // halt rmmod??
+ input_unregister_device(tpd->input); //
+
+ input_free_device(tpd->input);
+ kfree(tpd);
+ gpio_free(wmt_ts_get_irqgpnum());
+ gpio_free(wmt_ts_get_resetgpnum());
+}
+//module_exit(cyp140_ts_exit);
+
+void cyp140_set_ts_mode(u8 mode)
+{
+ dbg( "[Touch Screen]ts mode = %d \n", mode);
+}
+//EXPORT_SYMBOL_GPL(cyp140_set_ts_mode);
+
+struct wmtts_device cyp140_tsdev = {
+ .driver_name = WMT_TS_I2C_NAME,
+ .ts_id = "cyp140",
+ .init = tpd_local_init,
+ .exit = cyp140_ts_exit,
+ .suspend = tpd_suspend,
+ .resume = tpd_resume,
+};
+
+
+
+MODULE_DESCRIPTION("cyp140 I2C Touch Screen driver");
+MODULE_LICENSE("GPL v2");
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp.h b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp.h
new file mode 100755
index 00000000..6020018f
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp.h
@@ -0,0 +1,696 @@
+/* Header file for:
+ * Cypress TrueTouch(TM) Standard Product touchscreen drivers.
+ * include/linux/cyttsp.h
+ *
+ * Copyright (C) 2009, 2010 Cypress Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2, and only version 2, as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Cypress reserves the right to make changes without further notice
+ * to the materials described herein. Cypress does not assume any
+ * liability arising out of the application described herein.
+ *
+ * Contact Cypress Semiconductor at www.cypress.com
+ *
+ */
+
+
+#ifndef __CYTTSP_H__
+#define __CYTTSP_H__
+
+#include <linux/input.h>
+#include <linux/timer.h>
+#include <linux/workqueue.h>
+#include <linux/kernel.h>
+#include <linux/delay.h>
+
+#include <asm/mach-types.h>
+
+#define CYPRESS_TTSP_NAME "cyttsp"
+#define CY_I2C_NAME "cyttsp-i2c"
+#define CY_SPI_NAME "cyttsp-spi"
+
+#ifdef CY_DECLARE_GLOBALS
+ uint32_t cyttsp_tsdebug;
+ module_param_named(tsdebug, cyttsp_tsdebug, uint, 0664);
+ uint32_t cyttsp_tsxdebug;
+ module_param_named(tsxdebug, cyttsp_tsxdebug, uint, 0664);
+
+ uint32_t cyttsp_disable_touch;
+ module_param_named(disable_touch, cyttsp_disable_touch, uint, 0664);
+#else
+ extern uint32_t cyttsp_tsdebug;
+ extern uint32_t cyttsp_tsxdebug;
+ extern uint32_t cyttsp_disable_touch;
+#endif
+
+
+
+/******************************************************************************
+ * Global Control, Used to control the behavior of the driver
+ */
+
+/* defines for Gen2 (Txx2xx); Gen3 (Txx3xx)
+ * use these defines to set cyttsp_platform_data.gen in board config file
+ */
+#define CY_GEN2 2
+#define CY_GEN3 3
+
+/* define for using I2C driver
+ */
+#define CY_USE_I2C_DRIVER
+
+/* defines for using SPI driver */
+/*
+#define CY_USE_SPI_DRIVER
+ */
+#define CY_SPI_DFLT_SPEED_HZ 1000000
+#define CY_SPI_MAX_SPEED_HZ 4000000
+#define CY_SPI_SPEED_HZ CY_SPI_DFLT_SPEED_HZ
+#define CY_SPI_BITS_PER_WORD 8
+#define CY_SPI_DAV 139 /* set correct gpio id */
+#define CY_SPI_BUFSIZE 512
+
+/* Voltage and Current ratings */
+#define CY_TMA300_VTG_MAX_UV 5500000
+#define CY_TMA300_VTG_MIN_UV 1710000
+#define CY_TMA300_CURR_24HZ_UA 17500
+#define CY_I2C_VTG_MAX_UV 1800000
+#define CY_I2C_VTG_MIN_UV 1800000
+#define CY_I2C_CURR_UA 9630
+
+
+/* define for inclusion of TTSP App Update Load File
+ * use this define if update to the TTSP Device is desired
+ */
+/*
+#define CY_INCLUDE_LOAD_FILE
+*/
+
+/* define if force new load file for bootloader load */
+/*
+#define CY_FORCE_FW_UPDATE
+*/
+
+/* undef for production use */
+/*
+#define CY_USE_DEBUG
+*/
+
+/* undef for irq use; use this define in the board configuration file */
+/*
+#define CY_USE_TIMER
+ */
+
+/* undef to allow use of extra debug capability */
+/*
+#define CY_ALLOW_EXTRA_DEBUG
+*/
+
+/* undef to remove additional debug prints */
+/*
+#define CY_USE_EXTRA_DEBUG
+*/
+
+/* undef to remove additional debug prints */
+/*
+#define CY_USE_EXTRA_DEBUG1
+ */
+
+/* undef to use operational touch timer jiffies; else use test jiffies */
+/*
+ */
+ /*
+#define CY_USE_TIMER_DEBUG
+*/
+/* define to use canned test data */
+/*
+#define CY_USE_TEST_DATA
+ */
+
+/* define if gesture signaling is used
+ * and which gesture groups to use
+ */
+/*
+#define CY_USE_GEST
+#define CY_USE_GEST_GRP1
+#define CY_USE_GEST_GRP2
+#define CY_USE_GEST_GRP3
+#define CY_USE_GEST_GRP4
+ */
+/* Active distance in pixels for a gesture to be reported
+ * if set to 0, then all gesture movements are reported
+ */
+#define CY_ACT_DIST_DFLT 8
+#define CY_ACT_DIST CY_ACT_DIST_DFLT
+
+/* define if MT signals are desired */
+/*
+*/
+#define CY_USE_MT_SIGNALS
+
+/* define if MT tracking id signals are used */
+/*
+#define CY_USE_MT_TRACK_ID
+ */
+
+/* define if ST signals are required */
+/*
+*/
+//#define CY_USE_ST_SIGNALS
+
+/* define to send handshake to device */
+/*
+*/
+#define CY_USE_HNDSHK
+
+/* define if log all raw motion signals to a sysfs file */
+/*
+#define CY_LOG_TO_FILE
+*/
+
+
+/* End of the Global Control section
+ ******************************************************************************
+ */
+#define CY_DIFF(m, n) ((m) != (n))
+
+#ifdef CY_LOG_TO_FILE
+ #define cyttsp_openlog() /* use sysfs */
+#else
+ #define cyttsp_openlog()
+#endif /* CY_LOG_TO_FILE */
+
+/* see kernel.h for pr_xxx def'ns */
+#define cyttsp_info(f, a...) pr_info("%s:" f, __func__ , ## a)
+#define cyttsp_error(f, a...) pr_err("%s:" f, __func__ , ## a)
+#define cyttsp_alert(f, a...) pr_alert("%s:" f, __func__ , ## a)
+
+#ifdef CY_USE_DEBUG
+ #define cyttsp_debug(f, a...) pr_alert("%s:" f, __func__ , ## a)
+#else
+ #define cyttsp_debug(f, a...) {if (cyttsp_tsdebug) \
+ pr_alert("%s:" f, __func__ , ## a); }
+#endif /* CY_USE_DEBUG */
+
+#ifdef CY_ALLOW_EXTRA_DEBUG
+#ifdef CY_USE_EXTRA_DEBUG
+ #define cyttsp_xdebug(f, a...) pr_alert("%s:" f, __func__ , ## a)
+#else
+ #define cyttsp_xdebug(f, a...) {if (cyttsp_tsxdebug) \
+ pr_alert("%s:" f, __func__ , ## a); }
+#endif /* CY_USE_EXTRA_DEBUG */
+
+#ifdef CY_USE_EXTRA_DEBUG1
+ #define cyttsp_xdebug1(f, a...) pr_alert("%s:" f, __func__ , ## a)
+#else
+ #define cyttsp_xdebug1(f, a...)
+#endif /* CY_USE_EXTRA_DEBUG1 */
+#else
+ #define cyttsp_xdebug(f, a...)
+ #define cyttsp_xdebug1(f, a...)
+#endif /* CY_ALLOW_EXTRA_DEBUG */
+
+#ifdef CY_USE_TIMER_DEBUG
+ #define TOUCHSCREEN_TIMEOUT (msecs_to_jiffies(1000))
+#else
+ #define TOUCHSCREEN_TIMEOUT (msecs_to_jiffies(28))
+#endif
+
+/* reduce extra signals in MT only build
+ * be careful not to lose backward compatibility for pre-MT apps
+ */
+#ifdef CY_USE_ST_SIGNALS
+ #define CY_USE_ST 1
+#else
+ #define CY_USE_ST 0
+#endif /* CY_USE_ST_SIGNALS */
+
+/* rely on kernel input.h to define Multi-Touch capability */
+/* if input.h defines the Multi-Touch signals, then use MT */
+#if defined(ABS_MT_TOUCH_MAJOR) && defined(CY_USE_MT_SIGNALS)
+ #define CY_USE_MT 1
+ #define CY_MT_SYNC(input) input_mt_sync(input)
+#else
+ #define CY_USE_MT 0
+ #define CY_MT_SYNC(input)
+ /* the following includes are provided to ensure a compile;
+ * the code that compiles with these defines will not be executed if
+ * the CY_USE_MT is properly used in the platform structure init
+ */
+ #ifndef ABS_MT_TOUCH_MAJOR
+ #define ABS_MT_TOUCH_MAJOR 0x30 /* touching ellipse */
+ #define ABS_MT_TOUCH_MINOR 0x31 /* (omit if circular) */
+ #define ABS_MT_WIDTH_MAJOR 0x32 /* approaching ellipse */
+ #define ABS_MT_WIDTH_MINOR 0x33 /* (omit if circular) */
+ #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
+ #define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
+ #define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
+ #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
+ #define ABS_MT_BLOB_ID 0x38 /* Group set of pkts as blob */
+ #endif /* ABS_MT_TOUCH_MAJOR */
+#endif /* ABS_MT_TOUCH_MAJOR and CY_USE_MT_SIGNALS */
+#if defined(ABS_MT_TRACKING_ID) && defined(CY_USE_MT_TRACK_ID)
+ #define CY_USE_TRACKING_ID 1
+#else
+ #define CY_USE_TRACKING_ID 0
+/* define only if not defined already by system;
+ * value based on linux kernel 2.6.30.10
+ */
+#ifndef ABS_MT_TRACKING_ID
+ #define ABS_MT_TRACKING_ID (ABS_MT_BLOB_ID+1)
+#endif
+#endif /* ABS_MT_TRACKING_ID */
+
+#define CY_USE_DEEP_SLEEP_SEL 0x80
+#define CY_USE_LOW_POWER_SEL 0x01
+
+#ifdef CY_USE_TEST_DATA
+ #define cyttsp_testdat(ray1, ray2, sizeofray) \
+ { \
+ int i; \
+ u8 *up1 = (u8 *)ray1; \
+ u8 *up2 = (u8 *)ray2; \
+ for (i = 0; i < sizeofray; i++) { \
+ up1[i] = up2[i]; \
+ } \
+ }
+#else
+ #define cyttsp_testdat(xy, test_xy, sizeofray)
+#endif /* CY_USE_TEST_DATA */
+
+/* helper macros */
+#define GET_NUM_TOUCHES(x) ((x) & 0x0F)
+#define GET_TOUCH1_ID(x) (((x) & 0xF0) >> 4)
+#define GET_TOUCH2_ID(x) ((x) & 0x0F)
+#define GET_TOUCH3_ID(x) (((x) & 0xF0) >> 4)
+#define GET_TOUCH4_ID(x) ((x) & 0x0F)
+#define IS_LARGE_AREA(x) (((x) & 0x10) >> 4)
+#define FLIP_DATA_FLAG 0x01
+#define REVERSE_X_FLAG 0x02
+#define REVERSE_Y_FLAG 0x04
+#define FLIP_DATA(flags) ((flags) & FLIP_DATA_FLAG)
+#define REVERSE_X(flags) ((flags) & REVERSE_X_FLAG)
+#define REVERSE_Y(flags) ((flags) & REVERSE_Y_FLAG)
+#define FLIP_XY(x, y) { \
+ u16 tmp; \
+ tmp = (x); \
+ (x) = (y); \
+ (y) = tmp; \
+ }
+#define INVERT_X(x, xmax) ((xmax) - (x))
+#define INVERT_Y(y, maxy) ((maxy) - (y))
+#define SET_HSTMODE(reg, mode) ((reg) & (mode))
+#define GET_HSTMODE(reg) ((reg & 0x70) >> 4)
+#define GET_BOOTLOADERMODE(reg) ((reg & 0x10) >> 4)
+
+/* constant definitions */
+/* maximum number of concurrent ST track IDs */
+#define CY_NUM_ST_TCH_ID 2
+
+/* maximum number of concurrent MT track IDs */
+#define CY_NUM_MT_TCH_ID 4
+
+/* maximum number of track IDs */
+#define CY_NUM_TRK_ID 16
+
+#define CY_NTCH 0 /* no touch (lift off) */
+#define CY_TCH 1 /* active touch (touchdown) */
+#define CY_ST_FNGR1_IDX 0
+#define CY_ST_FNGR2_IDX 1
+#define CY_MT_TCH1_IDX 0
+#define CY_MT_TCH2_IDX 1
+#define CY_MT_TCH3_IDX 2
+#define CY_MT_TCH4_IDX 3
+#define CY_XPOS 0
+#define CY_YPOS 1
+#define CY_IGNR_TCH (-1)
+#define CY_SMALL_TOOL_WIDTH 10
+#define CY_LARGE_TOOL_WIDTH 255
+#define CY_REG_BASE 0x00
+#define CY_REG_GEST_SET 0x1E
+#define CY_REG_ACT_INTRVL 0x1D
+#define CY_REG_TCH_TMOUT (CY_REG_ACT_INTRVL+1)
+#define CY_REG_LP_INTRVL (CY_REG_TCH_TMOUT+1)
+#define CY_SOFT_RESET ((1 << 0))
+#define CY_DEEP_SLEEP ((1 << 1))
+#define CY_LOW_POWER ((1 << 2))
+#define CY_MAXZ 255
+#define CY_OK 0
+#define CY_INIT 1
+#define CY_DLY_DFLT 10 /* ms */
+#define CY_DLY_SYSINFO 20 /* ms */
+#define CY_DLY_BL 300
+#define CY_DLY_DNLOAD 100 /* ms */
+#define CY_NUM_RETRY 4 /* max num touch data read */
+
+/* handshake bit in the hst_mode reg */
+#define CY_HNDSHK_BIT 0x80
+#ifdef CY_USE_HNDSHK
+ #define CY_SEND_HNDSHK 1
+#else
+ #define CY_SEND_HNDSHK 0
+#endif
+
+/* Bootloader File 0 offset */
+#define CY_BL_FILE0 0x00
+
+/* Bootloader command directive */
+#define CY_BL_CMD 0xFF
+
+/* Bootloader Initiate Bootload */
+#define CY_BL_INIT_LOAD 0x38
+
+/* Bootloader Write a Block */
+#define CY_BL_WRITE_BLK 0x39
+
+/* Bootloader Terminate Bootload */
+#define CY_BL_TERMINATE 0x3B
+
+/* Bootloader Exit and Verify Checksum command */
+#define CY_BL_EXIT 0xA5
+
+/* Bootloader default keys */
+#define CY_BL_KEY0 0x00
+#define CY_BL_KEY1 0x01
+#define CY_BL_KEY2 0x02
+#define CY_BL_KEY3 0x03
+#define CY_BL_KEY4 0x04
+#define CY_BL_KEY5 0x05
+#define CY_BL_KEY6 0x06
+#define CY_BL_KEY7 0x07
+
+/* Active Power state scanning/processing refresh interval */
+#define CY_ACT_INTRVL_DFLT 0x00
+
+/* touch timeout for the Active power */
+#define CY_TCH_TMOUT_DFLT 0xFF
+
+/* Low Power state scanning/processing refresh interval */
+#define CY_LP_INTRVL_DFLT 0x0A
+
+#define CY_IDLE_STATE 0
+#define CY_ACTIVE_STATE 1
+#define CY_LOW_PWR_STATE 2
+#define CY_SLEEP_STATE 3
+
+/* device mode bits */
+#define CY_OP_MODE 0x00
+#define CY_SYSINFO_MODE 0x10
+
+/* power mode select bits */
+#define CY_SOFT_RESET_MODE 0x01 /* return to Bootloader mode */
+#define CY_DEEP_SLEEP_MODE 0x02
+#define CY_LOW_PWR_MODE 0x04
+
+#define CY_NUM_KEY 8
+
+#ifdef CY_USE_GEST
+ #define CY_USE_GESTURES 1
+#else
+ #define CY_USE_GESTURES 0
+#endif /* CY_USE_GESTURE_SIGNALS */
+
+#ifdef CY_USE_GEST_GRP1
+ #define CY_GEST_GRP1 0x10
+#else
+ #define CY_GEST_GRP1 0x00
+#endif /* CY_USE_GEST_GRP1 */
+#ifdef CY_USE_GEST_GRP2
+ #define CY_GEST_GRP2 0x20
+#else
+ #define CY_GEST_GRP2 0x00
+#endif /* CY_USE_GEST_GRP2 */
+#ifdef CY_USE_GEST_GRP3
+ #define CY_GEST_GRP3 0x40
+#else
+ #define CY_GEST_GRP3 0x00
+#endif /* CY_USE_GEST_GRP3 */
+#ifdef CY_USE_GEST_GRP4
+ #define CY_GEST_GRP4 0x80
+#else
+ #define CY_GEST_GRP4 0x00
+#endif /* CY_USE_GEST_GRP4 */
+
+struct cyttsp_regulator {
+ const char *name;
+ u32 min_uV;
+ u32 max_uV;
+ u32 load_uA;
+};
+
+struct cyttsp_platform_data {
+ u32 panel_maxx;
+ u32 panel_maxy;
+ u32 disp_resx;
+ u32 disp_resy;
+ u32 disp_minx;
+ u32 disp_miny;
+ u32 disp_maxx;
+ u32 disp_maxy;
+ u8 correct_fw_ver;
+ u32 flags;
+ u8 gen;
+ u8 use_st;
+ u8 use_mt;
+ u8 use_hndshk;
+ u8 use_trk_id;
+ u8 use_sleep;
+ u8 use_gestures;
+ u8 gest_set;
+ u8 act_intrvl;
+ u8 tch_tmout;
+ u8 lp_intrvl;
+ u8 power_state;
+ bool wakeup;
+ int sleep_gpio;
+ int resout_gpio;
+ int irq_gpio;
+ struct cyttsp_regulator *regulator_info;
+ u8 num_regulators;
+ const char *fw_fname;
+#ifdef CY_USE_I2C_DRIVER
+ s32 (*init)(struct i2c_client *client);
+ s32 (*resume)(struct i2c_client *client);
+#endif
+#ifdef CY_USE_SPI_DRIVER
+ s32 (*init)(struct spi_device *spi);
+ s32 (*resume)(struct spi_device *spi);
+#endif
+};
+
+/* TrueTouch Standard Product Gen3 (Txx3xx) interface definition */
+struct cyttsp_gen3_xydata_t {
+ u8 hst_mode;
+ u8 tt_mode;
+ u8 tt_stat;
+ u16 x1 __attribute__ ((packed));
+ u16 y1 __attribute__ ((packed));
+ u8 z1;
+ u8 touch12_id;
+ u16 x2 __attribute__ ((packed));
+ u16 y2 __attribute__ ((packed));
+ u8 z2;
+ u8 gest_cnt;
+ u8 gest_id;
+ u16 x3 __attribute__ ((packed));
+ u16 y3 __attribute__ ((packed));
+ u8 z3;
+ u8 touch34_id;
+ u16 x4 __attribute__ ((packed));
+ u16 y4 __attribute__ ((packed));
+ u8 z4;
+ u8 tt_undef[3];
+ u8 gest_set;
+ u8 tt_reserved;
+};
+
+/* TrueTouch Standard Product Gen2 (Txx2xx) interface definition */
+#define CY_GEN2_NOTOUCH 0x03 /* Both touches removed */
+#define CY_GEN2_GHOST 0x02 /* ghost */
+#define CY_GEN2_2TOUCH 0x03 /* 2 touch; no ghost */
+#define CY_GEN2_1TOUCH 0x01 /* 1 touch only */
+#define CY_GEN2_TOUCH2 0x01 /* 1st touch removed;
+ * 2nd touch remains */
+struct cyttsp_gen2_xydata_t {
+ u8 hst_mode;
+ u8 tt_mode;
+ u8 tt_stat;
+ u16 x1 __attribute__ ((packed));
+ u16 y1 __attribute__ ((packed));
+ u8 z1;
+ u8 evnt_idx;
+ u16 x2 __attribute__ ((packed));
+ u16 y2 __attribute__ ((packed));
+ u8 tt_undef1;
+ u8 gest_cnt;
+ u8 gest_id;
+ u8 tt_undef[14];
+ u8 gest_set;
+ u8 tt_reserved;
+};
+
+/* TTSP System Information interface definition */
+struct cyttsp_sysinfo_data_t {
+ u8 hst_mode;
+ u8 mfg_cmd;
+ u8 mfg_stat;
+ u8 cid[3];
+ u8 tt_undef1;
+ u8 uid[8];
+ u8 bl_verh;
+ u8 bl_verl;
+ u8 tts_verh;
+ u8 tts_verl;
+ u8 app_idh;
+ u8 app_idl;
+ u8 app_verh;
+ u8 app_verl;
+ u8 tt_undef[6];
+ u8 act_intrvl;
+ u8 tch_tmout;
+ u8 lp_intrvl;
+};
+
+/* TTSP Bootloader Register Map interface definition */
+#define CY_BL_CHKSUM_OK 0x01
+struct cyttsp_bootloader_data_t {
+ u8 bl_file;
+ u8 bl_status;
+ u8 bl_error;
+ u8 blver_hi;
+ u8 blver_lo;
+ u8 bld_blver_hi;
+ u8 bld_blver_lo;
+ u8 ttspver_hi;
+ u8 ttspver_lo;
+ u8 appid_hi;
+ u8 appid_lo;
+ u8 appver_hi;
+ u8 appver_lo;
+ u8 cid_0;
+ u8 cid_1;
+ u8 cid_2;
+};
+
+#define cyttsp_wake_data_t cyttsp_gen3_xydata_t
+#ifdef CY_DECLARE_GLOBALS
+ #ifdef CY_INCLUDE_LOAD_FILE
+ /* this file declares:
+ * firmware download block array (cyttsp_fw[]),
+ * the number of command block records (cyttsp_fw_records),
+ * and the version variables
+ */
+ #include "cyttsp_fw.h" /* imports cyttsp_fw[] array */
+ #define cyttsp_app_load() 1
+ #ifdef CY_FORCE_FW_UPDATE
+ #define cyttsp_force_fw_load() 1
+ #else
+ #define cyttsp_force_fw_load() 0
+ #endif
+
+ #else
+ /* the following declarations are to allow
+ * some debugging capability
+ */
+ unsigned char cyttsp_fw_tts_verh = 0x00;
+ unsigned char cyttsp_fw_tts_verl = 0x01;
+ unsigned char cyttsp_fw_app_idh = 0x02;
+ unsigned char cyttsp_fw_app_idl = 0x03;
+ unsigned char cyttsp_fw_app_verh = 0x04;
+ unsigned char cyttsp_fw_app_verl = 0x05;
+ unsigned char cyttsp_fw_cid_0 = 0x06;
+ unsigned char cyttsp_fw_cid_1 = 0x07;
+ unsigned char cyttsp_fw_cid_2 = 0x08;
+ #define cyttsp_app_load() 0
+ #define cyttsp_force_fw_load() 0
+ #endif
+ #define cyttsp_tts_verh() cyttsp_fw_tts_verh
+ #define cyttsp_tts_verl() cyttsp_fw_tts_verl
+ #define cyttsp_app_idh() cyttsp_fw_app_idh
+ #define cyttsp_app_idl() cyttsp_fw_app_idl
+ #define cyttsp_app_verh() cyttsp_fw_app_verh
+ #define cyttsp_app_verl() cyttsp_fw_app_verl
+ #define cyttsp_cid_0() cyttsp_fw_cid_0
+ #define cyttsp_cid_1() cyttsp_fw_cid_1
+ #define cyttsp_cid_2() cyttsp_fw_cid_2
+ #ifdef CY_USE_TEST_DATA
+ static struct cyttsp_gen2_xydata_t tt_gen2_testray[] = {
+ {0x00}, {0x00}, {0x04},
+ {0x4000}, {0x8000}, {0x80},
+ {0x03},
+ {0x2000}, {0x1000}, {0x00},
+ {0x00},
+ {0x00},
+ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
+ {0x00},
+ {0x00}
+ };
+
+ static struct cyttsp_gen3_xydata_t tt_gen3_testray[] = {
+ {0x00}, {0x00}, {0x04},
+ {0x4000}, {0x8000}, {0x80},
+ {0x12},
+ {0x2000}, {0x1000}, {0xA0},
+ {0x00}, {0x00},
+ {0x8000}, {0x4000}, {0xB0},
+ {0x34},
+ {0x4000}, {0x1000}, {0xC0},
+ {0x00, 0x00, 0x00},
+ {0x00},
+ {0x00}
+ };
+ #endif /* CY_USE_TEST_DATA */
+
+#else
+ extern u8 g_appload_ray[];
+#endif
+#define FW_FNAME_LEN 40
+#define TP_ID_GPIO 85
+
+
+/* CY TTSP I2C Driver private data */
+struct cyttsp {
+ struct i2c_client *client;
+ struct input_dev *input;
+ struct work_struct work;
+ struct timer_list timer;
+ struct mutex mutex;
+ char phys[32];
+ struct cyttsp_platform_data *platform_data;
+ u8 num_prv_st_tch;
+ u16 act_trk[CY_NUM_TRK_ID];
+ u16 prv_st_tch[CY_NUM_ST_TCH_ID];
+ u16 prv_mt_tch[CY_NUM_MT_TCH_ID];
+ u16 prv_mt_pos[CY_NUM_TRK_ID][2];
+ atomic_t irq_enabled;
+ bool cyttsp_update_fw;
+ bool cyttsp_fwloader_mode;
+ bool is_suspended;
+ struct regulator **vdd;
+ char fw_fname[FW_FNAME_LEN];
+#ifdef CONFIG_HAS_EARLYSUSPEND
+ struct early_suspend early_suspend;
+#endif /* CONFIG_HAS_EARLYSUSPEND */
+ int tpid;
+
+};
+extern struct cyttsp cust_ts;
+extern void cyttsp_fw_upgrade(void);
+extern void cyttsp_hw_reset(void);
+
+
+#endif /* __CYTTSP_H__ */
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp_fw_upgrade.c b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp_fw_upgrade.c
new file mode 100755
index 00000000..ca6e9d10
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/cyttsp_fw_upgrade.c
@@ -0,0 +1,993 @@
+/* Source for:
+ * Cypress TrueTouch(TM) Standard Product I2C touchscreen driver.
+ * drivers/input/touchscreen/cyttsp-i2c.c
+ *
+ * Copyright (C) 2009, 2010 Cypress Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2, and only version 2, as published by the
+ * Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Cypress reserves the right to make changes without further notice
+ * to the materials described herein. Cypress does not assume any
+ * liability arising out of the application described herein.
+ *
+ * Contact Cypress Semiconductor at www.cypress.com
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/i2c.h>
+#include <linux/input.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
+#include <linux/timer.h>
+#include <linux/workqueue.h>
+#include <linux/byteorder/generic.h>
+#include <linux/bitops.h>
+#include <linux/pm_runtime.h>
+#include <linux/firmware.h>
+#include <linux/mutex.h>
+#include <linux/regulator/consumer.h>
+#ifdef CONFIG_HAS_EARLYSUSPEND
+#include <linux/earlysuspend.h>
+#endif /* CONFIG_HAS_EARLYSUSPEND */
+//#include <mach/vreg.h>
+
+#define CY_DECLARE_GLOBALS
+
+#include "cyttsp.h"
+
+#include <linux/miscdevice.h>
+#include <asm/uaccess.h>
+
+#include <linux/poll.h>
+
+#define LOG_TP() printk("++++%s, Line %d\n", __FUNCTION__, __LINE__);
+
+
+#define CYTTSP_SUPPORT_READ_TP_VERSION
+
+#define CYTTSP_SUPPORT_TP_SENSOR
+// need upgrade,add MACRO
+//#ifdef CONFIG_LCT_AW551_YL
+#define CYTTSP_SUPPORT_SYS_NODE
+//#endif
+
+extern struct tpd_device *tpd;//add 2013-1-7
+
+int cyttsp_vendor_id=20;
+int cyttsp_firmware_version= -1;
+
+int cyttsp_has_bootloader=0;
+
+#ifdef CYTTSP_SUPPORT_TP_SENSOR
+
+#define CYTTSP_DEBUG_TP_SENSOR
+
+#define CYTTSP_SUPPORT_TP_SENSOR_FIRMWARE_VERSION (0xc) //if we change this value we should also change func apds9900_init_dev in file apds9000.c
+static DEFINE_MUTEX(cyttsp_sensor_mutex);
+static DECLARE_WAIT_QUEUE_HEAD(cyttsp_sensor_waitqueue);
+
+//static char cyttsp_sensor_data = 0; // 0 near 1 far
+//static int cyttsp_sensor_data_changed = 0;
+//static struct i2c_client *tp_sensor_I2Cclient = NULL;
+//static int cyttsp_sensor_opened = 0;
+
+
+
+#endif
+
+
+
+#define CYTTSP_AW551_OFILM "cyttspfw_aw551_ofilm.fw"
+#define CYTTSP_AW551_TRULY "cyttspfw_aw551_truly.fw"
+#define CYTTSP_AW550_TRULY "cyttspfw_aw550_truly.fw"
+
+uint32_t cyttsp_tsdebug1 = 0xff;
+
+module_param_named(tsdebug1, cyttsp_tsdebug1, uint, 0664);
+
+#define FW_FNAME_LEN 40
+#define TP_ID_GPIO 85
+
+//static u8 irq_cnt; /* comparison counter with register valuw */
+//static u32 irq_cnt_total; /* total interrupts */
+//static u32 irq_err_cnt; /* count number of touch interrupts with err */
+#define CY_IRQ_CNT_MASK 0x000000FF /* mapped for sizeof count in reg */
+#define CY_IRQ_CNT_REG 0x00 /* tt_undef[0]=reg 0x1B - Gen3 only */
+
+
+
+/* ****************************************************************************
+ * Prototypes for static functions
+ * ************************************************************************** */
+
+static int cyttsp_putbl(struct cyttsp *ts, int show,
+ int show_status, int show_version, int show_cid);
+/*static int __devinit cyttsp_probe(struct i2c_client *client,
+ const struct i2c_device_id *id); */
+//static int __devexit cyttsp_remove(struct i2c_client *client);
+//static int cyttsp_resume(struct device *dev);
+//static int cyttsp_suspend(struct device *dev);
+
+#ifdef CYTTSP_SUPPORT_SYS_NODE
+//static int cyttsp_power_down(void);
+#endif
+
+
+
+/* Static variables */
+//static struct cyttsp_gen3_xydata_t g_xy_data;
+static struct cyttsp_bootloader_data_t g_bl_data;
+static struct cyttsp_sysinfo_data_t g_sysinfo_data;
+static const struct i2c_device_id cyttsp_id[] = {
+ { CY_I2C_NAME, 0 }, { }
+};
+static u8 bl_cmd[] = {
+ CY_BL_FILE0, CY_BL_CMD, CY_BL_EXIT,
+ CY_BL_KEY0, CY_BL_KEY1, CY_BL_KEY2,
+ CY_BL_KEY3, CY_BL_KEY4, CY_BL_KEY5,
+ CY_BL_KEY6, CY_BL_KEY7};
+
+MODULE_DEVICE_TABLE(i2c, cyttsp_id);
+
+
+
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Cypress TrueTouch(R) Standard touchscreen driver");
+MODULE_AUTHOR("Cypress");
+
+
+
+#ifdef CYTTSP_SUPPORT_TP_SENSOR
+#define CYTTSP_SENSOR_IOM 'r'
+
+#define CYTTSP_SENSOR_IOC_SET_PS_ENABLE _IOW(CYTTSP_SENSOR_IOM, 0, char *)
+#define CYTTSP_SENSOR_READ_PS_DATA _IOR(CYTTSP_SENSOR_IOM, 2, char *)
+
+
+
+
+#endif
+
+
+
+
+
+
+
+
+
+static void cyttsp_exit_bl_mode(struct cyttsp *ts);
+
+
+
+
+
+#ifdef CYTTSP_SUPPORT_SYS_NODE
+/* firmware flashing block */
+#define BLK_SIZE 16
+#define DATA_REC_LEN 64
+#define START_ADDR 0x0880//0x0b00
+#define BLK_SEED 0xff
+#define RECAL_REG 0x1b
+
+enum bl_commands {
+ BL_CMD_WRBLK = 0x39,
+ BL_CMD_INIT = 0x38,
+ BL_CMD_TERMINATE = 0x3b,
+};
+/* TODO: Add key as part of platform data */
+#define KEY_CS (0 + 1 + 2 + 3 + 4 + 5 + 6 + 7)
+#define KEY {0, 1, 2, 3, 4, 5, 6, 7}
+
+static const char _key[] = KEY;
+#define KEY_LEN sizeof(_key)
+
+static int rec_cnt;
+struct fw_record {
+ u8 seed;
+ u8 cmd;
+ u8 key[KEY_LEN];
+ u8 blk_hi;
+ u8 blk_lo;
+ u8 data[DATA_REC_LEN];
+ u8 data_cs;
+ u8 rec_cs;
+};
+#define fw_rec_size (sizeof(struct fw_record))
+
+struct cmd_record {
+ u8 reg;
+ u8 seed;
+ u8 cmd;
+ u8 key[KEY_LEN];
+};
+#define cmd_rec_size (sizeof(struct cmd_record))
+
+static struct fw_record data_record = {
+ .seed = BLK_SEED,
+ .cmd = BL_CMD_WRBLK,
+ .key = KEY,
+};
+
+static const struct cmd_record terminate_rec = {
+ .reg = 0,
+ .seed = BLK_SEED,
+ .cmd = BL_CMD_TERMINATE,
+ .key = KEY,
+};
+static const struct cmd_record initiate_rec = {
+ .reg = 0,
+ .seed = BLK_SEED,
+ .cmd = BL_CMD_INIT,
+ .key = KEY,
+};
+
+#define BL_REC1_ADDR 0x0780
+#define BL_REC2_ADDR 0x07c0
+
+#define ID_INFO_REC ":40078000"
+#define ID_INFO_OFFSET_IN_REC 77
+
+#define REC_START_CHR ':'
+#define REC_LEN_OFFSET 1
+#define REC_ADDR_HI_OFFSET 3
+#define REC_ADDR_LO_OFFSET 5
+#define REC_TYPE_OFFSET 7
+#define REC_DATA_OFFSET 9
+#define REC_LINE_SIZE 141
+
+static int cyttsp_soft_reset(struct cyttsp *ts)
+{
+ int retval = 0, tries = 0;
+ u8 host_reg = CY_SOFT_RESET_MODE;
+
+ #if 0
+ gpio_set_value(ts->platform_data->resout_gpio, 1); //reset high valid
+ msleep(100);
+ gpio_set_value(ts->platform_data->resout_gpio, 0);
+ msleep(1000);
+ #endif
+ LOG_TP();
+
+ #if 1// 0 modify 2013-1-7!!!!!!!!!!!
+ do {
+ retval = i2c_smbus_write_i2c_block_data(ts->client,
+ CY_REG_BASE, sizeof(host_reg), &host_reg);
+ if (retval < 0)
+ msleep(20);
+ } while (tries++ < 10 && (retval < 0));
+
+ if (retval < 0) {
+ pr_err("%s: failed\n", __func__);
+ return retval;
+ }
+ #else
+ cyttsp_hw_reset(); //!!!! 2013-1-7 may not go here !!!
+ #endif
+
+ LOG_TP();
+ tries = 0;
+ do {
+ msleep(20);
+ cyttsp_putbl(ts, 1, true, true, false);
+ } while (g_bl_data.bl_status != 0x10 &&
+ g_bl_data.bl_status != 0x11 &&
+ tries++ < 100);
+ LOG_TP();
+ if (g_bl_data.bl_status != 0x11 && g_bl_data.bl_status != 0x10)
+ return -EINVAL;
+ LOG_TP();
+ return 0;
+}
+
+static void cyttsp_exit_bl_mode(struct cyttsp *ts)
+{
+ int retval, tries = 0;
+
+ do {
+ retval = i2c_smbus_write_i2c_block_data(ts->client,
+ CY_REG_BASE, sizeof(bl_cmd), bl_cmd);
+ if (retval < 0)
+ msleep(20);
+ } while (tries++ < 10 && (retval < 0));
+}
+
+static void cyttsp_set_sysinfo_mode(struct cyttsp *ts)
+{
+ int retval, tries = 0;
+ u8 host_reg = CY_SYSINFO_MODE;
+
+ do {
+ retval = i2c_smbus_write_i2c_block_data(ts->client,
+ CY_REG_BASE, sizeof(host_reg), &host_reg);
+ if (retval < 0)
+ msleep(20);
+ } while (tries++ < 10 && (retval < 0));
+
+ /* wait for TTSP Device to complete switch to SysInfo mode */
+ if (!(retval < 0)) {
+ retval = i2c_smbus_read_i2c_block_data(ts->client,
+ CY_REG_BASE,
+ sizeof(struct cyttsp_sysinfo_data_t),
+ (u8 *)&g_sysinfo_data);
+ } else
+ pr_err("%s: failed\n", __func__);
+}
+
+static void cyttsp_set_opmode(struct cyttsp *ts)
+{
+ int retval, tries = 0;
+ u8 host_reg = CY_OP_MODE;
+
+ do {
+ retval = i2c_smbus_write_i2c_block_data(ts->client,
+ CY_REG_BASE, sizeof(host_reg), &host_reg);
+ if (retval < 0)
+ msleep(20);
+ } while (tries++ < 10 && (retval < 0));
+}
+
+static int str2uc(char *str, u8 *val)
+{
+ char substr[3];
+ unsigned long ulval;
+ int rc;
+
+ if (!str && strlen(str) < 2)
+ return -EINVAL;
+
+ substr[0] = str[0];
+ substr[1] = str[1];
+ substr[2] = '\0';
+
+ rc = strict_strtoul(substr, 16, &ulval);
+ if (rc != 0)
+ return rc;
+
+ *val = (u8) ulval;
+
+ return 0;
+}
+
+static int flash_block(struct cyttsp *ts, u8 *blk, int len)
+{
+ int retval, i, tries = 0;
+ char buf[(2 * (BLK_SIZE + 1)) + 1];
+ char *p = buf;
+
+ for (i = 0; i < len; i++, p += 2)
+ sprintf(p, "%02x", blk[i]);
+ pr_debug("%s: size %d, pos %ld payload %s\n",
+ __func__, len, (long)0, buf);
+
+ do {
+ retval = i2c_smbus_write_i2c_block_data(ts->client,
+ CY_REG_BASE, len, blk);
+ if (retval < 0)
+ msleep(20);
+ } while (tries++ < 20 && (retval < 0));
+
+ if (retval < 0) {
+ pr_err("%s: failed\n", __func__);
+ return retval;
+ }
+
+ return 0;
+}
+
+static int flash_command(struct cyttsp *ts, const struct cmd_record *record)
+{
+ return flash_block(ts, (u8 *)record, cmd_rec_size);
+}
+
+static void init_data_record(struct fw_record *rec, unsigned short addr)
+{
+ addr >>= 6;
+ rec->blk_hi = (addr >> 8) & 0xff;
+ rec->blk_lo = addr & 0xff;
+ rec->rec_cs = rec->blk_hi + rec->blk_lo +
+ (unsigned char)(BLK_SEED + BL_CMD_WRBLK + KEY_CS);
+ rec->data_cs = 0;
+}
+
+static int check_record(u8 *rec)
+{
+ int rc;
+ u16 addr;
+ u8 r_len, type, hi_off, lo_off;
+
+ rc = str2uc(rec + REC_LEN_OFFSET, &r_len);
+ if (rc < 0)
+ return rc;
+
+ rc = str2uc(rec + REC_TYPE_OFFSET, &type);
+ if (rc < 0)
+ return rc;
+
+ if (*rec != REC_START_CHR || r_len != DATA_REC_LEN || type != 0)
+ return -EINVAL;
+
+ rc = str2uc(rec + REC_ADDR_HI_OFFSET, &hi_off);
+ if (rc < 0)
+ return rc;
+
+ rc = str2uc(rec + REC_ADDR_LO_OFFSET, &lo_off);
+ if (rc < 0)
+ return rc;
+
+ addr = (hi_off << 8) | lo_off;
+
+ if (addr >= START_ADDR || addr == BL_REC1_ADDR || addr == BL_REC2_ADDR)
+ return 0;
+
+ return -EINVAL;
+}
+
+static struct fw_record *prepare_record(u8 *rec)
+{
+ int i, rc;
+ u16 addr;
+ u8 hi_off, lo_off;
+ u8 *p;
+
+ rc = str2uc(rec + REC_ADDR_HI_OFFSET, &hi_off);
+ if (rc < 0)
+ return ERR_PTR((long) rc);
+
+ rc = str2uc(rec + REC_ADDR_LO_OFFSET, &lo_off);
+ if (rc < 0)
+ return ERR_PTR((long) rc);
+
+ addr = (hi_off << 8) | lo_off;
+
+ init_data_record(&data_record, addr);
+ p = rec + REC_DATA_OFFSET;
+ for (i = 0; i < DATA_REC_LEN; i++) {
+ rc = str2uc(p, &data_record.data[i]);
+ if (rc < 0)
+ return ERR_PTR((long) rc);
+ data_record.data_cs += data_record.data[i];
+ data_record.rec_cs += data_record.data[i];
+ p += 2;
+ }
+ data_record.rec_cs += data_record.data_cs;
+
+ return &data_record;
+}
+
+static int flash_record(struct cyttsp *ts, const struct fw_record *record)
+{
+ int len = fw_rec_size;
+ int blk_len, rc;
+ u8 *rec = (u8 *)record;
+ u8 data[BLK_SIZE + 1];
+ u8 blk_offset;
+
+ for (blk_offset = 0; len; len -= blk_len) {
+ data[0] = blk_offset;
+ blk_len = len > BLK_SIZE ? BLK_SIZE : len;
+ memcpy(data + 1, rec, blk_len);
+ rec += blk_len;
+ rc = flash_block(ts, data, blk_len + 1);
+ if (rc < 0)
+ return rc;
+ blk_offset += blk_len;
+ }
+ return 0;
+}
+
+static int flash_data_rec(struct cyttsp *ts, u8 *buf)
+{
+ struct fw_record *rec;
+ int rc, tries;
+LOG_TP();
+ if (!buf)
+ return -EINVAL;
+
+ rc = check_record(buf);
+
+ if (rc < 0) {
+ pr_debug("%s: record ignored %s", __func__, buf);
+ return 0;
+ }
+
+ rec = prepare_record(buf);
+ if (IS_ERR_OR_NULL(rec))
+ return PTR_ERR(rec);
+
+ rc = flash_record(ts, rec);
+ if (rc < 0)
+ return rc;
+
+ tries = 0;
+ do {
+//printk("++++%s, Line %d, tries=%d\n", __FUNCTION__, __LINE__,tries ); //wujinyou
+
+ //if (rec_cnt%2)
+ //msleep(20);
+ if(tries >50)
+ {
+ printk("++++%s, Line %d, tries=%d\n", __FUNCTION__, __LINE__,tries ); //wujinyou
+ msleep(20);
+ }
+ cyttsp_putbl(ts, 4, true, false, false);
+ } while (g_bl_data.bl_status != 0x10 &&
+ g_bl_data.bl_status != 0x11 &&
+ tries++ < 100);
+ rec_cnt++;
+ return rc;
+}
+
+static int cyttspfw_flash_firmware(struct cyttsp *ts, const u8 *data,
+ int data_len)
+{
+ u8 *buf;
+ int i, j;
+ int rc, tries = 0;
+ LOG_TP();
+
+ /* initiate bootload: this will erase all the existing data */
+ rc = flash_command(ts, &initiate_rec);
+ if (rc < 0)
+ return rc;
+
+ do {
+// LOG_TP();
+printk("++++%s, Line %d, tries=%d\n", __FUNCTION__, __LINE__,tries );
+ msleep(60);
+ cyttsp_putbl(ts, 4, true, false, false);
+ } while (g_bl_data.bl_status != 0x10 &&
+ g_bl_data.bl_status != 0x11 &&
+ tries++ < 100);
+
+ buf = kzalloc(REC_LINE_SIZE + 1, GFP_KERNEL);
+ if (!buf) {
+ pr_err("%s: no memory\n", __func__);
+ return -ENOMEM;
+ }
+ LOG_TP();
+ rec_cnt = 0;
+ /* flash data records */
+ for (i = 0, j = 0; i < data_len; i++, j++) {
+ if ((data[i] == REC_START_CHR) && j) {
+ buf[j] = 0;
+ rc = flash_data_rec(ts, buf);
+ if (rc < 0)
+ return rc;
+ j = 0;
+ }
+ buf[j] = data[i];
+ }
+ LOG_TP();
+ /* flash last data record */
+ if (j) {
+ buf[j] = 0;
+ rc = flash_data_rec(ts, buf);
+ if (rc < 0)
+ return rc;
+ }
+ LOG_TP();
+ kfree(buf);
+
+ /* termiate bootload */
+ tries = 0;
+ rc = flash_command(ts, &terminate_rec);
+ do {
+ msleep(100);
+printk("++++%s, Line %d, tries=%d\n", __FUNCTION__, __LINE__,tries );
+
+ cyttsp_putbl(ts, 4, true, false, false);
+ } while (g_bl_data.bl_status != 0x10 &&
+ g_bl_data.bl_status != 0x11 &&
+ tries++ < 100);
+ LOG_TP();
+ return rc;
+}
+
+static int get_hex_fw_ver(u8 *p, u8 *ttspver_hi, u8 *ttspver_lo,
+ u8 *appid_hi, u8 *appid_lo, u8 *appver_hi,
+ u8 *appver_lo, u8 *cid_0, u8 *cid_1, u8 *cid_2)
+{
+ int rc;
+
+ p = p + ID_INFO_OFFSET_IN_REC;
+ rc = str2uc(p, ttspver_hi);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, ttspver_lo);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, appid_hi);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, appid_lo);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, appver_hi);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, appver_lo);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, cid_0);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, cid_1);
+ if (rc < 0)
+ return rc;
+ p += 2;
+ rc = str2uc(p, cid_2);
+ if (rc < 0)
+ return rc;
+
+ return 0;
+}
+
+static void cyttspfw_flash_start(struct cyttsp *ts, const u8 *data,
+ int data_len, u8 *buf, bool force)
+{
+ int rc;
+ u8 ttspver_hi = 0, ttspver_lo = 0, fw_upgrade = 0;
+ u8 appid_hi = 0, appid_lo = 0;
+ u8 appver_hi = 0, appver_lo = 0;
+ u8 cid_0 = 0, cid_1 = 0, cid_2 = 0;
+ char *p = buf;
+
+ /* get hex firmware version */
+ rc = get_hex_fw_ver(p, &ttspver_hi, &ttspver_lo,
+ &appid_hi, &appid_lo, &appver_hi,
+ &appver_lo, &cid_0, &cid_1, &cid_2);
+printk("++++tpd-fw-ver: %x %x %x %x %x %x %x %x %x\n", ttspver_hi, ttspver_lo, appid_hi, appid_lo, appver_hi,appver_lo, cid_0, cid_1,cid_2);
+ if (rc < 0) {
+ pr_err("%s: unable to get hex firmware version\n", __func__);
+ return;
+ }
+#if 0 //wujinyou
+ /* disable interrupts before flashing */
+ if (ts->client->irq == 0)
+ del_timer(&ts->timer);
+ else
+ disable_irq(ts->client->irq);
+
+ rc = cancel_work_sync(&ts->work);
+
+ if (rc && ts->client->irq)
+ enable_irq(ts->client->irq);
+#endif
+
+ /* enter bootloader idle mode */
+ rc = cyttsp_soft_reset(ts);
+ //LOG_TP();
+ printk("++++%s, Line %d, rc=%d\n", __FUNCTION__, __LINE__,rc);
+
+ if (rc < 0) {
+ LOG_TP();
+ pr_err("%s: cyttsp_soft_reset try entering into idle mode"
+ " second time\n", __func__);
+ msleep(1000);
+
+ rc = cyttsp_soft_reset(ts);
+ }
+
+ if (rc < 0) {
+ LOG_TP();
+ pr_err("%s:cyttsp_soft_reset try again later\n", __func__);
+ return;
+ }
+
+ LOG_TP();
+
+ pr_info("Current firmware:lusongbai %d.%d.%d", g_bl_data.appid_lo,
+ g_bl_data.appver_hi, g_bl_data.appver_lo);
+ pr_info("New firmware: %d.%d.%d", appid_lo, appver_hi, appver_lo);
+ LOG_TP();
+
+ if (force)
+ fw_upgrade = 1;
+ else
+ if ((appid_hi == g_bl_data.appid_hi) &&
+ (appid_lo == g_bl_data.appid_lo)) {
+ if (appver_hi > g_bl_data.appver_hi) {
+ fw_upgrade = 1;
+ } else if ((appver_hi == g_bl_data.appver_hi) &&
+ (appver_lo > g_bl_data.appver_lo)) {
+ fw_upgrade = 1;
+ } else {
+ fw_upgrade = 0;
+ pr_info("%s: Firmware version "
+ "lesser/equal to existing firmware, "
+ "upgrade not needed\n", __func__);
+ }
+ } else {
+ fw_upgrade = 0;
+ pr_info("%s: Firware versions do not match, "
+ "cannot upgrade\n", __func__);
+ }
+
+ printk("++++%s, Line %d, fw_upgrade=%d\n", __FUNCTION__, __LINE__,fw_upgrade);
+
+ if (fw_upgrade) {
+ pr_info("%s: Starting firmware upgrade\n", __func__);
+ rc = cyttspfw_flash_firmware(ts, data, data_len);
+ if (rc < 0)
+ pr_err("%s: firmware upgrade failed\n", __func__);
+ else
+ pr_info("%s: lusongbai firmware upgrade success\n", __func__);
+ }
+ LOG_TP();
+
+ /* enter bootloader idle mode */
+ cyttsp_soft_reset(ts);
+ LOG_TP();
+
+ /* exit bootloader mode */
+ cyttsp_exit_bl_mode(ts);
+ LOG_TP();
+
+ msleep(100);
+ /* set sysinfo details */
+ cyttsp_set_sysinfo_mode(ts);
+ LOG_TP();
+
+ /* enter application mode */
+ cyttsp_set_opmode(ts);
+ LOG_TP();
+
+ if((fw_upgrade == 1) && (rc >= 0))
+ {
+ u8 tmpData[18] = {0};
+ rc = i2c_smbus_read_i2c_block_data(ts->client,CY_REG_BASE,18, tmpData);
+ if(rc < 0)
+ {
+ printk(KERN_ERR"cyttspfw_flash_start read version and module error\n");
+ }
+ else
+ {
+ cyttsp_vendor_id=tmpData[16];
+ cyttsp_firmware_version = tmpData[17];
+ printk(KERN_ERR"cyttspfw_flash_start tp module is:%x firmware version is %x:\n",tmpData[16],tmpData[17]);
+ }
+ }
+ LOG_TP();
+
+ /* enable interrupts */
+#if 0
+ if (ts->client->irq == 0)
+ mod_timer(&ts->timer, jiffies + TOUCHSCREEN_TIMEOUT);
+ else
+ enable_irq(ts->client->irq);
+#endif
+ LOG_TP();
+
+}
+
+static void cyttspfw_upgrade_start(struct cyttsp *ts, const u8 *data,
+ int data_len, bool force)
+{
+ int i, j;
+ u8 *buf;
+
+ buf = kzalloc(REC_LINE_SIZE + 1, GFP_KERNEL);
+ if (!buf) {
+ pr_err("%s: no memory\n", __func__);
+ return;
+ }
+
+ for (i = 0, j = 0; i < data_len; i++, j++) {
+ if ((data[i] == REC_START_CHR) && j) {
+ buf[j] = 0;
+ j = 0;
+ if (!strncmp(buf, ID_INFO_REC, strlen(ID_INFO_REC))) {
+ cyttspfw_flash_start(ts, data, data_len,
+ buf, force);
+ break;
+ }
+ }
+ buf[j] = data[i];
+ }
+
+ /* check in the last record of firmware */
+ if (j) {
+ buf[j] = 0;
+ if (!strncmp(buf, ID_INFO_REC, strlen(ID_INFO_REC))) {
+ cyttspfw_flash_start(ts, data, data_len,
+ buf, force);
+ }
+ }
+
+ kfree(buf);
+}
+static bool cyttsp_IsTpInBootloader(struct cyttsp *ts)
+{
+ int retval = -1;
+ u8 tmpData[18] = {0};
+ retval = i2c_smbus_read_i2c_block_data(ts->client,CY_REG_BASE,18, tmpData);
+ if(retval < 0)
+ {
+ printk(KERN_ERR"cyttsp_IsTpInBootloader read version and module error\n");
+ return false;
+ }
+ else
+ {
+ retval = 0;
+ retval = ((tmpData[1] & 0x10) >> 4);
+
+ printk(KERN_ERR"cyttsp_IsTpInBootloader tmpData[1]:%x retval:%x\n",tmpData[1],retval);
+ }
+ if(retval == 0)
+ {
+ return false;
+ }
+ return true;
+
+}
+
+const u8 fw_hex_of[] = {
+// #include "BOOT_AG500_OF_DW_2802_V2_20120702.i"
+// #include "BOOT_AG500_OF_DW_2803_V3_20120711.i"
+};
+const u8 fw_hex_hhx[] = {
+// #include "BOOT_AG500_F5_HHX_2503_V3_20120711.i"
+};
+struct cyttsp cust_ts;
+const u8* fw_hex = fw_hex_hhx;
+extern void cyttsp_print_reg(struct i2c_client *client);
+
+int read_vender_id(void)
+{
+ char buffer[32];
+ int ret =0;
+
+ ret = i2c_smbus_read_i2c_block_data(cust_ts.client, 0x00, 24, &(buffer[0]));
+ if(ret<0)
+ {
+ return -1;
+ }
+ cyttsp_vendor_id = buffer[3];
+ printk("++++cyttp read_vender_id=0x%x\n", cyttsp_vendor_id);
+ cyttsp_print_reg(cust_ts.client);
+ return 0;
+}
+
+
+void cyttsp_fw_upgrade(void)
+{
+ struct cyttsp *ts = &cust_ts;
+ bool force = 1;
+ /* check and start upgrade */
+ //if upgrade failed we should force upgrage when next power up
+
+ if(read_vender_id() != 0)
+ {
+ printk("++++cyttspfw_upgrade read vender id failed!\n");
+ return;
+ }
+ switch(cyttsp_vendor_id)
+ {
+ case 0x28:
+ fw_hex = fw_hex_of;
+ break;
+ case 0x25:
+ fw_hex = fw_hex_hhx;
+ break;
+ case 0x0:
+ break;
+ default:
+ break;
+ }
+
+ if(cyttsp_IsTpInBootloader(ts) == true)
+ {
+ LOG_TP();
+ printk(KERN_ERR"cyttspfw_upgrade we should force upgrade tp fw\n");
+ cyttspfw_upgrade_start(ts, fw_hex,
+ sizeof(fw_hex_of), true);
+ }
+ else
+ {
+ LOG_TP();
+ cyttspfw_upgrade_start(ts, fw_hex,
+ sizeof(fw_hex_of), force);
+ }
+}
+
+#endif
+
+
+
+static int cyttsp_putbl(struct cyttsp *ts, int show,
+ int show_status, int show_version, int show_cid)
+{
+ int retval = CY_OK;
+
+ int num_bytes = (show_status * 3) + (show_version * 6) + (show_cid * 3);
+
+ if (show_cid)
+ num_bytes = sizeof(struct cyttsp_bootloader_data_t);
+ else if (show_version)
+ num_bytes = sizeof(struct cyttsp_bootloader_data_t) - 3;
+ else
+ num_bytes = sizeof(struct cyttsp_bootloader_data_t) - 9;
+ LOG_TP();
+
+ if (show) {
+ retval = i2c_smbus_read_i2c_block_data(ts->client,
+ CY_REG_BASE, num_bytes, (u8 *)&g_bl_data);
+
+ {
+ int i = 0;
+ printk("cyttsp_putbl:");
+ for(i=0; i<num_bytes; i++)
+ printk(" 0x%x",*((u8 *)&g_bl_data+i));
+ printk("\n");
+ }
+ if (show_status) {
+ cyttsp_debug("BL%d: f=%02X s=%02X err=%02X bl=%02X%02X bld=%02X%02X\n", \
+ show, \
+ g_bl_data.bl_file, \
+ g_bl_data.bl_status, \
+ g_bl_data.bl_error, \
+ g_bl_data.blver_hi, g_bl_data.blver_lo, \
+ g_bl_data.bld_blver_hi, g_bl_data.bld_blver_lo);
+ }
+ if (show_version) {
+ cyttsp_debug("BL%d: ttspver=0x%02X%02X appid=0x%02X%02X appver=0x%02X%02X\n", \
+ show, \
+ g_bl_data.ttspver_hi, g_bl_data.ttspver_lo, \
+ g_bl_data.appid_hi, g_bl_data.appid_lo, \
+ g_bl_data.appver_hi, g_bl_data.appver_lo);
+ }
+ if (show_cid) {
+ cyttsp_debug("BL%d: cid=0x%02X%02X%02X\n", \
+ show, \
+ g_bl_data.cid_0, \
+ g_bl_data.cid_1, \
+ g_bl_data.cid_2);
+ }
+ }
+ //LOG_TP();
+
+ return retval;
+}
+
+
+#ifndef CYTTSP_SUPPORT_SYS_NODE
+static void cyttsp_exit_bl_mode(struct cyttsp *ts)
+{
+ int retval, tries = 0;
+
+ do {
+ retval = i2c_smbus_write_i2c_block_data(ts->client,
+ CY_REG_BASE, sizeof(bl_cmd), bl_cmd);
+ if (retval < 0)
+ msleep(20);
+ } while (tries++ < 10 && (retval < 0));
+}
+#endif
+
+
+
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/debug.txt b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/debug.txt
new file mode 100755
index 00000000..a424c186
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/debug.txt
@@ -0,0 +1,3 @@
+/ # wmtenv get wmt.io.touch
+1:cyp140:7:600:1024:4:0:1:-1:5 //it seems ok
+
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.c b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.c
new file mode 100755
index 00000000..d7234ac3
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.c
@@ -0,0 +1,1094 @@
+#include <linux/unistd.h>
+#include <linux/time.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+//#include <asm/semaphore.h>
+#include <linux/proc_fs.h>
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/interrupt.h>
+#include <linux/suspend.h>
+#include <linux/input.h>
+#include <linux/types.h>
+#include <linux/platform_device.h>
+#include <mach/hardware.h>
+#include <linux/i2c.h>
+#include <linux/irq.h>
+#include <linux/gpio.h>
+#include <mach/wmt_iomux.h>
+
+#include <asm/uaccess.h>
+#include <linux/fs.h>
+#include <linux/syscalls.h>
+
+#include "wmt_ts.h"
+//#include "zet6221_ts.h"
+
+/////////////////////////////////////////////////////////////////
+
+// commands for ui
+#define TS_IOC_MAGIC 't'
+
+#define TS_IOCTL_CAL_START _IO(TS_IOC_MAGIC, 1)
+#define TS_IOCTL_CAL_DONE _IOW(TS_IOC_MAGIC, 2, int*)
+#define TS_IOCTL_GET_RAWDATA _IOR(TS_IOC_MAGIC, 3, int*)
+#define TS_IOCTL_CAL_QUIT _IOW(TS_IOC_MAGIC, 4, int*)
+#define TS_IOCTL_AUTO_CALIBRATION _IOW(TS_IOC_MAGIC, 5, int*)
+#define TS_IOC_MAXNR 5
+
+#define TP_INFOR_ARRAY_SIZE (sizeof(l_tpinfor)/sizeof(l_tpinfor[1]))
+//
+#define TS_MAJOR 11
+#define TS_DRIVER_NAME "wmtts_touch"
+#define TS_NAME "wmtts"
+#define WMTTS_PROC_NAME "wmtts_config"
+
+#define EXT_GPIO0 0
+#define EXT_GPIO1 1
+#define EXT_GPIO2 2
+#define EXT_GPIO3 3
+#define EXT_GPIO4 4
+#define EXT_GPIO5 5
+#define EXT_GPIO6 6
+#define EXT_GPIO7 7
+
+typedef struct {
+ int a1;
+ int b1;
+ int c1;
+ int a2;
+ int b2;
+ int c2;
+ int delta;
+}CALIBRATION_PARAMETER, *PCALIBRATION_PARAMETER;
+
+
+static int irq_gpio = 7;//!!!2012-12-28
+static int rst_gpio = 4;//
+static int panelres_x;
+static int panelres_y;
+static DECLARE_WAIT_QUEUE_HEAD(queue);
+static CALIBRATION_PARAMETER g_CalcParam;
+static TS_EVENT g_evLast;
+static struct mutex cal_mutex;
+static DECLARE_WAIT_QUEUE_HEAD(ts_penup_wait_queue);
+static int lcd_exchg = 0;
+
+static struct class* l_dev_class = NULL;
+static struct device *l_clsdevice = NULL;
+extern struct wmtts_device cyp140_tsdev;
+static struct wmtts_device* l_tsdev = &cyp140_tsdev;
+struct proc_dir_entry* l_tsproc = NULL;
+static struct i2c_client *l_client=NULL;
+static int l_penup = 1; // 1-pen up,0-pen down
+
+struct tp_infor
+{
+ //enum tp_type type;
+ char name[64];
+ //unsigned int i2caddr;
+ unsigned int xaxis; //0: x,1: x swap with y
+ unsigned int xdir; // 1: positive,-1: revert
+ unsigned int ydir; // 1: positive,-1: revert
+ unsigned int max_finger_num;
+};
+
+static int l_tpindex = -1;
+static struct tp_infor l_tpinfor[1];
+
+/////////////////////////////////////////////////////
+// function declare
+/////////////////////////////////////////////////////
+extern int wmt_getsyspara(char *varname, unsigned char *varval, int *varlen);
+extern int wmt_setsyspara(char *varname, unsigned char *varval);
+static int ts_writeproc( struct file *file,
+ const char *buffer,
+ unsigned long count,
+ void *data );
+static int ts_readproc(char *page, char **start, off_t off,
+ int count, int *eof, void *data);
+///////////////////////////////////////////////////////////////////////
+void TouchPanelCalibrateAPoint(
+ int UncalX, //@PARM The uncalibrated X coordinate
+ int UncalY, //@PARM The uncalibrated Y coordinate
+ int *pCalX, //@PARM The calibrated X coordinate
+ int *pCalY //@PARM The calibrated Y coordinate
+ )
+{
+ int x, y;
+ mutex_lock(&cal_mutex);
+ x = (g_CalcParam.a1 * UncalX + g_CalcParam.b1 * UncalY +
+ g_CalcParam.c1) / g_CalcParam.delta;
+ y = (g_CalcParam.a2 * UncalX + g_CalcParam.b2 * UncalY +
+ g_CalcParam.c2) / g_CalcParam.delta;
+
+//klog("afer(%d,%d)(%d,%d)\n", x,y,panelres_x,panelres_y);
+ if ( x < 0 )
+ x = 0;
+
+ if ( y < 0 )
+ y = 0;
+ if (x >= panelres_x)
+ x = panelres_x-1;
+ if (y >= panelres_y)
+ y = panelres_y-1;
+
+ *pCalX = x;
+ *pCalY = y;
+ mutex_unlock(&cal_mutex);
+ return;
+}
+
+int wmt_ts_if_updatefw(void)
+{
+ /*if ((!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7dgntpc0350")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7zcc1950")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_8dgntpc0406")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7adc700148")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_8xdc806")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7tp070005q8")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7yiheng7002")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7atc7031"))||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7xclg7027a")) ||
+ (!strcmp(l_tpinfor[l_tpindex].name,"ZET6221_7est07000416")))
+ {
+ return 1;
+ }
+
+ return 0;
+ */
+
+ struct file *fp;
+ char filepath[128];
+
+ sprintf(filepath,"/lib/firmware/%s_fw.ts",l_tpinfor[l_tpindex].name);
+
+ fp = filp_open(filepath, O_RDONLY, 0);
+ if (IS_ERR(fp))
+ {
+ //printk("create file error\n");
+ return 0;
+ }
+ filp_close(fp, NULL);
+ return 1;
+}
+
+unsigned int wmt_ts_get_xaxis(void)
+{
+ return l_tpinfor[l_tpindex].xaxis;
+}
+
+unsigned int wmt_ts_get_xdir(void)
+{
+ return l_tpinfor[l_tpindex].xdir;
+}
+
+unsigned int wmt_ts_get_ydir(void)
+{
+ return l_tpinfor[l_tpindex].ydir;
+}
+
+unsigned int wmt_ts_get_maxfingernum(void)
+{
+ return l_tpinfor[l_tpindex].max_finger_num;
+}
+
+#if 0
+static int parse_firmwarefile(char* filedata, unsigned char** firmarr, int maxlen)
+{
+ char endflag[]="/* End flag */";
+ char* p = filedata;
+ int i = 0;
+ int j = 0;
+ char* s = NULL;
+
+ s = p;
+ // calculate the number of array
+ while (strncmp(p,endflag,strlen(endflag)))
+ {
+ if (!strncmp(p,"0x",strlen("0x")))
+ {
+ i++;
+ }
+ p++;
+ };
+ dbg("the number of arry:0x%x\n", i);
+ // alloc the memory for array
+ j = i + i%4;
+ *firmarr = kzalloc(sizeof(unsigned char)*j, GFP_KERNEL);
+ // parse the value of array
+ p = s;
+ j = 0;
+ while (strncmp(p,endflag,strlen(endflag)))
+ {
+ if (!strncmp(p,"0x",strlen("0x")))
+ {
+ //dbg("find 0x!\n");
+ sscanf(p,"0x%x", &((*firmarr)[j]));
+ //dbg("arry[0x%x]:%x\n",j,(*firmarr)[j]);
+ j++;
+ p+=4;
+ } else {
+ p++;
+ }
+ //p = strchr(p,'}');
+ if (j>=i-2)
+ {
+ dbg("%s",p);
+ }
+
+ };
+ if (i != j)
+ {
+ errlog("Error parsing file(the number of arry not match)!\n");
+ return -1;
+ };
+ dbg("paring firmware file end.\n");
+ return i;
+}
+
+//filepath:the path of firmware file;
+//firmdata:store the data from firmware file;
+//return:0-successful,negative-parsing error.
+int read_firmwarefile(char* filepath, unsigned char** firmdata)
+{
+ struct file *fp;
+ mm_segment_t fs;
+ loff_t pos;
+ char* data = NULL;
+ long fsize;
+ int alloclen = 2052*(8*5+2)+200;
+ int i = 0;
+
+ klog("ts firmware file:%s\n",filepath);
+ data = kzalloc(alloclen, GFP_KERNEL);
+ if (data == NULL)
+ {
+ errlog("Error when alloc memory for firmware file!\n");
+ return -1;
+ }
+ fp = filp_open(filepath, O_RDONLY, 0);
+ if (IS_ERR(fp)) {
+ printk("create file error\n");
+ goto error_flip_open;
+ }
+ fs = get_fs();
+ set_fs(KERNEL_DS);
+ pos = 0;
+ fsize = vfs_read(fp, data, alloclen, &pos);
+ dbg("filesize:0x%x,alloclen:0x%x\n",fsize,alloclen);
+ if (fsize <= 0)
+ {
+ errlog("alloc size is too small.\n");
+ goto error_vfs_read;
+ }
+ i = parse_firmwarefile(data,firmdata,fsize);
+ // Check the parsing and ori file
+ /* for (i=0;i < maxlen; i++)
+ {
+ if (firmdata[i]!=nvctp_BinaryFile_default[i])
+ {
+ errlog("Don't match:i=%x,parse:0x%x,ori:0x%x\n",i,firmdata[i], nvctp_BinaryFile_default[i]);
+ break;
+ }
+ };
+ dbg("parsing match with ori.\n");
+ */
+ filp_close(fp, NULL);
+ set_fs(fs);
+ kfree(data);
+ dbg("success to read firmware file!\n");;
+
+ //sscanf(data,"%hd %hd %hd",&offset.u.x,&offset.u.y,&offset.u.z);
+ return i;
+error_vfs_read:
+ filp_close(fp, NULL);
+ set_fs(fs);
+error_flip_open:
+ kfree(data);
+ return -1;
+}
+#endif
+
+void wmt_ts_get_firmwname(char* firmname)
+{
+ sprintf(firmname,"/lib/firmware/%s_fw.ts",l_tpinfor[l_tpindex].name);
+}
+
+ int wmt_ts_get_irqgpnum(void)
+{
+ return irq_gpio;
+}
+
+int wmt_ts_get_resetgpnum(void)
+{
+ return rst_gpio;
+}
+
+ int wmt_ts_get_lcdexchg(void)
+{
+ return lcd_exchg;
+}
+
+int wmt_ts_get_resolvX(void)
+{
+ return panelres_x;
+}
+
+int wmt_ts_get_resolvY(void)
+{
+ return panelres_y;
+}
+
+//up:1-pen up,0-pen down
+void wmt_ts_set_penup(int up)
+{
+ l_penup = up;
+}
+
+//
+int wmt_ts_wait_penup(void)
+{
+ int ret = wait_event_interruptible(
+ ts_penup_wait_queue,
+ (1==l_penup));
+ return ret;
+}
+
+// return:1-pen up,0-pen dwon
+int wmt_ts_ispenup(void)
+{
+ return l_penup;
+}
+
+
+void wmt_ts_wakeup_penup(void)
+{
+ wake_up(&ts_penup_wait_queue);
+}
+
+int wmt_is_tsirq_enable(void)
+{
+ int val = 0;
+ int num = irq_gpio;
+
+ if(num > 11)
+ return 0;
+
+ if(num<4)
+ val = REG32_VAL(__GPIO_BASE+0x0300) & (1<<(num*8+7));
+ else if(num >= 4 && num < 8)
+ val = REG32_VAL(__GPIO_BASE+0x0304) & (1<<((num-4)*8+7));
+ else
+ val = REG32_VAL(__GPIO_BASE+0x0308) & (1<<((num-8)*8+7));
+
+ return val?1:0;
+
+}
+
+int wmt_is_tsint(void)
+{
+ int num = irq_gpio;
+
+ if (num > 11)
+ {
+ return 0;
+ }
+ return (REG32_VAL(__GPIO_BASE+0x0360) & (1<<num)) ? 1: 0;
+}
+
+void wmt_clr_int(void)
+{
+ int num = irq_gpio;
+
+ if (num > 11)
+ {
+ return;
+ }
+ REG32_VAL(__GPIO_BASE+0x0360) = 1<<num;
+}
+
+void wmt_tsreset_init(void)
+{
+ int num = rst_gpio;
+/*
+ REG32_VAL(__GPIO_BASE+0x0040) |= (1<<num);//&= ~(1<<num); //enable gpio
+ REG32_VAL(__GPIO_BASE+0x00C0) &= ~(1<<num); // out low
+ REG32_VAL(__GPIO_BASE+0x0080) |= (1<<num); //output enable
+ msleep(10);
+ REG32_VAL(__GPIO_BASE+0x00C0) |= (1<<num); // out high
+*/
+ gpio_direction_output(num, 0);
+ msleep(10);
+ gpio_set_value(num, 1);
+}
+/*
+// enable:0-disable,1-enable
+void wmt_enable_rst_pull(int enable)
+{
+ if (enable)
+ {
+ REG32_VAL(__GPIO_BASE+0x0480) |= (1<<rst_gpio); //enable pull up/down
+ } else {
+ REG32_VAL(__GPIO_BASE+0x0480) &= ~(1<<rst_gpio); //disable pull up/down
+ }
+}
+*/
+
+// enable:0-disable,1-enable
+void wmt_disable_rst_pull(void)
+{
+ wmt_gpio_setpull(rst_gpio, WMT_GPIO_PULL_NONE);
+
+}
+
+// up:0-pull down,1-pull up
+void wmt_set_rst_pull(int up)
+{
+ wmt_gpio_setpull(rst_gpio, up ? WMT_GPIO_PULL_UP : WMT_GPIO_PULL_DOWN);
+}
+
+// high:0-low level,1-high level
+void wmt_rst_output(int high)
+{
+ if (high)
+ gpio_direction_output(rst_gpio, 1);
+ else
+ gpio_direction_output(rst_gpio, 0);
+}
+
+void wmt_rst_input(void)
+{
+ gpio_direction_input(rst_gpio);
+}
+
+void wmt_set_intasgp(void)
+{
+ REG32_VAL(__GPIO_BASE+0x0040) |= (1<<irq_gpio); //enable gpio
+}
+
+// val:1--high,0-low
+void wmt_intgp_out(int val)
+{
+ if (val)
+ {
+ REG32_VAL(__GPIO_BASE+0x00C0) |= (1<<irq_gpio); // high
+ } else {
+ REG32_VAL(__GPIO_BASE+0x00C0) &= ~(1<<irq_gpio); // low
+ }
+ REG32_VAL(__GPIO_BASE+0x0080) |= (1<<irq_gpio); //set output
+}
+
+void wmt_ts_set_irqinput(void)
+{
+ int num = irq_gpio;
+
+ REG32_VAL(__GPIO_BASE+0x0040) |= (1<<num); //enable gpio
+ REG32_VAL(__GPIO_BASE+0x0080) &= ~(1<<num); //set input
+}
+
+unsigned int wmt_ts_irqinval(void)
+{
+ return REG32_VAL(__GPIO_BASE+0x0000)&(1<<irq_gpio);
+}
+
+int wmt_set_gpirq(int type)
+{
+ int shift;
+ int offset;
+ unsigned long reg;
+ int num = irq_gpio;
+
+ if(num >11)
+ return -1;
+ //if (num > 9)
+ //GPIO_PIN_SHARING_SEL_4BYTE_VAL &= ~BIT4; // gpio10,11 as gpio
+ REG32_VAL(__GPIO_BASE+0x0040) &= ~(1<<num);//|=(1<<num);// //enable gpio
+ REG32_VAL(__GPIO_BASE+0x0080) &= ~(1<<num); //set input
+ REG32_VAL(__GPIO_BASE+0x04c0) |= (1<<num); //pull up
+ //REG32_VAL(__GPIO_BASE+0x0480) &= ~(1<<num); //enable pull up/down .debug pulldown 2013-5-8
+ REG32_VAL(__GPIO_BASE+0x0480) |= (1<<num); //enable pull up/down 2013-1-4 replace 2013-5-7 default enable!!
+ //REG32_VAL(__GPIO_BASE+0x0480) &= ~(1<<num); //enable pull up/down
+ //set gpio irq triger type
+ if(num < 4){//[0,3]
+ shift = num;
+ offset = 0x0300;
+ }else if(num >= 4 && num < 8){//[4,7]
+ shift = num-4;
+ offset = 0x0304;
+ }else{// [8,11]
+ shift = num-8;
+ offset = 0x0308;
+ }
+
+ reg = REG32_VAL(__GPIO_BASE + offset);
+
+ switch(type){
+ case IRQ_TYPE_LEVEL_LOW:
+ reg &= ~(1<<(shift*8+2));
+ reg &= ~(1<<(shift*8+1));
+ reg &= ~(1<<(shift*8));
+ break;
+ case IRQ_TYPE_LEVEL_HIGH:
+ reg &= ~(1<<(shift*8+2));
+ reg &= ~(1<<(shift*8+1));
+ reg |= (1<<(shift*8));
+ break;
+ case IRQ_TYPE_EDGE_FALLING:
+ reg &= ~(1<<(shift*8+2));
+ reg |= (1<<(shift*8+1));
+ reg &= ~(1<<(shift*8));
+ break;
+ case IRQ_TYPE_EDGE_RISING:
+ reg &= ~(1<<(shift*8+2));
+ reg |= (1<<(shift*8+1));
+ reg |= (1<<(shift*8));
+ break;
+ default://both edge
+ reg |= (1<<(shift*8+2));
+ reg &= ~(1<<(shift*8+1));
+ reg &= ~(1<<(shift*8));
+ break;
+
+ }
+ //reg |= 1<<(shift*8+7);//enable interrupt
+ reg &= ~(1<<(shift*8+7)); //disable int
+
+ REG32_VAL(__GPIO_BASE + offset) = reg;
+ REG32_VAL(__GPIO_BASE+0x0360) = 1<<num; //clear interrupt status
+ msleep(5);
+ return 0;
+}
+
+int wmt_enable_gpirq(void)
+{
+ int num = irq_gpio;
+
+ if(num > 11)
+ return -1;
+
+ if(num<4)
+ REG32_VAL(__GPIO_BASE+0x0300) |= 1<<(num*8+7); //enable interrupt
+ else if(num >= 4 && num < 8)
+ REG32_VAL(__GPIO_BASE+0x0304) |= 1<<((num-4)*8+7); //enable interrupt
+ else
+ REG32_VAL(__GPIO_BASE+0x0308) |= 1<<((num-8)*8+7); //enable interrupt
+
+ return 0;
+}
+
+int wmt_disable_gpirq(void)
+{
+ int num = irq_gpio;
+
+ if(num > 11)
+ return -1;
+
+ if(num<4)
+ REG32_VAL(__GPIO_BASE+0x0300) &= ~(1<<(num*8+7)); //enable interrupt
+ else if(num >= 4 && num < 8)
+ REG32_VAL(__GPIO_BASE+0x0304) &= ~(1<<((num-4)*8+7)); //enable interrupt
+ else
+ REG32_VAL(__GPIO_BASE+0x0308) &= ~(1<<((num-8)*8+7)); //enable interrupt
+
+ return 0;
+}
+
+
+int wmt_get_tsirqnum(void)
+{
+ return IRQ_GPIO;
+}
+
+
+int wmt_ts_set_rawcoord(unsigned short x, unsigned short y)
+{
+ g_evLast.x = x;
+ g_evLast.y = y;
+ //dbg("raw(%d,%d)*\n", x, y);
+ return 0;
+}
+
+static void wmt_ts_platform_release(struct device *device)
+{
+ return;
+}
+
+static struct platform_device wmt_ts_plt_device = {
+ .name = TS_DRIVER_NAME,
+ .id = 0,
+ .dev = {
+ .release = wmt_ts_platform_release,
+ },
+// .num_resources = ARRAY_SIZE(wm9715_ts_resources),
+// .resource = wm9715_ts_resources,
+};
+
+static int wmt_ts_suspend(struct platform_device *pdev, pm_message_t state)
+{
+ dbg("ts suspend....\n");
+ return l_tsdev->suspend(pdev, state);
+}
+static int wmt_ts_resume(struct platform_device *pdev)
+{
+ dbg("ts resume....\n");
+ return l_tsdev->resume(pdev);
+}
+
+static int wmt_ts_probe(struct platform_device *pdev)
+{
+ l_tsproc= create_proc_entry(WMTTS_PROC_NAME, 0666, NULL/*&proc_root*/);
+ if (l_tsproc != NULL)
+ {
+ l_tsproc->read_proc = ts_readproc;
+ l_tsproc->write_proc = ts_writeproc;
+ }
+
+ if (l_tsdev->probe != NULL)
+ return l_tsdev->probe(pdev);
+ else
+ return 0;
+}
+
+static int wmt_ts_remove(struct platform_device *pdev)
+{
+ if (l_tsproc != NULL)
+ {
+ remove_proc_entry(WMTTS_PROC_NAME, NULL);
+ l_tsproc = NULL;
+ }
+
+ if (l_tsdev->remove != NULL)
+ return l_tsdev->remove(pdev);
+ else
+ return 0;
+}
+
+static struct platform_driver wmt_ts_plt_driver = {
+ .driver = {
+ .name = TS_DRIVER_NAME,
+ .owner = THIS_MODULE,
+ },
+ .probe = wmt_ts_probe,
+ .remove = wmt_ts_remove,
+ .suspend = wmt_ts_suspend,
+ .resume = wmt_ts_resume,
+};
+
+static int wmt_ts_open(struct inode *inode, struct file *filp)
+{
+ int ret = 0;
+
+ klog("wmt ts driver opening...\n");
+
+ //ts_clear();
+ //try_module_get(THIS_MODULE);
+
+ return ret;
+}
+
+static int wmt_ts_close(struct inode *inode, struct file *filp)
+{
+ klog("wmt ts driver closing...\n");
+ //ts_clear();
+ //module_put(THIS_MODULE);
+
+ return 0;
+}
+
+static unsigned int wmt_ts_poll(struct file *filp, struct poll_table_struct *wait)
+{
+#if 0
+ poll_wait(filp, &queue, wait);
+ if ( head != tail )
+ return (POLLIN | POLLRDNORM);
+#endif
+ return 0;
+}
+
+static long wmt_ts_ioctl(/*struct inode * node,*/ struct file *dev, unsigned int cmd, unsigned long arg)
+{
+ int nBuff[7];
+ char env_val[96]={0};
+ //dbg("wmt_ts_ioctl(node=0x%p, dev=0x%p, cmd=0x%08x, arg=0x%08lx)\n", node, dev, cmd, arg);
+
+ if (_IOC_TYPE(cmd) != TS_IOC_MAGIC){
+ dbg("CMD ERROR!");
+ return -ENOTTY;
+ }
+
+ if (_IOC_NR(cmd) > TS_IOC_MAXNR){
+ dbg("NO SUCH IO CMD!\n");
+ return -ENOTTY;
+ }
+
+ switch (cmd) {
+
+ case TS_IOCTL_CAL_DONE:
+ klog("wmt_ts_ioctl: TS_IOCTL_CAL_DONE\n");
+ copy_from_user(nBuff, (unsigned int*)arg, 7*sizeof(int));
+
+ mutex_lock(&cal_mutex);
+ g_CalcParam.a1 = nBuff[0];
+ g_CalcParam.b1 = nBuff[1];
+ g_CalcParam.c1 = nBuff[2];
+ g_CalcParam.a2 = nBuff[3];
+ g_CalcParam.b2 = nBuff[4];
+ g_CalcParam.c2 = nBuff[5];
+ g_CalcParam.delta = nBuff[6];
+
+ if(g_CalcParam.delta == 0)
+ g_CalcParam.delta =1;//avoid divide by zero
+
+ mutex_unlock(&cal_mutex);
+
+ sprintf(env_val,"%d %d %d %d %d %d %d",nBuff[0],nBuff[1],nBuff[2],nBuff[3],nBuff[4],nBuff[5],nBuff[6]);
+ wmt_setsyspara("wmt.io.ts.2dcal", env_val);
+ klog("Tsc calibrate done data: [%s]\n",env_val);
+
+ return 0;
+
+
+ case TS_IOCTL_GET_RAWDATA:
+ // wait for point up
+ dbg("test wait_penup\n");
+ //l_tsdev->wait_penup(&gt811_tsdev);
+ klog("wmt_ts_ioctl: TS_IOCTL_GET_RAWDATA\n");
+ wmt_ts_wait_penup();
+
+ nBuff[0] = g_evLast.x;
+ nBuff[1] = g_evLast.y;
+ copy_to_user((unsigned int*)arg, nBuff, 2*sizeof(int));
+ klog("raw data: x=%d, y=%d\n", nBuff[0], nBuff[1]);
+
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
+static ssize_t wmt_ts_read(struct file *filp, char *buf, size_t count, loff_t *l)
+{
+ // read firmware file
+
+ return 0;
+}
+
+
+static struct file_operations wmt_ts_fops = {
+ .read = wmt_ts_read,
+ .poll = wmt_ts_poll,
+ .unlocked_ioctl = wmt_ts_ioctl,
+ .open = wmt_ts_open,
+ .release = wmt_ts_close,
+};
+
+static int ts_writeproc( struct file *file,
+ const char *buffer,
+ unsigned long count,
+ void *data )
+{
+ int calibrate = 0;
+ int val = 0;
+
+ if (sscanf(buffer, "calibrate=%d\n", &calibrate))
+ {
+ if (1 == calibrate)
+ {
+ if((l_tsdev->capacitance_calibrate != NULL) &&
+ (0 == l_tsdev->capacitance_calibrate()))
+ {
+ printk(KERN_ALERT "%s calibration successfully!\n", l_tsdev->ts_id);
+ } else {
+ printk(KERN_ALERT "%s calibration failed!\n", l_tsdev->ts_id);
+ }
+ }
+ } else if (sscanf(buffer, "reset=%d\n", &val))
+ {
+
+ }
+ return count;
+}
+
+static int ts_readproc(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ int len = 0;
+
+ len = sprintf(page,
+ "echo calibrate=1 > /proc/wmtts_config to calibrate ts.\n");
+ return len;
+}
+
+static int wmt_check_touch_env(void)
+{
+ int ret = 0;
+ int len = 96, i = 0;
+ char retval[200] = {0},*p=NULL,*s=NULL;
+ //int nBuff[7] = {0};
+ int Enable=0; //Gpio=0,PX=0,PY=0;
+ int val,val1;
+
+ // Get u-boot parameter
+ ret = wmt_getsyspara("wmt.io.touch", retval, &len);
+ if(ret){
+ errlog("Read wmt.io.touch Failed.\n");
+ return -EIO;
+ }
+ memset(l_tpinfor,0,sizeof(l_tpinfor[0]));
+ p = retval;
+ sscanf(p,"%d:", &Enable);
+ p = strchr(p,':');p++;
+ s = strchr(p,':');
+ strncpy(l_tpinfor[0].name,p, (s-p));
+ p = s+1;
+ dbg("ts_name=%s\n", l_tpinfor[0].name);
+
+ ret = sscanf(p,"%d:%d:%d:%d:%d:%d:%d:%d",
+ &irq_gpio,&panelres_x,&panelres_y,&rst_gpio,
+ &(l_tpinfor[0].xaxis),&(l_tpinfor[0].xdir),&(l_tpinfor[0].ydir),
+ &(l_tpinfor[0].max_finger_num));
+ if (ret != 8)
+ {
+ dbg("Wrong format ts u-boot param(%d)!\n",ret);
+ return -ENODEV;
+ }
+ //check touch enable
+ if(Enable == 0){
+ errlog("Touch Screen Is Disabled.\n");
+ return -ENODEV;
+ }
+
+ /*p = strchr(retval,':');
+ p++;
+ if(strncmp(p, l_tsdev->ts_id,strlen(l_tsdev->ts_id))){//check touch ID
+ //errlog(" %s!=====\n", l_tsdev->ts_id);
+ return -ENODEV;
+ }*/
+
+ //sscanf(p,"%s:", );
+#if 1
+ if (strstr(l_tpinfor[0].name, l_tsdev->ts_id) == NULL)// cyp140
+ {
+ dbg("Can't find %s!\n", l_tsdev->ts_id);
+ return -ENODEV;
+ }
+#endif //comment 2012-12-31
+ l_tpindex = 0;
+
+/*
+ p = strchr(p,':');
+ p++;
+ sscanf(p,"%d:%d:%d:%d",&irq_gpio,&panelres_x,&panelres_y,&rst_gpio);
+
+ irq_gpio = Gpio;
+ panelres_x = PX;
+ panelres_y = PY;
+ */
+ klog("p.x = %d, p.y = %d, gpio=%d, resetgpio=%d,xaxis=%d,xdir=%d,ydri=%d,maxfingernum=%d\n",
+ panelres_x, panelres_y, irq_gpio, rst_gpio,
+ l_tpinfor[0].xaxis,l_tpinfor[0].xdir,l_tpinfor[0].ydir,
+ l_tpinfor[0].max_finger_num);
+
+ // parse touch key param
+ memset(retval,0,sizeof(retval));
+ ret = wmt_getsyspara("wmt.io.tskeyindex", retval, &len);
+ if(ret){
+ dbg("no touch key!\n");
+ //return -EIO;
+ } else {
+ p = retval;
+ // the number of touch key
+ sscanf(retval,"%d:", &val);
+ dbg("tskey num:%d\n",val);
+ p = strchr(p,':');
+ p++;
+ // touch key range
+ for (i=0;i<val;i++)
+ {
+ sscanf(p,"%d:",&val1);
+ p = strchr(p,':');
+ p++;
+ //zet6221_set_tskey(i, val1); //own tp ic 2012-12-31??!!!
+ dbg("key%d:(%d)\n",i,val1);
+ };
+ }
+
+ ret = wmt_getsyspara("wmt.display.fb0", retval, &len);
+ if (!ret) {
+ int tmp[6];
+ p = retval;
+ sscanf(p, "%d:[%d:%d:%d:%d:%d", &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]);
+ if (tmp[4] > tmp[5])
+ lcd_exchg = 1;
+ }
+
+/* memset(retval,0,sizeof(retval));
+ ret = wmt_getsyspara("wmt.io.ts.2dcal", retval, &len);
+ if(ret){
+ errlog("Read env wmt.io.ts.2dcal Failed.\n ");
+ //return -EIO;
+ }
+ i = 0;
+ while(i < sizeof(retval)){
+ if(retval[i]==' ' || retval[i]==',' || retval[i]==':')
+ retval[i] = '\0';
+ i++;
+ }
+
+ i = 0;
+ p = retval;
+ while(i<7 && p < (retval + sizeof(retval))){
+ if(*p == '\0')
+ p++;
+ else{
+ sscanf(p,"%d",&nBuff[i]);
+ //printk("%d\n",nBuff[i]);
+ p=p+strlen(p);
+ i++;
+ }
+ }
+ //sscanf(retval,"%d %d %d %d %d %d %d %d",&nBuff[0],&nBuff[1],&nBuff[2],&nBuff[3],&nBuff[4],&nBuff[5],&nBuff[6]);
+ dbg("Tsc calibrate init data: [%d %d %d %d %d %d %d]\n",nBuff[0],nBuff[1],nBuff[2],nBuff[3],nBuff[4],nBuff[5],nBuff[6]);
+
+ g_CalcParam.a1 = nBuff[0];
+ g_CalcParam.b1 = nBuff[1];
+ g_CalcParam.c1 = nBuff[2];
+ g_CalcParam.a2 = nBuff[3];
+ g_CalcParam.b2 = nBuff[4];
+ g_CalcParam.c2 = nBuff[5];
+ g_CalcParam.delta = nBuff[6];
+
+ if(g_CalcParam.delta == 0)
+ g_CalcParam.delta =1;//avoid divide by zero
+*/
+ return 0;
+}
+
+struct i2c_board_info ts_i2c_board_info = {
+ .type = WMT_TS_I2C_NAME,
+ .flags = 0x00,
+ .addr = WMT_TS_I2C_ADDR,
+ .platform_data = NULL,
+ .archdata = NULL,
+ .irq = -1,
+};
+
+static int ts_i2c_register_device (void)
+{
+ struct i2c_board_info *ts_i2c_bi;
+ struct i2c_adapter *adapter = NULL;
+ //struct i2c_client *client = NULL;
+ ts_i2c_bi = &ts_i2c_board_info;
+ adapter = i2c_get_adapter(1);/*in bus 1*/
+
+ if (NULL == adapter) {
+ printk("can not get i2c adapter, client address error\n");
+ return -1;
+ }
+ l_client = i2c_new_device(adapter, ts_i2c_bi);
+ if (l_client == NULL) {
+ printk("allocate i2c client failed\n");
+ return -1;
+ }
+ i2c_put_adapter(adapter);
+ return 0;
+}
+
+static void ts_i2c_unregister_device(void)
+{
+ if (l_client != NULL)
+ {
+ i2c_unregister_device(l_client);
+ l_client = NULL;
+ }
+}
+
+struct i2c_client* ts_get_i2c_client(void)
+{
+ return l_client;
+}
+
+static int __init wmt_ts_init(void)
+{
+ int ret = 0;
+
+
+
+ if(wmt_check_touch_env())
+ return -ENODEV;
+
+ //ts_i2c_board_info.addr = l_tpinfor[l_tpindex].i2caddr;
+ if (ts_i2c_register_device()<0)
+ {
+ dbg("Error to run ts_i2c_register_device()!\n");
+ return -1;
+ }
+ mutex_init(&cal_mutex);
+
+ if (l_tsdev->init() < 0){
+ dbg("Errors to init %s ts IC!!!\n", l_tsdev->ts_id);
+ ret = -1;
+ goto err_init;
+ }
+ // Create device node
+ if (register_chrdev (TS_MAJOR, TS_NAME, &wmt_ts_fops)) {
+ printk (KERN_ERR "wmt touch: unable to get major %d\n", TS_MAJOR);
+ return -EIO;
+ }
+
+ l_dev_class = class_create(THIS_MODULE, TS_NAME);
+ if (IS_ERR(l_dev_class)){
+ ret = PTR_ERR(l_dev_class);
+ printk(KERN_ERR "Can't class_create touch device !!\n");
+ return ret;
+ }
+ l_clsdevice = device_create(l_dev_class, NULL, MKDEV(TS_MAJOR, 0), NULL, TS_NAME);
+ if (IS_ERR(l_clsdevice)){
+ ret = PTR_ERR(l_clsdevice);
+ printk(KERN_ERR "Failed to create device %s !!!",TS_NAME);
+ return ret;
+ }
+
+ // register device and driver of platform
+ ret = platform_device_register(&wmt_ts_plt_device);
+ if(ret){
+ errlog("wmt ts plat device register failed!\n");
+ return ret;
+ }
+ ret = platform_driver_register(&wmt_ts_plt_driver);
+ if(ret){
+ errlog("can not register platform_driver_register\n");
+ platform_device_unregister(&wmt_ts_plt_device);
+ return ret;
+ }
+
+ klog("%s driver init ok!\n",l_tsdev->ts_id);
+ return 0;
+err_init:
+ ts_i2c_unregister_device();
+ return ret;
+}
+
+static void __exit wmt_ts_exit(void)
+{
+ dbg("%s\n",__FUNCTION__);
+
+ l_tsdev->exit();
+ platform_driver_unregister(&wmt_ts_plt_driver);
+ platform_device_unregister(&wmt_ts_plt_device);
+ device_destroy(l_dev_class, MKDEV(TS_MAJOR, 0));
+ unregister_chrdev(TS_MAJOR, TS_NAME);
+ class_destroy(l_dev_class);
+ mutex_destroy(&cal_mutex);
+ ts_i2c_unregister_device();
+}
+
+
+module_init(wmt_ts_init);
+module_exit(wmt_ts_exit);
+
+MODULE_LICENSE("GPL");
+
diff --git a/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.h b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.h
new file mode 100755
index 00000000..11261348
--- /dev/null
+++ b/ANDROID_3.4.5/drivers/input/touchscreen/cyp140_ts/wmt_ts.h
@@ -0,0 +1,120 @@
+
+#ifndef WMT_TSH_201010191758
+#define WMT_TSH_201010191758
+
+#include <linux/platform_device.h>
+#include <linux/types.h>
+#include <linux/device.h>
+#include <linux/suspend.h>
+#include <linux/i2c.h>
+
+
+//#define DEBUG_WMT_TS
+#ifdef DEBUG_WMT_TS
+#undef dbg
+#define dbg(fmt, args...) printk(KERN_ALERT "[%s]: " fmt, __FUNCTION__ , ## args)
+
+//#define dbg(fmt, args...) if (kpadall_isrundbg()) printk(KERN_ALERT "[%s]: " fmt, __FUNCTION__, ## args)
+
+#else
+#define dbg(fmt, args...)
+#endif
+
+#undef errlog
+#undef klog
+#define errlog(fmt, args...) printk("[%s]: " fmt, __FUNCTION__, ## args)
+#define klog(fmt, args...) printk("[%s]: " fmt, __FUNCTION__, ## args)
+
+#define WMT_TS_I2C_NAME "cyp140-ts"
+#define WMT_TS_I2C_ADDR 0x24 //0x76
+
+
+
+
+
+//////////////////////////////data type///////////////////////////
+typedef struct {
+ short pressure;
+ short x;
+ short y;
+ //short millisecs;
+} TS_EVENT;
+
+struct wmtts_device
+{
+ //data
+ char* driver_name;
+ char* ts_id;
+ //function
+ int (*init)(void);
+ int (*probe)(struct platform_device *platdev);
+ int (*remove)(struct platform_device *pdev);
+ void (*exit)(void);
+ int (*suspend)(struct platform_device *pdev, pm_message_t state);
+ int (*resume)(struct platform_device *pdev);
+ int (*capacitance_calibrate)(void);
+ int (*wait_penup)(struct wmtts_device*tsdev); // waiting untill penup
+ int penup; // 0--pendown;1--penup
+
+};
+
+//////////////////////////function interface/////////////////////////
+extern int wmt_ts_get_irqgpnum(void);
+extern int wmt_ts_iscalibrating(void);
+extern int wmt_ts_get_resolvX(void);
+extern int wmt_ts_get_resolvY(void);
+extern int wmt_ts_set_rawcoord(unsigned short x, unsigned short y);
+extern int wmt_set_gpirq(int type);
+extern int wmt_get_tsirqnum(void);
+extern int wmt_disable_gpirq(void);
+extern int wmt_enable_gpirq(void);
+extern int wmt_is_tsirq_enable(void);
+extern int wmt_is_tsint(void);
+extern void wmt_clr_int(void);
+extern void wmt_tsreset_init(void);
+extern int wmt_ts_get_resetgpnum(void);
+extern int wmt_ts_get_lcdexchg(void);
+extern void wmt_disable_rst_pull(void);
+extern void wmt_set_rst_pull(int up);
+extern void wmt_rst_output(int high);
+extern void wmt_rst_input(void);
+extern void wmt_set_intasgp(void);
+extern void wmt_intgp_out(int val);
+extern void wmt_ts_set_irqinput(void);
+extern unsigned int wmt_ts_irqinval(void);
+extern void wmt_ts_set_penup(int up);
+extern int wmt_ts_wait_penup(void);
+extern void wmt_ts_wakeup_penup(void);
+extern struct i2c_client* ts_get_i2c_client(void);
+extern int wmt_ts_ispenup(void);
+extern void wmt_ts_get_firmwname(char* firmname);
+extern unsigned int wmt_ts_get_maxfingernum(void);
+extern unsigned int wmt_ts_get_ictype(void);
+extern unsigned int wmt_ts_get_xaxis(void);
+extern unsigned int wmt_ts_get_xdir(void);
+extern unsigned int wmt_ts_get_ydir(void);
+// short
+extern unsigned int wmt_ts_get_touchheight(void);
+// long
+extern unsigned int wmt_ts_get_touchwidth(void);
+extern int wmt_ts_if_updatefw(void);
+
+
+
+extern void TouchPanelCalibrateAPoint(
+ int UncalX, //@PARM The uncalibrated X coordinate
+ int UncalY, //@PARM The uncalibrated Y coordinate
+ int *pCalX, //@PARM The calibrated X coordinate
+ int *pCalY //@PARM The calibrated Y coordinate
+ );
+
+//filepath:the path of firmware file;
+//firmdata:store the data from firmware file;
+//maxlen: the max len of firmdata;
+//return:the length of firmware data,negative-parsing error.
+//extern int read_firmwarefile(char* filepath, unsigned char** firmdata);
+
+#endif
+
+
+