raydium_driver.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703
  1. /* raydium_driver.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/i2c.h>
  19. #include <linux/input.h>
  20. #include <linux/input/mt.h>
  21. #include <linux/delay.h>
  22. #include <linux/slab.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/kernel.h>
  25. #include <linux/mutex.h>
  26. #include <linux/module.h>
  27. #include <linux/gpio.h>
  28. #include <linux/unistd.h>
  29. #include <linux/uaccess.h>
  30. #include <linux/string.h>
  31. #include <linux/timer.h>
  32. #include <linux/regulator/consumer.h>
  33. #include <linux/device.h>
  34. #include <linux/kprobes.h>
  35. #include <asm/traps.h>
  36. #include <linux/firmware.h>
  37. #include <linux/of_gpio.h>
  38. #include <linux/err.h>
  39. #include <linux/of_device.h>
  40. #include "raydium_driver.h"
  41. #include <glink_interface.h>
  42. #include <linux/remoteproc/qcom_rproc.h>
  43. #if defined(CONFIG_FB)
  44. #include <linux/notifier.h>
  45. #include <linux/fb.h>
  46. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  47. #include <linux/earlysuspend.h>
  48. #endif /*end of CONFIG_FB*/
  49. #if defined(CONFIG_PANEL_NOTIFIER)
  50. #include <linux/soc/qcom/panel_event_notifier.h>
  51. #endif
  52. struct raydium_slot_status {
  53. unsigned char pt_id; /*Occupied point ID*/
  54. unsigned char need_update; /*Mark as info need to be updated*/
  55. unsigned char pt_report_offset; /*point info offset in report*/
  56. };
  57. /*The first 3 elements are currently occupied. therest is new coming points*/
  58. struct raydium_slot_status gst_slot[MAX_TOUCH_NUM * 2];
  59. struct raydium_slot_status gst_slot_init = {0xFF, 0, 0};
  60. static int raydium_enable_regulator(struct raydium_ts_data *cd, bool en);
  61. #if (defined(CONFIG_RM_SYSFS_DEBUG))
  62. const struct attribute_group raydium_attr_group;
  63. #endif /*end of CONFIG_RM_SYSFS_DEBUG*/
  64. #if defined(CONFIG_DRM) || defined(CONFIG_PANEL_NOTIFIER)
  65. static struct drm_panel *active_panel;
  66. #endif
  67. unsigned char g_u8_addr;
  68. unsigned char g_u8_raydium_flag;
  69. unsigned char g_u8_i2c_mode;
  70. unsigned char g_u8_upgrade_type;
  71. unsigned char g_u8_raw_data_type;
  72. unsigned int g_u32_raw_data_len; /* 128 bytes*/
  73. unsigned long g_u32_addr;
  74. unsigned int g_u32_length;
  75. unsigned int g_u32_driver_version;
  76. unsigned char *g_rad_fw_image, *g_rad_init_image;
  77. unsigned char *g_rad_boot_image, *g_rad_para_image;
  78. unsigned char *g_rad_testfw_image, *g_rad_testpara_image;
  79. unsigned char g_u8_table_setting, g_u8_table_init;
  80. unsigned char g_u8_resetflag;
  81. unsigned char g_u8_wakeup_flag;
  82. #ifdef ESD_SOLUTION_EN
  83. unsigned char g_u8_checkflag;
  84. #endif
  85. unsigned char g_u8_log_level;
  86. struct raydium_ts_data *g_raydium_ts;
  87. /*******************************************************************************
  88. * Name: raydium_variable_init
  89. * Brief:
  90. * Input:
  91. * Output:
  92. * Return:
  93. *******************************************************************************/
  94. static void raydium_variable_init(void)
  95. {
  96. g_u8_addr = RAYDIUM_PDA2_PDA_CFG_ADDR;
  97. g_u8_raydium_flag = NORMAL_MODE;
  98. g_u8_i2c_mode = PDA2_MODE;
  99. g_u8_upgrade_type = 0;
  100. g_u8_raw_data_type = RAYDIUM_FT_UPDATE;
  101. g_u32_raw_data_len = 64 * 2; /* 128 bytes*/
  102. g_u32_addr = RAYDIUM_CHK_I2C_CMD;
  103. g_u32_length = 1;
  104. g_u8_table_setting = 0;
  105. g_u8_table_init = 0;
  106. g_rad_fw_image = NULL;
  107. g_rad_init_image = NULL;
  108. g_rad_boot_image = NULL;
  109. g_rad_para_image = NULL;
  110. g_rad_testfw_image = NULL;
  111. g_rad_testpara_image = NULL;
  112. g_u32_driver_version = ((RAD_MAIN_VERSION << 24) |
  113. (RAD_MINOR_VERSION << 16) |
  114. (RAD_CUSTOMER_VERSION));
  115. g_u8_resetflag = false;
  116. g_u8_wakeup_flag = false;
  117. #ifdef ESD_SOLUTION_EN
  118. g_u8_checkflag = false;
  119. #endif
  120. g_u8_log_level = LOG_INFO;
  121. }
  122. /*******************************************************************************
  123. * Name: raydium_gpio_configure
  124. * Brief:
  125. * Input:
  126. * Output:
  127. * Return:
  128. *******************************************************************************/
  129. static int raydium_gpio_configure(bool on)
  130. {
  131. int i32_err = 0;
  132. if (on) {
  133. if (gpio_is_valid(g_raydium_ts->irq_gpio)) {
  134. i32_err = gpio_request(g_raydium_ts->irq_gpio,
  135. "raydium_irq_gpio");
  136. if (i32_err) {
  137. LOGD(LOG_ERR, "[touch]irq gpio request failed");
  138. goto err_irq_gpio_req;
  139. }
  140. i32_err = gpio_direction_input(g_raydium_ts->irq_gpio);
  141. if (i32_err) {
  142. LOGD(LOG_ERR, "[touch]set_direction for irq gpio failed\n");
  143. goto err_irq_gpio_dir;
  144. }
  145. }
  146. if (gpio_is_valid(g_raydium_ts->rst_gpio)) {
  147. i32_err = gpio_request(g_raydium_ts->rst_gpio,
  148. "raydium_rst_gpio");
  149. if (i32_err) {
  150. LOGD(LOG_ERR, "[touch]rst gpio request failed");
  151. goto err_irq_gpio_req;
  152. }
  153. i32_err = gpio_direction_output(g_raydium_ts->rst_gpio, 0);
  154. msleep(RAYDIUM_RESET_INTERVAL_10MSEC);
  155. if (i32_err) {
  156. LOGD(LOG_ERR,
  157. "[touch]set_direction for rst gpio failed\n");
  158. goto err_rst_gpio_dir;
  159. }
  160. i32_err = gpio_direction_output(g_raydium_ts->rst_gpio, 1);
  161. if (i32_err) {
  162. LOGD(LOG_ERR,
  163. "[touch]set_direction for irq gpio failed\n");
  164. goto err_rst_gpio_dir;
  165. }
  166. }
  167. } else {
  168. if (gpio_is_valid(g_raydium_ts->irq_gpio))
  169. gpio_free(g_raydium_ts->irq_gpio);
  170. }
  171. return 0;
  172. err_rst_gpio_dir:
  173. if (gpio_is_valid(g_raydium_ts->rst_gpio))
  174. gpio_free(g_raydium_ts->rst_gpio);
  175. return i32_err;
  176. err_irq_gpio_dir:
  177. if (gpio_is_valid(g_raydium_ts->irq_gpio))
  178. gpio_free(g_raydium_ts->irq_gpio);
  179. err_irq_gpio_req:
  180. return i32_err;
  181. }
  182. /*******************************************************************************
  183. * Name: raydium_ts_pinctrl_init
  184. * Brief:
  185. * Input:
  186. * Output:
  187. * Return:
  188. *******************************************************************************/
  189. #ifdef MSM_NEW_VER
  190. static int raydium_ts_pinctrl_init(void)
  191. {
  192. int i32_ret;
  193. /* Get pinctrl if target uses pinctrl */
  194. g_raydium_ts->ts_pinctrl = devm_pinctrl_get(&(g_raydium_ts->client->dev));
  195. if (IS_ERR_OR_NULL(g_raydium_ts->ts_pinctrl)) {
  196. i32_ret = PTR_ERR(g_raydium_ts->ts_pinctrl);
  197. LOGD(LOG_ERR, "[touch]target does not use pinctrl %d\n", i32_ret);
  198. goto err_pinctrl_get;
  199. }
  200. g_raydium_ts->pinctrl_state_active
  201. = pinctrl_lookup_state(g_raydium_ts->ts_pinctrl, PINCTRL_STATE_ACTIVE);
  202. if (IS_ERR_OR_NULL(g_raydium_ts->pinctrl_state_active)) {
  203. i32_ret = PTR_ERR(g_raydium_ts->pinctrl_state_active);
  204. LOGD(LOG_ERR, "[touch]Can not lookup %s pinstate %d\n",
  205. PINCTRL_STATE_ACTIVE, i32_ret);
  206. goto err_pinctrl_lookup;
  207. }
  208. g_raydium_ts->pinctrl_state_suspend
  209. = pinctrl_lookup_state(g_raydium_ts->ts_pinctrl,
  210. PINCTRL_STATE_SUSPEND);
  211. if (IS_ERR_OR_NULL(g_raydium_ts->pinctrl_state_suspend)) {
  212. i32_ret = PTR_ERR(g_raydium_ts->pinctrl_state_suspend);
  213. LOGD(LOG_ERR, "[touch]Can not lookup %s pinstate %d\n",
  214. PINCTRL_STATE_SUSPEND, i32_ret);
  215. goto err_pinctrl_lookup;
  216. }
  217. g_raydium_ts->pinctrl_state_release
  218. = pinctrl_lookup_state(g_raydium_ts->ts_pinctrl,
  219. PINCTRL_STATE_RELEASE);
  220. if (IS_ERR_OR_NULL(g_raydium_ts->pinctrl_state_release)) {
  221. i32_ret = PTR_ERR(g_raydium_ts->pinctrl_state_release);
  222. LOGD(LOG_ERR, "[touch]Can not lookup %s pinstate %d\n",
  223. PINCTRL_STATE_RELEASE, i32_ret);
  224. }
  225. return 0;
  226. err_pinctrl_lookup:
  227. devm_pinctrl_put(g_raydium_ts->ts_pinctrl);
  228. err_pinctrl_get:
  229. g_raydium_ts->ts_pinctrl = NULL;
  230. return i32_ret;
  231. }
  232. #endif/*end of MSM_NEW_VER*/
  233. #ifdef ESD_SOLUTION_EN
  234. static int raydium_hw_reset_fun(struct i2c_client *client)
  235. {
  236. int i32_ret = SUCCESS;
  237. LOGD(LOG_INFO, "[touch]HW reset\n");
  238. g_u8_raydium_flag |= ENG_MODE;
  239. g_u8_resetflag = true;
  240. /*HW reset*/
  241. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  242. gpio_set_value(g_raydium_ts->rst_gpio, 0);
  243. msleep(RAYDIUM_RESET_INTERVAL_MSEC);
  244. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  245. g_u8_i2c_mode = PDA2_MODE;
  246. i32_ret = wait_irq_state(client, 300, 2000);
  247. if (i32_ret != ERROR)
  248. msleep(35);
  249. g_u8_raydium_flag &= ~ENG_MODE;
  250. LOGD(LOG_INFO, "[touch]Raydium HW reset : %d\n", i32_ret);
  251. return i32_ret;
  252. }
  253. #endif
  254. int raydium_i2c_write_pda_via_pda2(struct i2c_client *client,
  255. unsigned int u32_addr, unsigned char *u8_w_data,
  256. unsigned short u16_length)
  257. {
  258. int i32_ret = -1;
  259. /*unsigned char u8_retry;*/
  260. unsigned char u8_mode = 0x00;
  261. unsigned char u8_buf[MAX_WRITE_PACKET_SIZE + 6];
  262. struct i2c_msg msg[] = {
  263. {
  264. .addr = RAYDIUM_I2C_NID,
  265. .flags = RAYDIUM_I2C_WRITE,
  266. .len = u16_length + 6,
  267. .buf = u8_buf,
  268. },
  269. };
  270. if (u16_length > MAX_WRITE_PACKET_SIZE)
  271. return -EINVAL;
  272. /*I2C access for register need to word mode*/
  273. if ((u16_length == 4) &&
  274. ((u32_addr & 0x50000000) || (u32_addr & 0x40000000)))
  275. u8_mode = I2C_PDA2_WORD_MODE;
  276. else
  277. u8_mode = I2C_PDA2_BYTE_MODE;
  278. if (u16_length > MAX_WRITE_PACKET_SIZE)
  279. return -EINVAL;
  280. g_u8_i2c_mode = PDA2_MODE;
  281. u8_buf[0] = RAYDIUM_I2C_PDA_CMD;
  282. u8_buf[1] = (unsigned char)u32_addr;
  283. u8_buf[2] = (unsigned char)(u32_addr >> 8);
  284. u8_buf[3] = (unsigned char)(u32_addr >> 16);
  285. u8_buf[4] = (unsigned char)(u32_addr >> 24);
  286. u8_buf[5] = u8_mode;
  287. memcpy(&u8_buf[6], u8_w_data, u16_length);
  288. /*for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {*/
  289. if (i2c_transfer(client->adapter, msg, 1) == 1) {
  290. i32_ret = u16_length;
  291. /*break;*/
  292. }
  293. i32_ret = u16_length;
  294. /*usleep_range(500, 1500);*/
  295. /*}*/
  296. /*if (u8_retry == SYN_I2C_RETRY_TIMES) {*/
  297. /* LOGD(LOG_ERR, "[touch]%s: I2C write over retry limit\n", __func__);*/
  298. /* i32_ret = -EIO;*/
  299. /*}*/
  300. return i32_ret;
  301. }
  302. int raydium_i2c_read_pda_via_pda2(struct i2c_client *client,
  303. unsigned int u32_addr, unsigned char *u8_r_data,
  304. unsigned short u16_length)
  305. {
  306. int i32_ret;
  307. /*unsigned char u8_retry;*/
  308. unsigned char u8_mode = 0x00;
  309. unsigned char u8_buf[6];
  310. struct i2c_msg msg[] = {
  311. {
  312. .addr = RAYDIUM_I2C_NID,
  313. .flags = RAYDIUM_I2C_WRITE,
  314. .len = 6,
  315. .buf = u8_buf,
  316. },
  317. {
  318. .addr = RAYDIUM_I2C_NID,
  319. .flags = RAYDIUM_I2C_READ,
  320. .len = u16_length,
  321. .buf = u8_r_data,
  322. },
  323. };
  324. if ((u32_addr & 0x50000000) || (u32_addr & 0x40000000))
  325. u8_mode = I2C_PDA2_WORD_MODE;
  326. else
  327. u8_mode = I2C_PDA2_BYTE_MODE;
  328. g_u8_i2c_mode = PDA2_MODE;
  329. u8_buf[0] = RAYDIUM_I2C_PDA_CMD;
  330. u8_buf[1] = (unsigned char)u32_addr;
  331. u8_buf[2] = (unsigned char)(u32_addr >> 8);
  332. u8_buf[3] = (unsigned char)(u32_addr >> 16);
  333. u8_buf[4] = (unsigned char)(u32_addr >> 24);
  334. u8_buf[5] = u8_mode;
  335. /*for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {*/
  336. if (i2c_transfer(g_raydium_ts->client->adapter, msg, 2) == 2) {
  337. i32_ret = u16_length;
  338. /*break;*/
  339. }
  340. i32_ret = u16_length;
  341. /*usleep_range(500, 1500);*/
  342. /*}*/
  343. /*if (u8_retry == SYN_I2C_RETRY_TIMES) {*/
  344. /* LOGD(LOG_ERR, "[touch]%s: I2C read over retry limit\n", __func__);*/
  345. /* i32_ret = -EIO;*/
  346. /*}*/
  347. return i32_ret;
  348. }
  349. int raydium_i2c_pda_set_address(unsigned int u32_address,
  350. unsigned char u8_mode)
  351. {
  352. int i32_ret = 0;
  353. unsigned char u8_retry;
  354. unsigned char u8_buf[RAD_I2C_PDA_ADDRESS_LENGTH];
  355. struct i2c_client *client = g_raydium_ts->client;
  356. client->addr = RAYDIUM_I2C_EID;
  357. u8_buf[0] = (u32_address & 0x0000FF00) >> 8;
  358. u8_buf[1] = (u32_address & 0x00FF0000) >> 16;
  359. u8_buf[2] = (u32_address & 0xFF000000) >> 24;
  360. u8_buf[3] = u8_mode;
  361. for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {
  362. i32_ret = i2c_master_send(client, u8_buf,
  363. RAD_I2C_PDA_ADDRESS_LENGTH);
  364. if (i32_ret != RAD_I2C_PDA_ADDRESS_LENGTH) {
  365. LOGD(LOG_ERR, "[touch]%s: I2C retry %d\n",
  366. __func__, u8_retry + 1);
  367. usleep_range(500, 1500);
  368. } else {
  369. break;
  370. }
  371. }
  372. return (i32_ret == RAD_I2C_PDA_ADDRESS_LENGTH) ? i32_ret : -EIO;
  373. }
  374. /*device attribute raydium_i2c_pda2_mode used*/
  375. int raydium_i2c_pda_read(struct i2c_client *client,
  376. unsigned int u32_addr, unsigned char *u8_r_data,
  377. unsigned short u16_length)
  378. {
  379. int i32_ret;
  380. unsigned char u8_retry;
  381. unsigned char u8_mode = 0x00;
  382. unsigned char u8_buf;
  383. struct i2c_msg msg[] = {
  384. {
  385. .addr = RAYDIUM_I2C_NID,
  386. .flags = RAYDIUM_I2C_WRITE,
  387. .len = 1,
  388. .buf = &u8_buf,
  389. },
  390. {
  391. .addr = RAYDIUM_I2C_NID,
  392. .flags = RAYDIUM_I2C_READ,
  393. .len = u16_length,
  394. .buf = u8_r_data,
  395. },
  396. };
  397. if (u16_length == 4)
  398. u8_mode |= RAD_I2C_PDA_MODE_ENABLE |
  399. RAD_I2C_PDA_2_MODE_DISABLE |
  400. RAD_I2C_PDA_MODE_WORD_MODE;
  401. else
  402. u8_mode |= RAD_I2C_PDA_MODE_ENABLE |
  403. RAD_I2C_PDA_2_MODE_DISABLE;
  404. u8_mode |= 0x03;
  405. u8_buf = u32_addr & MASK_8BIT;
  406. i32_ret = raydium_i2c_pda_set_address(u32_addr, u8_mode);
  407. if (i32_ret != RAD_I2C_PDA_ADDRESS_LENGTH)
  408. goto exit;
  409. usleep_range(50, 80);
  410. for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {
  411. if (i2c_transfer(g_raydium_ts->client->adapter, msg, 2) == 2) {
  412. i32_ret = u16_length;
  413. break;
  414. }
  415. LOGD(LOG_ERR, "%s: I2C retry %d\n", __func__, u8_retry + 1);
  416. usleep_range(500, 1500);
  417. }
  418. if (u8_retry == SYN_I2C_RETRY_TIMES) {
  419. LOGD(LOG_ERR, "%s: I2C read over retry limit\n", __func__);
  420. i32_ret = -EIO;
  421. }
  422. exit:
  423. return i32_ret;
  424. }
  425. int raydium_i2c_pda_write(struct i2c_client *client,
  426. unsigned int u32_addr, unsigned char *u8_w_data,
  427. unsigned short u16_length)
  428. {
  429. int i32_ret;
  430. unsigned char u8_retry;
  431. unsigned char u8_mode = 0x00;
  432. unsigned char u8_buf[MAX_WRITE_PACKET_SIZE + 1];
  433. struct i2c_msg msg[] = {
  434. {
  435. .addr = RAYDIUM_I2C_NID,
  436. .flags = RAYDIUM_I2C_WRITE,
  437. .len = u16_length + 1,
  438. .buf = u8_buf,
  439. },
  440. };
  441. if (u16_length > MAX_WRITE_PACKET_SIZE)
  442. return -EINVAL;
  443. if (u16_length == 4)
  444. u8_mode |= RAD_I2C_PDA_MODE_ENABLE |
  445. RAD_I2C_PDA_2_MODE_DISABLE |
  446. RAD_I2C_PDA_MODE_WORD_MODE;
  447. else
  448. u8_mode |= RAD_I2C_PDA_MODE_ENABLE |
  449. RAD_I2C_PDA_2_MODE_DISABLE;
  450. u8_buf[0] = u32_addr & MASK_8BIT;
  451. memcpy(&u8_buf[1], u8_w_data, u16_length);
  452. i32_ret = raydium_i2c_pda_set_address(u32_addr, u8_mode);
  453. if (i32_ret != RAD_I2C_PDA_ADDRESS_LENGTH)
  454. goto exit;
  455. usleep_range(50, 80);
  456. for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {
  457. if (i2c_transfer(client->adapter, msg, 1) == 1) {
  458. i32_ret = u16_length;
  459. break;
  460. }
  461. LOGD(LOG_ERR, "[touch]%s: I2C retry %d\n", __func__, u8_retry + 1);
  462. usleep_range(500, 1500);
  463. }
  464. if (u8_retry == SYN_I2C_RETRY_TIMES) {
  465. LOGD(LOG_ERR, "[touch]%s: I2C write over retry limit\n", __func__);
  466. i32_ret = -EIO;
  467. }
  468. exit:
  469. return i32_ret;
  470. }
  471. int handle_i2c_pda_read(struct i2c_client *client,
  472. unsigned int u32_addr, unsigned char *u8_r_data,
  473. unsigned short u16_length)
  474. {
  475. if ((g_u8_i2c_mode & PDA_MODE) != 0) {
  476. if (raydium_i2c_pda_read(client, u32_addr, u8_r_data, u16_length) == ERROR) {
  477. LOGD(LOG_ERR, "[touch] handle_ic_write I2C NG!\r\n");
  478. return ERROR;
  479. }
  480. } else {
  481. if (raydium_i2c_read_pda_via_pda2(client, u32_addr, u8_r_data, u16_length) == ERROR) {
  482. LOGD(LOG_ERR, "[touch] handle_ic_write I2C via_pda2 NG!\r\n");
  483. return ERROR;
  484. }
  485. }
  486. return SUCCESS;
  487. }
  488. int handle_i2c_pda_write(struct i2c_client *client,
  489. unsigned int u32_addr, unsigned char *u8_w_data,
  490. unsigned short u16_length)
  491. {
  492. if ((g_u8_i2c_mode & PDA_MODE) != 0) {
  493. if (raydium_i2c_pda_write(client, u32_addr, u8_w_data, u16_length) == ERROR) {
  494. LOGD(LOG_ERR, "[touch] handle_ic_write I2C NG!\r\n");
  495. return ERROR;
  496. }
  497. } else {
  498. if (raydium_i2c_write_pda_via_pda2(client, u32_addr, u8_w_data, u16_length) == ERROR) {
  499. LOGD(LOG_ERR, "[touch] handle_ic_write I2C via_pda2 NG!\r\n");
  500. return ERROR;
  501. }
  502. }
  503. return SUCCESS;
  504. }
  505. int raydium_i2c_pda2_set_page(struct i2c_client *client,
  506. unsigned int is_suspend,
  507. unsigned char u8_page)
  508. {
  509. int i32_ret = -1;
  510. unsigned char u8_retry;
  511. unsigned int u8_ret = (is_suspend) ? 10 : 2;
  512. unsigned char u8_buf[RAYDIUM_I2C_PDA2_PAGE_LENGTH];
  513. struct i2c_msg msg[] = {
  514. {
  515. .addr = RAYDIUM_I2C_NID,
  516. .flags = RAYDIUM_I2C_WRITE,
  517. .len = RAYDIUM_I2C_PDA2_PAGE_LENGTH,
  518. .buf = u8_buf,
  519. },
  520. };
  521. u8_buf[0] = RAYDIUM_PDA2_PAGE_ADDR;
  522. u8_buf[1] = u8_page;
  523. for (; u8_ret > 0; u8_ret--) {
  524. for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {
  525. if (i2c_transfer(client->adapter, msg, 1) == 1) {
  526. i32_ret = RAYDIUM_I2C_PDA2_PAGE_LENGTH;
  527. break;
  528. }
  529. usleep_range(500, 1500);
  530. }
  531. if (i32_ret == RAYDIUM_I2C_PDA2_PAGE_LENGTH)
  532. break;
  533. usleep_range(2000, 5000);
  534. }
  535. if (u8_ret == 0) {
  536. LOGD(LOG_ERR, "[touch]%s: I2C write over retry limit\n", __func__);
  537. i32_ret = -EIO;
  538. }
  539. return i32_ret;
  540. }
  541. int raydium_i2c_pda2_read(struct i2c_client *client,
  542. unsigned char u8_addr,
  543. unsigned char *u8_r_data,
  544. unsigned short u16_length)
  545. {
  546. int i32_ret = -1;
  547. unsigned char u8_retry;
  548. struct i2c_msg msg[] = {
  549. {
  550. .addr = RAYDIUM_I2C_NID,
  551. .flags = RAYDIUM_I2C_WRITE,
  552. .len = 1,
  553. .buf = &u8_addr,
  554. },
  555. {
  556. .addr = RAYDIUM_I2C_NID,
  557. .flags = RAYDIUM_I2C_READ,
  558. .len = u16_length,
  559. .buf = u8_r_data,
  560. },
  561. };
  562. g_u8_i2c_mode = PDA2_MODE;
  563. for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {
  564. if (i2c_transfer(g_raydium_ts->client->adapter, msg, 2) == 2) {
  565. i32_ret = u16_length;
  566. break;
  567. }
  568. usleep_range(500, 1500);
  569. }
  570. if (u8_retry == SYN_I2C_RETRY_TIMES) {
  571. LOGD(LOG_ERR, "[touch]%s: I2C read over retry limit\n", __func__);
  572. i32_ret = -EIO;
  573. }
  574. return i32_ret;
  575. }
  576. int raydium_i2c_pda2_write(struct i2c_client *client,
  577. unsigned char u8_addr,
  578. unsigned char *u8_w_data,
  579. unsigned short u16_length)
  580. {
  581. int i32_ret = -1;
  582. unsigned char u8_retry;
  583. unsigned char u8_buf[MAX_WRITE_PACKET_SIZE + 1];
  584. struct i2c_msg msg[] = {
  585. {
  586. .addr = RAYDIUM_I2C_NID,
  587. .flags = RAYDIUM_I2C_WRITE,
  588. .len = u16_length + 1,
  589. .buf = u8_buf,
  590. },
  591. };
  592. if (u16_length > MAX_WRITE_PACKET_SIZE)
  593. return -EINVAL;
  594. g_u8_i2c_mode = PDA2_MODE;
  595. u8_buf[0] = u8_addr;
  596. memcpy(&u8_buf[1], u8_w_data, u16_length);
  597. for (u8_retry = 0; u8_retry < SYN_I2C_RETRY_TIMES; u8_retry++) {
  598. if (i2c_transfer(client->adapter, msg, 1) == 1) {
  599. i32_ret = u16_length;
  600. break;
  601. }
  602. usleep_range(500, 1500);
  603. }
  604. if (u8_retry == SYN_I2C_RETRY_TIMES) {
  605. LOGD(LOG_ERR, "[touch]%s: I2C write over retry limit\n", __func__);
  606. i32_ret = -EIO;
  607. }
  608. return i32_ret;
  609. }
  610. void raydium_irq_control(bool enable)
  611. {
  612. if (enable) {
  613. if (g_raydium_ts->irq_enabled) {
  614. /*mutex_unlock(&ts->lock);*/
  615. LOGD(LOG_INFO, "[touch]Already enable irq\n");
  616. return;
  617. }
  618. /* Clear interrupts first */
  619. #if defined(CONFIG_PANEL_NOTIFIER)
  620. if (g_raydium_ts->blank != DRM_PANEL_EVENT_BLANK) {
  621. #else
  622. if (g_raydium_ts->blank != DRM_PANEL_BLANK_POWERDOWN) {
  623. #endif
  624. if (g_u8_i2c_mode == PDA2_MODE) {
  625. mutex_lock(&g_raydium_ts->lock);
  626. if (raydium_i2c_pda2_set_page(g_raydium_ts->client,
  627. g_raydium_ts->is_suspend,
  628. RAYDIUM_PDA2_PAGE_0) < 0)
  629. LOGD(LOG_ERR, "[touch]set page fail%s\n", __func__);
  630. mutex_unlock(&g_raydium_ts->lock);
  631. usleep_range(500, 1500);
  632. }
  633. }
  634. while (g_raydium_ts->irq_desc->depth > 0) {
  635. LOGD(LOG_INFO, "[touch]irq enable\n");
  636. g_raydium_ts->irq_enabled = true;
  637. enable_irq(g_raydium_ts->irq);
  638. }
  639. } else {
  640. if (g_raydium_ts->irq_enabled) {
  641. if (g_raydium_ts->irq_desc->depth == 0) {
  642. disable_irq(g_raydium_ts->irq);
  643. g_raydium_ts->irq_enabled = false;
  644. LOGD(LOG_INFO, "[touch]irq disable\n");
  645. }
  646. }
  647. }
  648. }
  649. unsigned char raydium_disable_i2c_deglitch(void)
  650. {
  651. unsigned int u32_buf = 0;
  652. unsigned char u8_retry = 3, u8_comfirm_time = 3;
  653. unsigned char u8_check = 0, u8_i = 0;
  654. unsigned int u32_i2c_deglitch = 0x07060000;
  655. unsigned char u8_buf[4];
  656. while (u8_retry--) {
  657. u32_buf = 0;
  658. handle_i2c_pda_read(g_raydium_ts->client, RAYDIUM_CHK_I2C_CMD,
  659. (unsigned char *)(&u32_buf), 4);
  660. if ((u32_buf & 0xFFFF0000) == 0xF3030000)
  661. u8_check++;
  662. }
  663. if (u8_check == 3) {
  664. LOGD(LOG_INFO, "[touch]PDA2 OK\r\n");
  665. return SUCCESS;
  666. }
  667. g_u8_i2c_mode = PDA_MODE;
  668. u8_retry = 100;
  669. while (u8_retry--) {
  670. u8_check = 0;
  671. for (u8_i = 0; u8_i < u8_comfirm_time; u8_i++) {
  672. /*check I2C*/
  673. u32_buf = 0;
  674. if (handle_i2c_pda_read(g_raydium_ts->client,
  675. RAYDIUM_PDA_I2CENG,
  676. (unsigned char *)(&u32_buf), 4) == ERROR) {
  677. LOGD(LOG_ERR, "[touch]%s: 1.handle_ic_read I2C NG!\r\n", __func__);
  678. break;
  679. }
  680. if (u32_buf == u32_i2c_deglitch)
  681. u8_check++;
  682. else
  683. break;
  684. }
  685. if (u8_check == u8_comfirm_time)
  686. break;
  687. if (handle_i2c_pda_write(g_raydium_ts->client, RAYDIUM_PDA_I2CENG,
  688. (unsigned char *)(&u32_i2c_deglitch), 4) == ERROR) {
  689. LOGD(LOG_ERR, "[touch]%s:handle_ic_write I2C NG!\r\n", __func__);
  690. continue;
  691. }
  692. u8_check = 0;
  693. for (u8_i = 0; u8_i < u8_comfirm_time; u8_i++) {
  694. /*check I2C*/
  695. u32_buf = 0;
  696. if (handle_i2c_pda_read(g_raydium_ts->client,
  697. RAYDIUM_PDA_I2CENG,
  698. (unsigned char *)(&u32_buf), 4) == ERROR) {
  699. LOGD(LOG_ERR, "[touch]%s:2.handle_ic_read I2C NG!\r\n", __func__);
  700. break;
  701. }
  702. if (u32_buf == u32_i2c_deglitch)
  703. u8_check++;
  704. else
  705. break;
  706. }
  707. if (u8_check == u8_comfirm_time)
  708. break;
  709. }
  710. if (u8_retry == 0)
  711. return ERROR;
  712. u32_buf = 0x03;
  713. if (handle_i2c_pda_write(g_raydium_ts->client, RAYDIUM_REG_GPIO_DEGLITCH,
  714. (unsigned char *)(&u32_buf), 4) == ERROR) {
  715. LOGD(LOG_ERR, "[touch]%s:3.handle_ic_write I2C NG!\r\n", __func__);
  716. return ERROR;
  717. }
  718. /*Disable PDA*/
  719. handle_i2c_pda_read(g_raydium_ts->client, RAYDIUM_PDA_I2CREG, u8_buf, 4);
  720. u8_buf[0] |= RAD_ENABLE_PDA2 | RAD_ENABLE_SI2;
  721. handle_i2c_pda_write(g_raydium_ts->client, RAYDIUM_PDA_I2CREG, u8_buf, 4);
  722. raydium_i2c_pda_set_address(0x50000628, DISABLE);
  723. g_u8_i2c_mode = PDA2_MODE;
  724. return SUCCESS;
  725. }
  726. #ifdef CONFIG_RM_SYSFS_DEBUG
  727. int raydium_i2c_mode_control(struct i2c_client *client,
  728. unsigned char u8_mode)
  729. {
  730. unsigned char u8_buf[4];
  731. switch (u8_mode) {
  732. case 0: /* Disable INT flag */
  733. LOGD(LOG_INFO, "[touch]RAD INT flag : %d\n", g_raydium_ts->irq_enabled);
  734. disable_irq(g_raydium_ts->irq);
  735. g_raydium_ts->irq_enabled = false;
  736. LOGD(LOG_INFO, "[touch]RAD irq disable\n");
  737. break;
  738. case 1: /* Enable INT flag */
  739. LOGD(LOG_INFO, "[touch]RAD INT flag : %d\n", g_raydium_ts->irq_enabled);
  740. enable_irq(g_raydium_ts->irq);
  741. g_raydium_ts->irq_enabled = true;
  742. LOGD(LOG_INFO, "[touch]RAD irq enable\n");
  743. break;
  744. case 2: /* Disable INT by raydium_irq_control */
  745. raydium_irq_control(DISABLE);
  746. break;
  747. case 3: /* Enable INT by raydium_irq_control */
  748. raydium_irq_control(ENABLE);
  749. break;
  750. case 4: /* Show RAD INT depth */
  751. LOGD(LOG_INFO, "[touch]RAD INT depth : %d\n", g_raydium_ts->irq_desc->depth);
  752. break;
  753. case 7:
  754. raydium_i2c_pda2_set_page(client,
  755. g_raydium_ts->is_suspend, RAYDIUM_PDA2_2_PDA);
  756. g_u8_i2c_mode = PDA_MODE;
  757. LOGD(LOG_INFO, "[touch]Disable PDA2_MODE\n");
  758. break;
  759. case 8:
  760. raydium_i2c_pda_read(client, RAYDIUM_PDA_I2CREG, u8_buf, 4);
  761. u8_buf[0] |= RAD_ENABLE_PDA2 | RAD_ENABLE_SI2;
  762. raydium_i2c_pda_write(client, RAYDIUM_PDA_I2CREG, u8_buf, 4);
  763. raydium_i2c_pda_set_address(RAYDIUM_PDA_I2CREG, DISABLE);
  764. g_u8_i2c_mode = PDA2_MODE;
  765. LOGD(LOG_INFO, "[touch]Enable PDA2_MODE\n");
  766. break;
  767. }
  768. return 0;
  769. }
  770. const struct attribute_group raydium_attr_group = {
  771. .attrs = raydium_attributes
  772. };
  773. /*create sysfs for debug update firmware*/
  774. static int raydium_create_sysfs(struct i2c_client *client)
  775. {
  776. int ret = -1;
  777. ret = sysfs_create_group(&(client->dev.kobj), &raydium_attr_group);
  778. if (ret) {
  779. LOGD(LOG_ERR, "[touch]failed to register sysfs\n");
  780. sysfs_remove_group(&client->dev.kobj, &raydium_attr_group);
  781. ret = -EIO;
  782. } else {
  783. LOGD(LOG_DEBUG, "[touch]create raydium sysfs attr_group successful\n");
  784. }
  785. return ret;
  786. }
  787. static void raydium_release_sysfs(struct i2c_client *client)
  788. {
  789. sysfs_remove_group(&client->dev.kobj, &raydium_attr_group);
  790. }
  791. #endif /*end of CONFIG_RM_SYSFS_DEBUG*/
  792. #ifdef ESD_SOLUTION_EN
  793. int raydium_esd_check(void)
  794. {
  795. int i32_ret = 0;
  796. unsigned char u8_esd_status[MAX_TCH_STATUS_PACKET_SIZE];
  797. mutex_lock(&g_raydium_ts->lock);
  798. if (g_u8_i2c_mode == PDA2_MODE) {
  799. i32_ret = raydium_i2c_pda2_set_page(g_raydium_ts->client,
  800. g_raydium_ts->is_suspend,
  801. RAYDIUM_PDA2_PAGE_0);
  802. if (i32_ret < 0)
  803. goto exit;
  804. /*read esd status*/
  805. i32_ret = raydium_i2c_pda2_read(g_raydium_ts->client,
  806. RAYDIUM_PDA2_TCH_RPT_STATUS_ADDR,
  807. u8_esd_status, MAX_TCH_STATUS_PACKET_SIZE);
  808. if (i32_ret < 0) {
  809. LOGD(LOG_ERR, "[touch]%s: failed to read data: %d\n",
  810. __func__, __LINE__);
  811. goto exit;
  812. }
  813. if (u8_esd_status[POS_FW_STATE] != 0x1A &&
  814. u8_esd_status[POS_FW_STATE] != 0xAA) {
  815. if (g_u8_resetflag == true) {
  816. LOGD(LOG_ERR, "[touch]%s -> filter abnormal irq\n"
  817. , __func__);
  818. goto exit;
  819. }
  820. LOGD(LOG_ERR, "[touch]%s -> abnormal irq, FW state = 0x%x\n",
  821. __func__, u8_esd_status[POS_FW_STATE]);
  822. g_u8_resetflag = false;
  823. i32_ret = -1;
  824. goto exit;
  825. }
  826. g_u8_resetflag = false;
  827. }
  828. exit:
  829. mutex_unlock(&g_raydium_ts->lock);
  830. LOGD(LOG_INFO, "[touch]%s\n", __func__);
  831. return i32_ret;
  832. }
  833. #endif
  834. static int raydium_touch_report(unsigned char *p_u8_buf,
  835. unsigned char u8_points_amount)
  836. {
  837. unsigned char u8_i, u8_j, u8_offset = 0, u8_pt_id;
  838. signed short i16_wx, i16_wy;
  839. /* number of touch points */
  840. unsigned char u8_touch_count = 0;
  841. //DECLARE_BITMAP(ids, g_raydium_ts->u8_max_touchs);
  842. unsigned long *ids = NULL;
  843. ids = kzalloc(sizeof(*ids)*BITS_TO_LONGS(g_raydium_ts->u8_max_touchs), GFP_KERNEL);
  844. if (!ids)
  845. return -ENOMEM;
  846. bitmap_zero(ids, g_raydium_ts->u8_max_touchs);
  847. for (u8_i = 0; u8_i < (g_raydium_ts->u8_max_touchs * 2); u8_i++) {
  848. gst_slot[u8_i].need_update = 0;
  849. gst_slot[u8_i].pt_report_offset = 0;
  850. }
  851. /*Check incoming point info*/
  852. for (u8_i = 0; u8_i < u8_points_amount; u8_i++) {
  853. u8_pt_id = p_u8_buf[POS_PT_ID + u8_i * LEN_PT];
  854. /* Current*/
  855. for (u8_j = 0; u8_j < g_raydium_ts->u8_max_touchs; u8_j++) {
  856. if (u8_pt_id == gst_slot[u8_j].pt_id) {
  857. gst_slot[u8_j].need_update = 1;
  858. gst_slot[u8_j].pt_report_offset = u8_i;
  859. break;
  860. }
  861. }
  862. /* New coming*/
  863. if (u8_j == g_raydium_ts->u8_max_touchs) {
  864. for (u8_j = g_raydium_ts->u8_max_touchs;
  865. u8_j < (g_raydium_ts->u8_max_touchs * 2); u8_j++) {
  866. if (!gst_slot[u8_j].need_update) {
  867. gst_slot[u8_j].pt_id = u8_pt_id;
  868. gst_slot[u8_j].need_update = 1;
  869. gst_slot[u8_j].pt_report_offset = u8_i;
  870. LOGD(LOG_DEBUG, "[touch]x:%d,y:%d\n",
  871. p_u8_buf[POS_X_L + u8_offset] |
  872. p_u8_buf[POS_X_H + u8_offset] << 8,
  873. p_u8_buf[POS_Y_L + u8_offset] |
  874. p_u8_buf[POS_Y_H + u8_offset] << 8);
  875. break;
  876. }
  877. }
  878. }
  879. }
  880. /*Release slot with non-occupied point*/
  881. for (u8_i = 0; u8_i < g_raydium_ts->u8_max_touchs; u8_i++) {
  882. if (!gst_slot[u8_i].need_update) {
  883. input_mt_slot(g_raydium_ts->input_dev, u8_i);
  884. input_mt_report_slot_state(g_raydium_ts->input_dev,
  885. MT_TOOL_FINGER, false);
  886. gst_slot[u8_i].pt_id = 0xFF;
  887. gst_slot[u8_i].pt_report_offset = 0;
  888. gst_slot[u8_i].need_update = 0;
  889. }
  890. }
  891. /*Assign new one to non-occupied slot*/
  892. for (u8_i = g_raydium_ts->u8_max_touchs;
  893. u8_i < (g_raydium_ts->u8_max_touchs * 2); u8_i++) {
  894. if (gst_slot[u8_i].need_update) {
  895. for (u8_j = 0; u8_j < g_raydium_ts->u8_max_touchs; u8_j++) {
  896. if (!gst_slot[u8_j].need_update) {
  897. gst_slot[u8_j] = gst_slot[u8_i];
  898. gst_slot[u8_i] = gst_slot_init;
  899. break;
  900. }
  901. }
  902. } else {
  903. break;
  904. }
  905. }
  906. for (u8_i = 0; u8_i < g_raydium_ts->u8_max_touchs; u8_i++) {
  907. if (gst_slot[u8_i].need_update) {
  908. u8_offset = gst_slot[u8_i].pt_report_offset * LEN_PT;
  909. g_raydium_ts->x_pos[u8_i] = p_u8_buf[POS_X_L + u8_offset] |
  910. p_u8_buf[POS_X_H + u8_offset] << BYTE_SHIFT;
  911. g_raydium_ts->y_pos[u8_i] = p_u8_buf[POS_Y_L + u8_offset] |
  912. p_u8_buf[POS_Y_H + u8_offset] << BYTE_SHIFT;
  913. g_raydium_ts->pressure = p_u8_buf[POS_PRESSURE_L + u8_offset] |
  914. p_u8_buf[POS_PRESSURE_H + u8_offset] << BYTE_SHIFT;
  915. i16_wx = p_u8_buf[POS_WX_L + u8_offset] |
  916. p_u8_buf[POS_WX_H + u8_offset] << BYTE_SHIFT;
  917. i16_wy = p_u8_buf[POS_WY_L + u8_offset] |
  918. p_u8_buf[POS_WY_H + u8_offset] << BYTE_SHIFT;
  919. input_mt_slot(g_raydium_ts->input_dev, u8_i);
  920. input_mt_report_slot_state(g_raydium_ts->input_dev,
  921. MT_TOOL_FINGER, true);
  922. __set_bit(u8_i, ids);
  923. input_report_abs(g_raydium_ts->input_dev,
  924. ABS_MT_POSITION_X, g_raydium_ts->x_pos[u8_i]);
  925. input_report_abs(g_raydium_ts->input_dev,
  926. ABS_MT_POSITION_Y, g_raydium_ts->y_pos[u8_i]);
  927. input_report_abs(g_raydium_ts->input_dev,
  928. ABS_MT_PRESSURE, g_raydium_ts->pressure);
  929. input_report_abs(g_raydium_ts->input_dev,
  930. ABS_MT_TOUCH_MAJOR, max(i16_wx, i16_wy));
  931. input_report_abs(g_raydium_ts->input_dev,
  932. ABS_MT_TOUCH_MINOR, min(i16_wx, i16_wy));
  933. LOGD(LOG_DEBUG, "[touch:%d]x:%d,y:%d\n",
  934. u8_i,
  935. p_u8_buf[POS_X_L + u8_offset] |
  936. p_u8_buf[POS_X_H + u8_offset] << 8,
  937. p_u8_buf[POS_Y_L + u8_offset] |
  938. p_u8_buf[POS_Y_H + u8_offset] << 8);
  939. u8_touch_count++;
  940. }
  941. }
  942. input_report_key(g_raydium_ts->input_dev,
  943. BTN_TOUCH, u8_touch_count > 0);
  944. input_report_key(g_raydium_ts->input_dev,
  945. BTN_TOOL_FINGER, u8_touch_count > 0);
  946. for (u8_i = 0; u8_i < g_raydium_ts->u8_max_touchs; u8_i++) {
  947. if (test_bit(u8_i, ids))
  948. continue;
  949. input_mt_slot(g_raydium_ts->input_dev, u8_i);
  950. input_mt_report_slot_state(g_raydium_ts->input_dev,
  951. MT_TOOL_FINGER, false);
  952. }
  953. input_sync(g_raydium_ts->input_dev);
  954. kfree(ids);
  955. return 0;
  956. }
  957. int raydium_read_touchdata(unsigned char *p_u8_tp_status, unsigned char *p_u8_buf)
  958. {
  959. int i32_ret = 0;
  960. unsigned char u8_points_amount;
  961. static unsigned char u8_seq_no;
  962. unsigned char u8_retry;
  963. unsigned char u8_read_size;
  964. unsigned char u8_read_buf[MAX_REPORT_PACKET_SIZE];
  965. u8_retry = 100;
  966. mutex_lock(&g_raydium_ts->lock);
  967. while (u8_retry != 0) {
  968. i32_ret = raydium_i2c_pda2_set_page(g_raydium_ts->client,
  969. g_raydium_ts->is_suspend, RAYDIUM_PDA2_PAGE_0);
  970. if (i32_ret < 0) {
  971. msleep(250);
  972. u8_retry--;
  973. } else
  974. break;
  975. }
  976. if (u8_retry == 0) {
  977. LOGD(LOG_ERR, "[touch]%s: failed to set page\n", __func__);
  978. goto reset_error;
  979. }
  980. memset(u8_read_buf, 0, MAX_REPORT_PACKET_SIZE);
  981. memset(p_u8_buf, 0, MAX_REPORT_PACKET_SIZE);
  982. memset(p_u8_tp_status, 0, MAX_TCH_STATUS_PACKET_SIZE);
  983. u8_read_size = 4 + MAX_TOUCH_NUM * LEN_PT + 1;
  984. /*read touch point information*/
  985. i32_ret = raydium_i2c_pda2_read(g_raydium_ts->client,
  986. RAYDIUM_PDA2_TCH_RPT_STATUS_ADDR,
  987. u8_read_buf, u8_read_size);
  988. if (i32_ret < 0) {
  989. LOGD(LOG_ERR, "[touch]%s: failed to read data: %d\n",
  990. __func__, __LINE__);
  991. goto exit_error;
  992. }
  993. memcpy(p_u8_tp_status, &u8_read_buf[0], MAX_TCH_STATUS_PACKET_SIZE);
  994. #ifdef ESD_SOLUTION_EN
  995. if (p_u8_tp_status[POS_FW_STATE] != 0x1A &&
  996. p_u8_tp_status[POS_FW_STATE] != 0xAA) {
  997. if (g_u8_resetflag == true) {
  998. LOGD(LOG_ERR, "[touch]%s -> filter irq, FW state = 0x%x\n",
  999. __func__, p_u8_tp_status[POS_FW_STATE]);
  1000. i32_ret = -1;
  1001. g_u8_resetflag = false;
  1002. goto exit_error;
  1003. }
  1004. LOGD(LOG_ERR, "[touch]%s -> abnormal irq, FW state = 0x%x\n",
  1005. __func__, p_u8_tp_status[POS_FW_STATE]);
  1006. i32_ret = -1;
  1007. goto reset_error;
  1008. }
  1009. #endif
  1010. /* inform IC to prepare next report*/
  1011. if (u8_seq_no == p_u8_tp_status[POS_SEQ]) {
  1012. p_u8_tp_status[POS_SEQ] = 0;
  1013. i32_ret = raydium_i2c_pda2_write(g_raydium_ts->client,
  1014. RAYDIUM_PDA2_TCH_RPT_STATUS_ADDR, p_u8_tp_status, 1);
  1015. if (i32_ret < 0) {
  1016. LOGD(LOG_ERR, "[touch]%s: write data failed: %d\n", __func__, i32_ret);
  1017. goto exit_error;
  1018. }
  1019. LOGD(LOG_DEBUG, "[touch]%s -> report not updated.\n", __func__);
  1020. goto exit_error;
  1021. }
  1022. u8_seq_no = p_u8_tp_status[POS_SEQ];
  1023. p_u8_tp_status[POS_SEQ] = 0;
  1024. i32_ret = raydium_i2c_pda2_write(g_raydium_ts->client,
  1025. RAYDIUM_PDA2_TCH_RPT_STATUS_ADDR, p_u8_tp_status, 1);
  1026. if (i32_ret < 0) {
  1027. LOGD(LOG_ERR, "[touch]%s: write data failed: %d\n", __func__, i32_ret);
  1028. goto exit_error;
  1029. }
  1030. u8_points_amount = p_u8_tp_status[POS_PT_AMOUNT];
  1031. if (u8_points_amount > MAX_TOUCH_NUM)
  1032. goto exit_error;
  1033. memcpy(p_u8_buf, &u8_read_buf[4], u8_points_amount * LEN_PT);
  1034. raydium_touch_report(p_u8_buf, u8_points_amount);
  1035. exit_error:
  1036. mutex_unlock(&g_raydium_ts->lock);
  1037. return i32_ret;
  1038. reset_error:
  1039. mutex_unlock(&g_raydium_ts->lock);
  1040. #ifdef ESD_SOLUTION_EN
  1041. u8_retry = 3;
  1042. while (u8_retry != 0) {
  1043. i32_ret = raydium_hw_reset_fun(g_raydium_ts->client);
  1044. LOGD(LOG_ERR, "[touch]%s: HW reset\n", __func__);
  1045. if (i32_ret < 0) {
  1046. msleep(100);
  1047. u8_retry--;
  1048. } else
  1049. break;
  1050. }
  1051. #endif
  1052. return i32_ret;
  1053. }
  1054. static void raydium_work_handler(struct work_struct *work)
  1055. {
  1056. int i32_ret = 0;
  1057. unsigned char u8_tp_status[MAX_TCH_STATUS_PACKET_SIZE] = {0};
  1058. unsigned char u8_buf[MAX_REPORT_PACKET_SIZE] = {0};
  1059. #ifdef GESTURE_EN
  1060. unsigned char u8_i;
  1061. LOGD(LOG_DEBUG, "[touch]ts->blank:%x, g_u8_i2c_mode:%x\n",
  1062. g_raydium_ts->blank, g_u8_i2c_mode);
  1063. LOGD(LOG_DEBUG, "[touch]u8_tp_status:%x, g_raydium_ts->is_palm:%x\n",
  1064. u8_tp_status[POS_GES_STATUS], g_raydium_ts->is_palm);
  1065. if (g_u8_i2c_mode == PDA2_MODE) {
  1066. i32_ret = raydium_read_touchdata(u8_tp_status, u8_buf);
  1067. if (i32_ret < 0) {
  1068. LOGD(LOG_ERR, "[touch]%s, read_touchdata error, ret:%d\n",
  1069. __func__, i32_ret);
  1070. return;
  1071. }
  1072. }
  1073. #if defined(CONFIG_PANEL_NOTIFIER)
  1074. if (g_raydium_ts->blank == DRM_PANEL_EVENT_BLANK_LP ||
  1075. g_raydium_ts->blank == DRM_PANEL_EVENT_BLANK || g_raydium_ts->fb_state == FB_OFF) {
  1076. #else
  1077. if (g_raydium_ts->blank == DRM_PANEL_BLANK_LP ||
  1078. g_raydium_ts->blank == DRM_PANEL_BLANK_POWERDOWN || g_raydium_ts->fb_state == FB_OFF) {
  1079. #endif
  1080. LOGD(LOG_DEBUG, "[touch] elseif u8_tp_status:%x\n", u8_tp_status[POS_GES_STATUS]);
  1081. /*need check small area*/
  1082. /*if (u8_tp_status[POS_GES_STATUS] == RAD_WAKE_UP */
  1083. /*&& g_u8_wakeup_flag == false) { */
  1084. if (u8_tp_status[POS_GES_STATUS] == 0) {
  1085. input_report_key(g_raydium_ts->input_dev, KEY_WAKEUP, true);
  1086. usleep_range(9500, 10500);
  1087. input_sync(g_raydium_ts->input_dev);
  1088. input_report_key(g_raydium_ts->input_dev, KEY_WAKEUP, false);
  1089. input_sync(g_raydium_ts->input_dev);
  1090. LOGD(LOG_DEBUG, "[touch]display wake up with g_u8_resetflag true\n");
  1091. /*goto exit;*/
  1092. }
  1093. }
  1094. /*when display on can use palm to suspend*/
  1095. #if defined(CONFIG_PANEL_NOTIFIER)
  1096. else if (g_raydium_ts->blank == DRM_PANEL_EVENT_UNBLANK) {
  1097. #else
  1098. else if (g_raydium_ts->blank == DRM_PANEL_BLANK_UNBLANK) {
  1099. #endif
  1100. if (u8_tp_status[POS_GES_STATUS] == RAD_PALM_ENABLE) {
  1101. if (g_raydium_ts->is_palm == 0) {
  1102. /* release all touches*/
  1103. for (u8_i = 0; u8_i < g_raydium_ts->u8_max_touchs;
  1104. u8_i++) {
  1105. input_mt_slot(g_raydium_ts->input_dev,
  1106. u8_i);
  1107. input_mt_report_slot_state(
  1108. g_raydium_ts->input_dev,
  1109. MT_TOOL_FINGER, false);
  1110. }
  1111. input_mt_report_pointer_emulation(
  1112. g_raydium_ts->input_dev,
  1113. false);
  1114. /*press sleep key*/
  1115. input_report_key(g_raydium_ts->input_dev,
  1116. KEY_SLEEP, true);
  1117. input_sync(g_raydium_ts->input_dev);
  1118. LOGD(LOG_INFO, "[touch]palm_status = %d.\n",
  1119. u8_tp_status[POS_GES_STATUS]);
  1120. g_raydium_ts->is_palm = 1;
  1121. /*goto exit;*/
  1122. }
  1123. } else if ((u8_tp_status[POS_GES_STATUS]
  1124. == RAD_PALM_DISABLE)
  1125. && (g_raydium_ts->is_palm == 1)) {
  1126. LOGD(LOG_INFO, "[touch]leave palm mode.\n");
  1127. input_report_key(g_raydium_ts->input_dev,
  1128. KEY_SLEEP, false);
  1129. input_sync(g_raydium_ts->input_dev);
  1130. /*raydium_irq_control(raydium_ts, DISABLE);*/
  1131. g_raydium_ts->is_palm = 0;
  1132. /*goto exit;*/
  1133. }
  1134. }
  1135. #else
  1136. if (g_u8_i2c_mode == PDA2_MODE) {
  1137. i32_ret = raydium_read_touchdata(u8_tp_status, u8_buf);
  1138. if (i32_ret < 0) {
  1139. LOGD(LOG_ERR, "[touch]%s, read_touchdata error, ret:%d\n",
  1140. __func__, i32_ret);
  1141. }
  1142. }
  1143. #endif
  1144. }
  1145. /*The raydium device will signal the host about TRIGGER_FALLING.
  1146. *Processed when the interrupt is asserted.
  1147. */
  1148. static irqreturn_t raydium_ts_interrupt(int irq, void *dev_id)
  1149. {
  1150. bool result = false;
  1151. LOGD(LOG_DEBUG, "[touch]%s\n", __func__);
  1152. /*For bootloader wrt/erase flash and software reset interrupt*/
  1153. if ((g_u8_raydium_flag & ENG_MODE) != 0) {
  1154. LOGD(LOG_INFO, "[touch]RAD_ENG_MODE\n");
  1155. g_u8_raydium_flag |= INT_FLAG;
  1156. } else {
  1157. if (!work_pending(&g_raydium_ts->work)) {
  1158. /* Clear interrupts*/
  1159. if (g_raydium_ts->workqueue) {
  1160. result = queue_work(g_raydium_ts->workqueue,
  1161. &g_raydium_ts->work);
  1162. }
  1163. if (!result) {
  1164. /*queue_work fail*/
  1165. LOGD(LOG_ERR, "[touch]queue_work fail.\n");
  1166. }
  1167. } else {
  1168. /*work pending*/
  1169. mutex_lock(&g_raydium_ts->lock);
  1170. if (raydium_i2c_pda2_set_page(g_raydium_ts->client,
  1171. g_raydium_ts->is_suspend,
  1172. RAYDIUM_PDA2_PAGE_0) < 0) {
  1173. LOGD(LOG_ERR, "[touch]%s: failed to set page in work_pending\n",
  1174. __func__);
  1175. }
  1176. mutex_unlock(&g_raydium_ts->lock);
  1177. LOGD(LOG_DEBUG, "[touch]work_pending\n");
  1178. }
  1179. }
  1180. return IRQ_HANDLED;
  1181. }
  1182. static int raydium_check_i2c_ready(unsigned short *u16_i2c_data)
  1183. {
  1184. unsigned char u8_buf[4];
  1185. int i32_ret = ERROR;
  1186. mutex_lock(&g_raydium_ts->lock);
  1187. if (g_u8_i2c_mode == PDA2_MODE) {
  1188. i32_ret = handle_i2c_pda_read(g_raydium_ts->client,
  1189. RAYDIUM_CHK_I2C_CMD, u8_buf, 4);
  1190. if (i32_ret < 0)
  1191. goto exit_error;
  1192. if (u8_buf[3] != 0xF3) {
  1193. LOGD(LOG_ERR, "[touch]PDA2 read i2c fail\n");
  1194. g_u8_i2c_mode = PDA_MODE;
  1195. i32_ret = handle_i2c_pda_read(g_raydium_ts->client,
  1196. RAYDIUM_CHK_I2C_CMD, u8_buf, 4);
  1197. if (i32_ret < 0)
  1198. goto exit_error;
  1199. }
  1200. } else {
  1201. i32_ret = handle_i2c_pda_read(g_raydium_ts->client,
  1202. RAYDIUM_CHK_I2C_CMD, u8_buf, 4);
  1203. if (i32_ret < 0)
  1204. goto exit_error;
  1205. }
  1206. *u16_i2c_data = u8_buf[3] << 8 | u8_buf[2];
  1207. LOGD(LOG_DEBUG, "[touch]RAD check I2C : 0x%02X%02X\n", u8_buf[3], u8_buf[2]);
  1208. exit_error:
  1209. mutex_unlock(&g_raydium_ts->lock);
  1210. return i32_ret;
  1211. }
  1212. #if defined(CONFIG_PM)
  1213. static void raydium_ts_do_suspend(void)
  1214. {
  1215. unsigned char u8_i = 0;
  1216. LOGD(LOG_INFO, "[touch]%s.\n", __func__);
  1217. if (g_u8_raw_data_type == 0)
  1218. g_u8_resetflag = false;
  1219. if (g_raydium_ts->is_suspend == 1 && (pm_suspend_via_firmware() == false)) {
  1220. LOGD(LOG_WARNING, "[touch]Already in suspend state\n");
  1221. return;
  1222. }
  1223. /*#ifndef GESTURE_EN*/
  1224. raydium_irq_control(DISABLE);
  1225. /*#endif*/
  1226. /*clear workqueue*/
  1227. if (!cancel_work_sync(&g_raydium_ts->work))
  1228. LOGD(LOG_DEBUG, "[touch]workqueue is empty!\n");
  1229. /* release all touches */
  1230. for (u8_i = 0; u8_i < g_raydium_ts->u8_max_touchs; u8_i++) {
  1231. input_mt_slot(g_raydium_ts->input_dev, u8_i);
  1232. input_mt_report_slot_state(g_raydium_ts->input_dev,
  1233. MT_TOOL_FINGER,
  1234. false);
  1235. }
  1236. input_mt_report_pointer_emulation(g_raydium_ts->input_dev, false);
  1237. input_sync(g_raydium_ts->input_dev);
  1238. #ifdef GESTURE_EN
  1239. if (pm_suspend_via_firmware() == false)
  1240. {
  1241. if (device_may_wakeup(&g_raydium_ts->client->dev)) {
  1242. LOGD(LOG_INFO, "[touch]Device may wakeup\n");
  1243. if (!enable_irq_wake(g_raydium_ts->irq))
  1244. g_raydium_ts->irq_wake = true;
  1245. } else {
  1246. LOGD(LOG_INFO, "[touch]Device not wakeup\n");
  1247. }
  1248. raydium_irq_control(ENABLE);
  1249. }
  1250. #endif
  1251. g_raydium_ts->is_suspend = 1;
  1252. }
  1253. static void raydium_ts_do_resume(void)
  1254. {
  1255. #ifdef ESD_SOLUTION_EN
  1256. int i32_ret = 0;
  1257. unsigned char u8_retry = 0;
  1258. #endif
  1259. LOGD(LOG_INFO, "[touch]%s, %d.\n", __func__, g_raydium_ts->is_suspend);
  1260. if (g_raydium_ts->is_suspend == 0) {
  1261. LOGD(LOG_WARNING, "[touch]Already in resume state\n");
  1262. return;
  1263. }
  1264. /* clear interrupts*/
  1265. mutex_lock(&g_raydium_ts->lock);
  1266. if (raydium_i2c_pda2_set_page(g_raydium_ts->client,
  1267. g_raydium_ts->is_suspend, RAYDIUM_PDA2_PAGE_0) < 0) {
  1268. LOGD(LOG_ERR, "[touch]%s: failed to set page\n", __func__);
  1269. mutex_unlock(&g_raydium_ts->lock);
  1270. return;
  1271. }
  1272. mutex_unlock(&g_raydium_ts->lock);
  1273. /* clear workqueue*/
  1274. if (!cancel_work_sync(&g_raydium_ts->work))
  1275. LOGD(LOG_DEBUG, "[ raydium ]workqueue is empty!\n");
  1276. #ifdef ESD_SOLUTION_EN
  1277. if (g_u8_checkflag == true) {
  1278. i32_ret = raydium_esd_check();
  1279. if (i32_ret < 0) {
  1280. u8_retry = 3;
  1281. while (u8_retry != 0) {
  1282. i32_ret = raydium_hw_reset_fun(g_raydium_ts->client);
  1283. if (i32_ret < 0) {
  1284. msleep(100);
  1285. u8_retry--;
  1286. } else
  1287. break;
  1288. }
  1289. }
  1290. g_u8_checkflag = false;
  1291. }
  1292. #endif
  1293. raydium_irq_control(ENABLE);
  1294. #ifdef GESTURE_EN
  1295. if (device_may_wakeup(&g_raydium_ts->client->dev)) {
  1296. LOGD(LOG_INFO, "[touch]Device may wakeup\n");
  1297. if (g_raydium_ts->irq_wake) {
  1298. disable_irq_wake(g_raydium_ts->irq);
  1299. g_raydium_ts->irq_wake = false;
  1300. }
  1301. } else
  1302. LOGD(LOG_INFO, "[touch]Device not wakeup\n");
  1303. #endif
  1304. g_raydium_ts->is_suspend = 0;
  1305. }
  1306. static int raydium_ts_suspend(struct device *dev)
  1307. {
  1308. raydium_ts_do_suspend();
  1309. return 0;
  1310. }
  1311. static int raydium_ts_resume(struct device *dev)
  1312. {
  1313. raydium_ts_do_resume();
  1314. return 0;
  1315. }
  1316. static const struct dev_pm_ops raydium_ts_pm_ops = {
  1317. #if (!defined(CONFIG_FB) && !defined(CONFIG_HAS_EARLYSUSPEND))
  1318. .suspend = raydium_ts_suspend,
  1319. .resume = raydium_ts_resume,
  1320. #endif /*end of CONFIG_PM*/
  1321. };
  1322. /*used for touch lock feature*/
  1323. static int raydium_ts_open(struct input_dev *input_dev)
  1324. {
  1325. //int i32_ret = 0;
  1326. LOGD(LOG_DEBUG, "[touch]%s()+\n", __func__);
  1327. LOGD(LOG_DEBUG, "[touch]ts->blank:%x\n", g_raydium_ts->blank);
  1328. if (g_raydium_ts->is_sleep == 1) {
  1329. mutex_lock(&g_raydium_ts->lock);
  1330. if (gpio_is_valid(g_raydium_ts->rst_gpio)) {
  1331. g_u8_resetflag = true;
  1332. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  1333. gpio_set_value(g_raydium_ts->rst_gpio, 0);
  1334. msleep(RAYDIUM_RESET_INTERVAL_MSEC);/*5ms*/
  1335. gpio_set_value(g_raydium_ts->rst_gpio, 1);
  1336. msleep(RAYDIUM_RESET_DELAY_MSEC);/*100ms*/
  1337. g_u8_i2c_mode = PDA2_MODE;
  1338. }
  1339. mutex_unlock(&g_raydium_ts->lock);
  1340. raydium_irq_control(ENABLE);
  1341. g_raydium_ts->is_sleep = 0;
  1342. LOGD(LOG_INFO, "[touch]disable touch lock.\n");
  1343. }
  1344. //return i32_ret;
  1345. return 0;
  1346. }
  1347. static void raydium_ts_close(struct input_dev *input_dev)
  1348. {
  1349. int i32_ret = 0;
  1350. unsigned char u8_i = 0;
  1351. unsigned char u8_wbuffer[1];
  1352. LOGD(LOG_INFO, "[touch]%s()+\n", __func__);
  1353. if (g_raydium_ts->is_sleep == 1) {
  1354. LOGD(LOG_INFO, "[touch]touch lock already enabled.\n");
  1355. return;
  1356. }
  1357. raydium_irq_control(DISABLE);
  1358. for (u8_i = 0; u8_i < g_raydium_ts->u8_max_touchs; u8_i++) {
  1359. input_mt_slot(g_raydium_ts->input_dev, u8_i);
  1360. input_mt_report_slot_state(g_raydium_ts->input_dev,
  1361. MT_TOOL_FINGER,
  1362. false);
  1363. }
  1364. input_mt_report_pointer_emulation(g_raydium_ts->input_dev, false);
  1365. input_sync(g_raydium_ts->input_dev);
  1366. mutex_lock(&g_raydium_ts->lock);
  1367. i32_ret = raydium_i2c_pda2_set_page(g_raydium_ts->client,
  1368. g_raydium_ts->is_suspend, RAYDIUM_PDA2_PAGE_0);
  1369. if (i32_ret < 0) {
  1370. LOGD(LOG_ERR, "[touch]ret:%d\n", i32_ret);
  1371. goto exit_i2c_error;
  1372. }
  1373. u8_wbuffer[0] = RAYDIUM_HOST_CMD_PWR_SLEEP;
  1374. i32_ret = raydium_i2c_pda2_write(g_raydium_ts->client,
  1375. RAYDIUM_PDA2_HOST_CMD_ADDR,
  1376. u8_wbuffer,
  1377. 1);
  1378. if (i32_ret < 0) {
  1379. LOGD(LOG_ERR, "[touch]ret:%d\n", i32_ret);
  1380. goto exit_i2c_error;
  1381. }
  1382. mutex_unlock(&g_raydium_ts->lock);
  1383. g_raydium_ts->is_sleep = 1;
  1384. LOGD(LOG_INFO, "[touch]enable touch lock.\n");
  1385. return;
  1386. exit_i2c_error:
  1387. mutex_unlock(&g_raydium_ts->lock);
  1388. raydium_irq_control(ENABLE);
  1389. }
  1390. #else
  1391. static int raydium_ts_suspend(struct device *dev)
  1392. {
  1393. return 0;
  1394. }
  1395. static int raydium_ts_resume(struct device *dev)
  1396. {
  1397. return 0;
  1398. }
  1399. #endif /*end of CONFIG_FB*/
  1400. #if defined(CONFIG_PANEL_NOTIFIER)
  1401. static void panel_event_notifier_callback(enum panel_event_notifier_tag tag,
  1402. struct panel_event_notification *notification, void *client_data)
  1403. {
  1404. struct raydium_ts_data *g_raydium_ts = client_data;
  1405. if(!notification)
  1406. {
  1407. LOGD(LOG_INFO, "%s: Invalid notification\n", __func__);
  1408. return ;
  1409. }
  1410. LOGD(LOG_INFO, "%s: DRM notifier called!\n", __func__);
  1411. LOGD(LOG_INFO, "%s: DRM event:%d fb_state %d ",
  1412. __func__, notification->notif_type, g_raydium_ts->fb_state);
  1413. LOGD(LOG_INFO, "%s: DRM Power - %d- FB state %d ",
  1414. __func__, (notification->notif_type == DRM_PANEL_EVENT_UNBLANK)?"UP":"DOWN", g_raydium_ts->fb_state);
  1415. if (notification->notif_type == DRM_PANEL_EVENT_UNBLANK) {
  1416. LOGD(LOG_INFO, "%s: UNBLANK!\n", __func__);
  1417. if (notification->notif_data.early_trigger) {
  1418. LOGD(LOG_INFO, "%s: resume: event = %d not care\n",
  1419. __func__, notification->notif_type);
  1420. } else {
  1421. LOGD(LOG_INFO, "%s: Resume notifier called!\n",
  1422. __func__);
  1423. #ifdef GESTURE_EN
  1424. /* clear palm status */
  1425. g_raydium_ts->is_palm = 0;
  1426. #endif
  1427. #if defined(CONFIG_PM)
  1428. raydium_ts_resume(&g_raydium_ts->client->dev);
  1429. #endif
  1430. g_raydium_ts->fb_state = FB_ON;
  1431. LOGD(LOG_INFO, "%s: Resume notified!\n", __func__);
  1432. }
  1433. } else if (notification->notif_type == DRM_PANEL_EVENT_BLANK_LP ||
  1434. notification->notif_type == DRM_PANEL_EVENT_BLANK) {
  1435. if (notification->notif_type == DRM_PANEL_EVENT_BLANK_LP) {
  1436. LOGD(LOG_INFO, "%s: LOWPOWER!\n", __func__);
  1437. } else {
  1438. LOGD(LOG_INFO, "%s: BLANK!\n", __func__);
  1439. }
  1440. if (notification->notif_data.early_trigger) {
  1441. LOGD(LOG_INFO, "%s: Suspend notifier called!\n",
  1442. __func__);
  1443. #ifdef GESTURE_EN
  1444. /* clear palm status */
  1445. g_raydium_ts->is_palm = 0;
  1446. #endif
  1447. #if defined(CONFIG_PM)
  1448. raydium_ts_suspend(&g_raydium_ts->client->dev);
  1449. #endif
  1450. g_raydium_ts->fb_state = FB_OFF;
  1451. LOGD(LOG_INFO, "%s: Suspend notified!\n", __func__);
  1452. } else {
  1453. LOGD(LOG_INFO, "%s: suspend: event = %d not care\n",
  1454. __func__, notification->notif_type);
  1455. }
  1456. } else {
  1457. LOGD(LOG_INFO, "%s: Undefined notif type (%d) do not need process\n",
  1458. __func__, notification->notif_type);
  1459. }
  1460. return ;
  1461. }
  1462. /*******************************************************************************
  1463. * FUNCTION: raydium_setup_drm_notifier
  1464. *
  1465. * SUMMARY: Set up call back function into drm notifier.
  1466. *
  1467. * PARAMETERS:
  1468. * g_raydium_ts - pointer to core data
  1469. *******************************************************************************/
  1470. static void raydium_setup_panel_notifier(struct raydium_ts_data *g_raydium_ts)
  1471. {
  1472. void *cookie = NULL;
  1473. if (!active_panel)
  1474. LOGD(LOG_ERR, "[touch]%s: Active panel not registered!\n", __func__);
  1475. cookie = panel_event_notifier_register(PANEL_EVENT_NOTIFICATION_PRIMARY,
  1476. PANEL_EVENT_NOTIFIER_CLIENT_PRIMARY_TOUCH,
  1477. active_panel,&panel_event_notifier_callback, g_raydium_ts);
  1478. g_raydium_ts->entry = cookie;
  1479. }
  1480. #elif defined(CONFIG_DRM)
  1481. /*******************************************************************************
  1482. * FUNCTION: drm_notifier_callback
  1483. *
  1484. * SUMMARY: Call back function for DRM notifier to allow to call
  1485. * resume/suspend attention list.
  1486. *
  1487. * RETURN:
  1488. * 0 = success
  1489. *
  1490. * PARAMETERS:
  1491. * self - pointer to notifier_block structure
  1492. * event - event type of fb notifier
  1493. * data - pointer to fb_event structure
  1494. ******************************************************************************/
  1495. static int drm_notifier_callback(struct notifier_block *self,
  1496. unsigned long event, void *data)
  1497. {
  1498. struct raydium_ts_data *g_raydium_ts =
  1499. container_of(self, struct raydium_ts_data, fb_notif);
  1500. struct drm_panel_notifier *evdata = data;
  1501. int *blank;
  1502. LOGD(LOG_INFO, "%s: DRM notifier called!\n", __func__);
  1503. if (!evdata)
  1504. goto exit;
  1505. if (!(event == DRM_PANEL_EARLY_EVENT_BLANK ||
  1506. event == DRM_PANEL_EVENT_BLANK)) {
  1507. LOGD(LOG_INFO, "%s: Event(%lu) do not need process\n",
  1508. __func__, event);
  1509. goto exit;
  1510. }
  1511. blank = evdata->data;
  1512. g_raydium_ts->blank = (*blank);
  1513. LOGD(LOG_INFO, "%s: DRM event:%lu,blank:%d fb_state %d ",
  1514. __func__, event, *blank, g_raydium_ts->fb_state);
  1515. LOGD(LOG_INFO, "%s: DRM Power - %s - FB state %d ",
  1516. __func__, (*blank == DRM_PANEL_BLANK_UNBLANK)?"UP":"DOWN", g_raydium_ts->fb_state);
  1517. if (*blank == DRM_PANEL_BLANK_UNBLANK) {
  1518. LOGD(LOG_INFO, "%s: UNBLANK!\n", __func__);
  1519. if (event == DRM_PANEL_EARLY_EVENT_BLANK) {
  1520. LOGD(LOG_INFO, "%s: resume: event = %lu, not care\n",
  1521. __func__, event);
  1522. } else if (event == DRM_PANEL_EVENT_BLANK) {
  1523. if (g_raydium_ts->fb_state != FB_ON) {
  1524. LOGD(LOG_INFO, "%s: Resume notifier called!\n",
  1525. __func__);
  1526. #ifdef GESTURE_EN
  1527. /* clear palm status */
  1528. g_raydium_ts->is_palm = 0;
  1529. #endif
  1530. #if defined(CONFIG_PM)
  1531. raydium_ts_resume(&g_raydium_ts->client->dev);
  1532. #endif
  1533. g_raydium_ts->fb_state = FB_ON;
  1534. LOGD(LOG_INFO, "%s: Resume notified!\n", __func__);
  1535. }
  1536. }
  1537. } else if (*blank == DRM_PANEL_BLANK_LP || *blank == DRM_PANEL_BLANK_POWERDOWN
  1538. || *blank == DRM_PANEL_BLANK_FPS_CHANGE) {
  1539. LOGD(LOG_INFO, "%s: LOWPOWER!\n", __func__);
  1540. if (event == DRM_PANEL_EARLY_EVENT_BLANK) {
  1541. if (g_raydium_ts->fb_state != FB_OFF) {
  1542. LOGD(LOG_INFO, "%s: Suspend notifier called!\n",
  1543. __func__);
  1544. #ifdef GESTURE_EN
  1545. /* clear palm status */
  1546. g_raydium_ts->is_palm = 0;
  1547. #endif
  1548. #if defined(CONFIG_PM)
  1549. raydium_ts_suspend(&g_raydium_ts->client->dev);
  1550. #endif
  1551. g_raydium_ts->fb_state = FB_OFF;
  1552. LOGD(LOG_INFO, "%s: Suspend notified!\n", __func__);
  1553. }
  1554. } else if (event == DRM_PANEL_EVENT_BLANK) {
  1555. LOGD(LOG_INFO, "%s: suspend: event = %lu, not care\n",
  1556. __func__, event);
  1557. }
  1558. } else {
  1559. LOGD(LOG_INFO, "%s: DRM BLANK(%d) do not need process\n",
  1560. __func__, *blank);
  1561. }
  1562. exit:
  1563. return 0;
  1564. }
  1565. static void raydium_setup_drm_unregister_notifier(void)
  1566. {
  1567. if (active_panel && drm_panel_notifier_unregister(active_panel,
  1568. &g_raydium_ts->fb_notif) < 0)
  1569. LOGD(LOG_ERR, "[touch]%s: DRM UnRegister notifier failed!\n", __func__);
  1570. }
  1571. /*******************************************************************************
  1572. * FUNCTION: raydium_setup_drm_notifier
  1573. *
  1574. * SUMMARY: Set up call back function into drm notifier.
  1575. *
  1576. * PARAMETERS:
  1577. * g_raydium_ts - pointer to core data
  1578. *******************************************************************************/
  1579. static void raydium_setup_drm_notifier(struct raydium_ts_data *g_raydium_ts)
  1580. {
  1581. g_raydium_ts->fb_state = FB_ON;
  1582. g_raydium_ts->fb_notif.notifier_call = drm_notifier_callback;
  1583. LOGD(LOG_INFO, "[touch]%s: Setting up drm notifier\n", __func__);
  1584. if (!active_panel)
  1585. LOGD(LOG_ERR, "[touch]%s: Active panel not registered!\n", __func__);
  1586. if (active_panel && drm_panel_notifier_register(active_panel,
  1587. &g_raydium_ts->fb_notif) < 0)
  1588. LOGD(LOG_ERR, "[touch]%s: Register notifier failed!\n", __func__);
  1589. }
  1590. #endif /*end of CONFIG_DRM*/
  1591. /*******************************************************************************
  1592. * FUNCTION: raydium_setup_drm_notifier
  1593. *
  1594. * SUMMARY: Set up call back function into fb notifier.
  1595. *
  1596. * PARAMETERS:
  1597. * g_raydium_ts - pointer to core data
  1598. *******************************************************************************/
  1599. #if defined(CONFIG_FB)
  1600. static int fb_notifier_callback(struct notifier_block *self,
  1601. unsigned long event,
  1602. void *data)
  1603. {
  1604. struct fb_event *evdata = data;
  1605. int *blank;
  1606. if (evdata && evdata->data && event == FB_EVENT_BLANK &&
  1607. g_raydium_ts && g_raydium_ts->client) {
  1608. blank = evdata->data;
  1609. g_raydium_ts->blank = (*blank);
  1610. switch (*blank) {
  1611. /*screen on*/
  1612. case FB_BLANK_UNBLANK:
  1613. LOGD(LOG_INFO, "[touch]FB_BLANK_UNBLANK\n");
  1614. #ifdef GESTURE_EN
  1615. /* clear palm status */
  1616. g_raydium_ts->is_palm = 0;
  1617. #endif
  1618. raydium_ts_resume(&g_raydium_ts->client->dev);
  1619. break;
  1620. /*screen off*/
  1621. case FB_BLANK_POWERDOWN:
  1622. LOGD(LOG_INFO, "[touch]FB_BLANK_POWERDOWN\n");
  1623. #ifdef GESTURE_EN
  1624. /* clear palm status */
  1625. g_raydium_ts->is_palm = 0;
  1626. #endif
  1627. raydium_ts_suspend(&g_raydium_ts->client->dev);
  1628. break;
  1629. /*ambient mode*/
  1630. case FB_BLANK_VSYNC_SUSPEND:
  1631. LOGD(LOG_INFO, "[touch]FB_BLANK_VSYNC_SUSPEND\n");
  1632. #ifdef GESTURE_EN
  1633. /* clear palm status */
  1634. g_raydium_ts->is_palm = 0;
  1635. #endif
  1636. raydium_ts_suspend(&g_raydium_ts->client->dev);
  1637. break;
  1638. default:
  1639. break;
  1640. }
  1641. }
  1642. return 0;
  1643. }
  1644. static void raydium_register_notifier(void)
  1645. {
  1646. memset(&g_raydium_ts->fb_notif, 0, sizeof(g_raydium_ts->fb_notif));
  1647. g_raydium_ts->fb_notif.notifier_call = fb_notifier_callback;
  1648. /* register on the fb notifier and work with fb*/
  1649. if (fb_register_client(&g_raydium_ts->fb_notif))
  1650. LOGD(LOG_ERR, "[touch]register notifier failed\n");
  1651. }
  1652. static void raydium_unregister_notifier(void)
  1653. {
  1654. fb_unregister_client(&g_raydium_ts->fb_notif);
  1655. }
  1656. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  1657. static void raydium_ts_early_suspend(struct early_suspend *handler)
  1658. {
  1659. raydium_ts_do_suspend();
  1660. }
  1661. static void raydium_ts_late_resume(struct early_suspend *handler)
  1662. {
  1663. raydium_ts_do_resume();
  1664. }
  1665. #endif /*end of CONFIG_FB*/
  1666. #ifdef CONFIG_OF
  1667. static int raydium_get_dt_coords(struct device *dev, char *name,
  1668. struct raydium_ts_platform_data *pdata)
  1669. {
  1670. u32 coords[COORDS_ARR_SIZE];
  1671. struct property *prop;
  1672. struct device_node *np = dev->of_node;
  1673. int coords_size, rc;
  1674. prop = of_find_property(np, name, NULL);
  1675. if (!prop)
  1676. return -EINVAL;
  1677. if (!prop->value)
  1678. return -ENODATA;
  1679. coords_size = prop->length / sizeof(u32);
  1680. if (coords_size != COORDS_ARR_SIZE) {
  1681. LOGD(LOG_ERR, "[touch]invalid %s\n", name);
  1682. return -EINVAL;
  1683. }
  1684. rc = of_property_read_u32_array(np, name, coords, coords_size);
  1685. if (rc && (rc != -EINVAL)) {
  1686. LOGD(LOG_ERR, "[touch]unable to read %s\n", name);
  1687. return rc;
  1688. }
  1689. if (!strcmp(name, "raydium,display-coords")) {
  1690. pdata->x_min = coords[0];
  1691. pdata->y_min = coords[1];
  1692. pdata->x_max = coords[2];
  1693. pdata->y_max = coords[3];
  1694. } else {
  1695. LOGD(LOG_ERR, "[touch]unsupported property %s\n", name);
  1696. return -EINVAL;
  1697. }
  1698. return 0;
  1699. }
  1700. /*******************************************************************************
  1701. * FUNCTION: raydium_check_dsi_panel_dt
  1702. *
  1703. * SUMMARY: Get the DSI active panel information from dtsi
  1704. *
  1705. * RETURN:
  1706. * 0 = success
  1707. * !0 = fail
  1708. *
  1709. * PARAMETERS:
  1710. * np - pointer to device_node structure
  1711. * active_panel - name of active DSI panel
  1712. ******************************************************************************/
  1713. static int raydium_check_dsi_panel_dt(struct device_node *np, struct drm_panel **active_panel)
  1714. {
  1715. int i = 0, rc = 0;
  1716. int count = 0;
  1717. struct device_node *node = NULL;
  1718. struct drm_panel *panel;
  1719. count = of_count_phandle_with_args(np, "panel", NULL);
  1720. LOGD(LOG_INFO, "[touch]%s: Active panel count: %d\n", __func__, count);
  1721. if (count <= 0)
  1722. return 0;
  1723. for (i = 0; i < count; i++) {
  1724. node = of_parse_phandle(np, "panel", i);
  1725. if (node != NULL)
  1726. LOGD(LOG_ERR, "[touch]%s: Node handle successfully parsed !\n", __func__);
  1727. panel = of_drm_find_panel(node);
  1728. of_node_put(node);
  1729. if (!IS_ERR(panel)) {
  1730. LOGD(LOG_ERR, "[touch]%s: Active panel selected !\n", __func__);
  1731. *active_panel = panel;
  1732. return 0;
  1733. }
  1734. }
  1735. LOGD(LOG_ERR, "[touch]%s: Active panel NOT selected !\n", __func__);
  1736. rc = PTR_ERR(panel);
  1737. return rc;
  1738. }
  1739. static int raydium_parse_dt(struct device *dev,
  1740. struct raydium_ts_platform_data *pdata)
  1741. {
  1742. struct device_node *np = dev->of_node;
  1743. struct drm_panel *active_panel = NULL;
  1744. int rc = 0;
  1745. u32 temp_val = 0;
  1746. pdata->name = RAYDIUM_NAME;
  1747. rc = raydium_get_dt_coords(dev, "raydium,display-coords", pdata);
  1748. if (rc)
  1749. return rc;
  1750. /* reset, irq gpio info */
  1751. pdata->reset_gpio = of_get_named_gpio_flags(np,
  1752. "raydium,reset-gpio",
  1753. 0,
  1754. &pdata->reset_gpio_flags);
  1755. //if (pdata->reset_gpio < 0)
  1756. if ((s32)(pdata->reset_gpio) < 0)
  1757. return pdata->reset_gpio;
  1758. pdata->irq_gpio = of_get_named_gpio_flags(np,
  1759. "raydium,irq-gpio",
  1760. 0,
  1761. &pdata->irq_gpio_flags);
  1762. //if (pdata->irq_gpio < 0)
  1763. if ((s32)(pdata->irq_gpio) < 0)
  1764. return pdata->irq_gpio;
  1765. rc = raydium_check_dsi_panel_dt(np, &active_panel);
  1766. LOGD(LOG_ERR, "[touch]%s: Panel not selected, rc=%d\n", __func__, rc);
  1767. if (rc) {
  1768. LOGD(LOG_ERR, "[touch]%s: Panel not selected, rc=%d\n", __func__, rc);
  1769. if (rc == -EPROBE_DEFER) {
  1770. LOGD(LOG_ERR, "[touch]%s: Probe defer selected, rc=%d\n", __func__, rc);
  1771. return rc;
  1772. }
  1773. }
  1774. pdata->active_panel = active_panel;
  1775. LOGD(LOG_ERR, "[touch]%s: Successful insert of active panel in core data\n", __func__);
  1776. rc = of_property_read_u32(np,
  1777. "raydium,hard-reset-delay-ms", &temp_val);
  1778. if (!rc)
  1779. pdata->hard_rst_dly = temp_val;
  1780. else
  1781. return rc;
  1782. rc = of_property_read_u32(np,
  1783. "raydium,soft-reset-delay-ms", &temp_val);
  1784. if (!rc)
  1785. pdata->soft_rst_dly = temp_val;
  1786. else
  1787. return rc;
  1788. rc = of_property_read_u32(np, "raydium,num-max-touches", &temp_val);
  1789. if (!rc)
  1790. pdata->num_max_touches = temp_val;
  1791. else
  1792. return rc;
  1793. #ifdef FW_MAPPING_BYID_EN
  1794. rc = of_property_read_u32(np, "raydium,fw_id", &temp_val);
  1795. if (!rc)
  1796. pdata->fw_id = temp_val;
  1797. else
  1798. return rc;
  1799. #endif
  1800. return 0;
  1801. }
  1802. #else
  1803. static int raydium_parse_dt(struct device *dev,
  1804. struct raydium_ts_platform_data *pdata)
  1805. {
  1806. return -ENODEV;
  1807. }
  1808. #endif /*end of CONFIG_OF*/
  1809. static void raydium_input_set(struct input_dev *input_dev)
  1810. {
  1811. int ret = 0;
  1812. unsigned char i;
  1813. input_dev->name = "raydium_ts";/*name need same with .idc*/
  1814. input_dev->id.bustype = BUS_I2C;
  1815. input_dev->dev.parent = &g_raydium_ts->client->dev;
  1816. input_dev->open = raydium_ts_open;/*touch lock*/
  1817. input_dev->close = raydium_ts_close;
  1818. input_set_drvdata(input_dev, g_raydium_ts);
  1819. __set_bit(EV_KEY, input_dev->evbit);
  1820. __set_bit(EV_ABS, input_dev->evbit);
  1821. __set_bit(BTN_TOUCH, input_dev->keybit);
  1822. __set_bit(INPUT_PROP_DIRECT, input_dev->propbit);
  1823. LOGD(LOG_INFO, "[touch]set abs prarams x[%d], y[%d]\n",
  1824. g_raydium_ts->x_max, g_raydium_ts->y_max);
  1825. /* Multitouch input params setup */
  1826. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0,
  1827. g_raydium_ts->x_max, 0, 0);
  1828. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0,
  1829. g_raydium_ts->y_max, 0, 0);
  1830. input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, PRESS_MAX, 0, 0);
  1831. input_set_abs_params(input_dev,
  1832. ABS_MT_TOUCH_MAJOR, 0, WIDTH_MAX, 0, 0);
  1833. input_set_abs_params(input_dev,
  1834. ABS_MT_TOUCH_MINOR, 0, WIDTH_MAX, 0, 0);
  1835. ret = input_mt_init_slots(input_dev, MAX_TOUCH_NUM,
  1836. INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
  1837. if (ret)
  1838. LOGD(LOG_ERR, "[touch]failed to initialize MT slots: %d\n", ret);
  1839. for (i = 0; i < (MAX_TOUCH_NUM * 2); i++)
  1840. gst_slot[i] = gst_slot_init;
  1841. }
  1842. void touch_notify_glink_channel_state(bool state)
  1843. {
  1844. LOGD(LOG_INFO, "%s:[touch] channel state: %d\n", __func__, state);
  1845. }
  1846. void glink_touch_rx_msg(void *data, int len)
  1847. {
  1848. int rc = 0;
  1849. LOGD(LOG_INFO, "%s:[touch]TOUCH_RX_MSG Start:\n", __func__);
  1850. if (len > TOUCH_GLINK_INTENT_SIZE) {
  1851. LOGD(LOG_ERR, "Invalid TOUCH glink intent size\n");
  1852. return;
  1853. }
  1854. /* check SLATE response */
  1855. slate_ack_resp = *(uint32_t *)&data[8];
  1856. LOGD(LOG_INFO, "[touch]slate_ack_resp :%0x\n", slate_ack_resp);
  1857. if (slate_ack_resp == 0x01) {
  1858. LOGD(LOG_INFO,"Bad SLATE response\n");
  1859. rc = -EINVAL;
  1860. goto err_ret;
  1861. }
  1862. LOGD(LOG_INFO, "%s:[touch]TOUCH_RX_MSG End:\n", __func__);
  1863. err_ret:
  1864. return;
  1865. }
  1866. static int raydium_set_resolution(void)
  1867. {
  1868. unsigned char u8_buf[4];
  1869. int i32_ret = -1;
  1870. unsigned int u32_x, u32_y;
  1871. mutex_lock(&g_raydium_ts->lock);
  1872. i32_ret = raydium_i2c_pda2_set_page(g_raydium_ts->client,
  1873. g_raydium_ts->is_suspend,
  1874. RAYDIUM_PDA2_PAGE_0);
  1875. if (i32_ret < 0)
  1876. goto exit_error;
  1877. i32_ret = raydium_i2c_pda2_read(g_raydium_ts->client,
  1878. RAYDIUM_PDA2_DISPLAY_INFO_ADDR,
  1879. u8_buf, 4);
  1880. if (i32_ret < 0)
  1881. goto exit_error;
  1882. u32_x = u8_buf[3] << 8 | u8_buf[2];
  1883. u32_y = u8_buf[1] << 8 | u8_buf[0];
  1884. LOGD(LOG_DEBUG, "[touch]RAD display info x:%d, y:%d\n", u32_x, u32_y);
  1885. if (u32_x > 100 && u32_y > 100 &&
  1886. u32_x < 600 && u32_y < 600) {
  1887. g_raydium_ts->x_max = u32_x - 1;
  1888. g_raydium_ts->y_max = u32_y - 1;
  1889. }
  1890. exit_error:
  1891. mutex_unlock(&g_raydium_ts->lock);
  1892. return i32_ret;
  1893. }
  1894. static int raydium_get_regulator(struct raydium_ts_data *cd, bool get)
  1895. {
  1896. int rc;
  1897. if (!get) {
  1898. rc = 0;
  1899. goto regulator_put;
  1900. }
  1901. #ifdef VDD_ANALOG_ENABLE
  1902. cd->vdd = regulator_get(&cd->client->dev, "vdd");
  1903. if (IS_ERR(cd->vdd)) {
  1904. rc = PTR_ERR(cd->vdd);
  1905. dev_err(&cd->client->dev,
  1906. "Regulator get failed vdd rc=%d\n", rc);
  1907. goto regulator_put;
  1908. }
  1909. #endif
  1910. cd->vcc_i2c = regulator_get(&cd->client->dev, "vcc_i2c");
  1911. if (IS_ERR(cd->vcc_i2c)) {
  1912. rc = PTR_ERR(cd->vcc_i2c);
  1913. dev_err(&cd->client->dev,
  1914. "Regulator get failed vcc_i2c rc=%d\n", rc);
  1915. goto regulator_put;
  1916. }
  1917. return 0;
  1918. regulator_put:
  1919. #ifdef VDD_ANALOG_ENABLE
  1920. if (!IS_ERR(cd->vdd)) {
  1921. dev_err(&cd->client->dev, "Regulator put vdd\n");
  1922. regulator_put(cd->vdd);
  1923. cd->vdd = NULL;
  1924. }
  1925. #endif
  1926. if (!IS_ERR(cd->vcc_i2c)) {
  1927. dev_err(&cd->client->dev, "Regulator put vcc_i2c\n");
  1928. regulator_put(cd->vcc_i2c);
  1929. cd->vcc_i2c = NULL;
  1930. }
  1931. return rc;
  1932. }
  1933. static int raydium_enable_regulator(struct raydium_ts_data *cd, bool en)
  1934. {
  1935. int rc;
  1936. if (!en) {
  1937. rc = 0;
  1938. goto disable_vcc_i2c_reg;
  1939. }
  1940. #ifdef VDD_ANALOG_ENABLE
  1941. if (cd->vdd) {
  1942. if (regulator_count_voltages(cd->vdd) > 0) {
  1943. rc = regulator_set_voltage(cd->vdd, VTG_MIN_UV,
  1944. VTG_MAX_UV);
  1945. if (rc) {
  1946. dev_err(&cd->client->dev,
  1947. "Regulator set_vtg failed vdd rc=%d\n", rc);
  1948. goto exit;
  1949. }
  1950. }
  1951. rc = regulator_enable(cd->vdd);
  1952. if (rc) {
  1953. dev_err(&cd->client->dev,
  1954. "Regulator vdd enable failed rc=%d\n", rc);
  1955. goto exit;
  1956. }
  1957. }
  1958. #endif
  1959. if (cd->vcc_i2c) {
  1960. if (regulator_count_voltages(cd->vcc_i2c) > 0) {
  1961. rc = regulator_set_voltage(cd->vcc_i2c, I2C_VTG_MIN_UV,
  1962. I2C_VTG_MAX_UV);
  1963. if (rc) {
  1964. dev_err(&cd->client->dev,
  1965. "Regulator set_vtg failed vcc_i2c rc=%d\n", rc);
  1966. goto disable_vdd_reg;
  1967. }
  1968. }
  1969. rc = regulator_enable(cd->vcc_i2c);
  1970. if (rc) {
  1971. dev_err(&cd->client->dev,
  1972. "Regulator vcc_i2c enable failed rc=%d\n", rc);
  1973. goto disable_vdd_reg;
  1974. }
  1975. }
  1976. return 0;
  1977. disable_vcc_i2c_reg:
  1978. if (cd->vcc_i2c) {
  1979. if (regulator_count_voltages(cd->vcc_i2c) > 0)
  1980. regulator_set_voltage(cd->vcc_i2c, I2C_VTG_MIN_UV,
  1981. I2C_VTG_MAX_UV);
  1982. regulator_disable(cd->vcc_i2c);
  1983. }
  1984. disable_vdd_reg:
  1985. #ifdef VDD_ANALOG_ENABLE
  1986. if (cd->vdd) {
  1987. if (regulator_count_voltages(cd->vdd) > 0)
  1988. regulator_set_voltage(cd->vdd, VTG_MIN_UV,
  1989. VTG_MAX_UV);
  1990. regulator_disable(cd->vdd);
  1991. }
  1992. #endif
  1993. #ifdef VDD_ANALOG_ENABLE
  1994. exit:
  1995. #endif
  1996. return rc;
  1997. }
  1998. static int raydium_ts_probe(struct i2c_client *client,
  1999. const struct i2c_device_id *id)
  2000. {
  2001. struct raydium_ts_platform_data *pdata =
  2002. (struct raydium_ts_platform_data *)client->dev.platform_data;
  2003. struct input_dev *input_dev;
  2004. unsigned short u16_i2c_data;
  2005. int ret = 0;
  2006. LOGD(LOG_INFO, "[touch] probe\n");
  2007. if (client->dev.of_node) {
  2008. pdata = devm_kzalloc(&client->dev,
  2009. sizeof(struct raydium_ts_platform_data),
  2010. GFP_KERNEL);
  2011. if (!pdata) {
  2012. LOGD(LOG_ERR, "[touch]failed to allocate memory\n");
  2013. return -ENOMEM;
  2014. }
  2015. ret = raydium_parse_dt(&client->dev, pdata);
  2016. if (ret) {
  2017. LOGD(LOG_ERR, "[touch]device tree parsing failed\n");
  2018. goto parse_dt_failed;
  2019. }
  2020. } else
  2021. pdata = client->dev.platform_data;
  2022. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  2023. ret = -ENODEV;
  2024. goto exit_check_functionality_failed;
  2025. }
  2026. g_raydium_ts = devm_kzalloc(&client->dev,
  2027. sizeof(struct raydium_ts_data),
  2028. GFP_KERNEL);
  2029. if (!g_raydium_ts) {
  2030. LOGD(LOG_ERR, "[touch]failed to allocate input driver data\n");
  2031. return -ENOMEM;
  2032. }
  2033. raydium_variable_init();
  2034. mutex_init(&g_raydium_ts->lock);
  2035. i2c_set_clientdata(client, g_raydium_ts);
  2036. g_raydium_ts->irq_enabled = false;
  2037. g_raydium_ts->irq_wake = false;
  2038. g_raydium_ts->irq_gpio = pdata->irq_gpio;
  2039. g_raydium_ts->rst_gpio = pdata->reset_gpio;
  2040. client->irq = g_raydium_ts->irq_gpio;
  2041. g_raydium_ts->u8_max_touchs = pdata->num_max_touches;
  2042. g_raydium_ts->client = client;
  2043. g_raydium_ts->x_max = pdata->x_max - 1;
  2044. g_raydium_ts->y_max = pdata->y_max - 1;
  2045. g_raydium_ts->is_suspend = 0;
  2046. g_raydium_ts->is_sleep = 0;
  2047. #ifdef GESTURE_EN
  2048. g_raydium_ts->is_palm = 0;
  2049. #endif
  2050. g_raydium_ts->fw_version = 0;
  2051. device_init_wakeup(&client->dev, 1);
  2052. #ifdef MSM_NEW_VER
  2053. ret = raydium_ts_pinctrl_init();
  2054. if (!ret && g_raydium_ts->ts_pinctrl) {
  2055. /*
  2056. * Pinctrl handle is optional. If pinctrl handle is found
  2057. * let pins to be configured in active state. If not
  2058. * found continue further without error.
  2059. */
  2060. ret = pinctrl_select_state(g_raydium_ts->ts_pinctrl,
  2061. g_raydium_ts->pinctrl_state_active);
  2062. if (ret < 0)
  2063. LOGD(LOG_ERR, "[touch]failed to set pin to active state\n");
  2064. }
  2065. #endif /*end of MSM_NEW_VER*/
  2066. ret = raydium_get_regulator(g_raydium_ts, true);
  2067. if (ret) {
  2068. dev_err(&client->dev, "Failed to get voltage regulators\n");
  2069. goto error_alloc_data;
  2070. }
  2071. ret = raydium_enable_regulator(g_raydium_ts, true);
  2072. if (ret) {
  2073. dev_err(&client->dev, "Failed to enable regulators: rc=%d\n", ret);
  2074. goto error_get_regulator;
  2075. }
  2076. ret = raydium_gpio_configure(true);
  2077. if (ret < 0) {
  2078. LOGD(LOG_ERR, "[touch]failed to configure the gpios\n");
  2079. goto err_gpio_req;
  2080. }
  2081. /*modify dtsi to 360*/
  2082. msleep(pdata->soft_rst_dly);
  2083. if (raydium_disable_i2c_deglitch() == ERROR) {
  2084. LOGD(LOG_ERR, "[touch]disable i2c deglicth NG!\r\n");
  2085. ret = -ENODEV;
  2086. goto exit_check_i2c;
  2087. }
  2088. /*print touch i2c ready*/
  2089. ret = raydium_check_i2c_ready(&u16_i2c_data);
  2090. if (ret < 0 || (u16_i2c_data == 0)) {
  2091. LOGD(LOG_ERR, "[touch]Check I2C failed\n");
  2092. ret = -EPROBE_DEFER;
  2093. goto exit_check_i2c;
  2094. }
  2095. glink_touch_channel_init(&touch_notify_glink_channel_state, &glink_touch_rx_msg);
  2096. #if defined(CONFIG_DRM) || defined(CONFIG_PANEL_NOTIFIER)
  2097. /* Setup active dsi panel */
  2098. active_panel = pdata->active_panel;
  2099. #endif
  2100. /*input device initialization*/
  2101. input_dev = input_allocate_device();
  2102. if (!input_dev) {
  2103. ret = -ENOMEM;
  2104. LOGD(LOG_ERR, "[touch]failed to allocate input device\n");
  2105. goto exit_input_dev_alloc_failed;
  2106. }
  2107. raydium_set_resolution();
  2108. g_raydium_ts->input_dev = input_dev;
  2109. raydium_input_set(input_dev);
  2110. ret = input_register_device(input_dev);
  2111. if (ret) {
  2112. LOGD(LOG_ERR, "[touch]failed to register input device: %s\n",
  2113. dev_name(&client->dev));
  2114. goto exit_input_register_device_failed;
  2115. }
  2116. #ifdef GESTURE_EN
  2117. input_set_capability(input_dev, EV_KEY, KEY_SLEEP);
  2118. input_set_capability(input_dev, EV_KEY, KEY_WAKEUP);
  2119. #endif
  2120. /*suspend/resume routine*/
  2121. #if defined(CONFIG_FB)
  2122. raydium_register_notifier();
  2123. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  2124. /*Early-suspend level*/
  2125. g_raydium_ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;
  2126. g_raydium_ts->early_suspend.suspend = raydium_ts_early_suspend;
  2127. g_raydium_ts->early_suspend.resume = raydium_ts_late_resume;
  2128. register_early_suspend(&g_raydium_ts->early_suspend);
  2129. #endif/*end of CONFIG_FB*/
  2130. #ifdef CONFIG_RM_SYSFS_DEBUG
  2131. raydium_create_sysfs(client);
  2132. #endif/*end of CONFIG_RM_SYSFS_DEBUG*/
  2133. INIT_WORK(&g_raydium_ts->work, raydium_work_handler);
  2134. g_raydium_ts->workqueue = create_singlethread_workqueue("raydium_ts");
  2135. /*irq_gpio = 13 irqflags = 108*/
  2136. LOGD(LOG_DEBUG, "[touch]pdata irq : %d\n", g_raydium_ts->irq_gpio);
  2137. LOGD(LOG_DEBUG, "[touch]client irq : %d, pdata flags : %d\n",
  2138. client->irq, pdata->irqflags);
  2139. #if defined(CONFIG_PANEL_NOTIFIER)
  2140. LOGD(LOG_DEBUG, "%s: Probe: Setup panel event notifier\n", __func__);
  2141. raydium_setup_panel_notifier(g_raydium_ts);
  2142. #elif defined(CONFIG_DRM)
  2143. LOGD(LOG_DEBUG, "%s: Probe: Setup drm notifier\n", __func__);
  2144. raydium_setup_drm_notifier(g_raydium_ts);
  2145. #endif/*end of CONFIG_DRM*/
  2146. g_raydium_ts->irq = gpio_to_irq(pdata->irq_gpio);
  2147. ret = request_threaded_irq(g_raydium_ts->irq, NULL, raydium_ts_interrupt,
  2148. IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
  2149. client->dev.driver->name, g_raydium_ts);
  2150. if (ret < 0) {
  2151. LOGD(LOG_ERR, "[touch]raydium_probe: request irq failed\n");
  2152. goto exit_irq_request_failed;
  2153. }
  2154. g_raydium_ts->irq_desc = irq_to_desc(g_raydium_ts->irq);
  2155. g_raydium_ts->irq_enabled = true;
  2156. g_raydium_ts->touch_offload = false;
  2157. /*disable_irq then enable_irq for avoid Unbalanced enable for IRQ */
  2158. /*raydium_irq_control(ts, ENABLE);*/
  2159. LOGD(LOG_DEBUG, "[touch]RAD Touch driver ver :0x%X\n", g_u32_driver_version);
  2160. /*fw update check*/
  2161. ret = raydium_fw_update_init(u16_i2c_data);
  2162. if (ret < 0) {
  2163. LOGD(LOG_ERR, "[touch]FW update init failed\n");
  2164. ret = -ENODEV;
  2165. goto exit_irq_request_failed;
  2166. }
  2167. LOGD(LOG_INFO, "[touch] probe: done\n");
  2168. return 0;
  2169. exit_irq_request_failed:
  2170. #if defined(CONFIG_FB)
  2171. raydium_unregister_notifier();
  2172. #elif defined(CONFIG_PANEL_NOTIFIER)
  2173. panel_event_notifier_unregister(g_raydium_ts->entry);
  2174. #elif defined(CONFIG_DRM)
  2175. raydium_setup_drm_unregister_notifier();
  2176. #endif
  2177. cancel_work_sync(&g_raydium_ts->work);
  2178. input_unregister_device(input_dev);
  2179. g_raydium_ts->input_dev = NULL;
  2180. exit_input_register_device_failed:
  2181. if (g_raydium_ts->input_dev)
  2182. input_free_device(input_dev);
  2183. g_raydium_ts->input_dev = NULL;
  2184. exit_input_dev_alloc_failed:
  2185. exit_check_i2c:
  2186. #ifdef MSM_NEW_VER
  2187. if (g_raydium_ts->ts_pinctrl) {
  2188. if (IS_ERR_OR_NULL(g_raydium_ts->pinctrl_state_release)) {
  2189. devm_pinctrl_put(g_raydium_ts->ts_pinctrl);
  2190. g_raydium_ts->ts_pinctrl = NULL;
  2191. } else {
  2192. if (pinctrl_select_state(g_raydium_ts->ts_pinctrl,
  2193. g_raydium_ts->pinctrl_state_release))
  2194. LOGD(LOG_ERR,
  2195. "[touch]pinctrl_select_state failed\n");
  2196. }
  2197. }
  2198. #endif/*end of MSM_NEW_VER*/
  2199. if (gpio_is_valid(pdata->reset_gpio))
  2200. gpio_free(pdata->reset_gpio);
  2201. if (gpio_is_valid(pdata->irq_gpio))
  2202. gpio_free(pdata->irq_gpio);
  2203. err_gpio_req:
  2204. raydium_enable_regulator(g_raydium_ts, false);
  2205. error_get_regulator:
  2206. raydium_get_regulator(g_raydium_ts, false);
  2207. error_alloc_data:
  2208. parse_dt_failed:
  2209. exit_check_functionality_failed:
  2210. return ret;
  2211. }
  2212. void raydium_ts_shutdown(struct i2c_client *client)
  2213. {
  2214. LOGD(LOG_INFO, "[touch] %s: start\n", __func__);
  2215. cancel_work_sync(&g_raydium_ts->work);
  2216. if (g_raydium_ts->workqueue) {
  2217. destroy_workqueue(g_raydium_ts->workqueue);
  2218. g_raydium_ts->workqueue = NULL;
  2219. }
  2220. #if defined(CONFIG_FB)
  2221. raydium_unregister_notifier();
  2222. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  2223. unregister_early_suspend(&g_raydium_ts->early_suspend);
  2224. #elif defined(CONFIG_PANEL_NOTIFIER)
  2225. if (active_panel)
  2226. panel_event_notifier_unregister(g_raydium_ts->entry);
  2227. #elif defined(CONFIG_DRM)
  2228. if (active_panel)
  2229. drm_panel_notifier_unregister(active_panel, &g_raydium_ts->fb_notif);
  2230. #endif/*end of CONFIG_FB*/
  2231. input_unregister_device(g_raydium_ts->input_dev);
  2232. g_raydium_ts->input_dev = NULL;
  2233. gpio_free(g_raydium_ts->rst_gpio);
  2234. #ifdef CONFIG_RM_SYSFS_DEBUG
  2235. raydium_release_sysfs(client);
  2236. #endif /*end of CONFIG_RM_SYSFS_DEBUG*/
  2237. disable_irq(g_raydium_ts->irq);
  2238. free_irq(client->irq, g_raydium_ts);
  2239. if (gpio_is_valid(g_raydium_ts->rst_gpio))
  2240. gpio_free(g_raydium_ts->rst_gpio);
  2241. if (gpio_is_valid(g_raydium_ts->irq_gpio))
  2242. gpio_free(g_raydium_ts->irq_gpio);
  2243. raydium_enable_regulator(g_raydium_ts, false);
  2244. raydium_get_regulator(g_raydium_ts, false);
  2245. devm_kfree(&client->dev, g_raydium_ts);
  2246. g_raydium_ts = NULL;
  2247. i2c_set_clientdata(client, NULL);
  2248. LOGD(LOG_INFO, "[touch] %s: done\n", __func__);
  2249. }
  2250. static int raydium_ts_remove(struct i2c_client *client)
  2251. {
  2252. LOGD(LOG_INFO, "[touch] %s: start\n", __func__);
  2253. cancel_work_sync(&g_raydium_ts->work);
  2254. if (g_raydium_ts->workqueue) {
  2255. destroy_workqueue(g_raydium_ts->workqueue);
  2256. g_raydium_ts->workqueue = NULL;
  2257. }
  2258. #if defined(CONFIG_FB)
  2259. raydium_unregister_notifier();
  2260. #elif defined(CONFIG_HAS_EARLYSUSPEND)
  2261. unregister_early_suspend(&g_raydium_ts->early_suspend);
  2262. #elif defined(CONFIG_PANEL_NOTIFIER)
  2263. if (active_panel)
  2264. panel_event_notifier_unregister(g_raydium_ts->entry);
  2265. #elif defined(CONFIG_DRM)
  2266. if (active_panel)
  2267. drm_panel_notifier_unregister(active_panel, &g_raydium_ts->fb_notif);
  2268. #endif/*end of CONFIG_FB*/
  2269. input_unregister_device(g_raydium_ts->input_dev);
  2270. g_raydium_ts->input_dev = NULL;
  2271. gpio_free(g_raydium_ts->rst_gpio);
  2272. #ifdef CONFIG_RM_SYSFS_DEBUG
  2273. raydium_release_sysfs(client);
  2274. #endif /*end of CONFIG_RM_SYSFS_DEBUG*/
  2275. disable_irq(g_raydium_ts->irq);
  2276. free_irq(client->irq, g_raydium_ts);
  2277. if (gpio_is_valid(g_raydium_ts->rst_gpio))
  2278. gpio_free(g_raydium_ts->rst_gpio);
  2279. if (gpio_is_valid(g_raydium_ts->irq_gpio))
  2280. gpio_free(g_raydium_ts->irq_gpio);
  2281. raydium_enable_regulator(g_raydium_ts, false);
  2282. raydium_get_regulator(g_raydium_ts, false);
  2283. devm_kfree(&client->dev, g_raydium_ts);
  2284. g_raydium_ts = NULL;
  2285. i2c_set_clientdata(client, NULL);
  2286. LOGD(LOG_INFO, "[touch] %s: done\n", __func__);
  2287. return 0;
  2288. }
  2289. static const struct i2c_device_id raydium_ts_id[] = {
  2290. {RAYDIUM_NAME, 0},
  2291. {}
  2292. };
  2293. MODULE_DEVICE_TABLE(i2c, raydium_ts_id);
  2294. #ifdef CONFIG_OF
  2295. static const struct of_device_id raydium_match_table[] = {
  2296. { .compatible = "raydium,raydium-ts",},
  2297. { },
  2298. };
  2299. #else
  2300. #define raydium_match_table NULL
  2301. #endif/*end of CONFIG_OF*/
  2302. static struct i2c_driver raydium_ts_driver = {
  2303. .probe = raydium_ts_probe,
  2304. .remove = raydium_ts_remove,
  2305. .shutdown = raydium_ts_shutdown,
  2306. .id_table = raydium_ts_id,
  2307. .driver = {
  2308. .name = RAYDIUM_NAME,
  2309. .owner = THIS_MODULE,
  2310. .of_match_table = raydium_match_table,
  2311. #if defined(CONFIG_PM)
  2312. .pm = &raydium_ts_pm_ops,
  2313. #endif/*end of CONFIG_PM*/
  2314. },
  2315. };
  2316. static int __init raydium_ts_init(void)
  2317. {
  2318. int ret;
  2319. ret = i2c_add_driver(&raydium_ts_driver);
  2320. return ret;
  2321. }
  2322. static void __exit raydium_ts_exit(void)
  2323. {
  2324. i2c_del_driver(&raydium_ts_driver);
  2325. }
  2326. module_init(raydium_ts_init);
  2327. module_exit(raydium_ts_exit);
  2328. MODULE_AUTHOR("<Rejion>");
  2329. MODULE_DESCRIPTION("Raydium TouchScreen driver");
  2330. MODULE_LICENSE("GPL");