Chinaunix首页 | 论坛 | 博客
  • 博客访问: 477051
  • 博文数量: 100
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 955
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-21 09:30
文章分类

全部博文(100)

文章存档

2017年(1)

2016年(16)

2015年(83)

我的朋友

分类: 嵌入式

2015-07-28 14:18:12

x210 kernel中的ft5x06.c:

点击(此处)折叠或打开

  1. /*
  2.  * drivers/input/touchscreen/ft5x0x_ts.c
  3.  *
  4.  * FocalTech ft5x0x TouchScreen driver.
  5.  *
  6.  * Copyright (c) 2010 Focal tech Ltd.
  7.  *
  8.  * This software is licensed under the terms of the GNU General Public
  9.  * License version 2, as published by the Free Software Foundation, and
  10.  * may be copied, distributed, and modified under those terms.
  11.  *
  12.  * This program is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15.  * GNU General Public License for more details.
  16.  *
  17.  * VERSION DATE AUTHOR Note
  18.  * 1.0 2010-01-05 WenFS only support mulititouch Wenfs 2010-10-01
  19.  * 2.0 2011-09-05 Duxx Add touch key, and project setting update, auto CLB command
  20.  *
  21.  *
  22.  */

  23. #include <linux/i2c.h>
  24. #include <linux/input.h>
  25. #include <linux/slab.h>
  26. #include "ft5x06_ts.h"
  27. #include <linux/earlysuspend.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/delay.h>
  30. #include <linux/irq.h>
  31. #include <linux/io.h>
  32. #include <linux/platform_device.h>
  33. #include <mach/gpio.h>
  34. #include <plat/gpio-cfg.h>
  35. //#include <asm/jzsoc.h>

  36. extern int have_cap_touchscreen;

  37. static struct i2c_client *this_client;

  38. #define CONFIG_FT5X0X_MULTITOUCH 1
  39. #define FT5406_I2C_BUS             1

  40. struct ts_event {
  41.     u16 au16_x[CFG_MAX_TOUCH_POINTS]; //x coordinate
  42.     u16 au16_y[CFG_MAX_TOUCH_POINTS]; //y coordinate
  43.     u8 au8_touch_event[CFG_MAX_TOUCH_POINTS]; //touch event: 0 -- down; 1-- contact; 2 -- contact
  44.     u8 au8_finger_id[CFG_MAX_TOUCH_POINTS]; //touch ID
  45.     u16 pressure;
  46.     u8 touch_point;
  47. };


  48. struct ft5x0x_ts_data {
  49.     struct input_dev *input_dev;
  50.     struct ts_event event;
  51.     struct work_struct pen_event_work;
  52.     struct workqueue_struct *ts_workqueue;
  53.     struct early_suspend early_suspend;
  54. };


  55. #if CFG_SUPPORT_TOUCH_KEY
  56. int tsp_keycodes[CFG_NUMOFKEYS] ={

  57.         KEY_MENU,
  58.         KEY_HOME,
  59.         KEY_BACK,
  60.         KEY_SEARCH
  61. };

  62. char *tsp_keyname[CFG_NUMOFKEYS] ={

  63.         "Menu",
  64.         "Home",
  65.         "Back",
  66.         "Search"
  67. };

  68. static bool tsp_keystatus[CFG_NUMOFKEYS];
  69. #endif
  70. /***********************************************************************************************
  71. Name : ft5x0x_i2c_rxdata

  72. Input : *rxdata
  73.               *length

  74. Output : ret

  75. function :

  76. ***********************************************************************************************/
  77. static int ft5x0x_i2c_rxdata(char *rxdata, int length)
  78. {
  79.     int ret;

  80.     struct i2c_msg msgs[] = {
  81.         {
  82.             .addr = this_client->addr,
  83.             .flags = 0,
  84.             .len = 1,
  85.             .buf = rxdata,
  86.         },
  87.         {
  88.             .addr = this_client->addr,
  89.             .flags = I2C_M_RD,
  90.             .len = length,
  91.             .buf = rxdata,
  92.         },
  93.     };

  94.     //msleep(1);
  95.     ret = i2c_transfer(this_client->adapter, msgs, 2);
  96.     if (ret < 0)
  97.         pr_err("msg %s i2c read error: %d\n", __func__, ret);
  98.     
  99.     return ret;
  100. }
  101. /***********************************************************************************************
  102. Name :

  103. Input :

  104. Output :

  105. function :

  106. ***********************************************************************************************/
  107. static int ft5x0x_i2c_txdata(char *txdata, int length)
  108. {
  109.     int ret;

  110.     struct i2c_msg msg[] = {
  111.         {
  112.             .addr = this_client->addr,
  113.             .flags = 0,
  114.             .len = length,
  115.             .buf = txdata,
  116.         },
  117.     };

  118.        //msleep(1);
  119.     ret = i2c_transfer(this_client->adapter, msg, 1);
  120.     if (ret < 0)
  121.         pr_err("%s i2c write error: %d\n", __func__, ret);

  122.     return ret;
  123. }
  124. /***********************************************************************************************
  125. Name : ft5x0x_write_reg

  126. Input : addr -- address
  127.                      para -- parameter

  128. Output :

  129. function : write register of ft5x0x

  130. ***********************************************************************************************/
  131. static int ft5x0x_write_reg(u8 addr, u8 para)
  132. {
  133.     u8 buf[3];
  134.     int ret = -1;

  135.     buf[0] = addr;
  136.     buf[1] = para;
  137.     ret = ft5x0x_i2c_txdata(buf, 2);
  138.     if (ret < 0) {
  139.         pr_err("write reg failed! %#x ret: %d", buf[0], ret);
  140.         return -1;
  141.     }
  142.     
  143.     return 0;
  144. }


  145. /***********************************************************************************************
  146. Name : ft5x0x_read_reg

  147. Input : addr
  148.               pdata

  149. Output :

  150. function : read register of ft5x0x

  151. ***********************************************************************************************/
  152. static int ft5x0x_read_reg(u8 addr, u8 *pdata)
  153. {
  154.     int ret;
  155.     u8 buf[2];
  156.     struct i2c_msg msgs[2];

  157.     //
  158.     buf[0] = addr; //register address
  159.     
  160.     msgs[0].addr = this_client->addr;
  161.     msgs[0].flags = 0;//先写I2C设备地址,写模式
  162.     msgs[0].len = 1;
  163.     msgs[0].buf = buf;
  164.     msgs[1].addr = this_client->addr;
  165.     msgs[1].flags = I2C_M_RD;//再写I2C寄存器,读模式
  166.     msgs[1].len = 1;
  167.     msgs[1].buf = buf;

  168.     ret = i2c_transfer(this_client->adapter, msgs, 2);
  169.     if (ret < 0)
  170.         pr_err("msg %s i2c read error: %d\n", __func__, ret);

  171.     *pdata = buf[0];
  172.     return ret;
  173. }


  174. /***********************************************************************************************
  175. Name : ft5x0x_read_fw_ver

  176. Input : void

  177. Output : firmware version

  178. function : read TP firmware version

  179. ***********************************************************************************************/
  180. static unsigned char ft5x0x_read_fw_ver(void)
  181. {
  182.     unsigned char ver;
  183.     ft5x0x_read_reg(FT5X0X_REG_FIRMID, &ver);
  184.     return(ver);
  185. }

  186. #if 1 //upgrade related
  187. typedef enum
  188. {
  189.     ERR_OK,
  190.     ERR_MODE,
  191.     ERR_READID,
  192.     ERR_ERASE,
  193.     ERR_STATUS,
  194.     ERR_ECC,
  195.     ERR_DL_ERASE_FAIL,
  196.     ERR_DL_PROGRAM_FAIL,
  197.     ERR_DL_VERIFY_FAIL
  198. }E_UPGRADE_ERR_TYPE;

  199. typedef unsigned char FTS_BYTE; //8 bit
  200. typedef unsigned short FTS_WORD; //16 bit
  201. typedef unsigned int FTS_DWRD; //16 bit
  202. typedef unsigned char FTS_BOOL; //8 bit

  203. typedef struct _FTS_CTP_PROJECT_SETTING_T
  204. {
  205.     unsigned char uc_i2C_addr; //I2C slave address (8 bit address)
  206.     unsigned char uc_io_voltage; //IO Voltage 0---3.3v; 1----1.8v
  207.     unsigned char uc_panel_factory_id; //TP panel factory ID
  208. }FTS_CTP_PROJECT_SETTING_T;

  209. #define FTS_NULL 0x0
  210. #define FTS_TRUE 0x01
  211. #define FTS_FALSE 0x0

  212. #define I2C_CTPM_ADDRESS 0x70>>1
  213. //#define I2C_CTPM_ADDRESS 0x38    //lqm test


  214. void delay_qt_ms(unsigned long w_ms)
  215. {
  216.     unsigned long i;
  217.     unsigned long j;

  218.     for (i = 0; i < w_ms; i++)
  219.     {
  220.         for (j = 0; j < 1000; j++)
  221.         {
  222.             udelay(1);
  223.         }
  224.     }
  225. }


  226. /*
  227. [function]:
  228.     callback: read data from ctpm by i2c interface,implemented by special user;
  229. [parameters]:
  230.     bt_ctpm_addr[in] :the address of the ctpm;
  231.     pbt_buf[out] :data buffer;
  232.     dw_lenth[in] :the length of the data buffer;
  233. [return]:
  234.     FTS_TRUE :success;
  235.     FTS_FALSE :fail;
  236. */
  237. FTS_BOOL i2c_read_interface(FTS_BYTE bt_ctpm_addr, FTS_BYTE* pbt_buf, FTS_DWRD dw_lenth)
  238. {
  239.     int ret;
  240.     
  241.     ret=i2c_master_recv(this_client, pbt_buf, dw_lenth);

  242.     if(ret<=0)
  243.     {
  244.         printk("[FTS]i2c_read_interface error\n");
  245.         return FTS_FALSE;
  246.     }

  247.     return FTS_TRUE;
  248. }

  249. /*
  250. [function]:
  251.     callback: write data to ctpm by i2c interface,implemented by special user;
  252. [parameters]:
  253.     bt_ctpm_addr[in] :the address of the ctpm;
  254.     pbt_buf[in] :data buffer;
  255.     dw_lenth[in] :the length of the data buffer;
  256. [return]:
  257.     FTS_TRUE :success;
  258.     FTS_FALSE :fail;
  259. */
  260. FTS_BOOL i2c_write_interface(FTS_BYTE bt_ctpm_addr, FTS_BYTE* pbt_buf, FTS_DWRD dw_lenth)
  261. {
  262.     int ret;
  263.     ret=i2c_master_send(this_client, pbt_buf, dw_lenth);
  264.     if(ret<=0)
  265.     {
  266.         printk("[FTS]i2c_write_interface error line = %d, ret = %d\n", __LINE__, ret);
  267.         return FTS_FALSE;
  268.     }

  269.     return FTS_TRUE;
  270. }

  271. /*
  272. [function]:
  273.     send a command to ctpm.
  274. [parameters]:
  275.     btcmd[in] :command code;
  276.     btPara1[in] :parameter 1;
  277.     btPara2[in] :parameter 2;
  278.     btPara3[in] :parameter 3;
  279.     num[in] :the valid input parameter numbers, if only command code needed and no parameters followed,then the num is 1;
  280. [return]:
  281.     FTS_TRUE :success;
  282.     FTS_FALSE :io fail;
  283. */
  284. FTS_BOOL cmd_write(FTS_BYTE btcmd,FTS_BYTE btPara1,FTS_BYTE btPara2,FTS_BYTE btPara3,FTS_BYTE num)
  285. {
  286.     FTS_BYTE write_cmd[4] = {0};

  287.     write_cmd[0] = btcmd;
  288.     write_cmd[1] = btPara1;
  289.     write_cmd[2] = btPara2;
  290.     write_cmd[3] = btPara3;
  291.     return i2c_write_interface(I2C_CTPM_ADDRESS, write_cmd, num);
  292. }

  293. /*
  294. [function]:
  295.     write data to ctpm , the destination address is 0.
  296. [parameters]:
  297.     pbt_buf[in] :point to data buffer;
  298.     bt_len[in] :the data numbers;
  299. [return]:
  300.     FTS_TRUE :success;
  301.     FTS_FALSE :io fail;
  302. */
  303. FTS_BOOL byte_write(FTS_BYTE* pbt_buf, FTS_DWRD dw_len)
  304. {
  305.     
  306.     return i2c_write_interface(I2C_CTPM_ADDRESS, pbt_buf, dw_len);
  307. }

  308. /*
  309. [function]:
  310.     read out data from ctpm,the destination address is 0.
  311. [parameters]:
  312.     pbt_buf[out] :point to data buffer;
  313.     bt_len[in] :the data numbers;
  314. [return]:
  315.     FTS_TRUE :success;
  316.     FTS_FALSE :io fail;
  317. */
  318. FTS_BOOL byte_read(FTS_BYTE* pbt_buf, FTS_BYTE bt_len)
  319. {
  320.     return i2c_read_interface(I2C_CTPM_ADDRESS, pbt_buf, bt_len);
  321. }


  322. /*
  323. [function]:
  324.     burn the FW to ctpm.
  325. [parameters]:(ref. SPEC)
  326.     pbt_buf[in] :point to Head+FW ;
  327.     dw_lenth[in]:the length of the FW + 6(the Head length);
  328.     bt_ecc[in] :the ECC of the FW
  329. [return]:
  330.     ERR_OK :no error;
  331.     ERR_MODE :fail to switch to UPDATE mode;
  332.     ERR_READID :read id fail;
  333.     ERR_ERASE :erase chip fail;
  334.     ERR_STATUS :status error;
  335.     ERR_ECC :ecc error.
  336. */


  337. #define FTS_PACKET_LENGTH 128

  338. static unsigned char CTPM_FW[]=
  339. {
  340. #include "x210ii_app.i"    //lqm masked for test.
  341. };

  342. E_UPGRADE_ERR_TYPE fts_ctpm_fw_upgrade(FTS_BYTE* pbt_buf, FTS_DWRD dw_lenth)
  343. {
  344.     FTS_BYTE reg_val[2] = {0};
  345.     FTS_DWRD i = 0;

  346.     FTS_DWRD packet_number;
  347.     FTS_DWRD j;
  348.     FTS_DWRD temp;
  349.     FTS_DWRD lenght;
  350.     FTS_BYTE packet_buf[FTS_PACKET_LENGTH + 6];
  351.     FTS_BYTE auc_i2c_write_buf[10];
  352.     FTS_BYTE bt_ecc;
  353.     int i_ret;

  354.     /*********Step 1:Reset CTPM *****/
  355.     /*write 0xaa to register 0xfc*/
  356.     ft5x0x_write_reg(0xfc,0xaa);
  357.     delay_qt_ms(50);
  358.      /*write 0x55 to register 0xfc*/
  359.     ft5x0x_write_reg(0xfc,0x55);
  360.     printk("[FTS] Step 1: Reset CTPM test\n");

  361.     delay_qt_ms(30);


  362.     /*********Step 2:Enter upgrade mode *****/
  363.     auc_i2c_write_buf[0] = 0x55;
  364.     auc_i2c_write_buf[1] = 0xaa;
  365.     do
  366.     {
  367.         i ++;
  368.         i_ret = ft5x0x_i2c_txdata(auc_i2c_write_buf, 2);
  369.         delay_qt_ms(5);
  370.     }while(i_ret <= 0 && i < 5 );

  371.     /*********Step 3:check READ-ID***********************/
  372.     cmd_write(0x90,0x00,0x00,0x00,4);
  373.     byte_read(reg_val,2);
  374.     if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
  375.     {
  376.         printk("[FTS] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
  377.     }
  378.     else
  379.     {
  380.         return ERR_READID;
  381.         //i_is_new_protocol = 1;
  382.     }

  383.     cmd_write(0xcd,0x0,0x00,0x00,1);
  384.     byte_read(reg_val,1);
  385.     printk("[FTS] bootloader version = 0x%x\n", reg_val[0]);

  386.      /*********Step 4:erase app and panel paramenter area ********************/
  387.     cmd_write(0x61,0x00,0x00,0x00,1); //erase app area
  388.     delay_qt_ms(1500);
  389.     cmd_write(0x63,0x00,0x00,0x00,1); //erase panel parameter area
  390.     delay_qt_ms(100);
  391.     printk("[FTS] Step 4: erase. \n");

  392.     /*********Step 5:write firmware(FW) to ctpm flash*********/
  393.     bt_ecc = 0;
  394.     printk("[FTS] Step 5: start upgrade. \n");
  395.     dw_lenth = dw_lenth - 8;
  396.     packet_number = (dw_lenth) / FTS_PACKET_LENGTH;
  397.     packet_buf[0] = 0xbf;
  398.     packet_buf[1] = 0x00;
  399.     for (j=0;j<packet_number;j++)
  400.     {
  401.         temp = j * FTS_PACKET_LENGTH;
  402.         packet_buf[2] = (FTS_BYTE)(temp>>8);
  403.         packet_buf[3] = (FTS_BYTE)temp;
  404.         lenght = FTS_PACKET_LENGTH;
  405.         packet_buf[4] = (FTS_BYTE)(lenght>>8);
  406.         packet_buf[5] = (FTS_BYTE)lenght;

  407.         for (i=0;i<FTS_PACKET_LENGTH;i++)
  408.         {
  409.             packet_buf[6+i] = pbt_buf[j*FTS_PACKET_LENGTH + i];
  410.             bt_ecc ^= packet_buf[6+i];
  411.         }
  412.         
  413.         byte_write(&packet_buf[0],FTS_PACKET_LENGTH + 6);
  414.         delay_qt_ms(FTS_PACKET_LENGTH/6 + 1);
  415.         if ((j * FTS_PACKET_LENGTH % 1024) == 0)
  416.         {
  417.               printk("[FTS] upgrade the 0x%x th byte.\n", ((unsigned int)j) * FTS_PACKET_LENGTH);
  418.         }
  419.     }

  420.     if ((dw_lenth) % FTS_PACKET_LENGTH > 0)
  421.     {
  422.         temp = packet_number * FTS_PACKET_LENGTH;
  423.         packet_buf[2] = (FTS_BYTE)(temp>>8);
  424.         packet_buf[3] = (FTS_BYTE)temp;

  425.         temp = (dw_lenth) % FTS_PACKET_LENGTH;
  426.         packet_buf[4] = (FTS_BYTE)(temp>>8);
  427.         packet_buf[5] = (FTS_BYTE)temp;

  428.         for (i=0;i<temp;i++)
  429.         {
  430.             packet_buf[6+i] = pbt_buf[ packet_number*FTS_PACKET_LENGTH + i];
  431.             bt_ecc ^= packet_buf[6+i];
  432.         }

  433.         byte_write(&packet_buf[0],temp+6);
  434.         delay_qt_ms(20);
  435.     }

  436.     //send the last six byte
  437.     for (i = 0; i<6; i++)
  438.     {
  439.         temp = 0x6ffa + i;
  440.         packet_buf[2] = (FTS_BYTE)(temp>>8);
  441.         packet_buf[3] = (FTS_BYTE)temp;
  442.         temp =1;
  443.         packet_buf[4] = (FTS_BYTE)(temp>>8);
  444.         packet_buf[5] = (FTS_BYTE)temp;
  445.         packet_buf[6] = pbt_buf[ dw_lenth + i];
  446.         bt_ecc ^= packet_buf[6];

  447.         byte_write(&packet_buf[0],7);
  448.         delay_qt_ms(20);
  449.     }


  450.     /*********Step 6: read out checksum***********************/
  451.     /*send the opration head*/
  452.     cmd_write(0xcc,0x00,0x00,0x00,1);
  453.     byte_read(reg_val,1);
  454.     printk("[FTS] Step 6: ecc read 0x%x, new firmware 0x%x. \n", reg_val[0], bt_ecc);
  455.     if(reg_val[0] != bt_ecc)
  456.     {
  457.         return ERR_ECC;
  458.     }

  459.     /*********Step 7: reset the new FW***********************/
  460.     cmd_write(0x07,0x00,0x00,0x00,1);

  461.     msleep(300); //make sure CTP startup normally
  462.     
  463.     return ERR_OK;
  464. }

  465. int fts_ctpm_auto_clb(void)
  466. {
  467.     unsigned char uc_temp;
  468.     unsigned char i ;

  469.     printk("[FTS] start auto CLB.\n");
  470.     msleep(200);
  471.     ft5x0x_write_reg(0, 0x40);
  472.     delay_qt_ms(100); //make sure already enter factory mode
  473.     ft5x0x_write_reg(2, 0x4); //write command to start calibration
  474.     delay_qt_ms(300);
  475.     for(i=0;i<100;i++)
  476.     {
  477.         ft5x0x_read_reg(0,&uc_temp);
  478.         if ( ((uc_temp&0x70)>>4) == 0x0) //return to normal mode, calibration finish
  479.         {
  480.             break;
  481.         }
  482.         delay_qt_ms(200);
  483.         printk("[FTS] waiting calibration %d\n",i);
  484.         
  485.     }
  486.     printk("[FTS] calibration OK.\n");
  487.     
  488.     msleep(300);
  489.     ft5x0x_write_reg(0, 0x40); //goto factory mode
  490.     delay_qt_ms(100); //make sure already enter factory mode
  491.     ft5x0x_write_reg(2, 0x5); //store CLB result
  492.     delay_qt_ms(300);
  493.     ft5x0x_write_reg(0, 0x0); //return to normal mode
  494.     msleep(300);
  495.     printk("[FTS] store CLB result OK.\n");
  496.     return 0;
  497. }

  498. int fts_ctpm_fw_upgrade_with_i_file(void)
  499. {
  500.    FTS_BYTE* pbt_buf = FTS_NULL;
  501.    int i_ret;
  502.     
  503.     //=========FW upgrade========================*/
  504.    pbt_buf = CTPM_FW;
  505.    /*call the upgrade function*/
  506.    i_ret = fts_ctpm_fw_upgrade(pbt_buf,sizeof(CTPM_FW));
  507.    if (i_ret != 0)
  508.    {
  509.        printk("[FTS] upgrade failed i_ret = %d.\n", i_ret);
  510.        //error handling ...
  511.        //TBD
  512.    }
  513.    else
  514.    {
  515.        printk("[FTS] upgrade successfully.\n");
  516.        fts_ctpm_auto_clb(); //start auto CLB
  517.    }

  518.    return i_ret;
  519. }

  520. unsigned char fts_ctpm_get_i_file_ver(void)
  521. {
  522.     unsigned int ui_sz;
  523.     ui_sz = sizeof(CTPM_FW);
  524.     if (ui_sz > 2)
  525.     {
  526.         return CTPM_FW[ui_sz - 2];
  527.     }
  528.     else
  529.     {
  530.         //TBD, error handling?
  531.         return 0xff; //default value
  532.     }
  533. }

  534. #define FTS_SETTING_BUF_LEN 128

  535. //update project setting
  536. //only update these settings for COB project, or for some special case
  537. int fts_ctpm_update_project_setting(void)
  538. {
  539.     unsigned char uc_i2c_addr; //I2C slave address (8 bit address)
  540.     unsigned char uc_io_voltage; //IO Voltage 0---3.3v; 1----1.8v
  541.     unsigned char uc_panel_factory_id; //TP panel factory ID

  542.     unsigned char buf[FTS_SETTING_BUF_LEN];
  543.     FTS_BYTE reg_val[2] = {0};
  544.     FTS_BYTE auc_i2c_write_buf[10];
  545.     FTS_BYTE packet_buf[FTS_SETTING_BUF_LEN + 6];
  546.     FTS_DWRD i = 0;
  547.     int i_ret;

  548.     uc_i2c_addr = 0x0;
  549.     uc_io_voltage = 0x0;
  550.     uc_panel_factory_id = 0x5a;

  551.     /*********Step 1:Reset CTPM *****/
  552.     /*write 0xaa to register 0xfc*/
  553.     ft5x0x_write_reg(0xfc,0xaa);
  554.     delay_qt_ms(50);
  555.      /*write 0x55 to register 0xfc*/
  556.     ft5x0x_write_reg(0xfc,0x55);
  557.     printk("[FTS] Step 1: Reset CTPM test\n");

  558.     delay_qt_ms(30);

  559.     /*********Step 2:Enter upgrade mode *****/
  560.     auc_i2c_write_buf[0] = 0x55;
  561.     auc_i2c_write_buf[1] = 0xaa;
  562.     do
  563.     {
  564.         i ++;
  565.         i_ret = ft5x0x_i2c_txdata(auc_i2c_write_buf, 2);
  566.         delay_qt_ms(5);
  567.     }while(i_ret <= 0 && i < 5 );

  568.     /*********Step 3:check READ-ID***********************/
  569.     cmd_write(0x90,0x00,0x00,0x00,4);
  570.     byte_read(reg_val,2);
  571.     if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
  572.     {
  573.         printk("[FTS] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
  574.     }
  575.     else
  576.     {
  577.         return ERR_READID;
  578.     }

  579.     cmd_write(0xcd,0x0,0x00,0x00,1);
  580.     byte_read(reg_val,1);
  581.     printk("bootloader version = 0x%x\n", reg_val[0]);


  582.     /* --------- read current project setting ---------- */
  583.     //set read start address
  584.     buf[0] = 0x3;
  585.     buf[1] = 0x0;
  586.     buf[2] = 0x78;
  587.     buf[3] = 0x0;
  588.     byte_write(buf, 4);
  589.     byte_read(buf, FTS_SETTING_BUF_LEN);
  590.     
  591.     printk("[FTS] old setting: uc_i2c_addr = 0x%x, uc_io_voltage = %d, uc_panel_factory_id = 0x%x\n",
  592.         buf[0], buf[2], buf[4]);
  593.     for (i = 0; i < FTS_SETTING_BUF_LEN; i++)
  594.     {
  595.         if (i % 16 == 0) printk("\n");
  596.         printk("0x%x, ", buf[i]);
  597.         
  598.     }
  599.     printk("\n");

  600.      /*--------- Step 4:erase project setting --------------*/
  601.     cmd_write(0x62,0x00,0x00,0x00,1);
  602.     delay_qt_ms(100);
  603.    
  604.     /*---------- Set new settings ---------------*/
  605.     buf[0] = uc_i2c_addr;
  606.     buf[1] = ~uc_i2c_addr;
  607.     buf[2] = uc_io_voltage;
  608.     buf[3] = ~uc_io_voltage;
  609.     buf[4] = uc_panel_factory_id;
  610.     buf[5] = ~uc_panel_factory_id;
  611.     packet_buf[0] = 0xbf;
  612.     packet_buf[1] = 0x00;
  613.     packet_buf[2] = 0x78;
  614.     packet_buf[3] = 0x0;
  615.     packet_buf[4] = 0;
  616.     packet_buf[5] = FTS_SETTING_BUF_LEN;
  617.     for (i = 0; i < FTS_SETTING_BUF_LEN; i++)
  618.     {
  619.         packet_buf[6 + i] = buf[i];
  620.         if (i % 16 == 0) printk("\n");
  621.         printk("0x%x, ", buf[i]);
  622.     }
  623.     printk("\n");
  624.     byte_write(&packet_buf[0],FTS_SETTING_BUF_LEN + 6);
  625.     delay_qt_ms(100);

  626.     /********* reset the new FW***********************/
  627.     cmd_write(0x07,0x00,0x00,0x00,1);

  628.     msleep(200);

  629.     return 0;
  630. }



  631. int fts_ctpm_read_project_setting(void)
  632. {
  633.     unsigned char uc_i2c_addr; //I2C slave address (8 bit address)
  634.     unsigned char uc_io_voltage; //IO Voltage 0---3.3v; 1----1.8v
  635.     unsigned char uc_panel_factory_id; //TP panel factory ID

  636.     unsigned char buf[FTS_SETTING_BUF_LEN];
  637.     FTS_BYTE reg_val[2] = {0};
  638.     FTS_BYTE auc_i2c_write_buf[10];
  639.     FTS_DWRD i = 0;
  640.     int i_ret;

  641.     uc_i2c_addr = 0x70;
  642.     uc_io_voltage = 0x0;
  643.     uc_panel_factory_id = 0x5a;

  644.     /*********Step 1:Reset CTPM *****/
  645.     /*write 0xaa to register 0xfc*/
  646.     ft5x0x_write_reg(0xfc,0xaa);
  647.     delay_qt_ms(50);
  648.      /*write 0x55 to register 0xfc*/
  649.     ft5x0x_write_reg(0xfc,0x55);
  650.     printk("[FTS] Step 1: Reset CTPM test\n");
  651.    
  652.     delay_qt_ms(30);

  653.     /*********Step 2:Enter upgrade mode *****/
  654.     auc_i2c_write_buf[0] = 0x55;
  655.     auc_i2c_write_buf[1] = 0xaa;
  656.     do
  657.     {
  658.         i ++;
  659.         i_ret = ft5x0x_i2c_txdata(auc_i2c_write_buf, 2);
  660.         delay_qt_ms(5);
  661.     }while(i_ret <= 0 && i < 5 );

  662.     /*********Step 3:check READ-ID***********************/
  663.     cmd_write(0x90,0x00,0x00,0x00,4);
  664.     byte_read(reg_val,2);
  665.     if (reg_val[0] == 0x79 && reg_val[1] == 0x3)
  666.     {
  667.         printk("[FTS] Step 3: CTPM ID,ID1 = 0x%x,ID2 = 0x%x\n",reg_val[0],reg_val[1]);
  668.     }
  669.     else
  670.     {
  671.         return ERR_READID;
  672.     }

  673.     cmd_write(0xcd,0x0,0x00,0x00,1);
  674.     byte_read(reg_val,1);
  675.     printk("bootloader version = 0x%x\n", reg_val[0]);


  676.     /* --------- read current project setting ---------- */
  677.     //set read start address
  678.     buf[0] = 0x3;
  679.     buf[1] = 0x0;
  680.     buf[2] = 0x78;
  681.     buf[3] = 0x0;
  682.     byte_write(buf, 4);
  683.     byte_read(buf, FTS_SETTING_BUF_LEN);
  684.     
  685.     printk("[FTS] old setting: uc_i2c_addr = 0x%x, uc_io_voltage = %d, uc_panel_factory_id = 0x%x\n",
  686.         buf[0], buf[2], buf[4]);
  687.     for (i = 0; i < FTS_SETTING_BUF_LEN; i++)
  688.     {
  689.         if (i % 16 == 0) printk("\n");
  690.         printk("0x%x, ", buf[i]);
  691.         
  692.     }
  693.     printk("\n");

  694.     /********* reset the new FW***********************/
  695.     cmd_write(0x07,0x00,0x00,0x00,1);

  696.     msleep(200);

  697.     return 0;
  698. }



  699. #if CFG_SUPPORT_AUTO_UPG

  700. int fts_ctpm_auto_upg(void)
  701. {
  702.     unsigned char uc_host_fm_ver;
  703.     unsigned char uc_tp_fm_ver;
  704.     int i_ret;

  705.     uc_tp_fm_ver = ft5x0x_read_fw_ver();
  706.     uc_host_fm_ver = fts_ctpm_get_i_file_ver();
  707.     if ( uc_tp_fm_ver == 0xa6 || //the firmware in touch panel maybe corrupted
  708.          uc_tp_fm_ver < uc_host_fm_ver //the firmware in host flash is new, need upgrade
  709.         )
  710.     {
  711.         msleep(100);
  712.         printk("[FTS] uc_tp_fm_ver = 0x%x, uc_host_fm_ver = 0x%x\n",
  713.             uc_tp_fm_ver, uc_host_fm_ver);
  714.         i_ret = fts_ctpm_fw_upgrade_with_i_file();
  715.         if (i_ret == 0)
  716.         {
  717.             msleep(300);
  718.             uc_host_fm_ver = ft5x0x_read_fw_ver();
  719.             printk("[FTS] upgrade to new version 0x%x\n", uc_host_fm_ver);
  720.         }
  721.         else
  722.         {
  723.             printk("[FTS] upgrade failed ret=%d.\n", i_ret);
  724.         }
  725.     }

  726.     return 0;
  727. }

  728. #endif

  729. #endif




  730. #if CFG_DBG_RAW_DATA_READ
  731. #define FTS_TX_NUM 28
  732. #define FTS_RX_NUM 16
  733. static unsigned char _suc_raw_data[FTS_TX_NUM][FTS_RX_NUM * 2];


  734. int fts_read_line(unsigned char uc_row, unsigned char uc_buf[], unsigned char uc_rx_num)
  735. {
  736.     int i_ret;

  737.     //set the row address
  738.     i_ret = ft5x0x_write_reg(0x1, uc_row);
  739.     if (i_ret < 0 )
  740.     {
  741.         return -1;
  742.     }

  743.     uc_buf[0] = 0x10;
  744.     i_ret = ft5x0x_i2c_rxdata(uc_buf, uc_rx_num * 2);
  745.     if (i_ret < 0)
  746.     {
  747.         return -2;
  748.     }

  749.     return 0;
  750.     
  751. }

  752. int fts_raw_data_test(void)
  753. {
  754.     int i;
  755.     int j;
  756.     int i_test;
  757.     unsigned short uc_data;

  758.     msleep(200); //make sure the CTP already start up normally
  759.     
  760.     ft5x0x_write_reg(0, 0x40); //switch to factory mode

  761.     msleep(100); //make sure already enter factory mode

  762.     printk("[TSP] raw data test start ----------------------- \n");

  763.     for (i_test = 0; i_test < 10; i_test ++)
  764.     {
  765.         printk("frame %d *********\n", i_test + 1);
  766.         ft5x0x_write_reg(0, 0xC0); //trigger start raw data scan bit
  767.         msleep(10);
  768.         for ( i = 0; i < FTS_TX_NUM; i ++)
  769.         {
  770.             msleep(1);
  771.             fts_read_line(i, _suc_raw_data[i], FTS_RX_NUM);
  772.             for ( j = 0; j<FTS_RX_NUM; j++)
  773.             {
  774.                 uc_data = _suc_raw_data[i][2*j];
  775.                 uc_data <<= 8;
  776.                 uc_data |= _suc_raw_data[i][2*j + 1];
  777.                 printk("%5d ", uc_data);
  778.             }
  779.             printk("\n");
  780.         }
  781.         msleep(30);
  782.         
  783.     }
  784.     printk("[TSP] raw data test end ----------------------- \n");

  785.     return 0;
  786. }

  787. #endif

  788. /***********************************************************************************************
  789. Name :

  790. Input :
  791.                      

  792. Output :

  793. function :

  794. ***********************************************************************************************/
  795. static void ft5x0x_ts_release(void)
  796. {
  797.     struct ft5x0x_ts_data *data = i2c_get_clientdata(this_client);
  798.    input_report_abs(data->input_dev, ABS_PRESSURE, 0);// input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 0);
  799.     input_sync(data->input_dev);
  800. }

  801. //read touch point information
  802. static int ft5x0x_read_data(void)
  803. {
  804.     struct ft5x0x_ts_data *data = i2c_get_clientdata(this_client);
  805.     struct ts_event *event = &data->event;
  806.     u8 buf[CFG_POINT_READ_BUF] = {0};
  807.     int ret = -1;
  808.     int i;
  809.     
  810.     ret = ft5x0x_i2c_rxdata(buf, CFG_POINT_READ_BUF);
  811.     if (ret < 0) {
  812.         printk("%s read_data i2c_rxdata failed: %d\n", __func__, ret);
  813.         return ret;
  814.     }
  815.     memset(event, 0, sizeof(struct ts_event));
  816.     //printk("[lqm] buf[2]=%d\r\n",buf[2]);
  817.     event->touch_point = buf[2] & 0x07; //lqm changed.
  818.     //event->touch_point = buf[2] >> 4;

  819.     if (event->touch_point > CFG_MAX_TOUCH_POINTS)
  820.     {
  821.         event->touch_point = CFG_MAX_TOUCH_POINTS;
  822.     }

  823.     for (i = 0; i < event->touch_point; i++)
  824.     {
  825.         event->au16_x[i] = (s16)(buf[3 + 6*i] & 0x0F)<<8 | (s16)buf[4 + 6*i];
  826.         event->au16_y[i] = (s16)(buf[5 + 6*i] & 0x0F)<<8 | (s16)buf[6 + 6*i];
  827.         event->au8_touch_event[i] = buf[0x3 + 6*i] >> 6;
  828.         event->au8_finger_id[i] = (buf[5 + 6*i])>>4;
  829.    // printk("%d, %d\n", event->au16_x[i], event->au16_y[i]);
  830.     }

  831.     event->pressure = 200;

  832. #if CFG_SUPPORT_READ_LEFT_DATA
  833.     return buf[1]; //the left touch data in the frames
  834. #else
  835.     return 0;
  836. #endif
  837. }

  838. /***********************************************************************************************
  839. Name :

  840. Input :


  841. Output :

  842. function :

  843. ***********************************************************************************************/


  844. #if CFG_SUPPORT_TOUCH_KEY
  845. int ft5x0x_touch_key_process(struct input_dev *dev, int x, int y, int touch_event)
  846. {
  847.     int i;
  848.     int key_id;
  849.     
  850.     if ( y < 150 && y > 90)//103
  851.     {
  852.         key_id = 2;
  853.     }
  854.     else if ( y < 90 &&y > 60)//73
  855.     {
  856.         key_id = 0;
  857.     }
  858.     
  859.     else if ( y < 60 && y > 30)//43
  860.     {
  861.         key_id = 1;
  862.     }
  863.     else if (y < 30)//0
  864.     {
  865.         key_id = 3;
  866.     }
  867.     else
  868.     {
  869.         key_id = 0xf;
  870.     }
  871.     
  872.     for(i = 0; i <CFG_NUMOFKEYS; i++ )
  873.     {
  874.         if(tsp_keystatus[i])
  875.         {
  876.             input_report_key(dev, tsp_keycodes[i], 0);
  877.             //printk("[FTS] %s key is release. Keycode : %d\n", tsp_keyname[i], tsp_keycodes[i]);
  878.             tsp_keystatus[i] = KEY_RELEASE;
  879.         }
  880.         else if( key_id == i )
  881.         {
  882.             if( touch_event == 0) // detect
  883.             {
  884.                 input_report_key(dev, tsp_keycodes[i], 1);
  885.                 //printk( "[FTS] %s key is pressed. Keycode : %d\n", tsp_keyname[i], tsp_keycodes[i]);
  886.                 tsp_keystatus[i] = KEY_PRESS;
  887.             }
  888.         }
  889.     }
  890.     return 0;
  891.     
  892. }
  893. #endif

  894. static void ft5x0x_report_value(void)
  895. {
  896.     struct ft5x0x_ts_data *data = i2c_get_clientdata(this_client);
  897.     struct ts_event *event = &data->event;
  898.     int i;
  899.   // printk("touchpoint = %d\n", event->touch_point);
  900.     for (i = 0; i < event->touch_point; i++)
  901.     {
  902.     
  903.      if (event->au16_x[i] < /*SCREEN_MAX_X*/800 && event->au16_y[i] < /*SCREEN_MAX_Y*/480)
  904.         // LCD view area
  905.         {
  906. //#ifdef CFG_ONBOARD_FT5X06
  907.      event->au16_y[i] = 480 - event->au16_y[i];
  908. //#endif
  909.              input_report_abs(data->input_dev, ABS_X, event->au16_x[i]); //input_report_abs(data->input_dev, ABS_MT_POSITION_X, event->au16_x[i]);
  910.             input_report_abs(data->input_dev, ABS_Y, event->au16_y[i]);//input_report_abs(data->input_dev, ABS_MT_POSITION_Y, event->au16_y[i]);
  911. input_report_abs(data->input_dev, ABS_Z, 0);
  912. input_report_abs(data->input_dev, BTN_TOUCH, 1);
  913.            // input_report_abs(data->input_dev, ABS_MT_WIDTH_MAJOR, 1);
  914.            // input_report_abs(data->input_dev, ABS_MT_TRACKING_ID, event->au8_finger_id[i]);
  915.         // if (event->au8_touch_event[i]== 0 || event->au8_touch_event[i] == 2)
  916.          //{
  917.                input_report_abs(data->input_dev, ABS_PRESSURE, 1);// input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
  918.         // }
  919.         // else
  920.         // {
  921.         // input_report_abs(data->input_dev, ABS_PRESSURE, 0);//input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR, 0);
  922.         // }
  923.   // printk("%d, %d\n", event->au16_x[i], event->au16_y[i]);
  924.         }
  925.         else //maybe the touch key area
  926.         {
  927. #if CFG_SUPPORT_TOUCH_KEY
  928.             if (event->au16_x[i] >= /*SCREEN_MAX_X*/800)
  929.             {
  930.                 //printk("key x = %d\n", event->au16_y[i]);
  931.                 ft5x0x_touch_key_process(data->input_dev, event->au16_x[i], event->au16_y[i], event->au8_touch_event[i]);
  932.             }
  933. #endif
  934.         }
  935.   
  936.     //input_mt_sync(data->input_dev);
  937.       }
  938.      input_sync(data->input_dev);

  939.     if (event->touch_point == 0) {
  940.         ft5x0x_ts_release();
  941.         return ;
  942.     }
  943. } /*end ft5x0x_report_value*/


  944. /***********************************************************************************************
  945. Name :

  946. Input :


  947. Output :

  948. function :

  949. ***********************************************************************************************/
  950. static void ft5x0x_ts_pen_irq_work(struct work_struct *work)
  951. {
  952.     int ret = -1;

  953. #if CFG_SUPPORT_READ_LEFT_DATA
  954.     do
  955.     {
  956.         ret = ft5x0x_read_data();
  957.         if (ret >= 0)
  958.         {
  959.             ft5x0x_report_value();
  960.         }
  961.     }while (ret > 0);

  962. #else
  963.     ret = ft5x0x_read_data();
  964.     if (ret == 0)
  965.     {
  966.         ft5x0x_report_value();
  967.     }
  968. #endif
  969.     enable_irq(IRQ_EINT7);
  970. }
  971. /***********************************************************************************************
  972. Name :

  973. Input :

  974. Output :

  975. function :

  976. ***********************************************************************************************/
  977. static irqreturn_t ft5x0x_ts_interrupt(int irq, void *dev_id)
  978. {
  979.     struct ft5x0x_ts_data *ft5x0x_ts = dev_id;

  980.     //disable_irq(IRQ_EINT8);
  981.     disable_irq_nosync(IRQ_EINT7);//lqm changed
  982.     if (!work_pending(&ft5x0x_ts->pen_event_work))
  983.     {
  984.         queue_work(ft5x0x_ts->ts_workqueue, &ft5x0x_ts->pen_event_work);
  985.     }

  986.     return IRQ_HANDLED;
  987. }

  988. #ifdef CONFIG_HAS_EARLYSUSPEND
  989. /***********************************************************************************************
  990. Name :

  991. Input :
  992.                      

  993. Output :

  994. function :

  995. ***********************************************************************************************/
  996. static void ft5x0x_ts_suspend(struct early_suspend *handler)
  997. {
  998. // struct ft5x0x_ts_data *ts;
  999. // ts = container_of(handler, struct ft5x0x_ts_data, early_suspend);

  1000.     printk("==ft5x0x_ts_suspend=\n");
  1001. // disable_irq(this_client->irq);
  1002. // disable_irq(IRQ_EINT(6));
  1003. // cancel_work_sync(&ts->pen_event_work);
  1004. // flush_workqueue(ts->ts_workqueue);
  1005.     // ==set mode ==,
  1006. // ft5x0x_set_reg(FT5X0X_REG_PMODE, PMODE_HIBERNATE);
  1007. }
  1008. /***********************************************************************************************
  1009. Name :

  1010. Input :
  1011.                      

  1012. Output :

  1013. function :

  1014. ***********************************************************************************************/
  1015. static void ft5x0x_ts_resume(struct early_suspend *handler)
  1016. {
  1017.     printk("==ft5x0x_ts_resume=\n");
  1018.     // wake the mode
  1019. // __gpio_as_output(GPIO_FT5X0X_WAKE);
  1020. // __gpio_clear_pin(GPIO_FT5X0X_WAKE); //set wake = 0,base on system
  1021. // msleep(100);
  1022. // __gpio_set_pin(GPIO_FT5X0X_WAKE); //set wake = 1,base on system
  1023. // msleep(100);
  1024. // enable_irq(this_client->irq);
  1025. // enable_irq(IRQ_EINT(6));
  1026. }
  1027. #endif //CONFIG_HAS_EARLYSUSPEND

  1028. static int
  1029. ft5x0x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
  1030. {
  1031.     struct ft5x0x_ts_data *ft5x0x_ts;
  1032.     struct input_dev *input_dev;
  1033.     int err = 0;
  1034.     unsigned char uc_reg_value;
  1035. #if CFG_SUPPORT_TOUCH_KEY
  1036.     int i;
  1037. #endif

  1038.     printk("[FTS] ft5x0x_ts_probe, driver version is %s.\n", CFG_FTS_CTP_DRIVER_VERSION);
  1039.     
  1040.     if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
  1041.     {
  1042.         err = -ENODEV;
  1043.         goto exit_check_functionality_failed;
  1044.     }

  1045.     ft5x0x_ts = kzalloc(sizeof(*ft5x0x_ts), GFP_KERNEL);
  1046.     if (!ft5x0x_ts)
  1047.     {
  1048.         err = -ENOMEM;
  1049.         goto exit_alloc_data_failed;
  1050.     }

  1051.     this_client = client;
  1052.     i2c_set_clientdata(client, ft5x0x_ts);

  1053.     INIT_WORK(&ft5x0x_ts->pen_event_work, ft5x0x_ts_pen_irq_work);

  1054.     ft5x0x_ts->ts_workqueue = create_singlethread_workqueue(dev_name(&client->dev));
  1055.     if (!ft5x0x_ts->ts_workqueue) {
  1056.         err = -ESRCH;
  1057.         goto exit_create_singlethread;
  1058.     }

  1059.     /* config interrupt pin
  1060.      * x210ii: INT = GPH0_7
  1061.      * */
  1062.     s3c_gpio_cfgpin(S5PV210_GPH0(7), S3C_GPIO_SFN(0xf));
  1063.     s3c_gpio_setpull(S5PV210_GPH0(7), S3C_GPIO_PULL_UP);
  1064.     set_irq_type(IRQ_EINT7, IRQF_TRIGGER_FALLING);

  1065.     err = request_irq(IRQ_EINT7, ft5x0x_ts_interrupt, IRQF_TRIGGER_FALLING, "ft5x0x_ts", ft5x0x_ts);
  1066.     if (err < 0)
  1067.     {
  1068.         dev_err(&client->dev, "ft5x0x_probe: request irq failed\n");
  1069.         goto exit_irq_request_failed;
  1070.     }

  1071.     //disable_irq(IRQ_EINT8);
  1072.     disable_irq_nosync(IRQ_EINT7);//lqm changed.

  1073.     input_dev = input_allocate_device();
  1074.     if (!input_dev) {
  1075.         err = -ENOMEM;
  1076.         dev_err(&client->dev, "failed to allocate input device\n");
  1077.         goto exit_input_dev_alloc_failed;
  1078.     }
  1079.     
  1080.     ft5x0x_ts->input_dev = input_dev;

  1081. // set_bit(ABS_PRESSURE, input_dev->absbit);
  1082. // set_bit(ABS_X, input_dev->absbit);
  1083. // set_bit(ABS_Y, input_dev->absbit);
  1084.  // set_bit(ABS_MT_WIDTH_MAJOR, input_dev->absbit);

  1085.     input_set_abs_params(input_dev, ABS_X, 0, 800, 0, 0);
  1086.     input_set_abs_params(input_dev, ABS_Y, 0, 480, 0, 0);
  1087.     input_set_abs_params(input_dev, ABS_PRESSURE, 0, 1, 0, 0);
  1088. // input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
  1089. // input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 5, 0, 0);
  1090. /*
  1091.     set_bit(ABS_MT_TOUCH_MAJOR, input_dev->absbit);
  1092.     set_bit(ABS_MT_POSITION_X, input_dev->absbit);
  1093.     set_bit(ABS_MT_POSITION_Y, input_dev->absbit);
  1094.     set_bit(ABS_MT_WIDTH_MAJOR, input_dev->absbit);

  1095.     input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, 800, 0, 0);
  1096.     input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, 480, 0, 0);
  1097.     input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, PRESS_MAX, 0, 0);
  1098.     input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0);
  1099.     input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, 5, 0, 0);
  1100. */
  1101.     set_bit(EV_KEY, input_dev->evbit);
  1102.     set_bit(EV_ABS, input_dev->evbit);

  1103. #if CFG_SUPPORT_TOUCH_KEY
  1104.     //setup key code area
  1105.     set_bit(EV_SYN, input_dev->evbit);
  1106.     set_bit(BTN_TOUCH, input_dev->keybit);
  1107.     input_dev->keycode = tsp_keycodes;
  1108.     for(i = 0; i < CFG_NUMOFKEYS; i++)
  1109.     {
  1110.         input_set_capability(input_dev, EV_KEY, ((int*)input_dev->keycode)[i]);
  1111.         tsp_keystatus[i] = KEY_RELEASE;
  1112.     }
  1113. #endif

  1114.     input_dev->name = FT5X0X_NAME; //dev_name(&client->dev)
  1115.     err = input_register_device(input_dev);
  1116.     if (err)
  1117.     {
  1118.         dev_err(&client->dev,"ft5x0x_ts_probe: failed to register input device: %s\n",
  1119.                              dev_name(&client->dev));
  1120.         goto exit_input_register_device_failed;
  1121.     }

  1122. #ifdef CONFIG_HAS_EARLYSUSPEND
  1123.     printk("==register_early_suspend =\n");
  1124.     ft5x0x_ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  1125.     ft5x0x_ts->early_suspend.suspend = ft5x0x_ts_suspend;
  1126.     ft5x0x_ts->early_suspend.resume = ft5x0x_ts_resume;
  1127.     register_early_suspend(&ft5x0x_ts->early_suspend);
  1128. #endif

  1129.     msleep(150); //make sure CTP already finish startup process

  1130.     //get some register information
  1131.     uc_reg_value = ft5x0x_read_fw_ver();
  1132.     printk("[FTS] Firmware version = 0x%x\n", uc_reg_value);

  1133.     ft5x0x_read_reg(FT5X0X_REG_PERIODACTIVE, &uc_reg_value);
  1134.     printk("[FTS] report rate is %dHz.\n", uc_reg_value * 10);
  1135.     ft5x0x_read_reg(FT5X0X_REG_THGROUP, &uc_reg_value);
  1136.     printk("[FTS] touch threshold is %d.\n", uc_reg_value * 4);

  1137. #if CFG_SUPPORT_AUTO_UPG
  1138.         fts_ctpm_auto_upg();
  1139. #endif


  1140. #if CFG_SUPPORT_UPDATE_PROJECT_SETTING
  1141.     fts_ctpm_update_project_setting();
  1142. #endif

  1143. #if CFG_DBG_RAW_DATA_READ
  1144.     fts_raw_data_test();
  1145. #endif

  1146. // msleep(300);
  1147. // fts_ctpm_read_project_setting();

  1148.     enable_irq(IRQ_EINT7);

  1149.     have_cap_touchscreen=1;

  1150.     printk("[FTS] ==probe over =\n");
  1151.     return 0;

  1152. exit_input_register_device_failed:
  1153.     input_free_device(input_dev);
  1154. exit_input_dev_alloc_failed:
  1155.     free_irq(IRQ_EINT7, ft5x0x_ts);
  1156. exit_irq_request_failed:
  1157. //exit_platform_data_null:
  1158.     cancel_work_sync(&ft5x0x_ts->pen_event_work);
  1159.     destroy_workqueue(ft5x0x_ts->ts_workqueue);
  1160. exit_create_singlethread:
  1161.     printk("==singlethread error =\n");
  1162.     i2c_set_clientdata(client, NULL);
  1163.     kfree(ft5x0x_ts);
  1164. exit_alloc_data_failed:
  1165. exit_check_functionality_failed:
  1166.     return err;
  1167. }

  1168. static int __devexit ft5x0x_ts_remove(struct i2c_client *client)
  1169. {
  1170.     struct ft5x0x_ts_data *ft5x0x_ts;
  1171.     printk("==ft5x0x_ts_remove=\n");
  1172.     ft5x0x_ts = i2c_get_clientdata(client);
  1173.     unregister_early_suspend(&ft5x0x_ts->early_suspend);
  1174.     free_irq(IRQ_EINT7, ft5x0x_ts);
  1175.     input_unregister_device(ft5x0x_ts->input_dev);
  1176.     kfree(ft5x0x_ts);
  1177.     cancel_work_sync(&ft5x0x_ts->pen_event_work);
  1178.     destroy_workqueue(ft5x0x_ts->ts_workqueue);
  1179.     i2c_set_clientdata(client, NULL);
  1180.     return 0;
  1181. }

  1182. static const struct i2c_device_id ft5x0x_ts_id[] = {
  1183.     { "ft5406-iic", 0 },{ }
  1184. };


  1185. MODULE_DEVICE_TABLE(i2c, ft5x0x_ts_id);

  1186. static struct i2c_driver ft5406_iic_driver = {
  1187.     .driver        = {
  1188.         .name    = "ft5406-iic",
  1189.         .owner = THIS_MODULE,
  1190.     },

  1191.     .probe        = ft5x0x_ts_probe,
  1192.     .remove        = __devexit_p(ft5x0x_ts_remove),
  1193.     .id_table    = ft5x0x_ts_id,
  1194. };

  1195. static int ft5406_ts_probe(struct platform_device * pdev)
  1196. {
  1197.     struct i2c_adapter * adapter;
  1198.     struct i2c_client * client;
  1199.     struct i2c_board_info info;
  1200.     int ret;

  1201.     adapter = i2c_get_adapter(FT5406_I2C_BUS);
  1202.     if(adapter == NULL)
  1203.         return -ENODEV;

  1204.     memset(&info, 0, sizeof(struct i2c_board_info));
  1205.     info.addr = I2C_CTPM_ADDRESS;
  1206.     strlcpy(info.type, "ft5406-iic", I2C_NAME_SIZE);

  1207.     client = i2c_new_device(adapter, &info);
  1208.     if(!client)
  1209.     {
  1210.         printk("Unable to add I2C device for 0x%x\n", info.addr);
  1211.         return -ENODEV;
  1212.     }
  1213.     i2c_put_adapter(adapter);

  1214.     ret = i2c_add_driver(&ft5406_iic_driver);
  1215.     if(ret)
  1216.     {
  1217.         printk("ft5406 iic add driver error!\r\n");
  1218.         return ret;
  1219.     }

  1220.     return 0;
  1221. }

  1222. static int ft5406_ts_remove(struct platform_device * pdev)
  1223. {
  1224.     i2c_del_driver(&ft5406_iic_driver);
  1225.     return 0;
  1226. }

  1227. static int ft5406_ts_suspend(struct platform_device * dev, pm_message_t state)
  1228. {
  1229.     return 0;
  1230. }

  1231. static int ft5406_ts_resume(struct platform_device * dev)
  1232. {
  1233.     return 0;
  1234. }

  1235. static struct platform_device ft5406_ts_device = {
  1236.     .name    = "ft5406-ts",
  1237.     .id        =-1,
  1238. };

  1239. static struct platform_driver ft5406_ts_driver = {
  1240.     .driver        = {
  1241.         .name    = "ft5406-ts",
  1242.     },
  1243.     .probe        = ft5406_ts_probe,
  1244.     .remove        = ft5406_ts_remove,
  1245.     .suspend    = ft5406_ts_suspend,
  1246.     .resume        = ft5406_ts_resume,
  1247. };

  1248. static int __init ft5x0x_ts_init(void)
  1249. {
  1250.     int ret;
  1251.     if(have_cap_touchscreen != 0)
  1252.         return 0;

  1253.     printk("==ft5x0x_ts_init==\n");

  1254.     /*
  1255.      * set cap touchscreen's shutdown pin to low level
  1256.      * x210ii: CAP_WAKE = GPH0_6
  1257.      */
  1258.     s3c_gpio_setpull(S5PV210_GPH0(6), S3C_GPIO_PULL_DOWN);
  1259.     s3c_gpio_cfgpin(S5PV210_GPH0(6), S3C_GPIO_SFN(1));
  1260.     gpio_set_value(S5PV210_GPH0(6), 0);
  1261.     /* wait a moment */
  1262.     mdelay(10);
  1263.     gpio_set_value(S5PV210_GPH0(6), 1);

  1264.     ret = platform_device_register(&ft5406_ts_device);
  1265.     if(ret)
  1266.     {
  1267.         printk("failed to register platform device\n");
  1268.     }

  1269.     ret = platform_driver_register(&ft5406_ts_driver);
  1270.     if(ret != 0)
  1271.     {
  1272.         printk("fail to register platform driver\n");
  1273.         return ret;
  1274.     }

  1275.     return 0;
  1276. }

  1277. static void __exit ft5x0x_ts_exit(void)
  1278. {
  1279.     printk("==ft5x0x_ts_exit==\n");
  1280.     platform_driver_unregister(&ft5406_ts_driver);
  1281. }

  1282. module_init(ft5x0x_ts_init);
  1283. module_exit(ft5x0x_ts_exit);

  1284. MODULE_AUTHOR("liuqiming");
  1285. MODULE_DESCRIPTION("FocalTech ft5x0x TouchScreen driver");
  1286. MODULE_LICENSE("GPL");

x210 kernel中的ft5x06.h:

点击(此处)折叠或打开

  1. #ifndef __LINUX_FT5X0X_TS_H__
  2. #define __LINUX_FT5X0X_TS_H__


  3. /* -- dirver configure -- */
  4. #define CFG_SUPPORT_AUTO_UPG 0
  5. #define CFG_SUPPORT_UPDATE_PROJECT_SETTING 0
  6. #define CFG_SUPPORT_TOUCH_KEY /*0*/1 //touch key, HOME, SEARCH, RETURN etc
  7. #define CFG_SUPPORT_READ_LEFT_DATA 0
  8. #define CFG_DBG_RAW_DATA_READ 0

  9. #define CFG_MAX_TOUCH_POINTS 1 //wangzm 5
  10. #define CFG_NUMOFKEYS 4
  11. #define CFG_FTS_CTP_DRIVER_VERSION "2.0"

  12. #define SCREEN_MAX_X 1728
  13. #define SCREEN_MAX_Y 1024
  14. #define PRESS_MAX 255

  15. #define CFG_POINT_READ_BUF (3 + 6 * (CFG_MAX_TOUCH_POINTS))

  16. #define FT5X0X_NAME    "ft5x0x_ts"//"synaptics_i2c_rmi"//"synaptics-rmi-ts"//

  17. #define KEY_PRESS 1
  18. #define KEY_RELEASE 0

  19. enum ft5x0x_ts_regs {
  20.     FT5X0X_REG_THGROUP                    = 0x80, /* touch threshold, related to sensitivity */
  21.     FT5X0X_REG_THPEAK                        = 0x81,
  22.     FT5X0X_REG_THCAL                        = 0x82,
  23.     FT5X0X_REG_THWATER                    = 0x83,
  24.     FT5X0X_REG_THTEMP                    = 0x84,
  25.     FT5X0X_REG_THDIFF                        = 0x85,                
  26.     FT5X0X_REG_CTRL                        = 0x86,
  27.     FT5X0X_REG_TIMEENTERMONITOR            = 0x87,
  28.     FT5X0X_REG_PERIODACTIVE                = 0x88, /* report rate */
  29.     FT5X0X_REG_PERIODMONITOR            = 0x89,
  30.     FT5X0X_REG_HEIGHT_B                    = 0x8a,
  31.     FT5X0X_REG_MAX_FRAME                    = 0x8b,
  32.     FT5X0X_REG_DIST_MOVE                    = 0x8c,
  33.     FT5X0X_REG_DIST_POINT                = 0x8d,
  34.     FT5X0X_REG_FEG_FRAME                    = 0x8e,
  35.     FT5X0X_REG_SINGLE_CLICK_OFFSET        = 0x8f,
  36.     FT5X0X_REG_DOUBLE_CLICK_TIME_MIN    = 0x90,
  37.     FT5X0X_REG_SINGLE_CLICK_TIME            = 0x91,
  38.     FT5X0X_REG_LEFT_RIGHT_OFFSET        = 0x92,
  39.     FT5X0X_REG_UP_DOWN_OFFSET            = 0x93,
  40.     FT5X0X_REG_DISTANCE_LEFT_RIGHT        = 0x94,
  41.     FT5X0X_REG_DISTANCE_UP_DOWN        = 0x95,
  42.     FT5X0X_REG_ZOOM_DIS_SQR                = 0x96,
  43.     FT5X0X_REG_RADIAN_VALUE                =0x97,
  44.     FT5X0X_REG_MAX_X_HIGH     = 0x98,
  45.     FT5X0X_REG_MAX_X_LOW             = 0x99,
  46.     FT5X0X_REG_MAX_Y_HIGH             = 0x9a,
  47.     FT5X0X_REG_MAX_Y_LOW             = 0x9b,
  48.     FT5X0X_REG_K_X_HIGH             = 0x9c,
  49.     FT5X0X_REG_K_X_LOW             = 0x9d,
  50.     FT5X0X_REG_K_Y_HIGH             = 0x9e,
  51.     FT5X0X_REG_K_Y_LOW             = 0x9f,
  52.     FT5X0X_REG_AUTO_CLB_MODE            = 0xa0,
  53.     FT5X0X_REG_LIB_VERSION_H                 = 0xa1,
  54.     FT5X0X_REG_LIB_VERSION_L                 = 0xa2,        
  55.     FT5X0X_REG_CIPHER                        = 0xa3,
  56.     FT5X0X_REG_MODE                        = 0xa4,
  57.     FT5X0X_REG_PMODE                        = 0xa5,     /* Power Consume Mode        */    
  58.     FT5X0X_REG_FIRMID                        = 0xa6, /* Firmware version */
  59.     FT5X0X_REG_STATE                        = 0xa7,
  60.     FT5X0X_REG_FT5201ID                    = 0xa8,
  61.     FT5X0X_REG_ERR                        = 0xa9,
  62.     FT5X0X_REG_CLB                        = 0xaa,
  63. };

  64. //FT5X0X_REG_PMODE
  65. #define PMODE_ACTIVE 0x00
  66. #define PMODE_MONITOR 0x01
  67. #define PMODE_STANDBY 0x02
  68. #define PMODE_HIBERNATE 0x03


  69.     #ifndef ABS_MT_TOUCH_MAJOR
  70.     #define ABS_MT_TOUCH_MAJOR    0x30    /* touching ellipse */
  71.     #define ABS_MT_TOUCH_MINOR    0x31    /* (omit if circular) */
  72.     #define ABS_MT_WIDTH_MAJOR    0x32    /* approaching ellipse */
  73.     #define ABS_MT_WIDTH_MINOR    0x33    /* (omit if circular) */
  74.     #define ABS_MT_ORIENTATION    0x34    /* Ellipse orientation */
  75.     #define ABS_MT_POSITION_X    0x35    /* Center X ellipse position */
  76.     #define ABS_MT_POSITION_Y    0x36    /* Center Y ellipse position */
  77.     #define ABS_MT_TOOL_TYPE    0x37    /* Type of touching device */
  78.     #define ABS_MT_BLOB_ID        0x38    /* Group set of pkts as blob */
  79.     #endif /* ABS_MT_TOUCH_MAJOR */

  80.     #ifndef ABS_MT_TRACKING_ID
  81.     #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
  82.     #endif

  83. #endif




阅读(4911) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~