goodix_ts_inspect.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981
  1. /*
  2. * Goodix Touchscreen Driver
  3. * Copyright (C) 2020 - 2021 Goodix, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be a reference
  11. * to you, when you are integrating the GOODiX's CTP IC into your system,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. */
  17. #include "goodix_ts_core.h"
  18. #include <linux/rtc.h>
  19. #include <linux/timer.h>
  20. #include <linux/version.h>
  21. #include <linux/fs.h>
  22. #include <asm/uaccess.h>
  23. /* test config */
  24. #define TOTAL_FRAME_NUM 1 /* rawdata test frames */
  25. #define NOISEDATA_TEST_TIMES 1 /* noise test frames */
  26. // #define SAVE_IN_CSV
  27. #define GOODIX_RESULT_SAVE_PATH "/vendor/etc/Test_Data.csv"
  28. #define GOODIX_TEST_FILE_NAME "goodix"
  29. #define MAX_DATA_BUFFER 28000
  30. #define MAX_SHORT_NUM 15
  31. #define MAX_LINE_LEN (1024 * 3 * 7)
  32. #define MAX_DRV_NUM 52
  33. #define MAX_SEN_NUM 75
  34. #define STATISTICS_DATA_LEN 32
  35. #define MAX_STR_LEN 32
  36. #define MAX_TEST_ITEMS 10 /* 0P-1P-2P-3P-5P total test items */
  37. #define GTP_CAP_TEST 1
  38. #define GTP_DELTA_TEST 2
  39. #define GTP_NOISE_TEST 3
  40. #define GTP_SHORT_TEST 5
  41. #define GTP_SELFCAP_TEST 6
  42. #define GTP_SELFNOISE_TEST 7
  43. #define GTP_TEST_PASS 1
  44. #define GTP_PANEL_REASON 2
  45. #define SYS_SOFTWARE_REASON 3
  46. #define CHN_VDD 0xFF
  47. #define CHN_GND 0x7F
  48. #define DRV_CHANNEL_FLAG 0x80
  49. #define CSV_TP_SPECIAL_RAW_MIN "special_raw_min"
  50. #define CSV_TP_SPECIAL_RAW_MAX "special_raw_max"
  51. #define CSV_TP_SPECIAL_RAW_DELTA "special_raw_delta"
  52. #define CSV_TP_SHORT_THRESHOLD "shortciurt_threshold"
  53. #define CSV_TP_SPECIAL_SELFRAW_MAX "special_selfraw_max"
  54. #define CSV_TP_SPECIAL_SELFRAW_MIN "special_selfraw_min"
  55. #define CSV_TP_NOISE_LIMIT "noise_data_limit"
  56. #define CSV_TP_SELFNOISE_LIMIT "noise_selfdata_limit"
  57. #define CSV_TP_TEST_CONFIG "test_config"
  58. #define MAX_TEST_TIME_MS 15000
  59. #define DEFAULT_TEST_TIME_MS 7000
  60. /* berlin A */
  61. #define MAX_DRV_NUM_BRA 21
  62. #define MAX_SEN_NUM_BRA 42
  63. #define SHORT_TEST_TIME_REG_BRA 0x11FF2
  64. #define DFT_ADC_DUMP_NUM_BRA 1396
  65. #define DFT_SHORT_THRESHOLD_BRA 16
  66. #define DFT_DIFFCODE_SHORT_THRESHOLD_BRA 16
  67. #define SHORT_TEST_STATUS_REG_BRA 0x10400
  68. #define SHORT_TEST_RESULT_REG_BRA 0x10410
  69. #define DRV_DRV_SELFCODE_REG_BRA 0x1045E
  70. #define SEN_SEN_SELFCODE_REG_BRA 0x1084E
  71. #define DRV_SEN_SELFCODE_REG_BRA 0x11712
  72. #define DIFF_CODE_DATA_REG_BRA 0x11F72
  73. /* berlin B */
  74. #define MAX_DRV_NUM_BRB 52
  75. #define MAX_SEN_NUM_BRB 75
  76. #define SHORT_TEST_TIME_REG_BRB 0x26AE0
  77. #define DFT_ADC_DUMP_NUM_BRB 762
  78. #define DFT_SHORT_THRESHOLD_BRB 100
  79. #define DFT_DIFFCODE_SHORT_THRESHOLD_BRB 32
  80. #define SHORT_TEST_STATUS_REG_BRB 0x20400
  81. #define SHORT_TEST_RESULT_REG_BRB 0x20410
  82. #define DRV_DRV_SELFCODE_REG_BRB 0x2049A
  83. #define SEN_SEN_SELFCODE_REG_BRB 0x21AF2
  84. #define DRV_SEN_SELFCODE_REG_BRB 0x248A6
  85. #define DIFF_CODE_DATA_REG_BRB 0x269E0
  86. /* berlinD */
  87. #define MAX_DRV_NUM_BRD 20
  88. #define MAX_SEN_NUM_BRD 40
  89. #define SHORT_TEST_TIME_REG_BRD 0x14D7A
  90. #define DFT_ADC_DUMP_NUM_BRD 762
  91. #define DFT_SHORT_THRESHOLD_BRD 100
  92. #define DFT_DIFFCODE_SHORT_THRESHOLD_BRD 32
  93. #define SHORT_TEST_STATUS_REG_BRD 0x13400
  94. #define SHORT_TEST_RESULT_REG_BRD 0x13408
  95. #define DRV_DRV_SELFCODE_REG_BRD 0x1344E
  96. #define SEN_SEN_SELFCODE_REG_BRD 0x137E6
  97. #define DRV_SEN_SELFCODE_REG_BRD 0x14556
  98. #define DIFF_CODE_DATA_REG_BRD 0x14D00
  99. #define ABS(val) ((val < 0)? -(val) : val)
  100. #define MAX(a, b) ((a > b)? a : b)
  101. static bool module_initialized;
  102. /* berlin A drv-sen map */
  103. static u8 brl_a_drv_map[] = {
  104. 42, 43, 44, 45, 46, 47, 48, 49,
  105. 50, 51, 52, 53, 54, 55, 56, 57,
  106. 58, 59, 60, 61, 62
  107. };
  108. static u8 brl_a_sen_map[] = {
  109. 0, 1, 2, 3, 4, 5, 6, 7,
  110. 8, 9, 10, 11, 12, 13, 14, 15,
  111. 16, 17, 18, 19, 20, 21, 22, 23,
  112. 24, 25, 26, 27, 28, 29, 30, 31,
  113. 32, 33, 34, 35, 36, 37, 38, 39,
  114. 40, 41
  115. };
  116. /* berlin B drv-sen map */
  117. static u8 brl_b_drv_map[] = {
  118. 75, 76, 77, 78, 79, 80, 81, 82,
  119. 83, 84, 85, 86, 87, 88, 89, 90,
  120. 91, 92, 93, 94, 95, 96, 97, 98,
  121. 99, 100, 101, 102, 103, 104, 105,
  122. 106, 107, 108, 109, 110, 111, 112,
  123. 113, 114, 115, 116, 117, 118, 119,
  124. 120, 121, 122, 123, 124, 125, 126
  125. };
  126. static u8 brl_b_sen_map[] = {
  127. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
  128. 11, 12, 13, 14, 15, 16, 17, 18,
  129. 19, 20, 21, 22, 23, 24, 25, 26,
  130. 27, 28, 29, 30, 31, 32, 33, 34,
  131. 35, 36, 37, 38, 39, 40, 41, 42,
  132. 43, 44, 45, 46, 47, 48, 49, 50,
  133. 51, 52, 53, 54, 55, 56, 57, 58,
  134. 59, 60, 61, 62, 63, 64, 65, 66,
  135. 67, 68, 69, 70, 71, 72, 73, 74
  136. };
  137. /* berlin D drv-sen map */
  138. static u8 brl_d_drv_map[] = {
  139. 40, 41, 42, 43, 44, 45, 46, 47,
  140. 48, 49, 50, 51, 52, 53, 54, 55,
  141. 56, 57, 58, 59,
  142. };
  143. static u8 brl_d_sen_map[] = {
  144. 0, 1, 2, 3, 4, 5, 6, 7,
  145. 8, 9, 10, 11, 12, 13, 14, 15,
  146. 16, 17, 18, 19, 20, 21, 22, 23,
  147. 24, 25, 26, 27, 28, 29, 30, 31,
  148. 32, 33, 34, 35, 36, 37, 38, 39,
  149. };
  150. typedef struct __attribute__((packed)) {
  151. u8 result;
  152. u8 drv_drv_num;
  153. u8 sen_sen_num;
  154. u8 drv_sen_num;
  155. u8 drv_gnd_avdd_num;
  156. u8 sen_gnd_avdd_num;
  157. u16 checksum;
  158. } test_result_t;
  159. struct params_info_t {
  160. u32 max_drv_num;
  161. u32 max_sen_num;
  162. u8 *drv_map;
  163. u8 *sen_map;
  164. u32 short_test_time_reg;
  165. u32 short_test_status_reg;
  166. u32 short_test_result_reg;
  167. u32 drv_drv_selfcode_reg;
  168. u32 sen_sen_selfcode_reg;
  169. u32 drv_sen_selfcode_reg;
  170. u32 diffcode_data_reg;
  171. u16 short_test_dump_num;
  172. u16 dft_short_threshold;
  173. u16 short_diffcode_threshold;
  174. };
  175. struct params_info_t params_bra = {
  176. MAX_DRV_NUM_BRA,
  177. MAX_SEN_NUM_BRA,
  178. brl_a_drv_map,
  179. brl_a_sen_map,
  180. SHORT_TEST_TIME_REG_BRA,
  181. SHORT_TEST_STATUS_REG_BRA,
  182. SHORT_TEST_RESULT_REG_BRA,
  183. DRV_DRV_SELFCODE_REG_BRA,
  184. SEN_SEN_SELFCODE_REG_BRA,
  185. DRV_SEN_SELFCODE_REG_BRA,
  186. DIFF_CODE_DATA_REG_BRA,
  187. DFT_ADC_DUMP_NUM_BRA,
  188. DFT_SHORT_THRESHOLD_BRA,
  189. DFT_DIFFCODE_SHORT_THRESHOLD_BRA,
  190. };
  191. struct params_info_t params_brb = {
  192. MAX_DRV_NUM_BRB,
  193. MAX_SEN_NUM_BRB,
  194. brl_b_drv_map,
  195. brl_b_sen_map,
  196. SHORT_TEST_TIME_REG_BRB,
  197. SHORT_TEST_STATUS_REG_BRB,
  198. SHORT_TEST_RESULT_REG_BRB,
  199. DRV_DRV_SELFCODE_REG_BRB,
  200. SEN_SEN_SELFCODE_REG_BRB,
  201. DRV_SEN_SELFCODE_REG_BRB,
  202. DIFF_CODE_DATA_REG_BRB,
  203. DFT_ADC_DUMP_NUM_BRB,
  204. DFT_SHORT_THRESHOLD_BRB,
  205. DFT_DIFFCODE_SHORT_THRESHOLD_BRB,
  206. };
  207. struct params_info_t params_brd = {
  208. MAX_DRV_NUM_BRD,
  209. MAX_SEN_NUM_BRD,
  210. brl_d_drv_map,
  211. brl_d_sen_map,
  212. SHORT_TEST_TIME_REG_BRD,
  213. SHORT_TEST_STATUS_REG_BRD,
  214. SHORT_TEST_RESULT_REG_BRD,
  215. DRV_DRV_SELFCODE_REG_BRD,
  216. SEN_SEN_SELFCODE_REG_BRD,
  217. DRV_SEN_SELFCODE_REG_BRD,
  218. DIFF_CODE_DATA_REG_BRD,
  219. DFT_ADC_DUMP_NUM_BRD,
  220. DFT_SHORT_THRESHOLD_BRD,
  221. DFT_DIFFCODE_SHORT_THRESHOLD_BRD,
  222. };
  223. struct ts_test_params {
  224. bool test_items[MAX_TEST_ITEMS];
  225. u32 rawdata_addr;
  226. u32 noisedata_addr;
  227. u32 self_rawdata_addr;
  228. u32 self_noisedata_addr;
  229. u32 drv_num;
  230. u32 sen_num;
  231. struct params_info_t *params_info;
  232. s32 cfg_buf[GOODIX_CFG_MAX_SIZE];
  233. s32 max_limits[MAX_DRV_NUM * MAX_SEN_NUM];
  234. s32 min_limits[MAX_DRV_NUM * MAX_SEN_NUM];
  235. s32 deviation_limits[MAX_DRV_NUM * MAX_SEN_NUM];
  236. s32 self_max_limits[MAX_DRV_NUM + MAX_SEN_NUM];
  237. s32 self_min_limits[MAX_DRV_NUM + MAX_SEN_NUM];
  238. s32 noise_threshold;
  239. s32 self_noise_threshold;
  240. u32 short_threshold;
  241. u32 r_drv_drv_threshold;
  242. u32 r_drv_sen_threshold;
  243. u32 r_sen_sen_threshold;
  244. u32 r_drv_gnd_threshold;
  245. u32 r_sen_gnd_threshold;
  246. u32 avdd_value;
  247. };
  248. struct ts_test_rawdata {
  249. s16 data[MAX_DRV_NUM * MAX_SEN_NUM];
  250. u32 size;
  251. };
  252. struct ts_test_self_rawdata {
  253. s16 data[MAX_DRV_NUM + MAX_SEN_NUM];
  254. u32 size;
  255. };
  256. struct ts_short_res {
  257. u8 short_num;
  258. s16 short_msg[4 * MAX_SHORT_NUM];
  259. };
  260. struct ts_open_res {
  261. u8 beyond_max_limit_cnt[MAX_DRV_NUM * MAX_SEN_NUM];
  262. u8 beyond_min_limit_cnt[MAX_DRV_NUM * MAX_SEN_NUM];
  263. u8 beyond_accord_limit_cnt[MAX_DRV_NUM * MAX_SEN_NUM];
  264. };
  265. struct goodix_ts_test {
  266. struct goodix_ts_core *ts;
  267. struct ts_test_params test_params;
  268. struct ts_test_rawdata rawdata[TOTAL_FRAME_NUM];
  269. struct ts_test_rawdata accord_arr[TOTAL_FRAME_NUM];
  270. struct ts_test_rawdata noisedata[NOISEDATA_TEST_TIMES];
  271. struct goodix_ic_config test_config;
  272. struct ts_test_self_rawdata self_rawdata;
  273. struct ts_test_self_rawdata self_noisedata;
  274. struct ts_short_res short_res;
  275. struct ts_open_res open_res;
  276. /*[0][0][0][0][0].. 0 without test; 1 pass, 2 panel failed; 3 software failed */
  277. char test_result[MAX_TEST_ITEMS];
  278. char test_info[TS_RAWDATA_RESULT_MAX];
  279. };
  280. static int cal_cha_to_cha_res(struct goodix_ts_test *ts_test, int v1, int v2)
  281. {
  282. if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
  283. return (v1 - v2) * 63 / v2;
  284. else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
  285. return (v1 - v2) * 74 / v2 + 20;
  286. else
  287. return (v1 / v2 - 1) * 70 + 59;
  288. }
  289. static int cal_cha_to_avdd_res(struct goodix_ts_test *ts_test, int v1, int v2)
  290. {
  291. if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
  292. return 64 * (2 * v2 - 25) * 40 / v1 - 40;
  293. else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
  294. return 64 * (2 * v2 - 25) * 99 / v1 - 60;
  295. else
  296. return 64 * (2 * v2 - 25) * 93 / v1 - 20;
  297. }
  298. static int cal_cha_to_gnd_res(struct goodix_ts_test *ts_test, int v)
  299. {
  300. if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
  301. return 64148 / v - 40;
  302. else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
  303. return 150500 / v - 60;
  304. else
  305. return 145000 / v - 15;
  306. }
  307. static int ts_test_reset(struct goodix_ts_test *ts_test, u32 delay_ms)
  308. {
  309. return ts_test->ts->hw_ops->reset(ts_test->ts, delay_ms);
  310. }
  311. static int ts_test_read(struct goodix_ts_test *ts_test,
  312. u32 addr, u8 *data, u32 len)
  313. {
  314. return ts_test->ts->hw_ops->read(ts_test->ts, addr, data, len);
  315. }
  316. static int ts_test_write(struct goodix_ts_test *ts_test,
  317. u32 addr, u8 *data, u32 len)
  318. {
  319. return ts_test->ts->hw_ops->write(ts_test->ts, addr, data, len);
  320. }
  321. static int ts_test_send_cmd(struct goodix_ts_test *ts_test,
  322. struct goodix_ts_cmd *cmd)
  323. {
  324. return ts_test->ts->hw_ops->send_cmd(ts_test->ts, cmd);
  325. }
  326. static int ts_test_irq_enable(struct goodix_ts_test *ts_test, bool flag)
  327. {
  328. return ts_test->ts->hw_ops->irq_enable(ts_test->ts, flag);
  329. }
  330. static int ts_test_send_config(struct goodix_ts_test *ts_test, int type)
  331. {
  332. struct goodix_ic_config *cfg;
  333. if (type >= GOODIX_MAX_CONFIG_GROUP) {
  334. ts_err("unsupproted config type %d", type);
  335. return -EINVAL;
  336. }
  337. cfg = ts_test->ts->ic_configs[type];
  338. if (!cfg || cfg->len <= 0) {
  339. ts_err("no valid normal config found");
  340. return -EINVAL;
  341. }
  342. return ts_test->ts->hw_ops->send_config(ts_test->ts, cfg->data, cfg->len);
  343. }
  344. static int ts_test_read_version(struct goodix_ts_test *ts_test,
  345. struct goodix_fw_version *version)
  346. {
  347. return ts_test->ts->hw_ops->read_version(ts_test->ts, version);
  348. }
  349. static void goto_next_line(char **ptr)
  350. {
  351. do {
  352. *ptr = *ptr + 1;
  353. } while (**ptr != '\n' && **ptr != '\0');
  354. if (**ptr == '\0')
  355. return;
  356. *ptr = *ptr + 1;
  357. }
  358. static void copy_this_line(char *dest, char *src)
  359. {
  360. char *copy_from;
  361. char *copy_to;
  362. copy_from = src;
  363. copy_to = dest;
  364. do {
  365. *copy_to = *copy_from;
  366. copy_from++;
  367. copy_to++;
  368. } while((*copy_from != '\n') && (*copy_from != '\r') && (*copy_from != '\0'));
  369. *copy_to = '\0';
  370. }
  371. static int getrid_space(s8* data, s32 len)
  372. {
  373. u8* buf = NULL;
  374. s32 i;
  375. u32 count = 0;
  376. buf = (char*)kzalloc(len + 5, GFP_KERNEL);
  377. if (!buf) {
  378. ts_err("get space kzalloc error");
  379. return -ESRCH;
  380. }
  381. for (i = 0; i < len; i++) {
  382. if (data[i] == ' ' || data[i] == '\r' || data[i] == '\n')
  383. continue;
  384. buf[count++] = data[i];
  385. }
  386. buf[count++] = '\0';
  387. memcpy(data, buf, count);
  388. kfree(buf);
  389. return count;
  390. }
  391. static int parse_valid_data(char *buf_start, loff_t buf_size,
  392. char *ptr, s32 *data, s32 rows)
  393. {
  394. int i = 0;
  395. int j = 0;
  396. char *token = NULL;
  397. char *tok_ptr = NULL;
  398. char *row_data = NULL;
  399. long temp_val;
  400. if (!ptr) {
  401. ts_err("ptr is NULL");
  402. return -EINVAL;
  403. }
  404. if (!data) {
  405. ts_err("data is NULL");
  406. return -EINVAL;
  407. }
  408. row_data = (char *)kzalloc(MAX_LINE_LEN, GFP_KERNEL);
  409. if (!row_data) {
  410. ts_err("alloc bytes %d failed.", MAX_LINE_LEN);
  411. return -ENOMEM;
  412. }
  413. for (i = 0; i < rows; i++) {
  414. memset(row_data, 0, MAX_LINE_LEN);
  415. copy_this_line(row_data, ptr);
  416. getrid_space(row_data, strlen(row_data));
  417. tok_ptr = row_data;
  418. while ((token = strsep(&tok_ptr,","))) {
  419. if (strlen(token) == 0)
  420. continue;
  421. if (kstrtol(token, 0, &temp_val)) {
  422. kfree(row_data);
  423. return -EINVAL;
  424. }
  425. data[j++] = (s32)temp_val;
  426. }
  427. if (i == rows - 1)
  428. break;
  429. goto_next_line(&ptr); //next row
  430. if(!ptr || (strlen(ptr) == 0) || (ptr >= (buf_start + buf_size))) {
  431. ts_info("invalid ptr, return");
  432. kfree(row_data);
  433. row_data = NULL;
  434. return -EPERM;
  435. }
  436. }
  437. kfree(row_data);
  438. return j;
  439. }
  440. static int parse_csvfile(char *buf, size_t size, char *target_name,
  441. s32 *data, s32 rows, s32 col)
  442. {
  443. int ret = 0;
  444. char *ptr = NULL;
  445. int read_ret;
  446. read_ret = size;
  447. if (read_ret > 0) {
  448. ptr = buf;
  449. ptr = strstr(ptr, target_name);
  450. if (!ptr) {
  451. ts_info("load %s failed 1, maybe not this item", target_name);
  452. return -EINTR;
  453. }
  454. goto_next_line(&ptr);
  455. if (!ptr || (strlen(ptr) == 0 )) {
  456. ts_err("load %s failed 2!", target_name);
  457. return -EIO;
  458. }
  459. if (data) {
  460. ret = parse_valid_data(buf, size, ptr, data, rows);
  461. } else {
  462. ts_err("load %s failed 3!", target_name);
  463. return -EINTR;
  464. }
  465. } else {
  466. ts_err("ret=%d, read_ret=%d", ret, read_ret);
  467. ret = -ENXIO;
  468. }
  469. return ret;
  470. }
  471. static void goodix_init_params(struct goodix_ts_test *ts_test)
  472. {
  473. struct goodix_ts_core *ts = ts_test->ts;
  474. struct ts_test_params *test_params = &ts_test->test_params;
  475. test_params->rawdata_addr = ts->ic_info.misc.mutual_rawdata_addr;
  476. test_params->noisedata_addr = ts->ic_info.misc.mutual_diffdata_addr;
  477. test_params->self_rawdata_addr = ts->ic_info.misc.self_rawdata_addr;
  478. test_params->self_noisedata_addr = ts->ic_info.misc.self_diffdata_addr;
  479. test_params->drv_num = ts->ic_info.parm.drv_num;
  480. test_params->sen_num = ts->ic_info.parm.sen_num;
  481. if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A)
  482. test_params->params_info = &params_bra;
  483. else if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_B)
  484. test_params->params_info = &params_brb;
  485. else
  486. test_params->params_info = &params_brd;
  487. }
  488. static int goodix_init_testlimits(struct goodix_ts_test *ts_test)
  489. {
  490. int ret;
  491. int i;
  492. u32 data_buf[10] = {0};
  493. char *temp_buf = NULL;
  494. struct ts_test_params *test_params = &ts_test->test_params;
  495. struct goodix_ts_core *ts_core = ts_test->ts;
  496. const struct firmware *firmware = NULL;
  497. struct device *dev = &ts_core->pdev->dev;
  498. char limit_file[100] = {0};
  499. u32 tx = test_params->drv_num;
  500. u32 rx = test_params->sen_num;
  501. scnprintf(limit_file, ARRAY_SIZE(limit_file), "%s_test_limits_%d.csv",
  502. GOODIX_TEST_FILE_NAME, ts_core->fw_version.sensor_id);
  503. ts_info("limit_file_name:%s", limit_file);
  504. ret = request_firmware(&firmware, limit_file, dev);
  505. if (ret < 0) {
  506. ts_err("limits file [%s] not available", limit_file);
  507. return -EINVAL;
  508. }
  509. if (!firmware) {
  510. ts_err("request_firmware failed");
  511. return -EINVAL;
  512. }
  513. if (firmware->size <= 0) {
  514. ts_err("request_firmware, limits param length error,len:%zu",
  515. firmware->size);
  516. ret = -EINVAL;
  517. goto exit_free;
  518. }
  519. temp_buf = kzalloc(firmware->size + 1, GFP_KERNEL);
  520. if (!temp_buf) {
  521. ts_err("kzalloc bytes failed.");
  522. ret = -ENOMEM;
  523. goto exit_free;
  524. }
  525. memcpy(temp_buf, firmware->data, firmware->size);
  526. /* obtain config data */
  527. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_TEST_CONFIG,
  528. test_params->cfg_buf, 1, GOODIX_CFG_MAX_SIZE);
  529. if (ret < 0) {
  530. ts_info("Can't find %s", CSV_TP_TEST_CONFIG);
  531. } else {
  532. ts_info("parse_csvfile %s OK, cfg_len:%d", CSV_TP_TEST_CONFIG, ret);
  533. for (i = 0; i < ret; i++)
  534. ts_test->test_config.data[i] = (u8)test_params->cfg_buf[i];
  535. ts_test->test_config.len = ret;
  536. }
  537. /* obtain mutual_raw min */
  538. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_RAW_MIN,
  539. test_params->min_limits, rx, tx);
  540. if (ret < 0) {
  541. ts_err("Failed get min_limits");
  542. goto exit_free;
  543. } else
  544. ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_RAW_MIN);
  545. /* obtain mutual_raw max */
  546. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_RAW_MAX,
  547. test_params->max_limits, rx, tx);
  548. if (ret < 0) {
  549. ts_err("Failed get max_limits");
  550. goto exit_free;
  551. } else
  552. ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_RAW_MAX);
  553. /* obtain delta limit */
  554. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_RAW_DELTA,
  555. test_params->deviation_limits, rx, tx);
  556. if (ret < 0) {
  557. ts_err("Failed get delta limit");
  558. goto exit_free;
  559. } else {
  560. ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_RAW_DELTA);
  561. }
  562. /* obtain self_raw min */
  563. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_SELFRAW_MIN,
  564. test_params->self_min_limits, 1, tx + rx);
  565. /* obtain self_raw max */
  566. ret |= parse_csvfile(temp_buf, firmware->size, CSV_TP_SPECIAL_SELFRAW_MAX,
  567. test_params->self_max_limits, 1, tx + rx);
  568. if (ret < 0) {
  569. ts_info("Can't find self_min_max_limits, ship this item");
  570. ret = 0;
  571. test_params->test_items[GTP_SELFCAP_TEST] = false;
  572. } else {
  573. ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_SELFRAW_MIN);
  574. ts_info("parse_csvfile %s OK", CSV_TP_SPECIAL_SELFRAW_MAX);
  575. test_params->test_items[GTP_SELFCAP_TEST] = true;
  576. }
  577. /* obtain noise_threshold */
  578. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_NOISE_LIMIT,
  579. &test_params->noise_threshold, 1, 1);
  580. if (ret < 0) {
  581. ts_info("Can't find noise_threshold, skip this item");
  582. ret = 0;
  583. test_params->test_items[GTP_NOISE_TEST] = false;
  584. } else {
  585. ts_info("parse_csvfile %s OK", CSV_TP_NOISE_LIMIT);
  586. test_params->test_items[GTP_NOISE_TEST] = true;
  587. }
  588. /* obtain self_noise_threshold */
  589. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SELFNOISE_LIMIT,
  590. &test_params->self_noise_threshold, 1, 1);
  591. if (ret < 0) {
  592. ts_info("Can't find self_noise_threshold, skip this item");
  593. ret = 0;
  594. test_params->test_items[GTP_SELFNOISE_TEST] = false;
  595. } else {
  596. ts_info("parse_csvfile %s OK", CSV_TP_SELFNOISE_LIMIT);
  597. test_params->test_items[GTP_SELFNOISE_TEST] = true;
  598. }
  599. /* obtain short_params */
  600. ret = parse_csvfile(temp_buf, firmware->size, CSV_TP_SHORT_THRESHOLD,
  601. (s32 *)data_buf, 1, 7);
  602. if (ret < 0) {
  603. ts_info("Can't find short shortciurt_threshold, skip this item");
  604. ret = 0;
  605. test_params->test_items[GTP_SHORT_TEST] = false;
  606. } else {
  607. ts_info("parse_csvfile %s OK", CSV_TP_SHORT_THRESHOLD);
  608. test_params->test_items[GTP_SHORT_TEST] = true;
  609. test_params->short_threshold = data_buf[0];
  610. test_params->r_drv_drv_threshold = data_buf[1];
  611. test_params->r_drv_sen_threshold = data_buf[2];
  612. test_params->r_sen_sen_threshold = data_buf[3];
  613. test_params->r_drv_gnd_threshold = data_buf[4];
  614. test_params->r_sen_gnd_threshold = data_buf[5];
  615. test_params->avdd_value = data_buf[6];
  616. }
  617. exit_free:
  618. kfree(temp_buf);
  619. release_firmware(firmware);
  620. return ret;
  621. }
  622. static int goodix_tptest_prepare(struct goodix_ts_test *ts_test)
  623. {
  624. int ret;
  625. struct goodix_ic_config *cfg = &ts_test->test_config;
  626. ts_info("TP test prepare IN");
  627. goodix_init_params(ts_test);
  628. /* parse test limits from csv */
  629. ret = goodix_init_testlimits(ts_test);
  630. if (ret < 0) {
  631. ts_err("Failed to init testlimits from csv.");
  632. return ret;
  633. }
  634. /* disable irq */
  635. ts_test_irq_enable(ts_test, false);
  636. /* close esd */
  637. goodix_ts_blocking_notify(NOTIFY_ESD_OFF, NULL);
  638. /* send test config if exist */
  639. if (cfg->len > 0) {
  640. ts_info("Test config exists and send it");
  641. ret = ts_test->ts->hw_ops->send_config(ts_test->ts, cfg->data, cfg->len);
  642. if (ret < 0) {
  643. ts_err("Send test config failed, exit");
  644. goodix_ts_blocking_notify(NOTIFY_ESD_ON, NULL);
  645. ts_test_irq_enable(ts_test, true);
  646. return ret;
  647. }
  648. }
  649. return 0;
  650. }
  651. static void goodix_tptest_finish(struct goodix_ts_test *ts_test)
  652. {
  653. ts_info("TP test finish IN");
  654. /* reset chip */
  655. ts_test_reset(ts_test, 100);
  656. /* send normal config */
  657. if (ts_test->test_config.len > 0) {
  658. if (ts_test_send_config(ts_test, CONFIG_TYPE_NORMAL))
  659. ts_err("Send normal config failed");
  660. }
  661. /* open esd */
  662. goodix_ts_blocking_notify(NOTIFY_ESD_ON, NULL);
  663. /* enable irq */
  664. ts_test_irq_enable(ts_test, true);
  665. }
  666. #define SHORT_TEST_RUN_REG 0x10400
  667. #define SHORT_TEST_RUN_FLAG 0xAA
  668. #define INSPECT_FW_SWITCH_CMD 0x85
  669. #define TEST_FW_PID "OST"
  670. static int goodix_short_test_prepare(struct goodix_ts_test *ts_test)
  671. {
  672. struct goodix_ts_cmd tmp_cmd;
  673. struct goodix_fw_version fw_ver;
  674. int ret;
  675. int retry;
  676. int resend = 3;
  677. u8 status;
  678. ts_info("short test prepare IN");
  679. ts_test->test_result[GTP_SHORT_TEST] = SYS_SOFTWARE_REASON;
  680. tmp_cmd.len = 4;
  681. tmp_cmd.cmd = INSPECT_FW_SWITCH_CMD;
  682. resend_cmd:
  683. ret = ts_test_send_cmd(ts_test, &tmp_cmd);
  684. if (ret < 0) {
  685. ts_err("send test mode failed");
  686. return ret;
  687. }
  688. retry = 3;
  689. while (retry--) {
  690. msleep(40);
  691. if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_A) {
  692. ret = ts_test_read_version(ts_test, &fw_ver);
  693. if (ret < 0) {
  694. ts_err("read test version failed");
  695. return ret;
  696. }
  697. ret = memcmp(&(fw_ver.patch_pid[3]), TEST_FW_PID, strlen(TEST_FW_PID));
  698. if (ret == 0)
  699. return 0;
  700. ts_info("patch ID dismatch %s != %s", fw_ver.patch_pid, TEST_FW_PID);
  701. } else {
  702. ret = ts_test_read(ts_test, SHORT_TEST_RUN_REG, &status, 1);
  703. if (!ret && status == SHORT_TEST_RUN_FLAG)
  704. return 0;
  705. ts_info("short_mode_status=0x%02x ret=%d", status, ret);
  706. }
  707. }
  708. if (resend--) {
  709. ts_test_reset(ts_test, 100);
  710. goto resend_cmd;
  711. }
  712. return -EINVAL;
  713. }
  714. static u32 map_die2pin(struct ts_test_params *test_params, u32 chn_num)
  715. {
  716. int i = 0;
  717. u32 res = 255;
  718. if (chn_num & DRV_CHANNEL_FLAG)
  719. chn_num = (chn_num & ~DRV_CHANNEL_FLAG) + test_params->params_info->max_sen_num;
  720. for (i = 0; i < test_params->params_info->max_sen_num; i++) {
  721. if (test_params->params_info->sen_map[i] == chn_num) {
  722. res = i;
  723. break;
  724. }
  725. }
  726. /* res != 255 mean found the corresponding channel num */
  727. if (res != 255)
  728. return res;
  729. /* if cannot find in SenMap try find in DrvMap */
  730. for (i = 0; i < test_params->params_info->max_drv_num; i++) {
  731. if (test_params->params_info->drv_map[i] == chn_num) {
  732. res = i;
  733. break;
  734. }
  735. }
  736. if (i >= test_params->params_info->max_drv_num)
  737. ts_err("Faild found corrresponding channel num:%d", chn_num);
  738. else
  739. res |= DRV_CHANNEL_FLAG;
  740. return res;
  741. }
  742. static void goodix_save_short_res(struct ts_test_params *params,
  743. u16 chn1, u16 chn2, int r)
  744. {
  745. int i;
  746. u8 repeat_cnt = 0;
  747. u8 repeat = 0;
  748. struct goodix_ts_test *ts_test = container_of(params,
  749. struct goodix_ts_test, test_params);
  750. struct ts_short_res *short_res = &ts_test->short_res;
  751. if (chn1 == chn2 || short_res->short_num >= MAX_SHORT_NUM)
  752. return;
  753. for (i = 0; i < short_res->short_num; i++) {
  754. repeat_cnt = 0;
  755. if (short_res->short_msg[4 * i] == chn1)
  756. repeat_cnt++;
  757. if (short_res->short_msg[4 * i] == chn2)
  758. repeat_cnt++;
  759. if (short_res->short_msg[4 * i + 1] == chn1)
  760. repeat_cnt++;
  761. if (short_res->short_msg[4 * i + 1] == chn2)
  762. repeat_cnt++;
  763. if (repeat_cnt >= 2){
  764. repeat = 1;
  765. break;
  766. }
  767. }
  768. if (repeat == 0) {
  769. short_res->short_msg[4 * short_res->short_num + 0] = chn1;
  770. short_res->short_msg[4 * short_res->short_num + 1] = chn2;
  771. short_res->short_msg[4 * short_res->short_num + 2] = (r >> 8) & 0xFF;
  772. short_res->short_msg[4 * short_res->short_num + 3] = r & 0xFF;
  773. if (short_res->short_num < MAX_SHORT_NUM)
  774. short_res->short_num++;
  775. }
  776. }
  777. static int gdix_check_tx_tx_shortcircut(struct goodix_ts_test *ts_test,
  778. u8 short_ch_num)
  779. {
  780. int ret = 0, err = 0;
  781. u32 r_threshold = 0, short_r = 0;
  782. int size = 0, i = 0, j = 0;
  783. u16 adc_signal = 0;
  784. u8 master_pin_num, slave_pin_num;
  785. u8 *data_buf;
  786. u32 data_reg;
  787. struct ts_test_params *test_params = &ts_test->test_params;
  788. int max_drv_num = test_params->params_info->max_drv_num;
  789. int max_sen_num = test_params->params_info->max_sen_num;
  790. u16 self_capdata, short_die_num = 0;
  791. size = 4 + max_drv_num * 2 + 2;
  792. data_buf = kzalloc(size, GFP_KERNEL);
  793. if (!data_buf) {
  794. ts_err("Failed to alloc memory");
  795. return -ENOMEM;
  796. }
  797. /* drv&drv shortcircut check */
  798. data_reg = test_params->params_info->drv_drv_selfcode_reg;
  799. for (i = 0; i < short_ch_num; i++) {
  800. ret = ts_test_read(ts_test, data_reg, data_buf, size);
  801. if (ret < 0) {
  802. ts_err("Failed read Drv-to-Drv short rawdata");
  803. err = -EINVAL;
  804. break;
  805. }
  806. if (checksum_cmp(data_buf, size, CHECKSUM_MODE_U8_LE)) {
  807. ts_err("Drv-to-Drv adc data checksum error");
  808. err = -EINVAL;
  809. break;
  810. }
  811. r_threshold = test_params->r_drv_drv_threshold;
  812. short_die_num = le16_to_cpup((__le16 *)&data_buf[0]);
  813. short_die_num -= max_sen_num;
  814. if (short_die_num >= max_drv_num) {
  815. ts_info("invalid short pad num:%d",
  816. short_die_num + max_sen_num);
  817. continue;
  818. }
  819. /* TODO: j start position need recheck */
  820. self_capdata = le16_to_cpup((__le16 *)&data_buf[2]);
  821. if (self_capdata == 0xffff || self_capdata == 0) {
  822. ts_info("invalid self_capdata:0x%x", self_capdata);
  823. continue;
  824. }
  825. for (j = short_die_num + 1; j < max_drv_num; j++) {
  826. adc_signal = le16_to_cpup((__le16 *)&data_buf[4 + j * 2]);
  827. if (adc_signal < test_params->short_threshold)
  828. continue;
  829. short_r = (u32)cal_cha_to_cha_res(ts_test, self_capdata, adc_signal);
  830. if (short_r < r_threshold) {
  831. master_pin_num =
  832. map_die2pin(test_params, short_die_num + max_sen_num);
  833. slave_pin_num =
  834. map_die2pin(test_params, j + max_sen_num);
  835. if (master_pin_num == 0xFF || slave_pin_num == 0xFF) {
  836. ts_info("WARNNING invalid pin");
  837. continue;
  838. }
  839. goodix_save_short_res(test_params, master_pin_num,
  840. slave_pin_num, short_r);
  841. ts_err("short circut:R=%dK,R_Threshold=%dK",
  842. short_r, r_threshold);
  843. ts_err("%s%d--%s%d shortcircut",
  844. (master_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
  845. (master_pin_num & ~DRV_CHANNEL_FLAG),
  846. (slave_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
  847. (slave_pin_num & ~DRV_CHANNEL_FLAG));
  848. err = -EINVAL;
  849. }
  850. }
  851. data_reg += size;
  852. }
  853. kfree(data_buf);
  854. return err;
  855. }
  856. static int gdix_check_rx_rx_shortcircut(struct goodix_ts_test *ts_test,
  857. u8 short_ch_num)
  858. {
  859. int ret = 0, err = 0;
  860. u32 r_threshold = 0, short_r = 0;
  861. int size = 0, i = 0, j = 0;
  862. u16 adc_signal = 0;
  863. u8 master_pin_num, slave_pin_num;
  864. u8 *data_buf;
  865. u32 data_reg;
  866. struct ts_test_params *test_params = &ts_test->test_params;
  867. int max_sen_num = test_params->params_info->max_sen_num;
  868. u16 self_capdata, short_die_num = 0;
  869. size = 4 + max_sen_num * 2 + 2;
  870. data_buf = kzalloc(size, GFP_KERNEL);
  871. if (!data_buf) {
  872. ts_err("Failed to alloc memory");
  873. return -ENOMEM;
  874. }
  875. /* drv&drv shortcircut check */
  876. data_reg = test_params->params_info->sen_sen_selfcode_reg;
  877. for (i = 0; i < short_ch_num; i++) {
  878. ret = ts_test_read(ts_test, data_reg, data_buf, size);
  879. if (ret) {
  880. ts_err("Failed read Sen-to-Sen short rawdata");
  881. err = -EINVAL;
  882. break;
  883. }
  884. if (checksum_cmp(data_buf, size, CHECKSUM_MODE_U8_LE)) {
  885. ts_err("Sen-to-Sen adc data checksum error");
  886. err = -EINVAL;
  887. break;
  888. }
  889. r_threshold = test_params->r_sen_sen_threshold;
  890. short_die_num = le16_to_cpup((__le16 *)&data_buf[0]);
  891. if (short_die_num >= max_sen_num) {
  892. ts_info("invalid short pad num:%d", short_die_num);
  893. continue;
  894. }
  895. /* TODO: j start position need recheck */
  896. self_capdata = le16_to_cpup((__le16 *)&data_buf[2]);
  897. if (self_capdata == 0xffff || self_capdata == 0) {
  898. ts_info("invalid self_capdata:0x%x", self_capdata);
  899. continue;
  900. }
  901. for (j = short_die_num + 1; j < max_sen_num; j++) {
  902. adc_signal = le16_to_cpup((__le16 *)&data_buf[4 + j * 2]);
  903. if (adc_signal < test_params->short_threshold)
  904. continue;
  905. short_r = (u32)cal_cha_to_cha_res(ts_test, self_capdata, adc_signal);
  906. if (short_r < r_threshold) {
  907. master_pin_num = map_die2pin(test_params, short_die_num);
  908. slave_pin_num = map_die2pin(test_params, j);
  909. if (master_pin_num == 0xFF || slave_pin_num == 0xFF) {
  910. ts_info("WARNNING invalid pin");
  911. continue;
  912. }
  913. goodix_save_short_res(test_params, master_pin_num,
  914. slave_pin_num, short_r);
  915. ts_err("short circut:R=%dK,R_Threshold=%dK",
  916. short_r, r_threshold);
  917. ts_err("%s%d--%s%d shortcircut",
  918. (master_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
  919. (master_pin_num & ~DRV_CHANNEL_FLAG),
  920. (slave_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
  921. (slave_pin_num & ~DRV_CHANNEL_FLAG));
  922. err = -EINVAL;
  923. }
  924. }
  925. data_reg += size;
  926. }
  927. kfree(data_buf);
  928. return err;
  929. }
  930. static int gdix_check_tx_rx_shortcircut(struct goodix_ts_test *ts_test,
  931. u8 short_ch_num)
  932. {
  933. int ret = 0, err = 0;
  934. u32 r_threshold = 0, short_r = 0;
  935. int size = 0, i = 0, j = 0;
  936. u16 adc_signal = 0;
  937. u8 master_pin_num, slave_pin_num;
  938. u8 *data_buf = NULL;
  939. u32 data_reg;
  940. struct ts_test_params *test_params = &ts_test->test_params;
  941. int max_drv_num = test_params->params_info->max_drv_num;
  942. int max_sen_num = test_params->params_info->max_sen_num;
  943. u16 self_capdata, short_die_num = 0;
  944. size = 4 + max_drv_num * 2 + 2;
  945. data_buf = kzalloc(size, GFP_KERNEL);
  946. if (!data_buf) {
  947. ts_err("Failed to alloc memory");
  948. return -ENOMEM;
  949. }
  950. /* drv&sen shortcircut check */
  951. data_reg = test_params->params_info->drv_sen_selfcode_reg;
  952. for (i = 0; i < short_ch_num; i++) {
  953. ret = ts_test_read(ts_test, data_reg, data_buf, size);
  954. if (ret) {
  955. ts_err("Failed read Drv-to-Sen short rawdata");
  956. err = -EINVAL;
  957. break;
  958. }
  959. if (checksum_cmp(data_buf, size, CHECKSUM_MODE_U8_LE)) {
  960. ts_err("Drv-to-Sen adc data checksum error");
  961. err = -EINVAL;
  962. break;
  963. }
  964. r_threshold = test_params->r_drv_sen_threshold;
  965. short_die_num = le16_to_cpup((__le16 *)&data_buf[0]);
  966. if (short_die_num >= max_sen_num) {
  967. ts_info("invalid short pad num:%d", short_die_num);
  968. continue;
  969. }
  970. /* TODO: j start position need recheck */
  971. self_capdata = le16_to_cpup((__le16 *)&data_buf[2]);
  972. if (self_capdata == 0xffff || self_capdata == 0) {
  973. ts_info("invalid self_capdata:0x%x", self_capdata);
  974. continue;
  975. }
  976. for (j = 0; j < max_drv_num; j++) {
  977. adc_signal = le16_to_cpup((__le16 *)&data_buf[4 + j * 2]);
  978. if (adc_signal < test_params->short_threshold)
  979. continue;
  980. short_r = (u32)cal_cha_to_cha_res(ts_test, self_capdata, adc_signal);
  981. if (short_r < r_threshold) {
  982. master_pin_num = map_die2pin(test_params, short_die_num);
  983. slave_pin_num = map_die2pin(test_params, j + max_sen_num);
  984. if (master_pin_num == 0xFF || slave_pin_num == 0xFF) {
  985. ts_info("WARNNING invalid pin");
  986. continue;
  987. }
  988. goodix_save_short_res(test_params, master_pin_num,
  989. slave_pin_num, short_r);
  990. ts_err("short circut:R=%dK,R_Threshold=%dK",
  991. short_r, r_threshold);
  992. ts_err("%s%d--%s%d shortcircut",
  993. (master_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
  994. (master_pin_num & ~DRV_CHANNEL_FLAG),
  995. (slave_pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
  996. (slave_pin_num & ~DRV_CHANNEL_FLAG));
  997. err = -EINVAL;
  998. }
  999. }
  1000. data_reg += size;
  1001. }
  1002. kfree(data_buf);
  1003. return err;
  1004. }
  1005. static int gdix_check_resistance_to_gnd(struct ts_test_params *test_params,
  1006. u16 adc_signal, u32 pos)
  1007. {
  1008. long r = 0;
  1009. u16 r_th = 0, avdd_value = 0;
  1010. u16 chn_id_tmp = 0;
  1011. u8 pin_num = 0;
  1012. unsigned short short_type;
  1013. struct goodix_ts_test *ts_test = container_of(test_params,
  1014. struct goodix_ts_test, test_params);
  1015. int max_drv_num = test_params->params_info->max_drv_num;
  1016. int max_sen_num = test_params->params_info->max_sen_num;
  1017. avdd_value = test_params->avdd_value;
  1018. short_type = adc_signal & 0x8000;
  1019. adc_signal &= ~0x8000;
  1020. if (adc_signal == 0)
  1021. adc_signal = 1;
  1022. if (short_type == 0) {
  1023. /* short to GND */
  1024. r = cal_cha_to_gnd_res(ts_test, adc_signal);
  1025. } else {
  1026. /* short to VDD */
  1027. r = cal_cha_to_avdd_res(ts_test, adc_signal, avdd_value);
  1028. }
  1029. if (pos < max_drv_num)
  1030. r_th = test_params->r_drv_gnd_threshold;
  1031. else
  1032. r_th = test_params->r_sen_gnd_threshold;
  1033. chn_id_tmp = pos;
  1034. if (chn_id_tmp < max_drv_num)
  1035. chn_id_tmp += max_sen_num;
  1036. else
  1037. chn_id_tmp -= max_drv_num;
  1038. if (r < r_th) {
  1039. pin_num = map_die2pin(test_params, chn_id_tmp);
  1040. goodix_save_short_res(test_params, pin_num,
  1041. short_type ? CHN_VDD : CHN_GND, r);
  1042. ts_err("%s%d shortcircut to %s,R=%ldK,R_Threshold=%dK",
  1043. (pin_num & DRV_CHANNEL_FLAG) ? "DRV" : "SEN",
  1044. (pin_num & ~DRV_CHANNEL_FLAG),
  1045. short_type ? "VDD" : "GND",
  1046. r, r_th);
  1047. return -EINVAL;
  1048. }
  1049. return 0;
  1050. }
  1051. static int gdix_check_gndvdd_shortcircut(struct goodix_ts_test *ts_test)
  1052. {
  1053. int ret = 0, err = 0;
  1054. int size = 0, i = 0;
  1055. u16 adc_signal = 0;
  1056. u32 data_reg;
  1057. u8 *data_buf = NULL;
  1058. int max_drv_num = ts_test->test_params.params_info->max_drv_num;
  1059. int max_sen_num = ts_test->test_params.params_info->max_sen_num;
  1060. size = (max_drv_num + max_sen_num) * 2 + 2;
  1061. data_buf = kzalloc(size, GFP_KERNEL);
  1062. if (!data_buf) {
  1063. ts_err("Failed to alloc memory");
  1064. return -ENOMEM;
  1065. }
  1066. /* read diff code, diff code will be used to calculate
  1067. * resistance between channel and GND */
  1068. data_reg = ts_test->test_params.params_info->diffcode_data_reg;
  1069. ret = ts_test_read(ts_test, data_reg, data_buf, size);
  1070. if (ret < 0) {
  1071. ts_err("Failed read to-gnd rawdata");
  1072. err = -EINVAL;
  1073. goto err_out;
  1074. }
  1075. if (checksum_cmp(data_buf, size, CHECKSUM_MODE_U8_LE)) {
  1076. ts_err("diff code checksum error");
  1077. err = -EINVAL;
  1078. goto err_out;
  1079. }
  1080. for (i = 0; i < max_drv_num + max_sen_num; i++) {
  1081. adc_signal = le16_to_cpup((__le16 *)&data_buf[i * 2]);
  1082. ret = gdix_check_resistance_to_gnd(&ts_test->test_params,
  1083. adc_signal, i);
  1084. if (ret != 0) {
  1085. ts_err("Resistance to-gnd/vdd short");
  1086. err = ret;
  1087. }
  1088. }
  1089. err_out:
  1090. kfree(data_buf);
  1091. return err;
  1092. }
  1093. static int goodix_shortcircut_analysis(struct goodix_ts_test *ts_test)
  1094. {
  1095. int ret;
  1096. int err = 0;
  1097. test_result_t test_result;
  1098. ret = ts_test_read(ts_test,
  1099. ts_test->test_params.params_info->short_test_result_reg,
  1100. (u8 *)&test_result, sizeof(test_result));
  1101. if (ret < 0) {
  1102. ts_err("Read TEST_RESULT_REG failed");
  1103. return ret;
  1104. }
  1105. if (checksum_cmp((u8 *)&test_result, sizeof(test_result),
  1106. CHECKSUM_MODE_U8_LE)) {
  1107. ts_err("shrot result checksum err");
  1108. return -EINVAL;
  1109. }
  1110. if (!(test_result.result & 0x0F)) {
  1111. ts_info(">>>>> No shortcircut");
  1112. return 0;
  1113. }
  1114. ts_info("short flag 0x%02x, drv&drv:%d, sen&sen:%d, drv&sen:%d, drv/GNDVDD:%d, sen/GNDVDD:%d",
  1115. test_result.result, test_result.drv_drv_num, test_result.sen_sen_num,
  1116. test_result.drv_sen_num, test_result.drv_gnd_avdd_num, test_result.sen_gnd_avdd_num);
  1117. if (test_result.drv_drv_num)
  1118. err |= gdix_check_tx_tx_shortcircut(ts_test, test_result.drv_drv_num);
  1119. if (test_result.sen_sen_num)
  1120. err |= gdix_check_rx_rx_shortcircut(ts_test, test_result.sen_sen_num);
  1121. if (test_result.drv_sen_num)
  1122. err |= gdix_check_tx_rx_shortcircut(ts_test, test_result.drv_sen_num);
  1123. if (test_result.drv_gnd_avdd_num || test_result.sen_gnd_avdd_num)
  1124. err |= gdix_check_gndvdd_shortcircut(ts_test);
  1125. ts_info(">>>>> short check return 0x%x", err);
  1126. return err;
  1127. }
  1128. #define SHORT_FW_CMD_REG 0x10400
  1129. static int send_test_cmd(struct goodix_ts_test *ts_test,
  1130. struct goodix_ts_cmd *cmd)
  1131. {
  1132. int ret;
  1133. u32 reg = SHORT_FW_CMD_REG;
  1134. cmd->state = 0;
  1135. cmd->ack = 0;
  1136. goodix_append_checksum(&(cmd->buf[2]), cmd->len - 2, CHECKSUM_MODE_U8_LE);
  1137. ret = ts_test_write(ts_test, reg, cmd->buf, cmd->len + 2);
  1138. if (ret < 0)
  1139. return ret;
  1140. usleep_range(10000, 11000);
  1141. return ret;
  1142. }
  1143. #define INSPECT_PARAM_CMD 0xAA
  1144. #define SHORT_TEST_FINISH_FLAG 0x88
  1145. #define SHORT_TEST_THRESHOLD_REG 0x20402
  1146. static void goodix_shortcircut_test(struct goodix_ts_test *ts_test)
  1147. {
  1148. int ret = 0;
  1149. int retry;
  1150. u16 test_time;
  1151. u8 status;
  1152. int ic_type = ts_test->ts->bus->ic_type;
  1153. struct goodix_ts_cmd test_parm_cmd;
  1154. // u8 test_param[6];
  1155. ts_info("---------------------- short_test begin ----------------------");
  1156. ret = goodix_short_test_prepare(ts_test);
  1157. if (ret < 0) {
  1158. ts_err("Failed enter short test mode");
  1159. return;
  1160. }
  1161. /* get short test time */
  1162. ret = ts_test_read(ts_test,
  1163. ts_test->test_params.params_info->short_test_time_reg,
  1164. (u8 *)&test_time, 2);
  1165. if (ret < 0) {
  1166. ts_err("Failed to get test_time, default %dms", DEFAULT_TEST_TIME_MS);
  1167. test_time = DEFAULT_TEST_TIME_MS;
  1168. } else {
  1169. if (ic_type == IC_TYPE_BERLIN_A)
  1170. test_time /= 10;
  1171. if (test_time > MAX_TEST_TIME_MS) {
  1172. ts_info("test time too long %d > %d",
  1173. test_time, MAX_TEST_TIME_MS);
  1174. test_time = MAX_TEST_TIME_MS;
  1175. }
  1176. ts_info("get test time %dms", test_time);
  1177. }
  1178. /* start short test */
  1179. if (ic_type == IC_TYPE_BERLIN_A) {
  1180. test_parm_cmd.len = 0x0A;
  1181. test_parm_cmd.cmd = INSPECT_PARAM_CMD;
  1182. test_parm_cmd.data[0] =
  1183. ts_test->test_params.params_info->dft_short_threshold & 0xFF;
  1184. test_parm_cmd.data[1] =
  1185. (ts_test->test_params.params_info->dft_short_threshold >> 8) & 0xFF;
  1186. test_parm_cmd.data[2] =
  1187. ts_test->test_params.params_info->short_diffcode_threshold & 0xFF;
  1188. test_parm_cmd.data[3] =
  1189. (ts_test->test_params.params_info->short_diffcode_threshold >> 8) & 0xFF;
  1190. test_parm_cmd.data[4] =
  1191. ts_test->test_params.params_info->short_test_dump_num & 0xFF;
  1192. test_parm_cmd.data[5] =
  1193. (ts_test->test_params.params_info->short_test_dump_num >> 8) & 0xFF;
  1194. ret = send_test_cmd(ts_test, &test_parm_cmd);
  1195. if (ret < 0) {
  1196. ts_err("send INSPECT_PARAM_CMD failed");
  1197. return;
  1198. }
  1199. } else {
  1200. // test_param[0] = ts_test->test_params.params_info->dft_short_threshold & 0xFF;
  1201. // test_param[1] =
  1202. // (ts_test->test_params.params_info->dft_short_threshold >> 8) & 0xFF;
  1203. // test_param[2] =
  1204. // ts_test->test_params.params_info->short_diffcode_threshold & 0xFF;
  1205. // test_param[3] =
  1206. // (ts_test->test_params.params_info->short_diffcode_threshold >> 8) & 0xFF;
  1207. // test_param[4] =
  1208. // ts_test->test_params.params_info->short_test_dump_num & 0xFF;
  1209. // test_param[5] =
  1210. // (ts_test->test_params.params_info->short_test_dump_num >> 8) & 0xFF;
  1211. // ts_test_write(ts_test, SHORT_TEST_THRESHOLD_REG,
  1212. // test_param, sizeof(test_param));
  1213. status = 0;
  1214. ts_test_write(ts_test, SHORT_TEST_RUN_REG, &status, 1);
  1215. }
  1216. /* wait short test finish */
  1217. msleep(test_time);
  1218. retry = 50;
  1219. while (retry--) {
  1220. ret = ts_test_read(ts_test,
  1221. ts_test->test_params.params_info->short_test_status_reg, &status, 1);
  1222. if (!ret && status == SHORT_TEST_FINISH_FLAG)
  1223. break;
  1224. msleep(50);
  1225. }
  1226. if (retry < 0) {
  1227. ts_err("short test failed, status:0x%02x", status);
  1228. return;
  1229. }
  1230. /* start analysis short result */
  1231. ts_info("short_test finished, start analysis");
  1232. ret = goodix_shortcircut_analysis(ts_test);
  1233. if (ret < 0)
  1234. ts_test->test_result[GTP_SHORT_TEST] = GTP_PANEL_REASON;
  1235. else
  1236. ts_test->test_result[GTP_SHORT_TEST] = GTP_TEST_PASS;
  1237. }
  1238. #define GOODIX_CMD_RAWDATA 2
  1239. #define GOODIX_TOUCH_EVENT 0x80
  1240. static int goodix_cap_test_prepare(struct goodix_ts_test *ts_test)
  1241. {
  1242. int ret;
  1243. struct goodix_ts_cmd temp_cmd;
  1244. ts_info("cap test prepare IN");
  1245. ts_test->test_result[GTP_CAP_TEST] = SYS_SOFTWARE_REASON;
  1246. ts_test->test_result[GTP_DELTA_TEST] = SYS_SOFTWARE_REASON;
  1247. if (ts_test->test_params.test_items[GTP_SELFCAP_TEST])
  1248. ts_test->test_result[GTP_SELFCAP_TEST] = SYS_SOFTWARE_REASON;
  1249. if (ts_test->test_params.test_items[GTP_NOISE_TEST])
  1250. ts_test->test_result[GTP_NOISE_TEST] = SYS_SOFTWARE_REASON;
  1251. if (ts_test->test_params.test_items[GTP_SELFNOISE_TEST])
  1252. ts_test->test_result[GTP_SELFNOISE_TEST] = SYS_SOFTWARE_REASON;
  1253. /* switch rawdata mode */
  1254. if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_D) {
  1255. temp_cmd.cmd = 0x90;
  1256. temp_cmd.data[0] = 0x81;
  1257. temp_cmd.len = 5;
  1258. } else {
  1259. temp_cmd.cmd = GOODIX_CMD_RAWDATA;
  1260. temp_cmd.len = 4;
  1261. }
  1262. ret = ts_test_send_cmd(ts_test, &temp_cmd);
  1263. if (ret < 0)
  1264. ts_err("Enter rawdata mode failed");
  1265. return ret;
  1266. }
  1267. static int goodix_cap_test_finish(struct goodix_ts_test *ts_test)
  1268. {
  1269. ts_info("cap_test finished");
  1270. /* switch coor mode */
  1271. ts_test_reset(ts_test, 100);
  1272. return 0;
  1273. }
  1274. static int goodix_cache_rawdata(struct goodix_ts_test *ts_test)
  1275. {
  1276. int ret;
  1277. int i;
  1278. int retry;
  1279. u8 val;
  1280. unsigned char frame_buf[GOODIX_MAX_FRAMEDATA_LEN];
  1281. struct frame_head *frame_head;
  1282. struct goodix_ts_core *cd = ts_test->ts;
  1283. unsigned char *cur_ptr;
  1284. u32 sen_num = ts_test->test_params.sen_num;
  1285. u32 drv_num = ts_test->test_params.drv_num;
  1286. u32 data_size = sen_num * drv_num;
  1287. u32 data_addr = ts_test->test_params.rawdata_addr;
  1288. u32 flag_addr = ts_test->ts->ic_info.misc.touch_data_addr;
  1289. if (ts_test->ts->bus->ic_type == IC_TYPE_BERLIN_D)
  1290. flag_addr = ts_test->ts->ic_info.misc.frame_data_addr;
  1291. for (i = 0; i < TOTAL_FRAME_NUM; i++) {
  1292. val = 0;
  1293. ret = ts_test_write(ts_test, flag_addr, &val, 1);
  1294. if (ret < 0) {
  1295. ts_err("clean touch event failed, exit");
  1296. return -EAGAIN;
  1297. }
  1298. retry = 20;
  1299. while (retry--) {
  1300. usleep_range(5000, 5100);
  1301. ret = ts_test_read(ts_test, flag_addr, &val, 1);
  1302. if (!ret && (val & 0x80))
  1303. break;
  1304. }
  1305. if (retry < 0) {
  1306. ts_err("rawdata is not ready val:0x%02x i:%d, exit", val, i);
  1307. return -EAGAIN;
  1308. }
  1309. if (cd->bus->ic_type == IC_TYPE_BERLIN_D) {
  1310. ret = ts_test_read(ts_test, flag_addr, frame_buf, sizeof(frame_buf));
  1311. if (ret < 0)
  1312. return ret;
  1313. if (checksum_cmp(frame_buf,
  1314. cd->ic_info.misc.frame_data_head_len, CHECKSUM_MODE_U8_LE)) {
  1315. ts_err("frame head checksum error");
  1316. return -EINVAL;
  1317. }
  1318. frame_head = (struct frame_head *)frame_buf;
  1319. if (checksum_cmp(frame_buf,
  1320. frame_head->cur_frame_len, CHECKSUM_MODE_U16_LE)) {
  1321. ts_err("frame body checksum error");
  1322. return -EINVAL;
  1323. }
  1324. cur_ptr = frame_buf;
  1325. cur_ptr += cd->ic_info.misc.frame_data_head_len;
  1326. cur_ptr += cd->ic_info.misc.fw_attr_len;
  1327. cur_ptr += cd->ic_info.misc.fw_log_len;
  1328. memcpy((u8 *)ts_test->rawdata[i].data, cur_ptr + 8,
  1329. cd->ic_info.misc.mutual_struct_len - 8);
  1330. } else {
  1331. ret = ts_test_read(ts_test, data_addr,
  1332. (u8 *)ts_test->rawdata[i].data, data_size * sizeof(s16));
  1333. if (ret < 0)
  1334. return ret;
  1335. }
  1336. ts_test->rawdata[i].size = data_size;
  1337. goodix_rotate_abcd2cbad(drv_num, sen_num, ts_test->rawdata[i].data);
  1338. }
  1339. return ret;
  1340. }
  1341. static void goodix_cache_deltadata(struct goodix_ts_test *ts_test)
  1342. {
  1343. u32 data_size;
  1344. int tx = ts_test->test_params.drv_num;
  1345. int i;
  1346. int j;
  1347. int max_val;
  1348. int raw;
  1349. int temp;
  1350. for (i = 0; i < TOTAL_FRAME_NUM; i++) {
  1351. data_size = ts_test->rawdata[i].size;
  1352. if (data_size == 0)
  1353. continue;
  1354. for (j = 0; j < data_size; j++) {
  1355. raw = ts_test->rawdata[i].data[j];
  1356. max_val = 0;
  1357. /* calcu delta with above node */
  1358. if (j - tx >= 0) {
  1359. temp = ts_test->rawdata[i].data[j - tx];
  1360. temp = ABS(temp - raw);
  1361. max_val = MAX(max_val, temp);
  1362. }
  1363. /* calcu delta with bellow node */
  1364. if (j + tx < data_size) {
  1365. temp = ts_test->rawdata[i].data[j + tx];
  1366. temp = ABS(temp - raw);
  1367. max_val = MAX(max_val, temp);
  1368. }
  1369. /* calcu delta with left node */
  1370. if (j > 0 && j % tx) {
  1371. temp = ts_test->rawdata[i].data[j - 1];
  1372. temp = ABS(temp - raw);
  1373. max_val = MAX(max_val, temp);
  1374. }
  1375. /* calcu delta with right node */
  1376. if ((j + 1) % tx) {
  1377. temp = ts_test->rawdata[i].data[j + 1];
  1378. temp = ABS(temp - raw);
  1379. max_val = MAX(max_val, temp);
  1380. }
  1381. ts_test->accord_arr[i].data[j] = max_val * 1000 / raw;
  1382. }
  1383. ts_test->accord_arr[i].size = data_size;
  1384. }
  1385. }
  1386. static int goodix_cache_self_rawdata(struct goodix_ts_test *ts_test)
  1387. {
  1388. int ret;
  1389. u32 sen_num = ts_test->test_params.sen_num;
  1390. u32 drv_num = ts_test->test_params.drv_num;
  1391. u32 data_size = sen_num + drv_num;
  1392. u32 data_addr = ts_test->test_params.self_rawdata_addr;
  1393. u32 flag_addr = ts_test->ts->ic_info.misc.frame_data_addr;
  1394. struct frame_head *frame_head;
  1395. struct goodix_ts_core *cd = ts_test->ts;
  1396. unsigned char frame_buf[GOODIX_MAX_FRAMEDATA_LEN];
  1397. unsigned char *cur_ptr;
  1398. if (cd->bus->ic_type == IC_TYPE_BERLIN_D) {
  1399. ret = ts_test_read(ts_test, flag_addr, frame_buf, sizeof(frame_buf));
  1400. if (ret < 0)
  1401. return ret;
  1402. if (checksum_cmp(frame_buf,
  1403. cd->ic_info.misc.frame_data_head_len, CHECKSUM_MODE_U8_LE)) {
  1404. ts_err("frame head checksum error");
  1405. return -EINVAL;
  1406. }
  1407. frame_head = (struct frame_head *)frame_buf;
  1408. if (checksum_cmp(frame_buf, frame_head->cur_frame_len, CHECKSUM_MODE_U16_LE)) {
  1409. ts_err("frame body checksum error");
  1410. return -EINVAL;
  1411. }
  1412. cur_ptr = frame_buf;
  1413. cur_ptr += cd->ic_info.misc.frame_data_head_len;
  1414. cur_ptr += cd->ic_info.misc.fw_attr_len;
  1415. cur_ptr += cd->ic_info.misc.fw_log_len;
  1416. cur_ptr += cd->ic_info.misc.mutual_struct_len;
  1417. memcpy((u8 *)ts_test->self_rawdata.data, cur_ptr + 10,
  1418. cd->ic_info.misc.self_struct_len - 10);
  1419. } else {
  1420. ret = ts_test_read(ts_test, data_addr,
  1421. (u8 *)ts_test->self_rawdata.data,
  1422. data_size * sizeof(s16));
  1423. if (ret < 0)
  1424. return ret;
  1425. }
  1426. ts_test->self_rawdata.size = data_size;
  1427. return ret;
  1428. }
  1429. static int goodix_cache_noisedata(struct goodix_ts_test *ts_test)
  1430. {
  1431. int ret;
  1432. int i;
  1433. int cnt;
  1434. int retry;
  1435. u8 val;
  1436. unsigned char frame_buf[GOODIX_MAX_FRAMEDATA_LEN];
  1437. unsigned char *cur_ptr;
  1438. struct frame_head *frame_head;
  1439. struct goodix_ts_cmd temp_cmd;
  1440. struct goodix_ts_core *cd = ts_test->ts;
  1441. u32 sen_num = ts_test->test_params.sen_num;
  1442. u32 drv_num = ts_test->test_params.drv_num;
  1443. u32 data_size = sen_num * drv_num;
  1444. u32 data_addr = ts_test->test_params.noisedata_addr;
  1445. u32 flag_addr = ts_test->ts->ic_info.misc.touch_data_addr;
  1446. if (cd->bus->ic_type == IC_TYPE_BERLIN_D) {
  1447. flag_addr = ts_test->ts->ic_info.misc.frame_data_addr;
  1448. temp_cmd.cmd = 0x90;
  1449. temp_cmd.data[0] = 0x82;
  1450. temp_cmd.len = 5;
  1451. ret = ts_test_send_cmd(ts_test, &temp_cmd);
  1452. if (ret < 0) {
  1453. ts_err("switch diffdata mode failed, exit!");
  1454. return ret;
  1455. }
  1456. }
  1457. for (cnt = 0; cnt < NOISEDATA_TEST_TIMES; cnt++) {
  1458. val = 0;
  1459. ret = ts_test_write(ts_test, flag_addr, &val, 1);
  1460. if (ret < 0) {
  1461. ts_err("clean touch event failed, exit");
  1462. return -EAGAIN;
  1463. }
  1464. retry = 20;
  1465. while (retry--) {
  1466. usleep_range(5000, 5100);
  1467. ret = ts_test_read(ts_test, flag_addr, &val, 1);
  1468. if (!ret && (val & 0x80))
  1469. break;
  1470. }
  1471. if (retry < 0) {
  1472. ts_err("noisedata is not ready val:0x%02x i:%d, exit", val, cnt);
  1473. return -EAGAIN;
  1474. }
  1475. if (cd->bus->ic_type == IC_TYPE_BERLIN_D) {
  1476. ret = ts_test_read(ts_test, flag_addr, frame_buf, sizeof(frame_buf));
  1477. if (ret < 0)
  1478. return ret;
  1479. if (checksum_cmp(frame_buf,
  1480. cd->ic_info.misc.frame_data_head_len,
  1481. CHECKSUM_MODE_U8_LE)) {
  1482. ts_err("frame head checksum error");
  1483. return -EINVAL;
  1484. }
  1485. frame_head = (struct frame_head *)frame_buf;
  1486. if (checksum_cmp(frame_buf,
  1487. frame_head->cur_frame_len,
  1488. CHECKSUM_MODE_U16_LE)) {
  1489. ts_err("frame body checksum error");
  1490. return -EINVAL;
  1491. }
  1492. cur_ptr = frame_buf;
  1493. cur_ptr += cd->ic_info.misc.frame_data_head_len;
  1494. cur_ptr += cd->ic_info.misc.fw_attr_len;
  1495. cur_ptr += cd->ic_info.misc.fw_log_len;
  1496. memcpy((u8 *)ts_test->noisedata[cnt].data, cur_ptr + 8,
  1497. cd->ic_info.misc.mutual_struct_len - 8);
  1498. } else {
  1499. ret = ts_test_read(ts_test, data_addr,
  1500. (u8 *)ts_test->noisedata[cnt].data, data_size * sizeof(s16));
  1501. if (ret < 0)
  1502. return ret;
  1503. }
  1504. ts_test->noisedata[cnt].size = data_size;
  1505. goodix_rotate_abcd2cbad(drv_num, sen_num, ts_test->noisedata[cnt].data);
  1506. for (i = 0; i < data_size; i++)
  1507. ts_test->noisedata[cnt].data[i] = ABS(ts_test->noisedata[cnt].data[i]);
  1508. }
  1509. return ret;
  1510. }
  1511. static int goodix_cache_self_noisedata(struct goodix_ts_test *ts_test)
  1512. {
  1513. int ret;
  1514. int i;
  1515. u32 sen_num = ts_test->test_params.sen_num;
  1516. u32 drv_num = ts_test->test_params.drv_num;
  1517. u32 data_size = sen_num + drv_num;
  1518. u32 data_addr = ts_test->test_params.self_noisedata_addr;
  1519. u32 flag_addr = ts_test->ts->ic_info.misc.frame_data_addr;
  1520. struct frame_head *frame_head;
  1521. struct goodix_ts_core *cd = ts_test->ts;
  1522. unsigned char frame_buf[GOODIX_MAX_FRAMEDATA_LEN];
  1523. unsigned char *cur_ptr;
  1524. if (cd->bus->ic_type == IC_TYPE_BERLIN_D) {
  1525. ret = ts_test_read(ts_test, flag_addr, frame_buf, sizeof(frame_buf));
  1526. if (ret < 0)
  1527. return ret;
  1528. if (checksum_cmp(frame_buf,
  1529. cd->ic_info.misc.frame_data_head_len, CHECKSUM_MODE_U8_LE)) {
  1530. ts_err("frame head checksum error");
  1531. return -EINVAL;
  1532. }
  1533. frame_head = (struct frame_head *)frame_buf;
  1534. if (checksum_cmp(frame_buf, frame_head->cur_frame_len, CHECKSUM_MODE_U16_LE)) {
  1535. ts_err("frame body checksum error");
  1536. return -EINVAL;
  1537. }
  1538. cur_ptr = frame_buf;
  1539. cur_ptr += cd->ic_info.misc.frame_data_head_len;
  1540. cur_ptr += cd->ic_info.misc.fw_attr_len;
  1541. cur_ptr += cd->ic_info.misc.fw_log_len;
  1542. cur_ptr += cd->ic_info.misc.mutual_struct_len;
  1543. memcpy((u8 *)ts_test->self_noisedata.data, cur_ptr + 10,
  1544. cd->ic_info.misc.self_struct_len - 10);
  1545. } else {
  1546. ret = ts_test_read(ts_test, data_addr,
  1547. (u8 *)ts_test->self_noisedata.data, data_size * sizeof(s16));
  1548. if (ret < 0)
  1549. return ret;
  1550. }
  1551. ts_test->self_noisedata.size = data_size;
  1552. for (i = 0; i < data_size; i++)
  1553. ts_test->self_noisedata.data[i] = ABS(ts_test->self_noisedata.data[i]);
  1554. return ret;
  1555. }
  1556. static int goodix_analysis_rawdata(struct goodix_ts_test *ts_test)
  1557. {
  1558. int i;
  1559. int j;
  1560. bool fail_flag = false;
  1561. int err_cnt = 0;
  1562. int times = TOTAL_FRAME_NUM;
  1563. s16 val;
  1564. u32 data_size = ts_test->rawdata[0].size;
  1565. for (i = 0; i < times; i++) {
  1566. for (j = 0; j < data_size; j++) {
  1567. val = ts_test->rawdata[i].data[j];
  1568. if (val < ts_test->test_params.min_limits[j]) {
  1569. fail_flag = true;
  1570. ts_test->open_res.beyond_min_limit_cnt[j]++;
  1571. }
  1572. if (val > ts_test->test_params.max_limits[j]) {
  1573. fail_flag = true;
  1574. ts_test->open_res.beyond_max_limit_cnt[j]++;
  1575. }
  1576. }
  1577. if (fail_flag)
  1578. err_cnt++;
  1579. fail_flag = false;
  1580. }
  1581. if (err_cnt > 0)
  1582. ts_err("rawdata have %d frames out of range", err_cnt);
  1583. err_cnt *= 100;
  1584. if (err_cnt > times * 100 * 9 / 10)
  1585. return -EINVAL;
  1586. return 0;
  1587. }
  1588. static int goodix_analysis_deltadata(struct goodix_ts_test *ts_test)
  1589. {
  1590. int i;
  1591. int j;
  1592. int ret = 0;
  1593. s16 val;
  1594. u32 data_size = ts_test->accord_arr[0].size;
  1595. for (i = 0; i < TOTAL_FRAME_NUM; i++) {
  1596. for (j = 0; j < data_size; j++) {
  1597. val = ts_test->accord_arr[i].data[j];
  1598. if (val > ts_test->test_params.deviation_limits[j]) {
  1599. ts_test->open_res.beyond_accord_limit_cnt[j]++;
  1600. ret = -EINVAL;
  1601. }
  1602. }
  1603. }
  1604. return ret;
  1605. }
  1606. static int goodix_analysis_self_rawdata(struct goodix_ts_test *ts_test)
  1607. {
  1608. int i;
  1609. s16 val;
  1610. u32 data_size = ts_test->self_rawdata.size;
  1611. for (i = 0; i < data_size; i++) {
  1612. val = ts_test->self_rawdata.data[i];
  1613. if (val < ts_test->test_params.self_min_limits[i] ||
  1614. val > ts_test->test_params.self_max_limits[i]) {
  1615. ts_err("self_rawdata isn't in range, val:%d threshold:[%d,%d]",
  1616. val, ts_test->test_params.self_min_limits[i],
  1617. ts_test->test_params.self_max_limits[i]);
  1618. return -EINVAL;
  1619. }
  1620. }
  1621. return 0;
  1622. }
  1623. static int goodix_analysis_noisedata(struct goodix_ts_test *ts_test)
  1624. {
  1625. int cnt;
  1626. int i;
  1627. bool fail_flag = false;
  1628. int err_cnt = 0;
  1629. int times = NOISEDATA_TEST_TIMES;
  1630. s16 val;
  1631. u32 data_size = ts_test->noisedata[0].size;
  1632. for (cnt = 0; cnt < times; cnt++) {
  1633. for (i = 0; i < data_size; i++) {
  1634. val = ts_test->noisedata[cnt].data[i];
  1635. if (val > ts_test->test_params.noise_threshold)
  1636. fail_flag = true;
  1637. }
  1638. if (fail_flag)
  1639. err_cnt++;
  1640. fail_flag = false;
  1641. }
  1642. if (err_cnt > 0)
  1643. ts_err("noisedata have %d frames out of range", err_cnt);
  1644. err_cnt *= 100;
  1645. if (err_cnt > times * 100 * 2 / 10)
  1646. return -EINVAL;
  1647. return 0;
  1648. }
  1649. static int goodix_analysis_self_noisedata(struct goodix_ts_test *ts_test)
  1650. {
  1651. int i;
  1652. s16 val;
  1653. u32 data_size = ts_test->self_noisedata.size;
  1654. for (i = 0; i < data_size; i++) {
  1655. val = ts_test->self_noisedata.data[i];
  1656. if (val > ts_test->test_params.self_noise_threshold) {
  1657. ts_err("self noisedata isn't in range, val:%d threshold:[0,%d]",
  1658. val, ts_test->test_params.self_noise_threshold);
  1659. return -EINVAL;
  1660. }
  1661. }
  1662. return 0;
  1663. }
  1664. static void goodix_capacitance_test(struct goodix_ts_test *ts_test)
  1665. {
  1666. int ret;
  1667. ts_info("---------------------- cap_test begin ----------------------");
  1668. ret = goodix_cap_test_prepare(ts_test);
  1669. if (ret < 0) {
  1670. ts_err("cap_test prepare failed, exit");
  1671. goto exit;
  1672. }
  1673. ts_info("cap rawdata prepare OK");
  1674. /* obtain rawdata */
  1675. ret = goodix_cache_rawdata(ts_test);
  1676. if (ret < 0) {
  1677. if (ret == -EAGAIN) {
  1678. ts_err("Capacitance exit");
  1679. goto exit;
  1680. } else
  1681. ts_err("Failed to read capdata");
  1682. } else {
  1683. ts_info("get rawdata finish, start analysis");
  1684. ret = goodix_analysis_rawdata(ts_test);
  1685. if (ret < 0)
  1686. ts_test->test_result[GTP_CAP_TEST] = GTP_PANEL_REASON;
  1687. else
  1688. ts_test->test_result[GTP_CAP_TEST] = GTP_TEST_PASS;
  1689. }
  1690. /* obtain delta_data */
  1691. goodix_cache_deltadata(ts_test);
  1692. ts_info("get deltadata finish, start analysis");
  1693. ret = goodix_analysis_deltadata(ts_test);
  1694. if (ret < 0)
  1695. ts_test->test_result[GTP_DELTA_TEST] = GTP_PANEL_REASON;
  1696. else
  1697. ts_test->test_result[GTP_DELTA_TEST] = GTP_TEST_PASS;
  1698. /* obtain self_rawdata */
  1699. if (ts_test->test_params.test_items[GTP_SELFCAP_TEST]) {
  1700. ret = goodix_cache_self_rawdata(ts_test);
  1701. if (ret < 0) {
  1702. ts_err("Failed to read self_capdata");
  1703. } else {
  1704. ts_info("get self_rawdata finish, start analysis");
  1705. ret = goodix_analysis_self_rawdata(ts_test);
  1706. if (ret < 0)
  1707. ts_test->test_result[GTP_SELFCAP_TEST] = GTP_PANEL_REASON;
  1708. else
  1709. ts_test->test_result[GTP_SELFCAP_TEST] = GTP_TEST_PASS;
  1710. }
  1711. }
  1712. /* obtain noisedata */
  1713. if (ts_test->test_params.test_items[GTP_NOISE_TEST]) {
  1714. ret = goodix_cache_noisedata(ts_test);
  1715. if (ret < 0) {
  1716. ts_err("Failed to read noisedata");
  1717. } else {
  1718. ts_info("get noisedata finish, start analysis");
  1719. ret = goodix_analysis_noisedata(ts_test);
  1720. if (ret < 0)
  1721. ts_test->test_result[GTP_NOISE_TEST] = GTP_PANEL_REASON;
  1722. else
  1723. ts_test->test_result[GTP_NOISE_TEST] = GTP_TEST_PASS;
  1724. }
  1725. }
  1726. /* obtain self_noisedata */
  1727. if (ts_test->test_params.test_items[GTP_SELFNOISE_TEST]) {
  1728. ret = goodix_cache_self_noisedata(ts_test);
  1729. if (ret < 0) {
  1730. ts_err("Failed to read self_noisedata");
  1731. } else {
  1732. ts_info("get self_noisedata finish, start analysis");
  1733. ret = goodix_analysis_self_noisedata(ts_test);
  1734. if (ret < 0)
  1735. ts_test->test_result[GTP_SELFNOISE_TEST] = GTP_PANEL_REASON;
  1736. else
  1737. ts_test->test_result[GTP_SELFNOISE_TEST] = GTP_TEST_PASS;
  1738. }
  1739. }
  1740. exit:
  1741. goodix_cap_test_finish(ts_test);
  1742. }
  1743. char *goodix_strncat(char *dest, char *src, size_t dest_size)
  1744. {
  1745. size_t dest_len = 0;
  1746. dest_len = strnlen(dest, dest_size);
  1747. strlcat(&dest[dest_len], src, dest_size - dest_len - 1);
  1748. return dest;
  1749. }
  1750. char *goodix_strncatint(char *dest, int src, char *format, size_t dest_size)
  1751. {
  1752. char src_str[MAX_STR_LEN] = {0};
  1753. snprintf(src_str, MAX_STR_LEN, format, src);
  1754. return goodix_strncat(dest, src_str, dest_size);
  1755. }
  1756. static void goodix_data_cal(s16 *data, size_t data_size, s16 *stat_result)
  1757. {
  1758. int i = 0;
  1759. s16 avg = 0;
  1760. s16 min = 0;
  1761. s16 max = 0;
  1762. long long sum = 0;
  1763. min = data[0];
  1764. max = data[0];
  1765. for (i = 0; i < data_size; i++) {
  1766. sum += data[i];
  1767. if (max < data[i])
  1768. max = data[i];
  1769. if (min > data[i])
  1770. min = data[i];
  1771. }
  1772. avg = div_s64(sum, data_size);
  1773. stat_result[0] = avg;
  1774. stat_result[1] = max;
  1775. stat_result[2] = min;
  1776. }
  1777. static void goodix_data_statistics(s16 *data, size_t data_size,
  1778. char *result, size_t res_size)
  1779. {
  1780. s16 stat_value[3];
  1781. if (!data || !result) {
  1782. ts_err("parameters error please check *data and *result value");
  1783. return;
  1784. }
  1785. if (data_size <= 0 || res_size <= 0) {
  1786. ts_err("input parameter is illegva:data_size=%ld, res_size=%ld",
  1787. data_size, res_size);
  1788. return;
  1789. }
  1790. goodix_data_cal(data, data_size, stat_value);
  1791. memset(result, 0, res_size);
  1792. snprintf(result, res_size, "[%d,%d,%d]",
  1793. stat_value[0], stat_value[1], stat_value[2]);
  1794. return;
  1795. }
  1796. #ifdef SAVE_IN_CSV
  1797. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 4, 0)
  1798. static ssize_t fs_write(const void* buf, size_t size, struct file* fp)
  1799. {
  1800. loff_t pos;
  1801. ssize_t len;
  1802. pos = fp->f_pos;
  1803. len = kernel_write(fp, buf, size, &pos);
  1804. fp->f_pos = pos;
  1805. return len;
  1806. }
  1807. #else
  1808. static ssize_t fs_write(const void* buf, size_t size, struct file* fp)
  1809. {
  1810. mm_segment_t old_fs;
  1811. loff_t pos;
  1812. ssize_t len;
  1813. pos = fp->f_pos;
  1814. old_fs = get_fs();
  1815. set_fs(KERNEL_DS);
  1816. len = vfs_write(fp, buf, size, &pos);
  1817. set_fs(old_fs);
  1818. fp->f_pos = pos;
  1819. return len;
  1820. }
  1821. #endif
  1822. static int goodix_save_test_config(struct goodix_ts_test *ts_test,
  1823. struct file *fp)
  1824. {
  1825. int ret = 0;
  1826. int i;
  1827. int bytes = 0;
  1828. char *data;
  1829. struct goodix_ic_config *cfg = &ts_test->test_config;
  1830. if (cfg->len <= 0) {
  1831. ts_info("Can't find vaild test config");
  1832. return 0;
  1833. }
  1834. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  1835. if (!data) {
  1836. ts_err("alloc memory failed");
  1837. return -ENOMEM;
  1838. }
  1839. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<OrderConfig>\n");
  1840. for (i = 0; i < cfg->len; i++)
  1841. bytes += scnprintf(&data[bytes],
  1842. MAX_DATA_BUFFER - bytes, "0x%02x,", cfg->data[i]);
  1843. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  1844. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</OrderConfig>\n");
  1845. ret = fs_write(data, bytes, fp);
  1846. if (ret < 0) {
  1847. ts_err("test config write failed");
  1848. goto save_end;
  1849. }
  1850. save_end:
  1851. kfree(data);
  1852. return ret;
  1853. }
  1854. static int goodix_save_header(struct goodix_ts_test *ts_test,
  1855. struct file *fp)
  1856. {
  1857. int ret;
  1858. int i;
  1859. int bytes = 0;
  1860. bool result = false;
  1861. char *data = NULL;
  1862. struct goodix_ts_core *ts = ts_test->ts;
  1863. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  1864. if (!data) {
  1865. ts_err("alloc memory failed");
  1866. return -ENOMEM;
  1867. }
  1868. bytes += scnprintf(&data[bytes],
  1869. MAX_DATA_BUFFER - bytes,
  1870. "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
  1871. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<TESTLOG>\n");
  1872. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<Header>\n");
  1873. /* sava test result */
  1874. for (i = 0; i < MAX_TEST_ITEMS; i++) {
  1875. if ((ts_test->test_result[i] > 0) &&
  1876. (ts_test->test_result[i] != GTP_TEST_PASS)) {
  1877. result = true;
  1878. break;
  1879. }
  1880. }
  1881. if (result)
  1882. bytes += scnprintf(&data[bytes],
  1883. MAX_DATA_BUFFER - bytes,
  1884. "<Result>NG</Result>\n");
  1885. else
  1886. bytes += scnprintf(&data[bytes],
  1887. MAX_DATA_BUFFER - bytes,
  1888. "<Result>OK</Result>\n");
  1889. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1890. "<DeviceType>GT%s</DeviceType>\n",
  1891. ts->fw_version.patch_pid);
  1892. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1893. "<SensorId>%d</SensorId>\n",
  1894. ts_test->ts->fw_version.sensor_id);
  1895. ret = fs_write(data, bytes, fp);
  1896. if (ret < 0) {
  1897. ts_err("header write failed");
  1898. goto save_end;
  1899. }
  1900. bytes = 0;
  1901. /* save test config */
  1902. ret = goodix_save_test_config(ts_test, fp);
  1903. if (ret < 0) {
  1904. ts_err("save test config failed");
  1905. goto save_end;
  1906. }
  1907. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</Header>\n");
  1908. ret = fs_write(data, bytes, fp);
  1909. if (ret < 0) {
  1910. ts_err("header write failed");
  1911. goto save_end;
  1912. }
  1913. bytes = 0;
  1914. /* item list */
  1915. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<ItemList>\n");
  1916. if (ts_test->test_result[GTP_CAP_TEST]) {
  1917. if (GTP_TEST_PASS == ts_test->test_result[GTP_CAP_TEST])
  1918. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1919. "<Item name=\"Rawdata MAX/MIN Test\" result=\"OK\"/>\n");
  1920. else
  1921. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1922. "<Item name=\"Rawdata MAX/MIN Test\" result=\"NG\"/>\n");
  1923. }
  1924. if (ts_test->test_result[GTP_DELTA_TEST]) {
  1925. if (GTP_TEST_PASS == ts_test->test_result[GTP_DELTA_TEST])
  1926. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1927. "<Item name=\"Rawdata Adjcent Deviation Test\" result=\"OK\"/>\n");
  1928. else
  1929. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1930. "<Item name=\"Rawdata Adjcent Deviation Test\" result=\"NG\"/>\n");
  1931. }
  1932. if (ts_test->test_result[GTP_NOISE_TEST]) {
  1933. if (GTP_TEST_PASS == ts_test->test_result[GTP_NOISE_TEST])
  1934. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1935. "<Item name=\"Diffdata Jitter Test\" result=\"OK\"/>\n");
  1936. else
  1937. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1938. "<Item name=\"Diffdata Jitter Test\" result=\"NG\"/>\n");
  1939. }
  1940. if (ts_test->test_result[GTP_SELFNOISE_TEST]) {
  1941. if (GTP_TEST_PASS == ts_test->test_result[GTP_SELFNOISE_TEST])
  1942. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1943. "<Item name=\"Self Diffdata Jitter Limit Test\" result=\"OK\"/>\n");
  1944. else
  1945. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1946. "<Item name=\"Self Diffdata Jitter Limit Test\" result=\"NG\"/>\n");
  1947. }
  1948. if (ts_test->test_result[GTP_SELFCAP_TEST]) {
  1949. if (GTP_TEST_PASS == ts_test->test_result[GTP_SELFCAP_TEST])
  1950. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1951. "<Item name=\"Self Rawdata Upper Limit Test\" result=\"OK\"/>\n");
  1952. else
  1953. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1954. "<Item name=\"Self Rawdata Upper Limit Test\" result=\"NG\"/>\n");
  1955. }
  1956. if (ts_test->test_result[GTP_SHORT_TEST]) {
  1957. if (GTP_TEST_PASS == ts_test->test_result[GTP_SHORT_TEST])
  1958. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1959. "<Item name=\"Short Test\" result=\"OK\"/>\n");
  1960. else
  1961. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1962. "<Item name=\"Short Test\" result=\"NG\"/>\n");
  1963. }
  1964. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</ItemList>\n");
  1965. ret = fs_write(data, bytes, fp);
  1966. if (ret < 0) {
  1967. ts_err("item list write failed");
  1968. goto save_end;
  1969. }
  1970. save_end:
  1971. kfree(data);
  1972. return ret;
  1973. }
  1974. static int goodix_save_limits(struct goodix_ts_test *ts_test,
  1975. struct file *fp)
  1976. {
  1977. int ret;
  1978. int i;
  1979. int bytes = 0;
  1980. char *data = NULL;
  1981. int tx = ts_test->test_params.drv_num;
  1982. int rx = ts_test->test_params.sen_num;
  1983. int chn1;
  1984. int chn2;
  1985. int r;
  1986. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  1987. if (!data) {
  1988. return -ENOMEM;
  1989. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<TestItems>\n");
  1990. /* save short result */
  1991. if (ts_test->test_result[GTP_SHORT_TEST]) {
  1992. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1993. "<Item name=\"Short Test\">\n");
  1994. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  1995. "<ShortNum>%d</ShortNum>\n",
  1996. ts_test->short_res.short_num);
  1997. for (i = 0; i < ts_test->short_res.short_num; i++) {
  1998. chn1 = ts_test->short_res.short_msg[4 * i];
  1999. chn2 = ts_test->short_res.short_msg[4 * i + 1];
  2000. r = (ts_test->short_res.short_msg[4 * i + 2] << 8) +
  2001. ts_test->short_res.short_msg[4 * i + 3];
  2002. if (chn1 == CHN_VDD)
  2003. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2004. "<ShortMess Chn1=\"VDD\" ");
  2005. else if (chn1 == CHN_GND)
  2006. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2007. "<ShortMess Chn1=\"GND\" ");
  2008. else if (chn1 & DRV_CHANNEL_FLAG)
  2009. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2010. "<ShortMess Chn1=\"Tx%d\" ",
  2011. chn1 & 0x7f);
  2012. else
  2013. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2014. "<ShortMess Chn1=\"Rx%d\" ",
  2015. chn1 & 0x7f);
  2016. if (chn2 == CHN_VDD)
  2017. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2018. "Chn2=\"VDD\" ShortResistor= \"%dKom\"/>\n", r);
  2019. else if (chn2 == CHN_GND)
  2020. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2021. "Chn2=\"GND\" ShortResistor= \"%dKom\"/>\n", r);
  2022. else if (chn2 & DRV_CHANNEL_FLAG)
  2023. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2024. "Chn2=\"Tx%d\" ShortResistor= \"%dKom\"/>\n",
  2025. chn2 & 0x7f, r);
  2026. else
  2027. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2028. "Chn2=\"Rx%d\" ShortResistor= \"%dKom\"/>\n",
  2029. chn2 & 0x7f, r);
  2030. }
  2031. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</Item>\n");
  2032. ret = fs_write(data, bytes, fp);
  2033. if (ret < 0) {
  2034. ts_err("short res write fail.");
  2035. goto save_end;
  2036. }
  2037. bytes = 0;
  2038. }
  2039. /* rawdata max limit */
  2040. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2041. "<Item name=\"Rawdata Test Sets\">\n");
  2042. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2043. "<TotalFrameCnt>%d</TotalFrameCnt>\n", TOTAL_FRAME_NUM);
  2044. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<MaxRawLimit>\n");
  2045. for (i = 0; i < tx * rx; i++) {
  2046. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2047. ts_test->test_params.max_limits[i]);
  2048. if ((i + 1) % tx == 0)
  2049. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2050. }
  2051. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</MaxRawLimit>\n");
  2052. /* BeyondRawdataUpperLimit */
  2053. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2054. "<BeyondRawdataUpperLimitCnt>\n");
  2055. for (i = 0; i < tx * rx; i++) {
  2056. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2057. ts_test->open_res.beyond_max_limit_cnt[i]);
  2058. if ((i + 1) % tx == 0)
  2059. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2060. }
  2061. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2062. "</BeyondRawdataUpperLimitCnt>\n");
  2063. ret = fs_write(data, bytes, fp);
  2064. if (ret < 0) {
  2065. ts_err("rawdata limit write failed");
  2066. goto save_end;
  2067. }
  2068. bytes = 0;
  2069. /* rawdata min limit */
  2070. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<MinRawLimit>\n");
  2071. for (i = 0; i < tx * rx; i++) {
  2072. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2073. ts_test->test_params.min_limits[i]);
  2074. if ((i + 1) % tx == 0)
  2075. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2076. }
  2077. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</MinRawLimit>\n");
  2078. /* BeyondRawdataLower limit */
  2079. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2080. "<BeyondRawdataLowerLimitCnt>\n");
  2081. for (i = 0; i < tx * rx; i++) {
  2082. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2083. ts_test->open_res.beyond_min_limit_cnt[i]);
  2084. if ((i + 1) % tx == 0)
  2085. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2086. }
  2087. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2088. "</BeyondRawdataLowerLimitCnt>\n");
  2089. ret = fs_write(data, bytes, fp);
  2090. if (ret < 0) {
  2091. ts_err("rawdata limit write failed");
  2092. goto save_end;
  2093. }
  2094. bytes = 0;
  2095. /* Max Accord limit */
  2096. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<MaxAccordLimit>\n");
  2097. for (i = 0; i < tx * rx; i++) {
  2098. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2099. ts_test->test_params.deviation_limits[i]);
  2100. if ((i + 1) % tx == 0)
  2101. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2102. }
  2103. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</MaxAccordLimit>\n");
  2104. /* BeyondAccordLimitCnt */
  2105. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<BeyondAccordLimitCnt>\n");
  2106. for (i = 0; i < tx * rx; i++) {
  2107. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2108. ts_test->open_res.beyond_accord_limit_cnt[i]);
  2109. if ((i + 1) % tx == 0)
  2110. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2111. }
  2112. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</BeyondAccordLimitCnt>\n");
  2113. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</Item>\n");
  2114. ret = fs_write(data, bytes, fp);
  2115. if (ret < 0) {
  2116. ts_err("rawdata limit write failed");
  2117. goto save_end;
  2118. }
  2119. bytes = 0;
  2120. /* save noise limit */
  2121. if (ts_test->test_result[GTP_NOISE_TEST]) {
  2122. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2123. "<Item name=\"Diffdata Test Sets\">\n");
  2124. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2125. "<TotalFrameCnt>%d</TotalFrameCnt>\n",
  2126. NOISEDATA_TEST_TIMES);
  2127. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2128. "<MaxJitterLimit>%d</MaxJitterLimit>\n",
  2129. ts_test->test_params.noise_threshold);
  2130. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</Item>\n");
  2131. ret = fs_write(data, bytes, fp);
  2132. if (ret < 0) {
  2133. ts_err("noise limit write failed");
  2134. goto save_end;
  2135. }
  2136. bytes = 0;
  2137. }
  2138. /* save self rawdata limit */
  2139. if (ts_test->test_result[GTP_SELFCAP_TEST]) {
  2140. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2141. "<Item name=\"Self Rawdata Test Sets\">\n");
  2142. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2143. "<TotalFrameCnt>1</TotalFrameCnt>\n");
  2144. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<MaxRawLimit>\n");
  2145. for (i = 0; i < tx + rx; i++) {
  2146. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2147. ts_test->test_params.self_max_limits[i]);
  2148. if ((i + 1) % tx == 0)
  2149. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2150. }
  2151. if ((tx + rx) % tx != 0)
  2152. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2153. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</MaxRawLimit>\n");
  2154. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<MinRawLimit>\n");
  2155. for (i = 0; i < tx + rx; i++) {
  2156. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,",
  2157. ts_test->test_params.self_min_limits[i]);
  2158. if ((i + 1) % tx == 0)
  2159. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2160. }
  2161. if ((tx + rx) % tx != 0)
  2162. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2163. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</MinRawLimit>\n");
  2164. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</Item>\n");
  2165. ret = fs_write(data, bytes, fp);
  2166. if (ret < 0) {
  2167. ts_err("self rawdata limit write failed");
  2168. goto save_end;
  2169. }
  2170. bytes = 0;
  2171. }
  2172. /* save selfnoise limit */
  2173. if (ts_test->test_result[GTP_SELFNOISE_TEST]) {
  2174. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2175. "<Item name=\"Self Diffdata Test Sets\">\n");
  2176. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2177. "<TotalFrameCnt>1</TotalFrameCnt>\n");
  2178. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2179. "<MaxJitterLimit>%d</MaxJitterLimit>\n",
  2180. ts_test->test_params.self_noise_threshold);
  2181. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</Item>\n");
  2182. ret = fs_write(data, bytes, fp);
  2183. if (ret < 0) {
  2184. ts_err("raw limit write failed");
  2185. goto save_end;
  2186. }
  2187. bytes = 0;
  2188. }
  2189. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</TestItems>\n");
  2190. ret = fs_write(data, bytes, fp);
  2191. if (ret < 0)
  2192. ts_err("limit write fail.");
  2193. save_end:
  2194. kfree(data);
  2195. return ret;
  2196. }
  2197. static int goodix_save_rawdata(struct goodix_ts_test *ts_test,
  2198. struct file *fp)
  2199. {
  2200. int i;
  2201. int j;
  2202. int ret;
  2203. int bytes = 0;
  2204. s16 stat_result[3];
  2205. char *data = NULL;
  2206. int tx = ts_test->test_params.drv_num;
  2207. int rx = ts_test->test_params.sen_num;
  2208. int len = tx * rx;
  2209. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  2210. if (!data)
  2211. return -ENOMEM;
  2212. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<RawDataRecord>\n");
  2213. for (i = 0; i < TOTAL_FRAME_NUM; i++) {
  2214. goodix_data_cal(ts_test->rawdata[i].data, len, stat_result);
  2215. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2216. "<DataContent No.=\"%d\" DataCount=\"%d\" Maximum=\"%d\" Minimum=\"%d\" Average=\"%d\">\n",
  2217. i, len, stat_result[1], stat_result[2], stat_result[0]);
  2218. for (j = 0; j < len; j++) {
  2219. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2220. "%d,", ts_test->rawdata[i].data[j]);
  2221. if ((j + 1) % tx == 0)
  2222. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2223. }
  2224. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</DataContent>\n");
  2225. goodix_data_cal(ts_test->accord_arr[i].data, len, stat_result);
  2226. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2227. "<RawAccord No.=\"%d\" DataCount=\"%d\" Maximum=\"%d\" Minimum=\"%d\" Average=\"%d\">\n",
  2228. i, len, stat_result[1], stat_result[2], stat_result[0]);
  2229. for (j = 0; j < len; j++) {
  2230. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2231. "%d,", ts_test->accord_arr[i].data[j]);
  2232. if ((j + 1) % tx == 0)
  2233. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2234. }
  2235. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</RawAccord>\n");
  2236. ret = fs_write(data, bytes, fp);
  2237. if (ret < 0) {
  2238. ts_err("rawdata write fail.");
  2239. goto save_end;
  2240. }
  2241. bytes = 0;
  2242. }
  2243. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</RawDataRecord>\n");
  2244. ret = fs_write(data, bytes, fp);
  2245. if (ret < 0)
  2246. ts_err("rawdata write fail.");
  2247. save_end:
  2248. kfree(data);
  2249. return ret;
  2250. }
  2251. static int goodix_save_noise_data(struct goodix_ts_test *ts_test,
  2252. struct file *fp)
  2253. {
  2254. int i;
  2255. int j;
  2256. int ret = 0;
  2257. int bytes = 0;
  2258. s16 stat_result[3];
  2259. char *data = NULL;
  2260. int tx = ts_test->test_params.drv_num;
  2261. int rx = ts_test->test_params.sen_num;
  2262. int len = tx * rx;
  2263. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  2264. if (!data)
  2265. return -ENOMEM;
  2266. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<DiffDataRecord>\n");
  2267. for (i = 0; i < NOISEDATA_TEST_TIMES; i++) {
  2268. goodix_data_cal(ts_test->noisedata[i].data, len, stat_result);
  2269. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2270. "<DataContent No.=\"%d\" DataCount=\"%d\" Maximum=\"%d\" Minimum=\"%d\" Average=\"%d\">\n",
  2271. i, len, stat_result[1], stat_result[2], stat_result[0]);
  2272. for (j = 0; j < len; j++) {
  2273. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2274. "%d,", ts_test->noisedata[i].data[j]);
  2275. if ((j + 1) % tx == 0)
  2276. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2277. }
  2278. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</DataContent>\n");
  2279. ret = fs_write(data, bytes, fp);
  2280. if (ret < 0) {
  2281. ts_err("noisedata write fail.");
  2282. goto save_end;
  2283. }
  2284. bytes = 0;
  2285. }
  2286. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</DiffDataRecord>\n");
  2287. ret = fs_write(data, bytes, fp);
  2288. if (ret < 0)
  2289. ts_err("noisedata write fail.");
  2290. save_end:
  2291. kfree(data);
  2292. return ret;
  2293. }
  2294. static int goodix_save_self_data(struct goodix_ts_test *ts_test,
  2295. struct file *fp, s16 *src_data, u8 *title, int len)
  2296. {
  2297. int i;
  2298. int ret = 0;
  2299. s32 bytes = 0;
  2300. char *data;
  2301. s16 stat_result[3];
  2302. int tx = ts_test->test_params.drv_num;
  2303. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  2304. if (!data)
  2305. return -ENOMEM;
  2306. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<%s>\n",title);
  2307. ret = fs_write(data, bytes, fp);
  2308. if (ret < 0) {
  2309. ts_err("rawdata write fail.");
  2310. goto save_end;
  2311. }
  2312. bytes = 0;
  2313. goodix_data_cal(src_data, len, stat_result);
  2314. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes,
  2315. "<DataContent No.=\"0\" DataCount=\"%d\" Maximum=\"%d\" Minimum=\"%d\" Average=\"%d\">\n",
  2316. len, stat_result[1], stat_result[2], stat_result[0]);
  2317. for (i = 0; i < len; i++) {
  2318. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "%d,", src_data[i]);
  2319. if ((i + 1) % tx == 0)
  2320. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2321. }
  2322. if (len % tx != 0)
  2323. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "\n");
  2324. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</DataContent>\n");
  2325. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</%s>\n",title);
  2326. ret = fs_write(data, bytes, fp);
  2327. if (ret < 0)
  2328. ts_err("rawdata write fail.");
  2329. save_end:
  2330. kfree(data);
  2331. return ret;
  2332. }
  2333. static int goodix_save_data(struct goodix_ts_test *ts_test,
  2334. struct file *fp)
  2335. {
  2336. int ret;
  2337. int bytes = 0;
  2338. char *data = NULL;
  2339. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  2340. if (!data)
  2341. return -ENOMEM;
  2342. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "<DataRecord>\n");
  2343. ret = fs_write(data, bytes, fp);
  2344. if (ret < 0) {
  2345. ts_err("rawdata record lable failed");
  2346. goto save_end;
  2347. }
  2348. bytes = 0;
  2349. ret = goodix_save_rawdata(ts_test, fp);
  2350. if (ret < 0)
  2351. goto save_end;
  2352. if (ts_test->test_result[GTP_NOISE_TEST]) {
  2353. ret = goodix_save_noise_data(ts_test, fp);
  2354. if (ret < 0)
  2355. goto save_end;
  2356. }
  2357. if (ts_test->test_result[GTP_SELFCAP_TEST]) {
  2358. ret = goodix_save_self_data(ts_test, fp,
  2359. ts_test->self_rawdata.data,
  2360. "selfDataRecord",
  2361. ts_test->self_rawdata.size);
  2362. if (ret < 0)
  2363. goto save_end;
  2364. }
  2365. if (ts_test->test_result[GTP_SELFNOISE_TEST]) {
  2366. ret = goodix_save_self_data(ts_test, fp,
  2367. ts_test->self_noisedata.data,
  2368. "selfDiffDataRecord",
  2369. ts_test->self_noisedata.size);
  2370. if (ret < 0)
  2371. goto save_end;
  2372. }
  2373. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER - bytes, "</DataRecord>\n");
  2374. ret = fs_write(data, bytes, fp);
  2375. if (ret < 0)
  2376. ts_err("rawdata data record lable fail.");
  2377. save_end:
  2378. kfree(data);
  2379. return ret;
  2380. }
  2381. /* save end tag in csv file */
  2382. static int goodix_save_tail(struct goodix_ts_test *ts_test,
  2383. struct file *fp)
  2384. {
  2385. int ret = 0;
  2386. int bytes = 0;
  2387. char *data = NULL;
  2388. data = kzalloc(MAX_DATA_BUFFER, GFP_KERNEL);
  2389. if (!data)
  2390. return -ENOMEM;
  2391. bytes += scnprintf(&data[bytes], MAX_DATA_BUFFER, "</TESTLOG>\n");
  2392. ret = fs_write(data, bytes, fp);
  2393. if (ret < 0)
  2394. ts_err("tail write failed");
  2395. kfree(data);
  2396. return ret;
  2397. }
  2398. static void goodix_save_result_data(struct goodix_ts_test *ts_test)
  2399. {
  2400. int ret = 0;
  2401. char save_path[100];
  2402. struct file *fp = NULL;
  2403. /* format result file */
  2404. scnprintf(save_path, ARRAY_SIZE(save_path), GOODIX_RESULT_SAVE_PATH);
  2405. ts_info("save result IN, file_name:%s", save_path);
  2406. fp = filp_open(save_path, O_CREAT | O_WRONLY | O_TRUNC, 0666);
  2407. if (IS_ERR(fp)) {
  2408. ts_err("create file:%s failed, fp:%ld", save_path, PTR_ERR(fp));
  2409. return;
  2410. }
  2411. /* save header */
  2412. ret = goodix_save_header(ts_test, fp);
  2413. if (ret < 0)
  2414. goto save_end;
  2415. /* save limits */
  2416. ret = goodix_save_limits(ts_test, fp);
  2417. if (ret < 0)
  2418. goto save_end;
  2419. /* save data */
  2420. ret = goodix_save_data(ts_test, fp);
  2421. if (ret < 0)
  2422. goto save_end;
  2423. /* save tail */
  2424. ret = goodix_save_tail(ts_test, fp);
  2425. if (ret < 0)
  2426. goto save_end;
  2427. ts_info("the test result save in %s", save_path);
  2428. save_end:
  2429. filp_close(fp, NULL);
  2430. }
  2431. #endif // SAVE_IN_CSV
  2432. static void goodix_put_test_result(struct goodix_ts_test *ts_test,
  2433. struct ts_rawdata_info *info)
  2434. {
  2435. int i;
  2436. bool have_bus_error = false;
  2437. bool have_panel_error = false;
  2438. char statistics_data[STATISTICS_DATA_LEN] = {0};
  2439. struct goodix_ts_core *ts = ts_test->ts;
  2440. ts_info("put test result IN");
  2441. info->buff[0] = ts_test->test_params.sen_num;
  2442. info->buff[1] = ts_test->test_params.drv_num;
  2443. info->used_size = 2;
  2444. /* save rawdata to info->buff, only one frame */
  2445. if (ts_test->rawdata[0].size) {
  2446. for (i = 0; i < ts_test->rawdata[0].size; i++)
  2447. info->buff[info->used_size + i] = ts_test->rawdata[0].data[i];
  2448. info->used_size += ts_test->rawdata[0].size;
  2449. }
  2450. /* save noisedata to info->buff */
  2451. if (ts_test->noisedata[0].size) {
  2452. for (i = 0; i < ts_test->noisedata[0].size; i++)
  2453. info->buff[info->used_size + i] = ts_test->noisedata[0].data[i];
  2454. info->used_size += ts_test->noisedata[0].size;
  2455. }
  2456. /* save self_noisedata to info->buff */
  2457. if (ts_test->self_noisedata.size) {
  2458. for (i = 0; i < ts_test->self_noisedata.size; i++)
  2459. info->buff[info->used_size + i] = ts_test->self_noisedata.data[i];
  2460. info->used_size += ts_test->self_noisedata.size;
  2461. }
  2462. /* save self_rawdata to info->buff */
  2463. if (ts_test->self_rawdata.size) {
  2464. for (i = 0; i < ts_test->self_rawdata.size; i++)
  2465. info->buff[info->used_size + i] = ts_test->self_rawdata.data[i];
  2466. info->used_size += ts_test->self_rawdata.size;
  2467. }
  2468. /* check if there have bus error */
  2469. for (i = 0; i < MAX_TEST_ITEMS; i++) {
  2470. if (ts_test->test_result[i] == SYS_SOFTWARE_REASON)
  2471. have_bus_error = true;
  2472. else if (ts_test->test_result[i] == GTP_PANEL_REASON)
  2473. have_panel_error = true;
  2474. }
  2475. ts_info("Have bus error:%d", have_bus_error);
  2476. if (have_bus_error || have_panel_error)
  2477. goodix_strncat(ts_test->test_info, "[FAIL]-",
  2478. TS_RAWDATA_RESULT_MAX);
  2479. else
  2480. goodix_strncat(ts_test->test_info, "[PASS]-",
  2481. TS_RAWDATA_RESULT_MAX);
  2482. if (have_bus_error)
  2483. goodix_strncat(ts_test->test_info, "0F-",
  2484. TS_RAWDATA_RESULT_MAX);
  2485. else
  2486. goodix_strncat(ts_test->test_info, "0P-",
  2487. TS_RAWDATA_RESULT_MAX);
  2488. for (i = 0; i < MAX_TEST_ITEMS; i++) {
  2489. /* if have tested, show result */
  2490. if (ts_test->test_result[i]) {
  2491. if (ts_test->test_result[i] == GTP_TEST_PASS)
  2492. goodix_strncatint(ts_test->test_info, i, "%dP-",
  2493. TS_RAWDATA_RESULT_MAX);
  2494. else
  2495. goodix_strncatint(ts_test->test_info, i, "%dF-",
  2496. TS_RAWDATA_RESULT_MAX);
  2497. }
  2498. }
  2499. /* calculate rawdata min avg max value*/
  2500. if (ts_test->rawdata[0].size) {
  2501. goodix_data_statistics(
  2502. ts_test->rawdata[0].data,
  2503. ts_test->rawdata[0].size,
  2504. statistics_data,
  2505. STATISTICS_DATA_LEN);
  2506. goodix_strncat(ts_test->test_info, statistics_data,
  2507. TS_RAWDATA_RESULT_MAX);
  2508. } else {
  2509. ts_err("NO valiable rawdata");
  2510. goodix_strncat(ts_test->test_info, "[0,0,0]",
  2511. TS_RAWDATA_RESULT_MAX);
  2512. }
  2513. /* calculate noisedata min avg max value*/
  2514. if (ts_test->test_params.test_items[GTP_NOISE_TEST]) {
  2515. if (ts_test->noisedata[0].size) {
  2516. goodix_data_statistics(
  2517. ts_test->noisedata[0].data,
  2518. ts_test->noisedata[0].size,
  2519. statistics_data,
  2520. STATISTICS_DATA_LEN);
  2521. goodix_strncat(ts_test->test_info, statistics_data,
  2522. TS_RAWDATA_RESULT_MAX);
  2523. } else {
  2524. ts_err("NO valiable noisedata");
  2525. goodix_strncat(ts_test->test_info, "[0,0,0]",
  2526. TS_RAWDATA_RESULT_MAX);
  2527. }
  2528. }
  2529. /* calculate self_rawdata min avg max value*/
  2530. if (ts_test->test_params.test_items[GTP_SELFCAP_TEST]) {
  2531. if (ts_test->self_rawdata.size <=
  2532. sizeof(ts_test->self_rawdata.data) / sizeof(ts_test->self_rawdata.data[0])) {
  2533. goodix_data_statistics(
  2534. ts_test->self_rawdata.data,
  2535. ts_test->self_rawdata.size,
  2536. statistics_data,
  2537. STATISTICS_DATA_LEN);
  2538. goodix_strncat(ts_test->test_info, statistics_data,
  2539. TS_RAWDATA_RESULT_MAX);
  2540. } else {
  2541. ts_err("NO valiable self_rawdata");
  2542. goodix_strncat(ts_test->test_info, "[0,0,0]",
  2543. TS_RAWDATA_RESULT_MAX);
  2544. }
  2545. }
  2546. /* calculate self_noisedata min avg max value*/
  2547. if (ts_test->test_params.test_items[GTP_SELFNOISE_TEST]) {
  2548. if (ts_test->self_noisedata.size <=
  2549. sizeof(ts_test->self_noisedata.data) / sizeof(ts_test->self_noisedata.data[0])) {
  2550. goodix_data_statistics(
  2551. ts_test->self_noisedata.data,
  2552. ts_test->self_noisedata.size,
  2553. statistics_data,
  2554. STATISTICS_DATA_LEN);
  2555. goodix_strncat(ts_test->test_info, statistics_data,
  2556. TS_RAWDATA_RESULT_MAX);
  2557. } else {
  2558. ts_err("NO valiable self_noisedata");
  2559. goodix_strncat(ts_test->test_info, "[0,0,0]",
  2560. TS_RAWDATA_RESULT_MAX);
  2561. }
  2562. }
  2563. goodix_strncat(ts_test->test_info, "-GT",
  2564. TS_RAWDATA_RESULT_MAX);
  2565. goodix_strncat(ts_test->test_info, ts->fw_version.patch_pid,
  2566. TS_RAWDATA_RESULT_MAX);
  2567. goodix_strncat(ts_test->test_info, "\n",
  2568. TS_RAWDATA_RESULT_MAX);
  2569. strlcpy(info->result, ts_test->test_info, TS_RAWDATA_RESULT_MAX - 1);
  2570. #ifdef SAVE_IN_CSV
  2571. /* save result to file */
  2572. goodix_save_result_data(ts_test);
  2573. #endif
  2574. }
  2575. static int goodix_do_inspect(struct goodix_ts_core *cd, struct ts_rawdata_info *info)
  2576. {
  2577. int ret;
  2578. struct goodix_ts_test *ts_test = NULL;
  2579. if (!cd || !info) {
  2580. ts_err("core_data or info is NULL");
  2581. return -ENODEV;
  2582. }
  2583. ts_test = kzalloc(sizeof(*ts_test), GFP_KERNEL);
  2584. if (!ts_test)
  2585. return -ENOMEM;
  2586. ts_test->ts = cd;
  2587. ret = goodix_tptest_prepare(ts_test);
  2588. if (ret < 0) {
  2589. ts_err("Failed to prepare TP test, exit");
  2590. strlcpy(info->result, "[FAIL]-0F-software reason\n",
  2591. TS_RAWDATA_RESULT_MAX - 1);
  2592. goto exit_finish;
  2593. }
  2594. ts_info("TP test prepare OK");
  2595. goodix_capacitance_test(ts_test); /* 1F 3F 6F 7F test */
  2596. if (ts_test->test_params.test_items[GTP_SHORT_TEST])
  2597. goodix_shortcircut_test(ts_test); /* 5F test */
  2598. goodix_put_test_result(ts_test, info);
  2599. goodix_tptest_finish(ts_test);
  2600. exit_finish:
  2601. kfree(ts_test);
  2602. return ret;
  2603. }
  2604. /* show rawdata */
  2605. static ssize_t get_rawdata_show(struct device *dev,
  2606. struct device_attribute *attr, char *buf)
  2607. {
  2608. int ret = 0;
  2609. struct ts_rawdata_info *info = NULL;
  2610. struct goodix_ts_core *cd = dev_get_drvdata(dev);
  2611. info = kzalloc(sizeof(*info), GFP_KERNEL);
  2612. if (!info)
  2613. return -ENOMEM;
  2614. goodix_do_inspect(cd, info);
  2615. ret = snprintf(buf, PAGE_SIZE, "resultInfo: %s", info->result);
  2616. kfree(info);
  2617. return ret;
  2618. }
  2619. static DEVICE_ATTR(get_rawdata, 0444, get_rawdata_show, NULL);
  2620. int inspect_module_init(void)
  2621. {
  2622. int ret;
  2623. struct kobject *def_kobj = goodix_get_default_kobj();
  2624. /* create sysfs */
  2625. ret = sysfs_create_file(def_kobj, &dev_attr_get_rawdata.attr);
  2626. if (ret < 0) {
  2627. ts_err("create sysfs of get_rawdata failed");
  2628. goto err_out;
  2629. }
  2630. module_initialized = true;
  2631. ts_info("inspect module init success");
  2632. return 0;
  2633. err_out:
  2634. ts_err("inspect module init failed!");
  2635. return ret;
  2636. }
  2637. void inspect_module_exit(void)
  2638. {
  2639. struct kobject *def_kobj = goodix_get_default_kobj();
  2640. ts_info("inspect module exit");
  2641. if (!module_initialized)
  2642. return;
  2643. sysfs_remove_file(def_kobj, &dev_attr_get_rawdata.attr);
  2644. module_initialized = false;
  2645. }