raydium_sysfs.c 42 KB

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