fts_sec.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. #ifdef SEC_TSP_FACTORY_TEST
  2. #define TSP_FACTEST_RESULT_PASS 2
  3. #define TSP_FACTEST_RESULT_FAIL 1
  4. #define TSP_FACTEST_RESULT_NONE 0
  5. #define BUFFER_MAX (256 * 1024) - 16
  6. #define READ_CHUNK_SIZE 128 // (2 * 1024) - 16
  7. enum {
  8. TYPE_RAW_DATA = 0,
  9. TYPE_FILTERED_DATA = 2,
  10. TYPE_STRENGTH_DATA = 4,
  11. TYPE_BASELINE_DATA = 6
  12. };
  13. #ifdef FTS_SUPPORT_TOUCH_KEY
  14. enum {
  15. TYPE_TOUCHKEY_RAW = 0x34,
  16. TYPE_TOUCHKEY_STRENGTH = 0x36
  17. };
  18. #endif // FTS_SUPPORT_TOUCH_KEY
  19. enum {
  20. BUILT_IN = 0,
  21. UMS,
  22. };
  23. enum CMD_STATUS {
  24. CMD_STATUS_WAITING = 0,
  25. CMD_STATUS_RUNNING,
  26. CMD_STATUS_OK,
  27. CMD_STATUS_FAIL,
  28. CMD_STATUS_NOT_APPLICABLE,
  29. };
  30. static void fw_update(void *device_data);
  31. static void get_fw_ver_bin(void *device_data);
  32. static void get_fw_ver_ic(void *device_data);
  33. static void get_config_ver(void *device_data);
  34. static void get_threshold(void *device_data);
  35. static void module_off_master(void *device_data);
  36. static void module_on_master(void *device_data);
  37. static void get_chip_vendor(void *device_data);
  38. static void get_chip_name(void *device_data);
  39. static void get_x_num(void *device_data);
  40. static void get_y_num(void *device_data);
  41. static void run_reference_read(void *device_data);
  42. static void get_reference(void *device_data);
  43. static void run_rawcap_read(void *device_data);
  44. static void get_rawcap(void *device_data);
  45. static void run_delta_read(void *device_data);
  46. static void get_delta(void *device_data);
  47. static void run_abscap_read(void *device_data);
  48. static void run_absdelta_read(void *device_data);
  49. static void run_trx_short_test(void *device_data);
  50. static void set_tsp_test_result(void *device_data);
  51. static void get_tsp_test_result(void *device_data);
  52. static void hover_enable(void *device_data);
  53. static void hover_no_sleep_enable(void *device_data);
  54. static void glove_mode(void *device_data);
  55. static void get_glove_sensitivity(void *device_data);
  56. static void clear_cover_mode(void *device_data);
  57. static void fast_glove_mode(void *device_data);
  58. static void report_rate(void *device_data);
  59. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  60. static void interrupt_control(void *device_data);
  61. #endif
  62. #ifdef FTS_SUPPORT_TOUCH_KEY
  63. static int read_touchkey_data(struct fts_ts_info *info, unsigned char type, unsigned int keycode);
  64. #endif
  65. #if defined(TOUCH_BOOSTER_DVFS)
  66. static void boost_level(void *device_data);
  67. #endif
  68. static void not_support_cmd(void *device_data);
  69. static ssize_t store_cmd(struct device *dev, struct device_attribute *devattr,
  70. const char *buf, size_t count);
  71. static ssize_t show_cmd_status(struct device *dev,
  72. struct device_attribute *devattr, char *buf);
  73. static ssize_t show_cmd_result(struct device *dev,
  74. struct device_attribute *devattr, char *buf);
  75. static ssize_t cmd_list_show(struct device *dev,
  76. struct device_attribute *attr, char *buf);
  77. #define FT_CMD(name, func) .cmd_name = name, .cmd_func = func
  78. struct ft_cmd {
  79. struct list_head list;
  80. const char *cmd_name;
  81. void (*cmd_func) (void *device_data);
  82. };
  83. struct ft_cmd ft_cmds[] = {
  84. {FT_CMD("fw_update", fw_update),},
  85. {FT_CMD("get_fw_ver_bin", get_fw_ver_bin),},
  86. {FT_CMD("get_fw_ver_ic", get_fw_ver_ic),},
  87. {FT_CMD("get_config_ver", get_config_ver),},
  88. {FT_CMD("get_threshold", get_threshold),},
  89. {FT_CMD("module_off_master", module_off_master),},
  90. {FT_CMD("module_on_master", module_on_master),},
  91. {FT_CMD("module_off_slave", not_support_cmd),},
  92. {FT_CMD("module_on_slave", not_support_cmd),},
  93. {FT_CMD("get_chip_vendor", get_chip_vendor),},
  94. {FT_CMD("get_chip_name", get_chip_name),},
  95. {FT_CMD("get_x_num", get_x_num),},
  96. {FT_CMD("get_y_num", get_y_num),},
  97. {FT_CMD("run_reference_read", run_reference_read),},
  98. {FT_CMD("get_reference", get_reference),},
  99. {FT_CMD("run_rawcap_read", run_rawcap_read),},
  100. {FT_CMD("get_rawcap", get_rawcap),},
  101. {FT_CMD("run_delta_read", run_delta_read),},
  102. {FT_CMD("get_delta", get_delta),},
  103. {FT_CMD("run_abscap_read" , run_abscap_read),},
  104. {FT_CMD("run_absdelta_read", run_absdelta_read),},
  105. {FT_CMD("run_trx_short_test", run_trx_short_test),},
  106. {FT_CMD("set_tsp_test_result", set_tsp_test_result),},
  107. {FT_CMD("get_tsp_test_result", get_tsp_test_result),},
  108. {FT_CMD("hover_enable", hover_enable),},
  109. {FT_CMD("hover_no_sleep_enable", hover_no_sleep_enable),},
  110. {FT_CMD("glove_mode", glove_mode),},
  111. {FT_CMD("get_glove_sensitivity", get_glove_sensitivity),},
  112. {FT_CMD("clear_cover_mode", clear_cover_mode),},
  113. {FT_CMD("fast_glove_mode", fast_glove_mode),},
  114. {FT_CMD("report_rate", report_rate),},
  115. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  116. {FT_CMD("interrupt_control", interrupt_control),},
  117. #endif
  118. #if defined(TOUCH_BOOSTER_DVFS)
  119. {FT_CMD("boost_level", boost_level),},
  120. #endif
  121. {FT_CMD("not_support_cmd", not_support_cmd),},
  122. };
  123. static DEVICE_ATTR(cmd, S_IWUSR | S_IWGRP, NULL, store_cmd);
  124. static DEVICE_ATTR(cmd_status, S_IRUGO, show_cmd_status, NULL);
  125. static DEVICE_ATTR(cmd_result, S_IRUGO, show_cmd_result, NULL);
  126. static DEVICE_ATTR(cmd_list, S_IRUGO, cmd_list_show, NULL);
  127. static struct attribute *sec_touch_facotry_attributes[] = {
  128. &dev_attr_cmd.attr,
  129. &dev_attr_cmd_status.attr,
  130. &dev_attr_cmd_result.attr,
  131. &dev_attr_cmd_list.attr,
  132. NULL,
  133. };
  134. static struct attribute_group sec_touch_factory_attr_group = {
  135. .attrs = sec_touch_facotry_attributes,
  136. };
  137. #ifdef FTS_SUPPORT_TOUCH_KEY
  138. static int read_touchkey_data(struct fts_ts_info *info, unsigned char type, unsigned int keycode)
  139. {
  140. unsigned char pCMD[8] = { 0xD0, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 };
  141. unsigned char buf[8] = { 0 };
  142. int i;
  143. int ret = 0;
  144. pCMD[2] = type;
  145. ret = fts_read_reg(info, &pCMD[0], 3, buf, 2);
  146. if (ret >= 0) {
  147. pCMD[1] = buf[1];
  148. pCMD[2] = buf[0];
  149. } else {
  150. return -1;
  151. }
  152. ret = fts_read_reg(info, &pCMD[0], 3, buf, 8);
  153. if (ret < 0) {
  154. return -2;
  155. }
  156. for (i = 0 ; i < info->board->num_touchkey ; i++)
  157. if (info->board->touchkey[i].keycode==keycode) {
  158. printk("the return value is %d \n", *(unsigned short *)&buf[i*2]);
  159. return (*(unsigned short *)&buf[i*2]);
  160. }
  161. return -3;
  162. }
  163. #endif
  164. #ifdef FTS_SUPPORT_TOUCH_KEY
  165. static ssize_t touchkey_d_menu_show(struct device *dev,
  166. struct device_attribute *attr, char *buf){
  167. struct fts_ts_info *info = dev_get_drvdata(dev);
  168. int value;
  169. if (info->touch_stopped) {
  170. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n", __func__);
  171. return snprintf(buf, sizeof(buf), "%s", "TSP turned off");
  172. }
  173. value = read_touchkey_data(info, TYPE_TOUCHKEY_STRENGTH, KEY_DUMMY_MENU);
  174. if (value<0) {
  175. return snprintf(buf, sizeof(buf), "Fail");
  176. }
  177. printk("touchkey_d_menu_show value is %d \n",value);
  178. return snprintf(buf, sizeof(buf), "%d\n", value);
  179. }
  180. static ssize_t touchkey_d_back_show(struct device *dev,
  181. struct device_attribute *attr, char *buf){
  182. struct fts_ts_info *info = dev_get_drvdata(dev);
  183. int value;
  184. if (info->touch_stopped) {
  185. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n", __func__);
  186. return snprintf(buf, sizeof(buf), "%s", "TSP turned off");
  187. }
  188. value = read_touchkey_data(info, TYPE_TOUCHKEY_STRENGTH, KEY_BACK);
  189. if (value<0) {
  190. return snprintf(buf, sizeof(buf), "Fail");
  191. }
  192. printk("the touchkey_d_back_show value is %d \n",value);
  193. return snprintf(buf, sizeof(buf), "%d\n", value);
  194. }
  195. static ssize_t touchkey_recent_show(struct device *dev,
  196. struct device_attribute *attr, char *buf){
  197. struct fts_ts_info *info = dev_get_drvdata(dev);
  198. int value;
  199. if (info->touch_stopped) {
  200. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n", __func__);
  201. return snprintf(buf, sizeof(buf), "%s", "TSP turned off");
  202. }
  203. value = read_touchkey_data(info, TYPE_TOUCHKEY_STRENGTH, KEY_RECENT);
  204. if (value<0) {
  205. return snprintf(buf, sizeof(buf), "Fail");
  206. }
  207. printk("touchkey_recent_show value is %d \n",value);
  208. return snprintf(buf, sizeof(buf), "%d\n", value);
  209. }
  210. static ssize_t touchkey_back_show(struct device *dev,
  211. struct device_attribute *attr, char *buf){
  212. struct fts_ts_info *info = dev_get_drvdata(dev);
  213. int value;
  214. if (info->touch_stopped) {
  215. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n", __func__);
  216. return snprintf(buf, sizeof(buf), "%s", "TSP turned off");
  217. }
  218. value = read_touchkey_data(info, TYPE_TOUCHKEY_STRENGTH, KEY_BACK);
  219. if (value<0) {
  220. return snprintf(buf, sizeof(buf), "Fail");
  221. }
  222. printk("the touchkey_back_show value is %d \n",value);
  223. return snprintf(buf, sizeof(buf), "%d\n", value);
  224. }
  225. static ssize_t get_touchkey_threshold(struct device *dev,
  226. struct device_attribute *attr, char *buf)
  227. {
  228. struct fts_ts_info *info = dev_get_drvdata(dev);
  229. unsigned char cmd[4] =
  230. { 0xB2, 0x01, 0xEF, 0x02 };
  231. int timeout=0;
  232. if (info->touch_stopped) {
  233. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n", __func__);
  234. return snprintf(buf, sizeof(buf), "%s", "TSP turned off");
  235. }
  236. info->touchkey_threshold = -1;
  237. fts_write_reg(info, &cmd[0], 4);
  238. info->cmd_state = CMD_STATUS_RUNNING;
  239. while (info->touchkey_threshold<0) {
  240. if (timeout++>30) {
  241. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Time out\n", __func__);
  242. return snprintf(buf, sizeof(buf), "%s", "Time out");
  243. }
  244. msleep(10);
  245. }
  246. printk("touchkey_threshold value is %d \n",info->touchkey_threshold);
  247. return snprintf(buf, sizeof(buf), "%d\n", info->touchkey_threshold);
  248. }
  249. static ssize_t touchkey_report_dummy_key_show(struct device *dev,
  250. struct device_attribute *attr, char *buf)
  251. {
  252. struct fts_ts_info *data = dev_get_drvdata(dev);
  253. return sprintf(buf, "%s\n", data->report_dummy_key? "True" : "False");
  254. }
  255. static ssize_t touchkey_report_dummy_key_store(struct device *dev,
  256. struct device_attribute *attr, const char *buf,
  257. size_t size)
  258. {
  259. struct fts_ts_info *data = dev_get_drvdata(dev);
  260. int input;
  261. int ret;
  262. ret = sscanf(buf, "%d", &input);
  263. if (ret != 1) {
  264. dev_info(&data->client->dev, "%s: %d err\n",
  265. __func__, ret);
  266. return size;
  267. }
  268. if (input)
  269. data->report_dummy_key = true;
  270. else
  271. data->report_dummy_key = false;
  272. return size;
  273. }
  274. static DEVICE_ATTR(touchkey_d_menu, S_IRUGO | S_IWUSR | S_IWGRP, touchkey_d_menu_show, NULL);
  275. static DEVICE_ATTR(touchkey_d_back, S_IRUGO | S_IWUSR | S_IWGRP, touchkey_d_back_show, NULL);
  276. static DEVICE_ATTR(touchkey_recent, S_IRUGO | S_IWUSR | S_IWGRP, touchkey_recent_show, NULL);
  277. static DEVICE_ATTR(touchkey_back, S_IRUGO | S_IWUSR | S_IWGRP, touchkey_back_show, NULL);
  278. static DEVICE_ATTR(touchkey_threshold, S_IRUGO | S_IWUSR | S_IWGRP, get_touchkey_threshold, NULL);
  279. //static DEVICE_ATTR(brightness, S_IRUGO | S_IWUSR | S_IWGRP, NULL, touchkey_led_control);
  280. static DEVICE_ATTR(extra_button_event, S_IRUGO | S_IWUSR | S_IWGRP,
  281. touchkey_report_dummy_key_show, touchkey_report_dummy_key_store);
  282. static struct attribute *touchkey_attributes[] = {
  283. &dev_attr_touchkey_d_menu.attr,
  284. &dev_attr_touchkey_d_back.attr,
  285. &dev_attr_touchkey_recent.attr,
  286. &dev_attr_touchkey_back.attr,
  287. &dev_attr_touchkey_threshold.attr,
  288. //&dev_attr_brightness.attr,
  289. &dev_attr_extra_button_event.attr,
  290. NULL,
  291. };
  292. static struct attribute_group sec_touchkey_attr_group = {
  293. .attrs = touchkey_attributes,
  294. };
  295. #endif
  296. static int fts_check_index(void *device_data)
  297. {
  298. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  299. char buff[CMD_STR_LEN] = { 0 };
  300. int node;
  301. if (info->cmd_param[0] < 0
  302. || info->cmd_param[0] >= info->SenseChannelLength
  303. || info->cmd_param[1] < 0
  304. || info->cmd_param[1] >= info->ForceChannelLength) {
  305. snprintf(buff, sizeof(buff), "%s", "NG");
  306. strncat(info->cmd_result, buff, strnlen(buff, sizeof(buff)));
  307. info->cmd_state = 3;
  308. tsp_debug_info(true, &info->client->dev, "%s: parameter error: %u,%u\n",
  309. __func__, info->cmd_param[0], info->cmd_param[1]);
  310. node = -1;
  311. return node;
  312. }
  313. node =
  314. info->cmd_param[1] * info->SenseChannelLength + info->cmd_param[0];
  315. tsp_debug_info(true, &info->client->dev, "%s: node = %d\n", __func__, node);
  316. return node;
  317. }
  318. static ssize_t store_cmd(struct device *dev, struct device_attribute *devattr,
  319. const char *buf, size_t count)
  320. {
  321. struct fts_ts_info *info = dev_get_drvdata(dev);
  322. char *cur, *start, *end;
  323. char buff[CMD_STR_LEN] = { 0 };
  324. int len, i;
  325. struct ft_cmd *ft_cmd_ptr = NULL;
  326. char delim = ',';
  327. bool cmd_found = false;
  328. int param_cnt = 0;
  329. if (!info) {
  330. printk(KERN_ERR "%s: No platform data found\n",
  331. __func__);
  332. return -EINVAL;
  333. }
  334. if (!info->input_dev) {
  335. printk(KERN_ERR "%s: No input_dev data found\n",
  336. __func__);
  337. return -EINVAL;
  338. }
  339. if (strlen(buf) >= CMD_STR_LEN) {
  340. tsp_debug_err(true, &info->client->dev, "%s: cmd length is over(%s,%d)!!\n", __func__, buf, (int)strlen(buf));
  341. return -EINVAL;
  342. }
  343. if (info->cmd_is_running == true) {
  344. tsp_debug_err(true, &info->client->dev, "ft_cmd: other cmd is running.\n");
  345. goto err_out;
  346. }
  347. /* check lock */
  348. mutex_lock(&info->cmd_lock);
  349. info->cmd_is_running = true;
  350. mutex_unlock(&info->cmd_lock);
  351. info->cmd_state = 1;
  352. for (i = 0; i < ARRAY_SIZE(info->cmd_param); i++)
  353. info->cmd_param[i] = 0;
  354. len = (int)count;
  355. if (*(buf + len - 1) == '\n')
  356. len--;
  357. memset(info->cmd, 0x00, ARRAY_SIZE(info->cmd));
  358. memcpy(info->cmd, buf, len);
  359. cur = strchr(buf, (int)delim);
  360. if (cur)
  361. memcpy(buff, buf, cur - buf);
  362. else
  363. memcpy(buff, buf, len);
  364. tsp_debug_info(true, &info->client->dev, "COMMAND : %s\n", buff);
  365. /* find command */
  366. list_for_each_entry(ft_cmd_ptr, &info->cmd_list_head, list) {
  367. if (!strncmp(buff, ft_cmd_ptr->cmd_name, CMD_STR_LEN)) {
  368. cmd_found = true;
  369. break;
  370. }
  371. }
  372. /* set not_support_cmd */
  373. if (!cmd_found) {
  374. list_for_each_entry(ft_cmd_ptr, &info->cmd_list_head, list) {
  375. if (!strncmp
  376. ("not_support_cmd", ft_cmd_ptr->cmd_name,
  377. CMD_STR_LEN))
  378. break;
  379. }
  380. }
  381. /* parsing parameters */
  382. if (cur && cmd_found) {
  383. cur++;
  384. start = cur;
  385. memset(buff, 0x00, ARRAY_SIZE(buff));
  386. do {
  387. if (*cur == delim || cur - buf == len) {
  388. end = cur;
  389. memcpy(buff, start, end - start);
  390. *(buff + strnlen(buff, ARRAY_SIZE(buff))) =
  391. '\0';
  392. if (kstrtoint
  393. (buff, 10,
  394. info->cmd_param + param_cnt) < 0)
  395. goto err_out;
  396. start = cur + 1;
  397. memset(buff, 0x00, ARRAY_SIZE(buff));
  398. param_cnt++;
  399. }
  400. cur++;
  401. } while ((cur - buf <= len) && (param_cnt < CMD_PARAM_NUM));
  402. }
  403. tsp_debug_info(true, &info->client->dev, "cmd = %s\n", ft_cmd_ptr->cmd_name);
  404. for (i = 0; i < param_cnt; i++)
  405. tsp_debug_info(true, &info->client->dev, "cmd param %d= %d\n", i,
  406. info->cmd_param[i]);
  407. ft_cmd_ptr->cmd_func(info);
  408. err_out:
  409. return count;
  410. }
  411. static ssize_t show_cmd_status(struct device *dev,
  412. struct device_attribute *devattr, char *buf)
  413. {
  414. struct fts_ts_info *info = dev_get_drvdata(dev);
  415. char buff[16] = { 0 };
  416. if (!info) {
  417. printk(KERN_ERR "%s: No platform data found\n",
  418. __func__);
  419. return -EINVAL;
  420. }
  421. if (!info->input_dev) {
  422. printk(KERN_ERR "%s: No input_dev data found\n",
  423. __func__);
  424. return -EINVAL;
  425. }
  426. tsp_debug_info(true, &info->client->dev, "tsp cmd: status:%d\n", info->cmd_state);
  427. if (info->cmd_state == CMD_STATUS_WAITING)
  428. snprintf(buff, sizeof(buff), "WAITING");
  429. else if (info->cmd_state == CMD_STATUS_RUNNING)
  430. snprintf(buff, sizeof(buff), "RUNNING");
  431. else if (info->cmd_state == CMD_STATUS_OK)
  432. snprintf(buff, sizeof(buff), "OK");
  433. else if (info->cmd_state == CMD_STATUS_FAIL)
  434. snprintf(buff, sizeof(buff), "FAIL");
  435. else if (info->cmd_state == CMD_STATUS_NOT_APPLICABLE)
  436. snprintf(buff, sizeof(buff), "NOT_APPLICABLE");
  437. return snprintf(buf, TSP_BUF_SIZE, "%s\n", buff);
  438. }
  439. static ssize_t show_cmd_result(struct device *dev,
  440. struct device_attribute *devattr, char *buf)
  441. {
  442. struct fts_ts_info *info = dev_get_drvdata(dev);
  443. if (!info) {
  444. printk(KERN_ERR "%s: No platform data found\n",
  445. __func__);
  446. return -EINVAL;
  447. }
  448. if (!info->input_dev) {
  449. printk(KERN_ERR "%s: No input_dev data found\n",
  450. __func__);
  451. return -EINVAL;
  452. }
  453. tsp_debug_info(true, &info->client->dev, "tsp cmd: result: %s\n",
  454. info->cmd_result);
  455. mutex_lock(&info->cmd_lock);
  456. info->cmd_is_running = false;
  457. mutex_unlock(&info->cmd_lock);
  458. info->cmd_state = 0;
  459. return snprintf(buf, TSP_BUF_SIZE, "%s\n", info->cmd_result);
  460. }
  461. static ssize_t cmd_list_show(struct device *dev,
  462. struct device_attribute *attr, char *buf)
  463. {
  464. struct fts_ts_info *info = dev_get_drvdata(dev);
  465. int ii = 0;
  466. char buffer[info->cmd_buffer_size + 30];
  467. char buffer_name[CMD_STR_LEN];
  468. snprintf(buffer, 30, "++factory command list++\n");
  469. while (strncmp(ft_cmds[ii].cmd_name, "not_support_cmd", 16) != 0) {
  470. snprintf(buffer_name, CMD_STR_LEN, "%s\n", ft_cmds[ii].cmd_name);
  471. strncat(buffer, buffer_name, (int)strlen(buffer_name));
  472. ii++;
  473. }
  474. dev_info(&info->client->dev,
  475. "%s: length : %u / %d\n", __func__,
  476. strlen(buffer), info->cmd_buffer_size);
  477. return snprintf(buf, TSP_BUF_SIZE, "%s\n", buffer);
  478. }
  479. static void set_default_result(struct fts_ts_info *info)
  480. {
  481. char delim = ':';
  482. memset(info->cmd_result, 0x00, info->cmd_buffer_size);
  483. memcpy(info->cmd_result, info->cmd, strnlen(info->cmd, CMD_STR_LEN));
  484. strncat(info->cmd_result, &delim, 1);
  485. }
  486. static void set_cmd_result(struct fts_ts_info *info, char *buff, int len)
  487. {
  488. strncat(info->cmd_result, buff, len);
  489. }
  490. static void not_support_cmd(void *device_data)
  491. {
  492. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  493. char buff[16] = { 0 };
  494. set_default_result(info);
  495. snprintf(buff, sizeof(buff), "%s", "NA");
  496. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  497. info->cmd_state = 4;
  498. tsp_debug_info(true, &info->client->dev, "%s: \"%s(%d)\"\n", __func__, buff,
  499. strnlen(buff, sizeof(buff)));
  500. }
  501. static void fw_update(void *device_data)
  502. {
  503. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  504. //struct i2c_client *client = info->client;
  505. char buff[64] = { 0 };
  506. int retval = 0;
  507. set_default_result(info);
  508. if (info->touch_stopped) {
  509. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  510. __func__);
  511. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  512. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  513. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  514. return;
  515. }
  516. retval = fts_fw_update_on_hidden_menu(info, info->cmd_param[0]);
  517. if (retval < 0) {
  518. sprintf(buff, "%s", "NA");
  519. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  520. info->cmd_state = CMD_STATUS_FAIL;
  521. tsp_debug_info(true, &info->client->dev, "%s: failed [%d]\n", __func__, retval);
  522. } else {
  523. sprintf(buff, "%s", "OK");
  524. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  525. info->cmd_state = CMD_STATUS_OK;
  526. tsp_debug_info(true, &info->client->dev, "%s: success [%d]\n", __func__, retval);
  527. }
  528. return;
  529. }
  530. static int getChannelInfo(struct fts_ts_info *info)
  531. {
  532. int rc;
  533. unsigned char cmd[4] =
  534. { 0xB2, 0x00, 0x14, 0x02 };
  535. unsigned char data[FTS_EVENT_SIZE];
  536. int retry = 0;
  537. memset(data, 0x0, FTS_EVENT_SIZE);
  538. rc = -1;
  539. fts_write_reg(info, &cmd[0], 4);
  540. cmd[0]=READ_ONE_EVENT;
  541. while (fts_read_reg
  542. (info, &cmd[0], 1, (unsigned char *)data, FTS_EVENT_SIZE)) {
  543. if (data[0] == EVENTID_RESULT_READ_REGISTER) {
  544. if ((data[1]==cmd[1]) && (data[2]==cmd[2]))
  545. {
  546. info->SenseChannelLength =data[3];
  547. info->ForceChannelLength =data[4];
  548. rc = 0;
  549. break;
  550. }
  551. }
  552. if (retry++ > 30) {
  553. rc = -1;
  554. tsp_debug_info(true, &info->client->dev, "Time over - wait for channel info\n");
  555. break;
  556. }
  557. mdelay(5);
  558. }
  559. return rc;
  560. }
  561. static void procedure_cmd_event(struct fts_ts_info *info, unsigned char *data)
  562. {
  563. char buff[16] = { 0 };
  564. if ((data[1] == 0x00) && (data[2] == 0x62))
  565. {
  566. snprintf(buff, sizeof(buff), "%d",
  567. *(unsigned short *)&data[3]);
  568. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", "get_threshold", buff,
  569. strnlen(buff, sizeof(buff)));
  570. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  571. info->cmd_state = CMD_STATUS_OK;
  572. }
  573. else if ((data[1] == 0x01) && (data[2] == 0xC6))
  574. {
  575. snprintf(buff, sizeof(buff), "%d",
  576. *(unsigned short *)&data[3]);
  577. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", "get_glove_sensitivity", buff,
  578. strnlen(buff, sizeof(buff)));
  579. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  580. info->cmd_state = CMD_STATUS_OK;
  581. }
  582. else if ((data[1] == 0x07) && (data[2] == 0xE7))
  583. {
  584. if (data[3] <= TSP_FACTEST_RESULT_PASS) {
  585. sprintf(buff, "%s",
  586. data[3] == TSP_FACTEST_RESULT_PASS ? "PASS" :
  587. data[3] == TSP_FACTEST_RESULT_FAIL ? "FAIL" : "NONE");
  588. tsp_debug_info(true, &info->client->dev, "%s: success [%s][%d]", "get_tsp_test_result",
  589. data[3] == TSP_FACTEST_RESULT_PASS ? "PASS" :
  590. data[3] == TSP_FACTEST_RESULT_FAIL ? "FAIL" :
  591. "NONE", data[3]);
  592. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  593. info->cmd_state = CMD_STATUS_OK;
  594. }
  595. else
  596. {
  597. snprintf(buff, sizeof(buff), "%s", "NG");
  598. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  599. info->cmd_state = CMD_STATUS_FAIL;
  600. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n",
  601. "get_tsp_test_result",
  602. buff,
  603. strnlen(buff, sizeof(buff)));
  604. }
  605. }
  606. #ifdef FTS_SUPPORT_TOUCH_KEY
  607. if ((data[1] == 0x01) && (data[2] == 0xEF))
  608. {
  609. info->touchkey_threshold = *(unsigned short *)&data[3];
  610. }
  611. #endif
  612. }
  613. void fts_print_frame(struct fts_ts_info *info, short *min, short *max)
  614. {
  615. int i = 0;
  616. int j = 0;
  617. unsigned char *pStr = NULL;
  618. unsigned char pTmp[16] = { 0 };
  619. pStr = kzalloc(6 * (info->SenseChannelLength + 1), GFP_KERNEL);
  620. if (pStr == NULL) {
  621. tsp_debug_info(true, &info->client->dev, "FTS pStr kzalloc failed\n");
  622. return;
  623. }
  624. memset(pStr, 0x0, 6 * (info->SenseChannelLength + 1));
  625. snprintf(pTmp, sizeof(pTmp), " ");
  626. strncat(pStr, pTmp, 6 * info->SenseChannelLength);
  627. for (i = 0; i < info->SenseChannelLength; i++) {
  628. snprintf(pTmp, sizeof(pTmp), "Rx%02d ", i);
  629. strncat(pStr, pTmp, 6 * info->SenseChannelLength);
  630. }
  631. tsp_debug_info(true, &info->client->dev, "FTS %s\n", pStr);
  632. memset(pStr, 0x0, 6 * (info->SenseChannelLength + 1));
  633. snprintf(pTmp, sizeof(pTmp), " +");
  634. strncat(pStr, pTmp, 6 * info->SenseChannelLength);
  635. for (i = 0; i < info->SenseChannelLength; i++) {
  636. snprintf(pTmp, sizeof(pTmp), "------");
  637. strncat(pStr, pTmp, 6 * info->SenseChannelLength);
  638. }
  639. tsp_debug_info(true, &info->client->dev, "FTS %s\n", pStr);
  640. for (i = 0; i < info->ForceChannelLength; i++) {
  641. memset(pStr, 0x0, 6 * (info->SenseChannelLength + 1));
  642. snprintf(pTmp, sizeof(pTmp), "Tx%02d | ", i);
  643. strncat(pStr, pTmp, 6 * info->SenseChannelLength);
  644. for (j = 0; j < info->SenseChannelLength; j++) {
  645. snprintf(pTmp, sizeof(pTmp), "%5d ", info->pFrame[(i * info->SenseChannelLength) + j]);
  646. if (i > 0) {
  647. if (info->pFrame[(i * info->SenseChannelLength) + j] < *min)
  648. *min = info->pFrame[(i * info->SenseChannelLength) + j];
  649. if (info->pFrame[(i * info->SenseChannelLength) + j] > *max)
  650. *max = info->pFrame[(i * info->SenseChannelLength) + j];
  651. }
  652. strncat(pStr, pTmp, 6 * info->SenseChannelLength);
  653. }
  654. tsp_debug_info(true, &info->client->dev, "FTS %s\n", pStr);
  655. }
  656. kfree(pStr);
  657. }
  658. int fts_read_frame(struct fts_ts_info *info, unsigned char type, short *min,
  659. short *max)
  660. {
  661. unsigned char pFrameAddress[8] =
  662. { 0xD0, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 };
  663. unsigned int FrameAddress = 0;
  664. unsigned int writeAddr = 0;
  665. unsigned int start_addr = 0;
  666. unsigned int end_addr = 0;
  667. unsigned int totalbytes = 0;
  668. unsigned int remained = 0;
  669. unsigned int readbytes = 0xFF;
  670. unsigned int dataposition = 0;
  671. unsigned char *pRead = NULL;
  672. int rc = 0;
  673. int ret = 0;
  674. int i = 0;
  675. pRead = kzalloc(BUFFER_MAX, GFP_KERNEL);
  676. if (pRead == NULL) {
  677. tsp_debug_info(true, &info->client->dev, "FTS pRead kzalloc failed\n");
  678. rc = 1;
  679. goto ErrorExit;
  680. }
  681. pFrameAddress[2] = type;
  682. totalbytes = info->SenseChannelLength * info->ForceChannelLength * 2;
  683. ret = fts_read_reg(info, &pFrameAddress[0], 3, pRead, pFrameAddress[3]);
  684. if (ret >= 0) {
  685. FrameAddress = pRead[0] + (pRead[1] << 8);
  686. start_addr = FrameAddress+info->SenseChannelLength*2;
  687. // end_addr = FrameAddress + totalbytes;
  688. end_addr = start_addr + totalbytes;
  689. } else {
  690. tsp_debug_info(true, &info->client->dev, "FTS read failed rc = %d \n", ret);
  691. rc = 2;
  692. goto ErrorExit;
  693. }
  694. #ifdef DEBUG_MSG
  695. tsp_debug_info(true, &info->client->dev, "FTS FrameAddress = %X \n", FrameAddress);
  696. tsp_debug_info(true, &info->client->dev, "FTS start_addr = %X, end_addr = %X \n", start_addr, end_addr);
  697. #endif
  698. remained = totalbytes;
  699. for (writeAddr = start_addr; writeAddr < end_addr;
  700. writeAddr += READ_CHUNK_SIZE) {
  701. pFrameAddress[1] = (writeAddr >> 8) & 0xFF;
  702. pFrameAddress[2] = writeAddr & 0xFF;
  703. if (remained >= READ_CHUNK_SIZE) {
  704. readbytes = READ_CHUNK_SIZE;
  705. } else {
  706. readbytes = remained;
  707. }
  708. memset(pRead, 0x0, readbytes);
  709. #ifdef DEBUG_MSG
  710. tsp_debug_info(true, &info->client->dev, "FTS %02X%02X%02X readbytes=%d\n",
  711. pFrameAddress[0], pFrameAddress[1],
  712. pFrameAddress[2], readbytes);
  713. #endif /* */
  714. fts_read_reg(info, &pFrameAddress[0], 3, pRead, readbytes);
  715. remained -= readbytes;
  716. for (i = 0; i < readbytes; i += 2) {
  717. //for(i = 0; i < totalbytes ; i += 2){
  718. info->pFrame[dataposition++] =
  719. pRead[i] + (pRead[i + 1] << 8);
  720. }
  721. }
  722. kfree(pRead);
  723. #ifdef DEBUG_MSG
  724. tsp_debug_info(true, &info->client->dev,
  725. "FTS writeAddr = %X, start_addr = %X, end_addr = %X \n",
  726. writeAddr, start_addr, end_addr);
  727. #endif
  728. switch (type) {
  729. case TYPE_RAW_DATA:
  730. tsp_debug_info(true, &info->client->dev, "FTS [Raw Data : 0x%X%X] \n", pFrameAddress[0],
  731. FrameAddress);
  732. break;
  733. case TYPE_FILTERED_DATA:
  734. tsp_debug_info(true, &info->client->dev, "FTS [Filtered Data : 0x%X%X] \n",
  735. pFrameAddress[0], FrameAddress);
  736. break;
  737. case TYPE_STRENGTH_DATA:
  738. tsp_debug_info(true, &info->client->dev, "FTS [Strength Data : 0x%X%X] \n",
  739. pFrameAddress[0], FrameAddress);
  740. break;
  741. case TYPE_BASELINE_DATA:
  742. tsp_debug_info(true, &info->client->dev, "FTS [Baseline Data : 0x%X%X] \n",
  743. pFrameAddress[0], FrameAddress);
  744. break;
  745. }
  746. fts_print_frame(info, min, max);
  747. ErrorExit:
  748. return rc;
  749. }
  750. static int fts_panel_ito_test(struct fts_ts_info *info)
  751. {
  752. unsigned char cmd = READ_ONE_EVENT;
  753. unsigned char data[FTS_EVENT_SIZE];
  754. unsigned char regAdd[4] = {0xB0, 0x03, 0x60, 0xFB};
  755. int retry = 0;
  756. int result = -1;
  757. fts_systemreset(info);
  758. fts_wait_for_ready(info);
  759. fts_command(info, SLEEPOUT);
  760. fts_delay(20);
  761. fts_interrupt_set(info, INT_DISABLE);
  762. fts_write_reg(info, &regAdd[0], 4);
  763. fts_command(info, FLUSHBUFFER);
  764. fts_command(info, 0xA7);
  765. fts_delay(200);
  766. memset(data, 0x0, FTS_EVENT_SIZE);
  767. while (fts_read_reg
  768. (info, &cmd, 1, (unsigned char *)data, FTS_EVENT_SIZE)) {
  769. if ((data[0] == 0x0F) && (data[1] == 0x05)) {
  770. switch (data[2]) {
  771. case 0x00 :
  772. result = 0;
  773. break;
  774. case 0x01 :
  775. tsp_debug_info(true, &info->client->dev, "[FTS] ITO Test result : Force channel [%d] open.\n",
  776. data[3]);
  777. break;
  778. case 0x02 :
  779. tsp_debug_info(true, &info->client->dev, "[FTS] ITO Test result : Sense channel [%d] open.\n",
  780. data[3]);
  781. break;
  782. case 0x03 :
  783. tsp_debug_info(true, &info->client->dev, "[FTS] ITO Test result : Force channel [%d] short to GND.\n",
  784. data[3]);
  785. break;
  786. case 0x04 :
  787. tsp_debug_info(true, &info->client->dev, "[FTS] ITO Test result : Sense channel [%d] short to GND.\n",
  788. data[3]);
  789. break;
  790. case 0x07 :
  791. tsp_debug_info(true, &info->client->dev, "[FTS] ITO Test result : Force channel [%d] short to force.\n",
  792. data[3]);
  793. break;
  794. case 0x0E :
  795. tsp_debug_info(true, &info->client->dev, "[FTS] ITO Test result : Sennse channel [%d] short to sense.\n",
  796. data[3]);
  797. break;
  798. default:
  799. break;
  800. }
  801. break;
  802. }
  803. if (retry++ > 30) {
  804. tsp_debug_info(true, &info->client->dev, "Time over - wait for result of ITO test\n");
  805. break;
  806. }
  807. fts_delay(10);
  808. }
  809. fts_systemreset(info);
  810. // wait for ready event
  811. fts_wait_for_ready(info);
  812. #ifdef FTS_SUPPORT_NOISE_PARAM
  813. fts_set_noise_param(info);
  814. #endif // FTS_SUPPORT_NOISE_PARAM
  815. fts_command(info, SLEEPOUT);
  816. fts_command(info, SENSEON);
  817. #ifdef FTS_SUPPORT_TOUCH_KEY
  818. info->fts_command(info, FTS_CMD_KEY_SENSE_ON);
  819. #endif
  820. if (info->hover_enabled)
  821. fts_command(info, FTS_CMD_HOVER_ON);
  822. if (info->flip_enable) {
  823. fts_set_flipcover_mode(info, true);
  824. } else {
  825. if (info->mshover_enabled)
  826. fts_command(info, FTS_CMD_MSHOVER_ON);
  827. }
  828. #ifdef FTS_SUPPORT_TA_MODE
  829. if (info->TA_Pluged)
  830. fts_command(info, FTS_CMD_CHARGER_PLUGGED);
  831. #endif
  832. info->touch_count = 0;
  833. fts_command(info, FLUSHBUFFER);
  834. fts_interrupt_set(info, INT_ENABLE);
  835. return result;
  836. }
  837. static void get_fw_ver_bin(void *device_data)
  838. {
  839. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  840. char buff[16] = { 0 };
  841. set_default_result(info);
  842. info->panel_revision = 0x00;
  843. sprintf(buff, "ST%02X%04X",
  844. info->panel_revision,
  845. info->fw_main_version_of_bin);
  846. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  847. info->cmd_state = CMD_STATUS_OK;
  848. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  849. strnlen(buff, sizeof(buff)));
  850. }
  851. static void get_fw_ver_ic(void *device_data)
  852. {
  853. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  854. char buff[16] = { 0 };
  855. set_default_result(info);
  856. info->panel_revision = 0x00;
  857. sprintf(buff, "ST%02X%04X",
  858. info->panel_revision,
  859. info->fw_main_version_of_ic);
  860. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  861. info->cmd_state = CMD_STATUS_OK;
  862. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  863. strnlen(buff, sizeof(buff)));
  864. }
  865. static void get_config_ver(void *device_data)
  866. {
  867. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  868. char buff[20] = { 0 };
  869. snprintf(buff, sizeof(buff), "%s_ST_%04X",
  870. info->board->project_name ?: STM_DEVICE_NAME,
  871. info->config_version_of_ic);
  872. set_default_result(info);
  873. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  874. info->cmd_state = CMD_STATUS_OK;
  875. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  876. strnlen(buff, sizeof(buff)));
  877. }
  878. static void get_threshold(void *device_data)
  879. {
  880. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  881. unsigned char cmd[4] =
  882. { 0xB2, 0x00, 0x62, 0x02 };
  883. int timeout=0;
  884. set_default_result(info);
  885. if (info->touch_stopped) {
  886. char buff[CMD_STR_LEN] = { 0 };
  887. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  888. __func__);
  889. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  890. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  891. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  892. return;
  893. }
  894. fts_write_reg(info, &cmd[0], 4);
  895. info->cmd_state = CMD_STATUS_RUNNING;
  896. while (info->cmd_state == CMD_STATUS_RUNNING) {
  897. if (timeout++>30) {
  898. info->cmd_state = CMD_STATUS_FAIL;
  899. break;
  900. }
  901. msleep(10);
  902. }
  903. }
  904. static void module_off_master(void *device_data)
  905. {
  906. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  907. char buff[3] = { 0 };
  908. int ret = 0;
  909. mutex_lock(&info->lock);
  910. if (info->enabled) {
  911. disable_irq(info->irq);
  912. info->enabled = false;
  913. }
  914. mutex_unlock(&info->lock);
  915. if (info->board->power)
  916. info->board->power(0);
  917. else
  918. ret = 1;
  919. if (ret == 0)
  920. snprintf(buff, sizeof(buff), "%s", "OK");
  921. else
  922. snprintf(buff, sizeof(buff), "%s", "NG");
  923. set_default_result(info);
  924. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  925. if (strncmp(buff, "OK", 2) == 0)
  926. info->cmd_state = CMD_STATUS_OK;
  927. else
  928. info->cmd_state = CMD_STATUS_FAIL;
  929. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  930. }
  931. static void module_on_master(void *device_data)
  932. {
  933. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  934. char buff[3] = { 0 };
  935. int ret = 0;
  936. mutex_lock(&info->lock);
  937. if (!info->enabled) {
  938. enable_irq(info->irq);
  939. info->enabled = true;
  940. }
  941. mutex_unlock(&info->lock);
  942. if (info->board->power)
  943. info->board->power(1);
  944. else
  945. ret = 1;
  946. if (ret == 0)
  947. snprintf(buff, sizeof(buff), "%s", "OK");
  948. else
  949. snprintf(buff, sizeof(buff), "%s", "NG");
  950. set_default_result(info);
  951. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  952. if (strncmp(buff, "OK", 2) == 0)
  953. info->cmd_state = CMD_STATUS_OK;
  954. else
  955. info->cmd_state = CMD_STATUS_FAIL;
  956. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  957. }
  958. static void get_chip_vendor(void *device_data)
  959. {
  960. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  961. char buff[16] = { 0 };
  962. strncpy(buff, "STM", sizeof(buff));
  963. set_default_result(info);
  964. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  965. info->cmd_state = CMD_STATUS_OK;
  966. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  967. strnlen(buff, sizeof(buff)));
  968. }
  969. static void get_chip_name(void *device_data)
  970. {
  971. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  972. char buff[16] = { 0 };
  973. strncpy(buff, "FTS", sizeof(buff));
  974. set_default_result(info);
  975. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  976. info->cmd_state = CMD_STATUS_OK;
  977. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  978. strnlen(buff, sizeof(buff)));
  979. }
  980. static void get_x_num(void *device_data)
  981. {
  982. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  983. char buff[16] = { 0 };
  984. set_default_result(info);
  985. snprintf(buff, sizeof(buff), "%d", info->SenseChannelLength);
  986. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  987. info->cmd_state = 2;
  988. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  989. strnlen(buff, sizeof(buff)));
  990. }
  991. static void get_y_num(void *device_data)
  992. {
  993. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  994. char buff[16] = { 0 };
  995. set_default_result(info);
  996. snprintf(buff, sizeof(buff), "%d", info->ForceChannelLength);
  997. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  998. info->cmd_state = CMD_STATUS_OK;
  999. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1000. strnlen(buff, sizeof(buff)));
  1001. }
  1002. static void run_reference_read(void *device_data)
  1003. {
  1004. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1005. char buff[CMD_STR_LEN] = { 0 };
  1006. short min = 0x7FFF;
  1007. short max = 0x8000;
  1008. set_default_result(info);
  1009. if (info->touch_stopped) {
  1010. char buff[CMD_STR_LEN] = { 0 };
  1011. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1012. __func__);
  1013. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1014. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1015. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1016. return;
  1017. }
  1018. fts_read_frame(info, TYPE_BASELINE_DATA, &min, &max);
  1019. snprintf(buff, sizeof(buff), "%d,%d", min, max);
  1020. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1021. info->cmd_state = CMD_STATUS_OK;
  1022. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1023. }
  1024. static void get_reference(void *device_data)
  1025. {
  1026. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1027. char buff[CMD_STR_LEN] = { 0 };
  1028. short min = 0x7FFF;
  1029. short max = 0x8000;
  1030. short val = 0;
  1031. int node = 0;
  1032. set_default_result(info);
  1033. if (info->touch_stopped) {
  1034. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1035. __func__);
  1036. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1037. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1038. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1039. return;
  1040. }
  1041. node = fts_check_index(info);
  1042. if (node < 0)
  1043. return;
  1044. fts_read_frame(info, TYPE_BASELINE_DATA, &min, &max);
  1045. val = info->pFrame[node];
  1046. snprintf(buff, sizeof(buff), "%d", val);
  1047. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1048. info->cmd_state = CMD_STATUS_OK;
  1049. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1050. strnlen(buff, sizeof(buff)));
  1051. }
  1052. static void run_rawcap_read(void *device_data)
  1053. {
  1054. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1055. char buff[CMD_STR_LEN] = { 0 };
  1056. short min = 0x7FFF;
  1057. short max = 0x8000;
  1058. set_default_result(info);
  1059. if (info->touch_stopped) {
  1060. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1061. __func__);
  1062. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1063. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1064. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1065. return;
  1066. }
  1067. fts_delay(500);
  1068. fts_read_frame(info, TYPE_FILTERED_DATA, &min, &max);
  1069. snprintf(buff, sizeof(buff), "%d,%d", min, max);
  1070. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1071. info->cmd_state = CMD_STATUS_OK;
  1072. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1073. }
  1074. static void get_rawcap(void *device_data)
  1075. {
  1076. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1077. char buff[CMD_STR_LEN] = { 0 };
  1078. short min = 0x7FFF;
  1079. short max = 0x8000;
  1080. short val = 0;
  1081. int node = 0;
  1082. set_default_result(info);
  1083. if (info->touch_stopped) {
  1084. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1085. __func__);
  1086. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1087. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1088. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1089. return;
  1090. }
  1091. node = fts_check_index(info);
  1092. if (node < 0)
  1093. return;
  1094. fts_read_frame(info, TYPE_FILTERED_DATA, &min, &max);
  1095. val = info->pFrame[node];
  1096. snprintf(buff, sizeof(buff), "%d", val);
  1097. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1098. info->cmd_state = CMD_STATUS_OK;
  1099. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1100. strnlen(buff, sizeof(buff)));
  1101. }
  1102. static void run_delta_read(void *device_data)
  1103. {
  1104. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1105. char buff[CMD_STR_LEN] = { 0 };
  1106. short min = 0x7FFF;
  1107. short max = 0x8000;
  1108. set_default_result(info);
  1109. if (info->touch_stopped) {
  1110. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1111. __func__);
  1112. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1113. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1114. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1115. return;
  1116. }
  1117. fts_read_frame(info, TYPE_STRENGTH_DATA, &min, &max);
  1118. snprintf(buff, sizeof(buff), "%d,%d", min, max);
  1119. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1120. info->cmd_state = CMD_STATUS_OK;
  1121. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1122. }
  1123. static void get_delta(void *device_data)
  1124. {
  1125. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1126. char buff[CMD_STR_LEN] = { 0 };
  1127. short min = 0x7FFF;
  1128. short max = 0x8000;
  1129. short val = 0;
  1130. int node = 0;
  1131. set_default_result(info);
  1132. if (info->touch_stopped) {
  1133. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1134. __func__);
  1135. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1136. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1137. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1138. return;
  1139. }
  1140. node = fts_check_index(info);
  1141. if (node < 0)
  1142. return;
  1143. fts_read_frame(info, TYPE_STRENGTH_DATA, &min, &max);
  1144. val = info->pFrame[node];
  1145. snprintf(buff, sizeof(buff), "%d", val);
  1146. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1147. info->cmd_state = CMD_STATUS_OK;
  1148. tsp_debug_info(true, &info->client->dev, "%s: %s(%d)\n", __func__, buff,
  1149. strnlen(buff, sizeof(buff)));
  1150. }
  1151. void fts_read_self_frame(struct fts_ts_info *info, unsigned short oAddr)
  1152. {
  1153. char buff[64] = { 0 };
  1154. short *data;
  1155. char temp[9] = { 0 };
  1156. char temp2[512] = { 0 };
  1157. int i;
  1158. int rc;
  1159. int retry=1;
  1160. unsigned char regAdd[6] = {0xD0, 0x00, 0x00, 0xD0, 0x00, 0x00};
  1161. if (info->touch_stopped) {
  1162. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1163. __func__);
  1164. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1165. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1166. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1167. return;
  1168. }
  1169. if (!info->hover_enabled) {
  1170. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Hover is disabled\n",
  1171. __func__);
  1172. snprintf(buff, sizeof(buff), "%s", "TSP Hover disabled");
  1173. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1174. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1175. return;
  1176. }
  1177. while (!info->hover_ready) {
  1178. if (retry++ > 500) { // max 5sec
  1179. tsp_debug_info(true, &info->client->dev, "%s: [FTS] Timeout - Abs Raw Data Ready Event\n",
  1180. __func__);
  1181. break;
  1182. }
  1183. fts_delay(10);
  1184. }
  1185. regAdd[1] = (oAddr >> 8) & 0xff;
  1186. regAdd[2] = oAddr & 0xff;
  1187. rc = info->fts_read_reg(info, &regAdd[0], 3, (unsigned char *)&buff[0], 4);
  1188. if (!rc) {
  1189. info->cmd_state = CMD_STATUS_FAIL;
  1190. return;
  1191. }
  1192. tsp_debug_info(true, &info->client->dev, "%s: Force Address : %02x%02x\n",
  1193. __func__, buff[1], buff[0]);
  1194. tsp_debug_info(true, &info->client->dev, "%s: Sense Address : %02x%02x\n",
  1195. __func__, buff[3], buff[2]);
  1196. regAdd[1] = buff[3];
  1197. regAdd[2] = buff[2];
  1198. regAdd[4] = buff[1];
  1199. regAdd[5] = buff[0];
  1200. rc = info->fts_read_reg(info, &regAdd[0], 3,
  1201. (unsigned char *)&buff[0],
  1202. info->SenseChannelLength*2);
  1203. if (!rc) {
  1204. info->cmd_state = CMD_STATUS_FAIL;
  1205. return;
  1206. }
  1207. data = (short *)&buff[0];
  1208. for (i = 0; i < info->SenseChannelLength; i++) {
  1209. tsp_debug_info(true, &info->client->dev,
  1210. "%s: Rx [%d] = %d\n", __func__,
  1211. i,
  1212. *data);
  1213. sprintf(temp, "%d,", *data);
  1214. strncat(temp2, temp, 9);
  1215. data++;
  1216. }
  1217. rc = info->fts_read_reg(info, &regAdd[3], 3,
  1218. (unsigned char *)&buff[0],
  1219. info->ForceChannelLength*2);
  1220. if (!rc) {
  1221. info->cmd_state = CMD_STATUS_FAIL;
  1222. return;
  1223. }
  1224. data = (short *)&buff[0];
  1225. for (i = 0; i < info->ForceChannelLength; i++) {
  1226. tsp_debug_info(true, &info->client->dev,
  1227. "%s: Tx [%d] = %d\n", __func__, i, *data);
  1228. sprintf(temp, "%d,", *data);
  1229. strncat(temp2, temp, 9);
  1230. data++;
  1231. }
  1232. set_cmd_result(info, temp2, strnlen(temp2, sizeof(temp2)));
  1233. info->cmd_state = CMD_STATUS_OK;
  1234. }
  1235. static void run_abscap_read(void *device_data)
  1236. {
  1237. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1238. set_default_result(info);
  1239. fts_read_self_frame(info, 0x000E);
  1240. }
  1241. static void run_absdelta_read(void *device_data)
  1242. {
  1243. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1244. set_default_result(info);
  1245. fts_read_self_frame(info, 0x0012);
  1246. }
  1247. static void run_trx_short_test(void *device_data)
  1248. {
  1249. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1250. char buff[CMD_STR_LEN] = { 0 };
  1251. int ret = 0;
  1252. set_default_result(info);
  1253. if (info->touch_stopped) {
  1254. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1255. __func__);
  1256. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1257. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1258. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1259. return;
  1260. }
  1261. disable_irq(info->irq);
  1262. ret = fts_panel_ito_test(info);
  1263. if (ret == 0)
  1264. snprintf(buff, sizeof(buff), "%s", "OK");
  1265. else
  1266. snprintf(buff, sizeof(buff), "%s", "FAIL");
  1267. enable_irq(info->irq);
  1268. info->cmd_state = CMD_STATUS_OK;
  1269. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1270. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1271. }
  1272. static void set_tsp_test_result(void *device_data)
  1273. {
  1274. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1275. char buff[CMD_STR_LEN] = { 0 };
  1276. unsigned char regAdd[4] = {0xB0, 0x07, 0xE7, 0x00};
  1277. set_default_result(info);
  1278. if (info->cmd_param[0] < TSP_FACTEST_RESULT_NONE
  1279. || info->cmd_param[0] > TSP_FACTEST_RESULT_PASS) {
  1280. snprintf(buff, sizeof(buff), "%s", "NG");
  1281. info->cmd_state = CMD_STATUS_FAIL;
  1282. return;
  1283. }
  1284. if (info->touch_stopped) {
  1285. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1286. __func__);
  1287. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1288. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1289. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1290. return;
  1291. }
  1292. regAdd[3] = info->cmd_param[0];
  1293. fts_write_reg(info, &regAdd[0], 4);
  1294. fts_delay(100);
  1295. fts_command(info, FTS_CMD_SAVE_FWCONFIG);
  1296. snprintf(buff, sizeof(buff), "%s", "OK");
  1297. info->cmd_state = CMD_STATUS_OK;
  1298. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1299. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1300. }
  1301. static void get_tsp_test_result(void *device_data)
  1302. {
  1303. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1304. unsigned char cmd[4] = {0xB2, 0x07, 0xE7, 0x01};
  1305. int timeout = 0;
  1306. set_default_result(info);
  1307. if (info->touch_stopped) {
  1308. char buff[CMD_STR_LEN] = { 0 };
  1309. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1310. __func__);
  1311. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1312. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1313. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1314. return;
  1315. }
  1316. fts_command(info, FLUSHBUFFER);
  1317. fts_write_reg(info, &cmd[0], 4);
  1318. info->cmd_state = CMD_STATUS_RUNNING;
  1319. while (info->cmd_state == CMD_STATUS_RUNNING) {
  1320. if (timeout++>30) {
  1321. info->cmd_state = CMD_STATUS_FAIL;
  1322. break;
  1323. }
  1324. fts_delay(10);
  1325. }
  1326. }
  1327. static void hover_enable(void *device_data)
  1328. {
  1329. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1330. char buff[CMD_STR_LEN] = { 0 };
  1331. set_default_result(info);
  1332. if (info->touch_stopped || !(info->reinit_done)) {
  1333. tsp_debug_info(true, &info->client->dev,
  1334. "%s: [ERROR] Touch is stopped : %d, reinit_done : %d\n",
  1335. __func__, info->touch_stopped, info->reinit_done);
  1336. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1337. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1338. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1339. if(info->cmd_param[0]==1){
  1340. retry_hover_enable_after_wakeup = 1;
  1341. tsp_debug_info(true, &info->client->dev, "%s: retry_hover_on_after_wakeup \n", __func__);
  1342. }
  1343. goto out;
  1344. }
  1345. if (info->cmd_param[0] < 0 || info->cmd_param[0] > 1) {
  1346. snprintf(buff, sizeof(buff), "%s", "NG");
  1347. info->cmd_state = CMD_STATUS_FAIL;
  1348. } else {
  1349. int enables;
  1350. enables = info->cmd_param[0];
  1351. if (enables) {
  1352. unsigned char regAdd[4] = {0xB0, 0x01, 0x29, 0x41};
  1353. fts_write_reg(info, &regAdd[0], 4);
  1354. fts_command(info, FTS_CMD_HOVER_ON);
  1355. info->hover_ready = false;
  1356. info->hover_enabled = true;
  1357. } else {
  1358. fts_command(info, FTS_CMD_HOVER_OFF);
  1359. info->hover_enabled = false;
  1360. info->hover_ready = false;
  1361. }
  1362. snprintf(buff, sizeof(buff), "%s", "OK");
  1363. info->cmd_state = CMD_STATUS_OK;
  1364. }
  1365. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1366. info->cmd_state = CMD_STATUS_WAITING;
  1367. out:
  1368. mutex_lock(&info->cmd_lock);
  1369. info->cmd_is_running = false;
  1370. mutex_unlock(&info->cmd_lock);
  1371. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1372. }
  1373. static void hover_no_sleep_enable(void *device_data)
  1374. {
  1375. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1376. unsigned char regAdd[4] = {0xB0, 0x01, 0x18, 0x00};
  1377. char buff[CMD_STR_LEN] = { 0 };
  1378. set_default_result(info);
  1379. if (info->touch_stopped) {
  1380. tsp_debug_info(true, &info->client->dev,
  1381. "%s: [ERROR] Touch is stopped : %d\n",
  1382. __func__, info->touch_stopped);
  1383. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1384. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1385. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1386. return;
  1387. }
  1388. if (info->cmd_param[0] < 0 || info->cmd_param[0] > 1) {
  1389. snprintf(buff, sizeof(buff), "%s", "NG");
  1390. info->cmd_state = CMD_STATUS_FAIL;
  1391. } else {
  1392. if (info->cmd_param[0]) {
  1393. regAdd[3]=0x0F;
  1394. } else {
  1395. regAdd[3]=0x08;
  1396. }
  1397. fts_write_reg(info, &regAdd[0], 4);
  1398. snprintf(buff, sizeof(buff), "%s", "OK");
  1399. info->cmd_state = CMD_STATUS_OK;
  1400. }
  1401. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1402. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1403. }
  1404. static void glove_mode(void *device_data)
  1405. {
  1406. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1407. char buff[CMD_STR_LEN] = { 0 };
  1408. set_default_result(info);
  1409. if (info->cmd_param[0] < 0 || info->cmd_param[0] > 1) {
  1410. snprintf(buff, sizeof(buff), "%s", "NG");
  1411. info->cmd_state = CMD_STATUS_FAIL;
  1412. } else {
  1413. info->mshover_enabled = info->cmd_param[0];
  1414. if (!info->touch_stopped && info->reinit_done) {
  1415. if (info->mshover_enabled)
  1416. fts_command(info, FTS_CMD_MSHOVER_ON);
  1417. else
  1418. fts_command(info, FTS_CMD_MSHOVER_OFF);
  1419. }
  1420. snprintf(buff, sizeof(buff), "%s", "OK");
  1421. info->cmd_state = CMD_STATUS_OK;
  1422. }
  1423. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1424. info->cmd_state = CMD_STATUS_WAITING;
  1425. mutex_lock(&info->cmd_lock);
  1426. info->cmd_is_running = false;
  1427. mutex_unlock(&info->cmd_lock);
  1428. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1429. }
  1430. static void get_glove_sensitivity(void *device_data)
  1431. {
  1432. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1433. unsigned char cmd[4] =
  1434. { 0xB2, 0x01, 0xC6, 0x02 };
  1435. int timeout=0;
  1436. set_default_result(info);
  1437. if (info->touch_stopped) {
  1438. char buff[CMD_STR_LEN] = { 0 };
  1439. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1440. __func__);
  1441. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1442. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1443. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1444. return;
  1445. }
  1446. fts_write_reg(info, &cmd[0], 4);
  1447. info->cmd_state = CMD_STATUS_RUNNING;
  1448. while (info->cmd_state == CMD_STATUS_RUNNING) {
  1449. if (timeout++>30) {
  1450. info->cmd_state = CMD_STATUS_FAIL;
  1451. break;
  1452. }
  1453. msleep(10);
  1454. }
  1455. }
  1456. static void clear_cover_mode(void *device_data)
  1457. {
  1458. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1459. char buff[CMD_STR_LEN] = { 0 };
  1460. set_default_result(info);
  1461. if (info->cmd_param[0] < 0 || info->cmd_param[0] > 3) {
  1462. snprintf(buff, sizeof(buff), "%s", "NG");
  1463. info->cmd_state = CMD_STATUS_FAIL;
  1464. } else {
  1465. if (info->cmd_param[0] > 1)
  1466. info->flip_enable = true;
  1467. else
  1468. info->flip_enable = false;
  1469. if (!info->touch_stopped && info->reinit_done) {
  1470. if (info->flip_enable) {
  1471. if (info->mshover_enabled)
  1472. fts_command(info, FTS_CMD_MSHOVER_OFF);
  1473. fts_set_flipcover_mode(info, true);
  1474. } else {
  1475. fts_set_flipcover_mode(info, false);
  1476. if (info->fast_mshover_enabled)
  1477. fts_command(info, FTS_CMD_SET_FAST_GLOVE_MODE);
  1478. else if (info->mshover_enabled)
  1479. fts_command(info, FTS_CMD_MSHOVER_ON);
  1480. }
  1481. }
  1482. snprintf(buff, sizeof(buff), "%s", "OK");
  1483. info->cmd_state = CMD_STATUS_OK;
  1484. }
  1485. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1486. info->cmd_state = CMD_STATUS_WAITING;
  1487. mutex_lock(&info->cmd_lock);
  1488. info->cmd_is_running = false;
  1489. mutex_unlock(&info->cmd_lock);
  1490. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1491. };
  1492. static void fast_glove_mode(void *device_data)
  1493. {
  1494. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1495. char buff[CMD_STR_LEN] = { 0 };
  1496. set_default_result(info);
  1497. if (info->cmd_param[0] < 0 || info->cmd_param[0] > 1) {
  1498. snprintf(buff, sizeof(buff), "%s", "NG");
  1499. info->cmd_state = CMD_STATUS_FAIL;
  1500. } else {
  1501. info->fast_mshover_enabled = info->cmd_param[0];
  1502. if (!info->touch_stopped && info->reinit_done) {
  1503. if (info->fast_mshover_enabled)
  1504. fts_command(info, FTS_CMD_SET_FAST_GLOVE_MODE);
  1505. else
  1506. fts_command(info, FTS_CMD_SET_NOR_GLOVE_MODE);
  1507. }
  1508. snprintf(buff, sizeof(buff), "%s", "OK");
  1509. info->cmd_state = CMD_STATUS_OK;
  1510. }
  1511. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1512. info->cmd_state = CMD_STATUS_WAITING;
  1513. mutex_lock(&info->cmd_lock);
  1514. info->cmd_is_running = false;
  1515. mutex_unlock(&info->cmd_lock);
  1516. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1517. };
  1518. static void report_rate(void *device_data)
  1519. {
  1520. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1521. char buff[CMD_STR_LEN] = { 0 };
  1522. set_default_result(info);
  1523. if (info->touch_stopped) {
  1524. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1525. __func__);
  1526. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1527. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1528. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1529. goto out;
  1530. }
  1531. if (info->panel_revision == 0) {
  1532. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Not supported panel\n",
  1533. __func__);
  1534. snprintf(buff, sizeof(buff), "%s", "OK");
  1535. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1536. info->cmd_state = CMD_STATUS_OK;
  1537. goto out;
  1538. }
  1539. if (info->cmd_param[0] < 0 || info->cmd_param[0] > 1) {
  1540. snprintf(buff, sizeof(buff), "%s", "NG");
  1541. info->cmd_state = CMD_STATUS_FAIL;
  1542. } else {
  1543. int enables;
  1544. enables = info->cmd_param[0];
  1545. if (enables) { // 60 Hz
  1546. if (!info->slow_report_rate) {
  1547. #if defined(CONFIG_SEC_S_PROJECT)
  1548. fts_command(info, FTS_CMD_SLOW_SCAN);
  1549. #else
  1550. fts_command(info, SENSEOFF);
  1551. fts_command(info, SENSEON_SLOW);
  1552. #endif
  1553. #ifdef FTS_SUPPORT_TOUCH_KEY
  1554. info->fts_command(info, FTS_CMD_KEY_SENSE_ON);
  1555. #endif // FTS_SUPPORT_TOUCH_KEY
  1556. info->slow_report_rate = true;
  1557. }
  1558. } else { // 90Hz
  1559. if (info->slow_report_rate) {
  1560. #if defined(CONFIG_SEC_S_PROJECT)
  1561. fts_command(info, FTS_CMD_FAST_SCAN);
  1562. #else
  1563. fts_command(info, SENSEOFF);
  1564. fts_command(info, SENSEON);
  1565. #endif
  1566. #ifdef FTS_SUPPORT_TOUCH_KEY
  1567. info->fts_command(info, FTS_CMD_KEY_SENSE_ON);
  1568. #endif // FTS_SUPPORT_TOUCH_KEY
  1569. info->slow_report_rate = false;
  1570. }
  1571. }
  1572. snprintf(buff, sizeof(buff), "%s", "OK");
  1573. info->cmd_state = CMD_STATUS_OK;
  1574. }
  1575. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1576. info->cmd_state = CMD_STATUS_WAITING;
  1577. out:
  1578. mutex_lock(&info->cmd_lock);
  1579. info->cmd_is_running = false;
  1580. mutex_unlock(&info->cmd_lock);
  1581. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1582. }
  1583. #if !defined(CONFIG_SAMSUNG_PRODUCT_SHIP)
  1584. static void interrupt_control(void *device_data)
  1585. {
  1586. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1587. char buff[CMD_STR_LEN] = { 0 };
  1588. set_default_result(info);
  1589. if (info->touch_stopped) {
  1590. tsp_debug_info(true, &info->client->dev, "%s: [ERROR] Touch is stopped\n",
  1591. __func__);
  1592. snprintf(buff, sizeof(buff), "%s", "TSP turned off");
  1593. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1594. info->cmd_state = CMD_STATUS_NOT_APPLICABLE;
  1595. goto out;
  1596. }
  1597. if (info->cmd_param[0] < 0 || info->cmd_param[0] > 1) {
  1598. snprintf(buff, sizeof(buff), "%s", "NG");
  1599. info->cmd_state = CMD_STATUS_FAIL;
  1600. } else {
  1601. int enables;
  1602. enables = info->cmd_param[0];
  1603. if (enables)
  1604. fts_irq_enable(info, true);
  1605. else
  1606. fts_irq_enable(info, false);
  1607. snprintf(buff, sizeof(buff), "%s", "OK");
  1608. info->cmd_state = CMD_STATUS_OK;
  1609. }
  1610. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1611. info->cmd_state = CMD_STATUS_WAITING;
  1612. out:
  1613. mutex_lock(&info->cmd_lock);
  1614. info->cmd_is_running = false;
  1615. mutex_unlock(&info->cmd_lock);
  1616. tsp_debug_info(true, &info->client->dev, "%s: %s\n", __func__, buff);
  1617. }
  1618. #endif
  1619. #ifdef TOUCH_BOOSTER_DVFS
  1620. static void boost_level(void *device_data)
  1621. {
  1622. struct fts_ts_info *info = (struct fts_ts_info *)device_data;
  1623. struct i2c_client *client = info->client;
  1624. char buff[CMD_STR_LEN] = { 0 };
  1625. int retval = 0;
  1626. set_default_result(info);
  1627. #ifdef CONFIG_SEC_S_PROJECT
  1628. /* Level 5 is replaced to Level 3 */
  1629. if(info->cmd_param[0] == DVFS_STAGE_PENTA){
  1630. info->cmd_param[0] = DVFS_STAGE_TRIPLE;
  1631. }
  1632. #endif
  1633. info->dvfs_boost_mode = info->cmd_param[0];
  1634. dev_info(&client->dev,
  1635. "%s: dvfs_boost_mode = %d\n",
  1636. __func__, info->dvfs_boost_mode);
  1637. snprintf(buff, sizeof(buff), "OK");
  1638. info->cmd_state = CMD_STATUS_OK;
  1639. if (info->dvfs_boost_mode == DVFS_STAGE_NONE) {
  1640. retval = set_freq_limit(DVFS_TOUCH_ID, -1);
  1641. if (retval < 0) {
  1642. dev_err(&info->client->dev,
  1643. "%s: booster stop failed(%d).\n",
  1644. __func__, retval);
  1645. snprintf(buff, sizeof(buff), "NG");
  1646. info->cmd_state = CMD_STATUS_FAIL;
  1647. info->dvfs_lock_status = false;
  1648. }
  1649. }
  1650. set_cmd_result(info, buff, strnlen(buff, sizeof(buff)));
  1651. info->cmd_state = CMD_STATUS_WAITING;
  1652. mutex_lock(&info->cmd_lock);
  1653. info->cmd_is_running = false;
  1654. mutex_unlock(&info->cmd_lock);
  1655. return;
  1656. }
  1657. #endif
  1658. #endif