raydium_sysfs.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  1. /*raydium_sysfs.c
  2. *
  3. * Raydium TouchScreen driver.
  4. *
  5. * Copyright (c) 2021 Raydium tech Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. */
  18. #include <linux/unistd.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/fs.h>
  21. #include <linux/string.h>
  22. #include <linux/kernel.h>
  23. #include <linux/slab.h>
  24. #include <linux/device.h>
  25. #include <linux/delay.h>
  26. #include <linux/i2c.h>
  27. #include <linux/gpio.h>
  28. #include "raydium_driver.h"
  29. static ssize_t raydium_touch_calibration_show(struct device *dev,
  30. struct device_attribute *attr,
  31. char *p_i8_buf)
  32. {
  33. unsigned char u8_rbuffer[1];
  34. unsigned short u16_len = 0;
  35. int i32_ret = -1;
  36. unsigned char u8_retry = 0;
  37. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  38. if (g_raydium_ts->is_suspend)
  39. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  40. g_u8_raydium_flag |= ENG_MODE;
  41. mutex_lock(&g_raydium_ts->lock);
  42. i32_ret = raydium_i2c_pda2_set_page(client,
  43. g_raydium_ts->is_suspend,
  44. RAYDIUM_PDA2_PAGE_0);
  45. if (i32_ret < 0)
  46. goto exit_i2c_error;
  47. u8_rbuffer[0] = RAYDIUM_HOST_CMD_CALIBRATION;
  48. i32_ret = raydium_i2c_pda2_write(client, RAYDIUM_PDA2_HOST_CMD_ADDR,
  49. u8_rbuffer, 1);
  50. if (i32_ret < 0)
  51. goto exit_i2c_error;
  52. do {
  53. if (u8_rbuffer[0] == RAYDIUM_HOST_CMD_NO_OP)
  54. break;
  55. msleep(1000);
  56. i32_ret = raydium_i2c_pda2_read(client,
  57. RAYDIUM_PDA2_HOST_CMD_ADDR,
  58. u8_rbuffer, 1);
  59. if (i32_ret < 0)
  60. goto exit_i2c_error;
  61. LOGD(LOG_INFO, "[touch]RAD %s return 0x%02x!!\n",
  62. __func__, u8_rbuffer[0]);
  63. } while (u8_retry++ < (SYN_I2C_RETRY_TIMES * 2));
  64. memcpy(p_i8_buf, u8_rbuffer, 1);
  65. u16_len = strlen(p_i8_buf);
  66. i32_ret = u16_len + 1;
  67. exit_i2c_error:
  68. mutex_unlock(&g_raydium_ts->lock);
  69. g_u8_raydium_flag &= ~ENG_MODE;
  70. return i32_ret;
  71. }
  72. static ssize_t raydium_i2c_pda_access_show(struct device *dev,
  73. struct device_attribute *attr,
  74. char *p_i8_buf)
  75. {
  76. unsigned char u8_rbuffer[4];
  77. unsigned short u16_len = 0;
  78. int i32_ret = -1;
  79. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  80. if (g_u32_length > 4)
  81. return -EINVAL;
  82. memset(u8_rbuffer, 0x00, 4);
  83. mutex_lock(&g_raydium_ts->lock);
  84. i32_ret = raydium_i2c_pda_read(client,
  85. g_u32_addr,
  86. u8_rbuffer,
  87. g_u32_length);
  88. mutex_unlock(&g_raydium_ts->lock);
  89. if (i32_ret < 0)
  90. return i32_ret;
  91. snprintf(p_i8_buf, PAGE_SIZE, "0x%08X : 0x%02X%02X%02X%02X\n",
  92. (unsigned int)g_u32_addr, u8_rbuffer[3], u8_rbuffer[2],
  93. u8_rbuffer[1], u8_rbuffer[0]);
  94. u16_len = strlen(p_i8_buf);
  95. return u16_len + 1;
  96. }
  97. static ssize_t raydium_i2c_pda_access_via_pda2_show(struct device *dev,
  98. struct device_attribute *attr,
  99. char *p_i8_buf)
  100. {
  101. unsigned char u8_rbuffer[4];
  102. unsigned short u16_len = 0;
  103. int i32_ret = -1;
  104. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  105. if (g_u32_length > 4)
  106. return -EINVAL;
  107. memset(u8_rbuffer, 0x00, 4);
  108. mutex_lock(&g_raydium_ts->lock);
  109. i32_ret = handle_i2c_pda_read(client,
  110. g_u32_addr,
  111. u8_rbuffer,
  112. g_u32_length);
  113. mutex_unlock(&g_raydium_ts->lock);
  114. if (i32_ret < 0)
  115. return i32_ret;
  116. snprintf(p_i8_buf, PAGE_SIZE, "0x%08X : 0x%02X%02X%02X%02X\n",
  117. (unsigned int)g_u32_addr, u8_rbuffer[3], u8_rbuffer[2],
  118. u8_rbuffer[1], u8_rbuffer[0]);
  119. u16_len = strlen(p_i8_buf);
  120. return u16_len + 1;
  121. }
  122. static ssize_t raydium_check_i2c_show(struct device *dev,
  123. struct device_attribute *attr,
  124. char *p_i8_buf)
  125. {
  126. unsigned char u8_rbuffer[4];
  127. unsigned short u16_len = 0;
  128. int i32_ret = -1;
  129. if (g_raydium_ts->is_suspend)
  130. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  131. mutex_lock(&g_raydium_ts->lock);
  132. i32_ret = handle_i2c_pda_read(g_raydium_ts->client,
  133. RAYDIUM_CHK_I2C_CMD, u8_rbuffer, 4);
  134. if (i32_ret < 0)
  135. goto exit_i2c_error;
  136. snprintf(p_i8_buf, PAGE_SIZE, "[touch]RAD Touch check i2c: %02X%02X\n",
  137. u8_rbuffer[3], u8_rbuffer[2]);
  138. u16_len = strlen(p_i8_buf);
  139. i32_ret = u16_len + 1;
  140. exit_i2c_error:
  141. mutex_unlock(&g_raydium_ts->lock);
  142. return i32_ret;
  143. }
  144. static ssize_t raydium_hw_reset_show(struct device *dev,
  145. struct device_attribute *attr,
  146. char *p_i8_buf)
  147. {
  148. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  149. int i32_ret = SUCCESS;
  150. LOGD(LOG_INFO, "[touch]HW reset\n");
  151. g_u8_resetflag = true;
  152. g_u8_raydium_flag |= ENG_MODE;
  153. /*HW reset*/
  154. if (gpio_is_valid(g_raydium_ts->rst_gpio)) {
  155. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  156. gpio_set_value(g_raydium_ts->rst_gpio, 0);
  157. msleep(RAYDIUM_RESET_INTERVAL_MSEC);
  158. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  159. }
  160. g_u8_i2c_mode = PDA2_MODE;
  161. if (raydium_disable_i2c_deglitch() == ERROR)
  162. LOGD(LOG_ERR, "[touch]disable_i2c_deglitch_3x NG!\r\n");
  163. i32_ret = wait_irq_state(client, 1000, 2000);
  164. if (i32_ret != ERROR)
  165. msleep(35);
  166. g_u8_raydium_flag &= ~ENG_MODE;
  167. snprintf(p_i8_buf, PAGE_SIZE, "Raydium HW Reset : %d\n", i32_ret);
  168. LOGD(LOG_INFO, "[touch]%s\n", p_i8_buf);
  169. return strlen(p_i8_buf) + 1;
  170. }
  171. static ssize_t raydium_palm_status_show(struct device *dev,
  172. struct device_attribute *attr,
  173. char *p_i8_buf)
  174. {
  175. unsigned short u16_len = 0;
  176. unsigned char u8_tp_status[MAX_TCH_STATUS_PACKET_SIZE];
  177. unsigned char u8_tp_buf[MAX_REPORT_PACKET_SIZE];
  178. raydium_read_touchdata(u8_tp_status, u8_tp_buf);
  179. snprintf(p_i8_buf, PAGE_SIZE, "[touch] palm_status : %d\n",
  180. u8_tp_status[POS_GES_STATUS]);
  181. u16_len = strlen(p_i8_buf);
  182. return u16_len + 1;
  183. }
  184. static ssize_t raydium_touch_lock_store(struct device *dev,
  185. struct device_attribute *attr,
  186. const char *p_i8_buf, size_t count)
  187. {
  188. int i32_ret = 0;
  189. unsigned char u8_mode;
  190. unsigned char u8_wbuffer[1];
  191. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  192. if (g_raydium_ts->is_suspend)
  193. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  194. /* receive command line arguments string */
  195. if (count > 2)
  196. return -EINVAL;
  197. i32_ret = kstrtou8(p_i8_buf, 16, &u8_mode);
  198. if (i32_ret < 0)
  199. return i32_ret;
  200. g_u8_raydium_flag |= ENG_MODE;
  201. mutex_lock(&g_raydium_ts->lock);
  202. switch (u8_mode) {
  203. case 0: /* Disable Touch lock */
  204. if (g_raydium_ts->is_sleep != 1)
  205. break;
  206. g_u8_resetflag = true;
  207. if (gpio_is_valid(g_raydium_ts->rst_gpio)) {
  208. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  209. gpio_set_value(g_raydium_ts->rst_gpio, 0);
  210. msleep(RAYDIUM_RESET_INTERVAL_MSEC);/*5ms*/
  211. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  212. msleep(RAYDIUM_RESET_DELAY_MSEC);/*100ms*/
  213. }
  214. LOGD(LOG_INFO, "[touch]RAD %s disable touch lock!!\n", __func__);
  215. g_raydium_ts->is_sleep = 0;
  216. break;
  217. case 1: /* Enable Touch lock */
  218. if (g_raydium_ts->is_sleep == 1)
  219. break;
  220. i32_ret = raydium_i2c_pda2_set_page(client,
  221. g_raydium_ts->is_suspend,
  222. RAYDIUM_PDA2_PAGE_0);
  223. if (i32_ret < 0)
  224. goto exit_i2c_error;
  225. /*fw enter sleep mode*/
  226. u8_wbuffer[0] = RAYDIUM_HOST_CMD_PWR_SLEEP;
  227. i32_ret = raydium_i2c_pda2_write(client,
  228. RAYDIUM_PDA2_HOST_CMD_ADDR,
  229. u8_wbuffer,
  230. 1);
  231. if (i32_ret < 0)
  232. goto exit_i2c_error;
  233. LOGD(LOG_INFO, "[touch]RAD %s enable touch lock!!\n", __func__);
  234. g_raydium_ts->is_sleep = 1;
  235. break;
  236. }
  237. exit_i2c_error:
  238. mutex_unlock(&g_raydium_ts->lock);
  239. g_u8_raydium_flag &= ~ENG_MODE;
  240. return count;
  241. }
  242. static ssize_t raydium_check_driver_version_show(struct device *dev,
  243. struct device_attribute *attr,
  244. char *p_i8_buf)
  245. {
  246. /*unsigned char rbuffer[4];*/
  247. unsigned short u16_len = 0;
  248. int i32_ret = -1;
  249. snprintf(p_i8_buf, PAGE_SIZE, "RAD Driver Ver: 0x%X\n",
  250. g_u32_driver_version);
  251. u16_len = strlen(p_i8_buf);
  252. i32_ret = u16_len + 1;
  253. return i32_ret;
  254. }
  255. static ssize_t raydium_check_fw_version_show(struct device *dev,
  256. struct device_attribute *attr,
  257. char *p_i8_buf)
  258. {
  259. unsigned char u8_rbuffer[4];
  260. unsigned short u16_len = 0;
  261. int i32_ret = -1;
  262. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  263. unsigned int fw_version, image_version;
  264. if (g_raydium_ts->is_suspend)
  265. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  266. g_u8_raydium_flag |= ENG_MODE;
  267. mutex_lock(&g_raydium_ts->lock);
  268. i32_ret = raydium_i2c_pda2_set_page(client,
  269. g_raydium_ts->is_suspend,
  270. RAYDIUM_PDA2_PAGE_0);
  271. if (i32_ret < 0)
  272. goto exit_i2c_error;
  273. i32_ret = raydium_i2c_pda2_read(client, RAYDIUM_PDA2_FW_VERSION_ADDR,
  274. u8_rbuffer, 4);
  275. if (i32_ret < 0)
  276. goto exit_i2c_error;
  277. snprintf(p_i8_buf, PAGE_SIZE, "RAD Touch FW Ver : %02X%02X%02X%02X\n",
  278. u8_rbuffer[0], u8_rbuffer[1], u8_rbuffer[2], u8_rbuffer[3]);
  279. fw_version = (u8_rbuffer[0] << 24)
  280. | (u8_rbuffer[1] << 16)
  281. | (u8_rbuffer[2] << 8)
  282. | u8_rbuffer[3];
  283. LOGD(LOG_INFO, "[touch]RAD FW ver : 0x%x\n", fw_version);
  284. image_version = (g_rad_para_image[PARA_FW_VERSION_OFFSET] << 24) |
  285. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 1] << 16) |
  286. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 2] << 8) |
  287. g_rad_para_image[PARA_FW_VERSION_OFFSET + 3];
  288. LOGD(LOG_INFO, "[touch]RAD Image FW ver : 0x%x\n", image_version);
  289. mutex_unlock(&g_raydium_ts->lock);
  290. g_u8_raydium_flag &= ~ENG_MODE;
  291. if (fw_version != image_version)
  292. LOGD(LOG_INFO, "[touch]%s, FW need upgrade.\n", __func__);
  293. u16_len = strlen(p_i8_buf);
  294. i32_ret = u16_len + 1;
  295. goto exit_upgrade;
  296. exit_i2c_error:
  297. mutex_unlock(&g_raydium_ts->lock);
  298. g_u8_raydium_flag &= ~ENG_MODE;
  299. exit_upgrade:
  300. return i32_ret;
  301. }
  302. static ssize_t raydium_check_panel_version_show(struct device *dev,
  303. struct device_attribute *attr,
  304. char *p_i8_buf)
  305. {
  306. unsigned char u8_rbuffer[8];
  307. unsigned short u16_len = 0;
  308. int i32_ret = -1;
  309. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  310. if (g_raydium_ts->is_suspend)
  311. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  312. g_u8_raydium_flag |= ENG_MODE;
  313. mutex_lock(&g_raydium_ts->lock);
  314. i32_ret = raydium_i2c_pda2_set_page(client,
  315. g_raydium_ts->is_suspend,
  316. RAYDIUM_PDA2_PAGE_0);
  317. if (i32_ret < 0)
  318. goto exit_i2c_error;
  319. i32_ret = raydium_i2c_pda2_read(client,
  320. RAYDIUM_PDA2_PANEL_VERSION_ADDR,
  321. u8_rbuffer, 8);
  322. if (i32_ret < 0)
  323. goto exit_i2c_error;
  324. snprintf(p_i8_buf, PAGE_SIZE,
  325. "RAD Touch Panel Version : %02X%02X%02X%02X%02X%02X\n",
  326. u8_rbuffer[0], u8_rbuffer[1], u8_rbuffer[2],
  327. u8_rbuffer[3], u8_rbuffer[4], u8_rbuffer[5]);
  328. mutex_unlock(&g_raydium_ts->lock);
  329. g_u8_raydium_flag &= ~ENG_MODE;
  330. u16_len = strlen(p_i8_buf);
  331. i32_ret = u16_len + 1;
  332. goto exit_upgrade;
  333. exit_i2c_error:
  334. mutex_unlock(&g_raydium_ts->lock);
  335. g_u8_raydium_flag &= ~ENG_MODE;
  336. exit_upgrade:
  337. return i32_ret;
  338. }
  339. static ssize_t raydium_fw_upgrade_store(struct device *dev,
  340. struct device_attribute *attr,
  341. const char *p_i8_buf, size_t count)
  342. {
  343. int i32_ret = 0;
  344. /* receive command line arguments string */
  345. if (count > 2)
  346. return -EINVAL;
  347. i32_ret = kstrtou8(p_i8_buf, 16, &g_u8_upgrade_type);
  348. if (i32_ret < 0)
  349. return i32_ret;
  350. return count;
  351. }
  352. static ssize_t raydium_fw_upgrade_show(struct device *dev,
  353. struct device_attribute *attr,
  354. char *p_i8_buf)
  355. {
  356. int i32_ret = 0, i32_result = FAIL;
  357. unsigned short u16_len = 0;
  358. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  359. LOGD(LOG_INFO, "[touch]RAD burn type is %d\n", g_u8_upgrade_type);
  360. g_u8_raydium_flag |= ENG_MODE;
  361. if ((g_u8_table_setting == 1) && (g_u8_table_init == 1))
  362. raydium_mem_table_setting();
  363. if (g_u8_upgrade_type == 1) {
  364. i32_ret = raydium_burn_fw(client);
  365. if (i32_ret < 0)
  366. goto exit_upgrade;
  367. i32_result = SUCCESS;
  368. } else if (g_u8_upgrade_type == 2) {
  369. i32_ret = raydium_burn_comp(client);
  370. if (i32_ret < 0)
  371. goto exit_upgrade;
  372. i32_result = SUCCESS;
  373. }
  374. #ifdef RAD_SELFTEST
  375. else if (g_u8_upgrade_type == 4) {
  376. i32_ret = raydium_load_test_fw(client);
  377. if (i32_ret < 0)
  378. goto exit_upgrade;
  379. i32_result = SUCCESS;
  380. }
  381. #endif
  382. exit_upgrade:
  383. LOGD(LOG_DEBUG, "[touch]g_u8_raydium_flag : %d", g_u8_raydium_flag);
  384. g_u8_raydium_flag &= ~ENG_MODE;
  385. g_u8_upgrade_type = 0;
  386. snprintf(p_i8_buf, PAGE_SIZE, "FW Upgrade result : %d\n", i32_result);
  387. u16_len = strlen(p_i8_buf);
  388. return u16_len + 1;
  389. }
  390. static ssize_t raydium_i2c_pda2_page_store(struct device *dev,
  391. struct device_attribute *attr,
  392. const char *p_i8_buf, size_t count)
  393. {
  394. int i32_ret = 0;
  395. unsigned char u8_page = 0;
  396. char *temp_buf, *token, *free_temp_buf, *free_token;
  397. const char *delim = " ,";
  398. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  399. /* receive command line arguments string */
  400. if (count < 2)
  401. return -EINVAL;
  402. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  403. if (temp_buf == NULL)
  404. return -ENOMEM;
  405. token = kzalloc(count + 1, GFP_KERNEL);
  406. if (token == NULL) {
  407. kfree(temp_buf);
  408. return -ENOMEM;
  409. }
  410. free_temp_buf = temp_buf;
  411. free_token = token;
  412. strlcpy(temp_buf, p_i8_buf, count);
  413. token = strsep(&temp_buf, delim);
  414. if (temp_buf) {
  415. LOGD(LOG_ERR, "[touch]input error, extra auguments!n");
  416. i32_ret = -EINVAL;
  417. goto exit_error;
  418. }
  419. i32_ret = kstrtou8(token, 16, &u8_page);
  420. if (i32_ret < 0)
  421. goto exit_error;
  422. mutex_lock(&g_raydium_ts->lock);
  423. i32_ret = raydium_i2c_pda2_set_page(client, g_raydium_ts->is_suspend, u8_page);
  424. if (i32_ret < 0)
  425. goto exit_set_error;
  426. /* TODO: Page check, Due to ISR will change page back to Page_0.
  427. * Or disable IRQ during PDA2 access period
  428. */
  429. exit_set_error:
  430. mutex_unlock(&g_raydium_ts->lock);
  431. exit_error:
  432. kfree(free_token);
  433. kfree(free_temp_buf);
  434. return count;
  435. }
  436. static ssize_t raydium_mem_store(struct device *dev,
  437. struct device_attribute *attr,
  438. const char *p_i8_buf, size_t count)
  439. {
  440. int i32_ret = 0;
  441. unsigned char u8_type = 0;
  442. unsigned int u32_image_version;
  443. /* receive command line arguments string */
  444. if (count > 2)
  445. return -EINVAL;
  446. LOGD(LOG_INFO, "[touch]%s\n", __func__);
  447. i32_ret = kstrtou8(p_i8_buf, 16, &u8_type);
  448. if (i32_ret < 0)
  449. return i32_ret;
  450. if (u8_type > 3) {
  451. LOGD(LOG_ERR, "[touch]Input invalid value!!\n");
  452. return ERROR;
  453. }
  454. if (g_rad_boot_image) {
  455. kfree(g_rad_boot_image);
  456. g_rad_boot_image = NULL;
  457. }
  458. if (g_rad_init_image) {
  459. kfree(g_rad_init_image);
  460. g_rad_init_image = NULL;
  461. }
  462. if (g_rad_fw_image) {
  463. kfree(g_rad_fw_image);
  464. g_rad_fw_image = NULL;
  465. }
  466. if (g_rad_para_image) {
  467. ree(g_rad_para_image);
  468. g_rad_para_image = NULL;
  469. }
  470. if (g_rad_testfw_image) {
  471. kfree(g_rad_testfw_image);
  472. g_rad_testfw_image = NULL;
  473. }
  474. if (g_rad_testpara_image) {
  475. free(g_rad_testpara_image);
  476. g_rad_testpara_image = NULL;
  477. }
  478. if (!raydium_id_init(u8_type)) {
  479. LOGD(LOG_ERR, "[touch]Set Raydium id failed!\n");
  480. return count;
  481. }
  482. raydium_mem_table_init(g_raydium_ts->id);
  483. if (raydium_mem_table_setting()) {
  484. u32_image_version = (g_rad_para_image[PARA_FW_VERSION_OFFSET] << 24) |
  485. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 1] << 16) |
  486. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 2] << 8) |
  487. g_rad_para_image[PARA_FW_VERSION_OFFSET + 3];
  488. LOGD(LOG_INFO, "[touch]RAD Image FW ver : 0x%x\n", u32_image_version);
  489. } else
  490. LOGD(LOG_ERR, "[touch]Mem init failed!\n");
  491. if (g_rad_para_image) {
  492. kfree(g_rad_para_image);
  493. g_rad_para_image = NULL;
  494. }
  495. return count;
  496. }
  497. static ssize_t raydium_i2c_raw_data_store(struct device *dev,
  498. struct device_attribute *attr,
  499. const char *p_i8_buf, size_t count)
  500. {
  501. int i32_ret = 0;
  502. char *temp_buf, *token, *free_temp_buf, *free_token;
  503. const char *delim = " ,";
  504. unsigned char u8_w_data[RAD_FT_CMD_LENGTH];
  505. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  506. /* receive command line arguments string */
  507. if (count < 2)
  508. return -EINVAL;
  509. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  510. if (temp_buf == NULL) {
  511. LOGD(LOG_ERR, "[touch]kzalloc temp_buf failed\n");
  512. return -ENOMEM;
  513. }
  514. token = kzalloc(count + 1, GFP_KERNEL);
  515. if (token == NULL) {
  516. kfree(temp_buf);
  517. return -ENOMEM;
  518. }
  519. free_temp_buf = temp_buf;
  520. free_token = token;
  521. strlcpy(temp_buf, p_i8_buf, count);
  522. token = strsep(&temp_buf, delim);
  523. i32_ret = kstrtou8(token, 16, &g_u8_raw_data_type);
  524. token = strsep(&temp_buf, delim);
  525. if (token) {
  526. i32_ret = kstrtouint(token, 16, &g_u32_raw_data_len);
  527. if (i32_ret < 0)
  528. goto exit_error;
  529. } else { /* without length info*/
  530. i32_ret = -EINVAL;
  531. goto exit_error;
  532. }
  533. if (temp_buf) { /* too much arguments*/
  534. i32_ret = -E2BIG;
  535. goto exit_error;
  536. }
  537. memset(u8_w_data, 0x00, RAD_FT_CMD_LENGTH);
  538. mutex_lock(&g_raydium_ts->lock);
  539. i32_ret = raydium_i2c_pda2_set_page(client,
  540. g_raydium_ts->is_suspend,
  541. RAYDIUM_PDA2_PAGE_0);
  542. if (i32_ret < 0) {
  543. mutex_unlock(&g_raydium_ts->lock);
  544. goto exit_error;
  545. }
  546. g_u8_resetflag = true;
  547. u8_w_data[RAD_HOST_CMD_POS] = RAYDIUM_HOST_CMD_NO_OP;
  548. u8_w_data[RAD_FT_CMD_POS] = g_u8_raw_data_type;
  549. i32_ret = raydium_i2c_pda2_write(client, RAYDIUM_PDA2_HOST_CMD_ADDR,
  550. u8_w_data, RAD_FT_CMD_LENGTH);
  551. mutex_unlock(&g_raydium_ts->lock);
  552. if (i32_ret < 0)
  553. goto exit_error;
  554. if (g_u8_raw_data_type == 0) {
  555. msleep(20);
  556. g_u8_resetflag = false;
  557. }
  558. exit_error:
  559. kfree(free_token);
  560. kfree(free_temp_buf);
  561. return count;
  562. }
  563. static ssize_t raydium_i2c_raw_data_show(struct device *dev,
  564. struct device_attribute *attr,
  565. char *p_i8_buf)
  566. {
  567. unsigned char u8_rbuffer[MAX_READ_PACKET_SIZE];
  568. unsigned int u32_target_addr;
  569. unsigned int u32_offset;
  570. unsigned short u16_read_length;
  571. int i32_ret = -1;
  572. int i32_retry = 0;
  573. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  574. struct raydium_ts_data *ts =
  575. (struct raydium_ts_data *)i2c_get_clientdata(client);
  576. unsigned char u8_retry_limit = (ts->is_suspend) ? 100 : 30;
  577. memset(u8_rbuffer, 0x00, MAX_READ_PACKET_SIZE);
  578. /* make sure update flag was set*/
  579. for (i32_retry = 0; i32_retry < u8_retry_limit; i32_retry++) {
  580. mutex_lock(&ts->lock);
  581. i32_ret = raydium_i2c_pda2_set_page(client,
  582. ts->is_suspend,
  583. RAYDIUM_PDA2_PAGE_0);
  584. if (i32_ret < 0) {
  585. mutex_unlock(&ts->lock);
  586. goto exit_i2c_error;
  587. }
  588. i32_ret = raydium_i2c_pda2_read(client,
  589. RAYDIUM_PDA2_HOST_CMD_ADDR,
  590. u8_rbuffer,
  591. RAD_FT_CMD_LENGTH);
  592. mutex_unlock(&ts->lock);
  593. if (i32_ret < 0)
  594. goto exit_flag_error;
  595. if ((u8_rbuffer[RAD_FT_CMD_POS] & RAYDIUM_FT_UPDATE) ==
  596. RAYDIUM_FT_UPDATE)
  597. break;
  598. usleep_range(500, 1500);
  599. }
  600. if (i32_retry == u8_retry_limit) {
  601. i32_ret = -EAGAIN;
  602. goto exit_flag_error;
  603. }
  604. u32_offset = 0;
  605. u16_read_length = 0;
  606. while (u32_offset < g_u32_raw_data_len) {
  607. if ((u32_offset + MAX_READ_PACKET_SIZE) <
  608. g_u32_raw_data_len)
  609. u16_read_length = MAX_READ_PACKET_SIZE;
  610. else
  611. u16_read_length =
  612. (unsigned short)(g_u32_raw_data_len - u32_offset);
  613. u32_target_addr = RAD_READ_FT_DATA_CMD + u32_offset;
  614. mutex_lock(&(ts->lock));
  615. /*using byte mode to read 4 bytes*/
  616. i32_ret = handle_i2c_pda_read(client,
  617. u32_target_addr,
  618. u8_rbuffer,
  619. u16_read_length);
  620. mutex_unlock(&(ts->lock));
  621. if (i32_ret < 0)
  622. goto exit_flag_error;
  623. memcpy((p_i8_buf + u32_offset), u8_rbuffer, u16_read_length);
  624. u32_offset += u16_read_length;
  625. }
  626. /* clear update flag to get next one*/
  627. u8_rbuffer[RAD_HOST_CMD_POS] = RAYDIUM_HOST_CMD_NO_OP;
  628. u8_rbuffer[RAD_FT_CMD_POS] = g_u8_raw_data_type;
  629. mutex_lock(&ts->lock);
  630. i32_ret = raydium_i2c_pda2_write(client, RAYDIUM_PDA2_HOST_CMD_ADDR,
  631. u8_rbuffer, RAD_FT_CMD_LENGTH);
  632. mutex_unlock(&ts->lock);
  633. if (i32_ret < 0)
  634. goto exit_flag_error;
  635. return g_u32_raw_data_len;
  636. exit_i2c_error:
  637. mutex_unlock(&(ts->lock));
  638. exit_flag_error:
  639. return i32_ret;
  640. }
  641. static ssize_t raydium_i2c_pda_access_store(struct device *dev,
  642. struct device_attribute *attr,
  643. const char *p_i8_buf, size_t count)
  644. {
  645. int i32_ret = 0;
  646. char *temp_buf, *token, *free_temp_buf, *free_token;
  647. const char *delim = " ,";
  648. unsigned char u8_w_data[MAX_WRITE_PACKET_SIZE];
  649. unsigned int u32_data_count = 0;
  650. unsigned int u32_data_index = 0;
  651. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  652. /* receive command line arguments string */
  653. if (count < 2)
  654. return -EINVAL;
  655. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  656. if (temp_buf == NULL)
  657. return -ENOMEM;
  658. token = kzalloc(count + 1, GFP_KERNEL);
  659. if (token == NULL) {
  660. kfree(temp_buf);
  661. return -ENOMEM;
  662. }
  663. free_temp_buf = temp_buf;
  664. free_token = token;
  665. strlcpy(temp_buf, p_i8_buf, count);
  666. token = strsep(&temp_buf, delim);
  667. i32_ret = kstrtoul(token, 16, &g_u32_addr);
  668. token = strsep(&temp_buf, delim);
  669. if (token)
  670. i32_ret = kstrtouint(token, 16, &u32_data_count);
  671. else
  672. goto exit_error;
  673. if (g_u32_length > MAX_WRITE_PACKET_SIZE)
  674. return -EINVAL;
  675. g_u32_length = u32_data_count;
  676. memset(u8_w_data, 0x00, MAX_WRITE_PACKET_SIZE);
  677. if (temp_buf && u32_data_count) {
  678. u32_data_index = 0;
  679. while (u32_data_count) {
  680. token = strsep(&temp_buf, delim);
  681. i32_ret = kstrtou8(token, 16,
  682. &u8_w_data[u32_data_index++]);
  683. if (i32_ret < 0)
  684. goto exit_error;
  685. u32_data_count--;
  686. }
  687. mutex_lock(&g_raydium_ts->lock);
  688. i32_ret = raydium_i2c_pda_write(client, g_u32_addr,
  689. u8_w_data, g_u32_length);
  690. mutex_unlock(&g_raydium_ts->lock);
  691. }
  692. exit_error:
  693. kfree(free_token);
  694. kfree(free_temp_buf);
  695. return count;
  696. }
  697. static ssize_t raydium_i2c_pda_access_via_pda2_store(struct device *dev,
  698. struct device_attribute *attr,
  699. const char *p_i8_buf, size_t count)
  700. {
  701. int i32_ret = 0;
  702. char *temp_buf, *token, *free_temp_buf, *free_token;
  703. const char *delim = " ,";
  704. unsigned char u8_w_data[MAX_WRITE_PACKET_SIZE];
  705. unsigned int u32_data_count = 0;
  706. unsigned int u32_data_index = 0;
  707. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  708. /* receive command line arguments string */
  709. if (count < 2)
  710. return -EINVAL;
  711. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  712. if (temp_buf == NULL)
  713. return -ENOMEM;
  714. token = kzalloc(count + 1, GFP_KERNEL);
  715. if (token == NULL) {
  716. kfree(temp_buf);
  717. return -ENOMEM;
  718. }
  719. free_temp_buf = temp_buf;
  720. free_token = token;
  721. strlcpy(temp_buf, p_i8_buf, count);
  722. token = strsep(&temp_buf, delim);
  723. i32_ret = kstrtoul(token, 16, &g_u32_addr);
  724. token = strsep(&temp_buf, delim);
  725. if (token)
  726. i32_ret = kstrtouint(token, 16, &u32_data_count);
  727. else
  728. goto exit_error;
  729. if (g_u32_length > MAX_WRITE_PACKET_SIZE)
  730. return -EINVAL;
  731. g_u32_length = u32_data_count;
  732. memset(u8_w_data, 0x00, MAX_WRITE_PACKET_SIZE);
  733. if (temp_buf && u32_data_count) {
  734. u32_data_index = 0;
  735. while (u32_data_count) {
  736. token = strsep(&temp_buf, delim);
  737. i32_ret = kstrtou8(token, 16,
  738. &u8_w_data[u32_data_index++]);
  739. if (i32_ret < 0)
  740. goto exit_error;
  741. u32_data_count--;
  742. }
  743. mutex_lock(&g_raydium_ts->lock);
  744. i32_ret = handle_i2c_pda_write(client, g_u32_addr,
  745. u8_w_data, g_u32_length);
  746. mutex_unlock(&g_raydium_ts->lock);
  747. }
  748. exit_error:
  749. kfree(free_token);
  750. kfree(free_temp_buf);
  751. return count;
  752. }
  753. static ssize_t raydium_i2c_pda2_mode_store(struct device *dev,
  754. struct device_attribute *attr,
  755. const char *p_i8_buf, size_t count)
  756. {
  757. int i32_ret = 0;
  758. unsigned char u8_mode;
  759. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  760. if (g_raydium_ts->is_suspend)
  761. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  762. /* receive command line arguments string */
  763. if (count > 2)
  764. return -EINVAL;
  765. i32_ret = kstrtou8(p_i8_buf, 16, &u8_mode);
  766. if (i32_ret < 0)
  767. return i32_ret;
  768. i32_ret = raydium_i2c_mode_control(client, u8_mode);
  769. if (i32_ret < 0)
  770. return i32_ret;
  771. return count;
  772. }
  773. static ssize_t raydium_i2c_pda2_access_show(struct device *dev,
  774. struct device_attribute *attr,
  775. char *p_i8_buf)
  776. {
  777. unsigned char u8_rbuffer[4];
  778. unsigned short u16_len = 0;
  779. int i32_ret = -1;
  780. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  781. if (g_u32_length > 4)
  782. return -EINVAL;
  783. memset(u8_rbuffer, 0x00, 4);
  784. mutex_lock(&g_raydium_ts->lock);
  785. i32_ret = raydium_i2c_pda2_read(client, g_u8_addr,
  786. u8_rbuffer, g_u32_length);
  787. mutex_unlock(&g_raydium_ts->lock);
  788. if (i32_ret < 0)
  789. return i32_ret;
  790. snprintf(p_i8_buf, PAGE_SIZE, "0x%04X : 0x%02X%02X%02X%02X\n",
  791. g_u8_addr, u8_rbuffer[3], u8_rbuffer[2],
  792. u8_rbuffer[1], u8_rbuffer[0]);
  793. u16_len = strlen(p_i8_buf);
  794. return u16_len + 1;
  795. }
  796. static ssize_t raydium_i2c_pda2_access_store(struct device *dev,
  797. struct device_attribute *attr,
  798. const char *p_i8_buf, size_t count)
  799. {
  800. int i32_ret = 0;
  801. char *temp_buf, *token, *free_temp_buf, *free_token;
  802. const char *delim = " ,";
  803. unsigned char u8_w_data[MAX_WRITE_PACKET_SIZE];
  804. unsigned int u32_data_count = 0;
  805. unsigned int u32_data_index = 0;
  806. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  807. /* receive command line arguments string */
  808. if (count < 2)
  809. return -EINVAL;
  810. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  811. if (temp_buf == NULL) {
  812. LOGD(LOG_ERR, "[touch]kzalloc temp_buf failed\n");
  813. return -ENOMEM;
  814. }
  815. token = kzalloc(count + 1, GFP_KERNEL);
  816. if (token == NULL) {
  817. kfree(temp_buf);
  818. return -ENOMEM;
  819. }
  820. free_temp_buf = temp_buf;
  821. free_token = token;
  822. strlcpy(temp_buf, p_i8_buf, count);
  823. token = strsep(&temp_buf, delim);
  824. i32_ret = kstrtou8(token, 16, &g_u8_addr);
  825. token = strsep(&temp_buf, delim);
  826. if (token)
  827. i32_ret = kstrtouint(token, 16, &u32_data_count);
  828. else {
  829. i32_ret = -EINVAL;
  830. goto exit_error;
  831. }
  832. if (u32_data_count > MAX_WRITE_PACKET_SIZE) {
  833. i32_ret = -EINVAL;
  834. goto exit_error;
  835. }
  836. memset(u8_w_data, 0x00, MAX_WRITE_PACKET_SIZE);
  837. g_u32_length = u32_data_count;
  838. if (temp_buf && u32_data_count) {
  839. u32_data_index = 0;
  840. while (u32_data_count) {
  841. token = strsep(&temp_buf, delim);
  842. i32_ret = kstrtou8(token, 16,
  843. &u8_w_data[u32_data_index++]);
  844. if (i32_ret < 0)
  845. goto exit_error;
  846. u32_data_count--;
  847. }
  848. mutex_lock(&g_raydium_ts->lock);
  849. i32_ret = raydium_i2c_pda2_write(client, g_u8_addr,
  850. u8_w_data, g_u32_length);
  851. mutex_unlock(&g_raydium_ts->lock);
  852. if (i32_ret < 0)
  853. goto exit_error;
  854. }
  855. exit_error:
  856. kfree(free_token);
  857. kfree(free_temp_buf);
  858. return count;
  859. }
  860. static ssize_t raydium_receive_fw_store(struct device *dev,
  861. struct device_attribute *attr,
  862. const char *p_i8_buf, size_t count)
  863. {
  864. int i32_ret = 0;
  865. const char *delim = " ,";
  866. char *token, *temp_buf, *free_token = NULL, *free_temp_buf = NULL;
  867. static unsigned char *p_u8_firmware_data;
  868. unsigned char u8_cmd;
  869. unsigned long u32_len;
  870. static unsigned char u8_type;
  871. static unsigned int u32_index;
  872. if (count == 20) { /*check FW type*/
  873. temp_buf = kzalloc(32, GFP_KERNEL);
  874. if (temp_buf == NULL) {
  875. LOGD(LOG_ERR, "[touch]kzalloc temp_buf failed\n");
  876. return -ENOMEM;
  877. }
  878. token = kzalloc(32, GFP_KERNEL);
  879. if (token == NULL) {
  880. kfree(temp_buf);
  881. return -ENOMEM;
  882. }
  883. free_token = token;
  884. free_temp_buf = temp_buf;
  885. snprintf(temp_buf, PAGE_SIZE, "%s", p_i8_buf);
  886. token = strsep(&temp_buf, delim);
  887. i32_ret = kstrtou8(token, 16, &u8_cmd);
  888. if (i32_ret < 0) {
  889. LOGD(LOG_ERR, "[touch]kstrtou8 failed\n");
  890. kfree(free_token);
  891. free_token = NULL;
  892. kfree(free_temp_buf);
  893. free_temp_buf = NULL;
  894. }
  895. token = strsep(&temp_buf, delim);
  896. i32_ret = kstrtou8(token, 16, &u8_type);
  897. if (i32_ret < 0) {
  898. LOGD(LOG_ERR, "[touch]kstrtou8 failed\n");
  899. kfree(temp_buf);
  900. kfree(token);
  901. }
  902. token = strsep(&temp_buf, delim);
  903. i32_ret = kstrtoul(token, 16, &u32_len);
  904. if (i32_ret < 0) {
  905. LOGD(LOG_ERR, "[touch]kstrtou8 failed\n");
  906. kfree(temp_buf);
  907. kfree(token);
  908. }
  909. LOGD(LOG_INFO, "[touch]uc_cmd=0x%x, uc_type=0x%x, u16_len=0x%x\n",
  910. u8_cmd, u8_type, (unsigned int)u32_len);
  911. if (u8_cmd == RAD_CMD_UPDATE_BIN) { /*check FW length*/
  912. u32_index = 0;
  913. if (u8_type == RAYDIUM_BOOTLOADER) {
  914. memset(g_rad_boot_image, 0, u32_len);
  915. p_u8_firmware_data = g_rad_boot_image;
  916. } else if (u8_type == RAYDIUM_INIT) {
  917. memset(g_rad_init_image, 0, u32_len);
  918. p_u8_firmware_data = g_rad_init_image;
  919. } else if (u8_type == RAYDIUM_PARA) {
  920. memset(g_rad_para_image, 0, u32_len);
  921. p_u8_firmware_data = g_rad_para_image;
  922. } else if (u8_type == RAYDIUM_FIRMWARE) {
  923. memset(g_rad_fw_image, 0, u32_len);
  924. p_u8_firmware_data = g_rad_fw_image;
  925. } else if (u8_type == RAYDIUM_TEST_PARA) {
  926. memset(g_rad_testpara_image, 0, u32_len);
  927. p_u8_firmware_data = g_rad_testpara_image;
  928. } else if (u8_type == RAYDIUM_TEST_FW) {
  929. memset(g_rad_testfw_image, 0, u32_len);
  930. p_u8_firmware_data = g_rad_testfw_image;
  931. }
  932. } else if (u8_cmd == RAD_CMD_UPDATE_END) { /*set buffer finish*/
  933. if (u8_type == RAYDIUM_TEST_FW) {
  934. memcpy((g_rad_testfw_image + RAD_FW_3X_SIZE),
  935. g_rad_testpara_image, RAD_PARA_3X_SIZE + 4);
  936. }
  937. u32_index = 0;
  938. g_u8_table_setting = 0;
  939. } else if (u8_cmd == RAD_CMD_BURN_FINISH) { /*free buffer*/
  940. u8_type = 0;
  941. u32_index = 0;
  942. g_u8_table_setting = 1;
  943. }
  944. if (free_temp_buf) {
  945. kfree(free_temp_buf);
  946. free_temp_buf = NULL;
  947. }
  948. if (free_token) {
  949. kfree(free_token);
  950. free_token = NULL;
  951. }
  952. } else if (count > 10) { /*start copy FW to array*/
  953. memcpy((p_u8_firmware_data + u32_index), p_i8_buf, count);
  954. u32_index += count;
  955. } else
  956. LOGD(LOG_ERR, "[touch]other case, count=%d\n", count);
  957. return count;
  958. }
  959. static ssize_t raydium_log_level_store(struct device *dev,
  960. struct device_attribute *attr,
  961. const char *p_i8_buf, size_t count)
  962. {
  963. int i32_ret = 0;
  964. unsigned char u8_level = 0;
  965. /* receive command line arguments string */
  966. if (count > 2)
  967. return -EINVAL;
  968. i32_ret = kstrtou8(p_i8_buf, 16, &u8_level);
  969. if (i32_ret < 0)
  970. return i32_ret;
  971. g_u8_log_level = u8_level;
  972. LOGD(LOG_ERR, "[touch]g_u8_log_level = %d\r\n", g_u8_log_level);
  973. return count;
  974. }
  975. #ifdef RAD_SELFTEST
  976. static ssize_t raydium_reset_control_store(struct device *dev,
  977. struct device_attribute *attr,
  978. const char *p_i8_buf, size_t count)
  979. {
  980. int i32_ret = 0;
  981. unsigned char u8_high;
  982. if (g_raydium_ts->is_suspend)
  983. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  984. /* receive command line arguments string */
  985. if (count > 2)
  986. return -EINVAL;
  987. i32_ret = kstrtou8(p_i8_buf, 16, &u8_high);
  988. if (i32_ret < 0)
  989. return i32_ret;
  990. g_u8_i2c_mode = PDA2_MODE;
  991. g_u8_resetflag = true;
  992. if (u8_high) {
  993. LOGD(LOG_INFO, "[touch]RAD %s set reset gpio to high!!\n",
  994. __func__);
  995. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  996. } else {
  997. LOGD(LOG_INFO, "[touch]RAD %s set reset gpio to low!!\n",
  998. __func__);
  999. gpio_set_value(g_raydium_ts->rst_gpio, 0);
  1000. }
  1001. return count;
  1002. }
  1003. static ssize_t raydium_irq_state_show(struct device *dev,
  1004. struct device_attribute *attr,
  1005. char *p_i8_buf)
  1006. {
  1007. unsigned int u32_irq_value;
  1008. u32_irq_value = gpio_get_value(g_raydium_ts->irq_gpio);
  1009. snprintf(p_i8_buf, PAGE_SIZE, "%d", u32_irq_value);
  1010. LOGD(LOG_DEBUG, "%s\n", p_i8_buf);
  1011. return strlen(p_i8_buf) + 1;
  1012. }
  1013. static ssize_t raydium_flag_show(struct device *dev,
  1014. struct device_attribute *attr,
  1015. char *p_i8_buf)
  1016. {
  1017. unsigned short u16_len = 0;
  1018. snprintf(p_i8_buf, PAGE_SIZE, "%d", g_u8_raydium_flag);
  1019. LOGD(LOG_DEBUG, "[touch]RAD flag : %d\n", g_u8_raydium_flag);
  1020. u16_len = strlen(p_i8_buf);
  1021. return u16_len + 1;
  1022. }
  1023. static ssize_t raydium_flag_store(struct device *dev,
  1024. struct device_attribute *attr,
  1025. const char *p_i8_buf, size_t count)
  1026. {
  1027. int i32_ret = 0;
  1028. unsigned char u8_flag = 0;
  1029. /* receive command line arguments string */
  1030. if (count > 2)
  1031. return -EINVAL;
  1032. i32_ret = kstrtou8(p_i8_buf, 16, &u8_flag);
  1033. if (i32_ret < 0)
  1034. return i32_ret;
  1035. g_u8_raydium_flag = u8_flag;
  1036. return count;
  1037. }
  1038. static ssize_t raydium_selftest_show(struct device *dev,
  1039. struct device_attribute *attr,
  1040. char *p_i8_buf)
  1041. {
  1042. int i32_ret = SUCCESS;
  1043. LOGD(LOG_INFO, "[touch]do selftest\n");
  1044. i32_ret = raydium_do_selftest(g_raydium_ts);
  1045. snprintf(p_i8_buf, PAGE_SIZE, "Raydium do selftest : %d\n", i32_ret);
  1046. return strlen(p_i8_buf) + 1;
  1047. }
  1048. #endif
  1049. /* panel calibration cmd (R)
  1050. * example:cat raydium_ic_verion
  1051. */
  1052. static DEVICE_ATTR(raydium_touch_calibration, 0644,
  1053. raydium_touch_calibration_show,
  1054. NULL);
  1055. /* check the i2c (R)
  1056. * example:cat raydium_check_i2c
  1057. */
  1058. static DEVICE_ATTR(raydium_check_i2c, 0644,
  1059. raydium_check_i2c_show,
  1060. NULL);
  1061. /* upgrade configurate and algo firmware from app.bin (W)
  1062. * example:echo "offset num_of_bin length *_app.bin [length *_app.bin]"
  1063. * > raydium_fw_upgrade_mode
  1064. */
  1065. static DEVICE_ATTR(raydium_fw_upgrade, 0644,
  1066. raydium_fw_upgrade_show,
  1067. raydium_fw_upgrade_store);
  1068. /* change I2C communication mode (W)
  1069. * example:echo 1 > raydium_i2c_pda2_mode ==> enable pda2 mode
  1070. * echo 0 > raydium_i2c_pda2_mode ==> disable pda2 mode
  1071. */
  1072. static DEVICE_ATTR(raydium_i2c_pda2_mode, 0644,
  1073. NULL,
  1074. raydium_i2c_pda2_mode_store);
  1075. /* I2C pda mode (R/W)
  1076. * example: cat raydium_i2c_pda_access ==> read pda address provided by the
  1077. * following cmd
  1078. * echo ADDRinHEX [DATAinHEX] > raydium_i2c_pda_access ==> write
  1079. * pda address [data]
  1080. */
  1081. static DEVICE_ATTR(raydium_i2c_pda_access, 0644,
  1082. raydium_i2c_pda_access_show,
  1083. raydium_i2c_pda_access_store);
  1084. /* I2C pda mode via pda2(R/W)
  1085. * example: cat raydium_i2c_pda_access ==> read pda address provided by the
  1086. * following cmd
  1087. * echo ADDRinHEX [DATAinHEX] > raydium_i2c_pda_access ==> write
  1088. * pda address [data]
  1089. */
  1090. static DEVICE_ATTR(raydium_i2c_pda_access_via_pda2, 0644,
  1091. raydium_i2c_pda_access_via_pda2_show,
  1092. raydium_i2c_pda_access_via_pda2_store);
  1093. /* I2C pda2 mode (R/W)
  1094. * example: cat raydium_i2c_pda2_access ==> read pda2 address provided by
  1095. * the following cmd
  1096. * echo ADDRinHEX [DATAinHEX] > raydium_i2c_pda2_access ==>
  1097. * write pda2 address [data]
  1098. */
  1099. static DEVICE_ATTR(raydium_i2c_pda2_access, 0644,
  1100. raydium_i2c_pda2_access_show,
  1101. raydium_i2c_pda2_access_store);
  1102. /* I2C pda2 mode page (W)
  1103. * example: echo PAGEinHEX > raydium_i2c_pda2_page ==> write pda2 page
  1104. */
  1105. static DEVICE_ATTR(raydium_i2c_pda2_page, 0644,
  1106. NULL,
  1107. raydium_i2c_pda2_page_store);
  1108. /* I2C read/set FT raw data (R/W)
  1109. * example: cat raydium_i2c_raw_data ==> read raw data with specific length
  1110. * of corresponding type provided by the following cmd
  1111. * echo DataTypeinHEX RawDataLengthinHEX > raydium_i2c_raw_data
  1112. * ==> set raw data type and its length
  1113. */
  1114. static DEVICE_ATTR(raydium_i2c_raw_data, 0644,
  1115. raydium_i2c_raw_data_show,
  1116. raydium_i2c_raw_data_store);
  1117. /* Touch lock (W)
  1118. * example: echo 1 > raydium_i2c_touch_lock ==> enable touch lock
  1119. * echo 0 > raydium_i2c_touch_lock ==> disable touch lock
  1120. */
  1121. static DEVICE_ATTR(raydium_i2c_touch_lock, 0644,
  1122. NULL,
  1123. raydium_touch_lock_store);
  1124. /* Log level (W)
  1125. * example: echo 1 > raydium_log_level ==> modify log level
  1126. */
  1127. static DEVICE_ATTR(raydium_log_level, 0644,
  1128. NULL,
  1129. raydium_log_level_store);
  1130. /* show the fw version (R)
  1131. * example:cat raydium_fw_version
  1132. */
  1133. static DEVICE_ATTR(raydium_check_fw_version, 0644,
  1134. raydium_check_fw_version_show,
  1135. NULL);
  1136. /* show the driver version (R)
  1137. * example:cat raydium_check_driver_version
  1138. */
  1139. static DEVICE_ATTR(raydium_check_driver_version, 0644,
  1140. raydium_check_driver_version_show,
  1141. NULL);
  1142. /* show the panel version (R)
  1143. * example:cat raydium_panel_version
  1144. */
  1145. static DEVICE_ATTR(raydium_check_panel_version, 0644,
  1146. raydium_check_panel_version_show,
  1147. NULL);
  1148. static DEVICE_ATTR(raydium_hw_reset, 0644,
  1149. raydium_hw_reset_show,
  1150. NULL);
  1151. static DEVICE_ATTR(raydium_palm_status, 0644,
  1152. raydium_palm_status_show,
  1153. NULL);
  1154. static DEVICE_ATTR(raydium_receive_fw_control, 0644,
  1155. NULL,
  1156. raydium_receive_fw_store);
  1157. static DEVICE_ATTR(raydium_mem_setting, 0644,
  1158. NULL,
  1159. raydium_mem_store);
  1160. #ifdef RAD_SELFTEST
  1161. /* Read interrupt flag cmd (R)
  1162. * example:cat raydium_int_flag
  1163. */
  1164. static DEVICE_ATTR(raydium_int_flag, 0644,
  1165. raydium_flag_show,
  1166. raydium_flag_store);
  1167. static DEVICE_ATTR(raydium_reset_control, 0644,
  1168. NULL,
  1169. raydium_reset_control_store);
  1170. static DEVICE_ATTR(raydium_irq_state, 0644,
  1171. raydium_irq_state_show,
  1172. NULL);
  1173. static DEVICE_ATTR(raydium_do_selftest, 0644,
  1174. raydium_selftest_show,
  1175. NULL);
  1176. #endif
  1177. /*add your attr in here*/
  1178. struct attribute *raydium_attributes[] = {
  1179. &dev_attr_raydium_touch_calibration.attr,
  1180. &dev_attr_raydium_check_i2c.attr,
  1181. &dev_attr_raydium_i2c_pda2_mode.attr,
  1182. &dev_attr_raydium_i2c_pda_access.attr,
  1183. &dev_attr_raydium_i2c_pda_access_via_pda2.attr,
  1184. &dev_attr_raydium_i2c_pda2_access.attr,
  1185. &dev_attr_raydium_i2c_pda2_page.attr,
  1186. &dev_attr_raydium_i2c_raw_data.attr,
  1187. &dev_attr_raydium_i2c_touch_lock.attr,
  1188. &dev_attr_raydium_fw_upgrade.attr,
  1189. &dev_attr_raydium_check_fw_version.attr,
  1190. &dev_attr_raydium_check_panel_version.attr,
  1191. &dev_attr_raydium_hw_reset.attr,
  1192. &dev_attr_raydium_palm_status.attr,
  1193. &dev_attr_raydium_check_driver_version.attr,
  1194. &dev_attr_raydium_receive_fw_control.attr,
  1195. &dev_attr_raydium_mem_setting.attr,
  1196. &dev_attr_raydium_log_level.attr,
  1197. #ifdef RAD_SELFTEST
  1198. &dev_attr_raydium_irq_state.attr,
  1199. &dev_attr_raydium_int_flag.attr,
  1200. &dev_attr_raydium_reset_control.attr,
  1201. &dev_attr_raydium_do_selftest.attr,
  1202. #endif
  1203. NULL
  1204. };