触摸屏GT9xx移植

转载地址:http://blog.csdn.net/mike8825/article/details/50357717

下载GT9xx的源码http://download.csdn.net/detail/u012724126/6506027

解压并编写Makefile文件,gt9xx.c的源码并不需要修改,gt9xx.h需根据平台和触摸屏进行一定的修改。

gt9xx.c的内容为

  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.         u8 report_num = 0;  
  558.   
  559.         coor_data = &point_data[3];  
  560.           
  561.         if(touch_num)  
  562.         {  
  563.             id = coor_data[pos] & 0x0F;  
  564.           
  565.         #if GTP_WITH_PEN  
  566.             id = coor_data[pos];  
  567.             if ((id == 128))    
  568.             {  
  569.                 GTP_DEBUG("Pen touch DOWN(Slot)!");  
  570.                 input_x  = coor_data[pos + 1] | (coor_data[pos + 2] << 8);  
  571.                 input_y  = coor_data[pos + 3] | (coor_data[pos + 4] << 8);  
  572.                 input_w  = coor_data[pos + 5] | (coor_data[pos + 6] << 8);  
  573.                   
  574.                 input_report_key(ts->input_dev, BTN_TOOL_PEN, 1);  
  575.                 input_mt_slot(ts->input_dev, 5);  
  576.                 input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, 5);  
  577.                 input_report_abs(ts->input_dev, ABS_MT_POSITION_X, input_x);  
  578.                 input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, input_y);  
  579.                 input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, input_w);  
  580.                 GTP_DEBUG("Pen/Stylus: (%d, %d)[%d]", input_x, input_y, input_w);  
  581.                 pre_pen = 1;  
  582.                 pre_touch = 0;  
  583.             }      
  584.         #endif  
  585.           
  586.             touch_index |= (0x01<<id);  
  587.         }  
  588.           
  589.         GTP_DEBUG("id = %d,touch_index = 0x%x, pre_touch = 0x%x\n",id, touch_index,pre_touch);  
  590.         for (i = 0; i < GTP_MAX_TOUCH; i++)  
  591.         {  
  592.         #if GTP_WITH_PEN  
  593.             if (pre_pen == 1)  
  594.             {  
  595.                 break;  
  596.             }  
  597.         #endif  
  598.           
  599.             if (touch_index & (0x01<<i))  
  600.             {  
  601.                 input_x  = coor_data[pos + 1] | (coor_data[pos + 2] << 8);  
  602.                 input_y  = coor_data[pos + 3] | (coor_data[pos + 4] << 8);  
  603.                 input_w  = coor_data[pos + 5] | (coor_data[pos + 6] << 8);  
  604.   
  605.                 gtp_touch_down(ts, id, input_x, input_y, input_w);  
  606.                 report_num++;  
  607.                 pre_touch |= 0x01 << i;  
  608.                   
  609.                 if(report_num < touch_num)  
  610.                 {  
  611.                     pos += 8;  
  612.                     id = coor_data[pos] & 0x0F;  
  613.                     touch_index |= (0x01<<id);  
  614.                 }  
  615.             }  
  616.             else  
  617.             {  
  618.                 gtp_touch_up(ts, i);  
  619.                 pre_touch &= ~(0x01 << i);  
  620.             }  
  621.         }  
  622.     }  
  623. #else  
  624.     input_report_key(ts->input_dev, BTN_TOUCH, (touch_num || key_value));  
  625.     if (touch_num)  
  626.     {  
  627.         for (i = 0; i < touch_num; i++)  
  628.         {  
  629.             coor_data = &point_data[i * 8 + 3];  
  630.   
  631.             id = coor_data[0];      //  & 0x0F;  
  632.             input_x  = coor_data[1] | (coor_data[2] << 8);  
  633.             input_y  = coor_data[3] | (coor_data[4] << 8);  
  634.             input_w  = coor_data[5] | (coor_data[6] << 8);  
  635.           
  636.         #if GTP_WITH_PEN  
  637.             if (id == 128)  
  638.             {  
  639.                 GTP_DEBUG("Pen touch DOWN!");  
  640.                 input_report_key(ts->input_dev, BTN_TOOL_PEN, 1);  
  641.                 pre_pen = 1;  
  642.                 id = 0;     
  643.             }  
  644.         #endif  
  645.           
  646.             gtp_touch_down(ts, id, input_x, input_y, input_w);  
  647.         }  
  648.     }  
  649.     else if (pre_touch)  
  650.     {  
  651.       
  652.     #if GTP_WITH_PEN  
  653.         if (pre_pen == 1)  
  654.         {  
  655.             GTP_DEBUG("Pen touch UP!");  
  656.             input_report_key(ts->input_dev, BTN_TOOL_PEN, 0);  
  657.             pre_pen = 0;  
  658.         }  
  659.     #endif  
  660.       
  661.         GTP_DEBUG("Touch Release!");  
  662.         gtp_touch_up(ts, 0);  
  663.     }  
  664.   
  665.     pre_touch = touch_num;  
  666. #endif  
  667.   
  668.     input_sync(ts->input_dev);  
  669.   
  670. exit_work_func:  
  671.     if(!ts->gtp_rawdiff_mode)  
  672.     {  
  673.         ret = gtp_i2c_write(ts->client, end_cmd, 3);  
  674.         if (ret < 0)  
  675.         {  
  676.             GTP_INFO("I2C write end_cmd error!");  
  677.         }  
  678.     }  
  679.     if (ts->use_irq)  
  680.     {  
  681.         gtp_irq_enable(ts);  
  682.     }  
  683. }  
  684.   
  685. /*******************************************************  
  686. Function:  
  687.     Timer interrupt service routine for polling mode.  
  688. Input:  
  689.     timer: timer struct pointer  
  690. Output:  
  691.     Timer work mode.   
  692.         HRTIMER_NORESTART: no restart mode  
  693. *********************************************************/  
  694. static enum hrtimer_restart goodix_ts_timer_handler(struct hrtimer *timer)  
  695. {  
  696.     struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer);  
  697.   
  698.     GTP_DEBUG_FUNC();  
  699.   
  700.     queue_work(goodix_wq, &ts->work);  
  701.     hrtimer_start(&ts->timer, ktime_set(0, (GTP_POLL_TIME+6)*1000000), HRTIMER_MODE_REL);  
  702.     return HRTIMER_NORESTART;  
  703. }  
  704.   
  705. /*******************************************************  
  706. Function:  
  707.     External interrupt service routine for interrupt mode.  
  708. Input:  
  709.     irq:  interrupt number.  
  710.     dev_id: private data pointer  
  711. Output:  
  712.     Handle Result.  
  713.         IRQ_HANDLED: interrupt handled successfully  
  714. *********************************************************/  
  715. static irqreturn_t goodix_ts_irq_handler(int irq, void *dev_id)  
  716. {  
  717.     struct goodix_ts_data *ts = dev_id;  
  718.   
  719.     GTP_DEBUG_FUNC();  
  720.    
  721.     gtp_irq_disable(ts);  
  722.   
  723.     queue_work(goodix_wq, &ts->work);  
  724.       
  725.     return IRQ_HANDLED;  
  726. }  
  727. /*******************************************************  
  728. Function:  
  729.     Synchronization.  
  730. Input:  
  731.     ms: synchronization time in millisecond.  
  732. Output:  
  733.     None.  
  734. *******************************************************/  
  735. void gtp_int_sync(s32 ms)  
  736. {  
  737.     GTP_GPIO_OUTPUT(GTP_INT_PORT, 0);  
  738.     msleep(ms);  
  739.     GTP_GPIO_AS_INT(GTP_INT_PORT);  
  740. }  
  741.   
  742. /*******************************************************  
  743. Function:  
  744.     Reset chip.  
  745. Input:  
  746.     ms: reset time in millisecond  
  747. Output:  
  748.     None.  
  749. *******************************************************/  
  750. void gtp_reset_guitar(struct i2c_client *client, s32 ms)  
  751. {  
  752.     GTP_DEBUG_FUNC();  
  753.   
  754.     GTP_GPIO_OUTPUT(GTP_RST_PORT, 0);   // begin select I2C slave addr  
  755.     msleep(ms);                         // T2: > 10ms  
  756.     // HIGH: 0x28/0x29, LOW: 0xBA/0xBB  
  757.     GTP_GPIO_OUTPUT(GTP_INT_PORT, client->addr == 0x14);  
  758.   
  759.     msleep(2);                          // T3: > 100us  
  760.     GTP_GPIO_OUTPUT(GTP_RST_PORT, 1);  
  761.       
  762.     msleep(6);                          // T4: > 5ms  
  763.   
  764.     GTP_GPIO_AS_INPUT(GTP_RST_PORT);    // end select I2C slave addr  
  765.   
  766.     gtp_int_sync(50);                    
  767.       
  768. #if GTP_ESD_PROTECT  
  769.     gtp_init_ext_watchdog(client);  
  770. #endif  
  771. }  
  772.   
  773. #if GTP_SLIDE_WAKEUP  
  774. /*******************************************************  
  775. Function:  
  776.     Enter doze mode for sliding wakeup.  
  777. Input:  
  778.     ts: goodix tp private data  
  779. Output:  
  780.     1: succeed, otherwise failed  
  781. *******************************************************/  
  782. static s8 gtp_enter_doze(struct goodix_ts_data *ts)  
  783. {  
  784.     s8 ret = -1;  
  785.     s8 retry = 0;  
  786.     u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 8};  
  787.   
  788.     GTP_DEBUG_FUNC();  
  789.   
  790. #if GTP_DBL_CLK_WAKEUP  
  791.     i2c_control_buf[2] = 0x09;  
  792. #endif  
  793.   
  794.     gtp_irq_disable(ts);  
  795.       
  796.     GTP_DEBUG("entering doze mode...");  
  797.     while(retry++ < 5)  
  798.     {  
  799.         i2c_control_buf[0] = 0x80;  
  800.         i2c_control_buf[1] = 0x46;  
  801.         ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);  
  802.         if (ret < 0)  
  803.         {  
  804.             GTP_DEBUG("failed to set doze flag into 0x8046, %d", retry);  
  805.             continue;  
  806.         }  
  807.         i2c_control_buf[0] = 0x80;  
  808.         i2c_control_buf[1] = 0x40;  
  809.         ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);  
  810.         if (ret > 0)  
  811.         {  
  812.             doze_status = DOZE_ENABLED;  
  813.             GTP_INFO("GTP has been working in doze mode!");  
  814.             gtp_irq_enable(ts);  
  815.             return ret;  
  816.         }  
  817.         msleep(10);  
  818.     }  
  819.     GTP_ERROR("GTP send doze cmd failed.");  
  820.     gtp_irq_enable(ts);  
  821.     return ret;  
  822. }  
  823. #else   
  824. /*******************************************************  
  825. Function:  
  826.     Enter sleep mode.  
  827. Input:  
  828.     ts: private data.  
  829. Output:  
  830.     Executive outcomes.  
  831.        1: succeed, otherwise failed.  
  832. *******************************************************/  
  833. static s8 gtp_enter_sleep(struct goodix_ts_data * ts)  
  834. {  
  835.     s8 ret = -1;  
  836.     s8 retry = 0;  
  837.     u8 i2c_control_buf[3] = {(u8)(GTP_REG_SLEEP >> 8), (u8)GTP_REG_SLEEP, 5};  
  838.   
  839.     GTP_DEBUG_FUNC();  
  840.       
  841.     GTP_GPIO_OUTPUT(GTP_INT_PORT, 0);  
  842.     msleep(5);  
  843.       
  844.     while(retry++ < 5)  
  845.     {  
  846.         ret = gtp_i2c_write(ts->client, i2c_control_buf, 3);  
  847.         if (ret > 0)  
  848.         {  
  849.             GTP_INFO("GTP enter sleep!");  
  850.               
  851.             return ret;  
  852.         }  
  853.         msleep(10);  
  854.     }  
  855.     GTP_ERROR("GTP send sleep cmd failed.");  
  856.     return ret;  
  857. }  
  858. #endif   
  859. /*******************************************************  
  860. Function:  
  861.     Wakeup from sleep.  
  862. Input:  
  863.     ts: private data.  
  864. Output:  
  865.     Executive outcomes.  
  866.         >0: succeed, otherwise: failed.  
  867. *******************************************************/  
  868. static s8 gtp_wakeup_sleep(struct goodix_ts_data * ts)  
  869. {  
  870.     u8 retry = 0;  
  871.     s8 ret = -1;  
  872.       
  873.     GTP_DEBUG_FUNC();  
  874.       
  875. #if GTP_POWER_CTRL_SLEEP  
  876.     while(retry++ < 5)  
  877.     {  
  878.         gtp_reset_guitar(ts->client, 20);  
  879.           
  880.         ret = gtp_send_cfg(ts->client);  
  881.         if (ret < 0)  
  882.         {  
  883.             GTP_INFO("Wakeup sleep send config failed!");  
  884.             continue;  
  885.         }  
  886.         GTP_INFO("GTP wakeup sleep");  
  887.         return 1;  
  888.     }  
  889. #else  
  890.     while(retry++ < 10)  
  891.     {  
  892.     #if GTP_SLIDE_WAKEUP  
  893.         if (DOZE_WAKEUP != doze_status)       // wakeup not by slide   
  894.         {  
  895.             gtp_reset_guitar(ts->client, 10);  
  896.         }  
  897.         else              // wakeup by slide   
  898.         {  
  899.             doze_status = DOZE_DISABLED;  
  900.         }  
  901.     #else  
  902.         if (chip_gt9xxs == 1)  
  903.         {  
  904.            gtp_reset_guitar(ts->client, 10);  
  905.         }  
  906.         else  
  907.         {  
  908.             GTP_GPIO_OUTPUT(GTP_INT_PORT, 1);  
  909.             msleep(5);  
  910.         }  
  911.     #endif  
  912.         ret = gtp_i2c_test(ts->client);  
  913.         if (ret > 0)  
  914.         {  
  915.             GTP_INFO("GTP wakeup sleep.");  
  916.               
  917.         #if (!GTP_SLIDE_WAKEUP)  
  918.             if (chip_gt9xxs == 0)  
  919.             {  
  920.                 gtp_int_sync(25);  
  921.                 msleep(20);  
  922.             #if GTP_ESD_PROTECT  
  923.                 gtp_init_ext_watchdog(ts->client);  
  924.             #endif  
  925.             }  
  926.         #endif  
  927.             return ret;  
  928.         }  
  929.         gtp_reset_guitar(ts->client, 20);  
  930.     }  
  931. #endif  
  932.   
  933.     GTP_ERROR("GTP wakeup sleep failed.");  
  934.     return ret;  
  935. }  
  936.   
  937. /*******************************************************  
  938. Function:  
  939.     Initialize gtp.  
  940. Input:  
  941.     ts: goodix private data  
  942. Output:  
  943.     Executive outcomes.  
  944.         0: succeed, otherwise: failed  
  945. *******************************************************/  
  946. static s32 gtp_init_panel(struct goodix_ts_data *ts)  
  947. {  
  948.     s32 ret = -1;  
  949.   
  950. #if GTP_DRIVER_SEND_CFG  
  951.     s32 i;  
  952.     u8 check_sum = 0;  
  953.     u8 opr_buf[16];  
  954.     u8 sensor_id = 0;  
  955.   
  956.     u8 cfg_info_group1[] = CTP_CFG_GROUP1;  
  957.     u8 cfg_info_group2[] = CTP_CFG_GROUP2;  
  958.     u8 cfg_info_group3[] = CTP_CFG_GROUP3;  
  959.     u8 cfg_info_group4[] = CTP_CFG_GROUP4;  
  960.     u8 cfg_info_group5[] = CTP_CFG_GROUP5;  
  961.     u8 cfg_info_group6[] = CTP_CFG_GROUP6;  
  962.     u8 *send_cfg_buf[] = {cfg_info_group1, cfg_info_group2, cfg_info_group3,  
  963.                         cfg_info_group4, cfg_info_group5, cfg_info_group6};  
  964.     u8 cfg_info_len[] = { CFG_GROUP_LEN(cfg_info_group1),  
  965.                           CFG_GROUP_LEN(cfg_info_group2),  
  966.                           CFG_GROUP_LEN(cfg_info_group3),  
  967.                           CFG_GROUP_LEN(cfg_info_group4),  
  968.                           CFG_GROUP_LEN(cfg_info_group5),  
  969.                           CFG_GROUP_LEN(cfg_info_group6)};  
  970.   
  971.     GTP_DEBUG("Config Groups\' Lengths: %d, %d, %d, %d, %d, %d",   
  972.         cfg_info_len[0], cfg_info_len[1], cfg_info_len[2], cfg_info_len[3],  
  973.         cfg_info_len[4], cfg_info_len[5]);  
  974.   
  975.     ret = gtp_i2c_read_dbl_check(ts->client, 0x41E4, opr_buf, 1);  
  976.     if (SUCCESS == ret)   
  977.     {  
  978.         if (opr_buf[0] != 0xBE)  
  979.         {  
  980.             ts->fw_error = 1;  
  981.             GTP_ERROR("Firmware error, no config sent!");  
  982.             return -1;  
  983.         }  
  984.     }  
  985.   
  986.     if ((!cfg_info_len[1]) && (!cfg_info_len[2]) &&   
  987.         (!cfg_info_len[3]) && (!cfg_info_len[4]) &&   
  988.         (!cfg_info_len[5]))  
  989.     {  
  990.         sensor_id = 0;   
  991.     }  
  992.     else  
  993.     {  
  994.         ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_SENSOR_ID, &sensor_id, 1);  
  995.         if (SUCCESS == ret)  
  996.         {  
  997.             if (sensor_id >= 0x06)  
  998.             {  
  999.                 GTP_ERROR("Invalid sensor_id(0x%02X), No Config Sent!", sensor_id);  
  1000.                 return -1;  
  1001.             }  
  1002.         }  
  1003.         else  
  1004.         {  
  1005.             GTP_ERROR("Failed to get sensor_id, No config sent!");  
  1006.             return -1;  
  1007.         }  
  1008.     }  
  1009.    <span style="color:#FF0000;"> GTP_DEBUG("Sensor_ID: %d", sensor_id);//根据该id发不同的配置</span>  
  1010.       
  1011.     ts->gtp_cfg_len = cfg_info_len[sensor_id];  
  1012.       
  1013.     if (ts->gtp_cfg_len < GTP_CONFIG_MIN_LENGTH)  
  1014.     {  
  1015.         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);  
  1016.         return -1;  
  1017.     }  
  1018.       
  1019.     ret = gtp_i2c_read_dbl_check(ts->client, GTP_REG_CONFIG_DATA, &opr_buf[0], 1);  
  1020.       
  1021.     if (ret == SUCCESS)  
  1022.     {  
  1023.         GTP_DEBUG("CFG_GROUP%d Config Version: %d, 0x%02X; IC Config Version: %d, 0x%02X", sensor_id+1,   
  1024.                     send_cfg_buf[sensor_id][0], send_cfg_buf[sensor_id][0], opr_buf[0], opr_buf[0]);  
  1025.           
  1026.         if (opr_buf[0] < 90)      
  1027.         {  
  1028.             grp_cfg_version = send_cfg_buf[sensor_id][0];       // backup group config version  
  1029.             send_cfg_buf[sensor_id][0] = 0x00;  
  1030.             ts->fixed_cfg = 0;  
  1031.         }  
  1032.         else        // treated as fixed config, not send config  
  1033.         {  
  1034.             GTP_INFO("Ic fixed config with config version(%d, 0x%02X)", opr_buf[0], opr_buf[0]);  
  1035.             ts->fixed_cfg = 1;  
  1036.         }  
  1037.     }  
  1038.     else  
  1039.     {  
  1040.         GTP_ERROR("Failed to get ic config version!No config sent!");  
  1041.         return -1;  
  1042.     }  
  1043.       
  1044.     memset(&config[GTP_ADDR_LENGTH], 0, GTP_CONFIG_MAX_LENGTH);  
  1045.     memcpy(&config[GTP_ADDR_LENGTH], send_cfg_buf[sensor_id], ts->gtp_cfg_len);  
  1046.   
  1047. #if GTP_CUSTOM_CFG  
  1048.     config[RESOLUTION_LOC]     = (u8)GTP_MAX_WIDTH;  
  1049.     config[RESOLUTION_LOC + 1] = (u8)(GTP_MAX_WIDTH>>8);  
  1050.     config[RESOLUTION_LOC + 2] = (u8)GTP_MAX_HEIGHT;  
  1051.     config[RESOLUTION_LOC + 3] = (u8)(GTP_MAX_HEIGHT>>8);  
  1052.       
  1053.     if (GTP_INT_TRIGGER == 0)  //RISING  
  1054.     {  
  1055.         config[TRIGGER_LOC] &= 0xfe;   
  1056.     }  
  1057.     else if (GTP_INT_TRIGGER == 1)  //FALLING  
  1058.     {  
  1059.         config[TRIGGER_LOC] |= 0x01;  
  1060.     }  
  1061. #endif  // GTP_CUSTOM_CFG  
  1062.       
  1063.     check_sum = 0;  
  1064.     for (i = GTP_ADDR_LENGTH; i < ts->gtp_cfg_len; i++)  
  1065.     {  
  1066.         check_sum += config[i];  
  1067.     }  
  1068.     config[ts->gtp_cfg_len] = (~check_sum) + 1;  
  1069.       
  1070. #else // DRIVER NOT SEND CONFIG  
  1071.     ts->gtp_cfg_len = GTP_CONFIG_MAX_LENGTH;  
  1072.     ret = gtp_i2c_read(ts->client, config, ts->gtp_cfg_len + GTP_ADDR_LENGTH);  
  1073.     if (ret < 0)  
  1074.     {  
  1075.         GTP_ERROR("Read Config Failed, Using Default Resolution & INT Trigger!");  
  1076.         ts->abs_x_max = GTP_MAX_WIDTH;  
  1077.         ts->abs_y_max = GTP_MAX_HEIGHT;  
  1078.         ts->int_trigger_type = GTP_INT_TRIGGER;  
  1079.     }  
  1080. #endif // GTP_DRIVER_SEND_CFG  
  1081.   
  1082.     GTP_DEBUG_FUNC();  
  1083.     if ((ts->abs_x_max == 0) && (ts->abs_y_max == 0))  
  1084.     {  
  1085.         ts->abs_x_max = (config[RESOLUTION_LOC + 1] << 8) + config[RESOLUTION_LOC];  
  1086.         ts->abs_y_max = (config[RESOLUTION_LOC + 3] << 8) + config[RESOLUTION_LOC + 2];  
  1087.         ts->int_trigger_type = (config[TRIGGER_LOC]) & 0x03;   
  1088.     }  
  1089.     ret = gtp_send_cfg(ts->client);  
  1090.     if (ret < 0)  
  1091.     {  
  1092.         GTP_ERROR("Send config error.");  
  1093.     }  
  1094.     GTP_DEBUG("X_MAX = %d, Y_MAX = %d, TRIGGER = 0x%02x",  
  1095.         ts->abs_x_max,ts->abs_y_max,ts->int_trigger_type);  
  1096.   
  1097.     msleep(10);  
  1098.     return 0;  
  1099. }  
  1100.   
  1101. /*******************************************************  
  1102. Function:  
  1103.     Read chip version.  
  1104. Input:  
  1105.     client:  i2c device  
  1106.     version: buffer to keep ic firmware version  
  1107. Output:  
  1108.     read operation return.  
  1109.         2: succeed, otherwise: failed  
  1110. *******************************************************/  
  1111. s32 gtp_read_version(struct i2c_client *client, u16* version)  
  1112. {  
  1113.     s32 ret = -1;  
  1114.     u8 buf[8] = {GTP_REG_VERSION >> 8, GTP_REG_VERSION & 0xff};  
  1115.   
  1116.     GTP_DEBUG_FUNC();  
  1117.   
  1118.     ret = gtp_i2c_read(client, buf, sizeof(buf));  
  1119.     if (ret < 0)  
  1120.     {  
  1121.         GTP_ERROR("GTP read version failed");  
  1122.         return ret;  
  1123.     }  
  1124.   
  1125.     if (version)  
  1126.     {  
  1127.         *version = (buf[7] << 8) | buf[6];  
  1128.     }  
  1129.       
  1130.     if (buf[5] == 0x00)  
  1131.     {  
  1132.         GTP_INFO("IC Version: %c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[7], buf[6]);  
  1133.     }  
  1134.     else  
  1135.     {  
  1136.         if (buf[5] == 'S' || buf[5] == 's')  
  1137.         {  
  1138.             chip_gt9xxs = 1;  
  1139.         }  
  1140.         GTP_INFO("IC Version: %c%c%c%c_%02x%02x", buf[2], buf[3], buf[4], buf[5], buf[7], buf[6]);  
  1141.     }  
  1142.     return ret;  
  1143. }  
  1144.   
  1145. /*******************************************************  
  1146. Function:  
  1147.     I2c test Function.  
  1148. Input:  
  1149.     client:i2c client.  
  1150. Output:  
  1151.     Executive outcomes.  
  1152.         2: succeed, otherwise failed.  
  1153. *******************************************************/  
  1154. static s8 gtp_i2c_test(struct i2c_client *client)  
  1155. {  
  1156.     u8 test[3] = {GTP_REG_CONFIG_DATA >> 8, GTP_REG_CONFIG_DATA & 0xff};  
  1157.     u8 retry = 0;  
  1158.     s8 ret = -1;  
  1159.     
  1160.     GTP_DEBUG_FUNC();  
  1161.     
  1162.     while(retry++ < 5)  
  1163.     {  
  1164.         ret = gtp_i2c_read(client, test, 3);  
  1165.         if (ret > 0)  
  1166.         {  
  1167.             return ret;  
  1168.         }  
  1169.         GTP_ERROR("GTP i2c test failed time %d.",retry);  
  1170.         msleep(10);  
  1171.     }  
  1172.     return ret;  
  1173. }  
  1174.   
  1175. /*******************************************************  
  1176. Function:  
  1177.     Request gpio(INT & RST) ports.  
  1178. Input:  
  1179.     ts: private data.  
  1180. Output:  
  1181.     Executive outcomes.  
  1182.         >= 0: succeed, < 0: failed  
  1183. *******************************************************/  
  1184. static s8 gtp_request_io_port(struct goodix_ts_data *ts)  
  1185. {  
  1186.     s32 ret = 0;  
  1187.   
  1188.     ret = GTP_GPIO_REQUEST(GTP_INT_PORT, "GTP_INT_IRQ");  
  1189.     if (ret < 0)   
  1190.     {  
  1191.         GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d", (s32)GTP_INT_PORT, ret);  
  1192.         ret = -ENODEV;  
  1193.     }  
  1194.     else  
  1195.     {  
  1196.         GTP_GPIO_AS_INT(GTP_INT_PORT);    
  1197.         ts->client->irq = GTP_INT_IRQ;  
  1198.     }  
  1199.   
  1200.     ret = GTP_GPIO_REQUEST(GTP_RST_PORT, "GTP_RST_PORT");  
  1201.     if (ret < 0)   
  1202.     {  
  1203.         GTP_ERROR("Failed to request GPIO:%d, ERRNO:%d",(s32)GTP_RST_PORT,ret);  
  1204.         ret = -ENODEV;  
  1205.     }  
  1206.   
  1207.     GTP_GPIO_AS_INPUT(GTP_RST_PORT);  
  1208.     gtp_reset_guitar(ts->client, 20);  
  1209.   
  1210.       
  1211.     if(ret < 0)  
  1212.     {  
  1213.         GTP_GPIO_FREE(GTP_RST_PORT);  
  1214.         GTP_GPIO_FREE(GTP_INT_PORT);  
  1215.     }  
  1216.   
  1217.     return ret;  
  1218. }  
  1219.   
  1220. /*******************************************************  
  1221. Function:  
  1222.     Request interrupt.  
  1223. Input:  
  1224.     ts: private data.  
  1225. Output:  
  1226.     Executive outcomes.  
  1227.         0: succeed, -1: failed.  
  1228. *******************************************************/  
  1229. static s8 gtp_request_irq(struct goodix_ts_data *ts)  
  1230. {  
  1231.     s32 ret = -1;  
  1232.     const u8 irq_table[] = GTP_IRQ_TAB;  
  1233.   
  1234.     GTP_DEBUG("INT trigger type:%x", ts->int_trigger_type);  
  1235.   
  1236.     ret  = request_irq(ts->client->irq,   
  1237.                        goodix_ts_irq_handler,  
  1238.                        irq_table[ts->int_trigger_type],  
  1239.                        ts->client->name,  
  1240.                        ts);  
  1241.     if (ret)  
  1242.     {  
  1243.         GTP_ERROR("Request IRQ failed!ERRNO:%d.", ret);  
  1244.         GTP_GPIO_AS_INPUT(GTP_INT_PORT);  
  1245.         GTP_GPIO_FREE(GTP_INT_PORT);  
  1246.   
  1247.         hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);  
  1248.         ts->timer.function = goodix_ts_timer_handler;  
  1249.         hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);  
  1250.         return -1;  
  1251.     }  
  1252.     else   
  1253.     {  
  1254.         gtp_irq_disable(ts);  
  1255.         ts->use_irq = 1;  
  1256.         return 0;  
  1257.     }  
  1258. }  
  1259.   
  1260. /*******************************************************  
  1261. Function:  
  1262.     Request input device Function.  
  1263. Input:  
  1264.     ts:private data.  
  1265. Output:  
  1266.     Executive outcomes.  
  1267.         0: succeed, otherwise: failed.  
  1268. *******************************************************/  
  1269. static s8 gtp_request_input_dev(struct goodix_ts_data *ts)  
  1270. {  
  1271.     s8 ret = -1;  
  1272.     s8 phys[32];  
  1273. #if GTP_HAVE_TOUCH_KEY  
  1274.     u8 index = 0;  
  1275. #endif  
  1276.     
  1277.     GTP_DEBUG_FUNC();  
  1278.     
  1279.     ts->input_dev = input_allocate_device();  
  1280.     if (ts->input_dev == NULL)  
  1281.     {  
  1282.         GTP_ERROR("Failed to allocate input device.");  
  1283.         return -ENOMEM;  
  1284.     }  
  1285.   
  1286.     ts->input_dev->evbit[0] = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;  
  1287. #if GTP_ICS_SLOT_REPORT  
  1288.     __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);  
  1289.     input_mt_init_slots(ts->input_dev, 10);     // in case of "out of memory"  
  1290. #else  
  1291.     ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);  
  1292. #endif  
  1293.   
  1294. #if GTP_HAVE_TOUCH_KEY  
  1295.     for (index = 0; index < GTP_MAX_KEY_NUM; index++)  
  1296.     {  
  1297.         input_set_capability(ts->input_dev, EV_KEY, touch_key_array[index]);    
  1298.     }  
  1299. #endif  
  1300.   
  1301. #if GTP_SLIDE_WAKEUP  
  1302.     input_set_capability(ts->input_dev, EV_KEY, KEY_POWER);  
  1303. #endif   
  1304.   
  1305. #if GTP_WITH_PEN  
  1306.     // pen support  
  1307.     __set_bit(BTN_TOOL_PEN, ts->input_dev->keybit);  
  1308.     __set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);  
  1309.     __set_bit(INPUT_PROP_POINTER, ts->input_dev->propbit);  
  1310. #endif  
  1311.   
  1312. #if GTP_CHANGE_X2Y  
  1313.     GTP_SWAP(ts->abs_x_max, ts->abs_y_max);  
  1314. #endif  
  1315.   
  1316.     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);  
  1317.     input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);  
  1318.     input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);  
  1319.     input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);  
  1320.     input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0);  
  1321.   
  1322.     sprintf(phys, "input/ts");  
  1323.     ts->input_dev->name = goodix_ts_name;  
  1324.     ts->input_dev->phys = phys;  
  1325.     ts->input_dev->id.bustype = BUS_I2C;  
  1326.     ts->input_dev->id.vendor = 0xDEAD;  
  1327.     ts->input_dev->id.product = 0xBEEF;  
  1328.     ts->input_dev->id.version = 10427;  
  1329.       
  1330.     ret = input_register_device(ts->input_dev);  
  1331.     if (ret)  
  1332.     {  
  1333.         GTP_ERROR("Register %s input device failed", ts->input_dev->name);  
  1334.         return -ENODEV;  
  1335.     }  
  1336.       
  1337. #ifdef CONFIG_HAS_EARLYSUSPEND  
  1338.     ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;  
  1339.     ts->early_suspend.suspend = goodix_ts_early_suspend;  
  1340.     ts->early_suspend.resume = goodix_ts_late_resume;  
  1341.     register_early_suspend(&ts->early_suspend);  
  1342. #endif  
  1343.   
  1344.     return 0;  
  1345. }  
  1346.   
  1347. /*******************************************************  
  1348. Function:  
  1349.     I2c probe.  
  1350. Input:  
  1351.     client: i2c device struct.  
  1352.     id: device id.  
  1353. Output:  
  1354.     Executive outcomes.   
  1355.         0: succeed.  
  1356. *******************************************************/  
  1357. static int goodix_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)  
  1358. {  
  1359.     s32 ret = -1;  
  1360.     struct goodix_ts_data *ts;  
  1361.     u16 version_info;  
  1362.   
  1363.     GTP_DEBUG_FUNC();  
  1364.       
  1365.     //do NOT remove these logs  
  1366.     GTP_INFO("GTP Driver Version: %s", GTP_DRIVER_VERSION);  
  1367.     GTP_INFO("GTP Driver Built@%s, %s", __TIME__, __DATE__);  
  1368.     GTP_INFO("GTP I2C Address: 0x%02x", client->addr);  
  1369.   
  1370.     i2c_connect_client = client;  
  1371.       
  1372.     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))   
  1373.     {  
  1374.         GTP_ERROR("I2C check functionality failed.");  
  1375.         return -ENODEV;  
  1376.     }  
  1377.     ts = kzalloc(sizeof(*ts), GFP_KERNEL);  
  1378.     if (ts == NULL)  
  1379.     {  
  1380.         GTP_ERROR("Alloc GFP_KERNEL memory failed.");  
  1381.         return -ENOMEM;  
  1382.     }  
  1383.      
  1384.     memset(ts, 0, sizeof(*ts));  
  1385.     INIT_WORK(&ts->work, goodix_ts_work_func);  
  1386.     ts->client = client;  
  1387.     spin_lock_init(&ts->irq_lock);          // 2.6.39 later  
  1388.     // ts->irq_lock = SPIN_LOCK_UNLOCKED;   // 2.6.39 & before  
  1389.     i2c_set_clientdata(client, ts);  
  1390.       
  1391.     ts->gtp_rawdiff_mode = 0;  
  1392.   
  1393.     ret = gtp_request_io_port(ts);  
  1394.     if (ret < 0)  
  1395.     {  
  1396.         GTP_ERROR("GTP request IO port failed.");  
  1397.         kfree(ts);  
  1398.         return ret;  
  1399.     }  
  1400.   
  1401.     ret = gtp_i2c_test(client);  
  1402.     if (ret < 0)  
  1403.     {  
  1404.         GTP_ERROR("I2C communication ERROR!");  
  1405.     }  
  1406.   
  1407. #if GTP_AUTO_UPDATE  
  1408.     ret = gup_init_update_proc(ts);  
  1409.     if (ret < 0)  
  1410.     {  
  1411.         GTP_ERROR("Create update thread error.");  
  1412.     }  
  1413. #endif  
  1414.       
  1415.     ret = gtp_init_panel(ts);  
  1416.     if (ret < 0)  
  1417.     {  
  1418.         GTP_ERROR("GTP init panel failed.");  
  1419.         ts->abs_x_max = GTP_MAX_WIDTH;  
  1420.         ts->abs_y_max = GTP_MAX_HEIGHT;  
  1421.         ts->int_trigger_type = GTP_INT_TRIGGER;  
  1422.     }  
  1423.   
  1424.     ret = gtp_request_input_dev(ts);  
  1425.     if (ret < 0)  
  1426.     {  
  1427.         GTP_ERROR("GTP request input dev failed");  
  1428.     }  
  1429.       
  1430.     ret = gtp_request_irq(ts);   
  1431.     if (ret < 0)  
  1432.     {  
  1433.         GTP_INFO("GTP works in polling mode.");  
  1434.     }  
  1435.     else  
  1436.     {  
  1437.         GTP_INFO("GTP works in interrupt mode.");  
  1438.     }  
  1439.   
  1440.     ret = gtp_read_version(client, &version_info);  
  1441.     if (ret < 0)  
  1442.     {  
  1443.         GTP_ERROR("Read version failed.");  
  1444.     }  
  1445.     if (ts->use_irq)  
  1446.     {  
  1447.         gtp_irq_enable(ts);  
  1448.     }  
  1449.       
  1450. #if GTP_CREATE_WR_NODE  
  1451.     init_wr_node(client);  
  1452. #endif  
  1453.       
  1454. #if GTP_ESD_PROTECT  
  1455.     gtp_esd_switch(client, SWITCH_ON);  
  1456. #endif  
  1457.     return 0;  
  1458. }  
  1459.   
  1460.   
  1461. /*******************************************************  
  1462. Function:  
  1463.     Goodix touchscreen driver release function.  
  1464. Input:  
  1465.     client: i2c device struct.  
  1466. Output:  
  1467.     Executive outcomes. 0---succeed.  
  1468. *******************************************************/  
  1469. static int goodix_ts_remove(struct i2c_client *client)  
  1470. {  
  1471.     struct goodix_ts_data *ts = i2c_get_clientdata(client);  
  1472.       
  1473.     GTP_DEBUG_FUNC();  
  1474.       
  1475. #ifdef CONFIG_HAS_EARLYSUSPEND  
  1476.     unregister_early_suspend(&ts->early_suspend);  
  1477. #endif  
  1478.   
  1479. #if GTP_CREATE_WR_NODE  
  1480.     uninit_wr_node();  
  1481. #endif  
  1482.   
  1483. #if GTP_ESD_PROTECT  
  1484.     destroy_workqueue(gtp_esd_check_workqueue);  
  1485. #endif  
  1486.   
  1487.     if (ts)   
  1488.     {  
  1489.         if (ts->use_irq)  
  1490.         {  
  1491.             GTP_GPIO_AS_INPUT(GTP_INT_PORT);  
  1492.             GTP_GPIO_FREE(GTP_INT_PORT);  
  1493.             free_irq(client->irq, ts);  
  1494.         }  
  1495.         else  
  1496.         {  
  1497.             hrtimer_cancel(&ts->timer);  
  1498.         }  
  1499.     }     
  1500.       
  1501.     GTP_INFO("GTP driver removing...");  
  1502.     i2c_set_clientdata(client, NULL);  
  1503.     input_unregister_device(ts->input_dev);  
  1504.     kfree(ts);  
  1505.   
  1506.     return 0;  
  1507. }  
  1508.   
  1509. #ifdef CONFIG_HAS_EARLYSUSPEND  
  1510. /*******************************************************  
  1511. Function:  
  1512.     Early suspend function.  
  1513. Input:  
  1514.     h: early_suspend struct.  
  1515. Output:  
  1516.     None.  
  1517. *******************************************************/  
  1518. static void goodix_ts_early_suspend(struct early_suspend *h)  
  1519. {  
  1520.     struct goodix_ts_data *ts;  
  1521.     s8 ret = -1;      
  1522.     ts = container_of(h, struct goodix_ts_data, early_suspend);  
  1523.       
  1524.     GTP_DEBUG_FUNC();  
  1525.   
  1526. #if GTP_ESD_PROTECT  
  1527.     ts->gtp_is_suspend = 1;  
  1528.     gtp_esd_switch(ts->client, SWITCH_OFF);  
  1529. #endif  
  1530.   
  1531. #if GTP_SLIDE_WAKEUP  
  1532.     ret = gtp_enter_doze(ts);  
  1533. #else  
  1534.     if (ts->use_irq)  
  1535.     {  
  1536.         gtp_irq_disable(ts);  
  1537.     }  
  1538.     else  
  1539.     {  
  1540.         hrtimer_cancel(&ts->timer);  
  1541.     }  
  1542.     ret = gtp_enter_sleep(ts);  
  1543. #endif   
  1544.     if (ret < 0)  
  1545.     {  
  1546.         GTP_ERROR("GTP early suspend failed.");  
  1547.     }  
  1548.     // to avoid waking up while not sleeping  
  1549.     //  delay 48 + 10ms to ensure reliability      
  1550.     msleep(58);     
  1551. }  
  1552.   
  1553. /*******************************************************  
  1554. Function:  
  1555.     Late resume function.  
  1556. Input:  
  1557.     h: early_suspend struct.  
  1558. Output:  
  1559.     None.  
  1560. *******************************************************/  
  1561. static void goodix_ts_late_resume(struct early_suspend *h)  
  1562. {  
  1563.     struct goodix_ts_data *ts;  
  1564.     s8 ret = -1;  
  1565.     ts = container_of(h, struct goodix_ts_data, early_suspend);  
  1566.       
  1567.     GTP_DEBUG_FUNC();  
  1568.       
  1569.     ret = gtp_wakeup_sleep(ts);  
  1570.   
  1571. #if GTP_SLIDE_WAKEUP  
  1572.     doze_status = DOZE_DISABLED;  
  1573. #endif  
  1574.   
  1575.     if (ret < 0)  
  1576.     {  
  1577.         GTP_ERROR("GTP later resume failed.");  
  1578.     }  
  1579.   
  1580.     if (ts->use_irq)  
  1581.     {  
  1582.         gtp_irq_enable(ts);  
  1583.     }  
  1584.     else  
  1585.     {  
  1586.         hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);  
  1587.     }  
  1588.   
  1589. #if GTP_ESD_PROTECT  
  1590.     ts->gtp_is_suspend = 0;  
  1591.     gtp_esd_switch(ts->client, SWITCH_ON);  
  1592. #endif  
  1593. }  
  1594. #endif  
  1595.   
  1596. #if GTP_ESD_PROTECT  
  1597. /*******************************************************  
  1598. Function:  
  1599.     switch on & off esd delayed work  
  1600. Input:  
  1601.     client:  i2c device  
  1602.     on:      SWITCH_ON / SWITCH_OFF  
  1603. Output:  
  1604.     void  
  1605. *********************************************************/  
  1606. void gtp_esd_switch(struct i2c_client *client, s32 on)  
  1607. {  
  1608.     struct goodix_ts_data *ts;  
  1609.       
  1610.     ts = i2c_get_clientdata(client);  
  1611.     if (SWITCH_ON == on)     // switch on esd   
  1612.     {  
  1613.         if (!ts->esd_running)  
  1614.         {  
  1615.             ts->esd_running = 1;  
  1616.             GTP_INFO("Esd started");  
  1617.             queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE);  
  1618.         }  
  1619.     }  
  1620.     else    // switch off esd  
  1621.     {  
  1622.         if (ts->esd_running)  
  1623.         {  
  1624.             ts->esd_running = 0;  
  1625.             GTP_INFO("Esd cancelled");  
  1626.             cancel_delayed_work_sync(>p_esd_check_work);  
  1627.         }  
  1628.     }  
  1629. }  
  1630.   
  1631. /*******************************************************  
  1632. Function:  
  1633.     Initialize external watchdog for esd protect  
  1634. Input:  
  1635.     client:  i2c device.  
  1636. Output:  
  1637.     result of i2c write operation.   
  1638.         1: succeed, otherwise: failed  
  1639. *********************************************************/  
  1640. static s32 gtp_init_ext_watchdog(struct i2c_client *client)  
  1641. {  
  1642.     u8 opr_buffer[4] = {0x80, 0x40, 0xAA, 0xAA};  
  1643.       
  1644.     struct i2c_msg msg;         // in case of recursively reset by calling gtp_i2c_write  
  1645.     s32 ret = -1;  
  1646.     s32 retries = 0;  
  1647.   
  1648.     GTP_DEBUG("Init external watchdog...");  
  1649.     GTP_DEBUG_FUNC();  
  1650.   
  1651.     msg.flags = !I2C_M_RD;  
  1652.     msg.addr  = client->addr;  
  1653.     msg.len   = 4;  
  1654.     msg.buf   = opr_buffer;  
  1655.   
  1656.     while(retries < 5)  
  1657.     {  
  1658.         ret = i2c_transfer(client->adapter, &msg, 1);  
  1659.         if (ret == 1)  
  1660.         {  
  1661.             return 1;  
  1662.         }  
  1663.         retries++;  
  1664.     }  
  1665.     if (retries >= 5)  
  1666.     {  
  1667.         GTP_ERROR("init external watchdog failed!");  
  1668.     }  
  1669.     return 0;  
  1670. }  
  1671.   
  1672. /*******************************************************  
  1673. Function:  
  1674.     Esd protect function.  
  1675.     Added external watchdog by meta, 2013/03/07  
  1676. Input:  
  1677.     work: delayed work  
  1678. Output:  
  1679.     None.  
  1680. *******************************************************/  
  1681. static void gtp_esd_check_func(struct work_struct *work)  
  1682. {  
  1683.     s32 i;  
  1684.     s32 ret = -1;  
  1685.     struct goodix_ts_data *ts = NULL;  
  1686.     u8 test[4] = {0x80, 0x40};  
  1687.       
  1688.     GTP_DEBUG_FUNC();  
  1689.      
  1690.     ts = i2c_get_clientdata(i2c_connect_client);  
  1691.   
  1692.     if (ts->gtp_is_suspend)  
  1693.     {  
  1694.         ts->esd_running = 0;  
  1695.         GTP_INFO("Esd terminated!");  
  1696.         return;  
  1697.     }  
  1698.       
  1699.     for (i = 0; i < 3; i++)  
  1700.     {  
  1701.         ret = gtp_i2c_read(ts->client, test, 4);  
  1702.           
  1703.         GTP_DEBUG("0x8040 = 0x%02X, 0x8041 = 0x%02X", test[2], test[3]);  
  1704.         if ((ret < 0))  
  1705.         {  
  1706.             // IIC communication problem  
  1707.             continue;  
  1708.         }  
  1709.         else  
  1710.         {   
  1711.             if ((test[2] == 0xAA) || (test[3] != 0xAA))  
  1712.             {  
  1713.                 // IC works abnormally..  
  1714.                 i = 3;  
  1715.                 break;    
  1716.             }  
  1717.             else   
  1718.             {  
  1719.                 // IC works normally, Write 0x8040 0xAA, feed the dog  
  1720.                 test[2] = 0xAA;   
  1721.                 gtp_i2c_write(ts->client, test, 3);  
  1722.                 break;  
  1723.             }  
  1724.         }  
  1725.     }  
  1726.     if (i >= 3)  
  1727.     {  
  1728.         GTP_ERROR("IC Working ABNORMALLY, Resetting Guitar...");  
  1729.         gtp_reset_guitar(ts->client, 50);  
  1730.     }  
  1731.   
  1732.     if(!ts->gtp_is_suspend)  
  1733.     {  
  1734.         queue_delayed_work(gtp_esd_check_workqueue, >p_esd_check_work, GTP_ESD_CHECK_CIRCLE);  
  1735.     }  
  1736.     else  
  1737.     {  
  1738.         GTP_INFO("Esd terminated!");  
  1739.         ts->esd_running = 0;  
  1740.     }  
  1741.     return;  
  1742. }  
  1743. #endif  
  1744.   
  1745. static const struct i2c_device_id goodix_ts_id[] = {  
  1746.     { GTP_I2C_NAME, 0 },  
  1747.     { }  
  1748. };  
  1749.   
  1750. static struct i2c_driver goodix_ts_driver = {  
  1751.     .probe      = goodix_ts_probe,  
  1752.     .remove     = goodix_ts_remove,  
  1753. #ifndef CONFIG_HAS_EARLYSUSPEND  
  1754.     .suspend    = goodix_ts_early_suspend,  
  1755.     .resume     = goodix_ts_late_resume,  
  1756. #endif  
  1757.     .id_table   = goodix_ts_id,  
  1758.     .driver = {  
  1759.         .name     = GTP_I2C_NAME,  
  1760.         .owner    = THIS_MODULE,  
  1761.     },  
  1762. };  
  1763.   
  1764. /*******************************************************      
  1765. Function:  
  1766.     Driver Install function.  
  1767. Input:  
  1768.     None.  
  1769. Output:  
  1770.     Executive Outcomes. 0---succeed.  
  1771. ********************************************************/  
  1772. static int __devinit goodix_ts_init(void)  
  1773. {  
  1774.     s32 ret;  
  1775.   
  1776.     GTP_DEBUG_FUNC();     
  1777.     GTP_INFO("GTP driver installing...");  
  1778.     goodix_wq = create_singlethread_workqueue("goodix_wq");  
  1779.     if (!goodix_wq)  
  1780.     {  
  1781.         GTP_ERROR("Creat workqueue failed.");  
  1782.         return -ENOMEM;  
  1783.     }  
  1784. #if GTP_ESD_PROTECT  
  1785.     INIT_DELAYED_WORK(>p_esd_check_work, gtp_esd_check_func);  
  1786.     gtp_esd_check_workqueue = create_workqueue("gtp_esd_check");  
  1787. #endif  
  1788.     ret = i2c_add_driver(&goodix_ts_driver);  
  1789.     return ret;   
  1790. }  
  1791.   
  1792. /*******************************************************      
  1793. Function:  
  1794.     Driver uninstall function.  
  1795. Input:  
  1796.     None.  
  1797. Output:  
  1798.     Executive Outcomes. 0---succeed.  
  1799. ********************************************************/  
  1800. static void __exit goodix_ts_exit(void)  
  1801. {  
  1802.     GTP_DEBUG_FUNC();  
  1803.     GTP_INFO("GTP driver exited.");  
  1804.     i2c_del_driver(&goodix_ts_driver);  
  1805.     if (goodix_wq)  
  1806.     {  
  1807.         destroy_workqueue(goodix_wq);  
  1808.     }  
  1809. }  
  1810.   
  1811. late_initcall(goodix_ts_init);  
  1812. module_exit(goodix_ts_exit);  
  1813.   
  1814. MODULE_DESCRIPTION("GTP Series Driver");  
  1815. MODULE_LICENSE("GPL");  

gt9xx.h的内容为

  1. /* drivers/input/touchscreen/gt9xx.h 
  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.  */  
  17.   
  18. #ifndef _GOODIX_GT9XX_H_  
  19. #define _GOODIX_GT9XX_H_  
  20.   
  21. #include <linux/kernel.h>  
  22. #include <linux/hrtimer.h>  
  23. #include <linux/i2c.h>  
  24. #include <linux/input.h>  
  25. #include <linux/module.h>  
  26. #include <linux/delay.h>  
  27. #include <linux/i2c.h>  
  28. #include <linux/proc_fs.h>  
  29. #include <linux/string.h>  
  30. #include <asm/uaccess.h>  
  31. #include <linux/vmalloc.h>  
  32. #include <linux/interrupt.h>  
  33. #include <linux/io.h>  
  34. #include <mach/gpio.h>  
  35. #include <linux/earlysuspend.h>  
  36.   
  37. struct goodix_ts_data {  
  38.     spinlock_t irq_lock;  
  39.     struct i2c_client *client;  
  40.     struct input_dev  *input_dev;  
  41.     struct hrtimer timer;  
  42.     struct work_struct  work;  
  43.     struct early_suspend early_suspend;  
  44.     s32 irq_is_disable;  
  45.     s32 use_irq;  
  46.     u16 abs_x_max;  
  47.     u16 abs_y_max;  
  48.     u8  max_touch_num;  
  49.     u8  int_trigger_type;  
  50.     u8  green_wake_mode;  
  51.     u8  chip_type;  
  52.     u8  enter_update;  
  53.     u8  gtp_is_suspend;  
  54.     u8  gtp_rawdiff_mode;  
  55.     u8  gtp_cfg_len;  
  56.     u8  fixed_cfg;  
  57.     u8  esd_running;  
  58.     u8  fw_error;  
  59. };  
  60.   
  61. extern u16 show_len;  
  62. extern u16 total_len;  
  63.   
  64. //***************************PART1:ON/OFF define*******************************  
  65. #define GTP_CUSTOM_CFG             0  
  66. #define GTP_CHANGE_X2Y              0         //是否打开X,Y坐标交换,这个比较容易判断,在屏幕上滑动一下便可知道  
  67. #define GTP_DRIVER_SEND_CFG   1  
  68. #define GTP_HAVE_TOUCH_KEY    0  
  69. #define GTP_POWER_CTRL_SLEEP  0  
  70. #define GTP_ICS_SLOT_REPORT     0  //坐标点汇报方式,在rk3188上需定义为1  
  71.   
  72. #define GTP_AUTO_UPDATE       1     // auto updated by .bin file as default 由于不需要升级,可屏蔽  
  73. #define GTP_HEADER_FW_UPDATE  0     // auto updated by head_fw_array in gt9xx_firmware.h, function together with GTP_AUTO_UPDATE  
  74.                                  
  75. #define GTP_CREATE_WR_NODE    1  
  76. #define GTP_ESD_PROTECT       0  
  77. #define GTP_WITH_PEN          0  
  78.   
  79. #define GTP_SLIDE_WAKEUP      0  
  80. #define GTP_DBL_CLK_WAKEUP    0     // double-click wakeup, function together with GTP_SLIDE_WAKEUP  
  81.   
  82. #define GTP_DEBUG_ON          1  
  83. #define GTP_DEBUG_ARRAY_ON    0  
  84. #define GTP_DEBUG_FUNC_ON     0  
  85.   
  86. //*************************** PART2:TODO define **********************************  
  87. // STEP_1(REQUIRED): Define Configuration Information Group(s)  
  88. // Sensor_ID Map:  
  89. /* sensor_opt1 sensor_opt2 Sensor_ID  
  90.     GND         GND         0   
  91.     VDDIO       GND         1   
  92.     NC          GND         2   
  93.     GND         NC/300K     3   
  94.     VDDIO       NC/300K     4   
  95.     NC          NC/300K     5   
  96. */  
  97. // TODO: define your own default or for Sensor_ID == 0 config here.   
  98. // The predefined one is just a sample config, which is not suitable for your tp in most cases.  
  99. #define CTP_CFG_GROUP1 {\  
  100.     0x41,0x1C,0x02,0xC0,0x03,0x0A,0x05,0x01,0x01,0x0F,\  
  101.     0x23,0x0F,0x5F,0x41,0x03,0x05,0x00,0x00,0x00,0x00,\  
  102.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x91,0x00,0x0A,\  
  103.     0x28,0x00,0xB8,0x0B,0x00,0x00,0x00,0x9A,0x03,0x25,\  
  104.     0x00,0x00,0x00,0x00,0x00,0x03,0x64,0x32,0x00,0x00,\  
  105.     0x00,0x32,0x8C,0x94,0x05,0x01,0x05,0x00,0x00,0x96,\  
  106.     0x0C,0x22,0xD8,0x0E,0x23,0x56,0x11,0x25,0xFF,0x13,\  
  107.     0x28,0xA7,0x15,0x2E,0x00,0x00,0x10,0x30,0x48,0x00,\  
  108.     0x56,0x4A,0x3A,0xFF,0xFF,0x16,0x00,0x00,0x00,0x00,\  
  109.     0x00,0x01,0x1B,0x14,0x0D,0x19,0x00,0x00,0x01,0x00,\  
  110.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\  
  111.     0x00,0x00,0x1A,0x18,0x16,0x14,0x12,0x10,0x0E,0x0C,\  
  112.     0x0A,0x08,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\  
  113.     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\  
  114.     0xFF,0xFF,0x1D,0x1E,0x1F,0x20,0x22,0x24,0x28,0x29,\  
  115.     0x0C,0x0A,0x08,0x00,0x02,0x04,0x05,0x06,0x0E,0xFF,\  
  116.     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\  
  117.     0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,\  
  118.     0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,\  
  119.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\  
  120.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\  
  121.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\  
  122.     0x00,0x00,0x00,0x00,0x00,0x00,0x91,0x01\  
  123.     }  
  124.       
  125. // TODO: define your config for Sensor_ID == 1 here, if needed  
  126. #define CTP_CFG_GROUP2 {\  
  127.     }  
  128. // TODO: define your config for Sensor_ID == 2 here, if needed  
  129. #define CTP_CFG_GROUP3 {\  
  130.     }  
  131.   
  132. // TODO: define your config for Sensor_ID == 3 here, if needed  
  133. #define CTP_CFG_GROUP4 {\  
  134.     }  
  135.   
  136. // TODO: define your config for Sensor_ID == 4 here, if needed  
  137. #define CTP_CFG_GROUP5 {\  
  138.     }  
  139.   
  140. // TODO: define your config for Sensor_ID == 5 here, if needed  
  141. #define CTP_CFG_GROUP6 {\  
  142.     }  
  143.   
  144. // STEP_2(REQUIRED): Customize your I/O ports & I/O operations  
  145. #define GTP_RST_PORT    S5PV210_GPJ3(6)     //复位引脚  
  146. #define GTP_INT_PORT    S5PV210_GPH1(3)    //中断引脚  
  147. #define GTP_INT_IRQ     gpio_to_irq(GTP_INT_PORT)  
  148. #define GTP_INT_CFG     S3C_GPIO_SFN(0xF)  
  149.   
  150. #define GTP_GPIO_AS_INPUT(pin)           do{\        //平台相关部分,需自己修改  
  151.                                                     gpio_direction_input(pin);\  
  152.                                                     s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);\  
  153.                                           }while(0)  
  154. #define GTP_GPIO_AS_INT(pin)             do{\     
  155.                                                        GTP_GPIO_AS_INPUT(pin);\  
  156.                                                        s3c_gpio_cfgpin(pin, GTP_INT_CFG);\  
  157.                                           }while(0)  
  158. #define GTP_GPIO_GET_VALUE(pin)         gpio_get_value(pin)  
  159. #define GTP_GPIO_OUTPUT(pin,level)      gpio_direction_output(pin,level)  
  160. #define GTP_GPIO_REQUEST(pin, label)    gpio_request(pin, label)  
  161. #define GTP_GPIO_FREE(pin)              gpio_free(pin)  
  162. #define GTP_IRQ_TAB                     {IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, IRQ_TYPE_LEVEL_LOW, IRQ_TYPE_LEVEL_HIGH}  
  163.   
  164. // STEP_3(optional): Specify your special config info if needed  
  165. #if GTP_CUSTOM_CFG  
  166.   #define GTP_MAX_HEIGHT   800  
  167.   #define GTP_MAX_WIDTH    480  
  168.   #define GTP_INT_TRIGGER  0            // 0: Rising 1: Falling  
  169. #else  
  170.   #define GTP_MAX_HEIGHT   4096  
  171.   #define GTP_MAX_WIDTH    4096  
  172.   #define GTP_INT_TRIGGER  1  
  173. #endif  
  174. #define GTP_MAX_TOUCH         5  
  175. #define GTP_ESD_CHECK_CIRCLE  2000      // jiffy: ms  
  176.   
  177. // STEP_4(optional): If keys are available and reported as keys, config your key info here                               
  178. #if GTP_HAVE_TOUCH_KEY  
  179.     #define GTP_KEY_TAB  {KEY_MENU, KEY_HOME, KEY_BACK}  
  180. #endif  
  181.   
  182. //***************************PART3:OTHER define*********************************  
  183. #define GTP_DRIVER_VERSION    "V1.8<2013/06/08>"  
  184. #define GTP_I2C_NAME          "Goodix-TS"  
  185. #define GTP_POLL_TIME         10     // jiffy: ms  
  186. #define GTP_ADDR_LENGTH       2  
  187. #define GTP_CONFIG_MIN_LENGTH 186  
  188. #define GTP_CONFIG_MAX_LENGTH 240  
  189. #define FAIL                  0  
  190. #define SUCCESS               1  
  191. #define SWITCH_OFF            0  
  192. #define SWITCH_ON             1  
  193.   
  194. // Registers define  
  195. #define GTP_READ_COOR_ADDR    0x814E  
  196. #define GTP_REG_SLEEP         0x8040  
  197. #define GTP_REG_SENSOR_ID     0x814A  
  198. #define GTP_REG_CONFIG_DATA   0x8047  
  199. #define GTP_REG_VERSION       0x8140  
  200.   
  201. #define RESOLUTION_LOC        3  
  202. #define TRIGGER_LOC           8  
  203.   
  204. #define CFG_GROUP_LEN(p_cfg_grp)  (sizeof(p_cfg_grp) / sizeof(p_cfg_grp[0]))  
  205. // Log define  
  206. #define GTP_INFO(fmt,arg...)           printk("<<-GTP-INFO->> "fmt"\n",##arg)  
  207. #define GTP_ERROR(fmt,arg...)          printk("<<-GTP-ERROR->> "fmt"\n",##arg)  
  208. #define GTP_DEBUG(fmt,arg...)          do{\  
  209.                                          if(GTP_DEBUG_ON)\  
  210.                                          printk("<<-GTP-DEBUG->> [%d]"fmt"\n",__LINE__, ##arg);\  
  211.                                        }while(0)  
  212. #define GTP_DEBUG_ARRAY(array, num)    do{\  
  213.                                          s32 i;\  
  214.                                          u8* a = array;\  
  215.                                          if(GTP_DEBUG_ARRAY_ON)\  
  216.                                          {\  
  217.                                             printk("<<-GTP-DEBUG-ARRAY->>\n");\  
  218.                                             for (i = 0; i < (num); i++)\  
  219.                                             {\  
  220.                                                 printk("%02x   ", (a)[i]);\  
  221.                                                 if ((i + 1 ) %10 == 0)\  
  222.                                                 {\  
  223.                                                     printk("\n");\  
  224.                                                 }\  
  225.                                             }\  
  226.                                             printk("\n");\  
  227.                                         }\  
  228.                                        }while(0)  
  229. #define GTP_DEBUG_FUNC()               do{\  
  230.                                          if(GTP_DEBUG_FUNC_ON)\  
  231.                                          printk("<<-GTP-FUNC->> Func:%s@Line:%d\n",__func__,__LINE__);\  
  232.                                        }while(0)  
  233. #define GTP_SWAP(x, y)                 do{\  
  234.                                          typeof(x) z = x;\  
  235.                                          x = y;\  
  236.                                          y = z;\  
  237.                                        }while (0)  
  238.   
  239. //*****************************End of Part III********************************  
  240.   
  241. #endif /* _GOODIX_GT9XX_H_ */  

编译Makefile文件

  1. ifeq ($(KERNELRELEASE),)           
  2. KERNELDIR_OUT ?= /home/w/M8974AAAAANLYD4275/out/target/product/msm8974/obj/KERNEL_OBJ  
  3. DBG_CROSS_COMPILE ?= /home/w/M8974AAAAANLYD4275/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/bin/arm-eabi-      
  4. PWD := $(shell pwd)               
  5. modules:                         #编译为驱动模块      
  6.     $(MAKE) -C $(KERNELDIR_OUT) M=$(PWD) ARCH=arm CROSS_COMPILE=$(DBG_CROSS_COMPILE) modules      
  7. modules_install:      
  8.     $(MAKE) -C $(KERNELDIR_OUT) M=$(PWD) ARCH=arm CROSS_COMPILE=$(DBG_CROSS_COMPILE) modules    
  9. clean:      
  10.     rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions modules.order Module.symvers          
  11. .PHONY: modules modules_install clean           
  12. else                                    
  13. GT9xx_CORE_OBJS  := gt9xx.o             #指定驱动模块的核心文件(有init 和 exit)      
  14. GT9xx_OTHER_OBJS := goodix_tool.o gt9xx_update.o #依赖文件      
  15. touchscreen-objs   := $(GT9xx_CORE_OBJS) $(GT9xx_OTHER_OBJS) #xxx-objs := 指定驱动模块的所有依赖文件      
  16. obj-m := touchscreen.o   #最终由xxx-objs链接生成touchscreen.o,再生成touchscreen.ko      
  17. endif  

然后在板级文件中注册该路IIC的设备信息  

  1. {  
  2.         .type            =  "Goodix-TS",  
  3.         .addr            =   0x14,  
  4.         .flags            =   0,  
  5. },  

或者在设备树上参考其他i2c设备添加ii2信息。

当然,i2c设备信息也可直接写在gt9xx.c的驱动中,可参考

http://blog.csdn.net/mike8825/article/details/51335582

goodix_ts_probe函数跑起来了,说明设备和驱动已经匹配成功。

接下来,确定点击触摸屏有没有检测到中断(/proc/interrupts),如果没有中断,检查中断IO口有没有配置出错,以及通过硬件手段来确定有没有中断信号。

至此,GT9xx驱动移植成功。

参考资料

http://blog.csdn.net/wocao1226/article/details/42459673
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值