1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/slab.h>
4 #include <linux/proc_fs.h>
6 #include <linux/uaccess.h>
8 #include <linux/interrupt.h>
13 #define APK_ITOUCH 0x01
16 #define HW_RESET_CMD 0x01
17 #define CHIP_INFO_CMD 0x02
18 #define DRIVER_INFO_CMD 0x03
19 #define CHIP_ID_CMD 0x04
20 #define WRITE_CHIP_CMD 0x05
21 #define READ_CHIP_CMD 0x06
22 #define RECOVERY_CMD 0x07
23 #define INTERRUPT_CMD 0x08
24 #define READ_CHECKSUM_CMD 0x09
25 #define READ_FWCHECKSUM_CMD 0x0a
26 #define XY_DEBUG_CMD 0x0b
29 #define LINUX_SHELL 'c'
30 #define SHELL_CHECKSUM_CMD '1'
31 #define SHELL_UPDATE_CMD '2'
32 #define SHELL_DEBUG_CMD '3'
36 static struct ts_info * ts_object = NULL;
38 /*****************************************************************************
40 *****************************************************************************/
41 static int apk_i2c_transfer(struct i2c_client *client,unsigned char i2c_addr,unsigned char len,unsigned char *buf,unsigned char rw)
43 struct i2c_msg msgs[1];
48 msgs[0].addr = i2c_addr;
51 msgs[0].scl_rate = TS_I2C_SPEED; //only for rockchip
53 if(i2c_transfer(client->adapter, msgs, 1)!= 1)
62 static int apk_open(struct inode *inode, struct file *file)
64 printk("___%s___\n",__func__);
67 ts_object = vtl_ts_get_object();
75 static int apk_close(struct inode *inode, struct file *file)
77 printk("___%s___\n",__func__);
82 static int apk_write(struct file *file, const char __user *buff, size_t count, loff_t *offp)
84 struct i2c_client *client = ts_object->driver->client;
85 unsigned char frame_data[255] = {0};
92 if(copy_from_user(frame_data, buff, count)){
96 if(frame_data[0]==APK_ITOUCH){
98 switch(frame_data[1]){
104 case INTERRUPT_CMD :{
106 enable_irq(ts_object->config_info.irq_number);
108 disable_irq(ts_object->config_info.irq_number);
113 ret = update(client);
116 case WRITE_CHIP_CMD:{
117 ret = apk_i2c_transfer(client,frame_data[2],frame_data[3],&frame_data[4],0);
121 if(ts_object->debug){
122 ts_object->debug = 0x00;
124 ts_object->debug = 0x01;
132 }else if(frame_data[0]==LINUX_SHELL){
133 printk("CMD: %s,count = %d\n",frame_data,count);
134 switch(frame_data[1]){
135 case SHELL_CHECKSUM_CMD :{
136 chip_get_checksum(client,&bin_checksum,&fw_checksum);
137 printk("bin_checksum = 0x%x,fw_checksum = 0x%x\n",bin_checksum,fw_checksum);
140 case SHELL_UPDATE_CMD :{
144 case SHELL_DEBUG_CMD :{
145 if(ts_object->debug){
146 ts_object->debug = 0x00;
148 ts_object->debug = 0x01;
167 static int apk_read(struct file *file, char __user *buff, size_t count, loff_t *offp)
169 struct i2c_client *client = ts_object->driver->client;
170 unsigned char frame_data[255];
171 int bin_checksum = 0;
177 if(copy_from_user(frame_data, buff, count))
183 if(frame_data[0]==APK_ITOUCH){
185 switch(frame_data[1]){
186 case DRIVER_INFO_CMD :{
187 frame_data[0] = client->addr;
190 case READ_CHIP_CMD :{
192 ret = apk_i2c_transfer(client,frame_data[2],frame_data[3],frame_data,1);
195 case READ_CHECKSUM_CMD :{
196 ret = chip_get_checksum(client,&bin_checksum,&fw_checksum);
197 frame_data[0] = bin_checksum & 0x00ff;
198 frame_data[1] = bin_checksum >> 8;
199 frame_data[2] = fw_checksum & 0x00ff;
200 frame_data[3] = fw_checksum >> 8;
202 case READ_FWCHECKSUM_CMD :{
203 ret = chip_get_fwchksum(client,&fw_checksum);
204 frame_data[0] = fw_checksum & 0x00ff;
205 frame_data[1] = fw_checksum >> 8;
214 if(copy_to_user(buff, frame_data,len)){
224 struct file_operations apk_fops = {
225 .owner = THIS_MODULE,
227 .release = apk_close,