synaptics_dsx_test_reporting.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324
  1. /*
  2. * Synaptics DSX touchscreen driver
  3. *
  4. * Copyright (C) 2012-2016 Synaptics Incorporated. All rights reserved.
  5. *
  6. * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
  7. * Copyright (C) 2012 Alexandra Chin <[email protected]>
  8. * Copyright (C) 2012 Scott Lin <[email protected]>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS
  21. * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
  23. * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS.
  24. * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION
  26. * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED
  27. * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  28. * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF
  29. * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES
  30. * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS'
  31. * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S.
  32. * DOLLARS.
  33. */
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/slab.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/delay.h>
  39. #include <linux/input.h>
  40. #include <linux/ctype.h>
  41. #include <linux/hrtimer.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/input/synaptics_dsx.h>
  44. #include "synaptics_dsx_core.h"
  45. #define SYSFS_FOLDER_NAME "f54"
  46. #define GET_REPORT_TIMEOUT_S 3
  47. #define CALIBRATION_TIMEOUT_S 10
  48. #define COMMAND_TIMEOUT_100MS 20
  49. #define NO_SLEEP_OFF (0 << 2)
  50. #define NO_SLEEP_ON (1 << 2)
  51. #define STATUS_IDLE 0
  52. #define STATUS_BUSY 1
  53. #define STATUS_ERROR 2
  54. #define REPORT_INDEX_OFFSET 1
  55. #define REPORT_DATA_OFFSET 3
  56. #define SENSOR_RX_MAPPING_OFFSET 1
  57. #define SENSOR_TX_MAPPING_OFFSET 2
  58. #define COMMAND_GET_REPORT 1
  59. #define COMMAND_FORCE_CAL 2
  60. #define COMMAND_FORCE_UPDATE 4
  61. #define CONTROL_NO_AUTO_CAL 1
  62. #define CONTROL_0_SIZE 1
  63. #define CONTROL_1_SIZE 1
  64. #define CONTROL_2_SIZE 2
  65. #define CONTROL_3_SIZE 1
  66. #define CONTROL_4_6_SIZE 3
  67. #define CONTROL_7_SIZE 1
  68. #define CONTROL_8_9_SIZE 3
  69. #define CONTROL_10_SIZE 1
  70. #define CONTROL_11_SIZE 2
  71. #define CONTROL_12_13_SIZE 2
  72. #define CONTROL_14_SIZE 1
  73. #define CONTROL_15_SIZE 1
  74. #define CONTROL_16_SIZE 1
  75. #define CONTROL_17_SIZE 1
  76. #define CONTROL_18_SIZE 1
  77. #define CONTROL_19_SIZE 1
  78. #define CONTROL_20_SIZE 1
  79. #define CONTROL_21_SIZE 2
  80. #define CONTROL_22_26_SIZE 7
  81. #define CONTROL_27_SIZE 1
  82. #define CONTROL_28_SIZE 2
  83. #define CONTROL_29_SIZE 1
  84. #define CONTROL_30_SIZE 1
  85. #define CONTROL_31_SIZE 1
  86. #define CONTROL_32_35_SIZE 8
  87. #define CONTROL_36_SIZE 1
  88. #define CONTROL_37_SIZE 1
  89. #define CONTROL_38_SIZE 1
  90. #define CONTROL_39_SIZE 1
  91. #define CONTROL_40_SIZE 1
  92. #define CONTROL_41_SIZE 1
  93. #define CONTROL_42_SIZE 2
  94. #define CONTROL_43_54_SIZE 13
  95. #define CONTROL_55_56_SIZE 2
  96. #define CONTROL_57_SIZE 1
  97. #define CONTROL_58_SIZE 1
  98. #define CONTROL_59_SIZE 2
  99. #define CONTROL_60_62_SIZE 3
  100. #define CONTROL_63_SIZE 1
  101. #define CONTROL_64_67_SIZE 4
  102. #define CONTROL_68_73_SIZE 8
  103. #define CONTROL_70_73_SIZE 6
  104. #define CONTROL_74_SIZE 2
  105. #define CONTROL_75_SIZE 1
  106. #define CONTROL_76_SIZE 1
  107. #define CONTROL_77_78_SIZE 2
  108. #define CONTROL_79_83_SIZE 5
  109. #define CONTROL_84_85_SIZE 2
  110. #define CONTROL_86_SIZE 1
  111. #define CONTROL_87_SIZE 1
  112. #define CONTROL_88_SIZE 1
  113. #define CONTROL_89_SIZE 1
  114. #define CONTROL_90_SIZE 1
  115. #define CONTROL_91_SIZE 1
  116. #define CONTROL_92_SIZE 1
  117. #define CONTROL_93_SIZE 1
  118. #define CONTROL_94_SIZE 1
  119. #define CONTROL_95_SIZE 1
  120. #define CONTROL_96_SIZE 1
  121. #define CONTROL_97_SIZE 1
  122. #define CONTROL_98_SIZE 1
  123. #define CONTROL_99_SIZE 1
  124. #define CONTROL_100_SIZE 1
  125. #define CONTROL_101_SIZE 1
  126. #define CONTROL_102_SIZE 1
  127. #define CONTROL_103_SIZE 1
  128. #define CONTROL_104_SIZE 1
  129. #define CONTROL_105_SIZE 1
  130. #define CONTROL_106_SIZE 1
  131. #define CONTROL_107_SIZE 1
  132. #define CONTROL_108_SIZE 1
  133. #define CONTROL_109_SIZE 1
  134. #define CONTROL_110_SIZE 1
  135. #define CONTROL_111_SIZE 1
  136. #define CONTROL_112_SIZE 1
  137. #define CONTROL_113_SIZE 1
  138. #define CONTROL_114_SIZE 1
  139. #define CONTROL_115_SIZE 1
  140. #define CONTROL_116_SIZE 1
  141. #define CONTROL_117_SIZE 1
  142. #define CONTROL_118_SIZE 1
  143. #define CONTROL_119_SIZE 1
  144. #define CONTROL_120_SIZE 1
  145. #define CONTROL_121_SIZE 1
  146. #define CONTROL_122_SIZE 1
  147. #define CONTROL_123_SIZE 1
  148. #define CONTROL_124_SIZE 1
  149. #define CONTROL_125_SIZE 1
  150. #define CONTROL_126_SIZE 1
  151. #define CONTROL_127_SIZE 1
  152. #define CONTROL_128_SIZE 1
  153. #define CONTROL_129_SIZE 1
  154. #define CONTROL_130_SIZE 1
  155. #define CONTROL_131_SIZE 1
  156. #define CONTROL_132_SIZE 1
  157. #define CONTROL_133_SIZE 1
  158. #define CONTROL_134_SIZE 1
  159. #define CONTROL_135_SIZE 1
  160. #define CONTROL_136_SIZE 1
  161. #define CONTROL_137_SIZE 1
  162. #define CONTROL_138_SIZE 1
  163. #define CONTROL_139_SIZE 1
  164. #define CONTROL_140_SIZE 1
  165. #define CONTROL_141_SIZE 1
  166. #define CONTROL_142_SIZE 1
  167. #define CONTROL_143_SIZE 1
  168. #define CONTROL_144_SIZE 1
  169. #define CONTROL_145_SIZE 1
  170. #define CONTROL_146_SIZE 1
  171. #define CONTROL_147_SIZE 1
  172. #define CONTROL_148_SIZE 1
  173. #define CONTROL_149_SIZE 1
  174. #define CONTROL_150_SIZE 1
  175. #define CONTROL_151_SIZE 1
  176. #define CONTROL_152_SIZE 1
  177. #define CONTROL_153_SIZE 1
  178. #define CONTROL_154_SIZE 1
  179. #define CONTROL_155_SIZE 1
  180. #define CONTROL_156_SIZE 1
  181. #define CONTROL_157_158_SIZE 2
  182. #define CONTROL_163_SIZE 1
  183. #define CONTROL_165_SIZE 1
  184. #define CONTROL_166_SIZE 1
  185. #define CONTROL_167_SIZE 1
  186. #define CONTROL_168_SIZE 1
  187. #define CONTROL_169_SIZE 1
  188. #define CONTROL_171_SIZE 1
  189. #define CONTROL_172_SIZE 1
  190. #define CONTROL_173_SIZE 1
  191. #define CONTROL_174_SIZE 1
  192. #define CONTROL_175_SIZE 1
  193. #define CONTROL_176_SIZE 1
  194. #define CONTROL_177_178_SIZE 2
  195. #define CONTROL_179_SIZE 1
  196. #define CONTROL_182_SIZE 1
  197. #define CONTROL_183_SIZE 1
  198. #define CONTROL_185_SIZE 1
  199. #define CONTROL_186_SIZE 1
  200. #define CONTROL_187_SIZE 1
  201. #define CONTROL_188_SIZE 1
  202. #define HIGH_RESISTANCE_DATA_SIZE 6
  203. #define FULL_RAW_CAP_MIN_MAX_DATA_SIZE 4
  204. #define TRX_OPEN_SHORT_DATA_SIZE 7
  205. #define attrify(propname) (&dev_attr_##propname.attr)
  206. #define show_prototype(propname)\
  207. static ssize_t propname##_show(\
  208. struct device *dev,\
  209. struct device_attribute *attr,\
  210. char *buf);\
  211. \
  212. static struct device_attribute dev_attr_##propname =\
  213. __ATTR_RO(propname)
  214. #define store_prototype(propname)\
  215. static ssize_t propname##_store(\
  216. struct device *dev,\
  217. struct device_attribute *attr,\
  218. const char *buf, size_t count);\
  219. \
  220. static struct device_attribute dev_attr_##propname =\
  221. __ATTR_WO(propname)
  222. #define show_store_prototype(propname)\
  223. static ssize_t propname##_show(\
  224. struct device *dev,\
  225. struct device_attribute *attr,\
  226. char *buf);\
  227. \
  228. static ssize_t propname##_store(\
  229. struct device *dev,\
  230. struct device_attribute *attr,\
  231. const char *buf, size_t count);\
  232. \
  233. static struct device_attribute dev_attr_##propname =\
  234. __ATTR_RW(propname)
  235. #define disable_cbc(ctrl_num)\
  236. do {\
  237. retval = synaptics_rmi4_reg_read(rmi4_data,\
  238. f54->control.ctrl_num->address,\
  239. f54->control.ctrl_num->data,\
  240. sizeof(f54->control.ctrl_num->data));\
  241. if (retval < 0) {\
  242. dev_err(rmi4_data->pdev->dev.parent,\
  243. "%s: Failed to disable CBC (" #ctrl_num ")\n",\
  244. __func__);\
  245. return retval;\
  246. } \
  247. f54->control.ctrl_num->cbc_tx_carrier_selection = 0;\
  248. retval = synaptics_rmi4_reg_write(rmi4_data,\
  249. f54->control.ctrl_num->address,\
  250. f54->control.ctrl_num->data,\
  251. sizeof(f54->control.ctrl_num->data));\
  252. if (retval < 0) {\
  253. dev_err(rmi4_data->pdev->dev.parent,\
  254. "%s: Failed to disable CBC (" #ctrl_num ")\n",\
  255. __func__);\
  256. return retval;\
  257. } \
  258. } while (0)
  259. enum f54_report_types {
  260. F54_8BIT_IMAGE = 1,
  261. F54_16BIT_IMAGE = 2,
  262. F54_RAW_16BIT_IMAGE = 3,
  263. F54_HIGH_RESISTANCE = 4,
  264. F54_TX_TO_TX_SHORTS = 5,
  265. F54_RX_TO_RX_SHORTS_1 = 7,
  266. F54_TRUE_BASELINE = 9,
  267. F54_FULL_RAW_CAP_MIN_MAX = 13,
  268. F54_RX_OPENS_1 = 14,
  269. F54_TX_OPENS = 15,
  270. F54_TX_TO_GND_SHORTS = 16,
  271. F54_RX_TO_RX_SHORTS_2 = 17,
  272. F54_RX_OPENS_2 = 18,
  273. F54_FULL_RAW_CAP = 19,
  274. F54_FULL_RAW_CAP_NO_RX_COUPLING = 20,
  275. F54_SENSOR_SPEED = 22,
  276. F54_ADC_RANGE = 23,
  277. F54_TRX_OPENS = 24,
  278. F54_TRX_TO_GND_SHORTS = 25,
  279. F54_TRX_SHORTS = 26,
  280. F54_ABS_RAW_CAP = 38,
  281. F54_ABS_DELTA_CAP = 40,
  282. F54_ABS_HYBRID_DELTA_CAP = 59,
  283. F54_ABS_HYBRID_RAW_CAP = 63,
  284. F54_AMP_FULL_RAW_CAP = 78,
  285. F54_AMP_RAW_ADC = 83,
  286. F54_FULL_RAW_CAP_TDDI = 92,
  287. INVALID_REPORT_TYPE = -1,
  288. };
  289. enum f54_afe_cal {
  290. F54_AFE_CAL,
  291. F54_AFE_IS_CAL,
  292. };
  293. struct f54_query {
  294. union {
  295. struct {
  296. /* query 0 */
  297. unsigned char num_of_rx_electrodes;
  298. /* query 1 */
  299. unsigned char num_of_tx_electrodes;
  300. /* query 2 */
  301. unsigned char f54_query2_b0__1:2;
  302. unsigned char has_baseline:1;
  303. unsigned char has_image8:1;
  304. unsigned char f54_query2_b4__5:2;
  305. unsigned char has_image16:1;
  306. unsigned char f54_query2_b7:1;
  307. /* queries 3.0 and 3.1 */
  308. unsigned short clock_rate;
  309. /* query 4 */
  310. unsigned char touch_controller_family;
  311. /* query 5 */
  312. unsigned char has_pixel_touch_threshold_adjustment:1;
  313. unsigned char f54_query5_b1__7:7;
  314. /* query 6 */
  315. unsigned char has_sensor_assignment:1;
  316. unsigned char has_interference_metric:1;
  317. unsigned char has_sense_frequency_control:1;
  318. unsigned char has_firmware_noise_mitigation:1;
  319. unsigned char has_ctrl11:1;
  320. unsigned char has_two_byte_report_rate:1;
  321. unsigned char has_one_byte_report_rate:1;
  322. unsigned char has_relaxation_control:1;
  323. /* query 7 */
  324. unsigned char curve_compensation_mode:2;
  325. unsigned char f54_query7_b2__7:6;
  326. /* query 8 */
  327. unsigned char f54_query8_b0:1;
  328. unsigned char has_iir_filter:1;
  329. unsigned char has_cmn_removal:1;
  330. unsigned char has_cmn_maximum:1;
  331. unsigned char has_touch_hysteresis:1;
  332. unsigned char has_edge_compensation:1;
  333. unsigned char has_per_frequency_noise_control:1;
  334. unsigned char has_enhanced_stretch:1;
  335. /* query 9 */
  336. unsigned char has_force_fast_relaxation:1;
  337. unsigned char has_multi_metric_state_machine:1;
  338. unsigned char has_signal_clarity:1;
  339. unsigned char has_variance_metric:1;
  340. unsigned char has_0d_relaxation_control:1;
  341. unsigned char has_0d_acquisition_control:1;
  342. unsigned char has_status:1;
  343. unsigned char has_slew_metric:1;
  344. /* query 10 */
  345. unsigned char has_h_blank:1;
  346. unsigned char has_v_blank:1;
  347. unsigned char has_long_h_blank:1;
  348. unsigned char has_startup_fast_relaxation:1;
  349. unsigned char has_esd_control:1;
  350. unsigned char has_noise_mitigation2:1;
  351. unsigned char has_noise_state:1;
  352. unsigned char has_energy_ratio_relaxation:1;
  353. /* query 11 */
  354. unsigned char has_excessive_noise_reporting:1;
  355. unsigned char has_slew_option:1;
  356. unsigned char has_two_overhead_bursts:1;
  357. unsigned char has_query13:1;
  358. unsigned char has_one_overhead_burst:1;
  359. unsigned char f54_query11_b5:1;
  360. unsigned char has_ctrl88:1;
  361. unsigned char has_query15:1;
  362. /* query 12 */
  363. unsigned char number_of_sensing_frequencies:4;
  364. unsigned char f54_query12_b4__7:4;
  365. } __packed;
  366. unsigned char data[14];
  367. };
  368. };
  369. struct f54_query_13 {
  370. union {
  371. struct {
  372. unsigned char has_ctrl86:1;
  373. unsigned char has_ctrl87:1;
  374. unsigned char has_ctrl87_sub0:1;
  375. unsigned char has_ctrl87_sub1:1;
  376. unsigned char has_ctrl87_sub2:1;
  377. unsigned char has_cidim:1;
  378. unsigned char has_noise_mitigation_enhancement:1;
  379. unsigned char has_rail_im:1;
  380. } __packed;
  381. unsigned char data[1];
  382. };
  383. };
  384. struct f54_query_15 {
  385. union {
  386. struct {
  387. unsigned char has_ctrl90:1;
  388. unsigned char has_transmit_strength:1;
  389. unsigned char has_ctrl87_sub3:1;
  390. unsigned char has_query16:1;
  391. unsigned char has_query20:1;
  392. unsigned char has_query21:1;
  393. unsigned char has_query22:1;
  394. unsigned char has_query25:1;
  395. } __packed;
  396. unsigned char data[1];
  397. };
  398. };
  399. struct f54_query_16 {
  400. union {
  401. struct {
  402. unsigned char has_query17:1;
  403. unsigned char has_data17:1;
  404. unsigned char has_ctrl92:1;
  405. unsigned char has_ctrl93:1;
  406. unsigned char has_ctrl94_query18:1;
  407. unsigned char has_ctrl95_query19:1;
  408. unsigned char has_ctrl99:1;
  409. unsigned char has_ctrl100:1;
  410. } __packed;
  411. unsigned char data[1];
  412. };
  413. };
  414. struct f54_query_21 {
  415. union {
  416. struct {
  417. unsigned char has_abs_rx:1;
  418. unsigned char has_abs_tx:1;
  419. unsigned char has_ctrl91:1;
  420. unsigned char has_ctrl96:1;
  421. unsigned char has_ctrl97:1;
  422. unsigned char has_ctrl98:1;
  423. unsigned char has_data19:1;
  424. unsigned char has_query24_data18:1;
  425. } __packed;
  426. unsigned char data[1];
  427. };
  428. };
  429. struct f54_query_22 {
  430. union {
  431. struct {
  432. unsigned char has_packed_image:1;
  433. unsigned char has_ctrl101:1;
  434. unsigned char has_dynamic_sense_display_ratio:1;
  435. unsigned char has_query23:1;
  436. unsigned char has_ctrl103_query26:1;
  437. unsigned char has_ctrl104:1;
  438. unsigned char has_ctrl105:1;
  439. unsigned char has_query28:1;
  440. } __packed;
  441. unsigned char data[1];
  442. };
  443. };
  444. struct f54_query_23 {
  445. union {
  446. struct {
  447. unsigned char has_ctrl102:1;
  448. unsigned char has_ctrl102_sub1:1;
  449. unsigned char has_ctrl102_sub2:1;
  450. unsigned char has_ctrl102_sub4:1;
  451. unsigned char has_ctrl102_sub5:1;
  452. unsigned char has_ctrl102_sub9:1;
  453. unsigned char has_ctrl102_sub10:1;
  454. unsigned char has_ctrl102_sub11:1;
  455. } __packed;
  456. unsigned char data[1];
  457. };
  458. };
  459. struct f54_query_25 {
  460. union {
  461. struct {
  462. unsigned char has_ctrl106:1;
  463. unsigned char has_ctrl102_sub12:1;
  464. unsigned char has_ctrl107:1;
  465. unsigned char has_ctrl108:1;
  466. unsigned char has_ctrl109:1;
  467. unsigned char has_data20:1;
  468. unsigned char f54_query25_b6:1;
  469. unsigned char has_query27:1;
  470. } __packed;
  471. unsigned char data[1];
  472. };
  473. };
  474. struct f54_query_27 {
  475. union {
  476. struct {
  477. unsigned char has_ctrl110:1;
  478. unsigned char has_data21:1;
  479. unsigned char has_ctrl111:1;
  480. unsigned char has_ctrl112:1;
  481. unsigned char has_ctrl113:1;
  482. unsigned char has_data22:1;
  483. unsigned char has_ctrl114:1;
  484. unsigned char has_query29:1;
  485. } __packed;
  486. unsigned char data[1];
  487. };
  488. };
  489. struct f54_query_29 {
  490. union {
  491. struct {
  492. unsigned char has_ctrl115:1;
  493. unsigned char has_ground_ring_options:1;
  494. unsigned char has_lost_bursts_tuning:1;
  495. unsigned char has_aux_exvcom2_select:1;
  496. unsigned char has_ctrl116:1;
  497. unsigned char has_data23:1;
  498. unsigned char has_ctrl117:1;
  499. unsigned char has_query30:1;
  500. } __packed;
  501. unsigned char data[1];
  502. };
  503. };
  504. struct f54_query_30 {
  505. union {
  506. struct {
  507. unsigned char has_ctrl118:1;
  508. unsigned char has_ctrl119:1;
  509. unsigned char has_ctrl120:1;
  510. unsigned char has_ctrl121:1;
  511. unsigned char has_ctrl122_query31:1;
  512. unsigned char has_ctrl123:1;
  513. unsigned char has_ctrl124:1;
  514. unsigned char has_query32:1;
  515. } __packed;
  516. unsigned char data[1];
  517. };
  518. };
  519. struct f54_query_32 {
  520. union {
  521. struct {
  522. unsigned char has_ctrl125:1;
  523. unsigned char has_ctrl126:1;
  524. unsigned char has_ctrl127:1;
  525. unsigned char has_abs_charge_pump_disable:1;
  526. unsigned char has_query33:1;
  527. unsigned char has_data24:1;
  528. unsigned char has_query34:1;
  529. unsigned char has_query35:1;
  530. } __packed;
  531. unsigned char data[1];
  532. };
  533. };
  534. struct f54_query_33 {
  535. union {
  536. struct {
  537. unsigned char has_ctrl128:1;
  538. unsigned char has_ctrl129:1;
  539. unsigned char has_ctrl130:1;
  540. unsigned char has_ctrl131:1;
  541. unsigned char has_ctrl132:1;
  542. unsigned char has_ctrl133:1;
  543. unsigned char has_ctrl134:1;
  544. unsigned char has_query36:1;
  545. } __packed;
  546. unsigned char data[1];
  547. };
  548. };
  549. struct f54_query_35 {
  550. union {
  551. struct {
  552. unsigned char has_data25:1;
  553. unsigned char has_ctrl135:1;
  554. unsigned char has_ctrl136:1;
  555. unsigned char has_ctrl137:1;
  556. unsigned char has_ctrl138:1;
  557. unsigned char has_ctrl139:1;
  558. unsigned char has_data26:1;
  559. unsigned char has_ctrl140:1;
  560. } __packed;
  561. unsigned char data[1];
  562. };
  563. };
  564. struct f54_query_36 {
  565. union {
  566. struct {
  567. unsigned char has_ctrl141:1;
  568. unsigned char has_ctrl142:1;
  569. unsigned char has_query37:1;
  570. unsigned char has_ctrl143:1;
  571. unsigned char has_ctrl144:1;
  572. unsigned char has_ctrl145:1;
  573. unsigned char has_ctrl146:1;
  574. unsigned char has_query38:1;
  575. } __packed;
  576. unsigned char data[1];
  577. };
  578. };
  579. struct f54_query_38 {
  580. union {
  581. struct {
  582. unsigned char has_ctrl147:1;
  583. unsigned char has_ctrl148:1;
  584. unsigned char has_ctrl149:1;
  585. unsigned char has_ctrl150:1;
  586. unsigned char has_ctrl151:1;
  587. unsigned char has_ctrl152:1;
  588. unsigned char has_ctrl153:1;
  589. unsigned char has_query39:1;
  590. } __packed;
  591. unsigned char data[1];
  592. };
  593. };
  594. struct f54_query_39 {
  595. union {
  596. struct {
  597. unsigned char has_ctrl154:1;
  598. unsigned char has_ctrl155:1;
  599. unsigned char has_ctrl156:1;
  600. unsigned char has_ctrl160:1;
  601. unsigned char has_ctrl157_ctrl158:1;
  602. unsigned char f54_query39_b5__6:2;
  603. unsigned char has_query40:1;
  604. } __packed;
  605. unsigned char data[1];
  606. };
  607. };
  608. struct f54_query_40 {
  609. union {
  610. struct {
  611. unsigned char has_ctrl169:1;
  612. unsigned char has_ctrl163_query41:1;
  613. unsigned char f54_query40_b2:1;
  614. unsigned char has_ctrl165_query42:1;
  615. unsigned char has_ctrl166:1;
  616. unsigned char has_ctrl167:1;
  617. unsigned char has_ctrl168:1;
  618. unsigned char has_query43:1;
  619. } __packed;
  620. unsigned char data[1];
  621. };
  622. };
  623. struct f54_query_43 {
  624. union {
  625. struct {
  626. unsigned char f54_query43_b0__1:2;
  627. unsigned char has_ctrl171:1;
  628. unsigned char has_ctrl172_query44_query45:1;
  629. unsigned char has_ctrl173:1;
  630. unsigned char has_ctrl174:1;
  631. unsigned char has_ctrl175:1;
  632. unsigned char has_query46:1;
  633. } __packed;
  634. unsigned char data[1];
  635. };
  636. };
  637. struct f54_query_46 {
  638. union {
  639. struct {
  640. unsigned char has_ctrl176:1;
  641. unsigned char has_ctrl177_ctrl178:1;
  642. unsigned char has_ctrl179:1;
  643. unsigned char f54_query46_b3:1;
  644. unsigned char has_data27:1;
  645. unsigned char has_data28:1;
  646. unsigned char f54_query46_b6:1;
  647. unsigned char has_query47:1;
  648. } __packed;
  649. unsigned char data[1];
  650. };
  651. };
  652. struct f54_query_47 {
  653. union {
  654. struct {
  655. unsigned char f54_query47_b0:1;
  656. unsigned char has_ctrl182:1;
  657. unsigned char has_ctrl183:1;
  658. unsigned char f54_query47_b3:1;
  659. unsigned char has_ctrl185:1;
  660. unsigned char has_ctrl186:1;
  661. unsigned char has_ctrl187:1;
  662. unsigned char has_query49:1;
  663. } __packed;
  664. unsigned char data[1];
  665. };
  666. };
  667. struct f54_query_49 {
  668. union {
  669. struct {
  670. unsigned char f54_query49_b0__1:2;
  671. unsigned char has_ctrl188:1;
  672. unsigned char has_data31:1;
  673. unsigned char f54_query49_b4__6:3;
  674. unsigned char has_query50:1;
  675. } __packed;
  676. unsigned char data[1];
  677. };
  678. };
  679. struct f54_query_50 {
  680. union {
  681. struct {
  682. unsigned char f54_query50_b0__6:7;
  683. unsigned char has_query51:1;
  684. } __packed;
  685. unsigned char data[1];
  686. };
  687. };
  688. struct f54_query_51 {
  689. union {
  690. struct {
  691. unsigned char f54_query51_b0__4:5;
  692. unsigned char has_query53_query54_ctrl198:1;
  693. unsigned char has_ctrl199:1;
  694. unsigned char has_query55:1;
  695. } __packed;
  696. unsigned char data[1];
  697. };
  698. };
  699. struct f54_query_55 {
  700. union {
  701. struct {
  702. unsigned char has_query56:1;
  703. unsigned char has_data33_data34:1;
  704. unsigned char has_alt_report_rate:1;
  705. unsigned char has_ctrl200:1;
  706. unsigned char has_ctrl201_ctrl202:1;
  707. unsigned char has_ctrl203:1;
  708. unsigned char has_ctrl204:1;
  709. unsigned char has_query57:1;
  710. } __packed;
  711. unsigned char data[1];
  712. };
  713. };
  714. struct f54_query_57 {
  715. union {
  716. struct {
  717. unsigned char has_ctrl205:1;
  718. unsigned char has_ctrl206:1;
  719. unsigned char has_usb_bulk_read:1;
  720. unsigned char has_ctrl207:1;
  721. unsigned char has_ctrl208:1;
  722. unsigned char has_ctrl209:1;
  723. unsigned char has_ctrl210:1;
  724. unsigned char has_query58:1;
  725. } __packed;
  726. unsigned char data[1];
  727. };
  728. };
  729. struct f54_query_58 {
  730. union {
  731. struct {
  732. unsigned char has_query59:1;
  733. unsigned char has_query60:1;
  734. unsigned char has_ctrl211:1;
  735. unsigned char has_ctrl212:1;
  736. unsigned char has_hybrid_abs_tx_axis_filtering:1;
  737. unsigned char has_hybrid_abs_tx_interpolation:1;
  738. unsigned char has_ctrl213:1;
  739. unsigned char has_query61:1;
  740. } __packed;
  741. unsigned char data[1];
  742. };
  743. };
  744. struct f54_query_61 {
  745. union {
  746. struct {
  747. unsigned char has_ctrl214:1;
  748. unsigned char has_ctrl215_query62_query63:1;
  749. unsigned char f54_query_61_b2:1;
  750. unsigned char has_ctrl216:1;
  751. unsigned char has_ctrl217:1;
  752. unsigned char has_misc_host_ctrl:1;
  753. unsigned char hybrid_abs_buttons:1;
  754. unsigned char has_query64:1;
  755. } __packed;
  756. unsigned char data[1];
  757. };
  758. };
  759. struct f54_query_64 {
  760. union {
  761. struct {
  762. unsigned char has_ctrl101_sub1:1;
  763. unsigned char has_ctrl220:1;
  764. unsigned char has_ctrl221:1;
  765. unsigned char has_ctrl222:1;
  766. unsigned char has_ctrl219_sub1:1;
  767. unsigned char has_ctrl103_sub3:1;
  768. unsigned char has_ctrl224_ctrl226_ctrl227:1;
  769. unsigned char has_query65:1;
  770. } __packed;
  771. unsigned char data[1];
  772. };
  773. };
  774. struct f54_query_65 {
  775. union {
  776. struct {
  777. unsigned char f54_query_65_b0__1:2;
  778. unsigned char has_ctrl101_sub2:1;
  779. unsigned char f54_query_65_b3__4:2;
  780. unsigned char has_query66_ctrl231:1;
  781. unsigned char has_ctrl232:1;
  782. unsigned char has_query67:1;
  783. } __packed;
  784. unsigned char data[1];
  785. };
  786. };
  787. struct f54_query_67 {
  788. union {
  789. struct {
  790. unsigned char has_abs_doze_spatial_filter_en:1;
  791. unsigned char has_abs_doze_avg_filter_enhancement_en:1;
  792. unsigned char has_single_display_pulse:1;
  793. unsigned char f54_query_67_b3__4:2;
  794. unsigned char has_ctrl235_ctrl236:1;
  795. unsigned char f54_query_67_b6:1;
  796. unsigned char has_query68:1;
  797. } __packed;
  798. unsigned char data[1];
  799. };
  800. };
  801. struct f54_query_68 {
  802. union {
  803. struct {
  804. unsigned char f54_query_68_b0:1;
  805. unsigned char has_ctrl238:1;
  806. unsigned char has_ctrl238_sub1:1;
  807. unsigned char has_ctrl238_sub2:1;
  808. unsigned char has_ctrl239:1;
  809. unsigned char has_freq_filter_bw_ext:1;
  810. unsigned char is_tddi_hic:1;
  811. unsigned char has_query69:1;
  812. } __packed;
  813. unsigned char data[1];
  814. };
  815. };
  816. struct f54_query_69 {
  817. union {
  818. struct {
  819. unsigned char has_ctrl240_sub0:1;
  820. unsigned char has_ctrl240_sub1_sub2:1;
  821. unsigned char has_ctrl240_sub3:1;
  822. unsigned char has_ctrl240_sub4:1;
  823. unsigned char f54_query_69_b4__7:4;
  824. } __packed;
  825. unsigned char data[1];
  826. };
  827. };
  828. struct f54_data_31 {
  829. union {
  830. struct {
  831. unsigned char is_calibration_crc:1;
  832. unsigned char calibration_crc:1;
  833. unsigned char short_test_row_number:5;
  834. } __packed;
  835. struct {
  836. unsigned char data[1];
  837. unsigned short address;
  838. } __packed;
  839. };
  840. };
  841. struct f54_control_7 {
  842. union {
  843. struct {
  844. unsigned char cbc_cap:3;
  845. unsigned char cbc_polarity:1;
  846. unsigned char cbc_tx_carrier_selection:1;
  847. unsigned char f54_ctrl7_b5__7:3;
  848. } __packed;
  849. struct {
  850. unsigned char data[1];
  851. unsigned short address;
  852. } __packed;
  853. };
  854. };
  855. struct f54_control_41 {
  856. union {
  857. struct {
  858. unsigned char no_signal_clarity:1;
  859. unsigned char f54_ctrl41_b1__7:7;
  860. } __packed;
  861. struct {
  862. unsigned char data[1];
  863. unsigned short address;
  864. } __packed;
  865. };
  866. };
  867. struct f54_control_57 {
  868. union {
  869. struct {
  870. unsigned char cbc_cap:3;
  871. unsigned char cbc_polarity:1;
  872. unsigned char cbc_tx_carrier_selection:1;
  873. unsigned char f54_ctrl57_b5__7:3;
  874. } __packed;
  875. struct {
  876. unsigned char data[1];
  877. unsigned short address;
  878. } __packed;
  879. };
  880. };
  881. struct f54_control_86 {
  882. union {
  883. struct {
  884. unsigned char enable_high_noise_state:1;
  885. unsigned char dynamic_sense_display_ratio:2;
  886. unsigned char f54_ctrl86_b3__7:5;
  887. } __packed;
  888. struct {
  889. unsigned char data[1];
  890. unsigned short address;
  891. } __packed;
  892. };
  893. };
  894. struct f54_control_88 {
  895. union {
  896. struct {
  897. unsigned char tx_low_reference_polarity:1;
  898. unsigned char tx_high_reference_polarity:1;
  899. unsigned char abs_low_reference_polarity:1;
  900. unsigned char abs_polarity:1;
  901. unsigned char cbc_polarity:1;
  902. unsigned char cbc_tx_carrier_selection:1;
  903. unsigned char charge_pump_enable:1;
  904. unsigned char cbc_abs_auto_servo:1;
  905. } __packed;
  906. struct {
  907. unsigned char data[1];
  908. unsigned short address;
  909. } __packed;
  910. };
  911. };
  912. struct f54_control_110 {
  913. union {
  914. struct {
  915. unsigned char active_stylus_rx_feedback_cap;
  916. unsigned char active_stylus_rx_feedback_cap_reference;
  917. unsigned char active_stylus_low_reference;
  918. unsigned char active_stylus_high_reference;
  919. unsigned char active_stylus_gain_control;
  920. unsigned char active_stylus_gain_control_reference;
  921. unsigned char active_stylus_timing_mode;
  922. unsigned char active_stylus_discovery_bursts;
  923. unsigned char active_stylus_detection_bursts;
  924. unsigned char active_stylus_discovery_noise_multiplier;
  925. unsigned char active_stylus_detection_envelope_min;
  926. unsigned char active_stylus_detection_envelope_max;
  927. unsigned char active_stylus_lose_count;
  928. } __packed;
  929. struct {
  930. unsigned char data[13];
  931. unsigned short address;
  932. } __packed;
  933. };
  934. };
  935. struct f54_control_149 {
  936. union {
  937. struct {
  938. unsigned char trans_cbc_global_cap_enable:1;
  939. unsigned char f54_ctrl149_b1__7:7;
  940. } __packed;
  941. struct {
  942. unsigned char data[1];
  943. unsigned short address;
  944. } __packed;
  945. };
  946. };
  947. struct f54_control_188 {
  948. union {
  949. struct {
  950. unsigned char start_calibration:1;
  951. unsigned char start_is_calibration:1;
  952. unsigned char frequency:2;
  953. unsigned char start_production_test:1;
  954. unsigned char short_test_calibration:1;
  955. unsigned char f54_ctrl188_b7:1;
  956. } __packed;
  957. struct {
  958. unsigned char data[1];
  959. unsigned short address;
  960. } __packed;
  961. };
  962. };
  963. struct f54_control {
  964. struct f54_control_7 *reg_7;
  965. struct f54_control_41 *reg_41;
  966. struct f54_control_57 *reg_57;
  967. struct f54_control_86 *reg_86;
  968. struct f54_control_88 *reg_88;
  969. struct f54_control_110 *reg_110;
  970. struct f54_control_149 *reg_149;
  971. struct f54_control_188 *reg_188;
  972. };
  973. struct synaptics_rmi4_f54_handle {
  974. bool no_auto_cal;
  975. bool skip_preparation;
  976. unsigned char status;
  977. unsigned char intr_mask;
  978. unsigned char intr_reg_num;
  979. unsigned char tx_assigned;
  980. unsigned char rx_assigned;
  981. unsigned char *report_data;
  982. unsigned short query_base_addr;
  983. unsigned short control_base_addr;
  984. unsigned short data_base_addr;
  985. unsigned short command_base_addr;
  986. unsigned short fifoindex;
  987. unsigned int report_size;
  988. unsigned int data_buffer_size;
  989. unsigned int data_pos;
  990. enum f54_report_types report_type;
  991. struct f54_query query;
  992. struct f54_query_13 query_13;
  993. struct f54_query_15 query_15;
  994. struct f54_query_16 query_16;
  995. struct f54_query_21 query_21;
  996. struct f54_query_22 query_22;
  997. struct f54_query_23 query_23;
  998. struct f54_query_25 query_25;
  999. struct f54_query_27 query_27;
  1000. struct f54_query_29 query_29;
  1001. struct f54_query_30 query_30;
  1002. struct f54_query_32 query_32;
  1003. struct f54_query_33 query_33;
  1004. struct f54_query_35 query_35;
  1005. struct f54_query_36 query_36;
  1006. struct f54_query_38 query_38;
  1007. struct f54_query_39 query_39;
  1008. struct f54_query_40 query_40;
  1009. struct f54_query_43 query_43;
  1010. struct f54_query_46 query_46;
  1011. struct f54_query_47 query_47;
  1012. struct f54_query_49 query_49;
  1013. struct f54_query_50 query_50;
  1014. struct f54_query_51 query_51;
  1015. struct f54_query_55 query_55;
  1016. struct f54_query_57 query_57;
  1017. struct f54_query_58 query_58;
  1018. struct f54_query_61 query_61;
  1019. struct f54_query_64 query_64;
  1020. struct f54_query_65 query_65;
  1021. struct f54_query_67 query_67;
  1022. struct f54_query_68 query_68;
  1023. struct f54_query_69 query_69;
  1024. struct f54_data_31 data_31;
  1025. struct f54_control control;
  1026. struct mutex status_mutex;
  1027. struct kobject *sysfs_dir;
  1028. struct hrtimer watchdog;
  1029. struct work_struct timeout_work;
  1030. struct work_struct test_report_work;
  1031. struct workqueue_struct *test_report_workqueue;
  1032. struct synaptics_rmi4_data *rmi4_data;
  1033. };
  1034. struct f55_query {
  1035. union {
  1036. struct {
  1037. /* query 0 */
  1038. unsigned char num_of_rx_electrodes;
  1039. /* query 1 */
  1040. unsigned char num_of_tx_electrodes;
  1041. /* query 2 */
  1042. unsigned char has_sensor_assignment:1;
  1043. unsigned char has_edge_compensation:1;
  1044. unsigned char curve_compensation_mode:2;
  1045. unsigned char has_ctrl6:1;
  1046. unsigned char has_alternate_transmitter_assignment:1;
  1047. unsigned char has_single_layer_multi_touch:1;
  1048. unsigned char has_query5:1;
  1049. } __packed;
  1050. unsigned char data[3];
  1051. };
  1052. };
  1053. struct f55_query_3 {
  1054. union {
  1055. struct {
  1056. unsigned char has_ctrl8:1;
  1057. unsigned char has_ctrl9:1;
  1058. unsigned char has_oncell_pattern_support:1;
  1059. unsigned char has_data0:1;
  1060. unsigned char has_single_wide_pattern_support:1;
  1061. unsigned char has_mirrored_tx_pattern_support:1;
  1062. unsigned char has_discrete_pattern_support:1;
  1063. unsigned char has_query9:1;
  1064. } __packed;
  1065. unsigned char data[1];
  1066. };
  1067. };
  1068. struct f55_query_5 {
  1069. union {
  1070. struct {
  1071. unsigned char has_corner_compensation:1;
  1072. unsigned char has_ctrl12:1;
  1073. unsigned char has_trx_configuration:1;
  1074. unsigned char has_ctrl13:1;
  1075. unsigned char f55_query5_b4:1;
  1076. unsigned char has_ctrl14:1;
  1077. unsigned char has_basis_function:1;
  1078. unsigned char has_query17:1;
  1079. } __packed;
  1080. unsigned char data[1];
  1081. };
  1082. };
  1083. struct f55_query_17 {
  1084. union {
  1085. struct {
  1086. unsigned char f55_query17_b0:1;
  1087. unsigned char has_ctrl16:1;
  1088. unsigned char has_ctrl18_ctrl19:1;
  1089. unsigned char has_ctrl17:1;
  1090. unsigned char has_ctrl20:1;
  1091. unsigned char has_ctrl21:1;
  1092. unsigned char has_ctrl22:1;
  1093. unsigned char has_query18:1;
  1094. } __packed;
  1095. unsigned char data[1];
  1096. };
  1097. };
  1098. struct f55_query_18 {
  1099. union {
  1100. struct {
  1101. unsigned char has_ctrl23:1;
  1102. unsigned char has_ctrl24:1;
  1103. unsigned char has_query19:1;
  1104. unsigned char has_ctrl25:1;
  1105. unsigned char has_ctrl26:1;
  1106. unsigned char has_ctrl27_query20:1;
  1107. unsigned char has_ctrl28_query21:1;
  1108. unsigned char has_query22:1;
  1109. } __packed;
  1110. unsigned char data[1];
  1111. };
  1112. };
  1113. struct f55_query_22 {
  1114. union {
  1115. struct {
  1116. unsigned char has_ctrl29:1;
  1117. unsigned char has_query23:1;
  1118. unsigned char has_guard_disable:1;
  1119. unsigned char has_ctrl30:1;
  1120. unsigned char has_ctrl31:1;
  1121. unsigned char has_ctrl32:1;
  1122. unsigned char has_query24_through_query27:1;
  1123. unsigned char has_query28:1;
  1124. } __packed;
  1125. unsigned char data[1];
  1126. };
  1127. };
  1128. struct f55_query_23 {
  1129. union {
  1130. struct {
  1131. unsigned char amp_sensor_enabled:1;
  1132. unsigned char image_transposed:1;
  1133. unsigned char first_column_at_left_side:1;
  1134. unsigned char size_of_column2mux:5;
  1135. } __packed;
  1136. unsigned char data[1];
  1137. };
  1138. };
  1139. struct f55_query_28 {
  1140. union {
  1141. struct {
  1142. unsigned char f55_query28_b0__4:5;
  1143. unsigned char has_ctrl37:1;
  1144. unsigned char has_query29:1;
  1145. unsigned char has_query30:1;
  1146. } __packed;
  1147. unsigned char data[1];
  1148. };
  1149. };
  1150. struct f55_query_30 {
  1151. union {
  1152. struct {
  1153. unsigned char has_ctrl38:1;
  1154. unsigned char has_query31_query32:1;
  1155. unsigned char has_ctrl39:1;
  1156. unsigned char has_ctrl40:1;
  1157. unsigned char has_ctrl41:1;
  1158. unsigned char has_ctrl42:1;
  1159. unsigned char has_ctrl43_ctrl44:1;
  1160. unsigned char has_query33:1;
  1161. } __packed;
  1162. unsigned char data[1];
  1163. };
  1164. };
  1165. struct f55_query_33 {
  1166. union {
  1167. struct {
  1168. unsigned char has_extended_amp_pad:1;
  1169. unsigned char has_extended_amp_btn:1;
  1170. unsigned char has_ctrl45_ctrl46:1;
  1171. unsigned char f55_query33_b3:1;
  1172. unsigned char has_ctrl47_sub0_sub1:1;
  1173. unsigned char f55_query33_b5__7:3;
  1174. } __packed;
  1175. unsigned char data[1];
  1176. };
  1177. };
  1178. struct f55_control_43 {
  1179. union {
  1180. struct {
  1181. unsigned char swap_sensor_side:1;
  1182. unsigned char f55_ctrl43_b1__7:7;
  1183. unsigned char afe_l_mux_size:4;
  1184. unsigned char afe_r_mux_size:4;
  1185. } __packed;
  1186. unsigned char data[2];
  1187. };
  1188. };
  1189. struct synaptics_rmi4_f55_handle {
  1190. bool amp_sensor;
  1191. bool extended_amp;
  1192. bool has_force;
  1193. unsigned char size_of_column2mux;
  1194. unsigned char afe_mux_offset;
  1195. unsigned char force_tx_offset;
  1196. unsigned char force_rx_offset;
  1197. unsigned char *tx_assignment;
  1198. unsigned char *rx_assignment;
  1199. unsigned char *force_tx_assignment;
  1200. unsigned char *force_rx_assignment;
  1201. unsigned short query_base_addr;
  1202. unsigned short control_base_addr;
  1203. unsigned short data_base_addr;
  1204. unsigned short command_base_addr;
  1205. struct f55_query query;
  1206. struct f55_query_3 query_3;
  1207. struct f55_query_5 query_5;
  1208. struct f55_query_17 query_17;
  1209. struct f55_query_18 query_18;
  1210. struct f55_query_22 query_22;
  1211. struct f55_query_23 query_23;
  1212. struct f55_query_28 query_28;
  1213. struct f55_query_30 query_30;
  1214. struct f55_query_33 query_33;
  1215. };
  1216. struct f21_query_2 {
  1217. union {
  1218. struct {
  1219. unsigned char size_of_query3;
  1220. struct {
  1221. unsigned char query0_is_present:1;
  1222. unsigned char query1_is_present:1;
  1223. unsigned char query2_is_present:1;
  1224. unsigned char query3_is_present:1;
  1225. unsigned char query4_is_present:1;
  1226. unsigned char query5_is_present:1;
  1227. unsigned char query6_is_present:1;
  1228. unsigned char query7_is_present:1;
  1229. } __packed;
  1230. struct {
  1231. unsigned char query8_is_present:1;
  1232. unsigned char query9_is_present:1;
  1233. unsigned char query10_is_present:1;
  1234. unsigned char query11_is_present:1;
  1235. unsigned char query12_is_present:1;
  1236. unsigned char query13_is_present:1;
  1237. unsigned char query14_is_present:1;
  1238. unsigned char query15_is_present:1;
  1239. } __packed;
  1240. };
  1241. unsigned char data[3];
  1242. };
  1243. };
  1244. struct f21_query_5 {
  1245. union {
  1246. struct {
  1247. unsigned char size_of_query6;
  1248. struct {
  1249. unsigned char ctrl0_is_present:1;
  1250. unsigned char ctrl1_is_present:1;
  1251. unsigned char ctrl2_is_present:1;
  1252. unsigned char ctrl3_is_present:1;
  1253. unsigned char ctrl4_is_present:1;
  1254. unsigned char ctrl5_is_present:1;
  1255. unsigned char ctrl6_is_present:1;
  1256. unsigned char ctrl7_is_present:1;
  1257. } __packed;
  1258. struct {
  1259. unsigned char ctrl8_is_present:1;
  1260. unsigned char ctrl9_is_present:1;
  1261. unsigned char ctrl10_is_present:1;
  1262. unsigned char ctrl11_is_present:1;
  1263. unsigned char ctrl12_is_present:1;
  1264. unsigned char ctrl13_is_present:1;
  1265. unsigned char ctrl14_is_present:1;
  1266. unsigned char ctrl15_is_present:1;
  1267. } __packed;
  1268. struct {
  1269. unsigned char ctrl16_is_present:1;
  1270. unsigned char ctrl17_is_present:1;
  1271. unsigned char ctrl18_is_present:1;
  1272. unsigned char ctrl19_is_present:1;
  1273. unsigned char ctrl20_is_present:1;
  1274. unsigned char ctrl21_is_present:1;
  1275. unsigned char ctrl22_is_present:1;
  1276. unsigned char ctrl23_is_present:1;
  1277. } __packed;
  1278. };
  1279. unsigned char data[4];
  1280. };
  1281. };
  1282. struct f21_query_11 {
  1283. union {
  1284. struct {
  1285. unsigned char has_high_resolution_force:1;
  1286. unsigned char has_force_sensing_txrx_mapping:1;
  1287. unsigned char f21_query11_00_b2__7:6;
  1288. unsigned char f21_query11_00_reserved;
  1289. unsigned char max_number_of_force_sensors;
  1290. unsigned char max_number_of_force_txs;
  1291. unsigned char max_number_of_force_rxs;
  1292. unsigned char f21_query11_01_reserved;
  1293. } __packed;
  1294. unsigned char data[6];
  1295. };
  1296. };
  1297. struct synaptics_rmi4_f21_handle {
  1298. bool has_force;
  1299. unsigned char tx_assigned;
  1300. unsigned char rx_assigned;
  1301. unsigned char max_num_of_tx;
  1302. unsigned char max_num_of_rx;
  1303. unsigned char max_num_of_txrx;
  1304. unsigned char *force_txrx_assignment;
  1305. unsigned short query_base_addr;
  1306. unsigned short control_base_addr;
  1307. unsigned short data_base_addr;
  1308. unsigned short command_base_addr;
  1309. };
  1310. show_prototype(num_of_mapped_tx);
  1311. show_prototype(num_of_mapped_rx);
  1312. show_prototype(tx_mapping);
  1313. show_prototype(rx_mapping);
  1314. show_prototype(num_of_mapped_force_tx);
  1315. show_prototype(num_of_mapped_force_rx);
  1316. show_prototype(force_tx_mapping);
  1317. show_prototype(force_rx_mapping);
  1318. show_prototype(report_size);
  1319. show_prototype(status);
  1320. store_prototype(do_preparation);
  1321. store_prototype(force_cal);
  1322. store_prototype(get_report);
  1323. store_prototype(resume_touch);
  1324. store_prototype(do_afe_calibration);
  1325. show_store_prototype(report_type);
  1326. show_store_prototype(fifoindex);
  1327. show_store_prototype(no_auto_cal);
  1328. show_store_prototype(read_report);
  1329. static struct attribute *attrs[] = {
  1330. attrify(num_of_mapped_tx),
  1331. attrify(num_of_mapped_rx),
  1332. attrify(tx_mapping),
  1333. attrify(rx_mapping),
  1334. attrify(num_of_mapped_force_tx),
  1335. attrify(num_of_mapped_force_rx),
  1336. attrify(force_tx_mapping),
  1337. attrify(force_rx_mapping),
  1338. attrify(report_size),
  1339. attrify(status),
  1340. attrify(do_preparation),
  1341. attrify(force_cal),
  1342. attrify(get_report),
  1343. attrify(resume_touch),
  1344. attrify(do_afe_calibration),
  1345. attrify(report_type),
  1346. attrify(fifoindex),
  1347. attrify(no_auto_cal),
  1348. attrify(read_report),
  1349. NULL,
  1350. };
  1351. static struct attribute_group attr_group = {
  1352. .attrs = attrs,
  1353. };
  1354. static ssize_t test_sysfs_data_read(struct file *data_file,
  1355. struct kobject *kobj, struct bin_attribute *attributes,
  1356. char *buf, loff_t pos, size_t count);
  1357. static struct bin_attribute test_report_data = {
  1358. .attr = {
  1359. .name = "report_data",
  1360. .mode = 0444,
  1361. },
  1362. .size = 0,
  1363. .read = test_sysfs_data_read,
  1364. };
  1365. static struct synaptics_rmi4_f54_handle *f54;
  1366. static struct synaptics_rmi4_f55_handle *f55;
  1367. static struct synaptics_rmi4_f21_handle *f21;
  1368. DECLARE_COMPLETION(test_remove_complete);
  1369. static bool test_report_type_valid(enum f54_report_types report_type)
  1370. {
  1371. switch (report_type) {
  1372. case F54_8BIT_IMAGE:
  1373. case F54_16BIT_IMAGE:
  1374. case F54_RAW_16BIT_IMAGE:
  1375. case F54_HIGH_RESISTANCE:
  1376. case F54_TX_TO_TX_SHORTS:
  1377. case F54_RX_TO_RX_SHORTS_1:
  1378. case F54_TRUE_BASELINE:
  1379. case F54_FULL_RAW_CAP_MIN_MAX:
  1380. case F54_RX_OPENS_1:
  1381. case F54_TX_OPENS:
  1382. case F54_TX_TO_GND_SHORTS:
  1383. case F54_RX_TO_RX_SHORTS_2:
  1384. case F54_RX_OPENS_2:
  1385. case F54_FULL_RAW_CAP:
  1386. case F54_FULL_RAW_CAP_NO_RX_COUPLING:
  1387. case F54_SENSOR_SPEED:
  1388. case F54_ADC_RANGE:
  1389. case F54_TRX_OPENS:
  1390. case F54_TRX_TO_GND_SHORTS:
  1391. case F54_TRX_SHORTS:
  1392. case F54_ABS_RAW_CAP:
  1393. case F54_ABS_DELTA_CAP:
  1394. case F54_ABS_HYBRID_DELTA_CAP:
  1395. case F54_ABS_HYBRID_RAW_CAP:
  1396. case F54_AMP_FULL_RAW_CAP:
  1397. case F54_AMP_RAW_ADC:
  1398. case F54_FULL_RAW_CAP_TDDI:
  1399. return true;
  1400. default:
  1401. f54->report_type = INVALID_REPORT_TYPE;
  1402. f54->report_size = 0;
  1403. return false;
  1404. }
  1405. }
  1406. static void test_set_report_size(void)
  1407. {
  1408. int retval;
  1409. unsigned char tx = f54->tx_assigned;
  1410. unsigned char rx = f54->rx_assigned;
  1411. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1412. switch (f54->report_type) {
  1413. case F54_8BIT_IMAGE:
  1414. f54->report_size = tx * rx;
  1415. break;
  1416. case F54_16BIT_IMAGE:
  1417. case F54_RAW_16BIT_IMAGE:
  1418. case F54_TRUE_BASELINE:
  1419. case F54_FULL_RAW_CAP:
  1420. case F54_FULL_RAW_CAP_NO_RX_COUPLING:
  1421. case F54_SENSOR_SPEED:
  1422. case F54_AMP_FULL_RAW_CAP:
  1423. case F54_AMP_RAW_ADC:
  1424. case F54_FULL_RAW_CAP_TDDI:
  1425. f54->report_size = 2 * tx * rx;
  1426. break;
  1427. case F54_HIGH_RESISTANCE:
  1428. f54->report_size = HIGH_RESISTANCE_DATA_SIZE;
  1429. break;
  1430. case F54_TX_TO_TX_SHORTS:
  1431. case F54_TX_OPENS:
  1432. case F54_TX_TO_GND_SHORTS:
  1433. f54->report_size = (tx + 7) / 8;
  1434. break;
  1435. case F54_RX_TO_RX_SHORTS_1:
  1436. case F54_RX_OPENS_1:
  1437. if (rx < tx)
  1438. f54->report_size = 2 * rx * rx;
  1439. else
  1440. f54->report_size = 2 * tx * rx;
  1441. break;
  1442. case F54_FULL_RAW_CAP_MIN_MAX:
  1443. f54->report_size = FULL_RAW_CAP_MIN_MAX_DATA_SIZE;
  1444. break;
  1445. case F54_RX_TO_RX_SHORTS_2:
  1446. case F54_RX_OPENS_2:
  1447. if (rx <= tx)
  1448. f54->report_size = 0;
  1449. else
  1450. f54->report_size = 2 * rx * (rx - tx);
  1451. break;
  1452. case F54_ADC_RANGE:
  1453. if (f54->query.has_signal_clarity) {
  1454. retval = synaptics_rmi4_reg_read(rmi4_data,
  1455. f54->control.reg_41->address,
  1456. f54->control.reg_41->data,
  1457. sizeof(f54->control.reg_41->data));
  1458. if (retval < 0) {
  1459. dev_dbg(rmi4_data->pdev->dev.parent,
  1460. "%s: Failed to read control reg_41\n",
  1461. __func__);
  1462. f54->report_size = 0;
  1463. break;
  1464. }
  1465. if (!f54->control.reg_41->no_signal_clarity) {
  1466. if (tx % 4)
  1467. tx += 4 - (tx % 4);
  1468. }
  1469. }
  1470. f54->report_size = 2 * tx * rx;
  1471. break;
  1472. case F54_TRX_OPENS:
  1473. case F54_TRX_TO_GND_SHORTS:
  1474. case F54_TRX_SHORTS:
  1475. f54->report_size = TRX_OPEN_SHORT_DATA_SIZE;
  1476. break;
  1477. case F54_ABS_RAW_CAP:
  1478. case F54_ABS_DELTA_CAP:
  1479. case F54_ABS_HYBRID_DELTA_CAP:
  1480. case F54_ABS_HYBRID_RAW_CAP:
  1481. tx += f21->tx_assigned;
  1482. rx += f21->rx_assigned;
  1483. f54->report_size = 4 * (tx + rx);
  1484. break;
  1485. default:
  1486. f54->report_size = 0;
  1487. }
  1488. }
  1489. static int test_set_interrupt(bool set)
  1490. {
  1491. int retval;
  1492. unsigned char ii;
  1493. unsigned char zero = 0x00;
  1494. unsigned char *intr_mask;
  1495. unsigned short f01_ctrl_reg;
  1496. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1497. intr_mask = rmi4_data->intr_mask;
  1498. f01_ctrl_reg = rmi4_data->f01_ctrl_base_addr + 1 + f54->intr_reg_num;
  1499. if (!set) {
  1500. retval = synaptics_rmi4_reg_write(rmi4_data,
  1501. f01_ctrl_reg,
  1502. &zero,
  1503. sizeof(zero));
  1504. if (retval < 0)
  1505. return retval;
  1506. }
  1507. for (ii = 0; ii < rmi4_data->num_of_intr_regs; ii++) {
  1508. if (intr_mask[ii] != 0x00) {
  1509. f01_ctrl_reg = rmi4_data->f01_ctrl_base_addr + 1 + ii;
  1510. if (set) {
  1511. retval = synaptics_rmi4_reg_write(rmi4_data,
  1512. f01_ctrl_reg,
  1513. &zero,
  1514. sizeof(zero));
  1515. if (retval < 0)
  1516. return retval;
  1517. } else {
  1518. retval = synaptics_rmi4_reg_write(rmi4_data,
  1519. f01_ctrl_reg,
  1520. &(intr_mask[ii]),
  1521. sizeof(intr_mask[ii]));
  1522. if (retval < 0)
  1523. return retval;
  1524. }
  1525. }
  1526. }
  1527. f01_ctrl_reg = rmi4_data->f01_ctrl_base_addr + 1 + f54->intr_reg_num;
  1528. if (set) {
  1529. retval = synaptics_rmi4_reg_write(rmi4_data,
  1530. f01_ctrl_reg,
  1531. &f54->intr_mask,
  1532. 1);
  1533. if (retval < 0)
  1534. return retval;
  1535. }
  1536. return 0;
  1537. }
  1538. static int test_wait_for_command_completion(void)
  1539. {
  1540. int retval;
  1541. unsigned char value;
  1542. unsigned char timeout_count;
  1543. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1544. timeout_count = 0;
  1545. do {
  1546. retval = synaptics_rmi4_reg_read(rmi4_data,
  1547. f54->command_base_addr,
  1548. &value,
  1549. sizeof(value));
  1550. if (retval < 0) {
  1551. dev_err(rmi4_data->pdev->dev.parent,
  1552. "%s: Failed to read command register\n",
  1553. __func__);
  1554. return retval;
  1555. }
  1556. if (value == 0x00)
  1557. break;
  1558. msleep(100);
  1559. timeout_count++;
  1560. } while (timeout_count < COMMAND_TIMEOUT_100MS);
  1561. if (timeout_count == COMMAND_TIMEOUT_100MS) {
  1562. dev_err(rmi4_data->pdev->dev.parent,
  1563. "%s: Timed out waiting for command completion\n",
  1564. __func__);
  1565. return -ETIMEDOUT;
  1566. }
  1567. return 0;
  1568. }
  1569. static int test_do_command(unsigned char command)
  1570. {
  1571. int retval;
  1572. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1573. retval = synaptics_rmi4_reg_write(rmi4_data,
  1574. f54->command_base_addr,
  1575. &command,
  1576. sizeof(command));
  1577. if (retval < 0) {
  1578. dev_err(rmi4_data->pdev->dev.parent,
  1579. "%s: Failed to write command\n",
  1580. __func__);
  1581. return retval;
  1582. }
  1583. retval = test_wait_for_command_completion();
  1584. if (retval < 0)
  1585. return retval;
  1586. return 0;
  1587. }
  1588. static int test_do_preparation(void)
  1589. {
  1590. int retval;
  1591. unsigned char value;
  1592. unsigned char zero = 0x00;
  1593. unsigned char device_ctrl;
  1594. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1595. retval = synaptics_rmi4_reg_read(rmi4_data,
  1596. rmi4_data->f01_ctrl_base_addr,
  1597. &device_ctrl,
  1598. sizeof(device_ctrl));
  1599. if (retval < 0) {
  1600. dev_err(rmi4_data->pdev->dev.parent,
  1601. "%s: Failed to set no sleep\n",
  1602. __func__);
  1603. return retval;
  1604. }
  1605. device_ctrl |= NO_SLEEP_ON;
  1606. retval = synaptics_rmi4_reg_write(rmi4_data,
  1607. rmi4_data->f01_ctrl_base_addr,
  1608. &device_ctrl,
  1609. sizeof(device_ctrl));
  1610. if (retval < 0) {
  1611. dev_err(rmi4_data->pdev->dev.parent,
  1612. "%s: Failed to set no sleep\n",
  1613. __func__);
  1614. return retval;
  1615. }
  1616. if (f54->skip_preparation)
  1617. return 0;
  1618. switch (f54->report_type) {
  1619. case F54_16BIT_IMAGE:
  1620. case F54_RAW_16BIT_IMAGE:
  1621. case F54_SENSOR_SPEED:
  1622. case F54_ADC_RANGE:
  1623. case F54_ABS_RAW_CAP:
  1624. case F54_ABS_DELTA_CAP:
  1625. case F54_ABS_HYBRID_DELTA_CAP:
  1626. case F54_ABS_HYBRID_RAW_CAP:
  1627. case F54_FULL_RAW_CAP_TDDI:
  1628. break;
  1629. case F54_AMP_RAW_ADC:
  1630. if (f54->query_49.has_ctrl188) {
  1631. retval = synaptics_rmi4_reg_read(rmi4_data,
  1632. f54->control.reg_188->address,
  1633. f54->control.reg_188->data,
  1634. sizeof(f54->control.reg_188->data));
  1635. if (retval < 0) {
  1636. dev_err(rmi4_data->pdev->dev.parent,
  1637. "%s: Failed to set start production test\n",
  1638. __func__);
  1639. return retval;
  1640. }
  1641. f54->control.reg_188->start_production_test = 1;
  1642. retval = synaptics_rmi4_reg_write(rmi4_data,
  1643. f54->control.reg_188->address,
  1644. f54->control.reg_188->data,
  1645. sizeof(f54->control.reg_188->data));
  1646. if (retval < 0) {
  1647. dev_err(rmi4_data->pdev->dev.parent,
  1648. "%s: Failed to set start production test\n",
  1649. __func__);
  1650. return retval;
  1651. }
  1652. }
  1653. break;
  1654. default:
  1655. if (f54->query.touch_controller_family == 1)
  1656. disable_cbc(reg_7);
  1657. else if (f54->query.has_ctrl88)
  1658. disable_cbc(reg_88);
  1659. if (f54->query.has_0d_acquisition_control)
  1660. disable_cbc(reg_57);
  1661. if ((f54->query.has_query15) &&
  1662. (f54->query_15.has_query25) &&
  1663. (f54->query_25.has_query27) &&
  1664. (f54->query_27.has_query29) &&
  1665. (f54->query_29.has_query30) &&
  1666. (f54->query_30.has_query32) &&
  1667. (f54->query_32.has_query33) &&
  1668. (f54->query_33.has_query36) &&
  1669. (f54->query_36.has_query38) &&
  1670. (f54->query_38.has_ctrl149)) {
  1671. retval = synaptics_rmi4_reg_write(rmi4_data,
  1672. f54->control.reg_149->address,
  1673. &zero,
  1674. sizeof(f54->control.reg_149->data));
  1675. if (retval < 0) {
  1676. dev_err(rmi4_data->pdev->dev.parent,
  1677. "%s: Failed to disable global CBC\n",
  1678. __func__);
  1679. return retval;
  1680. }
  1681. }
  1682. if (f54->query.has_signal_clarity) {
  1683. retval = synaptics_rmi4_reg_read(rmi4_data,
  1684. f54->control.reg_41->address,
  1685. &value,
  1686. sizeof(f54->control.reg_41->data));
  1687. if (retval < 0) {
  1688. dev_err(rmi4_data->pdev->dev.parent,
  1689. "%s: Failed to disable signal clarity\n",
  1690. __func__);
  1691. return retval;
  1692. }
  1693. value |= 0x01;
  1694. retval = synaptics_rmi4_reg_write(rmi4_data,
  1695. f54->control.reg_41->address,
  1696. &value,
  1697. sizeof(f54->control.reg_41->data));
  1698. if (retval < 0) {
  1699. dev_err(rmi4_data->pdev->dev.parent,
  1700. "%s: Failed to disable signal clarity\n",
  1701. __func__);
  1702. return retval;
  1703. }
  1704. }
  1705. retval = test_do_command(COMMAND_FORCE_UPDATE);
  1706. if (retval < 0) {
  1707. dev_err(rmi4_data->pdev->dev.parent,
  1708. "%s: Failed to do force update\n",
  1709. __func__);
  1710. return retval;
  1711. }
  1712. retval = test_do_command(COMMAND_FORCE_CAL);
  1713. if (retval < 0) {
  1714. dev_err(rmi4_data->pdev->dev.parent,
  1715. "%s: Failed to do force cal\n",
  1716. __func__);
  1717. return retval;
  1718. }
  1719. }
  1720. return 0;
  1721. }
  1722. static int test_do_afe_calibration(enum f54_afe_cal mode)
  1723. {
  1724. int retval;
  1725. unsigned char timeout = CALIBRATION_TIMEOUT_S;
  1726. unsigned char timeout_count = 0;
  1727. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1728. retval = synaptics_rmi4_reg_read(rmi4_data,
  1729. f54->control.reg_188->address,
  1730. f54->control.reg_188->data,
  1731. sizeof(f54->control.reg_188->data));
  1732. if (retval < 0) {
  1733. dev_err(rmi4_data->pdev->dev.parent,
  1734. "%s: Failed to start calibration\n",
  1735. __func__);
  1736. return retval;
  1737. }
  1738. if (mode == F54_AFE_CAL)
  1739. f54->control.reg_188->start_calibration = 1;
  1740. else if (mode == F54_AFE_IS_CAL)
  1741. f54->control.reg_188->start_is_calibration = 1;
  1742. retval = synaptics_rmi4_reg_write(rmi4_data,
  1743. f54->control.reg_188->address,
  1744. f54->control.reg_188->data,
  1745. sizeof(f54->control.reg_188->data));
  1746. if (retval < 0) {
  1747. dev_err(rmi4_data->pdev->dev.parent,
  1748. "%s: Failed to start calibration\n",
  1749. __func__);
  1750. return retval;
  1751. }
  1752. do {
  1753. retval = synaptics_rmi4_reg_read(rmi4_data,
  1754. f54->control.reg_188->address,
  1755. f54->control.reg_188->data,
  1756. sizeof(f54->control.reg_188->data));
  1757. if (retval < 0) {
  1758. dev_err(rmi4_data->pdev->dev.parent,
  1759. "%s: Failed to complete calibration\n",
  1760. __func__);
  1761. return retval;
  1762. }
  1763. if (mode == F54_AFE_CAL) {
  1764. if (!f54->control.reg_188->start_calibration)
  1765. break;
  1766. } else if (mode == F54_AFE_IS_CAL) {
  1767. if (!f54->control.reg_188->start_is_calibration)
  1768. break;
  1769. }
  1770. if (timeout_count == timeout) {
  1771. dev_err(rmi4_data->pdev->dev.parent,
  1772. "%s: Timed out waiting for calibration completion\n",
  1773. __func__);
  1774. return -EBUSY;
  1775. }
  1776. timeout_count++;
  1777. msleep(1000);
  1778. } while (true);
  1779. /* check CRC */
  1780. retval = synaptics_rmi4_reg_read(rmi4_data,
  1781. f54->data_31.address,
  1782. f54->data_31.data,
  1783. sizeof(f54->data_31.data));
  1784. if (retval < 0) {
  1785. dev_err(rmi4_data->pdev->dev.parent,
  1786. "%s: Failed to read calibration CRC\n",
  1787. __func__);
  1788. return retval;
  1789. }
  1790. if (mode == F54_AFE_CAL) {
  1791. if (f54->data_31.calibration_crc == 0)
  1792. return 0;
  1793. } else if (mode == F54_AFE_IS_CAL) {
  1794. if (f54->data_31.is_calibration_crc == 0)
  1795. return 0;
  1796. }
  1797. dev_err(rmi4_data->pdev->dev.parent,
  1798. "%s: Failed to read calibration CRC\n",
  1799. __func__);
  1800. return -EINVAL;
  1801. }
  1802. static int test_check_for_idle_status(void)
  1803. {
  1804. int retval;
  1805. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1806. switch (f54->status) {
  1807. case STATUS_IDLE:
  1808. retval = 0;
  1809. break;
  1810. case STATUS_BUSY:
  1811. dev_err(rmi4_data->pdev->dev.parent,
  1812. "%s: Status busy\n",
  1813. __func__);
  1814. retval = -EINVAL;
  1815. break;
  1816. case STATUS_ERROR:
  1817. dev_err(rmi4_data->pdev->dev.parent,
  1818. "%s: Status error\n",
  1819. __func__);
  1820. retval = -EINVAL;
  1821. break;
  1822. default:
  1823. dev_err(rmi4_data->pdev->dev.parent,
  1824. "%s: Invalid status (%d)\n",
  1825. __func__, f54->status);
  1826. retval = -EINVAL;
  1827. }
  1828. return retval;
  1829. }
  1830. static void test_timeout_work(struct work_struct *work)
  1831. {
  1832. int retval;
  1833. unsigned char command;
  1834. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  1835. mutex_lock(&f54->status_mutex);
  1836. if (f54->status == STATUS_BUSY) {
  1837. retval = synaptics_rmi4_reg_read(rmi4_data,
  1838. f54->command_base_addr,
  1839. &command,
  1840. sizeof(command));
  1841. if (retval < 0) {
  1842. dev_err(rmi4_data->pdev->dev.parent,
  1843. "%s: Failed to read command register\n",
  1844. __func__);
  1845. } else if (command & COMMAND_GET_REPORT) {
  1846. dev_err(rmi4_data->pdev->dev.parent,
  1847. "%s: Report type not supported by FW\n",
  1848. __func__);
  1849. } else {
  1850. queue_work(f54->test_report_workqueue,
  1851. &f54->test_report_work);
  1852. goto exit;
  1853. }
  1854. f54->status = STATUS_ERROR;
  1855. f54->report_size = 0;
  1856. }
  1857. exit:
  1858. mutex_unlock(&f54->status_mutex);
  1859. }
  1860. static enum hrtimer_restart test_get_report_timeout(struct hrtimer *timer)
  1861. {
  1862. schedule_work(&(f54->timeout_work));
  1863. return HRTIMER_NORESTART;
  1864. }
  1865. static ssize_t num_of_mapped_tx_show(struct device *dev,
  1866. struct device_attribute *attr, char *buf)
  1867. {
  1868. return snprintf(buf, PAGE_SIZE, "%u\n", f54->tx_assigned);
  1869. }
  1870. static ssize_t num_of_mapped_rx_show(struct device *dev,
  1871. struct device_attribute *attr, char *buf)
  1872. {
  1873. return snprintf(buf, PAGE_SIZE, "%u\n", f54->rx_assigned);
  1874. }
  1875. static ssize_t tx_mapping_show(struct device *dev,
  1876. struct device_attribute *attr, char *buf)
  1877. {
  1878. int cnt;
  1879. int count = 0;
  1880. unsigned char ii;
  1881. unsigned char tx_num;
  1882. unsigned char tx_electrodes;
  1883. if (!f55)
  1884. return -EINVAL;
  1885. tx_electrodes = f55->query.num_of_tx_electrodes;
  1886. for (ii = 0; ii < tx_electrodes; ii++) {
  1887. tx_num = f55->tx_assignment[ii];
  1888. if (tx_num == 0xff)
  1889. cnt = snprintf(buf, PAGE_SIZE - count, "xx ");
  1890. else
  1891. cnt = snprintf(buf, PAGE_SIZE - count, "%02u ", tx_num);
  1892. buf += cnt;
  1893. count += cnt;
  1894. }
  1895. snprintf(buf, PAGE_SIZE - count, "\n");
  1896. count++;
  1897. return count;
  1898. }
  1899. static ssize_t rx_mapping_show(struct device *dev,
  1900. struct device_attribute *attr, char *buf)
  1901. {
  1902. int cnt;
  1903. int count = 0;
  1904. unsigned char ii;
  1905. unsigned char rx_num;
  1906. unsigned char rx_electrodes;
  1907. if (!f55)
  1908. return -EINVAL;
  1909. rx_electrodes = f55->query.num_of_rx_electrodes;
  1910. for (ii = 0; ii < rx_electrodes; ii++) {
  1911. rx_num = f55->rx_assignment[ii];
  1912. if (rx_num == 0xff)
  1913. cnt = snprintf(buf, PAGE_SIZE - count, "xx ");
  1914. else
  1915. cnt = snprintf(buf, PAGE_SIZE - count, "%02u ", rx_num);
  1916. buf += cnt;
  1917. count += cnt;
  1918. }
  1919. snprintf(buf, PAGE_SIZE - count, "\n");
  1920. count++;
  1921. return count;
  1922. }
  1923. static ssize_t num_of_mapped_force_tx_show(struct device *dev,
  1924. struct device_attribute *attr, char *buf)
  1925. {
  1926. return snprintf(buf, PAGE_SIZE, "%u\n", f21->tx_assigned);
  1927. }
  1928. static ssize_t num_of_mapped_force_rx_show(struct device *dev,
  1929. struct device_attribute *attr, char *buf)
  1930. {
  1931. return snprintf(buf, PAGE_SIZE, "%u\n", f21->rx_assigned);
  1932. }
  1933. static ssize_t force_tx_mapping_show(struct device *dev,
  1934. struct device_attribute *attr, char *buf)
  1935. {
  1936. int cnt;
  1937. int count = 0;
  1938. unsigned char ii;
  1939. unsigned char tx_num;
  1940. unsigned char tx_electrodes;
  1941. if ((!f55 || !f55->has_force) && (!f21 || !f21->has_force))
  1942. return -EINVAL;
  1943. if (f55->has_force) {
  1944. tx_electrodes = f55->query.num_of_tx_electrodes;
  1945. for (ii = 0; ii < tx_electrodes; ii++) {
  1946. tx_num = f55->force_tx_assignment[ii];
  1947. if (tx_num == 0xff) {
  1948. cnt = snprintf(buf, PAGE_SIZE - count, "xx ");
  1949. } else {
  1950. cnt = snprintf(buf, PAGE_SIZE - count, "%02u ",
  1951. tx_num);
  1952. }
  1953. buf += cnt;
  1954. count += cnt;
  1955. }
  1956. } else if (f21->has_force) {
  1957. tx_electrodes = f21->max_num_of_tx;
  1958. for (ii = 0; ii < tx_electrodes; ii++) {
  1959. tx_num = f21->force_txrx_assignment[ii];
  1960. if (tx_num == 0xff) {
  1961. cnt = snprintf(buf, PAGE_SIZE - count, "xx ");
  1962. } else {
  1963. cnt = snprintf(buf, PAGE_SIZE - count, "%02u ",
  1964. tx_num);
  1965. }
  1966. buf += cnt;
  1967. count += cnt;
  1968. }
  1969. }
  1970. snprintf(buf, PAGE_SIZE - count, "\n");
  1971. count++;
  1972. return count;
  1973. }
  1974. static ssize_t force_rx_mapping_show(struct device *dev,
  1975. struct device_attribute *attr, char *buf)
  1976. {
  1977. int cnt;
  1978. int count = 0;
  1979. unsigned char ii;
  1980. unsigned char offset;
  1981. unsigned char rx_num;
  1982. unsigned char rx_electrodes;
  1983. if ((!f55 || !f55->has_force) && (!f21 || !f21->has_force))
  1984. return -EINVAL;
  1985. if (f55->has_force) {
  1986. rx_electrodes = f55->query.num_of_rx_electrodes;
  1987. for (ii = 0; ii < rx_electrodes; ii++) {
  1988. rx_num = f55->force_rx_assignment[ii];
  1989. if (rx_num == 0xff)
  1990. cnt = snprintf(buf, PAGE_SIZE - count, "xx ");
  1991. else
  1992. cnt = snprintf(buf, PAGE_SIZE - count, "%02u ",
  1993. rx_num);
  1994. buf += cnt;
  1995. count += cnt;
  1996. }
  1997. } else if (f21->has_force) {
  1998. offset = f21->max_num_of_tx;
  1999. rx_electrodes = f21->max_num_of_rx;
  2000. for (ii = offset; ii < (rx_electrodes + offset); ii++) {
  2001. rx_num = f21->force_txrx_assignment[ii];
  2002. if (rx_num == 0xff)
  2003. cnt = snprintf(buf, PAGE_SIZE - count, "xx ");
  2004. else
  2005. cnt = snprintf(buf, PAGE_SIZE - count, "%02u ",
  2006. rx_num);
  2007. buf += cnt;
  2008. count += cnt;
  2009. }
  2010. }
  2011. snprintf(buf, PAGE_SIZE - count, "\n");
  2012. count++;
  2013. return count;
  2014. }
  2015. static ssize_t report_size_show(struct device *dev,
  2016. struct device_attribute *attr, char *buf)
  2017. {
  2018. return snprintf(buf, PAGE_SIZE, "%u\n", f54->report_size);
  2019. }
  2020. static ssize_t status_show(struct device *dev,
  2021. struct device_attribute *attr, char *buf)
  2022. {
  2023. int retval;
  2024. mutex_lock(&f54->status_mutex);
  2025. retval = snprintf(buf, PAGE_SIZE, "%u\n", f54->status);
  2026. mutex_unlock(&f54->status_mutex);
  2027. return retval;
  2028. }
  2029. static ssize_t do_preparation_store(struct device *dev,
  2030. struct device_attribute *attr, const char *buf, size_t count)
  2031. {
  2032. int retval;
  2033. unsigned long setting;
  2034. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2035. retval = sstrtoul(buf, 10, &setting);
  2036. if (retval)
  2037. return retval;
  2038. if (setting != 1)
  2039. return -EINVAL;
  2040. mutex_lock(&f54->status_mutex);
  2041. retval = test_check_for_idle_status();
  2042. if (retval < 0)
  2043. goto exit;
  2044. retval = test_do_preparation();
  2045. if (retval < 0) {
  2046. dev_err(rmi4_data->pdev->dev.parent,
  2047. "%s: Failed to do preparation\n",
  2048. __func__);
  2049. goto exit;
  2050. }
  2051. retval = count;
  2052. exit:
  2053. mutex_unlock(&f54->status_mutex);
  2054. return retval;
  2055. }
  2056. static ssize_t force_cal_store(struct device *dev,
  2057. struct device_attribute *attr, const char *buf, size_t count)
  2058. {
  2059. int retval;
  2060. unsigned long setting;
  2061. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2062. retval = sstrtoul(buf, 10, &setting);
  2063. if (retval)
  2064. return retval;
  2065. if (setting != 1)
  2066. return -EINVAL;
  2067. mutex_lock(&f54->status_mutex);
  2068. retval = test_check_for_idle_status();
  2069. if (retval < 0)
  2070. goto exit;
  2071. retval = test_do_command(COMMAND_FORCE_CAL);
  2072. if (retval < 0) {
  2073. dev_err(rmi4_data->pdev->dev.parent,
  2074. "%s: Failed to do force cal\n",
  2075. __func__);
  2076. goto exit;
  2077. }
  2078. retval = count;
  2079. exit:
  2080. mutex_unlock(&f54->status_mutex);
  2081. return retval;
  2082. }
  2083. static ssize_t get_report_store(struct device *dev,
  2084. struct device_attribute *attr, const char *buf, size_t count)
  2085. {
  2086. int retval;
  2087. unsigned char command;
  2088. unsigned long setting;
  2089. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2090. retval = sstrtoul(buf, 10, &setting);
  2091. if (retval)
  2092. return retval;
  2093. if (setting != 1)
  2094. return -EINVAL;
  2095. mutex_lock(&f54->status_mutex);
  2096. retval = test_check_for_idle_status();
  2097. if (retval < 0)
  2098. goto exit;
  2099. if (!test_report_type_valid(f54->report_type)) {
  2100. dev_err(rmi4_data->pdev->dev.parent,
  2101. "%s: Invalid report type\n",
  2102. __func__);
  2103. retval = -EINVAL;
  2104. goto exit;
  2105. }
  2106. test_set_interrupt(true);
  2107. command = (unsigned char)COMMAND_GET_REPORT;
  2108. retval = synaptics_rmi4_reg_write(rmi4_data,
  2109. f54->command_base_addr,
  2110. &command,
  2111. sizeof(command));
  2112. if (retval < 0) {
  2113. dev_err(rmi4_data->pdev->dev.parent,
  2114. "%s: Failed to write get report command\n",
  2115. __func__);
  2116. goto exit;
  2117. }
  2118. f54->status = STATUS_BUSY;
  2119. f54->report_size = 0;
  2120. f54->data_pos = 0;
  2121. hrtimer_start(&f54->watchdog,
  2122. ktime_set(GET_REPORT_TIMEOUT_S, 0),
  2123. HRTIMER_MODE_REL);
  2124. retval = count;
  2125. exit:
  2126. mutex_unlock(&f54->status_mutex);
  2127. return retval;
  2128. }
  2129. static ssize_t resume_touch_store(struct device *dev,
  2130. struct device_attribute *attr, const char *buf, size_t count)
  2131. {
  2132. int retval;
  2133. unsigned char device_ctrl;
  2134. unsigned long setting;
  2135. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2136. retval = sstrtoul(buf, 10, &setting);
  2137. if (retval)
  2138. return retval;
  2139. if (setting != 1)
  2140. return -EINVAL;
  2141. retval = synaptics_rmi4_reg_read(rmi4_data,
  2142. rmi4_data->f01_ctrl_base_addr,
  2143. &device_ctrl,
  2144. sizeof(device_ctrl));
  2145. if (retval < 0) {
  2146. dev_err(rmi4_data->pdev->dev.parent,
  2147. "%s: Failed to restore no sleep setting\n",
  2148. __func__);
  2149. return retval;
  2150. }
  2151. device_ctrl = device_ctrl & ~NO_SLEEP_ON;
  2152. device_ctrl |= rmi4_data->no_sleep_setting;
  2153. retval = synaptics_rmi4_reg_write(rmi4_data,
  2154. rmi4_data->f01_ctrl_base_addr,
  2155. &device_ctrl,
  2156. sizeof(device_ctrl));
  2157. if (retval < 0) {
  2158. dev_err(rmi4_data->pdev->dev.parent,
  2159. "%s: Failed to restore no sleep setting\n",
  2160. __func__);
  2161. return retval;
  2162. }
  2163. test_set_interrupt(false);
  2164. if (f54->skip_preparation)
  2165. return count;
  2166. switch (f54->report_type) {
  2167. case F54_16BIT_IMAGE:
  2168. case F54_RAW_16BIT_IMAGE:
  2169. case F54_SENSOR_SPEED:
  2170. case F54_ADC_RANGE:
  2171. case F54_ABS_RAW_CAP:
  2172. case F54_ABS_DELTA_CAP:
  2173. case F54_ABS_HYBRID_DELTA_CAP:
  2174. case F54_ABS_HYBRID_RAW_CAP:
  2175. case F54_FULL_RAW_CAP_TDDI:
  2176. break;
  2177. case F54_AMP_RAW_ADC:
  2178. if (f54->query_49.has_ctrl188) {
  2179. retval = synaptics_rmi4_reg_read(rmi4_data,
  2180. f54->control.reg_188->address,
  2181. f54->control.reg_188->data,
  2182. sizeof(f54->control.reg_188->data));
  2183. if (retval < 0) {
  2184. dev_err(rmi4_data->pdev->dev.parent,
  2185. "%s: Failed to set start production test\n",
  2186. __func__);
  2187. return retval;
  2188. }
  2189. f54->control.reg_188->start_production_test = 0;
  2190. retval = synaptics_rmi4_reg_write(rmi4_data,
  2191. f54->control.reg_188->address,
  2192. f54->control.reg_188->data,
  2193. sizeof(f54->control.reg_188->data));
  2194. if (retval < 0) {
  2195. dev_err(rmi4_data->pdev->dev.parent,
  2196. "%s: Failed to set start production test\n",
  2197. __func__);
  2198. return retval;
  2199. }
  2200. }
  2201. break;
  2202. default:
  2203. rmi4_data->reset_device(rmi4_data, false);
  2204. }
  2205. return count;
  2206. }
  2207. static ssize_t do_afe_calibration_store(struct device *dev,
  2208. struct device_attribute *attr, const char *buf, size_t count)
  2209. {
  2210. int retval;
  2211. unsigned long setting;
  2212. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2213. retval = sstrtoul(buf, 10, &setting);
  2214. if (retval)
  2215. return retval;
  2216. if (!f54->query_49.has_ctrl188) {
  2217. dev_err(rmi4_data->pdev->dev.parent,
  2218. "%s: F54_ANALOG_Ctrl188 not found\n",
  2219. __func__);
  2220. return -EINVAL;
  2221. }
  2222. if (setting == 0 || setting == 1)
  2223. retval = test_do_afe_calibration((enum f54_afe_cal)setting);
  2224. else
  2225. return -EINVAL;
  2226. if (retval)
  2227. return retval;
  2228. else
  2229. return count;
  2230. }
  2231. static ssize_t report_type_show(struct device *dev,
  2232. struct device_attribute *attr, char *buf)
  2233. {
  2234. return snprintf(buf, PAGE_SIZE, "%u\n", f54->report_type);
  2235. }
  2236. static ssize_t report_type_store(struct device *dev,
  2237. struct device_attribute *attr, const char *buf, size_t count)
  2238. {
  2239. int retval;
  2240. unsigned char data;
  2241. unsigned long setting;
  2242. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2243. retval = sstrtoul(buf, 10, &setting);
  2244. if (retval)
  2245. return retval;
  2246. mutex_lock(&f54->status_mutex);
  2247. retval = test_check_for_idle_status();
  2248. if (retval < 0)
  2249. goto exit;
  2250. if (!test_report_type_valid((enum f54_report_types)setting)) {
  2251. dev_err(rmi4_data->pdev->dev.parent,
  2252. "%s: Report type not supported by driver\n",
  2253. __func__);
  2254. retval = -EINVAL;
  2255. goto exit;
  2256. }
  2257. f54->report_type = (enum f54_report_types)setting;
  2258. data = (unsigned char)setting;
  2259. retval = synaptics_rmi4_reg_write(rmi4_data,
  2260. f54->data_base_addr,
  2261. &data,
  2262. sizeof(data));
  2263. if (retval < 0) {
  2264. dev_err(rmi4_data->pdev->dev.parent,
  2265. "%s: Failed to write report type\n",
  2266. __func__);
  2267. goto exit;
  2268. }
  2269. retval = count;
  2270. exit:
  2271. mutex_unlock(&f54->status_mutex);
  2272. return retval;
  2273. }
  2274. static ssize_t fifoindex_show(struct device *dev,
  2275. struct device_attribute *attr, char *buf)
  2276. {
  2277. int retval;
  2278. unsigned char data[2];
  2279. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2280. retval = synaptics_rmi4_reg_read(rmi4_data,
  2281. f54->data_base_addr + REPORT_INDEX_OFFSET,
  2282. data,
  2283. sizeof(data));
  2284. if (retval < 0) {
  2285. dev_err(rmi4_data->pdev->dev.parent,
  2286. "%s: Failed to read report index\n",
  2287. __func__);
  2288. return retval;
  2289. }
  2290. batohs(&f54->fifoindex, data);
  2291. return snprintf(buf, PAGE_SIZE, "%u\n", f54->fifoindex);
  2292. }
  2293. static ssize_t fifoindex_store(struct device *dev,
  2294. struct device_attribute *attr, const char *buf, size_t count)
  2295. {
  2296. int retval;
  2297. unsigned char data[2];
  2298. unsigned long setting;
  2299. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2300. retval = sstrtoul(buf, 10, &setting);
  2301. if (retval)
  2302. return retval;
  2303. f54->fifoindex = setting;
  2304. hstoba(data, (unsigned short)setting);
  2305. retval = synaptics_rmi4_reg_write(rmi4_data,
  2306. f54->data_base_addr + REPORT_INDEX_OFFSET,
  2307. data,
  2308. sizeof(data));
  2309. if (retval < 0) {
  2310. dev_err(rmi4_data->pdev->dev.parent,
  2311. "%s: Failed to write report index\n",
  2312. __func__);
  2313. return retval;
  2314. }
  2315. return count;
  2316. }
  2317. static ssize_t no_auto_cal_show(struct device *dev,
  2318. struct device_attribute *attr, char *buf)
  2319. {
  2320. return snprintf(buf, PAGE_SIZE, "%u\n", f54->no_auto_cal);
  2321. }
  2322. static ssize_t no_auto_cal_store(struct device *dev,
  2323. struct device_attribute *attr, const char *buf, size_t count)
  2324. {
  2325. int retval;
  2326. unsigned char data;
  2327. unsigned long setting;
  2328. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2329. retval = sstrtoul(buf, 10, &setting);
  2330. if (retval)
  2331. return retval;
  2332. if (setting > 1)
  2333. return -EINVAL;
  2334. retval = synaptics_rmi4_reg_read(rmi4_data,
  2335. f54->control_base_addr,
  2336. &data,
  2337. sizeof(data));
  2338. if (retval < 0) {
  2339. dev_err(rmi4_data->pdev->dev.parent,
  2340. "%s: Failed to read no auto cal setting\n",
  2341. __func__);
  2342. return retval;
  2343. }
  2344. if (setting)
  2345. data |= CONTROL_NO_AUTO_CAL;
  2346. else
  2347. data &= ~CONTROL_NO_AUTO_CAL;
  2348. retval = synaptics_rmi4_reg_write(rmi4_data,
  2349. f54->control_base_addr,
  2350. &data,
  2351. sizeof(data));
  2352. if (retval < 0) {
  2353. dev_err(rmi4_data->pdev->dev.parent,
  2354. "%s: Failed to write no auto cal setting\n",
  2355. __func__);
  2356. return retval;
  2357. }
  2358. f54->no_auto_cal = (setting == 1);
  2359. return count;
  2360. }
  2361. static ssize_t read_report_show(struct device *dev,
  2362. struct device_attribute *attr, char *buf)
  2363. {
  2364. unsigned int ii;
  2365. unsigned int jj;
  2366. int cnt;
  2367. int count = 0;
  2368. int tx_num = f54->tx_assigned;
  2369. int rx_num = f54->rx_assigned;
  2370. char *report_data_8;
  2371. short *report_data_16;
  2372. int *report_data_32;
  2373. unsigned short *report_data_u16;
  2374. unsigned int *report_data_u32;
  2375. switch (f54->report_type) {
  2376. case F54_8BIT_IMAGE:
  2377. report_data_8 = (char *)f54->report_data;
  2378. for (ii = 0; ii < f54->report_size; ii++) {
  2379. cnt = snprintf(buf, PAGE_SIZE - count, "%03d: %d\n",
  2380. ii, *report_data_8);
  2381. report_data_8++;
  2382. buf += cnt;
  2383. count += cnt;
  2384. }
  2385. break;
  2386. case F54_AMP_RAW_ADC:
  2387. report_data_u16 = (unsigned short *)f54->report_data;
  2388. cnt = snprintf(buf, PAGE_SIZE - count, "tx = %d\nrx = %d\n",
  2389. tx_num, rx_num);
  2390. buf += cnt;
  2391. count += cnt;
  2392. for (ii = 0; ii < tx_num; ii++) {
  2393. for (jj = 0; jj < (rx_num - 1); jj++) {
  2394. cnt = snprintf(buf, PAGE_SIZE - count, "%-4d ",
  2395. *report_data_u16);
  2396. report_data_u16++;
  2397. buf += cnt;
  2398. count += cnt;
  2399. }
  2400. cnt = snprintf(buf, PAGE_SIZE - count, "%-4d\n",
  2401. *report_data_u16);
  2402. report_data_u16++;
  2403. buf += cnt;
  2404. count += cnt;
  2405. }
  2406. break;
  2407. case F54_16BIT_IMAGE:
  2408. case F54_RAW_16BIT_IMAGE:
  2409. case F54_TRUE_BASELINE:
  2410. case F54_FULL_RAW_CAP:
  2411. case F54_FULL_RAW_CAP_NO_RX_COUPLING:
  2412. case F54_SENSOR_SPEED:
  2413. case F54_AMP_FULL_RAW_CAP:
  2414. case F54_FULL_RAW_CAP_TDDI:
  2415. report_data_16 = (short *)f54->report_data;
  2416. cnt = snprintf(buf, PAGE_SIZE - count, "tx = %d\nrx = %d\n",
  2417. tx_num, rx_num);
  2418. buf += cnt;
  2419. count += cnt;
  2420. for (ii = 0; ii < tx_num; ii++) {
  2421. for (jj = 0; jj < (rx_num - 1); jj++) {
  2422. cnt = snprintf(buf, PAGE_SIZE - count, "%-4d ",
  2423. *report_data_16);
  2424. report_data_16++;
  2425. buf += cnt;
  2426. count += cnt;
  2427. }
  2428. cnt = snprintf(buf, PAGE_SIZE - count, "%-4d\n",
  2429. *report_data_16);
  2430. report_data_16++;
  2431. buf += cnt;
  2432. count += cnt;
  2433. }
  2434. break;
  2435. case F54_HIGH_RESISTANCE:
  2436. case F54_FULL_RAW_CAP_MIN_MAX:
  2437. report_data_16 = (short *)f54->report_data;
  2438. for (ii = 0; ii < f54->report_size; ii += 2) {
  2439. cnt = snprintf(buf, PAGE_SIZE - count, "%03d: %d\n",
  2440. ii / 2, *report_data_16);
  2441. report_data_16++;
  2442. buf += cnt;
  2443. count += cnt;
  2444. }
  2445. break;
  2446. case F54_ABS_RAW_CAP:
  2447. case F54_ABS_HYBRID_RAW_CAP:
  2448. tx_num += f21->tx_assigned;
  2449. rx_num += f21->rx_assigned;
  2450. report_data_u32 = (unsigned int *)f54->report_data;
  2451. cnt = snprintf(buf, PAGE_SIZE - count, "rx ");
  2452. buf += cnt;
  2453. count += cnt;
  2454. for (ii = 0; ii < rx_num; ii++) {
  2455. cnt = snprintf(buf, PAGE_SIZE - count, " %2d", ii);
  2456. buf += cnt;
  2457. count += cnt;
  2458. }
  2459. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2460. buf += cnt;
  2461. count += cnt;
  2462. cnt = snprintf(buf, PAGE_SIZE - count, " ");
  2463. buf += cnt;
  2464. count += cnt;
  2465. for (ii = 0; ii < rx_num; ii++) {
  2466. cnt = snprintf(buf, PAGE_SIZE - count, " %5u",
  2467. *report_data_u32);
  2468. report_data_u32++;
  2469. buf += cnt;
  2470. count += cnt;
  2471. }
  2472. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2473. buf += cnt;
  2474. count += cnt;
  2475. cnt = snprintf(buf, PAGE_SIZE - count, "tx ");
  2476. buf += cnt;
  2477. count += cnt;
  2478. for (ii = 0; ii < tx_num; ii++) {
  2479. cnt = snprintf(buf, PAGE_SIZE - count, " %2d", ii);
  2480. buf += cnt;
  2481. count += cnt;
  2482. }
  2483. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2484. buf += cnt;
  2485. count += cnt;
  2486. cnt = snprintf(buf, PAGE_SIZE - count, " ");
  2487. buf += cnt;
  2488. count += cnt;
  2489. for (ii = 0; ii < tx_num; ii++) {
  2490. cnt = snprintf(buf, PAGE_SIZE - count, " %5u",
  2491. *report_data_u32);
  2492. report_data_u32++;
  2493. buf += cnt;
  2494. count += cnt;
  2495. }
  2496. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2497. buf += cnt;
  2498. count += cnt;
  2499. break;
  2500. case F54_ABS_DELTA_CAP:
  2501. case F54_ABS_HYBRID_DELTA_CAP:
  2502. tx_num += f21->tx_assigned;
  2503. rx_num += f21->rx_assigned;
  2504. report_data_32 = (int *)f54->report_data;
  2505. cnt = snprintf(buf, PAGE_SIZE - count, "rx ");
  2506. buf += cnt;
  2507. count += cnt;
  2508. for (ii = 0; ii < rx_num; ii++) {
  2509. cnt = snprintf(buf, PAGE_SIZE - count, " %2d", ii);
  2510. buf += cnt;
  2511. count += cnt;
  2512. }
  2513. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2514. buf += cnt;
  2515. count += cnt;
  2516. cnt = snprintf(buf, PAGE_SIZE - count, " ");
  2517. buf += cnt;
  2518. count += cnt;
  2519. for (ii = 0; ii < rx_num; ii++) {
  2520. cnt = snprintf(buf, PAGE_SIZE - count, " %5d",
  2521. *report_data_32);
  2522. report_data_32++;
  2523. buf += cnt;
  2524. count += cnt;
  2525. }
  2526. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2527. buf += cnt;
  2528. count += cnt;
  2529. cnt = snprintf(buf, PAGE_SIZE - count, "tx ");
  2530. buf += cnt;
  2531. count += cnt;
  2532. for (ii = 0; ii < tx_num; ii++) {
  2533. cnt = snprintf(buf, PAGE_SIZE - count, " %2d", ii);
  2534. buf += cnt;
  2535. count += cnt;
  2536. }
  2537. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2538. buf += cnt;
  2539. count += cnt;
  2540. cnt = snprintf(buf, PAGE_SIZE - count, " ");
  2541. buf += cnt;
  2542. count += cnt;
  2543. for (ii = 0; ii < tx_num; ii++) {
  2544. cnt = snprintf(buf, PAGE_SIZE - count, " %5d",
  2545. *report_data_32);
  2546. report_data_32++;
  2547. buf += cnt;
  2548. count += cnt;
  2549. }
  2550. cnt = snprintf(buf, PAGE_SIZE - count, "\n");
  2551. buf += cnt;
  2552. count += cnt;
  2553. break;
  2554. default:
  2555. for (ii = 0; ii < f54->report_size; ii++) {
  2556. cnt = snprintf(buf, PAGE_SIZE - count, "%03d: 0x%02x\n",
  2557. ii, f54->report_data[ii]);
  2558. buf += cnt;
  2559. count += cnt;
  2560. }
  2561. }
  2562. snprintf(buf, PAGE_SIZE - count, "\n");
  2563. count++;
  2564. return count;
  2565. }
  2566. static ssize_t read_report_store(struct device *dev,
  2567. struct device_attribute *attr, const char *buf, size_t count)
  2568. {
  2569. int retval;
  2570. unsigned char timeout = GET_REPORT_TIMEOUT_S * 10;
  2571. unsigned char timeout_count;
  2572. const char cmd[] = {'1', 0};
  2573. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2574. retval = report_type_store(dev, attr, buf, count);
  2575. if (retval < 0)
  2576. goto exit;
  2577. retval = do_preparation_store(dev, attr, cmd, 1);
  2578. if (retval < 0)
  2579. goto exit;
  2580. retval = get_report_store(dev, attr, cmd, 1);
  2581. if (retval < 0)
  2582. goto exit;
  2583. timeout_count = 0;
  2584. do {
  2585. if (f54->status != STATUS_BUSY)
  2586. break;
  2587. msleep(100);
  2588. timeout_count++;
  2589. } while (timeout_count < timeout);
  2590. if ((f54->status != STATUS_IDLE) || (f54->report_size == 0)) {
  2591. dev_err(rmi4_data->pdev->dev.parent,
  2592. "%s: Failed to read report\n",
  2593. __func__);
  2594. retval = -EINVAL;
  2595. goto exit;
  2596. }
  2597. retval = resume_touch_store(dev, attr, cmd, 1);
  2598. if (retval < 0)
  2599. goto exit;
  2600. return count;
  2601. exit:
  2602. rmi4_data->reset_device(rmi4_data, false);
  2603. return retval;
  2604. }
  2605. static ssize_t test_sysfs_data_read(struct file *data_file,
  2606. struct kobject *kobj, struct bin_attribute *attributes,
  2607. char *buf, loff_t pos, size_t count)
  2608. {
  2609. int retval;
  2610. unsigned int read_size;
  2611. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2612. mutex_lock(&f54->status_mutex);
  2613. retval = test_check_for_idle_status();
  2614. if (retval < 0)
  2615. goto exit;
  2616. if (!f54->report_data) {
  2617. dev_err(rmi4_data->pdev->dev.parent,
  2618. "%s: Report type %d data not available\n",
  2619. __func__, f54->report_type);
  2620. retval = -EINVAL;
  2621. goto exit;
  2622. }
  2623. if ((f54->data_pos + count) > f54->report_size)
  2624. read_size = f54->report_size - f54->data_pos;
  2625. else
  2626. read_size = min_t(unsigned int, count, f54->report_size);
  2627. retval = secure_memcpy(buf, count, f54->report_data + f54->data_pos,
  2628. f54->data_buffer_size - f54->data_pos, read_size);
  2629. if (retval < 0) {
  2630. dev_err(rmi4_data->pdev->dev.parent,
  2631. "%s: Failed to copy report data\n",
  2632. __func__);
  2633. goto exit;
  2634. }
  2635. f54->data_pos += read_size;
  2636. retval = read_size;
  2637. exit:
  2638. mutex_unlock(&f54->status_mutex);
  2639. return retval;
  2640. }
  2641. static void test_report_work(struct work_struct *work)
  2642. {
  2643. int retval;
  2644. unsigned char report_index[2];
  2645. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2646. mutex_lock(&f54->status_mutex);
  2647. if (f54->status != STATUS_BUSY) {
  2648. retval = f54->status;
  2649. goto exit;
  2650. }
  2651. retval = test_wait_for_command_completion();
  2652. if (retval < 0) {
  2653. retval = STATUS_ERROR;
  2654. goto exit;
  2655. }
  2656. test_set_report_size();
  2657. if (f54->report_size == 0) {
  2658. dev_err(rmi4_data->pdev->dev.parent,
  2659. "%s: Report data size = 0\n",
  2660. __func__);
  2661. retval = STATUS_ERROR;
  2662. goto exit;
  2663. }
  2664. if (f54->data_buffer_size < f54->report_size) {
  2665. if (f54->data_buffer_size)
  2666. kfree(f54->report_data);
  2667. f54->report_data = kzalloc(f54->report_size, GFP_KERNEL);
  2668. if (!f54->report_data) {
  2669. dev_err(rmi4_data->pdev->dev.parent,
  2670. "%s: Failed to alloc mem for data buffer\n",
  2671. __func__);
  2672. f54->data_buffer_size = 0;
  2673. retval = STATUS_ERROR;
  2674. goto exit;
  2675. }
  2676. f54->data_buffer_size = f54->report_size;
  2677. }
  2678. report_index[0] = 0;
  2679. report_index[1] = 0;
  2680. retval = synaptics_rmi4_reg_write(rmi4_data,
  2681. f54->data_base_addr + REPORT_INDEX_OFFSET,
  2682. report_index,
  2683. sizeof(report_index));
  2684. if (retval < 0) {
  2685. dev_err(rmi4_data->pdev->dev.parent,
  2686. "%s: Failed to write report data index\n",
  2687. __func__);
  2688. retval = STATUS_ERROR;
  2689. goto exit;
  2690. }
  2691. retval = synaptics_rmi4_reg_read(rmi4_data,
  2692. f54->data_base_addr + REPORT_DATA_OFFSET,
  2693. f54->report_data,
  2694. f54->report_size);
  2695. if (retval < 0) {
  2696. dev_err(rmi4_data->pdev->dev.parent,
  2697. "%s: Failed to read report data\n",
  2698. __func__);
  2699. retval = STATUS_ERROR;
  2700. goto exit;
  2701. }
  2702. retval = STATUS_IDLE;
  2703. exit:
  2704. mutex_unlock(&f54->status_mutex);
  2705. if (retval == STATUS_ERROR)
  2706. f54->report_size = 0;
  2707. f54->status = retval;
  2708. }
  2709. static void test_remove_sysfs(void)
  2710. {
  2711. sysfs_remove_group(f54->sysfs_dir, &attr_group);
  2712. sysfs_remove_bin_file(f54->sysfs_dir, &test_report_data);
  2713. kobject_put(f54->sysfs_dir);
  2714. }
  2715. static int test_set_sysfs(void)
  2716. {
  2717. int retval;
  2718. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2719. f54->sysfs_dir = kobject_create_and_add(SYSFS_FOLDER_NAME,
  2720. &rmi4_data->input_dev->dev.kobj);
  2721. if (!f54->sysfs_dir) {
  2722. dev_err(rmi4_data->pdev->dev.parent,
  2723. "%s: Failed to create sysfs directory\n",
  2724. __func__);
  2725. goto exit_directory;
  2726. }
  2727. retval = sysfs_create_bin_file(f54->sysfs_dir, &test_report_data);
  2728. if (retval < 0) {
  2729. dev_err(rmi4_data->pdev->dev.parent,
  2730. "%s: Failed to create sysfs bin file\n",
  2731. __func__);
  2732. goto exit_bin_file;
  2733. }
  2734. retval = sysfs_create_group(f54->sysfs_dir, &attr_group);
  2735. if (retval < 0) {
  2736. dev_err(rmi4_data->pdev->dev.parent,
  2737. "%s: Failed to create sysfs attributes\n",
  2738. __func__);
  2739. goto exit_attributes;
  2740. }
  2741. return 0;
  2742. exit_attributes:
  2743. sysfs_remove_group(f54->sysfs_dir, &attr_group);
  2744. sysfs_remove_bin_file(f54->sysfs_dir, &test_report_data);
  2745. exit_bin_file:
  2746. kobject_put(f54->sysfs_dir);
  2747. exit_directory:
  2748. return -ENODEV;
  2749. }
  2750. static void test_free_control_mem(void)
  2751. {
  2752. struct f54_control control = f54->control;
  2753. kfree(control.reg_7);
  2754. kfree(control.reg_41);
  2755. kfree(control.reg_57);
  2756. kfree(control.reg_86);
  2757. kfree(control.reg_88);
  2758. kfree(control.reg_110);
  2759. kfree(control.reg_149);
  2760. kfree(control.reg_188);
  2761. }
  2762. static void test_set_data(void)
  2763. {
  2764. unsigned short reg_addr;
  2765. reg_addr = f54->data_base_addr + REPORT_DATA_OFFSET + 1;
  2766. /* data 4 */
  2767. if (f54->query.has_sense_frequency_control)
  2768. reg_addr++;
  2769. /* data 5 reserved */
  2770. /* data 6 */
  2771. if (f54->query.has_interference_metric)
  2772. reg_addr += 2;
  2773. /* data 7 */
  2774. if (f54->query.has_one_byte_report_rate |
  2775. f54->query.has_two_byte_report_rate)
  2776. reg_addr++;
  2777. if (f54->query.has_two_byte_report_rate)
  2778. reg_addr++;
  2779. /* data 8 */
  2780. if (f54->query.has_variance_metric)
  2781. reg_addr += 2;
  2782. /* data 9 */
  2783. if (f54->query.has_multi_metric_state_machine)
  2784. reg_addr += 2;
  2785. /* data 10 */
  2786. if (f54->query.has_multi_metric_state_machine |
  2787. f54->query.has_noise_state)
  2788. reg_addr++;
  2789. /* data 11 */
  2790. if (f54->query.has_status)
  2791. reg_addr++;
  2792. /* data 12 */
  2793. if (f54->query.has_slew_metric)
  2794. reg_addr += 2;
  2795. /* data 13 */
  2796. if (f54->query.has_multi_metric_state_machine)
  2797. reg_addr += 2;
  2798. /* data 14 */
  2799. if (f54->query_13.has_cidim)
  2800. reg_addr++;
  2801. /* data 15 */
  2802. if (f54->query_13.has_rail_im)
  2803. reg_addr++;
  2804. /* data 16 */
  2805. if (f54->query_13.has_noise_mitigation_enhancement)
  2806. reg_addr++;
  2807. /* data 17 */
  2808. if (f54->query_16.has_data17)
  2809. reg_addr++;
  2810. /* data 18 */
  2811. if (f54->query_21.has_query24_data18)
  2812. reg_addr++;
  2813. /* data 19 */
  2814. if (f54->query_21.has_data19)
  2815. reg_addr++;
  2816. /* data_20 */
  2817. if (f54->query_25.has_ctrl109)
  2818. reg_addr++;
  2819. /* data 21 */
  2820. if (f54->query_27.has_data21)
  2821. reg_addr++;
  2822. /* data 22 */
  2823. if (f54->query_27.has_data22)
  2824. reg_addr++;
  2825. /* data 23 */
  2826. if (f54->query_29.has_data23)
  2827. reg_addr++;
  2828. /* data 24 */
  2829. if (f54->query_32.has_data24)
  2830. reg_addr++;
  2831. /* data 25 */
  2832. if (f54->query_35.has_data25)
  2833. reg_addr++;
  2834. /* data 26 */
  2835. if (f54->query_35.has_data26)
  2836. reg_addr++;
  2837. /* data 27 */
  2838. if (f54->query_46.has_data27)
  2839. reg_addr++;
  2840. /* data 28 */
  2841. if (f54->query_46.has_data28)
  2842. reg_addr++;
  2843. /* data 29 30 reserved */
  2844. /* data 31 */
  2845. if (f54->query_49.has_data31) {
  2846. f54->data_31.address = reg_addr;
  2847. reg_addr++;
  2848. }
  2849. }
  2850. static int test_set_controls(void)
  2851. {
  2852. int retval;
  2853. unsigned char length = 0;
  2854. unsigned char num_of_sensing_freqs;
  2855. unsigned short reg_addr = f54->control_base_addr;
  2856. struct f54_control *control = &f54->control;
  2857. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  2858. num_of_sensing_freqs = f54->query.number_of_sensing_frequencies;
  2859. /* control 0 */
  2860. reg_addr += CONTROL_0_SIZE;
  2861. /* control 1 */
  2862. if ((f54->query.touch_controller_family == 0) ||
  2863. (f54->query.touch_controller_family == 1))
  2864. reg_addr += CONTROL_1_SIZE;
  2865. /* control 2 */
  2866. reg_addr += CONTROL_2_SIZE;
  2867. /* control 3 */
  2868. if (f54->query.has_pixel_touch_threshold_adjustment)
  2869. reg_addr += CONTROL_3_SIZE;
  2870. /* controls 4 5 6 */
  2871. if ((f54->query.touch_controller_family == 0) ||
  2872. (f54->query.touch_controller_family == 1))
  2873. reg_addr += CONTROL_4_6_SIZE;
  2874. /* control 7 */
  2875. if (f54->query.touch_controller_family == 1) {
  2876. control->reg_7 = kzalloc(sizeof(*(control->reg_7)),
  2877. GFP_KERNEL);
  2878. if (!control->reg_7)
  2879. goto exit_no_mem;
  2880. control->reg_7->address = reg_addr;
  2881. reg_addr += CONTROL_7_SIZE;
  2882. }
  2883. /* controls 8 9 */
  2884. if ((f54->query.touch_controller_family == 0) ||
  2885. (f54->query.touch_controller_family == 1))
  2886. reg_addr += CONTROL_8_9_SIZE;
  2887. /* control 10 */
  2888. if (f54->query.has_interference_metric)
  2889. reg_addr += CONTROL_10_SIZE;
  2890. /* control 11 */
  2891. if (f54->query.has_ctrl11)
  2892. reg_addr += CONTROL_11_SIZE;
  2893. /* controls 12 13 */
  2894. if (f54->query.has_relaxation_control)
  2895. reg_addr += CONTROL_12_13_SIZE;
  2896. /* controls 14 15 16 */
  2897. if (f54->query.has_sensor_assignment) {
  2898. reg_addr += CONTROL_14_SIZE;
  2899. reg_addr += CONTROL_15_SIZE * f54->query.num_of_rx_electrodes;
  2900. reg_addr += CONTROL_16_SIZE * f54->query.num_of_tx_electrodes;
  2901. }
  2902. /* controls 17 18 19 */
  2903. if (f54->query.has_sense_frequency_control) {
  2904. reg_addr += CONTROL_17_SIZE * num_of_sensing_freqs;
  2905. reg_addr += CONTROL_18_SIZE * num_of_sensing_freqs;
  2906. reg_addr += CONTROL_19_SIZE * num_of_sensing_freqs;
  2907. }
  2908. /* control 20 */
  2909. reg_addr += CONTROL_20_SIZE;
  2910. /* control 21 */
  2911. if (f54->query.has_sense_frequency_control)
  2912. reg_addr += CONTROL_21_SIZE;
  2913. /* controls 22 23 24 25 26 */
  2914. if (f54->query.has_firmware_noise_mitigation)
  2915. reg_addr += CONTROL_22_26_SIZE;
  2916. /* control 27 */
  2917. if (f54->query.has_iir_filter)
  2918. reg_addr += CONTROL_27_SIZE;
  2919. /* control 28 */
  2920. if (f54->query.has_firmware_noise_mitigation)
  2921. reg_addr += CONTROL_28_SIZE;
  2922. /* control 29 */
  2923. if (f54->query.has_cmn_removal)
  2924. reg_addr += CONTROL_29_SIZE;
  2925. /* control 30 */
  2926. if (f54->query.has_cmn_maximum)
  2927. reg_addr += CONTROL_30_SIZE;
  2928. /* control 31 */
  2929. if (f54->query.has_touch_hysteresis)
  2930. reg_addr += CONTROL_31_SIZE;
  2931. /* controls 32 33 34 35 */
  2932. if (f54->query.has_edge_compensation)
  2933. reg_addr += CONTROL_32_35_SIZE;
  2934. /* control 36 */
  2935. if ((f54->query.curve_compensation_mode == 1) ||
  2936. (f54->query.curve_compensation_mode == 2)) {
  2937. if (f54->query.curve_compensation_mode == 1) {
  2938. length = max(f54->query.num_of_rx_electrodes,
  2939. f54->query.num_of_tx_electrodes);
  2940. } else if (f54->query.curve_compensation_mode == 2) {
  2941. length = f54->query.num_of_rx_electrodes;
  2942. }
  2943. reg_addr += CONTROL_36_SIZE * length;
  2944. }
  2945. /* control 37 */
  2946. if (f54->query.curve_compensation_mode == 2)
  2947. reg_addr += CONTROL_37_SIZE * f54->query.num_of_tx_electrodes;
  2948. /* controls 38 39 40 */
  2949. if (f54->query.has_per_frequency_noise_control) {
  2950. reg_addr += CONTROL_38_SIZE * num_of_sensing_freqs;
  2951. reg_addr += CONTROL_39_SIZE * num_of_sensing_freqs;
  2952. reg_addr += CONTROL_40_SIZE * num_of_sensing_freqs;
  2953. }
  2954. /* control 41 */
  2955. if (f54->query.has_signal_clarity) {
  2956. control->reg_41 = kzalloc(sizeof(*(control->reg_41)),
  2957. GFP_KERNEL);
  2958. if (!control->reg_41)
  2959. goto exit_no_mem;
  2960. control->reg_41->address = reg_addr;
  2961. reg_addr += CONTROL_41_SIZE;
  2962. }
  2963. /* control 42 */
  2964. if (f54->query.has_variance_metric)
  2965. reg_addr += CONTROL_42_SIZE;
  2966. /* controls 43 44 45 46 47 48 49 50 51 52 53 54 */
  2967. if (f54->query.has_multi_metric_state_machine)
  2968. reg_addr += CONTROL_43_54_SIZE;
  2969. /* controls 55 56 */
  2970. if (f54->query.has_0d_relaxation_control)
  2971. reg_addr += CONTROL_55_56_SIZE;
  2972. /* control 57 */
  2973. if (f54->query.has_0d_acquisition_control) {
  2974. control->reg_57 = kzalloc(sizeof(*(control->reg_57)),
  2975. GFP_KERNEL);
  2976. if (!control->reg_57)
  2977. goto exit_no_mem;
  2978. control->reg_57->address = reg_addr;
  2979. reg_addr += CONTROL_57_SIZE;
  2980. }
  2981. /* control 58 */
  2982. if (f54->query.has_0d_acquisition_control)
  2983. reg_addr += CONTROL_58_SIZE;
  2984. /* control 59 */
  2985. if (f54->query.has_h_blank)
  2986. reg_addr += CONTROL_59_SIZE;
  2987. /* controls 60 61 62 */
  2988. if ((f54->query.has_h_blank) ||
  2989. (f54->query.has_v_blank) ||
  2990. (f54->query.has_long_h_blank))
  2991. reg_addr += CONTROL_60_62_SIZE;
  2992. /* control 63 */
  2993. if ((f54->query.has_h_blank) ||
  2994. (f54->query.has_v_blank) ||
  2995. (f54->query.has_long_h_blank) ||
  2996. (f54->query.has_slew_metric) ||
  2997. (f54->query.has_slew_option) ||
  2998. (f54->query.has_noise_mitigation2))
  2999. reg_addr += CONTROL_63_SIZE;
  3000. /* controls 64 65 66 67 */
  3001. if (f54->query.has_h_blank)
  3002. reg_addr += CONTROL_64_67_SIZE * 7;
  3003. else if ((f54->query.has_v_blank) ||
  3004. (f54->query.has_long_h_blank))
  3005. reg_addr += CONTROL_64_67_SIZE;
  3006. /* controls 68 69 70 71 72 73 */
  3007. if ((f54->query.has_h_blank) ||
  3008. (f54->query.has_v_blank) ||
  3009. (f54->query.has_long_h_blank)) {
  3010. if (f54->query_68.is_tddi_hic)
  3011. reg_addr += CONTROL_70_73_SIZE;
  3012. else
  3013. reg_addr += CONTROL_68_73_SIZE;
  3014. }
  3015. /* control 74 */
  3016. if (f54->query.has_slew_metric)
  3017. reg_addr += CONTROL_74_SIZE;
  3018. /* control 75 */
  3019. if (f54->query.has_enhanced_stretch)
  3020. reg_addr += CONTROL_75_SIZE * num_of_sensing_freqs;
  3021. /* control 76 */
  3022. if (f54->query.has_startup_fast_relaxation)
  3023. reg_addr += CONTROL_76_SIZE;
  3024. /* controls 77 78 */
  3025. if (f54->query.has_esd_control)
  3026. reg_addr += CONTROL_77_78_SIZE;
  3027. /* controls 79 80 81 82 83 */
  3028. if (f54->query.has_noise_mitigation2)
  3029. reg_addr += CONTROL_79_83_SIZE;
  3030. /* controls 84 85 */
  3031. if (f54->query.has_energy_ratio_relaxation)
  3032. reg_addr += CONTROL_84_85_SIZE;
  3033. /* control 86 */
  3034. if (f54->query_13.has_ctrl86) {
  3035. control->reg_86 = kzalloc(sizeof(*(control->reg_86)),
  3036. GFP_KERNEL);
  3037. if (!control->reg_86)
  3038. goto exit_no_mem;
  3039. control->reg_86->address = reg_addr;
  3040. retval = synaptics_rmi4_reg_read(rmi4_data,
  3041. f54->control.reg_86->address,
  3042. f54->control.reg_86->data,
  3043. sizeof(f54->control.reg_86->data));
  3044. if (retval < 0) {
  3045. dev_err(rmi4_data->pdev->dev.parent,
  3046. "%s: Failed to read sense display ratio\n",
  3047. __func__);
  3048. return retval;
  3049. }
  3050. reg_addr += CONTROL_86_SIZE;
  3051. }
  3052. /* control 87 */
  3053. if (f54->query_13.has_ctrl87)
  3054. reg_addr += CONTROL_87_SIZE;
  3055. /* control 88 */
  3056. if (f54->query.has_ctrl88) {
  3057. control->reg_88 = kzalloc(sizeof(*(control->reg_88)),
  3058. GFP_KERNEL);
  3059. if (!control->reg_88)
  3060. goto exit_no_mem;
  3061. control->reg_88->address = reg_addr;
  3062. reg_addr += CONTROL_88_SIZE;
  3063. }
  3064. /* control 89 */
  3065. if (f54->query_13.has_cidim ||
  3066. f54->query_13.has_noise_mitigation_enhancement ||
  3067. f54->query_13.has_rail_im)
  3068. reg_addr += CONTROL_89_SIZE;
  3069. /* control 90 */
  3070. if (f54->query_15.has_ctrl90)
  3071. reg_addr += CONTROL_90_SIZE;
  3072. /* control 91 */
  3073. if (f54->query_21.has_ctrl91)
  3074. reg_addr += CONTROL_91_SIZE;
  3075. /* control 92 */
  3076. if (f54->query_16.has_ctrl92)
  3077. reg_addr += CONTROL_92_SIZE;
  3078. /* control 93 */
  3079. if (f54->query_16.has_ctrl93)
  3080. reg_addr += CONTROL_93_SIZE;
  3081. /* control 94 */
  3082. if (f54->query_16.has_ctrl94_query18)
  3083. reg_addr += CONTROL_94_SIZE;
  3084. /* control 95 */
  3085. if (f54->query_16.has_ctrl95_query19)
  3086. reg_addr += CONTROL_95_SIZE;
  3087. /* control 96 */
  3088. if (f54->query_21.has_ctrl96)
  3089. reg_addr += CONTROL_96_SIZE;
  3090. /* control 97 */
  3091. if (f54->query_21.has_ctrl97)
  3092. reg_addr += CONTROL_97_SIZE;
  3093. /* control 98 */
  3094. if (f54->query_21.has_ctrl98)
  3095. reg_addr += CONTROL_98_SIZE;
  3096. /* control 99 */
  3097. if (f54->query.touch_controller_family == 2)
  3098. reg_addr += CONTROL_99_SIZE;
  3099. /* control 100 */
  3100. if (f54->query_16.has_ctrl100)
  3101. reg_addr += CONTROL_100_SIZE;
  3102. /* control 101 */
  3103. if (f54->query_22.has_ctrl101)
  3104. reg_addr += CONTROL_101_SIZE;
  3105. /* control 102 */
  3106. if (f54->query_23.has_ctrl102)
  3107. reg_addr += CONTROL_102_SIZE;
  3108. /* control 103 */
  3109. if (f54->query_22.has_ctrl103_query26) {
  3110. f54->skip_preparation = true;
  3111. reg_addr += CONTROL_103_SIZE;
  3112. }
  3113. /* control 104 */
  3114. if (f54->query_22.has_ctrl104)
  3115. reg_addr += CONTROL_104_SIZE;
  3116. /* control 105 */
  3117. if (f54->query_22.has_ctrl105)
  3118. reg_addr += CONTROL_105_SIZE;
  3119. /* control 106 */
  3120. if (f54->query_25.has_ctrl106)
  3121. reg_addr += CONTROL_106_SIZE;
  3122. /* control 107 */
  3123. if (f54->query_25.has_ctrl107)
  3124. reg_addr += CONTROL_107_SIZE;
  3125. /* control 108 */
  3126. if (f54->query_25.has_ctrl108)
  3127. reg_addr += CONTROL_108_SIZE;
  3128. /* control 109 */
  3129. if (f54->query_25.has_ctrl109)
  3130. reg_addr += CONTROL_109_SIZE;
  3131. /* control 110 */
  3132. if (f54->query_27.has_ctrl110) {
  3133. control->reg_110 = kzalloc(sizeof(*(control->reg_110)),
  3134. GFP_KERNEL);
  3135. if (!control->reg_110)
  3136. goto exit_no_mem;
  3137. control->reg_110->address = reg_addr;
  3138. reg_addr += CONTROL_110_SIZE;
  3139. }
  3140. /* control 111 */
  3141. if (f54->query_27.has_ctrl111)
  3142. reg_addr += CONTROL_111_SIZE;
  3143. /* control 112 */
  3144. if (f54->query_27.has_ctrl112)
  3145. reg_addr += CONTROL_112_SIZE;
  3146. /* control 113 */
  3147. if (f54->query_27.has_ctrl113)
  3148. reg_addr += CONTROL_113_SIZE;
  3149. /* control 114 */
  3150. if (f54->query_27.has_ctrl114)
  3151. reg_addr += CONTROL_114_SIZE;
  3152. /* control 115 */
  3153. if (f54->query_29.has_ctrl115)
  3154. reg_addr += CONTROL_115_SIZE;
  3155. /* control 116 */
  3156. if (f54->query_29.has_ctrl116)
  3157. reg_addr += CONTROL_116_SIZE;
  3158. /* control 117 */
  3159. if (f54->query_29.has_ctrl117)
  3160. reg_addr += CONTROL_117_SIZE;
  3161. /* control 118 */
  3162. if (f54->query_30.has_ctrl118)
  3163. reg_addr += CONTROL_118_SIZE;
  3164. /* control 119 */
  3165. if (f54->query_30.has_ctrl119)
  3166. reg_addr += CONTROL_119_SIZE;
  3167. /* control 120 */
  3168. if (f54->query_30.has_ctrl120)
  3169. reg_addr += CONTROL_120_SIZE;
  3170. /* control 121 */
  3171. if (f54->query_30.has_ctrl121)
  3172. reg_addr += CONTROL_121_SIZE;
  3173. /* control 122 */
  3174. if (f54->query_30.has_ctrl122_query31)
  3175. reg_addr += CONTROL_122_SIZE;
  3176. /* control 123 */
  3177. if (f54->query_30.has_ctrl123)
  3178. reg_addr += CONTROL_123_SIZE;
  3179. /* control 124 */
  3180. if (f54->query_30.has_ctrl124)
  3181. reg_addr += CONTROL_124_SIZE;
  3182. /* control 125 */
  3183. if (f54->query_32.has_ctrl125)
  3184. reg_addr += CONTROL_125_SIZE;
  3185. /* control 126 */
  3186. if (f54->query_32.has_ctrl126)
  3187. reg_addr += CONTROL_126_SIZE;
  3188. /* control 127 */
  3189. if (f54->query_32.has_ctrl127)
  3190. reg_addr += CONTROL_127_SIZE;
  3191. /* control 128 */
  3192. if (f54->query_33.has_ctrl128)
  3193. reg_addr += CONTROL_128_SIZE;
  3194. /* control 129 */
  3195. if (f54->query_33.has_ctrl129)
  3196. reg_addr += CONTROL_129_SIZE;
  3197. /* control 130 */
  3198. if (f54->query_33.has_ctrl130)
  3199. reg_addr += CONTROL_130_SIZE;
  3200. /* control 131 */
  3201. if (f54->query_33.has_ctrl131)
  3202. reg_addr += CONTROL_131_SIZE;
  3203. /* control 132 */
  3204. if (f54->query_33.has_ctrl132)
  3205. reg_addr += CONTROL_132_SIZE;
  3206. /* control 133 */
  3207. if (f54->query_33.has_ctrl133)
  3208. reg_addr += CONTROL_133_SIZE;
  3209. /* control 134 */
  3210. if (f54->query_33.has_ctrl134)
  3211. reg_addr += CONTROL_134_SIZE;
  3212. /* control 135 */
  3213. if (f54->query_35.has_ctrl135)
  3214. reg_addr += CONTROL_135_SIZE;
  3215. /* control 136 */
  3216. if (f54->query_35.has_ctrl136)
  3217. reg_addr += CONTROL_136_SIZE;
  3218. /* control 137 */
  3219. if (f54->query_35.has_ctrl137)
  3220. reg_addr += CONTROL_137_SIZE;
  3221. /* control 138 */
  3222. if (f54->query_35.has_ctrl138)
  3223. reg_addr += CONTROL_138_SIZE;
  3224. /* control 139 */
  3225. if (f54->query_35.has_ctrl139)
  3226. reg_addr += CONTROL_139_SIZE;
  3227. /* control 140 */
  3228. if (f54->query_35.has_ctrl140)
  3229. reg_addr += CONTROL_140_SIZE;
  3230. /* control 141 */
  3231. if (f54->query_36.has_ctrl141)
  3232. reg_addr += CONTROL_141_SIZE;
  3233. /* control 142 */
  3234. if (f54->query_36.has_ctrl142)
  3235. reg_addr += CONTROL_142_SIZE;
  3236. /* control 143 */
  3237. if (f54->query_36.has_ctrl143)
  3238. reg_addr += CONTROL_143_SIZE;
  3239. /* control 144 */
  3240. if (f54->query_36.has_ctrl144)
  3241. reg_addr += CONTROL_144_SIZE;
  3242. /* control 145 */
  3243. if (f54->query_36.has_ctrl145)
  3244. reg_addr += CONTROL_145_SIZE;
  3245. /* control 146 */
  3246. if (f54->query_36.has_ctrl146)
  3247. reg_addr += CONTROL_146_SIZE;
  3248. /* control 147 */
  3249. if (f54->query_38.has_ctrl147)
  3250. reg_addr += CONTROL_147_SIZE;
  3251. /* control 148 */
  3252. if (f54->query_38.has_ctrl148)
  3253. reg_addr += CONTROL_148_SIZE;
  3254. /* control 149 */
  3255. if (f54->query_38.has_ctrl149) {
  3256. control->reg_149 = kzalloc(sizeof(*(control->reg_149)),
  3257. GFP_KERNEL);
  3258. if (!control->reg_149)
  3259. goto exit_no_mem;
  3260. control->reg_149->address = reg_addr;
  3261. reg_addr += CONTROL_149_SIZE;
  3262. }
  3263. /* control 150 */
  3264. if (f54->query_38.has_ctrl150)
  3265. reg_addr += CONTROL_150_SIZE;
  3266. /* control 151 */
  3267. if (f54->query_38.has_ctrl151)
  3268. reg_addr += CONTROL_151_SIZE;
  3269. /* control 152 */
  3270. if (f54->query_38.has_ctrl152)
  3271. reg_addr += CONTROL_152_SIZE;
  3272. /* control 153 */
  3273. if (f54->query_38.has_ctrl153)
  3274. reg_addr += CONTROL_153_SIZE;
  3275. /* control 154 */
  3276. if (f54->query_39.has_ctrl154)
  3277. reg_addr += CONTROL_154_SIZE;
  3278. /* control 155 */
  3279. if (f54->query_39.has_ctrl155)
  3280. reg_addr += CONTROL_155_SIZE;
  3281. /* control 156 */
  3282. if (f54->query_39.has_ctrl156)
  3283. reg_addr += CONTROL_156_SIZE;
  3284. /* controls 157 158 */
  3285. if (f54->query_39.has_ctrl157_ctrl158)
  3286. reg_addr += CONTROL_157_158_SIZE;
  3287. /* controls 159 to 162 reserved */
  3288. /* control 163 */
  3289. if (f54->query_40.has_ctrl163_query41)
  3290. reg_addr += CONTROL_163_SIZE;
  3291. /* control 164 reserved */
  3292. /* control 165 */
  3293. if (f54->query_40.has_ctrl165_query42)
  3294. reg_addr += CONTROL_165_SIZE;
  3295. /* control 166 */
  3296. if (f54->query_40.has_ctrl166)
  3297. reg_addr += CONTROL_166_SIZE;
  3298. /* control 167 */
  3299. if (f54->query_40.has_ctrl167)
  3300. reg_addr += CONTROL_167_SIZE;
  3301. /* control 168 */
  3302. if (f54->query_40.has_ctrl168)
  3303. reg_addr += CONTROL_168_SIZE;
  3304. /* control 169 */
  3305. if (f54->query_40.has_ctrl169)
  3306. reg_addr += CONTROL_169_SIZE;
  3307. /* control 170 reserved */
  3308. /* control 171 */
  3309. if (f54->query_43.has_ctrl171)
  3310. reg_addr += CONTROL_171_SIZE;
  3311. /* control 172 */
  3312. if (f54->query_43.has_ctrl172_query44_query45)
  3313. reg_addr += CONTROL_172_SIZE;
  3314. /* control 173 */
  3315. if (f54->query_43.has_ctrl173)
  3316. reg_addr += CONTROL_173_SIZE;
  3317. /* control 174 */
  3318. if (f54->query_43.has_ctrl174)
  3319. reg_addr += CONTROL_174_SIZE;
  3320. /* control 175 */
  3321. if (f54->query_43.has_ctrl175)
  3322. reg_addr += CONTROL_175_SIZE;
  3323. /* control 176 */
  3324. if (f54->query_46.has_ctrl176)
  3325. reg_addr += CONTROL_176_SIZE;
  3326. /* controls 177 178 */
  3327. if (f54->query_46.has_ctrl177_ctrl178)
  3328. reg_addr += CONTROL_177_178_SIZE;
  3329. /* control 179 */
  3330. if (f54->query_46.has_ctrl179)
  3331. reg_addr += CONTROL_179_SIZE;
  3332. /* controls 180 to 181 reserved */
  3333. /* control 182 */
  3334. if (f54->query_47.has_ctrl182)
  3335. reg_addr += CONTROL_182_SIZE;
  3336. /* control 183 */
  3337. if (f54->query_47.has_ctrl183)
  3338. reg_addr += CONTROL_183_SIZE;
  3339. /* control 184 reserved */
  3340. /* control 185 */
  3341. if (f54->query_47.has_ctrl185)
  3342. reg_addr += CONTROL_185_SIZE;
  3343. /* control 186 */
  3344. if (f54->query_47.has_ctrl186)
  3345. reg_addr += CONTROL_186_SIZE;
  3346. /* control 187 */
  3347. if (f54->query_47.has_ctrl187)
  3348. reg_addr += CONTROL_187_SIZE;
  3349. /* control 188 */
  3350. if (f54->query_49.has_ctrl188) {
  3351. control->reg_188 = kzalloc(sizeof(*(control->reg_188)),
  3352. GFP_KERNEL);
  3353. if (!control->reg_188)
  3354. goto exit_no_mem;
  3355. control->reg_188->address = reg_addr;
  3356. reg_addr += CONTROL_188_SIZE;
  3357. }
  3358. return 0;
  3359. exit_no_mem:
  3360. dev_err(rmi4_data->pdev->dev.parent,
  3361. "%s: Failed to alloc mem for control registers\n",
  3362. __func__);
  3363. return -ENOMEM;
  3364. }
  3365. static int test_set_queries(void)
  3366. {
  3367. int retval;
  3368. unsigned char offset;
  3369. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  3370. retval = synaptics_rmi4_reg_read(rmi4_data,
  3371. f54->query_base_addr,
  3372. f54->query.data,
  3373. sizeof(f54->query.data));
  3374. if (retval < 0)
  3375. return retval;
  3376. offset = sizeof(f54->query.data);
  3377. /* query 12 */
  3378. if (f54->query.has_sense_frequency_control == 0)
  3379. offset -= 1;
  3380. /* query 13 */
  3381. if (f54->query.has_query13) {
  3382. retval = synaptics_rmi4_reg_read(rmi4_data,
  3383. f54->query_base_addr + offset,
  3384. f54->query_13.data,
  3385. sizeof(f54->query_13.data));
  3386. if (retval < 0)
  3387. return retval;
  3388. offset += 1;
  3389. }
  3390. /* query 14 */
  3391. if (f54->query_13.has_ctrl87)
  3392. offset += 1;
  3393. /* query 15 */
  3394. if (f54->query.has_query15) {
  3395. retval = synaptics_rmi4_reg_read(rmi4_data,
  3396. f54->query_base_addr + offset,
  3397. f54->query_15.data,
  3398. sizeof(f54->query_15.data));
  3399. if (retval < 0)
  3400. return retval;
  3401. offset += 1;
  3402. }
  3403. /* query 16 */
  3404. if (f54->query_15.has_query16) {
  3405. retval = synaptics_rmi4_reg_read(rmi4_data,
  3406. f54->query_base_addr + offset,
  3407. f54->query_16.data,
  3408. sizeof(f54->query_16.data));
  3409. if (retval < 0)
  3410. return retval;
  3411. offset += 1;
  3412. }
  3413. /* query 17 */
  3414. if (f54->query_16.has_query17)
  3415. offset += 1;
  3416. /* query 18 */
  3417. if (f54->query_16.has_ctrl94_query18)
  3418. offset += 1;
  3419. /* query 19 */
  3420. if (f54->query_16.has_ctrl95_query19)
  3421. offset += 1;
  3422. /* query 20 */
  3423. if (f54->query_15.has_query20)
  3424. offset += 1;
  3425. /* query 21 */
  3426. if (f54->query_15.has_query21) {
  3427. retval = synaptics_rmi4_reg_read(rmi4_data,
  3428. f54->query_base_addr + offset,
  3429. f54->query_21.data,
  3430. sizeof(f54->query_21.data));
  3431. if (retval < 0)
  3432. return retval;
  3433. offset += 1;
  3434. }
  3435. /* query 22 */
  3436. if (f54->query_15.has_query22) {
  3437. retval = synaptics_rmi4_reg_read(rmi4_data,
  3438. f54->query_base_addr + offset,
  3439. f54->query_22.data,
  3440. sizeof(f54->query_22.data));
  3441. if (retval < 0)
  3442. return retval;
  3443. offset += 1;
  3444. }
  3445. /* query 23 */
  3446. if (f54->query_22.has_query23) {
  3447. retval = synaptics_rmi4_reg_read(rmi4_data,
  3448. f54->query_base_addr + offset,
  3449. f54->query_23.data,
  3450. sizeof(f54->query_23.data));
  3451. if (retval < 0)
  3452. return retval;
  3453. offset += 1;
  3454. }
  3455. /* query 24 */
  3456. if (f54->query_21.has_query24_data18)
  3457. offset += 1;
  3458. /* query 25 */
  3459. if (f54->query_15.has_query25) {
  3460. retval = synaptics_rmi4_reg_read(rmi4_data,
  3461. f54->query_base_addr + offset,
  3462. f54->query_25.data,
  3463. sizeof(f54->query_25.data));
  3464. if (retval < 0)
  3465. return retval;
  3466. offset += 1;
  3467. }
  3468. /* query 26 */
  3469. if (f54->query_22.has_ctrl103_query26)
  3470. offset += 1;
  3471. /* query 27 */
  3472. if (f54->query_25.has_query27) {
  3473. retval = synaptics_rmi4_reg_read(rmi4_data,
  3474. f54->query_base_addr + offset,
  3475. f54->query_27.data,
  3476. sizeof(f54->query_27.data));
  3477. if (retval < 0)
  3478. return retval;
  3479. offset += 1;
  3480. }
  3481. /* query 28 */
  3482. if (f54->query_22.has_query28)
  3483. offset += 1;
  3484. /* query 29 */
  3485. if (f54->query_27.has_query29) {
  3486. retval = synaptics_rmi4_reg_read(rmi4_data,
  3487. f54->query_base_addr + offset,
  3488. f54->query_29.data,
  3489. sizeof(f54->query_29.data));
  3490. if (retval < 0)
  3491. return retval;
  3492. offset += 1;
  3493. }
  3494. /* query 30 */
  3495. if (f54->query_29.has_query30) {
  3496. retval = synaptics_rmi4_reg_read(rmi4_data,
  3497. f54->query_base_addr + offset,
  3498. f54->query_30.data,
  3499. sizeof(f54->query_30.data));
  3500. if (retval < 0)
  3501. return retval;
  3502. offset += 1;
  3503. }
  3504. /* query 31 */
  3505. if (f54->query_30.has_ctrl122_query31)
  3506. offset += 1;
  3507. /* query 32 */
  3508. if (f54->query_30.has_query32) {
  3509. retval = synaptics_rmi4_reg_read(rmi4_data,
  3510. f54->query_base_addr + offset,
  3511. f54->query_32.data,
  3512. sizeof(f54->query_32.data));
  3513. if (retval < 0)
  3514. return retval;
  3515. offset += 1;
  3516. }
  3517. /* query 33 */
  3518. if (f54->query_32.has_query33) {
  3519. retval = synaptics_rmi4_reg_read(rmi4_data,
  3520. f54->query_base_addr + offset,
  3521. f54->query_33.data,
  3522. sizeof(f54->query_33.data));
  3523. if (retval < 0)
  3524. return retval;
  3525. offset += 1;
  3526. }
  3527. /* query 34 */
  3528. if (f54->query_32.has_query34)
  3529. offset += 1;
  3530. /* query 35 */
  3531. if (f54->query_32.has_query35) {
  3532. retval = synaptics_rmi4_reg_read(rmi4_data,
  3533. f54->query_base_addr + offset,
  3534. f54->query_35.data,
  3535. sizeof(f54->query_35.data));
  3536. if (retval < 0)
  3537. return retval;
  3538. offset += 1;
  3539. }
  3540. /* query 36 */
  3541. if (f54->query_33.has_query36) {
  3542. retval = synaptics_rmi4_reg_read(rmi4_data,
  3543. f54->query_base_addr + offset,
  3544. f54->query_36.data,
  3545. sizeof(f54->query_36.data));
  3546. if (retval < 0)
  3547. return retval;
  3548. offset += 1;
  3549. }
  3550. /* query 37 */
  3551. if (f54->query_36.has_query37)
  3552. offset += 1;
  3553. /* query 38 */
  3554. if (f54->query_36.has_query38) {
  3555. retval = synaptics_rmi4_reg_read(rmi4_data,
  3556. f54->query_base_addr + offset,
  3557. f54->query_38.data,
  3558. sizeof(f54->query_38.data));
  3559. if (retval < 0)
  3560. return retval;
  3561. offset += 1;
  3562. }
  3563. /* query 39 */
  3564. if (f54->query_38.has_query39) {
  3565. retval = synaptics_rmi4_reg_read(rmi4_data,
  3566. f54->query_base_addr + offset,
  3567. f54->query_39.data,
  3568. sizeof(f54->query_39.data));
  3569. if (retval < 0)
  3570. return retval;
  3571. offset += 1;
  3572. }
  3573. /* query 40 */
  3574. if (f54->query_39.has_query40) {
  3575. retval = synaptics_rmi4_reg_read(rmi4_data,
  3576. f54->query_base_addr + offset,
  3577. f54->query_40.data,
  3578. sizeof(f54->query_40.data));
  3579. if (retval < 0)
  3580. return retval;
  3581. offset += 1;
  3582. }
  3583. /* query 41 */
  3584. if (f54->query_40.has_ctrl163_query41)
  3585. offset += 1;
  3586. /* query 42 */
  3587. if (f54->query_40.has_ctrl165_query42)
  3588. offset += 1;
  3589. /* query 43 */
  3590. if (f54->query_40.has_query43) {
  3591. retval = synaptics_rmi4_reg_read(rmi4_data,
  3592. f54->query_base_addr + offset,
  3593. f54->query_43.data,
  3594. sizeof(f54->query_43.data));
  3595. if (retval < 0)
  3596. return retval;
  3597. offset += 1;
  3598. }
  3599. if (f54->query_43.has_ctrl172_query44_query45)
  3600. offset += 2;
  3601. /* query 46 */
  3602. if (f54->query_43.has_query46) {
  3603. retval = synaptics_rmi4_reg_read(rmi4_data,
  3604. f54->query_base_addr + offset,
  3605. f54->query_46.data,
  3606. sizeof(f54->query_46.data));
  3607. if (retval < 0)
  3608. return retval;
  3609. offset += 1;
  3610. }
  3611. /* query 47 */
  3612. if (f54->query_46.has_query47) {
  3613. retval = synaptics_rmi4_reg_read(rmi4_data,
  3614. f54->query_base_addr + offset,
  3615. f54->query_47.data,
  3616. sizeof(f54->query_47.data));
  3617. if (retval < 0)
  3618. return retval;
  3619. offset += 1;
  3620. }
  3621. /* query 48 reserved */
  3622. /* query 49 */
  3623. if (f54->query_47.has_query49) {
  3624. retval = synaptics_rmi4_reg_read(rmi4_data,
  3625. f54->query_base_addr + offset,
  3626. f54->query_49.data,
  3627. sizeof(f54->query_49.data));
  3628. if (retval < 0)
  3629. return retval;
  3630. offset += 1;
  3631. }
  3632. /* query 50 */
  3633. if (f54->query_49.has_query50) {
  3634. retval = synaptics_rmi4_reg_read(rmi4_data,
  3635. f54->query_base_addr + offset,
  3636. f54->query_50.data,
  3637. sizeof(f54->query_50.data));
  3638. if (retval < 0)
  3639. return retval;
  3640. offset += 1;
  3641. }
  3642. /* query 51 */
  3643. if (f54->query_50.has_query51) {
  3644. retval = synaptics_rmi4_reg_read(rmi4_data,
  3645. f54->query_base_addr + offset,
  3646. f54->query_51.data,
  3647. sizeof(f54->query_51.data));
  3648. if (retval < 0)
  3649. return retval;
  3650. offset += 1;
  3651. }
  3652. /* query 53 54 */
  3653. if (f54->query_51.has_query53_query54_ctrl198)
  3654. offset += 2;
  3655. /* query 55 */
  3656. if (f54->query_51.has_query55) {
  3657. retval = synaptics_rmi4_reg_read(rmi4_data,
  3658. f54->query_base_addr + offset,
  3659. f54->query_55.data,
  3660. sizeof(f54->query_55.data));
  3661. if (retval < 0)
  3662. return retval;
  3663. offset += 1;
  3664. }
  3665. /* query 56 */
  3666. if (f54->query_55.has_query56)
  3667. offset += 1;
  3668. /* query 57 */
  3669. if (f54->query_55.has_query57) {
  3670. retval = synaptics_rmi4_reg_read(rmi4_data,
  3671. f54->query_base_addr + offset,
  3672. f54->query_57.data,
  3673. sizeof(f54->query_57.data));
  3674. if (retval < 0)
  3675. return retval;
  3676. offset += 1;
  3677. }
  3678. /* query 58 */
  3679. if (f54->query_57.has_query58) {
  3680. retval = synaptics_rmi4_reg_read(rmi4_data,
  3681. f54->query_base_addr + offset,
  3682. f54->query_58.data,
  3683. sizeof(f54->query_58.data));
  3684. if (retval < 0)
  3685. return retval;
  3686. offset += 1;
  3687. }
  3688. /* query 59 */
  3689. if (f54->query_58.has_query59)
  3690. offset += 1;
  3691. /* query 60 */
  3692. if (f54->query_58.has_query60)
  3693. offset += 1;
  3694. /* query 61 */
  3695. if (f54->query_58.has_query61) {
  3696. retval = synaptics_rmi4_reg_read(rmi4_data,
  3697. f54->query_base_addr + offset,
  3698. f54->query_61.data,
  3699. sizeof(f54->query_61.data));
  3700. if (retval < 0)
  3701. return retval;
  3702. offset += 1;
  3703. }
  3704. /* query 62 63 */
  3705. if (f54->query_61.has_ctrl215_query62_query63)
  3706. offset += 2;
  3707. /* query 64 */
  3708. if (f54->query_61.has_query64) {
  3709. retval = synaptics_rmi4_reg_read(rmi4_data,
  3710. f54->query_base_addr + offset,
  3711. f54->query_64.data,
  3712. sizeof(f54->query_64.data));
  3713. if (retval < 0)
  3714. return retval;
  3715. offset += 1;
  3716. }
  3717. /* query 65 */
  3718. if (f54->query_64.has_query65) {
  3719. retval = synaptics_rmi4_reg_read(rmi4_data,
  3720. f54->query_base_addr + offset,
  3721. f54->query_65.data,
  3722. sizeof(f54->query_65.data));
  3723. if (retval < 0)
  3724. return retval;
  3725. offset += 1;
  3726. }
  3727. /* query 66 */
  3728. if (f54->query_65.has_query66_ctrl231)
  3729. offset += 1;
  3730. /* query 67 */
  3731. if (f54->query_65.has_query67) {
  3732. retval = synaptics_rmi4_reg_read(rmi4_data,
  3733. f54->query_base_addr + offset,
  3734. f54->query_67.data,
  3735. sizeof(f54->query_67.data));
  3736. if (retval < 0)
  3737. return retval;
  3738. offset += 1;
  3739. }
  3740. /* query 68 */
  3741. if (f54->query_67.has_query68) {
  3742. retval = synaptics_rmi4_reg_read(rmi4_data,
  3743. f54->query_base_addr + offset,
  3744. f54->query_68.data,
  3745. sizeof(f54->query_68.data));
  3746. if (retval < 0)
  3747. return retval;
  3748. offset += 1;
  3749. }
  3750. /* query 68 */
  3751. if (f54->query_68.has_query69) {
  3752. retval = synaptics_rmi4_reg_read(rmi4_data,
  3753. f54->query_base_addr + offset,
  3754. f54->query_69.data,
  3755. sizeof(f54->query_69.data));
  3756. if (retval < 0)
  3757. return retval;
  3758. offset += 1;
  3759. }
  3760. return 0;
  3761. }
  3762. static void test_f54_set_regs(struct synaptics_rmi4_data *rmi4_data,
  3763. struct synaptics_rmi4_fn_desc *fd,
  3764. unsigned int intr_count,
  3765. unsigned char page)
  3766. {
  3767. unsigned char ii;
  3768. unsigned char intr_offset;
  3769. f54->query_base_addr = fd->query_base_addr | (page << 8);
  3770. f54->control_base_addr = fd->ctrl_base_addr | (page << 8);
  3771. f54->data_base_addr = fd->data_base_addr | (page << 8);
  3772. f54->command_base_addr = fd->cmd_base_addr | (page << 8);
  3773. f54->intr_reg_num = (intr_count + 7) / 8;
  3774. if (f54->intr_reg_num != 0)
  3775. f54->intr_reg_num -= 1;
  3776. f54->intr_mask = 0;
  3777. intr_offset = intr_count % 8;
  3778. for (ii = intr_offset;
  3779. ii < (fd->intr_src_count + intr_offset);
  3780. ii++) {
  3781. f54->intr_mask |= 1 << ii;
  3782. }
  3783. }
  3784. static int test_f55_set_controls(void)
  3785. {
  3786. unsigned char offset = 0;
  3787. /* controls 0 1 2 */
  3788. if (f55->query.has_sensor_assignment)
  3789. offset += 3;
  3790. /* control 3 */
  3791. if (f55->query.has_edge_compensation)
  3792. offset++;
  3793. /* control 4 */
  3794. if (f55->query.curve_compensation_mode == 0x1 ||
  3795. f55->query.curve_compensation_mode == 0x2)
  3796. offset++;
  3797. /* control 5 */
  3798. if (f55->query.curve_compensation_mode == 0x2)
  3799. offset++;
  3800. /* control 6 */
  3801. if (f55->query.has_ctrl6)
  3802. offset++;
  3803. /* control 7 */
  3804. if (f55->query.has_alternate_transmitter_assignment)
  3805. offset++;
  3806. /* control 8 */
  3807. if (f55->query_3.has_ctrl8)
  3808. offset++;
  3809. /* control 9 */
  3810. if (f55->query_3.has_ctrl9)
  3811. offset++;
  3812. /* control 10 */
  3813. if (f55->query_5.has_corner_compensation)
  3814. offset++;
  3815. /* control 11 */
  3816. if (f55->query.curve_compensation_mode == 0x3)
  3817. offset++;
  3818. /* control 12 */
  3819. if (f55->query_5.has_ctrl12)
  3820. offset++;
  3821. /* control 13 */
  3822. if (f55->query_5.has_ctrl13)
  3823. offset++;
  3824. /* control 14 */
  3825. if (f55->query_5.has_ctrl14)
  3826. offset++;
  3827. /* control 15 */
  3828. if (f55->query_5.has_basis_function)
  3829. offset++;
  3830. /* control 16 */
  3831. if (f55->query_17.has_ctrl16)
  3832. offset++;
  3833. /* control 17 */
  3834. if (f55->query_17.has_ctrl17)
  3835. offset++;
  3836. /* controls 18 19 */
  3837. if (f55->query_17.has_ctrl18_ctrl19)
  3838. offset += 2;
  3839. /* control 20 */
  3840. if (f55->query_17.has_ctrl20)
  3841. offset++;
  3842. /* control 21 */
  3843. if (f55->query_17.has_ctrl21)
  3844. offset++;
  3845. /* control 22 */
  3846. if (f55->query_17.has_ctrl22)
  3847. offset++;
  3848. /* control 23 */
  3849. if (f55->query_18.has_ctrl23)
  3850. offset++;
  3851. /* control 24 */
  3852. if (f55->query_18.has_ctrl24)
  3853. offset++;
  3854. /* control 25 */
  3855. if (f55->query_18.has_ctrl25)
  3856. offset++;
  3857. /* control 26 */
  3858. if (f55->query_18.has_ctrl26)
  3859. offset++;
  3860. /* control 27 */
  3861. if (f55->query_18.has_ctrl27_query20)
  3862. offset++;
  3863. /* control 28 */
  3864. if (f55->query_18.has_ctrl28_query21)
  3865. offset++;
  3866. /* control 29 */
  3867. if (f55->query_22.has_ctrl29)
  3868. offset++;
  3869. /* control 30 */
  3870. if (f55->query_22.has_ctrl30)
  3871. offset++;
  3872. /* control 31 */
  3873. if (f55->query_22.has_ctrl31)
  3874. offset++;
  3875. /* control 32 */
  3876. if (f55->query_22.has_ctrl32)
  3877. offset++;
  3878. /* controls 33 34 35 36 reserved */
  3879. /* control 37 */
  3880. if (f55->query_28.has_ctrl37)
  3881. offset++;
  3882. /* control 38 */
  3883. if (f55->query_30.has_ctrl38)
  3884. offset++;
  3885. /* control 39 */
  3886. if (f55->query_30.has_ctrl39)
  3887. offset++;
  3888. /* control 40 */
  3889. if (f55->query_30.has_ctrl40)
  3890. offset++;
  3891. /* control 41 */
  3892. if (f55->query_30.has_ctrl41)
  3893. offset++;
  3894. /* control 42 */
  3895. if (f55->query_30.has_ctrl42)
  3896. offset++;
  3897. /* controls 43 44 */
  3898. if (f55->query_30.has_ctrl43_ctrl44) {
  3899. f55->afe_mux_offset = offset;
  3900. offset += 2;
  3901. }
  3902. /* controls 45 46 */
  3903. if (f55->query_33.has_ctrl45_ctrl46) {
  3904. f55->has_force = true;
  3905. f55->force_tx_offset = offset;
  3906. f55->force_rx_offset = offset + 1;
  3907. offset += 2;
  3908. }
  3909. return 0;
  3910. }
  3911. static int test_f55_set_queries(void)
  3912. {
  3913. int retval;
  3914. unsigned char offset;
  3915. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  3916. retval = synaptics_rmi4_reg_read(rmi4_data,
  3917. f55->query_base_addr,
  3918. f55->query.data,
  3919. sizeof(f55->query.data));
  3920. if (retval < 0)
  3921. return retval;
  3922. offset = sizeof(f55->query.data);
  3923. /* query 3 */
  3924. if (f55->query.has_single_layer_multi_touch) {
  3925. retval = synaptics_rmi4_reg_read(rmi4_data,
  3926. f55->query_base_addr + offset,
  3927. f55->query_3.data,
  3928. sizeof(f55->query_3.data));
  3929. if (retval < 0)
  3930. return retval;
  3931. offset += 1;
  3932. }
  3933. /* query 4 */
  3934. if (f55->query_3.has_ctrl9)
  3935. offset += 1;
  3936. /* query 5 */
  3937. if (f55->query.has_query5) {
  3938. retval = synaptics_rmi4_reg_read(rmi4_data,
  3939. f55->query_base_addr + offset,
  3940. f55->query_5.data,
  3941. sizeof(f55->query_5.data));
  3942. if (retval < 0)
  3943. return retval;
  3944. offset += 1;
  3945. }
  3946. /* queries 6 7 */
  3947. if (f55->query.curve_compensation_mode == 0x3)
  3948. offset += 2;
  3949. /* query 8 */
  3950. if (f55->query_3.has_ctrl8)
  3951. offset += 1;
  3952. /* query 9 */
  3953. if (f55->query_3.has_query9)
  3954. offset += 1;
  3955. /* queries 10 11 12 13 14 15 16 */
  3956. if (f55->query_5.has_basis_function)
  3957. offset += 7;
  3958. /* query 17 */
  3959. if (f55->query_5.has_query17) {
  3960. retval = synaptics_rmi4_reg_read(rmi4_data,
  3961. f55->query_base_addr + offset,
  3962. f55->query_17.data,
  3963. sizeof(f55->query_17.data));
  3964. if (retval < 0)
  3965. return retval;
  3966. offset += 1;
  3967. }
  3968. /* query 18 */
  3969. if (f55->query_17.has_query18) {
  3970. retval = synaptics_rmi4_reg_read(rmi4_data,
  3971. f55->query_base_addr + offset,
  3972. f55->query_18.data,
  3973. sizeof(f55->query_18.data));
  3974. if (retval < 0)
  3975. return retval;
  3976. offset += 1;
  3977. }
  3978. /* query 19 */
  3979. if (f55->query_18.has_query19)
  3980. offset += 1;
  3981. /* query 20 */
  3982. if (f55->query_18.has_ctrl27_query20)
  3983. offset += 1;
  3984. /* query 21 */
  3985. if (f55->query_18.has_ctrl28_query21)
  3986. offset += 1;
  3987. /* query 22 */
  3988. if (f55->query_18.has_query22) {
  3989. retval = synaptics_rmi4_reg_read(rmi4_data,
  3990. f55->query_base_addr + offset,
  3991. f55->query_22.data,
  3992. sizeof(f55->query_22.data));
  3993. if (retval < 0)
  3994. return retval;
  3995. offset += 1;
  3996. }
  3997. /* query 23 */
  3998. if (f55->query_22.has_query23) {
  3999. retval = synaptics_rmi4_reg_read(rmi4_data,
  4000. f55->query_base_addr + offset,
  4001. f55->query_23.data,
  4002. sizeof(f55->query_23.data));
  4003. if (retval < 0)
  4004. return retval;
  4005. offset += 1;
  4006. f55->amp_sensor = f55->query_23.amp_sensor_enabled;
  4007. f55->size_of_column2mux = f55->query_23.size_of_column2mux;
  4008. }
  4009. /* queries 24 25 26 27 reserved */
  4010. /* query 28 */
  4011. if (f55->query_22.has_query28) {
  4012. retval = synaptics_rmi4_reg_read(rmi4_data,
  4013. f55->query_base_addr + offset,
  4014. f55->query_28.data,
  4015. sizeof(f55->query_28.data));
  4016. if (retval < 0)
  4017. return retval;
  4018. offset += 1;
  4019. }
  4020. /* query 29 */
  4021. if (f55->query_28.has_query29)
  4022. offset += 1;
  4023. /* query 30 */
  4024. if (f55->query_28.has_query30) {
  4025. retval = synaptics_rmi4_reg_read(rmi4_data,
  4026. f55->query_base_addr + offset,
  4027. f55->query_30.data,
  4028. sizeof(f55->query_30.data));
  4029. if (retval < 0)
  4030. return retval;
  4031. offset += 1;
  4032. }
  4033. /* queries 31 32 */
  4034. if (f55->query_30.has_query31_query32)
  4035. offset += 2;
  4036. /* query 33 */
  4037. if (f55->query_30.has_query33) {
  4038. retval = synaptics_rmi4_reg_read(rmi4_data,
  4039. f55->query_base_addr + offset,
  4040. f55->query_33.data,
  4041. sizeof(f55->query_33.data));
  4042. if (retval < 0)
  4043. return retval;
  4044. offset += 1;
  4045. f55->extended_amp = f55->query_33.has_extended_amp_pad;
  4046. }
  4047. return 0;
  4048. }
  4049. static void test_f55_init(struct synaptics_rmi4_data *rmi4_data)
  4050. {
  4051. int retval;
  4052. unsigned char ii;
  4053. unsigned char rx_electrodes;
  4054. unsigned char tx_electrodes;
  4055. struct f55_control_43 ctrl_43;
  4056. retval = test_f55_set_queries();
  4057. if (retval < 0) {
  4058. dev_err(rmi4_data->pdev->dev.parent,
  4059. "%s: Failed to read F55 query registers\n",
  4060. __func__);
  4061. return;
  4062. }
  4063. if (!f55->query.has_sensor_assignment)
  4064. return;
  4065. retval = test_f55_set_controls();
  4066. if (retval < 0) {
  4067. dev_err(rmi4_data->pdev->dev.parent,
  4068. "%s: Failed to set up F55 control registers\n",
  4069. __func__);
  4070. return;
  4071. }
  4072. tx_electrodes = f55->query.num_of_tx_electrodes;
  4073. rx_electrodes = f55->query.num_of_rx_electrodes;
  4074. f55->tx_assignment = kzalloc(tx_electrodes, GFP_KERNEL);
  4075. f55->rx_assignment = kzalloc(rx_electrodes, GFP_KERNEL);
  4076. retval = synaptics_rmi4_reg_read(rmi4_data,
  4077. f55->control_base_addr + SENSOR_TX_MAPPING_OFFSET,
  4078. f55->tx_assignment,
  4079. tx_electrodes);
  4080. if (retval < 0) {
  4081. dev_err(rmi4_data->pdev->dev.parent,
  4082. "%s: Failed to read F55 tx assignment\n",
  4083. __func__);
  4084. return;
  4085. }
  4086. retval = synaptics_rmi4_reg_read(rmi4_data,
  4087. f55->control_base_addr + SENSOR_RX_MAPPING_OFFSET,
  4088. f55->rx_assignment,
  4089. rx_electrodes);
  4090. if (retval < 0) {
  4091. dev_err(rmi4_data->pdev->dev.parent,
  4092. "%s: Failed to read F55 rx assignment\n",
  4093. __func__);
  4094. return;
  4095. }
  4096. f54->tx_assigned = 0;
  4097. for (ii = 0; ii < tx_electrodes; ii++) {
  4098. if (f55->tx_assignment[ii] != 0xff)
  4099. f54->tx_assigned++;
  4100. }
  4101. f54->rx_assigned = 0;
  4102. for (ii = 0; ii < rx_electrodes; ii++) {
  4103. if (f55->rx_assignment[ii] != 0xff)
  4104. f54->rx_assigned++;
  4105. }
  4106. if (f55->amp_sensor) {
  4107. f54->tx_assigned = f55->size_of_column2mux;
  4108. f54->rx_assigned /= 2;
  4109. }
  4110. if (f55->extended_amp) {
  4111. retval = synaptics_rmi4_reg_read(rmi4_data,
  4112. f55->control_base_addr + f55->afe_mux_offset,
  4113. ctrl_43.data,
  4114. sizeof(ctrl_43.data));
  4115. if (retval < 0) {
  4116. dev_err(rmi4_data->pdev->dev.parent,
  4117. "%s: Failed to read F55 AFE mux sizes\n",
  4118. __func__);
  4119. return;
  4120. }
  4121. f54->tx_assigned = ctrl_43.afe_l_mux_size +
  4122. ctrl_43.afe_r_mux_size;
  4123. }
  4124. /* force mapping */
  4125. if (f55->has_force) {
  4126. f55->force_tx_assignment = kzalloc(tx_electrodes, GFP_KERNEL);
  4127. f55->force_rx_assignment = kzalloc(rx_electrodes, GFP_KERNEL);
  4128. retval = synaptics_rmi4_reg_read(rmi4_data,
  4129. f55->control_base_addr + f55->force_tx_offset,
  4130. f55->force_tx_assignment,
  4131. tx_electrodes);
  4132. if (retval < 0) {
  4133. dev_err(rmi4_data->pdev->dev.parent,
  4134. "%s: Failed to read F55 force tx assignment\n",
  4135. __func__);
  4136. return;
  4137. }
  4138. retval = synaptics_rmi4_reg_read(rmi4_data,
  4139. f55->control_base_addr + f55->force_rx_offset,
  4140. f55->force_rx_assignment,
  4141. rx_electrodes);
  4142. if (retval < 0) {
  4143. dev_err(rmi4_data->pdev->dev.parent,
  4144. "%s: Failed to read F55 force rx assignment\n",
  4145. __func__);
  4146. return;
  4147. }
  4148. for (ii = 0; ii < tx_electrodes; ii++) {
  4149. if (f55->force_tx_assignment[ii] != 0xff)
  4150. f54->tx_assigned++;
  4151. }
  4152. for (ii = 0; ii < rx_electrodes; ii++) {
  4153. if (f55->force_rx_assignment[ii] != 0xff)
  4154. f54->rx_assigned++;
  4155. }
  4156. }
  4157. }
  4158. static void test_f55_set_regs(struct synaptics_rmi4_data *rmi4_data,
  4159. struct synaptics_rmi4_fn_desc *fd,
  4160. unsigned char page)
  4161. {
  4162. f55 = kzalloc(sizeof(*f55), GFP_KERNEL);
  4163. if (!f55) {
  4164. dev_err(rmi4_data->pdev->dev.parent,
  4165. "%s: Failed to alloc mem for F55\n",
  4166. __func__);
  4167. return;
  4168. }
  4169. f55->query_base_addr = fd->query_base_addr | (page << 8);
  4170. f55->control_base_addr = fd->ctrl_base_addr | (page << 8);
  4171. f55->data_base_addr = fd->data_base_addr | (page << 8);
  4172. f55->command_base_addr = fd->cmd_base_addr | (page << 8);
  4173. }
  4174. static void test_f21_init(struct synaptics_rmi4_data *rmi4_data)
  4175. {
  4176. int retval;
  4177. unsigned char ii;
  4178. unsigned char size_of_query2;
  4179. unsigned char size_of_query5;
  4180. unsigned char query_11_offset;
  4181. unsigned char ctrl_4_offset;
  4182. struct f21_query_2 *query_2 = NULL;
  4183. struct f21_query_5 *query_5 = NULL;
  4184. struct f21_query_11 *query_11 = NULL;
  4185. query_2 = kzalloc(sizeof(*query_2), GFP_KERNEL);
  4186. if (!query_2) {
  4187. dev_err(rmi4_data->pdev->dev.parent,
  4188. "%s: Failed to alloc mem for query_2\n",
  4189. __func__);
  4190. goto exit;
  4191. }
  4192. query_5 = kzalloc(sizeof(*query_5), GFP_KERNEL);
  4193. if (!query_5) {
  4194. dev_err(rmi4_data->pdev->dev.parent,
  4195. "%s: Failed to alloc mem for query_5\n",
  4196. __func__);
  4197. goto exit;
  4198. }
  4199. query_11 = kzalloc(sizeof(*query_11), GFP_KERNEL);
  4200. if (!query_11) {
  4201. dev_err(rmi4_data->pdev->dev.parent,
  4202. "%s: Failed to alloc mem for query_11\n",
  4203. __func__);
  4204. goto exit;
  4205. }
  4206. retval = synaptics_rmi4_reg_read(rmi4_data,
  4207. f21->query_base_addr + 1,
  4208. &size_of_query2,
  4209. sizeof(size_of_query2));
  4210. if (retval < 0)
  4211. goto exit;
  4212. if (size_of_query2 > sizeof(query_2->data))
  4213. size_of_query2 = sizeof(query_2->data);
  4214. retval = synaptics_rmi4_reg_read(rmi4_data,
  4215. f21->query_base_addr + 2,
  4216. query_2->data,
  4217. size_of_query2);
  4218. if (retval < 0)
  4219. goto exit;
  4220. if (!query_2->query11_is_present) {
  4221. dev_err(rmi4_data->pdev->dev.parent,
  4222. "%s: No F21 force capabilities\n",
  4223. __func__);
  4224. goto exit;
  4225. }
  4226. query_11_offset = query_2->query0_is_present +
  4227. query_2->query1_is_present +
  4228. query_2->query2_is_present +
  4229. query_2->query3_is_present +
  4230. query_2->query4_is_present +
  4231. query_2->query5_is_present +
  4232. query_2->query6_is_present +
  4233. query_2->query7_is_present +
  4234. query_2->query8_is_present +
  4235. query_2->query9_is_present +
  4236. query_2->query10_is_present;
  4237. retval = synaptics_rmi4_reg_read(rmi4_data,
  4238. f21->query_base_addr + 11,
  4239. query_11->data,
  4240. sizeof(query_11->data));
  4241. if (retval < 0)
  4242. goto exit;
  4243. if (!query_11->has_force_sensing_txrx_mapping) {
  4244. dev_err(rmi4_data->pdev->dev.parent,
  4245. "%s: No F21 force mapping\n",
  4246. __func__);
  4247. goto exit;
  4248. }
  4249. f21->max_num_of_tx = query_11->max_number_of_force_txs;
  4250. f21->max_num_of_rx = query_11->max_number_of_force_rxs;
  4251. f21->max_num_of_txrx = f21->max_num_of_tx + f21->max_num_of_rx;
  4252. f21->force_txrx_assignment = kzalloc(f21->max_num_of_txrx, GFP_KERNEL);
  4253. retval = synaptics_rmi4_reg_read(rmi4_data,
  4254. f21->query_base_addr + 4,
  4255. &size_of_query5,
  4256. sizeof(size_of_query5));
  4257. if (retval < 0)
  4258. goto exit;
  4259. if (size_of_query5 > sizeof(query_5->data))
  4260. size_of_query5 = sizeof(query_5->data);
  4261. retval = synaptics_rmi4_reg_read(rmi4_data,
  4262. f21->query_base_addr + 5,
  4263. query_5->data,
  4264. size_of_query5);
  4265. if (retval < 0)
  4266. goto exit;
  4267. ctrl_4_offset = query_5->ctrl0_is_present +
  4268. query_5->ctrl1_is_present +
  4269. query_5->ctrl2_is_present +
  4270. query_5->ctrl3_is_present;
  4271. retval = synaptics_rmi4_reg_read(rmi4_data,
  4272. f21->control_base_addr + ctrl_4_offset,
  4273. f21->force_txrx_assignment,
  4274. f21->max_num_of_txrx);
  4275. if (retval < 0) {
  4276. dev_err(rmi4_data->pdev->dev.parent,
  4277. "%s: Failed to read F21 force txrx assignment\n",
  4278. __func__);
  4279. goto exit;
  4280. }
  4281. f21->has_force = true;
  4282. for (ii = 0; ii < f21->max_num_of_tx; ii++) {
  4283. if (f21->force_txrx_assignment[ii] != 0xff)
  4284. f21->tx_assigned++;
  4285. }
  4286. for (ii = f21->max_num_of_tx; ii < f21->max_num_of_txrx; ii++) {
  4287. if (f21->force_txrx_assignment[ii] != 0xff)
  4288. f21->rx_assigned++;
  4289. }
  4290. exit:
  4291. kfree(query_2);
  4292. kfree(query_5);
  4293. kfree(query_11);
  4294. }
  4295. static void test_f21_set_regs(struct synaptics_rmi4_data *rmi4_data,
  4296. struct synaptics_rmi4_fn_desc *fd,
  4297. unsigned char page)
  4298. {
  4299. f21 = kzalloc(sizeof(*f21), GFP_KERNEL);
  4300. if (!f21) {
  4301. dev_err(rmi4_data->pdev->dev.parent,
  4302. "%s: Failed to alloc mem for F21\n",
  4303. __func__);
  4304. return;
  4305. }
  4306. f21->query_base_addr = fd->query_base_addr | (page << 8);
  4307. f21->control_base_addr = fd->ctrl_base_addr | (page << 8);
  4308. f21->data_base_addr = fd->data_base_addr | (page << 8);
  4309. f21->command_base_addr = fd->cmd_base_addr | (page << 8);
  4310. }
  4311. static int test_scan_pdt(void)
  4312. {
  4313. int retval;
  4314. unsigned char intr_count = 0;
  4315. unsigned char page;
  4316. unsigned short addr;
  4317. bool f54found = false;
  4318. bool f55found = false;
  4319. struct synaptics_rmi4_fn_desc rmi_fd;
  4320. struct synaptics_rmi4_data *rmi4_data = f54->rmi4_data;
  4321. for (page = 0; page < PAGES_TO_SERVICE; page++) {
  4322. for (addr = PDT_START; addr > PDT_END; addr -= PDT_ENTRY_SIZE) {
  4323. addr |= (page << 8);
  4324. retval = synaptics_rmi4_reg_read(rmi4_data,
  4325. addr,
  4326. (unsigned char *)&rmi_fd,
  4327. sizeof(rmi_fd));
  4328. if (retval < 0)
  4329. return retval;
  4330. addr &= ~(MASK_8BIT << 8);
  4331. if (!rmi_fd.fn_number)
  4332. break;
  4333. switch (rmi_fd.fn_number) {
  4334. case SYNAPTICS_RMI4_F54:
  4335. test_f54_set_regs(rmi4_data,
  4336. &rmi_fd, intr_count, page);
  4337. f54found = true;
  4338. break;
  4339. case SYNAPTICS_RMI4_F55:
  4340. test_f55_set_regs(rmi4_data,
  4341. &rmi_fd, page);
  4342. f55found = true;
  4343. break;
  4344. case SYNAPTICS_RMI4_F21:
  4345. test_f21_set_regs(rmi4_data,
  4346. &rmi_fd, page);
  4347. break;
  4348. default:
  4349. break;
  4350. }
  4351. if (f54found && f55found)
  4352. goto pdt_done;
  4353. intr_count += rmi_fd.intr_src_count;
  4354. }
  4355. }
  4356. if (!f54found) {
  4357. dev_err(rmi4_data->pdev->dev.parent,
  4358. "%s: Failed to find F54\n",
  4359. __func__);
  4360. return -EINVAL;
  4361. }
  4362. pdt_done:
  4363. return 0;
  4364. }
  4365. static void synaptics_rmi4_test_attn(struct synaptics_rmi4_data *rmi4_data,
  4366. unsigned char intr_mask)
  4367. {
  4368. if (!f54)
  4369. return;
  4370. if (f54->intr_mask & intr_mask)
  4371. queue_work(f54->test_report_workqueue, &f54->test_report_work);
  4372. return;
  4373. }
  4374. static int synaptics_rmi4_test_init(struct synaptics_rmi4_data *rmi4_data)
  4375. {
  4376. int retval;
  4377. if (f54) {
  4378. dev_dbg(rmi4_data->pdev->dev.parent,
  4379. "%s: Handle already exists\n",
  4380. __func__);
  4381. return 0;
  4382. }
  4383. f54 = kzalloc(sizeof(*f54), GFP_KERNEL);
  4384. if (!f54) {
  4385. dev_err(rmi4_data->pdev->dev.parent,
  4386. "%s: Failed to alloc mem for F54\n",
  4387. __func__);
  4388. retval = -ENOMEM;
  4389. goto exit;
  4390. }
  4391. f54->rmi4_data = rmi4_data;
  4392. f55 = NULL;
  4393. f21 = NULL;
  4394. retval = test_scan_pdt();
  4395. if (retval < 0)
  4396. goto exit_free_mem;
  4397. retval = test_set_queries();
  4398. if (retval < 0) {
  4399. dev_err(rmi4_data->pdev->dev.parent,
  4400. "%s: Failed to read F54 query registers\n",
  4401. __func__);
  4402. goto exit_free_mem;
  4403. }
  4404. f54->tx_assigned = f54->query.num_of_tx_electrodes;
  4405. f54->rx_assigned = f54->query.num_of_rx_electrodes;
  4406. retval = test_set_controls();
  4407. if (retval < 0) {
  4408. dev_err(rmi4_data->pdev->dev.parent,
  4409. "%s: Failed to set up F54 control registers\n",
  4410. __func__);
  4411. goto exit_free_control;
  4412. }
  4413. test_set_data();
  4414. if (f55)
  4415. test_f55_init(rmi4_data);
  4416. if (f21)
  4417. test_f21_init(rmi4_data);
  4418. if (rmi4_data->external_afe_buttons)
  4419. f54->tx_assigned++;
  4420. retval = test_set_sysfs();
  4421. if (retval < 0) {
  4422. dev_err(rmi4_data->pdev->dev.parent,
  4423. "%s: Failed to create sysfs entries\n",
  4424. __func__);
  4425. goto exit_sysfs;
  4426. }
  4427. f54->test_report_workqueue =
  4428. create_singlethread_workqueue("test_report_workqueue");
  4429. INIT_WORK(&f54->test_report_work, test_report_work);
  4430. hrtimer_init(&f54->watchdog, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
  4431. f54->watchdog.function = test_get_report_timeout;
  4432. INIT_WORK(&f54->timeout_work, test_timeout_work);
  4433. mutex_init(&f54->status_mutex);
  4434. f54->status = STATUS_IDLE;
  4435. return 0;
  4436. exit_sysfs:
  4437. if (f21)
  4438. kfree(f21->force_txrx_assignment);
  4439. if (f55) {
  4440. kfree(f55->tx_assignment);
  4441. kfree(f55->rx_assignment);
  4442. kfree(f55->force_tx_assignment);
  4443. kfree(f55->force_rx_assignment);
  4444. }
  4445. exit_free_control:
  4446. test_free_control_mem();
  4447. exit_free_mem:
  4448. kfree(f21);
  4449. f21 = NULL;
  4450. kfree(f55);
  4451. f55 = NULL;
  4452. kfree(f54);
  4453. f54 = NULL;
  4454. exit:
  4455. return retval;
  4456. }
  4457. static void synaptics_rmi4_test_remove(struct synaptics_rmi4_data *rmi4_data)
  4458. {
  4459. if (!f54)
  4460. goto exit;
  4461. hrtimer_cancel(&f54->watchdog);
  4462. cancel_work_sync(&f54->test_report_work);
  4463. flush_workqueue(f54->test_report_workqueue);
  4464. destroy_workqueue(f54->test_report_workqueue);
  4465. test_remove_sysfs();
  4466. if (f21)
  4467. kfree(f21->force_txrx_assignment);
  4468. if (f55) {
  4469. kfree(f55->tx_assignment);
  4470. kfree(f55->rx_assignment);
  4471. kfree(f55->force_tx_assignment);
  4472. kfree(f55->force_rx_assignment);
  4473. }
  4474. test_free_control_mem();
  4475. if (f54->data_buffer_size)
  4476. kfree(f54->report_data);
  4477. kfree(f21);
  4478. f21 = NULL;
  4479. kfree(f55);
  4480. f55 = NULL;
  4481. kfree(f54);
  4482. f54 = NULL;
  4483. exit:
  4484. complete(&test_remove_complete);
  4485. }
  4486. static void synaptics_rmi4_test_reset(struct synaptics_rmi4_data *rmi4_data)
  4487. {
  4488. int retval;
  4489. if (!f54) {
  4490. synaptics_rmi4_test_init(rmi4_data);
  4491. return;
  4492. }
  4493. if (f21)
  4494. kfree(f21->force_txrx_assignment);
  4495. if (f55) {
  4496. kfree(f55->tx_assignment);
  4497. kfree(f55->rx_assignment);
  4498. kfree(f55->force_tx_assignment);
  4499. kfree(f55->force_rx_assignment);
  4500. }
  4501. test_free_control_mem();
  4502. kfree(f55);
  4503. f55 = NULL;
  4504. kfree(f21);
  4505. f21 = NULL;
  4506. retval = test_scan_pdt();
  4507. if (retval < 0)
  4508. goto exit_free_mem;
  4509. retval = test_set_queries();
  4510. if (retval < 0) {
  4511. dev_err(rmi4_data->pdev->dev.parent,
  4512. "%s: Failed to read F54 query registers\n",
  4513. __func__);
  4514. goto exit_free_mem;
  4515. }
  4516. f54->tx_assigned = f54->query.num_of_tx_electrodes;
  4517. f54->rx_assigned = f54->query.num_of_rx_electrodes;
  4518. retval = test_set_controls();
  4519. if (retval < 0) {
  4520. dev_err(rmi4_data->pdev->dev.parent,
  4521. "%s: Failed to set up F54 control registers\n",
  4522. __func__);
  4523. goto exit_free_control;
  4524. }
  4525. test_set_data();
  4526. if (f55)
  4527. test_f55_init(rmi4_data);
  4528. if (f21)
  4529. test_f21_init(rmi4_data);
  4530. if (rmi4_data->external_afe_buttons)
  4531. f54->tx_assigned++;
  4532. f54->status = STATUS_IDLE;
  4533. return;
  4534. exit_free_control:
  4535. test_free_control_mem();
  4536. exit_free_mem:
  4537. hrtimer_cancel(&f54->watchdog);
  4538. cancel_work_sync(&f54->test_report_work);
  4539. flush_workqueue(f54->test_report_workqueue);
  4540. destroy_workqueue(f54->test_report_workqueue);
  4541. test_remove_sysfs();
  4542. if (f54->data_buffer_size)
  4543. kfree(f54->report_data);
  4544. kfree(f21);
  4545. f21 = NULL;
  4546. kfree(f55);
  4547. f55 = NULL;
  4548. kfree(f54);
  4549. f54 = NULL;
  4550. return;
  4551. }
  4552. static struct synaptics_rmi4_exp_fn test_module = {
  4553. .fn_type = RMI_TEST_REPORTING,
  4554. .init = synaptics_rmi4_test_init,
  4555. .remove = synaptics_rmi4_test_remove,
  4556. .reset = synaptics_rmi4_test_reset,
  4557. .reinit = NULL,
  4558. .early_suspend = NULL,
  4559. .suspend = NULL,
  4560. .resume = NULL,
  4561. .late_resume = NULL,
  4562. .attn = synaptics_rmi4_test_attn,
  4563. };
  4564. static int __init rmi4_test_module_init(void)
  4565. {
  4566. synaptics_rmi4_new_function(&test_module, true);
  4567. return 0;
  4568. }
  4569. static void __exit rmi4_test_module_exit(void)
  4570. {
  4571. synaptics_rmi4_new_function(&test_module, false);
  4572. wait_for_completion(&test_remove_complete);
  4573. }
  4574. module_init(rmi4_test_module_init);
  4575. module_exit(rmi4_test_module_exit);
  4576. MODULE_AUTHOR("Synaptics, Inc.");
  4577. MODULE_DESCRIPTION("Synaptics DSX Test Reporting Module");
  4578. MODULE_LICENSE("GPL v2");