Merge remote-tracking branch 'aosp/android-3.0' into develop-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / input / touchscreen / rk29_i2c_goodix.h
1 /*
2  * include/linux/goodix_touch.h
3  *
4  * Copyright (C) 2010 - 2011 Goodix, Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  *
16  */
17
18 #ifndef         _LINUX_GOODIX_TOUCH_H
19 #define         _LINUX_GOODIX_TOUCH_H
20
21 #include <linux/earlysuspend.h>
22 #include <linux/hrtimer.h>
23 #include <linux/i2c.h>
24 #include <linux/input.h>
25
26 //*************************TouchScreen Work Part*****************************
27
28 #define GOODIX_I2C_NAME "Goodix-TS"
29 #define GOODIX_1024X768  1
30
31 #define TS_MAX_X        1024                    
32 #define TS_MAX_Y                768
33
34 #if 1
35 #define INT_PORT                RK29_PIN0_PA2                                                   
36 #ifdef INT_PORT
37         #define TS_INT          gpio_to_irq(INT_PORT)                   
38 //      #define INT_CFG         S3C_GPIO_SFN(2)                                 //IO configer as EINT
39 #else
40         #define TS_INT  0
41 #endif  
42
43 //whether need send cfg?
44 //#define DRIVER_SEND_CFG
45
46 //set trigger mode
47 #define INT_TRIGGER                     0
48
49 #endif
50
51 #define POLL_TIME               10      //actual query spacing interval:POLL_TIME+6
52
53 #define GOODIX_MULTI_TOUCH
54 #ifdef GOODIX_MULTI_TOUCH
55         #define MAX_FINGER_NUM   10
56 #else
57         #define MAX_FINGER_NUM   1
58 #endif
59
60 //#define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0)
61
62 struct rk_touch_info
63 {
64         u32 status;   // 1:down,0:up
65         u32 x ;
66         u32 y ;
67 } ;
68 struct rk_ts_data{
69         uint16_t addr;
70         uint8_t bad_data;
71         struct i2c_client *client;
72         struct input_dev *input_dev;
73         int use_reset;                                  //use RESET flag
74         int use_irq;                                    //use EINT flag
75         int irq;
76         int irq_pin;
77         int read_mode;                                  //read moudle mode,20110221 by andrew
78         struct hrtimer timer;
79         struct workqueue_struct *ts_wq;
80         struct delayed_work  ts_work;
81         char phys[32];
82         int retry;
83         struct early_suspend early_suspend;
84         int (*power)(struct rk_ts_data * ts, int on);
85         int (*ts_init)(struct rk_ts_data*ts);
86         int (*input_parms_init)(struct rk_ts_data *ts);
87         void (*get_touch_info)(struct rk_ts_data *ts,char *point_num,struct rk_touch_info *info_buf);  //get touch data info
88         uint16_t abs_x_max;
89         uint16_t abs_y_max;
90         uint8_t max_touch_num;
91         uint8_t int_trigger_type;
92         bool            pendown;
93 };
94
95
96
97 struct goodix_ts_data {
98         uint16_t addr;
99         uint8_t bad_data;
100         struct i2c_client *client;
101         struct input_dev *input_dev;
102         int use_reset;          //use RESET flag
103         int use_irq;            //use EINT flag
104         int read_mode;          //read moudle mode,20110221 by andrew
105         struct hrtimer timer;
106         struct delayed_work  work;
107         char phys[32];
108         int retry;
109         struct early_suspend early_suspend;
110         int (*power)(struct goodix_ts_data * ts, int on);
111         uint16_t abs_x_max;
112         uint16_t abs_y_max;
113         uint8_t max_touch_num;
114         uint8_t int_trigger_type;
115         bool            pendown;
116 };
117
118 static const char *rk_ts_name = "Goodix Capacitive TouchScreen";
119 static struct workqueue_struct *goodix_wq;
120 struct i2c_client * i2c_connect_client = NULL; 
121 static struct proc_dir_entry *goodix_proc_entry;
122 //static struct kobject *goodix_debug_kobj;
123         
124 #ifdef CONFIG_HAS_EARLYSUSPEND
125 static void goodix_ts_early_suspend(struct early_suspend *h);
126 static void goodix_ts_late_resume(struct early_suspend *h);
127 #endif 
128
129 #define READ_COOR_ADDR 0x01
130
131 //*****************************End of Part I *********************************
132
133 //*************************Touchkey Surpport Part*****************************
134 //#define HAVE_TOUCH_KEY
135 #ifdef HAVE_TOUCH_KEY
136         #define READ_COOR_ADDR 0x00
137         const uint16_t touch_key_array[]={
138                                                                           KEY_MENU,                             //MENU
139                                                                           KEY_HOME,                             //HOME
140                                                                           KEY_SEND                              //CALL
141                                                                          }; 
142         #define MAX_KEY_NUM      (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
143 #else
144         #define READ_COOR_ADDR 0x01
145 #endif
146 //*****************************End of Part II*********************************
147 #if 1
148 //*************************Firmware Update part*******************************
149 #define CONFIG_TOUCHSCREEN_GOODIX_IAP
150 #ifdef CONFIG_TOUCHSCREEN_GOODIX_IAP
151 #define UPDATE_NEW_PROTOCOL
152
153 unsigned int oldcrc32 = 0xFFFFFFFF;
154 unsigned int crc32_table[256];
155 unsigned int ulPolynomial = 0x04c11db7;
156 unsigned char rd_cfg_addr;
157 unsigned char rd_cfg_len;
158 unsigned char g_enter_isp = 0;
159
160 static int goodix_update_write(struct file *filp, const char __user *buff, unsigned long len, void *data);
161 static int goodix_update_read( char *page, char **start, off_t off, int count, int *eof, void *data );
162
163 #define PACK_SIZE                                       64                                      //update file package size
164 #define MAX_TIMEOUT                                     60000                           //update time out conut
165 #define MAX_I2C_RETRIES                         20                                      //i2c retry times
166
167 //I2C buf address
168 #define ADDR_CMD                                        80
169 #define ADDR_STA                                        81
170 #ifdef UPDATE_NEW_PROTOCOL
171         #define ADDR_DAT                                0
172 #else
173         #define ADDR_DAT                                82
174 #endif
175
176 //moudle state
177 #define NEW_UPDATE_START                        0x01
178 #define UPDATE_START                            0x02
179 #define SLAVE_READY                                     0x08
180 #define UNKNOWN_ERROR                           0x00
181 #define FRAME_ERROR                                     0x10
182 #define CHECKSUM_ERROR                          0x20
183 #define TRANSLATE_ERROR                         0x40
184 #define FLASH_ERROR                                     0X80
185
186 //error no
187 #define ERROR_NO_FILE                           2       //ENOENT
188 #define ERROR_FILE_READ                         23      //ENFILE
189 #define ERROR_FILE_TYPE                         21      //EISDIR
190 #define ERROR_GPIO_REQUEST                      4       //EINTR
191 #define ERROR_I2C_TRANSFER                      5       //EIO
192 #define ERROR_NO_RESPONSE                       16      //EBUSY
193 #define ERROR_TIMEOUT                           110     //ETIMEDOUT
194
195 //update steps
196 #define STEP_SET_PATH              1
197 #define STEP_CHECK_FILE            2
198 #define STEP_WRITE_SYN             3
199 #define STEP_WAIT_SYN              4
200 #define STEP_WRITE_LENGTH          5
201 #define STEP_WAIT_READY            6
202 #define STEP_WRITE_DATA            7
203 #define STEP_READ_STATUS           8
204 #define FUN_CLR_VAL                9
205 #define FUN_CMD                    10
206 #define FUN_WRITE_CONFIG           11
207
208 //fun cmd
209 #define CMD_DISABLE_TP             0
210 #define CMD_ENABLE_TP              1
211 #define CMD_READ_VER               2
212 #define CMD_READ_RAW               3
213 #define CMD_READ_DIF               4
214 #define CMD_READ_CFG               5
215 #define CMD_SYS_REBOOT             101
216
217 //read mode
218 #define MODE_RD_VER                1
219 #define MODE_RD_RAW                2
220 #define MODE_RD_DIF                3
221 #define MODE_RD_CFG                4
222
223
224 #endif
225 //*****************************End of Part III********************************
226 #endif
227 struct goodix_i2c_platform_data {
228         uint32_t version;       /* Use this entry for panels with */
229         //reservation
230 };
231
232 #endif /* _LINUX_GOODIX_TOUCH_H */