ts: rk29_i2c_goodix: porting to 3.10
[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 #ifdef CONFIG_HAS_EARLYSUSPEND
22 #include <linux/earlysuspend.h>
23 #endif
24 #include <linux/hrtimer.h>
25 #include <linux/i2c.h>
26 #include <linux/input.h>
27
28 //*************************TouchScreen Work Part*****************************
29
30 #define GOODIX_I2C_NAME "Goodix-TS"
31 #define TS_MAX_X        CONFIG_TOUCH_MAX_X
32 #define TS_MAX_Y        CONFIG_TOUCH_MAX_Y
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 press;  
65         u32 x ;
66         u32 y ;
67         int status ; // 0 1
68 } ;
69 struct rk_ts_data{
70         struct i2c_client *client;
71         struct input_dev *input_dev;
72         int irq;
73         int irq_pin;
74         int pwr_pin;
75         int rst_pin;
76         int rst_val;
77         int read_mode;                                  //read moudle mode,20110221 by andrew
78         char phys[32];
79 #ifdef CONFIG_HAS_EARLYSUSPEND
80         struct early_suspend early_suspend;
81 #endif
82         int (*power)(struct rk_ts_data * ts, int on);
83         int (*ts_init)(struct rk_ts_data*ts);
84         int (*input_parms_init)(struct rk_ts_data *ts);
85         void (*get_touch_info)(struct rk_ts_data *ts,char *point_num,struct rk_touch_info *info_buf);  //get touch data info
86         uint16_t abs_x_max;
87         uint16_t abs_y_max;
88         uint8_t max_touch_num;
89         bool            pendown;
90         struct rk_touch_info *info_buf;
91 };
92
93
94
95 struct goodix_ts_data {
96         uint16_t addr;
97         uint8_t bad_data;
98         struct i2c_client *client;
99         struct input_dev *input_dev;
100         int use_reset;          //use RESET flag
101         int use_irq;            //use EINT flag
102         int read_mode;          //read moudle mode,20110221 by andrew
103         struct hrtimer timer;
104         struct delayed_work  work;
105         char phys[32];
106         int retry;
107 #ifdef CONFIG_HAS_EARLYSUSPEND
108         struct early_suspend early_suspend;
109 #endif
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 struct i2c_client * i2c_connect_client = NULL; 
120 static struct proc_dir_entry *goodix_proc_entry;
121 //static struct kobject *goodix_debug_kobj;
122         
123
124 #define READ_COOR_ADDR 0x01
125
126 //*****************************End of Part I *********************************
127
128 //*************************Touchkey Surpport Part*****************************
129 //#define HAVE_TOUCH_KEY
130 #ifdef HAVE_TOUCH_KEY
131         #define READ_COOR_ADDR 0x00
132         const uint16_t touch_key_array[]={
133                                                                           KEY_MENU,                             //MENU
134                                                                           KEY_HOME,                             //HOME
135                                                                           KEY_SEND                              //CALL
136                                                                          }; 
137         #define MAX_KEY_NUM      (sizeof(touch_key_array)/sizeof(touch_key_array[0]))
138 #else
139         #define READ_COOR_ADDR 0x01
140 #endif
141 //*****************************End of Part II*********************************
142 #if 1
143 //*************************Firmware Update part*******************************
144 //#define CONFIG_TOUCHSCREEN_GOODIX_IAP
145 #ifdef CONFIG_TOUCHSCREEN_GOODIX_IAP
146 #define UPDATE_NEW_PROTOCOL
147
148 unsigned int oldcrc32 = 0xFFFFFFFF;
149 unsigned int crc32_table[256];
150 unsigned int ulPolynomial = 0x04c11db7;
151 unsigned char rd_cfg_addr;
152 unsigned char rd_cfg_len;
153 unsigned char g_enter_isp = 0;
154
155 static int goodix_update_write(struct file *filp, const char __user *buff, unsigned long len, void *data);
156 static int goodix_update_read( char *page, char **start, off_t off, int count, int *eof, void *data );
157
158 #define PACK_SIZE                                       64                                      //update file package size
159 #define MAX_TIMEOUT                                     60000                           //update time out conut
160 #define MAX_I2C_RETRIES                         20                                      //i2c retry times
161
162 //I2C buf address
163 #define ADDR_CMD                                        80
164 #define ADDR_STA                                        81
165 #ifdef UPDATE_NEW_PROTOCOL
166         #define ADDR_DAT                                0
167 #else
168         #define ADDR_DAT                                82
169 #endif
170
171 //moudle state
172 #define NEW_UPDATE_START                        0x01
173 #define UPDATE_START                            0x02
174 #define SLAVE_READY                                     0x08
175 #define UNKNOWN_ERROR                           0x00
176 #define FRAME_ERROR                                     0x10
177 #define CHECKSUM_ERROR                          0x20
178 #define TRANSLATE_ERROR                         0x40
179 #define FLASH_ERROR                                     0X80
180
181 //error no
182 #define ERROR_NO_FILE                           2       //ENOENT
183 #define ERROR_FILE_READ                         23      //ENFILE
184 #define ERROR_FILE_TYPE                         21      //EISDIR
185 #define ERROR_GPIO_REQUEST                      4       //EINTR
186 #define ERROR_I2C_TRANSFER                      5       //EIO
187 #define ERROR_NO_RESPONSE                       16      //EBUSY
188 #define ERROR_TIMEOUT                           110     //ETIMEDOUT
189
190 //update steps
191 #define STEP_SET_PATH              1
192 #define STEP_CHECK_FILE            2
193 #define STEP_WRITE_SYN             3
194 #define STEP_WAIT_SYN              4
195 #define STEP_WRITE_LENGTH          5
196 #define STEP_WAIT_READY            6
197 #define STEP_WRITE_DATA            7
198 #define STEP_READ_STATUS           8
199 #define FUN_CLR_VAL                9
200 #define FUN_CMD                    10
201 #define FUN_WRITE_CONFIG           11
202
203 //fun cmd
204 #define CMD_DISABLE_TP             0
205 #define CMD_ENABLE_TP              1
206 #define CMD_READ_VER               2
207 #define CMD_READ_RAW               3
208 #define CMD_READ_DIF               4
209 #define CMD_READ_CFG               5
210 #define CMD_SYS_REBOOT             101
211
212 //read mode
213 #define MODE_RD_VER                1
214 #define MODE_RD_RAW                2
215 #define MODE_RD_DIF                3
216 #define MODE_RD_CFG                4
217
218
219 #endif
220 //*****************************End of Part III********************************
221 #endif
222 struct goodix_i2c_platform_data {
223         uint32_t version;       /* Use this entry for panels with */
224         //reservation
225 };
226
227 #endif /* _LINUX_GOODIX_TOUCH_H */