diff options
author | Srikant Patnaik | 2015-01-11 12:28:04 +0530 |
---|---|---|
committer | Srikant Patnaik | 2015-01-11 12:28:04 +0530 |
commit | 871480933a1c28f8a9fed4c4d34d06c439a7a422 (patch) | |
tree | 8718f573808810c2a1e8cb8fb6ac469093ca2784 /drivers/input/touchscreen/lw86x0_ts | |
parent | 9d40ac5867b9aefe0722bc1f110b965ff294d30d (diff) | |
download | FOSSEE-netbook-kernel-source-871480933a1c28f8a9fed4c4d34d06c439a7a422.tar.gz FOSSEE-netbook-kernel-source-871480933a1c28f8a9fed4c4d34d06c439a7a422.tar.bz2 FOSSEE-netbook-kernel-source-871480933a1c28f8a9fed4c4d34d06c439a7a422.zip |
Moved, renamed, and deleted files
The original directory structure was scattered and unorganized.
Changes are basically to make it look like kernel structure.
Diffstat (limited to 'drivers/input/touchscreen/lw86x0_ts')
-rwxr-xr-x | drivers/input/touchscreen/lw86x0_ts/Kconfig | 11 | ||||
-rwxr-xr-x | drivers/input/touchscreen/lw86x0_ts/Makefile | 34 | ||||
-rwxr-xr-x | drivers/input/touchscreen/lw86x0_ts/lw86x0_ts.c | 1321 | ||||
-rwxr-xr-x | drivers/input/touchscreen/lw86x0_ts/lw86x0_ts.h | 53 | ||||
-rwxr-xr-x | drivers/input/touchscreen/lw86x0_ts/wmt_ts.c | 1165 | ||||
-rwxr-xr-x | drivers/input/touchscreen/lw86x0_ts/wmt_ts.h | 98 |
6 files changed, 2682 insertions, 0 deletions
diff --git a/drivers/input/touchscreen/lw86x0_ts/Kconfig b/drivers/input/touchscreen/lw86x0_ts/Kconfig new file mode 100755 index 00000000..34cf42cb --- /dev/null +++ b/drivers/input/touchscreen/lw86x0_ts/Kconfig @@ -0,0 +1,11 @@ +config TOUCHSCREEN_LW86X0
+ tristate "LW86X0 Touchscreen Driver"
+ default y
+ depends on ARCH_WMT
+ ---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 lw86x0_ts.
+
diff --git a/drivers/input/touchscreen/lw86x0_ts/Makefile b/drivers/input/touchscreen/lw86x0_ts/Makefile new file mode 100755 index 00000000..a7cbba75 --- /dev/null +++ b/drivers/input/touchscreen/lw86x0_ts/Makefile @@ -0,0 +1,34 @@ +#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_lw86x0
+
+obj-m := $(MY_MODULE_NAME).o
+$(MY_MODULE_NAME)-objs := lw86x0_ts.o wmt_ts.o
+
+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/lw86x0_ts/lw86x0_ts.c b/drivers/input/touchscreen/lw86x0_ts/lw86x0_ts.c new file mode 100755 index 00000000..ce741c9c --- /dev/null +++ b/drivers/input/touchscreen/lw86x0_ts/lw86x0_ts.c @@ -0,0 +1,1321 @@ +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/i2c.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/i2c.h> +//#include <linux/earlysuspend.h> +#include <linux/delay.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/errno.h> +#include <mach/hardware.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/platform_device.h> +#include <linux/suspend.h> +#include <linux/async.h> +#include <linux/wait.h> +#include <linux/hrtimer.h> +#include <linux/init.h> +#include <linux/ioport.h> +#include <linux/irq.h> +#include <linux/kthread.h> +#include <linux/firmware.h> +#include <linux/power/wmt_battery.h> +#include "../../../video/backlight/wmt_bl.h" +#include "lw86x0_ts.h" +#include "wmt_ts.h" +//#include "wmt_custom_lw86x0.h" + +#define TIME_CHECK_CHARGE 3000 + +#define MAX_MULTI_DATA_SIZE 256 + +#define HDMI_BASE_ADDR (HDMI_TRANSMITTE_BASE_ADDR + 0xC000) +#define REG_HDMI_HOTPLUG_DETECT (HDMI_BASE_ADDR + 0x3ec) + +struct i2c_client *lw_i2c_client = NULL; +struct i2c_client *client;//add by jackie +extern char g_dbgmode; +extern int COL_NUM; +extern int ROW_NUM; +extern int SKIP_ZERO_POINT; + +struct wmtts_device lw86x0_tsdev; +static int tsirq_gpio; + +static int skip_zero_num = 0; + +u16 mcu_status_old = 0xffff; +u16 mcu_status = 0xffff; + +typedef struct Fw_Version{ //add by jackie + u8 magic_num1; + u8 magic_num2; + u8 mj_ver; + u8 mn_ver; +}Fw_Ver;//add by jackie + +//struct for report touch info +struct ts_event { + u16 x[SUPPORT_POINT_NUM_MAX];//point x + u16 y[SUPPORT_POINT_NUM_MAX];//point y + u16 pressure[SUPPORT_POINT_NUM_MAX];//point pressure + u8 touch_point;//touch point number +}; + +struct lw86x0_ts_data { + struct input_dev *input_dev; + struct ts_event event; + struct work_struct touch_event_work; + struct workqueue_struct *ts_workqueue; +#if defined(CONFIG_HAS_EARLYSUSPEND) + struct early_suspend early_suspend; +#endif +}l_tsdata; + +static struct mutex ts_data_mutex; +static int l_powermode = -1; +static int l_hdmimode = -1; + +static int l_keylen = 4; +static int l_baseaxis = 1; //0:x-axis,1:y-axis +int l_keypos[TS_KEY_NUM+1][2]; + +unsigned int l_tskey[TS_KEY_NUM][2] = { + {0,KEY_MENU}, + {0,KEY_HOME}, + {0,KEY_BACK}, + {0,KEY_SEARCH}, +}; +static int l_early_suspend = 0; // 1:the early suspend function has been excuted + +static int stop_timer = 0; +struct work_struct phone_status_work; +struct timer_list polling_phone_status_timer; +static int check_chip_status(void); +static int first_init_reg = 1; +static u16 auto_coff_value[20] = {0}; +//static finger_up_status = 1; + +u8 get_fw_file_check_sum(void); +u16 get_fw_check_sum(void); + +extern int register_bl_notifier(struct notifier_block *nb); + +extern int unregister_bl_notifier(struct notifier_block *nb); +//static struct ts_event old_event; + +void swap_byte_in_buffer(u16* buf, int count ) +{ + int i; + for(i = 0; i < count; i++ ) + { + buf[i] = swap16(buf[i]); + } +} + +/** +** for read register +** rxbuf:read value +** txdata:read register address +** rxlength:read value length +**/ + +static int lw86x0_i2c_rxdata(char *rxbuf, char*txdata, int rxlength) +{ + int ret; + //int reg;//add jackie + + struct i2c_msg msgs[] = { + { + .addr = lw_i2c_client->addr, + .flags = 0, + .len = 2, + .buf = txdata, + }, + { + .addr = lw_i2c_client->addr, + .flags = I2C_M_RD, + .len = rxlength, + .buf = rxbuf, + }, + }; + + //ret = wmt_i2c_xfer_continue_if_4(msgs, 2, 1); + + ret = i2c_transfer(lw_i2c_client->adapter, &msgs[0], 2);//add by jackie + if (ret != 2) + { + dbg("msg i2c rxdata error: %d\n", ret); + return -1; + } + else + { + return 0; + } + +#if 0 + struct i2c_msg xfer_msg[2]; + 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 + +} + +/** +** for write register +** txdata:register address and value u8 +** length:txdata length +**/ + +static int lw86x0_i2c_txdata(char *txdata, int length) +{ + int ret; + + struct i2c_msg msg[] = { + { + .addr = lw_i2c_client->addr, + .flags = 0, + .len = length, + .buf = txdata, + }, + }; + + + ret = i2c_transfer(lw_i2c_client->adapter, &msg[0], 1);//1 + + //ret = wmt_i2c_xfer_continue_if_4(msg, 1, 1); + if (ret != 1) + { + dbg("i2c txdata error: %d\n", ret); + return -1; + } + else + { + return 0; + } + +} + +/** +** Interface write register for other functions +** addr:write register address +** value:write register value +**/ + +int lw86x0_write_reg(u16 addr, u16 value) +{ + u8 buf[4]; + int ret = -1; + unsigned char * pVal = (unsigned char *) &value; + unsigned char * pOffset = (unsigned char *) &addr; + buf[0] = pOffset[1]; + buf[1] = pOffset[0]; + buf[2] = pVal[1]; + buf[3] = pVal[0]; + ret = lw86x0_i2c_txdata(buf, 4); + if (ret < 0) + { + dbg("lw86x0_write_reg error: %d\n", ret); + return -1; + } + return 0; +} + +/*int lw86x0_write_reg_multi(u16 start_addr, u16 value[], u16 num) +{ + u8 buf[MAX_MULTI_DATA_SIZE]; + int ret = -1; + int i = 0; + unsigned char * pVal = (unsigned char *) &value[0]; + unsigned char * pOffset = (unsigned char *) &addr; + buf[0] = pOffset[1]; + buf[1] = pOffset[0]; + //buf[2] = pVal[1]; + //buf[3] = pVal[0]; + for(i = 0; i < num; i++) + { + pVal = (unsigned char *) &value[i]; + buf[2*i + 2] = pVal[1]; + buf[2*i + 3] = pVal[0]; + } + + ret = lw86x0_i2c_txdata(buf, num*2+2); + + if (ret < 0) + { + dbg("lw86x0_write_reg error: %d\n", ret); + return -1; + } + return 0; +}*/ +/** +** Interface read register for other functions +** addr:read register address +** pdata:read register value +** regcnt:read register count +**/ + +int lw86x0_read_reg(u16 addr, u16 *pdata, int regcnt) +{ + int ret; + + u16 offset_reverse = swap16(addr); + ret = lw86x0_i2c_rxdata((char*)pdata, (char*)&offset_reverse, 2*regcnt); + + if (ret < 0) + { + dbg("lw86x0_read_reg error: %d\n", ret); + return -1; + } + else + { + swap_byte_in_buffer(pdata, regcnt); + return 0; + } +} + +int wmt_ts_load_firmware(char* firmwarename, unsigned char** firmdata, int* fwlen) +{ + int i; + const struct firmware *fw_entry; + for (i = 0; i < 3; i++) { + if(request_firmware(&fw_entry, firmwarename, &lw_i2c_client->dev)!=0) + printk(KERN_ERR "cat't request firmware #%d\n", i); + else + break; + } + if (i == 3) + return -EINVAL; + + if (fw_entry->size <= 0) { + printk(KERN_ERR "load firmware error\n"); + release_firmware(fw_entry); + return -1; + } + + *firmdata = kzalloc(fw_entry->size + 1, GFP_KERNEL); + memcpy(*firmdata, fw_entry->data, fw_entry->size); + *fwlen = fw_entry->size; + release_firmware(fw_entry); + + return 0; +} + +static u16 *default_setting_table; +static int cfg_len; + +static int load_cfgfile(void) +{ + u32 val[2]; + u16 temp[200]; + int i = 0; + char cfgname[32] = {0}; + u8 *pData; + int fileLen; + char *p; + char *s; + + wmt_ts_get_configfilename(cfgname); + if (wmt_ts_load_firmware(cfgname, &pData, &fileLen)) { + errlog("Load config file failed~ \n"); + return -1; + } + s = pData; + p = strstr(s, "COL_NUM"); + sscanf(p, "COL_NUM=%d;", &COL_NUM); + p = strstr(s, "ROW_NUM"); + sscanf(p, "ROW_NUM=%d;", &ROW_NUM); + p = strstr(s, "SKIP_ZERO_POINT"); + sscanf(p, "SKIP_ZERO_POINT=%d;", &SKIP_ZERO_POINT); + dbg("COL_NUM=%d;ROW_NUM=%d;SKIP_ZERO_POINT=%d;",COL_NUM,ROW_NUM,SKIP_ZERO_POINT); + + p = pData; + while (*p != '{') { + p++; + if(*p == '\0') { + errlog("Bad config file\n"); + i = -1; + goto end; + } + } + while (*p != '}') { + if (!strncmp(p, "0x", 2)) { + i++; + if ((i & 0x0001) != 0) { + sscanf(p, "0x%x,0x%x,", val, val+1); + temp[i-1] = val[0] & 0x0000FFFF; + temp[i] = val[1] & 0x0000FFFF; + } + } + p++; + if(*p == '\0') { + i = -1; + errlog("Bad config file\n"); + goto end; + } + }; + + dbg("the number of data:0x%x\n", i); + default_setting_table = kzalloc(i*2, GFP_KERNEL); + memcpy(default_setting_table, temp, i*2); + cfg_len = i; + + dbg("paring config file end.\n"); +end: + kfree(pData); + return i; +} + +void lw86x0_stop_timer(int flags) +{ + stop_timer = flags; +} + + +static u16 get_trim_info(void) +{ + u16 trim_info = 0; + u8 buf[2] = {0}; + lw86x0_write_reg(0x00e4, 0x0000); + lw86x0_write_reg(0x00e2, 0x0302); + lw86x0_write_reg(0x00e3, 0x0000); + lw86x0_write_reg(0x00e2, 0x034e); + lw86x0_write_reg(0x00e2, 0x0302); + lw86x0_read_reg(0x00e4, buf, 1); + lw86x0_write_reg(0x00e2, 0x0000); + trim_info = buf[1]; + dbg("trim info is %04x",trim_info); + return trim_info; +} + +/** +** load default register setting +**/ + +void lw86x0_load_def_setting(void) +{ + int i = 0; + u16 trim_value = 0; + u16 trim_info = 0; + + lw86x0_write_reg(0x00e6, 0x3311); + trim_info = get_trim_info(); + for(i = 0; i < cfg_len / 2; i++) + { + if(default_setting_table[2*i] == 0xffff) + { + msleep(default_setting_table[2*i+1]); + } + else + { + if(default_setting_table[2*i] == 0x00ee) + { + lw86x0_read_reg(0x00ee, &trim_value, 1); + if(trim_value == 0x00a0) + { + trim_value = 0x00c0 + trim_info; + } + else + { + trim_value = 0x100 + trim_value; + } + lw86x0_write_reg(0x00ee, trim_value); + } + else + { + lw86x0_write_reg(default_setting_table[2*i], default_setting_table[2*i+1]); + } + //lw86x0_write_reg(default_setting_table[2*i], default_setting_table[2*i+1]); + } + /*if(i == 0) + { + msleep(100); + }*/ + } + if(first_init_reg == 1) + { + for(i = 0; i < 19; i++) + { + lw86x0_read_reg(0x0092+i, &auto_coff_value[i], 1); + } + first_init_reg = 0; + } + else + { + lw86x0_write_reg(0x0035, 0x0070); + lw86x0_write_reg(0x0060, 0x0307); + lw86x0_write_reg(0x0091, 0x0200); + for(i = 0; i < 19; i++) + { + lw86x0_write_reg(0x0092+i, auto_coff_value[i]); + } + lw86x0_write_reg(0x0035, 0x2070); + msleep(100); + lw86x0_write_reg(0x0060, 0x0306); + } +} + +/** +** set reset pin for lw86x0 +**/ + +static void lw86x0_hw_reset(void) +{ + wmt_rst_output(0); + //msleep(500); + msleep(30); + wmt_rst_output(1); +} + +static void lw86x0_ts_release(void) +{ + int i = 0; + struct lw86x0_ts_data *data = &l_tsdata; + int down = 0; + + // dbg("lw86x0_ts_release"); + + for (i = 0; i < l_keylen; i++) + { + down |= l_tskey[i][0]; + } + if (down != 0) + { + // if down clear the flag + for ( i = 0; i < l_keylen; i++) + { + l_tskey[i][0] = 0; + }; + //dbg("key up!\n"); + if (wmt_ts_enable_keyled()) + wmt_ts_turnoff_light(); + } + else + { + if (!lw86x0_tsdev.penup) + { + input_mt_sync(data->input_dev); + input_sync(data->input_dev); + //dbg("rpt pen\n"); + } + lw86x0_tsdev.penup = 1; + //dbg("pen up\n"); + //wake_up(&ts_penup_wait_queue); + } +} + +/** +**set wmt touch key count +**/ + +void wmt_ts_set_keylen(int keylen) +{ + l_keylen = keylen; +} + +/** +**set wmt touch baseaxis +**axis:0--x axis,1--y axis. +**/ + +void wmt_ts_set_baseaxis(int axis) +{ + l_baseaxis = axis; +} + +/** +** set wmt touch key info struct keypos +** index:set key number +** min:key min point value +** max:key max point value +**/ + +void wmt_ts_set_keypos(int index, int min,int max) +{ + l_keypos[index][0] = min; + l_keypos[index][1] = max; +} + +/** +** report key info to wmt android +**/ +#if 0 + +static int lw86x0_report_key_info(void) +{ + struct lw86x0_ts_data *data = &l_tsdata; + u16 x, y; + u16 key_stpos,key_vrpos; // the stable and variable position for touch key + int i =0; + lw86x0_read_reg(0x0161, &x, 1); + lw86x0_read_reg(0x016B, &y, 1); + if (wmt_ts_enable_tskey() != 0) + { + switch (l_baseaxis) + { + case 0: + key_stpos = y; + key_vrpos = x; + break; + case 1: + default: + key_stpos = x; + key_vrpos = y; + break; + } + } + for (i=0;i < l_keylen;i++) + { + if ((key_vrpos>=l_keypos[i][0]) && (key_vrpos<=l_keypos[i][1])) + { + // report the key + if (0 == l_tskey[i][0]) + { + input_report_key(data->input_dev, l_tskey[i][1], 1); + input_report_key(data->input_dev, l_tskey[i][1], 0); + input_sync(data->input_dev); + l_tskey[i][0] = 1; + dbg("report tskey:%d\n",i); + if (wmt_ts_enable_keyled()) + wmt_ts_turnon_light(); + } + return 1;//key + } + } + return 0;//no key + +} +#endif + +static void check_mode(void) +{ + int dcin = wmt_charger_is_dc_plugin(); + int hdmiin = (REG32_VAL(REG_HDMI_HOTPLUG_DETECT) & BIT31) >> 31; + + if (dcin == l_powermode && hdmiin == l_hdmimode) + return; + if (!dcin && !hdmiin) { + klog("DC and HDMI removed\n"); + lw86x0_write_reg(0x01e9, 0x0000); + } else { + klog("DC or HDMI in\n"); + lw86x0_write_reg(0x01e9, 0x0001); + } + l_powermode = dcin; + l_hdmimode = hdmiin; +} + +/** +** report touch info to wmt android +** touch_number: touch count +**/ + +static void lw86x0_report_touch_info(u16 touch_number) +{ + struct lw86x0_ts_data *data = &l_tsdata; + struct ts_event *event = &data->event; + u16 i; + + //old_event = *event; + //dbg("Enter into lw86x0_report_touch_info"); + check_mode(); + if(touch_number == 0) + { + input_mt_sync(data->input_dev); + input_sync(data->input_dev); + return; + } + if(touch_number> wmt_ts_get_fingernum()){ + //dbg("Invalid Touch point count is found %d",touch_number); + return; + } + event->touch_point = touch_number; + + //memset(event->x, 0, SUPPORT_POINT_NUM*sizeof(u16) ); + //memset(event->y, 0, SUPPORT_POINT_NUM*sizeof(u16) ); + //memset(event->pressure, 0, SUPPORT_POINT_NUM*sizeof(u16) ); + for( i = 0; i <touch_number; i++ ) + { + lw86x0_read_reg(0x0161+i, &event->x[i], 1); + lw86x0_read_reg(0x016B+i, &event->y[i], 1); + lw86x0_read_reg(0x0175+i, &event->pressure[i], 1); + } + + for (i = 0; i < touch_number; i++) + { + int x = (event->x[i]) & 0x03ff; + int y = (event->y[i]) & 0x03ff; + int id = ((event->x[i])>>12)&0x000f; + int tmp; + + if(x>wmt_ts_get_resolvX()) + { + x = wmt_ts_get_resolvX(); + } + + if(y>wmt_ts_get_resolvY()) + { + y= wmt_ts_get_resolvY(); + } + + if (wmt_ts_get_xaxis()) { + tmp = x; + x = y; + y = tmp; + } + if (wmt_ts_get_xdir()) + x = wmt_ts_get_resolvX() - x; + if (wmt_ts_get_ydir()) + y = wmt_ts_get_resolvY() - y; + + if (wmt_ts_get_lcdexchg()) { + int tmp; + tmp = x; + x = y; + y = wmt_ts_get_resolvX() - tmp; + } + + dbg("id %d [%d, %d] p %d",id, x, y, event->pressure[i]); + //input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR,event->pressure[i]); + input_report_abs(data->input_dev, ABS_MT_POSITION_X, x); + input_report_abs(data->input_dev, ABS_MT_POSITION_Y, y); + input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, id); + input_mt_sync(data->input_dev); + } + /* SYN_REPORT */ + input_sync(data->input_dev); +} + +/** +**lw86x0 touch irq work function +**/ + +static void lw86x0_ts_touch_irq_work(struct work_struct *work) +{ + + u16 int_touch_status=0; + mutex_lock(&ts_data_mutex); + + //dbg("Enter into lw86x0_ts_touch_irq_work"); + + //finger_up_status = 0; + lw86x0_read_reg(0x01f5, &int_touch_status, 1); + + //dbg("Read 0x1f5 = %d",int_touch_status); + if( int_touch_status & 0x0001) + { + u16 touch_number=0; + lw86x0_read_reg(0x0160, &touch_number, 1); + //dbg("tn=%d\n",touch_number); + if(touch_number==0) + { + skip_zero_num++; + if(SKIP_ZERO_POINT==skip_zero_num) + { + dbg("tn=%d\n",touch_number); + lw86x0_write_reg(0x01f2, 0x0010); + lw86x0_report_touch_info(touch_number); + lw86x0_ts_release(); + //finger_up_status = 1; + } + else if(SKIP_ZERO_POINT<skip_zero_num) + { + skip_zero_num = SKIP_ZERO_POINT+1; + } + } + else if(touch_number==15) + { + //dbg("touch_number=%d\n",touch_number); + } + else + { + dbg("tn=%d\n",touch_number); + lw86x0_write_reg(0x01f2, 0x0011); + skip_zero_num = 0; + lw86x0_report_touch_info(touch_number); + } + } + else + { + //finger_up_status = 1; + } + lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt + //mdelay(500); + //dbg("clear interrupt 1"); + lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt + //mdelay(500); + //dbg("clear interrupt 2"); + //lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt + //mdelay(500); + //dbg("clear interrupt 3"); + //lw86x0_write_reg(0x01f5, 0xffff);//clear interrupt + //mdelay(500); + //dbg("clear interrupt 4"); + //dbg("Write 0x1f5 = 0xffff"); + //lw86x0_read_reg(0x01f5, &int_touch_status, 1); + //dbg("Re-Read 0x1f5 = %d",int_touch_status); + + if(g_dbgmode==0) + { + //dbg("Enable Irq"); + wmt_enable_gpirq(tsirq_gpio); + } + mutex_unlock(&ts_data_mutex); +} + +static irqreturn_t lw86x0_ts_interrupt(int irq, void *dev_id) +{ + //dbg("enter lw86x0_ts_interrupt"); + //if (!wmt_is_tsirq_enable(tsirq_gpio)) + //{ + // dbg("tsirq not enabled"); + // return IRQ_NONE; + //} + if (wmt_is_tsint(tsirq_gpio)) + { + wmt_clr_int(tsirq_gpio); + wmt_disable_gpirq(tsirq_gpio); + if(!l_early_suspend) + { + //dbg("tsirq enabled"); + queue_work(l_tsdata.ts_workqueue, &l_tsdata.touch_event_work); + } + return IRQ_HANDLED; + } + return IRQ_NONE; +} + +static void reset_chip(void) +{ + printk("\nReset LW IC\n\n"); + lw86x0_write_reg(0x00e6, 0x3311); + lw86x0_write_reg(0x00e0, 0x0005); + lw86x0_write_reg(0x0214, 0x0020); + lw86x0_write_reg(0x033d, 0x8100); + mdelay(500); + wmt_rst_output(0); + wmt_set_irq_mode(tsirq_gpio, 0); + mdelay(100); + wmt_rst_output(1); + wmt_set_gpirq(tsirq_gpio, GIRQ_FALLING); + lw86x0_load_def_setting(); + if(g_dbgmode==0) + { + wmt_enable_gpirq(tsirq_gpio); + } +} + + +static int check_chip_status(void) +{ + u16 read_value = 0; + u16 read_sram = 0; + int ret = lw86x0_read_reg(0x00e6, &read_value, 1); + if(ret != 0) + { + reset_chip(); + return 0; + } + if(read_value != 0x3311) + { + reset_chip(); + return 0; + } + else + { + lw86x0_read_reg(0x00e0, &read_value, 1); + if(read_value != 0x0005 && read_value != 0x000d) + { + dbg("0x00e0!=0x0005,0x000d\n"); + reset_chip(); + return 0; + } + lw86x0_read_reg(0x0180, &read_sram, 1); + if(read_sram != 0) + { + dbg("0x0180!=0\n"); + reset_chip(); + return 0; + } + lw86x0_read_reg(0x0181, &mcu_status, 1); + if(mcu_status_old == mcu_status) + { + dbg("0x0180 old!=new\n"); + reset_chip(); + mcu_status_old = mcu_status; + return 0; + } + else + { + mcu_status_old = mcu_status; + return 1; + } + } + return 1; +} + +static void phone_status_listener(struct work_struct *work) +{ + if(stop_timer == 0) + { + check_chip_status(); + } +} + +static void lw86x0_ts_polling_phone_status(long unsigned int dev_addr) +{ + schedule_work(&phone_status_work); + mod_timer(&polling_phone_status_timer, jiffies + msecs_to_jiffies(2000)); +} + +/** +** lw86x0 ts early suspend function +**/ +#ifdef CONFIG_HAS_EARLYSUSPEND +static void ts_early_suspend(void) +{ + wmt_disable_gpirq(tsirq_gpio); +} + +//#ifdef CONFIG_HAS_EARLYSUSPEND + +static void lw86x0_ts_early_suspend(struct early_suspend *handler) +{ + printk("lw86x0_ts_early_suspend\n"); + ts_early_suspend(); + l_early_suspend = 1; + lw86x0_write_reg(0x000c, 0xffff); + lw86x0_write_reg(0x033d, 0x0d60); + lw86x0_write_reg(0x00e2, 0x0300); + lw86x0_write_reg(0x000d, 0x4000); + lw86x0_write_reg(0x00e5, 0x4c01); + stop_timer = 1; +} + +/** +** lw86x0 late resume function +**/ +static void ts_late_resume(void) +{ + printk("ts_late_resume\n"); + //wmt_disable_gpirq(tsirq_gpio); + //lw86x0_hw_reset(); + l_early_suspend = 0; + + wmt_set_gpirq(tsirq_gpio, GIRQ_FALLING); + if(g_dbgmode==0) + { + printk("g_dbgmode==0\n"); + wmt_enable_gpirq(tsirq_gpio); + } +} + + +static void lw86x0_ts_late_resume(struct early_suspend *handler) +{ + printk("==lw86x0_ts_resume=\n"); + int ret = check_chip_status(); + if(ret == 1) + { + lw86x0_write_reg(0x000d, 0xc000); + lw86x0_write_reg(0x00e2, 0x0100); + lw86x0_write_reg(0x00e5, 0x4c00); + lw86x0_write_reg(0x000c, 0xffff); + } + ts_late_resume(); + l_early_suspend = 0; + stop_timer = 0; +} +#endif + +/** +** lw86x0 ts suspend function +**/ + +static int lw86x0_suspend(struct platform_device *pdev, pm_message_t state) +{ + return 0; +} + +/** +** lw86x0 resume function +**/ + +static int lw86x0_resume(struct platform_device *pdev) +{ + lw86x0_hw_reset(); + first_init_reg = 1; + lw86x0_load_def_setting(); + return 0; +} + +#ifdef SUPPORT_FW_UPGRADE +//add by jackie +#define BYTES_PER_PACKET 64 +//#define FILEPATH "/etc/firmware/TOUCH.BIN" +int fileLen; +u8 *pData; + +void read_data_from_fw_file(void) +{ + char fwname[32] = {0}; + wmt_ts_get_firmwfilename(fwname); + if (wmt_ts_load_firmware(fwname, &pData, &fileLen)) { + dbg("Load firmware file failed~ \n"); + return; + } +} + +u8 check_fw_version(void) +{ + //Fw_Ver* pfwVerInFile = NULL; + //Fw_Ver fwVer; + + u16 fw_check_sum; + u16 fw_file_check_sum = 0; + + read_data_from_fw_file(); + /*pfwVerInFile = (Fw_Ver* )&(pData[0x2000]); + + printk("struct data:%c%c%d%d\n",pfwVerInFile->magic_num1,pfwVerInFile->magic_num2,pfwVerInFile->mj_ver,pfwVerInFile->mn_ver);//add by jackie + lw86x0_write_reg(0x00e6,0x3311); + lw86x0_flash_read((u8*)&fwVer,0x2000,4); + printk("lw86x0_flash:%c%c%d%d\n",fwVer.magic_num1,fwVer.magic_num2,fwVer.mj_ver,fwVer.mn_ver);//add by jackie + //printk("lw86x0_flash:%d%d\n",fwVer.magic_num1,fwVer.magic_num2);//add by jackie + if((fwVer.magic_num1!='L'||fwVer.magic_num2!='W') + ||((fwVer.magic_num1=='L'&&fwVer.magic_num2=='W') + &&(pfwVerInFile->magic_num1=='L'&&pfwVerInFile->magic_num2=='W') + &&(fwVer.mj_ver!=pfwVerInFile->mj_ver || fwVer.mn_ver!=pfwVerInFile->mn_ver)) + )*/ + lw86x0_write_reg(0x00e6, 0x3311); + lw86x0_write_reg(0x0020, 0x9000); + lw86x0_write_reg(0x0002, 0x8900); + lw86x0_write_reg(0x0115, 0x0100); + lw86x0_write_reg(0x0020, 0x1000); + msleep(200); + fw_check_sum = get_fw_check_sum(); + fw_file_check_sum = get_fw_file_check_sum(); + printk("**********fw_check_sum = %04x, fw_file_check_sum = %04x\n",fw_check_sum,fw_file_check_sum); + if(((fw_check_sum&0xff00)!=0x8000)||((fw_check_sum&0x00ff)!=fw_file_check_sum)) + { + lw86x0_write_reg(0x0002, 0x8800); + printk("firmware crc check is not equal, update firmware......\n"); + return 1;//return 1 means needing upgrade + } + else + { + printk("firmware is not updated......\n"); + lw86x0_write_reg(0x0002, 0x8800); + return 0; + } +} + +void fw_download(void) +{ + int pkt_num = (fileLen+BYTES_PER_PACKET-1)/BYTES_PER_PACKET; + int i; + int last_pkt_size = ((int)fileLen) % BYTES_PER_PACKET; + printk("pkt_num is:%d\n",pkt_num);//add + if(last_pkt_size==0) + { + last_pkt_size = BYTES_PER_PACKET; + } + lw86x0_flash_write_prepare(); + for(i=0;i<pkt_num;i++) + { + lw86x0_flash_write(&pData[i*BYTES_PER_PACKET],i*BYTES_PER_PACKET,(i==pkt_num-1)?last_pkt_size:BYTES_PER_PACKET); + } + lw86x0_flash_write_finish(fileLen); + printk("firmware is updated......\n");//add +} + + +u8 get_fw_file_check_sum(void) +{ + //u16 dataLen; + //u8* pData = NULL; + u16 i; + u8 checksum = 0; + printk("**********dataLen = %04x\n",fileLen); + for(i=0;i<fileLen;i++) + { + checksum+=pData[i]; + } + return checksum; +} + +u16 get_fw_check_sum(void) +{ + u8 cnt = 10; + u16 check_sum = 0; + //u16 fw_length = 0; + while(cnt>0) + { + lw86x0_read_reg(0x0182, &check_sum, 1); + printk("**********check_sum = %04x\n",check_sum); + if((check_sum&0xff00)==0x8000) + { + break; + } + cnt--; + msleep(100); + } + return check_sum; +} + +static void fw_upgrader(void) +{ + u16 fw_check_sum; + u16 fw_file_check_sum = 0; + + if(check_fw_version()==0) + { + return; + } + + lw86x0_write_reg(0x00e6, 0x3311); + fw_download(); + lw86x0_write_reg(0x0020, 0x9000); + lw86x0_write_reg(0x0002, 0x8900); + lw86x0_write_reg(0x0115, 0x0100); + lw86x0_write_reg(0x0020, 0x1000); + msleep(200); + fw_check_sum = get_fw_check_sum(); + fw_file_check_sum = get_fw_file_check_sum(); + printk("**********fw_check_sum = %04x, fw_file_check_sum = %04x\n",fw_check_sum,fw_file_check_sum); + if(((fw_check_sum&0xff00)!=0x8000)||((fw_check_sum&0x00ff)!=fw_file_check_sum)) + { + printk("*********redownload fw\n"); + fw_download(); + lw86x0_write_reg(0x00e6, 0x3311); + lw86x0_write_reg(0x0020, 0x9000); + lw86x0_write_reg(0x0002, 0x8900); + lw86x0_write_reg(0x0115, 0x0100); + lw86x0_write_reg(0x0020, 0x1000); + msleep(200); + fw_check_sum = get_fw_check_sum(); + fw_file_check_sum = get_fw_file_check_sum(); + printk("**********re-check fw_check_sum = %04x, fw_file_check_sum = %04x\n",fw_check_sum,fw_file_check_sum); + if(((fw_check_sum&0xff00)!=0x8000)||((fw_check_sum&0x00ff)!=fw_file_check_sum)) + { + lw86x0_flash_write_prepare(); + } + } + else + { + } + lw86x0_write_reg(0x0002, 0x8800); + kfree(pData); + lw86x0_hw_reset(); + +} + +#endif + + +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_early_suspend = 1; + wmt_disable_gpirq(tsirq_gpio); + stop_timer = 1; + cancel_work_sync(&l_tsdata.touch_event_work); + cancel_work_sync(&phone_status_work); + printk("\nclose backlight\n\n"); + break; + case BL_OPEN: + l_early_suspend = 0; + wmt_enable_gpirq(tsirq_gpio); + lw86x0_write_reg(0x01f5,0xffff);//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + stop_timer = 0; + printk("\nopen backlight\n\n"); + break; + } + + return NOTIFY_OK; +} + +static struct notifier_block wmt_bl_notify = { + .notifier_call = wmt_wakeup_bl_notify, +}; + +static int lw86x0_ts_probe(struct platform_device *pdev) +{ + int err = 0; + int i = 0; + u16 read_from_e6 = 0; + lw_i2c_client = ts_get_i2c_client();//get i2c_client + + memset(&l_tsdata, 0 ,sizeof(l_tsdata)); + INIT_WORK(&l_tsdata.touch_event_work, lw86x0_ts_touch_irq_work); + mutex_init(&ts_data_mutex); + + l_tsdata.ts_workqueue = create_singlethread_workqueue("lw86x0-ts-queue"); + if (!l_tsdata.ts_workqueue) { + err = -ESRCH; + goto exit_create_singlethread; + } + + l_tsdata.input_dev = input_allocate_device(); + if (!l_tsdata.input_dev) { + err = -ENOMEM; + dbg("failed to allocate input device\n"); + goto exit_input_dev_alloc_failed; + } + + l_tsdata.input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); + l_tsdata.input_dev->propbit[0] = BIT_MASK(INPUT_PROP_DIRECT); + + if (wmt_ts_get_lcdexchg()) { + input_set_abs_params(l_tsdata.input_dev, + ABS_MT_POSITION_X, 0, wmt_ts_get_resolvY(), 0, 0); + input_set_abs_params(l_tsdata.input_dev, + ABS_MT_POSITION_Y, 0, wmt_ts_get_resolvX(), 0, 0); + } else { + input_set_abs_params(l_tsdata.input_dev, + ABS_MT_POSITION_X, 0, wmt_ts_get_resolvX(), 0, 0); + input_set_abs_params(l_tsdata.input_dev, + ABS_MT_POSITION_Y, 0, wmt_ts_get_resolvY(), 0, 0); + } + input_set_abs_params(l_tsdata.input_dev, + ABS_MT_TRACKING_ID, 0, 15, 0, 0); + + l_tsdata.input_dev->name = LW86X0_NAME; + for (i = 0; i < TS_KEY_NUM; i++) + { + set_bit(l_tskey[i][1], l_tsdata.input_dev->keybit); + }; + err = input_register_device(l_tsdata.input_dev); + if (err) { + errlog("lw86x0_ts_probe: failed to register input device."); + goto exit_input_register_device_failed; + } + +#ifdef SUPPORT_FW_UPGRADE + fw_upgrader(); + mdelay(500); +#endif + + err = load_cfgfile(); + if (err < 0) + goto exit_load_cfgfile_failed; + lw86x0_load_def_setting(); + +#ifdef CONFIG_HAS_EARLYSUSPEND + l_tsdata.early_suspend.level = EARLY_SUSPEND_LEVEL_DISABLE_FB+ 1; + l_tsdata.early_suspend.suspend = lw86x0_ts_early_suspend; + l_tsdata.early_suspend.resume = lw86x0_ts_late_resume; + register_early_suspend(&l_tsdata.early_suspend); +#endif + + // init interrupt gpio + tsirq_gpio = wmt_ts_get_gpionum(); + wmt_set_gpirq(tsirq_gpio, GIRQ_FALLING);//GIRQ_FALLING); + wmt_disable_gpirq(tsirq_gpio); + + if(request_irq(wmt_get_tsirqnum(), lw86x0_ts_interrupt, IRQF_SHARED, "ts_lw86x0", l_tsdata.input_dev) < 0){ + errlog("Could not allocate intrrupt for ts_lw86x0 !\n"); + err = -1; + goto exit_register_irq; + } + lw86x0_ts_touch_irq_work(&l_tsdata.touch_event_work); + if(g_dbgmode==0) + { + wmt_enable_gpirq(tsirq_gpio); + } + msleep(5); + dbg("irqgpio=%d,irq=%d,resetgpio=%d\n", tsirq_gpio, wmt_get_tsirqnum(),wmt_ts_get_resetgpnum()); + + lw86x0_read_reg(0x00e6, &read_from_e6, 1); + if(read_from_e6 == 0x3311 || read_from_e6 == 0xa311) + { + INIT_WORK(&phone_status_work, phone_status_listener); + init_timer(&polling_phone_status_timer); + setup_timer(&polling_phone_status_timer, lw86x0_ts_polling_phone_status, (long unsigned int) pdev); + lw86x0_ts_polling_phone_status((long unsigned int) pdev); + } + + register_bl_notifier(&wmt_bl_notify); + + return 0; +exit_register_irq: +#ifdef CONFIG_HAS_EARLYSUSPEND//add by jackie + unregister_early_suspend(&l_tsdata.early_suspend); +#endif + kfree(default_setting_table); +exit_load_cfgfile_failed: + +exit_input_register_device_failed: + input_free_device(l_tsdata.input_dev); +exit_input_dev_alloc_failed: + cancel_work_sync(&l_tsdata.touch_event_work); + destroy_workqueue(l_tsdata.ts_workqueue); +exit_create_singlethread: + return err; +} + +static int lw86x0_ts_remove(struct platform_device *pdev) +{ + kfree(default_setting_table); +#ifdef CONFIG_HAS_EARLYSUSPEND + unregister_early_suspend(&l_tsdata.early_suspend); +#endif + free_irq(wmt_get_tsirqnum(), l_tsdata.input_dev); + input_unregister_device(l_tsdata.input_dev); + flush_workqueue(l_tsdata.ts_workqueue); + cancel_work_sync(&l_tsdata.touch_event_work); + destroy_workqueue(l_tsdata.ts_workqueue); + mutex_destroy(&ts_data_mutex); + del_timer(&polling_phone_status_timer); + unregister_bl_notifier(&wmt_bl_notify); + dbg("remove...\n"); + return 0; +} + + +static int lw86x0_ts_init(void) +{ + dbg("lw86x0_ts_init\n"); + lw86x0_hw_reset(); + return 0; +} + +static void lw86x0_ts_exit(void) +{ + dbg("lw86x0_ts_exit\n"); +} + +struct wmtts_device lw86x0_tsdev = { + .driver_name = "s_lw86x0_ts", + .ts_id = "lw86x0", + .init = lw86x0_ts_init, + .exit = lw86x0_ts_exit, + .probe = lw86x0_ts_probe, + .remove = lw86x0_ts_remove, + .suspend = lw86x0_suspend, + .resume = lw86x0_resume, + .penup = 1, +}; + diff --git a/drivers/input/touchscreen/lw86x0_ts/lw86x0_ts.h b/drivers/input/touchscreen/lw86x0_ts/lw86x0_ts.h new file mode 100755 index 00000000..cc2d9e26 --- /dev/null +++ b/drivers/input/touchscreen/lw86x0_ts/lw86x0_ts.h @@ -0,0 +1,53 @@ +#ifndef _LW86X0_TS_H_ +#define _LW86X0_TS_H_ + +//#include "wmt_custom_lw86x0.h" + +// define byte swap of a WORD +#define swap16(a) ((((a)&0xff)<<8)|(((a)>>8)&0xff)) + +//struct _reg_word for ioctl read or write register +#define LW86X0_NAME "touch_lw86x0" + +#define SUPPORT_FW_UPGRADE +#define TS_KEY_NUM 4 +#define COL_NUM_MAX 28 +#define ROW_NUM_MAX 16 +#define SUPPORT_POINT_NUM_MAX 10 +#define MULTI_DATA_MAX_SIZE 49 + +typedef struct _reg_word +{ + u16 uOffset; + u16 uValue; + u16 multi_data[MULTI_DATA_MAX_SIZE]; + int data_size; +}reg_word; + +//struct _flash_op for ioctl write or read frimware +#define FLASH_XFER_PKT_SIZE 256 +typedef struct _flash_op +{ + u16 startaddr; //=0 if the first pkt + u16 lastpkt; // =1 if last pkt; =0, otherwise + u16 pktlen; //data length in this pkt + char data[FLASH_XFER_PKT_SIZE]; +}flash_op; + +//struct _raw_data for ioctl read cdc/amb/diff data +typedef struct _raw_data +{ + u8 row; + u8 col; + u16 data[COL_NUM_MAX*ROW_NUM_MAX]; +}rawdata; + +extern void wmt_ts_set_keylen(int keylen); +extern void wmt_ts_set_baseaxis(int axis); +extern void wmt_ts_set_keypos(int index, int min,int max); +extern int lw86x0_write_reg(u16 addr, u16 value); +extern int lw86x0_read_reg(u16 addr, u16 *pdata, int regcnt); +extern void getversion(void); +extern void lw86x0_stop_timer(int flags); + +#endif diff --git a/drivers/input/touchscreen/lw86x0_ts/wmt_ts.c b/drivers/input/touchscreen/lw86x0_ts/wmt_ts.c new file mode 100755 index 00000000..505dedfd --- /dev/null +++ b/drivers/input/touchscreen/lw86x0_ts/wmt_ts.c @@ -0,0 +1,1165 @@ +#include <linux/unistd.h> +#include <linux/time.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/init.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/proc_fs.h> +#include <linux/input.h> +#include <linux/types.h> +#include <linux/platform_device.h> +#include <mach/hardware.h> +#include <asm/uaccess.h> +#include <linux/i2c.h>//add +#include "wmt_ts.h" +#include "lw86x0_ts.h" +//#include "wmt_custom_lw86x0.h" + + +struct i2c_client *l_client = NULL; + + + +///////////////////////////////////////////////////////////////// + +// commands for ui +#define TS_IOC_MAGIC 't' +#define LW86X0_READ_REG _IOWR(TS_IOC_MAGIC, 1, int*) +#define LW86X0_WRITE_REG _IOW(TS_IOC_MAGIC, 2, int*) +#define LW86X0_FLASH_DOWNLOAD _IOW(TS_IOC_MAGIC, 3, int *) +#define LW86X0_FLASH_UPLOAD _IOWR(TS_IOC_MAGIC, 4, int *) +#define LW86X0_CTRL_DEBUG_MODE _IOW(TS_IOC_MAGIC, 5, int *) +#define LW86X0_CTRL_RD_DIFF _IOR(TS_IOC_MAGIC, 6, int *) +#define LW86X0_CTRL_RD_CDC _IOR(TS_IOC_MAGIC, 7, int *) +#define LW86X0_CTRL_RD_AMB _IOR(TS_IOC_MAGIC, 8, int *) +#define LW86X0_CTRL_STOP_TIMER _IOR(TS_IOC_MAGIC, 15, int *) +#define TS_IOC_MAXNR 15 + +// +#define TS_MAJOR 11 +#define TS_DRIVER_NAME "wmtts_touch" +#define TS_NAME "wmtts" +#define WMTTS_PROC_NAME "wmtts_config" + +#define LIGHT_ON_WAIT_TIME 5000 // 5s + +#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 + +struct touch_tp_info { + char name[64]; + unsigned 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 struct touch_tp_info l_tp[] = { + {"LW86X0",(0x30>>1), 0, 1, 1}, +}; + +static int irq_gpio; +static int rst_gpio; +static int keyled_gpio = -1; +static int light_level; +static int light_time = 5000; // unit: ms +static int panelres_x; +static int panelres_y; +static int lcd_exchg = 0; +static DECLARE_WAIT_QUEUE_HEAD(queue); +static TS_EVENT g_evLast; +static struct mutex cal_mutex; + +static struct class* l_dev_class = NULL; +static struct device *l_clsdevice = NULL; +extern struct wmtts_device lw86x0_tsdev; +static struct wmtts_device* l_tsdev = &lw86x0_tsdev; +static unsigned char ts_i2c_addr = 0; + +static struct proc_dir_entry* l_tsproc = NULL; +static struct timer_list l_lighttimer; // for shaking +static int l_tskey_btn = 0; // zero to disable touch key, positive to support touch key + +#if 0 +//add +struct tp_infor{ + +char name[64]; +int i2caddr; +int xaxis; +int xdir; +int ydir; +int finger_num; +}; + +//add by jackie +//static int l_tpindex = -1; +static struct tp_infor l_tpinfor[1]; +#endif +///////////////////////////////////////////////////// +// extrenal function +///////////////////////////////////////////////////// +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); + + +char g_dbgmode = 0; +int COL_NUM; +int ROW_NUM; +int SKIP_ZERO_POINT; + +int wmt_ts_get_configfilename(char* fname) +{ + sprintf(fname,"%s.cfg",l_tp[0].name); + return 0; +} + +int wmt_ts_get_firmwfilename(char* fname) +{ + sprintf(fname,"%s_fw.bin",l_tp[0].name); + return 0; +} + +int wmt_ts_get_xaxis(void) +{ + return l_tp[0].xaxis; +} + +int wmt_ts_get_xdir(void) +{ + return l_tp[0].xdir; +} + +int wmt_ts_get_ydir(void) +{ + return l_tp[0].ydir; +} + +int wmt_ts_get_fingernum(void) +{ + return l_tp[0].finger_num; +} + + 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; +} + +int wmt_ts_enable_tskey(void) +{ + return l_tskey_btn; +} + +int wmt_ts_enable_keyled(void) +{ + return (keyled_gpio>=0 ? 1:0); +} + + +static void ts_lighttimer_timeout(unsigned long timeout) +{ + // turn off the light + if (20 == keyled_gpio) + { + if (light_level>=0) + { + REG32_VAL(__GPIO_BASE+0x00F0) &= ~BIT4; // output low + dbg("turn off the light!\n"); + } else { + REG32_VAL(__GPIO_BASE+0x00F0) |= BIT4; // output high + dbg("turn off the light!\n"); + } + } +} + + +static void wmt_ts_init_light(void) +{ + if (20 == keyled_gpio) + { + setup_timer(&l_lighttimer, ts_lighttimer_timeout, 0); + // init gpio20 and turn off light + REG32_VAL(__GPIO_BASE+0x00F0) &= ~BIT4; // output low + REG32_VAL(__GPIO_BASE+0x00B0) |= BIT4; // output enable + REG32_VAL(__GPIO_BASE+0x0070) |= BIT4; // enable gpio + REG32_VAL(__GPIO_BASE+0x04F0) |= BIT4; // pull up + REG32_VAL(__GPIO_BASE+0x04B0) |= BIT4; // enable pull up/down + } +} + +void wmt_ts_turnoff_light(void) +{ + if (20 == keyled_gpio) + { + mod_timer(&l_lighttimer, jiffies + msecs_to_jiffies(light_time)); + } +} + +void wmt_ts_turnon_light(void) +{ + if (20 == keyled_gpio) + { + del_timer(&l_lighttimer); + if (light_level >= 0) + { + REG32_VAL(__GPIO_BASE+0x00F0) |= BIT4; // output high + dbg("turn on the light!\n"); + } else { + REG32_VAL(__GPIO_BASE+0x00F0) &= ~BIT4; // output low + dbg("turn on the light!\n"); + } + } +} + +static void wmt_ts_remove_light(void) +{ + if (20 == keyled_gpio) + { + if (light_level >= 0) + { + REG32_VAL(__GPIO_BASE+0x00F0) &= ~BIT4; // output low + } else { + REG32_VAL(__GPIO_BASE+0x00F0) |= BIT4; // output high + } + del_timer(&l_lighttimer); + } +} + +int wmt_is_tsirq_enable(int num) +{ + int val = 0; + + 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(int num) +{ + if (num > 11) + { + return 0; + } + return (REG32_VAL(__GPIO_BASE+0x0360) & (1<<num)) ? 1: 0; +} + +void wmt_clr_int(int num) +{ + if (num > 11) + { + return; + } + REG32_VAL(__GPIO_BASE+0x0360) = 1<<num; +} + +void wmt_tsreset_init(int num) +{ + REG32_VAL(__GPIO_BASE+0x0040) |= (1<<num);//&= ~(1<<num); //enable gpio + REG32_VAL(__GPIO_BASE+0x00C0) |= (1<<num); // out high + REG32_VAL(__GPIO_BASE+0x0080) |= (1<<num); //output enable + msleep(5); + //REG32_VAL(__GPIO_BASE+0x00C0) |= (1<<num); +} + +// 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 +} + +int wmt_set_irq_mode(unsigned int num, int mode) +{ + if(num >11) + return -1; + REG32_VAL(__GPIO_BASE+0x0040) &= ~(1<<num); //enable gpio + if(mode == 0) + { + REG32_VAL(__GPIO_BASE+0x0080) |= (1<<num); //set output + REG32_VAL(__GPIO_BASE+0x04c0) |= (1<<num); //pull down + REG32_VAL(__GPIO_BASE+0x0480) &= ~(1<<num); //enable pull up/down + } + else if(mode == 1) + REG32_VAL(__GPIO_BASE+0x0080) &= ~(1<<num); //set input + //msleep(5); + return 0; +} + + +int wmt_set_gpirq(unsigned int num, int type) +{ + int shift; + int offset; + unsigned long reg; + + 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 GIRQ_LOW: + reg &= ~(1<<(shift*8+2)); + reg &= ~(1<<(shift*8+1)); + reg &= ~(1<<(shift*8)); + break; + case GIRQ_HIGH: + reg &= ~(1<<(shift*8+2)); + reg &= ~(1<<(shift*8+1)); + reg |= (1<<(shift*8)); + break; + case GIRQ_FALLING: + reg &= ~(1<<(shift*8+2)); + reg |= (1<<(shift*8+1)); + reg &= ~(1<<(shift*8)); + break; + case GIRQ_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(unsigned int num) +{ + 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(unsigned int num) +{ + 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 (wmt_ts_enable_keyled()) + wmt_ts_remove_light(); + if (l_tsdev->suspend !=NULL) + { + return l_tsdev->suspend(pdev, state); + } + return 0; +} +static int wmt_ts_resume(struct platform_device *pdev) +{ + klog("ts resume....\n"); + if (wmt_ts_enable_keyled()) + wmt_ts_init_light(); + if (l_tsdev->resume != NULL) + { + return l_tsdev->resume(pdev); + } + 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; + return ret; +} + +static int wmt_ts_close(struct inode *inode, struct file *filp) +{ + return 0; +} + +static unsigned int wmt_ts_poll(struct file *filp, struct poll_table_struct *wait) +{ + return 0; +} + + +void read_diff(rawdata* pdata) +{ + //u16 Buffer[COL_NUM_MAX*ROW_NUM_MAX*2]; + u16 *Buffer; + u16 idx = 0; + int i,j; + u16 addr =0; + pdata->col = COL_NUM; + pdata->row = ROW_NUM; + Buffer = kzalloc(COL_NUM_MAX*ROW_NUM_MAX*2*2, GFP_KERNEL); + if (!Buffer) { + errlog("mem alloc fail.\n"); + return; + } + for(i=0;i<pdata->row;i++) + { + addr = 0x42f2+i*60; + printk("read_diff: addr=0x%04x\n",addr); + for(j=0;j<pdata->col*2;j++) + { + if(lw86x0_read_reg(addr+j, &Buffer[idx],1)!=0) + { + lw86x0_read_reg(addr+j, &Buffer[idx],1); + } + printk("read_diff: Buffer[%d]=0x%04x\n",idx,Buffer[idx]); + idx++; + } + } + for(i=0; i<pdata->col * pdata->row; i++) + { + pdata->data[i] = ((Buffer[i*2]<<8)&0xff00)|(Buffer[i*2+1]&0x00ff); + printk("read_diff: pdata->data[%d]=0x%04x\n",i,pdata->data[i]); + } + kfree(Buffer); +} + +void read_cdc(rawdata* pdata) +{ + int i,j; + u16 addr = 0x2fc8; + u16 idx = 0; + + pdata->col = COL_NUM; + pdata->row = ROW_NUM; + + for(i=0;i<pdata->col;i++) + { + for(j=0;j<pdata->row;j++) + { + printk("read_cdc: addr=0x%04x\n",addr+idx); + if(lw86x0_read_reg(addr+idx, &pdata->data[j*pdata->col+i],1)!=0) + { + lw86x0_read_reg(addr+idx, &pdata->data[j*pdata->col+i],1); + } + printk("read_cdc: pdata->data[%d]=0x%04x\n",j*pdata->col+i,pdata->data[j*pdata->col+i]); + idx++; + } + } +} + +void read_amb(rawdata* pdata) +{ + int i,j; + u16 addr = 0x2E04; + u16 idx = 0; + + pdata->col = COL_NUM; + pdata->row = ROW_NUM; + + for(i=0;i<pdata->col;i++) + { + for(j=0;j<pdata->row;j++) + { + printk("read_amb: addr=0x%04x\n",addr+idx); + if(lw86x0_read_reg(addr+idx, &pdata->data[j*pdata->col+i],1)!=0) + { + lw86x0_read_reg(addr+idx, &pdata->data[j*pdata->col+i],1); + } + printk("read_amb: pdata->data[%d]=0x%04x\n",j*pdata->col+i,pdata->data[j*pdata->col+i]); + idx++; + } + } + + +} + +void lw86x0_flash_write_prepare(void) +{ + lw86x0_stop_timer(1); + lw86x0_write_reg(0x00e2, 0x0300);//#write_en=1 tmr=1 + udelay(1); + //mass erase + lw86x0_write_reg(0x00e2, 0x0305);//#xe=1 mas1=1 + lw86x0_write_reg(0x00e2, 0x0315);//#erase=1 + udelay(5); + lw86x0_write_reg(0x00e2, 0x0395);//#nvstr=1 + mdelay(20); + lw86x0_write_reg(0x00e2, 0x0385);//#erase=0 + udelay(100); + lw86x0_write_reg(0x00e2, 0x0305);//#nvstr=0 + lw86x0_write_reg(0x00e2, 0x0300);//#xe=0 mas1=0 +} + +void lw86x0_flash_write(u8* pbData,u16 start_addr, u16 num) +{ + u16 yaddr = start_addr; + u16 xaddr = (start_addr)&0xFF80;//x addr is a 8bit address + u16 cnt = 0; + while(cnt<num) + { + while(1) + { + lw86x0_write_reg(0x00e3, xaddr);//#xaddr + lw86x0_write_reg(0x00e2, 0x0304);//#xe=1 + lw86x0_write_reg(0x00e2, 0x0324);//#prog=1 + udelay(5); + lw86x0_write_reg(0x00e2, 0x03a4);//#nvstr=1 + udelay(10); + do + { + u16 data = pbData[cnt]; + lw86x0_write_reg(0x00e3, yaddr);//#yaddr + lw86x0_write_reg(0x00e4, data);//#din + lw86x0_write_reg(0x00e2, 0xfbac);//#ye=0 + lw86x0_write_reg(0x00e2, 0x03a4);//#ye=0 + yaddr++; + cnt++; + if(cnt==num) + { + break; + } + }while(yaddr&0x007F); + xaddr+=0x0080; + udelay(20); + lw86x0_write_reg(0x00e2, 0x0384);//#prog=0 + udelay(100); + lw86x0_write_reg(0x00e2, 0x0304);//#nvstr=0 + lw86x0_write_reg(0x00e2, 0x0300);//#xe=0 + if(cnt==num) + { + break; + } + } + } + +} + +void lw86x0_flash_write_finish(u16 total_len) +{ + //write length of FW to last 2 byte of flash + u8 *pLen = (u8 *)&total_len; + lw86x0_flash_write(&(pLen[1]),0x7FFE, 1); + lw86x0_flash_write(&(pLen[0]),0x7FFF, 1); + + lw86x0_write_reg(0x00e2, 0x0300);//#tmr=1 + lw86x0_write_reg(0x00e2, 0x0200);//#tmr=0 + lw86x0_write_reg(0x00e2, 0x02c0);//#nvstr=1 se=1 + lw86x0_write_reg(0x00e2, 0x02eb);//#prog=1 ifren=1 ye=1 mas=1 + lw86x0_write_reg(0x00e2, 0x03eb);//#tmr=1 + lw86x0_write_reg(0x00e2, 0x02eb);//#tmr=0 + lw86x0_write_reg(0x00e2, 0x02c0);//#prog=0 ifren=0 ye=0 mas=0 + lw86x0_write_reg(0x00e2, 0x0200);//#nvstr=0 se=0 + lw86x0_write_reg(0x00e2, 0x0204);//#xe=1 + lw86x0_write_reg(0x00e2, 0x0214);//#erase=1 + udelay(5); + lw86x0_write_reg(0x00e2, 0x0294);//#nvstr=1 + mdelay(20); + lw86x0_write_reg(0x00e2, 0x0284);//#erase=0 + udelay(5); + lw86x0_write_reg(0x00e2, 0x0204);//#nvstr=0 + lw86x0_write_reg(0x00e2, 0x0200);//#xe=0 + lw86x0_write_reg(0x00e2, 0x0000); + lw86x0_write_reg(0x000c, 0xffff); + lw86x0_stop_timer(0); +} + +void lw86x0_flash_read(u8* pbData, u16 start_addr, u16 num) +{ + lw86x0_stop_timer(1); + u16 cnt; + u16 rd_data = 0; + u8 *buf; + for(cnt=0; cnt<num;cnt++) + { + lw86x0_write_reg(0x00e4, 0x0000);//#read data + lw86x0_write_reg(0x00e2, 0x0300);//#tmr=1 + lw86x0_write_reg(0x00e3, start_addr+cnt); + lw86x0_write_reg(0x00e2, 0x034c);//#se=1 ye=1 xe=1 + lw86x0_write_reg(0x00e2, 0x0300);//#se=1 ye=1 xe=1 + lw86x0_read_reg(0x00e4, &rd_data,1); + buf = (u8 *)&rd_data; + pbData[cnt] = buf[1]; + } + lw86x0_stop_timer(0); +} + + +static long wmt_ts_ioctl(/*struct inode * node,*/ struct file *dev, unsigned int cmd, unsigned long arg) +{ + reg_word regword; + //rawdata rdata; + rawdata *rdata; + flash_op f_pkt;//flash packet + + int ret = 0; + char ch; + rdata = kzalloc(sizeof(rawdata), GFP_KERNEL); + if (!rdata) { + errlog("mem alloc fail.\n"); + return -ENOMEM; + } + + 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 LW86X0_WRITE_REG: + copy_from_user(®word, (reg_word*)arg, sizeof(regword)); + dbg("write reg[%d] word value 0x%x", regword.uOffset, regword.uValue ); + ret = lw86x0_write_reg(regword.uOffset, regword.uValue); + if (ret != 0) + { + dbg("Faied to write reg. ret 0x%x\n",ret); + } + return 0; + case LW86X0_READ_REG: + copy_from_user(®word, (reg_word*)arg, sizeof(regword)); + ret = lw86x0_read_reg(regword.uOffset, ®word.uValue, 1); + if (ret != 0) + { + dbg("Faied to read reg. ret 0x%x\n",ret); + } + else + { + + dbg("read reg[%d]=0x%04x",regword.uOffset, regword.uValue); + } + copy_to_user((unsigned int*)arg, ®word, sizeof(regword)); + return 0; + case LW86X0_CTRL_DEBUG_MODE: + copy_from_user(&ch, (char*)arg, sizeof(char)); + printk("LW86X0_CTRL_DEBUG_MODE,%c", ch); + if(ch=='1') + { + g_dbgmode = 1; + wmt_disable_gpirq(irq_gpio); + } + else + { + g_dbgmode = 0; + wmt_enable_gpirq(irq_gpio); + } + return 0; + /* + case LW86X0_CTRL_RD_DIFF: + copy_from_user(&rdata, (rawdata*)arg, sizeof(rdata)); + printk("tpd-ioctrl: LW86X0_CTRL_RD_DIFF\n"); + read_diff(&rdata); + copy_to_user((unsigned int*)arg, &rdata, sizeof(rdata)); + return 0; + case LW86X0_CTRL_RD_CDC: + copy_from_user(&rdata, (rawdata*)arg, sizeof(rdata)); + printk("tpd-ioctrl: LW86X0_CTRL_RD_CDC\n"); + read_cdc(&rdata); + copy_to_user((unsigned int*)arg, &rdata, sizeof(rdata)); + return 0; + case LW86X0_CTRL_RD_AMB: + copy_from_user(&rdata, (rawdata*)arg, sizeof(rdata)); + printk("tpd-ioctrl: LW86X0_CTRL_RD_AMB\n"); + read_amb(&rdata); + copy_to_user((unsigned int*)arg, &rdata, sizeof(rdata)); + return 0; + */ + case LW86X0_CTRL_RD_DIFF: + copy_from_user(rdata, (rawdata*)arg, sizeof(*rdata)); + printk("tpd-ioctrl: LW86X0_CTRL_RD_DIFF\n"); + read_diff(rdata); + copy_to_user((unsigned int*)arg, rdata, sizeof(*rdata)); + return 0; + case LW86X0_CTRL_RD_CDC: + copy_from_user(rdata, (rawdata*)arg, sizeof(*rdata)); + printk("tpd-ioctrl: LW86X0_CTRL_RD_CDC\n"); + read_cdc(rdata); + copy_to_user((unsigned int*)arg, rdata, sizeof(*rdata)); + return 0; + case LW86X0_CTRL_RD_AMB: + copy_from_user(rdata, (rawdata*)arg, sizeof(*rdata)); + printk("tpd-ioctrl: LW86X0_CTRL_RD_AMB\n"); + read_amb(rdata); + copy_to_user((unsigned int*)arg, rdata, sizeof(*rdata)); + return 0; + case LW86X0_FLASH_DOWNLOAD: + copy_from_user(&f_pkt, (flash_op*)arg, sizeof(f_pkt)); + if(f_pkt.startaddr==0) + { + lw86x0_flash_write_prepare(); + } + lw86x0_flash_write(f_pkt.data, + f_pkt.startaddr, + f_pkt.pktlen); + printk("dnload: start addr = %04x\n",f_pkt.startaddr); + if(f_pkt.lastpkt==1) + { + u16 write_len = f_pkt.startaddr + f_pkt.pktlen; + lw86x0_flash_write_finish(write_len); + } + return 0; + case LW86X0_FLASH_UPLOAD: + copy_from_user(&f_pkt, (flash_op*)arg, sizeof(f_pkt)); + lw86x0_flash_read(f_pkt.data, f_pkt.startaddr, f_pkt.pktlen); + printk("upload: start addr = %04x\n",f_pkt.startaddr); + printk("\n"); + copy_to_user((int*)arg, &f_pkt, sizeof(f_pkt)); + return 0; + case LW86X0_CTRL_STOP_TIMER: + copy_from_user(&ch, (char*)arg, sizeof(char)); + if(ch == '1') + lw86x0_stop_timer(1); + else + lw86x0_stop_timer(0); + return 0; + } + kfree(rdata); + return -EINVAL; +} + +static ssize_t wmt_ts_read(struct file *filp, char *buf, size_t count, loff_t *l) +{ + 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, "out=%d\n", &val)) + { + switch(val) + { + case 1: // reset1 + REG32_VAL(__GPIO_BASE+0x0040) |= (1<<irq_gpio); //enable gpio + REG32_VAL(__GPIO_BASE+0x00C0) |= (1<<irq_gpio); //out high + REG32_VAL(__GPIO_BASE+0x0080) |= (1<<irq_gpio); //set input + break; + case 0: // reset2 + REG32_VAL(__GPIO_BASE+0x0040) |= (1<<irq_gpio); //enable gpio + REG32_VAL(__GPIO_BASE+0x00C0) &= ~(1<<irq_gpio); //out high + REG32_VAL(__GPIO_BASE+0x0080) |= (1<<irq_gpio); //set input + break; + default: + break; + }; + } + 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; +} + +unsigned char wmt_ts_get_i2caddr(void) +{ + return ts_i2c_addr; +} + +static int wmt_check_touch_env(void) +{ + int ret = 0; + int len = 127; + char retval[128] = {0},*p=NULL,*s=NULL; + int Enable=0; + + // Get u-boot parameter + ret = wmt_getsyspara("wmt.io.touch", retval, &len); + if(ret){ + errlog("Read wmt.io.touch Failed.\n"); + return -EIO; + } + + //check touch enable + p = retval; + sscanf(p,"%d:", &Enable); + if(Enable == 0){ + errlog("Touch Screen Is Disabled.\n"); + return -ENODEV; + } + + //check touch IC name + p = strchr(p,':');p++; + if (strncmp(p, l_tp[0].name, strlen(l_tp[0].name))) { + errlog("Can't find %s!\n", l_tp[0].name); + return -ENODEV; + } + + //get firmware file name + s = strchr(p,':'); + memset(l_tp[0].name,0x00,sizeof(l_tp[0].name)); + strncpy(l_tp[0].name, p, (s-p)); + dbg("ts_fwname=%s\n", l_tp[0].name); + + p = s + 1; + ret = sscanf(p,"%d:%d:%d:%d:%d:%d:%d:%d:%x", + &irq_gpio,&panelres_x,&panelres_y,&rst_gpio, + &(l_tp[0].xaxis),&(l_tp[0].xdir),&(l_tp[0].ydir), + &(l_tp[0].finger_num),&(l_tp[0].i2caddr)); + + dbg("%d;%d;%d;%d;%d;%d;%d;%d;%x;",irq_gpio,panelres_x,panelres_y,rst_gpio, + (l_tp[0].xaxis),(l_tp[0].xdir),(l_tp[0].ydir), + (l_tp[0].finger_num),(l_tp[0].i2caddr)); + + 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; + } + + return 0; +} +//#if 0 +//add by jackie i2c_board_info +struct i2c_board_info ts_i2c_board_info = { + .type = WMT_TS_I2C_NAME, + .flags = 0x00, + //.addr = 0x18, //WMT_TS_I2C_ADDR,//why error? + .platform_data = NULL, + .archdata = NULL, + .irq = -1, +}; +//add jackie 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_tp[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; +} +//add by jackie +struct i2c_client* ts_get_i2c_client(void) +{ + return l_client; +} +//add +static int __init wmt_ts_init(void) +{ + int ret = 0; + + if(wmt_check_touch_env()) + return -ENODEV; + +//add by jackie + 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){ + printk(KERN_ERR "Errors to init %s ts IC!!!\n", l_tsdev->ts_id); + return -1; + } + if (wmt_ts_enable_keyled()) + wmt_ts_init_light(); + // 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("wmt ts driver init ok!\n"); + return ret; +} + +//add by jackie +static void ts_i2c_unregister_device(void) +{ + if (l_client != NULL) + { + i2c_unregister_device(l_client); + l_client = NULL; + } +} +//add end + +static void __exit wmt_ts_exit(void) +{ + dbg("%s\n",__FUNCTION__); + + if (wmt_ts_enable_keyled()) + wmt_ts_remove_light(); + l_tsdev->exit(); + mutex_destroy(&cal_mutex); + 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); + ts_i2c_unregister_device(); +} + + +module_init(wmt_ts_init); +module_exit(wmt_ts_exit); + +MODULE_LICENSE("GPL"); + diff --git a/drivers/input/touchscreen/lw86x0_ts/wmt_ts.h b/drivers/input/touchscreen/lw86x0_ts/wmt_ts.h new file mode 100755 index 00000000..ff1218ac --- /dev/null +++ b/drivers/input/touchscreen/lw86x0_ts/wmt_ts.h @@ -0,0 +1,98 @@ + +#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> + +//#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 (wmt_ts_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 DONOTHING 0xff + +#define WMT_TS_I2C_NAME "lw86x0-ts" +//////////////////////////////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_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(unsigned int num, int type); +extern int wmt_get_tsirqnum(void); +extern int wmt_disable_gpirq(unsigned int num); +extern int wmt_enable_gpirq(unsigned int num); +extern int wmt_is_tsirq_enable(int num); +extern void wmt_enable_rst_pull(int enable); +extern void wmt_set_rst_pull(int up); +extern void wmt_rst_output(int high); +void wmt_rst_input(void); +extern int wmt_is_tsint(int num); +extern void wmt_clr_int(int num); +extern void wmt_tsreset_init(int num); +extern int wmt_ts_get_resetgpnum(void); +extern int wmt_ts_get_lcdexchg(void); +extern unsigned char wmt_ts_get_i2caddr(void); +extern void wmt_ts_turnoff_light(void); +extern void wmt_ts_turnon_light(void); +extern int wmt_ts_enable_tskey(void); +extern int wmt_ts_get_configfilename(char* fname); +extern int wmt_ts_get_firmwfilename(char* fname); +extern int wmt_ts_get_xaxis(void); +extern int wmt_ts_get_xdir(void); +extern int wmt_ts_get_ydir(void); +extern int wmt_ts_get_fingernum(void); +extern int wmt_ts_enable_keyled(void); +extern int wmt_set_irq_mode(unsigned int num, int mode); +extern int wmt_disable_gpirq(unsigned int num); +extern int wmt_enable_gpirq(unsigned int num); +extern int ts_i2c_register_device (void); +extern struct i2c_client* ts_get_i2c_client(void); + +extern void lw86x0_flash_write_prepare(void); +extern void lw86x0_flash_read(u8* pbData, u16 start_addr, u16 num); +extern void lw86x0_flash_write(u8* pbData,u16 start_addr, u16 num); +extern void lw86x0_flash_write_finish(u16 total_len); +#endif + + + |