| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201 |
- /*
- * cyttsp5_device_access.c
- * Parade TrueTouch(TM) Standard Product V5 Device Access Module.
- * Configuration and Test command/status user interface.
- * For use with Parade touchscreen controllers.
- * Supported parts include:
- * CYTMA5XX
- * CYTMA448
- * CYTMA445A
- * CYTT21XXX
- * CYTT31XXX
- *
- * Copyright (C) 2015 Parade Technologies
- * Copyright (C) 2012-2015 Cypress Semiconductor
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * version 2, and only version 2, as published by the
- * Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * Contact Parade Technologies at www.paradetech.com <ttdrivers@paradetech.com>
- *
- */
- #include "cyttsp5_regs.h"
- #include <linux/firmware.h>
- #include <linux/timer.h>
- #include <linux/timex.h>
- #include <linux/rtc.h>
- #define CY_CMCP_THRESHOLD_FILE_NAME "cyttsp5_thresholdfile.csv"
- #define CMCP_THRESHOLD_FILE_NAME "ttdl_cmcp_thresholdfile.csv"
- /* Max test case number */
- #define MAX_CASE_NUM (22)
- /* ASCII */
- #define ASCII_LF (0x0A)
- #define ASCII_CR (0x0D)
- #define ASCII_COMMA (0x2C)
- #define ASCII_ZERO (0x30)
- #define ASCII_NINE (0x39)
- /* Max characters of test case name */
- #define NAME_SIZE_MAX (50)
- /* Max sensor and button number */
- #define MAX_BUTTONS (HID_SYSINFO_MAX_BTN)
- #define MAX_SENSORS (1024)
- #define MAX_TX_SENSORS (128)
- #define MAX_RX_SENSORS (128)
- /* Multiply by 2 for double (min, max) values */
- #define TABLE_BUTTON_MAX_SIZE (MAX_BUTTONS * 2)
- #define TABLE_SENSOR_MAX_SIZE (MAX_SENSORS * 2)
- #define TABLE_TX_MAX_SIZE (MAX_TX_SENSORS*2)
- #define TABLE_RX_MAX_SIZE (MAX_RX_SENSORS*2)
- #define CM_PANEL_DATA_OFFSET (6)
- #define CM_BTN_DATA_OFFSET (6)
- #define CP_PANEL_DATA_OFFSET (6)
- #define CP_BTN_DATA_OFFSET (6)
- #define MAX_BUF_LEN (50000)
- /* cmcp csv file information */
- struct configuration {
- u32 cm_range_limit_row;
- u32 cm_range_limit_col;
- u32 cm_min_limit_cal;
- u32 cm_max_limit_cal;
- u32 cm_max_delta_sensor_percent;
- u32 cm_max_delta_button_percent;
- u32 min_sensor_rx;
- u32 max_sensor_rx;
- u32 min_sensor_tx;
- u32 max_sensor_tx;
- u32 min_button;
- u32 max_button;
- u32 max_delta_sensor;
- u32 cp_max_delta_sensor_rx_percent;
- u32 cp_max_delta_sensor_tx_percent;
- u32 cm_min_max_table_button[TABLE_BUTTON_MAX_SIZE];
- u32 cp_min_max_table_button[TABLE_BUTTON_MAX_SIZE];
- u32 cm_min_max_table_sensor[TABLE_SENSOR_MAX_SIZE];
- u32 cp_min_max_table_rx[TABLE_RX_MAX_SIZE];
- u32 cp_min_max_table_tx[TABLE_TX_MAX_SIZE];
- u32 cm_min_max_table_button_size;
- u32 cp_min_max_table_button_size;
- u32 cm_min_max_table_sensor_size;
- u32 cp_min_max_table_rx_size;
- u32 cp_min_max_table_tx_size;
- u32 cp_max_delta_button_percent;
- u32 cm_max_table_gradient_cols_percent[TABLE_TX_MAX_SIZE];
- u32 cm_max_table_gradient_cols_percent_size;
- u32 cm_max_table_gradient_rows_percent[TABLE_RX_MAX_SIZE];
- u32 cm_max_table_gradient_rows_percent_size;
- u32 cm_excluding_row_edge;
- u32 cm_excluding_col_edge;
- u32 rx_num;
- u32 tx_num;
- u32 btn_num;
- u32 cm_enabled;
- u32 cp_enabled;
- u32 is_valid_or_not;
- };
- /* Test case search definition */
- struct test_case_search {
- char name[NAME_SIZE_MAX]; /* Test case name */
- u32 name_size; /* Test case name size */
- u32 offset; /* Test case offset */
- };
- /* Test case field definition */
- struct test_case_field {
- char *name; /* Test case name */
- u32 name_size; /* Test case name size */
- u32 type; /* Test case type */
- u32 *bufptr; /* Buffer to store value information */
- u32 exist_or_not;/* Test case exist or not */
- u32 data_num; /* Buffer data number */
- u32 line_num; /* Buffer line number */
- };
- /* Test case type */
- enum test_case_type {
- TEST_CASE_TYPE_NO,
- TEST_CASE_TYPE_ONE,
- TEST_CASE_TYPE_MUL,
- TEST_CASE_TYPE_MUL_LINES,
- };
- /* Test case order in test_case_field_array */
- enum case_order {
- CM_TEST_INPUTS,
- CM_EXCLUDING_COL_EDGE,
- CM_EXCLUDING_ROW_EDGE,
- CM_GRADIENT_CHECK_COL,
- CM_GRADIENT_CHECK_ROW,
- CM_RANGE_LIMIT_ROW,
- CM_RANGE_LIMIT_COL,
- CM_MIN_LIMIT_CAL,
- CM_MAX_LIMIT_CAL,
- CM_MAX_DELTA_SENSOR_PERCENT,
- CM_MAX_DELTA_BUTTON_PERCENT,
- PER_ELEMENT_MIN_MAX_TABLE_BUTTON,
- PER_ELEMENT_MIN_MAX_TABLE_SENSOR,
- CP_TEST_INPUTS,
- CP_MAX_DELTA_SENSOR_RX_PERCENT,
- CP_MAX_DELTA_SENSOR_TX_PERCENT,
- CP_MAX_DELTA_BUTTON_PERCENT,
- CP_PER_ELEMENT_MIN_MAX_BUTTON,
- MIN_BUTTON,
- MAX_BUTTON,
- PER_ELEMENT_MIN_MAX_RX,
- PER_ELEMENT_MIN_MAX_TX,
- CASE_ORDER_MAX,
- };
- enum cmcp_test_item {
- CMCP_FULL = 0,
- CMCP_CM_PANEL,
- CMCP_CP_PANEL,
- CMCP_CM_BTN,
- CMCP_CP_BTN,
- };
- #define CM_ENABLED 0x10
- #define CP_ENABLED 0x20
- #define CM_PANEL (0x01 | CM_ENABLED)
- #define CP_PANEL (0x02 | CP_ENABLED)
- #define CM_BTN (0x04 | CM_ENABLED)
- #define CP_BTN (0x08 | CP_ENABLED)
- #define CMCP_FULL_CASE\
- (CM_PANEL | CP_PANEL | CM_BTN | CP_BTN | CM_ENABLED | CP_ENABLED)
- #define CYTTSP5_DEVICE_ACCESS_NAME "cyttsp5_device_access"
- #define CYTTSP5_INPUT_ELEM_SZ (sizeof("0xHH") + 1)
- #define STATUS_SUCCESS 0
- #define STATUS_FAIL -1
- #define PIP_CMD_MAX_LENGTH ((1 << 16) - 1)
- #ifdef TTHE_TUNER_SUPPORT
- struct heatmap_param {
- bool scan_start;
- enum scan_data_type_list data_type; /* raw, base, diff */
- int num_element;
- };
- #endif
- #define ABS(x) (((x) < 0) ? -(x) : (x))
- #define CY_MAX_CONFIG_BYTES 256
- #define CYTTSP5_TTHE_TUNER_GET_PANEL_DATA_FILE_NAME "get_panel_data"
- #define TTHE_TUNER_MAX_BUF (CY_MAX_PRBUF_SIZE * 3)
- struct cyttsp5_device_access_data {
- struct device *dev;
- struct cyttsp5_sysinfo *si;
- struct mutex sysfs_lock;
- u8 status;
- u16 response_length;
- bool sysfs_nodes_created;
- struct kobject mfg_test;
- u8 panel_scan_data_id;
- u8 get_idac_data_id;
- u8 calibrate_sensing_mode;
- u8 calibrate_initialize_baselines;
- u8 baseline_sensing_mode;
- #ifdef TTHE_TUNER_SUPPORT
- struct heatmap_param heatmap;
- struct dentry *tthe_get_panel_data_debugfs;
- struct mutex debugfs_lock;
- u8 tthe_get_panel_data_buf[TTHE_TUNER_MAX_BUF];
- u8 tthe_get_panel_data_is_open;
- #endif
- struct dentry *cmcp_results_debugfs;
- struct dentry *base_dentry;
- struct dentry *mfg_test_dentry;
- u8 ic_buf[CY_MAX_PRBUF_SIZE];
- u8 response_buf[CY_MAX_PRBUF_SIZE];
- struct mutex cmcp_threshold_lock;
- u8 *cmcp_threshold_data;
- int cmcp_threshold_size;
- bool cmcp_threshold_loading;
- struct work_struct cmcp_threshold_update;
- struct completion builtin_cmcp_threshold_complete;
- int builtin_cmcp_threshold_status;
- bool is_manual_upgrade_enabled;
- struct configuration *configs;
- struct cmcp_data *cmcp_info;
- struct result *result;
- struct test_case_search *test_search_array;
- struct test_case_field *test_field_array;
- int cmcp_test_items;
- int test_executed;
- int cmcp_range_check;
- int cmcp_force_calibrate;
- int cmcp_test_in_progress;
- };
- struct cmcp_data {
- struct gd_sensor *gd_sensor_col;
- struct gd_sensor *gd_sensor_row;
- int32_t *cm_data_panel;
- int32_t *cp_tx_data_panel;
- int32_t *cp_rx_data_panel;
- int32_t *cp_tx_cal_data_panel;
- int32_t *cp_rx_cal_data_panel;
- int32_t cp_sensor_rx_delta;
- int32_t cp_sensor_tx_delta;
- int32_t cp_button_delta;
- int32_t *cm_btn_data;
- int32_t *cp_btn_data;
- int32_t *cm_sensor_column_delta;
- int32_t *cm_sensor_row_delta;
- int32_t cp_btn_cal;
- int32_t cm_btn_cal;
- int32_t cp_button_ave;
- int32_t cm_ave_data_panel;
- int32_t cp_tx_ave_data_panel;
- int32_t cp_rx_ave_data_panel;
- int32_t cm_cal_data_panel;
- int32_t cm_ave_data_btn;
- int32_t cm_cal_data_btn;
- int32_t cm_delta_data_btn;
- int32_t cm_sensor_delta;
- int32_t tx_num;
- int32_t rx_num;
- int32_t btn_num;
- };
- struct result {
- int32_t sensor_assignment;
- int32_t config_ver;
- int32_t revision_ctrl;
- int32_t device_id_high;
- int32_t device_id_low;
- bool cm_test_run;
- bool cp_test_run;
- /* Sensor Cm validation */
- bool cm_test_pass;
- bool cm_sensor_validation_pass;
- bool cm_sensor_row_delta_pass;
- bool cm_sensor_col_delta_pass;
- bool cm_sensor_gd_row_pass;
- bool cm_sensor_gd_col_pass;
- bool cm_sensor_calibration_pass;
- bool cm_sensor_delta_pass;
- bool cm_button_validation_pass;
- bool cm_button_delta_pass;
- int32_t *cm_sensor_raw_data;
- int32_t cm_sensor_calibration;
- int32_t cm_sensor_delta;
- int32_t *cm_button_raw_data;
- int32_t cm_button_delta;
- /* Sensor Cp validation */
- bool cp_test_pass;
- bool cp_sensor_delta_pass;
- bool cp_sensor_rx_delta_pass;
- bool cp_sensor_tx_delta_pass;
- bool cp_sensor_average_pass;
- bool cp_button_delta_pass;
- bool cp_button_average_pass;
- bool cp_rx_validation_pass;
- bool cp_tx_validation_pass;
- bool cp_button_validation_pass;
- int32_t *cp_sensor_rx_raw_data;
- int32_t *cp_sensor_tx_raw_data;
- int32_t cp_sensor_rx_delta;
- int32_t cp_sensor_tx_delta;
- int32_t cp_sensor_rx_calibration;
- int32_t cp_sensor_tx_calibration;
- int32_t *cp_button_raw_data;
- int32_t cp_button_delta;
- /*other validation*/
- bool short_test_pass;
- bool test_summary;
- uint8_t *cm_open_pwc;
- };
- static struct cyttsp5_core_commands *cmd;
- static struct cyttsp5_module device_access_module;
- static ssize_t cyttsp5_run_and_get_selftest_result_noprint(struct device *dev,
- char *buf, size_t buf_len, u8 test_id, u16 read_length,
- bool get_result_on_pass);
- static int _cyttsp5_calibrate_idacs_cmd(struct device *dev,
- u8 sensing_mode, u8 *status);
- static inline struct cyttsp5_device_access_data *cyttsp5_get_device_access_data(
- struct device *dev)
- {
- return cyttsp5_get_module_data(dev, &device_access_module);
- }
- static ssize_t cyttsp5_status_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- u8 val;
- mutex_lock(&dad->sysfs_lock);
- val = dad->status;
- mutex_unlock(&dad->sysfs_lock);
- return scnprintf(buf, CY_MAX_PRBUF_SIZE, "%d\n", val);
- }
- static DEVICE_ATTR(status, S_IRUSR, cyttsp5_status_show, NULL);
- static ssize_t cyttsp5_response_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- int i;
- ssize_t num_read;
- int index;
- mutex_lock(&dad->sysfs_lock);
- index = scnprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status %d\n", dad->status);
- if (!dad->status)
- goto error;
- num_read = dad->response_length;
- for (i = 0; i < num_read; i++)
- index += scnprintf(buf + index, CY_MAX_PRBUF_SIZE - index,
- "0x%02X\n", dad->response_buf[i]);
- index += scnprintf(buf + index, CY_MAX_PRBUF_SIZE - index,
- "(%zd bytes)\n", num_read);
- error:
- mutex_unlock(&dad->sysfs_lock);
- return index;
- }
- static DEVICE_ATTR(response, S_IRUSR, cyttsp5_response_show, NULL);
- /*
- * Gets user input from sysfs and parse it
- * return size of parsed output buffer
- */
- static int cyttsp5_ic_parse_input(struct device *dev, const char *buf,
- size_t buf_size, u8 *ic_buf, size_t ic_buf_size)
- {
- const char *pbuf = buf;
- unsigned long value;
- char scan_buf[CYTTSP5_INPUT_ELEM_SZ];
- u32 i = 0;
- u32 j;
- int last = 0;
- int ret;
- parade_debug(dev, DEBUG_LEVEL_1,
- "%s: pbuf=%p buf=%p size=%zu %s=%zu buf=%s\n",
- __func__, pbuf, buf, buf_size, "scan buf size",
- CYTTSP5_INPUT_ELEM_SZ, buf);
- while (pbuf <= (buf + buf_size)) {
- if (i >= CY_MAX_CONFIG_BYTES) {
- dev_err(dev, "%s: %s size=%d max=%d\n", __func__,
- "Max cmd size exceeded", i,
- CY_MAX_CONFIG_BYTES);
- return -EINVAL;
- }
- if (i >= ic_buf_size) {
- dev_err(dev, "%s: %s size=%d buf_size=%zu\n", __func__,
- "Buffer size exceeded", i, ic_buf_size);
- return -EINVAL;
- }
- while (((*pbuf == ' ') || (*pbuf == ','))
- && (pbuf < (buf + buf_size))) {
- last = *pbuf;
- pbuf++;
- }
- if (pbuf >= (buf + buf_size))
- break;
- memset(scan_buf, 0, CYTTSP5_INPUT_ELEM_SZ);
- if ((last == ',') && (*pbuf == ',')) {
- dev_err(dev, "%s: %s \",,\" not allowed.\n", __func__,
- "Invalid data format.");
- return -EINVAL;
- }
- for (j = 0; j < (CYTTSP5_INPUT_ELEM_SZ - 1)
- && (pbuf < (buf + buf_size))
- && (*pbuf != ' ')
- && (*pbuf != ','); j++) {
- last = *pbuf;
- scan_buf[j] = *pbuf++;
- }
- ret = kstrtoul(scan_buf, 16, &value);
- if (ret < 0) {
- dev_err(dev, "%s: %s '%s' %s%s i=%d r=%d\n", __func__,
- "Invalid data format. ", scan_buf,
- "Use \"0xHH,...,0xHH\"", " instead.",
- i, ret);
- return ret;
- }
- ic_buf[i] = value;
- i++;
- }
- return i;
- }
- static ssize_t cyttsp5_command_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- ssize_t length;
- int rc;
- mutex_lock(&dad->sysfs_lock);
- dad->status = 0;
- dad->response_length = 0;
- length = cyttsp5_ic_parse_input(dev, buf, size, dad->ic_buf,
- CY_MAX_PRBUF_SIZE);
- if (length <= 0) {
- dev_err(dev, "%s: %s Group Data store\n", __func__,
- "Malformed input for");
- goto exit;
- }
- /* write ic_buf to log */
- cyttsp5_pr_buf(dev, dad->ic_buf, length, "ic_buf");
- pm_runtime_get_sync(dev);
- rc = cmd->nonhid_cmd->user_cmd(dev, 1, CY_MAX_PRBUF_SIZE,
- dad->response_buf, length, dad->ic_buf,
- &dad->response_length);
- pm_runtime_put(dev);
- if (rc) {
- dad->response_length = 0;
- dev_err(dev, "%s: Failed to store command\n", __func__);
- } else {
- dad->status = 1;
- }
- exit:
- mutex_unlock(&dad->sysfs_lock);
- parade_debug(dev, DEBUG_LEVEL_2, "%s: return size=%zu\n",
- __func__, size);
- return size;
- }
- static DEVICE_ATTR(command, S_IWUSR, NULL, cyttsp5_command_store);
- static int cmcp_check_config_fw_match(struct device *dev,
- struct configuration *configuration)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- int32_t tx_num = dad->configs->tx_num;
- int32_t rx_num = dad->configs->rx_num;
- int32_t button_num = dad->configs->btn_num;
- int ret = 0;
- if (tx_num != dad->si->sensing_conf_data.tx_num) {
- dev_err(dev, "%s: TX number mismatch!\n", __func__);
- ret = -EINVAL;
- }
- if (rx_num != dad->si->sensing_conf_data.rx_num) {
- dev_err(dev, "%s: RX number mismatch!\n", __func__);
- ret = -EINVAL;
- }
- if (button_num != dad->si->num_btns) {
- dev_err(dev, "%s: Button number mismatch!\n", __func__);
- ret = -EINVAL;
- }
- return ret;
- }
- static int validate_cm_test_results(struct device *dev,
- struct configuration *configuration, struct cmcp_data *cmcp_info,
- struct result *result, bool *pass, int test_item)
- {
- int32_t tx_num = cmcp_info->tx_num;
- int32_t rx_num = cmcp_info->rx_num;
- int32_t button_num = cmcp_info->btn_num;
- uint32_t sensor_num = tx_num * rx_num;
- int32_t *cm_sensor_data = cmcp_info->cm_data_panel;
- int32_t cm_button_delta;
- int32_t cm_sensor_calibration;
- int32_t *cm_button_data = cmcp_info->cm_btn_data;
- struct gd_sensor *gd_sensor_col = cmcp_info->gd_sensor_col;
- struct gd_sensor *gd_sensor_row = cmcp_info->gd_sensor_row;
- int32_t *cm_sensor_column_delta = cmcp_info->cm_sensor_column_delta;
- int32_t *cm_sensor_row_delta = cmcp_info->cm_sensor_row_delta;
- int ret = 0;
- int i, j;
- parade_debug(dev, DEBUG_LEVEL_2, "%s: start\n", __func__);
- if ((test_item & CM_PANEL) == CM_PANEL) {
- parade_debug(dev, DEBUG_LEVEL_2, "Check each sensor Cm data for min max value\n ");
- /* Check each sensor Cm data for min/max values */
- result->cm_sensor_validation_pass = true;
- for (i = 0; i < sensor_num; i++) {
- int row = i % rx_num;
- int col = i / rx_num;
- int32_t cm_sensor_min =
- configuration->cm_min_max_table_sensor[(row*tx_num+col)*2];
- int32_t cm_sensor_max =
- configuration->cm_min_max_table_sensor[(row*tx_num+col)*2+1];
- if ((cm_sensor_data[i] < cm_sensor_min)
- || (cm_sensor_data[i] > cm_sensor_max)) {
- dev_err(dev, "%s: Sensor[%d,%d]:%d (%d,%d)\n",
- "Cm sensor min/max test",
- row, col,
- cm_sensor_data[i],
- cm_sensor_min, cm_sensor_max);
- result->cm_sensor_validation_pass = false;
- }
- }
- /*check cm gradient column data*/
- result->cm_sensor_gd_col_pass = true;
- for (i = 0;
- i < configuration->cm_max_table_gradient_cols_percent_size;
- i++) {
- if ((gd_sensor_col + i)->gradient_val >
- 10 * configuration->cm_max_table_gradient_cols_percent[i]){
- dev_err(dev,
- "%s: cm_max_table_gradient_cols_percent[%d]:%d, gradient_val:%d\n",
- __func__,
- i,
- configuration->cm_max_table_gradient_cols_percent[i],
- (gd_sensor_col + i)->gradient_val);
- result->cm_sensor_gd_col_pass = false;
- }
- }
- /*check cm gradient row data*/
- result->cm_sensor_gd_row_pass = true;
- for (j = 0;
- j < configuration->cm_max_table_gradient_rows_percent_size;
- j++) {
- if ((gd_sensor_row + j)->gradient_val >
- 10 * configuration->cm_max_table_gradient_rows_percent[j]) {
- dev_err(dev,
- "%s: cm_max_table_gradient_rows_percent[%d]:%d, gradient_val:%d\n",
- __func__,
- j, configuration->cm_max_table_gradient_rows_percent[j],
- (gd_sensor_row + j)->gradient_val);
- result->cm_sensor_gd_row_pass = false;
- }
- }
- result->cm_sensor_row_delta_pass = true;
- result->cm_sensor_col_delta_pass = true;
- result->cm_sensor_calibration_pass = true;
- result->cm_sensor_delta_pass = true;
- /*
- * Check each row Cm data
- * with neighbor for difference
- */
- for (i = 0; i < tx_num; i++) {
- for (j = 1; j < rx_num; j++) {
- int32_t cm_sensor_row_diff =
- ABS(cm_sensor_data[i * rx_num + j] -
- cm_sensor_data[i * rx_num + j - 1]);
- cm_sensor_row_delta[i * rx_num + j - 1] =
- cm_sensor_row_diff;
- if (cm_sensor_row_diff
- > configuration->cm_range_limit_row) {
- dev_err(dev,
- "%s: Sensor[%d,%d]:%d (%d)\n",
- "Cm sensor row range limit test",
- j, i,
- cm_sensor_row_diff,
- configuration->cm_range_limit_row);
- result->cm_sensor_row_delta_pass = false;
- }
- }
- }
- /*
- * Check each column Cm data
- * with neighbor for difference
- */
- for (i = 1; i < tx_num; i++) {
- for (j = 0; j < rx_num; j++) {
- int32_t cm_sensor_col_diff =
- ABS((int)cm_sensor_data[i * rx_num + j] -
- (int)cm_sensor_data[(i - 1) * rx_num + j]);
- cm_sensor_column_delta[(i - 1) * rx_num + j] =
- cm_sensor_col_diff;
- if (cm_sensor_col_diff >
- configuration->cm_range_limit_col) {
- dev_err(dev,
- "%s: Sensor[%d,%d]:%d (%d)\n",
- "Cm sensor column range limit test",
- j, i,
- cm_sensor_col_diff,
- configuration->cm_range_limit_col);
- result->cm_sensor_col_delta_pass = false;
- }
- }
- }
- /* Check sensor calculated Cm for min/max values */
- cm_sensor_calibration = cmcp_info->cm_cal_data_panel;
- if (cm_sensor_calibration <
- configuration->cm_min_limit_cal
- || cm_sensor_calibration >
- configuration->cm_max_limit_cal) {
- dev_err(dev, "%s: Cm_cal:%d (%d,%d)\n",
- "Cm sensor Cm_cal min/max test",
- cm_sensor_calibration,
- configuration->cm_min_limit_cal,
- configuration->cm_max_limit_cal);
- result->cm_sensor_calibration_pass = false;
- }
- /* Check sensor Cm delta for range limit */
- if (cmcp_info->cm_sensor_delta
- > 10 * configuration->cm_max_delta_sensor_percent) {
- dev_err(dev,
- "%s: Cm_sensor_delta:%d (%d)\n",
- "Cm sensor delta range limit test",
- cmcp_info->cm_sensor_delta,
- configuration->cm_max_delta_sensor_percent);
- result->cm_sensor_delta_pass = false;
- }
- result->cm_test_pass = result->cm_sensor_gd_col_pass
- && result->cm_sensor_gd_row_pass
- && result->cm_sensor_validation_pass
- && result->cm_sensor_row_delta_pass
- && result->cm_sensor_col_delta_pass
- && result->cm_sensor_calibration_pass
- && result->cm_sensor_delta_pass;
- }
- if (((test_item & CM_BTN) == CM_BTN) && (cmcp_info->btn_num)) {
- /* Check each button Cm data for min/max values */
- result->cm_button_validation_pass = true;
- for (i = 0; i < button_num; i++) {
- int32_t cm_button_min =
- configuration->cm_min_max_table_button[i * 2];
- int32_t cm_button_max =
- configuration->cm_min_max_table_button[i * 2 + 1];
- if ((cm_button_data[i] <= cm_button_min)
- || (cm_button_data[i] >= cm_button_max)) {
- dev_err(dev,
- "%s: Button[%d]:%d (%d,%d)\n",
- "Cm button min/max test",
- i,
- cm_button_data[i],
- cm_button_min, cm_button_max);
- result->cm_button_validation_pass = false;
- }
- }
- /* Check button Cm delta for range limit */
- result->cm_button_delta_pass = true;
- cm_button_delta = ABS((cmcp_info->cm_ave_data_btn -
- cmcp_info->cm_cal_data_btn) * 100 /
- cmcp_info->cm_ave_data_btn);
- if (cm_button_delta >
- configuration->cm_max_delta_button_percent) {
- dev_err(dev,
- "%s: Cm_button_delta:%d (%d)\n",
- "Cm button delta range limit test",
- cm_button_delta,
- configuration->cm_max_delta_button_percent);
- result->cm_button_delta_pass = false;
- }
- result->cm_test_pass = result->cm_test_pass
- && result->cm_button_validation_pass
- && result->cm_button_delta_pass;
- }
- if (pass)
- *pass = result->cm_test_pass;
- return ret;
- }
- static int validate_cp_test_results(struct device *dev,
- struct configuration *configuration, struct cmcp_data *cmcp_info,
- struct result *result, bool *pass, int test_item)
- {
- int i = 0;
- uint32_t configuration_rx_num;
- uint32_t configuration_tx_num;
- int32_t *cp_sensor_tx_data = cmcp_info->cp_tx_data_panel;
- int32_t *cp_sensor_rx_data = cmcp_info->cp_rx_data_panel;
- int32_t cp_button_delta;
- int32_t cp_button_average;
- result->cp_test_pass = true;
- configuration_rx_num = configuration->cp_min_max_table_rx_size/2;
- configuration_tx_num = configuration->cp_min_max_table_tx_size/2;
- parade_debug(dev, DEBUG_LEVEL_2, "%s start\n", __func__);
- if ((test_item & CP_PANEL) == CP_PANEL) {
- int32_t cp_sensor_tx_delta;
- int32_t cp_sensor_rx_delta;
- /* Check Sensor Cp delta for range limit */
- result->cp_sensor_delta_pass = true;
- /*check cp_sensor_tx_delta */
- for (i = 0; i < configuration_tx_num; i++) {
- cp_sensor_tx_delta =
- ABS((cmcp_info->cp_tx_cal_data_panel[i]-
- cmcp_info->cp_tx_data_panel[i]) * 100 /
- cmcp_info->cp_tx_data_panel[i]);
- if (cp_sensor_tx_delta >
- configuration->cp_max_delta_sensor_tx_percent) {
- dev_err(dev,
- "%s: Cp_sensor_tx_delta:%d (%d)\n",
- "Cp sensor delta range limit test",
- cp_sensor_tx_delta,
- configuration->cp_max_delta_sensor_tx_percent);
- result->cp_sensor_delta_pass = false;
- }
- }
- /*check cp_sensor_rx_delta */
- for (i = 0; i < configuration_rx_num; i++) {
- cp_sensor_rx_delta =
- ABS((cmcp_info->cp_rx_cal_data_panel[i] -
- cmcp_info->cp_rx_data_panel[i]) * 100 /
- cmcp_info->cp_rx_data_panel[i]);
- if (cp_sensor_rx_delta >
- configuration->cp_max_delta_sensor_rx_percent) {
- dev_err(dev,
- "%s: Cp_sensor_rx_delta:%d(%d)\n",
- "Cp sensor delta range limit test",
- cp_sensor_rx_delta,
- configuration->cp_max_delta_sensor_rx_percent);
- result->cp_sensor_delta_pass = false;
- }
- }
- /* Check sensor Cp rx for min/max values */
- result->cp_rx_validation_pass = true;
- for (i = 0; i < configuration_rx_num; i++) {
- int32_t cp_rx_min =
- configuration->cp_min_max_table_rx[i * 2];
- int32_t cp_rx_max =
- configuration->cp_min_max_table_rx[i * 2 + 1];
- if ((cp_sensor_rx_data[i] <= cp_rx_min)
- || (cp_sensor_rx_data[i] >= cp_rx_max)) {
- dev_err(dev,
- "%s: Cp Rx[%d]:%d (%d,%d)\n",
- "Cp Rx min/max test",
- i,
- (int)cp_sensor_rx_data[i],
- cp_rx_min, cp_rx_max);
- result->cp_rx_validation_pass = false;
- }
- }
- /* Check sensor Cp tx for min/max values */
- result->cp_tx_validation_pass = true;
- for (i = 0; i < configuration_tx_num; i++) {
- int32_t cp_tx_min =
- configuration->cp_min_max_table_tx[i * 2];
- int32_t cp_tx_max =
- configuration->cp_min_max_table_tx[i * 2 + 1];
- if ((cp_sensor_tx_data[i] <= cp_tx_min)
- || (cp_sensor_tx_data[i] >= cp_tx_max)) {
- dev_err(dev,
- "%s: Cp Tx[%d]:%d(%d,%d)\n",
- "Cp Tx min/max test",
- i,
- cp_sensor_tx_data[i],
- cp_tx_min, cp_tx_max);
- result->cp_tx_validation_pass = false;
- }
- }
- result->cp_test_pass = result->cp_test_pass
- && result->cp_sensor_delta_pass
- && result->cp_rx_validation_pass
- && result->cp_tx_validation_pass;
- }
- if (((test_item & CP_BTN) == CP_BTN) && (cmcp_info->btn_num)) {
- result->cp_button_delta_pass = true;
- /* Check button Cp delta for range limit */
- cp_button_delta = ABS((cmcp_info->cp_btn_cal
- - cmcp_info->cp_button_ave) * 100 /
- cmcp_info->cp_button_ave);
- if (cp_button_delta >
- configuration->cp_max_delta_button_percent) {
- dev_err(dev,
- "%s: Cp_button_delta:%d (%d)\n",
- "Cp button delta range limit test",
- cp_button_delta,
- configuration->cp_max_delta_button_percent);
- result->cp_button_delta_pass = false;
- }
- /* Check button Cp average for min/max values */
- result->cp_button_average_pass = true;
- cp_button_average = cmcp_info->cp_button_ave;
- if (cp_button_average < configuration->min_button
- || cp_button_average >
- configuration->max_button) {
- dev_err(dev,
- "%s: Button Cp average fails min/max test\n",
- __func__);
- dev_err(dev,
- "%s: Cp_button_average:%d (%d,%d)\n",
- "Cp button average min/max test",
- cp_button_average,
- configuration->min_button,
- configuration->max_button);
- result->cp_button_average_pass = false;
- }
- /* Check each button Cp data for min/max values */
- result->cp_button_validation_pass = true;
- for (i = 0; i < cmcp_info->btn_num; i++) {
- int32_t cp_button_min =
- configuration->cp_min_max_table_button[i * 2];
- int32_t cp_button_max =
- configuration->cp_min_max_table_button[i * 2 + 1];
- if ((cmcp_info->cp_btn_data[i] <= cp_button_min)
- || (cmcp_info->cp_btn_data[i] >= cp_button_max)) {
- dev_err(dev,
- "%s: Button[%d]:%d (%d,%d)\n",
- "Cp button min/max test",
- i,
- cmcp_info->cp_btn_data[i],
- cp_button_min, cp_button_max);
- result->cp_button_validation_pass = false;
- }
- }
- result->cp_test_pass = result->cp_test_pass
- && result->cp_button_delta_pass
- && result->cp_button_average_pass
- && result->cp_button_validation_pass;
- }
- if (pass)
- *pass = result->cp_test_pass;
- return 0;
- }
- static void calculate_gradient_row(struct gd_sensor *gd_sensor_row_head,
- uint16_t row_num, int exclude_row_edge, int exclude_col_edge)
- {
- int i = 0;
- uint16_t cm_min_cur = 0;
- uint16_t cm_max_cur = 0;
- uint16_t cm_ave_cur = 0;
- uint16_t cm_ave_next = 0;
- uint16_t cm_ave_prev = 0;
- struct gd_sensor *p = gd_sensor_row_head;
- if (exclude_row_edge) {
- for (i = 0; i < row_num; i++) {
- if (!exclude_col_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (row_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (row_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if ((i == 0) || (i == (row_num-1))) {
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur) * 1000 /
- cm_ave_cur;
- } else if (i == 1) {
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
- cm_ave_cur;
- } else {
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
- cm_ave_cur;
- }
- }
- } else if (!exclude_row_edge) {
- for (i = 0; i < row_num; i++) {
- if (!exclude_col_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (row_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (row_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if (i <= 1)
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
- cm_ave_cur;
- else
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
- cm_ave_cur;
- }
- }
- }
- static void calculate_gradient_col(struct gd_sensor *gd_sensor_row_head,
- uint16_t col_num, int exclude_row_edge, int exclude_col_edge)
- {
- int i = 0;
- int32_t cm_min_cur = 0;
- int32_t cm_max_cur = 0;
- int32_t cm_ave_cur = 0;
- int32_t cm_ave_next = 0;
- int32_t cm_ave_prev = 0;
- struct gd_sensor *p = gd_sensor_row_head;
- if (!exclude_col_edge) {
- for (i = 0; i < col_num; i++) {
- if (!exclude_row_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (col_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (col_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if (i <= 1)
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_next)) * 1000 /
- cm_ave_cur;
- else
- (p + i)->gradient_val = (cm_max_cur - cm_min_cur
- + ABS(cm_ave_cur - cm_ave_prev)) * 1000 /
- cm_ave_cur;
- }
- } else if (exclude_col_edge) {
- for (i = 0; i < col_num; i++) {
- if (!exclude_row_edge) {
- cm_ave_cur = (p + i)->cm_ave;
- cm_min_cur = (p + i)->cm_min;
- cm_max_cur = (p + i)->cm_max;
- if (i < (col_num-1))
- cm_ave_next = (p + i+1)->cm_ave;
- if (i > 0)
- cm_ave_prev = (p + i-1)->cm_ave;
- } else {
- cm_ave_cur = (p + i)->cm_ave_exclude_edge;
- cm_min_cur = (p + i)->cm_min_exclude_edge;
- cm_max_cur = (p + i)->cm_max_exclude_edge;
- if (i < (col_num-1))
- cm_ave_next =
- (p + i+1)->cm_ave_exclude_edge;
- if (i > 0)
- cm_ave_prev =
- (p + i-1)->cm_ave_exclude_edge;
- }
- if (cm_ave_cur == 0)
- cm_ave_cur = 1;
- /*multiple 1000 to increate accuracy*/
- if ((i == 0) || (i == (col_num - 1)))
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur) * 1000 /
- cm_ave_cur;
- else if (i == 1)
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur +
- ABS(cm_ave_cur - cm_ave_next))
- * 1000 / cm_ave_cur;
- else
- (p + i)->gradient_val =
- (cm_max_cur - cm_min_cur +
- ABS(cm_ave_cur - cm_ave_prev))
- * 1000 / cm_ave_cur;
- }
- }
- }
- static void fill_gd_sensor_table(struct gd_sensor *head, int32_t index,
- int32_t cm_max, int32_t cm_min, int32_t cm_ave,
- int32_t cm_max_exclude_edge, int32_t cm_min_exclude_edge,
- int32_t cm_ave_exclude_edge)
- {
- (head + index)->cm_max = cm_max;
- (head + index)->cm_min = cm_min;
- (head + index)->cm_ave = cm_ave;
- (head + index)->cm_ave_exclude_edge = cm_ave_exclude_edge;
- (head + index)->cm_max_exclude_edge = cm_max_exclude_edge;
- (head + index)->cm_min_exclude_edge = cm_min_exclude_edge;
- }
- static void calculate_gd_info(struct gd_sensor *gd_sensor_col,
- struct gd_sensor *gd_sensor_row, int tx_num, int rx_num,
- int32_t *cm_sensor_data, int cm_excluding_row_edge,
- int cm_excluding_col_edge)
- {
- int32_t cm_max;
- int32_t cm_min;
- int32_t cm_ave;
- int32_t cm_max_exclude_edge;
- int32_t cm_min_exclude_edge;
- int32_t cm_ave_exclude_edge;
- int32_t cm_data;
- int i;
- int j;
- /*calculate all the gradient related info for column*/
- for (i = 0; i < tx_num; i++) {
- /*re-initialize for a new col*/
- cm_max = cm_sensor_data[i * rx_num];
- cm_min = cm_max;
- cm_ave = 0;
- cm_max_exclude_edge = cm_sensor_data[i * rx_num + 1];
- cm_min_exclude_edge = cm_max_exclude_edge;
- cm_ave_exclude_edge = 0;
- for (j = 0; j < rx_num; j++) {
- cm_data = cm_sensor_data[i * rx_num + j];
- if (cm_data > cm_max)
- cm_max = cm_data;
- if (cm_data < cm_min)
- cm_min = cm_data;
- cm_ave += cm_data;
- /*calculate exclude edge data*/
- if ((j > 0) && (j < (rx_num-1))) {
- if (cm_data > cm_max_exclude_edge)
- cm_max_exclude_edge = cm_data;
- if (cm_data < cm_min_exclude_edge)
- cm_min_exclude_edge = cm_data;
- cm_ave_exclude_edge += cm_data;
- }
- }
- cm_ave /= rx_num;
- cm_ave_exclude_edge /= (rx_num-2);
- fill_gd_sensor_table(gd_sensor_col, i, cm_max, cm_min, cm_ave,
- cm_max_exclude_edge, cm_min_exclude_edge, cm_ave_exclude_edge);
- }
- calculate_gradient_col(gd_sensor_col, tx_num, cm_excluding_row_edge,
- cm_excluding_col_edge);
- /*calculate all the gradient related info for row*/
- for (j = 0; j < rx_num; j++) {
- /*re-initialize for a new row*/
- cm_max = cm_sensor_data[j];
- cm_min = cm_max;
- cm_ave = 0;
- cm_max_exclude_edge = cm_sensor_data[rx_num + j];
- cm_min_exclude_edge = cm_max_exclude_edge;
- cm_ave_exclude_edge = 0;
- for (i = 0; i < tx_num; i++) {
- cm_data = cm_sensor_data[i * rx_num + j];
- if (cm_data > cm_max)
- cm_max = cm_data;
- if (cm_data < cm_min)
- cm_min = cm_data;
- cm_ave += cm_data;
- /*calculate exclude edge data*/
- if ((i > 0) && (i < (tx_num-1))) {
- if (cm_data > cm_max_exclude_edge)
- cm_max_exclude_edge = cm_data;
- if (cm_data < cm_min_exclude_edge)
- cm_min_exclude_edge = cm_data;
- cm_ave_exclude_edge += cm_data;
- }
- }
- cm_ave /= tx_num;
- cm_ave_exclude_edge /= (tx_num-2);
- fill_gd_sensor_table(gd_sensor_row, j, cm_max, cm_min, cm_ave,
- cm_max_exclude_edge, cm_min_exclude_edge, cm_ave_exclude_edge);
- }
- calculate_gradient_row(gd_sensor_row, rx_num, cm_excluding_row_edge,
- cm_excluding_col_edge);
- }
- static int cyttsp5_get_cmcp_info(struct cyttsp5_device_access_data *dad,
- struct cmcp_data *cmcp_info)
- {
- struct device *dev;
- int32_t *cm_data_panel = cmcp_info->cm_data_panel;
- int32_t *cp_tx_data_panel = cmcp_info->cp_tx_data_panel;
- int32_t *cp_rx_data_panel = cmcp_info->cp_rx_data_panel;
- int32_t *cp_tx_cal_data_panel = cmcp_info->cp_tx_cal_data_panel;
- int32_t *cp_rx_cal_data_panel = cmcp_info->cp_rx_cal_data_panel;
- int32_t *cm_btn_data = cmcp_info->cm_btn_data;
- int32_t *cp_btn_data = cmcp_info->cp_btn_data;
- struct gd_sensor *gd_sensor_col = cmcp_info->gd_sensor_col;
- struct gd_sensor *gd_sensor_row = cmcp_info->gd_sensor_row;
- struct result *result = dad->result;
- int32_t cp_btn_cal = 0;
- int32_t cm_btn_cal = 0;
- int32_t cp_btn_ave = 0;
- int32_t cm_ave_data_panel = 0;
- int32_t cm_ave_data_btn = 0;
- int32_t cm_delta_data_btn = 0;
- int32_t cp_tx_ave_data_panel = 0;
- int32_t cp_rx_ave_data_panel = 0;
- u8 tmp_buf[3];
- int tx_num;
- int rx_num;
- int btn_num;
- int rc = 0;
- int i;
- dev = dad->dev;
- cmcp_info->tx_num = dad->si->sensing_conf_data.tx_num;
- cmcp_info->rx_num = dad->si->sensing_conf_data.rx_num;
- cmcp_info->btn_num = dad->si->num_btns;
- tx_num = cmcp_info->tx_num;
- rx_num = cmcp_info->rx_num;
- btn_num = cmcp_info->btn_num;
- parade_debug(dev, DEBUG_LEVEL_2, "%s tx_num=%d", __func__, tx_num);
- parade_debug(dev, DEBUG_LEVEL_2, "%s rx_num=%d", __func__, rx_num);
- parade_debug(dev, DEBUG_LEVEL_2, "%s btn_num=%d", __func__, btn_num);
- /*short test*/
- result->short_test_pass = true;
- rc = cyttsp5_run_and_get_selftest_result_noprint(
- dev, tmp_buf, sizeof(tmp_buf),
- CY_ST_ID_AUTOSHORTS, PIP_CMD_MAX_LENGTH, false);
- if (rc) {
- dev_err(dev, "short test not supported");
- goto exit;
- }
- if (dad->ic_buf[1] != 0)
- result->short_test_pass = false;
- /*Get cm_panel data*/
- rc = cyttsp5_run_and_get_selftest_result_noprint(
- dev, tmp_buf, sizeof(tmp_buf),
- CY_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH, true);
- if (rc) {
- dev_err(dev, "Get CM Panel not supported");
- goto exit;
- }
- if (cm_data_panel != NULL) {
- for (i = 0; i < tx_num * rx_num; i++) {
- cm_data_panel[i] =
- 10*(dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2] + 256
- * dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2+1]);
- parade_debug(dev, DEBUG_LEVEL_2,
- "cm_data_panel[%d]=%d\n",
- i, cm_data_panel[i]);
- cm_ave_data_panel += cm_data_panel[i];
- }
- cm_ave_data_panel /= (tx_num * rx_num);
- cmcp_info->cm_ave_data_panel = cm_ave_data_panel;
- cmcp_info->cm_cal_data_panel =
- 10*(dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2]
- +256 * dad->ic_buf[CM_PANEL_DATA_OFFSET+i*2+1]);
- /*multiple 1000 to increate accuracy*/
- cmcp_info->cm_sensor_delta = ABS((cmcp_info->cm_ave_data_panel -
- cmcp_info->cm_cal_data_panel) * 1000 /
- cmcp_info->cm_ave_data_panel);
- }
- /*calculate gradient panel sensor column/row here*/
- calculate_gd_info(gd_sensor_col, gd_sensor_row, tx_num, rx_num,
- cm_data_panel, 1, 1);
- for (i = 0; i < tx_num; i++) {
- parade_debug(dev, DEBUG_LEVEL_2,
- "i=%d max=%d,min=%d,ave=%d, gradient=%d",
- i, gd_sensor_col[i].cm_max, gd_sensor_col[i].cm_min,
- gd_sensor_col[i].cm_ave, gd_sensor_col[i].gradient_val);
- }
- for (i = 0; i < rx_num; i++) {
- parade_debug(dev, DEBUG_LEVEL_2,
- "i=%d max=%d,min=%d,ave=%d, gradient=%d",
- i, gd_sensor_row[i].cm_max, gd_sensor_row[i].cm_min,
- gd_sensor_row[i].cm_ave, gd_sensor_row[i].gradient_val);
- }
- /*Get cp data*/
- rc = cyttsp5_run_and_get_selftest_result_noprint(
- dev, tmp_buf, sizeof(tmp_buf),
- CY_ST_ID_CP_PANEL, PIP_CMD_MAX_LENGTH, true);
- if (rc) {
- dev_err(dev, "Get CP Panel not supported");
- goto exit;
- }
- /*Get cp_tx_data_panel*/
- if (cp_tx_data_panel != NULL) {
- for (i = 0; i < tx_num; i++) {
- cp_tx_data_panel[i] =
- 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+i*2]
- + 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+i*2+1]);
- parade_debug(dev, DEBUG_LEVEL_2,
- "cp_tx_data_panel[%d]=%d\n",
- i, cp_tx_data_panel[i]);
- cp_tx_ave_data_panel += cp_tx_data_panel[i];
- }
- cp_tx_ave_data_panel /= tx_num;
- cmcp_info->cp_tx_ave_data_panel = cp_tx_ave_data_panel;
- }
- /*Get cp_tx_cal_data_panel*/
- if (cp_tx_cal_data_panel != NULL) {
- for (i = 0; i < tx_num; i++) {
- cp_tx_cal_data_panel[i] =
- 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*2+i*2]
- + 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*2+i*2+1]);
- parade_debug(dev, DEBUG_LEVEL_2, " cp_tx_cal_data_panel[%d]=%d\n",
- i, cp_tx_cal_data_panel[i]);
- }
- }
- /*get cp_sensor_tx_delta,using the first sensor cal value for temp */
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cp_sensor_tx_delta = ABS((cp_tx_cal_data_panel[0]
- - cp_tx_ave_data_panel) * 1000 / cp_tx_ave_data_panel);
- /*Get cp_rx_data_panel*/
- if (cp_rx_data_panel != NULL) {
- for (i = 0; i < rx_num; i++) {
- cp_rx_data_panel[i] =
- 10*(dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+i*2] +
- 256 * dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+i*2+1]);
- parade_debug(dev, DEBUG_LEVEL_2,
- "cp_rx_data_panel[%d]=%d\n", i,
- cp_rx_data_panel[i]);
- cp_rx_ave_data_panel += cp_rx_data_panel[i];
- }
- cp_rx_ave_data_panel /= rx_num;
- cmcp_info->cp_rx_ave_data_panel = cp_rx_ave_data_panel;
- }
- /*Get cp_rx_cal_data_panel*/
- if (cp_rx_cal_data_panel != NULL) {
- for (i = 0; i < rx_num; i++) {
- cp_rx_cal_data_panel[i] =
- 10 * (dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+rx_num*2+i*2] +
- 256 *
- dad->ic_buf[CP_PANEL_DATA_OFFSET+tx_num*4+rx_num*2+i*2+1]);
- parade_debug(dev, DEBUG_LEVEL_2,
- "cp_rx_cal_data_panel[%d]=%d\n", i,
- cp_rx_cal_data_panel[i]);
- }
- }
- /*get cp_sensor_rx_delta,using the first sensor cal value for temp */
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cp_sensor_rx_delta = ABS((cp_rx_cal_data_panel[0]
- - cp_rx_ave_data_panel) * 1000 / cp_rx_ave_data_panel);
- if (btn_num == 0)
- goto skip_button_test;
- /*get cm btn data*/
- rc = cyttsp5_run_and_get_selftest_result_noprint(
- dev, tmp_buf, sizeof(tmp_buf),
- CY_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH, true);
- if (rc) {
- dev_err(dev, "Get CM BTN not supported");
- goto exit;
- }
- if (cm_btn_data != NULL) {
- for (i = 0; i < btn_num; i++) {
- cm_btn_data[i] =
- 10 * (dad->ic_buf[CM_BTN_DATA_OFFSET+i*2] +
- 256 * dad->ic_buf[CM_BTN_DATA_OFFSET+i*2+1]);
- parade_debug(dev, DEBUG_LEVEL_2,
- " cm_btn_data[%d]=%d\n",
- i, cm_btn_data[i]);
- cm_ave_data_btn += cm_btn_data[i];
- }
- cm_ave_data_btn /= btn_num;
- cm_btn_cal = 10*(dad->ic_buf[CM_BTN_DATA_OFFSET+i*2]
- + 256 * dad->ic_buf[CM_BTN_DATA_OFFSET+i*2+1]);
- /*multiple 1000 to increase accuracy*/
- cm_delta_data_btn = ABS((cm_ave_data_btn-cm_btn_cal)
- * 1000 / cm_ave_data_btn);
- parade_debug(dev, DEBUG_LEVEL_2, " cm_btn_cal=%d\n",
- cm_btn_cal);
- cmcp_info->cm_ave_data_btn = cm_ave_data_btn;
- cmcp_info->cm_cal_data_btn = cm_btn_cal;
- cmcp_info->cm_delta_data_btn = cm_delta_data_btn;
- }
- /*get cp btn data*/
- rc = cyttsp5_run_and_get_selftest_result_noprint(
- dev, tmp_buf, sizeof(tmp_buf),
- CY_ST_ID_CP_BUTTON, PIP_CMD_MAX_LENGTH, true);
- if (rc) {
- dev_err(dev, "Get CP BTN not supported");
- goto exit;
- }
- if (cp_btn_data != NULL) {
- for (i = 0; i < btn_num; i++) {
- cp_btn_data[i] =
- 10 * (dad->ic_buf[CP_BTN_DATA_OFFSET+i*2] +
- 256 * dad->ic_buf[CP_BTN_DATA_OFFSET+i*2+1]);
- cp_btn_ave += cp_btn_data[i];
- parade_debug(dev, DEBUG_LEVEL_2,
- "cp_btn_data[%d]=%d\n",
- i, cp_btn_data[i]);
- }
- cp_btn_ave /= btn_num;
- cp_btn_cal = 10*(dad->ic_buf[CP_BTN_DATA_OFFSET+i*2]
- + 256 * dad->ic_buf[CP_BTN_DATA_OFFSET+i*2+1]);
- cmcp_info->cp_button_ave = cp_btn_ave;
- cmcp_info->cp_btn_cal = cp_btn_cal;
- /*multiple 1000 to increase accuracy*/
- cmcp_info->cp_button_delta = ABS((cp_btn_cal
- - cp_btn_ave) * 1000 / cp_btn_ave);
- parade_debug(dev, DEBUG_LEVEL_2, " cp_btn_cal=%d\n",
- cp_btn_cal);
- parade_debug(dev, DEBUG_LEVEL_2, " cp_btn_ave=%d\n",
- cp_btn_ave);
- }
- skip_button_test:
- exit:
- return rc;
- }
- static void cyttsp5_free_cmcp_buf(struct cmcp_data *cmcp_info)
- {
- if (cmcp_info->gd_sensor_col != NULL)
- kfree(cmcp_info->gd_sensor_col);
- if (cmcp_info->gd_sensor_row != NULL)
- kfree(cmcp_info->gd_sensor_row);
- if (cmcp_info->cm_data_panel != NULL)
- kfree(cmcp_info->cm_data_panel);
- if (cmcp_info->cp_tx_data_panel != NULL)
- kfree(cmcp_info->cp_tx_data_panel);
- if (cmcp_info->cp_rx_data_panel != NULL)
- kfree(cmcp_info->cp_rx_data_panel);
- if (cmcp_info->cp_tx_cal_data_panel != NULL)
- kfree(cmcp_info->cp_tx_cal_data_panel);
- if (cmcp_info->cp_rx_cal_data_panel != NULL)
- kfree(cmcp_info->cp_rx_cal_data_panel);
- if (cmcp_info->cm_btn_data != NULL)
- kfree(cmcp_info->cm_btn_data);
- if (cmcp_info->cp_btn_data != NULL)
- kfree(cmcp_info->cp_btn_data);
- if (cmcp_info->cm_sensor_column_delta != NULL)
- kfree(cmcp_info->cm_sensor_column_delta);
- if (cmcp_info->cm_sensor_row_delta != NULL)
- kfree(cmcp_info->cm_sensor_row_delta);
- }
- static int cyttsp5_cmcp_get_test_item(int item_input)
- {
- int test_item = 0;
- switch (item_input) {
- case CMCP_FULL:
- test_item = CMCP_FULL_CASE;
- break;
- case CMCP_CM_PANEL:
- test_item = CM_PANEL;
- break;
- case CMCP_CP_PANEL:
- test_item = CP_PANEL;
- break;
- case CMCP_CM_BTN:
- test_item = CM_BTN;
- break;
- case CMCP_CP_BTN:
- test_item = CP_BTN;
- break;
- }
- return test_item;
- }
- static ssize_t cyttsp5_cmcp_test_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- struct cmcp_data *cmcp_info = dad->cmcp_info;
- struct result *result = dad->result;
- struct configuration *configuration = dad->configs;
- bool final_pass = true;
- static const char * const cmcp_test_case_array[] = {"Full Cm/Cp test",
- "Cm panel test", "Cp panel test",
- "Cm button test", "Cp button test"};
- int index = 0;
- int test_item = 0;
- int no_builtin_file = 0;
- int rc;
- u8 status;
- int self_test_id_supported = 0;
- dev = dad->dev;
- if ((configuration == NULL) || (cmcp_info == NULL))
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- if (dad->cmcp_test_in_progress) {
- mutex_unlock(&dad->sysfs_lock);
- goto cmcp_not_ready;
- }
- dad->cmcp_test_in_progress = 1;
- dad->test_executed = 0;
- test_item = cyttsp5_cmcp_get_test_item(dad->cmcp_test_items);
- if (dad->builtin_cmcp_threshold_status < 0) {
- dev_err(dev, "%s: No cmcp threshold file.\n", __func__);
- no_builtin_file = 1;
- mutex_unlock(&dad->sysfs_lock);
- goto start_testing;
- }
- if (dad->cmcp_test_items < 0) {
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Invalid test item! Should be 0~4!\n", __func__);
- mutex_unlock(&dad->sysfs_lock);
- goto invalid_item;
- }
- parade_debug(dev, DEBUG_LEVEL_2, "%s: Test item is %s, %d\n",
- __func__, cmcp_test_case_array[dad->cmcp_test_items],
- test_item);
- if ((dad->si->num_btns == 0)
- && ((dad->cmcp_test_items == CMCP_CM_BTN)
- || (dad->cmcp_test_items == CMCP_CP_BTN))) {
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: FW doesn't support button!\n", __func__);
- mutex_unlock(&dad->sysfs_lock);
- goto invalid_item_btn;
- }
- mutex_unlock(&dad->sysfs_lock);
- if (cmcp_check_config_fw_match(dev, configuration))
- goto mismatch;
- start_testing:
- parade_debug(dev, DEBUG_LEVEL_2, "%s: Start Cm/Cp test!\n", __func__);
- result->cm_test_pass = true;
- result->cp_test_pass = true;
- /*stop watchdog*/
- rc = cmd->request_stop_wd(dev);
- if (rc)
- dev_err(dev, "stop watchdog failed");
- /*force single tx*/
- rc = cmd->nonhid_cmd->set_param(dev, 0, 0x1F, 1, 1);
- if (rc)
- dev_err(dev, "force single tx failed");
- /*suspend_scanning */
- rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
- if (rc)
- dev_err(dev, "suspend_scanning failed");
- /*do calibration*/
- if (!dad->cmcp_force_calibrate) {
- parade_debug(dev, DEBUG_LEVEL_2, "do calibration in single tx mode");
- rc = _cyttsp5_calibrate_idacs_cmd(dev, 0, &status);
- if (rc < 0) {
- dev_err(dev, "%s: Error on calibrate idacs for mutual r=%d\n",
- __func__, rc);
- }
- rc = _cyttsp5_calibrate_idacs_cmd(dev, 1, &status);
- if (rc < 0) {
- dev_err(dev, "%s: Error on calibrate idacs for buttons r=%d\n",
- __func__, rc);
- }
- rc = _cyttsp5_calibrate_idacs_cmd(dev, 2, &status);
- if (rc < 0) {
- dev_err(dev, "%s: Error on calibrate idacs for self r=%d\n",
- __func__, rc);
- }
- }
- /*resume_scanning */
- rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
- if (rc)
- dev_err(dev, "resume_scanning failed");
- /*get all cmcp data from FW*/
- self_test_id_supported =
- cyttsp5_get_cmcp_info(dad, cmcp_info);
- if (self_test_id_supported)
- dev_err(dev, "cyttsp5_get_cmcp_info failed");
- /*restore to multi tx*/
- rc = cmd->nonhid_cmd->set_param(dev, 0, 0x1F, 0, 1);
- if (rc)
- dev_err(dev, "restore multi tx failed");
- /*suspend_scanning */
- rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
- if (rc)
- dev_err(dev, "suspend_scanning failed");
- /*do calibration*/
- if (!dad->cmcp_force_calibrate) {
- parade_debug(dev, DEBUG_LEVEL_2, "do calibration in multi tx mode");
- rc = _cyttsp5_calibrate_idacs_cmd(dev, 0, &status);
- if (rc < 0) {
- dev_err(dev, "%s: Error on calibrate idacs for mutual r=%d\n",
- __func__, rc);
- }
- rc = _cyttsp5_calibrate_idacs_cmd(dev, 1, &status);
- if (rc < 0) {
- dev_err(dev, "%s: Error on calibrate idacs for buttons r=%d\n",
- __func__, rc);
- }
- rc = _cyttsp5_calibrate_idacs_cmd(dev, 2, &status);
- if (rc < 0) {
- dev_err(dev, "%s: Error on calibrate idacs for self r=%d\n",
- __func__, rc);
- }
- }
- /*resume_scanning */
- rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
- if (rc)
- dev_err(dev, "resume_scanning failed");
- /*start watchdog*/
- rc = cmd->request_start_wd(dev);
- if (rc)
- dev_err(dev, "start watchdog failed");
- if (self_test_id_supported)
- goto self_test_id_failed;
- if (no_builtin_file)
- goto no_builtin;
- if (test_item && CM_ENABLED)
- validate_cm_test_results(dev, configuration, cmcp_info,
- result, &final_pass, test_item);
- if (test_item && CP_ENABLED)
- validate_cp_test_results(dev, configuration, cmcp_info,
- result, &final_pass, test_item);
- no_builtin:
- if ((dad->cmcp_test_items == CMCP_FULL)
- && (dad->cmcp_range_check == 0)) {
- /*full test and full check*/
- result->test_summary =
- result->cm_test_pass
- && result->cp_test_pass
- && result->short_test_pass;
- } else if ((dad->cmcp_test_items == CMCP_FULL)
- && (dad->cmcp_range_check == 1)) {
- /*full test and basic check*/
- result->test_summary =
- result->cm_sensor_gd_col_pass
- && result->cm_sensor_gd_row_pass
- && result->cm_sensor_validation_pass
- && result->cp_rx_validation_pass
- && result->cp_tx_validation_pass
- && result->short_test_pass;
- } else if (dad->cmcp_test_items == CMCP_CM_PANEL) {
- /*cm panel test result only*/
- result->test_summary =
- result->cm_sensor_gd_col_pass
- && result->cm_sensor_gd_row_pass
- && result->cm_sensor_validation_pass
- && result->cm_sensor_row_delta_pass
- && result->cm_sensor_col_delta_pass
- && result->cm_sensor_calibration_pass
- && result->cm_sensor_delta_pass;
- } else if (dad->cmcp_test_items == CMCP_CP_PANEL) {
- /*cp panel test result only*/
- result->test_summary =
- result->cp_sensor_delta_pass
- && result->cp_rx_validation_pass
- && result->cp_tx_validation_pass;
- } else if (dad->cmcp_test_items == CMCP_CM_BTN) {
- /*cm button test result only*/
- result->test_summary =
- result->cm_button_validation_pass
- && result->cm_button_delta_pass;
- } else if (dad->cmcp_test_items == CMCP_CP_BTN) {
- /*cp button test result only*/
- result->test_summary =
- result->cp_button_delta_pass
- && result->cp_button_average_pass
- && result->cp_button_validation_pass;
- }
- mutex_lock(&dad->sysfs_lock);
- dad->test_executed = 1;
- mutex_unlock(&dad->sysfs_lock);
- if (result->test_summary) {
- dev_vdbg(dev, "%s: Finish Cm/Cp test! All Test Passed\n",
- __func__);
- index = snprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status 1\n");
- } else {
- dev_vdbg(dev, "%s: Finish Cm/Cp test! Range Check Failure\n",
- __func__);
- index = snprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status 6\n");
- }
- goto cmcp_ready;
- mismatch:
- index = snprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status 2\nInput cmcp threshold file mismatches with FW\n");
- goto cmcp_ready;
- invalid_item_btn:
- index = snprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status 3\nFW doesn't support button!\n");
- goto cmcp_ready;
- invalid_item:
- index = snprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status 4\nWrong test item or range check input!\nOnly support below items:\n0 - Cm/Cp Panel & Button with Gradient (Typical)\n1 - Cm Panel with Gradient\n2 - Cp Panel\n3 - Cm Button\n4 - Cp Button\nOnly support below range check:\n0 - Full Range Checking (default)\n1 - Basic Range Checking(TSG5 style)\n");
- goto cmcp_ready;
- self_test_id_failed:
- index = snprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status 5\nget self test ID not supported!");
- goto cmcp_ready;
- cmcp_not_ready:
- index = snprintf(buf, CY_MAX_PRBUF_SIZE,
- "Status 0\n");
- goto cmcp_ready;
- cmcp_ready:
- mutex_lock(&dad->sysfs_lock);
- dad->cmcp_test_in_progress = 0;
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return index;
- }
- static ssize_t cyttsp5_cmcp_test_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- u8 test_item = 0;
- u8 range_check = 0;
- u8 force_calibrate = 0;
- int ret;
- static const char * const cmcp_test_case_array[] = {"Full Cm/Cp test",
- "Cm panel test", "Cp panel test",
- "Cm button test", "Cp button test"};
- static const char * const cmcp_test_range_check_array[] = {
- "Full (default)", "Basic"};
- static const char * const cmcp_test_force_cal_array[] = {
- "Calibrate When Testing (default)", "No Calibration"};
- ssize_t length = 0;
- pm_runtime_get_sync(dev);
- mutex_lock(&dad->sysfs_lock);
- length = cyttsp5_ic_parse_input(dev, buf, size, dad->ic_buf,
- CY_MAX_PRBUF_SIZE);
- if (length <= 0 || length > 3) {
- dev_err(dev, "%s: Input format error!\n", __func__);
- dad->cmcp_test_items = -EINVAL;
- ret = -EINVAL;
- goto error;
- }
- /* Get test item */
- test_item = dad->ic_buf[0];
- /* Get range check */
- if (length >= 2)
- range_check = dad->ic_buf[1];
- /* Get force calibration */
- if (length == 3)
- force_calibrate = dad->ic_buf[2];
- /*
- * Test item limitation:
- * 0: Perform all Tests
- * 1: CM Panel with Gradient
- * 2: CP Panel
- * 3: CM Button
- * 4: CP Button
- * Ranage check limitation:
- * 0: full check
- * 1: basic check
- * Force calibrate limitation:
- * 0: do calibration
- * 1: don't do calibration
- */
- if ((test_item < 0) || (test_item > 4) || (range_check > 1)
- || (force_calibrate > 1)) {
- dev_err(dev,
- "%s: Test item should be 0~4; Range check should be 0~1; Force calibrate should be 0~1\n",
- __func__);
- dad->cmcp_test_items = -EINVAL;
- ret = -EINVAL;
- goto error;
- }
- /*
- * If it is not all Test, then range_check should be 0
- * because other test does not has concept of basic check
- */
- if (test_item > 0 && test_item < 5)
- range_check = 0;
- dad->cmcp_test_items = test_item;
- dad->cmcp_range_check = range_check;
- dad->cmcp_force_calibrate = force_calibrate;
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Test item is %s; Range check is %s; Force calibrate is %s.\n",
- __func__,
- cmcp_test_case_array[test_item],
- cmcp_test_range_check_array[range_check],
- cmcp_test_force_cal_array[force_calibrate]);
- error:
- mutex_unlock(&dad->sysfs_lock);
- pm_runtime_put(dev);
- if (ret)
- return ret;
- return size;
- }
- static DEVICE_ATTR(cmcp_test, S_IRUSR | S_IWUSR,
- cyttsp5_cmcp_test_show, cyttsp5_cmcp_test_store);
- int prepare_print_string(char *out_buf, char *in_buf, int index)
- {
- if ((out_buf == NULL) || (in_buf == NULL))
- return index;
- index += scnprintf(&out_buf[index], MAX_BUF_LEN - index,
- "%s", in_buf);
- return index;
- }
- int prepare_print_data(char *out_buf, int32_t *in_buf, int index, int data_num)
- {
- int i;
- if ((out_buf == NULL) || (in_buf == NULL))
- return index;
- for (i = 0; i < data_num; i++)
- index += scnprintf(&out_buf[index], MAX_BUF_LEN - index,
- "%d,", in_buf[i]);
- return index;
- }
- int save_header(char *out_buf, int index, struct result *result)
- {
- struct timex txc;
- struct rtc_time tm;
- char time_buf[100] = {0};
- do_gettimeofday(&(txc.time));
- rtc_time_to_tm(txc.time.tv_sec, &tm);
- scnprintf(time_buf, 100, "%d/%d/%d,TIME,%d:%d:%d,", tm.tm_year+1900,
- tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
- index = prepare_print_string(out_buf, ",.header,\n", index);
- index = prepare_print_string(out_buf, ",DATE,", index);
- index = prepare_print_string(out_buf, &time_buf[0], index);
- index = prepare_print_string(out_buf, ",\n", index);
- index = prepare_print_string(out_buf, ",SW_VERSION,", index);
- index = prepare_print_string(out_buf, CY_DRIVER_VERSION, index);
- index = prepare_print_string(out_buf, ",\n", index);
- index = prepare_print_string(out_buf, ",.end,\n", index);
- index = prepare_print_string(out_buf, ",.engineering data,\n", index);
- return index;
- }
- static int print_silicon_id(char *out_buf, char *in_buf, int index)
- {
- index = prepare_print_string(out_buf, ",1,", index);
- index = prepare_print_string(out_buf, &in_buf[0], index);
- return index;
- }
- int save_engineering_data(struct device *dev, char *out_buf, int index,
- struct cmcp_data *cmcp_info, struct configuration *configuration,
- struct result *result, int test_item, int no_builtin_file)
- {
- int i;
- int j;
- int tx_num = cmcp_info->tx_num;
- int rx_num = cmcp_info->rx_num;
- int btn_num = cmcp_info->btn_num;
- int tmp = 0;
- uint32_t fw_revision_control;
- uint32_t fw_config_ver;
- char device_id[20] = {0};
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- fw_revision_control = dad->si->cydata.revctrl;
- fw_config_ver = dad->si->cydata.fw_ver_conf;
- /*calculate silicon id*/
- result->device_id_low = 0;
- result->device_id_high = 0;
- for (i = 0; i < 4; i++)
- result->device_id_low =
- (result->device_id_low << 8) + dad->si->cydata.mfg_id[i];
- for (i = 4; i < 8; i++)
- result->device_id_high =
- (result->device_id_high << 8) + dad->si->cydata.mfg_id[i];
- scnprintf(device_id, 20, "%x%x",
- result->device_id_high, result->device_id_low);
- /*print test summary*/
- index = print_silicon_id(out_buf, &device_id[0], index);
- if (result->test_summary)
- index = prepare_print_string(out_buf, ",PASS,\n", index);
- else
- index = prepare_print_string(out_buf, ",FAIL,\n", index);
- /*revision ctrl number*/
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf, ",FW revision Control,", index);
- index = prepare_print_data(out_buf, &fw_revision_control, index, 1);
- index = prepare_print_string(out_buf, "\n", index);
- /*config version*/
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf, ",CONFIG_VER,", index);
- index = prepare_print_data(out_buf, &fw_config_ver, index, 1);
- index = prepare_print_string(out_buf, "\n", index);
- /*short test*/
- index = print_silicon_id(out_buf, &device_id[0], index);
- if (result->short_test_pass)
- index = prepare_print_string(out_buf, ",Shorts,PASS,\n", index);
- else
- index = prepare_print_string(out_buf, ",Shorts,FAIL,\n", index);
- if ((test_item & CM_ENABLED) == CM_ENABLED) {
- /*print BUTNS_CM_DATA_ROW00*/
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,BUTNS_CM_DATA_ROW00,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_btn_data[0],
- index,
- btn_num);
- index = prepare_print_string(out_buf, "\n", index);
- }
- if ((test_item & CM_PANEL) == CM_PANEL) {
- /*print CM_DATA_ROW*/
- for (i = 0; i < rx_num; i++) {
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,CM_DATA_ROW",
- index);
- index = prepare_print_data(out_buf, &i,
- index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_data_panel[j*rx_num+i],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- if (!no_builtin_file) {
- /*print CM_MAX_GRADIENT_COLS_PERCENT*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,CM_MAX_GRADIENT_COLS_PERCENT,",
- index);
- for (i = 0; i < tx_num; i++) {
- char tmp_buf[10] = {0};
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->gd_sensor_col[i].gradient_val / 10,
- cmcp_info->gd_sensor_col[i].gradient_val % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print CM_MAX_GRADIENT_ROWS_PERCENT*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,CM_MAX_GRADIENT_ROWS_PERCENT,",
- index);
- for (i = 0; i < rx_num; i++) {
- char tmp_buf[10] = {0};
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->gd_sensor_row[i].gradient_val / 10,
- cmcp_info->gd_sensor_row[i].gradient_val % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- if (!dad->cmcp_range_check) {
- /*print CM_DELTA_COLUMN*/
- for (i = 0; i < rx_num; i++) {
- index = print_silicon_id(
- out_buf,
- &device_id[0], index);
- index = prepare_print_string(
- out_buf,
- ",Sensor Cm Validation,DELTA_COLUMNS_ROW",
- index);
- index = prepare_print_data(
- out_buf,
- &i, index, 1);
- index = prepare_print_data(
- out_buf,
- &tmp, index, 1);
- for (j = 1; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &cmcp_info->cm_sensor_column_delta[(j-1)*rx_num+i],
- index, 1);
- index = prepare_print_string(
- out_buf,
- "\n", index);
- }
- /*print CM_DELTA_ROW*/
- index = print_silicon_id(out_buf,
- &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,DELTA_ROWS_ROW",
- index);
- index = prepare_print_data(out_buf,
- &tmp, index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &tmp, index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- for (i = 1; i < rx_num; i++) {
- index = print_silicon_id(
- out_buf,
- &device_id[0],
- index);
- index = prepare_print_string(
- out_buf,
- ",Sensor Cm Validation,DELTA_ROWS_ROW",
- index);
- index = prepare_print_data(
- out_buf, &i,
- index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &cmcp_info->cm_sensor_row_delta[j*rx_num+i-1],
- index, 1);
- index = prepare_print_string(
- out_buf,
- "\n", index);
- }
- /*print pass/fail Sensor Cm Validation*/
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- if (result->cm_test_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,PASS,\n",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,FAIL,\n",
- index);
- }
- }
- }
- if (!no_builtin_file) {
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)
- && (!dad->cmcp_range_check)) {
- char tmp_buf[10] = {0};
- /*print Button Element by Element */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- if (result->cm_button_validation_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Button Element by Element,PASS\n",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Button Element by Element,FAIL\n",
- index);
- /*
- *print Sensor Cm Validation
- *- Buttons Range Buttons Range
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,Buttons Range,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cm_delta_data_btn / 10,
- cmcp_info->cm_delta_data_btn % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation
- *-Buttons Range Cm_button_avg
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,Cm_button_avg,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_ave_data_btn,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation
- * -Buttons Range Cm_button_avg
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,Cm_button_cal,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_cal_data_btn,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation
- *-Buttons Range pass/fail
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_button_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Buttons Range,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_delta_button_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- if ((test_item & CM_PANEL) == CM_PANEL &&
- !dad->cmcp_range_check) {
- char tmp_buf[10] = {0};
- /*print Cm_sensor_cal */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Calibration,Cm_sensor_cal,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_cal_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm_sensor_cal limit*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_calibration_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Calibration,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Calibration,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_min_limit_cal,
- index, 1);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_limit_cal,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Columns Delta Matrix*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_col_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Columns Delta Matrix,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Columns Delta Matrix,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_range_limit_col,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm Validation - Element by Element*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_validation_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Element by Element,PASS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Element by Element,FAIL,",
- index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm Validation -Gradient Cols*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_gd_col_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Cols,PASS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Cols,FAIL,",
- index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm Validation -Gradient Rows*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_gd_row_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Rows,PASS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Gradient Rows,FAIL,",
- index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*
- * Print Sensor Cm Validation
- * -Rows Delta Matrix
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_row_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Rows Delta Matrix,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Rows Delta Matrix,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_range_limit_row,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cm_sensor_avg */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,Cm_sensor_avg,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cm_ave_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*printSensor Cm Validation -
- * Sensor Range, Sensor Range
- */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,Sensor Range,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cm_sensor_delta / 10,
- cmcp_info->cm_sensor_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Sensor Cm Validation - Sensor Range*/
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- if (result->cm_sensor_delta_pass)
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,PASS,LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation - Sensor Range,FAIL,LIMITS,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_delta_sensor_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- }
- if ((test_item & CP_ENABLED) == CP_ENABLED) {
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
- /*print BUTNS_CP_DATA_ROW00 */
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,BUTNS_CP_DATA_ROW00,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_btn_data[0],
- index, btn_num);
- index = prepare_print_string(out_buf,
- "\n", index);
- if (!no_builtin_file && !dad->cmcp_range_check) {
- /*print Cp Button Element by Element */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- if (result->cp_button_validation_pass)
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check - Button Element by Element,PASS\n",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check - Button Element by Element,FAIL\n",
- index);
- /*print cp_button_ave */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_button_avg,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_button_ave,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_button_cal */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_button_cal,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_btn_cal,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if ((test_item & CP_PANEL) == CP_PANEL) {
- /*print CP_DATA_RX */
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,CP_DATA_RX,", index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_rx_data_panel[0], index, rx_num);
- index = prepare_print_string(out_buf, "\n", index);
- /*print CP_DATA_TX */
- index = print_silicon_id(out_buf, &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,CP_DATA_TX,", index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_tx_data_panel[0], index, tx_num);
- index = prepare_print_string(out_buf, "\n", index);
- }
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)
- && !dad->cmcp_range_check) {
- if (!no_builtin_file) {
- char tmp_buf[10] = {0};
- /*print Cp_delta_button */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_delta_button,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cp_button_delta / 10,
- cmcp_info->cp_button_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf, "\n",
- index);
- }
- }
- if ((test_item & CP_PANEL) == CP_PANEL &&
- !dad->cmcp_range_check) {
- if (!no_builtin_file) {
- char tmp_buf[10] = {0};
- /*print Cp_delta_rx */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_delta_rx,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cp_sensor_rx_delta / 10,
- cmcp_info->cp_sensor_rx_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf, "\n",
- index);
- /*print Cp_delta_tx */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_delta_tx,",
- index);
- scnprintf(tmp_buf, 10, "%d.%d,",
- cmcp_info->cp_sensor_tx_delta / 10,
- cmcp_info->cp_sensor_tx_delta % 10);
- index = prepare_print_string(out_buf,
- &tmp_buf[0], index);
- index = prepare_print_string(out_buf, "\n",
- index);
- /*print Cp_sensor_avg_rx */
- index = print_silicon_id(out_buf, &device_id[0],
- index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_avg_rx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_rx_ave_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_sensor_avg_tx */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_avg_tx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_tx_ave_data_panel,
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_sensor_cal_rx */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_cal_rx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_rx_cal_data_panel[0],
- index, rx_num);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print Cp_sensor_cal_tx */
- index = print_silicon_id(out_buf,
- &device_id[0], index);
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,Cp_sensor_cal_tx,",
- index);
- index = prepare_print_data(out_buf,
- &cmcp_info->cp_tx_cal_data_panel[0],
- index, tx_num);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if (!no_builtin_file && !dad->cmcp_range_check) {
- /*print cp test limits */
- index = print_silicon_id(out_buf, &device_id[0], index);
- if (result->cp_test_pass)
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,PASS, LIMITS,",
- index);
- else
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,FAIL, LIMITS,",
- index);
- index = prepare_print_string(out_buf,
- "CP_MAX_DELTA_SENSOR_RX_PERCENT,", index);
- index = prepare_print_data(out_buf,
- &configuration->cp_max_delta_sensor_rx_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "CP_MAX_DELTA_SENSOR_TX_PERCENT,", index);
- index = prepare_print_data(out_buf,
- &configuration->cp_max_delta_sensor_tx_percent,
- index, 1);
- index = prepare_print_string(out_buf,
- "CP_MAX_DELTA_BUTTON_PERCENT,", index);
- index = prepare_print_data(out_buf,
- &configuration->cp_max_delta_button_percent,
- index, 1);
- index = prepare_print_string(out_buf, "\n", index);
- }
- }
- if (!no_builtin_file) {
- if ((test_item & CM_ENABLED) == CM_ENABLED) {
- if ((test_item & CM_PANEL) == CM_PANEL) {
- /*print columns gradient limit*/
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX_LIMITS,CM_MAX_GRADIENT_COLS_PERCENT,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_table_gradient_cols_percent[0],
- index,
- configuration->cm_max_table_gradient_cols_percent_size);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print rows gradient limit*/
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX_LIMITS,CM_MAX_GRADIENT_ROWS_PERCENT,",
- index);
- index = prepare_print_data(out_buf,
- &configuration->cm_max_table_gradient_rows_percent[0],
- index,
- configuration->cm_max_table_gradient_rows_percent_size);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print cm max limit*/
- for (i = 0; i < rx_num; i++) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX_LIMITS,CM_DATA_ROW",
- index);
- index = prepare_print_data(out_buf,
- &i, index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &configuration->cm_min_max_table_sensor[i*tx_num*2+j*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MAX LIMITS,M_BUTNS,",
- index);
- for (j = 0; j < btn_num; j++) {
- index = prepare_print_data(out_buf,
- &configuration->cm_min_max_table_button[2*j+1],
- index, 1);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation MAX LIMITS\n", index);
- if ((test_item & CM_PANEL) == CM_PANEL) {
- /*print cm min limit*/
- for (i = 0; i < rx_num; i++) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MIN_LIMITS,CM_DATA_ROW",
- index);
- index = prepare_print_data(out_buf, &i,
- index, 1);
- for (j = 0; j < tx_num; j++)
- index = prepare_print_data(
- out_buf,
- &configuration->cm_min_max_table_sensor[i*tx_num*2 + j*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- if (((test_item & CM_BTN) == CM_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation,MIN LIMITS,M_BUTNS,",
- index);
- for (j = 0; j < btn_num; j++) {
- index = prepare_print_data(out_buf,
- &configuration->cm_min_max_table_button[2*j],
- index, 1);
- }
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- index = prepare_print_string(out_buf,
- ",Sensor Cm Validation MIN LIMITS\n", index);
- }
- if ((test_item & CP_ENABLED) == CP_ENABLED) {
- if ((test_item & CP_PANEL) == CP_PANEL) {
- /*print cp tx max limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MAX_LIMITS,TX,",
- index);
- for (i = 0; i < tx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_tx[i*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print cp rx max limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MAX_LIMITS,RX,",
- index);
- for (i = 0; i < rx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_rx[i*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- /*print cp btn max limit*/
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MAX_LIMITS,S_BUTNS,",
- index);
- for (i = 0; i < btn_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_button[i*2+1],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- if ((test_item & CP_PANEL) == CP_PANEL) {
- /*print cp tx min limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MIN_LIMITS,TX,",
- index);
- for (i = 0; i < tx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_tx[i*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- /*print cp rx min limit*/
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MIN_LIMITS,RX,",
- index);
- for (i = 0; i < rx_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_rx[i*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- /*print cp btn min limit*/
- if (((test_item & CP_BTN) == CP_BTN) && (btn_num > 0)) {
- index = prepare_print_string(out_buf,
- ",Self-cap Calibration Check,MIN_LIMITS,S_BUTNS,",
- index);
- for (i = 0; i < btn_num; i++)
- index = prepare_print_data(out_buf,
- &configuration->cp_min_max_table_button[i*2],
- index, 1);
- index = prepare_print_string(out_buf,
- "\n", index);
- }
- }
- }
- return index;
- }
- int result_save(struct device *dev, char *buf,
- struct configuration *configuration, struct result *result,
- struct cmcp_data *cmcp_info, loff_t *ppos, size_t count, int test_item,
- int no_builtin_file)
- {
- u8 *out_buf = NULL;
- int index = 0;
- int byte_left;
- out_buf = kzalloc(MAX_BUF_LEN, GFP_KERNEL);
- if (configuration == NULL)
- dev_err(dev, "config is NULL");
- if (result == NULL)
- dev_err(dev, "result is NULL");
- if (cmcp_info == NULL)
- dev_err(dev, "cmcp_info is NULL");
- index = save_header(out_buf, index, result);
- index = save_engineering_data(dev, out_buf, index,
- cmcp_info, configuration, result,
- test_item, no_builtin_file);
- byte_left = simple_read_from_buffer(buf, count, ppos, out_buf, index);
- kfree(out_buf);
- return byte_left;
- }
- static int cmcp_results_debugfs_open(struct inode *inode,
- struct file *filp)
- {
- filp->private_data = inode->i_private;
- return 0;
- }
- static int cmcp_results_debugfs_close(struct inode *inode,
- struct file *filp)
- {
- filp->private_data = NULL;
- return 0;
- }
- static ssize_t cmcp_results_debugfs_read(struct file *filp,
- char __user *buf, size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_data *dad = filp->private_data;
- struct device *dev;
- struct cmcp_data *cmcp_info = dad->cmcp_info;
- struct result *result = dad->result;
- struct configuration *configuration = dad->configs;
- int ret = 0;
- int test_item;
- int no_builtin_file = 0;
- int test_executed = 0;
- dev = dad->dev;
- mutex_lock(&dad->sysfs_lock);
- test_executed = dad->test_executed;
- test_item = cyttsp5_cmcp_get_test_item(dad->cmcp_test_items);
- if (dad->builtin_cmcp_threshold_status < 0) {
- dev_err(dev, "%s: No cmcp threshold file.\n", __func__);
- no_builtin_file = 1;
- }
- mutex_unlock(&dad->sysfs_lock);
- if (test_executed)
- /*save result to buf*/
- ret = result_save(dev, buf, configuration, result, cmcp_info,
- ppos, count, test_item, no_builtin_file);
- else {
- char warning_info[] =
- "No test result available!\n";
- dev_err(dev, "%s: No test result available!\n", __func__);
- return simple_read_from_buffer(buf, count, ppos, warning_info,
- strlen(warning_info));
- }
- return ret;
- }
- static const struct file_operations cmcp_results_debugfs_fops = {
- .open = cmcp_results_debugfs_open,
- .release = cmcp_results_debugfs_close,
- .read = cmcp_results_debugfs_read,
- .write = NULL,
- };
- static ssize_t cyttsp5_cmcp_threshold_loading_show(struct device *dev,
- struct device_attribute *attr, char *buf)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- bool cmcp_threshold_loading;
- mutex_lock(&dad->cmcp_threshold_lock);
- cmcp_threshold_loading = dad->cmcp_threshold_loading;
- mutex_unlock(&dad->cmcp_threshold_lock);
- return sprintf(buf, "%d\n", cmcp_threshold_loading);
- }
- /* Return the buffer offset of new test case */
- u32 cmcp_return_offset_of_new_case(const char *bufPtr, u32 first_time)
- {
- static u32 offset, first_search;
- if (first_time == 0) {
- first_search = 0;
- offset = 0;
- }
- if (first_search != 0) {
- /* Search one case */
- for (;;) {
- /* Search ASCII_LF */
- while (*bufPtr++ != ASCII_LF)
- offset++;
- offset++;
- /*
- * Single line: end loop
- * Multiple lines: continue loop
- */
- if (*bufPtr != ASCII_COMMA)
- break;
- }
- } else
- first_search = 1;
- return offset;
- }
- /* Get test case information from cmcp threshold file */
- u32 cmcp_get_case_info_from_threshold_file(struct device *dev, const char *buf,
- struct test_case_search *search_array, u32 file_size)
- {
- u32 case_num = 0, buffer_offset = 0, name_count = 0, first_search = 0;
- parade_debug(dev, DEBUG_LEVEL_2, "%s: Search cmcp threshold file\n",
- __func__);
- /* Get all the test cases */
- for (case_num = 0; case_num < MAX_CASE_NUM; case_num++) {
- buffer_offset =
- cmcp_return_offset_of_new_case(&buf[buffer_offset],
- first_search);
- first_search = 1;
- if (buf[buffer_offset] == 0)
- break;
- for (name_count = 0; name_count < NAME_SIZE_MAX; name_count++) {
- /* File end */
- if (buf[buffer_offset + name_count] == ASCII_COMMA)
- break;
- search_array[case_num].name[name_count] =
- buf[buffer_offset + name_count];
- }
- /* Exit when buffer offset is larger than file size */
- if (buffer_offset >= file_size)
- break;
- search_array[case_num].name_size = name_count;
- search_array[case_num].offset = buffer_offset;
- /*
- * parade_debug(dev, DEBUG_LEVEL_2, "Find case %d: Name is %s;
- * Name size is %d; Case offset is %d\n",
- * case_num,
- * search_array[case_num].name,
- * search_array[case_num].name_size,
- * search_array[case_num].offset);
- */
- }
- return case_num;
- }
- /* Compose one value based on data of each bit */
- int cmcp_compose_data(char *buf, u32 count)
- {
- u32 base_array[] = {1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9};
- int value = 0;
- u32 index = 0;
- for (index = 0; index < count; index++)
- value += buf[index] * base_array[count - 1 - index];
- return value;
- }
- /* Return one value */
- int cmcp_return_one_value(struct device *dev,
- const char *buf, u32 *offset, u32 *line_num)
- {
- int value = -1;
- char tmp_buffer[10];
- u32 count = 0;
- u32 tmp_offset = *offset;
- static u32 line_count = 1;
- /* Bypass extra commas */
- while (buf[tmp_offset] == ASCII_COMMA
- && buf[tmp_offset + 1] == ASCII_COMMA)
- tmp_offset++;
- /* Windows and Linux difference at the end of one line */
- if (buf[tmp_offset] == ASCII_COMMA
- && buf[tmp_offset + 1] == ASCII_CR
- && buf[tmp_offset + 2] == ASCII_LF)
- tmp_offset += 2;
- else if (buf[tmp_offset] == ASCII_COMMA
- && buf[tmp_offset + 1] == ASCII_LF)
- tmp_offset += 1;
- else if (buf[tmp_offset] == ASCII_COMMA
- && buf[tmp_offset + 1] == ASCII_CR)
- tmp_offset += 1;
- /* New line for multiple lines */
- if (buf[tmp_offset] == ASCII_LF && buf[tmp_offset + 1] == ASCII_COMMA) {
- tmp_offset++;
- line_count++;
- /*parade_debug(dev, DEBUG_LEVEL_2, "\n");*/
- }
- /* Beginning */
- if (buf[tmp_offset] == ASCII_COMMA) {
- tmp_offset++;
- for (;;) {
- if ((buf[tmp_offset] >= ASCII_ZERO)
- && (buf[tmp_offset] <= ASCII_NINE)) {
- tmp_buffer[count++] =
- buf[tmp_offset] - ASCII_ZERO;
- tmp_offset++;
- } else {
- if (count != 0) {
- value = cmcp_compose_data(tmp_buffer,
- count);
- /*parade_debug(dev, DEBUG_LEVEL_2, */
- /* ",%d", value);*/
- } else {
- /* 0 indicates no data available */
- value = -1;
- }
- break;
- }
- }
- } else {
- /* Multiple line: line count */
- *line_num = line_count;
- /* Reset for next case */
- line_count = 1;
- }
- *offset = tmp_offset;
- return value;
- }
- /* Get configuration information */
- void cmcp_get_configuration_info(struct device *dev,
- const char *buf, struct test_case_search *search_array,
- u32 case_count, struct test_case_field *field_array,
- struct configuration *config)
- {
- u32 count = 0, sub_count = 0;
- u32 exist_or_not = 0;
- u32 value_offset = 0;
- int retval = 0;
- u32 data_num = 0;
- u32 line_num = 1;
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Fill configuration struct per cmcp threshold file\n",
- __func__);
- /* Search cases */
- for (count = 0; count < MAX_CASE_NUM; count++) {
- exist_or_not = 0;
- for (sub_count = 0; sub_count < case_count; sub_count++) {
- if (!strncmp(field_array[count].name,
- search_array[sub_count].name,
- field_array[count].name_size)) {
- exist_or_not = 1;
- break;
- }
- }
- field_array[count].exist_or_not = exist_or_not;
- /* Clear data number */
- data_num = 0;
- if (exist_or_not == 1) {
- switch (field_array[count].type) {
- case TEST_CASE_TYPE_NO:
- field_array[count].data_num = 0;
- field_array[count].line_num = 1;
- break;
- case TEST_CASE_TYPE_ONE:
- value_offset = search_array[sub_count].offset
- + search_array[sub_count].name_size;
- *field_array[count].bufptr =
- cmcp_return_one_value(dev, buf,
- &value_offset, 0);
- field_array[count].data_num = 1;
- field_array[count].line_num = 1;
- break;
- case TEST_CASE_TYPE_MUL:
- case TEST_CASE_TYPE_MUL_LINES:
- line_num = 1;
- value_offset = search_array[sub_count].offset
- + search_array[sub_count].name_size;
- for (;;) {
- retval = cmcp_return_one_value(dev,
- buf, &value_offset, &line_num);
- if (retval >= 0) {
- *field_array[count].bufptr++ =
- retval;
- data_num++;
- } else
- break;
- }
- field_array[count].data_num = data_num;
- field_array[count].line_num = line_num;
- break;
- default:
- break;
- }
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: %s: Data number is %d, line number is %d\n",
- __func__,
- field_array[count].name,
- field_array[count].data_num,
- field_array[count].line_num);
- } else
- parade_debug(dev, DEBUG_LEVEL_2, "%s: !!! %s doesn't exist\n",
- __func__, field_array[count].name);
- }
- }
- /* Get basic information, like tx, rx, button number */
- void cmcp_get_basic_info(struct device *dev,
- struct test_case_field *field_array, struct configuration *config)
- {
- #define CMCP_DEBUG 0
- u32 tx_num = 0;
- #if CMCP_DEBUG
- u32 index = 0;
- #endif
- config->is_valid_or_not = 1; /* Set to valid by default */
- config->cm_enabled = 0;
- config->cp_enabled = 0;
- if (field_array[CM_TEST_INPUTS].exist_or_not)
- config->cm_enabled = 1;
- if (field_array[CP_TEST_INPUTS].exist_or_not)
- config->cp_enabled = 1;
- /* Get basic information only when CM and CP are enabled */
- if (config->cm_enabled && config->cp_enabled) {
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Find CM and CP thresholds\n", __func__);
- config->rx_num =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num;
- tx_num =
- (field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num >> 1)
- /field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num;
- config->tx_num = tx_num;
- config->btn_num =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_BUTTON].data_num >> 1;
- config->cm_min_max_table_button_size =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_BUTTON].data_num;
- config->cm_min_max_table_sensor_size =
- field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num;
- config->cp_min_max_table_rx_size =
- field_array[PER_ELEMENT_MIN_MAX_RX].data_num;
- config->cp_min_max_table_tx_size =
- field_array[PER_ELEMENT_MIN_MAX_TX].data_num;
- config->cm_max_table_gradient_cols_percent_size =
- field_array[CM_GRADIENT_CHECK_COL].data_num;
- config->cm_max_table_gradient_rows_percent_size =
- field_array[CM_GRADIENT_CHECK_ROW].data_num;
- config->cp_min_max_table_button_size =
- field_array[CP_PER_ELEMENT_MIN_MAX_BUTTON].data_num;
- #if CMCP_DEBUG
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_excluding_col_edge);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_excluding_row_edge);
- for (index = 0;
- index < config->cm_max_table_gradient_cols_percent_size;
- index++)
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_max_table_gradient_cols_percent[index]);
- for (index = 0;
- index < config->cm_max_table_gradient_rows_percent_size;
- index++)
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_max_table_gradient_rows_percent[index]);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_range_limit_row);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_range_limit_col);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_min_limit_cal);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_max_limit_cal);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_max_delta_sensor_percent);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_max_delta_button_percent);
- for (index = 0;
- index < config->cm_min_max_table_button_size; index++)
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_min_max_table_button[index]);
- for (index = 0;
- index < config->cm_min_max_table_sensor_size; index++)
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cm_min_max_table_sensor[index]);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cp_max_delta_sensor_rx_percent);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cp_max_delta_sensor_tx_percent);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cp_max_delta_button_percent);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->min_button);
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->max_button);
- for (index = 0;
- index < config->cp_min_max_table_button_size; index++)
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cp_min_max_table_button[index]);
- for (index = 0;
- index < config->cp_min_max_table_rx_size; index++)
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cp_min_max_table_rx[index]);
- for (index = 0;
- index < config->cp_min_max_table_tx_size; index++)
- parade_debug(dev, DEBUG_LEVEL_2, "%d\n",
- config->cp_min_max_table_tx[index]);
- #endif
- /* Invalid mutual data length */
- if ((field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].data_num >>
- 1) % field_array[PER_ELEMENT_MIN_MAX_TABLE_SENSOR].line_num) {
- config->is_valid_or_not = 0;
- parade_debug(dev, DEBUG_LEVEL_2, "Invalid mutual data length\n");
- }
- } else {
- if (!config->cm_enabled)
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Miss CM thresholds or CM data format is wrong!\n",
- __func__);
- if (!config->cp_enabled)
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Miss CP thresholds or CP data format is wrong!\n",
- __func__);
- config->rx_num = 0;
- config->tx_num = 0;
- config->btn_num = 0;
- config->is_valid_or_not = 0;
- }
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s:\n"
- "Input file is %s!\n"
- "CM test: %s\n"
- "CP test: %s\n"
- "rx_num is %d\n"
- "tx_num is %d\n"
- "btn_num is %d\n",
- __func__,
- config->is_valid_or_not == 1 ? "VALID" : "!!! INVALID !!!",
- config->cm_enabled == 1 ? "Found" : "Not found",
- config->cp_enabled == 1 ? "Found" : "Not found",
- config->rx_num,
- config->tx_num,
- config->btn_num);
- }
- void cmcp_test_case_field_init(struct test_case_field *test_field_array,
- struct configuration *configs)
- {
- struct test_case_field test_case_field_array[MAX_CASE_NUM] = {
- {"CM TEST INPUTS", 14, TEST_CASE_TYPE_NO,
- NULL, 0, 0, 0},
- {"CM_EXCLUDING_COL_EDGE", 21, TEST_CASE_TYPE_ONE,
- &configs->cm_excluding_col_edge, 0, 0, 0},
- {"CM_EXCLUDING_ROW_EDGE", 21, TEST_CASE_TYPE_ONE,
- &configs->cm_excluding_row_edge, 0, 0, 0},
- {"CM_GRADIENT_CHECK_COL", 21, TEST_CASE_TYPE_MUL,
- &configs->cm_max_table_gradient_cols_percent[0],
- 0, 0, 0},
- {"CM_GRADIENT_CHECK_ROW", 21, TEST_CASE_TYPE_MUL,
- &configs->cm_max_table_gradient_rows_percent[0],
- 0, 0, 0},
- {"CM_RANGE_LIMIT_ROW", 18, TEST_CASE_TYPE_ONE,
- &configs->cm_range_limit_row, 0, 0, 0},
- {"CM_RANGE_LIMIT_COL", 18, TEST_CASE_TYPE_ONE,
- &configs->cm_range_limit_col, 0, 0, 0},
- {"CM_MIN_LIMIT_CAL", 16, TEST_CASE_TYPE_ONE,
- &configs->cm_min_limit_cal, 0, 0, 0},
- {"CM_MAX_LIMIT_CAL", 16, TEST_CASE_TYPE_ONE,
- &configs->cm_max_limit_cal, 0, 0, 0},
- {"CM_MAX_DELTA_SENSOR_PERCENT", 27, TEST_CASE_TYPE_ONE,
- &configs->cm_max_delta_sensor_percent, 0, 0, 0},
- {"CM_MAX_DELTA_BUTTON_PERCENT", 27, TEST_CASE_TYPE_ONE,
- &configs->cm_max_delta_button_percent, 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_TABLE_BUTTON", 32, TEST_CASE_TYPE_MUL,
- &configs->cm_min_max_table_button[0], 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_TABLE_SENSOR", 32,
- TEST_CASE_TYPE_MUL_LINES,
- &configs->cm_min_max_table_sensor[0], 0, 0, 0},
- {"CP TEST INPUTS", 14, TEST_CASE_TYPE_NO,
- NULL, 0, 0, 0},
- {"CP_PER_ELEMENT_MIN_MAX_BUTTON", 29, TEST_CASE_TYPE_MUL,
- &configs->cp_min_max_table_button[0], 0, 0, 0},
- {"CP_MAX_DELTA_SENSOR_RX_PERCENT", 30, TEST_CASE_TYPE_ONE,
- &configs->cp_max_delta_sensor_rx_percent,
- 0, 0, 0},
- {"CP_MAX_DELTA_SENSOR_TX_PERCENT", 30, TEST_CASE_TYPE_ONE,
- &configs->cp_max_delta_sensor_tx_percent,
- 0, 0, 0},
- {"CP_MAX_DELTA_BUTTON_PERCENT", 27, TEST_CASE_TYPE_ONE,
- &configs->cp_max_delta_button_percent, 0, 0, 0},
- {"MIN_BUTTON", 10, TEST_CASE_TYPE_ONE,
- &configs->min_button, 0, 0, 0},
- {"MAX_BUTTON", 10, TEST_CASE_TYPE_ONE,
- &configs->max_button, 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_RX", 22, TEST_CASE_TYPE_MUL,
- &configs->cp_min_max_table_rx[0], 0, 0, 0},
- {"PER_ELEMENT_MIN_MAX_TX", 22, TEST_CASE_TYPE_MUL,
- &configs->cp_min_max_table_tx[0], 0, 0, 0},
- };
- memcpy(test_field_array, test_case_field_array,
- sizeof(struct test_case_field) * MAX_CASE_NUM);
- }
- static ssize_t cyttsp5_parse_cmcp_threshold_file_common(
- struct device *dev, const char *buf, u32 file_size)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- ssize_t rc = 0;
- u32 case_count = 0;
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Start parsing cmcp threshold file. File size is %d\n",
- __func__, file_size);
- cmcp_test_case_field_init(dad->test_field_array, dad->configs);
- /* Get all the cases from .csv file */
- case_count = cmcp_get_case_info_from_threshold_file(dev,
- buf, dad->test_search_array, file_size);
- /* Search cases */
- cmcp_get_configuration_info(dev,
- buf,
- dad->test_search_array, case_count, dad->test_field_array,
- dad->configs);
- /* Get basic information */
- cmcp_get_basic_info(dev, dad->test_field_array, dad->configs);
- return rc;
- }
- static ssize_t cyttsp5_cmcp_threshold_loading_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t size)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- long value;
- int rc;
- rc = kstrtol(buf, 10, &value);
- if (rc < 0 || value < -1 || value > 1) {
- dev_err(dev, "%s: Invalid value\n", __func__);
- return size;
- }
- mutex_lock(&dad->cmcp_threshold_lock);
- if (value == 1)
- dad->cmcp_threshold_loading = true;
- else if (value == -1)
- dad->cmcp_threshold_loading = false;
- else if (value == 0 && dad->cmcp_threshold_loading) {
- dad->cmcp_threshold_loading = false;
- if (dad->cmcp_threshold_size == 0) {
- dev_err(dev, "%s: No cmcp threshold data\n", __func__);
- goto exit_free;
- }
- /* Clear test executed flag */
- dad->test_executed = 0;
- cyttsp5_parse_cmcp_threshold_file_common(dev,
- &dad->cmcp_threshold_data[0], dad->cmcp_threshold_size);
- /* Mark valid */
- dad->builtin_cmcp_threshold_status = 0;
- /* Restore test item to default value when new file input */
- dad->cmcp_test_items = 0;
- }
- exit_free:
- kfree(dad->cmcp_threshold_data);
- dad->cmcp_threshold_data = NULL;
- dad->cmcp_threshold_size = 0;
- mutex_unlock(&dad->cmcp_threshold_lock);
- if (rc)
- return rc;
- return size;
- }
- static DEVICE_ATTR(cmcp_threshold_loading, S_IRUSR | S_IWUSR,
- cyttsp5_cmcp_threshold_loading_show,
- cyttsp5_cmcp_threshold_loading_store);
- /*
- * cmcp threshold data write
- */
- static ssize_t cyttsp5_cmcp_threshold_data_write(struct file *filp,
- struct kobject *kobj, struct bin_attribute *bin_attr,
- char *buf, loff_t offset, size_t count)
- {
- struct device *dev = container_of(kobj, struct device, kobj);
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- u8 *p;
- parade_debug(dev, DEBUG_LEVEL_2, "%s: offset:%lld count:%zu\n",
- __func__, offset, count);
- mutex_lock(&dad->cmcp_threshold_lock);
- if (!dad->cmcp_threshold_loading) {
- mutex_unlock(&dad->cmcp_threshold_lock);
- return -ENODEV;
- }
- p = krealloc(dad->cmcp_threshold_data, offset + count, GFP_KERNEL);
- if (!p) {
- kfree(dad->cmcp_threshold_data);
- dad->cmcp_threshold_data = NULL;
- mutex_unlock(&dad->cmcp_threshold_lock);
- return -ENOMEM;
- }
- dad->cmcp_threshold_data = p;
- memcpy(&dad->cmcp_threshold_data[offset], buf, count);
- dad->cmcp_threshold_size += count;
- mutex_unlock(&dad->cmcp_threshold_lock);
- return count;
- }
- static struct bin_attribute bin_attr_cmcp_threshold_data = {
- .attr = {
- .name = "cmcp_threshold_data",
- .mode = S_IWUSR,
- },
- .size = 0,
- .write = cyttsp5_cmcp_threshold_data_write,
- };
- /*
- * Suspend scan command
- */
- static int cyttsp5_suspend_scan_cmd_(struct device *dev)
- {
- int rc;
- rc = cmd->nonhid_cmd->suspend_scanning(dev, 0);
- if (rc < 0)
- dev_err(dev, "%s: Suspend scan failed r=%d\n",
- __func__, rc);
- return rc;
- }
- /*
- * Resume scan command
- */
- static int cyttsp5_resume_scan_cmd_(struct device *dev)
- {
- int rc;
- rc = cmd->nonhid_cmd->resume_scanning(dev, 0);
- if (rc < 0)
- dev_err(dev, "%s: Resume scan failed r=%d\n",
- __func__, rc);
- return rc;
- }
- /*
- * Execute scan command
- */
- static int cyttsp5_exec_scan_cmd_(struct device *dev)
- {
- int rc;
- rc = cmd->nonhid_cmd->exec_panel_scan(dev, 0);
- if (rc < 0)
- dev_err(dev, "%s: Heatmap start scan failed r=%d\n",
- __func__, rc);
- return rc;
- }
- /*
- * Retrieve panel data command
- */
- static int cyttsp5_ret_scan_data_cmd_(struct device *dev, u16 read_offset,
- u16 read_count, u8 data_id, u8 *response, u8 *config,
- u16 *actual_read_len, u8 *return_buf)
- {
- int rc;
- rc = cmd->nonhid_cmd->retrieve_panel_scan(dev, 0, read_offset,
- read_count, data_id, response, config, actual_read_len,
- return_buf);
- if (rc < 0)
- dev_err(dev, "%s: Retrieve scan data failed r=%d\n",
- __func__, rc);
- return rc;
- }
- /*
- * Get data structure command
- */
- static int cyttsp5_get_data_structure_cmd_(struct device *dev, u16 read_offset,
- u16 read_length, u8 data_id, u8 *status, u8 *data_format,
- u16 *actual_read_len, u8 *data)
- {
- int rc;
- rc = cmd->nonhid_cmd->get_data_structure(dev, 0, read_offset,
- read_length, data_id, status, data_format,
- actual_read_len, data);
- if (rc < 0)
- dev_err(dev, "%s: Get data structure failed r=%d\n",
- __func__, rc);
- return rc;
- }
- /*
- * Run self test command
- */
- static int cyttsp5_run_selftest_cmd_(struct device *dev, u8 test_id,
- u8 write_idacs_to_flash, u8 *status, u8 *summary_result,
- u8 *results_available)
- {
- int rc;
- rc = cmd->nonhid_cmd->run_selftest(dev, 0, test_id,
- write_idacs_to_flash, status, summary_result,
- results_available);
- if (rc < 0)
- dev_err(dev, "%s: Run self test failed r=%d\n",
- __func__, rc);
- return rc;
- }
- /*
- * Get self test result command
- */
- static int cyttsp5_get_selftest_result_cmd_(struct device *dev,
- u16 read_offset, u16 read_length, u8 test_id, u8 *status,
- u16 *actual_read_len, u8 *data)
- {
- int rc;
- rc = cmd->nonhid_cmd->get_selftest_result(dev, 0, read_offset,
- read_length, test_id, status, actual_read_len, data);
- if (rc < 0)
- dev_err(dev, "%s: Get self test result failed r=%d\n",
- __func__, rc);
- return rc;
- }
- /*
- * Calibrate IDACs command
- */
- static int _cyttsp5_calibrate_idacs_cmd(struct device *dev,
- u8 sensing_mode, u8 *status)
- {
- int rc;
- rc = cmd->nonhid_cmd->calibrate_idacs(dev, 0, sensing_mode, status);
- return rc;
- }
- /*
- * Initialize Baselines command
- */
- static int _cyttsp5_initialize_baselines_cmd(struct device *dev,
- u8 sensing_mode, u8 *status)
- {
- int rc;
- rc = cmd->nonhid_cmd->initialize_baselines(dev, 0, sensing_mode,
- status);
- return rc;
- }
- static int prepare_print_buffer(int status, u8 *in_buf, int length,
- u8 *out_buf, size_t out_buf_size)
- {
- int index = 0;
- int i;
- index += scnprintf(out_buf, out_buf_size, "status %d\n", status);
- for (i = 0; i < length; i++) {
- index += scnprintf(&out_buf[index], out_buf_size - index,
- "%02X\n", in_buf[i]);
- }
- return index;
- }
- static ssize_t cyttsp5_run_and_get_selftest_result_noprint(struct device *dev,
- char *buf, size_t buf_len, u8 test_id, u16 read_length,
- bool get_result_on_pass)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- int status = STATUS_FAIL;
- u8 cmd_status = 0;
- u8 summary_result = 0;
- u16 act_length = 0;
- int length = 0;
- int rc;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, CY_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- dev_err(dev, "%s: Error on request exclusive r=%d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = cyttsp5_suspend_scan_cmd_(dev);
- if (rc < 0) {
- dev_err(dev, "%s: Error on suspend scan r=%d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = cyttsp5_run_selftest_cmd_(dev, test_id, 0,
- &cmd_status, &summary_result, NULL);
- if (rc < 0) {
- dev_err(dev, "%s: Error on run self test for test_id:%d r=%d\n",
- __func__, test_id, rc);
- goto resume_scan;
- }
- /* Form response buffer */
- dad->ic_buf[0] = cmd_status;
- dad->ic_buf[1] = summary_result;
- length = 2;
- /* Get data if command status is success */
- if (cmd_status != CY_CMD_STATUS_SUCCESS)
- goto status_success;
- /* Get data unless test result is pass */
- if (summary_result == CY_ST_RESULT_PASS && !get_result_on_pass)
- goto status_success;
- rc = cyttsp5_get_selftest_result_cmd_(dev, 0, read_length,
- test_id, &cmd_status, &act_length, &dad->ic_buf[6]);
- if (rc < 0) {
- dev_err(dev, "%s: Error on get self test result r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- dad->ic_buf[2] = cmd_status;
- dad->ic_buf[3] = test_id;
- dad->ic_buf[4] = LOW_BYTE(act_length);
- dad->ic_buf[5] = HI_BYTE(act_length);
- length = 6 + act_length;
- status_success:
- status = STATUS_SUCCESS;
- resume_scan:
- cyttsp5_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- mutex_unlock(&dad->sysfs_lock);
- return status;
- }
- static ssize_t cyttsp5_run_and_get_selftest_result(struct device *dev,
- char *buf, size_t buf_len, u8 test_id, u16 read_length,
- bool get_result_on_pass)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- int status = STATUS_FAIL;
- u8 cmd_status = 0;
- u8 summary_result = 0;
- u16 act_length = 0;
- int length = 0;
- int size;
- int rc;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, CY_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- dev_err(dev, "%s: Error on request exclusive r=%d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = cyttsp5_suspend_scan_cmd_(dev);
- if (rc < 0) {
- dev_err(dev, "%s: Error on suspend scan r=%d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = cyttsp5_run_selftest_cmd_(dev, test_id, 0,
- &cmd_status, &summary_result, NULL);
- if (rc < 0) {
- dev_err(dev, "%s: Error on run self test for test_id:%d r=%d\n",
- __func__, test_id, rc);
- goto resume_scan;
- }
- /* Form response buffer */
- dad->ic_buf[0] = cmd_status;
- dad->ic_buf[1] = summary_result;
- length = 2;
- /* Get data if command status is success */
- if (cmd_status != CY_CMD_STATUS_SUCCESS)
- goto status_success;
- /* Get data unless test result is pass */
- if (summary_result == CY_ST_RESULT_PASS && !get_result_on_pass)
- goto status_success;
- rc = cyttsp5_get_selftest_result_cmd_(dev, 0, read_length,
- test_id, &cmd_status, &act_length, &dad->ic_buf[6]);
- if (rc < 0) {
- dev_err(dev, "%s: Error on get self test result r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- dad->ic_buf[2] = cmd_status;
- dad->ic_buf[3] = test_id;
- dad->ic_buf[4] = LOW_BYTE(act_length);
- dad->ic_buf[5] = HI_BYTE(act_length);
- length = 6 + act_length;
- status_success:
- status = STATUS_SUCCESS;
- resume_scan:
- cyttsp5_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- size = prepare_print_buffer(status, dad->ic_buf, length, buf, buf_len);
- mutex_unlock(&dad->sysfs_lock);
- return size;
- }
- struct cyttsp5_device_access_debugfs_data {
- struct cyttsp5_device_access_data *dad;
- ssize_t pr_buf_len;
- u8 pr_buf[3 * CY_MAX_PRBUF_SIZE];
- };
- static int cyttsp5_device_access_debugfs_open(struct inode *inode,
- struct file *filp)
- {
- struct cyttsp5_device_access_data *dad = inode->i_private;
- struct cyttsp5_device_access_debugfs_data *data;
- data = kzalloc(sizeof(*data), GFP_KERNEL);
- if (!data)
- return -ENOMEM;
- data->dad = dad;
- filp->private_data = data;
- return nonseekable_open(inode, filp);
- }
- static int cyttsp5_device_access_debugfs_release(struct inode *inode,
- struct file *filp)
- {
- kfree(filp->private_data);
- return 0;
- }
- #define CY_DEBUGFS_FOPS(_name, _read, _write) \
- static const struct file_operations _name##_debugfs_fops = { \
- .open = cyttsp5_device_access_debugfs_open, \
- .release = cyttsp5_device_access_debugfs_release, \
- .read = _read, \
- .write = _write, \
- }
- static ssize_t panel_scan_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- struct cyttsp5_core_data *cd = dev_get_drvdata(dev);
- int status = STATUS_FAIL;
- u8 config;
- u16 actual_read_len;
- int length = 0;
- u8 element_size = 0;
- u8 *buf_offset;
- int elem_offset = 0;
- int rc;
- if (*ppos)
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, CY_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- dev_err(dev, "%s: Error on request exclusive r=%d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = cyttsp5_suspend_scan_cmd_(dev);
- if (rc < 0) {
- dev_err(dev, "%s: Error on suspend scan r=%d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = cyttsp5_exec_scan_cmd_(dev);
- if (rc < 0) {
- dev_err(dev, "%s: Error on execute panel scan r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- /* Set length to max to read all */
- rc = cyttsp5_ret_scan_data_cmd_(dev, 0, 0xFFFF,
- dad->panel_scan_data_id, dad->ic_buf, &config,
- &actual_read_len, NULL);
- if (rc < 0) {
- dev_err(dev, "%s: Error on retrieve panel scan r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- length = get_unaligned_le16(&dad->ic_buf[0]);
- buf_offset = dad->ic_buf + length;
- element_size = config & 0x07;
- elem_offset = actual_read_len;
- while (actual_read_len > 0) {
- rc = cyttsp5_ret_scan_data_cmd_(dev, elem_offset, 0xFFFF,
- dad->panel_scan_data_id, NULL, &config,
- &actual_read_len, buf_offset);
- if (rc < 0)
- goto resume_scan;
- length += actual_read_len * element_size;
- buf_offset = dad->ic_buf + length;
- elem_offset += actual_read_len;
- }
- /* Reconstruct cmd header */
- put_unaligned_le16(length, &dad->ic_buf[0]);
- put_unaligned_le16(elem_offset, &dad->ic_buf[7]);
- /* Do not print command header */
- length -= 5;
- status = STATUS_SUCCESS;
- resume_scan:
- cyttsp5_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- if (cd->show_timestamp) {
- int index = 0;
- index += scnprintf(data->pr_buf, sizeof(data->pr_buf),
- "[%u] ", jiffies_to_msecs(jiffies));
- data->pr_buf_len = prepare_print_buffer(status,
- &dad->ic_buf[5], length, &data->pr_buf[index],
- sizeof(data->pr_buf)-index);
- } else {
- data->pr_buf_len = prepare_print_buffer(status,
- &dad->ic_buf[5], length, data->pr_buf,
- sizeof(data->pr_buf));
- }
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- static ssize_t panel_scan_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- ssize_t length;
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cyttsp5_ic_parse_input(dad->dev, data->pr_buf, count,
- dad->ic_buf, CY_MAX_PRBUF_SIZE);
- if (length != 1) {
- dev_err(dad->dev, "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- dad->panel_scan_data_id = dad->ic_buf[0];
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- CY_DEBUGFS_FOPS(panel_scan, panel_scan_debugfs_read, panel_scan_debugfs_write);
- static ssize_t get_idac_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- int status = STATUS_FAIL;
- u8 cmd_status = 0;
- u8 data_format = 0;
- u16 act_length = 0;
- int length = 0;
- int rc;
- if (*ppos)
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, CY_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- dev_err(dev, "%s: Error on request exclusive r=%d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = cyttsp5_suspend_scan_cmd_(dev);
- if (rc < 0) {
- dev_err(dev, "%s: Error on suspend scan r=%d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = cyttsp5_get_data_structure_cmd_(dev, 0, PIP_CMD_MAX_LENGTH,
- dad->get_idac_data_id, &cmd_status, &data_format,
- &act_length, &dad->ic_buf[5]);
- if (rc < 0) {
- dev_err(dev, "%s: Error on get data structure r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- dad->ic_buf[0] = cmd_status;
- dad->ic_buf[1] = dad->get_idac_data_id;
- dad->ic_buf[2] = LOW_BYTE(act_length);
- dad->ic_buf[3] = HI_BYTE(act_length);
- dad->ic_buf[4] = data_format;
- length = 5 + act_length;
- status = STATUS_SUCCESS;
- resume_scan:
- cyttsp5_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
- data->pr_buf, sizeof(data->pr_buf));
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- static ssize_t get_idac_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- ssize_t length;
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cyttsp5_ic_parse_input(dad->dev, data->pr_buf, count,
- dad->ic_buf, CY_MAX_PRBUF_SIZE);
- if (length != 1) {
- dev_err(dad->dev, "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- dad->get_idac_data_id = dad->ic_buf[0];
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- CY_DEBUGFS_FOPS(get_idac, get_idac_debugfs_read, get_idac_debugfs_write);
- static ssize_t calibrate_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- int status = STATUS_FAIL;
- int length = 0;
- int rc;
- if (*ppos)
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, CY_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- dev_err(dev, "%s: Error on request exclusive r=%d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = cyttsp5_suspend_scan_cmd_(dev);
- if (rc < 0) {
- dev_err(dev, "%s: Error on suspend scan r=%d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = _cyttsp5_calibrate_idacs_cmd(dev, dad->calibrate_sensing_mode,
- &dad->ic_buf[0]);
- if (rc < 0) {
- dev_err(dev, "%s: Error on calibrate idacs r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- length = 1;
- /* Check if baseline initialization is requested */
- if (dad->calibrate_initialize_baselines) {
- /* Perform baseline initialization for all modes */
- rc = _cyttsp5_initialize_baselines_cmd(dev, CY_IB_SM_MUTCAP |
- CY_IB_SM_SELFCAP | CY_IB_SM_BUTTON,
- &dad->ic_buf[length]);
- if (rc < 0) {
- dev_err(dev, "%s: Error on initialize baselines r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- length++;
- }
- status = STATUS_SUCCESS;
- resume_scan:
- cyttsp5_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
- data->pr_buf, sizeof(data->pr_buf));
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- static ssize_t calibrate_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- ssize_t length;
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cyttsp5_ic_parse_input(dad->dev, data->pr_buf, count,
- dad->ic_buf, CY_MAX_PRBUF_SIZE);
- if (length != 2) {
- dev_err(dad->dev, "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- dad->calibrate_sensing_mode = dad->ic_buf[0];
- dad->calibrate_initialize_baselines = dad->ic_buf[1];
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- CY_DEBUGFS_FOPS(calibrate, calibrate_debugfs_read, calibrate_debugfs_write);
- static ssize_t baseline_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- struct device *dev = dad->dev;
- int status = STATUS_FAIL;
- int length = 0;
- int rc;
- if (*ppos)
- goto exit;
- mutex_lock(&dad->sysfs_lock);
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, CY_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0) {
- dev_err(dev, "%s: Error on request exclusive r=%d\n",
- __func__, rc);
- goto put_pm_runtime;
- }
- rc = cyttsp5_suspend_scan_cmd_(dev);
- if (rc < 0) {
- dev_err(dev, "%s: Error on suspend scan r=%d\n",
- __func__, rc);
- goto release_exclusive;
- }
- rc = _cyttsp5_initialize_baselines_cmd(dev, dad->baseline_sensing_mode,
- &dad->ic_buf[0]);
- if (rc < 0) {
- dev_err(dev, "%s: Error on initialize baselines r=%d\n",
- __func__, rc);
- goto resume_scan;
- }
- length = 1;
- status = STATUS_SUCCESS;
- resume_scan:
- cyttsp5_resume_scan_cmd_(dev);
- release_exclusive:
- cmd->release_exclusive(dev);
- put_pm_runtime:
- pm_runtime_put(dev);
- if (status == STATUS_FAIL)
- length = 0;
- data->pr_buf_len = prepare_print_buffer(status, dad->ic_buf, length,
- data->pr_buf, sizeof(data->pr_buf));
- mutex_unlock(&dad->sysfs_lock);
- exit:
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- static ssize_t baseline_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- struct cyttsp5_device_access_data *dad = data->dad;
- ssize_t length;
- int rc = 0;
- rc = simple_write_to_buffer(data->pr_buf, sizeof(data->pr_buf), ppos,
- buf, count);
- if (rc < 0)
- return rc;
- count = rc;
- mutex_lock(&dad->sysfs_lock);
- length = cyttsp5_ic_parse_input(dad->dev, buf, count, dad->ic_buf,
- CY_MAX_PRBUF_SIZE);
- if (length != 1) {
- dev_err(dad->dev, "%s: Malformed input\n", __func__);
- rc = -EINVAL;
- goto exit_unlock;
- }
- dad->baseline_sensing_mode = dad->ic_buf[0];
- exit_unlock:
- mutex_unlock(&dad->sysfs_lock);
- if (rc)
- return rc;
- return count;
- }
- CY_DEBUGFS_FOPS(baseline, baseline_debugfs_read, baseline_debugfs_write);
- static ssize_t auto_shorts_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = cyttsp5_run_and_get_selftest_result(
- data->dad->dev, data->pr_buf, sizeof(data->pr_buf),
- CY_ST_ID_AUTOSHORTS, PIP_CMD_MAX_LENGTH, false);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- CY_DEBUGFS_FOPS(auto_shorts, auto_shorts_debugfs_read, NULL);
- static ssize_t opens_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = cyttsp5_run_and_get_selftest_result(
- data->dad->dev, data->pr_buf, sizeof(data->pr_buf),
- CY_ST_ID_OPENS, PIP_CMD_MAX_LENGTH, false);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- CY_DEBUGFS_FOPS(opens, opens_debugfs_read, NULL);
- static ssize_t cm_panel_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = cyttsp5_run_and_get_selftest_result(
- data->dad->dev, data->pr_buf, sizeof(data->pr_buf),
- CY_ST_ID_CM_PANEL, PIP_CMD_MAX_LENGTH, true);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- CY_DEBUGFS_FOPS(cm_panel, cm_panel_debugfs_read, NULL);
- static ssize_t cp_panel_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = cyttsp5_run_and_get_selftest_result(
- data->dad->dev, data->pr_buf, sizeof(data->pr_buf),
- CY_ST_ID_CP_PANEL, PIP_CMD_MAX_LENGTH, true);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- CY_DEBUGFS_FOPS(cp_panel, cp_panel_debugfs_read, NULL);
- static ssize_t cm_button_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = cyttsp5_run_and_get_selftest_result(
- data->dad->dev, data->pr_buf, sizeof(data->pr_buf),
- CY_ST_ID_CM_BUTTON, PIP_CMD_MAX_LENGTH, true);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- CY_DEBUGFS_FOPS(cm_button, cm_button_debugfs_read, NULL);
- static ssize_t cp_button_debugfs_read(struct file *filp, char __user *buf,
- size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_debugfs_data *data = filp->private_data;
- if (!*ppos)
- /* Set length to PIP_CMD_MAX_LENGTH to read all */
- data->pr_buf_len = cyttsp5_run_and_get_selftest_result(
- data->dad->dev, data->pr_buf, sizeof(data->pr_buf),
- CY_ST_ID_CP_BUTTON, PIP_CMD_MAX_LENGTH, true);
- return simple_read_from_buffer(buf, count, ppos, data->pr_buf,
- data->pr_buf_len);
- }
- CY_DEBUGFS_FOPS(cp_button, cp_button_debugfs_read, NULL);
- #ifdef TTHE_TUNER_SUPPORT
- static ssize_t tthe_get_panel_data_debugfs_read(struct file *filp,
- char __user *buf, size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_data *dad = filp->private_data;
- struct device *dev;
- struct cyttsp5_core_data *cd;
- u8 config;
- u16 actual_read_len;
- u16 length = 0;
- u8 element_size = 0;
- u8 *buf_offset;
- u8 *buf_out;
- int elem;
- int elem_offset = 0;
- int print_idx = 0;
- int rc;
- int rc1;
- int i;
- mutex_lock(&dad->debugfs_lock);
- dev = dad->dev;
- cd = dev_get_drvdata(dev);
- buf_out = dad->tthe_get_panel_data_buf;
- if (!buf_out)
- goto release_mutex;
- pm_runtime_get_sync(dev);
- rc = cmd->request_exclusive(dev, CY_REQUEST_EXCLUSIVE_TIMEOUT);
- if (rc < 0)
- goto put_runtime;
- if (dad->heatmap.scan_start) {
- /*
- * To fix CDT206291: avoid multiple scans when
- * return data is larger than 4096 bytes in one cycle
- */
- dad->heatmap.scan_start = 0;
- /* Start scan */
- rc = cyttsp5_exec_scan_cmd_(dev);
- if (rc < 0)
- goto release_exclusive;
- }
- elem = dad->heatmap.num_element;
- #if defined(CY_ENABLE_MAX_ELEN)
- if (elem > CY_MAX_ELEN) {
- rc = cyttsp5_ret_scan_data_cmd_(dev, elem_offset,
- CY_MAX_ELEN, dad->heatmap.data_type, dad->ic_buf,
- &config, &actual_read_len, NULL);
- } else{
- rc = cyttsp5_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, dad->ic_buf, &config,
- &actual_read_len, NULL);
- }
- #else
- rc = cyttsp5_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, dad->ic_buf, &config,
- &actual_read_len, NULL);
- #endif
- if (rc < 0)
- goto release_exclusive;
- length = get_unaligned_le16(&dad->ic_buf[0]);
- buf_offset = dad->ic_buf + length;
- element_size = config & CY_CMD_RET_PANEL_ELMNT_SZ_MASK;
- elem -= actual_read_len;
- elem_offset = actual_read_len;
- while (elem > 0) {
- #ifdef CY_ENABLE_MAX_ELEN
- if (elem > CY_MAX_ELEN) {
- rc = cyttsp5_ret_scan_data_cmd_(dev, elem_offset,
- CY_MAX_ELEN, dad->heatmap.data_type, NULL, &config,
- &actual_read_len, buf_offset);
- } else{
- rc = cyttsp5_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, NULL, &config,
- &actual_read_len, buf_offset);
- }
- #else
- rc = cyttsp5_ret_scan_data_cmd_(dev, elem_offset, elem,
- dad->heatmap.data_type, NULL, &config,
- &actual_read_len, buf_offset);
- #endif
- if (rc < 0)
- goto release_exclusive;
- if (!actual_read_len)
- break;
- length += actual_read_len * element_size;
- buf_offset = dad->ic_buf + length;
- elem -= actual_read_len;
- elem_offset += actual_read_len;
- }
- /* Reconstruct cmd header */
- put_unaligned_le16(length, &dad->ic_buf[0]);
- put_unaligned_le16(elem_offset, &dad->ic_buf[7]);
- release_exclusive:
- rc1 = cmd->release_exclusive(dev);
- put_runtime:
- pm_runtime_put(dev);
- if (rc < 0)
- goto release_mutex;
- if (cd->show_timestamp)
- print_idx += scnprintf(buf_out, TTHE_TUNER_MAX_BUF,
- "[%u] CY_DATA:", jiffies_to_msecs(jiffies));
- else
- print_idx += scnprintf(buf_out, TTHE_TUNER_MAX_BUF,
- "CY_DATA:");
- for (i = 0; i < length; i++)
- print_idx += scnprintf(buf_out + print_idx,
- TTHE_TUNER_MAX_BUF - print_idx,
- "%02X ", dad->ic_buf[i]);
- print_idx += scnprintf(buf_out + print_idx,
- TTHE_TUNER_MAX_BUF - print_idx,
- ":(%d bytes)\n", length);
- rc = simple_read_from_buffer(buf, count, ppos, buf_out, print_idx);
- print_idx = rc;
- release_mutex:
- mutex_unlock(&dad->debugfs_lock);
- return print_idx;
- }
- static ssize_t tthe_get_panel_data_debugfs_write(struct file *filp,
- const char __user *buf, size_t count, loff_t *ppos)
- {
- struct cyttsp5_device_access_data *dad = filp->private_data;
- struct device *dev = dad->dev;
- ssize_t length;
- int max_read;
- u8 *buf_in = dad->tthe_get_panel_data_buf;
- int ret;
- mutex_lock(&dad->debugfs_lock);
- ret = copy_from_user(buf_in + (*ppos), buf, count);
- if (ret)
- goto exit;
- buf_in[count] = 0;
- length = cyttsp5_ic_parse_input(dev, buf_in, count, dad->ic_buf,
- CY_MAX_PRBUF_SIZE);
- if (length <= 0) {
- dev_err(dev, "%s: %s Group Data store\n", __func__,
- "Malformed input for");
- goto exit;
- }
- /* update parameter value */
- dad->heatmap.num_element = get_unaligned_le16(&dad->ic_buf[3]);
- dad->heatmap.data_type = dad->ic_buf[5];
- if (dad->ic_buf[6] > 0)
- dad->heatmap.scan_start = true;
- else
- dad->heatmap.scan_start = false;
- /* elem can not be bigger then buffer size */
- max_read = CY_CMD_RET_PANEL_HDR;
- max_read += dad->heatmap.num_element * CY_CMD_RET_PANEL_ELMNT_SZ_MAX;
- if (max_read >= CY_MAX_PRBUF_SIZE) {
- dad->heatmap.num_element =
- (CY_MAX_PRBUF_SIZE - CY_CMD_RET_PANEL_HDR)
- / CY_CMD_RET_PANEL_ELMNT_SZ_MAX;
- parade_debug(dev, DEBUG_LEVEL_2, "%s: Will get %d element\n",
- __func__, dad->heatmap.num_element);
- }
- exit:
- mutex_unlock(&dad->debugfs_lock);
- parade_debug(dev, DEBUG_LEVEL_2, "%s: return count=%zu\n",
- __func__, count);
- return count;
- }
- static int tthe_get_panel_data_debugfs_open(struct inode *inode,
- struct file *filp)
- {
- struct cyttsp5_device_access_data *dad = inode->i_private;
- mutex_lock(&dad->debugfs_lock);
- if (dad->tthe_get_panel_data_is_open) {
- mutex_unlock(&dad->debugfs_lock);
- return -EBUSY;
- }
- filp->private_data = inode->i_private;
- dad->tthe_get_panel_data_is_open = 1;
- mutex_unlock(&dad->debugfs_lock);
- return 0;
- }
- static int tthe_get_panel_data_debugfs_close(struct inode *inode,
- struct file *filp)
- {
- struct cyttsp5_device_access_data *dad = filp->private_data;
- mutex_lock(&dad->debugfs_lock);
- filp->private_data = NULL;
- dad->tthe_get_panel_data_is_open = 0;
- mutex_unlock(&dad->debugfs_lock);
- return 0;
- }
- static const struct file_operations tthe_get_panel_data_fops = {
- .open = tthe_get_panel_data_debugfs_open,
- .release = tthe_get_panel_data_debugfs_close,
- .read = tthe_get_panel_data_debugfs_read,
- .write = tthe_get_panel_data_debugfs_write,
- };
- #endif
- static int cyttsp5_setup_sysfs(struct device *dev)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- int rc;
- rc = device_create_file(dev, &dev_attr_command);
- if (rc) {
- dev_err(dev, "%s: Error, could not create command\n",
- __func__);
- goto exit;
- }
- rc = device_create_file(dev, &dev_attr_status);
- if (rc) {
- dev_err(dev, "%s: Error, could not create status\n",
- __func__);
- goto unregister_command;
- }
- rc = device_create_file(dev, &dev_attr_response);
- if (rc) {
- dev_err(dev, "%s: Error, could not create response\n",
- __func__);
- goto unregister_status;
- }
- dad->base_dentry = debugfs_create_dir(dev_name(dev), NULL);
- if (IS_ERR_OR_NULL(dad->base_dentry)) {
- dev_err(dev, "%s: Error, could not create base directory\n",
- __func__);
- goto unregister_response;
- }
- dad->mfg_test_dentry = debugfs_create_dir("mfg_test",
- dad->base_dentry);
- if (IS_ERR_OR_NULL(dad->mfg_test_dentry)) {
- dev_err(dev, "%s: Error, could not create mfg_test directory\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("panel_scan", 0600,
- dad->mfg_test_dentry, dad,
- &panel_scan_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create panel_scan\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("get_idac", 0600,
- dad->mfg_test_dentry, dad, &get_idac_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create get_idac\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("auto_shorts", 0400,
- dad->mfg_test_dentry, dad,
- &auto_shorts_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create auto_shorts\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("opens", 0400,
- dad->mfg_test_dentry, dad, &opens_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create opens\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("calibrate", 0600,
- dad->mfg_test_dentry, dad, &calibrate_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create calibrate\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("baseline", 0600,
- dad->mfg_test_dentry, dad, &baseline_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create baseline\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cm_panel", 0400,
- dad->mfg_test_dentry, dad, &cm_panel_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create cm_panel\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cp_panel", 0400,
- dad->mfg_test_dentry, dad, &cp_panel_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create cp_panel\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cm_button", 0400,
- dad->mfg_test_dentry, dad, &cm_button_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create cm_button\n",
- __func__);
- goto unregister_base_dir;
- }
- if (IS_ERR_OR_NULL(debugfs_create_file("cp_button", 0400,
- dad->mfg_test_dentry, dad, &cp_button_debugfs_fops))) {
- dev_err(dev, "%s: Error, could not create cp_button\n",
- __func__);
- goto unregister_base_dir;
- }
- dad->cmcp_results_debugfs = debugfs_create_file("cmcp_results", 0644,
- dad->mfg_test_dentry, dad, &cmcp_results_debugfs_fops);
- if (IS_ERR_OR_NULL(dad->cmcp_results_debugfs)) {
- dev_err(dev, "%s: Error, could not create cmcp_results\n",
- __func__);
- dad->cmcp_results_debugfs = NULL;
- goto unregister_base_dir;
- }
- #ifdef TTHE_TUNER_SUPPORT
- dad->tthe_get_panel_data_debugfs = debugfs_create_file(
- CYTTSP5_TTHE_TUNER_GET_PANEL_DATA_FILE_NAME,
- 0644, NULL, dad, &tthe_get_panel_data_fops);
- if (IS_ERR_OR_NULL(dad->tthe_get_panel_data_debugfs)) {
- dev_err(dev, "%s: Error, could not create get_panel_data\n",
- __func__);
- dad->tthe_get_panel_data_debugfs = NULL;
- goto unregister_base_dir;
- }
- #endif
- rc = device_create_file(dev, &dev_attr_cmcp_test);
- if (rc) {
- dev_err(dev, "%s: Error, could not create cmcp_test\n",
- __func__);
- goto unregister_base_dir;
- }
- rc = device_create_file(dev, &dev_attr_cmcp_threshold_loading);
- if (rc) {
- dev_err(dev, "%s: Error, could not create cmcp_thresold_loading\n",
- __func__);
- goto unregister_cmcp_test;
- }
- rc = device_create_bin_file(dev, &bin_attr_cmcp_threshold_data);
- if (rc) {
- dev_err(dev, "%s: Error, could not create cmcp_thresold_data\n",
- __func__);
- goto unregister_cmcp_thresold_loading;
- }
- dad->sysfs_nodes_created = true;
- return rc;
- unregister_cmcp_thresold_loading:
- device_remove_file(dev, &dev_attr_cmcp_threshold_loading);
- unregister_cmcp_test:
- device_remove_file(dev, &dev_attr_cmcp_test);
- unregister_base_dir:
- debugfs_remove_recursive(dad->base_dentry);
- unregister_response:
- device_remove_file(dev, &dev_attr_response);
- unregister_status:
- device_remove_file(dev, &dev_attr_status);
- unregister_command:
- device_remove_file(dev, &dev_attr_command);
- exit:
- return rc;
- }
- static int cyttsp5_setup_sysfs_attention(struct device *dev)
- {
- struct cyttsp5_device_access_data *dad
- = cyttsp5_get_device_access_data(dev);
- int rc = 0;
- dad->si = cmd->request_sysinfo(dev);
- if (!dad->si)
- return -EINVAL;
- rc = cyttsp5_setup_sysfs(dev);
- cmd->unsubscribe_attention(dev, CY_ATTEN_STARTUP,
- CYTTSP5_DEVICE_ACCESS_NAME, cyttsp5_setup_sysfs_attention,
- 0);
- return rc;
- }
- #ifdef CONFIG_TOUCHSCREEN_CYPRESS_CYTTSP5_DEVICE_ACCESS_API
- int cyttsp5_device_access_user_command(const char *core_name, u16 read_len,
- u8 *read_buf, u16 write_len, u8 *write_buf,
- u16 *actual_read_len)
- {
- struct cyttsp5_core_data *cd;
- int rc;
- might_sleep();
- /* Check parameters */
- if (!read_buf || !write_buf || !actual_read_len)
- return -EINVAL;
- if (!core_name)
- core_name = CY_DEFAULT_CORE_ID;
- /* Find device */
- cd = cyttsp5_get_core_data((char *)core_name);
- if (!cd) {
- pr_err("%s: No device.\n", __func__);
- return -ENODEV;
- }
- pm_runtime_get_sync(cd->dev);
- rc = cmd->nonhid_cmd->user_cmd(cd->dev, 1, read_len, read_buf,
- write_len, write_buf, actual_read_len);
- pm_runtime_put(cd->dev);
- return rc;
- }
- EXPORT_SYMBOL_GPL(cyttsp5_device_access_user_command);
- struct command_work {
- struct work_struct work;
- const char *core_name;
- u16 read_len;
- u8 *read_buf;
- u16 write_len;
- u8 *write_buf;
- void (*cont)(const char *core_name, u16 read_len, u8 *read_buf,
- u16 write_len, u8 *write_buf, u16 actual_read_length,
- int rc);
- };
- static void cyttsp5_device_access_user_command_work_func(
- struct work_struct *work)
- {
- struct command_work *cmd_work =
- container_of(work, struct command_work, work);
- u16 actual_read_length;
- int rc;
- rc = cyttsp5_device_access_user_command(cmd_work->core_name,
- cmd_work->read_len, cmd_work->read_buf,
- cmd_work->write_len, cmd_work->write_buf,
- &actual_read_length);
- if (cmd_work->cont)
- cmd_work->cont(cmd_work->core_name,
- cmd_work->read_len, cmd_work->read_buf,
- cmd_work->write_len, cmd_work->write_buf,
- actual_read_length, rc);
- kfree(cmd_work);
- }
- int cyttsp5_device_access_user_command_async(const char *core_name,
- u16 read_len, u8 *read_buf, u16 write_len, u8 *write_buf,
- void (*cont)(const char *core_name, u16 read_len, u8 *read_buf,
- u16 write_len, u8 *write_buf, u16 actual_read_length,
- int rc))
- {
- struct command_work *cmd_work;
- cmd_work = kzalloc(sizeof(*cmd_work), GFP_ATOMIC);
- if (!cmd_work)
- return -ENOMEM;
- cmd_work->core_name = core_name;
- cmd_work->read_len = read_len;
- cmd_work->read_buf = read_buf;
- cmd_work->write_len = write_len;
- cmd_work->write_buf = write_buf;
- cmd_work->cont = cont;
- INIT_WORK(&cmd_work->work,
- cyttsp5_device_access_user_command_work_func);
- schedule_work(&cmd_work->work);
- return 0;
- }
- EXPORT_SYMBOL_GPL(cyttsp5_device_access_user_command_async);
- #endif
- static void cyttsp5_cmcp_parse_threshold_file(const struct firmware *fw,
- void *context)
- {
- struct device *dev = context;
- struct cyttsp5_device_access_data *dad =
- cyttsp5_get_device_access_data(dev);
- if (!fw) {
- dev_info(dev, "%s: No builtin cmcp threshold file\n", __func__);
- goto exit;
- }
- if (!fw->data || !fw->size) {
- dev_err(dev, "%s: Invalid builtin cmcp threshold file\n",
- __func__);
- goto exit;
- }
- parade_debug(dev, DEBUG_LEVEL_1, "%s: Found cmcp threshold file.\n",
- __func__);
- cyttsp5_parse_cmcp_threshold_file_common(dev, &fw->data[0], fw->size);
- dad->builtin_cmcp_threshold_status = 0;
- complete(&dad->builtin_cmcp_threshold_complete);
- return;
- exit:
- release_firmware(fw);
- dad->builtin_cmcp_threshold_status = -EINVAL;
- complete(&dad->builtin_cmcp_threshold_complete);
- }
- static void cyttsp5_parse_cmcp_threshold_builtin(
- struct work_struct *cmcp_threshold_update)
- {
- struct cyttsp5_device_access_data *dad =
- container_of(cmcp_threshold_update,
- struct cyttsp5_device_access_data,
- cmcp_threshold_update);
- struct device *dev = dad->dev;
- int retval;
- dad->si = cmd->request_sysinfo(dev);
- if (!dad->si) {
- dev_err(dev, "%s: Fail get sysinfo pointer from core\n",
- __func__);
- return;
- }
- parade_debug(dev, DEBUG_LEVEL_2,
- "%s: Enabling cmcp threshold class loader built-in\n",
- __func__);
- /* Open threshold file */
- retval = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
- CMCP_THRESHOLD_FILE_NAME, dev, GFP_KERNEL, dev,
- cyttsp5_cmcp_parse_threshold_file);
- if (retval < 0) {
- dev_err(dev, "%s: Failed loading cmcp threshold file, attempting legacy file\n",
- __func__);
- /* Try legacy file name */
- retval = request_firmware_nowait(THIS_MODULE, FW_ACTION_HOTPLUG,
- CY_CMCP_THRESHOLD_FILE_NAME, dev, GFP_KERNEL,
- dev, cyttsp5_cmcp_parse_threshold_file);
- if (retval < 0) {
- dev_err(dev, "%s: Fail request cmcp threshold class file load\n",
- __func__);
- goto exit;
- }
- }
- /* wait until cmcp threshold upgrade finishes */
- wait_for_completion(&dad->builtin_cmcp_threshold_complete);
- retval = dad->builtin_cmcp_threshold_status;
- exit:
- return;
- }
- static int cyttsp5_device_access_probe(struct device *dev, void **data)
- {
- struct cyttsp5_device_access_data *dad;
- struct configuration *configurations;
- struct cmcp_data *cmcp_info;
- struct result *result;
- int tx_num = MAX_TX_SENSORS;
- int rx_num = MAX_RX_SENSORS;
- int btn_num = MAX_BUTTONS;
- struct test_case_field *test_case_field_array;
- struct test_case_search *test_case_search_array;
- int rc = 0;
- dad = kzalloc(sizeof(*dad), GFP_KERNEL);
- if (!dad) {
- rc = -ENOMEM;
- goto cyttsp5_device_access_probe_data_failed;
- }
- configurations =
- kzalloc(sizeof(*configurations), GFP_KERNEL);
- if (!configurations) {
- rc = -ENOMEM;
- goto cyttsp5_device_access_probe_configs_failed;
- }
- dad->configs = configurations;
- cmcp_info = kzalloc(sizeof(*cmcp_info), GFP_KERNEL);
- if (!cmcp_info) {
- rc = -ENOMEM;
- goto cyttsp5_device_access_probe_cmcp_info_failed;
- }
- dad->cmcp_info = cmcp_info;
- cmcp_info->tx_num = tx_num;
- cmcp_info->rx_num = rx_num;
- cmcp_info->btn_num = btn_num;
- result = kzalloc(sizeof(*result), GFP_KERNEL);
- if (!result) {
- rc = -ENOMEM;
- goto cyttsp5_device_access_probe_result_failed;
- }
- dad->result = result;
- test_case_field_array =
- kzalloc(sizeof(*test_case_field_array) * MAX_CASE_NUM,
- GFP_KERNEL);
- if (!test_case_field_array) {
- rc = -ENOMEM;
- goto cyttsp5_device_access_probe_field_array_failed;
- }
- test_case_search_array =
- kzalloc(sizeof(*test_case_search_array) * MAX_CASE_NUM,
- GFP_KERNEL);
- if (!test_case_search_array) {
- rc = -ENOMEM;
- goto cyttsp5_device_access_probe_search_array_failed;
- }
- cmcp_info->gd_sensor_col = (struct gd_sensor *)
- kzalloc(tx_num * sizeof(struct gd_sensor), GFP_KERNEL);
- if (cmcp_info->gd_sensor_col == NULL)
- goto cyttsp5_device_access_probe_gd_sensor_col_failed;
- cmcp_info->gd_sensor_row = (struct gd_sensor *)
- kzalloc(rx_num * sizeof(struct gd_sensor), GFP_KERNEL);
- if (cmcp_info->gd_sensor_row == NULL)
- goto cyttsp5_device_access_probe_gd_sensor_row_failed;
- cmcp_info->cm_data_panel =
- kzalloc((tx_num * rx_num + 1) * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_data_panel == NULL)
- goto cyttsp5_device_access_probe_cm_data_panel_failed;
- cmcp_info->cp_tx_data_panel =
- kzalloc(tx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_tx_data_panel == NULL)
- goto cyttsp5_device_access_probe_cp_tx_data_panel_failed;
- cmcp_info->cp_tx_cal_data_panel =
- kzalloc(tx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_tx_cal_data_panel == NULL)
- goto cyttsp5_device_access_probe_cp_tx_cal_data_panel_failed;
- cmcp_info->cp_rx_data_panel =
- kzalloc(rx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_rx_data_panel == NULL)
- goto cyttsp5_device_access_probe_cp_rx_data_panel_failed;
- cmcp_info->cp_rx_cal_data_panel =
- kzalloc(rx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_rx_cal_data_panel == NULL)
- goto cyttsp5_device_access_probe_cp_rx_cal_data_panel_failed;
- cmcp_info->cm_btn_data = kcalloc(btn_num, sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_btn_data == NULL)
- goto cyttsp5_device_access_probe_cm_btn_data_failed;
- cmcp_info->cp_btn_data = kcalloc(btn_num, sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cp_btn_data == NULL)
- goto cyttsp5_device_access_probe_cp_btn_data_failed;
- cmcp_info->cm_sensor_column_delta =
- kzalloc(rx_num * tx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_sensor_column_delta == NULL)
- goto cyttsp5_device_access_probe_cm_sensor_column_delta_failed;
- cmcp_info->cm_sensor_row_delta =
- kzalloc(tx_num * rx_num * sizeof(int32_t), GFP_KERNEL);
- if (cmcp_info->cm_sensor_row_delta == NULL)
- goto cyttsp5_device_access_probe_cm_sensor_row_delta_failed;
- mutex_init(&dad->sysfs_lock);
- mutex_init(&dad->cmcp_threshold_lock);
- dad->dev = dev;
- #ifdef TTHE_TUNER_SUPPORT
- mutex_init(&dad->debugfs_lock);
- dad->heatmap.num_element = 200;
- #endif
- *data = dad;
- dad->test_field_array = test_case_field_array;
- dad->test_search_array = test_case_search_array;
- dad->test_executed = 0;
- init_completion(&dad->builtin_cmcp_threshold_complete);
- /* get sysinfo */
- dad->si = cmd->request_sysinfo(dev);
- if (dad->si) {
- rc = cyttsp5_setup_sysfs(dev);
- if (rc)
- goto cyttsp5_device_access_setup_sysfs_failed;
- } else {
- dev_err(dev, "%s: Fail get sysinfo pointer from core p=%p\n",
- __func__, dad->si);
- cmd->subscribe_attention(dev, CY_ATTEN_STARTUP,
- CYTTSP5_DEVICE_ACCESS_NAME,
- cyttsp5_setup_sysfs_attention, 0);
- }
- INIT_WORK(&dad->cmcp_threshold_update,
- cyttsp5_parse_cmcp_threshold_builtin);
- schedule_work(&dad->cmcp_threshold_update);
- return 0;
- cyttsp5_device_access_setup_sysfs_failed:
- kfree(cmcp_info->cm_sensor_row_delta);
- cyttsp5_device_access_probe_cm_sensor_row_delta_failed:
- kfree(cmcp_info->cm_sensor_column_delta);
- cyttsp5_device_access_probe_cm_sensor_column_delta_failed:
- kfree(cmcp_info->cp_btn_data);
- cyttsp5_device_access_probe_cp_btn_data_failed:
- kfree(cmcp_info->cm_btn_data);
- cyttsp5_device_access_probe_cm_btn_data_failed:
- kfree(cmcp_info->cp_rx_cal_data_panel);
- cyttsp5_device_access_probe_cp_rx_cal_data_panel_failed:
- kfree(cmcp_info->cp_rx_data_panel);
- cyttsp5_device_access_probe_cp_rx_data_panel_failed:
- kfree(cmcp_info->cp_tx_cal_data_panel);
- cyttsp5_device_access_probe_cp_tx_cal_data_panel_failed:
- kfree(cmcp_info->cp_tx_data_panel);
- cyttsp5_device_access_probe_cp_tx_data_panel_failed:
- kfree(cmcp_info->cm_data_panel);
- cyttsp5_device_access_probe_cm_data_panel_failed:
- kfree(cmcp_info->gd_sensor_row);
- cyttsp5_device_access_probe_gd_sensor_row_failed:
- kfree(cmcp_info->gd_sensor_col);
- cyttsp5_device_access_probe_gd_sensor_col_failed:
- kfree(test_case_search_array);
- cyttsp5_device_access_probe_search_array_failed:
- kfree(test_case_field_array);
- cyttsp5_device_access_probe_field_array_failed:
- kfree(result);
- cyttsp5_device_access_probe_result_failed:
- kfree(cmcp_info);
- cyttsp5_device_access_probe_cmcp_info_failed:
- kfree(configurations);
- cyttsp5_device_access_probe_configs_failed:
- kfree(dad);
- cyttsp5_device_access_probe_data_failed:
- dev_err(dev, "%s failed.\n", __func__);
- return rc;
- }
- static void cyttsp5_device_access_release(struct device *dev, void *data)
- {
- struct cyttsp5_device_access_data *dad = data;
- if (dad->sysfs_nodes_created) {
- device_remove_file(dev, &dev_attr_command);
- device_remove_file(dev, &dev_attr_status);
- device_remove_file(dev, &dev_attr_response);
- debugfs_remove(dad->cmcp_results_debugfs);
- debugfs_remove_recursive(dad->base_dentry);
- #ifdef TTHE_TUNER_SUPPORT
- debugfs_remove(dad->tthe_get_panel_data_debugfs);
- #endif
- device_remove_file(dev, &dev_attr_cmcp_test);
- device_remove_file(dev, &dev_attr_cmcp_threshold_loading);
- device_remove_bin_file(dev, &bin_attr_cmcp_threshold_data);
- kfree(dad->cmcp_threshold_data);
- } else {
- cmd->unsubscribe_attention(dev, CY_ATTEN_STARTUP,
- CYTTSP5_DEVICE_ACCESS_NAME,
- cyttsp5_setup_sysfs_attention, 0);
- }
- kfree(dad->test_search_array);
- kfree(dad->test_field_array);
- kfree(dad->configs);
- cyttsp5_free_cmcp_buf(dad->cmcp_info);
- kfree(dad->cmcp_info);
- kfree(dad->result);
- kfree(dad);
- }
- static struct cyttsp5_module device_access_module = {
- .name = CYTTSP5_DEVICE_ACCESS_NAME,
- .probe = cyttsp5_device_access_probe,
- .release = cyttsp5_device_access_release,
- };
- static int __init cyttsp5_device_access_init(void)
- {
- int rc;
- cmd = cyttsp5_get_commands();
- if (!cmd)
- return -EINVAL;
- rc = cyttsp5_register_module(&device_access_module);
- if (rc < 0) {
- pr_err("%s: Error, failed registering module\n",
- __func__);
- return rc;
- }
- pr_info("%s: Parade TTSP Device Access Driver (Built %s) rc=%d\n",
- __func__, CY_DRIVER_VERSION, rc);
- return 0;
- }
- module_init(cyttsp5_device_access_init);
- static void __exit cyttsp5_device_access_exit(void)
- {
- cyttsp5_unregister_module(&device_access_module);
- }
- module_exit(cyttsp5_device_access_exit);
- MODULE_LICENSE("GPL");
- MODULE_DESCRIPTION("Parade TrueTouch(R) Standard Product Device Access Driver");
- MODULE_AUTHOR("Parade Technologies <ttdrivers@paradetech.com>");
|