diff options
author | Srikant Patnaik | 2015-01-13 15:08:24 +0530 |
---|---|---|
committer | Srikant Patnaik | 2015-01-13 15:08:24 +0530 |
commit | 97327692361306d1e6259021bc425e32832fdb50 (patch) | |
tree | fe9088f3248ec61e24f404f21b9793cb644b7f01 /drivers/input/touchscreen/gsl1680_ts | |
parent | 2d05a8f663478a44e088d122e0d62109bbc801d0 (diff) | |
parent | a3a8b90b61e21be3dde9101c4e86c881e0f06210 (diff) | |
download | FOSSEE-netbook-kernel-source-97327692361306d1e6259021bc425e32832fdb50.tar.gz FOSSEE-netbook-kernel-source-97327692361306d1e6259021bc425e32832fdb50.tar.bz2 FOSSEE-netbook-kernel-source-97327692361306d1e6259021bc425e32832fdb50.zip |
dirty fix to merging
Diffstat (limited to 'drivers/input/touchscreen/gsl1680_ts')
-rwxr-xr-x | drivers/input/touchscreen/gsl1680_ts/Kconfig | 16 | ||||
-rwxr-xr-x | drivers/input/touchscreen/gsl1680_ts/Makefile | 33 | ||||
-rwxr-xr-x | drivers/input/touchscreen/gsl1680_ts/gslX680.c | 1416 | ||||
-rwxr-xr-x | drivers/input/touchscreen/gsl1680_ts/gslX680.h | 35 | ||||
-rwxr-xr-x | drivers/input/touchscreen/gsl1680_ts/gsl_point_id.b | bin | 0 -> 38321 bytes | |||
-rwxr-xr-x | drivers/input/touchscreen/gsl1680_ts/wmt_ts.c | 1102 | ||||
-rwxr-xr-x | drivers/input/touchscreen/gsl1680_ts/wmt_ts.h | 117 |
7 files changed, 2719 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/gsl1680_ts/Kconfig b/drivers/input/touchscreen/gsl1680_ts/Kconfig new file mode 100755 index 00000000..0f47c8bc --- /dev/null +++ b/drivers/input/touchscreen/gsl1680_ts/Kconfig @@ -0,0 +1,16 @@ +# +# GSL1680 capacity touch screen driver configuration +# +config TOUCHSCREEN_GSL1680 + tristate "ilead GSL1680 I2C Touchscreen Input Driver Support" + depends on ARCH_WMT + default y + 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_gsl1680. + diff --git a/drivers/input/touchscreen/gsl1680_ts/Makefile b/drivers/input/touchscreen/gsl1680_ts/Makefile new file mode 100755 index 00000000..372a0fce --- /dev/null +++ b/drivers/input/touchscreen/gsl1680_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_gsl1680
+
+obj-m := $(MY_MODULE_NAME).o
+$(MY_MODULE_NAME)-objs := gslX680.o wmt_ts.o gsl_point_id.b
+
+default:
+ $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
+ $(STRIP) --strip-debug $(MY_MODULE_NAME).ko
+ 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/drivers/input/touchscreen/gsl1680_ts/gslX680.c b/drivers/input/touchscreen/gsl1680_ts/gslX680.c new file mode 100755 index 00000000..bcb252a5 --- /dev/null +++ b/drivers/input/touchscreen/gsl1680_ts/gslX680.c @@ -0,0 +1,1416 @@ +/* + * drivers/input/touchscreen/gslX680.c + * + * Copyright (c) 2012 Shanghai Basewin + * Guan Yuwei<guanyuwei@basewin.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + + + +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/i2c.h> +#include <linux/delay.h> +//#include <mach/gpio.h> +//#include <mach/gpio_data.h> +#include <linux/jiffies.h> +#include <linux/cdev.h> +#include <asm/uaccess.h> +#include <linux/pm_runtime.h> + +#if defined(CONFIG_HAS_EARLYSUSPEND) +#include <linux/earlysuspend.h> +#endif +#include <linux/input/mt.h> + +#include <linux/i2c.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/errno.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/platform_device.h> +#include <linux/async.h> +#include <linux/hrtimer.h> +#include <linux/init.h> +#include <linux/ioport.h> +#include <linux/irq.h> +#include <linux/kthread.h> +#include <linux/wakelock.h> + + +#include <linux/gpio.h> +#include <mach/wmt_iomux.h> + + +//#include <asm/irq.h> +//#include <asm/io.h> + +//#include <mach/irqs.h> +//#include <mach/system.h> +//#include <mach/hardware.h> +#include "gslX680.h" +#include "wmt_ts.h" +#include "../../../video/backlight/wmt_bl.h" + +//#define GSL_DEBUG +//#define GSL_TIMER +//#define REPORT_DATA_ANDROID_4_0 + +#define HAVE_TOUCH_KEY + +#define SCREEN_MAX_X 480 +#define SCREEN_MAX_Y 800 + + +#define GSLX680_I2C_NAME "touch_gslX680" +#define GSLX680_I2C_ADDR 0x40 +#define IRQ_PORT INT_GPIO_0 + +#define GSL_DATA_REG 0x80 +#define GSL_STATUS_REG 0xe0 +#define GSL_PAGE_REG 0xf0 + +#define PRESS_MAX 255 +#define MAX_FINGERS 5 +#define MAX_CONTACTS 10 +#define DMA_TRANS_LEN 0x20 + +#ifdef GSL_NOID_VERSION +int gsl_noid_ver = 0; +unsigned int gsl_config_data_id[512] = {0}; +#endif + +#ifdef HAVE_TOUCH_KEY +static u16 key = 0; +static int key_state_flag = 0; +struct key_data { + u16 key; + u16 x_min; + u16 x_max; + u16 y_min; + u16 y_max; +}; + +const u16 key_array[]={ + KEY_BACK, + KEY_HOME, + KEY_MENU, + KEY_SEARCH, + }; +#define MAX_KEY_NUM (sizeof(key_array)/sizeof(key_array[0])) + +struct key_data gsl_key_data[MAX_KEY_NUM] = { + {KEY_BACK, 2048, 2048, 2048, 2048}, + {KEY_HOME, 2048, 2048, 2048, 2048}, + {KEY_MENU, 2048, 2048, 2048, 2048}, + {KEY_SEARCH, 2048, 2048, 2048, 2048}, +}; +#endif + +struct gsl_ts_data { + u8 x_index; + u8 y_index; + u8 z_index; + u8 id_index; + u8 touch_index; + u8 data_reg; + u8 status_reg; + u8 data_size; + u8 touch_bytes; + u8 update_data; + u8 touch_meta_data; + u8 finger_size; +}; + +static struct gsl_ts_data devices[] = { + { + .x_index = 6, + .y_index = 4, + .z_index = 5, + .id_index = 7, + .data_reg = GSL_DATA_REG, + .status_reg = GSL_STATUS_REG, + .update_data = 0x4, + .touch_bytes = 4, + .touch_meta_data = 4, + .finger_size = 70, + }, +}; + +struct gsl_ts { + struct i2c_client *client; + struct input_dev *input; + struct work_struct work; + struct workqueue_struct *wq; + struct gsl_ts_data *dd; + u8 *touch_data; + u8 device_id; + u8 prev_touches; + bool is_suspended; + bool int_pending; + struct mutex sus_lock; +// uint32_t gpio_irq; + int irq; +#if defined(CONFIG_HAS_EARLYSUSPEND) + struct early_suspend early_suspend; +#endif +#ifdef GSL_TIMER + struct timer_list gsl_timer; +#endif + + struct workqueue_struct *timeout_queue; + struct delayed_work timeout_work; + struct mutex timeout_mutex; + int timeout_count; +}; + +#define DELAY_TIMEOUT 1000 +#define DELAY_TIMEOUT_MAX 3 + + + +struct gsl_ts *l_ts=NULL; + +static u32 id_sign[MAX_CONTACTS+1] = {0}; +static u8 id_state_flag[MAX_CONTACTS+1] = {0}; +static u8 id_state_old_flag[MAX_CONTACTS+1] = {0}; +static u16 x_old[MAX_CONTACTS+1] = {0}; +static u16 y_old[MAX_CONTACTS+1] = {0}; +static u16 x_new = 0; +static u16 y_new = 0; + +static struct fw_data* GSLX680_FW = NULL; +static int l_fwlen = 0; +static struct task_struct *resume_download_task; +static struct wake_lock downloadWakeLock; +static int is_delay = 0; + +extern int tp_led_gpio; +extern int tp_led_gpio_active; + +extern int sel_reg_bit; +extern int sel_reg_active; + + +extern int register_bl_notifier(struct notifier_block *nb); + +extern int unregister_bl_notifier(struct notifier_block *nb); + +extern int wmt_getsyspara(char *varname, unsigned char *varval, int *varlen); + +//////////////////////////////////////////////////////////////////// +static int wmt_get_fwdata(void); + +//////////////////////////////////////////////////////////////////// +static int gslX680_chip_init(void) +{ + //gpio_set_status(PAD_GPIOA_6, gpio_status_out); + //gpio_out(PAD_GPIOA_6, 1); + // shutdown pin + wmt_rst_output(1); + // irq pin + //gpio_set_status(PAD_GPIOA_16, gpio_status_in); + //gpio_irq_set(PAD_GPIOA_16, GPIO_IRQ(INT_GPIO_0-INT_GPIO_0, GPIO_IRQ_RISING)); + wmt_set_gpirq(IRQ_TYPE_EDGE_RISING);//GIRQ_FALLING); + wmt_disable_gpirq(); + msleep(20); + return 0; +} + +static int gslX680_shutdown_low(void) +{ + //gpio_set_status(PAD_GPIOA_6, gpio_status_out); + //gpio_out(PAD_GPIOA_6, 0); + wmt_rst_output(0); + return 0; +} + +static int gslX680_shutdown_high(void) +{ + //gpio_set_status(PAD_GPIOA_6, gpio_status_out); + //gpio_out(PAD_GPIOA_6, 1); + wmt_rst_output(1); + return 0; +} + +static inline u16 join_bytes(u8 a, u8 b) +{ + u16 ab = 0; + ab = ab | a; + ab = ab << 8 | b; + return ab; +} + +#if 0 +static u32 gsl_read_interface(struct i2c_client *client, u8 reg, u8 *buf, u32 num) +{ + struct i2c_msg xfer_msg[2]; + + xfer_msg[0].addr = client->addr; + xfer_msg[0].len = 1; + xfer_msg[0].flags = client->flags & I2C_M_TEN; + xfer_msg[0].buf = ® + + xfer_msg[1].addr = client->addr; + xfer_msg[1].len = num; + xfer_msg[1].flags |= I2C_M_RD; + xfer_msg[1].buf = buf; + + if (reg < 0x80) { + i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)); + msleep(5); + } + + return i2c_transfer(client->adapter, xfer_msg, ARRAY_SIZE(xfer_msg)) == ARRAY_SIZE(xfer_msg) ? 0 : -EFAULT; +} +#endif + +static u32 gsl_write_interface(struct i2c_client *client, const u8 reg, u8 *buf, u32 num) +{ + struct i2c_msg xfer_msg[1]; + + buf[0] = reg; + + xfer_msg[0].addr = client->addr; + xfer_msg[0].len = num + 1; + xfer_msg[0].flags = client->flags & I2C_M_TEN; + xfer_msg[0].buf = buf; + + return i2c_transfer(client->adapter, xfer_msg, 1) == 1 ? 0 : -EFAULT; +} + +static __inline__ void fw2buf(u8 *buf, const u32 *fw) +{ + u32 *u32_buf = (int *)buf; + *u32_buf = *fw; +} + +static int wmt_get_fwdata(void) +{ + char fwname[128]; + + // get the firmware file name + memset(fwname,0,sizeof(fwname)); + wmt_ts_get_firmwfilename(fwname); + // load the data into GSLX680_FW + l_fwlen = read_firmwfile(fwname, &GSLX680_FW, gsl_config_data_id); + return ((l_fwlen>0)?0:-1); +} + +static void gsl_load_fw(struct i2c_client *client) +{ + u8 buf[DMA_TRANS_LEN*4 + 1] = {0}; + u8 send_flag = 1; + u8 *cur = buf + 1; + u32 source_line = 0; + u32 source_len = l_fwlen;//ARRAY_SIZE(GSLX680_FW); + + printk("=============gsl_load_fw start==============\n"); + + for (source_line = 0; source_line < source_len; source_line++) + { + /* init page trans, set the page val */ + if (GSL_PAGE_REG == GSLX680_FW[source_line].offset) + { + fw2buf(cur, &GSLX680_FW[source_line].val); + gsl_write_interface(client, GSL_PAGE_REG, buf, 4); + send_flag = 1; + } + else + { + if (1 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20)) + buf[0] = (u8)GSLX680_FW[source_line].offset; + + fw2buf(cur, &GSLX680_FW[source_line].val); + cur += 4; + + if (0 == send_flag % (DMA_TRANS_LEN < 0x20 ? DMA_TRANS_LEN : 0x20)) + { + gsl_write_interface(client, buf[0], buf, cur - buf - 1); + cur = buf + 1; + } + + send_flag++; + } + } + + printk("=============gsl_load_fw end==============\n"); + +} + + +static int gsl_ts_write(struct i2c_client *client, u8 addr, u8 *pdata, int datalen) +{ + int ret = 0; + u8 tmp_buf[128]; + unsigned int bytelen = 0; + if (datalen > 125) + { + dbg("%s too big datalen = %d!\n", __func__, datalen); + return -1; + } + + tmp_buf[0] = addr; + bytelen++; + + if (datalen != 0 && pdata != NULL) + { + memcpy(&tmp_buf[bytelen], pdata, datalen); + bytelen += datalen; + } + + ret = i2c_master_send(client, tmp_buf, bytelen); + return ret; +} + +static int gsl_ts_read(struct i2c_client *client, u8 addr, u8 *pdata, unsigned int datalen) +{ + int ret = 0; + + if (datalen > 126) + { + dbg("%s too big datalen = %d!\n", __func__, datalen); + return -1; + } + + ret = gsl_ts_write(client, addr, NULL, 0); + if (ret < 0) + { + dbg("%s set data address fail!\n", __func__); + return ret; + } + + return i2c_master_recv(client, pdata, datalen); +} + +#if 0 +static void test_i2c(struct i2c_client *client) +{ + u8 read_buf = 0; + u8 write_buf = 0x12; + int ret; + ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) ); + if (ret < 0) + { + pr_info("I2C transfer error!\n"); + } + else + { + pr_info("I read reg 0xf0 is %x\n", read_buf); + } + msleep(10); + + ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf)); + if (ret < 0) + { + pr_info("I2C transfer error!\n"); + } + else + { + pr_info("I write reg 0xf0 0x12\n"); + } + msleep(10); + + ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) ); + if (ret < 0 ) + { + pr_info("I2C transfer error!\n"); + } + else + { + pr_info("I read reg 0xf0 is 0x%x\n", read_buf); + } + msleep(10); + +} +#endif + +static int test_i2c(struct i2c_client *client) +{ + u8 read_buf = 0; + u8 write_buf = 0x12; + int ret, rc = 1; + + ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) ); + if (ret < 0) + rc --; + else + dbg("I read reg 0xf0 is %x\n", read_buf); + + msleep(2); + ret = gsl_ts_write(client, 0xf0, &write_buf, sizeof(write_buf)); + if(ret >= 0 ) + dbg("I write reg 0xf0 0x12\n"); + + msleep(2); + ret = gsl_ts_read( client, 0xf0, &read_buf, sizeof(read_buf) ); + if(ret < 0 ) + rc --; + else + dbg("I read reg 0xf0 is 0x%x\n", read_buf); + + return rc; +} + +static void startup_chip(struct i2c_client *client) +{ + u8 tmp = 0x00; +#ifdef GSL_NOID_VERSION + if (gsl_noid_ver) + gsl_DataInit(gsl_config_data_id); +#endif + gsl_ts_write(client, 0xe0, &tmp, 1); + msleep(10); +} + +static void reset_chip(struct i2c_client *client) +{ + u8 buf[4] = {0x00}; + u8 tmp = 0x88; + gsl_ts_write(client, 0xe0, &tmp, sizeof(tmp)); + msleep(10); + + tmp = 0x04; + gsl_ts_write(client, 0xe4, &tmp, sizeof(tmp)); + msleep(10); + + gsl_ts_write(client, 0xbc, buf, sizeof(buf)); + msleep(10); +} + +static void clr_reg(struct i2c_client *client) +{ + u8 write_buf[4] = {0}; + + write_buf[0] = 0x88; + gsl_ts_write(client, 0xe0, &write_buf[0], 1); + msleep(20); + write_buf[0] = 0x03; + gsl_ts_write(client, 0x80, &write_buf[0], 1); + msleep(5); + write_buf[0] = 0x04; + gsl_ts_write(client, 0xe4, &write_buf[0], 1); + msleep(5); + write_buf[0] = 0x00; + gsl_ts_write(client, 0xe0, &write_buf[0], 1); + msleep(20); +} + +static void init_chip(struct i2c_client *client) +{ + int rc; + + gslX680_shutdown_low(); + msleep(20); + gslX680_shutdown_high(); + msleep(20); + rc = test_i2c(client); + if(rc < 0) + { + printk("------gslX680 test_i2c error------\n"); + return; + } + clr_reg(client); + reset_chip(client); + gsl_load_fw(client); + startup_chip(client); + reset_chip(client); + startup_chip(client); +} + +static void check_mem_data(struct i2c_client *client) +{ + /*char write_buf; + char read_buf[4] = {0}; + + msleep(30); + write_buf = 0x00; + gsl_ts_write(client,0xf0, &write_buf, sizeof(write_buf)); + gsl_ts_read(client,0x00, read_buf, sizeof(read_buf)); + gsl_ts_read(client,0x00, read_buf, sizeof(read_buf)); + if (read_buf[3] != 0x1 || read_buf[2] != 0 || read_buf[1] != 0 || read_buf[0] != 0) + { + dbg("!!!!!!!!!!!page: %x offset: %x val: %x %x %x %x\n",0x0, 0x0, read_buf[3], read_buf[2], read_buf[1], read_buf[0]); + init_chip(client); + }*/ + + u8 read_buf[4] = {0}; + + msleep(30); + gsl_ts_read(client,0xb0, read_buf, sizeof(read_buf)); + + if (read_buf[3] != 0x5a || read_buf[2] != 0x5a || read_buf[1] != 0x5a || read_buf[0] != 0x5a) + { + printk("#########check mem read 0xb0 = %x %x %x %x #########\n", read_buf[3], read_buf[2], read_buf[1], read_buf[0]); + init_chip(client); + } + +} + +static void record_point(u16 x, u16 y , u8 id) +{ + u16 x_err =0; + u16 y_err =0; + + id_sign[id]=id_sign[id]+1; + + if(id_sign[id]==1){ + x_old[id]=x; + y_old[id]=y; + } + + x = (x_old[id] + x)/2; + y = (y_old[id] + y)/2; + + if(x>x_old[id]){ + x_err=x -x_old[id]; + } + else{ + x_err=x_old[id]-x; + } + + if(y>y_old[id]){ + y_err=y -y_old[id]; + } + else{ + y_err=y_old[id]-y; + } + + if( (x_err > 3 && y_err > 1) || (x_err > 1 && y_err > 3) ){ + x_new = x; x_old[id] = x; + y_new = y; y_old[id] = y; + } + else{ + if(x_err > 3){ + x_new = x; x_old[id] = x; + } + else + x_new = x_old[id]; + if(y_err> 3){ + y_new = y; y_old[id] = y; + } + else + y_new = y_old[id]; + } + + if(id_sign[id]==1){ + x_new= x_old[id]; + y_new= y_old[id]; + } + +} + +void wmt_set_keypos(int index,int xmin,int xmax,int ymin,int ymax) +{ + gsl_key_data[index].x_min = xmin; + gsl_key_data[index].x_max = xmax; + gsl_key_data[index].y_min = ymin; + gsl_key_data[index].y_max = ymax; +} + +#ifdef HAVE_TOUCH_KEY +static void report_key(struct gsl_ts *ts, u16 x, u16 y) +{ + u16 i = 0; + + for(i = 0; i < MAX_KEY_NUM; i++) + { + if((gsl_key_data[i].x_min <= x) && (x <= gsl_key_data[i].x_max)&&(gsl_key_data[i].y_min <= y) && (y <= gsl_key_data[i].y_max)) + { + key = gsl_key_data[i].key; + input_report_key(ts->input, key, 1); + input_sync(ts->input); + key_state_flag = 1; + dbg("rport key:%d\n",key); + + if( tp_led_gpio >= 0 ){ + gpio_set_value(tp_led_gpio,tp_led_gpio_active); + + mutex_lock(&ts->timeout_mutex); + if( ts->timeout_count < 0 ){ + queue_delayed_work(ts->timeout_queue, &ts->timeout_work, msecs_to_jiffies(DELAY_TIMEOUT)); + } + ts->timeout_count = DELAY_TIMEOUT_MAX; + mutex_unlock(&ts->timeout_mutex); + } + break; + } + } +} +#endif + +static void report_data(struct gsl_ts *ts, u16 x, u16 y, u8 pressure, u8 id) +{ + //swap(x, y); + int tx,ty; + int keyx,keyy; + + dbg("#####id=%d,x=%d,y=%d######\n",id,x,y); + + + tx = x; + ty = y; + keyx = x; + keyy = y; + + if( (x>=wmt_ts_get_resolvX()&&x>=wmt_ts_get_resolvY()) + || (y>= wmt_ts_get_resolvX()&&y>= wmt_ts_get_resolvY())) + { + #ifdef HAVE_TOUCH_KEY + if (wmt_ts_if_tskey()) + { + report_key(ts,keyx,keyy); + } + #endif + return; + } + + + if (wmt_ts_get_xaxis()==1) + { + tx = y; + ty = x; + } + if (wmt_ts_get_xdir()==-1) + { + tx = wmt_ts_get_resolvX() - tx - 1; + } + if (wmt_ts_get_ydir()==-1) + { + ty = wmt_ts_get_resolvY() - ty - 1; + } + /*if ((tx < 0) || (tx >= wmt_ts_get_resolvX()) || + (ty < 0) || (ty >= wmt_ts_get_resolvY())) + { + dbg("Invalid point(%d,%d)\n"); + return; + }*/ + x = tx; + y = ty; + + + if (wmt_ts_get_lcdexchg()) { + int tmp; + tmp = x; + x = y; + y = wmt_ts_get_resolvX() - tmp; + } + + dbg("rpt%d(%d,%d)\n",id,x,y); +#ifdef REPORT_DATA_ANDROID_4_0 + input_mt_slot(ts->input, id); + input_report_abs(ts->input, ABS_MT_TRACKING_ID, id); + //input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure); + input_report_abs(ts->input, ABS_MT_POSITION_X, x); + input_report_abs(ts->input, ABS_MT_POSITION_Y, y); + //input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1); +#else + //add for cross finger 2013-1-10 + input_report_key(ts->input, BTN_TOUCH, 1); + input_report_abs(ts->input, ABS_MT_TRACKING_ID, id); + //input_report_abs(ts->input, ABS_MT_TOUCH_MAJOR, pressure); + input_report_abs(ts->input, ABS_MT_POSITION_X,x); + input_report_abs(ts->input, ABS_MT_POSITION_Y, y); + //input_report_abs(ts->input, ABS_MT_WIDTH_MAJOR, 1); + input_mt_sync(ts->input); +#endif +} + +static void process_gslX680_data(struct gsl_ts *ts) +{ + u8 id, touches; + u16 x, y; + int i = 0; +#ifdef GSL_NOID_VERSION + u32 tmp1; + u8 buf[4] = {0}; + struct gsl_touch_info cinfo; +#endif + touches = ts->touch_data[ts->dd->touch_index]; + +#ifdef GSL_NOID_VERSION + if (gsl_noid_ver) { + cinfo.finger_num = touches; + dbg("tp-gsl finger_num = %d\n",cinfo.finger_num); + for(i = 0; i < (touches < MAX_CONTACTS ? touches : MAX_CONTACTS); i ++) { + cinfo.x[i] = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf), + ts->touch_data[ts->dd->x_index + 4 * i]); + cinfo.y[i] = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1], + ts->touch_data[ts->dd->y_index + 4 * i ]); + cinfo.id[i] = ((ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf0)>>4); + dbg("tp-gsl x = %d y = %d \n",cinfo.x[i],cinfo.y[i]); + } + cinfo.finger_num=(ts->touch_data[3]<<24)|(ts->touch_data[2]<<16) + |(ts->touch_data[1]<<8)|(ts->touch_data[0]); + gsl_alg_id_main(&cinfo); + tmp1=gsl_mask_tiaoping(); + dbg("[tp-gsl] tmp1=%x\n",tmp1); + if(tmp1>0&&tmp1<0xffffffff) { + buf[0]=0xa;buf[1]=0;buf[2]=0;buf[3]=0; + gsl_ts_write(ts->client,0xf0,buf,4); + buf[0]=(u8)(tmp1 & 0xff); + buf[1]=(u8)((tmp1>>8) & 0xff); + buf[2]=(u8)((tmp1>>16) & 0xff); + buf[3]=(u8)((tmp1>>24) & 0xff); + dbg("tmp1=%08x,buf[0]=%02x,buf[1]=%02x,buf[2]=%02x,buf[3]=%02x\n", + tmp1,buf[0],buf[1],buf[2],buf[3]); + gsl_ts_write(ts->client,0x8,buf,4); + } + touches = cinfo.finger_num; + } +#endif + + for(i=1;i<=MAX_CONTACTS;i++) + { + if(touches == 0) + id_sign[i] = 0; + id_state_flag[i] = 0; + } + for(i= 0;i < (touches > MAX_FINGERS ? MAX_FINGERS : touches);i ++) + { + #ifdef GSL_NOID_VERSION + if (gsl_noid_ver) { + id = cinfo.id[i]; + x = cinfo.x[i]; + y = cinfo.y[i]; + } + else { + x = join_bytes( ( ts->touch_data[ts->dd->x_index + 4 * i + 1] & 0xf), + ts->touch_data[ts->dd->x_index + 4 * i]); + y = join_bytes(ts->touch_data[ts->dd->y_index + 4 * i + 1], + ts->touch_data[ts->dd->y_index + 4 * i ]); + id = ts->touch_data[ts->dd->id_index + 4 * i] >> 4; + } + #endif + + if(1 <=id && id <= MAX_CONTACTS) + { + dbg("raw%d(%d,%d)\n", id, x, y); + record_point(x, y , id); + dbg("new%d(%d,%d)\n", id, x_new, y_new); + report_data(ts, x_new, y_new, 10, id); + id_state_flag[id] = 1; + } + } + for(i=1;i<=MAX_CONTACTS;i++) + { + if( (0 == touches) || ((0 != id_state_old_flag[i]) && (0 == id_state_flag[i])) ) + { + #ifdef REPORT_DATA_ANDROID_4_0 + input_mt_slot(ts->input, i); + input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1); + input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false); + #endif + id_sign[i]=0; + } + id_state_old_flag[i] = id_state_flag[i]; + } +#ifndef REPORT_DATA_ANDROID_4_0 + if(0 == touches) + { + //add 2013-1-10 cross fingers + //input_report_abs(ts->input, ABS_MT_TRACKING_ID, -1); + input_report_key(ts->input, BTN_TOUCH, 0); + //********************** + input_mt_sync(ts->input); + #ifdef HAVE_TOUCH_KEY + if (wmt_ts_if_tskey()) + { + if(key_state_flag) + { + input_report_key(ts->input, key, 0); + input_sync(ts->input); + key_state_flag = 0; + } + } + #endif + } +#endif + input_sync(ts->input); + ts->prev_touches = touches; +} + + +static void gsl_ts_xy_worker(struct work_struct *work) +{ + int rc; + u8 read_buf[4] = {0}; + + struct gsl_ts *ts = container_of(work, struct gsl_ts,work); + + dbg("---gsl_ts_xy_worker---\n"); + + if (ts->is_suspended == true) { + dev_dbg(&ts->client->dev, "TS is supended\n"); + ts->int_pending = true; + goto schedule; + } + + /* read data from DATA_REG */ + rc = gsl_ts_read(ts->client, 0x80, ts->touch_data, ts->dd->data_size); + dbg("---touches: %d ---\n",ts->touch_data[0]); + + if (rc < 0) + { + dev_err(&ts->client->dev, "read failed\n"); + goto schedule; + } + + if (ts->touch_data[ts->dd->touch_index] == 0xff) { + goto schedule; + } + + rc = gsl_ts_read( ts->client, 0xbc, read_buf, sizeof(read_buf)); + if (rc < 0) + { + dev_err(&ts->client->dev, "read 0xbc failed\n"); + goto schedule; + } + dbg("//////// reg %x : %x %x %x %x\n",0xbc, read_buf[3], read_buf[2], read_buf[1], read_buf[0]); + + if (read_buf[3] == 0 && read_buf[2] == 0 && read_buf[1] == 0 && read_buf[0] == 0) + { + process_gslX680_data(ts); + } + else + { + reset_chip(ts->client); + startup_chip(ts->client); + } + +schedule: + //enable_irq(ts->irq); + wmt_enable_gpirq(); + +} + +static irqreturn_t gsl_ts_irq(int irq, void *dev_id) +{ + struct gsl_ts *ts = dev_id; + + if (wmt_is_tsint()) + { + wmt_clr_int(); + if (wmt_is_tsirq_enable() && ts->is_suspended == false) + { + wmt_disable_gpirq(); + dbg("begin..\n"); + //if (!work_pending(&l_tsdata.pen_event_work)) + { + queue_work(ts->wq, &ts->work); + } + } + return IRQ_HANDLED; + } + return IRQ_NONE; + + + /*disable_irq_nosync(ts->irq); + + if (!work_pending(&ts->work)) + { + queue_work(ts->wq, &ts->work); + } + + return IRQ_HANDLED;*/ + +} + +#ifdef GSL_TIMER +static void gsl_timer_handle(unsigned long data) +{ + struct gsl_ts *ts = (struct gsl_ts *)data; + +#ifdef GSL_DEBUG + dbg("----------------gsl_timer_handle-----------------\n"); +#endif + + disable_irq_nosync(ts->irq); + check_mem_data(ts->client); + ts->gsl_timer.expires = jiffies + 3 * HZ; + add_timer(&ts->gsl_timer); + enable_irq(ts->irq); + +} +#endif + +static int gsl_ts_init_ts(struct i2c_client *client, struct gsl_ts *ts) +{ + struct input_dev *input_device; + int i; + int rc = 0; + + dbg("[GSLX680] Enter %s\n", __func__); + + + ts->dd = &devices[ts->device_id]; + + if (ts->device_id == 0) { + ts->dd->data_size = MAX_FINGERS * ts->dd->touch_bytes + ts->dd->touch_meta_data; + ts->dd->touch_index = 0; + } + + ts->touch_data = kzalloc(ts->dd->data_size, GFP_KERNEL); + if (!ts->touch_data) { + pr_err("%s: Unable to allocate memory\n", __func__); + return -ENOMEM; + } + + ts->prev_touches = 0; + + input_device = input_allocate_device(); + if (!input_device) { + rc = -ENOMEM; + goto error_alloc_dev; + } + + ts->input = input_device; + input_device->name = GSLX680_I2C_NAME; + input_device->id.bustype = BUS_I2C; + input_device->dev.parent = &client->dev; + input_set_drvdata(input_device, ts); + +#ifdef REPORT_DATA_ANDROID_4_0 + __set_bit(EV_ABS, input_device->evbit); + __set_bit(EV_KEY, input_device->evbit); + __set_bit(EV_REP, input_device->evbit); + __set_bit(INPUT_PROP_DIRECT, input_device->propbit); + input_mt_init_slots(input_device, (MAX_CONTACTS+1)); +#else + //input_set_abs_params(input_device,ABS_MT_TRACKING_ID, 0, (MAX_CONTACTS+1), 0, 0); + set_bit(EV_ABS, input_device->evbit); + set_bit(EV_KEY, input_device->evbit); + __set_bit(INPUT_PROP_DIRECT, input_device->propbit); +#endif + + input_device->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); +#ifdef HAVE_TOUCH_KEY + //input_device->evbit[0] = BIT_MASK(EV_KEY); + if (wmt_ts_if_tskey()) + { + for (i = 0; i < MAX_KEY_NUM; i++) + set_bit(key_array[i], input_device->keybit); + } +#endif + + set_bit(ABS_MT_POSITION_X, input_device->absbit); + set_bit(ABS_MT_POSITION_Y, input_device->absbit); + //set_bit(ABS_MT_TOUCH_MAJOR, input_device->absbit); + //set_bit(ABS_MT_WIDTH_MAJOR, input_device->absbit); + //****************add 2013-1-10 + set_bit(BTN_TOUCH, input_device->keybit); + set_bit(ABS_MT_TRACKING_ID, input_device->absbit); + + dbg("regsister:x=%d,y=%d\n",wmt_ts_get_resolvX(),wmt_ts_get_resolvY()); + if (wmt_ts_get_lcdexchg()) { + input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, wmt_ts_get_resolvY(), 0, 0); + input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, wmt_ts_get_resolvX(), 0, 0); + } else { + input_set_abs_params(input_device,ABS_MT_POSITION_X, 0, wmt_ts_get_resolvX(), 0, 0); + input_set_abs_params(input_device,ABS_MT_POSITION_Y, 0, wmt_ts_get_resolvY(), 0, 0); + } + //input_set_abs_params(input_device,ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0); + //input_set_abs_params(input_device,ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0); + + //client->irq = IRQ_PORT, + //ts->irq = client->irq; + + ts->wq = create_singlethread_workqueue("kworkqueue_ts"); + if (!ts->wq) { + dev_err(&client->dev, "Could not create workqueue\n"); + goto error_wq_create; + } + flush_workqueue(ts->wq); + + INIT_WORK(&ts->work, gsl_ts_xy_worker); + + rc = input_register_device(input_device); + if (rc) + goto error_unreg_device; + + + + return 0; + +error_unreg_device: + destroy_workqueue(ts->wq); +error_wq_create: + input_free_device(input_device); +error_alloc_dev: + kfree(ts->touch_data); + return rc; +} + +static int gsl_ts_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct gsl_ts *ts = l_ts; //dev_get_drvdata(dev); + //int rc = 0; + + printk("I'am in gsl_ts_suspend() start\n"); + ts->is_suspended = true; + +#ifdef GSL_TIMER + printk( "gsl_ts_suspend () : delete gsl_timer\n"); + + del_timer(&ts->gsl_timer); +#endif + //disable_irq_nosync(ts->irq); + wmt_disable_gpirq(); + + reset_chip(ts->client); + gslX680_shutdown_low(); + msleep(10); + + return 0; +} + +int resume_download_thread(void *arg) +{ + wake_lock(&downloadWakeLock); + gslX680_chip_init(); + gslX680_shutdown_high(); + msleep(20); + reset_chip(l_ts->client); + startup_chip(l_ts->client); + //check_mem_data(l_ts->client); + init_chip(l_ts->client); + + l_ts->is_suspended = false; + if (!earlysus_en) + wmt_enable_gpirq(); + wake_unlock(&downloadWakeLock); + return 0; +} + +static int gsl_ts_resume(struct platform_device *pdev) +{ + + gpio_direction_output(tp_led_gpio, !tp_led_gpio_active); +#ifdef GSL_TIMER + dbg( "gsl_ts_resume () : add gsl_timer\n"); + + init_timer(&ts->gsl_timer); + ts->gsl_timer.expires = jiffies + 3 * HZ; + ts->gsl_timer.function = &gsl_timer_handle; + ts->gsl_timer.data = (unsigned long)ts; + add_timer(&ts->gsl_timer); +#endif + if (is_delay) { + resume_download_task = kthread_create(resume_download_thread, NULL , "resume_download"); + if(IS_ERR(resume_download_task)) { + errlog("cread thread failed\n"); + } + wake_up_process(resume_download_task); + } else + resume_download_thread(NULL); + + return 0; +} + +#ifdef CONFIG_HAS_EARLYSUSPEND +static void gsl_ts_early_suspend(struct early_suspend *h) +{ + //struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend); + dbg("[GSL1680] Enter %s\n", __func__); + //gsl_ts_suspend(&ts->client->dev); + wmt_disable_gpirq(); +} + +static void gsl_ts_late_resume(struct early_suspend *h) +{ + //struct gsl_ts *ts = container_of(h, struct gsl_ts, early_suspend); + dbg("[GSL1680] Enter %s\n", __func__); + //gsl_ts_resume(&ts->client->dev); + wmt_enable_gpirq(); +} +#endif + +static void check_Backlight_delay(void) +{ + int ret; + int len = 7; + char retval[8]; + + ret = wmt_getsyspara("wmt.backlight.delay", retval, &len); + if(ret) { + dbg("Read wmt.backlight.delay Failed.\n"); + is_delay = 0; + } else + is_delay = 1; +} + +static void timeout_func(struct work_struct *work){ + struct gsl_ts *ts = + container_of(work, struct gsl_ts, timeout_work.work); + int button_up = -1; + + mutex_lock(&ts->timeout_mutex); + button_up = --ts->timeout_count; + mutex_unlock(&ts->timeout_mutex); + + if( button_up < 0){ + gpio_set_value(tp_led_gpio,!tp_led_gpio_active); + }else{ + queue_delayed_work(ts->timeout_queue, &ts->timeout_work, msecs_to_jiffies(DELAY_TIMEOUT)); + } + +} + + +static int gsl_ts_probe(struct i2c_client *client) +{ + struct gsl_ts *ts; + int rc; + + dbg("GSLX680 Enter %s\n", __func__); + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + dev_err(&client->dev, "I2C functionality not supported\n"); + return -ENODEV; + } + if (wmt_get_fwdata()) + { + errlog("Failed to load the firmware data!\n"); + return -1; + } + ts = kzalloc(sizeof(*ts), GFP_KERNEL); + if (!ts) { + rc = -ENOMEM; + goto error_kfree_fw; + } + dbg("==kzalloc success=\n"); + l_ts = ts; + + ts->client = client; + i2c_set_clientdata(client, ts); + ts->device_id = 0;//id->driver_data; + + ts->is_suspended = false; + ts->int_pending = false; + wake_lock_init(&downloadWakeLock, WAKE_LOCK_SUSPEND, "resume_download"); + mutex_init(&ts->sus_lock); + + rc = gsl_ts_init_ts(client, ts); + if (rc < 0) { + dev_err(&client->dev, "GSLX680 init failed\n"); + goto error_mutex_destroy; + } + + gslX680_chip_init(); + init_chip(ts->client); + check_mem_data(ts->client); + + ts->irq = wmt_get_tsirqnum(); + rc= request_irq(wmt_get_tsirqnum(), gsl_ts_irq, IRQF_SHARED, client->name, ts); + if (rc < 0) { + dbg( "gsl_probe: request irq failed\n"); + goto error_req_irq_fail; + } + + if( tp_led_gpio >= 0 ){ + if(gpio_request(tp_led_gpio, "tp_led_gpio") >= 0){ + wmt_gpio_setpull(tp_led_gpio, tp_led_gpio_active ? WMT_GPIO_PULL_UP : WMT_GPIO_PULL_DOWN); + gpio_direction_output(tp_led_gpio, !tp_led_gpio_active); + #if 0 + errlog("sel_reg_bit:%d sel_reg_active:%d\n",sel_reg_bit,sel_reg_active); + if(sel_reg_bit >= 0 && sel_reg_active >= 0){ + if(sel_reg_active == 0){ + REG32_VAL(__GPIO_BASE+PIN_SHARING_SEL_OFFSET) &= ~(1<<sel_reg_bit); + }else { + REG32_VAL(__GPIO_BASE+PIN_SHARING_SEL_OFFSET) |= (1<<sel_reg_bit); + } + } + #endif + }else{ + errlog(" touch panel led gpio request failed !! \n"); + goto error_req_irq_fail; + } + + mutex_init(&ts->timeout_mutex); + ts->timeout_count = -1; + ts->timeout_queue= create_singlethread_workqueue("timeout_queue"); + INIT_DELAYED_WORK(&ts->timeout_work,timeout_func); + + } + + + + +#ifdef GSL_TIMER + dbg( "gsl_ts_probe () : add gsl_timer\n"); + + init_timer(&ts->gsl_timer); + ts->gsl_timer.expires = jiffies + 3 * HZ; //¶¨Ê±3 ÃëÖÓ + ts->gsl_timer.function = &gsl_timer_handle; + ts->gsl_timer.data = (unsigned long)ts; + add_timer(&ts->gsl_timer); +#endif + + /* create debug attribute */ + //rc = device_create_file(&ts->input->dev, &dev_attr_debug_enable); + +#ifdef CONFIG_HAS_EARLYSUSPEND + ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; + ts->early_suspend.suspend = gsl_ts_early_suspend; + ts->early_suspend.resume = gsl_ts_late_resume; + register_early_suspend(&ts->early_suspend); +#endif + + dbg("[GSLX680] End %s\n", __func__); + wmt_enable_gpirq(); + + check_Backlight_delay(); + return 0; + + + +error_req_irq_fail: + free_irq(ts->irq, ts); + +error_mutex_destroy: + mutex_destroy(&ts->sus_lock); + wake_lock_destroy(&downloadWakeLock); + input_free_device(ts->input); + kfree(ts); +error_kfree_fw: + kfree(GSLX680_FW); + return rc; +} + +static int gsl_ts_remove(struct i2c_client *client) +{ + + + struct gsl_ts *ts = i2c_get_clientdata(client); + dbg("==gsl_ts_remove=\n"); + +#ifdef CONFIG_HAS_EARLYSUSPEND + unregister_early_suspend(&ts->early_suspend); +#endif + + //device_init_wakeup(&client->dev, 0); + cancel_work_sync(&ts->work); + + if( tp_led_gpio >= 0 ){ + mutex_destroy(&ts->timeout_mutex); + gpio_free(tp_led_gpio); + tp_led_gpio = -1; + tp_led_gpio_active = -1; + } + + free_irq(ts->irq, ts); + destroy_workqueue(ts->wq); + input_unregister_device(ts->input); + mutex_destroy(&ts->sus_lock); + wake_lock_destroy(&downloadWakeLock); + + //device_remove_file(&ts->input->dev, &dev_attr_debug_enable); + + if(GSLX680_FW){ + kfree(GSLX680_FW); + GSLX680_FW = NULL; + } + + kfree(ts->touch_data); + kfree(ts); + + return 0; +} + +/* +static const struct i2c_device_id gsl_ts_id[] = { + {GSLX680_I2C_NAME, 0}, + {} +}; +MODULE_DEVICE_TABLE(i2c, gsl_ts_id); + + +static struct i2c_driver gsl_ts_driver = { + .driver = { + .name = GSLX680_I2C_NAME, + .owner = THIS_MODULE, + }, +#ifndef CONFIG_HAS_EARLYSUSPEND + .suspend = gsl_ts_suspend, + .resume = gsl_ts_resume, +#endif + .probe = gsl_ts_probe, + .remove = __devexit_p(gsl_ts_remove), + .id_table = gsl_ts_id, +}; +*/ +static int wmt_wakeup_bl_notify(struct notifier_block *nb, unsigned long event, + void *dummy) +{ + //printk("get notify\n"); + switch (event) { + case BL_CLOSE: + l_ts->is_suspended = true; + //printk("\nclose backlight\n\n"); + //printk("disable irq\n\n"); + wmt_disable_gpirq(); + break; + case BL_OPEN: + l_ts->is_suspended = false; + //printk("\nopen backlight\n\n"); + //printk("enable irq\n\n"); + wmt_enable_gpirq(); + break; + } + + return NOTIFY_OK; +} + +static struct notifier_block wmt_bl_notify = { + .notifier_call = wmt_wakeup_bl_notify, +}; + +static int gsl_ts_init(void) +{ + int ret = 0; + ret = gsl_ts_probe(ts_get_i2c_client()); + if (ret) + { + dbg("Can't load gsl1680 ts driver!\n"); + } + //dbg("ret=%d\n",ret); + if (earlysus_en) + register_bl_notifier(&wmt_bl_notify); + return ret; +} +static void gsl_ts_exit(void) +{ + dbg("==gsl_ts_exit==\n"); + //i2c_del_driver(&gsl_ts_driver); + gsl_ts_remove(ts_get_i2c_client()); + if (earlysus_en) + unregister_bl_notifier(&wmt_bl_notify); + return; +} + +struct wmtts_device gslx680_tsdev = { + .driver_name = WMT_TS_I2C_NAME, + .ts_id = "GSL1680", + .init = gsl_ts_init, + .exit = gsl_ts_exit, + .suspend = gsl_ts_suspend, + .resume = gsl_ts_resume, +}; + + +//module_init(gsl_ts_init); +//module_exit(gsl_ts_exit); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("GSLX680 touchscreen controller driver"); +MODULE_AUTHOR("Guan Yuwei, guanyuwei@basewin.com"); +MODULE_ALIAS("platform:gsl_ts"); diff --git a/drivers/input/touchscreen/gsl1680_ts/gslX680.h b/drivers/input/touchscreen/gsl1680_ts/gslX680.h new file mode 100755 index 00000000..c146127c --- /dev/null +++ b/drivers/input/touchscreen/gsl1680_ts/gslX680.h @@ -0,0 +1,35 @@ +#ifndef _GSLX680_H_
+#define _GSLX680_H_
+
+
+
+#define GSL_NOID_VERSION
+#ifdef GSL_NOID_VERSION
+struct gsl_touch_info
+{
+ int x[10];
+ int y[10];
+ int id[10];
+ int finger_num;
+};
+extern unsigned int gsl_mask_tiaoping(void);
+extern unsigned int gsl_version_id(void);
+extern void gsl_alg_id_main(struct gsl_touch_info *cinfo);
+extern void gsl_DataInit(int *ret);
+
+extern int gsl_noid_ver;
+extern unsigned int gsl_config_data_id[512];
+#endif
+
+struct fw_data
+{
+ //u32 offset : 8;
+ //u32 : 0;
+ u32 offset;
+ u32 val;
+};
+
+extern void wmt_set_keypos(int index,int xmin,int xmax,int ymin,int ymax);
+
+
+#endif
diff --git a/drivers/input/touchscreen/gsl1680_ts/gsl_point_id.b b/drivers/input/touchscreen/gsl1680_ts/gsl_point_id.b Binary files differnew file mode 100755 index 00000000..f25fccd3 --- /dev/null +++ b/drivers/input/touchscreen/gsl1680_ts/gsl_point_id.b diff --git a/drivers/input/touchscreen/gsl1680_ts/wmt_ts.c b/drivers/input/touchscreen/gsl1680_ts/wmt_ts.c new file mode 100755 index 00000000..e0ddf9e7 --- /dev/null +++ b/drivers/input/touchscreen/gsl1680_ts/wmt_ts.c @@ -0,0 +1,1102 @@ +#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 <asm/uaccess.h> +#include <linux/fs.h> +#include <linux/syscalls.h> + +#include "gslX680.h" +#include "wmt_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 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; +static int rst_gpio; +static int panelres_x; +static int panelres_y; +static int lcd_exchg = 0; +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 struct class* l_dev_class = NULL; +static struct device *l_clsdevice = NULL; +extern struct wmtts_device gslx680_tsdev; +static struct wmtts_device* l_tsdev = &gslx680_tsdev; +struct proc_dir_entry* l_tsproc = NULL; +static struct i2c_client *l_client=NULL; +static int l_penup = 0; // 1-pen up,0-pen down +static int l_iftskey = -1; // 1:have ts key +int earlysus_en = 0; + +int tp_led_gpio; +int tp_led_gpio_active; + +int sel_reg_bit; +int sel_reg_active; + + +struct tp_infor +{ + //enum tp_type type; + char name[64]; + int i2caddr; + int xaxis; //0: x,1: x swap with y + int xdir; // 1: positive,-1: revert + int ydir; // 1: positive,-1: revert + int 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_tskey(void) +{ + return ((l_iftskey==1) ? 1: 0); +} + +int wmt_ts_get_firmwfilename(char* fname) +{ + sprintf(fname,"%s_fw.tpf",l_tpinfor[l_tpindex].name); + return 0; +} + + +static struct device* get_tp_device(void){ + if(l_client == NULL){ + errlog("l_client is NULL\n"); + } + return &l_client->dev; +} + + +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; +} + +static int parse_firmwarefile(const char* filedata, struct fw_data** firmarr, unsigned int* id_config) +{ + char endflag[]="/* End flag */"; + const char *p = filedata; + u32 val[2]; + int i = 0; + int j = 0; + int k = 0; + const char *s = NULL; + int hex = 0; + +#ifdef GSL_NOID_VERSION + if (gsl_noid_ver) { + while (*p != '{') p++; + p++; + s = p; + while (*s != '}') { + if (*s == '0' && *(s+1) == 'x') { + hex = 1; + break; + } + s++; + } + while (*p != '}') { + sscanf(p,hex ? "%x" : "%u,",&(id_config[k++])); + p = strchr(p,',');p++; + } + } +#endif + + // the first { + while (*p!='{') p++; + p++; + s = p; + // calculate the number of array + while (strncmp(p,endflag,strlen(endflag))) + { + if (*p=='{') + { + i++; + } + p++; + }; + dbg("the number of arry:0x%x\n", i); + // alloc the memory for array + *firmarr = kzalloc(sizeof(struct fw_data)*i, GFP_KERNEL); + // parse the value of array + p = s; + j = 0; + while (strncmp(p,endflag,strlen(endflag))) + { + if (*p=='{') + { + memset(val,0,sizeof(val)); + sscanf(p,"{%x,%x}",val,val+1); + (*firmarr)[j].offset = val[0]&0x00FF; + (*firmarr)[j].val= val[1]; + //dbg("data%x{%x,%x}\n",j,(*firmarr)[j].offset,(*firmarr)[j].val); + j++; + } + //p = strchr(p,'}'); + p++; + if (j>=i-2) + { + dbg("%s",p); + } + + }; + if (i != j) + { + errlog("Error parsing file(the number of arry not match)!\n"); + errlog("i=0x%x,j=0x%x\n", i,j); + kfree(*firmarr); + return -1; + }; + dbg("paring firmware file end.\n"); + return i; +} + + + +//filepath:the path of firmware file; +//firmdata:store the data from firmware file; +//id_config:config data for some ICs whitch have no id; +//return:the lengthen of firmware data,negative-parsing error. +int read_firmwfile(char* filepath, struct fw_data** firmdata, unsigned int* id_config) +{ + const u8 *data = NULL; + int i = 0; + int ret = -1; + const struct firmware* tpfirmware = NULL; + + klog("ts firmware file:%s\n",filepath); + ret = request_firmware(&tpfirmware, filepath, get_tp_device()); + if (ret < 0) { + errlog("Failed load tp firmware: %s ret=%d\n", filepath,ret); + goto err_end; + } + data = tpfirmware->data; + + i = parse_firmwarefile(data,firmdata,id_config); + + if (i <= 0){ + dbg("Failed to pare firmware file!\n"); + ret = -1; + goto error_parse_fw; + } + dbg("firmware arry len=0x%x\n", i); + ret = i; + dbg("success to read firmware file!\n");; +error_parse_fw: + if(tpfirmware){ + release_firmware(tpfirmware); + tpfirmware = NULL; + } +err_end: + return ret; +} + + + + int wmt_ts_get_gpionum(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 +} + +// 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 + } +} + +// up:0-pull down,1-pull up +void wmt_set_rst_pull(int up) +{ + if (up) + { + REG32_VAL(__GPIO_BASE+0x04c0) |= (1<<rst_gpio); //pull up + } else { + REG32_VAL(__GPIO_BASE+0x04c0) &= ~(1<<rst_gpio); //pull down + } +} + +// high:0-low level,1-high level +void wmt_rst_output(int high) +{ + REG32_VAL(__GPIO_BASE+0x0040) |= (1<<rst_gpio); //enable gpio + if (high) + { + REG32_VAL(__GPIO_BASE+0x00C0) |= (1<<rst_gpio); // high + } else { + REG32_VAL(__GPIO_BASE+0x00C0) &= ~(1<<rst_gpio); // low + } + REG32_VAL(__GPIO_BASE+0x0080) |= (1<<rst_gpio); //set output +} + +void wmt_rst_input(void) +{ + REG32_VAL(__GPIO_BASE+0x0040) |= (1<<rst_gpio); //enable gpio + REG32_VAL(__GPIO_BASE+0x0080) &= ~(1<<rst_gpio); //set input +} + +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) +{ + REG32_VAL(__GPIO_BASE+0x0040) &= ~(1<<irq_gpio); //enable gpio + REG32_VAL(__GPIO_BASE+0x0080) &= ~(1<<irq_gpio); //set input + 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); //enable gpio + REG32_VAL(__GPIO_BASE+0x0080) &= ~(1<<num); //set input + REG32_VAL(__GPIO_BASE+0x04c0) |= (1<<num); //pull down + 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"); + if (l_tsdev->suspend != NULL) + { + return l_tsdev->suspend(pdev, state); + } + return 0; +} +static int wmt_ts_resume(struct platform_device *pdev) +{ + dbg("ts resume....\n"); + if (l_tsdev->resume != NULL) + { + return l_tsdev->resume(pdev); + } + klog("...\n"); + return 0; +} + +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(>811_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 = 127, i = 0; + char retval[128] = {0},*p=NULL,*s=NULL; + int Enable=0; + int keypos[4][4]; + + // 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:%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].finger_num), + &(l_tpinfor[0].i2caddr),&gsl_noid_ver); + if (ret < 9) + { + 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; + } + + /*if (strstr(l_tpinfor[0].name, l_tsdev->ts_id) == NULL) + { + dbg("Can't find %s!\n", l_tsdev->ts_id); + return -ENODEV; + }*/ + l_tpindex = 0; + + klog("p.x = %d, p.y = %d, gpio=%d, resetgpio=%d,xaxis=%d,xdir=%d,ydri=%d,i2caddr=%d,gsl_noid_ver=%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].i2caddr, gsl_noid_ver); + + + memset(retval,0,sizeof(retval)); + ret = wmt_getsyspara("wmt.io.tskey", retval, &len); + if(ret) + { + l_iftskey = 0; + } else { + // get touch key + p = retval; + sscanf(p,"%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", \ + keypos[0],keypos[0]+1,keypos[0]+2,keypos[0]+3, \ + keypos[1],keypos[1]+1,keypos[1]+2,keypos[1]+3, \ + keypos[2],keypos[2]+1,keypos[2]+2,keypos[2]+3, \ + keypos[3],keypos[3]+1,keypos[3]+2,keypos[3]+3); + for (i = 0; i < 4; i++) + { + wmt_set_keypos(i,keypos[i][0],keypos[i][1],keypos[i][2],keypos[i][3]); + dbg("%d:%d,%d,%d,%d\n",i,keypos[i][0],keypos[i][1],keypos[i][2],keypos[i][3]); + }; + l_iftskey = 1; + } + + memset(retval,0,sizeof(retval)); + ret = wmt_getsyspara("wmt.touch.earlysus", retval, &len); + if(!ret) { + p = retval; + sscanf(p, "%d", &earlysus_en); + } + + 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; + } + + //wmt.tpkey.led 141:1 + tp_led_gpio = -1; + tp_led_gpio_active = -1; + sel_reg_bit = -1; + sel_reg_active = -1; + ret = wmt_getsyspara("wmt.tpkey.led", retval, &len); + + errlog("wmt.tpkey.led: %s \n",retval); + + if (!ret) { + int tmp[4] = {0}; + p = retval; + ret = sscanf(p, "%d:%d:%d:%d", &tmp[0], &tmp[1], &tmp[2], &tmp[3]); + if(ret == 2){ + tp_led_gpio = tmp[0]; + tp_led_gpio_active = tmp[1]; + } + if(ret == 4){ + tp_led_gpio = tmp[0]; + tp_led_gpio_active = tmp[1]; + sel_reg_bit = tmp[2]; + sel_reg_active = tmp[3]; + } + errlog("tp_led_gpio:%d tp_led_gpio_active:%d sel_reg_bit:%d sel_reg_active:%d \n" + ,tp_led_gpio,tp_led_gpio_active,sel_reg_bit,sel_reg_active); + } + +/* + 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]); + printk("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_board_info.addr = l_tpinfor[0].i2caddr; + 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; + + 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/drivers/input/touchscreen/gsl1680_ts/wmt_ts.h b/drivers/input/touchscreen/gsl1680_ts/wmt_ts.h new file mode 100755 index 00000000..ea764fd4 --- /dev/null +++ b/drivers/input/touchscreen/gsl1680_ts/wmt_ts.h @@ -0,0 +1,117 @@ + +#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> +#include <linux/firmware.h> +#include <mach/hardware.h> + + +//#define DEBUG_WMT_TS // kinseyli +#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 "gsl1680-ts" +//#define WMT_TS_I2C_ADDR 0x15 + +#define PIN_SHARING_SEL_OFFSET 0x200 + + +#define FW_BINARYFILE_SIZE 0x8000 + +extern int earlysus_en; + +//////////////////////////////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_gpionum(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_enable_rst_pull(int enable); +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 unsigned int wmt_ts_get_xaxis(void); +extern unsigned int wmt_ts_get_xdir(void); +extern unsigned int wmt_ts_get_ydir(void); +extern int wmt_ts_if_tskey(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; +//return:the lengthen of firmware data,negative-parsing error. +extern int read_firmwfile(char* filepath, struct fw_data** firmdata, unsigned int* id_config); +extern int wmt_ts_get_firmwfilename(char* fname); + +#endif + + + |