Andrew Huang | ab45aab | 2013-06-27 10:06:56 +0000 | [diff] [blame] | 1 | /* drivers/input/touchscreen/gt9xx.c |
| 2 | * |
| 3 | * 2010 - 2013 Goodix Technology. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be a reference |
| 11 | * to you, when you are integrating the GOODiX's CTP IC into your system, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * Version: 1.8 |
| 17 | * Authors: andrew@goodix.com, meta@goodix.com |
| 18 | * Release Date: 2013/04/25 |
| 19 | * Revision record: |
| 20 | * V1.0: |
| 21 | * first Release. By Andrew, 2012/08/31 |
| 22 | * V1.2: |
| 23 | * modify gtp_reset_guitar,slot report,tracking_id & 0x0F. By Andrew, 2012/10/15 |
| 24 | * V1.4: |
| 25 | * modify gt9xx_update.c. By Andrew, 2012/12/12 |
| 26 | * V1.6: |
| 27 | * 1. new heartbeat/esd_protect mechanism(add external watchdog) |
| 28 | * 2. doze mode, sliding wakeup |
| 29 | * 3. 3 more cfg_group(GT9 Sensor_ID: 0~5) |
| 30 | * 3. config length verification |
| 31 | * 4. names & comments |
| 32 | * By Meta, 2013/03/11 |
| 33 | * V1.8: |
| 34 | * 1. pen/stylus identification |
| 35 | * 2. read double check & fixed config support |
| 36 | * 2. new esd & slide wakeup optimization |
| 37 | * By Meta, 2013/06/08 |
| 38 | */ |
| 39 | |
| 40 | #include <linux/irq.h> |
| 41 | #include "gt9xx.h" |
| 42 | |
| 43 | #if GTP_ICS_SLOT_REPORT |
| 44 | #include <linux/input/mt.h> |
| 45 | #endif |
| 46 | |
| 47 | static const char *goodix_ts_name = "Goodix Capacitive TouchScreen"; |
| 48 | static struct workqueue_struct *goodix_wq; |
| 49 | struct i2c_client * i2c_connect_client = NULL; |
| 50 | u8 config[GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH] |
| 51 | = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; |
| 52 | |
| 53 | #if GTP_HAVE_TOUCH_KEY |
| 54 | static const u16 touch_key_array[] = GTP_KEY_TAB; |
| 55 | #define GTP_MAX_KEY_NUM (sizeof(touch_key_array)/sizeof(touch_key_array[0])) |
| 56 | |
| 57 | #if GTP_DEBUG_ON |
| 58 | static const int key_codes[] = {KEY_HOME, KEY_BACK, KEY_MENU, KEY_SEARCH}; |
| 59 | static const char *key_names[] = {"Key_Home", "Key_Back", "Key_Menu", "Key_Search"}; |
| 60 | #endif |
| 61 | |
| 62 | #endif |
| 63 | |
| 64 | static s8 gtp_i2c_test(struct i2c_client *client); |
| 65 | void gtp_reset_guitar(struct i2c_client *client, s32 ms); |
| 66 | void gtp_int_sync(s32 ms); |
| 67 | |
| 68 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 69 | static void goodix_ts_early_suspend(struct early_suspend *h); |
| 70 | static void goodix_ts_late_resume(struct early_suspend *h); |
| 71 | #endif |
| 72 | |
| 73 | #if GTP_CREATE_WR_NODE |
| 74 | extern s32 init_wr_node(struct i2c_client*); |
| 75 | extern void uninit_wr_node(void); |
| 76 | #endif |
| 77 | |
| 78 | #if GTP_AUTO_UPDATE |
| 79 | extern u8 gup_init_update_proc(struct goodix_ts_data *); |
| 80 | #endif |
| 81 | |
| 82 | #if GTP_ESD_PROTECT |
| 83 | static struct delayed_work gtp_esd_check_work; |
| 84 | static struct workqueue_struct * gtp_esd_check_workqueue = NULL; |
| 85 | static void gtp_esd_check_func(struct work_struct *); |
| 86 | static s32 gtp_init_ext_watchdog(struct i2c_client *client); |
| 87 | void gtp_esd_switch(struct i2c_client *, s32); |
| 88 | #endif |
| 89 | |
| 90 | |
| 91 | #if GTP_SLIDE_WAKEUP |
| 92 | typedef enum |
| 93 | { |
| 94 | DOZE_DISABLED = 0, |
| 95 | DOZE_ENABLED = 1, |
| 96 | DOZE_WAKEUP = 2, |
| 97 | }DOZE_T; |
| 98 | static DOZE_T doze_status = DOZE_DISABLED; |
| 99 | static s8 gtp_enter_doze(struct goodix_ts_data *ts); |
| 100 | #endif |
| 101 | |
| 102 | static u8 chip_gt9xxs = 0; // true if ic is gt9xxs, like gt915s |
| 103 | u8 grp_cfg_version = 0; |
| 104 | |
| 105 | /******************************************************* |
| 106 | Function: |
| 107 | Read data from the i2c slave device. |
| 108 | Input: |
| 109 | client: i2c device. |
| 110 | buf[0~1]: read start address. |
| 111 | buf[2~len-1]: read data buffer. |
| 112 | len: GTP_ADDR_LENGTH + read bytes count |
| 113 | Output: |
| 114 | numbers of i2c_msgs to transfer: |
| 115 | 2: succeed, otherwise: failed |
| 116 | *********************************************************/ |
| 117 | s32 gtp_i2c_read(struct i2c_client *client, u8 *buf, s32 len) |
| 118 | { |
| 119 | struct i2c_msg msgs[2]; |
| 120 | s32 ret=-1; |
| 121 | s32 retries = 0; |
| 122 | |
| 123 | GTP_DEBUG_FUNC(); |
| 124 | |
| 125 | msgs[0].flags = !I2C_M_RD; |
| 126 | msgs[0].addr = client->addr; |
| 127 | msgs[0].len = GTP_ADDR_LENGTH; |
| 128 | msgs[0].buf = &buf[0]; |
| 129 | //msgs[0].scl_rate = 300 * 1000; // for Rockchip |
| 130 | |
| 131 | msgs[1].flags = I2C_M_RD; |
| 132 | msgs[1].addr = client->addr; |
| 133 | msgs[1].len = len - GTP_ADDR_LENGTH; |
| 134 | msgs[1].buf = &buf[GTP_ADDR_LENGTH]; |
| 135 | //msgs[1].scl_rate = 300 * 1000; |
| 136 | |
| 137 | while(retries < 5) |
| 138 | { |
| 139 | ret = i2c_transfer(client->adapter, msgs, 2); |
| 140 | if(ret == 2)break; |
| 141 | retries++; |
| 142 | } |
| 143 | if((retries >= 5)) |
| 144 | { |
| 145 | #if GTP_SLIDE_WAKEUP |
| 146 | // reset chip would quit doze mode |
| 147 | if (DOZE_ENABLED == doze_status) |
| 148 | { |
| 149 | return ret; |
| 150 | } |
| 151 | #endif |
| 152 | GTP_DEBUG("I2C communication timeout, resetting chip..."); |
| 153 | gtp_reset_guitar(client, 10); |
| 154 | } |
| 155 | return ret; |
| 156 | } |
| 157 | |
| 158 | /******************************************************* |
| 159 | Function: |
| 160 | Write data to the i2c slave device. |
| 161 | Input: |
| 162 | client: i2c device. |
| 163 | buf[0~1]: write start address. |
| 164 | buf[2~len-1]: data buffer |
| 165 | len: GTP_ADDR_LENGTH + write bytes count |
| 166 | Output: |
| 167 | numbers of i2c_msgs to transfer: |
| 168 | 1: succeed, otherwise: failed |
| 169 | *********************************************************/ |
| 170 | s32 gtp_i2c_write(struct i2c_client *client,u8 *buf,s32 len) |
| 171 | { |
| 172 | struct i2c_msg msg; |
| 173 | s32 ret = -1; |
| 174 | s32 retries = 0; |
| 175 | |
| 176 | GTP_DEBUG_FUNC(); |
| 177 | |
| 178 | msg.flags = !I2C_M_RD; |
| 179 | msg.addr = client->addr; |
| 180 | msg.len = len; |
| 181 | msg.buf = buf; |
| 182 | //msg.scl_rate = 300 * 1000; // for Rockchip |
| 183 | |
| 184 | while(retries < 5) |
| 185 | { |
| 186 | ret = i2c_transfer(client->adapter, &msg, 1); |
| 187 | if (ret == 1)break; |
| 188 | retries++; |
| 189 | } |
| 190 | if((retries >= 5)) |
| 191 | { |
| 192 | #if GTP_SLIDE_WAKEUP |
| 193 | if (DOZE_ENABLED == doze_status) |
| 194 | { |
| 195 | return ret; |
| 196 | } |
| 197 | #endif |
| 198 | GTP_DEBUG("I2C communication timeout, resetting chip..."); |
| 199 | gtp_reset_guitar(client, 10); |
| 200 | } |
| 201 | return ret; |
| 202 | } |
| 203 | /******************************************************* |
| 204 | Function: |
| 205 | i2c read twice, compare the results |
| 206 | Input: |
| 207 | client: i2c device |
| 208 | addr: operate address |
| 209 | rxbuf: read data to store, if compare successful |
| 210 | len: bytes to read |
| 211 | Output: |
| 212 | FAIL: read failed |
| 213 | SUCCESS: read successful |
| 214 | *********************************************************/ |
| 215 | s32 gtp_i2c_read_dbl_check(struct i2c_client *client, u16 addr, u8 *rxbuf, int len) |
| 216 | { |
| 217 | u8 buf[16] = {0}; |
| 218 | u8 confirm_buf[16] = {0}; |
| 219 | u8 retry = 0; |
| 220 | |
| 221 | while (retry++ < 3) |
| 222 | { |
| 223 | memset(buf, 0xAA, 16); |
| 224 | buf[0] = (u8)(addr >> 8); |
| 225 | buf[1] = (u8)(addr & 0xFF); |
| 226 | gtp_i2c_read(client, buf, len + 2); |
| 227 | |
| 228 | memset(confirm_buf, 0xAB, 16); |
| 229 | confirm_buf[0] = (u8)(addr >> 8); |
| 230 | confirm_buf[1] = (u8)(addr & 0xFF); |
| 231 | gtp_i2c_read(client, confirm_buf, len + 2); |
| 232 | |
| 233 | if (!memcmp(buf, confirm_buf, len+2)) |
| 234 | { |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | if (retry < 3) |
| 239 | { |
| 240 | memcpy(rxbuf, confirm_buf+2, len); |
| 241 | return SUCCESS; |
| 242 | } |
| 243 | else |
| 244 | { |
| 245 | GTP_ERROR("i2c read 0x%04X, %d bytes, double check failed!", addr, len); |
| 246 | return FAIL; |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | /******************************************************* |
| 251 | Function: |
| 252 | Send config. |
| 253 | Input: |
| 254 | client: i2c device. |
| 255 | Output: |
| 256 | result of i2c write operation. |
| 257 | 1: succeed, otherwise: failed |
| 258 | *********************************************************/ |
| 259 | s32 gtp_send_cfg(struct i2c_client *client) |
| 260 | { |
| 261 | s32 ret = 2; |
| 262 | |
| 263 | #if GTP_DRIVER_SEND_CFG |
| 264 | s32 retry = 0; |
| 265 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
| 266 | |
| 267 | if (ts->fixed_cfg) |
| 268 | { |
| 269 | GTP_INFO("Ic fixed config, no config sent!"); |
| 270 | return 2; |
| 271 | } |
| 272 | GTP_INFO("driver send config"); |
| 273 | for (retry = 0; retry < 5; retry++) |
| 274 | { |
| 275 | ret = gtp_i2c_write(client, config , GTP_CONFIG_MAX_LENGTH + GTP_ADDR_LENGTH); |
| 276 | if (ret > 0) |
| 277 | { |
| 278 | break; |
| 279 | } |
| 280 | } |
| 281 | #endif |
| 282 | |
| 283 | return ret; |
| 284 | } |
| 285 | |
| 286 | /******************************************************* |
| 287 | Function: |
| 288 | Disable irq function |
| 289 | Input: |
| 290 | ts: goodix i2c_client private data |
| 291 | Output: |
| 292 | None. |
| 293 | *********************************************************/ |
| 294 | void gtp_irq_disable(struct goodix_ts_data *ts) |
| 295 | { |
| 296 | unsigned long irqflags; |
| 297 | |
| 298 | GTP_DEBUG_FUNC(); |
| 299 | |
| 300 | spin_lock_irqsave(&ts->irq_lock, irqflags); |
| 301 | if (!ts->irq_is_disable) |
| 302 | { |
| 303 | ts->irq_is_disable = 1; |
| 304 | disable_irq_nosync(ts->client->irq); |
| 305 | } |
| 306 | spin_unlock_irqrestore(&ts->irq_lock, irqflags); |
| 307 | } |
| 308 | |
| 309 | /******************************************************* |
| 310 | Function: |
| 311 | Enable irq function |
| 312 | Input: |
| 313 | ts: goodix i2c_client private data |
| 314 | Output: |
| 315 | None. |
| 316 | *********************************************************/ |
| 317 | void gtp_irq_enable(struct goodix_ts_data *ts) |
| 318 | { |
| 319 | unsigned long irqflags = 0; |
| 320 | |
| 321 | GTP_DEBUG_FUNC(); |
| 322 | |
| 323 | spin_lock_irqsave(&ts->irq_lock, irqflags); |
| 324 | if (ts->irq_is_disable) |
| 325 | { |
| 326 | enable_irq(ts->client->irq); |
| 327 | ts->irq_is_disable = 0; |
| 328 | } |
| 329 | spin_unlock_irqrestore(&ts->irq_lock, irqflags); |
| 330 | } |
| 331 | |
| 332 | |
| 333 | /******************************************************* |
| 334 | Function: |
| 335 | Report touch point event |
| 336 | Input: |
| 337 | ts: goodix i2c_client private data |
| 338 | id: trackId |
| 339 | x: input x coordinate |
| 340 | y: input y coordinate |
| 341 | w: input pressure |
| 342 | Output: |
| 343 | None. |
| 344 | *********************************************************/ |
| 345 | static void gtp_touch_down(struct goodix_ts_data* ts,s32 id,s32 x,s32 y,s32 w) |
| 346 | { |
| 347 | #if GTP_CHANGE_X2Y |
| 348 | GTP_SWAP(x, y); |
| 349 | #endif |
| 350 | |
| 351 | #if GTP_ICS_SLOT_REPORT |
| 352 | input_mt_slot(ts->input_dev, id); |
| 353 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id); |
| 354 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x); |
| 355 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y); |
| 356 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); |
| 357 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); |
| 358 | #else |
| 359 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x); |
| 360 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y); |
| 361 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, w); |
| 362 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, w); |
| 363 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id); |
| 364 | input_mt_sync(ts->input_dev); |
| 365 | #endif |
| 366 | |
| 367 | GTP_DEBUG("ID:%d, X:%d, Y:%d, W:%d", id, x, y, w); |
| 368 | } |
| 369 | |
| 370 | /******************************************************* |
| 371 | Function: |
| 372 | Report touch release event |
| 373 | Input: |
| 374 | ts: goodix i2c_client private data |
| 375 | Output: |
| 376 | None. |
| 377 | *********************************************************/ |
| 378 | static void gtp_touch_up(struct goodix_ts_data* ts, s32 id) |
| 379 | { |
| 380 | #if GTP_ICS_SLOT_REPORT |
| 381 | input_mt_slot(ts->input_dev, id); |
| 382 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1); |
| 383 | GTP_DEBUG("Touch id[%2d] release!", id); |
| 384 | #else |
| 385 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0); |
| 386 | input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0); |
| 387 | input_mt_sync(ts->input_dev); |
| 388 | #endif |
| 389 | } |
| 390 | |
| 391 | |
| 392 | /******************************************************* |
| 393 | Function: |
| 394 | Goodix touchscreen work function |
| 395 | Input: |
| 396 | work: work struct of goodix_workqueue |
| 397 | Output: |
| 398 | None. |
| 399 | *********************************************************/ |
| 400 | static void goodix_ts_work_func(struct work_struct *work) |
| 401 | { |
| 402 | u8 end_cmd[3] = {GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF, 0}; |
| 403 | u8 point_data[2 + 1 + 8 * GTP_MAX_TOUCH + 1]={GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF}; |
| 404 | u8 touch_num = 0; |
| 405 | u8 finger = 0; |
| 406 | static u16 pre_touch = 0; |
| 407 | static u8 pre_key = 0; |
| 408 | #if GTP_WITH_PEN |
| 409 | static u8 pre_pen = 0; |
| 410 | #endif |
| 411 | u8 key_value = 0; |
| 412 | u8* coor_data = NULL; |
| 413 | s32 input_x = 0; |
| 414 | s32 input_y = 0; |
| 415 | s32 input_w = 0; |
| 416 | s32 id = 0; |
| 417 | s32 i = 0; |
| 418 | s32 ret = -1; |
| 419 | struct goodix_ts_data *ts = NULL; |
| 420 | |
| 421 | #if GTP_SLIDE_WAKEUP |
| 422 | u8 doze_buf[3] = {0x81, 0x4B}; |
| 423 | #endif |
| 424 | |
| 425 | GTP_DEBUG_FUNC(); |
| 426 | ts = container_of(work, struct goodix_ts_data, work); |
| 427 | if (ts->enter_update) |
| 428 | { |
| 429 | return; |
| 430 | } |
| 431 | #if GTP_SLIDE_WAKEUP |
| 432 | if (DOZE_ENABLED == doze_status) |
| 433 | { |
| 434 | ret = gtp_i2c_read(i2c_connect_client, doze_buf, 3); |
| 435 | GTP_DEBUG("0x814B = 0x%02X", doze_buf[2]); |
| 436 | if (ret > 0) |
| 437 | { |
| 438 | if (doze_buf[2] == 0xAA) |
| 439 | { |
| 440 | GTP_INFO("Slide(0xAA) To Light up the screen!"); |
| 441 | doze_status = DOZE_WAKEUP; |
| 442 | input_report_key(ts->input_dev, KEY_POWER, 1); |
| 443 | input_sync(ts->input_dev); |
| 444 | input_report_key(ts->input_dev, KEY_POWER, 0); |
| 445 | input_sync(ts->input_dev); |
| 446 | // clear 0x814B |
| 447 | doze_buf[2] = 0x00; |
| 448 | gtp_i2c_write(i2c_connect_client, doze_buf, 3); |
| 449 | } |
| 450 | else if (doze_buf[2] == 0xBB) |
| 451 | { |
| 452 | GTP_INFO("Slide(0xBB) To Light up the screen!"); |
| 453 | doze_status = DOZE_WAKEUP; |
| 454 | input_report_key(ts->input_dev, KEY_POWER, 1); |
| 455 | input_sync(ts->input_dev); |
| 456 | input_report_key(ts->input_dev, KEY_POWER, 0); |
| 457 | input_sync(ts->input_dev); |
| 458 | // clear 0x814B |
| 459 | doze_buf[2] = 0x00; |
| 460 | gtp_i2c_write(i2c_connect_client, doze_buf, 3); |
| 461 | } |
| 462 | else if (0xC0 == (doze_buf[2] & 0xC0)) |
| 463 | { |
| 464 | GTP_INFO("double click to light up the screen!"); |
| 465 | doze_status = DOZE_WAKEUP; |
| 466 | input_report_key(ts->input_dev, KEY_POWER, 1); |
| 467 | input_sync(ts->input_dev); |
| 468 | input_report_key(ts->input_dev, KEY_POWER, 0); |
| 469 | input_sync(ts->input_dev); |
| 470 | // clear 0x814B |
| 471 | doze_buf[2] = 0x00; |
| 472 | gtp_i2c_write(i2c_connect_client, doze_buf, 3); |
| 473 | } |
| 474 | else |
| 475 | { |
| 476 | gtp_enter_doze(ts); |
| 477 | } |
| 478 | } |
| 479 | if (ts->use_irq) |
| 480 | { |
| 481 | gtp_irq_enable(ts); |
| 482 | } |
| 483 | return; |
| 484 | } |
| 485 | #endif |
| 486 | |
| 487 | ret = gtp_i2c_read(ts->client, point_data, 12); |
| 488 | if (ret < 0) |
| 489 | { |
| 490 | GTP_ERROR("I2C transfer error. errno:%d\n ", ret); |
| 491 | goto exit_work_func; |
| 492 | } |
| 493 | |
| 494 | finger = point_data[GTP_ADDR_LENGTH]; |
| 495 | if((finger & 0x80) == 0) |
| 496 | { |
| 497 | goto exit_work_func; |
| 498 | } |
| 499 | |
| 500 | touch_num = finger & 0x0f; |
| 501 | if (touch_num > GTP_MAX_TOUCH) |
| 502 | { |
| 503 | goto exit_work_func; |
| 504 | } |
| 505 | |
| 506 | if (touch_num > 1) |
| 507 | { |
| 508 | u8 buf[8 * GTP_MAX_TOUCH] = {(GTP_READ_COOR_ADDR + 10) >> 8, (GTP_READ_COOR_ADDR + 10) & 0xff}; |
| 509 | |
| 510 | ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1)); |
| 511 | memcpy(&point_data[12], &buf[2], 8 * (touch_num - 1)); |
| 512 | } |
| 513 | |
| 514 | #if GTP_HAVE_TOUCH_KEY |
| 515 | key_value = point_data[3 + 8 * touch_num]; |
| 516 | |
| 517 | if(key_value || pre_key) |
| 518 | { |
| 519 | for (i = 0; i < GTP_MAX_KEY_NUM; i++) |
| 520 | { |
| 521 | #if GTP_DEBUG_ON |
| 522 | for (ret = 0; ret < 4; ++ret) |
| 523 | { |
| 524 | if (key_codes[ret] == touch_key_array[i]) |
| 525 | { |
| 526 | GTP_DEBUG("Key: %s %s", key_names[ret], (key_value & (0x01 << i)) ? "Down" : "Up"); |
| 527 | break; |
| 528 | } |
| 529 | } |
| 530 | #endif |
| 531 | input_report_key(ts->input_dev, touch_key_array[i], key_value & (0x01<<i)); |
| 532 | } |
| 533 | touch_num = 0; |
| 534 | pre_touch = 0; |
| 535 | } |
| 536 | #endif |
| 537 | pre_key = key_value; |
| 538 | |
| 539 | GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger); |
| 540 | |
| 541 | #if GTP_ICS_SLOT_REPORT |
| 542 | |
| 543 | #if GTP_WITH_PEN |
| 544 | if (pre_pen && (touch_num == 0)) |
| 545 | { |
| 546 | GTP_DEBUG("Pen touch UP(Slot)!"); |
| 547 | input_report_key(ts->input_dev, BTN_TOOL_PEN, 0); |
| 548 | input_mt_slot(ts->input_dev, 5); |
| 549 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, -1); |
| 550 | pre_pen = 0; |
| 551 | } |
| 552 | #endif |
| 553 | if (pre_touch || touch_num) |
| 554 | { |
| 555 | s32 pos = 0; |
| 556 | u16 touch_index = 0; |
| 557 | |
| 558 | coor_data = &point_data[3]; |
| 559 | |
| 560 | if(touch_num) |
| 561 | { |
| 562 | id = coor_data[pos] & 0x0F; |
| 563 | |
| 564 | #if GTP_WITH_PEN |
| 565 | id = coor_data[pos]; |
| 566 | if ((id == 128)) |
| 567 | { |
| 568 | GTP_DEBUG("Pen touch DOWN(Slot)!"); |
| 569 | input_x = coor_data[pos + 1] | (coor_data[pos + 2] << 8); |
| 570 | input_y = coor_data[pos + 3] | (coor_data[pos + 4] << 8); |
| 571 | input_w = coor_data[pos + 5] | (coor_data[pos + 6] << 8); |
| 572 | |
| 573 | input_report_key(ts->input_dev, BTN_TOOL_PEN, 1); |
| 574 | input_mt_slot(ts->input_dev, 5); |
| 575 | input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 5); |
| 576 | input_report_abs(ts->input_dev, ABS_MT_POSITION_X, input_x); |
| 577 | input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, input_y); |
| 578 | input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w); |
| 579 | GTP_DEBUG("Pen/Stylus: (%d, %d)[%d]", input_x, input_y, input_w); |
| 580 | pre_pen = 1; |
| 581 | pre_touch = 0; |
| 582 | } |
| 583 | #endif |
| 584 | |
| 585 | touch_index |= (0x01<<id); |
| 586 | } |
| 587 | |
| 588 | GTP_DEBUG("id = %d,touch_index = 0x%x, pre_touch = 0x%x\n",id, touch_index,pre_touch); |
| 589 | for (i = 0; i < GTP_MAX_TOUCH; i++) |
| 590 | { |
| 591 | #if GTP_WITH_PEN |
| 592 | if (pre_pen == 1) |
| 593 | { |
| 594 | break; |
| 595 | } |
| 596 | #endif |
| 597 | |
| 598 | if (touch_index & (0x01<<i)) |
| 599 | { |
| 600 | input_x = coor_data[pos + 1] | (coor_data[pos + 2] << 8); |
| 601 | input_y = coor_data[pos + 3] | (coor_data[pos + 4] << 8); |
| 602 | input_w = coor_data[pos + 5] | (coor_data[pos + 6] << 8); |
| 603 | |
| 604 | gtp_touch_down(ts, id, input_x, input_y, input_w); |
| 605 | pre_touch |= 0x01 << i; |
| 606 | |
| 607 | pos += 8; |
| 608 | id = coor_data[pos] & 0x0F; |
| 609 | touch_index |= (0x01<<id); |
| 610 | } |
| 611 | else |
| 612 | { |
| 613 | gtp_touch_up(ts, i); |
| 614 | pre_touch &= ~(0x01 << i); |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | #else |
| 619 | input_report_key(ts->input_dev, BTN_TOUCH, (touch_num || key_value)); |
| 620 | if (touch_num) |
| 621 | { |
| 622 | for (i = 0; i < touch_num; i++) |
| 623 | { |
| 624 | coor_data = &point_data[i * 8 + 3]; |
| 625 | |
| 626 | id = coor_data[0]; // & 0x0F; |
| 627 | input_x = coor_data[1] | (coor_data[2] << 8); |
| 628 | input_y = coor_data[3] | (coor_data[4] << 8); |
| 629 | input_w = coor_data[5] | (coor_data[6] << 8); |
| 630 | |
| 631 | #if GTP_WITH_PEN |
| 632 | if (id == 128) |
| 633 | { |
| 634 | GTP_DEBUG("Pen touch DOWN!"); |
| 635 | input_report_key(ts->input_dev, BTN_TOOL_PEN, 1); |
| 636 | pre_pen = 1; |
| 637 | id = 0; |
| 638 | } |
| 639 | #endif |
| 640 | |
| 641 | gtp_touch_down(ts, id, input_x, input_y, input_w); |
| 642 | } |
| 643 | } |
| 644 | else if (pre_touch) |
| 645 | { |
| 646 | |
| 647 | #if GTP_WITH_PEN |
| 648 | if (pre_pen == 1) |
| 649 | { |
| 650 | GTP_DEBUG("Pen touch UP!"); |
| 651 | input_report_key(ts->input_dev, BTN_TOOL_PEN, 0); |
| 652 | pre_pen = 0; |
| 653 | } |
| 654 | #endif |
| 655 | |
| 656 | GTP_DEBUG("Touch Release!"); |
| 657 | gtp_touch_up(ts, 0); |
| 658 | } |
| 659 | |
| 660 | pre_touch = touch_num; |
| 661 | #endif |
| 662 | |
| 663 | input_sync(ts->input_dev); |
| 664 | |
| 665 | exit_work_func: |
| 666 | if(!ts->gtp_rawdiff_mode) |
| 667 | { |
| 668 | ret = gtp_i2c_write(ts->client, end_cmd, 3); |
| 669 | if (ret < 0) |
| 670 | { |
| 671 | GTP_INFO("I2C write end_cmd error!"); |
| 672 | } |
| 673 | } |
| 674 | if (ts->use_irq) |
| 675 | { |
| 676 | gtp_irq_enable(ts); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | /******************************************************* |
| 681 | Function: |
| 682 | Timer interrupt service routine for polling mode. |
| 683 | Input: |
| 684 | timer: timer struct pointer |
| 685 | Output: |
| 686 | Timer work mode. |
| 687 | HRTIMER_NORESTART: no restart mode |
| 688 | *********************************************************/ |
| 689 | static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer) |
| 690 | { |
| 691 | struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer); |
| 692 | |
| 693 | GTP_DEBUG_FUNC(); |
| 694 | |
| 695 | queue_work(goodix_wq, &ts->work); |
| 696 | hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME+6)*1000000), HRTIMER_MODE_REL); |
| 697 | return HRTIMER_NORESTART; |
| 698 | } |
| 699 | |
| 700 | /******************************************************* |
| 701 | Function: |
| 702 | External interrupt service routine for interrupt mode. |
| 703 | Input: |
| 704 | irq: interrupt number. |
| 705 | dev_id: private data pointer |
| 706 | Output: |
| 707 | Handle Result. |
| 708 | IRQ_HANDLED: interrupt handled successfully |
| 709 | *********************************************************/ |
| 710 | static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id) |
| 711 | { |
| 712 | struct goodix_ts_data *ts = dev_id; |
| 713 | |
| 714 | GTP_DEBUG_FUNC(); |
| 715 | |
| 716 | gtp_irq_disable(ts); |
| 717 | |
| 718 | queue_work(goodix_wq, &ts->work); |
| 719 | |
| 720 | return IRQ_HANDLED; |
| 721 | } |
| 722 | /******************************************************* |
| 723 | Function: |
| 724 | Synchronization. |
| 725 | Input: |
| 726 | ms: synchronization time in millisecond. |
| 727 | Output: |
| 728 | None. |
| 729 | *******************************************************/ |
| 730 | void gtp_int_sync(s32 ms) |
| 731 | { |
| 732 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); |
| 733 | msleep(ms); |
| 734 | GTP_GPIO_AS_INT(GTP_INT_PORT); |
| 735 | } |
| 736 | |
| 737 | /******************************************************* |
| 738 | Function: |
| 739 | Reset chip. |
| 740 | Input: |
| 741 | ms: reset time in millisecond |
| 742 | Output: |
| 743 | None. |
| 744 | *******************************************************/ |
| 745 | void gtp_reset_guitar(struct i2c_client *client, s32 ms) |
| 746 | { |
| 747 | GTP_DEBUG_FUNC(); |
| 748 | |
| 749 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 0); // begin select I2C slave addr |
| 750 | msleep(ms); // T2: > 10ms |
| 751 | // HIGH: 0x28/0x29, LOW: 0xBA/0xBB |
| 752 | GTP_GPIO_OUTPUT(GTP_INT_PORT, client->addr == 0x14); |
| 753 | |
| 754 | msleep(2); // T3: > 100us |
| 755 | GTP_GPIO_OUTPUT(GTP_RST_PORT, 1); |
| 756 | |
| 757 | msleep(6); // T4: > 5ms |
| 758 | |
| 759 | GTP_GPIO_AS_INPUT(GTP_RST_PORT); // end select I2C slave addr |
| 760 | |
| 761 | gtp_int_sync(50); |
| 762 | |
| 763 | #if GTP_ESD_PROTECT |
| 764 | gtp_init_ext_watchdog(client); |
| 765 | #endif |
| 766 | } |
| 767 | |
| 768 | #if GTP_SLIDE_WAKEUP |
| 769 | /******************************************************* |
| 770 | Function: |
| 771 | Enter doze mode for sliding wakeup. |
| 772 | Input: |
| 773 | ts: goodix tp private data |
| 774 | Output: |
| 775 | 1: succeed, otherwise failed |
| 776 | *******************************************************/ |
| 777 | static s8 gtp_enter_doze(struct goodix_ts_data *ts) |
| 778 | { |
| 779 | s8 ret = -1; |
| 780 | s8 retry = 0; |
| 781 | u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 8}; |
| 782 | |
| 783 | GTP_DEBUG_FUNC(); |
| 784 | |
| 785 | #if GTP_DBL_CLK_WAKEUP |
| 786 | i2c_control_buf[2] = 0x09; |
| 787 | #endif |
| 788 | |
| 789 | gtp_irq_disable(ts); |
| 790 | |
| 791 | GTP_DEBUG("entering doze mode..."); |
| 792 | while(retry++ < 5) |
| 793 | { |
| 794 | i2c_control_buf[0] = 0x80; |
| 795 | i2c_control_buf[1] = 0x46; |
| 796 | ret = gtp_i2c_write(ts->client, i2c_control_buf, 3); |
| 797 | if (ret < 0) |
| 798 | { |
| 799 | GTP_DEBUG("failed to set doze flag into 0x8046, %d", retry); |
| 800 | continue; |
| 801 | } |
| 802 | i2c_control_buf[0] = 0x80; |
| 803 | i2c_control_buf[1] = 0x40; |
| 804 | ret = gtp_i2c_write(ts->client, i2c_control_buf, 3); |
| 805 | if (ret > 0) |
| 806 | { |
| 807 | doze_status = DOZE_ENABLED; |
| 808 | GTP_INFO("GTP has been working in doze mode!"); |
| 809 | gtp_irq_enable(ts); |
| 810 | return ret; |
| 811 | } |
| 812 | msleep(10); |
| 813 | } |
| 814 | GTP_ERROR("GTP send doze cmd failed."); |
| 815 | gtp_irq_enable(ts); |
| 816 | return ret; |
| 817 | } |
| 818 | #else |
| 819 | /******************************************************* |
| 820 | Function: |
| 821 | Enter sleep mode. |
| 822 | Input: |
| 823 | ts: private data. |
| 824 | Output: |
| 825 | Executive outcomes. |
| 826 | 1: succeed, otherwise failed. |
| 827 | *******************************************************/ |
| 828 | static s8 gtp_enter_sleep(struct goodix_ts_data * ts) |
| 829 | { |
| 830 | s8 ret = -1; |
| 831 | s8 retry = 0; |
| 832 | u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5}; |
| 833 | |
| 834 | GTP_DEBUG_FUNC(); |
| 835 | |
| 836 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 0); |
| 837 | msleep(5); |
| 838 | |
| 839 | while(retry++ < 5) |
| 840 | { |
| 841 | ret = gtp_i2c_write(ts->client, i2c_control_buf, 3); |
| 842 | if (ret > 0) |
| 843 | { |
| 844 | GTP_INFO("GTP enter sleep!"); |
| 845 | |
| 846 | return ret; |
| 847 | } |
| 848 | msleep(10); |
| 849 | } |
| 850 | GTP_ERROR("GTP send sleep cmd failed."); |
| 851 | return ret; |
| 852 | } |
| 853 | #endif |
| 854 | /******************************************************* |
| 855 | Function: |
| 856 | Wakeup from sleep. |
| 857 | Input: |
| 858 | ts: private data. |
| 859 | Output: |
| 860 | Executive outcomes. |
| 861 | >0: succeed, otherwise: failed. |
| 862 | *******************************************************/ |
| 863 | static s8 gtp_wakeup_sleep(struct goodix_ts_data * ts) |
| 864 | { |
| 865 | u8 retry = 0; |
| 866 | s8 ret = -1; |
| 867 | |
| 868 | GTP_DEBUG_FUNC(); |
| 869 | |
| 870 | #if GTP_POWER_CTRL_SLEEP |
| 871 | while(retry++ < 5) |
| 872 | { |
| 873 | gtp_reset_guitar(ts->client, 20); |
| 874 | |
| 875 | ret = gtp_send_cfg(ts->client); |
| 876 | if (ret < 0) |
| 877 | { |
| 878 | GTP_INFO("Wakeup sleep send config failed!"); |
| 879 | continue; |
| 880 | } |
| 881 | GTP_INFO("GTP wakeup sleep"); |
| 882 | return 1; |
| 883 | } |
| 884 | #else |
| 885 | while(retry++ < 10) |
| 886 | { |
| 887 | #if GTP_SLIDE_WAKEUP |
| 888 | if (DOZE_WAKEUP != doze_status) // wakeup not by slide |
| 889 | { |
| 890 | gtp_reset_guitar(ts->client, 10); |
| 891 | } |
| 892 | else // wakeup by slide |
| 893 | { |
| 894 | doze_status = DOZE_DISABLED; |
| 895 | } |
| 896 | #else |
| 897 | if (chip_gt9xxs == 1) |
| 898 | { |
| 899 | gtp_reset_guitar(ts->client, 10); |
| 900 | } |
| 901 | else |
| 902 | { |
| 903 | GTP_GPIO_OUTPUT(GTP_INT_PORT, 1); |
| 904 | msleep(5); |
| 905 | } |
| 906 | #endif |
| 907 | ret = gtp_i2c_test(ts->client); |
| 908 | if (ret > 0) |
| 909 | { |
| 910 | GTP_INFO("GTP wakeup sleep."); |
| 911 | |
| 912 | #if (!GTP_SLIDE_WAKEUP) |
| 913 | if (chip_gt9xxs == 0) |
| 914 | { |
| 915 | gtp_int_sync(25); |
| 916 | msleep(20); |
| 917 | #if GTP_ESD_PROTECT |
| 918 | gtp_init_ext_watchdog(ts->client); |
| 919 | #endif |
| 920 | } |
| 921 | #endif |
| 922 | return ret; |
| 923 | } |
| 924 | gtp_reset_guitar(ts->client, 20); |
| 925 | } |
| 926 | #endif |
| 927 | |
| 928 | GTP_ERROR("GTP wakeup sleep failed."); |
| 929 | return ret; |
| 930 | } |
| 931 | |
| 932 | /******************************************************* |
| 933 | Function: |
| 934 | Initialize gtp. |
| 935 | Input: |
| 936 | ts: goodix private data |
| 937 | Output: |
| 938 | Executive outcomes. |
| 939 | 0: succeed, otherwise: failed |
| 940 | *******************************************************/ |
| 941 | static s32 gtp_init_panel(struct goodix_ts_data *ts) |
| 942 | { |
| 943 | s32 ret = -1; |
| 944 | |
| 945 | #if GTP_DRIVER_SEND_CFG |
| 946 | s32 i; |
| 947 | u8 check_sum = 0; |
| 948 | u8 opr_buf[16]; |
| 949 | u8 sensor_id = 0; |
| 950 | |
| 951 | u8 cfg_info_group1[] = CTP_CFG_GROUP1; |
| 952 | u8 cfg_info_group2[] = CTP_CFG_GROUP2; |
| 953 | u8 cfg_info_group3[] = CTP_CFG_GROUP3; |
| 954 | u8 cfg_info_group4[] = CTP_CFG_GROUP4; |
| 955 | u8 cfg_info_group5[] = CTP_CFG_GROUP5; |
| 956 | u8 cfg_info_group6[] = CTP_CFG_GROUP6; |
| 957 | u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, cfg_info_group3, |
| 958 | cfg_info_group4, cfg_info_group5, cfg_info_group6}; |
| 959 | u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group1), |
| 960 | CFG_GROUP_LEN(cfg_info_group2), |
| 961 | CFG_GROUP_LEN(cfg_info_group3), |
| 962 | CFG_GROUP_LEN(cfg_info_group4), |
| 963 | CFG_GROUP_LEN(cfg_info_group5), |
| 964 | CFG_GROUP_LEN(cfg_info_group6)}; |
| 965 | |
| 966 | GTP_DEBUG("Config Groups\' Lengths: %d, %d, %d, %d, %d, %d", |
| 967 | cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], cfg_info_len[3], |
| 968 | cfg_info_len[4], cfg_info_len[5]); |
| 969 | |
| 970 | ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1); |
| 971 | if (SUCCESS == ret) |
| 972 | { |
| 973 | if (opr_buf[0] != 0xBE) |
| 974 | { |
| 975 | ts->fw_error = 1; |
| 976 | GTP_ERROR("Firmware error, no config sent!"); |
| 977 | return -1; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | if ((!cfg_info_len[1]) && (!cfg_info_len[2]) && |
| 982 | (!cfg_info_len[3]) && (!cfg_info_len[4]) && |
| 983 | (!cfg_info_len[5])) |
| 984 | { |
| 985 | sensor_id = 0; |
| 986 | } |
| 987 | else |
| 988 | { |
| 989 | ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1); |
| 990 | if (SUCCESS == ret) |
| 991 | { |
| 992 | if (sensor_id >= 0x06) |
| 993 | { |
| 994 | GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id); |
| 995 | return -1; |
| 996 | } |
| 997 | } |
| 998 | else |
| 999 | { |
| 1000 | GTP_ERROR("Failed to get sensor_id, No config sent!"); |
| 1001 | return -1; |
| 1002 | } |
| 1003 | } |
| 1004 | GTP_DEBUG("Sensor_ID: %d", sensor_id); |
| 1005 | |
| 1006 | ts->gtp_cfg_len = cfg_info_len[sensor_id]; |
| 1007 | |
| 1008 | if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH) |
| 1009 | { |
| 1010 | GTP_ERROR("Sensor_ID(%d) matches with NULL or INVALID CONFIG GROUP! NO Config Sent! You need to check you header file CFG_GROUP section!", sensor_id); |
| 1011 | return -1; |
| 1012 | } |
| 1013 | |
| 1014 | ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1); |
| 1015 | |
| 1016 | if (ret == SUCCESS) |
| 1017 | { |
| 1018 | GTP_DEBUG("CFG_GROUP%d Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X", sensor_id+1, |
| 1019 | send_cfg_buf[sensor_id][0], send_cfg_buf[sensor_id][0], opr_buf[0], opr_buf[0]); |
| 1020 | |
| 1021 | if (opr_buf[0] < 90) |
| 1022 | { |
| 1023 | grp_cfg_version = send_cfg_buf[sensor_id][0]; // backup group config version |
| 1024 | send_cfg_buf[sensor_id][0] = 0x00; |
| 1025 | ts->fixed_cfg = 0; |
| 1026 | } |
| 1027 | else // treated as fixed config, not send config |
| 1028 | { |
| 1029 | GTP_INFO("Ic fixed config with config version(%d, 0x%02X)", opr_buf[0], opr_buf[0]); |
| 1030 | ts->fixed_cfg = 1; |
| 1031 | } |
| 1032 | } |
| 1033 | else |
| 1034 | { |
| 1035 | GTP_ERROR("Failed to get ic config version!No config sent!"); |
| 1036 | return -1; |
| 1037 | } |
| 1038 | |
| 1039 | memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH); |
| 1040 | memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len); |
| 1041 | |
| 1042 | #if GTP_CUSTOM_CFG |
| 1043 | config[RESOLUTION_LOC] = (u8)GTP_MAX_WIDTH; |
| 1044 | config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8); |
| 1045 | config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT; |
| 1046 | config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8); |
| 1047 | |
| 1048 | if (GTP_INT_TRIGGER == 0) //RISING |
| 1049 | { |
| 1050 | config[TRIGGER_LOC] &= 0xfe; |
| 1051 | } |
| 1052 | else if (GTP_INT_TRIGGER == 1) //FALLING |
| 1053 | { |
| 1054 | config[TRIGGER_LOC] |= 0x01; |
| 1055 | } |
| 1056 | #endif // GTP_CUSTOM_CFG |
| 1057 | |
| 1058 | check_sum = 0; |
| 1059 | for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++) |
| 1060 | { |
| 1061 | check_sum += config[i]; |
| 1062 | } |
| 1063 | config[ts->gtp_cfg_len] = (~check_sum) + 1; |
| 1064 | |
| 1065 | #else // DRIVER NOT SEND CONFIG |
| 1066 | ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH; |
| 1067 | ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH); |
| 1068 | if (ret < 0) |
| 1069 | { |
| 1070 | GTP_ERROR("Read Config Failed, Using Default Resolution & INT Trigger!"); |
| 1071 | ts->abs_x_max = GTP_MAX_WIDTH; |
| 1072 | ts->abs_y_max = GTP_MAX_HEIGHT; |
| 1073 | ts->int_trigger_type = GTP_INT_TRIGGER; |
| 1074 | } |
| 1075 | #endif // GTP_DRIVER_SEND_CFG |
| 1076 | |
| 1077 | GTP_DEBUG_FUNC(); |
| 1078 | if ((ts->abs_x_max == 0) && (ts->abs_y_max == 0)) |
| 1079 | { |
| 1080 | ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC]; |
| 1081 | ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2]; |
| 1082 | ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03; |
| 1083 | } |
| 1084 | ret = gtp_send_cfg(ts->client); |
| 1085 | if (ret < 0) |
| 1086 | { |
| 1087 | GTP_ERROR("Send config error."); |
| 1088 | } |
| 1089 | GTP_DEBUG("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x", |
| 1090 | ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type); |
| 1091 | |
| 1092 | msleep(10); |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
| 1096 | /******************************************************* |
| 1097 | Function: |
| 1098 | Read chip version. |
| 1099 | Input: |
| 1100 | client: i2c device |
| 1101 | version: buffer to keep ic firmware version |
| 1102 | Output: |
| 1103 | read operation return. |
| 1104 | 2: succeed, otherwise: failed |
| 1105 | *******************************************************/ |
| 1106 | s32 gtp_read_version(struct i2c_client *client, u16* version) |
| 1107 | { |
| 1108 | s32 ret = -1; |
| 1109 | u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff}; |
| 1110 | |
| 1111 | GTP_DEBUG_FUNC(); |
| 1112 | |
| 1113 | ret = gtp_i2c_read(client, buf, sizeof(buf)); |
| 1114 | if (ret < 0) |
| 1115 | { |
| 1116 | GTP_ERROR("GTP read version failed"); |
| 1117 | return ret; |
| 1118 | } |
| 1119 | |
| 1120 | if (version) |
| 1121 | { |
| 1122 | *version = (buf[7] << 8) | buf[6]; |
| 1123 | } |
| 1124 | |
| 1125 | if (buf[5] == 0x00) |
| 1126 | { |
| 1127 | GTP_INFO("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]); |
| 1128 | } |
| 1129 | else |
| 1130 | { |
| 1131 | if (buf[5] == 'S' || buf[5] == 's') |
| 1132 | { |
| 1133 | chip_gt9xxs = 1; |
| 1134 | } |
| 1135 | GTP_INFO("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]); |
| 1136 | } |
| 1137 | return ret; |
| 1138 | } |
| 1139 | |
| 1140 | /******************************************************* |
| 1141 | Function: |
| 1142 | I2c test Function. |
| 1143 | Input: |
| 1144 | client:i2c client. |
| 1145 | Output: |
| 1146 | Executive outcomes. |
| 1147 | 2: succeed, otherwise failed. |
| 1148 | *******************************************************/ |
| 1149 | static s8 gtp_i2c_test(struct i2c_client *client) |
| 1150 | { |
| 1151 | u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff}; |
| 1152 | u8 retry = 0; |
| 1153 | s8 ret = -1; |
| 1154 | |
| 1155 | GTP_DEBUG_FUNC(); |
| 1156 | |
| 1157 | while(retry++ < 5) |
| 1158 | { |
| 1159 | ret = gtp_i2c_read(client, test, 3); |
| 1160 | if (ret > 0) |
| 1161 | { |
| 1162 | return ret; |
| 1163 | } |
| 1164 | GTP_ERROR("GTP i2c test failed time %d.",retry); |
| 1165 | msleep(10); |
| 1166 | } |
| 1167 | return ret; |
| 1168 | } |
| 1169 | |
| 1170 | /******************************************************* |
| 1171 | Function: |
| 1172 | Request gpio(INT & RST) ports. |
| 1173 | Input: |
| 1174 | ts: private data. |
| 1175 | Output: |
| 1176 | Executive outcomes. |
| 1177 | >= 0: succeed, < 0: failed |
| 1178 | *******************************************************/ |
| 1179 | static s8 gtp_request_io_port(struct goodix_ts_data *ts) |
| 1180 | { |
| 1181 | s32 ret = 0; |
| 1182 | |
| 1183 | ret = GTP_GPIO_REQUEST(GTP_INT_PORT, "GTP_INT_IRQ"); |
| 1184 | if (ret < 0) |
| 1185 | { |
| 1186 | GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d", (s32)GTP_INT_PORT, ret); |
| 1187 | ret = -ENODEV; |
| 1188 | } |
| 1189 | else |
| 1190 | { |
| 1191 | GTP_GPIO_AS_INT(GTP_INT_PORT); |
| 1192 | ts->client->irq = GTP_INT_IRQ; |
| 1193 | } |
| 1194 | |
| 1195 | ret = GTP_GPIO_REQUEST(GTP_RST_PORT, "GTP_RST_PORT"); |
| 1196 | if (ret < 0) |
| 1197 | { |
| 1198 | GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d",(s32)GTP_RST_PORT,ret); |
| 1199 | ret = -ENODEV; |
| 1200 | } |
| 1201 | |
| 1202 | GTP_GPIO_AS_INPUT(GTP_RST_PORT); |
| 1203 | gtp_reset_guitar(ts->client, 20); |
| 1204 | |
| 1205 | |
| 1206 | if(ret < 0) |
| 1207 | { |
| 1208 | GTP_GPIO_FREE(GTP_RST_PORT); |
| 1209 | GTP_GPIO_FREE(GTP_INT_PORT); |
| 1210 | } |
| 1211 | |
| 1212 | return ret; |
| 1213 | } |
| 1214 | |
| 1215 | /******************************************************* |
| 1216 | Function: |
| 1217 | Request interrupt. |
| 1218 | Input: |
| 1219 | ts: private data. |
| 1220 | Output: |
| 1221 | Executive outcomes. |
| 1222 | 0: succeed, -1: failed. |
| 1223 | *******************************************************/ |
| 1224 | static s8 gtp_request_irq(struct goodix_ts_data *ts) |
| 1225 | { |
| 1226 | s32 ret = -1; |
| 1227 | const u8 irq_table[] = GTP_IRQ_TAB; |
| 1228 | |
| 1229 | GTP_DEBUG("INT trigger type:%x", ts->int_trigger_type); |
| 1230 | |
| 1231 | ret = request_irq(ts->client->irq, |
| 1232 | goodix_ts_irq_handler, |
| 1233 | irq_table[ts->int_trigger_type], |
| 1234 | ts->client->name, |
| 1235 | ts); |
| 1236 | if (ret) |
| 1237 | { |
| 1238 | GTP_ERROR("Request IRQ failed!ERRNO:%d.", ret); |
| 1239 | GTP_GPIO_AS_INPUT(GTP_INT_PORT); |
| 1240 | GTP_GPIO_FREE(GTP_INT_PORT); |
| 1241 | |
| 1242 | hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 1243 | ts->timer.function = goodix_ts_timer_handler; |
| 1244 | hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL); |
| 1245 | return -1; |
| 1246 | } |
| 1247 | else |
| 1248 | { |
| 1249 | gtp_irq_disable(ts); |
| 1250 | ts->use_irq = 1; |
| 1251 | return 0; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | /******************************************************* |
| 1256 | Function: |
| 1257 | Request input device Function. |
| 1258 | Input: |
| 1259 | ts:private data. |
| 1260 | Output: |
| 1261 | Executive outcomes. |
| 1262 | 0: succeed, otherwise: failed. |
| 1263 | *******************************************************/ |
| 1264 | static s8 gtp_request_input_dev(struct goodix_ts_data *ts) |
| 1265 | { |
| 1266 | s8 ret = -1; |
| 1267 | s8 phys[32]; |
| 1268 | #if GTP_HAVE_TOUCH_KEY |
| 1269 | u8 index = 0; |
| 1270 | #endif |
| 1271 | |
| 1272 | GTP_DEBUG_FUNC(); |
| 1273 | |
| 1274 | ts->input_dev = input_allocate_device(); |
| 1275 | if (ts->input_dev == NULL) |
| 1276 | { |
| 1277 | GTP_ERROR("Failed to allocate input device."); |
| 1278 | return -ENOMEM; |
| 1279 | } |
| 1280 | |
| 1281 | ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ; |
| 1282 | #if GTP_ICS_SLOT_REPORT |
| 1283 | __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); |
| 1284 | input_mt_init_slots(ts->input_dev, 10); // in case of "out of memory" |
| 1285 | #else |
| 1286 | ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
| 1287 | #endif |
| 1288 | |
| 1289 | #if GTP_HAVE_TOUCH_KEY |
| 1290 | for (index = 0; index < GTP_MAX_KEY_NUM; index++) |
| 1291 | { |
| 1292 | input_set_capability(ts->input_dev, EV_KEY, touch_key_array[index]); |
| 1293 | } |
| 1294 | #endif |
| 1295 | |
| 1296 | #if GTP_SLIDE_WAKEUP |
| 1297 | input_set_capability(ts->input_dev, EV_KEY, KEY_POWER); |
| 1298 | #endif |
| 1299 | |
| 1300 | #if GTP_WITH_PEN |
| 1301 | // pen support |
| 1302 | __set_bit(BTN_TOOL_PEN, ts->input_dev->keybit); |
| 1303 | __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit); |
| 1304 | __set_bit(INPUT_PROP_POINTER, ts->input_dev->propbit); |
| 1305 | #endif |
| 1306 | |
| 1307 | #if GTP_CHANGE_X2Y |
| 1308 | GTP_SWAP(ts->abs_x_max, ts->abs_y_max); |
| 1309 | #endif |
| 1310 | |
| 1311 | input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0); |
| 1312 | input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0); |
| 1313 | input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0); |
| 1314 | input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); |
| 1315 | input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0); |
| 1316 | |
| 1317 | sprintf(phys, "input/ts"); |
| 1318 | ts->input_dev->name = goodix_ts_name; |
| 1319 | ts->input_dev->phys = phys; |
| 1320 | ts->input_dev->id.bustype = BUS_I2C; |
| 1321 | ts->input_dev->id.vendor = 0xDEAD; |
| 1322 | ts->input_dev->id.product = 0xBEEF; |
| 1323 | ts->input_dev->id.version = 10427; |
| 1324 | |
| 1325 | ret = input_register_device(ts->input_dev); |
| 1326 | if (ret) |
| 1327 | { |
| 1328 | GTP_ERROR("Register %s input device failed", ts->input_dev->name); |
| 1329 | return -ENODEV; |
| 1330 | } |
| 1331 | |
| 1332 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 1333 | ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1; |
| 1334 | ts->early_suspend.suspend = goodix_ts_early_suspend; |
| 1335 | ts->early_suspend.resume = goodix_ts_late_resume; |
| 1336 | register_early_suspend(&ts->early_suspend); |
| 1337 | #endif |
| 1338 | |
| 1339 | return 0; |
| 1340 | } |
| 1341 | |
| 1342 | /******************************************************* |
| 1343 | Function: |
| 1344 | I2c probe. |
| 1345 | Input: |
| 1346 | client: i2c device struct. |
| 1347 | id: device id. |
| 1348 | Output: |
| 1349 | Executive outcomes. |
| 1350 | 0: succeed. |
| 1351 | *******************************************************/ |
| 1352 | static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id) |
| 1353 | { |
| 1354 | s32 ret = -1; |
| 1355 | struct goodix_ts_data *ts; |
| 1356 | u16 version_info; |
| 1357 | |
| 1358 | GTP_DEBUG_FUNC(); |
| 1359 | |
| 1360 | //do NOT remove these logs |
| 1361 | GTP_INFO("GTP Driver Version: %s", GTP_DRIVER_VERSION); |
| 1362 | GTP_INFO("GTP Driver Built@%s, %s", __TIME__, __DATE__); |
| 1363 | GTP_INFO("GTP I2C Address: 0x%02x", client->addr); |
| 1364 | |
| 1365 | i2c_connect_client = client; |
| 1366 | |
| 1367 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) |
| 1368 | { |
| 1369 | GTP_ERROR("I2C check functionality failed."); |
| 1370 | return -ENODEV; |
| 1371 | } |
| 1372 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); |
| 1373 | if (ts == NULL) |
| 1374 | { |
| 1375 | GTP_ERROR("Alloc GFP_KERNEL memory failed."); |
| 1376 | return -ENOMEM; |
| 1377 | } |
| 1378 | |
| 1379 | memset(ts, 0, sizeof(*ts)); |
| 1380 | INIT_WORK(&ts->work, goodix_ts_work_func); |
| 1381 | ts->client = client; |
| 1382 | spin_lock_init(&ts->irq_lock); // 2.6.39 later |
| 1383 | // ts->irq_lock = SPIN_LOCK_UNLOCKED; // 2.6.39 & before |
| 1384 | i2c_set_clientdata(client, ts); |
| 1385 | |
| 1386 | ts->gtp_rawdiff_mode = 0; |
| 1387 | |
| 1388 | ret = gtp_request_io_port(ts); |
| 1389 | if (ret < 0) |
| 1390 | { |
| 1391 | GTP_ERROR("GTP request IO port failed."); |
| 1392 | kfree(ts); |
| 1393 | return ret; |
| 1394 | } |
| 1395 | |
| 1396 | ret = gtp_i2c_test(client); |
| 1397 | if (ret < 0) |
| 1398 | { |
| 1399 | GTP_ERROR("I2C communication ERROR!"); |
| 1400 | } |
| 1401 | |
| 1402 | #if GTP_AUTO_UPDATE |
| 1403 | ret = gup_init_update_proc(ts); |
| 1404 | if (ret < 0) |
| 1405 | { |
| 1406 | GTP_ERROR("Create update thread error."); |
| 1407 | } |
| 1408 | #endif |
| 1409 | |
| 1410 | ret = gtp_init_panel(ts); |
| 1411 | if (ret < 0) |
| 1412 | { |
| 1413 | GTP_ERROR("GTP init panel failed."); |
| 1414 | ts->abs_x_max = GTP_MAX_WIDTH; |
| 1415 | ts->abs_y_max = GTP_MAX_HEIGHT; |
| 1416 | ts->int_trigger_type = GTP_INT_TRIGGER; |
| 1417 | } |
| 1418 | |
| 1419 | ret = gtp_request_input_dev(ts); |
| 1420 | if (ret < 0) |
| 1421 | { |
| 1422 | GTP_ERROR("GTP request input dev failed"); |
| 1423 | } |
| 1424 | |
| 1425 | ret = gtp_request_irq(ts); |
| 1426 | if (ret < 0) |
| 1427 | { |
| 1428 | GTP_INFO("GTP works in polling mode."); |
| 1429 | } |
| 1430 | else |
| 1431 | { |
| 1432 | GTP_INFO("GTP works in interrupt mode."); |
| 1433 | } |
| 1434 | |
| 1435 | ret = gtp_read_version(client, &version_info); |
| 1436 | if (ret < 0) |
| 1437 | { |
| 1438 | GTP_ERROR("Read version failed."); |
| 1439 | } |
| 1440 | if (ts->use_irq) |
| 1441 | { |
| 1442 | gtp_irq_enable(ts); |
| 1443 | } |
| 1444 | |
| 1445 | #if GTP_CREATE_WR_NODE |
| 1446 | init_wr_node(client); |
| 1447 | #endif |
| 1448 | |
| 1449 | #if GTP_ESD_PROTECT |
| 1450 | gtp_esd_switch(client, SWITCH_ON); |
| 1451 | #endif |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
| 1455 | |
| 1456 | /******************************************************* |
| 1457 | Function: |
| 1458 | Goodix touchscreen driver release function. |
| 1459 | Input: |
| 1460 | client: i2c device struct. |
| 1461 | Output: |
| 1462 | Executive outcomes. 0---succeed. |
| 1463 | *******************************************************/ |
| 1464 | static int goodix_ts_remove(struct i2c_client *client) |
| 1465 | { |
| 1466 | struct goodix_ts_data *ts = i2c_get_clientdata(client); |
| 1467 | |
| 1468 | GTP_DEBUG_FUNC(); |
| 1469 | |
| 1470 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 1471 | unregister_early_suspend(&ts->early_suspend); |
| 1472 | #endif |
| 1473 | |
| 1474 | #if GTP_CREATE_WR_NODE |
| 1475 | uninit_wr_node(); |
| 1476 | #endif |
| 1477 | |
| 1478 | #if GTP_ESD_PROTECT |
| 1479 | destroy_workqueue(gtp_esd_check_workqueue); |
| 1480 | #endif |
| 1481 | |
| 1482 | if (ts) |
| 1483 | { |
| 1484 | if (ts->use_irq) |
| 1485 | { |
| 1486 | GTP_GPIO_AS_INPUT(GTP_INT_PORT); |
| 1487 | GTP_GPIO_FREE(GTP_INT_PORT); |
| 1488 | free_irq(client->irq, ts); |
| 1489 | } |
| 1490 | else |
| 1491 | { |
| 1492 | hrtimer_cancel(&ts->timer); |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | GTP_INFO("GTP driver removing..."); |
| 1497 | i2c_set_clientdata(client, NULL); |
| 1498 | input_unregister_device(ts->input_dev); |
| 1499 | kfree(ts); |
| 1500 | |
| 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | #ifdef CONFIG_HAS_EARLYSUSPEND |
| 1505 | /******************************************************* |
| 1506 | Function: |
| 1507 | Early suspend function. |
| 1508 | Input: |
| 1509 | h: early_suspend struct. |
| 1510 | Output: |
| 1511 | None. |
| 1512 | *******************************************************/ |
| 1513 | static void goodix_ts_early_suspend(struct early_suspend *h) |
| 1514 | { |
| 1515 | struct goodix_ts_data *ts; |
| 1516 | s8 ret = -1; |
| 1517 | ts = container_of(h, struct goodix_ts_data, early_suspend); |
| 1518 | |
| 1519 | GTP_DEBUG_FUNC(); |
| 1520 | |
| 1521 | #if GTP_ESD_PROTECT |
| 1522 | ts->gtp_is_suspend = 1; |
| 1523 | gtp_esd_switch(ts->client, SWITCH_OFF); |
| 1524 | #endif |
| 1525 | |
| 1526 | #if GTP_SLIDE_WAKEUP |
| 1527 | ret = gtp_enter_doze(ts); |
| 1528 | #else |
| 1529 | if (ts->use_irq) |
| 1530 | { |
| 1531 | gtp_irq_disable(ts); |
| 1532 | } |
| 1533 | else |
| 1534 | { |
| 1535 | hrtimer_cancel(&ts->timer); |
| 1536 | } |
| 1537 | ret = gtp_enter_sleep(ts); |
| 1538 | #endif |
| 1539 | if (ret < 0) |
| 1540 | { |
| 1541 | GTP_ERROR("GTP early suspend failed."); |
| 1542 | } |
| 1543 | // to avoid waking up while not sleeping |
| 1544 | // delay 48 + 10ms to ensure reliability |
| 1545 | msleep(58); |
| 1546 | } |
| 1547 | |
| 1548 | /******************************************************* |
| 1549 | Function: |
| 1550 | Late resume function. |
| 1551 | Input: |
| 1552 | h: early_suspend struct. |
| 1553 | Output: |
| 1554 | None. |
| 1555 | *******************************************************/ |
| 1556 | static void goodix_ts_late_resume(struct early_suspend *h) |
| 1557 | { |
| 1558 | struct goodix_ts_data *ts; |
| 1559 | s8 ret = -1; |
| 1560 | ts = container_of(h, struct goodix_ts_data, early_suspend); |
| 1561 | |
| 1562 | GTP_DEBUG_FUNC(); |
| 1563 | |
| 1564 | ret = gtp_wakeup_sleep(ts); |
| 1565 | |
| 1566 | #if GTP_SLIDE_WAKEUP |
| 1567 | doze_status = DOZE_DISABLED; |
| 1568 | #endif |
| 1569 | |
| 1570 | if (ret < 0) |
| 1571 | { |
| 1572 | GTP_ERROR("GTP later resume failed."); |
| 1573 | } |
| 1574 | |
| 1575 | if (ts->use_irq) |
| 1576 | { |
| 1577 | gtp_irq_enable(ts); |
| 1578 | } |
| 1579 | else |
| 1580 | { |
| 1581 | hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL); |
| 1582 | } |
| 1583 | |
| 1584 | #if GTP_ESD_PROTECT |
| 1585 | ts->gtp_is_suspend = 0; |
| 1586 | gtp_esd_switch(ts->client, SWITCH_ON); |
| 1587 | #endif |
| 1588 | } |
| 1589 | #endif |
| 1590 | |
| 1591 | #if GTP_ESD_PROTECT |
| 1592 | /******************************************************* |
| 1593 | Function: |
| 1594 | switch on & off esd delayed work |
| 1595 | Input: |
| 1596 | client: i2c device |
| 1597 | on: SWITCH_ON / SWITCH_OFF |
| 1598 | Output: |
| 1599 | void |
| 1600 | *********************************************************/ |
| 1601 | void gtp_esd_switch(struct i2c_client *client, s32 on) |
| 1602 | { |
| 1603 | struct goodix_ts_data *ts; |
| 1604 | |
| 1605 | ts = i2c_get_clientdata(client); |
| 1606 | if (SWITCH_ON == on) // switch on esd |
| 1607 | { |
| 1608 | if (!ts->esd_running) |
| 1609 | { |
| 1610 | ts->esd_running = 1; |
| 1611 | GTP_INFO("Esd started"); |
| 1612 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); |
| 1613 | } |
| 1614 | } |
| 1615 | else // switch off esd |
| 1616 | { |
| 1617 | if (ts->esd_running) |
| 1618 | { |
| 1619 | ts->esd_running = 0; |
| 1620 | GTP_INFO("Esd cancelled"); |
| 1621 | cancel_delayed_work_sync(>p_esd_check_work); |
| 1622 | } |
| 1623 | } |
| 1624 | } |
| 1625 | |
| 1626 | /******************************************************* |
| 1627 | Function: |
| 1628 | Initialize external watchdog for esd protect |
| 1629 | Input: |
| 1630 | client: i2c device. |
| 1631 | Output: |
| 1632 | result of i2c write operation. |
| 1633 | 1: succeed, otherwise: failed |
| 1634 | *********************************************************/ |
| 1635 | static s32 gtp_init_ext_watchdog(struct i2c_client *client) |
| 1636 | { |
| 1637 | u8 opr_buffer[4] = {0x80, 0x40, 0xAA, 0xAA}; |
| 1638 | |
| 1639 | struct i2c_msg msg; // in case of recursively reset by calling gtp_i2c_write |
| 1640 | s32 ret = -1; |
| 1641 | s32 retries = 0; |
| 1642 | |
| 1643 | GTP_DEBUG("Init external watchdog..."); |
| 1644 | GTP_DEBUG_FUNC(); |
| 1645 | |
| 1646 | msg.flags = !I2C_M_RD; |
| 1647 | msg.addr = client->addr; |
| 1648 | msg.len = 4; |
| 1649 | msg.buf = opr_buffer; |
| 1650 | |
| 1651 | while(retries < 5) |
| 1652 | { |
| 1653 | ret = i2c_transfer(client->adapter, &msg, 1); |
| 1654 | if (ret == 1) |
| 1655 | { |
| 1656 | return 1; |
| 1657 | } |
| 1658 | retries++; |
| 1659 | } |
| 1660 | if (retries >= 5) |
| 1661 | { |
| 1662 | GTP_ERROR("init external watchdog failed!"); |
| 1663 | } |
| 1664 | return 0; |
| 1665 | } |
| 1666 | |
| 1667 | /******************************************************* |
| 1668 | Function: |
| 1669 | Esd protect function. |
| 1670 | Added external watchdog by meta, 2013/03/07 |
| 1671 | Input: |
| 1672 | work: delayed work |
| 1673 | Output: |
| 1674 | None. |
| 1675 | *******************************************************/ |
| 1676 | static void gtp_esd_check_func(struct work_struct *work) |
| 1677 | { |
| 1678 | s32 i; |
| 1679 | s32 ret = -1; |
| 1680 | struct goodix_ts_data *ts = NULL; |
| 1681 | u8 test[4] = {0x80, 0x40}; |
| 1682 | |
| 1683 | GTP_DEBUG_FUNC(); |
| 1684 | |
| 1685 | ts = i2c_get_clientdata(i2c_connect_client); |
| 1686 | |
| 1687 | if (ts->gtp_is_suspend) |
| 1688 | { |
| 1689 | ts->esd_running = 0; |
| 1690 | GTP_INFO("Esd terminated!"); |
| 1691 | return; |
| 1692 | } |
| 1693 | |
| 1694 | for (i = 0; i < 3; i++) |
| 1695 | { |
| 1696 | ret = gtp_i2c_read(ts->client, test, 4); |
| 1697 | |
| 1698 | GTP_DEBUG("0x8040 = 0x%02X, 0x8041 = 0x%02X", test[2], test[3]); |
| 1699 | if ((ret < 0)) |
| 1700 | { |
| 1701 | // IIC communication problem |
| 1702 | continue; |
| 1703 | } |
| 1704 | else |
| 1705 | { |
| 1706 | if ((test[2] == 0xAA) || (test[3] != 0xAA)) |
| 1707 | { |
| 1708 | // IC works abnormally.. |
| 1709 | i = 3; |
| 1710 | break; |
| 1711 | } |
| 1712 | else |
| 1713 | { |
| 1714 | // IC works normally, Write 0x8040 0xAA, feed the dog |
| 1715 | test[2] = 0xAA; |
| 1716 | gtp_i2c_write(ts->client, test, 3); |
| 1717 | break; |
| 1718 | } |
| 1719 | } |
| 1720 | } |
| 1721 | if (i >= 3) |
| 1722 | { |
| 1723 | GTP_ERROR("IC Working ABNORMALLY, Resetting Guitar..."); |
| 1724 | gtp_reset_guitar(ts->client, 50); |
| 1725 | } |
| 1726 | |
| 1727 | if(!ts->gtp_is_suspend) |
| 1728 | { |
| 1729 | queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE); |
| 1730 | } |
| 1731 | else |
| 1732 | { |
| 1733 | GTP_INFO("Esd terminated!"); |
| 1734 | ts->esd_running = 0; |
| 1735 | } |
| 1736 | return; |
| 1737 | } |
| 1738 | #endif |
| 1739 | |
| 1740 | static const struct i2c_device_id goodix_ts_id[] = { |
| 1741 | { GTP_I2C_NAME, 0 }, |
| 1742 | { } |
| 1743 | }; |
| 1744 | |
| 1745 | static struct i2c_driver goodix_ts_driver = { |
| 1746 | .probe = goodix_ts_probe, |
| 1747 | .remove = goodix_ts_remove, |
| 1748 | #ifndef CONFIG_HAS_EARLYSUSPEND |
| 1749 | .suspend = goodix_ts_early_suspend, |
| 1750 | .resume = goodix_ts_late_resume, |
| 1751 | #endif |
| 1752 | .id_table = goodix_ts_id, |
| 1753 | .driver = { |
| 1754 | .name = GTP_I2C_NAME, |
| 1755 | .owner = THIS_MODULE, |
| 1756 | }, |
| 1757 | }; |
| 1758 | |
| 1759 | /******************************************************* |
| 1760 | Function: |
| 1761 | Driver Install function. |
| 1762 | Input: |
| 1763 | None. |
| 1764 | Output: |
| 1765 | Executive Outcomes. 0---succeed. |
| 1766 | ********************************************************/ |
| 1767 | static int __devinit goodix_ts_init(void) |
| 1768 | { |
| 1769 | s32 ret; |
| 1770 | |
| 1771 | GTP_DEBUG_FUNC(); |
| 1772 | GTP_INFO("GTP driver installing..."); |
| 1773 | goodix_wq = create_singlethread_workqueue("goodix_wq"); |
| 1774 | if (!goodix_wq) |
| 1775 | { |
| 1776 | GTP_ERROR("Creat workqueue failed."); |
| 1777 | return -ENOMEM; |
| 1778 | } |
| 1779 | #if GTP_ESD_PROTECT |
| 1780 | INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func); |
| 1781 | gtp_esd_check_workqueue = create_workqueue("gtp_esd_check"); |
| 1782 | #endif |
| 1783 | ret = i2c_add_driver(&goodix_ts_driver); |
| 1784 | return ret; |
| 1785 | } |
| 1786 | |
| 1787 | /******************************************************* |
| 1788 | Function: |
| 1789 | Driver uninstall function. |
| 1790 | Input: |
| 1791 | None. |
| 1792 | Output: |
| 1793 | Executive Outcomes. 0---succeed. |
| 1794 | ********************************************************/ |
| 1795 | static void __exit goodix_ts_exit(void) |
| 1796 | { |
| 1797 | GTP_DEBUG_FUNC(); |
| 1798 | GTP_INFO("GTP driver exited."); |
| 1799 | i2c_del_driver(&goodix_ts_driver); |
| 1800 | if (goodix_wq) |
| 1801 | { |
| 1802 | destroy_workqueue(goodix_wq); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | late_initcall(goodix_ts_init); |
| 1807 | module_exit(goodix_ts_exit); |
| 1808 | |
| 1809 | MODULE_DESCRIPTION("GTP Series Driver"); |
| 1810 | MODULE_LICENSE("GPL"); |