raydium_sysfs.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675
  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. g_raydium_ts->touch_offload = true;
  336. break;
  337. case 1: /* Enable Touch offload */
  338. LOGD(LOG_INFO, "[touch]RAD %s enable touch offload!!\n", __func__);
  339. raydium_ts_touch_exit();
  340. g_raydium_ts->touch_offload = false;
  341. break;
  342. }
  343. return count;
  344. }
  345. static ssize_t raydium_touch_offload_show(struct device *dev,
  346. struct device_attribute *attr,
  347. char *p_i8_buf)
  348. {
  349. return snprintf(p_i8_buf, PAGE_SIZE,
  350. "Touch offload : %s\n",
  351. (g_raydium_ts->touch_offload)? "Enabled" : "Disabled");
  352. }
  353. static ssize_t raydium_touch_lock_store(struct device *dev,
  354. struct device_attribute *attr,
  355. const char *p_i8_buf, size_t count)
  356. {
  357. int i32_ret = 0;
  358. unsigned char u8_mode;
  359. unsigned char u8_wbuffer[1];
  360. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  361. if (g_raydium_ts->is_suspend)
  362. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  363. /* receive command line arguments string */
  364. if (count > 2)
  365. return -EINVAL;
  366. i32_ret = kstrtou8(p_i8_buf, 16, &u8_mode);
  367. if (i32_ret < 0)
  368. return i32_ret;
  369. g_u8_raydium_flag |= ENG_MODE;
  370. mutex_lock(&g_raydium_ts->lock);
  371. switch (u8_mode) {
  372. case 0: /* Disable Touch lock */
  373. if (g_raydium_ts->is_sleep != 1)
  374. break;
  375. g_u8_resetflag = true;
  376. if (gpio_is_valid(g_raydium_ts->rst_gpio)) {
  377. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  378. gpio_set_value(g_raydium_ts->rst_gpio, 0);
  379. msleep(RAYDIUM_RESET_INTERVAL_MSEC);/*5ms*/
  380. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  381. msleep(RAYDIUM_RESET_DELAY_MSEC);/*100ms*/
  382. }
  383. LOGD(LOG_INFO, "[touch]RAD %s disable touch lock!!\n", __func__);
  384. g_raydium_ts->is_sleep = 0;
  385. break;
  386. case 1: /* Enable Touch lock */
  387. if (g_raydium_ts->is_sleep == 1)
  388. break;
  389. i32_ret = raydium_i2c_pda2_set_page(client,
  390. g_raydium_ts->is_suspend,
  391. RAYDIUM_PDA2_PAGE_0);
  392. if (i32_ret < 0)
  393. goto exit_i2c_error;
  394. /*fw enter sleep mode*/
  395. u8_wbuffer[0] = RAYDIUM_HOST_CMD_PWR_SLEEP;
  396. i32_ret = raydium_i2c_pda2_write(client,
  397. RAYDIUM_PDA2_HOST_CMD_ADDR,
  398. u8_wbuffer,
  399. 1);
  400. if (i32_ret < 0)
  401. goto exit_i2c_error;
  402. LOGD(LOG_INFO, "[touch]RAD %s enable touch lock!!\n", __func__);
  403. g_raydium_ts->is_sleep = 1;
  404. break;
  405. }
  406. exit_i2c_error:
  407. mutex_unlock(&g_raydium_ts->lock);
  408. g_u8_raydium_flag &= ~ENG_MODE;
  409. return count;
  410. }
  411. static ssize_t raydium_check_driver_version_show(struct device *dev,
  412. struct device_attribute *attr,
  413. char *p_i8_buf)
  414. {
  415. /*unsigned char rbuffer[4];*/
  416. unsigned short u16_len = 0;
  417. int i32_ret = -1;
  418. snprintf(p_i8_buf, PAGE_SIZE, "RAD Driver Ver: 0x%X\n",
  419. g_u32_driver_version);
  420. u16_len = strlen(p_i8_buf);
  421. i32_ret = u16_len + 1;
  422. return i32_ret;
  423. }
  424. static ssize_t raydium_check_fw_version_show(struct device *dev,
  425. struct device_attribute *attr,
  426. char *p_i8_buf)
  427. {
  428. unsigned char u8_rbuffer[4];
  429. unsigned short u16_len = 0;
  430. int i32_ret = -1;
  431. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  432. unsigned int fw_version, image_version;
  433. if (g_raydium_ts->is_suspend)
  434. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  435. g_u8_raydium_flag |= ENG_MODE;
  436. mutex_lock(&g_raydium_ts->lock);
  437. i32_ret = raydium_i2c_pda2_set_page(client,
  438. g_raydium_ts->is_suspend,
  439. RAYDIUM_PDA2_PAGE_0);
  440. if (i32_ret < 0)
  441. goto exit_i2c_error;
  442. i32_ret = raydium_i2c_pda2_read(client, RAYDIUM_PDA2_FW_VERSION_ADDR,
  443. u8_rbuffer, 4);
  444. if (i32_ret < 0)
  445. goto exit_i2c_error;
  446. snprintf(p_i8_buf, PAGE_SIZE, "RAD Touch FW Ver : %02X%02X%02X%02X\n",
  447. u8_rbuffer[0], u8_rbuffer[1], u8_rbuffer[2], u8_rbuffer[3]);
  448. fw_version = (u8_rbuffer[0] << 24)
  449. | (u8_rbuffer[1] << 16)
  450. | (u8_rbuffer[2] << 8)
  451. | u8_rbuffer[3];
  452. LOGD(LOG_INFO, "[touch]RAD FW ver : 0x%x\n", fw_version);
  453. image_version = (g_rad_para_image[PARA_FW_VERSION_OFFSET] << 24) |
  454. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 1] << 16) |
  455. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 2] << 8) |
  456. g_rad_para_image[PARA_FW_VERSION_OFFSET + 3];
  457. LOGD(LOG_INFO, "[touch]RAD Image FW ver : 0x%x\n", image_version);
  458. mutex_unlock(&g_raydium_ts->lock);
  459. g_u8_raydium_flag &= ~ENG_MODE;
  460. if (fw_version != image_version)
  461. LOGD(LOG_INFO, "[touch]%s, FW need upgrade.\n", __func__);
  462. u16_len = strlen(p_i8_buf);
  463. i32_ret = u16_len + 1;
  464. goto exit_upgrade;
  465. exit_i2c_error:
  466. mutex_unlock(&g_raydium_ts->lock);
  467. g_u8_raydium_flag &= ~ENG_MODE;
  468. exit_upgrade:
  469. return i32_ret;
  470. }
  471. static ssize_t raydium_check_panel_version_show(struct device *dev,
  472. struct device_attribute *attr,
  473. char *p_i8_buf)
  474. {
  475. unsigned char u8_rbuffer[8];
  476. unsigned short u16_len = 0;
  477. int i32_ret = -1;
  478. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  479. if (g_raydium_ts->is_suspend)
  480. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  481. g_u8_raydium_flag |= ENG_MODE;
  482. mutex_lock(&g_raydium_ts->lock);
  483. i32_ret = raydium_i2c_pda2_set_page(client,
  484. g_raydium_ts->is_suspend,
  485. RAYDIUM_PDA2_PAGE_0);
  486. if (i32_ret < 0)
  487. goto exit_i2c_error;
  488. i32_ret = raydium_i2c_pda2_read(client,
  489. RAYDIUM_PDA2_PANEL_VERSION_ADDR,
  490. u8_rbuffer, 8);
  491. if (i32_ret < 0)
  492. goto exit_i2c_error;
  493. snprintf(p_i8_buf, PAGE_SIZE,
  494. "RAD Touch Panel Version : %02X%02X%02X%02X%02X%02X\n",
  495. u8_rbuffer[0], u8_rbuffer[1], u8_rbuffer[2],
  496. u8_rbuffer[3], u8_rbuffer[4], u8_rbuffer[5]);
  497. mutex_unlock(&g_raydium_ts->lock);
  498. g_u8_raydium_flag &= ~ENG_MODE;
  499. u16_len = strlen(p_i8_buf);
  500. i32_ret = u16_len + 1;
  501. goto exit_upgrade;
  502. exit_i2c_error:
  503. mutex_unlock(&g_raydium_ts->lock);
  504. g_u8_raydium_flag &= ~ENG_MODE;
  505. exit_upgrade:
  506. return i32_ret;
  507. }
  508. static ssize_t raydium_fw_upgrade_store(struct device *dev,
  509. struct device_attribute *attr,
  510. const char *p_i8_buf, size_t count)
  511. {
  512. int i32_ret = 0;
  513. /* receive command line arguments string */
  514. if (count > 2)
  515. return -EINVAL;
  516. i32_ret = kstrtou8(p_i8_buf, 16, &g_u8_upgrade_type);
  517. if (i32_ret < 0)
  518. return i32_ret;
  519. return count;
  520. }
  521. static ssize_t raydium_fw_upgrade_show(struct device *dev,
  522. struct device_attribute *attr,
  523. char *p_i8_buf)
  524. {
  525. int i32_ret = 0, i32_result = FAIL;
  526. unsigned short u16_len = 0;
  527. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  528. LOGD(LOG_INFO, "[touch]RAD burn type is %d\n", g_u8_upgrade_type);
  529. g_u8_raydium_flag |= ENG_MODE;
  530. if ((g_u8_table_setting == 1) && (g_u8_table_init == 1))
  531. raydium_mem_table_setting();
  532. if (g_u8_upgrade_type == 1) {
  533. i32_ret = raydium_burn_fw(client);
  534. if (i32_ret < 0)
  535. goto exit_upgrade;
  536. i32_result = SUCCESS;
  537. } else if (g_u8_upgrade_type == 2) {
  538. i32_ret = raydium_burn_comp(client);
  539. if (i32_ret < 0)
  540. goto exit_upgrade;
  541. i32_result = SUCCESS;
  542. }
  543. #ifdef RAD_SELFTEST
  544. else if (g_u8_upgrade_type == 4) {
  545. i32_ret = raydium_load_test_fw(client);
  546. if (i32_ret < 0)
  547. goto exit_upgrade;
  548. i32_result = SUCCESS;
  549. }
  550. #endif
  551. exit_upgrade:
  552. LOGD(LOG_DEBUG, "[touch]g_u8_raydium_flag : %d", g_u8_raydium_flag);
  553. g_u8_raydium_flag &= ~ENG_MODE;
  554. g_u8_upgrade_type = 0;
  555. snprintf(p_i8_buf, PAGE_SIZE, "FW Upgrade result : %d\n", i32_result);
  556. u16_len = strlen(p_i8_buf);
  557. return u16_len + 1;
  558. }
  559. static ssize_t raydium_i2c_pda2_page_store(struct device *dev,
  560. struct device_attribute *attr,
  561. const char *p_i8_buf, size_t count)
  562. {
  563. int i32_ret = 0;
  564. unsigned char u8_page = 0;
  565. char *temp_buf, *token, *free_temp_buf, *free_token;
  566. const char *delim = " ,";
  567. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  568. /* receive command line arguments string */
  569. if (count < 2)
  570. return -EINVAL;
  571. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  572. if (temp_buf == NULL)
  573. return -ENOMEM;
  574. token = kzalloc(count + 1, GFP_KERNEL);
  575. if (token == NULL) {
  576. kfree(temp_buf);
  577. return -ENOMEM;
  578. }
  579. free_temp_buf = temp_buf;
  580. free_token = token;
  581. strlcpy(temp_buf, p_i8_buf, count);
  582. token = strsep(&temp_buf, delim);
  583. if (temp_buf) {
  584. LOGD(LOG_ERR, "[touch]input error, extra auguments!n");
  585. i32_ret = -EINVAL;
  586. goto exit_error;
  587. }
  588. i32_ret = kstrtou8(token, 16, &u8_page);
  589. if (i32_ret < 0)
  590. goto exit_error;
  591. mutex_lock(&g_raydium_ts->lock);
  592. i32_ret = raydium_i2c_pda2_set_page(client, g_raydium_ts->is_suspend, u8_page);
  593. if (i32_ret < 0)
  594. goto exit_set_error;
  595. /* TODO: Page check, Due to ISR will change page back to Page_0.
  596. * Or disable IRQ during PDA2 access period
  597. */
  598. exit_set_error:
  599. mutex_unlock(&g_raydium_ts->lock);
  600. exit_error:
  601. kfree(free_token);
  602. kfree(free_temp_buf);
  603. return count;
  604. }
  605. static ssize_t raydium_mem_store(struct device *dev,
  606. struct device_attribute *attr,
  607. const char *p_i8_buf, size_t count)
  608. {
  609. #if !ENABLE_FW_LOADER
  610. int i32_ret = 0;
  611. unsigned char u8_type = 0;
  612. unsigned int u32_image_version;
  613. /* receive command line arguments string */
  614. if (count > 2)
  615. return -EINVAL;
  616. LOGD(LOG_INFO, "[touch]%s\n", __func__);
  617. i32_ret = kstrtou8(p_i8_buf, 16, &u8_type);
  618. if (i32_ret < 0)
  619. return i32_ret;
  620. if (u8_type > 3) {
  621. LOGD(LOG_ERR, "[touch]Input invalid value!!\n");
  622. return ERROR;
  623. }
  624. if (g_rad_boot_image) {
  625. kfree(g_rad_boot_image);
  626. g_rad_boot_image = NULL;
  627. }
  628. if (g_rad_init_image) {
  629. kfree(g_rad_init_image);
  630. g_rad_init_image = NULL;
  631. }
  632. if (g_rad_fw_image) {
  633. kfree(g_rad_fw_image);
  634. g_rad_fw_image = NULL;
  635. }
  636. kfree(g_rad_para_image);
  637. g_rad_para_image = NULL;
  638. if (g_rad_testfw_image) {
  639. kfree(g_rad_testfw_image);
  640. g_rad_testfw_image = NULL;
  641. }
  642. kfree(g_rad_testpara_image);
  643. g_rad_testpara_image = NULL;
  644. if (!raydium_id_init(u8_type)) {
  645. LOGD(LOG_ERR, "[touch]Set Raydium id failed!\n");
  646. return count;
  647. }
  648. raydium_mem_table_init(g_raydium_ts->id);
  649. if (raydium_mem_table_setting()) {
  650. u32_image_version = (g_rad_para_image[PARA_FW_VERSION_OFFSET] << 24) |
  651. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 1] << 16) |
  652. (g_rad_para_image[PARA_FW_VERSION_OFFSET + 2] << 8) |
  653. g_rad_para_image[PARA_FW_VERSION_OFFSET + 3];
  654. LOGD(LOG_INFO, "[touch]RAD Image FW ver : 0x%x\n", u32_image_version);
  655. } else
  656. LOGD(LOG_ERR, "[touch]Mem init failed!\n");
  657. if (g_rad_para_image) {
  658. kfree(g_rad_para_image);
  659. g_rad_para_image = NULL;
  660. }
  661. #endif
  662. return count;
  663. }
  664. static ssize_t raydium_i2c_raw_data_store(struct device *dev,
  665. struct device_attribute *attr,
  666. const char *p_i8_buf, size_t count)
  667. {
  668. int i32_ret = 0;
  669. char *temp_buf, *token, *free_temp_buf, *free_token;
  670. const char *delim = " ,";
  671. unsigned char u8_w_data[RAD_FT_CMD_LENGTH];
  672. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  673. /* receive command line arguments string */
  674. if (count < 2)
  675. return -EINVAL;
  676. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  677. if (temp_buf == NULL) {
  678. LOGD(LOG_ERR, "[touch]kzalloc temp_buf failed\n");
  679. return -ENOMEM;
  680. }
  681. token = kzalloc(count + 1, GFP_KERNEL);
  682. if (token == NULL) {
  683. kfree(temp_buf);
  684. return -ENOMEM;
  685. }
  686. free_temp_buf = temp_buf;
  687. free_token = token;
  688. strlcpy(temp_buf, p_i8_buf, count);
  689. token = strsep(&temp_buf, delim);
  690. i32_ret = kstrtou8(token, 16, &g_u8_raw_data_type);
  691. token = strsep(&temp_buf, delim);
  692. if (token) {
  693. i32_ret = kstrtouint(token, 16, &g_u32_raw_data_len);
  694. if (i32_ret < 0)
  695. goto exit_error;
  696. } else { /* without length info*/
  697. i32_ret = -EINVAL;
  698. goto exit_error;
  699. }
  700. if (temp_buf) { /* too much arguments*/
  701. i32_ret = -E2BIG;
  702. goto exit_error;
  703. }
  704. memset(u8_w_data, 0x00, RAD_FT_CMD_LENGTH);
  705. mutex_lock(&g_raydium_ts->lock);
  706. i32_ret = raydium_i2c_pda2_set_page(client,
  707. g_raydium_ts->is_suspend,
  708. RAYDIUM_PDA2_PAGE_0);
  709. if (i32_ret < 0) {
  710. mutex_unlock(&g_raydium_ts->lock);
  711. goto exit_error;
  712. }
  713. g_u8_resetflag = true;
  714. u8_w_data[RAD_HOST_CMD_POS] = RAYDIUM_HOST_CMD_NO_OP;
  715. u8_w_data[RAD_FT_CMD_POS] = g_u8_raw_data_type;
  716. i32_ret = raydium_i2c_pda2_write(client, RAYDIUM_PDA2_HOST_CMD_ADDR,
  717. u8_w_data, RAD_FT_CMD_LENGTH);
  718. mutex_unlock(&g_raydium_ts->lock);
  719. if (i32_ret < 0)
  720. goto exit_error;
  721. if (g_u8_raw_data_type == 0) {
  722. msleep(20);
  723. g_u8_resetflag = false;
  724. }
  725. exit_error:
  726. kfree(free_token);
  727. kfree(free_temp_buf);
  728. return count;
  729. }
  730. static ssize_t raydium_i2c_raw_data_show(struct device *dev,
  731. struct device_attribute *attr,
  732. char *p_i8_buf)
  733. {
  734. unsigned char u8_rbuffer[MAX_READ_PACKET_SIZE];
  735. unsigned int u32_target_addr;
  736. unsigned int u32_offset;
  737. unsigned short u16_read_length;
  738. int i32_ret = -1;
  739. int i32_retry = 0;
  740. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  741. struct raydium_ts_data *ts =
  742. (struct raydium_ts_data *)i2c_get_clientdata(client);
  743. unsigned char u8_retry_limit = (ts->is_suspend) ? 100 : 30;
  744. memset(u8_rbuffer, 0x00, MAX_READ_PACKET_SIZE);
  745. /* make sure update flag was set*/
  746. for (i32_retry = 0; i32_retry < u8_retry_limit; i32_retry++) {
  747. mutex_lock(&ts->lock);
  748. i32_ret = raydium_i2c_pda2_set_page(client,
  749. ts->is_suspend,
  750. RAYDIUM_PDA2_PAGE_0);
  751. if (i32_ret < 0) {
  752. mutex_unlock(&ts->lock);
  753. goto exit_i2c_error;
  754. }
  755. i32_ret = raydium_i2c_pda2_read(client,
  756. RAYDIUM_PDA2_HOST_CMD_ADDR,
  757. u8_rbuffer,
  758. RAD_FT_CMD_LENGTH);
  759. mutex_unlock(&ts->lock);
  760. if (i32_ret < 0)
  761. goto exit_flag_error;
  762. if ((u8_rbuffer[RAD_FT_CMD_POS] & RAYDIUM_FT_UPDATE) ==
  763. RAYDIUM_FT_UPDATE)
  764. break;
  765. usleep_range(500, 1500);
  766. }
  767. if (i32_retry == u8_retry_limit) {
  768. i32_ret = -EAGAIN;
  769. goto exit_flag_error;
  770. }
  771. u32_offset = 0;
  772. u16_read_length = 0;
  773. while (u32_offset < g_u32_raw_data_len) {
  774. if ((u32_offset + MAX_READ_PACKET_SIZE) <
  775. g_u32_raw_data_len)
  776. u16_read_length = MAX_READ_PACKET_SIZE;
  777. else
  778. u16_read_length =
  779. (unsigned short)(g_u32_raw_data_len - u32_offset);
  780. u32_target_addr = RAD_READ_FT_DATA_CMD + u32_offset;
  781. mutex_lock(&(ts->lock));
  782. /*using byte mode to read 4 bytes*/
  783. i32_ret = handle_i2c_pda_read(client,
  784. u32_target_addr,
  785. u8_rbuffer,
  786. u16_read_length);
  787. mutex_unlock(&(ts->lock));
  788. if (i32_ret < 0)
  789. goto exit_flag_error;
  790. memcpy((p_i8_buf + u32_offset), u8_rbuffer, u16_read_length);
  791. u32_offset += u16_read_length;
  792. }
  793. /* clear update flag to get next one*/
  794. u8_rbuffer[RAD_HOST_CMD_POS] = RAYDIUM_HOST_CMD_NO_OP;
  795. u8_rbuffer[RAD_FT_CMD_POS] = g_u8_raw_data_type;
  796. mutex_lock(&ts->lock);
  797. i32_ret = raydium_i2c_pda2_write(client, RAYDIUM_PDA2_HOST_CMD_ADDR,
  798. u8_rbuffer, RAD_FT_CMD_LENGTH);
  799. mutex_unlock(&ts->lock);
  800. if (i32_ret < 0)
  801. goto exit_flag_error;
  802. return g_u32_raw_data_len;
  803. exit_i2c_error:
  804. mutex_unlock(&(ts->lock));
  805. exit_flag_error:
  806. return i32_ret;
  807. }
  808. static ssize_t raydium_i2c_pda_access_store(struct device *dev,
  809. struct device_attribute *attr,
  810. const char *p_i8_buf, size_t count)
  811. {
  812. int i32_ret = 0;
  813. char *temp_buf, *token, *free_temp_buf, *free_token;
  814. const char *delim = " ,";
  815. unsigned char u8_w_data[MAX_WRITE_PACKET_SIZE];
  816. unsigned int u32_data_count = 0;
  817. unsigned int u32_data_index = 0;
  818. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  819. /* receive command line arguments string */
  820. if (count < 2)
  821. return -EINVAL;
  822. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  823. if (temp_buf == NULL)
  824. return -ENOMEM;
  825. token = kzalloc(count + 1, GFP_KERNEL);
  826. if (token == NULL) {
  827. kfree(temp_buf);
  828. return -ENOMEM;
  829. }
  830. free_temp_buf = temp_buf;
  831. free_token = token;
  832. strlcpy(temp_buf, p_i8_buf, count);
  833. token = strsep(&temp_buf, delim);
  834. i32_ret = kstrtoul(token, 16, &g_u32_addr);
  835. token = strsep(&temp_buf, delim);
  836. if (token)
  837. i32_ret = kstrtouint(token, 16, &u32_data_count);
  838. else
  839. goto exit_error;
  840. if (g_u32_length > MAX_WRITE_PACKET_SIZE)
  841. return -EINVAL;
  842. g_u32_length = u32_data_count;
  843. memset(u8_w_data, 0x00, MAX_WRITE_PACKET_SIZE);
  844. if (temp_buf && u32_data_count) {
  845. u32_data_index = 0;
  846. while (u32_data_count) {
  847. token = strsep(&temp_buf, delim);
  848. i32_ret = kstrtou8(token, 16,
  849. &u8_w_data[u32_data_index++]);
  850. if (i32_ret < 0)
  851. goto exit_error;
  852. u32_data_count--;
  853. }
  854. mutex_lock(&g_raydium_ts->lock);
  855. i32_ret = raydium_i2c_pda_write(client, g_u32_addr,
  856. u8_w_data, g_u32_length);
  857. mutex_unlock(&g_raydium_ts->lock);
  858. }
  859. exit_error:
  860. kfree(free_token);
  861. kfree(free_temp_buf);
  862. return count;
  863. }
  864. static ssize_t raydium_i2c_pda_access_via_pda2_store(struct device *dev,
  865. struct device_attribute *attr,
  866. const char *p_i8_buf, size_t count)
  867. {
  868. int i32_ret = 0;
  869. char *temp_buf, *token, *free_temp_buf, *free_token;
  870. const char *delim = " ,";
  871. unsigned char u8_w_data[MAX_WRITE_PACKET_SIZE];
  872. unsigned int u32_data_count = 0;
  873. unsigned int u32_data_index = 0;
  874. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  875. /* receive command line arguments string */
  876. if (count < 2)
  877. return -EINVAL;
  878. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  879. if (temp_buf == NULL)
  880. return -ENOMEM;
  881. token = kzalloc(count + 1, GFP_KERNEL);
  882. if (token == NULL) {
  883. kfree(temp_buf);
  884. return -ENOMEM;
  885. }
  886. free_temp_buf = temp_buf;
  887. free_token = token;
  888. strlcpy(temp_buf, p_i8_buf, count);
  889. token = strsep(&temp_buf, delim);
  890. i32_ret = kstrtoul(token, 16, &g_u32_addr);
  891. token = strsep(&temp_buf, delim);
  892. if (token)
  893. i32_ret = kstrtouint(token, 16, &u32_data_count);
  894. else
  895. goto exit_error;
  896. if (g_u32_length > MAX_WRITE_PACKET_SIZE)
  897. return -EINVAL;
  898. g_u32_length = u32_data_count;
  899. memset(u8_w_data, 0x00, MAX_WRITE_PACKET_SIZE);
  900. if (temp_buf && u32_data_count) {
  901. u32_data_index = 0;
  902. while (u32_data_count) {
  903. token = strsep(&temp_buf, delim);
  904. i32_ret = kstrtou8(token, 16,
  905. &u8_w_data[u32_data_index++]);
  906. if (i32_ret < 0)
  907. goto exit_error;
  908. u32_data_count--;
  909. }
  910. mutex_lock(&g_raydium_ts->lock);
  911. i32_ret = handle_i2c_pda_write(client, g_u32_addr,
  912. u8_w_data, g_u32_length);
  913. mutex_unlock(&g_raydium_ts->lock);
  914. }
  915. exit_error:
  916. kfree(free_token);
  917. kfree(free_temp_buf);
  918. return count;
  919. }
  920. static ssize_t raydium_i2c_pda2_mode_store(struct device *dev,
  921. struct device_attribute *attr,
  922. const char *p_i8_buf, size_t count)
  923. {
  924. int i32_ret = 0;
  925. unsigned char u8_mode;
  926. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  927. if (g_raydium_ts->is_suspend)
  928. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  929. /* receive command line arguments string */
  930. if (count > 2)
  931. return -EINVAL;
  932. i32_ret = kstrtou8(p_i8_buf, 16, &u8_mode);
  933. if (i32_ret < 0)
  934. return i32_ret;
  935. i32_ret = raydium_i2c_mode_control(client, u8_mode);
  936. if (i32_ret < 0)
  937. return i32_ret;
  938. return count;
  939. }
  940. static ssize_t raydium_i2c_pda2_access_show(struct device *dev,
  941. struct device_attribute *attr,
  942. char *p_i8_buf)
  943. {
  944. unsigned char u8_rbuffer[4];
  945. unsigned short u16_len = 0;
  946. int i32_ret = -1;
  947. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  948. if (g_u32_length > 4)
  949. return -EINVAL;
  950. memset(u8_rbuffer, 0x00, 4);
  951. mutex_lock(&g_raydium_ts->lock);
  952. i32_ret = raydium_i2c_pda2_read(client, g_u8_addr,
  953. u8_rbuffer, g_u32_length);
  954. mutex_unlock(&g_raydium_ts->lock);
  955. if (i32_ret < 0)
  956. return i32_ret;
  957. snprintf(p_i8_buf, PAGE_SIZE, "0x%04X : 0x%02X%02X%02X%02X\n",
  958. g_u8_addr, u8_rbuffer[3], u8_rbuffer[2],
  959. u8_rbuffer[1], u8_rbuffer[0]);
  960. u16_len = strlen(p_i8_buf);
  961. return u16_len + 1;
  962. }
  963. static ssize_t raydium_i2c_pda2_access_store(struct device *dev,
  964. struct device_attribute *attr,
  965. const char *p_i8_buf, size_t count)
  966. {
  967. int i32_ret = 0;
  968. char *temp_buf, *token, *free_temp_buf, *free_token;
  969. const char *delim = " ,";
  970. unsigned char u8_w_data[MAX_WRITE_PACKET_SIZE];
  971. unsigned int u32_data_count = 0;
  972. unsigned int u32_data_index = 0;
  973. struct i2c_client *client = container_of(dev, struct i2c_client, dev);
  974. /* receive command line arguments string */
  975. if (count < 2)
  976. return -EINVAL;
  977. temp_buf = kzalloc(count + 1, GFP_KERNEL);
  978. if (temp_buf == NULL) {
  979. LOGD(LOG_ERR, "[touch]kzalloc temp_buf failed\n");
  980. return -ENOMEM;
  981. }
  982. token = kzalloc(count + 1, GFP_KERNEL);
  983. if (token == NULL) {
  984. kfree(temp_buf);
  985. return -ENOMEM;
  986. }
  987. free_temp_buf = temp_buf;
  988. free_token = token;
  989. strlcpy(temp_buf, p_i8_buf, count);
  990. token = strsep(&temp_buf, delim);
  991. i32_ret = kstrtou8(token, 16, &g_u8_addr);
  992. token = strsep(&temp_buf, delim);
  993. if (token)
  994. i32_ret = kstrtouint(token, 16, &u32_data_count);
  995. else {
  996. i32_ret = -EINVAL;
  997. goto exit_error;
  998. }
  999. if (u32_data_count > MAX_WRITE_PACKET_SIZE) {
  1000. i32_ret = -EINVAL;
  1001. goto exit_error;
  1002. }
  1003. memset(u8_w_data, 0x00, MAX_WRITE_PACKET_SIZE);
  1004. g_u32_length = u32_data_count;
  1005. if (temp_buf && u32_data_count) {
  1006. u32_data_index = 0;
  1007. while (u32_data_count) {
  1008. token = strsep(&temp_buf, delim);
  1009. i32_ret = kstrtou8(token, 16,
  1010. &u8_w_data[u32_data_index++]);
  1011. if (i32_ret < 0)
  1012. goto exit_error;
  1013. u32_data_count--;
  1014. }
  1015. mutex_lock(&g_raydium_ts->lock);
  1016. i32_ret = raydium_i2c_pda2_write(client, g_u8_addr,
  1017. u8_w_data, g_u32_length);
  1018. mutex_unlock(&g_raydium_ts->lock);
  1019. if (i32_ret < 0)
  1020. goto exit_error;
  1021. }
  1022. exit_error:
  1023. kfree(free_token);
  1024. kfree(free_temp_buf);
  1025. return count;
  1026. }
  1027. static ssize_t raydium_receive_fw_store(struct device *dev,
  1028. struct device_attribute *attr,
  1029. const char *p_i8_buf, size_t count)
  1030. {
  1031. int i32_ret = 0;
  1032. const char *delim = " ,";
  1033. char *token, *temp_buf, *free_token = NULL, *free_temp_buf = NULL;
  1034. static unsigned char *p_u8_firmware_data;
  1035. unsigned char u8_cmd;
  1036. unsigned long u32_len;
  1037. static unsigned char u8_type;
  1038. static unsigned int u32_index;
  1039. if (count == 20) { /*check FW type*/
  1040. temp_buf = kzalloc(32, GFP_KERNEL);
  1041. if (temp_buf == NULL) {
  1042. LOGD(LOG_ERR, "[touch]kzalloc temp_buf failed\n");
  1043. return -ENOMEM;
  1044. }
  1045. token = kzalloc(32, GFP_KERNEL);
  1046. if (token == NULL) {
  1047. kfree(temp_buf);
  1048. return -ENOMEM;
  1049. }
  1050. free_token = token;
  1051. free_temp_buf = temp_buf;
  1052. snprintf(temp_buf, 32, "%s", p_i8_buf);
  1053. token = strsep(&temp_buf, delim);
  1054. i32_ret = kstrtou8(token, 16, &u8_cmd);
  1055. if (i32_ret < 0) {
  1056. LOGD(LOG_ERR, "[touch]kstrtou8 failed\n");
  1057. kfree(free_token);
  1058. free_token = NULL;
  1059. kfree(free_temp_buf);
  1060. free_temp_buf = NULL;
  1061. }
  1062. token = strsep(&temp_buf, delim);
  1063. i32_ret = kstrtou8(token, 16, &u8_type);
  1064. if (i32_ret < 0) {
  1065. LOGD(LOG_ERR, "[touch]kstrtou8 failed\n");
  1066. kfree(temp_buf);
  1067. kfree(token);
  1068. }
  1069. token = strsep(&temp_buf, delim);
  1070. i32_ret = kstrtoul(token, 16, &u32_len);
  1071. if (i32_ret < 0) {
  1072. LOGD(LOG_ERR, "[touch]kstrtou8 failed\n");
  1073. kfree(temp_buf);
  1074. kfree(token);
  1075. }
  1076. LOGD(LOG_INFO, "[touch]uc_cmd=0x%x, uc_type=0x%x, u16_len=0x%x\n",
  1077. u8_cmd, u8_type, (unsigned int)u32_len);
  1078. if (u8_cmd == RAD_CMD_UPDATE_BIN) { /*check FW length*/
  1079. u32_index = 0;
  1080. if (u8_type == RAYDIUM_BOOTLOADER) {
  1081. memset(g_rad_boot_image, 0, u32_len);
  1082. p_u8_firmware_data = g_rad_boot_image;
  1083. } else if (u8_type == RAYDIUM_INIT) {
  1084. memset(g_rad_init_image, 0, u32_len);
  1085. p_u8_firmware_data = g_rad_init_image;
  1086. } else if (u8_type == RAYDIUM_PARA) {
  1087. memset(g_rad_para_image, 0, u32_len);
  1088. p_u8_firmware_data = g_rad_para_image;
  1089. } else if (u8_type == RAYDIUM_FIRMWARE) {
  1090. memset(g_rad_fw_image, 0, u32_len);
  1091. p_u8_firmware_data = g_rad_fw_image;
  1092. } else if (u8_type == RAYDIUM_TEST_PARA) {
  1093. memset(g_rad_testpara_image, 0, u32_len);
  1094. p_u8_firmware_data = g_rad_testpara_image;
  1095. } else if (u8_type == RAYDIUM_TEST_FW) {
  1096. memset(g_rad_testfw_image, 0, u32_len);
  1097. p_u8_firmware_data = g_rad_testfw_image;
  1098. }
  1099. } else if (u8_cmd == RAD_CMD_UPDATE_END) { /*set buffer finish*/
  1100. if (u8_type == RAYDIUM_TEST_FW) {
  1101. memcpy((g_rad_testfw_image + RAD_FW_3X_SIZE),
  1102. g_rad_testpara_image, RAD_PARA_3X_SIZE + 4);
  1103. }
  1104. u32_index = 0;
  1105. g_u8_table_setting = 0;
  1106. } else if (u8_cmd == RAD_CMD_BURN_FINISH) { /*free buffer*/
  1107. u8_type = 0;
  1108. u32_index = 0;
  1109. g_u8_table_setting = 1;
  1110. }
  1111. if (free_temp_buf) {
  1112. kfree(free_temp_buf);
  1113. free_temp_buf = NULL;
  1114. }
  1115. if (free_token) {
  1116. kfree(free_token);
  1117. free_token = NULL;
  1118. }
  1119. } else if (count > 10) { /*start copy FW to array*/
  1120. memcpy((p_u8_firmware_data + u32_index), p_i8_buf, count);
  1121. u32_index += count;
  1122. } else
  1123. LOGD(LOG_ERR, "[touch]other case, count=%d\n", count);
  1124. return count;
  1125. }
  1126. static ssize_t raydium_log_level_store(struct device *dev,
  1127. struct device_attribute *attr,
  1128. const char *p_i8_buf, size_t count)
  1129. {
  1130. int i32_ret = 0;
  1131. unsigned char u8_level = 0;
  1132. /* receive command line arguments string */
  1133. if (count > 2)
  1134. return -EINVAL;
  1135. i32_ret = kstrtou8(p_i8_buf, 16, &u8_level);
  1136. if (i32_ret < 0)
  1137. return i32_ret;
  1138. g_u8_log_level = u8_level;
  1139. LOGD(LOG_ERR, "[touch]g_u8_log_level = %d\r\n", g_u8_log_level);
  1140. return count;
  1141. }
  1142. #ifdef RAD_SELFTEST
  1143. static ssize_t raydium_reset_control_store(struct device *dev,
  1144. struct device_attribute *attr,
  1145. const char *p_i8_buf, size_t count)
  1146. {
  1147. int i32_ret = 0;
  1148. unsigned char u8_high;
  1149. if (g_raydium_ts->is_suspend)
  1150. LOGD(LOG_DEBUG, "[touch]RAD is_suspend at %s\n", __func__);
  1151. /* receive command line arguments string */
  1152. if (count > 2)
  1153. return -EINVAL;
  1154. i32_ret = kstrtou8(p_i8_buf, 16, &u8_high);
  1155. if (i32_ret < 0)
  1156. return i32_ret;
  1157. g_u8_i2c_mode = PDA2_MODE;
  1158. g_u8_resetflag = true;
  1159. if (u8_high) {
  1160. LOGD(LOG_INFO, "[touch]RAD %s set reset gpio to high!!\n",
  1161. __func__);
  1162. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  1163. } else {
  1164. LOGD(LOG_INFO, "[touch]RAD %s set reset gpio to low!!\n",
  1165. __func__);
  1166. gpio_set_value(g_raydium_ts->rst_gpio, 0);
  1167. }
  1168. return count;
  1169. }
  1170. static ssize_t raydium_irq_state_show(struct device *dev,
  1171. struct device_attribute *attr,
  1172. char *p_i8_buf)
  1173. {
  1174. unsigned int u32_irq_value;
  1175. u32_irq_value = gpio_get_value(g_raydium_ts->irq_gpio);
  1176. snprintf(p_i8_buf, PAGE_SIZE, "%d", u32_irq_value);
  1177. LOGD(LOG_DEBUG, "%s\n", p_i8_buf);
  1178. return strlen(p_i8_buf) + 1;
  1179. }
  1180. static ssize_t raydium_flag_show(struct device *dev,
  1181. struct device_attribute *attr,
  1182. char *p_i8_buf)
  1183. {
  1184. unsigned short u16_len = 0;
  1185. snprintf(p_i8_buf, PAGE_SIZE, "%d", g_u8_raydium_flag);
  1186. LOGD(LOG_DEBUG, "[touch]RAD flag : %d\n", g_u8_raydium_flag);
  1187. u16_len = strlen(p_i8_buf);
  1188. return u16_len + 1;
  1189. }
  1190. static ssize_t raydium_flag_store(struct device *dev,
  1191. struct device_attribute *attr,
  1192. const char *p_i8_buf, size_t count)
  1193. {
  1194. int i32_ret = 0;
  1195. unsigned char u8_flag = 0;
  1196. /* receive command line arguments string */
  1197. if (count > 2)
  1198. return -EINVAL;
  1199. i32_ret = kstrtou8(p_i8_buf, 16, &u8_flag);
  1200. if (i32_ret < 0)
  1201. return i32_ret;
  1202. g_u8_raydium_flag = u8_flag;
  1203. return count;
  1204. }
  1205. static ssize_t raydium_selftest_show(struct device *dev,
  1206. struct device_attribute *attr,
  1207. char *p_i8_buf)
  1208. {
  1209. int i32_ret = SUCCESS;
  1210. LOGD(LOG_INFO, "[touch]do selftest\n");
  1211. i32_ret = raydium_do_selftest(g_raydium_ts);
  1212. snprintf(p_i8_buf, PAGE_SIZE, "Raydium do selftest : %d\n", i32_ret);
  1213. return strlen(p_i8_buf) + 1;
  1214. }
  1215. #endif
  1216. /* panel calibration cmd (R)
  1217. * example:cat raydium_ic_verion
  1218. */
  1219. static DEVICE_ATTR(raydium_touch_calibration, 0644,
  1220. raydium_touch_calibration_show,
  1221. NULL);
  1222. /* check the i2c (R)
  1223. * example:cat raydium_check_i2c
  1224. */
  1225. static DEVICE_ATTR(raydium_check_i2c, 0644,
  1226. raydium_check_i2c_show,
  1227. NULL);
  1228. /* upgrade configurate and algo firmware from app.bin (W)
  1229. * example:echo "offset num_of_bin length *_app.bin [length *_app.bin]"
  1230. * > raydium_fw_upgrade_mode
  1231. */
  1232. static DEVICE_ATTR(raydium_fw_upgrade, 0644,
  1233. raydium_fw_upgrade_show,
  1234. raydium_fw_upgrade_store);
  1235. /* change I2C communication mode (W)
  1236. * example:echo 1 > raydium_i2c_pda2_mode ==> enable pda2 mode
  1237. * echo 0 > raydium_i2c_pda2_mode ==> disable pda2 mode
  1238. */
  1239. static DEVICE_ATTR(raydium_i2c_pda2_mode, 0644,
  1240. NULL,
  1241. raydium_i2c_pda2_mode_store);
  1242. /* I2C pda mode (R/W)
  1243. * example: cat raydium_i2c_pda_access ==> read pda address provided by the
  1244. * following cmd
  1245. * echo ADDRinHEX [DATAinHEX] > raydium_i2c_pda_access ==> write
  1246. * pda address [data]
  1247. */
  1248. static DEVICE_ATTR(raydium_i2c_pda_access, 0644,
  1249. raydium_i2c_pda_access_show,
  1250. raydium_i2c_pda_access_store);
  1251. /* I2C pda mode via pda2(R/W)
  1252. * example: cat raydium_i2c_pda_access ==> read pda address provided by the
  1253. * following cmd
  1254. * echo ADDRinHEX [DATAinHEX] > raydium_i2c_pda_access ==> write
  1255. * pda address [data]
  1256. */
  1257. static DEVICE_ATTR(raydium_i2c_pda_access_via_pda2, 0644,
  1258. raydium_i2c_pda_access_via_pda2_show,
  1259. raydium_i2c_pda_access_via_pda2_store);
  1260. /* I2C pda2 mode (R/W)
  1261. * example: cat raydium_i2c_pda2_access ==> read pda2 address provided by
  1262. * the following cmd
  1263. * echo ADDRinHEX [DATAinHEX] > raydium_i2c_pda2_access ==>
  1264. * write pda2 address [data]
  1265. */
  1266. static DEVICE_ATTR(raydium_i2c_pda2_access, 0644,
  1267. raydium_i2c_pda2_access_show,
  1268. raydium_i2c_pda2_access_store);
  1269. /* I2C pda2 mode page (W)
  1270. * example: echo PAGEinHEX > raydium_i2c_pda2_page ==> write pda2 page
  1271. */
  1272. static DEVICE_ATTR(raydium_i2c_pda2_page, 0644,
  1273. NULL,
  1274. raydium_i2c_pda2_page_store);
  1275. /* I2C read/set FT raw data (R/W)
  1276. * example: cat raydium_i2c_raw_data ==> read raw data with specific length
  1277. * of corresponding type provided by the following cmd
  1278. * echo DataTypeinHEX RawDataLengthinHEX > raydium_i2c_raw_data
  1279. * ==> set raw data type and its length
  1280. */
  1281. static DEVICE_ATTR(raydium_i2c_raw_data, 0644,
  1282. raydium_i2c_raw_data_show,
  1283. raydium_i2c_raw_data_store);
  1284. /* Touch lock (W)
  1285. * example: echo 1 > raydium_i2c_touch_lock ==> enable touch lock
  1286. * echo 0 > raydium_i2c_touch_lock ==> disable touch lock
  1287. */
  1288. static DEVICE_ATTR(raydium_i2c_touch_lock, 0644,
  1289. NULL,
  1290. raydium_touch_lock_store);
  1291. /* Touch Offload (W)
  1292. * example: echo 1 > raydium_touch_offload ==> enable touch offload
  1293. * echo 0 > raydium_touch_offload ==> disable touch offload
  1294. */
  1295. static DEVICE_ATTR(raydium_touch_offload, 0644,
  1296. raydium_touch_offload_show,
  1297. raydium_touch_offload_store);
  1298. /* Log level (W)
  1299. * example: echo 1 > raydium_log_level ==> modify log level
  1300. */
  1301. static DEVICE_ATTR(raydium_log_level, 0644,
  1302. NULL,
  1303. raydium_log_level_store);
  1304. /* show the fw version (R)
  1305. * example:cat raydium_fw_version
  1306. */
  1307. static DEVICE_ATTR(raydium_check_fw_version, 0644,
  1308. raydium_check_fw_version_show,
  1309. NULL);
  1310. /* show the driver version (R)
  1311. * example:cat raydium_check_driver_version
  1312. */
  1313. static DEVICE_ATTR(raydium_check_driver_version, 0644,
  1314. raydium_check_driver_version_show,
  1315. NULL);
  1316. /* show the panel version (R)
  1317. * example:cat raydium_panel_version
  1318. */
  1319. static DEVICE_ATTR(raydium_check_panel_version, 0644,
  1320. raydium_check_panel_version_show,
  1321. NULL);
  1322. static DEVICE_ATTR(raydium_hw_reset, 0644,
  1323. raydium_hw_reset_show,
  1324. NULL);
  1325. static DEVICE_ATTR(raydium_palm_status, 0644,
  1326. raydium_palm_status_show,
  1327. NULL);
  1328. static DEVICE_ATTR(raydium_receive_fw_control, 0644,
  1329. NULL,
  1330. raydium_receive_fw_store);
  1331. static DEVICE_ATTR(raydium_mem_setting, 0644,
  1332. NULL,
  1333. raydium_mem_store);
  1334. #ifdef RAD_SELFTEST
  1335. /* Read interrupt flag cmd (R)
  1336. * example:cat raydium_int_flag
  1337. */
  1338. static DEVICE_ATTR(raydium_int_flag, 0644,
  1339. raydium_flag_show,
  1340. raydium_flag_store);
  1341. static DEVICE_ATTR(raydium_reset_control, 0644,
  1342. NULL,
  1343. raydium_reset_control_store);
  1344. static DEVICE_ATTR(raydium_irq_state, 0644,
  1345. raydium_irq_state_show,
  1346. NULL);
  1347. static DEVICE_ATTR(raydium_do_selftest, 0644,
  1348. raydium_selftest_show,
  1349. NULL);
  1350. #endif
  1351. /*add your attr in here*/
  1352. struct attribute *raydium_attributes[] = {
  1353. &dev_attr_raydium_touch_calibration.attr,
  1354. &dev_attr_raydium_check_i2c.attr,
  1355. &dev_attr_raydium_i2c_pda2_mode.attr,
  1356. &dev_attr_raydium_i2c_pda_access.attr,
  1357. &dev_attr_raydium_i2c_pda_access_via_pda2.attr,
  1358. &dev_attr_raydium_i2c_pda2_access.attr,
  1359. &dev_attr_raydium_i2c_pda2_page.attr,
  1360. &dev_attr_raydium_i2c_raw_data.attr,
  1361. &dev_attr_raydium_i2c_touch_lock.attr,
  1362. &dev_attr_raydium_touch_offload.attr,
  1363. &dev_attr_raydium_fw_upgrade.attr,
  1364. &dev_attr_raydium_check_fw_version.attr,
  1365. &dev_attr_raydium_check_panel_version.attr,
  1366. &dev_attr_raydium_hw_reset.attr,
  1367. &dev_attr_raydium_palm_status.attr,
  1368. &dev_attr_raydium_check_driver_version.attr,
  1369. &dev_attr_raydium_receive_fw_control.attr,
  1370. &dev_attr_raydium_mem_setting.attr,
  1371. &dev_attr_raydium_log_level.attr,
  1372. #ifdef RAD_SELFTEST
  1373. &dev_attr_raydium_irq_state.attr,
  1374. &dev_attr_raydium_int_flag.attr,
  1375. &dev_attr_raydium_reset_control.attr,
  1376. &dev_attr_raydium_do_selftest.attr,
  1377. #endif
  1378. NULL
  1379. };