raydium_driver.c 70 KB

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