input: vtl_ts: fix compilation warning
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / vtl_ts / apk.c
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/slab.h>
4 #include <linux/proc_fs.h>
5 #include <linux/fs.h>
6 #include <linux/uaccess.h>
7 #include <linux/i2c.h>
8 #include <linux/interrupt.h>
9
10 #include "vtl_ts.h"
11 #include "chip.h"
12
13 #define         APK_ITOUCH                      0x01
14
15 #define         INVALID                         0x00
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
27
28
29 #define         LINUX_SHELL                     'c'
30 #define         SHELL_CHECKSUM_CMD              '1'
31 #define         SHELL_UPDATE_CMD                '2'
32 #define         SHELL_DEBUG_CMD                 '3'
33
34
35
36 static struct ts_info * ts_object = NULL;
37
38 /*****************************************************************************
39 ** Function define
40 *****************************************************************************/
41 static int apk_i2c_transfer(struct i2c_client *client,unsigned char i2c_addr,unsigned char len,unsigned char *buf,unsigned char rw)
42 {
43         struct i2c_msg msgs[1];
44         
45         DEBUG();
46         
47         msgs[0].flags = rw;
48         msgs[0].addr  = i2c_addr;
49         msgs[0].len   = len;
50         msgs[0].buf   = buf;
51         msgs[0].scl_rate = TS_I2C_SPEED;                //only for rockchip
52         
53         if(i2c_transfer(client->adapter, msgs, 1)!= 1)
54         {
55                 return -1;
56         }       
57         return 0;
58 }
59
60
61
62 static int apk_open(struct inode *inode, struct file *file)
63 {
64         printk("___%s___\n",__func__);
65         DEBUG();
66
67         ts_object = vtl_ts_get_object();        
68         if(ts_object == NULL)
69         {
70                 return -1;
71         }
72         return 0;
73 }
74
75 static int apk_close(struct inode *inode, struct file *file)
76 {
77         printk("___%s___\n",__func__);
78         DEBUG();
79
80         return 0;
81 }
82 static ssize_t apk_write(struct file *file, const char __user *buff, size_t count, loff_t *offp)
83 {
84         struct i2c_client *client = ts_object->driver->client;  
85         unsigned char frame_data[255] = {0};
86         int bin_checksum = 0;
87         int fw_checksum = 0;
88         int ret = 0;
89
90         DEBUG();
91         
92         if(copy_from_user(frame_data, buff, count)){
93                 return -EFAULT;
94         }
95         
96         if(frame_data[0]==APK_ITOUCH){
97                 
98                 switch(frame_data[1]){
99                         
100                         case    HW_RESET_CMD :{
101                                         vtl_ts_hw_reset();                                                      
102                                 }break;
103
104                         case    INTERRUPT_CMD :{
105                                         if(frame_data[4]){
106                                                 enable_irq(ts_object->config_info.irq_number);
107                                         }else{
108                                                 disable_irq(ts_object->config_info.irq_number);
109                                         }                                               
110                                 }break;
111
112                         case    RECOVERY_CMD :{         
113                                         ret = update(client);                   
114                                 }break;
115                                                                         
116                         case    WRITE_CHIP_CMD:{                                        
117                                         ret = apk_i2c_transfer(client,frame_data[2],frame_data[3],&frame_data[4],0);    
118                                 }break;
119
120                         case    XY_DEBUG_CMD :{ 
121                                         if(ts_object->debug){
122                                                 ts_object->debug = 0x00;
123                                         }else{
124                                                 ts_object->debug = 0x01;
125                                         }                               
126                                 }break;
127                         
128                         default :{
129                                 
130                                 }break;
131                 }
132         }else if(frame_data[0]==LINUX_SHELL){
133                 printk("CMD: %s,count = %zu\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);
138                                 }break;
139
140                         case    SHELL_UPDATE_CMD :{             
141                                         chip_update(client);                    
142                                 }break;
143
144                         case    SHELL_DEBUG_CMD :{
145                                         if(ts_object->debug){
146                                                 ts_object->debug = 0x00;
147                                         }else{
148                                                 ts_object->debug = 0x01;
149                                         }               
150                                                                 
151                                 }break;
152
153                         default :{
154                                         
155                                 }break;
156                 }
157         }else{
158                 return -1;
159         }
160         if(ret<0){
161                 return -1;      
162         }
163
164         return count;
165 }
166
167 static ssize_t apk_read(struct file *file, char __user *buff, size_t count, loff_t *offp)
168 {
169         struct i2c_client *client = ts_object->driver->client;
170         unsigned char frame_data[255];
171         int bin_checksum = 0;
172         int fw_checksum = 0;
173         int len = 0;
174         int ret = 0;
175
176         DEBUG();
177         if(copy_from_user(frame_data, buff, count))
178         {
179                 return -EFAULT;
180         }
181
182         len = frame_data[3];
183         if(frame_data[0]==APK_ITOUCH){
184                 
185                 switch(frame_data[1]){
186                         case    DRIVER_INFO_CMD :{
187                                         frame_data[0] = client->addr;
188                                 }break;
189                                                                         
190                         case    READ_CHIP_CMD :{
191                                         
192                                         ret = apk_i2c_transfer(client,frame_data[2],frame_data[3],frame_data,1);
193                                 }break;
194
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;
201                                 }break;
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;
206                                 }break;
207                         
208                         default :{
209                                         
210                                 }break;
211                 }
212         }
213
214         if(copy_to_user(buff, frame_data,len)){
215                 return -EFAULT; 
216         };      
217         if(ret<0){
218                 return -1;      
219         }
220         
221         return count;
222 }
223
224 struct file_operations apk_fops = {
225         .owner   = THIS_MODULE,
226         .open    = apk_open,
227         .release = apk_close,
228         .write   = apk_write,
229         .read    = apk_read,
230 };
231