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