ist30xx_misc.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  1. /*
  2. * Copyright (C) 2010,Imagis Technology 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. #include <linux/i2c.h>
  16. #include <linux/delay.h>
  17. #include <linux/slab.h>
  18. #include "ist30xx.h"
  19. #include "ist30xx_update.h"
  20. #include "ist30xx_misc.h"
  21. #define TSP_CH_SCREEN (1)
  22. #define TSP_CH_KEY (2)
  23. #define TOUCH_NODE_PARSING_DEBUG (0)
  24. extern struct ist30xx_data *ts_data;
  25. TSP_INFO ist30xx_tsp_info;
  26. TKEY_INFO ist30xx_tkey_info;
  27. static u32 *ist30xx_frame_buf;
  28. static u32 *ist30xx_frame_rawbuf;
  29. static u32 *ist30xx_frame_fltbuf;
  30. int ist30xx_tkey_update_info(void)
  31. {
  32. int ret = 0;
  33. u32 tkey_info1, tkey_info2, tkey_info3;
  34. TKEY_INFO *tkey = &ist30xx_tkey_info;
  35. ret = ist30xx_read_cmd(ts_data->client, CMD_GET_KEY_INFO1, &tkey_info1);
  36. if (unlikely(ret)) return ret;
  37. ret = ist30xx_read_cmd(ts_data->client, CMD_GET_KEY_INFO2, &tkey_info2);
  38. if (unlikely(ret)) return ret;
  39. ret = ist30xx_read_cmd(ts_data->client, CMD_GET_KEY_INFO3, &tkey_info3);
  40. if (unlikely(ret)) return ret;
  41. tkey->enable = ((tkey_info1 & (0xFF << 24)) ? true : false);
  42. tkey->key_num = (tkey_info1 >> 16) & 0xFF;
  43. tkey->ch_num[0] = (tkey_info2 >> 24) & 0xFF;
  44. tkey->ch_num[1] = (tkey_info2 >> 16) & 0xFF;
  45. tkey->ch_num[2] = (tkey_info2 >> 8) & 0xFF;
  46. tkey->ch_num[3] = tkey_info2 & 0xFF;
  47. tkey->ch_num[4] = (tkey_info3 >> 24) & 0xFF;
  48. return ret;
  49. }
  50. #define TSP_INFO_SWAP_XY (1 << 0)
  51. #define TSP_INFO_FLIP_X (1 << 1)
  52. #define TSP_INFO_FLIP_Y (1 << 2)
  53. int ist30xx_tsp_update_info(void)
  54. {
  55. int ret = 0;
  56. u32 tsp_ch_num, tsp_swap, tsp_dir;
  57. TSP_INFO *tsp = &ist30xx_tsp_info;
  58. ret = ist30xx_read_cmd(ts_data->client, CMD_GET_TSP_SWAP_INFO, &tsp_swap);
  59. if (unlikely(ret)) return ret;
  60. ret = ist30xx_read_cmd(ts_data->client, CMD_GET_TSP_DIRECTION, &tsp_dir);
  61. if (unlikely(ret)) return ret;
  62. ret = ist30xx_read_cmd(ts_data->client, CMD_GET_TSP_CHNUM1, &tsp_ch_num);
  63. if (unlikely(ret || !tsp_ch_num)) return ret;
  64. tsp->finger_num = IST30XX_MAX_MT_FINGERS;
  65. tsp->ch_num.rx = tsp_ch_num >> 16;
  66. tsp->ch_num.tx = tsp_ch_num & 0xFFFF;
  67. tsp->dir.swap_xy = (tsp_swap & TSP_INFO_SWAP_XY ? true : false);
  68. tsp->dir.flip_x = (tsp_swap & TSP_INFO_FLIP_X ? true : false);
  69. tsp->dir.flip_y = (tsp_swap & TSP_INFO_FLIP_Y ? true : false);
  70. tsp->node.len = tsp->ch_num.tx * tsp->ch_num.rx;
  71. tsp->height = (tsp->dir.swap_xy ? tsp->ch_num.rx : tsp->ch_num.tx);
  72. tsp->width = (tsp->dir.swap_xy ? tsp->ch_num.tx : tsp->ch_num.rx);
  73. return ret;
  74. }
  75. int ist30xx_check_valid_ch(int ch_tx, int ch_rx)
  76. {
  77. TKEY_INFO *tkey = &ist30xx_tkey_info;
  78. TSP_INFO *tsp = &ist30xx_tsp_info;
  79. if (unlikely((ch_tx > tsp->ch_num.tx) || (ch_rx > tsp->ch_num.rx)))
  80. return 0;
  81. if (tkey->enable) {
  82. if (tkey->axis_rx) {
  83. tsp_verb("%s: tx: %d, rx: %d\n", __func__, ch_tx, ch_rx);
  84. if (ch_rx == tsp->ch_num.rx - 1) {
  85. tsp_verb("%s: ch_tx: %d\n", __func__, ch_tx);
  86. if ((ch_tx == tkey->ch_num[0]) || (ch_tx == tkey->ch_num[1]) ||
  87. (ch_tx == tkey->ch_num[2]) || (ch_tx == tkey->ch_num[3]) ||
  88. (ch_tx == tkey->ch_num[4]))
  89. return TSP_CH_KEY;
  90. else
  91. return 0;
  92. }
  93. } else {
  94. if (ch_tx == tsp->ch_num.tx - 1) {
  95. if ((ch_rx == tkey->ch_num[0]) || (ch_rx == tkey->ch_num[1]) ||
  96. (ch_rx == tkey->ch_num[2]) || (ch_rx == tkey->ch_num[3]) ||
  97. (ch_rx == tkey->ch_num[4]))
  98. return TSP_CH_KEY;
  99. else
  100. return 0;
  101. }
  102. }
  103. }
  104. return TSP_CH_SCREEN;
  105. }
  106. int ist30xx_parse_touch_node(u8 flag, struct TSP_NODE_BUF *node)
  107. {
  108. #if TOUCH_NODE_PARSING_DEBUG
  109. int j;
  110. TSP_INFO *tsp = &ist30xx_tsp_info;
  111. #endif
  112. int i;
  113. u16 *raw = (u16 *)&node->raw;
  114. u16 *base = (u16 *)&node->base;
  115. u16 *filter = (u16 *)&node->filter;
  116. u32 *tmp_rawbuf = ist30xx_frame_rawbuf;
  117. u32 *tmp_fltbuf = ist30xx_frame_fltbuf;
  118. for (i = 0; i < node->len; i++) {
  119. if (flag & (NODE_FLAG_RAW | NODE_FLAG_BASE)) {
  120. *raw++ = *tmp_rawbuf & 0xFFF;
  121. *base++ = (*tmp_rawbuf >> 16) & 0xFFF;
  122. tmp_rawbuf++;
  123. }
  124. if (flag & NODE_FLAG_FILTER)
  125. *filter++ = *tmp_fltbuf++ & 0xFFF;
  126. }
  127. #if TOUCH_NODE_PARSING_DEBUG
  128. tsp_info("%s: RAW - %d * %d\n", __func__, tsp->ch_num.tx, tsp->ch_num.rx);
  129. for (i = 0; i < tsp->ch_num.tx; i++) {
  130. printk("\n[ TSP ] ");
  131. for (j = 0; j < tsp->ch_num.rx; j++)
  132. printk("%4d ", node->raw[i][j]);
  133. }
  134. tsp_info("%s: BASE - %d * %d\n", __func__, tsp->ch_num.tx, tsp->ch_num.rx);
  135. for (i = 0; i < tsp->ch_num.tx; i++) {
  136. printk("\n[ TSP ] ");
  137. for (j = 0; j < tsp->ch_num.rx; j++)
  138. printk("%4d ", node->base[i][j]);
  139. }
  140. tsp_info("%s: FILTER - %d * %d\n", __func__, tsp->ch_num.tx, tsp->ch_num.rx);
  141. for (i = 0; i < tsp->ch_num.tx; i++) {
  142. printk("\n[ TSP ] ");
  143. for (j = 0; j < tsp->ch_num.rx; j++)
  144. printk("%4d ", node->filter[i][j]);
  145. }
  146. #endif
  147. return 0;
  148. }
  149. int print_touch_node(u8 flag, struct TSP_NODE_BUF *node, char *buf, bool ch_tsp)
  150. {
  151. int i, j;
  152. int count = 0;
  153. int val = 0;
  154. const int msg_len = 128;
  155. char msg[msg_len];
  156. TSP_INFO *tsp = &ist30xx_tsp_info;
  157. if (tsp->dir.swap_xy) {
  158. } else {
  159. for (i = 0; i < tsp->ch_num.tx; i++) {
  160. for (j = 0; j < tsp->ch_num.rx; j++) {
  161. if (ch_tsp && (ist30xx_check_valid_ch(i, j) != TSP_CH_SCREEN))
  162. continue;
  163. if (flag == NODE_FLAG_RAW)
  164. val = (int)node->raw[i][j];
  165. else if (flag == NODE_FLAG_BASE)
  166. val = (int)node->base[i][j];
  167. else if (flag == NODE_FLAG_FILTER)
  168. val = (int)node->filter[i][j];
  169. else if (flag == NODE_FLAG_DIFF)
  170. val = (int)(node->raw[i][j] - node->base[i][j]);
  171. else
  172. return 0;
  173. if (val < 0) val = 0;
  174. count += snprintf(msg, msg_len, "%4d ", val);
  175. strncat(buf, msg, msg_len);
  176. }
  177. count += snprintf(msg, msg_len, "\n");
  178. strncat(buf, msg, msg_len);
  179. }
  180. }
  181. return count;
  182. }
  183. int parse_tsp_node(u8 flag, struct TSP_NODE_BUF *node, s16 *buf16)
  184. {
  185. int i, j;
  186. s16 val = 0;
  187. TSP_INFO *tsp = &ist30xx_tsp_info;
  188. if (unlikely((flag != NODE_FLAG_RAW) && (flag != NODE_FLAG_BASE) &&
  189. (flag != NODE_FLAG_FILTER) && (flag != NODE_FLAG_DIFF)))
  190. return -EPERM;
  191. if (tsp->dir.swap_xy) {
  192. } else {
  193. for (i = 0; i < tsp->ch_num.tx; i++) {
  194. for (j = 0; j < tsp->ch_num.rx; j++) {
  195. if (ist30xx_check_valid_ch(i, j) != TSP_CH_SCREEN)
  196. continue;
  197. switch ((int)flag) {
  198. case NODE_FLAG_RAW:
  199. val = (s16)node->raw[i][j];
  200. break;
  201. case NODE_FLAG_BASE:
  202. val = (s16)node->base[i][j];
  203. break;
  204. case NODE_FLAG_FILTER:
  205. val = (s16)node->filter[i][j];
  206. break;
  207. case NODE_FLAG_DIFF:
  208. val = (s16)(node->raw[i][j] - node->base[i][j]);
  209. break;
  210. }
  211. if (val < 0) val = 0;
  212. *buf16++ = val;
  213. }
  214. }
  215. }
  216. return 0;
  217. }
  218. int ist30xx_read_touch_node(u8 flag, struct TSP_NODE_BUF *node)
  219. {
  220. int ret = 0;
  221. u32 addr = IST30XXB_RAW_ADDR;
  222. if (ts_data->chip_id == IST3038_CHIP_ID)
  223. addr = 0x401002D4;
  224. ist30xx_disable_irq(ts_data);
  225. if (flag & NODE_FLAG_NO_CCP) {
  226. ret = ist30xx_cmd_run_device(ts_data->client, true);
  227. if (unlikely(ret)) goto read_tsp_node_end;
  228. ret = ist30xx_write_cmd(ts_data->client, CMD_USE_CORRECT_CP, 0);
  229. if (unlikely(ret)) goto read_tsp_node_end;
  230. }
  231. ret = ist30xx_cmd_reg(ts_data->client, CMD_ENTER_REG_ACCESS);
  232. if (unlikely(ret)) goto read_tsp_node_end;
  233. ret = ist30xx_write_cmd(ts_data->client, IST30XX_RX_CNT_ADDR, node->len);
  234. if (unlikely(ret)) goto read_tsp_node_end;
  235. if (flag & (NODE_FLAG_RAW | NODE_FLAG_BASE)) {
  236. tsp_debug("%s: Reg addr: %x, size: %d\n", __func__, addr, node->len);
  237. ret = ist30xx_read_buf(ts_data->client, addr,
  238. ist30xx_frame_rawbuf, node->len);
  239. if (unlikely(ret)) goto read_tsp_node_end;
  240. }
  241. if (flag & NODE_FLAG_FILTER) {
  242. tsp_debug("%s: Reg addr: %x, size: %d\n", __func__, IST30XXB_FILTER_ADDR, node->len);
  243. ret = ist30xx_read_buf(ts_data->client, IST30XXB_FILTER_ADDR,
  244. ist30xx_frame_fltbuf, node->len);
  245. if (unlikely(ret)) goto read_tsp_node_end;
  246. }
  247. ret = ist30xx_cmd_reg(ts_data->client, CMD_EXIT_REG_ACCESS);
  248. if (unlikely(ret)) goto read_tsp_node_end;
  249. ret = ist30xx_cmd_start_scan(ts_data->client);
  250. if (unlikely(ret)) goto read_tsp_node_end;
  251. read_tsp_node_end:
  252. ist30xx_enable_irq(ts_data);
  253. return ret;
  254. }
  255. /* sysfs: /sys/class/touch/node/refresh */
  256. ssize_t ist30xx_frame_refresh(struct device *dev, struct device_attribute *attr,
  257. char *buf)
  258. {
  259. int ret = 0;
  260. TSP_INFO *tsp = &ist30xx_tsp_info;
  261. u8 flag = NODE_FLAG_RAW | NODE_FLAG_BASE | NODE_FLAG_FILTER;
  262. ret = ist30xx_read_touch_node(flag, &tsp->node);
  263. if (unlikely(ret))
  264. ret = sprintf(buf, "cmd 1frame raw update fail\n");
  265. ret = ist30xx_parse_touch_node(flag, &tsp->node);
  266. return ret;
  267. }
  268. /* sysfs: /sys/class/touch/node/read_nocp */
  269. ssize_t ist30xx_frame_nocp(struct device *dev, struct device_attribute *attr,
  270. char *buf)
  271. {
  272. int ret = 0;
  273. TSP_INFO *tsp = &ist30xx_tsp_info;
  274. u8 flag = NODE_FLAG_RAW | NODE_FLAG_BASE | NODE_FLAG_FILTER |
  275. NODE_FLAG_NO_CCP;
  276. ret = ist30xx_read_touch_node(flag, &tsp->node);
  277. if (unlikely(ret))
  278. ret = sprintf(buf, "cmd 1frame raw update fail\n");
  279. ret = ist30xx_parse_touch_node(flag, &tsp->node);
  280. return ret;
  281. }
  282. /* sysfs: /sys/class/touch/node/base */
  283. ssize_t ist30xx_base_show(struct device *dev, struct device_attribute *attr,
  284. char *buf)
  285. {
  286. int count = 0;
  287. TSP_INFO *tsp = &ist30xx_tsp_info;
  288. buf[0] = '\0';
  289. count = sprintf(buf, "dump ist30xxb baseline(%d)\n", tsp->node.len);
  290. count += print_touch_node(NODE_FLAG_BASE, &tsp->node, buf, false);
  291. return count;
  292. }
  293. /* sysfs: /sys/class/touch/node/raw */
  294. ssize_t ist30xx_raw_show(struct device *dev, struct device_attribute *attr,
  295. char *buf)
  296. {
  297. int count = 0;
  298. TSP_INFO *tsp = &ist30xx_tsp_info;
  299. buf[0] = '\0';
  300. count = sprintf(buf, "dump ist30xxb raw(%d)\n", tsp->node.len);
  301. count += print_touch_node(NODE_FLAG_RAW, &tsp->node, buf, false);
  302. return count;
  303. }
  304. /* sysfs: /sys/class/touch/node/diff */
  305. ssize_t ist30xx_diff_show(struct device *dev, struct device_attribute *attr,
  306. char *buf)
  307. {
  308. int count = 0;
  309. TSP_INFO *tsp = &ist30xx_tsp_info;
  310. buf[0] = '\0';
  311. count = sprintf(buf, "dump ist30xxb difference (%d)\n", tsp->node.len);
  312. count += print_touch_node(NODE_FLAG_DIFF, &tsp->node, buf, false);
  313. return count;
  314. }
  315. /* sysfs: /sys/class/touch/node/filter */
  316. ssize_t ist30xx_filter_show(struct device *dev, struct device_attribute *attr,
  317. char *buf)
  318. {
  319. int count = 0;
  320. TSP_INFO *tsp = &ist30xx_tsp_info;
  321. buf[0] = '\0';
  322. count = sprintf(buf, "dump ist30xxb filter (%d)\n", tsp->node.len);
  323. count += print_touch_node(NODE_FLAG_FILTER, &tsp->node, buf, false);
  324. return count;
  325. }
  326. extern int calib_ms_delay;
  327. /* sysfs: /sys/class/touch/sys/clb */
  328. ssize_t ist30xx_calib_store(struct device *dev, struct device_attribute *attr,
  329. const char *buf, size_t size)
  330. {
  331. int ret = -1;
  332. int ms_delay;
  333. sscanf(buf, "%d", &ms_delay);
  334. if (ms_delay > 10 && ms_delay < 1000) // 1sec ~ 100sec
  335. calib_ms_delay = ms_delay;
  336. tsp_info("%s: Calibration wait time %dsec\n", __func__, calib_ms_delay / 10);
  337. ist30xx_disable_irq(ts_data);
  338. ret = ist30xx_cmd_run_device(ts_data->client, true);
  339. if (unlikely(ret)) {
  340. ist30xx_enable_irq(ts_data);
  341. return size;
  342. }
  343. ist30xx_calibrate(1);
  344. ist30xx_start(ts_data);
  345. return size;
  346. }
  347. ssize_t ist30xx_calib_show(struct device *dev, struct device_attribute *attr,
  348. char *buf)
  349. {
  350. int ret;
  351. int count = 0;
  352. u32 value;
  353. mutex_lock(&ist30xx_mutex);
  354. ist30xx_disable_irq(ts_data);
  355. ret = ist30xx_cmd_run_device(ts_data->client, true);
  356. if (unlikely(ret))
  357. goto calib_show_end;
  358. ret = ist30xx_read_cmd(ts_data->client, CMD_GET_CALIB_RESULT, &value);
  359. if (unlikely(ret)) {
  360. count = sprintf(buf, "Error Read Calibration Result\n");
  361. goto calib_show_end;
  362. }
  363. count = sprintf(buf,
  364. "Calibration Status : %d, Max raw gap : %d - (raw: %08x)\n",
  365. CALIB_TO_STATUS(value), CALIB_TO_GAP(value), value);
  366. calib_show_end:
  367. ist30xx_start(ts_data);
  368. ist30xx_enable_irq(ts_data);
  369. mutex_unlock(&ist30xx_mutex);
  370. return count;
  371. }
  372. /* sysfs: /sys/class/touch/sys/power */
  373. ssize_t ist30xx_power_store(struct device *dev, struct device_attribute *attr,
  374. const char *buf, size_t size)
  375. {
  376. u32 power_en;
  377. sscanf(buf, "%d", &power_en);
  378. tsp_info("%s: Power enable: %d\n", __func__, power_en);
  379. if (unlikely(power_en > 1)) {
  380. tsp_err("%s: Unknown argument value, %d\n", __func__, power_en);
  381. return size;
  382. }
  383. if (power_en) {
  384. mutex_lock(&ist30xx_mutex);
  385. ist30xx_internal_resume(ts_data);
  386. ist30xx_enable_irq(ts_data);
  387. mutex_unlock(&ist30xx_mutex);
  388. ist30xx_start(ts_data);
  389. } else {
  390. mutex_lock(&ist30xx_mutex);
  391. ist30xx_disable_irq(ts_data);
  392. ist30xx_internal_suspend(ts_data);
  393. mutex_unlock(&ist30xx_mutex);
  394. }
  395. return size;
  396. }
  397. extern int ist30xx_max_error_cnt;
  398. /* sysfs: /sys/class/touch/sys/errcnt */
  399. ssize_t ist30xx_errcnt_store(struct device *dev, struct device_attribute *attr,
  400. const char *buf, size_t size)
  401. {
  402. int err_cnt;
  403. sscanf(buf, "%d", &err_cnt);
  404. if (unlikely(err_cnt < 0)) return size;
  405. tsp_info("%s: Request reset error count: %d\n", __func__, err_cnt);
  406. ist30xx_max_error_cnt = err_cnt;
  407. return size;
  408. }
  409. #if IST30XX_EVENT_MODE
  410. extern int ist30xx_max_scan_retry;
  411. /* sysfs: /sys/class/touch/sys/scancnt */
  412. ssize_t ist30xx_scancnt_store(struct device *dev, struct device_attribute *attr,
  413. const char *buf, size_t size)
  414. {
  415. int retry;
  416. sscanf(buf, "%d", &retry);
  417. if (unlikely(retry < 0)) return size;
  418. tsp_info("%s: Timer scan count retry: %d\n", __func__, retry);
  419. ist30xx_max_scan_retry = retry;
  420. return size;
  421. }
  422. extern int timer_period_ms;
  423. /* sysfs: /sys/class/touch/sys/timerms */
  424. ssize_t ist30xx_timerms_store(struct device *dev, struct device_attribute *attr,
  425. const char *buf, size_t size)
  426. {
  427. int ms;
  428. sscanf(buf, "%d", &ms);
  429. if (unlikely((ms < 0) || (ms > 10000))) return size;
  430. tsp_info("%s: Timer period ms: %dms\n", __func__, ms);
  431. timer_period_ms = ms;
  432. return size;
  433. }
  434. #endif
  435. extern int ist30xx_dbg_level;
  436. /* sysfs: /sys/class/touch/sys/printk */
  437. ssize_t ist30xx_printk_store(struct device *dev, struct device_attribute *attr,
  438. const char *buf, size_t size)
  439. {
  440. int level;
  441. sscanf(buf, "%d", &level);
  442. if (unlikely((level < DEV_ERR) || (level > DEV_VERB))) return size;
  443. tsp_info("%s: prink log level: %d\n", __func__, level);
  444. ist30xx_dbg_level = level;
  445. return size;
  446. }
  447. ssize_t ist30xx_printk_show(struct device *dev, struct device_attribute *attr,
  448. char *buf)
  449. {
  450. return sprintf(buf, "prink log level: %d\n", ist30xx_dbg_level);
  451. }
  452. extern void ist30xx_scheduled_reset(void);
  453. extern int ist30xx_report_rate;
  454. /* sysfs: /sys/class/touch/sys/touch_rate */
  455. ssize_t ist30xx_touch_rate_store(struct device *dev, struct device_attribute *attr,
  456. const char *buf, size_t size)
  457. {
  458. int rate;
  459. sscanf(buf, "%d", &rate); // us
  460. if (unlikely(rate > 0xFFFF)) return size; // over 65.5ms
  461. tsp_info("touch reporting rate: %d\n", rate);
  462. ist30xx_report_rate = rate;
  463. ist30xx_scheduled_reset();
  464. return size;
  465. }
  466. extern int ist30xx_idle_rate;
  467. /* sysfs: /sys/class/touch/sys/idle_rate */
  468. ssize_t ist30xx_idle_scan_rate_store(struct device *dev, struct device_attribute *attr,
  469. const char *buf, size_t size)
  470. {
  471. int rate;
  472. sscanf(buf, "%d", &rate); // us
  473. if (unlikely(rate > 0xFFFF)) return size; // over 65.5ms
  474. tsp_info("touch idle scan rate: %d\n", rate);
  475. ist30xx_idle_rate = rate;
  476. ist30xx_scheduled_reset();
  477. return size;
  478. }
  479. extern void ist30xx_set_ta_mode(bool charging);
  480. /* sysfs: /sys/class/touch/sys/mode_ta */
  481. ssize_t ist30xx_ta_mode_store(struct device *dev, struct device_attribute *attr,
  482. const char *buf, size_t size)
  483. {
  484. int mode;
  485. sscanf(buf, "%d", &mode);
  486. if (unlikely((mode != 0) && (mode != 1))) return size; // enable/disable
  487. ist30xx_set_ta_mode(mode);
  488. return size;
  489. }
  490. extern void ist30xx_set_call_mode(int mode);
  491. /* sysfs: /sys/class/touch/sys/mode_call */
  492. ssize_t ist30xx_call_mode_store(struct device *dev, struct device_attribute *attr,
  493. const char *buf, size_t size)
  494. {
  495. int mode;
  496. sscanf(buf, "%d", &mode);
  497. if (unlikely((mode != 0) && (mode != 1))) return size; // enable/disable
  498. ist30xx_set_call_mode(mode);
  499. return size;
  500. }
  501. extern void ist30xx_set_cover_mode(int mode);
  502. /* sysfs: /sys/class/touch/sys/mode_cover */
  503. ssize_t ist30xx_cover_mode_store(struct device *dev, struct device_attribute *attr,
  504. const char *buf, size_t size)
  505. {
  506. int mode;
  507. sscanf(buf, "%d", &mode);
  508. if (unlikely((mode != 0) && (mode != 1))) return size; // enable/disable
  509. ist30xx_set_cover_mode(mode);
  510. return size;
  511. }
  512. #define TUNES_CMD_WRITE (1)
  513. #define TUNES_CMD_READ (2)
  514. #define TUNES_CMD_REG_ENTER (3)
  515. #define TUNES_CMD_REG_EXIT (4)
  516. #define TUNES_CMD_UPDATE_PARAM (5)
  517. #define TUNES_CMD_UPDATE_FW (6)
  518. #define DIRECT_ADDR(k) (IST30XXB_DA_ADDR(k))
  519. #define DIRECT_CMD_WRITE ('w')
  520. #define DIRECT_CMD_READ ('r')
  521. #pragma pack(1)
  522. typedef struct {
  523. u8 cmd;
  524. u32 addr;
  525. u16 len;
  526. } TUNES_INFO;
  527. #pragma pack()
  528. #pragma pack(1)
  529. typedef struct {
  530. char cmd;
  531. u32 addr;
  532. u32 val;
  533. } DIRECT_INFO;
  534. #pragma pack()
  535. static TUNES_INFO ist30xx_tunes;
  536. static DIRECT_INFO ist30xx_direct;
  537. static bool tunes_cmd_done = false;
  538. static bool ist30xx_reg_mode = false;
  539. /* sysfs: /sys/class/touch/sys/direct */
  540. ssize_t ist30xxb_direct_store(struct device *dev, struct device_attribute *attr,
  541. const char *buf, size_t size)
  542. {
  543. int ret = -EPERM;
  544. DIRECT_INFO *direct = (DIRECT_INFO *)&ist30xx_direct;
  545. sscanf(buf, "%c %x %x", &direct->cmd, &direct->addr, &direct->val);
  546. tsp_debug("%s: Direct cmd: %c, addr: %x, val: %x\n",
  547. __func__, direct->cmd, direct->addr, direct->val);
  548. if (unlikely((direct->cmd != DIRECT_CMD_WRITE) &&
  549. (direct->cmd != DIRECT_CMD_READ))) {
  550. tsp_warn("%s: Direct cmd is not correct!\n", __func__);
  551. return size;
  552. }
  553. if (ist30xx_intr_wait(30) < 0) return size;
  554. ts_data->status.event_mode = false;
  555. if (direct->cmd == DIRECT_CMD_WRITE) {
  556. ret = ist30xx_write_cmd(ts_data->client, DIRECT_ADDR(direct->addr),
  557. direct->val);
  558. ret = ist30xx_read_cmd(ts_data->client, DIRECT_ADDR(direct->addr),
  559. &direct->val);
  560. tsp_debug("%s: Direct write addr: %x, val: %x\n",
  561. __func__, direct->addr, direct->val);
  562. }
  563. ts_data->status.event_mode = true;
  564. return size;
  565. }
  566. #define DIRECT_BUF_COUNT (4)
  567. ssize_t ist30xxb_direct_show(struct device *dev, struct device_attribute *attr,
  568. char *buf)
  569. {
  570. int i, ret, count = 0;
  571. int len;
  572. u32 addr;
  573. u32 buf32[DIRECT_BUF_COUNT];
  574. int max_len = DIRECT_BUF_COUNT;
  575. const int msg_len = 256;
  576. char msg[msg_len];
  577. DIRECT_INFO *direct = (DIRECT_INFO *)&ist30xx_direct;
  578. if (unlikely(direct->cmd != DIRECT_CMD_READ))
  579. return sprintf(buf, "ex) echo r addr len > direct\n");
  580. len = direct->val;
  581. addr = DIRECT_ADDR(direct->addr);
  582. if (ist30xx_intr_wait(30) < 0) return 0;
  583. ts_data->status.event_mode = false;
  584. while (len > 0) {
  585. if (len < max_len) max_len = len;
  586. memset(buf32, 0, sizeof(buf32));
  587. ret = ist30xxb_burst_read(ts_data->client, addr, buf32, max_len);
  588. if (unlikely(ret)) {
  589. count = sprintf(buf, "I2C Burst read fail, addr: %x\n", addr);
  590. break;
  591. }
  592. for (i = 0; i < max_len; i++) {
  593. count += snprintf(msg, msg_len, "0x%08x ", buf32[i]);
  594. strncat(buf, msg, msg_len);
  595. }
  596. count += snprintf(msg, msg_len, "\n");
  597. strncat(buf, msg, msg_len);
  598. addr += max_len * IST30XX_DATA_LEN;
  599. len -= max_len;
  600. }
  601. ts_data->status.event_mode = true;
  602. tsp_debug("%s: %s", __func__, buf);
  603. return count;
  604. }
  605. /* sysfs: /sys/class/touch/tunes/regcmd */
  606. ssize_t tunes_regcmd_store(struct device *dev, struct device_attribute *attr,
  607. const char *buf, size_t size)
  608. {
  609. int ret = -1;
  610. u32 *buf32;
  611. memcpy(&ist30xx_tunes, buf, sizeof(ist30xx_tunes));
  612. buf += sizeof(ist30xx_tunes);
  613. buf32 = (u32 *)buf;
  614. tunes_cmd_done = false;
  615. switch (ist30xx_tunes.cmd) {
  616. case TUNES_CMD_WRITE:
  617. break;
  618. case TUNES_CMD_READ:
  619. break;
  620. case TUNES_CMD_REG_ENTER:
  621. ist30xx_disable_irq(ts_data);
  622. ret = ist30xx_cmd_run_device(ts_data->client, true);
  623. if (unlikely(ret)) goto regcmd_fail;
  624. /* enter reg access mode */
  625. ret = ist30xx_cmd_reg(ts_data->client, CMD_ENTER_REG_ACCESS);
  626. if (unlikely(ret)) goto regcmd_fail;
  627. ist30xx_reg_mode = true;
  628. break;
  629. case TUNES_CMD_REG_EXIT:
  630. /* exit reg access mode */
  631. ret = ist30xx_cmd_reg(ts_data->client, CMD_EXIT_REG_ACCESS);
  632. if (unlikely(ret)) goto regcmd_fail;
  633. ret = ist30xx_cmd_start_scan(ts_data->client);
  634. if (unlikely(ret)) goto regcmd_fail;
  635. ist30xx_reg_mode = false;
  636. ist30xx_enable_irq(ts_data);
  637. break;
  638. default:
  639. ist30xx_enable_irq(ts_data);
  640. return size;
  641. }
  642. tunes_cmd_done = true;
  643. return size;
  644. regcmd_fail:
  645. tsp_err("%s: Tunes regcmd i2c_fail, ret=%d\n", __func__, ret);
  646. return size;
  647. }
  648. ssize_t tunes_regcmd_show(struct device *dev, struct device_attribute *attr,
  649. char *buf)
  650. {
  651. int size;
  652. size = sprintf(buf, "cmd: 0x%02x, addr: 0x%08x, len: 0x%04x\n",
  653. ist30xx_tunes.cmd, ist30xx_tunes.addr, ist30xx_tunes.len);
  654. return size;
  655. }
  656. #define MAX_WRITE_LEN (1)
  657. /* sysfs: /sys/class/touch/tunes/reg */
  658. ssize_t tunes_reg_store(struct device *dev, struct device_attribute *attr,
  659. const char *buf, size_t size)
  660. {
  661. int ret;
  662. u32 *buf32 = (u32 *)buf;
  663. int waddr, wcnt = 0, len = 0;
  664. if (unlikely(ist30xx_tunes.cmd != TUNES_CMD_WRITE)) {
  665. tsp_err("%s: error, IST30XX_REG_CMD is not correct!\n", __func__);
  666. return size;
  667. }
  668. if (unlikely(!ist30xx_reg_mode)) {
  669. tsp_err("%s: error, IST30XX_REG_CMD is not ready!\n", __func__);
  670. return size;
  671. }
  672. if (unlikely(!tunes_cmd_done)) {
  673. tsp_err("%s: error, IST30XX_REG_CMD is not ready!\n", __func__);
  674. return size;
  675. }
  676. waddr = ist30xx_tunes.addr;
  677. if (ist30xx_tunes.len >= MAX_WRITE_LEN)
  678. len = MAX_WRITE_LEN;
  679. else
  680. len = ist30xx_tunes.len;
  681. while (wcnt < ist30xx_tunes.len) {
  682. ret = ist30xx_write_buf(ts_data->client, waddr, buf32, len);
  683. if (unlikely(ret)) {
  684. tsp_err("%s: Tunes regstore i2c_fail, ret=%d\n", __func__, ret);
  685. return size;
  686. }
  687. wcnt += len;
  688. if ((ist30xx_tunes.len - wcnt) < MAX_WRITE_LEN)
  689. len = ist30xx_tunes.len - wcnt;
  690. buf32 += MAX_WRITE_LEN;
  691. waddr += MAX_WRITE_LEN * IST30XX_DATA_LEN;
  692. }
  693. tunes_cmd_done = false;
  694. return size;
  695. }
  696. ssize_t tunes_reg_show(struct device *dev, struct device_attribute *attr,
  697. char *buf)
  698. {
  699. int ret;
  700. int size;
  701. u32 *buf32 = (u32 *)buf;
  702. #if I2C_MONOPOLY_MODE
  703. unsigned long flags;
  704. #endif
  705. if (unlikely(ist30xx_tunes.cmd != TUNES_CMD_READ)) {
  706. tsp_err("%s: error, IST30XX_REG_CMD is not correct!\n", __func__);
  707. return 0;
  708. }
  709. if (unlikely(!tunes_cmd_done)) {
  710. tsp_err("%s: error, IST30XX_REG_CMD is not ready!\n", __func__);
  711. return 0;
  712. }
  713. size = ist30xx_tunes.len;
  714. ret = ist30xx_write_cmd(ts_data->client, IST30XX_RX_CNT_ADDR, size);
  715. if (unlikely(ret)) {
  716. tsp_err("%s: Tunes regshow i2c_fail, ret=%d\n", __func__, ret);
  717. return 0;
  718. }
  719. #if I2C_MONOPOLY_MODE
  720. local_irq_save(flags); // Activated only when the GPIO I2C is used
  721. #endif
  722. ret = ist30xx_read_buf(ts_data->client, ist30xx_tunes.addr, buf32, size);
  723. #if I2C_MONOPOLY_MODE
  724. local_irq_restore(flags); // Activated only when the GPIO I2C is used
  725. #endif
  726. if (unlikely(ret)) {
  727. tsp_err("%s: Tunes regshow i2c_fail, ret=%d\n", __func__, ret);
  728. return size;
  729. }
  730. size = ist30xx_tunes.len * IST30XX_DATA_LEN;
  731. tunes_cmd_done = false;
  732. return size;
  733. }
  734. /* sysfs: /sys/class/touch/tunes/firmware */
  735. ssize_t tunes_fw_store(struct device *dev, struct device_attribute *attr,
  736. const char *buf, size_t size)
  737. {
  738. ist30xx_get_update_info(ts_data, buf, size);
  739. mutex_lock(&ist30xx_mutex);
  740. ist30xx_fw_update(ts_data->client, buf, size, true);
  741. mutex_unlock(&ist30xx_mutex);
  742. ist30xx_calibrate(1);
  743. ist30xx_init_touch_driver(ts_data);
  744. return size;
  745. }
  746. /* sysfs: /sys/class/touch/tunes/adb */
  747. ssize_t tunes_adb_store(struct device *dev, struct device_attribute *attr,
  748. const char *buf, size_t size)
  749. {
  750. int ret;
  751. char *tmp, *ptr;
  752. char token[9];
  753. u32 cmd, addr, len, val;
  754. int write_len;
  755. sscanf(buf, "%x %x %x", &cmd, &addr, &len);
  756. switch (cmd) {
  757. case TUNES_CMD_WRITE: /* write cmd */
  758. write_len = 0;
  759. ptr = (char *)(buf + 15);
  760. while (write_len < len) {
  761. memcpy(token, ptr, 8);
  762. token[8] = 0;
  763. val = simple_strtoul(token, &tmp, 16);
  764. ret = ist30xx_write_buf(ts_data->client, addr, &val, 1);
  765. if (unlikely(ret)) {
  766. tsp_err("%s: Tunes regstore i2c_fail, ret=%d\n", __func__, ret);
  767. return size;
  768. }
  769. ptr += 8;
  770. write_len++;
  771. addr += 4;
  772. }
  773. break;
  774. case TUNES_CMD_READ: /* read cmd */
  775. ist30xx_tunes.cmd = cmd;
  776. ist30xx_tunes.addr = addr;
  777. ist30xx_tunes.len = len;
  778. break;
  779. case TUNES_CMD_REG_ENTER: /* enter */
  780. ist30xx_disable_irq(ts_data);
  781. ret = ist30xx_cmd_run_device(ts_data->client, true);
  782. if (unlikely(ret < 0)) goto cmd_fail;
  783. ret = ist30xx_cmd_reg(ts_data->client, CMD_ENTER_REG_ACCESS);
  784. if (unlikely(ret < 0)) goto cmd_fail;
  785. ist30xx_reg_mode = true;
  786. break;
  787. case TUNES_CMD_REG_EXIT: /* exit */
  788. if (ist30xx_reg_mode == true) {
  789. ret = ist30xx_cmd_reg(ts_data->client, CMD_EXIT_REG_ACCESS);
  790. if (unlikely(ret < 0)) goto cmd_fail;
  791. ret = ist30xx_cmd_start_scan(ts_data->client);
  792. if (unlikely(ret < 0)) goto cmd_fail;
  793. ist30xx_reg_mode = false;
  794. ist30xx_enable_irq(ts_data);
  795. }
  796. break;
  797. default:
  798. break;
  799. }
  800. return size;
  801. cmd_fail:
  802. tsp_err("%s: Tunes adb i2c_fail\n", __func__);
  803. return size;
  804. }
  805. ssize_t tunes_adb_show(struct device *dev, struct device_attribute *attr,
  806. char *buf)
  807. {
  808. int ret;
  809. int i, len, size = 0;
  810. char reg_val[10];
  811. #if I2C_MONOPOLY_MODE
  812. unsigned long flags;
  813. #endif
  814. ret = ist30xx_write_cmd(ts_data->client, IST30XX_RX_CNT_ADDR, ist30xx_tunes.len);
  815. if (unlikely(ret)) {
  816. tsp_err("%s: Tunes regshow i2c_fail, ret=%d\n", __func__, ret);
  817. return size;
  818. }
  819. #if I2C_MONOPOLY_MODE
  820. local_irq_save(flags);
  821. #endif
  822. ret = ist30xx_read_buf(ts_data->client, ist30xx_tunes.addr,
  823. ist30xx_frame_buf, ist30xx_tunes.len);
  824. #if I2C_MONOPOLY_MODE
  825. local_irq_restore(flags);
  826. #endif
  827. if (unlikely(ret)) {
  828. tsp_err("%s: Tunes regshow i2c_fail, ret=%d\n", __func__, ret);
  829. return size;
  830. }
  831. size = 0;
  832. buf[0] = 0;
  833. len = sprintf(reg_val, "%08x", ist30xx_tunes.addr);
  834. strcat(buf, reg_val);
  835. size += len;
  836. for (i = 0; i < ist30xx_tunes.len; i++) {
  837. len = sprintf(reg_val, "%08x", ist30xx_frame_buf[i]);
  838. strcat(buf, reg_val);
  839. size += len;
  840. }
  841. return size;
  842. }
  843. #if IST30XX_ALGORITHM_MODE
  844. /* sysfs: /sys/class/touch/tunes/algorithm */
  845. extern u32 ist30xx_algr_addr, ist30xx_algr_size;
  846. ssize_t ist30xx_algr_store(struct device *dev, struct device_attribute *attr,
  847. const char *buf, size_t size)
  848. {
  849. sscanf(buf, "%x %d", &ist30xx_algr_addr, &ist30xx_algr_size);
  850. tsp_info("%s: Algorithm addr: 0x%x, count: %d\n",
  851. __func__, ist30xx_algr_addr, ist30xx_algr_size);
  852. ist30xx_algr_addr |= IST30XXB_ACCESS_ADDR;
  853. return size;
  854. }
  855. ssize_t ist30xx_algr_show(struct device *dev, struct device_attribute *attr,
  856. char *buf)
  857. {
  858. int ret;
  859. u32 algr_addr;
  860. int count = 0;
  861. ret = ist30xx_read_cmd(ts_data->client, IST30XXB_MEM_ALGORITHM, &algr_addr);
  862. if (unlikely(ret)) {
  863. tsp_warn("%s: Algorithm mem addr read fail!\n", __func__);
  864. return 0;
  865. }
  866. tsp_info("%s: algr_addr(0x%x): 0x%x\n", __func__, IST30XXB_MEM_ALGORITHM, algr_addr);
  867. count = sprintf(buf, "Algorithm addr : 0x%x\n", algr_addr);
  868. return count;
  869. }
  870. #endif // IST30XX_ALGORITHM_MODE
  871. /* sysfs: /sys/class/touch/tunes/intr_debug */
  872. extern u32 intr_debug_addr, intr_debug_size;
  873. ssize_t intr_debug_store(struct device *dev, struct device_attribute *attr,
  874. const char *buf, size_t size)
  875. {
  876. sscanf(buf, "%x %d", &intr_debug_addr, &intr_debug_size);
  877. tsp_info("Interrupt debug addr: 0x%x, count: %d\n",
  878. intr_debug_addr, intr_debug_size);
  879. intr_debug_addr |= IST30XXB_ACCESS_ADDR;
  880. return size;
  881. }
  882. ssize_t intr_debug_show(struct device *dev, struct device_attribute *attr,
  883. char *buf)
  884. {
  885. int count = 0;
  886. tsp_info("intr_debug_addr(0x%x): %d\n", intr_debug_addr, intr_debug_size);
  887. count = sprintf(buf, "intr_debug_addr(0x%x): %d\n",
  888. intr_debug_addr, intr_debug_size);
  889. return count;
  890. }
  891. #define MISC_DEFAULT_ATTR (0644)
  892. /* sysfs : node */
  893. static DEVICE_ATTR(refresh, MISC_DEFAULT_ATTR, ist30xx_frame_refresh, NULL);
  894. static DEVICE_ATTR(nocp, MISC_DEFAULT_ATTR, ist30xx_frame_nocp, NULL);
  895. static DEVICE_ATTR(filter, MISC_DEFAULT_ATTR, ist30xx_filter_show, NULL);
  896. static DEVICE_ATTR(raw, MISC_DEFAULT_ATTR, ist30xx_raw_show, NULL);
  897. static DEVICE_ATTR(base, MISC_DEFAULT_ATTR, ist30xx_base_show, NULL);
  898. static DEVICE_ATTR(diff, MISC_DEFAULT_ATTR, ist30xx_diff_show, NULL);
  899. /* sysfs : sys */
  900. static DEVICE_ATTR(printk, MISC_DEFAULT_ATTR, ist30xx_printk_show, ist30xx_printk_store);
  901. static DEVICE_ATTR(direct, MISC_DEFAULT_ATTR, ist30xxb_direct_show, ist30xxb_direct_store);
  902. static DEVICE_ATTR(clb, MISC_DEFAULT_ATTR, ist30xx_calib_show, ist30xx_calib_store);
  903. static DEVICE_ATTR(tsp_power, MISC_DEFAULT_ATTR, NULL, ist30xx_power_store);
  904. static DEVICE_ATTR(errcnt, MISC_DEFAULT_ATTR, NULL, ist30xx_errcnt_store);
  905. #if IST30XX_EVENT_MODE
  906. static DEVICE_ATTR(scancnt, MISC_DEFAULT_ATTR, NULL, ist30xx_scancnt_store);
  907. static DEVICE_ATTR(timerms, MISC_DEFAULT_ATTR, NULL, ist30xx_timerms_store);
  908. #endif
  909. static DEVICE_ATTR(report_rate, MISC_DEFAULT_ATTR, NULL, ist30xx_touch_rate_store);
  910. static DEVICE_ATTR(idle_rate, MISC_DEFAULT_ATTR, NULL, ist30xx_idle_scan_rate_store);
  911. static DEVICE_ATTR(mode_ta, MISC_DEFAULT_ATTR, NULL, ist30xx_ta_mode_store);
  912. static DEVICE_ATTR(mode_call, MISC_DEFAULT_ATTR, NULL, ist30xx_call_mode_store);
  913. static DEVICE_ATTR(mode_cover, MISC_DEFAULT_ATTR, NULL, ist30xx_cover_mode_store);
  914. /* sysfs : tunes */
  915. static DEVICE_ATTR(regcmd, MISC_DEFAULT_ATTR, tunes_regcmd_show, tunes_regcmd_store);
  916. static DEVICE_ATTR(reg, MISC_DEFAULT_ATTR, tunes_reg_show, tunes_reg_store);
  917. static DEVICE_ATTR(tunes_fw, MISC_DEFAULT_ATTR, NULL, tunes_fw_store);
  918. static DEVICE_ATTR(adb, MISC_DEFAULT_ATTR, tunes_adb_show, tunes_adb_store);
  919. #if IST30XX_ALGORITHM_MODE
  920. static DEVICE_ATTR(algorithm, MISC_DEFAULT_ATTR, ist30xx_algr_show, ist30xx_algr_store);
  921. #endif
  922. static DEVICE_ATTR(intr_debug, MISC_DEFAULT_ATTR, intr_debug_show, intr_debug_store);
  923. static struct attribute *node_attributes[] = {
  924. &dev_attr_refresh.attr,
  925. &dev_attr_nocp.attr,
  926. &dev_attr_filter.attr,
  927. &dev_attr_raw.attr,
  928. &dev_attr_base.attr,
  929. &dev_attr_diff.attr,
  930. NULL,
  931. };
  932. static struct attribute *sys_attributes[] = {
  933. &dev_attr_printk.attr,
  934. &dev_attr_direct.attr,
  935. &dev_attr_clb.attr,
  936. &dev_attr_tsp_power.attr,
  937. &dev_attr_errcnt.attr,
  938. #if IST30XX_EVENT_MODE
  939. &dev_attr_scancnt.attr,
  940. &dev_attr_timerms.attr,
  941. #endif
  942. &dev_attr_report_rate.attr,
  943. &dev_attr_idle_rate.attr,
  944. &dev_attr_mode_ta.attr,
  945. &dev_attr_mode_call.attr,
  946. &dev_attr_mode_cover.attr,
  947. NULL,
  948. };
  949. static struct attribute *tunes_attributes[] = {
  950. &dev_attr_regcmd.attr,
  951. &dev_attr_reg.attr,
  952. &dev_attr_tunes_fw.attr,
  953. &dev_attr_adb.attr,
  954. #if IST30XX_ALGORITHM_MODE
  955. &dev_attr_algorithm.attr,
  956. #endif
  957. &dev_attr_intr_debug.attr,
  958. NULL,
  959. };
  960. static struct attribute_group node_attr_group = {
  961. .attrs = node_attributes,
  962. };
  963. static struct attribute_group sys_attr_group = {
  964. .attrs = sys_attributes,
  965. };
  966. static struct attribute_group tunes_attr_group = {
  967. .attrs = tunes_attributes,
  968. };
  969. extern struct class *ist30xx_class;
  970. struct device *ist30xx_sys_dev;
  971. struct device *ist30xx_tunes_dev;
  972. struct device *ist30xx_node_dev;
  973. int ist30xx_init_misc_sysfs(void)
  974. {
  975. /* /sys/class/touch/sys */
  976. ist30xx_sys_dev = device_create(ist30xx_class, NULL, 0, NULL, "sys");
  977. /* /sys/class/touch/sys/... */
  978. if (unlikely(sysfs_create_group(&ist30xx_sys_dev->kobj,
  979. &sys_attr_group)))
  980. tsp_err("Failed to create sysfs group(%s)!\n", "sys");
  981. /* /sys/class/touch/tunes */
  982. ist30xx_tunes_dev = device_create(ist30xx_class, NULL, 0, NULL, "tunes");
  983. /* /sys/class/touch/tunes/... */
  984. if (unlikely(sysfs_create_group(&ist30xx_tunes_dev->kobj,
  985. &tunes_attr_group)))
  986. tsp_err("Failed to create sysfs group(%s)!\n", "tunes");
  987. /* /sys/class/touch/node */
  988. ist30xx_node_dev = device_create(ist30xx_class, NULL, 0, NULL, "node");
  989. /* /sys/class/touch/node/... */
  990. if (unlikely(sysfs_create_group(&ist30xx_node_dev->kobj,
  991. &node_attr_group)))
  992. tsp_err("Failed to create sysfs group(%s)!\n", "node");
  993. ist30xx_frame_buf = kmalloc(4096, GFP_KERNEL);
  994. ist30xx_frame_rawbuf = kmalloc(4096, GFP_KERNEL);
  995. ist30xx_frame_fltbuf = kmalloc(4096, GFP_KERNEL);
  996. if (!ist30xx_frame_buf || !ist30xx_frame_rawbuf || !ist30xx_frame_fltbuf)
  997. return -ENOMEM;
  998. return 0;
  999. }