Advertisement
Guest User

focaltech5x06.c

a guest
Aug 30th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 39.96 KB | None | 0 0
  1. /*
  2.  
  3.  * drivers/input/touchscreen/ft5x0x_ts.c
  4.  
  5.  *
  6.  
  7.  * FocalTech ft5x0x TouchScreen driver.
  8.  
  9.  *
  10.  
  11.  * Copyright (c) 2010  Focal tech Ltd.
  12.  
  13.  *
  14.  
  15.  * This software is licensed under the terms of the GNU General Public
  16.  
  17.  * License version 2, as published by the Free Software Foundation, and
  18.  
  19.  * may be copied, distributed, and modified under those terms.
  20.  
  21.  *
  22.  
  23.  * This program is distributed in the hope that it will be useful,
  24.  
  25.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.  
  27.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  28.  
  29.  * GNU General Public License for more details.
  30.  
  31.  *
  32.  
  33.  * VERSION          DATE            AUTHOR
  34.  
  35.  *    1.0         2010-01-05            WenFS
  36.  
  37.  *
  38.  
  39.  * note: only support mulititouch   Wenfs 2010-10-01
  40.  
  41.  */
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. #include <linux/i2c.h>
  50.  
  51. #include <linux/delay.h>
  52.  
  53. #include <linux/input.h>
  54.  
  55. #include <linux/earlysuspend.h>
  56.  
  57. #include <linux/interrupt.h>
  58.  
  59. #include <linux/slab.h>
  60.  
  61. #include <linux/device.h>
  62.  
  63. #include <linux/platform_device.h>
  64.  
  65. #include <linux/workqueue.h>
  66.  
  67. #include <mach/gpio.h>
  68.  
  69. #include <mach/gpio_data.h>
  70.  
  71. #include <linux/input/mt.h>
  72.  
  73. #include <linux/ft5x06_ts.h>
  74.  
  75. static int ft5x0x_write_reg(u8 addr, u8 para);
  76.  
  77. static int ft5x0x_read_reg(u8 addr, u8 *pdata);
  78.  
  79. static struct i2c_client *this_client;
  80.  
  81. static struct ts_platform_data *focaltechPdata2;
  82.  
  83. static int ft5x0x_printk_enable_flag=0;
  84.  
  85.  
  86.  
  87. #define FT5X0X_EVENT_MAX    5
  88.  
  89. //#define CONFIG_TOUCH_PANEL_KEY
  90.  
  91. //const for events type
  92. #define TOUCH_EVENT_DOWN        0x00
  93. #define TOUCH_EVENT_UP          0x01
  94. #define TOUCH_EVENT_ON          0x02
  95. #define TOUCH_EVENT_RESERVED        0x03
  96.  
  97. #ifdef CONFIG_TOUCH_PANEL_KEY
  98.  
  99. #define TOUCH_SCREEN_RELEASE_DELAY (100 * 1000000)//unit usec
  100.  
  101. #define TAP_KEY_RELEASE_DELAY (100 * 1000000)
  102.  
  103. #define TAP_KEY_TIME 10
  104.  
  105. enum {
  106.  
  107.     NO_TOUCH,
  108.  
  109.     TOUCH_KEY_PRE,
  110.  
  111.     TAP_KEY,
  112.  
  113.     TOUCH_KEY,
  114.  
  115.     TOUCH_SCREEN,
  116.  
  117.     TOUCH_SCREEN_RELEASE,
  118.  
  119. };
  120.  
  121. #endif
  122.  
  123.  
  124.  
  125. struct ts_event {
  126.  
  127.     u8 id;
  128.  
  129.     s16 x;
  130.  
  131.     s16 y;
  132.  
  133.     s16 z;
  134.  
  135.     s16 w;
  136.  
  137.     //add type event
  138.     u8 type;
  139. };
  140.  
  141.  
  142.  
  143. struct ft5x0x_ts_data {
  144.  
  145.     struct input_dev    *input_dev;
  146.  
  147.     struct ts_event event[FT5X0X_EVENT_MAX];
  148.  
  149.     u8 event_num;
  150.  
  151.     struct work_struct  pen_event_work;
  152.  
  153.     struct workqueue_struct *ts_workqueue;
  154.  
  155.     struct early_suspend    early_suspend;
  156.  
  157. #ifdef CONFIG_TOUCH_PANEL_KEY
  158.  
  159.     u8 touch_state;
  160.  
  161.     short key;
  162.  
  163.     struct hrtimer timer;
  164.  
  165.     struct ts_event first_event;
  166.  
  167.     int offset;
  168.  
  169.     int touch_count;
  170.  
  171. #endif
  172.  
  173. };
  174.  
  175.  
  176.  
  177. #define ft5x0x_dbg(fmt, args...)  { if(ft5x0x_printk_enable_flag) \
  178.                     printk("[ft5x0x]: " fmt, ## args); }
  179.  
  180.  
  181.  
  182. //#define AC_DETECT_IN_TOUCH_DRIVER
  183.  
  184. #ifdef AC_DETECT_IN_TOUCH_DRIVER
  185.  
  186. static int ac_detect_flag_current=0;
  187.  
  188. static int ac_detect_flag_old=3;
  189.  
  190. static void Ac_Detect_In_Touch_Driver(void)
  191.  
  192. {
  193.  
  194.     unsigned char ver;
  195.  
  196.     int ac_detect_flag_temp=0;
  197.  
  198.     if (!focaltechPdata2->Ac_is_connect) return;
  199.  
  200.     ac_detect_flag_temp=focaltechPdata2->Ac_is_connect();
  201.  
  202.     ac_detect_flag_current=ac_detect_flag_temp;
  203.  
  204.     if(ac_detect_flag_current!=ac_detect_flag_old)
  205.  
  206.         {
  207.  
  208.         if(1==focaltechPdata2->Ac_is_connect())
  209.  
  210.             ft5x0x_write_reg(0xb2,0x1);
  211.  
  212.         else
  213.  
  214.             ft5x0x_write_reg(0xb2,0x0);
  215.  
  216.         ac_detect_flag_old=ac_detect_flag_current;
  217.  
  218.         }
  219.  
  220.     if(1==ft5x0x_printk_enable_flag)
  221.  
  222.         {
  223.  
  224.         ft5x0x_read_reg(0xb2, &ver);
  225.  
  226.         printk("reg 0xb2=%d\n",ver);
  227.  
  228.         }
  229.  
  230. }
  231.  
  232. #endif
  233.  
  234. static ssize_t ft5x0x_read(struct device *dev, struct device_attribute *attr, char *buf)
  235.  
  236. {
  237.  
  238.     struct capts *ts = (struct capts *)dev_get_drvdata(dev);
  239.  
  240.  
  241.  
  242.     if (!strcmp(attr->attr.name, "ft5x0xPrintFlag")) {
  243.  
  244.         memcpy(buf, &ft5x0x_printk_enable_flag,sizeof(ft5x0x_printk_enable_flag));
  245.  
  246.         printk("buf[0]=%d, buf[1]=%d\n", buf[0], buf[1]);
  247.  
  248.         return sizeof(ft5x0x_printk_enable_flag);
  249.  
  250.     }
  251.  
  252.     return 0;
  253.  
  254. }
  255.  
  256.  
  257.  
  258. static ssize_t ft5x0x_write(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  259.  
  260. {
  261.  
  262.     int ret = 0;
  263.  
  264.     struct capts *ts = (struct capts *)dev_get_drvdata(dev);
  265.  
  266.  
  267.  
  268.     if (!strcmp(attr->attr.name, "ft5x0xPrintFlag")) {
  269.  
  270.         printk("buf[0]=%d, buf[1]=%d\n", buf[0], buf[1]);
  271.  
  272.         if (buf[0] == '0') ft5x0x_printk_enable_flag = 0;
  273.  
  274.         if (buf[0] == '1') ft5x0x_printk_enable_flag = 1;
  275.  
  276.         if (buf[0] == '2') {
  277.  
  278.             ft5x0x_printk_enable_flag=2;
  279.  
  280.             if(focaltechPdata2->power){
  281.  
  282.                 focaltechPdata2->power(0);
  283.  
  284.                 msleep(50);
  285.  
  286.                 focaltechPdata2->power(1);
  287.  
  288.                 msleep(200);
  289.  
  290.             }
  291.  
  292.         }
  293.  
  294.         if (buf[0] == '3') {
  295.  
  296.             u8 data;
  297.  
  298.             ft5x0x_write_reg(0xa5, 0x03);
  299.  
  300.             printk("set reg[0xa5] = 0x03\n");
  301.  
  302.             msleep(20);
  303.  
  304.             ft5x0x_read_reg(0xa5, &data);
  305.  
  306.             printk("read back: reg[0xa5] = %d\n", data);
  307.  
  308.     }
  309.  
  310.   }
  311.  
  312.     return count;
  313.  
  314. }
  315.  
  316.  
  317.  
  318. static DEVICE_ATTR(ft5x0xPrintFlag, S_IRWXUGO, ft5x0x_read, ft5x0x_write);
  319.  
  320. static struct attribute *ft5x0x_attr[] = {
  321.  
  322.     &dev_attr_ft5x0xPrintFlag.attr,
  323.  
  324.     NULL
  325.  
  326. };
  327.  
  328.  
  329.  
  330. static struct attribute_group ft5x0x_attr_group = {
  331.  
  332.     .name = NULL,
  333.  
  334.     .attrs = ft5x0x_attr,
  335.  
  336. };
  337.  
  338.  
  339.  
  340.  
  341.  
  342. /***********************************************************************************************
  343.  
  344. Name    :   ft5x0x_i2c_rxdata
  345.  
  346.  
  347.  
  348. Input   :   *rxdata
  349.  
  350.                      *length
  351.  
  352.  
  353.  
  354. Output  :   ret
  355.  
  356.  
  357.  
  358. function    :  
  359.  
  360.  
  361.  
  362. ***********************************************************************************************/
  363.  
  364. static int ft5x0x_i2c_rxdata(char *rxdata, int length)
  365.  
  366. {
  367.  
  368.     int ret;
  369.  
  370.  
  371.  
  372.     struct i2c_msg msgs[] = {
  373.  
  374.         {
  375.  
  376.             .addr   = this_client->addr,
  377.  
  378.             .flags  = 0,
  379.  
  380.             .len    = 1,
  381.  
  382.             .buf    = rxdata,
  383.  
  384.         },
  385.  
  386.         {
  387.  
  388.             .addr   = this_client->addr,
  389.  
  390.             .flags  = I2C_M_RD,
  391.  
  392.             .len    = length,
  393.  
  394.             .buf    = rxdata,
  395.  
  396.         },
  397.  
  398.     };
  399.  
  400.  
  401.  
  402.     //msleep(1);
  403.  
  404.     ret = i2c_transfer(this_client->adapter, msgs, 2);
  405.  
  406.     if (ret < 0)
  407.  
  408.         pr_err("msg %s i2c read error: %d\n", __func__, ret);
  409.  
  410.    
  411.  
  412.     return ret;
  413.  
  414. }
  415.  
  416. /***********************************************************************************************
  417.  
  418. Name    :    
  419.  
  420.  
  421.  
  422. Input   :  
  423.  
  424.                      
  425.  
  426.  
  427.  
  428. Output  :  
  429.  
  430.  
  431.  
  432. function    :  
  433.  
  434.  
  435.  
  436. ***********************************************************************************************/
  437.  
  438. static int ft5x0x_i2c_txdata(char *txdata, int length)
  439.  
  440. {
  441.  
  442.     int ret;
  443.  
  444.  
  445.  
  446.     struct i2c_msg msg[] = {
  447.  
  448.         {
  449.  
  450.             .addr   = this_client->addr,
  451.  
  452.             .flags  = 0,
  453.  
  454.             .len    = length,
  455.  
  456.             .buf    = txdata,
  457.  
  458.         },
  459.  
  460.     };
  461.  
  462.  
  463.  
  464.     //msleep(1);
  465.  
  466.     ret = i2c_transfer(this_client->adapter, msg, 1);
  467.  
  468.     if (ret < 0)
  469.  
  470.         pr_err("%s i2c write error: %d\n", __func__, ret);
  471.  
  472.  
  473.  
  474.     return ret;
  475.  
  476. }
  477.  
  478. /***********************************************************************************************
  479.  
  480. Name    :    ft5x0x_write_reg
  481.  
  482.  
  483.  
  484. Input   :   addr -- address
  485.  
  486.                      para -- parameter
  487.  
  488.  
  489.  
  490. Output  :  
  491.  
  492.  
  493.  
  494. function    :   write register of ft5x0x
  495.  
  496.  
  497.  
  498. ***********************************************************************************************/
  499.  
  500. static int ft5x0x_write_reg(u8 addr, u8 para)
  501.  
  502. {
  503.  
  504.     u8 buf[3];
  505.  
  506.     int ret = -1;
  507.  
  508.  
  509.  
  510.     buf[0] = addr;
  511.  
  512.     buf[1] = para;
  513.  
  514.     ret = ft5x0x_i2c_txdata(buf, 2);
  515.  
  516.     if (ret < 0) {
  517.  
  518.         pr_err("write reg failed! %#x ret: %d", buf[0], ret);
  519.  
  520.         return -1;
  521.  
  522.     }
  523.  
  524.    
  525.  
  526.     return 0;
  527.  
  528. }
  529.  
  530.  
  531.  
  532.  
  533.  
  534. /***********************************************************************************************
  535.  
  536. Name    :   ft5x0x_read_reg
  537.  
  538.  
  539.  
  540. Input   :   addr
  541.  
  542.                      pdata
  543.  
  544.  
  545.  
  546. Output  :  
  547.  
  548.  
  549.  
  550. function    :   read register of ft5x0x
  551.  
  552.  
  553.  
  554. ***********************************************************************************************/
  555.  
  556. static int ft5x0x_read_reg(u8 addr, u8 *pdata)
  557.  
  558. {
  559.  
  560.     int ret;
  561.  
  562.     u8 buf[2] = {0};
  563.  
  564.  
  565.  
  566.     buf[0] = addr;
  567.  
  568.     struct i2c_msg msgs[] = {
  569.  
  570.         {
  571.  
  572.             .addr   = this_client->addr,
  573.  
  574.             .flags  = 0,
  575.  
  576.             .len    = 1,
  577.  
  578.             .buf    = buf,
  579.  
  580.         },
  581.  
  582.         {
  583.  
  584.             .addr   = this_client->addr,
  585.  
  586.             .flags  = I2C_M_RD,
  587.  
  588.             .len    = 1,
  589.  
  590.             .buf    = buf,
  591.  
  592.         },
  593.  
  594.     };
  595.  
  596.  
  597.  
  598.     //msleep(1);
  599.  
  600.     ret = i2c_transfer(this_client->adapter, msgs, 2);
  601.  
  602.     if (ret < 0)
  603.  
  604.         pr_err("msg %s i2c read error: %d\n", __func__, ret);
  605.  
  606.  
  607.  
  608.     *pdata = buf[0];
  609.  
  610.     return ret;
  611.  
  612.  
  613.  
  614. }
  615.  
  616.  
  617.  
  618.  
  619.  
  620. /***********************************************************************************************
  621.  
  622. Name    :    ft5x0x_read_fw_ver
  623.  
  624.  
  625.  
  626. Input   :    void
  627.  
  628.                      
  629.  
  630.  
  631.  
  632. Output  :    firmware version  
  633.  
  634.  
  635.  
  636. function    :    read TP firmware version
  637.  
  638.  
  639.  
  640. ***********************************************************************************************/
  641.  
  642. static unsigned char ft5x0x_read_fw_ver(void)
  643.  
  644. {
  645.  
  646.     unsigned char ver;
  647.  
  648.     ft5x0x_read_reg(FT5X0X_REG_FIRMID, &ver);
  649.  
  650.     return(ver);
  651.  
  652. }
  653.  
  654.  
  655.  
  656.  
  657.  
  658. #define CONFIG_FOCALTECH_TOUCHSCREEN_CODE_UPG
  659.  
  660.  
  661.  
  662.  
  663.  
  664. #ifdef CONFIG_FOCALTECH_TOUCHSCREEN_CODE_UPG
  665.  
  666.  
  667.  
  668. typedef enum
  669.  
  670. {
  671.  
  672.     ERR_OK,
  673.  
  674.     ERR_MODE,
  675.  
  676.     ERR_READID,
  677.  
  678.     ERR_ERASE,
  679.  
  680.     ERR_STATUS,
  681.  
  682.     ERR_ECC,
  683.  
  684.     ERR_DL_ERASE_FAIL,
  685.  
  686.     ERR_DL_PROGRAM_FAIL,
  687.  
  688.     ERR_DL_VERIFY_FAIL
  689.  
  690. }E_UPGRADE_ERR_TYPE;
  691.  
  692.  
  693.  
  694. typedef unsigned char         FTS_BYTE;     //8 bit
  695.  
  696. typedef unsigned short        FTS_WORD;    //16 bit
  697.  
  698. typedef unsigned int          FTS_DWRD;    //16 bit
  699.  
  700. typedef unsigned char         FTS_BOOL;    //8 bit
  701.  
  702.  
  703.  
  704. #define FTS_NULL                0x0
  705.  
  706. #define FTS_TRUE                0x01
  707.  
  708. #define FTS_FALSE              0x0
  709.  
  710.  
  711.  
  712. #define I2C_CTPM_ADDRESS       0x70
  713.  
  714.  
  715.  
  716.  
  717.  
  718. void delay_qt_ms(unsigned long  w_ms)
  719.  
  720. {
  721.  
  722.     unsigned long i;
  723.  
  724.     unsigned long j;
  725.  
  726.  
  727.  
  728.     for (i = 0; i < w_ms; i++)
  729.  
  730.     {
  731.  
  732.         for (j = 0; j < 1000; j++)
  733.  
  734.         {
  735.  
  736.             udelay(1);
  737.  
  738.         }
  739.  
  740.     }
  741.  
  742. }
  743.  
  744.  
  745.  
  746.  
  747.  
  748. /*
  749.  
  750. [function]:
  751.  
  752.     callback: read data from ctpm by i2c interface,implemented by special user;
  753.  
  754. [parameters]:
  755.  
  756.     bt_ctpm_addr[in]    :the address of the ctpm;
  757.  
  758.     pbt_buf[out]        :data buffer;
  759.  
  760.     dw_lenth[in]        :the length of the data buffer;
  761.  
  762. [return]:
  763.  
  764.     FTS_TRUE     :success;
  765.  
  766.     FTS_FALSE    :fail;
  767.  
  768. */
  769.  
  770. FTS_BOOL i2c_read_interface(FTS_BYTE bt_ctpm_addr, FTS_BYTE* pbt_buf, FTS_DWRD dw_lenth)
  771.  
  772. {
  773.  
  774.     int ret;
  775.  
  776.    
  777.  
  778.     ret=i2c_master_recv(this_client, pbt_buf, dw_lenth);
  779.  
  780.  
  781.  
  782.     if(ret<=0)
  783.  
  784.     {
  785.  
  786.         printk("[TSP]i2c_read_interface error\n");
  787.  
  788.         return FTS_FALSE;
  789.  
  790.     }
  791.  
  792.  
  793.  
  794.     return FTS_TRUE;
  795.  
  796. }
  797.  
  798.  
  799.  
  800. /*
  801.  
  802. [function]:
  803.  
  804.     callback: write data to ctpm by i2c interface,implemented by special user;
  805.  
  806. [parameters]:
  807.  
  808.     bt_ctpm_addr[in]    :the address of the ctpm;
  809.  
  810.     pbt_buf[in]        :data buffer;
  811.  
  812.     dw_lenth[in]        :the length of the data buffer;
  813.  
  814. [return]:
  815.  
  816.     FTS_TRUE     :success;
  817.  
  818.     FTS_FALSE    :fail;
  819.  
  820. */
  821.  
  822. FTS_BOOL i2c_write_interface(FTS_BYTE bt_ctpm_addr, FTS_BYTE* pbt_buf, FTS_DWRD dw_lenth)
  823.  
  824. {
  825.  
  826.     int ret;
  827.  
  828.     ret=i2c_master_send(this_client, pbt_buf, dw_lenth);
  829.  
  830.     if(ret<=0)
  831.  
  832.     {
  833.  
  834.         printk("[TSP]i2c_write_interface error line = %d, ret = %d\n", __LINE__, ret);
  835.  
  836.         return FTS_FALSE;
  837.  
  838.     }
  839.  
  840.  
  841.  
  842.     return FTS_TRUE;
  843.  
  844. }
  845.  
  846.  
  847.  
  848. /*
  849.  
  850. [function]:
  851.  
  852.     send a command to ctpm.
  853.  
  854. [parameters]:
  855.  
  856.     btcmd[in]        :command code;
  857.  
  858.     btPara1[in]    :parameter 1;    
  859.  
  860.     btPara2[in]    :parameter 2;    
  861.  
  862.     btPara3[in]    :parameter 3;    
  863.  
  864.     num[in]        :the valid input parameter numbers, if only command code needed and no parameters followed,then the num is 1;    
  865.  
  866. [return]:
  867.  
  868.     FTS_TRUE    :success;
  869.  
  870.     FTS_FALSE    :io fail;
  871.  
  872. */
  873.  
  874. FTS_BOOL cmd_write(FTS_BYTE btcmd,FTS_BYTE btPara1,FTS_BYTE btPara2,FTS_BYTE btPara3,FTS_BYTE num)
  875.  
  876. {
  877.  
  878.     FTS_BYTE write_cmd[4] = {0};
  879.  
  880.  
  881.  
  882.     write_cmd[0] = btcmd;
  883.  
  884.     write_cmd[1] = btPara1;
  885.  
  886.     write_cmd[2] = btPara2;
  887.  
  888.     write_cmd[3] = btPara3;
  889.  
  890.     return i2c_write_interface(I2C_CTPM_ADDRESS, write_cmd, num);
  891.  
  892. }
  893.  
  894.  
  895.  
  896. /*
  897.  
  898. [function]:
  899.  
  900.     write data to ctpm , the destination address is 0.
  901.  
  902. [parameters]:
  903.  
  904.     pbt_buf[in]    :point to data buffer;
  905.  
  906.     bt_len[in]        :the data numbers;    
  907.  
  908. [return]:
  909.  
  910.     FTS_TRUE    :success;
  911.  
  912.     FTS_FALSE    :io fail;
  913.  
  914. */
  915.  
  916. FTS_BOOL byte_write(FTS_BYTE* pbt_buf, FTS_DWRD dw_len)
  917.  
  918. {
  919.  
  920.    
  921.  
  922.     return i2c_write_interface(I2C_CTPM_ADDRESS, pbt_buf, dw_len);
  923.  
  924. }
  925.  
  926.  
  927.  
  928. /*
  929.  
  930. [function]:
  931.  
  932.     read out data from ctpm,the destination address is 0.
  933.  
  934. [parameters]:
  935.  
  936.     pbt_buf[out]    :point to data buffer;
  937.  
  938.     bt_len[in]        :the data numbers;    
  939.  
  940. [return]:
  941.  
  942.     FTS_TRUE    :success;
  943.  
  944.     FTS_FALSE    :io fail;
  945.  
  946. */
  947.  
  948. FTS_BOOL byte_read(FTS_BYTE* pbt_buf, FTS_BYTE bt_len)
  949.  
  950. {
  951.  
  952.     return i2c_read_interface(I2C_CTPM_ADDRESS, pbt_buf, bt_len);
  953.  
  954. }
  955.  
  956.  
  957.  
  958.  
  959.  
  960. /*
  961.  
  962. [function]:
  963.  
  964.     burn the FW to ctpm.
  965.  
  966. [parameters]:(ref. SPEC)
  967.  
  968.     pbt_buf[in]    :point to Head+FW ;
  969.  
  970.     dw_lenth[in]:the length of the FW + 6(the Head length);    
  971.  
  972.     bt_ecc[in]    :the ECC of the FW
  973.  
  974. [return]:
  975.  
  976.     ERR_OK        :no error;
  977.  
  978.     ERR_MODE    :fail to switch to UPDATE mode;
  979.  
  980.     ERR_READID    :read id fail;
  981.  
  982.     ERR_ERASE    :erase chip fail;
  983.  
  984.     ERR_STATUS    :status error;
  985.  
  986.     ERR_ECC        :ecc error.
  987.  
  988. */
  989.  
  990.  
  991.  
  992.  
  993.  
  994. #define    FTS_PACKET_LENGTH        128
  995.  
  996. static unsigned char CTPM_FW[]=
  997.  
  998. {
  999.  
  1000. #include "ft_app.ft"
  1001.  
  1002. };
  1003.  
  1004. int fts_ctpm_auto_clb(void)
  1005.  
  1006. {
  1007.  
  1008.     unsigned char uc_temp;
  1009.  
  1010.     unsigned char i ;
  1011.  
  1012.  
  1013.  
  1014.     printk("[FTS] start auto CLB.\n");
  1015.  
  1016.     msleep(200);
  1017.  
  1018.     ft5x0x_write_reg(0, 0x40);  
  1019.  
  1020.     delay_qt_ms(100);   //make sure already enter factory mode
  1021.  
  1022.     ft5x0x_write_reg(2, 0x4);  //write command to start calibration
  1023.  
  1024.     delay_qt_ms(300);
  1025.  
  1026.     for(i=0;i<100;i++)
  1027.  
  1028.     {
  1029.  
  1030.         ft5x0x_read_reg(0,&uc_temp);
  1031.  
  1032.         if ( ((uc_temp&0x70)>>4) == 0x0)  //return to normal mode, calibration finish
  1033.  
  1034.         {
  1035.  
  1036.             break;
  1037.  
  1038.         }
  1039.  
  1040.         delay_qt_ms(200);
  1041.  
  1042.         printk("[FTS] waiting calibration %d\n",i);
  1043.  
  1044.        
  1045.  
  1046.     }
  1047.  
  1048.     printk("[FTS] calibration OK.\n");
  1049.  
  1050.    
  1051.  
  1052.     msleep(300);
  1053.  
  1054.     ft5x0x_write_reg(0, 0x40);  //goto factory mode
  1055.  
  1056.     delay_qt_ms(100);   //make sure already enter factory mode
  1057.  
  1058.     ft5x0x_write_reg(2, 0x5);  //store CLB result
  1059.  
  1060.     delay_qt_ms(300);
  1061.  
  1062.     ft5x0x_write_reg(0, 0x0); //return to normal mode
  1063.  
  1064.     msleep(300);
  1065.  
  1066.     printk("[FTS] store CLB result OK.\n");
  1067.  
  1068.     return 0;
  1069.  
  1070. }
  1071.  
  1072.  
  1073.  
  1074. E_UPGRADE_ERR_TYPE  fts_ctpm_fw_upgrade(FTS_BYTE* pbt_buf, FTS_DWRD dw_lenth)
  1075.  
  1076. {
  1077.  
  1078.     FTS_BYTE reg_val[2] = {0};
  1079.  
  1080.     FTS_DWRD i = 0;
  1081.  
  1082.  
  1083.  
  1084.     FTS_DWRD  packet_number;
  1085.  
  1086.     FTS_DWRD  j;
  1087.  
  1088.     FTS_DWRD  temp;
  1089.  
  1090.     FTS_DWRD  lenght;
  1091.  
  1092.     FTS_BYTE  packet_buf[FTS_PACKET_LENGTH + 6];
  1093.  
  1094.     FTS_BYTE  auc_i2c_write_buf[10];
  1095.  
  1096.     FTS_BYTE bt_ecc;
  1097.  
  1098.     int      i_ret;
  1099.  
  1100.  
  1101.  
  1102.     /*********Step 1:Reset  CTPM *****/
  1103.  
  1104.     /*write 0xaa to register 0xfc*/
  1105.  
  1106.     ft5x0x_write_reg(0xfc,0xaa);
  1107.  
  1108.     delay_qt_ms(50);
  1109.  
  1110.      /*write 0x55 to register 0xfc*/
  1111.  
  1112.     ft5x0x_write_reg(0xfc,0x55);
  1113.  
  1114.     printk("[TSP] Step 1: Reset CTPM test\n");
  1115.  
  1116.    
  1117.  
  1118.     delay_qt_ms(30);  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.     /*********Step 2:Enter upgrade mode *****/
  1125.  
  1126.     auc_i2c_write_buf[0] = 0x55;
  1127.  
  1128.     auc_i2c_write_buf[1] = 0xaa;
  1129.  
  1130.     do
  1131.  
  1132.     {
  1133.  
  1134.         i ++;
  1135.  
  1136.         i_ret = ft5x0x_i2c_txdata(auc_i2c_write_buf, 2);
  1137.  
  1138.         delay_qt_ms(5);
  1139.  
  1140.     }while(i_ret <= 0 && i < 5 );
  1141.  
  1142.  
  1143.  
  1144.     /*********Step 3:check READ-ID***********************/
  1145.  
  1146. //  delay_qt_ms(5);
  1147.  
  1148.     cmd_write(0x90,0x00,0x00,0x00,4);
  1149.  
  1150.     byte_read(reg_val,2);
  1151.  
  1152.     if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
  1153.  
  1154.     {
  1155.  
  1156.         printk("[TSP] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
  1157.  
  1158.     }
  1159.  
  1160.     else
  1161.  
  1162.     {
  1163.  
  1164.         for(i=0;i<10;i++)
  1165.  
  1166.             {
  1167.  
  1168.              byte_read(reg_val,2);
  1169.  
  1170.              if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
  1171.  
  1172.                 {
  1173.  
  1174.                  printk("[TSP] Step 3: succes = 0x%x",i);
  1175.  
  1176.                  break;
  1177.  
  1178.                 }
  1179.  
  1180.              else
  1181.  
  1182.                 {
  1183.  
  1184.                  printk("[TSP] Step 3: error = 0x%x",i);
  1185.  
  1186.                 }
  1187.  
  1188.             }
  1189.  
  1190.         if(i==10)
  1191.  
  1192.             {
  1193.  
  1194.             printk("[TSP] Step 3: return error = 0x%x",i);
  1195.  
  1196.             return ERR_READID;
  1197.  
  1198.             }
  1199.  
  1200.         //i_is_new_protocol = 1;
  1201.  
  1202.     }
  1203.  
  1204.  
  1205.  
  1206.     cmd_write(0xcd,0x0,0x00,0x00,1);
  1207.  
  1208.     byte_read(reg_val,1);
  1209.  
  1210.     printk("[FTS] bootloader version = 0x%x\n", reg_val[0]);
  1211.  
  1212.     cmd_write(0x61,0x00,0x00,0x00,1);
  1213.  
  1214.    
  1215.  
  1216.     delay_qt_ms(1500);
  1217.  
  1218.     cmd_write(0x63,0x00,0x00,0x00,1);  //erase panel parameter area
  1219.  
  1220.     delay_qt_ms(100);
  1221.  
  1222.     printk("[TSP] Step 4: erase. \n");
  1223.  
  1224.  
  1225.  
  1226.     /*********Step 5:write firmware(FW) to ctpm flash*********/
  1227.  
  1228.     bt_ecc = 0;
  1229.  
  1230.     printk("[TSP] Step 5: start upgrade. \n");
  1231.  
  1232.     dw_lenth = dw_lenth - 8;
  1233.  
  1234.     packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
  1235.  
  1236.     packet_buf[0] = 0xbf;
  1237.  
  1238.     packet_buf[1] = 0x00;
  1239.  
  1240.     for (j=0;j<packet_number;j++)
  1241.  
  1242.     {
  1243.  
  1244.         temp = j * FTS_PACKET_LENGTH;
  1245.  
  1246.         packet_buf[2] = (FTS_BYTE)(temp>>8);
  1247.  
  1248.         packet_buf[3] = (FTS_BYTE)temp;
  1249.  
  1250.         lenght = FTS_PACKET_LENGTH;
  1251.  
  1252.         packet_buf[4] = (FTS_BYTE)(lenght>>8);
  1253.  
  1254.         packet_buf[5] = (FTS_BYTE)lenght;
  1255.  
  1256.  
  1257.  
  1258.         for (i=0;i<FTS_PACKET_LENGTH;i++)
  1259.  
  1260.         {
  1261.  
  1262.             packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
  1263.  
  1264.             bt_ecc ^= packet_buf[6+i];
  1265.  
  1266.         }
  1267.  
  1268.        
  1269.  
  1270.         byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
  1271.  
  1272.         delay_qt_ms(FTS_PACKET_LENGTH/6 + 1);
  1273.  
  1274.         if ((j * FTS_PACKET_LENGTH % 1024) == 0)
  1275.  
  1276.         {
  1277.  
  1278.               printk("[TSP] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
  1279.  
  1280.         }
  1281.  
  1282.     }
  1283.  
  1284.  
  1285.  
  1286.     if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
  1287.  
  1288.     {
  1289.  
  1290.         temp = packet_number * FTS_PACKET_LENGTH;
  1291.  
  1292.         packet_buf[2] = (FTS_BYTE)(temp>>8);
  1293.  
  1294.         packet_buf[3] = (FTS_BYTE)temp;
  1295.  
  1296.  
  1297.  
  1298.         temp = (dw_lenth) % FTS_PACKET_LENGTH;
  1299.  
  1300.         packet_buf[4] = (FTS_BYTE)(temp>>8);
  1301.  
  1302.         packet_buf[5] = (FTS_BYTE)temp;
  1303.  
  1304.  
  1305.  
  1306.         for (i=0;i<temp;i++)
  1307.  
  1308.         {
  1309.  
  1310.             packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
  1311.  
  1312.             bt_ecc ^= packet_buf[6+i];
  1313.  
  1314.         }
  1315.  
  1316.  
  1317.  
  1318.         byte_write(&packet_buf[0],temp+6);    
  1319.  
  1320.         delay_qt_ms(20);
  1321.  
  1322.     }
  1323.  
  1324.  
  1325.  
  1326.     //send the last six byte
  1327.  
  1328.     for (i = 0; i<6; i++)
  1329.  
  1330.     {
  1331.  
  1332.         temp = 0x6ffa + i;
  1333.  
  1334.         packet_buf[2] = (FTS_BYTE)(temp>>8);
  1335.  
  1336.         packet_buf[3] = (FTS_BYTE)temp;
  1337.  
  1338.         temp =1;
  1339.  
  1340.         packet_buf[4] = (FTS_BYTE)(temp>>8);
  1341.  
  1342.         packet_buf[5] = (FTS_BYTE)temp;
  1343.  
  1344.         packet_buf[6] = pbt_buf[ dw_lenth + i];
  1345.  
  1346.         bt_ecc ^= packet_buf[6];
  1347.  
  1348.  
  1349.  
  1350.         byte_write(&packet_buf[0],7);  
  1351.  
  1352.         delay_qt_ms(20);
  1353.  
  1354.     }
  1355.  
  1356.  
  1357.  
  1358.     /*********Step 6: read out checksum***********************/
  1359.  
  1360.     /*send the opration head*/
  1361.  
  1362.     cmd_write(0xcc,0x00,0x00,0x00,1);
  1363.  
  1364.     byte_read(reg_val,1);
  1365.  
  1366.     printk("[TSP] Step 6:  ecc read 0x%x, new firmware 0x%x. \n", reg_val[0], bt_ecc);
  1367.  
  1368.     if(reg_val[0] != bt_ecc)
  1369.  
  1370.     {
  1371.  
  1372.     printk("[TSP] Step 6:  ecc error and return \n");
  1373.  
  1374.         return ERR_ECC;
  1375.  
  1376.     }
  1377.  
  1378.  
  1379.  
  1380.     /*********Step 7: reset the new FW***********************/
  1381.  
  1382.    
  1383.  
  1384.     cmd_write(0x07,0x00,0x00,0x00,1);
  1385.  
  1386.     printk("[TSP] Step 7 \n");
  1387.  
  1388.     delay_qt_ms(300);
  1389.  
  1390.     fts_ctpm_auto_clb();
  1391.  
  1392.     return ERR_OK;
  1393.  
  1394. }
  1395.  
  1396.  
  1397.  
  1398. unsigned char fts_ctpm_get_upg_ver(void)
  1399.  
  1400. {
  1401.  
  1402.     unsigned int ui_sz;
  1403.  
  1404.     ui_sz = sizeof(CTPM_FW);
  1405.  
  1406.     if (ui_sz > 2)
  1407.  
  1408.     {
  1409.  
  1410.         return CTPM_FW[ui_sz - 2];
  1411.  
  1412.     }
  1413.  
  1414.     else
  1415.  
  1416.     {
  1417.  
  1418.         //TBD, error handling?
  1419.  
  1420.         return 0xff; //default value
  1421.  
  1422.     }
  1423.  
  1424. }
  1425.  
  1426.  
  1427.  
  1428. #endif
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436. static int is_tp_key(struct tp_key *tp_key, int key_num, int x, int y)
  1437.  
  1438. {
  1439.  
  1440.     int i;
  1441.  
  1442.    
  1443.  
  1444.     if (tp_key && key_num) {
  1445.  
  1446.         for (i=0; i<key_num; i++) {
  1447.  
  1448.             if ((x > tp_key->x1) && (x < tp_key->x2)
  1449.  
  1450.             && (y > tp_key->y1) && (y < tp_key->y2)) {
  1451.  
  1452.                 return tp_key->key;
  1453.  
  1454.             }
  1455.  
  1456.             tp_key++;
  1457.  
  1458.         }
  1459.  
  1460.     }
  1461.  
  1462.     return 0;
  1463.  
  1464. }
  1465.  
  1466. int fts_ctpm_fw_upgrade_with_i_file(void)
  1467.  
  1468. {
  1469.  
  1470.    FTS_BYTE*     pbt_buf = FTS_NULL;
  1471.  
  1472.    int i_ret;
  1473.  
  1474.     unsigned char uc_host_fm_ver;  
  1475.  
  1476.    unsigned char uc_tp_fm_ver;
  1477.  
  1478.     //=========FW upgrade========================*/
  1479.  
  1480.    pbt_buf = CTPM_FW;
  1481.  
  1482.    /*call the upgrade function*/
  1483.  
  1484.    uc_tp_fm_ver = ft5x0x_read_fw_ver();    
  1485.  
  1486.    uc_host_fm_ver = fts_ctpm_get_upg_ver();  
  1487.  
  1488.   if ( uc_tp_fm_ver == 0xa6  ||   //the firmware in touch panel maybe corrupted    
  1489.  
  1490.          uc_tp_fm_ver != uc_host_fm_ver   //the firmware in host flash is new, need upgrade  
  1491.  
  1492.          )
  1493.  
  1494.     {    printk("[FTS] upgrade start.\n");
  1495.  
  1496.             i_ret =  fts_ctpm_fw_upgrade(pbt_buf,sizeof(CTPM_FW));
  1497.  
  1498.     }
  1499.  
  1500.    else{
  1501.  
  1502.             printk("[FTS] do not upgrade.\n");
  1503.  
  1504.     }
  1505.  
  1506.    if (i_ret != 0)
  1507.  
  1508.    {
  1509.  
  1510.        //error handling ...
  1511.  
  1512.        //TBD
  1513.  
  1514.    }
  1515.  
  1516.  
  1517.  
  1518.    return i_ret;
  1519.  
  1520. }
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526. #ifdef CONFIG_TOUCH_PANEL_KEY
  1527.  
  1528. static enum hrtimer_restart ft5x0x_timer(struct hrtimer *timer)
  1529.  
  1530. {
  1531.  
  1532.     struct ft5x0x_ts_data *data = container_of(timer, struct ft5x0x_ts_data, timer);
  1533.  
  1534.  
  1535.  
  1536.     if (data->touch_state == TOUCH_SCREEN) {
  1537.  
  1538.         input_report_key(data->input_dev, BTN_TOUCH, 0);
  1539.  
  1540.         input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 0);
  1541.  
  1542.         input_sync(data->input_dev);
  1543.  
  1544.         ft5x0x_dbg("touch screen up(2)!\n");
  1545.  
  1546.     }
  1547.  
  1548.     else if (data->touch_state == TAP_KEY) {
  1549.  
  1550.         input_report_key(data->input_dev, data->key, 1);
  1551.  
  1552.         input_report_key(data->input_dev, data->key, 0);
  1553.  
  1554.         input_sync(data->input_dev);
  1555.  
  1556.         ft5x0x_dbg("touch key(%d) down(short)\n", data->key);
  1557.  
  1558.         ft5x0x_dbg("touch key(%d) up(short)\n", data->key);
  1559.  
  1560.     }
  1561.  
  1562.     data->touch_state = NO_TOUCH;
  1563.  
  1564.     return HRTIMER_NORESTART;
  1565.  
  1566. };
  1567.  
  1568. #endif
  1569.  
  1570.  
  1571.  
  1572. /*
  1573.  
  1574.  * return event number.
  1575.  
  1576. */
  1577.  
  1578. static int ft5x0x_get_event(struct ts_event *event)
  1579.  
  1580. {
  1581.  
  1582.     u8 buf[32] = {0};
  1583.  
  1584.     int ret, i;
  1585.  
  1586.  
  1587.  
  1588.     ret = ft5x0x_i2c_rxdata(buf, 31);
  1589.  
  1590.     if (ret < 0) {
  1591.  
  1592.         printk("%s read_data i2c_rxdata failed: %d\n", __func__, ret);
  1593.  
  1594.         return ret;
  1595.  
  1596.     }
  1597.  
  1598.  
  1599.  
  1600.     ret = (buf[2] & 0x07);
  1601.  
  1602.     if (ret > FT5X0X_EVENT_MAX) ret = FT5X0X_EVENT_MAX;
  1603.  
  1604.     for (i=0; i<FT5X0X_EVENT_MAX; i++) {
  1605.  
  1606.         event->id = (buf[5+i*6] >> 4) & 0x0F;
  1607.         event->type = buf[3+i*6] >> 6;
  1608.  
  1609.         if (event->type == TOUCH_EVENT_RESERVED) {
  1610.             event++;
  1611.             continue;
  1612.         }
  1613.         //event->id = i;
  1614.         event->x = (s16)(buf[3+i*6] & 0x0F)<<8 | (s16)buf[4+i*6];
  1615.         event->y = (s16)(buf[5+i*6] & 0x0F)<<8 | (s16)buf[6+i*6];
  1616.        
  1617. /*
  1618.  
  1619. x & y are 12 bits... in deed
  1620. 4 first bits are something different (on x 2 first bits of x event are type of event, 4 first bits of y event are id)
  1621.  
  1622. NOTE ommit 4 bits of every cords.
  1623. x0 = buf[3] <<8 | buff[4]
  1624. y0 = buff[5] <<9  | buff[6]
  1625. 7 & 8 ??
  1626. x1 = buff[9] <<8 | buff[10]
  1627. y1 = buff[11] <<8 | buff[12]
  1628. 13&14 ??
  1629. x2 = buff[15] << 8 | buff[16]
  1630. y2 = buff[17] <<8 | buff[18]
  1631. */
  1632.     event->z = 200;
  1633.  
  1634.     event->w = 1;
  1635.  
  1636.     if (focaltechPdata2->swap_xy)
  1637.  
  1638.         swap(event->x, event->y);
  1639.  
  1640.     if (focaltechPdata2->xpol)
  1641.  
  1642.             event->x = focaltechPdata2->screen_max_x - event->x;
  1643.  
  1644.     if (focaltechPdata2->ypol)
  1645.  
  1646.             event->y = focaltechPdata2->screen_max_y - event->y;
  1647.  
  1648.        
  1649.  
  1650.         //Denisc recommendation to use full pixel count
  1651.  
  1652.     /*  if (event->x < 20) event->x = 20;
  1653.  
  1654.         if (event->x > 1004) event->x = 1004;
  1655.  
  1656.         if (event->y < 20) event->y = 20;
  1657.  
  1658.         if (event->y > 580) event->y = 580; */
  1659.  
  1660.              
  1661.  
  1662.         if (event->x == 0) event->x = 1;
  1663.  
  1664.         if (event->y == 0) event->y = 1;
  1665.  
  1666.         event++;
  1667.  
  1668.     }
  1669.  
  1670.  
  1671.  
  1672.     return ret;
  1673.  
  1674. }
  1675.  
  1676.  
  1677.  
  1678. static void ft5x0x_report_mt_event(struct input_dev *input, struct ts_event *event, int event_num, int type)
  1679.  
  1680. {
  1681.  
  1682.     int i;
  1683.    
  1684.  
  1685.     for (i=0; i<FT5X0X_EVENT_MAX; i++) {
  1686.         bool down;
  1687.  
  1688.         if (event->type == TOUCH_EVENT_RESERVED)
  1689.             continue;
  1690.  
  1691.  
  1692.         down = (event->type != TOUCH_EVENT_UP);
  1693.         //input_report_abs(input, ABS_MT_TOUCH_ID, event->id);
  1694.  
  1695.         input_mt_slot(input, event->id);
  1696.  
  1697.         //maybe click ?
  1698.         //input_report_key(input, BTN_TOUCH, down);
  1699.  
  1700.         input_mt_report_slot_state(input, MT_TOOL_FINGER, down);
  1701.  
  1702.         if (!down)
  1703.             continue;
  1704.  
  1705.         input_report_abs(input, ABS_MT_POSITION_X, event->x);
  1706.         input_report_abs(input, ABS_MT_POSITION_Y, event->y);
  1707.  
  1708.         //input_report_abs(input, ABS_MT_TOUCH_MAJOR, event->z);
  1709.         //input_report_abs(input, ABS_MT_WIDTH_MAJOR, event->w);
  1710.  
  1711.         //input_mt_sync(input);
  1712.  
  1713.         ft5x0x_dbg("point_%d: %d, %d\n",event->id, event->x,event->y);
  1714.  
  1715.         event++;
  1716.  
  1717.     }
  1718.     input_mt_report_pointer_emulation(input, true);
  1719.     input_sync(input);
  1720.  
  1721. }
  1722.  
  1723.  
  1724.  
  1725. #define enter_touch_screen_state() {\
  1726.     data->first_event = data->event[0];\
  1727.     data->offset = 0;\
  1728.     data->touch_count = 0;\
  1729.     input_report_key(data->input_dev, BTN_TOUCH, 1);\
  1730.     data->touch_state = TOUCH_SCREEN;\
  1731. }
  1732.  
  1733.  
  1734.  
  1735. #define enter_key_pre_state() {\
  1736.     data->key = key;\
  1737.     data->touch_count = 0;\
  1738.     data->touch_state = TOUCH_KEY_PRE;\
  1739. }
  1740.  
  1741. /***********************************************************************************************
  1742.  
  1743. Name    :    
  1744.  
  1745.  
  1746.  
  1747. Input   :  
  1748.  
  1749.                      
  1750.  
  1751.  
  1752.  
  1753. Output  :  
  1754.  
  1755.  
  1756.  
  1757. function    :  
  1758.  
  1759.  
  1760.  
  1761. ***********************************************************************************************/
  1762.  
  1763. static void ft5x0x_ts_pen_irq_work(struct work_struct *work)
  1764.  
  1765. {
  1766.  
  1767.     struct ft5x0x_ts_data *data = i2c_get_clientdata(this_client);
  1768.  
  1769.     struct ts_event *event = &data->event[0];
  1770.  
  1771.     int event_num = 0;
  1772.  
  1773.    
  1774.  
  1775.     event_num = ft5x0x_get_event(event);
  1776.  
  1777.     if (event_num < 0) {
  1778.  
  1779.         enable_irq(this_client->irq);
  1780.  
  1781.         return;
  1782.  
  1783.     }
  1784.  
  1785.  
  1786.  
  1787. #ifdef AC_DETECT_IN_TOUCH_DRIVER
  1788.  
  1789.     Ac_Detect_In_Touch_Driver();
  1790.  
  1791. #endif
  1792.  
  1793.  
  1794.  
  1795. #ifdef CONFIG_TOUCH_PANEL_KEY
  1796.  
  1797.     int key = 0;
  1798.  
  1799.     if (event_num == 1) {
  1800.  
  1801.         key = is_tp_key(focaltechPdata2->tp_key, focaltechPdata2->tp_key_num, event->x, event->y);
  1802.  
  1803.         if (key)
  1804.  
  1805.             ft5x0x_dbg("key pos: %d, %d\n", event->x,event->y);
  1806.  
  1807.     }
  1808.  
  1809.    
  1810.  
  1811.     switch (data->touch_state) {
  1812.  
  1813.     case NO_TOUCH:
  1814.  
  1815.         if(key) {
  1816.  
  1817.             ft5x0x_dbg("touch key(%d) down 0\n", key);
  1818.  
  1819.             enter_key_pre_state();
  1820.  
  1821.         }
  1822.  
  1823.         else if (event_num) {
  1824.  
  1825.             ft5x0x_dbg("touch screen down\n");
  1826.  
  1827.             ft5x0x_report_mt_event(data->input_dev, event, event_num, data->touch_state);
  1828.  
  1829.             enter_touch_screen_state();
  1830.  
  1831.         }
  1832.  
  1833.         break;
  1834.  
  1835.  
  1836.  
  1837.     case TOUCH_KEY_PRE:
  1838.  
  1839.         if (key) {
  1840.  
  1841.             data->key = key;
  1842.  
  1843.             if (++data->touch_count > TAP_KEY_TIME) {
  1844.  
  1845.                 ft5x0x_dbg("touch key(%d) down\n", key);
  1846.  
  1847.                 input_report_key(data->input_dev, key, 1);
  1848.  
  1849.                 input_sync(data->input_dev);
  1850.  
  1851.                 data->touch_state = TOUCH_KEY;
  1852.  
  1853.             }
  1854.  
  1855.         }
  1856.  
  1857.         else if(event_num) {
  1858.  
  1859.             ft5x0x_report_mt_event(data->input_dev, event, event_num, data->touch_state);
  1860.  
  1861.             enter_touch_screen_state();
  1862.  
  1863.         }      
  1864.  
  1865.         else {
  1866.  
  1867.             hrtimer_start(&data->timer, ktime_set(0, TAP_KEY_RELEASE_DELAY), HRTIMER_MODE_REL);
  1868.  
  1869.             data->touch_state = TAP_KEY;
  1870.  
  1871.         }
  1872.  
  1873.         break;
  1874.  
  1875.    
  1876.  
  1877.     case TAP_KEY:
  1878.  
  1879.         if (key) {
  1880.  
  1881.             hrtimer_cancel(&data->timer);
  1882.  
  1883.             input_report_key(data->input_dev, data->key, 1);
  1884.  
  1885.             input_report_key(data->input_dev, data->key, 0);
  1886.  
  1887.             input_sync(data->input_dev);
  1888.  
  1889.             ft5x0x_dbg("touch key(%d) down(tap)\n", data->key);
  1890.  
  1891.             ft5x0x_dbg("touch key(%d) up(tap)\n", data->key);
  1892.  
  1893.             enter_key_pre_state();
  1894.  
  1895.         }
  1896.  
  1897.         else if (event_num) {
  1898.  
  1899.             hrtimer_cancel(&data->timer);
  1900.  
  1901.             ft5x0x_dbg("ignore the tap key!\n");
  1902.  
  1903.             ft5x0x_report_mt_event(data->input_dev, event, event_num, data->touch_state);
  1904.  
  1905.             enter_touch_screen_state();
  1906.  
  1907.         }
  1908.  
  1909.         break;
  1910.  
  1911.        
  1912.  
  1913.     case TOUCH_KEY:
  1914.  
  1915.         if (!event_num) {
  1916.  
  1917.             input_report_key(data->input_dev, data->key, 0);
  1918.  
  1919.             input_sync(data->input_dev);
  1920.  
  1921.             ft5x0x_dbg("touch key(%d) up\n", data->key);
  1922.  
  1923.             data->touch_state = NO_TOUCH;
  1924.  
  1925.         }
  1926.  
  1927.         break;
  1928.  
  1929.        
  1930.  
  1931.     case TOUCH_SCREEN:
  1932.  
  1933.         if (!event_num) {
  1934.  
  1935.             if ((data->offset < 10) && (data->touch_count > 1)) {
  1936.  
  1937.                 input_report_key(data->input_dev, BTN_TOUCH, 0);
  1938.  
  1939.                 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 0);
  1940.  
  1941.                 input_sync(data->input_dev);
  1942.  
  1943.                 ft5x0x_dbg("touch screen up!\n");
  1944.  
  1945.             data->touch_state = NO_TOUCH;
  1946.  
  1947.         }
  1948.  
  1949.         else {
  1950.  
  1951.                 #if 0
  1952.  
  1953.           hrtimer_start(&data->timer, ktime_set(0, TP_KEY_GUARANTEE_TIME_AFTER_TOUCH), HRTIMER_MODE_REL);//honghaoyu
  1954.  
  1955.                 #else
  1956.  
  1957.                 input_report_key(data->input_dev, BTN_TOUCH, 0);
  1958.  
  1959.                 input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 0);
  1960.  
  1961.                 input_sync(data->input_dev);
  1962.  
  1963.                 data->touch_state = NO_TOUCH;      
  1964.  
  1965.                 #endif 
  1966.  
  1967.          }
  1968.  
  1969.         }
  1970.  
  1971.         else {
  1972.  
  1973.             hrtimer_cancel(&data->timer);
  1974.  
  1975.             data->touch_count++;
  1976.  
  1977.             if (!key) {
  1978.  
  1979.                 int offset;
  1980.  
  1981.                 ft5x0x_report_mt_event(data->input_dev, event, event_num, data->touch_state);
  1982.  
  1983.                 offset = abs(event->x - data->first_event.x);
  1984.  
  1985.                 offset += abs(event->y - data->first_event.y);
  1986.  
  1987.                 if (offset > data->offset) data->offset = offset;
  1988.  
  1989.             }
  1990.  
  1991.         }
  1992.  
  1993.         break;
  1994.  
  1995.        
  1996.  
  1997.     default:
  1998.  
  1999.         break;
  2000.  
  2001.     }
  2002.  
  2003. #else
  2004.  
  2005.     //report even if even_num = 0;
  2006.     ft5x0x_report_mt_event(data->input_dev, event, event_num, 0);
  2007.     /*
  2008.     if (event_num)
  2009.  
  2010.     {  
  2011.  
  2012.         input_report_key(data->input_dev, BTN_TOUCH, 1);
  2013.  
  2014.         ft5x0x_report_mt_event(data->input_dev, event, event_num);
  2015.  
  2016.     }
  2017.  
  2018.     else {
  2019.  
  2020.         input_report_key(data->input_dev, BTN_TOUCH, 0);
  2021.  
  2022.         input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 0);
  2023.  
  2024.         input_sync(data->input_dev);
  2025.  
  2026.     } */
  2027.  
  2028. #endif
  2029.  
  2030.     enable_irq(this_client->irq);
  2031.  
  2032. }
  2033.  
  2034. /***********************************************************************************************
  2035.  
  2036. Name    :    
  2037.  
  2038.  
  2039.  
  2040. Input   :  
  2041.  
  2042.                      
  2043.  
  2044.  
  2045.  
  2046. Output  :  
  2047.  
  2048.  
  2049.  
  2050. function    :  
  2051.  
  2052.  
  2053.  
  2054. ***********************************************************************************************/
  2055.  
  2056. static irqreturn_t ft5x0x_ts_interrupt(int irq, void *dev_id)
  2057.  
  2058. {
  2059.  
  2060.     static int irq_count = 0;
  2061.  
  2062.     ft5x0x_dbg("irq count: %d\n", irq_count++);
  2063.  
  2064.     struct ft5x0x_ts_data *ft5x0x_ts = dev_id;
  2065.  
  2066.     disable_irq_nosync(this_client->irq);  
  2067.  
  2068.     if (!work_pending(&ft5x0x_ts->pen_event_work)) {
  2069.  
  2070.         queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);
  2071.  
  2072.     }
  2073.  
  2074.     return IRQ_HANDLED;
  2075.  
  2076. }
  2077.  
  2078. #ifdef CONFIG_HAS_EARLYSUSPEND
  2079.  
  2080. /***********************************************************************************************
  2081.  
  2082. Name    :    
  2083.  
  2084.  
  2085.  
  2086. Input   :  
  2087.  
  2088.                      
  2089.  
  2090.  
  2091.  
  2092. Output  :  
  2093.  
  2094.  
  2095.  
  2096. function    :  
  2097.  
  2098.  
  2099.  
  2100. ***********************************************************************************************/
  2101.  
  2102. static void ft5x0x_ts_suspend(struct early_suspend *handler)
  2103.  
  2104. {
  2105.  
  2106. //  struct ft5x0x_ts_data *ts;
  2107.  
  2108. //  ts =  container_of(handler, struct ft5x0x_ts_data, early_suspend);
  2109.  
  2110.     printk("==ft5x0x_ts_suspend=\n");
  2111.  
  2112.     if(focaltechPdata2->power) {
  2113.  
  2114.         u8 data;
  2115.  
  2116.         ft5x0x_write_reg(0xa5, 0x03);
  2117.  
  2118.         printk("set reg[0xa5] = 0x03\n");
  2119.  
  2120.         msleep(20);
  2121.  
  2122.         ft5x0x_read_reg(0xa5, &data);
  2123.  
  2124.         printk("read back: reg[0xa5] = %d\n", data);
  2125.  
  2126.     }
  2127.  
  2128.     gpio_out(PAD_GPIOC_3, 0);
  2129.  
  2130.     if (focaltechPdata2->key_led_ctrl)
  2131.  
  2132.         focaltechPdata2->key_led_ctrl(0);
  2133.  
  2134. }
  2135.  
  2136. /***********************************************************************************************
  2137.  
  2138. Name    :    
  2139.  
  2140.  
  2141.  
  2142. Input   :  
  2143.  
  2144.                      
  2145.  
  2146.  
  2147.  
  2148. Output  :  
  2149.  
  2150.  
  2151.  
  2152. function    :  
  2153.  
  2154.  
  2155.  
  2156. ***********************************************************************************************/
  2157.  
  2158. static void ft5x0x_ts_resume(struct early_suspend *handler)
  2159.  
  2160. {
  2161.  
  2162.     printk("==ft5x0x_ts_resume=\n");
  2163.  
  2164.     if(focaltechPdata2->power) {
  2165.  
  2166.         focaltechPdata2->power(0);
  2167.  
  2168.         msleep(50);
  2169.  
  2170.         focaltechPdata2->power(1);
  2171.  
  2172.         msleep(200);
  2173.  
  2174.     }
  2175.  
  2176.     gpio_out(PAD_GPIOC_3, 1);
  2177.  
  2178.     if (focaltechPdata2->key_led_ctrl)
  2179.  
  2180.         focaltechPdata2->key_led_ctrl(1);
  2181.  
  2182. }
  2183.  
  2184. #endif  //CONFIG_HAS_EARLYSUSPEND
  2185.  
  2186. /***********************************************************************************************
  2187.  
  2188. Name    :    
  2189.  
  2190.  
  2191.  
  2192. Input   :  
  2193.  
  2194.                      
  2195.  
  2196.  
  2197.  
  2198. Output  :  
  2199.  
  2200.  
  2201.  
  2202. function    :  
  2203.  
  2204.  
  2205.  
  2206. ***********************************************************************************************/
  2207.  
  2208. static int
  2209.  
  2210. ft5x0x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
  2211.  
  2212. {
  2213.  
  2214.     struct ft5x0x_ts_data *ft5x0x_ts;
  2215.  
  2216.     struct input_dev *input_dev;
  2217.  
  2218.     int err = 0;
  2219.  
  2220.     unsigned char uc_reg_value;
  2221.  
  2222.     struct ts_platform_data *pdata = client->dev.platform_data;
  2223.  
  2224.    
  2225.  
  2226.     if (!pdata) {
  2227.  
  2228.         printk("%s: no platform data\n", __FUNCTION__);
  2229.  
  2230.         err = -ENODEV;
  2231.  
  2232.         goto exit_check_functionality_failed;
  2233.  
  2234.        
  2235.  
  2236.     }
  2237.  
  2238.     focaltechPdata2 = client->dev.platform_data;
  2239.  
  2240.       gpio_out(PAD_GPIOC_3, 1);
  2241.  
  2242.         mdelay(5);
  2243.  
  2244.      
  2245.  
  2246.     if(pdata->power){
  2247.  
  2248.         pdata->power(0);
  2249.  
  2250.         mdelay(5);
  2251.  
  2252.         pdata->power(1);
  2253.  
  2254.         mdelay(300);
  2255.  
  2256.     }
  2257.  
  2258.    
  2259.  
  2260.     printk("==ft5x0x_ts_probe=\n");
  2261.  
  2262.    
  2263.  
  2264.    
  2265.  
  2266.     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  2267.  
  2268.         err = -ENODEV;
  2269.  
  2270.         goto exit_check_functionality_failed;
  2271.  
  2272.     }
  2273.  
  2274.     //client->irq =  client->dev.platform_data->irq;
  2275.  
  2276.     client->irq =pdata->irq;
  2277.  
  2278.     printk("==kzalloc=\n");
  2279.  
  2280.     ft5x0x_ts = kzalloc(sizeof(*ft5x0x_ts), GFP_KERNEL);
  2281.  
  2282.     if (!ft5x0x_ts) {
  2283.  
  2284.         err = -ENOMEM;
  2285.  
  2286.         goto exit_alloc_data_failed;
  2287.  
  2288.     }
  2289.  
  2290.  
  2291.  
  2292.     printk("==kzalloc success=\n");
  2293.  
  2294.     this_client = client;
  2295.  
  2296.     i2c_set_clientdata(client, ft5x0x_ts);
  2297.  
  2298.  
  2299.  
  2300.     INIT_WORK(&ft5x0x_ts->pen_event_work, ft5x0x_ts_pen_irq_work);
  2301.  
  2302.     ft5x0x_ts->ts_workqueue = create_singlethread_workqueue(dev_name(&client->dev));
  2303.  
  2304.     if (!ft5x0x_ts->ts_workqueue) {
  2305.  
  2306.         err = -ESRCH;
  2307.  
  2308.         goto exit_create_singlethread;
  2309.  
  2310.     }
  2311.  
  2312.  
  2313.  
  2314. //  __gpio_as_irq_fall_edge(pdata->intr);       //
  2315.  
  2316. printk("==enable Irq=\n");
  2317.  
  2318.     if (pdata->init_irq) {
  2319.  
  2320.         pdata->init_irq();
  2321.  
  2322.     }
  2323.  
  2324. printk("==enable Irq success=\n");
  2325.  
  2326.  
  2327.  
  2328.     disable_irq_nosync(this_client->irq);
  2329.  
  2330. //  disable_irq(IRQ_EINT(6));
  2331.  
  2332.  
  2333.  
  2334.     printk("==input_allocate_device=\n");
  2335.  
  2336.     input_dev = input_allocate_device();
  2337.  
  2338.     if (!input_dev) {
  2339.  
  2340.         err = -ENOMEM;
  2341.  
  2342.         dev_err(&client->dev, "failed to allocate input device\n");
  2343.  
  2344.         goto exit_input_dev_alloc_failed;
  2345.  
  2346.     }
  2347.  
  2348.    
  2349.  
  2350.     ft5x0x_ts->input_dev = input_dev;
  2351.  
  2352. #ifdef CONFIG_TOUCH_PANEL_KEY
  2353.  
  2354.     ft5x0x_ts->touch_state = NO_TOUCH;
  2355.  
  2356.     ft5x0x_ts->key = 0;
  2357.  
  2358.     if (pdata->tp_key && pdata->tp_key_num) {
  2359.  
  2360.         int i;
  2361.  
  2362.         for (i=0; i<pdata->tp_key_num; i++) {
  2363.  
  2364.             set_bit(pdata->tp_key[i].key, input_dev->keybit);
  2365.  
  2366.             printk("tp key (%d)registered\n", pdata->tp_key[i].key);
  2367.  
  2368.         }
  2369.  
  2370.         set_bit(EV_SYN, input_dev->evbit);
  2371.  
  2372.         hrtimer_init(&ft5x0x_ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  2373.  
  2374.         ft5x0x_ts->timer.function = ft5x0x_timer;
  2375.  
  2376.     }
  2377.  
  2378. #endif
  2379.  
  2380.  
  2381.  
  2382.     //add EV_SYN
  2383.     __set_bit(EV_SYN, input_dev->evbit);
  2384.     __set_bit(EV_KEY, input_dev->evbit);
  2385.     __set_bit(EV_ABS, input_dev->evbit);
  2386.     __set_bit(BTN_TOUCH, input_dev->keybit);
  2387.  
  2388.     /*
  2389.     set_bit(ABS_MT_TOUCH_MAJOR, input_dev->absbit);
  2390.  
  2391.     set_bit(ABS_MT_POSITION_X, input_dev->absbit);
  2392.  
  2393.     set_bit(ABS_MT_POSITION_Y, input_dev->absbit);
  2394.  
  2395.     set_bit(ABS_MT_WIDTH_MAJOR, input_dev->absbit);
  2396.     */
  2397.  
  2398.     // add ABS_X & ABS_Y
  2399.     input_set_abs_params(input_dev,
  2400.                  ABS_X, 0, pdata->screen_max_x, 0, 0);
  2401.  
  2402.     input_set_abs_params(input_dev,
  2403.                  ABS_Y, 0, pdata->screen_max_y, 0, 0);
  2404.  
  2405.     input_set_abs_params(input_dev,
  2406.                  ABS_MT_POSITION_X, 0, pdata->screen_max_x, 0, 0);
  2407.  
  2408.     input_set_abs_params(input_dev,
  2409.                  ABS_MT_POSITION_Y, 0, pdata->screen_max_y, 0, 0);
  2410.  
  2411.  
  2412.     //init mt slots
  2413.     err = input_mt_init_slots(input_dev, FT5X0X_EVENT_MAX);
  2414.    
  2415.     if(err) {
  2416.         dev_err(&client->dev, "failed to allocate input device\n");
  2417.         goto exit_input_register_device_failed;
  2418.     }
  2419.     /*
  2420.     input_set_abs_params(input_dev,
  2421.                  ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
  2422.  
  2423.     input_set_abs_params(input_dev,
  2424.                  ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
  2425.  
  2426.     */
  2427.  
  2428.    
  2429.  
  2430.  
  2431.  
  2432.     input_dev->name     = FT5X0X_NAME;      //dev_name(&client->dev)
  2433.  
  2434.     err = input_register_device(input_dev);
  2435.  
  2436.     if (err) {
  2437.  
  2438.         dev_err(&client->dev,
  2439.  
  2440.         "ft5x0x_ts_probe: failed to register input device: %s\n",
  2441.  
  2442.         dev_name(&client->dev));
  2443.  
  2444.         goto exit_input_register_device_failed;
  2445.  
  2446.     }
  2447.  
  2448.  
  2449.  
  2450. #ifdef CONFIG_HAS_EARLYSUSPEND
  2451.  
  2452.     printk("==register_early_suspend =\n");
  2453.  
  2454.     ft5x0x_ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  2455.  
  2456.     ft5x0x_ts->early_suspend.suspend = ft5x0x_ts_suspend;
  2457.  
  2458.     ft5x0x_ts->early_suspend.resume = ft5x0x_ts_resume;
  2459.  
  2460.     register_early_suspend(&ft5x0x_ts->early_suspend);
  2461.  
  2462. #endif
  2463.  
  2464.  
  2465.  
  2466.     uc_reg_value = ft5x0x_read_fw_ver();
  2467.  
  2468.     printk("[FST] Firmware version = 0x%x\n", uc_reg_value);
  2469.  
  2470. #ifdef CONFIG_FOCALTECH_TOUCHSCREEN_CODE_UPG
  2471.  
  2472.     msleep(50);
  2473.  
  2474.     //get some register information
  2475.  
  2476.     uc_reg_value = ft5x0x_read_fw_ver();
  2477.  
  2478.     printk("[FST] Firmware old version = 0x%x\n", uc_reg_value);
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.     fts_ctpm_fw_upgrade_with_i_file();
  2485.  
  2486.     mdelay(200);
  2487.  
  2488.     uc_reg_value = ft5x0x_read_fw_ver();
  2489.  
  2490.     printk("[FST] Firmware new version after update = 0x%x\n", uc_reg_value);
  2491.  
  2492. #endif
  2493.  
  2494.  
  2495.  
  2496.     err = request_irq(client->irq, ft5x0x_ts_interrupt, IRQF_DISABLED, "ft5x0x_ts", ft5x0x_ts);
  2497.  
  2498. //  err = request_irq(IRQ_EINT(6), ft5x0x_ts_interrupt, IRQF_TRIGGER_FALLING, "ft5x0x_ts", ft5x0x_ts);
  2499.  
  2500.     if (err < 0) {
  2501.  
  2502.         dev_err(&client->dev, "ft5x0x_probe: request irq failed\n");
  2503.  
  2504.         goto exit_irq_request_failed;
  2505.  
  2506.     }
  2507.  
  2508.  
  2509.  
  2510.    
  2511.  
  2512. //wake the CTPM
  2513.  
  2514. //  __gpio_as_output(GPIO_FT5X0X_WAKE);    
  2515.  
  2516. //  __gpio_clear_pin(GPIO_FT5X0X_WAKE);     //set wake = 0,base on system
  2517.  
  2518. //   msleep(100);
  2519.  
  2520. //  __gpio_set_pin(GPIO_FT5X0X_WAKE);           //set wake = 1,base on system
  2521.  
  2522. //  msleep(100);
  2523.  
  2524. //  ft5x0x_set_reg(0x88, 0x05); //5, 6,7,8
  2525.  
  2526. //  ft5x0x_set_reg(0x80, 30);
  2527.  
  2528. //  msleep(50);
  2529.  
  2530. //  enable_irq(this_client->irq);
  2531.  
  2532.    // enable_irq(IRQ_EINT(6));
  2533.  
  2534.    
  2535.  
  2536.     err = sysfs_create_group(&client->dev.kobj, &ft5x0x_attr_group);
  2537.  
  2538.     if(err)
  2539.         goto exit_input_register_device_failed;
  2540.  
  2541.  
  2542.     if (focaltechPdata2->key_led_ctrl)
  2543.  
  2544.         focaltechPdata2->key_led_ctrl(1);
  2545.  
  2546.     printk("==probe over =\n");
  2547.  
  2548.     return 0;
  2549.  
  2550.  
  2551.  
  2552. exit_input_register_device_failed:
  2553.  
  2554.     input_free_device(input_dev);
  2555.  
  2556. exit_input_dev_alloc_failed:
  2557.  
  2558.     free_irq(client->irq, ft5x0x_ts);
  2559.  
  2560. //  free_irq(IRQ_EINT(6), ft5x0x_ts);
  2561.  
  2562. exit_irq_request_failed:
  2563.  
  2564. exit_platform_data_null:
  2565.  
  2566.     cancel_work_sync(&ft5x0x_ts->pen_event_work);
  2567.  
  2568.     destroy_workqueue(ft5x0x_ts->ts_workqueue);
  2569.  
  2570. exit_create_singlethread:
  2571.  
  2572.     printk("==singlethread error =\n");
  2573.  
  2574.     i2c_set_clientdata(client, NULL);
  2575.  
  2576.     kfree(ft5x0x_ts);
  2577.  
  2578. exit_alloc_data_failed:
  2579.  
  2580. exit_check_functionality_failed:
  2581.  
  2582.     return err;
  2583.  
  2584. }
  2585.  
  2586. /***********************************************************************************************
  2587.  
  2588. Name    :    
  2589.  
  2590.  
  2591.  
  2592. Input   :  
  2593.  
  2594.                      
  2595.  
  2596.  
  2597.  
  2598. Output  :  
  2599.  
  2600.  
  2601.  
  2602. function    :  
  2603.  
  2604.  
  2605.  
  2606. ***********************************************************************************************/
  2607.  
  2608. static int __devexit ft5x0x_ts_remove(struct i2c_client *client)
  2609.  
  2610. {
  2611.  
  2612.     printk("==ft5x0x_ts_remove=\n");
  2613.  
  2614.     struct ft5x0x_ts_data *ft5x0x_ts = i2c_get_clientdata(client);
  2615.  
  2616.     unregister_early_suspend(&ft5x0x_ts->early_suspend);
  2617.  
  2618.     free_irq(client->irq, ft5x0x_ts);
  2619.  
  2620. //  free_irq(IRQ_EINT(6), ft5x0x_ts);
  2621.  
  2622.     input_unregister_device(ft5x0x_ts->input_dev);
  2623.  
  2624.     kfree(ft5x0x_ts);
  2625.  
  2626.     cancel_work_sync(&ft5x0x_ts->pen_event_work);
  2627.  
  2628.     destroy_workqueue(ft5x0x_ts->ts_workqueue);
  2629.  
  2630.     i2c_set_clientdata(client, NULL);
  2631.  
  2632.     return 0;
  2633.  
  2634. }
  2635.  
  2636.  
  2637.  
  2638. static const struct i2c_device_id ft5x0x_ts_id[] = {
  2639.  
  2640.     { FT5X0X_NAME, 0 },{ }
  2641.  
  2642. };
  2643.  
  2644.  
  2645.  
  2646.  
  2647.  
  2648. MODULE_DEVICE_TABLE(i2c, ft5x0x_ts_id);
  2649.  
  2650.  
  2651.  
  2652. static struct i2c_driver ft5x0x_ts_driver = {
  2653.  
  2654.     .probe      = ft5x0x_ts_probe,
  2655.  
  2656.     .remove     = __devexit_p(ft5x0x_ts_remove),
  2657.  
  2658.     .id_table   = ft5x0x_ts_id,
  2659.  
  2660.     .driver = {
  2661.  
  2662.         .name   = FT5X0X_NAME,
  2663.  
  2664.         .owner  = THIS_MODULE,
  2665.  
  2666.     },
  2667.  
  2668. };
  2669.  
  2670.  
  2671.  
  2672. /***********************************************************************************************
  2673.  
  2674. Name    :    
  2675.  
  2676.  
  2677.  
  2678. Input   :  
  2679.  
  2680.                      
  2681.  
  2682.  
  2683.  
  2684. Output  :  
  2685.  
  2686.  
  2687.  
  2688. function    :  
  2689.  
  2690.  
  2691.  
  2692. ***********************************************************************************************/
  2693.  
  2694. static int __init ft5x0x_ts_init(void)
  2695.  
  2696. {
  2697.  
  2698.     int ret;
  2699.  
  2700.     printk("==ft5x0x_ts_init==\n");
  2701.  
  2702.     ret = i2c_add_driver(&ft5x0x_ts_driver);
  2703.  
  2704.     printk("ret=%d\n",ret);
  2705.  
  2706.     return ret;
  2707.  
  2708. //  return i2c_add_driver(&ft5x0x_ts_driver);
  2709.  
  2710. }
  2711.  
  2712.  
  2713.  
  2714. /***********************************************************************************************
  2715.  
  2716. Name    :    
  2717.  
  2718.  
  2719.  
  2720. Input   :  
  2721.  
  2722.                      
  2723.  
  2724.  
  2725.  
  2726. Output  :  
  2727.  
  2728.  
  2729.  
  2730. function    :  
  2731.  
  2732.  
  2733.  
  2734. ***********************************************************************************************/
  2735.  
  2736. static void __exit ft5x0x_ts_exit(void)
  2737.  
  2738. {
  2739.  
  2740.     printk("==ft5x0x_ts_exit==\n");
  2741.  
  2742.     i2c_del_driver(&ft5x0x_ts_driver);
  2743.  
  2744. }
  2745.  
  2746.  
  2747.  
  2748. module_init(ft5x0x_ts_init);
  2749.  
  2750. module_exit(ft5x0x_ts_exit);
  2751.  
  2752.  
  2753.  
  2754. MODULE_AUTHOR("<wenfs@Focaltech-systems.com>");
  2755.  
  2756. MODULE_DESCRIPTION("FocalTech ft5x0x TouchScreen driver");
  2757.  
  2758. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement