goodix_ts_inspect.c 80 KB

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