raydium_sysfs.c 41 KB

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