Wang Yafei | fa2e93e | 2018-07-03 17:30:32 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Goodix GT9xx touchscreen driver |
| 3 | * |
| 4 | * Copyright (C) 2016 - 2017 Goodix. Ltd. |
| 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 a reference |
| 12 | * to you, when you are integrating the GOODiX's CTP IC into your system, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * Version: 2.8.0.2 |
| 18 | * Release Date: 2017/12/14 |
| 19 | */ |
| 20 | |
| 21 | #ifndef _GOODIX_GT9XX_H_ |
| 22 | #define _GOODIX_GT9XX_H_ |
| 23 | |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/hrtimer.h> |
| 26 | #include <linux/i2c.h> |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <linux/i2c.h> |
| 31 | #include <linux/proc_fs.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/uaccess.h> |
| 34 | #include <linux/vmalloc.h> |
| 35 | #include <linux/interrupt.h> |
| 36 | #include <linux/io.h> |
| 37 | #include <linux/gpio.h> |
| 38 | #include <linux/regulator/consumer.h> |
| 39 | #include <linux/major.h> |
| 40 | #include <linux/kdev_t.h> |
| 41 | #ifdef CONFIG_OF |
| 42 | #include <linux/of_gpio.h> |
| 43 | #endif |
| 44 | #ifdef CONFIG_FB |
| 45 | #include <linux/notifier.h> |
| 46 | #include <linux/fb.h> |
| 47 | #endif |
| 48 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 49 | #include <linux/earlysuspend.h> |
| 50 | #endif |
| 51 | #include <linux/usb.h> |
| 52 | #include <linux/power_supply.h> |
| 53 | |
| 54 | #define GTP_TOOL_PEN 1 |
| 55 | #define GTP_TOOL_FINGER 2 |
| 56 | |
| 57 | #define MAX_KEY_NUMS 4 |
| 58 | #define GTP_CONFIG_MAX_LENGTH 240 |
| 59 | #define GTP_ADDR_LENGTH 2 |
| 60 | |
| 61 | /***************************PART1:ON/OFF define*******************************/ |
| 62 | #define GTP_DEBUG_ON 1 |
| 63 | #define GTP_DEBUG_ARRAY_ON 0 |
| 64 | #define GTP_DEBUG_FUNC_ON 0 |
| 65 | |
| 66 | struct goodix_point_t { |
| 67 | int id; |
| 68 | int x; |
| 69 | int y; |
| 70 | int w; |
| 71 | int p; |
| 72 | int tool_type; |
| 73 | }; |
| 74 | |
| 75 | struct goodix_config_data { |
| 76 | int length; |
| 77 | u8 data[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH]; |
| 78 | }; |
| 79 | |
| 80 | struct goodix_ts_platform_data { |
| 81 | int irq_gpio; |
| 82 | int rst_gpio; |
| 83 | u32 irq_flags; |
| 84 | u32 abs_size_x; |
| 85 | u32 abs_size_y; |
| 86 | u32 max_touch_id; |
| 87 | u32 max_touch_width; |
| 88 | u32 max_touch_pressure; |
| 89 | u32 key_map[MAX_KEY_NUMS]; |
| 90 | u32 key_nums; |
| 91 | u32 int_sync; |
| 92 | u32 driver_send_cfg; |
| 93 | u32 swap_x2y; |
| 94 | u32 slide_wakeup; |
| 95 | u32 auto_update; |
| 96 | u32 auto_update_cfg; |
| 97 | u32 esd_protect; |
| 98 | u32 type_a_report; |
| 99 | u32 power_off_sleep; |
| 100 | u32 resume_in_workqueue; |
| 101 | u32 pen_suppress_finger; |
| 102 | struct goodix_config_data config; |
| 103 | }; |
| 104 | |
| 105 | struct goodix_ts_esd { |
| 106 | struct delayed_work delayed_work; |
| 107 | struct mutex mutex; |
| 108 | bool esd_on; |
| 109 | }; |
| 110 | |
| 111 | enum { |
| 112 | REPORT_THREAD_ENABLED = 0, |
| 113 | HRTIMER_USED, |
| 114 | FW_ERROR, |
| 115 | |
| 116 | DOZE_MODE, |
| 117 | SLEEP_MODE, |
| 118 | POWER_OFF_MODE, |
| 119 | RAW_DATA_MODE, |
| 120 | |
| 121 | FW_UPDATE_RUNNING, |
| 122 | PANEL_RESETTING |
| 123 | }; |
| 124 | |
| 125 | struct goodix_pinctrl { |
| 126 | struct pinctrl *pinctrl; |
| 127 | struct pinctrl_state *int_default; |
| 128 | struct pinctrl_state *int_out_high; |
| 129 | struct pinctrl_state *int_out_low; |
| 130 | struct pinctrl_state *int_input; |
| 131 | struct pinctrl_state *rst_default; |
| 132 | struct pinctrl_state *rst_out_high; |
| 133 | struct pinctrl_state *rst_out_low; |
| 134 | struct pinctrl_state *rst_input; |
| 135 | }; |
| 136 | |
| 137 | struct goodix_fw_info { |
| 138 | u8 pid[6]; |
| 139 | u16 version; |
| 140 | u8 sensor_id; |
| 141 | }; |
| 142 | |
| 143 | struct goodix_ts_data { |
| 144 | unsigned long flags; /* This member record the device status */ |
| 145 | |
| 146 | struct goodix_ts_esd ts_esd; |
| 147 | struct i2c_client *client; |
| 148 | struct input_dev *input_dev; |
| 149 | struct input_dev *pen_dev; |
| 150 | struct goodix_ts_platform_data *pdata; |
| 151 | /* use pinctrl control int-pin output low or high */ |
| 152 | struct goodix_pinctrl pinctrl; |
| 153 | struct hrtimer timer; |
| 154 | struct mutex lock; |
| 155 | struct notifier_block ps_notif; |
| 156 | struct regulator *vdd_ana; |
| 157 | struct regulator *vcc_i2c; |
| 158 | #if defined(CONFIG_FB) |
| 159 | struct notifier_block notifier; |
| 160 | struct work_struct fb_notify_work; |
| 161 | #elif defined(CONFIG_HAS_EARLYSUSPEND) |
| 162 | struct early_suspend early_suspend; |
| 163 | #endif |
| 164 | struct goodix_fw_info fw_info; |
| 165 | bool force_update; |
| 166 | bool init_done; |
| 167 | }; |
| 168 | |
| 169 | /************************* PART2:TODO define *******************************/ |
| 170 | /* STEP_1(REQUIRED): Define Configuration Information Group(s) |
| 171 | * Sensor_ID Map: |
| 172 | * sensor_opt1 sensor_opt2 Sensor_ID |
| 173 | * GND GND 0 |
| 174 | * VDDIO GND 1 |
| 175 | * NC GND 2 |
| 176 | * GND NC/300K 3 |
| 177 | * VDDIO NC/300K 4 |
| 178 | * NC NC/300K 5 |
| 179 | */ |
| 180 | /* TODO: define your own default or for Sensor_ID == 0 config here. |
| 181 | * The predefined one is just a sample config, |
| 182 | * which is not suitable for your tp in most cases. |
| 183 | */ |
| 184 | #define CTP_CFG_GROUP0 {\ |
| 185 | 0x41, 0xD0, 0x02, 0x00, 0x05, 0x0A, 0x34, \ |
| 186 | 0x00, 0x01, 0x08, 0x28, 0x05, 0x50, 0x32, \ |
| 187 | 0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 188 | 0x00, 0x00, 0x17, 0x19, 0x1E, 0x14, 0x8C, \ |
| 189 | 0x2D, 0x0E, 0x3C, 0x3E, 0x82, 0x0A, 0x82, \ |
| 190 | 0x0A, 0x00, 0x99, 0x33, 0x1D, 0x00, 0x00, \ |
| 191 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 192 | 0x00, 0x2B, 0x19, 0x64, 0x94, 0xC0, 0x02, \ |
| 193 | 0x08, 0x00, 0x00, 0x04, 0xF2, 0x1C, 0x00, \ |
| 194 | 0xB9, 0x26, 0x00, 0x93, 0x32, 0x00, 0x77, \ |
| 195 | 0x42, 0x00, 0x62, 0x57, 0x00, 0x62, 0x00, \ |
| 196 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 197 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 198 | 0x00, 0x00, 0x00, 0xFF, 0x65, 0x00, 0x00, \ |
| 199 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 200 | 0x19, 0x46, 0x00, 0x00, 0x00, 0x00, 0x32, \ |
| 201 | 0x1C, 0x1A, 0x18, 0x16, 0x14, 0x12, 0x10, \ |
| 202 | 0x0E, 0x0C, 0x0A, 0x08, 0x06, 0x04, 0x02, \ |
| 203 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 204 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 205 | 0x00, 0x00, 0x00, 0x02, 0x04, 0x06, 0x08, \ |
| 206 | 0x0A, 0x0C, 0x0F, 0x10, 0x12, 0x13, 0x14, \ |
| 207 | 0x18, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, \ |
| 208 | 0x22, 0x24, 0x26, 0x28, 0x29, 0x2A, 0xFF, \ |
| 209 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 210 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ |
| 211 | 0x00, 0x00, 0xB8, 0x01\ |
| 212 | } |
| 213 | |
| 214 | /* TODO: define your config for Sensor_ID == 1 here, if needed */ |
| 215 | #define CTP_CFG_GROUP1 {\ |
| 216 | } |
| 217 | |
| 218 | /* TODO: define your config for Sensor_ID == 2 here, if needed */ |
| 219 | #define CTP_CFG_GROUP2 {\ |
| 220 | } |
| 221 | |
| 222 | /* TODO: define your config for Sensor_ID == 3 here, if needed */ |
| 223 | #define CTP_CFG_GROUP3 {\ |
| 224 | } |
| 225 | /* TODO: define your config for Sensor_ID == 4 here, if needed */ |
| 226 | #define CTP_CFG_GROUP4 {\ |
| 227 | } |
| 228 | |
| 229 | /* TODO: define your config for Sensor_ID == 5 here, if needed */ |
| 230 | #define CTP_CFG_GROUP5 {\ |
| 231 | } |
| 232 | |
| 233 | /* STEP_2(REQUIRED): Customize your I/O ports & I/O operations */ |
| 234 | #define GTP_RST_PORT 64 /* EXYNOS4_GPX2(0) */ |
| 235 | #define GTP_INT_PORT 65 /* EXYNOS4_GPX2(1) */ |
| 236 | |
| 237 | #define GTP_GPIO_AS_INPUT(pin) (gpio_direction_input(pin)) |
| 238 | #define GTP_GPIO_AS_INT(pin) (GTP_GPIO_AS_INPUT(pin)) |
| 239 | #define GTP_GPIO_GET_VALUE(pin) gpio_get_value(pin) |
| 240 | #define GTP_GPIO_OUTPUT(pin, level) gpio_direction_output(pin, level) |
| 241 | #define GTP_GPIO_REQUEST(pin, label) gpio_request(pin, label) |
| 242 | #define GTP_GPIO_FREE(pin) gpio_free(pin) |
| 243 | |
| 244 | /* STEP_3(optional): Specify your special config info if needed */ |
| 245 | #define GTP_DEFAULT_MAX_X 720 /* default coordinate max values */ |
| 246 | #define GTP_DEFAULT_MAX_Y 1080 |
| 247 | #define GTP_DEFAULT_MAX_WIDTH 1024 |
| 248 | #define GTP_DEFAULT_MAX_PRESSURE 1024 |
| 249 | #define GTP_DEFAULT_INT_TRIGGER 1 /* 1 rising, 2 falling */ |
| 250 | #define GTP_MAX_TOUCH_ID 16 |
| 251 | |
| 252 | /* STEP_4(optional): If keys are available and reported as keys, |
| 253 | * config your key info here |
| 254 | */ |
| 255 | #define GTP_KEY_TAB {KEY_MENU, KEY_HOME, KEY_BACK, KEY_HOMEPAGE, \ |
| 256 | KEY_F1, KEY_F2, KEY_F3} |
| 257 | |
| 258 | /**************************PART3:OTHER define*******************************/ |
| 259 | #define GTP_DRIVER_VERSION "V2.8.0.2<2017/12/14>" |
| 260 | #define GTP_I2C_NAME "goodix-ts" |
| 261 | #define GT91XX_CONFIG_PROC_FILE "gt9xx_config" |
| 262 | #define GTP_POLL_TIME 10 |
| 263 | #define GTP_CONFIG_MIN_LENGTH 186 |
| 264 | #define GTP_ESD_CHECK_VALUE 0xAA |
| 265 | #define RETRY_MAX_TIMES 5 |
| 266 | #define PEN_TRACK_ID 9 |
| 267 | #define MASK_BIT_8 0x80 |
| 268 | #define FAIL 0 |
| 269 | #define SUCCESS 1 |
| 270 | |
| 271 | /* Registers define */ |
| 272 | #define GTP_REG_COMMAND 0x8040 |
| 273 | #define GTP_REG_ESD_CHECK 0x8041 |
| 274 | #define GTP_REG_COMMAND_CHECK 0x8046 |
| 275 | #define GTP_REG_CONFIG_DATA 0x8047 |
| 276 | #define GTP_REG_VERSION 0x8140 |
| 277 | #define GTP_REG_SENSOR_ID 0x814A |
| 278 | #define GTP_REG_DOZE_BUF 0x814B |
| 279 | #define GTP_READ_COOR_ADDR 0x814E |
| 280 | |
| 281 | /* Sleep time define */ |
| 282 | #define GTP_1_DLY_MS 1 |
| 283 | #define GTP_2_DLY_MS 2 |
| 284 | #define GTP_10_DLY_MS 10 |
| 285 | #define GTP_20_DLY_MS 20 |
| 286 | #define GTP_50_DLY_MS 50 |
| 287 | #define GTP_58_DLY_MS 58 |
| 288 | #define GTP_100_DLY_MS 100 |
| 289 | #define GTP_500_DLY_MS 500 |
| 290 | #define GTP_1000_DLY_MS 1000 |
| 291 | #define GTP_3000_DLY_MS 3000 |
| 292 | |
| 293 | #define RESOLUTION_LOC 3 |
| 294 | #define TRIGGER_LOC 8 |
| 295 | |
| 296 | #define CFG_GROUP_LEN(p_cfg_grp) ARRAY_SIZE(p_cfg_grp) |
| 297 | /* Log define */ |
| 298 | #define GTP_DEBUG(fmt, arg...) \ |
| 299 | do { \ |
| 300 | if (GTP_DEBUG_ON) {\ |
| 301 | pr_info("<<-GTP-DEBUG->> [%d]"fmt"\n", __LINE__, ##arg);\ |
| 302 | } \ |
| 303 | } while (0) |
| 304 | #define GTP_DEBUG_ARRAY(array, num) \ |
| 305 | do { \ |
| 306 | s32 i;\ |
| 307 | u8 *a = array;\ |
| 308 | if (GTP_DEBUG_ARRAY_ON) {\ |
| 309 | pr_warn("<<-GTP-DEBUG-ARRAY->>\n");\ |
| 310 | for (i = 0; i < (num); i++) {\ |
| 311 | pr_warn("%02x ", (a)[i]);\ |
| 312 | if ((i + 1) % 10 == 0) {\ |
| 313 | pr_warn("\n");\ |
| 314 | } \ |
| 315 | } \ |
| 316 | pr_warn("\n");\ |
| 317 | } \ |
| 318 | } while (0) |
| 319 | #define GTP_DEBUG_FUNC() \ |
| 320 | do {\ |
| 321 | if (GTP_DEBUG_FUNC_ON) {\ |
| 322 | pr_warn("<<-GTP-FUNC->> Func:%s@Line:%d\n", \ |
| 323 | __func__, __LINE__);\ |
| 324 | } \ |
| 325 | } while (0) |
| 326 | #define GTP_SWAP(x, y) \ |
| 327 | do {\ |
| 328 | typeof(x) z = x;\ |
| 329 | x = y;\ |
| 330 | y = z;\ |
| 331 | } while (0) |
| 332 | |
| 333 | /******************************End of Part III********************************/ |
| 334 | #ifdef CONFIG_OF |
| 335 | extern int gtp_parse_dt_cfg(struct device *dev, u8 *cfg, int *cfg_len, u8 sid); |
| 336 | #endif |
| 337 | |
| 338 | extern void gtp_reset_guitar(struct i2c_client *client, s32 ms); |
| 339 | extern void gtp_int_sync(struct goodix_ts_data *ts, s32 ms); |
| 340 | extern void gtp_esd_on(struct goodix_ts_data *ts); |
| 341 | extern void gtp_esd_off(struct goodix_ts_data *ts); |
| 342 | extern void gtp_work_control_enable(struct goodix_ts_data *ts, bool enable); |
| 343 | |
| 344 | #ifdef CONFIG_TOUCHSCREEN_GT9XX_UPDATE |
| 345 | extern u16 show_len; |
| 346 | extern u16 total_len; |
| 347 | extern u8 gup_init_update_proc(struct goodix_ts_data *ts); |
| 348 | extern s32 gup_update_proc(void *dir); |
| 349 | extern s32 gup_enter_update_mode(struct i2c_client *client); |
| 350 | extern void gup_leave_update_mode(struct i2c_client *client); |
| 351 | #endif |
| 352 | |
| 353 | #ifdef CONFIG_TOUCHSCREEN_GT9XX_TOOL |
| 354 | extern s32 init_wr_node(struct i2c_client *client); |
| 355 | extern void uninit_wr_node(void); |
| 356 | #endif |
| 357 | |
| 358 | /*********** For gt9xx_update Start *********/ |
| 359 | extern struct i2c_client *i2c_connect_client; |
| 360 | extern void gtp_reset_guitar(struct i2c_client *client, s32 ms); |
| 361 | extern void gtp_int_output(struct goodix_ts_data *ts, int level); |
| 362 | extern void gtp_rst_output(struct goodix_ts_data *ts, int level); |
| 363 | extern void gtp_rst_input(struct goodix_ts_data *ts); |
| 364 | extern s32 gtp_send_cfg(struct i2c_client *client); |
| 365 | extern s32 gtp_get_fw_info(struct i2c_client *client, |
| 366 | struct goodix_fw_info *fw_info); |
| 367 | extern s32 gtp_i2c_read_dbl_check(struct i2c_client *client, |
| 368 | u16 addr, u8 *rxbuf, int len); |
| 369 | extern int gtp_i2c_read(struct i2c_client *client, u8 *buf, int len); |
| 370 | extern int gtp_i2c_write(struct i2c_client *client, u8 *buf, int len); |
| 371 | extern s32 gtp_fw_startup(struct i2c_client *client); |
| 372 | extern int gtp_ascii_to_array(const u8 *src_buf, int src_len, u8 *dst_buf); |
| 373 | /*********** For gt9xx_update End *********/ |
| 374 | |
| 375 | #endif /* _GOODIX_GT9XX_H_ */ |