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