PageRenderTime 4977ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 1ms

/drivers/input/touchscreen/mxt1664s.c

http://github.com/sakuramilk/sc02c_kernel_ics
C | 3402 lines | 2702 code | 519 blank | 181 comment | 459 complexity | 25c51b4c04a5187fb284aa0ce1357ade MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (C) 2010, Samsung Electronics Co. Ltd. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/input.h>
  19. #include <linux/input/mt.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/i2c.h>
  22. #include <linux/delay.h>
  23. #include <linux/earlysuspend.h>
  24. #include <linux/slab.h>
  25. #include <linux/gpio.h>
  26. #include <linux/i2c/mxt1664s.h>
  27. #include <asm/unaligned.h>
  28. #include <linux/firmware.h>
  29. #include <linux/string.h>
  30. #define OBJECT_TABLE_START_ADDRESS 7
  31. #define OBJECT_TABLE_ELEMENT_SIZE 6
  32. #define CMD_RESET_OFFSET 0
  33. #define CMD_BACKUP_OFFSET 1
  34. #define CMD_CALIBRATE_OFFSET 2
  35. #define CMD_REPORTATLL_OFFSET 3
  36. #define CMD_DEBUG_CTRL_OFFSET 4
  37. #define CMD_DIAGNOSTIC_OFFSET 5
  38. #define DETECT_MSG_MASK 0x80
  39. #define PRESS_MSG_MASK 0x40
  40. #define RELEASE_MSG_MASK 0x20
  41. #define MOVE_MSG_MASK 0x10
  42. #define AMPLITUDE_MSG_MASK 0x04
  43. #define SUPPRESS_MSG_MASK 0x02
  44. /* Slave addresses */
  45. /* need to check + */
  46. #define MXT_APP_LOW 0x4a
  47. #define MXT_APP_HIGH 0x4d
  48. #define MXT_BOOT_LOW 0x26
  49. #define MXT_BOOT_HIGH 0x27
  50. /* need to check - */
  51. /* FIRMWARE NAME */
  52. #define MXT_FW_NAME "tsp_atmel/mXT1664S.fw"
  53. #define MXT_BOOT_VALUE 0xa5
  54. #define MXT_BACKUP_VALUE 0x55
  55. /* Bootloader mode status */
  56. #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */
  57. #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */
  58. #define MXT_FRAME_CRC_CHECK 0x02
  59. #define MXT_FRAME_CRC_FAIL 0x03
  60. #define MXT_FRAME_CRC_PASS 0x04
  61. #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */
  62. #define MXT_BOOT_STATUS_MASK 0x3f
  63. /* Command to unlock bootloader */
  64. #define MXT_UNLOCK_CMD_MSB 0xaa
  65. #define MXT_UNLOCK_CMD_LSB 0xdc
  66. #define ID_BLOCK_SIZE 7
  67. #define MXT_STATE_INACTIVE -1
  68. #define MXT_STATE_RELEASE 0
  69. #define MXT_STATE_PRESS 1
  70. #define MXT_STATE_MOVE 2
  71. #define MAX_USING_FINGER_NUM 10
  72. /* Feature */
  73. /*#######################################*/
  74. #define TOUCH_BOOSTER 1
  75. #define USE_SUMSIZE 0
  76. #define SYSFS 1
  77. #define FOR_BRINGUP 1
  78. #define UPDATE_ON_PROBE 1
  79. #define READ_FW_FROM_HEADER 0
  80. #define FOR_DEBUGGING_TEST_DOWNLOADFW_BIN 0
  81. #define ITDEV 1
  82. #define SHOW_COORDINATE 1
  83. #define DEBUG_INFO 0
  84. /*#######################################*/
  85. /* touch booster */
  86. #if TOUCH_BOOSTER
  87. #include <mach/cpufreq.h>
  88. #define TOUCH_BOOSTER_TIME 3000
  89. #define TOUCH_BOOSTER_LIMIT_CLK 500000
  90. static bool tsp_press_status;
  91. static bool touch_cpu_lock_status;
  92. static int cpu_lv = -1;
  93. #endif
  94. /* use sumsize in T57 register */
  95. #if USE_SUMSIZE
  96. #define MAX_SUMSIZE 40
  97. #define MAX_SINGLE_SUMSIZE 100
  98. static uint16_t sum_size;
  99. #endif
  100. /* Firmware */
  101. #if READ_FW_FROM_HEADER
  102. static u8 firmware_mXT[] = {
  103. #include "mXT1664S-V0.5.2_.h"
  104. };
  105. #endif
  106. #if ITDEV
  107. static int driver_paused;
  108. static int debug_enabled;
  109. #endif
  110. /* add for protection code */
  111. /*#######################################*/
  112. /*#######################################*/
  113. /* variable related protection code */
  114. /*#######################################*/
  115. static int treat_median_error_status;
  116. /*#######################################*/
  117. struct object_t {
  118. u8 object_type;
  119. u16 i2c_address;
  120. u8 size;
  121. u8 instances;
  122. u8 num_report_ids;
  123. } __packed;
  124. struct finger_info {
  125. s16 x;
  126. s16 y;
  127. s16 z;
  128. u16 w;
  129. s8 state;
  130. int16_t component;
  131. u16 mcount; /*add for debug*/
  132. };
  133. struct report_id_map_t {
  134. u8 object_type; /*!< Object type. */
  135. u8 instance; /*!< Instance number. */
  136. };
  137. u8 max_report_id;
  138. struct report_id_map_t *rid_map;
  139. static bool rid_map_alloc;
  140. struct mxt_data {
  141. struct i2c_client *client;
  142. struct input_dev *input_dev;
  143. struct mxt_platform_data *pdata;
  144. struct early_suspend early_suspend;
  145. u8 family_id;
  146. u32 finger_mask;
  147. int gpio_read_done;
  148. struct object_t *objects;
  149. u8 objects_len;
  150. u8 tsp_version;
  151. u8 tsp_build;
  152. u8 tsp_variant;
  153. u8 finger_type;
  154. u16 msg_proc;
  155. u16 cmd_proc;
  156. u16 msg_object_size;
  157. u32 x_dropbits:2;
  158. u32 y_dropbits:2;
  159. u8 tchthr_batt;
  160. u8 tchthr_charging;
  161. u8 calcfg_batt;
  162. u8 calcfg_charging;
  163. const u8 *t48_config_batt;
  164. const u8 *t48_config_chrg;
  165. #if TOUCH_BOOSTER
  166. struct delayed_work dvfs_dwork;
  167. #endif
  168. void (*power_on)(void);
  169. void (*power_off)(void);
  170. void (*register_cb)(void *);
  171. void (*read_ta_status)(bool *);
  172. int num_fingers;
  173. #if ITDEV
  174. u16 last_read_addr;
  175. u16 msg_proc_addr;
  176. #endif
  177. struct finger_info fingers[];
  178. };
  179. struct mxt_data *copy_data;
  180. int touch_is_pressed;
  181. EXPORT_SYMBOL(touch_is_pressed);
  182. static int mxt_enabled;
  183. static bool g_debug_switch;
  184. static u8 threshold;
  185. static int firm_status_data;
  186. static u8 firmware_latest[] = {0x5, 0x2}; /* version, build_version */
  187. #if DEBUG_INFO
  188. static u8 *object_type_name[60] = {
  189. /* [0] = "Reserved", */
  190. /* [2] = "T2 - Obsolete", */
  191. /* [3] = "T3 - Obsolete", */
  192. [5] = "GEN_MESSAGEPROCESSOR_T5",
  193. [6] = "GEN_COMMANDPROCESSOR_T6",
  194. [7] = "GEN_POWERCONFIG_T7",
  195. [8] = "GEN_ACQUIRECONFIG_T8",
  196. [9] = "TOUCH_MULTITOUCHSCREEN_T9",
  197. [15] = "TOUCH_KEYARRAY_T15",
  198. [18] = "SPT_COMCONFIG_T18",
  199. /* [22] = "PROCG_NOISESUPPRESSION_T22",*/
  200. /* [23] = "TOUCH_PROXIMITY_T23",*/
  201. /* [24] = "PROCI_ONETOUCHGESTUREPROCESSOR_T24",*/
  202. [25] = "SPT_SELFTEST_T25",
  203. /* [26] = "T26 - Obsolete",*/
  204. /* [27] = "PROCI_TWOTOUCHGESTUREPROCESSOR_T27",*/
  205. /* [28] = "SPT_CTECONFIG_T28",*/
  206. [37] = "DEBUG_DIAGNOSTICS_T37",
  207. [38] = "USER_DATA_T38",
  208. [40] = "PROCI_GRIPSUPPRESSION_T40",
  209. [42] = "PROCI_TOUCHSUPPRESSION_T42",
  210. [43] = "SPT_DIGITIZER_T43",
  211. [46] = "SPT_CTECONFIG_T46",
  212. [48] = "PROCG_NOISESUPPRESSION_T48",
  213. [56] = "PROCI_SHIELDLESS_T56",
  214. [57] = "SPT_GENERICDATA_T57",
  215. };
  216. #endif
  217. /* declare function proto type */
  218. static void mxt_ta_probe(int ta_status);
  219. static void report_input_data(struct mxt_data *data);
  220. static int read_mem(struct mxt_data *data, u16 reg, u8 len, u8 *buf)
  221. {
  222. int ret;
  223. u16 le_reg = cpu_to_le16(reg);
  224. struct i2c_msg msg[2] = {
  225. {
  226. .addr = data->client->addr,
  227. .flags = 0,
  228. .len = 2,
  229. .buf = (u8 *)&le_reg,
  230. },
  231. {
  232. .addr = data->client->addr,
  233. .flags = I2C_M_RD,
  234. .len = len,
  235. .buf = buf,
  236. },
  237. };
  238. ret = i2c_transfer(data->client->adapter, msg, 2);
  239. if (ret < 0) {
  240. pr_err("i2c failed ret = %d\n", ret);
  241. return ret;
  242. }
  243. return ret == 2 ? 0 : -EIO;
  244. }
  245. static int write_mem(struct mxt_data *data, u16 reg, u8 len, const u8 *buf)
  246. {
  247. int ret;
  248. u8 tmp[len + 2];
  249. put_unaligned_le16(cpu_to_le16(reg), tmp);
  250. memcpy(tmp + 2, buf, len);
  251. ret = i2c_master_send(data->client, tmp, sizeof(tmp));
  252. if (ret < 0)
  253. return ret;
  254. return ret == sizeof(tmp) ? 0 : -EIO;
  255. }
  256. static int __devinit mxt_reset(struct mxt_data *data)
  257. {
  258. u8 buf = 1u;
  259. return write_mem(data, data->cmd_proc + CMD_RESET_OFFSET, 1, &buf);
  260. }
  261. static int __devinit mxt_backup(struct mxt_data *data)
  262. {
  263. u8 buf = 0x55u;
  264. return write_mem(data, data->cmd_proc + CMD_BACKUP_OFFSET, 1, &buf);
  265. }
  266. static int get_object_info(struct mxt_data *data, u8 object_type, u16 *size,
  267. u16 *address)
  268. {
  269. int i;
  270. for (i = 0; i < data->objects_len; i++) {
  271. if (data->objects[i].object_type == object_type) {
  272. *size = data->objects[i].size + 1;
  273. *address = data->objects[i].i2c_address;
  274. return 0;
  275. }
  276. }
  277. return -ENODEV;
  278. }
  279. static int write_config(struct mxt_data *data, u8 type, const u8 *cfg)
  280. {
  281. int ret;
  282. u16 address = 0;
  283. u16 size = 0;
  284. ret = get_object_info(data, type, &size, &address);
  285. if (size == 0 && address == 0)
  286. return 0;
  287. else
  288. return write_mem(data, address, size, cfg);
  289. }
  290. static int check_instance(struct mxt_data *data, u8 object_type)
  291. {
  292. int i;
  293. for (i = 0; i < data->objects_len; i++) {
  294. if (data->objects[i].object_type == object_type)
  295. return data->objects[i].instances;
  296. }
  297. return 0;
  298. }
  299. static int init_write_config(struct mxt_data *data, u8 type, const u8 *cfg)
  300. {
  301. int ret;
  302. u16 address = 0;
  303. u16 size = 0;
  304. u8 *temp;
  305. ret = get_object_info(data, type, &size, &address);
  306. if ((size == 0) || (address == 0)) {
  307. pr_err("%s error object_type(%d)\n", __func__, type);
  308. return -ENODEV;
  309. }
  310. ret = write_mem(data, address, size, cfg);
  311. if (check_instance(data, type)) {
  312. #if DEBUG_INFO
  313. pr_info("exist instance1 object (%d)\n", type);
  314. #endif
  315. temp = kmalloc(size * sizeof(u8), GFP_KERNEL);
  316. memset(temp, 0, size);
  317. ret |= write_mem(data, address+size, size, temp);
  318. kfree(temp);
  319. }
  320. return ret;
  321. }
  322. static int change_config(struct mxt_data *data,
  323. u16 reg, u8 offeset, u8 change_value)
  324. {
  325. u8 value = 0;
  326. value = change_value;
  327. return write_mem(data, reg+offeset, 1, &value);
  328. }
  329. static u32 __devinit crc24(u32 crc, u8 byte1, u8 byte2)
  330. {
  331. static const u32 crcpoly = 0x80001B;
  332. u32 res;
  333. u16 data_word;
  334. data_word = (((u16)byte2) << 8) | byte1;
  335. res = (crc << 1) ^ (u32)data_word;
  336. if (res & 0x1000000)
  337. res ^= crcpoly;
  338. return res;
  339. }
  340. static int __devinit calculate_infoblock_crc(struct mxt_data *data,
  341. u32 *crc_pointer)
  342. {
  343. u32 crc = 0;
  344. u8 mem[7 + data->objects_len * 6];
  345. int status;
  346. int i;
  347. status = read_mem(data, 0, sizeof(mem), mem);
  348. if (status)
  349. return status;
  350. for (i = 0; i < sizeof(mem) - 1; i += 2)
  351. crc = crc24(crc, mem[i], mem[i + 1]);
  352. *crc_pointer = crc24(crc, mem[i], 0) & 0x00FFFFFF;
  353. return 0;
  354. }
  355. uint8_t calibrate_chip_e(void)
  356. {
  357. u8 cal_data = 1;
  358. int ret = 0;
  359. /* send calibration command to the chip */
  360. ret = write_mem(copy_data,
  361. copy_data->cmd_proc + CMD_CALIBRATE_OFFSET,
  362. 1, &cal_data);
  363. /* set flag for calibration lockup
  364. recovery if cal command was successful */
  365. if (!ret)
  366. pr_info("calibration success!!!\n");
  367. return ret;
  368. }
  369. static void treat_error_status(void)
  370. {
  371. bool ta_status = 0;
  372. u16 size;
  373. u16 obj_address = 0;
  374. int error = 0;
  375. struct mxt_data *data = copy_data;
  376. data->read_ta_status(&ta_status);
  377. if (treat_median_error_status) {
  378. pr_err("Error status already treated\n");
  379. return;
  380. } else
  381. treat_median_error_status = 1;
  382. pr_info("Error status TA is[%d]\n", ta_status);
  383. if (ta_status) {
  384. #if !(FOR_BRINGUP)
  385. get_object_info(data,
  386. GEN_POWERCONFIG_T7, &size, &obj_address);
  387. /* 1:ACTVACQINT */
  388. error = change_config(data, obj_address, 1, 255);
  389. get_object_info(data,
  390. GEN_ACQUISITIONCONFIG_T8, &size, &obj_address);
  391. /* 0:CHRGTIME */
  392. error |= change_config(data, obj_address, 0, 64);
  393. /* 8:ATCHFRCCALTHR*/
  394. error |= change_config(data, obj_address, 8, 50);
  395. /* 9:ATCHFRCCALRATIO*/
  396. error |= change_config(data, obj_address, 9, 0);
  397. get_object_info(data,
  398. PROCI_TOUCHSUPPRESSION_T42, &size, &obj_address);
  399. /* 0:CTRL */
  400. error |= change_config(data, obj_address, 0, 3);
  401. get_object_info(data,
  402. SPT_CTECONFIG_T46, &size, &obj_address);
  403. /* 2:IDLESYNCSPERX */
  404. error |= change_config(data, obj_address, 2, 48);
  405. /* 3:ACTVSYNCSPERX */
  406. error |= change_config(data, obj_address, 3, 48);
  407. get_object_info(data,
  408. PROCG_NOISESUPPRESSION_T48, &size, &obj_address);
  409. /* 2:CALCFG */
  410. error |= change_config(data, obj_address, 2, 114);
  411. /* 3:BASEFREQ */
  412. error |= change_config(data, obj_address, 3, 15);
  413. /* 8:MFFREQ[0] */
  414. error |= change_config(data, obj_address, 8, 3);
  415. /* 9:MFFREQ[1] */
  416. error |= change_config(data, obj_address, 9, 5);
  417. /* 10:NLGAIN*/
  418. error |= change_config(data, obj_address, 10, 96);
  419. /* 11:NLTHR*/
  420. error |= change_config(data, obj_address, 11, 30);
  421. /* 17:GCMAXADCSPERX */
  422. error |= change_config(data, obj_address, 17, 100);
  423. /* 34:BLEN[0] */
  424. error |= change_config(data, obj_address, 34, 80);
  425. /* 35:TCHTHR[0] */
  426. error |= change_config(data, obj_address, 35, 40);
  427. /* 36:TCHDI[0] */
  428. error |= change_config(data, obj_address, 36, 2);
  429. /* 39:MOVFILTER[0] */
  430. error |= change_config(data, obj_address, 39, 65);
  431. /* 41:MRGHYST[0] */
  432. error |= change_config(data, obj_address, 41, 40);
  433. /* 42:MRGTHR[0] */
  434. error |= change_config(data, obj_address, 42, 50);
  435. /* 43:XLOCLIP[0] */
  436. error |= change_config(data, obj_address, 43, 5);
  437. /* 44:XHICLIP[0] */
  438. error |= change_config(data, obj_address, 44, 5);
  439. /* 51:JUMPLIMIT[0] */
  440. error |= change_config(data, obj_address, 51, 25);
  441. /* 52:TCHHYST[0] */
  442. error |= change_config(data, obj_address, 52, 15);
  443. #endif
  444. if (error < 0)
  445. pr_err("failed to write error status\n");
  446. } else {
  447. #if !(FOR_BRINGUP)
  448. get_object_info(data,
  449. GEN_POWERCONFIG_T7, &size, &obj_address);
  450. /* 1:ACTVACQINT */
  451. error = change_config(data, obj_address, 1, 255);
  452. get_object_info(data,
  453. GEN_ACQUISITIONCONFIG_T8, &size, &obj_address);
  454. /* 0:CHRGTIME */
  455. error |= change_config(data, obj_address, 0, 64);
  456. /* 8:ATCHFRCCALTHR*/
  457. error |= change_config(data, obj_address, 8, 50);
  458. /* 9:ATCHFRCCALRATIO*/
  459. error |= change_config(data, obj_address, 9, 0);
  460. get_object_info(data,
  461. TOUCH_MULTITOUCHSCREEN_T9, &size, &obj_address);
  462. /* 31:TCHHYST */
  463. error |= change_config(data, obj_address, 31, 15);
  464. get_object_info(data,
  465. PROCI_TOUCHSUPPRESSION_T42, &size, &obj_address);
  466. /* 0:CTRL */
  467. error |= change_config(data, obj_address, 0, 3);
  468. get_object_info(data,
  469. SPT_CTECONFIG_T46, &size, &obj_address);
  470. /* 2:IDLESYNCSPERX */
  471. error |= change_config(data, obj_address, 2, 48);
  472. /* 3:ACTVSYNCSPERX */
  473. error |= change_config(data, obj_address, 3, 48);
  474. get_object_info(data,
  475. PROCG_NOISESUPPRESSION_T48, &size, &obj_address);
  476. /* 2:CALCFG */
  477. error |= change_config(data, obj_address, 2, 242);
  478. /* 3:BASEFREQ */
  479. error |= change_config(data, obj_address, 3, 15);
  480. /* 8:MFFREQ[0] */
  481. error |= change_config(data, obj_address, 8, 3);
  482. /* 9:MFFREQ[1] */
  483. error |= change_config(data, obj_address, 9, 5);
  484. /* 10:NLGAIN*/
  485. error |= change_config(data, obj_address, 10, 112);
  486. /* 11:NLTHR*/
  487. error |= change_config(data, obj_address, 11, 25);
  488. /* 17:GCMAXADCSPERX */
  489. error |= change_config(data, obj_address, 17, 100);
  490. /* 34:BLEN[0] */
  491. error |= change_config(data, obj_address, 34, 112);
  492. /* 35:TCHTHR[0] */
  493. error |= change_config(data, obj_address, 35, 40);
  494. /* 41:MRGHYST[0] */
  495. error |= change_config(data, obj_address, 41, 40);
  496. /* 42:MRGTHR[0] */
  497. error |= change_config(data, obj_address, 42, 50);
  498. /* 51:JUMPLIMIT[0] */
  499. error |= change_config(data, obj_address, 51, 25);
  500. /* 52:TCHHYST[0] */
  501. error |= change_config(data, obj_address, 52, 15);
  502. #endif
  503. if (error < 0)
  504. pr_err("failed to write error status\n");
  505. }
  506. }
  507. #if TOUCH_BOOSTER
  508. static void mxt_set_dvfs_off(struct work_struct *work)
  509. {
  510. struct mxt_data *data =
  511. container_of(work, struct mxt_data, dvfs_dwork.work);
  512. if (mxt_enabled) {
  513. disable_irq(data->client->irq);
  514. if (touch_cpu_lock_status
  515. && !tsp_press_status){
  516. exynos_cpufreq_lock_free(DVFS_LOCK_ID_TSP);
  517. touch_cpu_lock_status = 0;
  518. }
  519. enable_irq(data->client->irq);
  520. }
  521. }
  522. static void mxt_set_dvfs_on(struct mxt_data *data)
  523. {
  524. cancel_delayed_work(&data->dvfs_dwork);
  525. if (cpu_lv < 0)
  526. exynos_cpufreq_get_level(TOUCH_BOOSTER_LIMIT_CLK, &cpu_lv);
  527. exynos_cpufreq_lock(DVFS_LOCK_ID_TSP, cpu_lv);
  528. touch_cpu_lock_status = 1;
  529. }
  530. #endif
  531. static void mxt_ta_probe(int ta_status)
  532. {
  533. #if !(FOR_BRINGUP)
  534. u16 obj_address = 0;
  535. u16 size;
  536. int error;
  537. struct mxt_data *data = copy_data;
  538. if (!mxt_enabled) {
  539. pr_err("%s mxt_enabled is 0\n", __func__);
  540. return;
  541. }
  542. if (treat_median_error_status)
  543. treat_median_error_status = 0;
  544. if (ta_status) {
  545. error = write_config(data, data->t48_config_chrg[0],
  546. data->t48_config_chrg + 1);
  547. threshold = data->tchthr_charging;
  548. if (error < 0)
  549. pr_err("ta_probe write config Error!!\n");
  550. } else {
  551. error |= write_config(data, data->t48_config_batt[0],
  552. data->t48_config_batt + 1);
  553. threshold = data->tchthr_batt;
  554. if (error < 0)
  555. pr_err("%s write config Error!!\n", __func__);
  556. }
  557. #endif
  558. pr_info("%s : threshold[%d]\n", __func__, threshold);
  559. };
  560. uint8_t reportid_to_type(struct mxt_data *data, u8 report_id, u8 *instance)
  561. {
  562. struct report_id_map_t *report_id_map;
  563. report_id_map = rid_map;
  564. if (report_id <= max_report_id) {
  565. *instance = report_id_map[report_id].instance;
  566. return report_id_map[report_id].object_type;
  567. } else
  568. return 0;
  569. }
  570. static int __devinit mxt_init_touch_driver(struct mxt_data *data)
  571. {
  572. struct object_t *object_table;
  573. struct report_id_map_t *report_id_map_t;
  574. u32 read_crc = 0;
  575. u32 calc_crc;
  576. u16 crc_address;
  577. u16 dummy;
  578. int i, j;
  579. u8 id[ID_BLOCK_SIZE];
  580. int ret;
  581. u8 type_count = 0;
  582. u8 tmp;
  583. int current_report_id, start_report_id;
  584. ret = read_mem(data, 0, sizeof(id), id);
  585. if (ret)
  586. return ret;
  587. pr_info("family = %#02x, variant = %#02x, version "
  588. "= %#02x, build = %#02x, "
  589. "matrix X,Y size = %d,%d\n"
  590. , id[0], id[1], id[2], id[3], id[4], id[5]);
  591. data->family_id = id[0];
  592. data->tsp_variant = id[1];
  593. data->tsp_version = id[2];
  594. data->tsp_build = id[3];
  595. data->objects_len = id[6];
  596. object_table = kmalloc(data->objects_len * sizeof(*object_table),
  597. GFP_KERNEL);
  598. if (!object_table)
  599. return -ENOMEM;
  600. ret = read_mem(data, OBJECT_TABLE_START_ADDRESS,
  601. data->objects_len * sizeof(*object_table),
  602. (u8 *)object_table);
  603. if (ret)
  604. goto err;
  605. max_report_id = 0;
  606. for (i = 0; i < data->objects_len; i++) {
  607. object_table[i].i2c_address =
  608. le16_to_cpu(object_table[i].i2c_address);
  609. max_report_id += object_table[i].num_report_ids *
  610. (object_table[i].instances + 1);
  611. tmp = 0;
  612. if (object_table[i].num_report_ids) {
  613. tmp = type_count + 1;
  614. type_count += object_table[i].num_report_ids *
  615. (object_table[i].instances + 1);
  616. }
  617. switch (object_table[i].object_type) {
  618. case TOUCH_MULTITOUCHSCREEN_T9:
  619. data->finger_type = tmp;
  620. pr_info("Finger type = %d\n",
  621. data->finger_type);
  622. break;
  623. case GEN_MESSAGEPROCESSOR_T5:
  624. #if ITDEV
  625. data->msg_proc_addr = object_table[i].i2c_address;
  626. #endif
  627. data->msg_object_size = object_table[i].size + 1;
  628. break;
  629. }
  630. }
  631. if (rid_map_alloc) {
  632. rid_map_alloc = false;
  633. kfree(rid_map);
  634. }
  635. rid_map = kmalloc((sizeof(report_id_map_t) * max_report_id + 1),
  636. GFP_KERNEL);
  637. if (!rid_map) {
  638. kfree(object_table);
  639. return -ENOMEM;
  640. }
  641. rid_map_alloc = true;
  642. rid_map[0].instance = 0;
  643. rid_map[0].object_type = 0;
  644. current_report_id = 1;
  645. for (i = 0; i < data->objects_len; i++) {
  646. if (object_table[i].num_report_ids != 0) {
  647. for (j = 0; j <= object_table[i].instances; j++) {
  648. for (start_report_id = current_report_id;
  649. current_report_id <
  650. (start_report_id +
  651. object_table[i].num_report_ids);
  652. current_report_id++) {
  653. rid_map[current_report_id].instance = j;
  654. rid_map[current_report_id].object_type =
  655. object_table[i].object_type;
  656. }
  657. }
  658. }
  659. }
  660. data->objects = object_table;
  661. /* Verify CRC */
  662. crc_address = OBJECT_TABLE_START_ADDRESS +
  663. data->objects_len * OBJECT_TABLE_ELEMENT_SIZE;
  664. #ifdef __BIG_ENDIAN
  665. #error The following code will likely break on a big endian machine
  666. #endif
  667. ret = read_mem(data, crc_address, 3, (u8 *)&read_crc);
  668. if (ret)
  669. goto err;
  670. read_crc = le32_to_cpu(read_crc);
  671. ret = calculate_infoblock_crc(data, &calc_crc);
  672. if (ret)
  673. goto err;
  674. if (read_crc != calc_crc) {
  675. pr_err("CRC error\n");
  676. ret = -EFAULT;
  677. goto err;
  678. }
  679. ret = get_object_info(data, GEN_MESSAGEPROCESSOR_T5, &dummy,
  680. &data->msg_proc);
  681. if (ret)
  682. goto err;
  683. ret = get_object_info(data, GEN_COMMANDPROCESSOR_T6, &dummy,
  684. &data->cmd_proc);
  685. if (ret)
  686. goto err;
  687. #if DEBUG_INFO
  688. pr_info("maXTouch: %d Objects\n",
  689. data->objects_len);
  690. for (i = 0; i < data->objects_len; i++) {
  691. pr_info("Type:\t\t\t[%d]: %s\n",
  692. object_table[i].object_type,
  693. object_type_name[object_table[i].object_type]);
  694. pr_info("\tAddress:\t0x%04X\n",
  695. object_table[i].i2c_address);
  696. pr_info("\tSize:\t\t%d Bytes\n",
  697. object_table[i].size);
  698. pr_info("\tInstances:\t%d\n",
  699. object_table[i].instances);
  700. pr_info("\tReport Id's:\t%d\n",
  701. object_table[i].num_report_ids);
  702. }
  703. #endif
  704. return 0;
  705. err:
  706. kfree(object_table);
  707. return ret;
  708. }
  709. static void report_input_data(struct mxt_data *data)
  710. {
  711. int i;
  712. int count = 0;
  713. int report_count = 0;
  714. for (i = 0; i < data->num_fingers; i++) {
  715. if (data->fingers[i].state == MXT_STATE_INACTIVE)
  716. continue;
  717. if (data->fingers[i].state == MXT_STATE_RELEASE) {
  718. input_mt_slot(data->input_dev, i);
  719. input_mt_report_slot_state(data->input_dev,
  720. MT_TOOL_FINGER, false);
  721. } else {
  722. input_mt_slot(data->input_dev, i);
  723. input_mt_report_slot_state(data->input_dev,
  724. MT_TOOL_FINGER, true);
  725. input_report_abs(data->input_dev, ABS_MT_POSITION_X,
  726. data->fingers[i].x);
  727. input_report_abs(data->input_dev, ABS_MT_POSITION_Y,
  728. data->fingers[i].y);
  729. input_report_abs(data->input_dev, ABS_MT_TOUCH_MAJOR,
  730. data->fingers[i].z);
  731. input_report_abs(data->input_dev, ABS_MT_PRESSURE,
  732. data->fingers[i].w);
  733. }
  734. #ifdef _SUPPORT_SHAPE_TOUCH_
  735. input_report_abs(data->input_dev, ABS_MT_COMPONENT,
  736. data->fingers[i].component);
  737. #endif
  738. report_count++;
  739. #if SHOW_COORDINATE
  740. switch (data->fingers[i].state) {
  741. case MXT_STATE_PRESS:
  742. pr_info("P: "
  743. "id[%d],x=%d,y=%d,w=%d\n",
  744. i, data->fingers[i].x, data->fingers[i].y
  745. , data->fingers[i].w);
  746. break;
  747. /*
  748. case MXT_STATE_MOVE:
  749. pr_info("M: "
  750. "id[%d],x=%d,y=%d,w=%d,mc=%d\n",
  751. i, data->fingers[i].x, data->fingers[i].y
  752. , data->fingers[i].w, data->fingers[i].mcount);
  753. break;
  754. */
  755. case MXT_STATE_RELEASE:
  756. pr_info("R: "
  757. "id[%d],mc=%d\n",
  758. i, data->fingers[i].mcount);
  759. break;
  760. default:
  761. break;
  762. }
  763. #else
  764. if (data->fingers[i].state == MXT_STATE_PRESS)
  765. pr_info("P: id[%d],w=%d\n"
  766. , i, data->fingers[i].w);
  767. else if (data->fingers[i].state == MXT_STATE_RELEASE)
  768. pr_info("R: id[%d],mc=%d\n"
  769. , i, data->fingers[i].mcount);
  770. #endif
  771. if (data->fingers[i].state == MXT_STATE_RELEASE) {
  772. data->fingers[i].state = MXT_STATE_INACTIVE;
  773. data->fingers[i].mcount = 0;
  774. } else {
  775. data->fingers[i].state = MXT_STATE_MOVE;
  776. count++;
  777. }
  778. }
  779. if (report_count > 0) {
  780. #if ITDEV
  781. if (!driver_paused)
  782. #endif
  783. input_sync(data->input_dev);
  784. }
  785. if (count)
  786. touch_is_pressed = 1;
  787. else
  788. touch_is_pressed = 0;
  789. #if TOUCH_BOOSTER
  790. if (count == 0) {
  791. if (touch_cpu_lock_status) {
  792. cancel_delayed_work(&data->dvfs_dwork);
  793. schedule_delayed_work(&data->dvfs_dwork,
  794. msecs_to_jiffies(TOUCH_BOOSTER_TIME));
  795. }
  796. tsp_press_status = 0;
  797. } else
  798. tsp_press_status = 1;
  799. #endif
  800. data->finger_mask = 0;
  801. }
  802. static irqreturn_t mxt_irq_thread(int irq, void *ptr)
  803. {
  804. struct mxt_data *data = ptr;
  805. int id;
  806. u8 msg[data->msg_object_size];
  807. u8 touch_message_flag = 0;
  808. u16 obj_address = 0;
  809. u16 size;
  810. u8 value;
  811. int error;
  812. u8 object_type, instance;
  813. do {
  814. touch_message_flag = 0;
  815. if (read_mem(data, data->msg_proc, sizeof(msg), msg)) {
  816. #if TOUCH_BOOSTER
  817. if (touch_cpu_lock_status) {
  818. exynos_cpufreq_lock_free(DVFS_LOCK_ID_TSP);
  819. touch_cpu_lock_status = 0;
  820. }
  821. #endif
  822. return IRQ_HANDLED;
  823. }
  824. #if ITDEV
  825. if (debug_enabled)
  826. print_hex_dump(KERN_INFO, "MXT MSG:",
  827. DUMP_PREFIX_NONE, 16, 1, msg, sizeof(msg), false);
  828. #endif
  829. object_type = reportid_to_type(data, msg[0] , &instance);
  830. if (object_type == GEN_COMMANDPROCESSOR_T6) {
  831. if (msg[1] == 0x00) /* normal mode */
  832. pr_info("normal mode\n");
  833. if ((msg[1]&0x04) == 0x04) /* I2C checksum error */
  834. pr_info("I2C checksum error\n");
  835. if ((msg[1]&0x08) == 0x08) /* config error */
  836. pr_info("config error\n");
  837. if ((msg[1]&0x10) == 0x10) /* calibration */
  838. pr_info("calibration is"
  839. " on going !!\n");
  840. if ((msg[1]&0x20) == 0x20) /* signal error */
  841. pr_info("signal error\n");
  842. if ((msg[1]&0x40) == 0x40) /* overflow */
  843. pr_info("overflow detected\n");
  844. if ((msg[1]&0x80) == 0x80) /* reset */
  845. pr_info("reset is ongoing\n");
  846. }
  847. if (object_type == PROCI_TOUCHSUPPRESSION_T42) {
  848. get_object_info(data, GEN_ACQUISITIONCONFIG_T8,
  849. &size, &obj_address);
  850. if ((msg[1] & 0x01) == 0x00) {
  851. /* Palm release */
  852. pr_info("palm touch released\n");
  853. touch_is_pressed = 0;
  854. } else if ((msg[1] & 0x01) == 0x01) {
  855. /* Palm Press */
  856. pr_info("palm touch detected\n");
  857. touch_is_pressed = 1;
  858. touch_message_flag = 1;
  859. }
  860. }
  861. if (object_type == PROCG_NOISESUPPRESSION_T48) {
  862. /* pr_info("T48 [STATUS]:%#02x"
  863. "[ADCSPERX]:%#02x[FRQ]:%#02x"
  864. "[STATE]:%#02x[NLEVEL]:%#02x\n"
  865. , msg[1], msg[2], msg[3], msg[4], msg[5]);*/
  866. if (msg[4] == 5) { /* Median filter error */
  867. pr_info("Median filter error\n");
  868. if ((data->family_id == 0xA1)
  869. && ((data->tsp_version == 0x13)
  870. || (data->tsp_version == 0x20))) {
  871. if (data->read_ta_status)
  872. treat_error_status();
  873. } else {
  874. get_object_info(data,
  875. PROCG_NOISESUPPRESSION_T48,
  876. &size, &obj_address);
  877. value = data->calcfg_batt;
  878. error = write_mem(data,
  879. obj_address+2, 1, &value);
  880. msleep(20);
  881. value |= 0x20;
  882. error |= write_mem(data,
  883. obj_address+2, 1, &value);
  884. if (error)
  885. pr_err("failed to"
  886. "reenable CHRGON\n");
  887. }
  888. }
  889. }
  890. #if USE_SUMSIZE
  891. if (object_type == SPT_GENERICDATA_T57) {
  892. sum_size = msg[1];
  893. sum_size += (msg[2]<<8);
  894. }
  895. #endif
  896. if (object_type == TOUCH_MULTITOUCHSCREEN_T9) {
  897. id = msg[0] - data->finger_type;
  898. /* If not a touch event, then keep going */
  899. if (id < 0 || id >= data->num_fingers)
  900. continue;
  901. if (data->finger_mask & (1U << id))
  902. report_input_data(data);
  903. if (msg[1] & RELEASE_MSG_MASK) {
  904. data->fingers[id].z = 0;
  905. data->fingers[id].w = msg[5];
  906. data->finger_mask |= 1U << id;
  907. data->fingers[id].state = MXT_STATE_RELEASE;
  908. } else if ((msg[1] & DETECT_MSG_MASK) && (msg[1] &
  909. (PRESS_MSG_MASK | MOVE_MSG_MASK))) {
  910. #if TOUCH_BOOSTER
  911. if (!touch_cpu_lock_status)
  912. mxt_set_dvfs_on(data);
  913. #endif
  914. touch_message_flag = 1;
  915. data->fingers[id].z = msg[6];
  916. data->fingers[id].w = msg[5];
  917. data->fingers[id].x =
  918. (((msg[2] << 4) | (msg[4] >> 4))
  919. >> data->x_dropbits);
  920. data->fingers[id].y =
  921. (((msg[3] << 4) | (msg[4] & 0xF))
  922. >> data->y_dropbits);
  923. data->finger_mask |= 1U << id;
  924. if (msg[1] & PRESS_MSG_MASK) {
  925. data->fingers[id].state =
  926. MXT_STATE_PRESS;
  927. data->fingers[id].mcount = 0;
  928. } else if (msg[1] & MOVE_MSG_MASK)
  929. data->fingers[id].mcount += 1;
  930. #ifdef _SUPPORT_SHAPE_TOUCH_
  931. data->fingers[id].component = msg[7];
  932. #endif
  933. } else if ((msg[1] & SUPPRESS_MSG_MASK)
  934. && (data->fingers[id].state != MXT_STATE_INACTIVE)) {
  935. data->fingers[id].z = 0;
  936. data->fingers[id].w = msg[5];
  937. data->fingers[id].state = MXT_STATE_RELEASE;
  938. data->finger_mask |= 1U << id;
  939. } else {
  940. /* ignore changed amplitude message */
  941. if (!((msg[1] & DETECT_MSG_MASK)
  942. && (msg[1] & AMPLITUDE_MSG_MASK)))
  943. pr_err("Unknown state %#02x %#02x\n",
  944. msg[0], msg[1]);
  945. continue;
  946. }
  947. }
  948. } while (!gpio_get_value(data->gpio_read_done));
  949. if (data->finger_mask) {
  950. #if USE_SUMSIZE
  951. if (sum_size > 0) {
  952. /* case of normal configuration */
  953. u8 num_finger = 0;
  954. u8 i;
  955. uint16_t t9_sum_size = 0;
  956. for (i = 0; i < data->num_fingers; i++) {
  957. if (data->fingers[i].state == MXT_STATE_INACTIVE
  958. || data->fingers[i].state == MXT_STATE_RELEASE)
  959. continue;
  960. t9_sum_size += data->fingers[i].w;
  961. num_finger++;
  962. }
  963. if ((num_finger == 1)
  964. && ((sum_size-t9_sum_size) >= MAX_SUMSIZE)) {
  965. pr_info(
  966. "recalibrate for max sumsize[%d]"
  967. "t9_sum_size[%d]\n"
  968. , sum_size, t9_sum_size);
  969. calibrate_chip_e();
  970. } else {
  971. report_input_data(data);
  972. }
  973. t9_sum_size = 0;
  974. sum_size = 0;
  975. } else {
  976. /* case of recovery configuration */
  977. report_input_data(data);
  978. }
  979. #else
  980. report_input_data(data);
  981. #endif
  982. }
  983. return IRQ_HANDLED;
  984. }
  985. static int mxt_internal_suspend(struct mxt_data *data)
  986. {
  987. int i;
  988. int count = 0;
  989. for (i = 0; i < data->num_fingers; i++) {
  990. if (data->fingers[i].state == MXT_STATE_INACTIVE)
  991. continue;
  992. data->fingers[i].z = 0;
  993. data->fingers[i].state = MXT_STATE_RELEASE;
  994. count++;
  995. }
  996. if (count)
  997. report_input_data(data);
  998. #if TOUCH_BOOSTER
  999. cancel_delayed_work(&data->dvfs_dwork);
  1000. tsp_press_status = 0;
  1001. if (touch_cpu_lock_status) {
  1002. exynos_cpufreq_lock_free(DVFS_LOCK_ID_TSP);
  1003. touch_cpu_lock_status = 0;
  1004. }
  1005. #endif
  1006. data->power_off();
  1007. return 0;
  1008. }
  1009. static int mxt_internal_resume(struct mxt_data *data)
  1010. {
  1011. data->power_on();
  1012. return 0;
  1013. }
  1014. #ifdef CONFIG_HAS_EARLYSUSPEND
  1015. #define mxt_suspend NULL
  1016. #define mxt_resume NULL
  1017. static void mxt_early_suspend(struct early_suspend *h)
  1018. {
  1019. struct mxt_data *data = container_of(h, struct mxt_data,
  1020. early_suspend);
  1021. if (mxt_enabled == 1) {
  1022. pr_info("%s\n", __func__);
  1023. mxt_enabled = 0;
  1024. touch_is_pressed = 0;
  1025. disable_irq(data->client->irq);
  1026. mxt_internal_suspend(data);
  1027. } else
  1028. pr_err("%s. but touch already off\n", __func__);
  1029. }
  1030. static void mxt_late_resume(struct early_suspend *h)
  1031. {
  1032. bool ta_status = 0;
  1033. struct mxt_data *data = container_of(h, struct mxt_data,
  1034. early_suspend);
  1035. if (mxt_enabled == 0) {
  1036. pr_info("%s\n", __func__);
  1037. mxt_internal_resume(data);
  1038. mxt_enabled = 1;
  1039. if (data->read_ta_status) {
  1040. data->read_ta_status(&ta_status);
  1041. pr_info("ta_status is %d\n", ta_status);
  1042. mxt_ta_probe(ta_status);
  1043. }
  1044. treat_median_error_status = 0;
  1045. calibrate_chip_e();
  1046. enable_irq(data->client->irq);
  1047. } else
  1048. pr_err("%s. but touch already on\n", __func__);
  1049. }
  1050. #else
  1051. static int mxt_suspend(struct device *dev)
  1052. {
  1053. struct i2c_client *client = to_i2c_client(dev);
  1054. struct mxt_data *data = i2c_get_clientdata(client);
  1055. mxt_enabled = 0;
  1056. touch_is_pressed = 0;
  1057. #if TOUCH_BOOSTER
  1058. tsp_press_status = 0;
  1059. #endif
  1060. return mxt_internal_suspend(data);
  1061. }
  1062. static int mxt_resume(struct device *dev)
  1063. {
  1064. int ret = 0;
  1065. bool ta_status = 0;
  1066. struct i2c_client *client = to_i2c_client(dev);
  1067. struct mxt_data *data = i2c_get_clientdata(client);
  1068. ret = mxt_internal_resume(data);
  1069. mxt_enabled = 1;
  1070. if (data->read_ta_status) {
  1071. data->read_ta_status(&ta_status);
  1072. pr_info("ta_status is %d\n", ta_status);
  1073. mxt_ta_probe(ta_status);
  1074. }
  1075. return ret;
  1076. }
  1077. #endif
  1078. void Mxt_force_released(void)
  1079. {
  1080. struct mxt_data *data = copy_data;
  1081. int i;
  1082. if (!mxt_enabled) {
  1083. pr_err("mxt_enabled is 0\n");
  1084. return;
  1085. }
  1086. for (i = 0; i < data->num_fingers; i++) {
  1087. if (data->fingers[i].state == MXT_STATE_INACTIVE)
  1088. continue;
  1089. data->fingers[i].z = 0;
  1090. data->fingers[i].state = MXT_STATE_RELEASE;
  1091. }
  1092. report_input_data(data);
  1093. calibrate_chip_e();
  1094. };
  1095. #if SYSFS
  1096. static ssize_t mxt_debug_setting(struct device *dev,
  1097. struct device_attribute *attr,
  1098. const char *buf, size_t count)
  1099. {
  1100. g_debug_switch = !g_debug_switch;
  1101. return 0;
  1102. }
  1103. static ssize_t mxt_object_setting(struct device *dev,
  1104. struct device_attribute *attr,
  1105. const char *buf, size_t count)
  1106. {
  1107. struct mxt_data *data = dev_get_drvdata(dev);
  1108. unsigned int object_type;
  1109. unsigned int object_register;
  1110. unsigned int register_value;
  1111. u8 value;
  1112. u8 val;
  1113. int ret;
  1114. u16 address;
  1115. u16 size;
  1116. sscanf(buf, "%u%u%u", &object_type, &object_register, &register_value);
  1117. pr_info("object type T%d", object_type);
  1118. pr_info("object register ->Byte%d\n", object_register);
  1119. pr_info("register value %d\n", register_value);
  1120. ret = get_object_info(data, (u8)object_type, &size, &address);
  1121. if (ret) {
  1122. pr_err("fail to get object_info\n");
  1123. return count;
  1124. }
  1125. size = 1;
  1126. value = (u8)register_value;
  1127. write_mem(data, address+(u16)object_register, size, &value);
  1128. read_mem(data, address+(u16)object_register, (u8)size, &val);
  1129. pr_info("T%d Byte%d is %d\n",
  1130. object_type, object_register, val);
  1131. return count;
  1132. }
  1133. static ssize_t mxt_object_show(struct device *dev,
  1134. struct device_attribute *attr,
  1135. const char *buf, size_t count)
  1136. {
  1137. struct mxt_data *data = dev_get_drvdata(dev);
  1138. unsigned int object_type;
  1139. u8 val;
  1140. int ret;
  1141. u16 address;
  1142. u16 size;
  1143. u16 i;
  1144. sscanf(buf, "%u", &object_type);
  1145. pr_info("object type T%d\n", object_type);
  1146. ret = get_object_info(data, (u8)object_type, &size, &address);
  1147. if (ret) {
  1148. pr_err("fail to get object_info\n");
  1149. return count;
  1150. }
  1151. for (i = 0; i < size; i++) {
  1152. read_mem(data, address+i, 1, &val);
  1153. pr_info("Byte %u --> %u\n", i, val);
  1154. }
  1155. return count;
  1156. }
  1157. struct device *sec_touchscreen;
  1158. struct device *mxt_noise_test;
  1159. /*
  1160. top_left, top_right, center, bottom_left, bottom_right
  1161. */
  1162. unsigned int test_node[5] = {642, 98, 367, 668, 124};
  1163. uint16_t qt_refrence_node[768] = { 0 };
  1164. uint16_t qt_delta_node[768] = { 0 };
  1165. void diagnostic_chip(u8 mode)
  1166. {
  1167. int error;
  1168. u16 t6_address = 0;
  1169. u16 size_one;
  1170. int ret;
  1171. u8 value;
  1172. u16 t37_address = 0;
  1173. ret = get_object_info(copy_data,
  1174. GEN_COMMANDPROCESSOR_T6, &size_one, &t6_address);
  1175. size_one = 1;
  1176. error = write_mem(copy_data, t6_address+5, (u8)size_one, &mode);
  1177. /* QT602240_COMMAND_DIAGNOSTIC, mode); */
  1178. if (error < 0) {
  1179. pr_err("error %s: write_object\n", __func__);
  1180. } else {
  1181. get_object_info(copy_data,
  1182. DEBUG_DIAGNOSTIC_T37, &size_one, &t37_address);
  1183. size_one = 1;
  1184. /* pr_info("diagnostic_chip setting success\n"); */
  1185. read_mem(copy_data, t37_address, (u8)size_one, &value);
  1186. /* pr_info("dianostic_chip mode is %d\n",value); */
  1187. }
  1188. }
  1189. uint8_t read_uint16_t(struct mxt_data *data, uint16_t address, uint16_t *buf)
  1190. {
  1191. uint8_t status;
  1192. uint8_t temp[2];
  1193. status = read_mem(data, address, 2, temp);
  1194. *buf = ((uint16_t)temp[1]<<8) + (uint16_t)temp[0];
  1195. return status;
  1196. }
  1197. void read_dbg_data(uint8_t dbg_mode , uint16_t node, uint16_t *dbg_data)
  1198. {
  1199. u8 read_page, read_point;
  1200. uint8_t mode, page;
  1201. u16 size;
  1202. u16 diagnostic_addr = 0;
  1203. if (!mxt_enabled) {
  1204. pr_err("read_dbg_data. mxt_enabled is 0\n");
  1205. return;
  1206. }
  1207. get_object_info(copy_data,
  1208. DEBUG_DIAGNOSTIC_T37, &size, &diagnostic_addr);
  1209. read_page = node / 64;
  1210. node %= 64;
  1211. read_point = (node * 2) + 2;
  1212. /* Page Num Clear */
  1213. diagnostic_chip(MXT_CTE_MODE);
  1214. msleep(20);
  1215. do {
  1216. if (read_mem(copy_data, diagnostic_addr, 1, &mode)) {
  1217. pr_info("READ_MEM_FAILED\n");
  1218. return;
  1219. }
  1220. } while (mode != MXT_CTE_MODE);
  1221. diagnostic_chip(dbg_mode);
  1222. msleep(20);
  1223. do {
  1224. if (read_mem(copy_data, diagnostic_addr, 1, &mode)) {
  1225. pr_info("READ_MEM_FAILED\n");
  1226. return;
  1227. }
  1228. } while (mode != dbg_mode);
  1229. for (page = 1; page <= read_page; page++) {
  1230. diagnostic_chip(MXT_PAGE_UP);
  1231. msleep(20);
  1232. do {
  1233. if (read_mem(copy_data,
  1234. diagnostic_addr + 1, 1, &mode)) {
  1235. pr_info("READ_MEM_FAILED\n");
  1236. return;
  1237. }
  1238. } while (mode != page);
  1239. }
  1240. if (read_uint16_t(copy_data, diagnostic_addr + read_point, dbg_data)) {
  1241. pr_info("READ_MEM_FAILED\n");
  1242. return;
  1243. }
  1244. }
  1245. #define MIN_VALUE 19744
  1246. #define MAX_VALUE 28884
  1247. #define MIN_VALUE_TA_ERROR_MODE 19125
  1248. #define T48_CALCFG_CHRGON 0x20
  1249. /* caution : should check the sensor level
  1250. this value is depend on tsp tunning state */
  1251. #define SENSOR_GAIN_TAERROR 5
  1252. int read_all_data(uint16_t dbg_mode)
  1253. {
  1254. u8 read_page, read_point;
  1255. u16 max_value = MIN_VALUE, min_value = MAX_VALUE;
  1256. u16 ref_max_value = MAX_VALUE;
  1257. u16 ref_min_value = MIN_VALUE;
  1258. u16 object_address = 0;
  1259. u8 data_buffer[2] = { 0 };
  1260. u8 node = 0;
  1261. int state = 0;
  1262. int num = 0;
  1263. int ret;
  1264. u16 size;
  1265. u8 val = 0;
  1266. u8 sensor_gain = 0;
  1267. bool ta_status = 0;
  1268. if (!mxt_enabled) {
  1269. pr_err("%s : mxt_enabled is 0\n", __func__);
  1270. return 1;
  1271. }
  1272. if (copy_data->read_ta_status) {
  1273. copy_data->read_ta_status(&ta_status);
  1274. pr_info("ta_status is %d\n", ta_status);
  1275. }
  1276. /* check the CHRG_ON bit is set or not */
  1277. /* when CHRG_ON is setted dual x is on so skip read last line*/
  1278. get_object_info(copy_data,
  1279. PROCG_NOISESUPPRESSION_T48, &size, &object_address);
  1280. ret = read_mem(copy_data, object_address+2 , 1, &val);
  1281. if (ret < 0)
  1282. pr_err("TSP read fail : %s", __func__);
  1283. pr_info("%s CALCFG[%#02x]\n", __func__, val);
  1284. val = val & T48_CALCFG_CHRGON;
  1285. /* read sensor gain to check reference value */
  1286. if (val == T48_CALCFG_CHRGON) {
  1287. ret = read_mem(copy_data, object_address+34 , 1, &sensor_gain);
  1288. if (ret < 0)
  1289. pr_err("TSP read fail : %s", __func__);
  1290. sensor_gain = (sensor_gain&0xF0)>>4;
  1291. pr_info("%s BLEN[%d]\n", __func__, sensor_gain);
  1292. if (sensor_gain == SENSOR_GAIN_TAERROR)
  1293. ref_min_value = MIN_VALUE_TA_ERROR_MODE;
  1294. }
  1295. /* Page Num Clear */
  1296. diagnostic_chip(MXT_CTE_MODE);
  1297. msleep(30);/* msleep(20); */
  1298. diagnostic_chip(dbg_mode);
  1299. msleep(30);/* msleep(20); */
  1300. ret = get_object_info(copy_data,
  1301. DEBUG_DIAGNOSTIC_T37, &size, &object_address);
  1302. msleep(50); /* msleep(20); */
  1303. /* 768/64 */
  1304. for (read_page = 0 ; read_page < 12; read_page++) {
  1305. for (node = 0; node < 64; node++) {
  1306. read_point = (node * 2) + 2;
  1307. read_mem(copy_data,
  1308. object_address+(u16)read_point, 2, data_buffer);
  1309. qt_refrence_node[num] = ((uint16_t)data_buffer[1]<<8)
  1310. + (uint16_t)data_buffer[0];
  1311. /* last X line has 1/2 reference during
  1312. TA mode So do not check min/max value */
  1313. if ((val != T48_CALCFG_CHRGON)
  1314. || (val == T48_CALCFG_CHRGON && (num < 736))) {
  1315. if ((qt_refrence_node[num] < ref_min_value)
  1316. || (qt_refrence_node[num] > ref_max_value)) {
  1317. if (sensor_gain == SENSOR_GAIN_TAERROR)
  1318. state = 2;
  1319. else
  1320. state = 1;
  1321. pr_err(
  1322. "qt_refrence_node[%3d] = %5d\n"
  1323. , num, qt_refrence_node[num]);
  1324. }
  1325. if (data_buffer[0] != 0) {
  1326. if (qt_refrence_node[num] > max_value)
  1327. max_value =
  1328. qt_refrence_node[num];
  1329. if (qt_refrence_node[num] < min_value)
  1330. min_value =
  1331. qt_refrence_node[num];
  1332. }
  1333. }
  1334. num++;
  1335. /* all node => 24 * 32 = 768 => (12page * 64) */
  1336. /* if ((read_page == 11) && (node == 64))
  1337. break; */
  1338. if (qt_refrence_node[num-1] == 0)
  1339. pr_err("qt_refrence_node"
  1340. "[%d] = 0\n", num);
  1341. if (num == 768)
  1342. break;
  1343. }
  1344. diagnostic_chip(MXT_PAGE_UP);
  1345. msleep(35);
  1346. if (num == 768)
  1347. break;
  1348. }
  1349. if ((max_value - min_value) > 4500) {
  1350. pr_err("diff = %d, max_value = %d, min_value = %d\n",
  1351. (max_value - min_value), max_value, min_value);
  1352. state = 1;
  1353. }
  1354. return state;
  1355. }
  1356. int read_all_delta_data(uint16_t dbg_mode)
  1357. {
  1358. u8 read_page, read_point;
  1359. u16 object_address = 0;
  1360. u8 data_buffer[2] = { 0 };
  1361. u8 node = 0;
  1362. int state = 0;
  1363. int num = 0;
  1364. int ret;
  1365. u16 size;
  1366. if (!mxt_enabled) {
  1367. pr_err("%s : mxt_enabled is 0\n", __func__);
  1368. return 1;
  1369. }
  1370. /* Page Num Clear */
  1371. diagnostic_chip(MXT_CTE_MODE);
  1372. msleep(30);/* msleep(20); */
  1373. diagnostic_chip(dbg_mode);
  1374. msleep(30);/* msleep(20); */
  1375. ret = get_object_info(copy_data,
  1376. DEBUG_DIAGNOSTIC_T37, &size, &object_address);
  1377. /*jerry no need to leave it */
  1378. #if 0
  1379. for (i = 0; i < 5; i++) {
  1380. if (data_buffer[0] == dbg_mode)
  1381. break;
  1382. msleep(20);
  1383. }
  1384. #else
  1385. msleep(50); /* msleep(20); */
  1386. #endif
  1387. /* 768/64 */
  1388. for (read_page = 0 ; read_page < 12; read_page++) {
  1389. for (node = 0; node < 64; node++) {
  1390. read_point = (node * 2) + 2;
  1391. read_mem(copy_data,
  1392. object_address+(u16)read_point, 2, data_buffer);
  1393. qt_delta_node[num] =
  1394. ((uint16_t)data_buffer[1]<<8)
  1395. + (uint16_t)data_buffer[0];
  1396. num++;
  1397. /* all node => 24 * 32 = 768 => (12page * 64) */
  1398. /*if ((read_page == 11) && (node == 64))
  1399. break;*/
  1400. }
  1401. diagnostic_chip(MXT_PAGE_UP);
  1402. msleep(35);
  1403. }
  1404. return state;
  1405. }
  1406. int find_channel(uint16_t dbg_mode)
  1407. {
  1408. u8 read_page, read_point;
  1409. u16 object_address = 0;
  1410. u8 data_buffer[2] = { 0 };
  1411. u8 node = 0;
  1412. int state = 0;
  1413. int num = 0;
  1414. int ret;
  1415. u16 size;
  1416. u16 delta_val = 0;
  1417. u16 max_val = 0;
  1418. if (!mxt_enabled) {
  1419. pr_err("%s : mxt_enabled is 0\n", __func__);
  1420. return 1;
  1421. }
  1422. /* Page Num Clear */
  1423. diagnostic_chip(MXT_CTE_MODE);
  1424. msleep(30);/* msleep(20); */
  1425. diagnostic_chip(dbg_mode);
  1426. msleep(30);/* msleep(20); */
  1427. ret = get_object_info(copy_data,
  1428. DEBUG_DIAGNOSTIC_T37, &size, &object_address);
  1429. /*jerry no need to leave it */
  1430. #if 0
  1431. for (i = 0; i < 5; i++) {
  1432. if (data_buffer[0] == dbg_mode)
  1433. break;
  1434. msleep(20);
  1435. }
  1436. #else
  1437. msleep(50); /* msleep(20); */
  1438. #endif
  1439. /* 768/64 */
  1440. for (read_page = 0 ; read_page < 12; read_page++) {
  1441. for (node = 0; node < 64; node++) {
  1442. read_point = (node * 2) + 2;
  1443. read_mem(copy_data,
  1444. object_address+(u16)read_point, 2, data_buffer);
  1445. delta_val = ((uint16_t)data_buffer[1]<<8)
  1446. + (uint16_t)data_buffer[0];
  1447. if (delta_val > 32767)
  1448. delta_val = 65535 - delta_val;
  1449. if (delta_val > max_val) {
  1450. max_val = delta_val;
  1451. state = (read_point - 2)/2 +
  1452. (read_page * 64);
  1453. }
  1454. num++;
  1455. /* all node => 24 * 32 = 768 => (12page * 64) */
  1456. /*if ((read_page == 11) && (node == 64))
  1457. break;*/
  1458. }
  1459. diagnostic_chip(MXT_PAGE_UP);
  1460. msleep(35);
  1461. }
  1462. return state;
  1463. }
  1464. static ssize_t find_channel_show(struct device *dev,
  1465. struct device_attribute *attr,
  1466. char *buf)
  1467. {
  1468. int status = 0;
  1469. status = find_channel(MXT_DELTA_MODE);
  1470. return sprintf(buf, "%u\n", status);
  1471. }
  1472. #endif
  1473. static int mxt_check_bootloader(struct i2c_client *client,
  1474. unsigned int state)
  1475. {
  1476. u8 val;
  1477. u8 temp;
  1478. recheck:
  1479. if (i2c_master_recv(client, &val, 1) != 1)
  1480. return -EIO;
  1481. if (val & 0x20) {
  1482. if (i2c_master_recv(client, &temp, 1) != 1)
  1483. return -EIO;
  1484. if (i2c_master_recv(client, &temp, 1) != 1)
  1485. return -EIO;
  1486. val &= ~0x20;
  1487. }
  1488. if ((val & 0xF0) == MXT_APP_CRC_FAIL) {
  1489. pr_info("MXT_APP_CRC_FAIL\n");
  1490. if (i2c_master_recv(client, &val, 1) != 1)
  1491. return -EIO;
  1492. if (val & 0x20) {
  1493. if (i2c_master_recv(client, &temp, 1) != 1)
  1494. return -EIO;
  1495. if (i2c_master_recv(client, &temp, 1) != 1)
  1496. return -EIO;
  1497. val &= ~0x20;
  1498. }
  1499. }
  1500. switch (state) {
  1501. case MXT_WAITING_BOOTLOAD_CMD:
  1502. case MXT_WAITING_FRAME_DATA:
  1503. val &= ~MXT_BOOT_STATUS_MASK;
  1504. break;
  1505. case MXT_FRAME_CRC_PASS:
  1506. if (val == MXT_FRAME_CRC_CHECK)
  1507. goto recheck;
  1508. break;
  1509. default:
  1510. return -EINVAL;
  1511. }
  1512. if (val != state) {
  1513. pr_err("Unvalid bootloader mode state\n");
  1514. return -EINVAL;
  1515. }
  1516. return 0;
  1517. }
  1518. static int mxt_unlock_bootloader(struct i2c_client *client)
  1519. {
  1520. u8 buf[2];
  1521. buf[0] = MXT_UNLOCK_CMD_LSB;
  1522. buf[1] = MXT_UNLOCK_CMD_MSB;
  1523. if (i2c_master_send(client, buf, 2) != 2) {
  1524. pr_err("%s: i2c send failed\n",
  1525. __func__);
  1526. return -EIO;
  1527. }
  1528. return 0;
  1529. }
  1530. static int mxt_fw_write(struct i2c_client *client,
  1531. const u8 *data, unsigned int frame_size)
  1532. {
  1533. if (i2c_master_send(client, data, frame_size) != frame_size) {
  1534. pr_err("%s: i2c send failed\n", __func__);
  1535. return -EIO;
  1536. }
  1537. return 0;
  1538. }
  1539. static int mxt_load_fw(struct device *dev, const char *fn)
  1540. {
  1541. struct mxt_data *data = copy_data;
  1542. struct i2c_client *client = copy_data->client;
  1543. unsigned int frame_size;
  1544. unsigned int pos = 0;
  1545. int ret;
  1546. u16 obj_address = 0;
  1547. u16 size_one;
  1548. u8 value;
  1549. unsigned int object_register;
  1550. int check_frame_crc_error = 0;
  1551. int check_wating_frame_data_error = 0;
  1552. #if READ_FW_FROM_HEADER
  1553. struct firmware *fw = NULL;
  1554. pr_info("mxt_load_fw start from header!!!\n");
  1555. fw = kzalloc(sizeof(struct firmware), GFP_KERNEL);
  1556. fw->data = firmware_mXT;
  1557. fw->size = sizeof(firmware_mXT);
  1558. #else
  1559. const struct firmware *fw = NULL;
  1560. pr_info("mxt_load_fw startl!!!\n");
  1561. ret = request_firmware(&fw, fn, &client->dev);
  1562. if (ret) {
  1563. pr_err("Unable to open firmware %s\n", fn);
  1564. return ret;
  1565. }
  1566. #endif
  1567. /* Change to the bootloader mode */
  1568. object_register = 0;
  1569. value = (u8)MXT_BOOT_VALUE;
  1570. ret = get_object_info(data,
  1571. GEN_COMMANDPROCESSOR_T6, &size_one, &obj_address);
  1572. if (ret) {
  1573. pr_err("fail to get object_info\n");
  1574. release_firmware(fw);
  1575. return ret;
  1576. }
  1577. size_one = 1;
  1578. write_mem(data, obj_address+(u16)object_register, (u8)size_one, &value);
  1579. msleep(MXT_SW_RESET_TIME);
  1580. /* Change to slave address of bootloader */
  1581. if (client->addr == MXT_APP_LOW)
  1582. client->addr = MXT_BOOT_LOW;
  1583. else
  1584. client->addr = MXT_BOOT_HIGH;
  1585. ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD);
  1586. if (ret)
  1587. goto out;
  1588. /* Unlock bootloader */
  1589. mxt_unlock_bootloader(client);
  1590. while (pos < fw->size) {
  1591. ret = mxt_check_bootloader(client,
  1592. MXT_WAITING_FRAME_DATA);
  1593. if (ret) {
  1594. check_wating_frame_data_error++;
  1595. if (check_wating_frame_data_error > 10) {
  1596. pr_err("firm update fail. wating_frame_data err\n");
  1597. goto out;
  1598. } else {
  1599. pr_err("check_wating_frame_data_error = %d, retry\n",
  1600. check_wating_frame_data_error);
  1601. continue;
  1602. }
  1603. }
  1604. frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
  1605. /* We should add 2 at frame size as the the firmware data is not
  1606. * included the CRC bytes.
  1607. */
  1608. frame_size += 2;
  1609. /* Write one frame to device */
  1610. mxt_fw_write(client, fw->data + pos, frame_size);
  1611. ret = mxt_check_bootloader(client,
  1612. MXT_FRAME_CRC_PASS);
  1613. if (ret) {
  1614. check_frame_crc_error++;
  1615. if (check_frame_crc_error > 10) {
  1616. pr_err("firm update fail. frame_crc err\n");
  1617. goto out;
  1618. } else {
  1619. pr_err("check_frame_crc_error = %d, retry\n",
  1620. check_frame_crc_error);
  1621. continue;
  1622. }
  1623. }
  1624. pos += frame_size;
  1625. pr_info("Updated %d bytes / %zd bytes\n",
  1626. pos, fw->size);
  1627. msleep(20);
  1628. }
  1629. out:
  1630. #if READ_FW_FROM_HEADER
  1631. kfree(fw);
  1632. #else
  1633. release_firmware(fw);
  1634. #endif
  1635. /* Change to slave address of application */
  1636. if (client->addr == MXT_BOOT_LOW)
  1637. client->addr = MXT_APP_LOW;
  1638. else
  1639. client->addr = MXT_APP_HIGH;
  1640. return ret;
  1641. }
  1642. static int mxt_load_fw_bootmode(struct device *dev, const char *fn)
  1643. {
  1644. struct i2c_client *client = copy_data->client;
  1645. unsigned int frame_size;
  1646. unsigned int pos = 0;
  1647. int ret;
  1648. int check_frame_crc_error = 0;
  1649. int check_wating_frame_data_error = 0;
  1650. #if READ_FW_FROM_HEADER
  1651. struct firmware *fw = NULL;
  1652. pr_info("mxt_load_fw start from header!!!\n");
  1653. fw = kzalloc(sizeof(struct firmware), GFP_KERNEL);
  1654. fw->data = firmware_mXT;
  1655. fw->size = sizeof(firmware_mXT);
  1656. #else
  1657. const struct firmware *fw = NULL;
  1658. pr_info("mxt_load_fw start!!!\n");
  1659. ret = request_firmware(&fw, fn, &client->dev);
  1660. if (ret) {
  1661. pr_err("Unable to open firmware %s\n", fn);
  1662. return ret;
  1663. }
  1664. #endif
  1665. /* Unlock bootloader */
  1666. mxt_unlock_bootloader(client);
  1667. while (pos < fw->size) {
  1668. ret = mxt_check_bootloader(client,
  1669. MXT_WAITING_FRAME_DATA);
  1670. if (ret) {
  1671. check_wating_frame_data_error++;
  1672. if (check_wating_frame_data_error > 10) {
  1673. pr_err("firm update fail. wating_frame_data err\n");
  1674. goto out;
  1675. } else {
  1676. pr_err("check_wating_frame_data_error = %d, retry\n",
  1677. check_wating_frame_data_error);
  1678. continue;
  1679. }
  1680. }
  1681. frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1));
  1682. /* We should add 2 at frame size as the the firmware data is not
  1683. * included the CRC bytes.
  1684. */
  1685. frame_size += 2;
  1686. /* Write one frame to device */
  1687. mxt_fw_write(client, fw->data + pos, frame_size);
  1688. ret = mxt_check_bootloader(client,
  1689. MXT_FRAME_CRC_PASS);
  1690. if (ret) {
  1691. check_frame_crc_error++;
  1692. if (check_frame_crc_error > 10) {
  1693. pr_err("firm update fail. frame_crc err\n");
  1694. goto out;
  1695. } else {
  1696. pr_err("check_frame_crc_error = %d, retry\n",
  1697. check_frame_crc_error);
  1698. continue;
  1699. }
  1700. }
  1701. pos += frame_size;
  1702. pr_info("Updated %d bytes / %zd bytes\n",
  1703. pos, fw->size);
  1704. msleep(20);
  1705. }
  1706. out:
  1707. #if READ_FW_FROM_HEADER
  1708. kfree(fw);
  1709. #else
  1710. release_firmware(fw);
  1711. #endif
  1712. /* Change to slave address of application */
  1713. if (client->addr == MXT_BOOT_LOW)
  1714. client->addr = MXT_APP_LOW;
  1715. else
  1716. client->addr = MXT_APP_HIGH;
  1717. return ret;
  1718. }
  1719. #if SYSFS
  1720. static ssize_t set_refer0_mode_show(struct device *dev,
  1721. struct device_attribute *attr, char *buf)
  1722. {
  1723. uint16_t mxt_reference = 0;
  1724. read_dbg_data(MXT_REFERENCE_MODE, test_node[0], &mxt_reference);
  1725. return sprintf(buf, "%u\n", mxt_reference);
  1726. }
  1727. static ssize_t set_refer1_mode_show(struct device *dev,
  1728. struct device_attribute *attr, char *buf)
  1729. {
  1730. uint16_t mxt_reference = 0;
  1731. read_dbg_data(MXT_REFERENCE_MODE, test_node[1], &mxt_reference);
  1732. return sprintf(buf, "%u\n", mxt_reference);
  1733. }
  1734. static ssize_t set_refer2_mode_show(struct device *dev,
  1735. struct device_attribute *attr, char *buf)
  1736. {
  1737. uint16_t mxt_reference = 0;
  1738. read_dbg_data(MXT_REFERENCE_MODE, test_node[2], &mxt_reference);
  1739. return sprintf(buf, "%u\n", mxt_reference);
  1740. }
  1741. static ssize_t set_refer3_mode_show(struct device *dev,
  1742. struct device_attribute *attr, char *buf)
  1743. {
  1744. uint16_t mxt_reference = 0;
  1745. read_dbg_data(MXT_REFERENCE_MODE, test_node[3], &mxt_reference);
  1746. return sprintf(buf, "%u\n", mxt_reference);
  1747. }
  1748. static ssize_t set_refer4_mode_show(struct device *dev,
  1749. struct device_attribute *attr, char *buf)
  1750. {
  1751. uint16_t mxt_reference = 0;
  1752. read_dbg_data(MXT_REFERENCE_MODE, test_node[4], &mxt_reference);
  1753. return sprintf(buf, "%u\n", mxt_reference);
  1754. }
  1755. static ssize_t set_delta0_mode_show(struct device *dev,
  1756. struct device_attribute *attr, char *buf)
  1757. {
  1758. uint16_t mxt_delta = 0;
  1759. read_dbg_data(MXT_DELTA_MODE, test_node[0], &mxt_delta);
  1760. if (mxt_delta < 32767)
  1761. return sprintf(buf, "%u\n", mxt_delta);
  1762. else
  1763. mxt_delta = 65535 - mxt_delta;
  1764. if (mxt_delta)
  1765. return sprintf(buf, "-%u\n", mxt_delta);
  1766. else
  1767. return sprintf(buf, "%u\n", mxt_delta);
  1768. }
  1769. static ssize_t set_delta1_mode_show(struct device *dev,
  1770. struct device_attribute *attr, char *buf)
  1771. {
  1772. uint16_t mxt_delta = 0;
  1773. read_dbg_data(MXT_DELTA_MODE, test_node[1], &mxt_delta);
  1774. if (mxt_delta < 32767)
  1775. return sprintf(buf, "%u\n", mxt_delta);
  1776. else
  1777. mxt_delta = 65535 - mxt_delta;
  1778. if (mxt_delta)
  1779. return sprintf(buf, "-%u\n", mxt_delta);
  1780. else
  1781. return sprintf(buf, "%u\n", mxt_delta);
  1782. }
  1783. static ssize_t set_delta2_mode_show(struct device *dev,
  1784. struct device_attribute *attr, char *buf)
  1785. {
  1786. uint16_t mxt_delta = 0;
  1787. read_dbg_data(MXT_DELTA_MODE, test_node[2], &mxt_delta);
  1788. if (mxt_delta < 32767)
  1789. return sprintf(buf, "%u\n", mxt_delta);
  1790. else
  1791. mxt_delta = 65535 - mxt_delta;
  1792. if (mxt_delta)
  1793. return sprintf(buf, "-%u\n", mxt_delta);
  1794. else
  1795. return sprintf(buf, "%u\n", mxt_delta);
  1796. }
  1797. static ssize_t set_delta3_mode_show(struct device *dev,
  1798. struct device_attribute *attr, char *buf)
  1799. {
  1800. uint16_t mxt_delta = 0;
  1801. read_dbg_data(MXT_DELTA_MODE, test_node[3], &mxt_delta);
  1802. if (mxt_delta < 32767)
  1803. return sprintf(buf, "%u\n", mxt_delta);
  1804. else
  1805. mxt_delta = 65535 - mxt_delta;
  1806. if (mxt_delta)
  1807. return sprintf(buf, "-%u\n", mxt_delta);
  1808. else
  1809. return sprintf(buf, "%u\n", mxt_delta);
  1810. }
  1811. static ssize_t set_delta4_mode_show(struct device *dev,
  1812. struct device_attribute *attr, char *buf)
  1813. {
  1814. uint16_t mxt_delta = 0;
  1815. read_dbg_data(MXT_DELTA_MODE, test_node[4], &mxt_delta);
  1816. if (mxt_delta < 32767)
  1817. return sprintf(buf, "%u\n", mxt_delta);
  1818. else
  1819. mxt_delta = 65

Large files files are truncated, but you can click here to view the full file