Guest User

Untitled

a guest
Mar 29th, 2015
481
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Copyright (C) 2011 XiaoMi, Inc.
  3. *
  4. * This software is licensed under the terms of the GNU General Public
  5. * License version 2, as published by the Free Software Foundation, and
  6. * may be copied, distributed, and modified under those terms.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. */
  14.  
  15. #include <linux/delay.h>
  16. #include <linux/firmware.h>
  17. #include <linux/gpio.h>
  18. #include <linux/init.h>
  19. #include <linux/of_gpio.h>
  20. #include <linux/regulator/consumer.h>
  21. #include <linux/firmware.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/i2c.h>
  24. #include <linux/input.h>
  25. #include <linux/input/ft5x06_ts.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/module.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/slab.h>
  30. #include <linux/uaccess.h>
  31. #include <linux/wakelock.h>
  32. #include <linux/power_supply.h>
  33. #include <linux/input/mt.h>
  34. #include "ft5x06_ts.h"
  35. #if defined(CONFIG_FB)
  36. #include <linux/notifier.h>
  37. #include <linux/fb.h>
  38. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  39. #include <linux/earlysuspend.h>
  40. #endif
  41. #ifdef CONFIG_FTS_GESTURE
  42. #include <linux/timer.h>
  43. #endif
  44.  
  45. #ifdef CONFIG_FTS_GESTURE
  46. #define FT_GESTURE_DOUBLECLICK 0x24
  47. #define FT_GESTURE_OUTPUT_ADRESS 0xD3
  48. #define FT_GESTRUE_POINTS_HEADER 8
  49. #endif
  50.  
  51.  
  52. //register address
  53. #define FT5X0X_REG_DEVIDE_MODE 0x00
  54. #define FT5X0X_REG_ROW_ADDR 0x01
  55. #define FT5X0X_REG_TD_STATUS 0x02
  56. #define FT5X0X_REG_START_SCAN 0x02
  57. #define FT5X0X_REG_TOUCH_START 0x03
  58. #define FT5X0X_REG_VOLTAGE 0x05
  59. #define FT5X0X_REG_CHIP_ID 0xA3
  60. #define FT5X0X_ID_G_PMODE 0xA5
  61. #define FT5x0x_REG_FW_VER 0xA6
  62. #define FT5x0x_ID_G_FT5201ID 0xA8
  63. #define FT5X0X_NOISE_FILTER 0x8B
  64. #define FT5x0x_REG_POINT_RATE 0x88
  65. #define FT5X0X_REG_THGROUP 0x80
  66. #define FT5X0X_REG_RESET 0xFC
  67.  
  68. #define FT5X0X_DEVICE_MODE_NORMAL 0x00
  69. #define FT5X0X_DEVICE_MODE_TEST 0x40
  70. #define FT5X0X_DEVICE_START_CALIB 0x04
  71. #define FT5X0X_DEVICE_SAVE_RESULT 0x05
  72.  
  73. #define FT5X0X_POWER_ACTIVE 0x00
  74. #define FT5X0X_POWER_MONITOR 0x01
  75. #define FT5X0X_POWER_HIBERNATE 0x03
  76.  
  77.  
  78. /* ft5x0x register list */
  79. #define FT5X0X_TOUCH_LENGTH 6
  80.  
  81. #define FT5X0X_TOUCH_XH 0x00 /* offset from each touch */
  82. #define FT5X0X_TOUCH_XL 0x01
  83. #define FT5X0X_TOUCH_YH 0x02
  84. #define FT5X0X_TOUCH_YL 0x03
  85. #define FT5X0X_TOUCH_PRESSURE 0x04
  86. #define FT5X0X_TOUCH_SIZE 0x05
  87.  
  88. /* ft5x0x bit field definition */
  89. #define FT5X0X_MODE_NORMAL 0x00
  90. #define FT5X0X_MODE_SYSINFO 0x10
  91. #define FT5X0X_MODE_TEST 0x40
  92. #define FT5X0X_MODE_MASK 0x70
  93.  
  94. #define FT5X0X_EVENT_DOWN 0x00
  95. #define FT5X0X_EVENT_UP 0x40
  96. #define FT5X0X_EVENT_CONTACT 0x80
  97. #define FT5X0X_EVENT_MASK 0xc0
  98.  
  99.  
  100. /* ft5x0x firmware upgrade definition */
  101. #define FT5X0X_FIRMWARE_TAIL -8 /* base on the end of firmware */
  102. #define FT5X0X_FIRMWARE_VERION -2
  103. #define FT5X0X_PACKET_HEADER 6
  104. #define FT5X0X_PACKET_LENGTH 128
  105.  
  106. /* ft5x0x absolute value */
  107. #define FT5X0X_MAX_FINGER 0x0A
  108. #define FT5X0X_MAX_SIZE 0xff
  109. #define FT5X0X_MAX_PRESSURE 0xff
  110.  
  111. #define NOISE_FILTER_DELAY HZ
  112.  
  113. #define FT_VTG_MIN_UV 2600000
  114. #define FT_VTG_MAX_UV 3300000
  115. #define FT_I2C_VTG_MIN_UV 1800000
  116. #define FT_I2C_VTG_MAX_UV 1800000
  117.  
  118. /*upgrade config of FT5316*/
  119. #define FT5316_UPGRADE_AA_DELAY 50
  120. #define FT5316_UPGRADE_55_DELAY 40
  121. #define FT5316_UPGRADE_ID_1 0x79
  122. #define FT5316_UPGRADE_ID_2 0x07
  123. #define FT5316_UPGRADE_READID_DELAY 1
  124.  
  125. /*upgrade config of FT5X36*/
  126. #define FT5X36_UPGRADE_AA_DELAY 30
  127. #define FT5X36_UPGRADE_55_DELAY 30
  128. #define FT5X36_UPGRADE_ID_1 0x79
  129. #define FT5X36_UPGRADE_ID_2 0x11
  130. #define FT5X36_UPGRADE_READID_DELAY 10
  131.  
  132. #define FT5316_CHIP_ID 0x0A
  133. #define FT5X36_CHIP_ID 0x14
  134.  
  135. #define FT5316_PROJ_ID "FTS0000x000"
  136. #define FT5X36_PROJ_ID "FTS0000P000"
  137.  
  138. #define FT5X0X_UPGRADE_LOOP 3
  139.  
  140. #define BL_VERSION_LZ4 0
  141. #define BL_VERSION_Z7 1
  142. #define BL_VERSION_GZF 2
  143.  
  144. struct upgrade_info {
  145. u16 delay_aa; /*delay of write FT_UPGRADE_AA*/
  146. u16 delay_55; /*delay of write FT_UPGRADE_55*/
  147. u8 upgrade_id_1; /*upgrade id 1*/
  148. u8 upgrade_id_2; /*upgrade id 2*/
  149. u16 delay_readid; /*delay of read id*/
  150. };
  151.  
  152. struct ft5x06_packet {
  153. u8 magic1;
  154. u8 magic2;
  155. u16 offset;
  156. u16 length;
  157. u8 payload[FT5X0X_PACKET_LENGTH];
  158. };
  159.  
  160. struct ft5x06_finger {
  161. int x, y;
  162. int size;
  163. int pressure;
  164. bool detect;
  165. };
  166.  
  167. struct ft5x06_tracker {
  168. int x, y;
  169. bool detect;
  170. bool moving;
  171. unsigned long jiffies;
  172. };
  173.  
  174. struct ft5x06_data {
  175. struct mutex mutex;
  176. struct device *dev;
  177. struct input_dev *input;
  178. struct kobject *vkeys_dir;
  179. struct kobj_attribute vkeys_attr;
  180. struct notifier_block power_supply_notifier;
  181. struct regulator *vdd;
  182. struct regulator *vcc_i2c;
  183. const struct ft5x06_bus_ops *bops;
  184. struct ft5x06_tracker tracker[FT5X0X_MAX_FINGER];
  185. int irq;
  186. bool dbgdump;
  187. unsigned int test_result;
  188. bool in_suspend;
  189. struct delayed_work noise_filter_delayed_work;
  190. u8 chip_id;
  191. u8 is_usb_plug_in;
  192. u8 *tch_data;
  193. #if defined(CONFIG_FB)
  194. struct notifier_block fb_notif;
  195. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  196. struct early_suspend early_suspend;
  197. #endif
  198. };
  199.  
  200.  
  201. #ifdef CONFIG_FTS_GESTURE
  202. #define FTS_GESTURE_PROC_FILE "gesture_open"
  203. static struct proc_dir_entry *gesture_proc = NULL;
  204. static struct timer_list ft5x06_gesture_timer;
  205. static char ft5x06_gesture_state;
  206. static char ft5x06_gesture_open=1;
  207. struct device * ft5x06_dev=NULL;
  208. #endif
  209.  
  210. static int ft5x06_recv_byte(struct ft5x06_data *ft5x06, u8 len, ...)
  211. {
  212. int error;
  213. va_list varg;
  214. u8 i, buf[len];
  215.  
  216. error = ft5x06->bops->recv(ft5x06->dev, buf, len);
  217. if (error)
  218. return error;
  219.  
  220. va_start(varg, len);
  221. for (i = 0; i < len; i++)
  222. *va_arg(varg, u8 *) = buf[i];
  223. va_end(varg);
  224.  
  225. return 0;
  226. }
  227.  
  228. static int ft5x06_send_block(struct ft5x06_data *ft5x06,
  229. const void *buf, int len)
  230. {
  231. return ft5x06->bops->send(ft5x06->dev, buf, len);
  232. }
  233.  
  234. static int ft5x06_send_byte(struct ft5x06_data *ft5x06, u8 len, ...)
  235. {
  236. va_list varg;
  237. u8 i, buf[len];
  238.  
  239. va_start(varg, len);
  240. for (i = 0; i < len; i++)
  241. buf[i] = va_arg(varg, int); /* u8 promote to int */
  242. va_end(varg);
  243.  
  244. return ft5x06_send_block(ft5x06, buf, len);
  245. }
  246.  
  247. static int ft5x06_read_block(struct ft5x06_data *ft5x06,
  248. u8 addr, void *buf, u8 len)
  249. {
  250. return ft5x06->bops->read(ft5x06->dev, addr, buf, len);
  251. }
  252.  
  253. static int ft5x06_read_byte(struct ft5x06_data *ft5x06, u8 addr, u8 *data)
  254. {
  255. return ft5x06_read_block(ft5x06, addr, data, sizeof(*data));
  256. }
  257.  
  258. static int ft5x06_write_byte(struct ft5x06_data *ft5x06, u8 addr, u8 data)
  259. {
  260. return ft5x06->bops->write(ft5x06->dev, addr, &data, sizeof(data));
  261. }
  262.  
  263.  
  264. static void ft5x06_charger_state_changed(struct ft5x06_data *ft5x06)
  265. {
  266. u8 is_usb_exist;
  267.  
  268. is_usb_exist = power_supply_is_system_supplied();
  269. if (is_usb_exist != ft5x06->is_usb_plug_in) {
  270. ft5x06->is_usb_plug_in = is_usb_exist;
  271. dev_info(ft5x06->dev, "Power state changed, set noise filter to 0x%x\n", is_usb_exist);
  272. mutex_lock(&ft5x06->mutex);
  273. ft5x06_write_byte(ft5x06, FT5X0X_NOISE_FILTER, is_usb_exist);
  274. mutex_unlock(&ft5x06->mutex);
  275. }
  276. }
  277.  
  278. static void ft5x06_noise_filter_delayed_work(struct work_struct *work)
  279. {
  280. struct delayed_work *delayed_work = to_delayed_work(work);
  281. struct ft5x06_data *ft5x06 = container_of(delayed_work, struct ft5x06_data, noise_filter_delayed_work);
  282.  
  283. dev_info(ft5x06->dev, "ft5x06_noise_filter_delayed_work called\n");
  284. ft5x06_charger_state_changed(ft5x06);
  285. }
  286.  
  287. static int ft5x06_power_supply_event(struct notifier_block *nb, unsigned long event, void *ptr)
  288. {
  289. struct ft5x06_data *ft5x06 = container_of(nb, struct ft5x06_data, power_supply_notifier);
  290.  
  291. if (ft5x06->dbgdump)
  292. dev_info(ft5x06->dev, "Power_supply_event\n");
  293. if (!ft5x06->in_suspend)
  294. ft5x06_charger_state_changed(ft5x06);
  295. else if (ft5x06->dbgdump)
  296. dev_info(ft5x06->dev, "Don't response to power supply event in suspend mode!\n");
  297.  
  298. return 0;
  299. }
  300.  
  301. #ifdef CONFIG_TOUCHSCREEN_FT5X06_CALIBRATE
  302. static int ft5x06_auto_calib(struct ft5x06_data *ft5x06)
  303. {
  304. int error;
  305. u8 val1;
  306. int i;
  307. msleep(200);
  308. error = ft5x06_write_byte(ft5x06, /* enter factory mode */
  309. FT5X0X_REG_DEVIDE_MODE, FT5X0X_DEVICE_MODE_TEST);
  310. if (error)
  311. return error;
  312. msleep(100);
  313.  
  314. error = ft5x06_write_byte(ft5x06, /* start calibration */
  315. FT5X0X_REG_START_SCAN, FT5X0X_DEVICE_START_CALIB);
  316. if (error)
  317. return error;
  318. msleep(300);
  319.  
  320. for (i = 0; i < 100; i++) {
  321. error = ft5x06_read_byte(ft5x06, FT5X0X_REG_DEVIDE_MODE, &val1);
  322. if (error)
  323. return error;
  324. if ((val1&0x70) == 0) /* return to normal mode? */
  325. break;
  326. msleep(200); /* not yet, wait and try again later */
  327. }
  328. dev_info(ft5x06->dev, "[FTS] calibration OK.\n");
  329.  
  330. msleep(300); /* enter factory mode again */
  331. error = ft5x06_write_byte(ft5x06, FT5X0X_REG_DEVIDE_MODE, FT5X0X_DEVICE_MODE_TEST);
  332. if (error)
  333. return error;
  334. msleep(100);
  335.  
  336. error = ft5x06_write_byte(ft5x06, /* save calibration result */
  337. FT5X0X_REG_START_SCAN, FT5X0X_DEVICE_SAVE_RESULT);
  338. if (error)
  339. return error;
  340. msleep(300);
  341.  
  342. error = ft5x06_write_byte(ft5x06, /* return to normal mode */
  343. FT5X0X_REG_DEVIDE_MODE, FT5X0X_DEVICE_MODE_NORMAL);
  344. if (error)
  345. return error;
  346. msleep(300);
  347. dev_info(ft5x06->dev, "[FTS] Save calib result OK.\n");
  348.  
  349. return 0;
  350. }
  351. #endif
  352.  
  353. #ifdef CONFIG_FTS_GESTURE
  354.  
  355. static void ft5x06_gesture_change_state(unsigned long lparam)
  356. {
  357. ft5x06_gesture_state=0;
  358. printk("D2W on ftx06_gesture_change_state");
  359. }
  360. void ft5x06_gesture_init_temer(void)
  361. {
  362. init_timer(&ft5x06_gesture_timer);
  363. ft5x06_gesture_timer.expires = jiffies + HZ/2;
  364. ft5x06_gesture_timer.function = ft5x06_gesture_change_state;
  365. add_timer(&ft5x06_gesture_timer);
  366. ft5x06_gesture_state=1;
  367. printk("D2W on ftx06_gesture_init_temer");
  368. }
  369. static void ft5x06_read_gesture_data(struct ft5x06_data *ft5x06)
  370. {
  371. int ret;
  372. u8 *buf = ft5x06->tch_data;
  373.  
  374. if(ft5x06_gesture_state == 1)
  375. return;
  376. buf[0] = FT_GESTURE_OUTPUT_ADRESS;
  377. ret = ft5x06_read_block(ft5x06, FT5X0X_REG_TOUCH_START, buf, FT_GESTRUE_POINTS_HEADER);
  378. if (ret < 0)
  379. {
  380. printk( "%s read touchdata failed.\n", __func__);
  381. return;
  382. }
  383.  
  384. if(FT_GESTURE_DOUBLECLICK == buf[0])
  385. {
  386. input_event(ft5x06->input,EV_KEY,116,1);
  387. input_event(ft5x06->input,EV_KEY,116,0);
  388. input_sync(ft5x06->input);
  389. }
  390. printk("D2W on ftx06_read_gesture_data");
  391. ft5x06_gesture_init_temer();
  392. }
  393. #endif
  394.  
  395. static void fts_get_upgrade_info(struct ft5x06_data *ft5x06, struct upgrade_info *ui)
  396. {
  397. switch(ft5x06->chip_id) {
  398. case FT5316_CHIP_ID:
  399. ui->delay_55 = FT5316_UPGRADE_55_DELAY;
  400. ui->delay_aa = FT5316_UPGRADE_AA_DELAY;
  401. ui->upgrade_id_1 = FT5316_UPGRADE_ID_1;
  402. ui->upgrade_id_2 = FT5316_UPGRADE_ID_2;
  403. ui->delay_readid = FT5316_UPGRADE_READID_DELAY;
  404. break;
  405. case FT5X36_CHIP_ID:
  406. default:
  407. ui->delay_55 = FT5X36_UPGRADE_55_DELAY;
  408. ui->delay_aa = FT5X36_UPGRADE_AA_DELAY;
  409. ui->upgrade_id_1 = FT5X36_UPGRADE_ID_1;
  410. ui->upgrade_id_2 = FT5X36_UPGRADE_ID_2;
  411. ui->delay_readid = FT5X36_UPGRADE_READID_DELAY;
  412. break;
  413. }
  414. }
  415.  
  416. static u8 reset_delay[] = {
  417. 30, 33, 36, 39, 42, 45, 27, 24, 11, 18, 15
  418. };
  419.  
  420. static u8 ft5x06_get_factory_id(struct ft5x06_data *ft5x06)
  421. {
  422. int error = 0;
  423. int i, j;
  424. u8 reg_val[2], val1, val2;
  425. u8 ft5336_bootloader_ver;
  426. struct ft5x06_packet packet;
  427. u8 vid;
  428.  
  429. for (i = 0, error = -1; i < sizeof(reset_delay) && error; i++) {
  430. /* step 1: reset device */
  431. error = ft5x06_write_byte(ft5x06, FT5X0X_REG_RESET, 0xaa);
  432. if (error)
  433. continue;
  434. msleep(50);
  435.  
  436. error = ft5x06_write_byte(ft5x06, FT5X0X_REG_RESET, 0x55);
  437. if (error)
  438. continue;
  439. msleep(reset_delay[i]);
  440. dev_info(ft5x06->dev, "[FTS] step1: Reset device.\n");
  441.  
  442. /* step 2: enter upgrade mode */
  443. for (j = 0; j < 10; j++) {
  444. error = ft5x06_send_byte(ft5x06, 2, 0x55, 0xaa);
  445. msleep(5);
  446. if (!error)
  447. break;
  448. }
  449. if (error)
  450. continue;
  451.  
  452. dev_info(ft5x06->dev, "[FTS] step2: Enter upgrade mode.\n");
  453.  
  454. /* step 4: check device id */
  455. error = ft5x06_send_byte(ft5x06, 4, 0x90, 0x00, 0x00, 0x00);
  456. if (error) {
  457. dev_err(ft5x06->dev, "Failed to send 90 00 00 00\n");
  458. continue;
  459. }
  460.  
  461. error = ft5x06_recv_byte(ft5x06, 2, &val1, &val2);
  462. if (error) {
  463. dev_err(ft5x06->dev, "Failed to receive device id\n");
  464. continue;
  465. }
  466.  
  467. pr_info("read id = 0x%x, 0x%x\n", val1, val2);
  468.  
  469. dev_info(ft5x06->dev, "[FTS] step3: Check device id.\n");
  470.  
  471. if (val1 == FT5316_UPGRADE_ID_1 && val2 == FT5316_UPGRADE_ID_2) {
  472. ft5x06->chip_id = FT5316_CHIP_ID;
  473. break;
  474. } else if (val1 == FT5X36_UPGRADE_ID_1 && val2 == FT5X36_UPGRADE_ID_2) {
  475. ft5x06->chip_id = FT5X36_CHIP_ID;
  476. break;
  477. }
  478. }
  479.  
  480. if (error)
  481. return error;
  482.  
  483. error = ft5x06_send_byte(ft5x06, 1, 0xCD);
  484. if (error)
  485. return error;
  486. error = ft5x06_recv_byte(ft5x06, 1, &reg_val[0]);
  487. if (error)
  488. return error;
  489. dev_info(ft5x06->dev, "bootloader version = 0x%x\n", reg_val[0]);
  490. if (ft5x06->chip_id == FT5X36_CHIP_ID) {
  491. if (reg_val[0] <= 4)
  492. ft5336_bootloader_ver = BL_VERSION_LZ4;
  493. else if (reg_val[0] == 7)
  494. ft5336_bootloader_ver = BL_VERSION_Z7;
  495. else if (reg_val[0] >= 0x0f)
  496. ft5336_bootloader_ver = BL_VERSION_GZF;
  497. } else
  498. ft5336_bootloader_ver = BL_VERSION_LZ4;
  499.  
  500. packet.magic1 = 0x03;
  501. packet.magic2 = 0x00;
  502.  
  503. if (ft5336_bootloader_ver == BL_VERSION_Z7 ||
  504. ft5336_bootloader_ver == BL_VERSION_GZF)
  505. packet.offset = cpu_to_be16(0x07b4 + j);
  506. else
  507. packet.offset = cpu_to_be16(0x7820 + j);
  508. error = ft5x06_send_block(ft5x06, &packet,
  509. FT5X0X_PACKET_HEADER);
  510. if (error)
  511. return error;
  512. error = ft5x06_recv_byte(ft5x06, 1, &vid);
  513. if (error)
  514. return error;
  515.  
  516. error = ft5x06_send_byte(ft5x06, 1, 0x07);
  517. if (error)
  518. return error;
  519. msleep(200);
  520.  
  521. return vid;
  522. }
  523.  
  524. static int ft5x06_load_firmware(struct ft5x06_data *ft5x06,
  525. struct ft5x06_firmware_data *firmware, bool *upgraded)
  526. {
  527. struct ft5x06_packet packet;
  528. int i, j, length, error = 0;
  529. u8 val1, val2, vid, ecc = 0, id;
  530. #ifdef CONFIG_TOUCHSCREEN_FT5X06_CALIBRATE
  531. const int max_calib_time = 3;
  532. bool calib_ok = false;
  533. #endif
  534. bool is_5336_fwsize_30 = false;
  535. u8 ft5336_bootloader_ver;
  536. struct upgrade_info ui;
  537. const struct firmware *fw;
  538. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  539.  
  540. /* step 0a: check and init argument */
  541. if (upgraded)
  542. *upgraded = false;
  543.  
  544. if (firmware == NULL)
  545. return 0;
  546.  
  547. /* step 0b: find the right firmware for touch screen */
  548. error = ft5x06_read_byte(ft5x06, FT5x0x_ID_G_FT5201ID, &vid);
  549. if (error)
  550. return error;
  551. dev_info(ft5x06->dev, "firmware vendor is %02x\n", vid);
  552. id = vid;
  553. if (vid == FT5x0x_ID_G_FT5201ID ||
  554. vid == 0 || ft5x06->chip_id == 0) {
  555. vid = ft5x06_get_factory_id(ft5x06);
  556. dev_err(ft5x06->dev, "firmware corruption, read real factory id = 0x%x!\n", vid);
  557. }
  558.  
  559. for (i = 0; i < pdata->cfg_size; i++, firmware++) {
  560. if (vid == firmware->vendor) {
  561. if (ft5x06->dev->of_node)
  562. if(ft5x06->chip_id == firmware->chip) {
  563. dev_info(ft5x06->dev, "chip id = 0x%x, found it!\n",
  564. ft5x06->chip_id);
  565. break;
  566. }
  567. else
  568. continue;
  569. else
  570. break;
  571. }
  572. }
  573.  
  574. if (!ft5x06->dev->of_node && firmware->size == 0) {
  575. dev_err(ft5x06->dev, "unknown touch screen vendor, failed!\n");
  576. return -ENOENT;
  577. } else if (ft5x06->dev->of_node && (i == pdata->cfg_size)) {
  578. dev_err(ft5x06->dev, "Failed to find matched config!\n");
  579. return -ENOENT;
  580. }
  581.  
  582. if (firmware->size == 0 && ft5x06->dev->of_node) {
  583. dev_info(ft5x06->dev, "firmware name = %s\n", firmware->fwname);
  584. error = request_firmware(&fw, firmware->fwname, ft5x06->dev);
  585. if (!error) {
  586. firmware->data = kmalloc((int)fw->size, GFP_KERNEL);
  587. if (!firmware->data) {
  588. dev_err(ft5x06->dev, "Failed to allocate firmware!\n");
  589. return -ENOMEM;
  590. } else {
  591. memcpy(firmware->data, fw->data, (int)fw->size);
  592. firmware->size = (int)fw->size;
  593. }
  594. }
  595. }
  596.  
  597. fts_get_upgrade_info(ft5x06, &ui);
  598. if (firmware->data[firmware->size - 12] == 30)
  599. is_5336_fwsize_30 = true;
  600. else
  601. is_5336_fwsize_30 = false;
  602.  
  603. /* step 1: check firmware id is different */
  604. error = ft5x06_read_byte(ft5x06, FT5x0x_REG_FW_VER, &id);
  605. if (error)
  606. return error;
  607. dev_info(ft5x06->dev, "firmware version is %02x\n", id);
  608.  
  609. if (id == firmware->data[firmware->size+FT5X0X_FIRMWARE_VERION])
  610. return 0;
  611. dev_info(ft5x06->dev, "upgrade firmware to %02x\n",
  612. firmware->data[firmware->size+FT5X0X_FIRMWARE_VERION]);
  613. dev_info(ft5x06->dev, "[FTS] step1: check fw id\n");
  614.  
  615. for (i = 0, error = -1; i < sizeof(reset_delay) && error; i++) {
  616. /* step 2: reset device */
  617. error = ft5x06_write_byte(ft5x06, FT5X0X_REG_RESET, 0xaa);
  618. if (error)
  619. continue;
  620. msleep(ui.delay_aa);
  621.  
  622. error = ft5x06_write_byte(ft5x06, FT5X0X_REG_RESET, 0x55);
  623. if (error)
  624. continue;
  625. msleep(reset_delay[i]);
  626. dev_info(ft5x06->dev, "[FTS] step2: Reset device.\n");
  627.  
  628. /* step 3: enter upgrade mode */
  629. for (j = 0; j < 10; j++) {
  630. error = ft5x06_send_byte(ft5x06, 2, 0x55, 0xaa);
  631. msleep(5);
  632. if (!error)
  633. break;
  634. }
  635. if (error)
  636. continue;
  637.  
  638. dev_info(ft5x06->dev, "[FTS] step3: Enter upgrade mode.\n");
  639.  
  640. /* step 4: check device id */
  641. error = ft5x06_send_byte(ft5x06, 4, 0x90, 0x00, 0x00, 0x00);
  642. if (error) {
  643. dev_err(ft5x06->dev, "Failed to send 90 00 00 00\n");
  644. continue;
  645. }
  646.  
  647. error = ft5x06_recv_byte(ft5x06, 2, &val1, &val2);
  648. if (error) {
  649. dev_err(ft5x06->dev, "Failed to receive device id\n");
  650. continue;
  651. }
  652.  
  653. pr_info("read id = 0x%x, 0x%x, id = 0x%x, 0x%x\n", val1, val2,
  654. ui.upgrade_id_1, ui.upgrade_id_2);
  655. if (val1 != ui.upgrade_id_1 || val2 != ui.upgrade_id_2)
  656. error = -ENODEV;
  657.  
  658. dev_info(ft5x06->dev, "[FTS] step4: Check device id.\n");
  659. }
  660.  
  661. if (error) /* check the final result */
  662. return error;
  663.  
  664. error = ft5x06_send_byte(ft5x06, 1, 0xcd);
  665. if (error)
  666. return error;
  667. error = ft5x06_recv_byte(ft5x06, 1, &val1);
  668. if (error)
  669. return error;
  670. dev_info(ft5x06->dev, "[FTS] bootloader version is 0x%x\n", val1);
  671. if (ft5x06->chip_id == FT5X36_CHIP_ID) {
  672. if (val1 <= 4)
  673. ft5336_bootloader_ver = BL_VERSION_LZ4;
  674. else if (val1 == 7)
  675. ft5336_bootloader_ver = BL_VERSION_Z7;
  676. else if (val1 >= 0x0f)
  677. ft5336_bootloader_ver = BL_VERSION_GZF;
  678. } else
  679. ft5336_bootloader_ver = BL_VERSION_LZ4;
  680.  
  681. /* step 5: erase device */
  682. error = ft5x06_send_byte(ft5x06, 1, 0x61);
  683. if (error)
  684. return error;
  685. msleep(1500);
  686. if (is_5336_fwsize_30) {
  687. error = ft5x06_send_byte(ft5x06, 1, 0x63);
  688. if (error)
  689. return error;
  690. msleep(50);
  691. }
  692. dev_info(ft5x06->dev, "[FTS] step5: Erase device.\n");
  693.  
  694. /* step 6: flash firmware to device */
  695. if (ft5336_bootloader_ver == BL_VERSION_LZ4 ||
  696. ft5336_bootloader_ver == BL_VERSION_Z7)
  697. firmware->size -= 8;
  698. else if (ft5336_bootloader_ver == BL_VERSION_GZF)
  699. firmware->size -= 14;
  700.  
  701. packet.magic1 = 0xbf;
  702. packet.magic2 = 0x00;
  703. /* step 6a: send data in 128 bytes chunk each time */
  704. for (i = 0; i < firmware->size; i += length) {
  705. length = min(FT5X0X_PACKET_LENGTH,
  706. firmware->size - i);
  707.  
  708. packet.offset = cpu_to_be16(i);
  709. packet.length = cpu_to_be16(length);
  710.  
  711. for (j = 0; j < length; j++) {
  712. packet.payload[j] = firmware->data[i+j];
  713. ecc ^= firmware->data[i+j];
  714. }
  715.  
  716. error = ft5x06_send_block(ft5x06, &packet,
  717. FT5X0X_PACKET_HEADER+length);
  718. if (error)
  719. return error;
  720.  
  721. msleep(FT5X0X_PACKET_LENGTH/6 + 1);
  722. }
  723. dev_info(ft5x06->dev, "[FTS] step6a: Send data in 128 bytes chunk each time.\n");
  724.  
  725. /* step 6b: send one byte each time for last six bytes */
  726. if (ft5336_bootloader_ver == BL_VERSION_LZ4 ||
  727. ft5336_bootloader_ver == BL_VERSION_Z7) {
  728. for (j = 0; i < firmware->size + 6; i++, j++) {
  729. if (ft5336_bootloader_ver== BL_VERSION_Z7 &&
  730. ft5x06->chip_id == FT5X36_CHIP_ID)
  731. packet.offset = cpu_to_be16(0x7bfa+j);
  732. else if (ft5336_bootloader_ver == BL_VERSION_LZ4)
  733. packet.offset = cpu_to_be16(0x6ffa+j);
  734. packet.length = cpu_to_be16(1);
  735.  
  736. packet.payload[0] = firmware->data[i];
  737. ecc ^= firmware->data[i];
  738.  
  739. error = ft5x06_send_block(ft5x06, &packet,
  740. FT5X0X_PACKET_HEADER+1);
  741. if (error)
  742. return error;
  743.  
  744. msleep(20);
  745. }
  746. }
  747. else if (ft5336_bootloader_ver == BL_VERSION_GZF) {
  748. for (j = 0; i < firmware->size + 12; i++, j++) {
  749. if(is_5336_fwsize_30 &&
  750. ft5x06->chip_id == FT5X36_CHIP_ID)
  751. packet.offset = cpu_to_be16(0x7ff4+j);
  752. else if (ft5x06->chip_id == FT5X36_CHIP_ID)
  753. packet.offset = cpu_to_be16(0x7bf4+j);
  754. packet.length = cpu_to_be16(1);
  755.  
  756. packet.payload[0] = firmware->data[i];
  757. ecc ^= firmware->data[i];
  758.  
  759. error = ft5x06_send_block(ft5x06, &packet,
  760. FT5X0X_PACKET_HEADER+1);
  761. if (error)
  762. return error;
  763.  
  764. msleep(20);
  765. }
  766. }
  767. dev_info(ft5x06->dev, "[FTS] step6b: Send one byte each time for last six bytes.\n");
  768.  
  769. /* step 7: verify checksum */
  770. error = ft5x06_send_byte(ft5x06, 1, 0xcc);
  771. if (error)
  772. return error;
  773.  
  774. error = ft5x06_recv_byte(ft5x06, 1, &val1);
  775. if (error)
  776. return error;
  777.  
  778. if (val1 != ecc)
  779. return -ERANGE;
  780. dev_info(ft5x06->dev, "[FTS] step7:Verify checksum.\n");
  781.  
  782. /* step 8: reset to new firmware */
  783. error = ft5x06_send_byte(ft5x06, 1, 0x07);
  784. if (error)
  785. return error;
  786. msleep(300);
  787. dev_info(ft5x06->dev, "[FTS] step8: Reset to new firmware.\n");
  788.  
  789. #ifdef CONFIG_TOUCHSCREEN_FT5X06_CALIBRATE
  790. /* step 9: calibrate the reference value */
  791. for (i = 0; i < max_calib_time; i++) {
  792. error = ft5x06_auto_calib(ft5x06);
  793. if (!error) {
  794. calib_ok = true;
  795. dev_info(ft5x06->dev, "[FTS] step9: Calibrate the ref value successfully.\n");
  796. break;
  797. }
  798. }
  799. if (!calib_ok) {
  800. dev_info(ft5x06->dev, "[FTS] step9: Calibrate the ref value failed.\n");
  801. return error;
  802. }
  803. #endif
  804.  
  805. if (upgraded)
  806. *upgraded = true;
  807.  
  808. return 0;
  809. }
  810.  
  811. static int ft5x06_collect_finger(struct ft5x06_data *ft5x06,
  812. struct ft5x06_finger *finger, int count)
  813. {
  814. u8 number, buf[256];
  815. int i, error;
  816.  
  817. error = ft5x06_read_byte(ft5x06, FT5X0X_REG_TD_STATUS, &number);
  818. if (error)
  819. return error;
  820. number &= 0x0f;
  821.  
  822. if (number > FT5X0X_MAX_FINGER)
  823. number = FT5X0X_MAX_FINGER;
  824.  
  825. error = ft5x06_read_block(ft5x06, FT5X0X_REG_TOUCH_START,
  826. buf, FT5X0X_TOUCH_LENGTH*number);
  827. if (error)
  828. return error;
  829.  
  830. /* clear the finger buffer */
  831. memset(finger, 0, sizeof(*finger)*count);
  832.  
  833. for (i = 0; i < number; i++) {
  834. u8 xh = buf[FT5X0X_TOUCH_LENGTH*i+FT5X0X_TOUCH_XH];
  835. u8 xl = buf[FT5X0X_TOUCH_LENGTH*i+FT5X0X_TOUCH_XL];
  836. u8 yh = buf[FT5X0X_TOUCH_LENGTH*i+FT5X0X_TOUCH_YH];
  837. u8 yl = buf[FT5X0X_TOUCH_LENGTH*i+FT5X0X_TOUCH_YL];
  838.  
  839. u8 size = buf[FT5X0X_TOUCH_LENGTH*i+FT5X0X_TOUCH_SIZE];
  840. u8 pressure = buf[FT5X0X_TOUCH_LENGTH*i+FT5X0X_TOUCH_PRESSURE];
  841.  
  842. u8 id = (yh&0xf0)>>4;
  843. if (id >= FT5X0X_MAX_FINGER)
  844. id = FT5X0X_MAX_FINGER - 1;
  845.  
  846. finger[id].x = ((xh&0x0f)<<8)|xl;
  847. finger[id].y = ((yh&0x0f)<<8)|yl;
  848. finger[id].size = size;
  849. finger[id].pressure = pressure;
  850. finger[id].detect = (xh&FT5X0X_EVENT_MASK) != FT5X0X_EVENT_UP;
  851.  
  852. if (ft5x06->dbgdump)
  853. dev_info(ft5x06->dev,
  854. "fig(%02u): %d %04d %04d %03d %03d\n", id,
  855. finger[i].detect, finger[i].x, finger[i].y,
  856. finger[i].pressure, finger[i].size);
  857. }
  858.  
  859. return 0;
  860. }
  861.  
  862. static void ft5x06_apply_filter(struct ft5x06_data *ft5x06,
  863. struct ft5x06_finger *finger, int count)
  864. {
  865. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  866. int i;
  867.  
  868. for (i = 0; i < count; i++) {
  869. if (!finger[i].detect) /* finger release */
  870. ft5x06->tracker[i].detect = false;
  871. else if (!ft5x06->tracker[i].detect) { /* initial touch */
  872. ft5x06->tracker[i].x = finger[i].x;
  873. ft5x06->tracker[i].y = finger[i].y;
  874. ft5x06->tracker[i].detect = true;
  875. ft5x06->tracker[i].moving = false;
  876. ft5x06->tracker[i].jiffies = jiffies;
  877. } else { /* the rest report until finger lift */
  878. unsigned long landed_jiffies;
  879. int delta_x, delta_y, threshold;
  880.  
  881. landed_jiffies = ft5x06->tracker[i].jiffies;
  882. landed_jiffies += pdata->landing_jiffies;
  883.  
  884. /* no significant movement yet */
  885. if (!ft5x06->tracker[i].moving) {
  886. /* use the big threshold for landing period */
  887. if (time_before(jiffies, landed_jiffies))
  888. threshold = pdata->landing_threshold;
  889. else /* use the middle jitter threshold */
  890. threshold = pdata->staying_threshold;
  891. } else { /* use the small threshold during movement */
  892. threshold = pdata->moving_threshold;
  893. }
  894.  
  895. delta_x = finger[i].x - ft5x06->tracker[i].x;
  896. delta_y = finger[i].y - ft5x06->tracker[i].y;
  897.  
  898. delta_x *= delta_x;
  899. delta_y *= delta_y;
  900.  
  901. /* use the saved value for small change */
  902. if (delta_x + delta_y <= threshold * threshold)
  903. {
  904. finger[i].x = ft5x06->tracker[i].x;
  905. finger[i].y = ft5x06->tracker[i].y;
  906. } else {/* save new location */
  907. ft5x06->tracker[i].x = finger[i].x;
  908. ft5x06->tracker[i].y = finger[i].y;
  909. ft5x06->tracker[i].moving = true;
  910. }
  911. }
  912. }
  913. }
  914.  
  915. static void ft5x06_report_touchevent(struct ft5x06_data *ft5x06,
  916. struct ft5x06_finger *finger, int count)
  917. {
  918. #ifndef CONFIG_TOUCHSCREEN_FT5X06_TYPEB
  919. bool mt_sync_sent = false;
  920. #endif
  921. int i;
  922.  
  923. for (i = 0; i < count; i++) {
  924. #ifdef CONFIG_TOUCHSCREEN_FT5X06_TYPEB
  925. input_mt_slot(ft5x06->input, i);
  926. #endif
  927. if (!finger[i].detect) {
  928. #ifdef CONFIG_TOUCHSCREEN_FT5X06_TYPEB
  929. input_mt_report_slot_state(ft5x06->input, MT_TOOL_FINGER, 0);
  930. input_report_abs(ft5x06->input, ABS_MT_TRACKING_ID, -1);
  931. #endif
  932. continue;
  933. }
  934.  
  935. #ifdef CONFIG_TOUCHSCREEN_FT5X06_TYPEB
  936. input_mt_report_slot_state(ft5x06->input, MT_TOOL_FINGER, 1);
  937. #endif
  938. input_report_abs(ft5x06->input, ABS_MT_TRACKING_ID, i);
  939. input_report_abs(ft5x06->input, ABS_MT_POSITION_X ,
  940. max(1, finger[i].x)); /* for fruit ninja */
  941. input_report_abs(ft5x06->input, ABS_MT_POSITION_Y ,
  942. max(1, finger[i].y)); /* for fruit ninja */
  943. input_report_abs(ft5x06->input, ABS_MT_TOUCH_MAJOR,
  944. max(1, finger[i].pressure));
  945. input_report_abs(ft5x06->input, ABS_MT_WIDTH_MAJOR,
  946. max(1, finger[i].size));
  947. #ifndef CONFIG_TOUCHSCREEN_FT5X06_TYPEB
  948. input_mt_sync(ft5x06->input);
  949. mt_sync_sent = true;
  950. #endif
  951. if (ft5x06->dbgdump)
  952. dev_info(ft5x06->dev,
  953. "tch(%02d): %04d %04d %03d %03d\n",
  954. i, finger[i].x, finger[i].y,
  955. finger[i].pressure, finger[i].size);
  956. }
  957. #ifndef CONFIG_TOUCHSCREEN_FT5X06_TYPEB
  958. if (!mt_sync_sent) {
  959. input_mt_sync(ft5x06->input);
  960. if (ft5x06->dbgdump)
  961. dev_info(ft5x06->dev, "tch(xx): no touch contact\n");
  962. }
  963. #endif
  964.  
  965. input_sync(ft5x06->input);
  966. }
  967.  
  968. static irqreturn_t ft5x06_interrupt(int irq, void *dev_id)
  969. {
  970. struct ft5x06_finger finger[FT5X0X_MAX_FINGER];
  971. struct ft5x06_data *ft5x06 = dev_id;
  972. int error;
  973. u8 *buf = ft5x06->tch_data;
  974. printk("D2W on ftx06_interrupt");
  975.  
  976. #ifdef CONFIG_FTS_GESTURE
  977. if(1 == ft5x06_gesture_open)
  978. {
  979. ft5x06_read_byte(ft5x06, 0xd0, buf);
  980. if(1 == buf[0])
  981. {
  982. ft5x06_read_gesture_data(ft5x06);
  983. return IRQ_HANDLED;
  984. }
  985. }
  986.  
  987. #endif
  988.  
  989. mutex_lock(&ft5x06->mutex);
  990. error = ft5x06_collect_finger(ft5x06, finger, FT5X0X_MAX_FINGER);
  991. if (error >= 0) {
  992. ft5x06_apply_filter(ft5x06, finger, FT5X0X_MAX_FINGER);
  993. ft5x06_report_touchevent(ft5x06, finger, FT5X0X_MAX_FINGER);
  994. } else
  995. dev_err(ft5x06->dev, "fail to collect finger(%d)\n", error);
  996. mutex_unlock(&ft5x06->mutex);
  997.  
  998. return IRQ_HANDLED;
  999. }
  1000.  
  1001. int ft5x06_gesture_open_export(void);
  1002. int ft5x06_gesture_close_export(void);
  1003. int ft5x06_suspend(struct ft5x06_data *ft5x06)
  1004. {
  1005. int error = 0;
  1006.  
  1007. #ifdef CONFIG_FTS_GESTURE
  1008. printk("D2W on ftx06_suspend");
  1009. if(ft5x06_gesture_open_export() == 1)
  1010. return 0;
  1011. #endif
  1012.  
  1013.  
  1014. disable_irq(ft5x06->irq);
  1015. mutex_lock(&ft5x06->mutex);
  1016. memset(ft5x06->tracker, 0, sizeof(ft5x06->tracker));
  1017.  
  1018. ft5x06->in_suspend = true;
  1019. cancel_delayed_work_sync(&ft5x06->noise_filter_delayed_work);
  1020. error = ft5x06_write_byte(ft5x06,
  1021. FT5X0X_ID_G_PMODE, FT5X0X_POWER_HIBERNATE);
  1022.  
  1023. mutex_unlock(&ft5x06->mutex);
  1024.  
  1025. return error;
  1026. }
  1027. EXPORT_SYMBOL_GPL(ft5x06_suspend);
  1028.  
  1029. int ft5x06_resume(struct ft5x06_data *ft5x06)
  1030. {
  1031. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  1032.  
  1033. #ifdef CONFIG_FTS_GESTURE
  1034. printk("D2W on ftx06_resume");
  1035. if(ft5x06_gesture_close_export()==1)
  1036. return 0;
  1037. #endif
  1038.  
  1039. mutex_lock(&ft5x06->mutex);
  1040.  
  1041. /* reset device */
  1042. gpio_set_value_cansleep(pdata->reset_gpio, 0);
  1043. msleep(20);
  1044. gpio_set_value_cansleep(pdata->reset_gpio, 1);
  1045. msleep(50);
  1046.  
  1047. schedule_delayed_work(&ft5x06->noise_filter_delayed_work,
  1048. NOISE_FILTER_DELAY);
  1049. ft5x06->in_suspend = false;
  1050. mutex_unlock(&ft5x06->mutex);
  1051. enable_irq(ft5x06->irq);
  1052.  
  1053. return 0;
  1054. }
  1055. EXPORT_SYMBOL_GPL(ft5x06_resume);
  1056.  
  1057. #if defined(CONFIG_FB)
  1058. static int fb_notifier_callback(struct notifier_block *self,
  1059. unsigned long event, void *data)
  1060. {
  1061. struct fb_event *evdata = data;
  1062. int *blank;
  1063. struct ft5x06_data *ft5x06 =
  1064. container_of(self, struct ft5x06_data, fb_notif);
  1065.  
  1066. if (evdata && evdata->data && event == FB_EVENT_BLANK &&
  1067. ft5x06 && ft5x06->dev) {
  1068. blank = evdata->data;
  1069. if (*blank == FB_BLANK_UNBLANK) {
  1070. pr_info("ft5x06 resume!\n");
  1071. ft5x06_resume(ft5x06);
  1072. }
  1073. else if (*blank == FB_BLANK_POWERDOWN) {
  1074. pr_info("ft5x06 suspend!\n");
  1075. ft5x06_suspend(ft5x06);
  1076. }
  1077. }
  1078.  
  1079. return 0;
  1080. }
  1081. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  1082. static void ft5x06_early_suspend(struct early_suspend *h)
  1083. {
  1084. struct ft5x06_data *ft5x06 = container_of(h,
  1085. struct ft5x06_data, early_suspend);
  1086. ft5x06_suspend(ft5x06);
  1087. }
  1088.  
  1089. static void ft5x06_early_resume(struct early_suspend *h)
  1090. {
  1091. struct ft5x06_data *ft5x06 = container_of(h,
  1092. struct ft5x06_data, early_suspend);
  1093. ft5x06_resume(ft5x06);
  1094. }
  1095. #endif
  1096.  
  1097. static ssize_t ft5x06_vkeys_show(struct kobject *kobj,
  1098. struct kobj_attribute *attr, char *buf)
  1099. {
  1100. struct ft5x06_data *ft5x06 =
  1101. container_of(attr, struct ft5x06_data, vkeys_attr);
  1102. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  1103. const struct ft5x06_keypad_data *keypad;
  1104. int i, count = 0;
  1105.  
  1106. for (i = 0; i < pdata->cfg_size; i++) {
  1107. if (ft5x06->chip_id == pdata->keypad[i].chip) {
  1108. keypad = &pdata->keypad[i];
  1109. }
  1110. }
  1111. for (i = 0; keypad && i < keypad->length; i++) {
  1112. int width = keypad->button[i].width;
  1113. int height = keypad->button[i].height;
  1114. int midx = keypad->button[i].left+width/2;
  1115. int midy = keypad->button[i].top+height/2;
  1116.  
  1117. count += snprintf(buf+count, PAGE_SIZE-count,
  1118. "0x%02x:%d:%d:%d:%d:%d:",
  1119. EV_KEY, keypad->keymap[i],
  1120. midx, midy, width, height);
  1121. }
  1122.  
  1123. count -= 1; /* remove the last colon */
  1124. count += snprintf(buf+count, PAGE_SIZE-count, "\n");
  1125. return count;
  1126. }
  1127.  
  1128. static ssize_t ft5x06_object_show(struct device *dev,
  1129. struct device_attribute *attr, char *buf)
  1130. {
  1131. static struct {
  1132. u8 addr;
  1133. const char *fmt;
  1134. } reg_list[] = {
  1135. /* threshold setting */
  1136. {0x80, "THGROUP %3d\n" },
  1137. {0x81, "THPEAK %3d\n" },
  1138. {0x82, "THCAL %3d\n" },
  1139. {0x83, "THWATER %3d\n" },
  1140. {0x84, "THTEMP %3d\n" },
  1141. {0x85, "THDIFF %3d\n" },
  1142. {0xae, "THBAREA %3d\n" },
  1143. /* mode setting */
  1144. {0x86, "CTRL %02x\n"},
  1145. {0xa0, "AUTOCLB %02x\n"},
  1146. {0xa4, "MODE %02x\n"},
  1147. {0xa5, "PMODE %02x\n"},
  1148. {0xa7, "STATE %02x\n"},
  1149. {0xa9, "ERR %02x\n"},
  1150. /* timer setting */
  1151. {0x87, "TIME2MONITOR %3d\n" },
  1152. {0x88, "PERIODACTIVE %3d\n" },
  1153. {0x89, "PERIODMONITOR %3d\n" },
  1154. /* version info */
  1155. {0xa1, "LIBVERH %02x\n"},
  1156. {0xa2, "LIBVERL %02x\n"},
  1157. {0xa3, "CIPHER %02x\n"},
  1158. {0xa6, "FIRMID %02x\n"},
  1159. {0xa8, "FT5201ID %02x\n"},
  1160. {/* end of the list */},
  1161. };
  1162.  
  1163. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1164. int i, error, count = 0;
  1165. u8 val;
  1166.  
  1167. mutex_lock(&ft5x06->mutex);
  1168. for (i = 0; reg_list[i].addr != 0; i++) {
  1169. error = ft5x06_read_byte(ft5x06, reg_list[i].addr, &val);
  1170. if (error)
  1171. break;
  1172.  
  1173. count += snprintf(buf+count, PAGE_SIZE-count,
  1174. reg_list[i].fmt, val);
  1175. }
  1176. mutex_unlock(&ft5x06->mutex);
  1177.  
  1178. return error ? : count;
  1179. }
  1180.  
  1181. static ssize_t ft5x06_object_store(struct device *dev,
  1182. struct device_attribute *attr,
  1183. const char *buf, size_t count)
  1184. {
  1185. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1186. u8 addr, val;
  1187. int error;
  1188.  
  1189. mutex_lock(&ft5x06->mutex);
  1190. if (sscanf(buf, "%hhx=%hhx", &addr, &val) == 2)
  1191. error = ft5x06_write_byte(ft5x06, addr, val);
  1192. else
  1193. error = -EINVAL;
  1194. mutex_unlock(&ft5x06->mutex);
  1195.  
  1196. return error ? : count;
  1197. }
  1198.  
  1199. static ssize_t ft5x06_dbgdump_show(struct device *dev,
  1200. struct device_attribute *attr, char *buf)
  1201. {
  1202. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1203. int count;
  1204.  
  1205. mutex_lock(&ft5x06->mutex);
  1206. count = sprintf(buf, "%d\n", ft5x06->dbgdump);
  1207. mutex_unlock(&ft5x06->mutex);
  1208.  
  1209. return count;
  1210. }
  1211.  
  1212. static ssize_t ft5x06_dbgdump_store(struct device *dev,
  1213. struct device_attribute *attr,
  1214. const char *buf, size_t count)
  1215. {
  1216. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1217. unsigned long dbgdump;
  1218. int error;
  1219.  
  1220. mutex_lock(&ft5x06->mutex);
  1221. error = strict_strtoul(buf, 0, &dbgdump);
  1222. if (!error)
  1223. ft5x06->dbgdump = dbgdump;
  1224. mutex_unlock(&ft5x06->mutex);
  1225.  
  1226. return error ? : count;
  1227. }
  1228.  
  1229. static ssize_t ft5x06_updatefw_store(struct device *dev,
  1230. struct device_attribute *attr,
  1231. const char *buf, size_t count)
  1232. {
  1233. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1234. struct ft5x06_firmware_data firmware;
  1235. const struct firmware *fw;
  1236. bool upgraded;
  1237. int error;
  1238.  
  1239. error = request_firmware(&fw, "ft5x06.bin", dev);
  1240. if (!error) {
  1241. firmware.data = kmalloc((int)fw->size, GFP_KERNEL);
  1242. memcpy(firmware.data, fw->data, (int)fw->size);
  1243. firmware.size = fw->size;
  1244.  
  1245. mutex_lock(&ft5x06->mutex);
  1246. error = ft5x06_load_firmware(ft5x06, &firmware, &upgraded);
  1247. mutex_unlock(&ft5x06->mutex);
  1248.  
  1249. kfree(firmware.data);
  1250. release_firmware(fw);
  1251. }
  1252.  
  1253. return error ? : count;
  1254. }
  1255.  
  1256. static ssize_t ft5x06_tpfwver_show(struct device *dev,
  1257. struct device_attribute *attr, char *buf)
  1258. {
  1259. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1260. ssize_t num_read_chars = 0;
  1261. u8 fwver = 0;
  1262. int error;
  1263. mutex_lock(&ft5x06->mutex);
  1264. error = ft5x06_read_byte(ft5x06, FT5x0x_REG_FW_VER, &fwver);
  1265. if (error)
  1266. num_read_chars = snprintf(buf, PAGE_SIZE, "Get firmware version failed!\n");
  1267. else
  1268. num_read_chars = snprintf(buf, PAGE_SIZE, "%02X\n", fwver);
  1269. mutex_unlock(&ft5x06->mutex);
  1270. return num_read_chars;
  1271. }
  1272.  
  1273. static int ft5x06_enter_factory(struct ft5x06_data *ft5x06_ts)
  1274. {
  1275. u8 reg_val;
  1276. int error;
  1277.  
  1278. error = ft5x06_write_byte(ft5x06_ts, FT5X0X_REG_DEVIDE_MODE,
  1279. FT5X0X_DEVICE_MODE_TEST);
  1280. if (error)
  1281. return -1;
  1282. msleep(100);
  1283. error = ft5x06_read_byte(ft5x06_ts, FT5X0X_REG_DEVIDE_MODE, &reg_val);
  1284. if (error)
  1285. return -1;
  1286. if ((reg_val & 0x70) != FT5X0X_DEVICE_MODE_TEST) {
  1287. dev_info(ft5x06_ts->dev, "ERROR: The Touch Panel was not put in Factory Mode.");
  1288. return -1;
  1289. }
  1290.  
  1291. return 0;
  1292. }
  1293.  
  1294. static int ft5x06_enter_work(struct ft5x06_data *ft5x06_ts)
  1295. {
  1296. u8 reg_val;
  1297. int error;
  1298. error = ft5x06_write_byte(ft5x06_ts, FT5X0X_REG_DEVIDE_MODE,
  1299. FT5X0X_DEVICE_MODE_NORMAL);
  1300. if (error)
  1301. return -1;
  1302. msleep(100);
  1303. error = ft5x06_read_byte(ft5x06_ts, FT5X0X_REG_DEVIDE_MODE, &reg_val);
  1304. if (error)
  1305. return -1;
  1306. if ((reg_val & 0x70) != FT5X0X_DEVICE_MODE_NORMAL) {
  1307. dev_info(ft5x06_ts->dev, "ERROR: The Touch Panel was not put in Normal Mode.\n");
  1308. return -1;
  1309. }
  1310.  
  1311. return 0;
  1312. }
  1313.  
  1314. #define FT5x0x_TX_NUM 28
  1315. #define FT5x0x_RX_NUM 16
  1316. static int ft5x06_get_rawData(struct ft5x06_data *ft5x06_ts,
  1317. u16 rawdata[][FT5x0x_RX_NUM])
  1318. {
  1319. int ret_val = 0;
  1320. int error;
  1321. u8 val;
  1322. int row_num = 0;
  1323. u8 read_buffer[FT5x0x_RX_NUM * 2];
  1324. int read_len;
  1325. int i;
  1326.  
  1327. error = ft5x06_read_byte(ft5x06_ts, FT5X0X_REG_DEVIDE_MODE, &val);
  1328. if (error < 0) {
  1329. dev_err(ft5x06_ts->dev, "ERROR: Read mode failed!\n");
  1330. ret_val = -1;
  1331. goto error_return;
  1332. }
  1333. val |= 0x80;
  1334. error = ft5x06_write_byte(ft5x06_ts, FT5X0X_REG_DEVIDE_MODE, val);
  1335. if (error < 0) {
  1336. dev_err(ft5x06_ts->dev, "ERROR: Write mode failed!\n");
  1337. ret_val = -1;
  1338. goto error_return;
  1339. }
  1340. msleep(20);
  1341. error = ft5x06_read_byte(ft5x06_ts, FT5X0X_REG_DEVIDE_MODE, &val);
  1342. if (error < 0) {
  1343. dev_err(ft5x06_ts->dev, "ERROR: Read mode failed!\n");
  1344. ret_val = -1;
  1345. goto error_return;
  1346. }
  1347. if (0x00 != (val & 0x80)) {
  1348. dev_err(ft5x06_ts->dev, "ERROR: Read mode failed!\n");
  1349. ret_val = -1;
  1350. goto error_return;
  1351. }
  1352. dev_info(ft5x06_ts->dev, "Read rawdata......\n");
  1353. for (row_num = 0; row_num < FT5x0x_TX_NUM; row_num++) {
  1354. memset(read_buffer, 0x00, (FT5x0x_RX_NUM * 2));
  1355. error = ft5x06_write_byte(ft5x06_ts, FT5X0X_REG_ROW_ADDR, row_num);
  1356. if (error < 0) {
  1357. dev_err(ft5x06_ts->dev, "ERROR: Write row addr failed!\n");
  1358. ret_val = -1;
  1359. goto error_return;
  1360. }
  1361. msleep(1);
  1362. read_len = FT5x0x_RX_NUM * 2;
  1363. error = ft5x06_write_byte(ft5x06_ts, 0x10, read_len);
  1364. if (error < 0) {
  1365. dev_err(ft5x06_ts->dev, "ERROR: Write len failed!\n");
  1366. ret_val = -1;
  1367. goto error_return;
  1368. }
  1369. error = ft5x06_read_block(ft5x06_ts, 0x10,
  1370. read_buffer, FT5x0x_RX_NUM * 2);
  1371. if (error < 0) {
  1372. dev_err(ft5x06_ts->dev,
  1373. "ERROR: Coule not read row %u data!\n", row_num);
  1374. ret_val = -1;
  1375. goto error_return;
  1376. }
  1377. for (i = 0; i < FT5x0x_RX_NUM; i++) {
  1378. rawdata[row_num][i] = read_buffer[i<<1];
  1379. rawdata[row_num][i] = rawdata[row_num][i] << 8;
  1380. rawdata[row_num][i] |= read_buffer[(i<<1)+1];
  1381. }
  1382. }
  1383. error_return:
  1384. return ret_val;
  1385. }
  1386.  
  1387. static int ft5x06_get_diffData(struct ft5x06_data *ft5x06_ts,
  1388. u16 diffdata[][FT5x0x_RX_NUM],
  1389. u16 *average)
  1390. {
  1391. u16 after_rawdata[FT5x0x_TX_NUM][FT5x0x_RX_NUM];
  1392. int error;
  1393. int ret_val = 0;
  1394. u8 reg_value;
  1395. u8 orig_vol = 0;
  1396. int i, j;
  1397. unsigned int total = 0;
  1398. struct ft5x06_ts_platform_data *pdata = ft5x06_ts->dev->platform_data;
  1399. int tx_num = pdata->tx_num - 1;
  1400. int rx_num = pdata->rx_num;
  1401.  
  1402. /*get original voltage and change it to get new frame rawdata*/
  1403. error = ft5x06_read_byte(ft5x06_ts, FT5X0X_REG_VOLTAGE, &reg_value);
  1404. if (error < 0) {
  1405. dev_err(ft5x06_ts->dev, "ERROR: Could not get voltage data!\n");
  1406. goto error_return;
  1407. } else
  1408. orig_vol = reg_value;
  1409.  
  1410. error = ft5x06_write_byte(ft5x06_ts, FT5X0X_REG_VOLTAGE, 0);
  1411. if (error < 0) {
  1412. dev_err(ft5x06_ts->dev, "ERROR: Could not set voltage data to 0!\n");
  1413. goto error_return;
  1414. }
  1415.  
  1416. for (i = 0; i < 3; i++) {
  1417. error = ft5x06_get_rawData(ft5x06_ts, diffdata);
  1418. if (error < 0) {
  1419. dev_err(ft5x06_ts->dev, "ERROR: Could not get original raw data!\n");
  1420. ret_val = error;
  1421. goto error_return;
  1422. }
  1423. }
  1424.  
  1425. reg_value = 2;
  1426.  
  1427. dev_info(ft5x06_ts->dev, "original voltage: 0 changed voltage:%u\n",
  1428. reg_value);
  1429.  
  1430. error = ft5x06_write_byte(ft5x06_ts, FT5X0X_REG_VOLTAGE, reg_value);
  1431. if (error < 0) {
  1432. dev_err(ft5x06_ts->dev, "ERROR: Could not set voltage data!\n");
  1433. ret_val = error;
  1434. goto error_return;
  1435. }
  1436.  
  1437. /* get raw data */
  1438. for (i = 0; i < 3; i++) {
  1439. error = ft5x06_get_rawData(ft5x06_ts, after_rawdata);
  1440. if (error < 0) {
  1441. dev_err(ft5x06_ts->dev, "ERROR: Could not get after raw data!\n");
  1442. ret_val = error;
  1443. goto error_voltage;
  1444. }
  1445. }
  1446.  
  1447. for (i = 0; i < tx_num; i++) {
  1448. for (j = 0; j < rx_num; j++) {
  1449. if (after_rawdata[i][j] > diffdata[i][j])
  1450. diffdata[i][j] = after_rawdata[i][j] - diffdata[i][j];
  1451. else
  1452. diffdata[i][j] = diffdata[i][j] - after_rawdata[i][j];
  1453.  
  1454. total += diffdata[i][j];
  1455.  
  1456. printk(KERN_CONT "%d ", diffdata[i][j]);
  1457. }
  1458. pr_info("total = %d\n", total);
  1459. }
  1460.  
  1461. *average = (u16)(total / (tx_num * rx_num));
  1462.  
  1463. error_voltage:
  1464. error = ft5x06_write_byte(ft5x06_ts, FT5X0X_REG_VOLTAGE, orig_vol);
  1465. if (error < 0) {
  1466. ret_val = error;
  1467. dev_err(ft5x06_ts->dev, "ERROR: Could not get voltage data!\n");
  1468. }
  1469.  
  1470. error_return:
  1471. return ret_val;
  1472.  
  1473. }
  1474.  
  1475. static ssize_t ft5x06_rawdata_show(struct device *dev,
  1476. struct device_attribute *attr, char *buf)
  1477. {
  1478. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1479. u16 rawdata[FT5x0x_TX_NUM][FT5x0x_RX_NUM];
  1480. int error;
  1481. int i = 0, j = 0;
  1482. int num_read_chars = 0;
  1483. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  1484. int tx_num = pdata->tx_num - 1;
  1485. int rx_num = pdata->rx_num;
  1486.  
  1487. mutex_lock(&ft5x06->mutex);
  1488.  
  1489. disable_irq_nosync(ft5x06->irq);
  1490. error = ft5x06_enter_factory(ft5x06);
  1491. if (error < 0) {
  1492. dev_err(ft5x06->dev, "ERROR: Could not enter factory mode!\n");
  1493. goto end;
  1494. }
  1495.  
  1496. error = ft5x06_get_rawData(ft5x06, rawdata);
  1497. if (error < 0)
  1498. sprintf(buf, "%s", "Could not get rawdata\n");
  1499. else {
  1500. for (i = 0; i < tx_num; i++) {
  1501. for (j = 0; j < rx_num; j++) {
  1502. num_read_chars += sprintf(&buf[num_read_chars],
  1503. "%u ", rawdata[i][j]);
  1504. }
  1505. buf[num_read_chars-1] = '\n';
  1506. }
  1507. }
  1508.  
  1509. error = ft5x06_enter_work(ft5x06);
  1510. if (error < 0)
  1511. dev_err(ft5x06->dev, "ERROR: Could not enter work mode!\n");
  1512.  
  1513. end:
  1514. enable_irq(ft5x06->irq);
  1515. mutex_unlock(&ft5x06->mutex);
  1516. return num_read_chars;
  1517. }
  1518.  
  1519. static ssize_t ft5x06_diffdata_show(struct device *dev,
  1520. struct device_attribute *attr, char *buf)
  1521. {
  1522. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1523. u16 diffdata[FT5x0x_TX_NUM][FT5x0x_RX_NUM];
  1524. int error;
  1525. int i = 0, j = 0;
  1526. int num_read_chars = 0;
  1527. u16 average;
  1528. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  1529. int tx_num = pdata->tx_num - 1;
  1530. int rx_num = pdata->rx_num;
  1531.  
  1532. mutex_lock(&ft5x06->mutex);
  1533. disable_irq_nosync(ft5x06->irq);
  1534. error = ft5x06_enter_factory(ft5x06);
  1535. if (error < 0) {
  1536. dev_err(ft5x06->dev, "ERROR: Could not enter factory mode!\n");
  1537. goto end;
  1538. }
  1539.  
  1540. error = ft5x06_get_diffData(ft5x06, diffdata, &average);
  1541. if (error < 0)
  1542. sprintf(buf, "%s", "Could not get rawdata\n");
  1543. else {
  1544. for (i = 0; i < tx_num; i++) {
  1545. for (j = 0; j < rx_num; j++) {
  1546. num_read_chars += sprintf(&buf[num_read_chars],
  1547. "%u ", diffdata[i][j]);
  1548. }
  1549. buf[num_read_chars-1] = '\n';
  1550. }
  1551. }
  1552.  
  1553. error = ft5x06_enter_work(ft5x06);
  1554. if (error < 0)
  1555. dev_err(ft5x06->dev, "ERROR: Could not enter work mode!\n");
  1556.  
  1557. end:
  1558. enable_irq(ft5x06->irq);
  1559. mutex_unlock(&ft5x06->mutex);
  1560. return num_read_chars;
  1561. }
  1562.  
  1563. unsigned int ft5x06_do_selftest(struct ft5x06_data *ft5x06)
  1564. {
  1565. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  1566. u16 testdata[FT5x0x_TX_NUM][FT5x0x_RX_NUM];
  1567. int i, j;
  1568. int error;
  1569. const struct ft5x06_keypad_data *keypad;
  1570. u16 average;
  1571.  
  1572. for (i = 0; i < pdata->cfg_size; i++) {
  1573. if (ft5x06->chip_id == pdata->keypad[i].chip) {
  1574. keypad = &pdata->keypad[i];
  1575. }
  1576. }
  1577.  
  1578. /* 1. test raw data */
  1579. error = ft5x06_get_rawData(ft5x06, testdata);
  1580. if (error)
  1581. return 0;
  1582.  
  1583. for (i = 0; i < pdata->tx_num; i++) {
  1584. if (i != pdata->tx_num - 1) {
  1585. for (j = 0; j < pdata->rx_num; j++) {
  1586. if (testdata[i][j] < pdata->raw_min ||
  1587. testdata[i][j] > pdata->raw_max) {
  1588. return 0;
  1589. }
  1590. }
  1591. } else {
  1592. for (j = 0; j < keypad->length; j++) {
  1593. if (testdata[i][keypad->key_pos[j]] < pdata->raw_min ||
  1594. testdata[i][keypad->key_pos[j]] > pdata->raw_max) {
  1595. return 0;
  1596. }
  1597. }
  1598. }
  1599. }
  1600.  
  1601. /* 2. test diff data */
  1602. error = ft5x06_get_diffData(ft5x06, testdata, &average);
  1603. if (error)
  1604. return 0;
  1605. for (i = 0; i < pdata->tx_num - 1; i++) {
  1606. for (j = 0; j < pdata->rx_num; j++) {
  1607. if ((testdata[i][j] < average * 13 / 20) ||
  1608. (testdata[i][j] > average * 27 / 20)) {
  1609. dev_info(ft5x06->dev, "Failed, testdata = %d, average = %d\n",
  1610. testdata[i][j], average);
  1611. return 0;
  1612. }
  1613. }
  1614. }
  1615.  
  1616. return 1;
  1617. }
  1618.  
  1619. static ssize_t ft5x06_selftest_store(struct device *dev,
  1620. struct device_attribute *attr,
  1621. const char *buf, size_t count)
  1622. {
  1623. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1624. int error;
  1625. unsigned long val;
  1626.  
  1627. error = strict_strtoul(buf, 0, &val);
  1628. if (error )
  1629. return error;
  1630. if (val != 1)
  1631. return -EINVAL;
  1632.  
  1633. mutex_lock(&ft5x06->mutex);
  1634.  
  1635. disable_irq_nosync(ft5x06->irq);
  1636. error = ft5x06_enter_factory(ft5x06);
  1637. if (error < 0) {
  1638. dev_err(ft5x06->dev, "ERROR: Could not enter factory mode!\n");
  1639. goto end;
  1640. }
  1641.  
  1642. ft5x06->test_result = ft5x06_do_selftest(ft5x06);
  1643.  
  1644. error = ft5x06_enter_work(ft5x06);
  1645. if (error < 0)
  1646. dev_err(ft5x06->dev, "ERROR: Could not enter work mode!\n");
  1647.  
  1648. end:
  1649. enable_irq(ft5x06->irq);
  1650. mutex_unlock(&ft5x06->mutex);
  1651. return count;
  1652. }
  1653.  
  1654. static ssize_t ft5x06_selftest_show(struct device *dev,
  1655. struct device_attribute *attr, char *buf)
  1656. {
  1657. struct ft5x06_data *ft5x06 = dev_get_drvdata(dev);
  1658.  
  1659. return sprintf(&buf[0], "%u\n", ft5x06->test_result);
  1660. }
  1661.  
  1662. /* sysfs */
  1663. static DEVICE_ATTR(tpfwver, 0644, ft5x06_tpfwver_show, NULL);
  1664. static DEVICE_ATTR(object, 0644, ft5x06_object_show, ft5x06_object_store);
  1665. static DEVICE_ATTR(dbgdump, 0644, ft5x06_dbgdump_show, ft5x06_dbgdump_store);
  1666. static DEVICE_ATTR(updatefw, 0200, NULL, ft5x06_updatefw_store);
  1667. static DEVICE_ATTR(rawdatashow, 0644, ft5x06_rawdata_show, NULL);
  1668. static DEVICE_ATTR(diffdatashow, 0644, ft5x06_diffdata_show, NULL);
  1669. static DEVICE_ATTR(selftest, 0644, ft5x06_selftest_show, ft5x06_selftest_store);
  1670.  
  1671. #ifdef CONFIG_FTS_GESTURE
  1672. int ft5x06_gesture_open_export(void)
  1673. {
  1674. struct ft5x06_data *ft5x06=NULL;
  1675. char i;
  1676. if(ft5x06_dev == NULL)
  1677. return 0;
  1678. ft5x06 = dev_get_drvdata(ft5x06_dev);
  1679. if(ft5x06==NULL)
  1680. return 0;
  1681. if(ft5x06_gesture_open == 0)
  1682. return 0;
  1683. ft5x06_write_byte(ft5x06,0xd0,0x01);//let fw open gestrue function
  1684. ft5x06_write_byte(ft5x06,0xd1,0x3f);//let fw open gestrue function
  1685. ft5x06_write_byte(ft5x06,0xd2,0x3f);//let fw open gestrue function
  1686. ft5x06_write_byte(ft5x06,0xd3,0x00);//let fw open gestrue function
  1687. ft5x06->in_suspend = true;
  1688. /* release all touches */
  1689. for (i = 0; i < 2; i++) {
  1690. input_mt_slot(ft5x06->input, i);
  1691. input_mt_report_slot_state(ft5x06->input, MT_TOOL_FINGER, 0);
  1692. }
  1693. input_mt_report_pointer_emulation(ft5x06->input, false);
  1694. input_sync(ft5x06->input);
  1695. printk(KERN_ERR "liyatang gesture open\n");
  1696. return 1;
  1697. }
  1698. EXPORT_SYMBOL(ft5x06_gesture_open_export);
  1699. int ft5x06_gesture_close_export(void)
  1700. {
  1701. struct ft5x06_data *ft5x06=NULL;
  1702. if(ft5x06_dev == NULL)
  1703. return 0;
  1704. ft5x06 = dev_get_drvdata(ft5x06_dev);
  1705. if(ft5x06==NULL)
  1706. return 0;
  1707. if(ft5x06_gesture_open == 0)
  1708. return 0;
  1709. ft5x06_write_byte(ft5x06,0xd0,0x00);//let fw close gestrue function
  1710. ft5x06_write_byte(ft5x06,0xd1,0x00);//let fw close gestrue function
  1711. ft5x06_write_byte(ft5x06,0xd2,0x00);//let fw close gestrue function
  1712. printk(KERN_ERR "liyatang gesture close\n");
  1713. ft5x06->in_suspend = false;
  1714. return 1;
  1715. }
  1716. EXPORT_SYMBOL(ft5x06_gesture_close_export);
  1717. #endif
  1718.  
  1719. static struct attribute *ft5x06_attrs[] = {
  1720. &dev_attr_tpfwver.attr,
  1721. &dev_attr_object.attr,
  1722. &dev_attr_dbgdump.attr,
  1723. &dev_attr_updatefw.attr,
  1724. &dev_attr_rawdatashow.attr,
  1725. &dev_attr_diffdatashow.attr,
  1726. &dev_attr_selftest.attr,
  1727. NULL
  1728. };
  1729.  
  1730. static const struct attribute_group ft5x06_attr_group = {
  1731. .attrs = ft5x06_attrs
  1732. };
  1733.  
  1734. #ifdef CONFIG_FTS_GESTURE
  1735. static ssize_t fts_gesture_proc_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
  1736. {
  1737. int cnt= 0;
  1738. char *page = NULL;
  1739. page = kzalloc(FT5X0X_TOUCH_LENGTH, GFP_KERNEL);
  1740. if(ft5x06_gesture_open)
  1741. cnt = sprintf(page, "FT5x06 gesture open\n");
  1742. else
  1743. cnt = sprintf(page, "FT5x06 gesture close\n");
  1744. cnt = simple_read_from_buffer(buf, size, ppos, page, cnt);
  1745. kfree(page);
  1746. return cnt;
  1747. }
  1748.  
  1749. static ssize_t fts_gesture_proc_write(struct file *file, const char __user *buf, size_t size, loff_t *ppos)
  1750. {
  1751. char i;
  1752. struct ft5x06_data *ft5x06 = dev_get_drvdata(ft5x06_dev);
  1753. if(copy_from_user(&i,buf,1))
  1754. {
  1755. return -EFAULT;
  1756. }
  1757. if(ft5x06->in_suspend == false)
  1758. {
  1759. if (i == '1')
  1760. ft5x06_gesture_open = 1;
  1761. else if(i == '0')
  1762. ft5x06_gesture_open = 0;
  1763. else if(i=='2')
  1764. ft5x06_gesture_open_export();
  1765. }
  1766. return size;
  1767. }
  1768. static const struct file_operations fts_gesture_proc_fops= {
  1769. .read = fts_gesture_proc_read,
  1770. .write = fts_gesture_proc_write,
  1771. };
  1772. #endif
  1773.  
  1774. static int ft5x06_power_on(struct ft5x06_data *data, bool on)
  1775. {
  1776. int rc;
  1777.  
  1778. if (!on)
  1779. goto power_off;
  1780.  
  1781. rc = regulator_enable(data->vdd);
  1782. if (rc) {
  1783. dev_err(data->dev,
  1784. "Regulator vdd enable failed rc=%d\n", rc);
  1785. return rc;
  1786. }
  1787.  
  1788. rc = regulator_enable(data->vcc_i2c);
  1789. if (rc) {
  1790. dev_err(data->dev,
  1791. "Regulator vcc_i2c enable failed rc=%d\n", rc);
  1792. regulator_disable(data->vdd);
  1793. }
  1794.  
  1795. return rc;
  1796.  
  1797. power_off:
  1798. rc = regulator_disable(data->vdd);
  1799. if (rc) {
  1800. dev_err(data->dev,
  1801. "Regulator vdd disable failed rc=%d\n", rc);
  1802. return rc;
  1803. }
  1804.  
  1805. rc = regulator_disable(data->vcc_i2c);
  1806. if (rc) {
  1807. dev_err(data->dev,
  1808. "Regulator vcc_i2c disable failed rc=%d\n", rc);
  1809. regulator_enable(data->vdd);
  1810. }
  1811.  
  1812. return rc;
  1813. }
  1814.  
  1815. static int ft5x06_power_init(struct ft5x06_data *data, bool on)
  1816. {
  1817. int rc;
  1818.  
  1819. if (!on)
  1820. goto pwr_deinit;
  1821.  
  1822. data->vdd = regulator_get(data->dev, "vdd");
  1823. if (IS_ERR(data->vdd)) {
  1824. rc = PTR_ERR(data->vdd);
  1825. dev_err(data->dev,
  1826. "Regulator get failed vdd rc=%d\n", rc);
  1827. return rc;
  1828. }
  1829.  
  1830. if (regulator_count_voltages(data->vdd) > 0) {
  1831. rc = regulator_set_voltage(data->vdd, FT_VTG_MIN_UV,
  1832. FT_VTG_MAX_UV);
  1833. if (rc) {
  1834. dev_err(data->dev,
  1835. "Regulator set_vtg failed vdd rc=%d\n", rc);
  1836. goto reg_vdd_put;
  1837. }
  1838. }
  1839.  
  1840. data->vcc_i2c = regulator_get(data->dev, "vcc_i2c");
  1841. if (IS_ERR(data->vcc_i2c)) {
  1842. rc = PTR_ERR(data->vcc_i2c);
  1843. dev_err(data->dev,
  1844. "Regulator get failed vcc_i2c rc=%d\n", rc);
  1845. goto reg_vdd_set_vtg;
  1846. }
  1847.  
  1848. if (regulator_count_voltages(data->vcc_i2c) > 0) {
  1849. rc = regulator_set_voltage(data->vcc_i2c, FT_I2C_VTG_MIN_UV,
  1850. FT_I2C_VTG_MAX_UV);
  1851. if (rc) {
  1852. dev_err(data->dev,
  1853. "Regulator set_vtg failed vcc_i2c rc=%d\n", rc);
  1854. goto reg_vcc_i2c_put;
  1855. }
  1856. }
  1857.  
  1858. return 0;
  1859.  
  1860. reg_vcc_i2c_put:
  1861. regulator_put(data->vcc_i2c);
  1862. reg_vdd_set_vtg:
  1863. if (regulator_count_voltages(data->vdd) > 0)
  1864. regulator_set_voltage(data->vdd, 0, FT_VTG_MAX_UV);
  1865. reg_vdd_put:
  1866. regulator_put(data->vdd);
  1867. return rc;
  1868.  
  1869. pwr_deinit:
  1870. if (regulator_count_voltages(data->vdd) > 0)
  1871. regulator_set_voltage(data->vdd, 0, FT_VTG_MAX_UV);
  1872.  
  1873. regulator_put(data->vdd);
  1874.  
  1875. if (regulator_count_voltages(data->vcc_i2c) > 0)
  1876. regulator_set_voltage(data->vcc_i2c, 0, FT_I2C_VTG_MAX_UV);
  1877.  
  1878. regulator_put(data->vcc_i2c);
  1879. return 0;
  1880. }
  1881.  
  1882. static void ft5x06_dt_dump(struct device *dev,
  1883. struct ft5x06_ts_platform_data *pdata)
  1884. {
  1885. int key_num;
  1886. int i, j;
  1887.  
  1888. pr_info("i2c-pull-up = %d\n", (int)pdata->i2c_pull_up);
  1889. pr_info("reset gpio = %d\n", (int)pdata->reset_gpio);
  1890. pr_info("irq gpio = %d\n", (int)pdata->irq_gpio);
  1891. pr_info("x_max = %d\n", (int)pdata->x_max);
  1892. pr_info("y_max = %d\n", (int)pdata->y_max);
  1893. pr_info("z_max = %d\n", (int)pdata->z_max);
  1894. pr_info("w_max = %d\n", (int)pdata->w_max);
  1895. pr_info("landing_jiffies = %d\n", (int)pdata->landing_jiffies);
  1896. pr_info("landing_threshold = %d\n", (int)pdata->landing_threshold);
  1897. pr_info("staying_threshold = %d\n", (int)pdata->staying_threshold);
  1898. pr_info("tx num = %d\n", pdata->tx_num);
  1899. pr_info("rx num = %d\n", pdata->rx_num);
  1900. pr_info("raw min = %d\n", (int)pdata->raw_min);
  1901. pr_info("raw max = %d\n", (int)pdata->raw_max);
  1902. for (j = 0; j < pdata->cfg_size; j++) {
  1903. key_num = pdata->keypad[j].length;
  1904. pr_info("key_num = %d\n", key_num);
  1905. for (i = 0; i < key_num; i++) {
  1906. pr_info("keymap[%d] = %d\n", i, pdata->keypad[j].keymap[i]);
  1907. pr_info("keypos[%d] = %d\n", i, pdata->keypad[j].key_pos[i]);
  1908. pr_info("key[%d]: %d %d %d %d\n", i,
  1909. pdata->keypad[j].button[i].left,
  1910. pdata->keypad[j].button[i].top,
  1911. pdata->keypad[j].button[i].width,
  1912. pdata->keypad[j].button[i].height);
  1913. }
  1914. }
  1915.  
  1916. pr_info("firmare 0 chip = 0x%x, vendor = 0x%x name = %s\n",
  1917. pdata->firmware[0].chip,
  1918. pdata->firmware[0].vendor,
  1919. pdata->firmware[0].fwname);
  1920. pr_info("firmare 1 chip = 0x%x, vendor = 0x%x name = %s\n",
  1921. pdata->firmware[1].chip,
  1922. pdata->firmware[1].vendor,
  1923. pdata->firmware[1].fwname);
  1924. }
  1925.  
  1926. static int ft5x06_parse_dt(struct device *dev,
  1927. struct ft5x06_ts_platform_data *pdata)
  1928. {
  1929. int rc, i, j;
  1930. struct device_node *np = dev->of_node;
  1931. u32 temp_val, num_buttons, num_fw;
  1932. u32 rect[12];
  1933. u32 keymap[3], keypos[3];
  1934. struct device_node *sub_np;
  1935.  
  1936. pdata->i2c_pull_up = of_property_read_bool(np,
  1937. "ft5x06_i2c,i2c-pull-up");
  1938. /* reset, irq gpio info */
  1939. pdata->reset_gpio = of_get_named_gpio_flags(np, "ft5x06_i2c,reset-gpio",
  1940. 0, &pdata->reset_gpio_flags);
  1941. if (pdata->reset_gpio < 0)
  1942. return pdata->reset_gpio;
  1943.  
  1944. pdata->irq_gpio = of_get_named_gpio_flags(np, "ft5x06_i2c,irq-gpio",
  1945. 0, &pdata->irq_gpio_flags);
  1946. if (pdata->irq_gpio < 0)
  1947. return pdata->irq_gpio;
  1948.  
  1949. rc = of_property_read_u32(np, "ft5x06_i2c,x-max", &pdata->x_max);
  1950. if (rc) {
  1951. dev_err(dev, "can't read x-max\n");
  1952. return rc;
  1953. }
  1954. rc = of_property_read_u32(np, "ft5x06_i2c,y-max", &pdata->y_max);
  1955. if (rc) {
  1956. dev_err(dev, "can't read y-max\n");
  1957. return rc;
  1958. }
  1959. rc = of_property_read_u32(np, "ft5x06_i2c,z-max", &pdata->z_max);
  1960. if (rc) {
  1961. dev_err(dev, "can't read z-max\n");
  1962. return rc;
  1963. }
  1964. rc = of_property_read_u32(np, "ft5x06_i2c,w-max", &pdata->w_max);
  1965. if (rc) {
  1966. dev_err(dev, "can't read w-max\n");
  1967. return rc;
  1968. }
  1969.  
  1970. rc = of_property_read_u32(np, "ft5x06_i2c,landing-jiffies", &temp_val);
  1971. if (rc) {
  1972. dev_err(dev, "can't read landing-jiffies\n");
  1973. return rc;
  1974. } else
  1975. pdata->landing_jiffies = (unsigned long)temp_val;
  1976. rc = of_property_read_u32(np, "ft5x06_i2c,landing-threshold", &pdata->landing_threshold);
  1977. if (rc) {
  1978. dev_err(dev, "can't read landing-threshold\n");
  1979. return rc;
  1980. }
  1981. rc = of_property_read_u32(np, "ft5x06_i2c,staying-threshold", &pdata->staying_threshold);
  1982. if (rc) {
  1983. dev_err(dev, "can't read staying-threshold\n");
  1984. return rc;
  1985. }
  1986.  
  1987. rc = of_property_read_u32(np, "ft5x06_i2c,tx-num", &pdata->tx_num);
  1988. if (rc) {
  1989. dev_err(dev, "can't read tx-num\n");
  1990. return rc;
  1991. }
  1992. rc = of_property_read_u32(np, "ft5x06_i2c,rx-num", &pdata->rx_num);
  1993. if (rc) {
  1994. dev_err(dev, "can't read rx-num\n");
  1995. return rc;
  1996. }
  1997.  
  1998. rc = of_property_read_u32(np, "ft5x06_i2c,raw-min", &temp_val);
  1999. if (rc) {
  2000. dev_err(dev, "can't read raw-min\n");
  2001. return rc;
  2002. } else
  2003. pdata->raw_min = (u16)temp_val;
  2004. rc = of_property_read_u32(np, "ft5x06_i2c,raw-max", &temp_val);
  2005. if (rc) {
  2006. dev_err(dev, "can't read raw-max\n");
  2007. return rc;
  2008. } else
  2009. pdata->raw_max = (u16)temp_val;
  2010.  
  2011. rc = of_property_read_u32(np, "ft5x06_i2c,firmware-array-size", &num_fw);
  2012. if (rc) {
  2013. dev_err(dev, "can't get firmware-array-size\n");
  2014. return rc;
  2015. }
  2016.  
  2017. pr_info("num_fw = %d\n", num_fw);
  2018.  
  2019. pdata->firmware = kmalloc(sizeof(struct ft5x06_firmware_data) * (num_fw + 1),
  2020. GFP_KERNEL);
  2021. if (pdata->firmware == NULL)
  2022. return -ENOMEM;
  2023. pdata->keypad = kmalloc(sizeof(struct ft5x06_keypad_data) * num_fw, GFP_KERNEL);
  2024. if (pdata->keypad == NULL)
  2025. return -ENOMEM;
  2026.  
  2027. pdata->cfg_size = num_fw;
  2028. j = 0;
  2029. for_each_child_of_node(np, sub_np) {
  2030. rc = of_property_read_u32(sub_np, "ft5x06_i2c,key-length", &temp_val);
  2031. if (rc) {
  2032. dev_err(dev, "can't read key-length\n");
  2033. return rc;
  2034. } else
  2035. pdata->keypad[j].length = temp_val;
  2036. num_buttons = pdata->keypad[j].length;
  2037.  
  2038. pdata->keypad[j].keymap = devm_kzalloc(dev,
  2039. sizeof(unsigned int) * num_buttons, GFP_KERNEL);
  2040. if (pdata->keypad[j].keymap == NULL)
  2041. return -ENOMEM;
  2042. pdata->keypad[j].key_pos = devm_kzalloc(dev,
  2043. sizeof(unsigned int) * num_buttons, GFP_KERNEL);
  2044. if (pdata->keypad[j].key_pos == NULL)
  2045. return -ENOMEM;
  2046. pdata->keypad[j].button = devm_kzalloc(dev,
  2047. sizeof(struct ft5x06_rect) * num_buttons, GFP_KERNEL);
  2048. if (pdata->keypad[j].button == NULL)
  2049. return -ENOMEM;
  2050.  
  2051. rc = of_property_read_u32_array(sub_np, "ft5x06_i2c,key-map",
  2052. keymap, num_buttons);
  2053. if (rc) {
  2054. dev_err(dev, "can't get key-map\n");
  2055. return rc;
  2056. }
  2057. rc = of_property_read_u32_array(sub_np, "ft5x06_i2c,key-pos",
  2058. keypos, num_buttons);
  2059. if (rc) {
  2060. dev_err(dev, "can't get key-pos\n");
  2061. return rc;
  2062. }
  2063. rc = of_property_read_u32_array(sub_np, "ft5x06_i2c,key-menu", rect, 4);
  2064. if (rc) {
  2065. dev_err(dev, "can't get key-menu\n");
  2066. return rc;
  2067. }
  2068. rc = of_property_read_u32_array(sub_np, "ft5x06_i2c,key-home", rect + 4, 4);
  2069. if (rc) {
  2070. dev_err(dev, "can't get key-home\n");
  2071. return rc;
  2072. }
  2073. rc = of_property_read_u32_array(sub_np, "ft5x06_i2c,key-back", rect + 8, 4);
  2074. if (rc) {
  2075. dev_err(dev, "can't get key-back\n");
  2076. return rc;
  2077. }
  2078.  
  2079. for (i = 0; i < num_buttons; i++) {
  2080. pdata->keypad[j].keymap[i] = keymap[i];
  2081. pdata->keypad[j].key_pos[i] = keypos[i];
  2082. pdata->keypad[j].button[i].left = rect[i*4];
  2083. pdata->keypad[j].button[i].top = rect[i*4+1];
  2084. pdata->keypad[j].button[i].width = rect[i*4+2];
  2085. pdata->keypad[j].button[i].height = rect[i*4+3];
  2086. }
  2087.  
  2088. rc = of_property_read_u32(sub_np, "ft5x06_i2c,chip", &temp_val);
  2089. if (rc) {
  2090. dev_err(dev, "can't get chip id\n");
  2091. return rc;
  2092. } else
  2093. pdata->firmware[j].chip = (u8)temp_val;
  2094. pdata->keypad[j].chip = (u8)temp_val;
  2095. rc = of_property_read_u32(sub_np, "ft5x06_i2c,vendor", &temp_val);
  2096. if (rc) {
  2097. dev_err(dev, "can't get vendor id\n");
  2098. return rc;
  2099. } else
  2100. pdata->firmware[j].vendor = (u8)temp_val;
  2101. rc = of_property_read_string(sub_np, "ft5x06_i2c,fw-name",
  2102. &pdata->firmware[j].fwname);
  2103. if (rc && (rc != -EINVAL)) {
  2104. dev_err(dev, "can't read fw-name\n");
  2105. return rc;
  2106. }
  2107. pdata->firmware[j].size = 0;
  2108. j ++;
  2109. }
  2110.  
  2111. ft5x06_dt_dump(dev, pdata);
  2112.  
  2113. return 0;
  2114. }
  2115.  
  2116. struct ft5x06_data *ft5x06_probe(struct device *dev,
  2117. const struct ft5x06_bus_ops *bops)
  2118. {
  2119. int error;
  2120. struct ft5x06_data *ft5x06;
  2121. struct ft5x06_ts_platform_data *pdata;
  2122.  
  2123. /* check input argument */
  2124. if (dev->of_node) {
  2125. pdata = devm_kzalloc(dev,
  2126. sizeof(struct ft5x06_ts_platform_data), GFP_KERNEL);
  2127. if (!pdata) {
  2128. dev_err(dev, "Failed to allocate memory!\n");
  2129. return ERR_PTR(-ENOMEM);
  2130. }
  2131.  
  2132. error = ft5x06_parse_dt(dev, pdata);
  2133. if (error)
  2134. goto err;
  2135. } else
  2136. pdata = dev->platform_data;
  2137. if (pdata == NULL) {
  2138. dev_err(dev, "platform data doesn't exist\n");
  2139. error = -EINVAL;
  2140. goto err;
  2141. }
  2142.  
  2143. /* alloc and init data object */
  2144. ft5x06 = kzalloc(sizeof(struct ft5x06_data), GFP_KERNEL);
  2145. if (ft5x06 == NULL) {
  2146. dev_err(dev, "fail to allocate data object\n");
  2147. error = -ENOMEM;
  2148. goto err;
  2149. }
  2150. ft5x06->dev = dev;
  2151. ft5x06->irq = gpio_to_irq(pdata->irq_gpio);
  2152. ft5x06->bops = bops;
  2153. if (dev->of_node)
  2154. ft5x06->dev->platform_data = pdata;
  2155.  
  2156. /* init platform stuff */
  2157. if (pdata->power_init) {
  2158. error = pdata->power_init(true);
  2159. if (error) {
  2160. dev_err(dev, "fail to power_init platform (pdata)\n");
  2161. goto err_free_data;
  2162. }
  2163. } else {
  2164. error = ft5x06_power_init(ft5x06, true);
  2165. if (error) {
  2166. dev_err(dev, "fail to power_init platform\n");
  2167. goto err_free_data;
  2168. }
  2169. }
  2170.  
  2171. if (pdata->power_on) {
  2172. error = pdata->power_on(true);
  2173. if (error) {
  2174. dev_err(dev, "fail to power on (pdata)!\n");
  2175. goto err_power_init;
  2176. }
  2177. } else {
  2178. error = ft5x06_power_on(ft5x06, true);
  2179. if (error) {
  2180. dev_err(dev, "fail to power on\n");
  2181. goto err_power_init;
  2182. }
  2183. }
  2184.  
  2185. if (gpio_is_valid(pdata->irq_gpio)) {
  2186. error = gpio_request(pdata->irq_gpio, "ft5x06_irq_gpio");
  2187. if (error < 0) {
  2188. dev_err(dev, "irq gpio request failed");
  2189. goto err_power;
  2190. }
  2191. error = gpio_direction_input(pdata->irq_gpio);
  2192. if (error < 0) {
  2193. dev_err(dev, "set_direction for irq gpio failed\n");
  2194. goto free_irq_gpio;
  2195. }
  2196. }
  2197.  
  2198. if (gpio_is_valid(pdata->reset_gpio)) {
  2199. error = gpio_request(pdata->reset_gpio, "ft5x06_reset_gpio");
  2200. if (error < 0) {
  2201. dev_err(dev, "irq gpio request failed");
  2202. goto free_irq_gpio;
  2203. }
  2204. error = gpio_direction_output(pdata->reset_gpio, 0);
  2205. if (error < 0) {
  2206. dev_err(dev, "set_direction for irq gpio failed\n");
  2207. goto free_reset_gpio;
  2208. }
  2209. msleep(100);
  2210. gpio_set_value_cansleep(pdata->reset_gpio, 1);
  2211. }
  2212.  
  2213. msleep(100);
  2214. mutex_init(&ft5x06->mutex);
  2215.  
  2216. /* alloc and init input device */
  2217. ft5x06->input = input_allocate_device();
  2218. if (ft5x06->input == NULL) {
  2219. dev_err(dev, "fail to allocate input device\n");
  2220. error = -ENOMEM;
  2221. goto free_reset_gpio;
  2222. }
  2223.  
  2224. ft5x06->tch_data = devm_kzalloc(ft5x06->dev,
  2225. FT5X0X_MAX_FINGER * FT5X0X_TOUCH_LENGTH, GFP_KERNEL);
  2226.  
  2227. input_set_drvdata(ft5x06->input, ft5x06);
  2228. ft5x06->input->name = "ft5x06";
  2229. ft5x06->input->id.bustype = bops->bustype;
  2230. ft5x06->input->id.vendor = 0x4654; /* FocalTech */
  2231. ft5x06->input->id.product = 0x5000; /* ft5x0x */
  2232. ft5x06->input->id.version = 0x0100; /* 1.0 */
  2233. ft5x06->input->dev.parent = dev;
  2234.  
  2235. /* init touch parameter */
  2236. #ifdef CONFIG_TOUCHSCREEN_FT5X06_TYPEB
  2237. input_mt_init_slots(ft5x06->input, FT5X0X_MAX_FINGER);
  2238. #endif
  2239. set_bit(ABS_MT_TOUCH_MAJOR, ft5x06->input->absbit);
  2240. set_bit(ABS_MT_POSITION_X, ft5x06->input->absbit);
  2241. set_bit(ABS_MT_POSITION_Y, ft5x06->input->absbit);
  2242. set_bit(ABS_MT_WIDTH_MAJOR, ft5x06->input->absbit);
  2243. #ifdef CONFIG_FTS_GESTURE
  2244. set_bit(116, ft5x06->input->keybit);
  2245. #endif
  2246. set_bit(INPUT_PROP_DIRECT, ft5x06->input->propbit);
  2247.  
  2248. input_set_abs_params(ft5x06->input,
  2249. ABS_MT_POSITION_X, 0, pdata->x_max, 0, 0);
  2250. input_set_abs_params(ft5x06->input,
  2251. ABS_MT_POSITION_Y, 0, pdata->y_max, 0, 0);
  2252. input_set_abs_params(ft5x06->input,
  2253. ABS_MT_TOUCH_MAJOR, 0, pdata->z_max, 0, 0);
  2254. input_set_abs_params(ft5x06->input,
  2255. ABS_MT_WIDTH_MAJOR, 0, pdata->w_max, 0, 0);
  2256. input_set_abs_params(ft5x06->input,
  2257. ABS_MT_TRACKING_ID, 0, 10, 0, 0);
  2258.  
  2259. set_bit(EV_KEY, ft5x06->input->evbit);
  2260. set_bit(EV_ABS, ft5x06->input->evbit);
  2261.  
  2262. error = ft5x06_read_byte(ft5x06, FT5X0X_REG_CHIP_ID, &ft5x06->chip_id);
  2263. if (error) {
  2264. dev_err(dev, "failed to read chip id\n");
  2265. goto err_free_input;
  2266. }
  2267.  
  2268. error = ft5x06_load_firmware(ft5x06, pdata->firmware, NULL);
  2269. if (error) {
  2270. dev_err(dev, "fail to load firmware\n");
  2271. goto err_free_input;
  2272. }
  2273.  
  2274. ft5x06->input->enabled = true;
  2275. /* register input device */
  2276. error = input_register_device(ft5x06->input);
  2277. if (error) {
  2278. dev_err(dev, "fail to register input device\n");
  2279. goto err_free_input;
  2280. }
  2281.  
  2282. ft5x06->input->phys =
  2283. kobject_get_path(&ft5x06->input->dev.kobj, GFP_KERNEL);
  2284. if (ft5x06->input->phys == NULL) {
  2285. dev_err(dev, "fail to get input device path\n");
  2286. error = -ENOMEM;
  2287. goto err_unregister_input;
  2288. }
  2289.  
  2290. /* start interrupt process */
  2291. error = request_threaded_irq(ft5x06->irq, NULL, ft5x06_interrupt,
  2292. IRQF_TRIGGER_FALLING, "ft5x06", ft5x06);
  2293. if (error) {
  2294. dev_err(dev, "fail to request interrupt\n");
  2295. goto err_free_phys;
  2296. }
  2297.  
  2298. /* export sysfs entries */
  2299. ft5x06->vkeys_dir = kobject_create_and_add("board_properties", NULL);
  2300. if (ft5x06->vkeys_dir == NULL) {
  2301. error = -ENOMEM;
  2302. dev_err(dev, "fail to create board_properties entry\n");
  2303. goto err_free_irq;
  2304. }
  2305.  
  2306. sysfs_attr_init(&ft5x06->vkeys_attr.attr);
  2307. ft5x06->vkeys_attr.attr.name = "virtualkeys.ft5x06";
  2308. ft5x06->vkeys_attr.attr.mode = (S_IRUSR|S_IRGRP|S_IROTH);
  2309. ft5x06->vkeys_attr.show = ft5x06_vkeys_show;
  2310.  
  2311. error = sysfs_create_file(ft5x06->vkeys_dir, &ft5x06->vkeys_attr.attr);
  2312. if (error) {
  2313. dev_err(dev, "fail to create virtualkeys entry\n");
  2314. goto err_put_vkeys;
  2315. }
  2316.  
  2317. #ifdef CONFIG_FTS_GESTURE
  2318. enable_irq_wake(ft5x06->irq);
  2319. gesture_proc = proc_create_data(FTS_GESTURE_PROC_FILE, 0666, NULL, &fts_gesture_proc_fops, NULL);
  2320. if (IS_ERR_OR_NULL(gesture_proc))
  2321. printk("create_proc_entry gesture_proc failed\n");
  2322. #endif
  2323.  
  2324. error = sysfs_create_group(&dev->kobj, &ft5x06_attr_group);
  2325. if (error) {
  2326. dev_err(dev, "fail to export sysfs entires\n");
  2327. goto err_put_vkeys;
  2328. }
  2329.  
  2330. #if defined(CONFIG_FB)
  2331. ft5x06->fb_notif.notifier_call = fb_notifier_callback;
  2332.  
  2333. error = fb_register_client(&ft5x06->fb_notif);
  2334.  
  2335. if (error)
  2336. dev_err(dev, "Unable to register fb_notifier: %d\n",
  2337. error);
  2338. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  2339. ft5x06->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN+1;
  2340. ft5x06->early_suspend.suspend = ft5x06_early_suspend;
  2341. ft5x06->early_suspend.resume = ft5x06_early_resume;
  2342. register_early_suspend(&ft5x06->early_suspend);
  2343. #endif
  2344.  
  2345. ft5x06->power_supply_notifier.notifier_call = ft5x06_power_supply_event;
  2346. register_power_supply_notifier(&ft5x06->power_supply_notifier);
  2347.  
  2348. INIT_DELAYED_WORK(&ft5x06->noise_filter_delayed_work,
  2349. ft5x06_noise_filter_delayed_work);
  2350. return ft5x06;
  2351.  
  2352. err_put_vkeys:
  2353. kobject_put(ft5x06->vkeys_dir);
  2354. err_free_irq:
  2355. free_irq(ft5x06->irq, ft5x06);
  2356. err_free_phys:
  2357. kfree(ft5x06->input->phys);
  2358. err_unregister_input:
  2359. input_unregister_device(ft5x06->input);
  2360. ft5x06->input = NULL;
  2361. err_free_input:
  2362. input_free_device(ft5x06->input);
  2363. free_reset_gpio:
  2364. if (gpio_is_valid(pdata->reset_gpio))
  2365. gpio_free(pdata->reset_gpio);
  2366. free_irq_gpio:
  2367. if (gpio_is_valid(pdata->irq_gpio))
  2368. gpio_free(pdata->irq_gpio);
  2369. err_power:
  2370. if (pdata->power_on)
  2371. pdata->power_on(false);
  2372. //else
  2373. // ft5x06_power_on(ft5x06, false);
  2374. err_power_init:
  2375. if (pdata->power_init)
  2376. pdata->power_init(false);
  2377. //else
  2378. // ft5x06_power_init(ft5x06, false);
  2379. err_free_data:
  2380. kfree(ft5x06);
  2381. err:
  2382. return ERR_PTR(error);
  2383. }
  2384. EXPORT_SYMBOL_GPL(ft5x06_probe);
  2385.  
  2386. void ft5x06_remove(struct ft5x06_data *ft5x06)
  2387. {
  2388. struct ft5x06_ts_platform_data *pdata = ft5x06->dev->platform_data;
  2389.  
  2390. cancel_delayed_work_sync(&ft5x06->noise_filter_delayed_work);
  2391. unregister_power_supply_notifier(&ft5x06->power_supply_notifier);
  2392. #ifdef CONFIG_HAS_EARLYSUSPEND
  2393. unregister_early_suspend(&ft5x06->early_suspend);
  2394. #endif
  2395. sysfs_remove_group(&ft5x06->dev->kobj, &ft5x06_attr_group);
  2396. kobject_put(ft5x06->vkeys_dir);
  2397. free_irq(ft5x06->irq, ft5x06);
  2398. kfree(ft5x06->input->phys);
  2399. input_unregister_device(ft5x06->input);
  2400. kfree(ft5x06);
  2401. if (gpio_is_valid(pdata->reset_gpio))
  2402. gpio_free(pdata->reset_gpio);
  2403. if (gpio_is_valid(pdata->irq_gpio))
  2404. gpio_free(pdata->irq_gpio);
  2405. if (pdata->power_on)
  2406. pdata->power_on(false);
  2407. if (pdata->power_init)
  2408. pdata->power_init(false);
  2409. }
  2410. EXPORT_SYMBOL_GPL(ft5x06_remove);
  2411.  
  2412. MODULE_AUTHOR("Zhang Bo <zhangbo_a@xiaomi.com>");
  2413. MODULE_DESCRIPTION("ft5x0x touchscreen input driver");
  2414. MODULE_LICENSE("GPL");
RAW Paste Data