Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.75 KB | None | 0 0
  1. /*
  2. * This software is licensed under the terms of the GNU General Public
  3. * License version 2, as published by the Free Software Foundation, and
  4. * may be copied, distributed, and modified under those terms.
  5. * This program is distributed in the hope that it will be useful,
  6. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. * GNU General Public License for more details.
  9. * * VERSION DATE AUTHOR Note
  10. * 1.0 2013-7-16 Focaltech initial based on MTK platform
  11. *
  12. */
  13.  
  14. #include "tpd.h"
  15.  
  16. #include "tpd_custom_ft5206.h"
  17. #include "focaltech_ex_fun.h"
  18. #include <linux/netdevice.h>
  19. #ifdef FTS_CTL_IIC
  20. #include "focaltech_ctl.h"
  21. /*create sysfs for debug*/
  22. extern int fts_create_sysfs(struct i2c_client * client);
  23. extern void fts_release_sysfs(struct i2c_client * client);
  24. extern int ft5x0x_create_apk_debug_channel(struct i2c_client *client);
  25. extern void ft5x0x_release_apk_debug_channel(void);
  26. #endif
  27. #define TPD_PROXIMITY
  28. #ifdef TPD_PROXIMITY
  29. #include <linux/hwmsensor.h>
  30. #include <linux/hwmsen_dev.h>
  31. #include <linux/sensors_io.h>
  32. #endif
  33. #ifdef VELOCITY_CUSTOM
  34. extern int tpd_v_magnify_x;
  35. extern int tpd_v_magnify_y;
  36. #endif
  37. #include <cust_eint.h>
  38. #include <cust_gpio_usage.h>
  39. #include <mach/mt_pm_ldo.h>
  40. #include <mach/mt_typedefs.h>
  41. #include <mach/mt_boot.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/i2c.h>
  44. #include <linux/sched.h>
  45. #include <linux/kthread.h>
  46. #include <linux/rtpm_prio.h>
  47. #include <linux/wait.h>
  48. #include <linux/time.h>
  49. #include <linux/delay.h>
  50.  
  51. u8 *I2CDMABuf_va = NULL;
  52. dma_addr_t I2CDMABuf_pa = 0;
  53.  
  54. #ifdef TPD_PROXIMITY
  55. #define APS_ERR(fmt,arg...) printk("<<proximity>> "fmt"\n",##arg)
  56. #define TPD_PROXIMITY_DEBUG(fmt,arg...) printk("<<proximity>> "fmt"\n",##arg)
  57. #define TPD_PROXIMITY_DMESG(fmt,arg...) printk("<<proximity>> "fmt"\n",##arg)
  58.  
  59. static u8 tpd_proximity_flag = 0;
  60. static u8 tpd_proximity_flag_one = 0; //add for tpd_proximity by wangdongfang
  61. static u8 tpd_proximity_detect = 1;//0-->close ; 1--> far away
  62. #endif
  63.  
  64. extern struct tpd_device *tpd;
  65.  
  66. struct i2c_client *i2c_client = NULL;
  67. struct task_struct *thread = NULL;
  68.  
  69. #ifdef VELOCITY_CUSTOM
  70. extern int tpd_v_magnify_x;
  71. extern int tpd_v_magnify_y;
  72. #endif
  73. static DECLARE_WAIT_QUEUE_HEAD(waiter);
  74. static DEFINE_MUTEX(i2c_access);
  75.  
  76.  
  77. static void tpd_eint_interrupt_handler(void);
  78.  
  79. static int tpd_probe(struct i2c_client *client, const struct i2c_device_id *id);
  80. static int tpd_detect (struct i2c_client *client, struct i2c_board_info *info);
  81. static int tpd_remove(struct i2c_client *client);
  82. static int touch_event_handler(void *unused);
  83.  
  84. static int tpd_flag = 0;
  85. static int tpd_halt = 0;
  86.  
  87. #define TPD_OK 0
  88.  
  89. #define TPD_AUTO_UPGRADE
  90.  
  91. #define TPD_RESET_ISSUE_WORKAROUND
  92. #define TPD_MAX_RESET_COUNT 3
  93. //extern int tpd_mstar_status ; // compatible mstar and ft6306 chenzhecong
  94.  
  95. #ifdef TPD_HAVE_BUTTON
  96. static int tpd_keys_local[TPD_KEY_COUNT] = TPD_KEYS;
  97. static int tpd_keys_dim_local[TPD_KEY_COUNT][4] = TPD_KEYS_DIM;
  98. #endif
  99. #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
  100. static int tpd_wb_start_local[TPD_WARP_CNT] = TPD_WARP_START;
  101. static int tpd_wb_end_local[TPD_WARP_CNT] = TPD_WARP_END;
  102. #endif
  103. #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
  104. static int tpd_calmat_local[8] = TPD_CALIBRATION_MATRIX;
  105. static int tpd_def_calmat_local[8] = TPD_CALIBRATION_MATRIX;
  106. #endif
  107.  
  108. #include <linux/device.h>
  109. #include <linux/miscdevice.h>
  110. #include <asm/uaccess.h>
  111.  
  112. struct touch_info {
  113. int y[10];
  114. int x[10];
  115. int p[10];
  116. int id[10];
  117. };
  118.  
  119. static const struct i2c_device_id ft5206_tpd_id[] = {{"mtk-focal",0},{}};
  120. static struct i2c_board_info __initdata ft5206_i2c_tpd={ I2C_BOARD_INFO("mtk-focal", (0x70>>1))};
  121.  
  122. static struct i2c_driver tpd_i2c_driver = {
  123. .driver = {
  124. .name = "mtk-focal",
  125. },
  126. .probe = tpd_probe,
  127. .remove = tpd_remove,
  128. .id_table = ft5206_tpd_id,
  129. .detect = tpd_detect,
  130. };
  131.  
  132.  
  133. static void tpd_down(int x, int y, int id) {
  134. input_report_key(tpd->dev, BTN_TOUCH, 1);
  135. input_report_abs(tpd->dev, ABS_MT_TOUCH_MAJOR, 20);
  136. input_report_abs(tpd->dev, ABS_MT_POSITION_X, x);
  137. input_report_abs(tpd->dev, ABS_MT_POSITION_Y, y);
  138. input_report_abs(tpd->dev, ABS_MT_TRACKING_ID, id);
  139. input_mt_sync(tpd->dev);
  140. TPD_EM_PRINT(x, y, x, y, id-1, 1);
  141. if (FACTORY_BOOT == get_boot_mode()|| RECOVERY_BOOT == get_boot_mode())
  142. {
  143. tpd_button(x, y, 1);
  144. }
  145. }
  146.  
  147. static void tpd_up(int x, int y) {
  148. input_report_key(tpd->dev, BTN_TOUCH, 0);
  149. TPD_EM_PRINT(x, y, x, y, 0, 0);
  150. if (FACTORY_BOOT == get_boot_mode()|| RECOVERY_BOOT == get_boot_mode())
  151. {
  152. tpd_button(x, y, 0);
  153. }
  154. }
  155.  
  156. #ifdef TPD_PROXIMITY
  157. int tpd_read_ps(void)
  158. {
  159. tpd_proximity_detect;
  160. return 0;
  161. }
  162.  
  163. static int tpd_get_ps_value(void)
  164. {
  165. return tpd_proximity_detect;
  166. }
  167.  
  168. static int tpd_enable_ps(int enable)
  169. {
  170. u8 state;
  171. int ret = -1;
  172.  
  173. i2c_smbus_read_i2c_block_data(i2c_client, 0xB0, 1, &state);
  174. printk("[proxi_5206]read: 999 0xb0's value is 0x%02X\n", state);
  175. if (enable){
  176. state |= 0x01;
  177. tpd_proximity_flag = 1;
  178. TPD_PROXIMITY_DEBUG("[proxi_5206]ps function is on\n");
  179. }else{
  180. state &= 0x00;
  181. tpd_proximity_flag = 0;
  182. TPD_PROXIMITY_DEBUG("[proxi_5206]ps function is off\n");
  183. }
  184.  
  185. ret = i2c_smbus_write_i2c_block_data(i2c_client, 0xB0, 1, &state);
  186. TPD_PROXIMITY_DEBUG("[proxi_5206]write: 0xB0's value is 0x%02X\n", state);
  187. return 0;
  188. }
  189.  
  190. int tpd_ps_operate(void* self, uint32_t command, void* buff_in, int size_in,
  191. void* buff_out, int size_out, int* actualout)
  192. {
  193. int err = 0;
  194. int value;
  195.  
  196. hwm_sensor_data *sensor_data;
  197. TPD_DEBUG("[proxi_5206]command = 0x%02X\n", command);
  198. switch (command)
  199. {
  200. case SENSOR_DELAY:
  201. if((buff_in == NULL) || (size_in < sizeof(int)))
  202. {
  203. APS_ERR("Set delay parameter error!\n");
  204. err = -EINVAL;
  205. }
  206. // Do nothing
  207. break;
  208.  
  209. case SENSOR_ENABLE:
  210. if((buff_in == NULL) || (size_in < sizeof(int)))
  211. {
  212. APS_ERR("Enable sensor parameter error!\n");
  213. err = -EINVAL;
  214. }
  215. else
  216. {
  217. value = *(int *)buff_in;
  218. if(value)
  219. {
  220. if((tpd_enable_ps(1) != 0))
  221. {
  222. APS_ERR("enable ps fail: %d\n", err);
  223. return -1;
  224. }
  225. }
  226. else
  227. {
  228. if((tpd_enable_ps(0) != 0))
  229. {
  230. APS_ERR("disable ps fail: %d\n", err);
  231. return -1;
  232. }
  233. }
  234. }
  235. break;
  236.  
  237. case SENSOR_GET_DATA:
  238. if((buff_out == NULL) || (size_out< sizeof(hwm_sensor_data)))
  239. {
  240. APS_ERR("get sensor data parameter error!\n");
  241. err = -EINVAL;
  242. }
  243. else
  244. {
  245.  
  246. sensor_data = (hwm_sensor_data *)buff_out;
  247.  
  248. if((err = tpd_read_ps()))
  249. {
  250. err = -1;;
  251. }
  252. else
  253. {
  254. sensor_data->values[0] = tpd_get_ps_value();
  255. TPD_PROXIMITY_DEBUG("huang sensor_data->values[0] 1082 = %d\n", sensor_data->values[0]);
  256. sensor_data->value_divide = 1;
  257. sensor_data->status = SENSOR_STATUS_ACCURACY_MEDIUM;
  258. }
  259.  
  260. }
  261. break;
  262. default:
  263. APS_ERR("proxmy sensor operate function no this parameter %d!\n", command);
  264. err = -1;
  265. break;
  266. }
  267.  
  268. return err;
  269. }
  270. #endif
  271.  
  272. static int tpd_i2c_read_bytes(struct i2c_client *client, u16 addr, u8 *rxbuf, int len)
  273. {
  274. u8 buffer[1];
  275. u16 left = len;
  276. u16 offset = 0;
  277.  
  278. struct i2c_msg msg[2] =
  279. {
  280. {
  281. .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
  282. .flags = 0,
  283. .buf = buffer,
  284. .len = 1,
  285. .timing = 300
  286. },
  287. {
  288. .addr = ((client->addr &I2C_MASK_FLAG) | (I2C_ENEXT_FLAG)),
  289. .flags = I2C_M_RD,
  290. .timing = 300
  291. },
  292. };
  293.  
  294. if (rxbuf == NULL)
  295. return -1;
  296.  
  297. printk("i2c_read_bytes to device %02X address %04X len %d\n", client->addr, addr, len);
  298.  
  299. while (left > 0)
  300. {
  301. buffer[0] = (addr + offset) & 0xFF;
  302.  
  303. msg[1].buf = &rxbuf[offset];
  304.  
  305. if (left > 8)
  306. {
  307. msg[1].len = 8;
  308. left -= 8;
  309. offset += 8;
  310. }
  311. else
  312. {
  313. msg[1].len = left;
  314. left = 0;
  315. }
  316.  
  317. if (i2c_transfer(client->adapter, &msg[0], 2) != 2)
  318. {
  319. printk("I2C read 0x%X length=%d failed\n", addr + offset, len);
  320. return -1;
  321. }
  322. }
  323.  
  324. return 0;
  325. }
  326.  
  327.  
  328. static int tpd_touchinfo(struct touch_info *cinfo, struct touch_info *pinfo, int *point_num)
  329. {
  330. int i = 0;
  331. char data[128] = {0};
  332. u16 high_byte,low_byte;
  333. u8 reg;
  334.  
  335. mutex_lock(&i2c_access);
  336. if (tpd_halt)
  337. {
  338. mutex_unlock(&i2c_access);
  339. TPD_DMESG( "tpd_touchinfo return ..\n");
  340. return false;
  341. }
  342.  
  343.  
  344. reg = 0x00;
  345. memset(data, 0, 32);
  346. #ifdef TPD_AUTO_UPGRADE
  347. fts_i2c_Read(i2c_client, &reg, 1, data, 32);
  348. //tpd_i2c_read_bytes(i2c_client, 0x00, data, 32);
  349. #else
  350. i2c_smbus_read_i2c_block_data(i2c_client, 0x00, 8, &(data[0]));
  351. i2c_smbus_read_i2c_block_data(i2c_client, 0x08, 8, &(data[8]));
  352. i2c_smbus_read_i2c_block_data(i2c_client, 0x10, 8, &(data[16]));
  353. i2c_smbus_read_i2c_block_data(i2c_client, 0x18, 8, &(data[24]));
  354. #endif
  355. mutex_unlock(&i2c_access);
  356. //TPD_DEBUG("received raw data from touch panel as following:\n");
  357. //TPD_DEBUG("[data[0]=%x,data[1]= %x ,data[2]=%x ,data[3]=%x ,data[4]=%x ,data[5]=%x]\n",data[0],data[1],data[2],data[3],data[4],data[5]);
  358. //TPD_DEBUG("[data[9]=%x,data[10]= %x ,data[11]=%x ,data[12]=%x]\n",data[9],data[10],data[11],data[12]);
  359. //TPD_DEBUG("[data[15]=%x,data[16]= %x ,data[17]=%x ,data[18]=%x]\n",data[15],data[16],data[17],data[18]);
  360.  
  361. /*get the number of the touch points*/
  362. *point_num= data[2] & 0x0f;
  363.  
  364. //TPD_DEBUG("point_num =%d\n",point_num);
  365.  
  366. for(i = 0; i < *point_num; i++)
  367. {
  368. //cinfo->p[i] = data[3+6*i] >> 6; //event flag
  369. cinfo->id[i] = data[3+6*i+2]>>4; //touch id
  370. /*get the X coordinate, 2 bytes*/
  371. high_byte = data[3+6*i];
  372. high_byte <<= 8;
  373. high_byte &= 0x0f00;
  374. low_byte = data[3+6*i + 1];
  375. cinfo->x[i] = high_byte |low_byte;
  376.  
  377. //cinfo->x[i] = cinfo->x[i] * 480 >> 11; //calibra
  378.  
  379. /*get the Y coordinate, 2 bytes*/
  380.  
  381. high_byte = data[3+6*i+2];
  382. high_byte <<= 8;
  383. high_byte &= 0x0f00;
  384. low_byte = data[3+6*i+3];
  385. cinfo->y[i] = high_byte |low_byte;
  386.  
  387. //cinfo->y[i]= cinfo->y[i] * 800 >> 11;
  388. }
  389. //TPD_DEBUG(" cinfo->x[0] = %d, cinfo->y[0] = %d, cinfo->id[0] = %d\n", cinfo->x[0], cinfo->y[0], cinfo->id[0]);
  390. //TPD_DEBUG(" cinfo->x[1] = %d, cinfo->y[1] = %d, cinfo->p[1] = %d\n", cinfo->x[1], cinfo->y[1], cinfo->p[1]);
  391. //TPD_DEBUG(" cinfo->x[2]= %d, cinfo->y[2]= %d, cinfo->p[2] = %d\n", cinfo->x[2], cinfo->y[2], cinfo->p[2]);
  392.  
  393. return true;
  394. };
  395. #ifdef TPD_AUTO_UPGRADE
  396. static int tpd_ft_update_fw(void *unused)
  397. {
  398. mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
  399. msleep(3000);
  400. printk("********************Enter CTP Auto Upgrade********************\n");
  401. fts_ctpm_auto_upgrade(i2c_client);
  402. mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
  403. return 0;
  404. }
  405. #endif
  406. static int touch_event_handler(void *unused)
  407. {
  408. struct touch_info cinfo, pinfo;
  409. int i=0, point_num=0;
  410. struct sched_param param = { .sched_priority = RTPM_PRIO_TPD };
  411. #ifdef TPD_PROXIMITY
  412. int err;
  413. hwm_sensor_data sensor_data;
  414. u8 proximity_status;
  415. u8 state;
  416. #endif
  417.  
  418. sched_setscheduler(current, SCHED_RR, &param);
  419.  
  420. do
  421. {
  422. set_current_state(TASK_INTERRUPTIBLE);
  423. wait_event_interruptible(waiter,tpd_flag!=0);
  424. tpd_flag = 0;
  425. set_current_state(TASK_RUNNING);
  426.  
  427. #ifdef TPD_PROXIMITY
  428. if (tpd_proximity_flag == 1)
  429. {
  430. i2c_smbus_read_i2c_block_data(i2c_client, 0xB0, 1, &state);
  431. TPD_PROXIMITY_DEBUG("proxi_5206 0xB0 state value is 1131 0x%02X\n", state);
  432.  
  433. if(!(state&0x01))
  434. {
  435. tpd_enable_ps(1);
  436. }
  437.  
  438. i2c_smbus_read_i2c_block_data(i2c_client, 0x01, 1, &proximity_status);
  439. TPD_PROXIMITY_DEBUG("proxi_5206 0x01 value is 1139 0x%02X\n", proximity_status);
  440.  
  441. if (proximity_status == 0xC0)
  442. {
  443. tpd_proximity_detect = 0;
  444. }
  445. else if(proximity_status == 0xE0)
  446. {
  447. tpd_proximity_detect = 1;
  448. }
  449.  
  450. TPD_PROXIMITY_DEBUG("tpd_proximity_detect 1149 = %d\n", tpd_proximity_detect);
  451.  
  452. if ((err = tpd_read_ps()))
  453. {
  454. TPD_PROXIMITY_DMESG("proxi_5206 read ps data 1156: %d\n", err);
  455. }
  456. sensor_data.values[0] = tpd_get_ps_value();
  457. sensor_data.value_divide = 1;
  458. sensor_data.status = SENSOR_STATUS_ACCURACY_MEDIUM;
  459. if ((err = hwmsen_get_interrupt_data(ID_PROXIMITY, &sensor_data)))
  460. {
  461. TPD_PROXIMITY_DMESG(" proxi_5206 call hwmsen_get_interrupt_data failed= %d\n", err);
  462. }
  463. }
  464. #endif
  465.  
  466. if (tpd_touchinfo(&cinfo, &pinfo, &point_num))
  467. {
  468. //TPD_DEBUG("point_num = %d\n",point_num);
  469. TPD_DEBUG_SET_TIME;
  470. if(point_num >0)
  471. {
  472. for(i =0; i<point_num; i++)
  473. {
  474. tpd_down(cinfo.x[i], cinfo.y[i], cinfo.id[i]);
  475. }
  476. input_sync(tpd->dev);
  477. }
  478. else
  479. {
  480. tpd_up(cinfo.x[0], cinfo.y[0]);
  481. input_sync(tpd->dev);
  482. }
  483. }
  484. mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
  485. }while(!kthread_should_stop());
  486. return 0;
  487. }
  488.  
  489. static int tpd_detect (struct i2c_client *client, struct i2c_board_info *info)
  490. {
  491. strcpy(info->type, TPD_DEVICE);
  492. return 0;
  493. }
  494.  
  495. static void tpd_eint_interrupt_handler(void)
  496. {
  497. //TPD_DEBUG("TPD interrupt has been triggered\n");
  498. TPD_DEBUG_PRINT_INT;
  499. tpd_flag = 1;
  500. wake_up_interruptible(&waiter);
  501. }
  502. static int tpd_probe(struct i2c_client *client, const struct i2c_device_id *id)
  503. {
  504. int retval = TPD_OK;
  505. char data;
  506. int reset_count = 0;
  507.  
  508. client->timing = 300;
  509. i2c_client = client;
  510. reset_proc:
  511.  
  512. //power on, need confirm with SA
  513. mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
  514. mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
  515. mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ZERO);
  516. msleep(5);
  517. TPD_DMESG(" fts ic reset\n");
  518.  
  519. #ifdef TPD_POWER_SOURCE_CUSTOM
  520. hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_2800, "TP");
  521. #else
  522. hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_2800, "TP");
  523. #endif
  524.  
  525. #ifdef TPD_POWER_SOURCE_1800
  526. hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP");
  527. #endif
  528. mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
  529. mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
  530. mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE);
  531.  
  532. msleep(200);
  533.  
  534. if((i2c_smbus_read_i2c_block_data(i2c_client, 0x00, 1, &data))< 0)
  535. {
  536. TPD_DMESG("I2C transfer error, line: %d\n", __LINE__);
  537. #ifdef TPD_RESET_ISSUE_WORKAROUND
  538. if ( reset_count < TPD_MAX_RESET_COUNT )
  539. {
  540. reset_count++;
  541. goto reset_proc;
  542. }
  543. #endif
  544. return -1;
  545. }
  546.  
  547. mt_set_gpio_mode(GPIO_CTP_EINT_PIN, GPIO_CTP_EINT_PIN_M_EINT);
  548. mt_set_gpio_dir(GPIO_CTP_EINT_PIN, GPIO_DIR_IN);
  549. mt_set_gpio_pull_enable(GPIO_CTP_EINT_PIN, GPIO_PULL_ENABLE);
  550. mt_set_gpio_pull_select(GPIO_CTP_EINT_PIN, GPIO_PULL_UP);
  551.  
  552. mt_eint_registration(CUST_EINT_TOUCH_PANEL_NUM, CUST_EINT_TOUCH_PANEL_TYPE, tpd_eint_interrupt_handler, 0);
  553. mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
  554.  
  555. #ifdef TPD_AUTO_UPGRADE
  556. #ifndef TPD_SYSFS_DEBUG
  557. I2CDMABuf_va = (u8 *)dma_alloc_coherent(NULL, FTS_DMA_BUF_SIZE, &I2CDMABuf_pa, GFP_KERNEL);
  558.  
  559. if(!I2CDMABuf_va)
  560. {
  561. TPD_DMESG("%s Allocate DMA I2C Buffer failed!\n",__func__);
  562. return -EIO;
  563. }
  564. #endif
  565. #endif
  566.  
  567. #ifdef VELOCITY_CUSTOM
  568. tpd_v_magnify_x = TPD_VELOCITY_CUSTOM_X;
  569. tpd_v_magnify_y = TPD_VELOCITY_CUSTOM_Y;
  570. #endif
  571.  
  572. tpd_load_status = 1;
  573.  
  574. #ifdef FTS_APK_DEBUG
  575. ft5x0x_create_apk_debug_channel(client);
  576. #endif
  577. #ifdef TPD_SYSFS_DEBUG
  578. fts_create_sysfs(i2c_client);
  579. #endif
  580.  
  581. #ifdef FTS_CTL_IIC
  582. if (ft_rw_iic_drv_init(i2c_client) < 0)
  583. TPD_DMESG(TPD_DEVICE, "%s:[FTS] create fts control iic driver failed\n",__func__);
  584. #endif
  585.  
  586. #ifdef TPD_AUTO_UPGRADE
  587. thread = kthread_run(tpd_ft_update_fw, 0, TPD_DEVICE);
  588. if (IS_ERR(thread))
  589. {
  590. retval = PTR_ERR(thread);
  591. TPD_DMESG(TPD_DEVICE " failed to create kernel thread for update fw: %d\n", retval);
  592. }
  593. #endif
  594.  
  595. thread = kthread_run(touch_event_handler, 0, TPD_DEVICE);
  596. if (IS_ERR(thread))
  597. {
  598. retval = PTR_ERR(thread);
  599. TPD_DMESG(TPD_DEVICE " failed to create kernel thread: %d\n", retval);
  600. }
  601.  
  602. TPD_DMESG("FTS Touch Panel Device Probe %s\n", (retval < TPD_OK) ? "FAIL" : "PASS");
  603.  
  604. #ifdef TPD_PROXIMITY
  605. struct hwmsen_object obj_ps;
  606. int err = 0;
  607. obj_ps.polling = 0;//interrupt mode
  608. obj_ps.sensor_operate = tpd_ps_operate;
  609. if((err = hwmsen_attach(ID_PROXIMITY, &obj_ps)))
  610. {
  611. APS_ERR("proxi_fts attach fail = %d\n", err);
  612. }
  613. else
  614. {
  615. APS_ERR("proxi_fts attach ok = %d\n", err);
  616. }
  617. #endif
  618. return 0;
  619.  
  620. }
  621.  
  622. static int tpd_remove(struct i2c_client *client)
  623. {
  624.  
  625. #ifdef FTS_APK_DEBUG
  626. ft5x0x_release_apk_debug_channel();
  627. #endif
  628. #ifdef TPD_SYSFS_DEBUG
  629. fts_release_sysfs(client);
  630. #endif
  631.  
  632. #ifdef FTS_CTL_IIC
  633. ft_rw_iic_drv_exit();
  634. #endif
  635.  
  636. TPD_DEBUG("TPD removed\n");
  637.  
  638. return 0;
  639. }
  640.  
  641. static int tpd_local_init(void)
  642. {
  643. TPD_DMESG("FTS I2C Touchscreen Driver (Built %s @ %s)\n", __DATE__, __TIME__);
  644.  
  645. if(i2c_add_driver(&tpd_i2c_driver)!=0)
  646. {
  647. TPD_DMESG("FTS unable to add i2c driver.\n");
  648. return -1;
  649. }
  650. if(tpd_load_status == 0)
  651. {
  652. TPD_DMESG("FTS add error touch panel driver.\n");
  653. i2c_del_driver(&tpd_i2c_driver);
  654. return -1;
  655. }
  656.  
  657. #ifdef TPD_HAVE_BUTTON
  658. tpd_button_setting(TPD_KEY_COUNT, tpd_keys_local, tpd_keys_dim_local);// initialize tpd button data
  659. #endif
  660.  
  661. #if (defined(TPD_WARP_START) && defined(TPD_WARP_END))
  662. TPD_DO_WARP = 1;
  663. memcpy(tpd_wb_start, tpd_wb_start_local, TPD_WARP_CNT*4);
  664. memcpy(tpd_wb_end, tpd_wb_start_local, TPD_WARP_CNT*4);
  665. #endif
  666.  
  667. #if (defined(TPD_HAVE_CALIBRATION) && !defined(TPD_CUSTOM_CALIBRATION))
  668. memcpy(tpd_calmat, tpd_def_calmat_local, 8*4);
  669. memcpy(tpd_def_calmat, tpd_def_calmat_local, 8*4);
  670. #endif
  671. TPD_DMESG("end %s, %d\n", __FUNCTION__, __LINE__);
  672. tpd_type_cap = 1;
  673. return 0;
  674. }
  675.  
  676. static void tpd_resume( struct early_suspend *h )
  677. {
  678. #ifdef TPD_PROXIMITY
  679. if (tpd_proximity_flag == 1)
  680. {
  681. if(tpd_proximity_flag_one == 1)
  682. {
  683. tpd_proximity_flag_one = 0;
  684. TPD_DMESG(TPD_DEVICE " tpd_proximity_flag_one \n");
  685. return;
  686. }
  687. }
  688. #endif
  689.  
  690. TPD_DMESG("TPD wake up\n");
  691. #ifdef TPD_CLOSE_POWER_IN_SLEEP
  692. #ifdef TPD_POWER_SOURCE_CUSTOM
  693. hwPowerOn(TPD_POWER_SOURCE_CUSTOM, VOL_2800, "TP");
  694. #else
  695. hwPowerOn(MT65XX_POWER_LDO_VGP2, VOL_2800, "TP");
  696. #endif
  697. #ifdef TPD_POWER_SOURCE_1800
  698. hwPowerOn(TPD_POWER_SOURCE_1800, VOL_1800, "TP");
  699. #endif
  700. #endif
  701. mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
  702. mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
  703. mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ONE);
  704. msleep(30);
  705. tpd_halt = 0;
  706. mt_eint_unmask(CUST_EINT_TOUCH_PANEL_NUM);
  707. tpd_up(0,0);
  708. input_sync(tpd->dev);
  709. TPD_DMESG("TPD wake up done\n");
  710. }
  711.  
  712. static void tpd_suspend( struct early_suspend *h )
  713. {
  714. #ifndef TPD_CLOSE_POWER_IN_SLEEP
  715. static char data = 0x3;
  716. #endif
  717.  
  718. #ifdef TPD_PROXIMITY
  719. if (tpd_proximity_flag == 1)
  720. {
  721. tpd_proximity_flag_one = 1;
  722. return;
  723. }
  724. #endif
  725. TPD_DMESG("TPD enter sleep\n");
  726. mutex_lock(&i2c_access);
  727. tpd_halt = 1;
  728. mt_eint_mask(CUST_EINT_TOUCH_PANEL_NUM);
  729. mutex_unlock(&i2c_access);
  730.  
  731. mt_set_gpio_mode(GPIO_CTP_RST_PIN, GPIO_CTP_RST_PIN_M_GPIO);
  732. mt_set_gpio_dir(GPIO_CTP_RST_PIN, GPIO_DIR_OUT);
  733. mt_set_gpio_out(GPIO_CTP_RST_PIN, GPIO_OUT_ZERO);
  734. msleep(1);
  735. #ifdef TPD_CLOSE_POWER_IN_SLEEP
  736. #ifdef TPD_POWER_SOURCE_CUSTOM
  737. hwPowerDown(TPD_POWER_SOURCE_CUSTOM, "TP");
  738. #else
  739. hwPowerDown(MT65XX_POWER_LDO_VGP2, "TP");
  740. #endif
  741. #ifdef TPD_POWER_SOURCE_1800
  742. hwPowerDown(TPD_POWER_SOURCE_1800, "TP");
  743. #endif
  744. #else
  745. i2c_smbus_write_i2c_block_data(i2c_client, 0xA5, 1, &data); //TP enter sleep mode
  746. #endif
  747. TPD_DMESG("TPD enter sleep done\n");
  748. }
  749.  
  750.  
  751. static struct tpd_driver_t tpd_device_driver = {
  752. .tpd_device_name = "mtk-focal",
  753. .tpd_local_init = tpd_local_init,
  754. .suspend = tpd_suspend,
  755. .resume = tpd_resume,
  756. #ifdef TPD_HAVE_BUTTON
  757. .tpd_have_button = 1,
  758. #else
  759. .tpd_have_button = 0,
  760. #endif
  761. };
  762. /* called when loaded into kernel */
  763. static int __init tpd_driver_init(void) {
  764. printk("MediaTek FTS touch panel driver init\n");
  765. i2c_register_board_info(TPD_I2C_NUMBER, &ft5206_i2c_tpd, 1);
  766. if(tpd_driver_add(&tpd_device_driver) < 0)
  767. TPD_DMESG("add FTS driver failed\n");
  768. return 0;
  769. }
  770.  
  771. /* should never be called */
  772. static void __exit tpd_driver_exit(void) {
  773. TPD_DMESG("MediaTek FTS touch panel driver exit\n");
  774. //input_unregister_device(tpd->dev);
  775. tpd_driver_remove(&tpd_device_driver);
  776. }
  777.  
  778. module_init(tpd_driver_init);
  779. module_exit(tpd_driver_exit);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement